diff options
-rw-r--r-- | src/game/GridNotifiers.h | 13 | ||||
-rw-r--r-- | src/game/World.cpp | 67 | ||||
-rw-r--r-- | src/game/World.h | 2 |
3 files changed, 82 insertions, 0 deletions
diff --git a/src/game/GridNotifiers.h b/src/game/GridNotifiers.h index 5dd863493a8..b00bd33bd24 100644 --- a/src/game/GridNotifiers.h +++ b/src/game/GridNotifiers.h @@ -595,6 +595,19 @@ namespace Trinity Unit const* i_funit; float i_range; }; + + class CreatureWithDbGUIDCheck + { + public: + CreatureWithDbGUIDCheck(WorldObject const* obj, uint32 lowguid) : i_obj(obj), i_lowguid(lowguid) {} + bool operator()(Creature* u) + { + return u->GetDBTableGUIDLow() == i_lowguid; + } + private: + WorldObject const* i_obj; + uint32 i_lowguid; + }; class AnyFriendlyUnitInObjectRangeCheck { diff --git a/src/game/World.cpp b/src/game/World.cpp index 2f331c73893..d97cd327072 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -2268,6 +2268,73 @@ void World::ScriptsProcess() break; } + case SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT: + { + if(!step.script->datalong || !step.script->datalong2) + { + sLog.outError("SCRIPT_COMMAND_CALLSCRIPT calls invallid db_script_id or lowguid not present: skipping."); + break; + } + Creature* target = NULL; + + if(source) //using grid searcher + { + CellPair p(Trinity::ComputeCellPair(((Unit*)source)->GetPositionX(), ((Unit*)source)->GetPositionY())); + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + + //sLog.outDebug("Attempting to find Creature: Db GUID: %i", step.script->datalong); + Trinity::CreatureWithDbGUIDCheck target_check(((Unit*)source), step.script->datalong); + Trinity::CreatureSearcher<Trinity::CreatureWithDbGUIDCheck> checker(target,target_check); + + TypeContainerVisitor<Trinity::CreatureSearcher <Trinity::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); + CellLock<GridReadGuard> cell_lock(cell, p); + cell_lock->Visit(cell_lock, unit_checker, *(((Unit*)source)->GetMap())); + } + else //check hashmap holders + { + if(CreatureData const* data = objmgr.GetCreatureData(step.script->datalong)) + ObjectAccessor::GetObjectInWorld<Creature>(data->mapid, data->posX, data->posY, MAKE_NEW_GUID(step.script->datalong, data->id, HIGHGUID_UNIT), target); + } + + if(!target) + break; + //Lets choose our ScriptMap map + ScriptMapMap datamap; + switch(step.script->dataint) + { + case 1: + datamap = sQuestEndScripts; + break; + case 2: + datamap = sQuestStartScripts; + break; + case 3: + datamap = sSpellScripts; + break; + case 4: + datamap = sGameObjectScripts; + break; + case 5: + datamap = sEventScripts; + break; + case 6: + datamap = sWaypointScripts; + break; + default: + { + sLog.outError("SCRIPT_COMMAND_CALLSCRIPT ERROR: no scriptmap present... ignoring"); + m_scriptSchedule.erase(iter); + return; + } + } + + uint32 script_id = step.script->datalong2; + + m_scriptSchedule.erase(iter); + ScriptsStart(datamap, script_id, target, NULL); + } + default: sLog.outError("Unknown script command %u called.",step.script->command); break; diff --git a/src/game/World.h b/src/game/World.h index c31e05d5a3b..ec3e4ec50b5 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -326,6 +326,8 @@ enum RealmZone #define SCRIPT_COMMAND_REMOVE_AURA 14 // source (datalong2!=0) or target (datalong==0) unit, datalong = spell_id #define SCRIPT_COMMAND_CAST_SPELL 15 // source (datalong2!=0) or target (datalong==0) unit, datalong = spell_id #define SCRIPT_COMMAND_LOAD_PATH 16 // source = unit, path = datalong, repeatable datalong2 +#define SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT 17 // datalong scriptid, lowguid datalong2, dataint table + /// Storage class for commands issued for delayed execution struct CliCommandHolder |