diff options
author | megamage <none@none> | 2009-03-06 18:09:01 -0600 |
---|---|---|
committer | megamage <none@none> | 2009-03-06 18:09:01 -0600 |
commit | 7915fd768a34604f6edf6be63bdf77fb2663d556 (patch) | |
tree | 372241b979bda672dcc03c9f203a1928848bc553 /src | |
parent | 13fc3dcd7e95288cd9482e7440df3b15a3c580cb (diff) | |
parent | b49732c04db0d5bf67bf78e73e9c22f2078fd47c (diff) |
*Merge.
--HG--
branch : trunk
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/scripts/scripts/npc/npcs_special.cpp | 2 | ||||
-rw-r--r-- | src/game/Chat.cpp | 1 | ||||
-rw-r--r-- | src/game/Chat.h | 1 | ||||
-rw-r--r-- | src/game/Creature.cpp | 40 | ||||
-rw-r--r-- | src/game/Creature.h | 7 | ||||
-rw-r--r-- | src/game/CreatureAI.cpp | 6 | ||||
-rw-r--r-- | src/game/CreatureAI.h | 8 | ||||
-rw-r--r-- | src/game/GridNotifiersImpl.h | 6 | ||||
-rw-r--r-- | src/game/Level2.cpp | 2 | ||||
-rw-r--r-- | src/game/Level3.cpp | 8 | ||||
-rw-r--r-- | src/game/Map.h | 5 | ||||
-rw-r--r-- | src/game/MapManager.cpp | 14 | ||||
-rw-r--r-- | src/game/MiscHandler.cpp | 56 | ||||
-rw-r--r-- | src/game/Object.cpp | 2 | ||||
-rw-r--r-- | src/game/ObjectMgr.cpp | 164 | ||||
-rw-r--r-- | src/game/ObjectMgr.h | 22 | ||||
-rw-r--r-- | src/game/OutdoorPvP.cpp | 2 | ||||
-rw-r--r-- | src/game/Pet.cpp | 10 | ||||
-rw-r--r-- | src/game/PetAI.cpp | 3 | ||||
-rw-r--r-- | src/game/PetHandler.cpp | 7 | ||||
-rw-r--r-- | src/game/Player.cpp | 68 | ||||
-rw-r--r-- | src/game/Player.h | 15 | ||||
-rw-r--r-- | src/game/Spell.cpp | 10 | ||||
-rw-r--r-- | src/game/SpellEffects.cpp | 10 | ||||
-rw-r--r-- | src/game/TemporarySummon.cpp | 2 | ||||
-rw-r--r-- | src/game/Unit.cpp | 66 | ||||
-rw-r--r-- | src/game/Unit.h | 18 | ||||
-rw-r--r-- | src/game/World.cpp | 5 | ||||
-rw-r--r-- | src/shared/Database/SQLStorage.cpp | 4 |
29 files changed, 329 insertions, 235 deletions
diff --git a/src/bindings/scripts/scripts/npc/npcs_special.cpp b/src/bindings/scripts/scripts/npc/npcs_special.cpp index 07556ce46f4..be1986f3169 100644 --- a/src/bindings/scripts/scripts/npc/npcs_special.cpp +++ b/src/bindings/scripts/scripts/npc/npcs_special.cpp @@ -901,7 +901,7 @@ struct TRINITY_DLL_DECL npc_steam_tonkAI : public ScriptedAI if (apply) { // Initialize the action bar without the melee attack command - m_creature->InitCharmInfo(m_creature); + m_creature->InitCharmInfo(); m_creature->GetCharmInfo()->InitEmptyActionBar(false); m_creature->SetReactState(REACT_PASSIVE); diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index f30d4f76751..e894dc3e12f 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -271,6 +271,7 @@ ChatCommand * ChatHandler::getCommandTable() { "areatrigger_tavern", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAreaTriggerTavernCommand, "", NULL }, { "areatrigger_teleport", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAreaTriggerTeleportCommand, "", NULL }, + { "access_requirement", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAccessRequirementCommand, "", NULL }, { "areatrigger_involvedrelation",SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadQuestAreaTriggersCommand, "", NULL }, { "event_scripts", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadEventScriptsCommand, "", NULL }, { "command", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadCommandCommand, "", NULL }, diff --git a/src/game/Chat.h b/src/game/Chat.h index ebdd0c39726..21795671a35 100644 --- a/src/game/Chat.h +++ b/src/game/Chat.h @@ -225,6 +225,7 @@ class ChatHandler bool HandleReloadWpScriptsCommand(const char* args); bool HandleReloadAreaTriggerTavernCommand(const char* args); bool HandleReloadAreaTriggerTeleportCommand(const char* args); + bool HandleReloadAccessRequirementCommand(const char* args); bool HandleReloadEventScriptsCommand(const char* args); bool HandleReloadCommandCommand(const char* args); bool HandleReloadCreatureQuestRelationsCommand(const char* args); diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 09e29591e66..bfe8e752b94 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -126,7 +126,7 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) { assistant->SetNoCallAssistance(true); assistant->CombatStart(victim); - if(assistant->AI()) + if(assistant->IsAIEnabled) assistant->AI()->AttackStart(victim); } } @@ -135,7 +135,7 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) } Creature::Creature() : -Unit(), i_AI(NULL), i_AI_possessed(NULL), +Unit(), i_AI(NULL), lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0), m_lootMoney(0), m_lootRecipient(0), m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f), @@ -164,12 +164,6 @@ Creature::~Creature() delete i_AI; i_AI = NULL; - - if (i_AI_possessed) - { - delete i_AI_possessed; - i_AI_possessed = NULL; - } } void Creature::AddToWorld() @@ -486,7 +480,7 @@ void Creature::Update(uint32 diff) if(!isAlive()) break; - if(!IsInEvadeMode() && m_AI_enabled) + if(!IsInEvadeMode() && IsAIEnabled) { // do not allow the AI to be changed during update m_AI_locked = true; @@ -603,36 +597,10 @@ bool Creature::AIM_Initialize(CreatureAI* ai) i_AI = ai ? ai : FactorySelector::selectAI(this); if (oldAI) delete oldAI; - m_AI_enabled = true; + IsAIEnabled = true; return true; } -void Creature::InitPossessedAI() -{ - if (!isPossessed()) return; - - if (!i_AI_possessed) - i_AI_possessed = new PossessedAI(this); - - // Signal the old AI that it's been disabled - i_AI->OnPossess(true); - - if(!(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_CHARM_AI)) - m_AI_enabled = false; -} - -void Creature::DisablePossessedAI() -{ - if (!i_AI_possessed) return; - - delete i_AI_possessed; - - // Signal the old AI that it's been re-enabled - i_AI->OnPossess(false); - - m_AI_enabled = true; -} - bool Creature::Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, const CreatureData *data) { SetMapId(map->GetId()); diff --git a/src/game/Creature.h b/src/game/Creature.h index def2eebb2ae..8c448432cbe 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -132,7 +132,7 @@ enum CreatureFlagsExtra CREATURE_FLAG_EXTRA_NO_XP_AT_KILL = 0x00000040, // creature kill not provide XP CREATURE_FLAG_EXTRA_TRIGGER = 0x00000080, // trigger creature CREATURE_FLAG_EXTRA_WORLDEVENT = 0x00004000, // custom flag for world event creatures (left room for merging) - CREATURE_FLAG_EXTRA_CHARM_AI = 0x00008000, // use ai when charmed + //CREATURE_FLAG_EXTRA_CHARM_AI = 0x00008000, // use ai when charmed CREATURE_FLAG_EXTRA_NO_TAUNT = 0x00010000, // cannot be taunted }; @@ -417,7 +417,6 @@ typedef std::map<uint32,time_t> CreatureSpellCooldowns; class TRINITY_DLL_SPEC Creature : public Unit { CreatureAI *i_AI; - CreatureAI *i_AI_possessed; public: @@ -483,11 +482,9 @@ class TRINITY_DLL_SPEC Creature : public Unit bool IsInEvadeMode() const; bool AIM_Initialize(CreatureAI* ai = NULL); - void InitPossessedAI(); - void DisablePossessedAI(); void AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type); - CreatureAI* AI() { return isPossessed() && i_AI_possessed ? i_AI_possessed : i_AI; } + CreatureAI* AI() { return i_AI; } uint32 GetShieldBlockValue() const //dunno mob block value { diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 880522c20d2..06b2d382d8f 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -36,6 +36,12 @@ void UnitAI::AttackStart(Unit *victim) } } +//Enable PlayerAI when charmed +void PlayerAI::OnCharmed(bool apply) { me->IsAIEnabled = apply; } + +//Disable CreatureAI when charmed +void CreatureAI::OnCharmed(bool apply) { me->IsAIEnabled = !apply; } + void CreatureAI::MoveInLineOfSight(Unit *who) { if(!me->getVictim() && me->canStartAttack(who)) diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h index 6e291e2a604..78d856416ff 100644 --- a/src/game/CreatureAI.h +++ b/src/game/CreatureAI.h @@ -78,6 +78,9 @@ class TRINITY_DLL_SPEC UnitAI UnitAI(Unit *u) : me(u) {} virtual void AttackStart(Unit *); virtual void UpdateAI(const uint32 diff) = 0; + + // Called when unit is charmed + virtual void OnCharmed(bool apply) = 0; }; class TRINITY_DLL_SPEC PlayerAI : public UnitAI @@ -86,6 +89,8 @@ class TRINITY_DLL_SPEC PlayerAI : public UnitAI Player *me; public: PlayerAI(Player *p) : UnitAI((Unit*)p), me(p) {} + + void OnCharmed(bool apply); }; class TRINITY_DLL_SPEC SimpleCharmedAI : public PlayerAI @@ -140,8 +145,7 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI // Called at waypoint reached or point movement finished virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {} - // Called when AI is temporarily replaced or put back when possess is applied or removed - virtual void OnPossess(bool apply) {} + void OnCharmed(bool apply); // Called at reaching home after evade virtual void JustReachedHome() {} diff --git a/src/game/GridNotifiersImpl.h b/src/game/GridNotifiersImpl.h index 525402f0a1c..1704d26263c 100644 --- a/src/game/GridNotifiersImpl.h +++ b/src/game/GridNotifiersImpl.h @@ -74,7 +74,7 @@ inline void PlayerCreatureRelocationWorker(Player* pl, Creature* c) // Creature AI reaction if(c->HasReactState(REACT_AGGRESSIVE) && !c->hasUnitState(UNIT_STAT_SIGHTLESS)) { - if( c->AI() && c->IsWithinSightDist(pl) && !c->IsInEvadeMode() ) + if( c->IsAIEnabled && c->IsWithinSightDist(pl) && !c->IsInEvadeMode() ) c->AI()->MoveInLineOfSight(pl); } } @@ -83,13 +83,13 @@ inline void CreatureCreatureRelocationWorker(Creature* c1, Creature* c2) { if(c1->HasReactState(REACT_AGGRESSIVE) && !c1->hasUnitState(UNIT_STAT_SIGHTLESS)) { - if( c1->AI() && c1->IsWithinSightDist(c2) && !c1->IsInEvadeMode() ) + if( c1->IsAIEnabled && c1->IsWithinSightDist(c2) && !c1->IsInEvadeMode() ) c1->AI()->MoveInLineOfSight(c2); } if(c2->HasReactState(REACT_AGGRESSIVE) && !c2->hasUnitState(UNIT_STAT_SIGHTLESS)) { - if( c2->AI() && c1->IsWithinSightDist(c2) && !c2->IsInEvadeMode() ) + if( c2->IsAIEnabled && c1->IsWithinSightDist(c2) && !c2->IsInEvadeMode() ) c2->AI()->MoveInLineOfSight(c1); } } diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 40b9cec6a2a..93aca9307be 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -4119,7 +4119,7 @@ bool ChatHandler::HandleNpcTameCommand(const char* /*args*/) pet->Relocate (x,y,z,M_PI-player->GetOrientation ()); // set pet to defensive mode by default (some classes can't control controlled pets in fact). - pet->GetCharmInfo()->SetReactState(REACT_DEFENSIVE); + pet->SetReactState(REACT_DEFENSIVE); // calculate proper level uint32 level = (creatureTarget->getLevel() < (player->getLevel() - 5)) ? (player->getLevel() - 5) : creatureTarget->getLevel(); diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 781c9d1a0c6..ec487544d2f 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -666,6 +666,14 @@ bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*) return true; } +bool ChatHandler::HandleReloadAccessRequirementCommand(const char*) +{ + sLog.outString( "Re-Loading Access Requirement definitions..." ); + objmgr.LoadAccessRequirements(); + SendGlobalGMSysMessage("DB table `access_requirement` reloaded."); + return true; + } + bool ChatHandler::HandleReloadCommandCommand(const char*) { load_command_table = true; diff --git a/src/game/Map.h b/src/game/Map.h index 17d9953aa19..22f015ad588 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -97,12 +97,11 @@ struct CreatureMover struct InstanceTemplate { uint32 map; - uint32 parent; - uint32 levelMin; - uint32 levelMax; + uint32 parent; uint32 maxPlayers; uint32 maxPlayersHeroic; uint32 reset_delay; // FIX ME: now exist normal/heroic raids with possible different time of reset. + uint32 access_id; float startLocX; float startLocY; float startLocZ; diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index df8521be7d0..b2856b1fb1f 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -210,14 +210,12 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player) } } - // TODO: move this to a map dependent location - /*if(i_data && i_data->IsEncounterInProgress()) - { - sLog.outDebug("MAP: Player '%s' can't enter instance '%s' while an encounter is in progress.", player->GetName(), GetMapName()); - player->SendTransferAborted(GetId(), TRANSFER_ABORT_ZONE_IN_COMBAT); - return(false); - }*/ - return true; + // Requirements + InstanceTemplate const* instance = objmgr.GetInstanceTemplate(mapid); + if(!instance) + return false; + + return player->Satisfy(objmgr.GetAccessRequirement(instance->access_id), mapid, true); } else return true; diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp index 3a582f96f27..7f48f2c20b8 100644 --- a/src/game/MiscHandler.cpp +++ b/src/game/MiscHandler.cpp @@ -856,60 +856,8 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data) if(!at) return; - if(!GetPlayer()->isGameMaster()) - { - uint32 missingLevel = 0; - if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL)) - missingLevel = at->requiredLevel; - - // must have one or the other, report the first one that's missing - uint32 missingItem = 0; - if(at->requiredItem) - { - if(!GetPlayer()->HasItemCount(at->requiredItem, 1) && - (!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1))) - missingItem = at->requiredItem; - } - else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1)) - missingItem = at->requiredItem2; - - uint32 missingKey = 0; - uint32 missingHeroicQuest = 0; - if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC) - { - if(at->heroicKey) - { - if(!GetPlayer()->HasItemCount(at->heroicKey, 1) && - (!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1))) - missingKey = at->heroicKey; - } - else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1)) - missingKey = at->heroicKey2; - - if(at->heroicQuest && !GetPlayer()->GetQuestRewardStatus(at->heroicQuest)) - missingHeroicQuest = at->heroicQuest; - } - - uint32 missingQuest = 0; - if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest)) - missingQuest = at->requiredQuest; - - if(missingLevel || missingItem || missingKey || missingQuest || missingHeroicQuest) - { - // TODO: all this is probably wrong - if(missingItem) - SendAreaTriggerMessage(GetTrinityString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, objmgr.GetItemPrototype(missingItem)->Name1); - else if(missingKey) - GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY, DIFFICULTY_HEROIC); - else if(missingHeroicQuest) - SendAreaTriggerMessage(at->heroicQuestFailedText.c_str()); - else if(missingQuest) - SendAreaTriggerMessage(at->requiredFailedText.c_str()); - else if(missingLevel) - SendAreaTriggerMessage(GetTrinityString(LANG_LEVEL_MINREQUIRED), missingLevel); - return; - } - } + if(!GetPlayer()->Satisfy(objmgr.GetAccessRequirement(at->access_id), at->target_mapId, true)) + return; GetPlayer()->TeleportTo(at->target_mapId,at->target_X,at->target_Y,at->target_Z,at->target_Orientation,TELE_TO_NOT_LEAVE_TRANSPORT); } diff --git a/src/game/Object.cpp b/src/game/Object.cpp index ab79ca366e4..62f9c606b6b 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1603,7 +1603,7 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa pCreature->SetHomePosition(x, y, z, ang); pCreature->Summon(spwtype, despwtime); - if(GetTypeId()==TYPEID_UNIT && ((Creature*)this)->AI()) + if(GetTypeId()==TYPEID_UNIT && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->JustSummoned(pCreature); if(pCreature->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER && pCreature->m_spells[0]) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 5f7c9ae5b8b..b3fb36cfeea 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -5009,8 +5009,8 @@ void ObjectMgr::LoadAreaTriggerTeleports() uint32 count = 0; - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 - QueryResult *result = WorldDatabase.Query("SELECT id, required_level, required_item, required_item2, heroic_key, heroic_key2, heroic_required_quest_done, heroic_required_failed_quest_text, required_quest_done, required_failed_text, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM areatrigger_teleport"); + // 0 1 2 3 4 5 6 + QueryResult *result = WorldDatabase.Query("SELECT id, access_id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM areatrigger_teleport"); if( !result ) { @@ -5037,20 +5037,12 @@ void ObjectMgr::LoadAreaTriggerTeleports() AreaTrigger at; - at.requiredLevel = fields[1].GetUInt8(); - at.requiredItem = fields[2].GetUInt32(); - at.requiredItem2 = fields[3].GetUInt32(); - at.heroicKey = fields[4].GetUInt32(); - at.heroicKey2 = fields[5].GetUInt32(); - at.heroicQuest = fields[6].GetUInt32(); - at.heroicQuestFailedText = fields[7].GetCppString(); - at.requiredQuest = fields[8].GetUInt32(); - at.requiredFailedText = fields[9].GetCppString(); - at.target_mapId = fields[10].GetUInt32(); - at.target_X = fields[11].GetFloat(); - at.target_Y = fields[12].GetFloat(); - at.target_Z = fields[13].GetFloat(); - at.target_Orientation = fields[14].GetFloat(); + at.access_id = fields[1].GetUInt32(); + at.target_mapId = fields[2].GetUInt32(); + at.target_X = fields[3].GetFloat(); + at.target_Y = fields[4].GetFloat(); + at.target_Z = fields[5].GetFloat(); + at.target_Orientation = fields[6].GetFloat(); AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); if(!atEntry) @@ -5058,85 +5050,141 @@ void ObjectMgr::LoadAreaTriggerTeleports() sLog.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID); continue; } + + MapEntry const* mapEntry = sMapStore.LookupEntry(at.target_mapId); + if(!mapEntry) + { + sLog.outErrorDb("Area trigger (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Trigger_ID,at.target_mapId); + continue; + } - if(at.requiredItem) + if(at.target_X==0 && at.target_Y==0 && at.target_Z==0) { - ItemPrototype const *pProto = GetItemPrototype(at.requiredItem); - if(!pProto) - { - sLog.outError("Key item %u does not exist for trigger %u, removing key requirement.", at.requiredItem, Trigger_ID); - at.requiredItem = 0; - } + sLog.outErrorDb("Area trigger (ID:%u) target coordinates not provided.",Trigger_ID); + continue; } - if(at.requiredItem2) + + mAreaTriggers[Trigger_ID] = at; + + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u area trigger teleport definitions", count ); +} + +void ObjectMgr::LoadAccessRequirements() +{ + mAccessRequirements.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 3 4 5 6 7 8 9 10 + QueryResult *result = WorldDatabase.Query("SELECT id, level_min, level_max, item, item2, heroic_key, heroic_key2, quest_done, quest_failed_text, heroic_quest_done, heroic_quest_failed_text FROM access_requirement"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u access requirement definitions", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + ++count; + + uint32 requiremt_ID = fields[0].GetUInt32(); + + AccessRequirement ar; + + ar.levelMin = fields[1].GetUInt8(); + ar.levelMax = fields[2].GetUInt32(); + ar.item = fields[3].GetUInt32(); + ar.item2 = fields[4].GetUInt32(); + ar.heroicKey = fields[5].GetUInt32(); + ar.heroicKey2 = fields[6].GetUInt32(); + ar.quest = fields[7].GetUInt32(); + ar.questFailedText = fields[8].GetCppString(); + ar.heroicQuest = fields[9].GetUInt32(); + ar.heroicQuestFailedText = fields[10].GetCppString(); + + if(ar.item) { - ItemPrototype const *pProto = GetItemPrototype(at.requiredItem2); + ItemPrototype const *pProto = GetItemPrototype(ar.item); if(!pProto) { - sLog.outError("Second item %u not exist for trigger %u, remove key requirement.", at.requiredItem2, Trigger_ID); - at.requiredItem2 = 0; + sLog.outError("Key item %u does not exist for requirement %u, removing key requirement.", ar.item, requiremt_ID); + ar.item = 0; } } - if(at.heroicKey) + if(ar.item2) { - ItemPrototype const *pProto = GetItemPrototype(at.heroicKey); + ItemPrototype const *pProto = GetItemPrototype(ar.item2); if(!pProto) { - sLog.outError("Heroic key item %u not exist for trigger %u, remove key requirement.", at.heroicKey, Trigger_ID); - at.heroicKey = 0; + sLog.outError("Second item %u does not exist for requirement %u, removing key requirement.", ar.item2, requiremt_ID); + ar.item2 = 0; } } - if(at.heroicKey2) + if(ar.heroicKey) { - ItemPrototype const *pProto = GetItemPrototype(at.heroicKey2); + ItemPrototype const *pProto = GetItemPrototype(ar.heroicKey); if(!pProto) { - sLog.outError("Heroic second key item %u not exist for trigger %u, remove key requirement.", at.heroicKey2, Trigger_ID); - at.heroicKey2 = 0; + sLog.outError("Heroic key %u not exist for trigger %u, remove key requirement.", ar.heroicKey, requiremt_ID); + ar.heroicKey = 0; } } - if(at.heroicQuest) + if(ar.heroicKey2) { - if(!mQuestTemplates[at.heroicQuest]) + ItemPrototype const *pProto = GetItemPrototype(ar.heroicKey2); + if(!pProto) { - sLog.outErrorDb("Required Heroic Quest %u not exist for trigger %u, remove heroic quest done requirement.",at.heroicQuest,Trigger_ID); - at.heroicQuest = 0; + sLog.outError("Second heroic key %u not exist for trigger %u, remove key requirement.", ar.heroicKey2, requiremt_ID); + ar.heroicKey2 = 0; } } - if(at.requiredQuest) + if(ar.heroicQuest) + { + if(!mQuestTemplates[ar.heroicQuest]) + { + sLog.outErrorDb("Required Heroic Quest %u not exist for trigger %u, remove heroic quest done requirement.",ar.heroicQuest,requiremt_ID); + ar.heroicQuest = 0; + } + } + + if(ar.quest) { - if(!mQuestTemplates[at.requiredQuest]) + if(!mQuestTemplates[ar.quest]) { - sLog.outErrorDb("Required Quest %u not exist for trigger %u, remove quest done requirement.",at.requiredQuest,Trigger_ID); - at.requiredQuest = 0; + sLog.outErrorDb("Required Quest %u not exist for trigger %u, remove quest done requirement.",ar.quest,requiremt_ID); + ar.quest = 0; } } - MapEntry const* mapEntry = sMapStore.LookupEntry(at.target_mapId); - if(!mapEntry) - { - sLog.outErrorDb("Area trigger (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Trigger_ID,at.target_mapId); - continue; - } - - if(at.target_X==0 && at.target_Y==0 && at.target_Z==0) - { - sLog.outErrorDb("Area trigger (ID:%u) target coordinates not provided.",Trigger_ID); - continue; - } - - mAreaTriggers[Trigger_ID] = at; + mAccessRequirements[requiremt_ID] = ar; } while( result->NextRow() ); delete result; sLog.outString(); - sLog.outString( ">> Loaded %u area trigger teleport definitions", count ); + sLog.outString( ">> Loaded %u access requirement definitions", count ); } /* diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 3946f912b96..b33e2ac26e4 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -101,15 +101,7 @@ extern ScriptMapMap sWaypointScripts; struct AreaTrigger { - uint8 requiredLevel; - uint32 requiredItem; - uint32 requiredItem2; - uint32 heroicKey; - uint32 heroicKey2; - uint32 heroicQuest; - std::string heroicQuestFailedText; - uint32 requiredQuest; - std::string requiredFailedText; + uint32 access_id; uint32 target_mapId; float target_X; float target_Y; @@ -327,6 +319,8 @@ class ObjectMgr typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap; + typedef UNORDERED_MAP<uint32, AccessRequirement> AccessRequirementMap; + typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap; typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap; @@ -466,6 +460,14 @@ class ObjectMgr return NULL; } + AccessRequirement const* GetAccessRequirement(uint32 requirement) const + { + AccessRequirementMap::const_iterator itr = mAccessRequirements.find( requirement ); + if( itr != mAccessRequirements.end( ) ) + return &itr->second; + return NULL; + } + AreaTrigger const* GetGoBackTrigger(uint32 Map) const; AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const; @@ -551,6 +553,7 @@ class ObjectMgr void LoadGossipText(); void LoadAreaTriggerTeleports(); + void LoadAccessRequirements(); void LoadQuestAreaTriggers(); void LoadAreaTriggerScripts(); void LoadTavernAreaTriggers(); @@ -840,6 +843,7 @@ class ObjectMgr GossipTextMap mGossipText; AreaTriggerMap mAreaTriggers; AreaTriggerScriptMap mAreaTriggerScripts; + AccessRequirementMap mAccessRequirements; RepOnKillMap mRepOnKill; diff --git a/src/game/OutdoorPvP.cpp b/src/game/OutdoorPvP.cpp index b48a226d6a4..8aa117b5c4a 100644 --- a/src/game/OutdoorPvP.cpp +++ b/src/game/OutdoorPvP.cpp @@ -56,7 +56,7 @@ void OutdoorPvPObjective::HandlePlayerActivityChanged(Player * plr) { if(m_CapturePointCreature) if(Creature * c = HashMapHolder<Creature>::Find(m_CapturePointCreature)) - if(c->AI()) + if(c->IsAIEnabled) c->AI()->MoveInLineOfSight(plr); } diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 77851ed6cbc..d722809f4c1 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -51,12 +51,12 @@ m_declinedname(NULL) m_regenTimer = 4000; // pets always have a charminfo, even if they are not actually charmed - CharmInfo* charmInfo = InitCharmInfo(this); + CharmInfo* charmInfo = InitCharmInfo(); if(type == MINI_PET || type == POSSESSED_PET) // always passive - charmInfo->SetReactState(REACT_PASSIVE); + SetReactState(REACT_PASSIVE); else if(type == GUARDIAN_PET) // always aggressive - charmInfo->SetReactState(REACT_AGGRESSIVE); + SetReactState(REACT_AGGRESSIVE); //m_isActive = true; } @@ -213,7 +213,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32()); SetCreatorGUID(owner->GetGUID()); - m_charmInfo->SetReactState(ReactStates(fields[6].GetUInt8())); + SetReactState( ReactStates( fields[6].GetUInt8() )); uint32 savedhealth = fields[11].GetUInt32(); uint32 savedmana = fields[12].GetUInt32(); @@ -404,7 +404,7 @@ void Pet::SavePetToDB(PetSaveMode mode) << GetNativeDisplayId() << ", " << getLevel() << ", " << GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ", " - << uint32(m_charmInfo->GetReactState()) << ", " + << uint32(GetReactState()) << ", " << uint32(GetFreeTalentPoints()) << ", " << uint32(mode) << ", '" << name.c_str() << "', " diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp index 29450b549e1..6f43d511dd0 100644 --- a/src/game/PetAI.cpp +++ b/src/game/PetAI.cpp @@ -47,7 +47,6 @@ PetAI::PetAI(Creature *c) : CreatureAI(c), i_pet(*c), i_tracker(TIME_INTERVAL_LO void PetAI::MoveInLineOfSight(Unit *u) { if( !i_pet.getVictim() && i_pet.GetCharmInfo() && - i_pet.GetCharmInfo()->HasReactState(REACT_AGGRESSIVE) && i_pet.IsHostileTo( u ) && i_pet.canAttack(u) && u->isInAccessiblePlaceFor(&i_pet)) { @@ -181,7 +180,7 @@ void PetAI::UpdateAI(const uint32 diff) } else if(owner && i_pet.GetCharmInfo()) { - if(owner->isInCombat() && !(i_pet.GetCharmInfo()->HasReactState(REACT_PASSIVE) || i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY))) + if(owner->isInCombat() && !(i_pet.HasReactState(REACT_PASSIVE) || i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY))) { AttackStart(owner->getAttackerForHelper()); } diff --git a/src/game/PetHandler.cpp b/src/game/PetHandler.cpp index 17c2ba4275b..45fcbbb3219 100644 --- a/src/game/PetHandler.cpp +++ b/src/game/PetHandler.cpp @@ -127,7 +127,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data ) if(pet->GetTypeId() != TYPEID_PLAYER) { pet->GetMotionMaster()->Clear(); - if (((Creature*)pet)->AI()) + if (((Creature*)pet)->IsAIEnabled) ((Creature*)pet)->AI()->AttackStart(TargetUnit); //10% chance to play special pet attack talk, else growl @@ -173,7 +173,8 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data ) case REACT_PASSIVE: //passive case REACT_DEFENSIVE: //recovery case REACT_AGGRESSIVE: //activete - charmInfo->SetReactState( ReactStates(spellid) ); + if(pet->GetTypeId() == TYPEID_UNIT) + ((Creature*)pet)->SetReactState( ReactStates(spellid) ); break; } break; @@ -249,7 +250,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data ) if (pet->getVictim()) pet->AttackStop(); pet->GetMotionMaster()->Clear(); - if (((Creature*)pet)->AI()) + if (((Creature*)pet)->IsAIEnabled) ((Creature*)pet)->AI()->AttackStart(unit_target); } } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index cf1e79e687b..4fdca264993 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -16008,6 +16008,70 @@ void Player::ConvertInstancesToGroup(Player *player, Group *group, uint64 player if(!player || has_solo) CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND permanent = 0", GUID_LOPART(player_guid)); } +bool Player::Satisfy(AccessRequirement const *ar, uint32 target_map, bool report) +{ + if(!isGameMaster() && ar) + { + uint32 LevelMin = 0; + if(getLevel() < ar->levelMin && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL)) + LevelMin = ar->levelMin; + + uint32 LevelMax = 0; + if(ar->levelMax >= ar->levelMin && getLevel() > ar->levelMax && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL)) + LevelMax = ar->levelMax; + + uint32 missingItem = 0; + if(ar->item) + { + if(!HasItemCount(ar->item, 1) && + (!ar->item2 || !HasItemCount(ar->item2, 1))) + missingItem = ar->item; + } + else if(ar->item2 && !HasItemCount(ar->item2, 1)) + missingItem = ar->item2; + + uint32 missingKey = 0; + uint32 missingHeroicQuest = 0; + if(GetDifficulty() == DIFFICULTY_HEROIC) + { + if(ar->heroicKey) + { + if(!HasItemCount(ar->heroicKey, 1) && + (!ar->heroicKey2 || !HasItemCount(ar->heroicKey2, 1))) + missingKey = ar->heroicKey; + } + else if(ar->heroicKey2 && !HasItemCount(ar->heroicKey2, 1)) + missingKey = ar->heroicKey2; + + if(ar->heroicQuest && !GetQuestRewardStatus(ar->heroicQuest)) + missingHeroicQuest = ar->heroicQuest; + } + + uint32 missingQuest = 0; + if(ar->quest && !GetQuestRewardStatus(ar->quest)) + missingQuest = ar->quest; + + if(LevelMin || LevelMax || missingItem || missingKey || missingQuest || missingHeroicQuest) + { + if(report) + { + if(missingItem) + GetSession()->SendAreaTriggerMessage(GetSession()->GetTrinityString(LANG_LEVEL_MINREQUIRED_AND_ITEM), ar->levelMin, objmgr.GetItemPrototype(missingItem)->Name1); + else if(missingKey) + SendTransferAborted(target_map, TRANSFER_ABORT_DIFFICULTY); + else if(missingHeroicQuest) + GetSession()->SendAreaTriggerMessage(ar->heroicQuestFailedText.c_str()); + else if(missingQuest) + GetSession()->SendAreaTriggerMessage(ar->questFailedText.c_str()); + else if(LevelMin) + GetSession()->SendAreaTriggerMessage(GetSession()->GetTrinityString(LANG_LEVEL_MINREQUIRED), LevelMin); + } + return false; + } + } + return true; +} + bool Player::_LoadHomeBind(QueryResult *result) { PlayerInfo const *info = objmgr.GetPlayerInfo(getRace(), getClass()); @@ -17163,7 +17227,7 @@ void Player::PetSpellInitialize() data << uint64(pet->GetGUID()); data << uint32(pet->GetCreatureInfo()->family); // creature family (required for pet talents) data << uint32(0); - data << uint8(charmInfo->GetReactState()) << uint8(charmInfo->GetCommandState()) << uint16(0); + data << uint8(pet->GetReactState()) << uint8(charmInfo->GetCommandState()) << uint16(0); // action bar loop for(uint32 i = 0; i < 10; i++) @@ -17300,7 +17364,7 @@ void Player::CharmSpellInitialize() data << uint32(0x00000000); data << uint32(0); if(charm->GetTypeId() != TYPEID_PLAYER) - data << uint8(charmInfo->GetReactState()) << uint8(charmInfo->GetCommandState()); + data << uint8(((Creature*)charm)->GetReactState()) << uint8(charmInfo->GetCommandState()); else data << uint8(0) << uint8(0); data << uint16(0); diff --git a/src/game/Player.h b/src/game/Player.h index f128dd4d422..c16ddc5abb3 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -864,6 +864,20 @@ struct InstancePlayerBind InstancePlayerBind() : save(NULL), perm(false) {} }; +struct AccessRequirement +{ + uint8 levelMin; + uint8 levelMax; + uint32 item; + uint32 item2; + uint32 heroicKey; + uint32 heroicKey2; + uint32 quest; + std::string questFailedText; + uint32 heroicQuest; + std::string heroicQuestFailedText; + }; + class TRINITY_DLL_SPEC PlayerTaxi { public: @@ -2127,6 +2141,7 @@ class TRINITY_DLL_SPEC Player : public Unit void SendRaidInfo(); void SendSavedInstances(); static void ConvertInstancesToGroup(Player *player, Group *group = NULL, uint64 player_guid = 0); + bool Satisfy(AccessRequirement const*, uint32 target_map, bool report = false); /*********************************************************/ /*** GROUP SYSTEM ***/ diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 66f2eded6ac..6d34d29b644 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -1164,10 +1164,10 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask) } } - if(unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->AI()) + if(unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->IsAIEnabled) ((Creature*)unit)->AI()->SpellHit(m_caster, m_spellInfo); - if(m_caster->GetTypeId() == TYPEID_UNIT && ((Creature*)m_caster)->AI()) + if(m_caster->GetTypeId() == TYPEID_UNIT && ((Creature*)m_caster)->IsAIEnabled) ((Creature*)m_caster)->AI()->SpellHitTarget(unit, m_spellInfo); for(ChanceTriggerSpells::const_iterator i = m_ChanceTriggerSpells.begin(); i != m_ChanceTriggerSpells.end(); ++i) @@ -4251,10 +4251,8 @@ uint8 Spell::CanCast(bool strict) InstanceTemplate const* instance = ObjectMgr::GetInstanceTemplate(m_caster->GetMapId()); if(!instance) return SPELL_FAILED_TARGET_NOT_IN_INSTANCE; - if ( instance->levelMin > target->getLevel() ) - return SPELL_FAILED_LOWLEVEL; - if ( instance->levelMax && instance->levelMax < target->getLevel() ) - return SPELL_FAILED_HIGHLEVEL; + if(!target->Satisfy(objmgr.GetAccessRequirement(instance->access_id), m_caster->GetMapId())) + return SPELL_FAILED_BAD_TARGETS; } break; } diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 01bf60ccde1..dcd5b9bf08d 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -1177,7 +1177,7 @@ void Spell::EffectDummy(uint32 i) pCreature->SetHealth(health); ((Player*)m_caster)->KilledMonster(16992,pCreature->GetGUID()); - if (pCreature->AI()) + if (pCreature->IsAIEnabled) pCreature->AI()->AttackStart(m_caster); return; @@ -3402,7 +3402,7 @@ void Spell::EffectSummon(uint32 i) name.append(petTypeSuffix[spawnCreature->getPetType()]); spawnCreature->SetName( name ); - spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE ); + spawnCreature->SetReactState( REACT_DEFENSIVE ); } void Spell::EffectLearnSpell(uint32 i) @@ -3617,7 +3617,7 @@ void Spell::EffectPickPocket(uint32 /*i*/) { // Reveal action + get attack m_caster->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TALK); - if (((Creature*)unitTarget)->AI()) + if (((Creature*)unitTarget)->IsAIEnabled) ((Creature*)unitTarget)->AI()->AttackStart(m_caster); } } @@ -4230,9 +4230,9 @@ void Spell::EffectSummonPet(uint32 i) if(m_caster->GetTypeId() == TYPEID_UNIT) { if ( ((Creature*)m_caster)->isTotem() ) - pet->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE); + pet->SetReactState(REACT_AGGRESSIVE); else - pet->GetCharmInfo()->SetReactState(REACT_DEFENSIVE); + pet->SetReactState(REACT_DEFENSIVE); } pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id); diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp index 147133bd362..f8daff972d8 100644 --- a/src/game/TemporarySummon.cpp +++ b/src/game/TemporarySummon.cpp @@ -176,7 +176,7 @@ void TemporarySummon::UnSummon() AddObjectToRemoveList(); Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL; - if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->AI()) + if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->IsAIEnabled) { ((Creature*)sum)->AI()->SummonedCreatureDespawn(this); } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index da76612bec7..9610657b233 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -75,7 +75,7 @@ static bool procPrepared = InitTriggerAuraData(); Unit::Unit() : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) -, m_IsInNotifyList(false), m_Notified(false), m_AI_enabled(false) +, m_IsInNotifyList(false), m_Notified(false), IsAIEnabled(false) { m_objectType |= TYPEMASK_UNIT; m_objectTypeId = TYPEID_UNIT; @@ -593,7 +593,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa } //Script Event damage taken - if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() ) + if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->IsAIEnabled ) { ((Creature *)pVictim)->AI()->DamageTaken(this, damage); @@ -906,7 +906,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa if(!getVictim()) /*{ // if have target and damage pVictim just call AI reaction - if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI()) + if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsAIEnabled) ((Creature*)pVictim)->AI()->AttackedBy(this); } else*/ @@ -7622,7 +7622,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack) m_attacking = victim; m_attacking->_addAttacker(this); - //if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->AI()) + //if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->IsAIEnabled) // ((Creature*)m_attacking)->AI()->AttackedBy(this); if(GetTypeId()==TYPEID_UNIT) @@ -9449,7 +9449,7 @@ void Unit::CombatStart(Unit* target) target->SetStandState(UNIT_STAND_STATE_STAND); if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER - && !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->AI()) + && !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->IsAIEnabled) ((Creature*)target)->AI()->AttackStart(this); SetInCombatWith(target); @@ -10086,7 +10086,7 @@ void Unit::TauntApply(Unit* taunter) return; SetInFront(taunter); - if (((Creature*)this)->AI()) + if (((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->AttackStart(taunter); m_ThreatManager.tauntApply(taunter); @@ -10110,7 +10110,7 @@ void Unit::TauntFadeOut(Unit *taunter) if(m_ThreatManager.isThreatListEmpty()) { - if(((Creature*)this)->AI()) + if(((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->EnterEvadeMode(); return; } @@ -10121,7 +10121,7 @@ void Unit::TauntFadeOut(Unit *taunter) if (target && target != taunter) { SetInFront(target); - if (((Creature*)this)->AI()) + if (((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->AttackStart(target); } } @@ -10965,21 +10965,43 @@ void Unit::CleanupsBeforeDelete() RemoveFromWorld(); } -CharmInfo* Unit::InitCharmInfo(Unit *charm) +CharmInfo* Unit::InitCharmInfo() { if(!m_charmInfo) - m_charmInfo = new CharmInfo(charm); + m_charmInfo = new CharmInfo(this); return m_charmInfo; } +void Unit::DeleteCharmInfo() +{ + if(!m_charmInfo) + return; + + delete m_charmInfo; + m_charmInfo = NULL; +} + CharmInfo::CharmInfo(Unit* unit) -: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0), m_barInit(false) +: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_petnumber(0), m_barInit(false) { for(int i =0; i<4; ++i) { m_charmspells[i].spellId = 0; m_charmspells[i].active = ACT_DISABLED; } + if(m_unit->GetTypeId() == TYPEID_UNIT) + { + m_oldReactState = ((Creature*)m_unit)->GetReactState(); + ((Creature*)m_unit)->SetReactState(REACT_PASSIVE); + } +} + +CharmInfo::~CharmInfo() +{ + if(m_unit->GetTypeId() == TYPEID_UNIT) + { + ((Creature*)m_unit)->SetReactState(m_oldReactState); + } } void CharmInfo::InitPetActionBar() @@ -11643,7 +11665,7 @@ void Unit::SetFeared(bool apply, uint64 casterGUID, uint32 spellID) // attack caster if can Unit* caster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL); - if(caster && caster != getVictim() && ((Creature*)this)->AI()) + if(caster && caster != getVictim() && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->AttackStart(caster); } } @@ -12405,7 +12427,7 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) ((Player*)pVictim)->GetSession()->SendPacket(&data); } // Call KilledUnit for creatures - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->KilledUnit(pVictim); // last damage from non duel opponent or opponent controlled creature @@ -12428,11 +12450,11 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) } // Call KilledUnit for creatures, this needs to be called after the lootable flag is set - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->KilledUnit(pVictim); // Call creature just died function - if (cVictim->AI()) + if (cVictim->IsAIEnabled) cVictim->AI()->JustDied(this); // Dungeon specific stuff, only applies to players killing creatures @@ -12705,7 +12727,7 @@ void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess) if(GetTypeId() == TYPEID_UNIT) { - ((Creature*)this)->InitPossessedAI(); + ((Creature*)this)->AI()->OnCharmed(true); StopMoving(); GetMotionMaster()->Clear(false); GetMotionMaster()->MoveIdle(); @@ -12720,8 +12742,7 @@ void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess) // Pets already have a properly initialized CharmInfo, don't overwrite it. if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet()) { - CharmInfo *charmInfo = InitCharmInfo(this); - charmInfo->SetReactState(REACT_DEFENSIVE); + CharmInfo *charmInfo = InitCharmInfo(); if(possess) charmInfo->InitPossessCreateSpells(); else @@ -12792,8 +12813,8 @@ void Unit::RemoveCharmedOrPossessedBy(Unit *charmer) if(!((Creature*)this)->isPet()) RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - ((Creature*)this)->DisablePossessedAI(); - if(isAlive() && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->OnCharmed(false); + if(isAlive() && ((Creature*)this)->IsAIEnabled) { if(charmer && !IsFriendlyTo(charmer)) { @@ -12840,6 +12861,11 @@ void Unit::RemoveCharmedOrPossessedBy(Unit *charmer) } } + if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet()) + { + DeleteCharmInfo(); + } + if(possess || charmer->GetTypeId() == TYPEID_PLAYER) { // Remove pet spell action bar diff --git a/src/game/Unit.h b/src/game/Unit.h index 8d08f793eac..fa5faa4452a 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -778,15 +778,16 @@ struct TRINITY_DLL_SPEC CharmInfo { public: explicit CharmInfo(Unit* unit); + ~CharmInfo(); uint32 GetPetNumber() const { return m_petnumber; } void SetPetNumber(uint32 petnumber, bool statwindow); void SetCommandState(CommandStates st) { m_CommandState = st; } CommandStates GetCommandState() { return m_CommandState; } bool HasCommandState(CommandStates state) { return (m_CommandState == state); } - void SetReactState(ReactStates st) { m_reactState = st; } - ReactStates GetReactState() { return m_reactState; } - bool HasReactState(ReactStates state) { return (m_reactState == state); } + //void SetReactState(ReactStates st) { m_reactState = st; } + //ReactStates GetReactState() { return m_reactState; } + //bool HasReactState(ReactStates state) { return (m_reactState == state); } void InitPossessCreateSpells(); void InitCharmCreateSpells(); @@ -803,9 +804,12 @@ struct TRINITY_DLL_SPEC CharmInfo UnitActionBarEntry PetActionBar[10]; CharmSpellEntry m_charmspells[4]; CommandStates m_CommandState; - ReactStates m_reactState; + //ReactStates m_reactState; uint32 m_petnumber; bool m_barInit; + + //for restoration after charmed + ReactStates m_oldReactState; }; // for clearing special attacks @@ -1208,7 +1212,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject bool isPossessing(Unit* u) const { return u->isPossessed() && GetCharmGUID() == u->GetGUID(); } CharmInfo* GetCharmInfo() { return m_charmInfo; } - CharmInfo* InitCharmInfo(Unit* charm); + CharmInfo* InitCharmInfo(); + void DeleteCharmInfo(); SharedVisionList const& GetSharedVisionList() { return m_sharedVision; } void AddPlayerToVision(Player* plr); void RemovePlayerFromVision(Player* plr); @@ -1539,6 +1544,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject } uint32 GetReducedThreatPercent() { return m_reducedThreatPercent; } Unit *GetMisdirectionTarget() { return m_misdirectionTargetGUID ? GetUnit(*this, m_misdirectionTargetGUID) : NULL; } + + bool IsAIEnabled; protected: explicit Unit (); @@ -1594,7 +1601,6 @@ class TRINITY_DLL_SPEC Unit : public WorldObject ThreatManager m_ThreatManager; - bool m_AI_enabled; private: void SendAttackStop(Unit* victim); // only from AttackStop(Unit*) //void SendAttackStart(Unit* pVictim); // only from Unit::AttackStart(Unit*) diff --git a/src/game/World.cpp b/src/game/World.cpp index 9312667cefc..c7a9ccf23eb 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1270,7 +1270,10 @@ void World::SetInitialWorldSettings() spellmgr.LoadSpellAreas(); sLog.outString( "Loading AreaTrigger definitions..." ); - objmgr.LoadAreaTriggerTeleports(); // must be after item template load + objmgr.LoadAreaTriggerTeleports(); + + sLog.outString( "Loading Access Requirements..." ); + objmgr.LoadAccessRequirements(); // must be after item template load sLog.outString( "Loading Quest Area Triggers..." ); objmgr.LoadQuestAreaTriggers(); // must be after LoadQuests diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index 8ffc42dccd3..83649e77641 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -39,8 +39,8 @@ const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiii"; const char PageTextfmt[]="isi"; const char SpellThreatfmt[]="ii"; -const char InstanceTemplatesrcfmt[]="iiiiiiiffffs"; -const char InstanceTemplatedstfmt[]="iiiiiiiffffi"; +const char InstanceTemplatesrcfmt[]="iiiiiiffffs"; +const char InstanceTemplatedstfmt[]="iiiiiiffffi"; SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template"); SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon"); |