[7877] Correctly set totem PvP state at loading and owner PvP state change, including GM totem case.

* Also set PvP state in proper way at pet loading if owner in PvP state.
This commit is contained in:
VladimirMangos 2009-05-23 00:30:18 +04:00
parent e0e5ed7bd8
commit bc4611e8c0
6 changed files with 42 additions and 20 deletions

View file

@ -211,6 +211,9 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
sLog.outError("Pet have incorrect type (%u) for pet loading.", getPetType()); sLog.outError("Pet have incorrect type (%u) for pet loading.", getPetType());
} }
if(owner->IsPvP())
SetPvP(true);
InitStatsForLevel(petlevel); InitStatsForLevel(petlevel);
SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32()); SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32());

View file

@ -2079,6 +2079,11 @@ void Player::SetGameMaster(bool on)
pet->getHostilRefManager().setOnlineOfflineState(false); pet->getHostilRefManager().setOnlineOfflineState(false);
} }
for (int8 i = 0; i < MAX_TOTEM; ++i)
if(m_TotemSlot[i])
if(Creature *totem = GetMap()->GetCreature(m_TotemSlot[i]))
totem->setFaction(35);
RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
ResetContestedPvP(); ResetContestedPvP();
@ -2103,6 +2108,11 @@ void Player::SetGameMaster(bool on)
pet->getHostilRefManager().setOnlineOfflineState(true); pet->getHostilRefManager().setOnlineOfflineState(true);
} }
for (int8 i = 0; i < MAX_TOTEM; ++i)
if(m_TotemSlot[i])
if(Creature *totem = GetMap()->GetCreature(m_TotemSlot[i]))
totem->setFaction(getFaction());
// restore FFA PvP Server state // restore FFA PvP Server state
if(sWorld.IsFFAPvPRealm()) if(sWorld.IsFFAPvPRealm())
SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
@ -17371,11 +17381,6 @@ void Player::UpdatePvP(bool state, bool ovrride)
if(!state || ovrride) if(!state || ovrride)
{ {
SetPvP(state); SetPvP(state);
if(Pet* pet = GetPet())
pet->SetPvP(state);
if(Unit* charmed = GetCharm())
charmed->SetPvP(state);
pvpInfo.endTimer = 0; pvpInfo.endTimer = 0;
} }
else else
@ -17383,14 +17388,7 @@ void Player::UpdatePvP(bool state, bool ovrride)
if(pvpInfo.endTimer != 0) if(pvpInfo.endTimer != 0)
pvpInfo.endTimer = time(NULL); pvpInfo.endTimer = time(NULL);
else else
{
SetPvP(state); SetPvP(state);
if(Pet* pet = GetPet())
pet->SetPvP(state);
if(Unit* charmed = GetCharm())
charmed->SetPvP(state);
}
} }
} }

View file

@ -4181,6 +4181,9 @@ void Spell::EffectSummonPet(uint32 i)
if(m_caster->GetTypeId() == TYPEID_PLAYER) if(m_caster->GetTypeId() == TYPEID_PLAYER)
NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE); NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE);
if(m_caster->IsPvP())
NewSummon->SetPvP(true);
NewSummon->InitStatsForLevel(petlevel); NewSummon->InitStatsForLevel(petlevel);
NewSummon->InitPetCreateSpells(); NewSummon->InitPetCreateSpells();
NewSummon->InitLevelupSpellsForLevel(); NewSummon->InitLevelupSpellsForLevel();
@ -5515,6 +5518,9 @@ void Spell::EffectSummonTotem(uint32 i)
if(m_caster->GetTypeId() == TYPEID_PLAYER) if(m_caster->GetTypeId() == TYPEID_PLAYER)
pTotem->SetFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE); pTotem->SetFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE);
if(m_caster->IsPvP())
pTotem->SetPvP(true);
pTotem->Summon(m_caster); pTotem->Summon(m_caster);
if(slot < MAX_TOTEM && m_caster->GetTypeId() == TYPEID_PLAYER) if(slot < MAX_TOTEM && m_caster->GetTypeId() == TYPEID_PLAYER)

View file

@ -11398,6 +11398,9 @@ Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id)
if(GetTypeId()==TYPEID_PLAYER) if(GetTypeId()==TYPEID_PLAYER)
pet->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); pet->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
if(IsPvP())
pet->SetPvP(true);
uint32 level = (creatureTarget->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget->getLevel(); uint32 level = (creatureTarget->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget->getLevel();
if(!pet->InitStatsForLevel(level)) if(!pet->InitStatsForLevel(level))
@ -11602,3 +11605,21 @@ void Unit::NearTeleportTo( float x, float y, float z, float orientation, bool ca
SendMessageToSet(&data, false); SendMessageToSet(&data, false);
} }
} }
void Unit::SetPvP( bool state )
{
if(state)
SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP);
else
RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP);
if(Pet* pet = GetPet())
pet->SetPvP(state);
if(Unit* charmed = GetCharm())
charmed->SetPvP(state);
for (int8 i = 0; i < MAX_TOTEM; ++i)
if(m_TotemSlot[i])
if(Creature *totem = GetMap()->GetCreature(m_TotemSlot[i]))
totem->SetPvP(state);
}

View file

@ -924,13 +924,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
return false; return false;
} }
bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); } bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); }
void SetPvP(bool state) void SetPvP(bool state);
{
if(state)
SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP);
else
RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP);
}
uint32 GetCreatureType() const; uint32 GetCreatureType() const;
uint32 GetCreatureTypeMask() const uint32 GetCreatureTypeMask() const
{ {

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "7876" #define REVISION_NR "7877"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__