static bool HandleGameObjectActivateCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } // Activate obj.SetLootState(LootState.Ready); obj.UseDoorOrButton(10000, false, handler.GetSession().GetPlayer()); handler.SendSysMessage("Object activated!"); return(true); }
static bool HandleGameObjectDeleteCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r string id = handler.ExtractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } Player player = handler.GetSession().GetPlayer(); // force respawn to make sure we find something player.GetMap().RemoveRespawnTime(SpawnObjectType.GameObject, guidLow, true); GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } ObjectGuid ownerGuid = obj.GetOwnerGUID(); if (ownerGuid.IsEmpty()) { Unit owner = Global.ObjAccessor.GetUnit(player, ownerGuid); if (!owner || !ownerGuid.IsPlayer()) { handler.SendSysMessage(CypherStrings.CommandDelobjrefercreature, ownerGuid.ToString(), obj.GetGUID().ToString()); return(false); } owner.RemoveGameObject(obj, false); } obj.SetRespawnTime(0); // not save respawn time obj.Delete(); obj.DeleteFromDB(); handler.SendSysMessage(CypherStrings.CommandDelobjmessage, obj.GetGUID().ToString()); return(true); }
static bool HandleGameObjectDeleteCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r string id = handler.ExtractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong spawnId) || spawnId == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(spawnId); if (obj != null) { Player player = handler.GetSession().GetPlayer(); ObjectGuid ownerGuid = obj.GetOwnerGUID(); if (!ownerGuid.IsEmpty()) { Unit owner = Global.ObjAccessor.GetUnit(player, ownerGuid); if (!owner || !ownerGuid.IsPlayer()) { handler.SendSysMessage(CypherStrings.CommandDelobjrefercreature, ownerGuid.ToString(), obj.GetGUID().ToString()); return(false); } owner.RemoveGameObject(obj, false); } } if (GameObject.DeleteFromDB(spawnId)) { handler.SendSysMessage(CypherStrings.CommandDelobjmessage, spawnId); return(true); } handler.SendSysMessage(CypherStrings.CommandObjnotfound, obj.GetGUID().ToString()); return(false); }
static bool HandleGameObjectSetStateCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string type = args.NextString(); if (string.IsNullOrEmpty(type)) { return(false); } if (!int.TryParse(type, out int objectType)) { return(false); } if (objectType < 0) { if (objectType == -1) { obj.SendGameObjectDespawn(); } else if (objectType == -2) { return(false); } return(true); } string state = args.NextString(); if (string.IsNullOrEmpty(state)) { return(false); } if (!uint.TryParse(state, out uint objectState)) { return(false); } switch (objectType) { case 0: obj.SetGoState((GameObjectState)objectState); break; case 1: obj.SetGoType((GameObjectTypes)objectState); break; case 2: obj.SetGoArtKit((byte)objectState); break; case 3: obj.SetGoAnimProgress(objectState); break; case 4: obj.SendCustomAnim(objectState); break; case 5: if (objectState < 0 || objectState > (uint)GameObjectDestructibleState.Rebuilding) { return(false); } obj.SetDestructibleState((GameObjectDestructibleState)objectState); break; default: break; } handler.SendSysMessage("Set gobject type {0} state {1}", objectType, objectState); return(true); }
static bool HandleGameObjectTurnCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string orientation = args.NextString(); float oz = 0.0f, oy = 0.0f, ox = 0.0f; if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out oz)) { return(false); } orientation = args.NextString(); if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out oy)) { return(false); } orientation = args.NextString(); if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out ox)) { return(false); } } } } else { Player player = handler.GetPlayer(); oz = player.GetOrientation(); } Map map = obj.GetMap(); obj.Relocate(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ()); obj.SetWorldRotationAngles(oz, oy, ox); obj.SaveToDB(); // Generate a completely new spawn with new guid // client caches recently deleted objects and brings them back to life // when CreateObject block for this guid is received again // however it entirely skips parsing that block and only uses already known location obj.Delete(); obj = GameObject.CreateGameObjectFromDB(guidLow, map); if (!obj) { return(false); } handler.SendSysMessage(CypherStrings.CommandTurnobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString(), obj.GetOrientation()); return(true); }
static bool HandleGameObjectTargetCommand(StringArguments args, CommandHandler handler) { Player player = handler.GetSession().GetPlayer(); SQLResult result; var activeEventsList = Global.GameEventMgr.GetActiveEventList(); if (!args.Empty()) { // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r string idStr = handler.extractKeyFromLink(args, "Hgameobject_entry"); if (string.IsNullOrEmpty(idStr)) { return(false); } if (!uint.TryParse(idStr, out uint objectId) || objectId != 0) { result = DB.World.Query("SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM gameobject WHERE map = '{3}' AND id = '{4}' ORDER BY order_ ASC LIMIT 1", player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), player.GetMapId(), objectId); } else { result = DB.World.Query( "SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - {0}, 2) + POW(position_y - {1}, 2) + POW(position_z - {2}, 2)) AS order_ " + "FROM gameobject LEFT JOIN gameobject_template ON gameobject_template.entry = gameobject.id WHERE map = {3} AND name LIKE CONCAT('%%', '{4}', '%%') ORDER BY order_ ASC LIMIT 1", player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), player.GetMapId(), objectId); } } else { StringBuilder eventFilter = new StringBuilder(); eventFilter.Append(" AND (eventEntry IS NULL "); bool initString = true; foreach (var entry in activeEventsList) { if (initString) { eventFilter.Append("OR eventEntry IN (" + entry); initString = false; } else { eventFilter.Append(',' + entry); } } if (!initString) { eventFilter.Append("))"); } else { eventFilter.Append(')'); } result = DB.World.Query("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, " + "(POW(position_x - {0}, 2) + POW(position_y - {1}, 2) + POW(position_z - {2}, 2)) AS order_ FROM gameobject " + "LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '{3}' {4} ORDER BY order_ ASC LIMIT 10", handler.GetSession().GetPlayer().GetPositionX(), handler.GetSession().GetPlayer().GetPositionY(), handler.GetSession().GetPlayer().GetPositionZ(), handler.GetSession().GetPlayer().GetMapId(), eventFilter.ToString()); } if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.CommandTargetobjnotfound); return(true); } bool found = false; float x, y, z, o; ulong guidLow; uint id, phaseId, phaseGroup; ushort mapId; uint poolId; do { guidLow = result.Read <ulong>(0); id = result.Read <uint>(1); x = result.Read <float>(2); y = result.Read <float>(3); z = result.Read <float>(4); o = result.Read <float>(5); mapId = result.Read <ushort>(6); phaseId = result.Read <uint>(7); phaseGroup = result.Read <uint>(8); poolId = Global.PoolMgr.IsPartOfAPool <GameObject>(guidLow); if (poolId == 0 || Global.PoolMgr.IsSpawnedObject <GameObject>(guidLow)) { found = true; } } while (result.NextRow() && !found); if (!found) { handler.SendSysMessage(CypherStrings.GameobjectNotExist, id); return(false); } GameObjectTemplate objectInfo = Global.ObjectMgr.GetGameObjectTemplate(id); if (objectInfo == null) { handler.SendSysMessage(CypherStrings.GameobjectNotExist, id); return(false); } GameObject target = handler.GetObjectFromPlayerMapByDbGuid(guidLow); handler.SendSysMessage(CypherStrings.GameobjectDetail, guidLow, objectInfo.name, guidLow, id, x, y, z, mapId, o, phaseId, phaseGroup); if (target) { int curRespawnDelay = (int)(target.GetRespawnTimeEx() - Time.UnixTime); if (curRespawnDelay < 0) { curRespawnDelay = 0; } string curRespawnDelayStr = Time.secsToTimeString((uint)curRespawnDelay, true); string defRespawnDelayStr = Time.secsToTimeString(target.GetRespawnDelay(), true); handler.SendSysMessage(CypherStrings.CommandRawpawntimes, defRespawnDelayStr, curRespawnDelayStr); } return(true); }
static bool HandleGameObjectMoveCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string toX = args.NextString(); string toY = args.NextString(); string toZ = args.NextString(); float x, y, z; if (string.IsNullOrEmpty(toX)) { Player player = handler.GetSession().GetPlayer(); player.GetPosition(out x, out y, out z); } else { if (!float.TryParse(toX, out x)) { return(false); } if (!float.TryParse(toY, out y)) { return(false); } if (!float.TryParse(toZ, out z)) { return(false); } if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, obj.GetMapId()); return(false); } } Map map = obj.GetMap(); obj.Relocate(x, y, z, obj.GetOrientation()); obj.SaveToDB(); // Generate a completely new spawn with new guid // client caches recently deleted objects and brings them back to life // when CreateObject block for this guid is received again // however it entirely skips parsing that block and only uses already known location obj.Delete(); obj = GameObject.CreateGameObjectFromDB(guidLow, map); if (!obj) { return(false); } handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString()); return(true); }
static bool HandleGameObjectSetStateCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string type = args.NextString(); if (string.IsNullOrEmpty(type)) { return(false); } if (!int.TryParse(type, out int objectType)) { return(false); } if (objectType < 0) { if (objectType == -1) { obj.SendGameObjectDespawn(); } else if (objectType == -2) { return(false); } return(true); } string state = args.NextString(); if (string.IsNullOrEmpty(state)) { return(false); } if (!uint.TryParse(state, out uint objectState)) { return(false); } if (objectType < 4) { obj.SetByteValue(GameObjectFields.Bytes1, (byte)objectType, (byte)objectState); } else if (objectType == 4) { obj.SendCustomAnim(objectState); } handler.SendSysMessage("Set gobject type {0} state {1}", objectType, objectState); return(true); }
static bool HandleGameObjectTurnCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string orientation = args.NextString(); float oz = 0.0f, oy = 0.0f, ox = 0.0f; if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out oz)) { return(false); } orientation = args.NextString(); if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out oy)) { return(false); } orientation = args.NextString(); if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out ox)) { return(false); } } } } else { Player player = handler.GetPlayer(); oz = player.GetOrientation(); } obj.Relocate(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ()); obj.RelocateStationaryPosition(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ(), obj.GetOrientation()); obj.SetWorldRotationAngles(oz, oy, ox); obj.DestroyForNearbyPlayers(); obj.UpdateObjectVisibility(); obj.SaveToDB(); handler.SendSysMessage(CypherStrings.CommandTurnobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString(), obj.GetOrientation()); return(true); }
static bool HandleGameObjectMoveCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string toX = args.NextString(); string toY = args.NextString(); string toZ = args.NextString(); float x, y, z; if (string.IsNullOrEmpty(toX)) { Player player = handler.GetSession().GetPlayer(); player.GetPosition(out x, out y, out z); } else { if (!float.TryParse(toX, out x)) { return(false); } if (!float.TryParse(toY, out y)) { return(false); } if (!float.TryParse(toZ, out z)) { return(false); } if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, obj.GetMapId()); return(false); } } obj.DestroyForNearbyPlayers(); obj.RelocateStationaryPosition(x, y, z, obj.GetOrientation()); obj.GetMap().GameObjectRelocation(obj, x, y, z, obj.GetOrientation()); obj.SaveToDB(); handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString()); return(true); }
static bool HandleGameObjectInfoCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string param1 = handler.ExtractKeyFromLink(args, "Hgameobject_entry"); if (param1.IsEmpty()) { return(false); } GameObject thisGO = null; GameObjectData data = null; uint entry; ulong spawnId = 0; if (param1.Equals("guid")) { string cValue = handler.ExtractKeyFromLink(args, "Hgameobject"); if (cValue.IsEmpty()) { return(false); } if (!ulong.TryParse(cValue, out spawnId)) { return(false); } data = Global.ObjectMgr.GetGameObjectData(spawnId); if (data == null) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, spawnId); return(false); } entry = data.Id; thisGO = handler.GetObjectFromPlayerMapByDbGuid(spawnId); } else { if (!uint.TryParse(param1, out entry)) { return(false); } } GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry); if (gameObjectInfo == null) { handler.SendSysMessage(CypherStrings.GameobjectNotExist, entry); return(false); } GameObjectTypes type = gameObjectInfo.type; uint displayId = gameObjectInfo.displayId; string name = gameObjectInfo.name; uint lootId = gameObjectInfo.GetLootId(); // If we have a real object, send some info about it if (thisGO != null) { handler.SendSysMessage(CypherStrings.SpawninfoGuidinfo, thisGO.GetGUID().ToString()); handler.SendSysMessage(CypherStrings.SpawninfoCompatibilityMode, thisGO.GetRespawnCompatibilityMode()); if (thisGO.GetGameObjectData() != null && thisGO.GetGameObjectData().spawnGroupData.groupId != 0) { SpawnGroupTemplateData groupData = thisGO.ToGameObject().GetGameObjectData().spawnGroupData; handler.SendSysMessage(CypherStrings.SpawninfoGroupId, groupData.name, groupData.groupId, groupData.flags, thisGO.GetMap().IsSpawnGroupActive(groupData.groupId)); } GameObjectOverride goOverride = Global.ObjectMgr.GetGameObjectOverride(spawnId); if (goOverride == null) { goOverride = Global.ObjectMgr.GetGameObjectTemplateAddon(entry); } if (goOverride != null) { handler.SendSysMessage(CypherStrings.GoinfoAddon, goOverride.Faction, goOverride.Flags); } } if (data != null) { data.rotation.toEulerAnglesZYX(out float yaw, out float pitch, out float roll); handler.SendSysMessage(CypherStrings.SpawninfoSpawnidLocation, data.SpawnId, data.SpawnPoint.GetPositionX(), data.SpawnPoint.GetPositionY(), data.SpawnPoint.GetPositionZ()); handler.SendSysMessage(CypherStrings.SpawninfoRotation, yaw, pitch, roll); } handler.SendSysMessage(CypherStrings.GoinfoEntry, entry); handler.SendSysMessage(CypherStrings.GoinfoType, type); handler.SendSysMessage(CypherStrings.GoinfoLootid, lootId); handler.SendSysMessage(CypherStrings.GoinfoDisplayid, displayId); handler.SendSysMessage(CypherStrings.GoinfoName, name); handler.SendSysMessage(CypherStrings.GoinfoSize, gameObjectInfo.size); handler.SendSysMessage(CypherStrings.ObjectInfoAIInfo, gameObjectInfo.AIName, Global.ObjectMgr.GetScriptName(gameObjectInfo.ScriptId)); var ai = thisGO != null?thisGO.GetAI() : null; if (ai != null) { handler.SendSysMessage(CypherStrings.ObjectInfoAIType, nameof(ai)); } GameObjectDisplayInfoRecord modelInfo = CliDB.GameObjectDisplayInfoStorage.LookupByKey(displayId); if (modelInfo != null) { handler.SendSysMessage(CypherStrings.GoinfoModel, modelInfo.GeoBoxMax.X, modelInfo.GeoBoxMax.Y, modelInfo.GeoBoxMax.Z, modelInfo.GeoBoxMin.X, modelInfo.GeoBoxMin.Y, modelInfo.GeoBoxMin.Z); } return(true); }