diff options
author | Kargatum <dowlandtop@yandex.com> | 2020-10-12 15:08:15 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 10:08:15 +0200 |
commit | a2b26272d28f137473c4e14841da0f042e3e8bdc (patch) | |
tree | 43a44857f92affd0ffd220a2fc09951e6ddd3f92 /src/server/game/Scripting/MapScripts.cpp | |
parent | e99b526e17ce628e919347dff4c150cd6645d01b (diff) |
refactor(Core/Game): restyle game lib with astyle (#3466)
Diffstat (limited to 'src/server/game/Scripting/MapScripts.cpp')
-rw-r--r-- | src/server/game/Scripting/MapScripts.cpp | 431 |
1 files changed, 217 insertions, 214 deletions
diff --git a/src/server/game/Scripting/MapScripts.cpp b/src/server/game/Scripting/MapScripts.cpp index 25369c7a78..dcc0ede48f 100644 --- a/src/server/game/Scripting/MapScripts.cpp +++ b/src/server/game/Scripting/MapScripts.cpp @@ -21,7 +21,7 @@ /// Put scripts in the execution queue void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, Object* target) -{ +{ ///- Find the script map ScriptMapMap::const_iterator s = scripts.find(id); if (s == scripts.end()) @@ -59,7 +59,7 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O } void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target) -{ +{ // NOTE: script record _must_ exist until command executed // prepare static data @@ -88,7 +88,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou // Helpers for ScriptProcess method. inline Player* Map::_GetScriptPlayerSourceOrTarget(Object* source, Object* target, const ScriptInfo* scriptInfo) const -{ +{ Player* player = nullptr; if (!source && !target) sLog->outError("%s source and target objects are NULL.", scriptInfo->GetDebugInfo().c_str()); @@ -102,15 +102,15 @@ inline Player* Map::_GetScriptPlayerSourceOrTarget(Object* source, Object* targe if (!player) sLog->outError("%s neither source nor target object is player (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.", - scriptInfo->GetDebugInfo().c_str(), - source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0, - target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0); + scriptInfo->GetDebugInfo().c_str(), + source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0, + target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0); } return player; } inline Creature* Map::_GetScriptCreatureSourceOrTarget(Object* source, Object* target, const ScriptInfo* scriptInfo, bool bReverse) const -{ +{ Creature* creature = nullptr; if (!source && !target) sLog->outError("%s source and target objects are NULL.", scriptInfo->GetDebugInfo().c_str()); @@ -135,33 +135,33 @@ inline Creature* Map::_GetScriptCreatureSourceOrTarget(Object* source, Object* t if (!creature) sLog->outError("%s neither source nor target are creatures (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.", - scriptInfo->GetDebugInfo().c_str(), - source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0, - target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0); + scriptInfo->GetDebugInfo().c_str(), + source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0, + target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0); } return creature; } inline Unit* Map::_GetScriptUnit(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const -{ +{ Unit* unit = nullptr; if (!obj) sLog->outError("%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target"); else if (!obj->isType(TYPEMASK_UNIT)) sLog->outError("%s %s object is not unit (TypeId: %u, Entry: %u, GUID: %u), skipping.", - scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); + scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); else { unit = obj->ToUnit(); if (!unit) sLog->outError("%s %s object could not be casted to unit.", - scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target"); + scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target"); } return unit; } inline Player* Map::_GetScriptPlayer(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const -{ +{ Player* player = nullptr; if (!obj) sLog->outError("%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target"); @@ -170,13 +170,13 @@ inline Player* Map::_GetScriptPlayer(Object* obj, bool isSource, const ScriptInf player = obj->ToPlayer(); if (!player) sLog->outError("%s %s object is not a player (TypeId: %u, Entry: %u, GUID: %u).", - scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); + scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); } return player; } inline Creature* Map::_GetScriptCreature(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const -{ +{ Creature* creature = nullptr; if (!obj) sLog->outError("%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target"); @@ -185,36 +185,39 @@ inline Creature* Map::_GetScriptCreature(Object* obj, bool isSource, const Scrip creature = obj->ToCreature(); if (!creature) sLog->outError("%s %s object is not a creature (TypeId: %u, Entry: %u, GUID: %u).", scriptInfo->GetDebugInfo().c_str(), - isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); + isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); } return creature; } inline WorldObject* Map::_GetScriptWorldObject(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const -{ +{ WorldObject* pWorldObject = nullptr; if (!obj) sLog->outError("%s %s object is NULL.", - scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target"); + scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target"); else { pWorldObject = dynamic_cast<WorldObject*>(obj); if (!pWorldObject) sLog->outError("%s %s object is not a world object (TypeId: %u, Entry: %u, GUID: %u).", - scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); + scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow()); } return pWorldObject; } inline void Map::_ScriptProcessDoor(Object* source, Object* target, const ScriptInfo* scriptInfo) const -{ +{ bool bOpen = false; uint32 guid = scriptInfo->ToggleDoor.GOGuid; int32 nTimeToToggle = std::max(15, int32(scriptInfo->ToggleDoor.ResetDelay)); switch (scriptInfo->command) { - case SCRIPT_COMMAND_OPEN_DOOR: bOpen = true; break; - case SCRIPT_COMMAND_CLOSE_DOOR: break; + case SCRIPT_COMMAND_OPEN_DOOR: + bOpen = true; + break; + case SCRIPT_COMMAND_CLOSE_DOOR: + break; default: sLog->outError("%s unknown command for _ScriptProcessDoor.", scriptInfo->GetDebugInfo().c_str()); return; @@ -225,13 +228,13 @@ inline void Map::_ScriptProcessDoor(Object* source, Object* target, const Script sLog->outError("%s source object is NULL.", scriptInfo->GetDebugInfo().c_str()); else if (!source->isType(TYPEMASK_UNIT)) sLog->outError("%s source object is not unit (TypeId: %u, Entry: %u, GUID: %u), skipping.", scriptInfo->GetDebugInfo().c_str(), - source->GetTypeId(), source->GetEntry(), source->GetGUIDLow()); + source->GetTypeId(), source->GetEntry(), source->GetGUIDLow()); else { WorldObject* wSource = dynamic_cast <WorldObject*> (source); if (!wSource) sLog->outError("%s source object could not be casted to world object (TypeId: %u, Entry: %u, GUID: %u), skipping.", - scriptInfo->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow()); + scriptInfo->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow()); else { GameObject* pDoor = _FindGameObject(wSource, guid); @@ -239,7 +242,7 @@ inline void Map::_ScriptProcessDoor(Object* source, Object* target, const Script sLog->outError("%s gameobject was not found (guid: %u).", scriptInfo->GetDebugInfo().c_str(), guid); else if (pDoor->GetGoType() != GAMEOBJECT_TYPE_DOOR) sLog->outError("%s gameobject is not a door (GoType: %u, Entry: %u, GUID: %u).", - scriptInfo->GetDebugInfo().c_str(), pDoor->GetGoType(), pDoor->GetEntry(), pDoor->GetGUIDLow()); + scriptInfo->GetDebugInfo().c_str(), pDoor->GetGoType(), pDoor->GetEntry(), pDoor->GetGUIDLow()); else if (bOpen == (pDoor->GetGoState() == GO_STATE_READY)) { pDoor->UseDoorOrButton(nTimeToToggle); @@ -256,7 +259,7 @@ inline void Map::_ScriptProcessDoor(Object* source, Object* target, const Script } inline GameObject* Map::_FindGameObject(WorldObject* searchObject, uint32 guid) const -{ +{ GameObject* gameobject = nullptr; CellCoord p(acore::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY())); @@ -273,7 +276,7 @@ inline GameObject* Map::_FindGameObject(WorldObject* searchObject, uint32 guid) /// Process queued scripts void Map::ScriptsProcess() -{ +{ if (m_scriptSchedule.empty()) return; @@ -311,14 +314,14 @@ void Map::ScriptsProcess() source = GetCorpse(step.sourceGUID); break; case HIGHGUID_MO_TRANSPORT: - { - GameObject* go = GetGameObject(step.sourceGUID); - source = go ? go->ToTransport() : nullptr; - break; - } + { + GameObject* go = GetGameObject(step.sourceGUID); + source = go ? go->ToTransport() : nullptr; + break; + } default: sLog->outError("%s source with unsupported high guid (GUID: " UI64FMTD ", high guid: %u).", - step.script->GetDebugInfo().c_str(), step.sourceGUID, GUID_HIPART(step.sourceGUID)); + step.script->GetDebugInfo().c_str(), step.sourceGUID, GUID_HIPART(step.sourceGUID)); break; } } @@ -346,14 +349,14 @@ void Map::ScriptsProcess() target = GetCorpse(step.targetGUID); break; case HIGHGUID_MO_TRANSPORT: - { - GameObject* go = GetGameObject(step.targetGUID); - target = go ? go->ToTransport() : nullptr; - break; - } + { + GameObject* go = GetGameObject(step.targetGUID); + target = go ? go->ToTransport() : nullptr; + break; + } default: sLog->outError("%s target with unsupported high guid (GUID: " UI64FMTD ", high guid: %u).", - step.script->GetDebugInfo().c_str(), step.targetGUID, GUID_HIPART(step.targetGUID)); + step.script->GetDebugInfo().c_str(), step.targetGUID, GUID_HIPART(step.targetGUID)); break; } } @@ -388,14 +391,14 @@ void Map::ScriptsProcess() break; case CHAT_TYPE_WHISPER: case CHAT_MSG_RAID_BOSS_WHISPER: - { - uint64 targetGUID = target ? target->GetGUID() : 0; - if (!targetGUID || !IS_PLAYER_GUID(targetGUID)) - sLog->outError("%s attempt to whisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str()); - else - player->Whisper(text, LANG_UNIVERSAL, targetGUID); - break; - } + { + uint64 targetGUID = target ? target->GetGUID() : 0; + if (!targetGUID || !IS_PLAYER_GUID(targetGUID)) + sLog->outError("%s attempt to whisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str()); + else + player->Whisper(text, LANG_UNIVERSAL, targetGUID); + break; + } default: break; // must be already checked at load } @@ -458,8 +461,8 @@ void Map::ScriptsProcess() // Validate field number. if (step.script->FieldSet.FieldID <= OBJECT_FIELD_ENTRY || step.script->FieldSet.FieldID >= cSource->GetValuesCount()) sLog->outError("%s wrong field %u (max count: %u) in object (TypeId: %u, Entry: %u, GUID: %u) specified, skipping.", - step.script->GetDebugInfo().c_str(), step.script->FieldSet.FieldID, - cSource->GetValuesCount(), cSource->GetTypeId(), cSource->GetEntry(), cSource->GetGUIDLow()); + step.script->GetDebugInfo().c_str(), step.script->FieldSet.FieldID, + cSource->GetValuesCount(), cSource->GetTypeId(), cSource->GetEntry(), cSource->GetGUIDLow()); else cSource->SetUInt32Value(step.script->FieldSet.FieldID, step.script->FieldSet.FieldValue); } @@ -469,7 +472,7 @@ void Map::ScriptsProcess() // Source or target must be Creature. if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script)) { - Unit * unit = (Unit*)cSource; + Unit* unit = (Unit*)cSource; if (step.script->MoveTo.TravelTime != 0) { float speed = unit->GetDistance(step.script->MoveTo.DestX, step.script->MoveTo.DestY, step.script->MoveTo.DestZ) / ((float)step.script->MoveTo.TravelTime * 0.001f); @@ -487,8 +490,8 @@ void Map::ScriptsProcess() // Validate field number. if (step.script->FlagToggle.FieldID <= OBJECT_FIELD_ENTRY || step.script->FlagToggle.FieldID >= cSource->GetValuesCount()) sLog->outError("%s wrong field %u (max count: %u) in object (TypeId: %u, Entry: %u, GUID: %u) specified, skipping.", - step.script->GetDebugInfo().c_str(), step.script->FlagToggle.FieldID, - cSource->GetValuesCount(), cSource->GetTypeId(), cSource->GetEntry(), cSource->GetGUIDLow()); + step.script->GetDebugInfo().c_str(), step.script->FlagToggle.FieldID, + cSource->GetValuesCount(), cSource->GetTypeId(), cSource->GetEntry(), cSource->GetGUIDLow()); else cSource->SetFlag(step.script->FlagToggle.FieldID, step.script->FlagToggle.FieldValue); } @@ -501,8 +504,8 @@ void Map::ScriptsProcess() // Validate field number. if (step.script->FlagToggle.FieldID <= OBJECT_FIELD_ENTRY || step.script->FlagToggle.FieldID >= cSource->GetValuesCount()) sLog->outError("%s wrong field %u (max count: %u) in object (TypeId: %u, Entry: %u, GUID: %u) specified, skipping.", - step.script->GetDebugInfo().c_str(), step.script->FlagToggle.FieldID, - cSource->GetValuesCount(), cSource->GetTypeId(), cSource->GetEntry(), cSource->GetGUIDLow()); + step.script->GetDebugInfo().c_str(), step.script->FlagToggle.FieldID, + cSource->GetValuesCount(), cSource->GetTypeId(), cSource->GetEntry(), cSource->GetGUIDLow()); else cSource->RemoveFlag(step.script->FlagToggle.FieldID, step.script->FlagToggle.FieldValue); } @@ -524,62 +527,62 @@ void Map::ScriptsProcess() break; case SCRIPT_COMMAND_QUEST_EXPLORED: - { - if (!source) - { - sLog->outError("%s source object is NULL.", step.script->GetDebugInfo().c_str()); - break; - } - if (!target) - { - sLog->outError("%s target object is NULL.", step.script->GetDebugInfo().c_str()); - break; - } - - // when script called for item spell casting then target == (unit or GO) and source is player - WorldObject* worldObject; - Player* player = target->ToPlayer(); - if (player) { - if (source->GetTypeId() != TYPEID_UNIT && source->GetTypeId() != TYPEID_GAMEOBJECT && source->GetTypeId() != TYPEID_PLAYER) + if (!source) { - sLog->outError("%s source is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.", - step.script->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow()); + sLog->outError("%s source object is NULL.", step.script->GetDebugInfo().c_str()); break; } - worldObject = dynamic_cast<WorldObject*>(source); - } - else - { - player = source->ToPlayer(); + if (!target) + { + sLog->outError("%s target object is NULL.", step.script->GetDebugInfo().c_str()); + break; + } + + // when script called for item spell casting then target == (unit or GO) and source is player + WorldObject* worldObject; + Player* player = target->ToPlayer(); if (player) { - if (target->GetTypeId() != TYPEID_UNIT && target->GetTypeId() != TYPEID_GAMEOBJECT && target->GetTypeId() != TYPEID_PLAYER) + if (source->GetTypeId() != TYPEID_UNIT && source->GetTypeId() != TYPEID_GAMEOBJECT && source->GetTypeId() != TYPEID_PLAYER) { - sLog->outError("%s target is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.", - step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow()); + sLog->outError("%s source is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.", + step.script->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow()); break; } - worldObject = dynamic_cast<WorldObject*>(target); + worldObject = dynamic_cast<WorldObject*>(source); } else { - sLog->outError("%s neither source nor target is player (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.", - step.script->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow(), - target->GetTypeId(), target->GetEntry(), target->GetGUIDLow()); - break; + player = source->ToPlayer(); + if (player) + { + if (target->GetTypeId() != TYPEID_UNIT && target->GetTypeId() != TYPEID_GAMEOBJECT && target->GetTypeId() != TYPEID_PLAYER) + { + sLog->outError("%s target is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.", + step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow()); + break; + } + worldObject = dynamic_cast<WorldObject*>(target); + } + else + { + sLog->outError("%s neither source nor target is player (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.", + step.script->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow(), + target->GetTypeId(), target->GetEntry(), target->GetGUIDLow()); + break; + } } - } - // quest id and flags checked at script loading - if ((worldObject->GetTypeId() != TYPEID_UNIT || ((Unit*)worldObject)->IsAlive()) && - (step.script->QuestExplored.Distance == 0 || worldObject->IsWithinDistInMap(player, float(step.script->QuestExplored.Distance)))) - player->AreaExploredOrEventHappens(step.script->QuestExplored.QuestID); - else - player->FailQuest(step.script->QuestExplored.QuestID); + // quest id and flags checked at script loading + if ((worldObject->GetTypeId() != TYPEID_UNIT || ((Unit*)worldObject)->IsAlive()) && + (step.script->QuestExplored.Distance == 0 || worldObject->IsWithinDistInMap(player, float(step.script->QuestExplored.Distance)))) + player->AreaExploredOrEventHappens(step.script->QuestExplored.QuestID); + else + player->FailQuest(step.script->QuestExplored.QuestID); - break; - } + break; + } case SCRIPT_COMMAND_KILL_CREDIT: // Source or target must be Player. @@ -610,12 +613,12 @@ void Map::ScriptsProcess() } if (pGO->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE || - pGO->GetGoType() == GAMEOBJECT_TYPE_DOOR || - pGO->GetGoType() == GAMEOBJECT_TYPE_BUTTON || - pGO->GetGoType() == GAMEOBJECT_TYPE_TRAP) + pGO->GetGoType() == GAMEOBJECT_TYPE_DOOR || + pGO->GetGoType() == GAMEOBJECT_TYPE_BUTTON || + pGO->GetGoType() == GAMEOBJECT_TYPE_TRAP) { sLog->outError("%s can not be used with gameobject of type %u (guid: %u).", - step.script->GetDebugInfo().c_str(), uint32(pGO->GetGoType()), step.script->RespawnGameobject.GOGuid); + step.script->GetDebugInfo().c_str(), uint32(pGO->GetGoType()), step.script->RespawnGameobject.GOGuid); break; } @@ -632,32 +635,32 @@ void Map::ScriptsProcess() break; case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE: - { - // Source must be WorldObject. - if (WorldObject* pSummoner = _GetScriptWorldObject(source, true, step.script)) { - if (!step.script->TempSummonCreature.CreatureEntry) - sLog->outError("%s creature entry (datalong) is not specified.", step.script->GetDebugInfo().c_str()); - else + // Source must be WorldObject. + if (WorldObject* pSummoner = _GetScriptWorldObject(source, true, step.script)) { - uint32 entry = step.script->TempSummonCreature.CreatureEntry; + if (!step.script->TempSummonCreature.CreatureEntry) + sLog->outError("%s creature entry (datalong) is not specified.", step.script->GetDebugInfo().c_str()); + else + { + uint32 entry = step.script->TempSummonCreature.CreatureEntry; - float x = step.script->TempSummonCreature.PosX; - float y = step.script->TempSummonCreature.PosY; - float z = step.script->TempSummonCreature.PosZ; - float o = step.script->TempSummonCreature.Orientation; + float x = step.script->TempSummonCreature.PosX; + float y = step.script->TempSummonCreature.PosY; + float z = step.script->TempSummonCreature.PosZ; + float o = step.script->TempSummonCreature.Orientation; - if (step.script->TempSummonCreature.CheckIfExists) - if (Unit* trigger = pSummoner->SummonTrigger(x, y, z, o, 1)) - if (trigger->FindNearestCreature(entry, 60.0f)) - break; + if (step.script->TempSummonCreature.CheckIfExists) + if (Unit* trigger = pSummoner->SummonTrigger(x, y, z, o, 1)) + if (trigger->FindNearestCreature(entry, 60.0f)) + break; - if (!pSummoner->SummonCreature(entry, x, y, z, o, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, step.script->TempSummonCreature.DespawnDelay)) - sLog->outError("%s creature was not spawned (entry: %u).", step.script->GetDebugInfo().c_str(), step.script->TempSummonCreature.CreatureEntry); + if (!pSummoner->SummonCreature(entry, x, y, z, o, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, step.script->TempSummonCreature.DespawnDelay)) + sLog->outError("%s creature was not spawned (entry: %u).", step.script->GetDebugInfo().c_str(), step.script->TempSummonCreature.CreatureEntry); + } } + break; } - break; - } case SCRIPT_COMMAND_OPEN_DOOR: case SCRIPT_COMMAND_CLOSE_DOOR: @@ -678,7 +681,7 @@ void Map::ScriptsProcess() if (target->GetTypeId() != TYPEID_GAMEOBJECT) { sLog->outError("%s target object is not gameobject (TypeId: %u, Entry: %u, GUID: %u), skipping.", - step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow()); + step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow()); break; } @@ -688,69 +691,69 @@ void Map::ScriptsProcess() break; case SCRIPT_COMMAND_REMOVE_AURA: - { - // Source (datalong2 != 0) or target (datalong2 == 0) must be Unit. - bool bReverse = step.script->RemoveAura.Flags & SF_REMOVEAURA_REVERSE; - if (Unit* unit = _GetScriptUnit(bReverse ? source : target, bReverse, step.script)) - unit->RemoveAurasDueToSpell(step.script->RemoveAura.SpellID); - break; - } - - case SCRIPT_COMMAND_CAST_SPELL: - { - // TODO: Allow gameobjects to be targets and casters - if (!source && !target) { - sLog->outError("%s source and target objects are NULL.", step.script->GetDebugInfo().c_str()); + // Source (datalong2 != 0) or target (datalong2 == 0) must be Unit. + bool bReverse = step.script->RemoveAura.Flags & SF_REMOVEAURA_REVERSE; + if (Unit* unit = _GetScriptUnit(bReverse ? source : target, bReverse, step.script)) + unit->RemoveAurasDueToSpell(step.script->RemoveAura.SpellID); break; } - Unit* uSource = nullptr; - Unit* uTarget = nullptr; - // source/target cast spell at target/source (script->datalong2: 0: s->t 1: s->s 2: t->t 3: t->s - switch (step.script->CastSpell.Flags) + case SCRIPT_COMMAND_CAST_SPELL: { - case SF_CASTSPELL_SOURCE_TO_TARGET: // source -> target - uSource = source ? source->ToUnit() : nullptr; - uTarget = target ? target->ToUnit() : nullptr; - break; - case SF_CASTSPELL_SOURCE_TO_SOURCE: // source -> source - uSource = source ? source->ToUnit() : nullptr; - uTarget = uSource; - break; - case SF_CASTSPELL_TARGET_TO_TARGET: // target -> target - uSource = target ? target->ToUnit() : nullptr; - uTarget = uSource; - break; - case SF_CASTSPELL_TARGET_TO_SOURCE: // target -> source - uSource = target ? target->ToUnit() : nullptr; - uTarget = source ? source->ToUnit() : nullptr; + // TODO: Allow gameobjects to be targets and casters + if (!source && !target) + { + sLog->outError("%s source and target objects are NULL.", step.script->GetDebugInfo().c_str()); break; - case SF_CASTSPELL_SEARCH_CREATURE: // source -> creature with entry - uSource = source ? source->ToUnit() : nullptr; - uTarget = uSource ? GetClosestCreatureWithEntry(uSource, abs(step.script->CastSpell.CreatureEntry), step.script->CastSpell.SearchRadius) : nullptr; + } + + Unit* uSource = nullptr; + Unit* uTarget = nullptr; + // source/target cast spell at target/source (script->datalong2: 0: s->t 1: s->s 2: t->t 3: t->s + switch (step.script->CastSpell.Flags) + { + case SF_CASTSPELL_SOURCE_TO_TARGET: // source -> target + uSource = source ? source->ToUnit() : nullptr; + uTarget = target ? target->ToUnit() : nullptr; + break; + case SF_CASTSPELL_SOURCE_TO_SOURCE: // source -> source + uSource = source ? source->ToUnit() : nullptr; + uTarget = uSource; + break; + case SF_CASTSPELL_TARGET_TO_TARGET: // target -> target + uSource = target ? target->ToUnit() : nullptr; + uTarget = uSource; + break; + case SF_CASTSPELL_TARGET_TO_SOURCE: // target -> source + uSource = target ? target->ToUnit() : nullptr; + uTarget = source ? source->ToUnit() : nullptr; + break; + case SF_CASTSPELL_SEARCH_CREATURE: // source -> creature with entry + uSource = source ? source->ToUnit() : nullptr; + uTarget = uSource ? GetClosestCreatureWithEntry(uSource, abs(step.script->CastSpell.CreatureEntry), step.script->CastSpell.SearchRadius) : nullptr; + break; + } + + if (!uSource || !uSource->isType(TYPEMASK_UNIT)) + { + sLog->outError("%s no source unit found for spell %u", step.script->GetDebugInfo().c_str(), step.script->CastSpell.SpellID); break; - } + } - if (!uSource || !uSource->isType(TYPEMASK_UNIT)) - { - sLog->outError("%s no source unit found for spell %u", step.script->GetDebugInfo().c_str(), step.script->CastSpell.SpellID); - break; - } + if (!uTarget || !uTarget->isType(TYPEMASK_UNIT)) + { + sLog->outError("%s no target unit found for spell %u", step.script->GetDebugInfo().c_str(), step.script->CastSpell.SpellID); + break; + } - if (!uTarget || !uTarget->isType(TYPEMASK_UNIT)) - { - sLog->outError("%s no target unit found for spell %u", step.script->GetDebugInfo().c_str(), step.script->CastSpell.SpellID); + bool triggered = (step.script->CastSpell.Flags != 4) ? + step.script->CastSpell.CreatureEntry & SF_CASTSPELL_TRIGGERED : + step.script->CastSpell.CreatureEntry < 0; + uSource->CastSpell(uTarget, step.script->CastSpell.SpellID, triggered); break; } - bool triggered = (step.script->CastSpell.Flags != 4) ? - step.script->CastSpell.CreatureEntry & SF_CASTSPELL_TRIGGERED : - step.script->CastSpell.CreatureEntry < 0; - uSource->CastSpell(uTarget, step.script->CastSpell.SpellID, triggered); - break; - } - case SCRIPT_COMMAND_PLAY_SOUND: // Source must be WorldObject. if (WorldObject* object = _GetScriptWorldObject(source, true, step.script)) @@ -807,64 +810,64 @@ void Map::ScriptsProcess() break; case SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT: - { - if (!step.script->CallScript.CreatureEntry) { - sLog->outError("%s creature entry is not specified, skipping.", step.script->GetDebugInfo().c_str()); - break; - } - if (!step.script->CallScript.ScriptID) - { - sLog->outError("%s script id is not specified, skipping.", step.script->GetDebugInfo().c_str()); - break; - } + if (!step.script->CallScript.CreatureEntry) + { + sLog->outError("%s creature entry is not specified, skipping.", step.script->GetDebugInfo().c_str()); + break; + } + if (!step.script->CallScript.ScriptID) + { + sLog->outError("%s script id is not specified, skipping.", step.script->GetDebugInfo().c_str()); + break; + } - Creature* cTarget = nullptr; - WorldObject* wSource = dynamic_cast <WorldObject*> (source); - if (wSource) //using grid searcher - { - CellCoord p(acore::ComputeCellCoord(wSource->GetPositionX(), wSource->GetPositionY())); - Cell cell(p); + Creature* cTarget = nullptr; + WorldObject* wSource = dynamic_cast <WorldObject*> (source); + if (wSource) //using grid searcher + { + CellCoord p(acore::ComputeCellCoord(wSource->GetPositionX(), wSource->GetPositionY())); + Cell cell(p); - acore::CreatureWithDbGUIDCheck target_check(step.script->CallScript.CreatureEntry); - acore::CreatureSearcher<acore::CreatureWithDbGUIDCheck> checker(wSource, cTarget, target_check); + acore::CreatureWithDbGUIDCheck target_check(step.script->CallScript.CreatureEntry); + acore::CreatureSearcher<acore::CreatureWithDbGUIDCheck> checker(wSource, cTarget, target_check); - TypeContainerVisitor<acore::CreatureSearcher <acore::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); - cell.Visit(p, unit_checker, *wSource->GetMap(), *wSource, wSource->GetGridActivationRange()); - } - else //check hashmap holders - { - if (CreatureData const* data = sObjectMgr->GetCreatureData(step.script->CallScript.CreatureEntry)) - cTarget = ObjectAccessor::GetObjectInWorld<Creature>(data->mapid, data->posX, data->posY, MAKE_NEW_GUID(step.script->CallScript.CreatureEntry, data->id, HIGHGUID_UNIT), cTarget); - } + TypeContainerVisitor<acore::CreatureSearcher <acore::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); + cell.Visit(p, unit_checker, *wSource->GetMap(), *wSource, wSource->GetGridActivationRange()); + } + else //check hashmap holders + { + if (CreatureData const* data = sObjectMgr->GetCreatureData(step.script->CallScript.CreatureEntry)) + cTarget = ObjectAccessor::GetObjectInWorld<Creature>(data->mapid, data->posX, data->posY, MAKE_NEW_GUID(step.script->CallScript.CreatureEntry, data->id, HIGHGUID_UNIT), cTarget); + } - if (!cTarget) - { - sLog->outError("%s target was not found (entry: %u)", step.script->GetDebugInfo().c_str(), step.script->CallScript.CreatureEntry); - break; - } + if (!cTarget) + { + sLog->outError("%s target was not found (entry: %u)", step.script->GetDebugInfo().c_str(), step.script->CallScript.CreatureEntry); + break; + } - //Lets choose our ScriptMap map - ScriptMapMap* datamap = GetScriptsMapByType(ScriptsType(step.script->CallScript.ScriptType)); - //if no scriptmap present... - if (!datamap) - { - sLog->outError("%s unknown scriptmap (%u) specified, skipping.", step.script->GetDebugInfo().c_str(), step.script->CallScript.ScriptType); + //Lets choose our ScriptMap map + ScriptMapMap* datamap = GetScriptsMapByType(ScriptsType(step.script->CallScript.ScriptType)); + //if no scriptmap present... + if (!datamap) + { + sLog->outError("%s unknown scriptmap (%u) specified, skipping.", step.script->GetDebugInfo().c_str(), step.script->CallScript.ScriptType); + break; + } + + // Insert script into schedule but do not start it + ScriptsStart(*datamap, step.script->CallScript.ScriptID, cTarget, nullptr); break; } - // Insert script into schedule but do not start it - ScriptsStart(*datamap, step.script->CallScript.ScriptID, cTarget, nullptr); - break; - } - case SCRIPT_COMMAND_KILL: // Source or target must be Creature. if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script)) { if (cSource->isDead()) sLog->outError("%s creature is already dead (Entry: %u, GUID: %u)", - step.script->GetDebugInfo().c_str(), cSource->GetEntry(), cSource->GetGUIDLow()); + step.script->GetDebugInfo().c_str(), cSource->GetEntry(), cSource->GetGUIDLow()); else { cSource->setDeathState(JUST_DIED); |