mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[12047] Refactor Unit kills Creature case
Add method Unit::JustKilledCreature to include code of killed creature case in Unit::DealDamage
This commit is contained in:
parent
bd5340b3a9
commit
8b075e1037
3 changed files with 84 additions and 84 deletions
|
|
@ -561,26 +561,14 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
|
||||||
// If (this) is TYPEID_PLAYER, (this) will enter combat w/victim, but after some time, automatically leave combat.
|
// If (this) is TYPEID_PLAYER, (this) will enter combat w/victim, but after some time, automatically leave combat.
|
||||||
// It is unclear how it should work for other cases.
|
// It is unclear how it should work for other cases.
|
||||||
|
|
||||||
((Creature*)pVictim)->SetLootRecipient(this);
|
DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE, "DealDamage critter, critter dies");
|
||||||
|
|
||||||
pVictim->SetDeathState(JUST_DIED);
|
pVictim->SetDeathState(JUST_DIED);
|
||||||
pVictim->SetHealth(0);
|
pVictim->SetHealth(0);
|
||||||
|
|
||||||
// allow loot only if has loot_id in creature_template
|
((Creature*)pVictim)->SetLootRecipient(this);
|
||||||
((Creature*)pVictim)->PrepareBodyLootState();
|
|
||||||
((Creature*)pVictim)->AllLootRemovedFromCorpse();
|
|
||||||
|
|
||||||
// some critters required for quests (need normal entry instead possible heroic in any cases)
|
JustKilledCreature((Creature*)pVictim);
|
||||||
if (GetTypeId() == TYPEID_PLAYER)
|
|
||||||
{
|
|
||||||
if (CreatureInfo const* normalInfo = ObjectMgr::GetCreatureTemplate(pVictim->GetEntry()))
|
|
||||||
((Player*)this)->KilledMonster(normalInfo, pVictim->GetObjectGuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (InstanceData* mapInstance = pVictim->GetInstanceData())
|
|
||||||
mapInstance->OnCreatureDeath(((Creature*)pVictim));
|
|
||||||
|
|
||||||
DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE, "DealDamage critter, critter dies");
|
|
||||||
|
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
@ -677,9 +665,6 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
|
||||||
Player *player_tap = GetCharmerOrOwnerPlayerOrPlayerItself();
|
Player *player_tap = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||||
Group *group_tap = NULL;
|
Group *group_tap = NULL;
|
||||||
|
|
||||||
// find owner of pVictim, used for creature cases, AI calls
|
|
||||||
Unit* pOwner = pVictim->GetCharmerOrOwner();
|
|
||||||
|
|
||||||
// in creature kill case group/player tap stored for creature
|
// in creature kill case group/player tap stored for creature
|
||||||
if (pVictim->GetTypeId() == TYPEID_UNIT)
|
if (pVictim->GetTypeId() == TYPEID_UNIT)
|
||||||
{
|
{
|
||||||
|
|
@ -814,70 +799,8 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
|
||||||
}
|
}
|
||||||
else // creature died
|
else // creature died
|
||||||
{
|
{
|
||||||
DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE,"DealDamageNotPlayer");
|
DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE,"DealDamage Killed NPC");
|
||||||
Creature *cVictim = (Creature*)pVictim;
|
JustKilledCreature((Creature*)pVictim);
|
||||||
|
|
||||||
if(!cVictim->IsPet())
|
|
||||||
{
|
|
||||||
cVictim->DeleteThreatList();
|
|
||||||
// only lootable if it has loot or can drop gold
|
|
||||||
cVictim->PrepareBodyLootState();
|
|
||||||
// may have no loot, so update death timer if allowed
|
|
||||||
cVictim->AllLootRemovedFromCorpse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call creature just died function
|
|
||||||
if (cVictim->AI())
|
|
||||||
cVictim->AI()->JustDied(this);
|
|
||||||
|
|
||||||
if (cVictim->IsTemporarySummon())
|
|
||||||
{
|
|
||||||
TemporarySummon* pSummon = (TemporarySummon*)cVictim;
|
|
||||||
if (pSummon->GetSummonerGuid().IsCreatureOrVehicle())
|
|
||||||
if(Creature* pSummoner = cVictim->GetMap()->GetCreature(pSummon->GetSummonerGuid()))
|
|
||||||
if (pSummoner->AI())
|
|
||||||
pSummoner->AI()->SummonedCreatureJustDied(cVictim);
|
|
||||||
}
|
|
||||||
else if (pOwner && pOwner->GetTypeId() == TYPEID_UNIT)
|
|
||||||
{
|
|
||||||
if (((Creature*)pOwner)->AI())
|
|
||||||
((Creature*)pOwner)->AI()->SummonedCreatureJustDied(cVictim);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (InstanceData* mapInstance = cVictim->GetInstanceData())
|
|
||||||
mapInstance->OnCreatureDeath(cVictim);
|
|
||||||
|
|
||||||
if (cVictim->IsLinkingEventTrigger())
|
|
||||||
cVictim->GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_DIE, cVictim);
|
|
||||||
|
|
||||||
// Dungeon specific stuff, only applies to players killing creatures
|
|
||||||
if(cVictim->GetInstanceId())
|
|
||||||
{
|
|
||||||
Map *m = cVictim->GetMap();
|
|
||||||
Player *creditedPlayer = GetCharmerOrOwnerPlayerOrPlayerItself();
|
|
||||||
// TODO: do instance binding anyway if the charmer/owner is offline
|
|
||||||
|
|
||||||
if(m->IsDungeon() && creditedPlayer)
|
|
||||||
{
|
|
||||||
if (m->IsRaidOrHeroicDungeon())
|
|
||||||
{
|
|
||||||
if(cVictim->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND)
|
|
||||||
((DungeonMap *)m)->PermBindAllPlayers(creditedPlayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DungeonPersistentState* save = ((DungeonMap*)m)->GetPersistanceState();
|
|
||||||
// the reset time is set but not added to the scheduler
|
|
||||||
// until the players leave the instance
|
|
||||||
time_t resettime = cVictim->GetRespawnTimeEx() + 2 * HOUR;
|
|
||||||
if (save->GetResetTime() < resettime)
|
|
||||||
save->SetResetTime(resettime);
|
|
||||||
}
|
|
||||||
|
|
||||||
// update encounter state if needed
|
|
||||||
((DungeonMap*)m)->GetPersistanceState()->UpdateEncounterState(ENCOUNTER_CREDIT_KILL_CREATURE, ((Creature*)cVictim)->GetEntry());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// last damage from non duel opponent or opponent controlled creature
|
// last damage from non duel opponent or opponent controlled creature
|
||||||
|
|
@ -1069,6 +992,81 @@ struct PetOwnerKilledUnitHelper
|
||||||
Unit* m_victim;
|
Unit* m_victim;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void Unit::JustKilledCreature(Creature* victim)
|
||||||
|
{
|
||||||
|
if (!victim->IsPet()) // Prepare loot if can
|
||||||
|
{
|
||||||
|
victim->DeleteThreatList();
|
||||||
|
// only lootable if it has loot or can drop gold
|
||||||
|
victim->PrepareBodyLootState();
|
||||||
|
// may have no loot, so update death timer if allowed
|
||||||
|
victim->AllLootRemovedFromCorpse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// some critters required for quests (need normal entry instead possible heroic in any cases)
|
||||||
|
if (victim->GetCreatureType() == CREATURE_TYPE_CRITTER && GetTypeId() == TYPEID_PLAYER)
|
||||||
|
{
|
||||||
|
if (CreatureInfo const* normalInfo = sCreatureStorage.LookupEntry<CreatureInfo>(victim->GetEntry()))
|
||||||
|
((Player*)this)->KilledMonster(normalInfo, victim->GetObjectGuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inform victim's AI
|
||||||
|
if (victim->AI())
|
||||||
|
victim->AI()->JustDied(this);
|
||||||
|
|
||||||
|
// Inform Owner
|
||||||
|
Unit* pOwner = victim->GetCharmerOrOwner();
|
||||||
|
if (victim->IsTemporarySummon())
|
||||||
|
{
|
||||||
|
TemporarySummon* pSummon = (TemporarySummon*)victim;
|
||||||
|
if (pSummon->GetSummonerGuid().IsCreatureOrVehicle())
|
||||||
|
if(Creature* pSummoner = victim->GetMap()->GetCreature(pSummon->GetSummonerGuid()))
|
||||||
|
if (pSummoner->AI())
|
||||||
|
pSummoner->AI()->SummonedCreatureJustDied(victim);
|
||||||
|
}
|
||||||
|
else if (pOwner && pOwner->GetTypeId() == TYPEID_UNIT)
|
||||||
|
{
|
||||||
|
if (((Creature*)pOwner)->AI())
|
||||||
|
((Creature*)pOwner)->AI()->SummonedCreatureJustDied(victim);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inform Instance Data and Linking
|
||||||
|
if (InstanceData* mapInstance = victim->GetInstanceData())
|
||||||
|
mapInstance->OnCreatureDeath(victim);
|
||||||
|
|
||||||
|
if (victim->IsLinkingEventTrigger())
|
||||||
|
victim->GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_DIE, victim);
|
||||||
|
|
||||||
|
// Dungeon specific stuff
|
||||||
|
if (victim->GetInstanceId())
|
||||||
|
{
|
||||||
|
Map* m = victim->GetMap();
|
||||||
|
Player* creditedPlayer = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||||
|
// TODO: do instance binding anyway if the charmer/owner is offline
|
||||||
|
|
||||||
|
if (m->IsDungeon() && creditedPlayer)
|
||||||
|
{
|
||||||
|
if (m->IsRaidOrHeroicDungeon())
|
||||||
|
{
|
||||||
|
if (victim->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND)
|
||||||
|
((DungeonMap*)m)->PermBindAllPlayers(creditedPlayer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DungeonPersistentState* save = ((DungeonMap*)m)->GetPersistanceState();
|
||||||
|
// the reset time is set but not added to the scheduler
|
||||||
|
// until the players leave the instance
|
||||||
|
time_t resettime = victim->GetRespawnTimeEx() + 2 * HOUR;
|
||||||
|
if (save->GetResetTime() < resettime)
|
||||||
|
save->SetResetTime(resettime);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update encounter state if needed
|
||||||
|
((DungeonMap*)m)->GetPersistanceState()->UpdateEncounterState(ENCOUNTER_CREDIT_KILL_CREATURE, victim->GetEntry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Unit::PetOwnerKilledUnit(Unit* pVictim)
|
void Unit::PetOwnerKilledUnit(Unit* pVictim)
|
||||||
{
|
{
|
||||||
// for minipet and guardians (including protector)
|
// for minipet and guardians (including protector)
|
||||||
|
|
|
||||||
|
|
@ -1021,8 +1021,8 @@ struct CharmInfo
|
||||||
CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
|
CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
|
||||||
|
|
||||||
GlobalCooldownMgr& GetGlobalCooldownMgr() { return m_GlobalCooldownMgr; }
|
GlobalCooldownMgr& GetGlobalCooldownMgr() { return m_GlobalCooldownMgr; }
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
Unit* m_unit;
|
Unit* m_unit;
|
||||||
UnitActionBarEntry PetActionBar[MAX_UNIT_ACTION_BAR_INDEX];
|
UnitActionBarEntry PetActionBar[MAX_UNIT_ACTION_BAR_INDEX];
|
||||||
CharmSpellEntry m_charmspells[CREATURE_MAX_SPELLS];
|
CharmSpellEntry m_charmspells[CREATURE_MAX_SPELLS];
|
||||||
|
|
@ -1972,6 +1972,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
|
||||||
Unit* _GetTotem(TotemSlot slot) const; // for templated function without include need
|
Unit* _GetTotem(TotemSlot slot) const; // for templated function without include need
|
||||||
Pet* _GetPet(ObjectGuid guid) const; // for templated function without include need
|
Pet* _GetPet(ObjectGuid guid) const; // for templated function without include need
|
||||||
|
|
||||||
|
void JustKilledCreature(Creature* victim); // Wrapper called by DealDamage when a creature is killed
|
||||||
|
|
||||||
uint32 m_state; // Even derived shouldn't modify
|
uint32 m_state; // Even derived shouldn't modify
|
||||||
uint32 m_CombatTimer;
|
uint32 m_CombatTimer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "12046"
|
#define REVISION_NR "12047"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue