From 62c5720227f2863270ab7c3f8d72c90a802e7084 Mon Sep 17 00:00:00 2001 From: Muhaha Date: Wed, 13 May 2009 10:34:55 +0200 Subject: * avoid loot/exp when the mobs are killed by npc. Authore: KAPATEJIb @ getmangos.org --HG-- branch : trunk --- src/game/AggressorAI.cpp | 1 + src/game/Creature.cpp | 2 ++ src/game/Creature.h | 5 +++++ src/game/CreatureAI.cpp | 1 + src/game/Player.cpp | 3 +++ src/game/ReactorAI.cpp | 1 + src/game/Unit.cpp | 23 +++++++++++++++++++---- 7 files changed, 32 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/game/AggressorAI.cpp b/src/game/AggressorAI.cpp index a001ea5af22..d44cab9fd22 100644 --- a/src/game/AggressorAI.cpp +++ b/src/game/AggressorAI.cpp @@ -93,6 +93,7 @@ void AggressorAI::EnterEvadeMode() i_victimGuid = 0; i_creature.CombatStop(); i_creature.SetLootRecipient(NULL); + i_creature.ResetDamageByPlayers(); } void diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 5d18140f200..fc79caf7260 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -159,6 +159,7 @@ m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),m_creatureInfo(NULL), m_DBTabl m_GlobalCooldown = 0; m_unit_movement_flags = MOVEMENTFLAG_WALK_MODE; DisableReputationGain = false; + ResetDamageByPlayers(); } Creature::~Creature() @@ -1653,6 +1654,7 @@ void Creature::setDeathState(DeathState s) // setActive(true); SetHealth(GetMaxHealth()); SetLootRecipient(NULL); + ResetDamageByPlayers(); Unit::setDeathState(ALIVE); CreatureInfo const *cinfo = GetCreatureInfo(); RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); diff --git a/src/game/Creature.h b/src/game/Creature.h index 5a8fd48f97d..b25893b5ba9 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -637,6 +637,10 @@ class TRINITY_DLL_SPEC Creature : public Unit void SetDisableReputationGain(bool disable) { DisableReputationGain = disable; } bool IsReputationGainDisabled() { return DisableReputationGain; } + bool IsDamageEnoughForLootingAndReward() { return m_unDamageByPlayers >= (uint32)(GetMaxHealth() / 2); } + void AddDamageByPlayers(uint32 unDamage) { m_unDamageByPlayers += unDamage; } + void ResetDamageByPlayers() { m_unDamageByPlayers = 0; } + protected: bool CreateFromProto(uint32 guidlow,uint32 Entry,uint32 team, const CreatureData *data = NULL); bool InitEntry(uint32 entry, uint32 team=ALLIANCE, const CreatureData* data=NULL); @@ -651,6 +655,7 @@ class TRINITY_DLL_SPEC Creature : public Unit uint32 m_lootMoney; uint64 m_lootRecipient; + uint32 m_unDamageByPlayers; /// Timers uint32 m_deathTimer; // (msecs)timer for death or corpse disappearance diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index d21fe43fcaa..3a7cb896e88 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -100,6 +100,7 @@ void CreatureAI::EnterEvadeMode() me->CombatStop(); me->LoadCreaturesAddon(); me->SetLootRecipient(NULL); + me->ResetDamageByPlayers(); if(me->isAlive()) me->GetMotionMaster()->MoveTargetedHome(); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index fcdeb30a42d..e91728ab9be 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -14379,6 +14379,9 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) bool Player::isAllowedToLoot(Creature* creature) { + if(creature->isDead() && !creature->IsDamageEnoughForLootingAndReward()) + return false; + if(Player* recipient = creature->GetLootRecipient()) { if (recipient == this) diff --git a/src/game/ReactorAI.cpp b/src/game/ReactorAI.cpp index d15c71b28ef..f9fe0abfdc2 100644 --- a/src/game/ReactorAI.cpp +++ b/src/game/ReactorAI.cpp @@ -104,6 +104,7 @@ ReactorAI::EnterEvadeMode() i_victimGuid = 0; i_creature.CombatStop(); i_creature.SetLootRecipient(NULL); + i_creature.ResetDamageByPlayers(); if(!i_creature.GetCharmerOrOwner()) { diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index d0b71d0f3a3..0890bcce364 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -788,8 +788,15 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa } } - if (pVictim->GetTypeId() == TYPEID_UNIT && !((Creature*)pVictim)->isPet() && !((Creature*)pVictim)->hasLootRecipient()) - ((Creature*)pVictim)->SetLootRecipient(this); + if (pVictim->GetTypeId() == TYPEID_UNIT && !((Creature*)pVictim)->isPet()) + { + if(!((Creature*)pVictim)->hasLootRecipient()) + ((Creature*)pVictim)->SetLootRecipient(this); + + if(GetCharmerOrOwnerPlayerOrPlayerItself()) + ((Creature*)pVictim)->AddDamageByPlayers(health < damage ? health : damage); + } + if (health <= damage) { DEBUG_LOG("DealDamage: victim just died"); @@ -12471,11 +12478,19 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) // find player: owner of controlled `this` or `this` itself maybe Player *player = GetCharmerOrOwnerPlayerOrPlayerItself(); - if(pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->GetLootRecipient()) + bool bRewardIsAllowed = true; + if(pVictim->GetTypeId() == TYPEID_UNIT) + { + bRewardIsAllowed = ((Creature*)pVictim)->IsDamageEnoughForLootingAndReward(); + if(!bRewardIsAllowed) + ((Creature*)pVictim)->SetLootRecipient(NULL); + } + + if(bRewardIsAllowed && pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->GetLootRecipient()) player = ((Creature*)pVictim)->GetLootRecipient(); // Reward player, his pets, and group/raid members // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop) - if(player && player!=pVictim) + if(bRewardIsAllowed && player && player!=pVictim) { if(player->RewardPlayerAndGroupAtKill(pVictim)) player->ProcDamageAndSpell(pVictim, PROC_FLAG_KILL_AND_GET_XP, PROC_FLAG_KILLED, PROC_EX_NONE, 0); -- cgit v1.2.3 From 5748c36621f36a64cad29243dfe880291826059a Mon Sep 17 00:00:00 2001 From: raczman Date: Wed, 13 May 2009 13:22:43 +0200 Subject: Properly deallocate memory in tile assembler, and dereference memory when fread fails. --HG-- branch : trunk --- src/shared/vmap/TileAssembler.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/shared/vmap/TileAssembler.cpp b/src/shared/vmap/TileAssembler.cpp index e6a1a6f448b..119e5de4538 100644 --- a/src/shared/vmap/TileAssembler.cpp +++ b/src/shared/vmap/TileAssembler.cpp @@ -416,57 +416,57 @@ namespace VMAP AABSPTree *gtree = new AABSPTree(); G3D::uint32 flags; - if(fread(&flags, sizeof(G3D::uint32), 1, rf) != 1) { fclose(rf); return(false); } + if(fread(&flags, sizeof(G3D::uint32), 1, rf) != 1) { fclose(rf); delete gtree; return(false); } G3D::uint32 branches; - if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); return(false); } - if(strcmp(blockId, "GRP ") != 0) { fclose(rf); return(false); } - if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); return(false); } - if(fread(&branches, sizeof(G3D::uint32), 1, rf) != 1) { fclose(rf); return(false); } + if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); delete gtree; return(false); } + if(strcmp(blockId, "GRP ") != 0) { fclose(rf); delete gtree; return(false); } + if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); delete gtree; return(false); } + if(fread(&branches, sizeof(G3D::uint32), 1, rf) != 1) { fclose(rf); delete gtree; return(false); } for(int b=0;b<(int)branches; b++) { G3D::uint32 indexes; // indexes for each branch (not used jet) - if(fread(&indexes, sizeof(G3D::uint32), 1, rf) != 1) { fclose(rf); return(false); } + if(fread(&indexes, sizeof(G3D::uint32), 1, rf) != 1) { fclose(rf); delete gtree; return(false); } } // ---- indexes - if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); return(false); } - if(strcmp(blockId, "INDX") != 0) { fclose(rf); return(false); } - if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); return(false); } + if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); delete gtree; return(false); } + if(strcmp(blockId, "INDX") != 0) { fclose(rf); delete gtree; return(false); } + if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); delete gtree; return(false); } unsigned int nindexes; if(fread(&nindexes, sizeof(G3D::uint32), 1, rf) != 1) { fclose(rf); return(false); } if(nindexes >0) { unsigned short *indexarray = new unsigned short[nindexes*sizeof(unsigned short)]; - if(fread(indexarray, sizeof(unsigned short), nindexes, rf) != nindexes) { fclose(rf); return(false); } + if(fread(indexarray, sizeof(unsigned short), nindexes, rf) != nindexes) { fclose(rf); delete gtree; delete[] indexarray; return(false); } for(int i=0;i<(int)nindexes; i++) { unsigned short val = indexarray[i]; tempIndexArray.append(val); } - delete indexarray; + delete[] indexarray; } // ---- vectors - if(fread(&blockId, 4, 1, rf) != 1) {fclose(rf); return(false); } + if(fread(&blockId, 4, 1, rf) != 1) {fclose(rf); delete gtree; return(false); } if(strcmp(blockId, "VERT") != 0) { fclose(rf); return(false); } - if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); return(false); } + if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); delete gtree; return(false); } unsigned int nvectors; - if(fread(&nvectors, sizeof(int), 1, rf) != 1) { fclose(rf); return(false); } + if(fread(&nvectors, sizeof(int), 1, rf) != 1) { fclose(rf); delete gtree; return(false); } float *vectorarray = 0; if(nvectors >0) { vectorarray = new float[nvectors*sizeof(float)*3]; - if(fread(vectorarray, sizeof(float)*3, nvectors, rf) != nvectors) { fclose(rf); return(false); } + if(fread(vectorarray, sizeof(float)*3, nvectors, rf) != nvectors) { fclose(rf); delete gtree; delete[] vectorarray; return(false); } } // ----- liquit if(flags & 1) { // we have liquit -> not handled yet ... skip - if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); return(false); } - if(strcmp(blockId, "LIQU") != 0) { fclose(rf); return(false); } - if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); return(false); } + if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); delete gtree; delete[] vectorarray; return(false); } + if(strcmp(blockId, "LIQU") != 0) { fclose(rf); delete gtree; delete[] vectorarray; return(false); } + if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); delete gtree; delete[] vectorarray; return(false); } fseek(rf, blocksize, SEEK_CUR); } -- cgit v1.2.3 From bfaaa8201e6887fedd2145d668f40a484a609dac Mon Sep 17 00:00:00 2001 From: raczman Date: Wed, 13 May 2009 14:06:33 +0200 Subject: Possibly fixed more memory leaks in other places. --HG-- branch : trunk --- src/game/BattleGround.cpp | 1 + src/game/Chat.cpp | 1 + src/game/Level2.cpp | 4 ++++ src/game/ObjectMgr.cpp | 6 +++++- src/game/OutdoorPvP.cpp | 2 ++ src/game/OutdoorPvPSI.cpp | 9 +++++++-- 6 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index 6c8185b97d2..9be5650a16e 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -1323,6 +1323,7 @@ Creature* BattleGround::AddCreature(uint32 entry, uint32 type, uint32 teamval, f if(!pCreature->IsPositionValid()) { sLog.outError("ERROR: Creature (guidlow %d, entry %d) not added to battleground. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); + delete pCreature; return NULL; } diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index 15206f10c29..5d0901b0596 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -766,6 +766,7 @@ void ChatHandler::SendGlobalGMSysMessage(const char *str) FillSystemMessageData(&data, line); sWorld.SendGlobalGMMessage(&data); } + delete buf; } void ChatHandler::SendSysMessage(int32 entry) diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 4937d230142..fc6e8a51a74 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -3827,6 +3827,9 @@ bool ChatHandler::HandleCreatePetCommand(const char* args) // Everything looks OK, create new pet Pet* pet = new Pet(HUNTER_PET); + if(!pet) + return false; + if(!pet->CreateBaseAtCreature(creatureTarget)) { delete pet; @@ -3846,6 +3849,7 @@ bool ChatHandler::HandleCreatePetCommand(const char* args) { sLog.outError("ERROR: InitStatsForLevel() in EffectTameCreature failed! Pet deleted."); PSendSysMessage("Error 2"); + delete pet; return false; } diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index c948ad9d073..227b0f90f28 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -4124,7 +4124,11 @@ void ObjectMgr::LoadGossipText() pGText->Options[i].Emotes[2]._Emote = fields[cic++].GetUInt32(); } - if ( !pGText->Text_ID ) continue; + if ( !pGText->Text_ID ){ + delete pGText; + continue; + } + AddGossipText( pGText ); } while( result->NextRow() ); diff --git a/src/game/OutdoorPvP.cpp b/src/game/OutdoorPvP.cpp index 99b1c9a55f0..17f08131197 100644 --- a/src/game/OutdoorPvP.cpp +++ b/src/game/OutdoorPvP.cpp @@ -170,6 +170,7 @@ bool OutdoorPvPObjective::AddCreature(uint32 type, uint32 entry, uint32 teamval, if(!pCreature->IsPositionValid()) { sLog.outError("ERROR: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); + delete pCreature; return false; } @@ -283,6 +284,7 @@ bool OutdoorPvPObjective::AddCapturePoint(uint32 entry, uint32 map, float x, flo if(!pCreature->IsPositionValid()) { sLog.outError("ERROR: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); + delete pCreature; return false; } diff --git a/src/game/OutdoorPvPSI.cpp b/src/game/OutdoorPvPSI.cpp index 378543da48e..e4686573a67 100644 --- a/src/game/OutdoorPvPSI.cpp +++ b/src/game/OutdoorPvPSI.cpp @@ -200,8 +200,13 @@ bool OutdoorPvPSI::HandleDropFlag(Player *plr, uint32 spellId) // he dropped it further, summon mound GameObject * go = new GameObject; Map * map = MapManager::Instance().GetMap(plr->GetMapId(), plr); - if(!map) - return true; + if(!map){ + + delete go; + return true; + + } + if(!go->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT),SI_SILITHYST_MOUND, map,plr->GetPositionX(),plr->GetPositionY(),plr->GetPositionZ(),plr->GetOrientation(),0,0,0,0,100,1)) { delete go; -- cgit v1.2.3