diff --git a/src/game/CombatHandler.cpp b/src/game/CombatHandler.cpp index 12fedd89a..ddc6748e2 100644 --- a/src/game/CombatHandler.cpp +++ b/src/game/CombatHandler.cpp @@ -81,7 +81,13 @@ void WorldSession::HandleSetSheathedOpcode( WorldPacket & recv_data ) //sLog.outDebug( "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed ); - GetPlayer()->SetSheath(sheathed); + if(sheathed >= MAX_SHEATH_STATE) + { + sLog.outError("Unknown sheath state %u ??",sheathed); + return; + } + + GetPlayer()->SetSheath(SheathState(sheathed)); } void WorldSession::SendAttackStop(Unit const* enemy) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 7c6cbdb6c..4ac9c77ad 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -256,7 +256,7 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data ) m_regenHealth = GetCreatureInfo()->RegenHealth; // creatures always have melee weapon ready if any - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetSheath(SHEATH_STATE_MELEE); SelectLevel(GetCreatureInfo()); if (team == HORDE) diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 5a1cf5716..b98ad6a2b 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -783,6 +783,11 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 cell_lock->Visit(cell_lock, grid_creature_searcher, *m_creature->GetMap()); break; } + case ACTION_T_SET_SHEATH: + { + m_creature->SetSheath(SheathState(action.set_sheath.sheath)); + break; + } } } diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 5f967c51d..0fd9b06b2 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -102,7 +102,7 @@ enum EventAI_ActionType ACTION_T_DIE = 37, // No Params ACTION_T_ZONE_COMBAT_PULSE = 38, // No Params ACTION_T_CALL_FOR_HELP = 39, // Radius - + ACTION_T_SET_SHEATH = 40, // Sheath (0-passive,1-melee,2-ranged) ACTION_T_END, }; @@ -364,6 +364,11 @@ struct CreatureEventAI_Action { uint32 radius; } call_for_help; + // ACTION_T_SET_SHEATH = 40 + struct + { + uint32 sheath; + } set_sheath; // RAW struct { diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index b3678dad6..5caaa2311 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -641,6 +641,13 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() if (!sCreatureStorage.LookupEntry(action.update_template.creatureId)) sLog.outErrorDb("CreatureEventAI: Event %u Action %u uses non-existant creature entry %u.", i, j+1, action.update_template.creatureId); break; + case ACTION_T_SET_SHEATH: + if (action.set_sheath.sheath >= MAX_SHEATH_STATE) + { + sLog.outErrorDb("CreatureEventAI: Event %u Action %u uses wrong sheath state %u.", i, j+1, action.set_sheath.sheath); + action.set_sheath.sheath = SHEATH_STATE_UNARMED; + } + break; case ACTION_T_EVADE: //No Params case ACTION_T_FLEE_FOR_ASSIST: //No Params case ACTION_T_DIE: //No Params diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 60b7c06b4..078c9c843 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -197,7 +197,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool break; case HUNTER_PET: SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE); + SetSheath(SHEATH_STATE_MELEE); SetByteValue(UNIT_FIELD_BYTES_2, 2, fields[9].GetBool() ? UNIT_RENAME_NOT_ALLOWED : UNIT_RENAME_ALLOWED); SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); @@ -783,7 +783,7 @@ bool Pet::CreateBaseAtCreature(Creature* creature) if(cinfo->type == CREATURE_TYPE_BEAST) { SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetSheath(SHEATH_STATE_MELEE); SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); SetUInt32Value(UNIT_MOD_CAST_SPEED, creature->GetUInt32Value(UNIT_MOD_CAST_SPEED)); } @@ -1756,7 +1756,7 @@ bool Pet::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint3 if(!InitEntry(Entry)) return false; - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE); + SetSheath(SHEATH_STATE_MELEE); if(getPetType() == MINI_PET) // always non-attackable SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index b5c0ebc8a..93a84ae9d 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -7913,7 +7913,7 @@ void Player::SetVirtualItemSlot( uint8 i, Item* item) } } -void Player::SetSheath( uint32 sheathed ) +void Player::SetSheath( SheathState sheathed ) { switch (sheathed) { @@ -7939,7 +7939,7 @@ void Player::SetSheath( uint32 sheathed ) SetVirtualItemSlot(2,NULL); break; } - SetByteValue(UNIT_FIELD_BYTES_2, 0, sheathed); // this must visualize Sheath changing for other players... + Unit::SetSheath(sheathed); // this must visualize Sheath changing for other players... } uint8 Player::FindEquipSlot( ItemPrototype const* proto, uint32 slot, bool swap ) const diff --git a/src/game/Player.h b/src/game/Player.h index 5c4dd2dc5..1b29a685b 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -963,7 +963,7 @@ class MANGOS_DLL_SPEC Player : public Unit /*********************************************************/ void SetVirtualItemSlot( uint8 i, Item* item); - void SetSheath( uint32 sheathed ); + void SetSheath( SheathState sheathed ); // overwrite Unit version uint8 FindEquipSlot( ItemPrototype const* proto, uint32 slot, bool swap ) const; uint32 GetItemCount( uint32 item, bool inBankAlso = false, Item* skipItem = NULL ) const; Item* GetItemByGuid( uint64 guid ) const; diff --git a/src/game/Unit.h b/src/game/Unit.h index ccefb8c86..301116756 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -191,6 +191,8 @@ enum SheathState SHEATH_STATE_RANGED = 2 // prepared ranged weapon }; +#define MAX_SHEATH_STATE 3 + // byte (1 from 0..3) of UNIT_FIELD_BYTES_2 enum UnitBytes2_Flags { @@ -918,6 +920,9 @@ class MANGOS_DLL_SPEC Unit : public WorldObject void ApplyAttackTimePercentMod(WeaponAttackType att,float val, bool apply); void ApplyCastTimePercentMod(float val, bool apply); + SheathState GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2, 0)); } + virtual void SetSheath( SheathState sheathed ) { SetByteValue(UNIT_FIELD_BYTES_2, 0, sheathed); } + // faction template id uint32 getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); } void setFaction(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction ); } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index de10281b6..f5a326b91 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7904" + #define REVISION_NR "7905" #endif // __REVISION_NR_H__