diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 28ab92b8694..0744cb43ae0 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -2876,6 +2876,66 @@ void Map::ScriptsProcess() break; } + case SCRIPT_COMMAND_MOVEMENT: + { + if (!source) + { + sLog.outError("SCRIPT_COMMAND_MOVEMENT (script id %u) call for NULL source.", step.script->id); + break; + } + + if (!source->isType(TYPEMASK_WORLDOBJECT)) + { + sLog.outError("SCRIPT_COMMAND_MOVEMENT (script id %u) call for unsupported non-worldobject (TypeId: %u), skipping.", step.script->id, source->GetTypeId()); + break; + } + + WorldObject* pSource = (WorldObject*)source; + Creature* pMover = NULL; + + if (!step.script->datalong2) // No buddy defined, so try use source (or target where source is player) + { + if (pSource->GetTypeId() != TYPEID_UNIT) + { + // we can't move source being non-creature, so see if target is creature + if (target && target->GetTypeId() == TYPEID_UNIT) + pMover = (Creature*)target; + } + else if (pSource->GetTypeId() == TYPEID_UNIT) + pMover = (Creature*)pSource; + } + else // If step has a buddy entry defined, search for it + { + MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*pSource, step.script->datalong2, true, step.script->datalong3); + MaNGOS::CreatureLastSearcher searcher(pSource, pMover, u_check); + + Cell::VisitGridObjects(pSource, searcher, step.script->datalong3); + } + + if (!pMover) + { + sLog.outError("SCRIPT_COMMAND_MOVEMENT (script id %u) call for non-creature (TypeIdSource: %u)(TypeIdTarget: %u), skipping.", step.script->id, source ? source->GetTypeId() : 0, target ? target->GetTypeId() : 0); + break; + } + + // Consider add additional checks for cases where creature should not change movementType + // (pet? in combat? already using same MMgen as script try to apply?) + + switch(step.script->datalong) + { + case IDLE_MOTION_TYPE: + pMover->GetMotionMaster()->MoveIdle(); + break; + case RANDOM_MOTION_TYPE: + pMover->GetMotionMaster()->MoveRandom(); + break; + case WAYPOINT_MOTION_TYPE: + pMover->GetMotionMaster()->MoveWaypoint(); + break; + } + + break; + } default: sLog.outError("Unknown SCRIPT_COMMAND_ %u called for script id %u.",step.script->command, step.script->id); break; diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index c3f4b926358..950c8d20afe 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -4663,7 +4663,28 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) continue; } break; - } + } + case SCRIPT_COMMAND_MOVEMENT: + { + if (tmp.datalong >= MAX_DB_MOTION_TYPE) + { + sLog.outErrorDb("Table `%s` SCRIPT_COMMAND_MOVEMENT has invalid MovementType %u for script id %u", + tablename, tmp.datalong, tmp.id); + continue; + } + if (tmp.datalong2 && !GetCreatureTemplate(tmp.datalong2)) + { + sLog.outErrorDb("Table `%s` has datalong2 = %u in SCRIPT_COMMAND_MOVEMENT for script id %u, but this creature_template does not exist.", tablename, tmp.datalong2, tmp.id); + continue; + } + if (tmp.datalong2 && !tmp.datalong3) + { + sLog.outErrorDb("Table `%s` has datalong2 = %u in SCRIPT_COMMAND_MOVEMENT for script id %u, but search radius is too small (datalong3 = %u).", tablename, tmp.datalong2, tmp.id, tmp.datalong3); + continue; + } + + break; + } } if (scripts.find(tmp.id) == scripts.end()) diff --git a/src/game/World.h b/src/game/World.h index 723ecc89e1b..edee8b9b1da 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -417,6 +417,8 @@ enum RealmZone #define SCRIPT_COMMAND_CREATE_ITEM 17 // source or target must be player, datalong = item entry, datalong2 = amount #define SCRIPT_COMMAND_DESPAWN_SELF 18 // source or target must be creature, datalong = despawn delay #define SCRIPT_COMMAND_PLAY_MOVIE 19 // target can only be a player, datalog = movie id +#define SCRIPT_COMMAND_MOVEMENT 20 // source or target must be creature. datalong = MovementType (0:idle, 1:random or 2:waypoint) + // datalong2 = creature entry (searching for a buddy, closest to source), datalong3 = creature search radius /// Storage class for commands issued for delayed execution struct CliCommandHolder diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index c7d82f3a0ec..bfdc1a86cb4 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10486" + #define REVISION_NR "10487" #endif // __REVISION_NR_H__