static bool HandleCharacterChangeAccountCommand(StringArguments args, CommandHandler handler) { string playerNameStr; string accountName; handler.extractOptFirstArg(args, out playerNameStr, out accountName); if (accountName.IsEmpty()) { return(false); } ObjectGuid targetGuid; string targetName; Player playerNotUsed; if (!handler.extractPlayerTarget(new StringArguments(playerNameStr), out playerNotUsed, out targetGuid, out targetName)) { return(false); } CharacterInfo characterInfo = Global.WorldMgr.GetCharacterInfo(targetGuid); if (characterInfo == null) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } uint oldAccountId = characterInfo.AccountId; uint newAccountId = oldAccountId; PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ID_BY_NAME); stmt.AddValue(0, accountName); SQLResult result = DB.Login.Query(stmt); if (!result.IsEmpty()) { newAccountId = result.Read <uint>(0); } else { handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(false); } // nothing to do :) if (newAccountId == oldAccountId) { return(true); } uint charCount = Global.AccountMgr.GetCharactersCount(newAccountId); if (charCount != 0) { if (charCount >= WorldConfig.GetIntValue(WorldCfg.CharactersPerRealm)) { handler.SendSysMessage(CypherStrings.AccountCharacterListFull, accountName, newAccountId); return(false); } } stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ACCOUNT_BY_GUID); stmt.AddValue(0, newAccountId); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.DirectExecute(stmt); Global.WorldMgr.UpdateRealmCharCount(oldAccountId); Global.WorldMgr.UpdateRealmCharCount(newAccountId); Global.WorldMgr.UpdateCharacterInfoAccount(targetGuid, newAccountId); handler.SendSysMessage(CypherStrings.ChangeAccountSuccess, targetName, accountName); string logString = $"changed ownership of player {targetName} ({targetGuid.ToString()}) from account {oldAccountId} to account {newAccountId}"; WorldSession session = handler.GetSession(); if (session != null) { Player player = session.GetPlayer(); if (player != null) { Log.outCommand(session.GetAccountId(), $"GM {player.GetName()} (Account: {session.GetAccountId()}) {logString}"); } } else { Log.outCommand(0, $"{handler.GetCypherString(CypherStrings.Console)} {logString}"); } 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(); 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 HandleGameObjectAddCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // 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) { return(false); } uint spawntimeSecs = args.NextUInt32(); GameObjectTemplate objectInfo = Global.ObjectMgr.GetGameObjectTemplate(objectId); if (objectInfo == null) { handler.SendSysMessage(CypherStrings.GameobjectNotExist, objectId); return(false); } if (objectInfo.displayId != 0 && !CliDB.GameObjectDisplayInfoStorage.ContainsKey(objectInfo.displayId)) { // report to DB errors log as in loading case Log.outError(LogFilter.Sql, "Gameobject (Entry {0} GoType: {1}) have invalid displayId ({2}), not spawned.", objectId, objectInfo.type, objectInfo.displayId); handler.SendSysMessage(CypherStrings.GameobjectHaveInvalidData, objectId); return(false); } Player player = handler.GetPlayer(); Map map = player.GetMap(); GameObject obj = GameObject.CreateGameObject(objectInfo.entry, map, player, Quaternion.fromEulerAnglesZYX(player.GetOrientation(), 0.0f, 0.0f), 255, GameObjectState.Ready); if (!obj) { return(false); } PhasingHandler.InheritPhaseShift(obj, player); if (spawntimeSecs != 0) { obj.SetRespawnTime((int)spawntimeSecs); } // fill the gameobject data and save to the db obj.SaveToDB(map.GetId(), new List <Difficulty>() { map.GetDifficultyID() }); ulong spawnId = obj.GetSpawnId(); // this will generate a new guid if the object is in an instance obj = GameObject.CreateGameObjectFromDB(spawnId, map); if (!obj) { return(false); } // TODO: is it really necessary to add both the real and DB table guid here ? Global.ObjectMgr.AddGameObjectToGrid(spawnId, Global.ObjectMgr.GetGameObjectData(spawnId)); handler.SendSysMessage(CypherStrings.GameobjectAdd, objectId, objectInfo.name, spawnId, player.GetPositionX(), player.GetPositionY(), player.GetPositionZ()); return(true); }
public static void HandleCharacterLevel(Player player, ObjectGuid playerGuid, int oldLevel, int newLevel, CommandHandler handler) { if (player) { player.GiveLevel((uint)newLevel); player.InitTalentForLevel(); player.SetUInt32Value(PlayerFields.Xp, 0); if (handler.needReportToTarget(player)) { if (oldLevel == newLevel) { player.SendSysMessage(CypherStrings.YoursLevelProgressReset, handler.GetNameLink()); } else if (oldLevel < newLevel) { player.SendSysMessage(CypherStrings.YoursLevelUp, handler.GetNameLink(), newLevel); } else // if (oldlevel > newlevel) { player.SendSysMessage(CypherStrings.YoursLevelDown, handler.GetNameLink(), newLevel); } } } else { // Update level and reset XP, everything else will be updated at login PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_LEVEL); stmt.AddValue(0, newLevel); stmt.AddValue(1, playerGuid.GetCounter()); DB.Characters.Execute(stmt); } }
static bool HandleGameObjectInfoCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string param1 = handler.ExtractKeyFromLink(args, "Hgameobject_entry"); if (param1.IsEmpty()) { return(false); } uint entry; if (param1.Equals("guid")) { string cValue = handler.ExtractKeyFromLink(args, "Hgameobject"); if (cValue.IsEmpty()) { return(false); } if (!ulong.TryParse(cValue, out ulong guidLow)) { return(false); } GameObjectData data = Global.ObjectMgr.GetGameObjectData(guidLow); if (data == null) { return(false); } entry = data.Id; } else { if (!uint.TryParse(param1, out entry)) { return(false); } } GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry); if (gameObjectInfo == null) { return(false); } GameObject thisGO = null; if (handler.GetSession().GetPlayer()) { thisGO = handler.GetSession().GetPlayer().FindNearestGameObject(entry, 30); } else if (handler.GetSelectedObject() != null && handler.GetSelectedObject().IsTypeId(TypeId.GameObject)) { thisGO = handler.GetSelectedObject().ToGameObject(); } 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.SpawninfoSpawnidLocation, thisGO.GetSpawnId(), thisGO.GetPositionX(), thisGO.GetPositionY(), thisGO.GetPositionZ()); Player player = handler.GetSession().GetPlayer(); if (player != null) { Position playerPos = player.GetPosition(); float dist = thisGO.GetExactDist(playerPos); handler.SendSysMessage(CypherStrings.SpawninfoDistancefromplayer, dist); } } handler.SendSysMessage(CypherStrings.GoinfoEntry, entry); handler.SendSysMessage(CypherStrings.GoinfoType, type); handler.SendSysMessage(CypherStrings.GoinfoLootid, lootId); handler.SendSysMessage(CypherStrings.GoinfoDisplayid, displayId); WorldObject obj = handler.GetSelectedObject(); if (obj != null) { if (obj.IsGameObject() && obj.ToGameObject().GetGameObjectData() != null && obj.ToGameObject().GetGameObjectData().spawnGroupData.groupId != 0) { SpawnGroupTemplateData groupData = obj.ToGameObject().GetGameObjectData().spawnGroupData; handler.SendSysMessage(CypherStrings.SpawninfoGroupId, groupData.name, groupData.groupId, groupData.flags, obj.GetMap().IsSpawnGroupActive(groupData.groupId)); } if (obj.IsGameObject()) { handler.SendSysMessage(CypherStrings.SpawninfoCompatibilityMode, obj.ToGameObject().GetRespawnCompatibilityMode()); } } handler.SendSysMessage(CypherStrings.GoinfoName, name); handler.SendSysMessage(CypherStrings.GoinfoSize, gameObjectInfo.size); GameObjectTemplateAddon addon = Global.ObjectMgr.GetGameObjectTemplateAddon(entry); if (addon != null) { handler.SendSysMessage(CypherStrings.GoinfoAddon, addon.faction, addon.flags); } 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); }
static bool HandleResetTalentsCommand(StringArguments args, CommandHandler handler) { Player target; ObjectGuid targetGuid; string targetName; if (!handler.ExtractPlayerTarget(args, out target, out targetGuid, out targetName)) { /* TODO: 6.x remove/update pet talents * // Try reset talents as Hunter Pet * Creature* creature = handler.getSelectedCreature(); * if (!*args && creature && creature.IsPet()) * { * Unit* owner = creature.GetOwner(); * if (owner && owner.GetTypeId() == TYPEID_PLAYER && creature.ToPet().IsPermanentPetFor(owner.ToPlayer())) * { * creature.ToPet().resetTalents(); * owner.ToPlayer().SendTalentsInfoData(true); * * ChatHandler(owner.ToPlayer().GetSession()).SendSysMessage(LANG_RESET_PET_TALENTS); * if (!handler.GetSession() || handler.GetSession().GetPlayer() != owner.ToPlayer()) * handler.PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler.GetNameLink(owner.ToPlayer()).c_str()); * } * return true; * } */ handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); } if (target) { target.ResetTalents(true); target.ResetTalentSpecialization(); target.SendTalentsInfoData(); target.SendSysMessage(CypherStrings.ResetTalents); if (handler.GetSession() == null || handler.GetSession().GetPlayer() != target) { handler.SendSysMessage(CypherStrings.ResetTalentsOnline, handler.GetNameLink(target)); } /* TODO: 6.x remove/update pet talents * Pet* pet = target.GetPet(); * Pet.resetTalentsForAllPetsOf(target, pet); * if (pet) * target.SendTalentsInfoData(true); */ return(true); } else if (!targetGuid.IsEmpty()) { PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG); stmt.AddValue(0, (ushort)(AtLoginFlags.None | AtLoginFlags.ResetPetTalents)); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); string nameLink = handler.PlayerLink(targetName); handler.SendSysMessage(CypherStrings.ResetTalentsOffline, nameLink); return(true); } handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); }
static void HandleCharacterDeletedListHelper(List <DeletedInfo> foundList, CommandHandler handler) { if (handler.GetSession() == null) { handler.SendSysMessage(CypherStrings.CharacterDeletedListBar); handler.SendSysMessage(CypherStrings.CharacterDeletedListHeader); handler.SendSysMessage(CypherStrings.CharacterDeletedListBar); } foreach (var info in foundList) { string dateStr = Time.UnixTimeToDateTime(info.deleteDate).ToShortDateString(); if (!handler.GetSession()) { handler.SendSysMessage(CypherStrings.CharacterDeletedListLineConsole, info.guid.ToString(), info.name, info.accountName.IsEmpty() ? "<Not existed>" : info.accountName, info.accountId, dateStr); } else { handler.SendSysMessage(CypherStrings.CharacterDeletedListLineChat, info.guid.ToString(), info.name, info.accountName.IsEmpty() ? "<Not existed>" : info.accountName, info.accountId, dateStr); } } if (!handler.GetSession()) { handler.SendSysMessage(CypherStrings.CharacterDeletedListBar); } }
static bool HandleModifyMoneyCommand(StringArguments args, CommandHandler handler) { Player target = handler.GetSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } long moneyToAdd = args.NextInt64(); ulong targetMoney = target.GetMoney(); if (moneyToAdd < 0) { long newmoney = (long)targetMoney + moneyToAdd; Log.outDebug(LogFilter.ChatSystem, Global.ObjectMgr.GetCypherString(CypherStrings.CurrentMoney), targetMoney, moneyToAdd, newmoney); if (newmoney <= 0) { handler.SendSysMessage(CypherStrings.YouTakeAllMoney, handler.GetNameLink(target)); if (handler.NeedReportToTarget(target)) { target.SendSysMessage(CypherStrings.YoursAllMoneyGone, handler.GetNameLink()); } target.SetMoney(0); } else { ulong moneyToAddMsg = (ulong)(moneyToAdd * -1); if (newmoney > (long)PlayerConst.MaxMoneyAmount) { newmoney = (long)PlayerConst.MaxMoneyAmount; } handler.SendSysMessage(CypherStrings.YouTakeMoney, moneyToAddMsg, handler.GetNameLink(target)); if (handler.NeedReportToTarget(target)) { target.SendSysMessage(CypherStrings.YoursMoneyTaken, handler.GetNameLink(), moneyToAddMsg); } target.SetMoney((ulong)newmoney); } } else { handler.SendSysMessage(CypherStrings.YouGiveMoney, moneyToAdd, handler.GetNameLink(target)); if (handler.NeedReportToTarget(target)) { target.SendSysMessage(CypherStrings.YoursMoneyGiven, handler.GetNameLink(), moneyToAdd); } if ((ulong)moneyToAdd >= PlayerConst.MaxMoneyAmount) { moneyToAdd = Convert.ToInt64(PlayerConst.MaxMoneyAmount); } moneyToAdd = (long)Math.Min((ulong)moneyToAdd, (PlayerConst.MaxMoneyAmount - targetMoney)); target.ModifyMoney(moneyToAdd); } Log.outDebug(LogFilter.ChatSystem, Global.ObjectMgr.GetCypherString(CypherStrings.NewMoney), targetMoney, moneyToAdd, target.GetMoney()); return(true); }
static bool HandleModifyRepCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player target = handler.GetSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } string factionTxt = handler.ExtractKeyFromLink(args, "Hfaction"); if (string.IsNullOrEmpty(factionTxt)) { return(false); } if (!uint.TryParse(factionTxt, out uint factionId)) { return(false); } string rankTxt = args.NextString(); if (factionId == 0 || !int.TryParse(rankTxt, out int amount)) { return(false); } var factionEntry = CliDB.FactionStorage.LookupByKey(factionId); if (factionEntry == null) { handler.SendSysMessage(CypherStrings.CommandFactionUnknown, factionId); return(false); } if (factionEntry.ReputationIndex < 0) { handler.SendSysMessage(CypherStrings.CommandFactionNorepError, factionEntry.Name[handler.GetSessionDbcLocale()], factionId); return(false); } // try to find rank by name if ((amount == 0) && !(amount < 0) && !rankTxt.IsNumber()) { string rankStr = rankTxt.ToLower(); int i = 0; int r = 0; for (; i != ReputationMgr.ReputationRankThresholds.Length - 1; ++i, ++r) { string rank = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[r]); if (string.IsNullOrEmpty(rank)) { continue; } if (rank.Equals(rankStr)) { break; } if (i == ReputationMgr.ReputationRankThresholds.Length - 1) { handler.SendSysMessage(CypherStrings.CommandFactionInvparam, rankTxt); return(false); } amount = ReputationMgr.ReputationRankThresholds[i]; string deltaTxt = args.NextString(); if (!string.IsNullOrEmpty(deltaTxt)) { int toNextRank = 0; var nextThresholdIndex = i; ++nextThresholdIndex; if (nextThresholdIndex != ReputationMgr.ReputationRankThresholds.Length - 1) { toNextRank = nextThresholdIndex - i; } if (!int.TryParse(deltaTxt, out int delta) || delta < 0 || delta >= toNextRank) { handler.SendSysMessage(CypherStrings.CommandFactionDelta, Math.Max(0, toNextRank - 1)); return(false); } amount += delta; } } } target.GetReputationMgr().SetOneFactionReputation(factionEntry, amount, false); target.GetReputationMgr().SendState(target.GetReputationMgr().GetState(factionEntry)); handler.SendSysMessage(CypherStrings.CommandModifyRep, factionEntry.Name[handler.GetSessionDbcLocale()], factionId, handler.GetNameLink(target), target.GetReputationMgr().GetReputation(factionEntry)); return(true); }
static bool HandleModifySpellCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } byte spellflatid = args.NextByte(); if (spellflatid == 0) { return(false); } byte op = args.NextByte(); if (op == 0) { return(false); } ushort val = args.NextUInt16(); if (val == 0) { return(false); } if (!ushort.TryParse(args.NextString(), out ushort mark)) { mark = 65535; } Player target = handler.GetSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } handler.SendSysMessage(CypherStrings.YouChangeSpellflatid, spellflatid, val, mark, handler.GetNameLink(target)); if (handler.NeedReportToTarget(target)) { target.SendSysMessage(CypherStrings.YoursSpellflatidChanged, handler.GetNameLink(), spellflatid, val, mark); } SetSpellModifier packet = new(ServerOpcodes.SetFlatSpellModifier); SpellModifierInfo spellMod = new(); spellMod.ModIndex = op; SpellModifierData modData; modData.ClassIndex = spellflatid; modData.ModifierValue = val; spellMod.ModifierData.Add(modData); packet.Modifiers.Add(spellMod); target.SendPacket(packet); return(true); }
static bool HandleModifyTalentCommand(StringArguments args, CommandHandler handler) { return(false); }
static bool HandleLfgGroupInfoCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player playerTarget = null; ObjectGuid guidTarget; string nameTarget; ObjectGuid parseGUID = ObjectGuid.Create(HighGuid.Player, args.NextUInt64()); if (ObjectManager.GetPlayerNameByGUID(parseGUID, out nameTarget)) { playerTarget = Global.ObjAccessor.FindPlayer(parseGUID); guidTarget = parseGUID; } else if (!handler.extractPlayerTarget(args, out playerTarget, out guidTarget, out nameTarget)) { return(false); } Group groupTarget = null; if (playerTarget) { groupTarget = playerTarget.GetGroup(); } else { PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GROUP_MEMBER); stmt.AddValue(0, guidTarget.GetCounter()); SQLResult resultGroup = DB.Characters.Query(stmt); if (!resultGroup.IsEmpty()) { groupTarget = Global.GroupMgr.GetGroupByDbStoreId(resultGroup.Read <uint>(0)); } } if (!groupTarget) { handler.SendSysMessage(CypherStrings.LfgNotInGroup, nameTarget); return(false); } ObjectGuid guid = groupTarget.GetGUID(); handler.SendSysMessage(CypherStrings.LfgGroupInfo, groupTarget.isLFGGroup(), Global.LFGMgr.GetState(guid), Global.LFGMgr.GetDungeon(guid)); foreach (var slot in groupTarget.GetMemberSlots()) { Player p = Global.ObjAccessor.FindPlayer(slot.guid); if (p) { GetPlayerInfo(handler, p); } else { handler.SendSysMessage("{0} is offline.", slot.name); } } return(true); }
static bool HandleLfgCleanCommand(StringArguments args, CommandHandler handler) { handler.SendSysMessage(CypherStrings.LfgClean); Global.LFGMgr.Clean(); return(true); }
static bool HandleLfgQueueInfoCommand(StringArguments args, CommandHandler handler) { handler.SendSysMessage(Global.LFGMgr.DumpQueueInfo(args.NextBoolean())); return(true); }
static bool HandleGameObjectInfoCommand(StringArguments args, CommandHandler handler) { uint entry = 0; GameObjectTypes type = 0; uint displayId = 0; uint lootId = 0; if (args.Empty()) { return(false); } string param1 = handler.extractKeyFromLink(args, "Hgameobject_entry"); if (param1.IsEmpty()) { return(false); } if (param1.Equals("guid")) { string cValue = handler.extractKeyFromLink(args, "Hgameobject"); if (cValue.IsEmpty()) { return(false); } if (!ulong.TryParse(cValue, out ulong guidLow)) { return(false); } GameObjectData data = Global.ObjectMgr.GetGOData(guidLow); if (data == null) { return(false); } entry = data.id; } else { if (!uint.TryParse(param1, out entry)) { return(false); } } GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry); if (gameObjectInfo == null) { return(false); } type = gameObjectInfo.type; displayId = gameObjectInfo.displayId; string name = gameObjectInfo.name; lootId = gameObjectInfo.GetLootId(); 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); GameObjectTemplateAddon addon = Global.ObjectMgr.GetGameObjectTemplateAddon(entry); if (addon != null) { handler.SendSysMessage(CypherStrings.GoinfoAddon, addon.faction, addon.flags); } 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); }
static bool HandleModifyGenderCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player target = handler.GetSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } PlayerInfo info = Global.ObjectMgr.GetPlayerInfo(target.GetRace(), target.GetClass()); if (info == null) { return(false); } string gender_str = args.NextString(); Gender gender; if (gender_str == "male") // MALE { if (target.GetGender() == Gender.Male) { return(true); } gender = Gender.Male; } else if (gender_str == "female") // FEMALE { if (target.GetGender() == Gender.Female) { return(true); } gender = Gender.Female; } else { handler.SendSysMessage(CypherStrings.MustMaleOrFemale); return(false); } // Set gender target.SetGender(gender); target.SetNativeSex(gender); // Change display ID target.InitDisplayIds(); target.RestoreDisplayId(false); Global.CharacterCacheStorage.UpdateCharacterGender(target.GetGUID(), (byte)gender); // Generate random customizations List <ChrCustomizationChoice> customizations = new(); var options = Global.DB2Mgr.GetCustomiztionOptions(target.GetRace(), gender); WorldSession worldSession = target.GetSession(); foreach (ChrCustomizationOptionRecord option in options) { ChrCustomizationReqRecord optionReq = CliDB.ChrCustomizationReqStorage.LookupByKey(option.ChrCustomizationReqID); if (optionReq != null && !worldSession.MeetsChrCustomizationReq(optionReq, target.GetClass(), false, customizations)) { continue; } // Loop over the options until the first one fits var choicesForOption = Global.DB2Mgr.GetCustomiztionChoices(option.Id); foreach (ChrCustomizationChoiceRecord choiceForOption in choicesForOption) { var choiceReq = CliDB.ChrCustomizationReqStorage.LookupByKey(choiceForOption.ChrCustomizationReqID); if (choiceReq != null && !worldSession.MeetsChrCustomizationReq(choiceReq, target.GetClass(), false, customizations)) { continue; } ChrCustomizationChoiceRecord choiceEntry = choicesForOption[0]; ChrCustomizationChoice choice = new(); choice.ChrCustomizationOptionID = option.Id; choice.ChrCustomizationChoiceID = choiceEntry.Id; customizations.Add(choice); break; } } target.SetCustomizations(customizations); handler.SendSysMessage(CypherStrings.YouChangeGender, handler.GetNameLink(target), gender); if (handler.NeedReportToTarget(target)) { target.SendSysMessage(CypherStrings.YourGenderChanged, gender, handler.GetNameLink()); } 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 (!int.TryParse(state, out int objectState)) { return(false); } if (objectType < 4) { obj.SetByteValue(GameObjectFields.Bytes1, (byte)objectType, (byte)objectState); } else if (objectType == 4) { obj.SendCustomAnim((uint)objectState); } else if (objectType == 5) { if (objectState < 0 || objectState > (uint)GameObjectDestructibleState.Rebuilding) { return(false); } obj.SetDestructibleState((GameObjectDestructibleState)objectState); } handler.SendSysMessage("Set gobject type {0} state {1}", objectType, objectState); return(true); }
static bool HandleModifySpeedCommand(StringArguments args, CommandHandler handler) { return(HandleModifyASpeedCommand(args, handler)); }
static bool HandleCharacterReputationCommand(StringArguments args, CommandHandler handler) { Player target; if (!handler.extractPlayerTarget(args, out target)) { return(false); } LocaleConstant loc = handler.GetSessionDbcLocale(); var targetFSL = target.GetReputationMgr().GetStateList(); foreach (var pair in targetFSL) { FactionState faction = pair.Value; FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(faction.ID); string factionName = factionEntry != null ? factionEntry.Name[loc] : "#Not found#"; ReputationRank rank = target.GetReputationMgr().GetRank(factionEntry); string rankName = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[(int)rank]); StringBuilder ss = new StringBuilder(); if (handler.GetSession() != null) { ss.AppendFormat("{0} - |cffffffff|Hfaction:{0}|h[{1} {2}]|h|r", faction.ID, factionName, loc); } else { ss.AppendFormat("{0} - {1} {2}", faction.ID, factionName, loc); } ss.AppendFormat(" {0} ({1})", rankName, target.GetReputationMgr().GetReputation(factionEntry)); if (faction.Flags.HasAnyFlag(FactionFlags.Visible)) { ss.Append(handler.GetCypherString(CypherStrings.FactionVisible)); } if (faction.Flags.HasAnyFlag(FactionFlags.AtWar)) { ss.Append(handler.GetCypherString(CypherStrings.FactionAtwar)); } if (faction.Flags.HasAnyFlag(FactionFlags.PeaceForced)) { ss.Append(handler.GetCypherString(CypherStrings.FactionPeaceForced)); } if (faction.Flags.HasAnyFlag(FactionFlags.Hidden)) { ss.Append(handler.GetCypherString(CypherStrings.FactionHidden)); } if (faction.Flags.HasAnyFlag(FactionFlags.InvisibleForced)) { ss.Append(handler.GetCypherString(CypherStrings.FactionInvisibleForced)); } if (faction.Flags.HasAnyFlag(FactionFlags.Inactive)) { ss.Append(handler.GetCypherString(CypherStrings.FactionInactive)); } handler.SendSysMessage(ss.ToString()); } return(true); }
static bool Complete(StringArguments args, CommandHandler handler) { Player player = handler.getSelectedPlayer(); if (!player) { handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); } // .quest complete #entry // number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r string cId = handler.extractKeyFromLink(args, "Hquest"); if (!uint.TryParse(cId, out uint entry)) { return(false); } Quest quest = Global.ObjectMgr.GetQuestTemplate(entry); // If player doesn't have the quest if (quest == null || player.GetQuestStatus(entry) == QuestStatus.None) { handler.SendSysMessage(CypherStrings.CommandQuestNotfound, entry); return(false); } for (int i = 0; i < quest.Objectives.Count; ++i) { QuestObjective obj = quest.Objectives[i]; switch (obj.Type) { case QuestObjectiveType.Item: { uint curItemCount = player.GetItemCount((uint)obj.ObjectID, true); List <ItemPosCount> dest = new List <ItemPosCount>(); InventoryResult msg = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, (uint)obj.ObjectID, (uint)(obj.Amount - curItemCount)); if (msg == InventoryResult.Ok) { Item item = player.StoreNewItem(dest, (uint)obj.ObjectID, true); player.SendNewItem(item, (uint)(obj.Amount - curItemCount), true, false); } break; } case QuestObjectiveType.Monster: { CreatureTemplate creatureInfo = Global.ObjectMgr.GetCreatureTemplate((uint)obj.ObjectID); if (creatureInfo != null) { for (int z = 0; z < obj.Amount; ++z) { player.KilledMonster(creatureInfo, ObjectGuid.Empty); } } break; } case QuestObjectiveType.GameObject: { for (int z = 0; z < obj.Amount; ++z) { player.KillCreditGO((uint)obj.ObjectID); } break; } case QuestObjectiveType.MinReputation: { int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID); if (curRep < obj.Amount) { FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID); if (factionEntry != null) { player.GetReputationMgr().SetReputation(factionEntry, obj.Amount); } } break; } case QuestObjectiveType.MaxReputation: { int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID); if (curRep > obj.Amount) { FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID); if (factionEntry != null) { player.GetReputationMgr().SetReputation(factionEntry, obj.Amount); } } break; } case QuestObjectiveType.Money: { player.ModifyMoney(obj.Amount); break; } } } player.CompleteQuest(entry); return(true); }
static bool HandleCharacterRenameCommand(StringArguments args, CommandHandler handler) { Player target; ObjectGuid targetGuid; string targetName; if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName)) { return(false); } string newNameStr = args.NextString(); if (!string.IsNullOrEmpty(newNameStr)) { string playerOldName; string newName = newNameStr; if (target) { // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } playerOldName = target.GetName(); } else { // check offline security if (handler.HasLowerSecurity(null, targetGuid)) { return(false); } ObjectManager.GetPlayerNameByGUID(targetGuid, out playerOldName); } if (!ObjectManager.NormalizePlayerName(ref newName)) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } if (ObjectManager.CheckPlayerName(newName, target ? target.GetSession().GetSessionDbcLocale() : Global.WorldMgr.GetDefaultDbcLocale(), true) != ResponseCodes.CharNameSuccess) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } WorldSession session = handler.GetSession(); if (session != null) { if (!session.HasPermission(RBACPermissions.SkipCheckCharacterCreationReservedname) && Global.ObjectMgr.IsReservedName(newName)) { handler.SendSysMessage(CypherStrings.ReservedName); return(false); } } PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHECK_NAME); stmt.AddValue(0, newName); SQLResult result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { handler.SendSysMessage(CypherStrings.RenamePlayerAlreadyExists, newName); return(false); } // Remove declined name from db stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_DECLINED_NAME); stmt.AddValue(0, targetGuid.GetCounter()); DB.Characters.Execute(stmt); if (target) { target.SetName(newName); session = target.GetSession(); if (session != null) { session.KickPlayer(); } } else { stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_NAME_BY_GUID); stmt.AddValue(0, newName); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); } Global.WorldMgr.UpdateCharacterInfo(targetGuid, newName); handler.SendSysMessage(CypherStrings.RenamePlayerWithNewName, playerOldName, newName); Player player = handler.GetPlayer(); if (player) { Log.outCommand(session.GetAccountId(), "GM {0} (Account: {1}) forced rename {2} to player {3} (Account: {4})", player.GetName(), session.GetAccountId(), newName, playerOldName, ObjectManager.GetPlayerAccountIdByGUID(targetGuid)); } else { Log.outCommand(0, "CONSOLE forced rename '{0}' to '{1}' ({2})", playerOldName, newName, targetGuid.ToString()); } } else { if (target) { // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } handler.SendSysMessage(CypherStrings.RenamePlayer, handler.GetNameLink(target)); target.SetAtLoginFlag(AtLoginFlags.Rename); } else { // check offline security if (handler.HasLowerSecurity(null, targetGuid)) { return(false); } string oldNameLink = handler.playerLink(targetName); handler.SendSysMessage(CypherStrings.RenamePlayerGuid, oldNameLink, targetGuid.ToString()); PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG); stmt.AddValue(0, AtLoginFlags.Rename); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); } } 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 HandlePDumpLoadCommand(StringArguments args, CommandHandler handler) { /* * if (args.Empty()) * return false; * * string fileStr = strtok((char*)args, " "); * if (!fileStr) * return false; * * char* accountStr = strtok(NULL, " "); * if (!accountStr) * return false; * * string accountName = accountStr; * if (!AccountMgr.normalizeString(accountName)) * { * handler.SendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName); * handler.SetSentErrorMessage(true); * return false; * } * * public uint accountId = AccountMgr.GetId(accountName); * if (!accountId) * { * accountId = atoi(accountStr); // use original string * if (!accountId) * { * handler.SendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName); * * return false; * } * } * * if (!AccountMgr.GetName(accountId, accountName)) * { * handler.SendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName); * handler.SetSentErrorMessage(true); * return false; * } * * char* guidStr = NULL; * char* nameStr = strtok(NULL, " "); * * string name; * if (nameStr) * { * name = nameStr; * // normalize the name if specified and check if it exists * if (!ObjectManager.NormalizePlayerName(name)) * { * handler.SendSysMessage(LANG_INVALID_CHARACTER_NAME); * * return false; * } * * if (ObjectMgr.CheckPlayerName(name, true) != CHAR_NAME_SUCCESS) * { * handler.SendSysMessage(LANG_INVALID_CHARACTER_NAME); * * return false; * } * * guidStr = strtok(NULL, " "); * } * * public uint guid = 0; * * if (guidStr) * { * guid = uint32(atoi(guidStr)); * if (!guid) * { * handler.SendSysMessage(LANG_INVALID_CHARACTER_GUID); * * return false; * } * * if (Global.ObjectMgr.GetPlayerAccountIdByGUID(guid)) * { * handler.SendSysMessage(LANG_CHARACTER_GUID_IN_USE, guid); * * return false; * } * } * * switch (PlayerDumpReader().LoadDump(fileStr, accountId, name, guid)) * { * case DUMP_SUCCESS: * handler.SendSysMessage(LANG_COMMAND_IMPORT_SUCCESS); * break; * case DUMP_FILE_OPEN_ERROR: * handler.SendSysMessage(LANG_FILE_OPEN_FAIL, fileStr); * * return false; * case DUMP_FILE_BROKEN: * handler.SendSysMessage(LANG_DUMP_BROKEN, fileStr); * * return false; * case DUMP_TOO_MANY_CHARS: * handler.SendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, accountName, accountId); * * return false; * default: * handler.SendSysMessage(LANG_COMMAND_IMPORT_FAILED); * * return false; * } */ 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); } } 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 LocCommand(StringArguments args, CommandHandler handler) { handler.SendSysMessage("mmap tileloc:"); // grid tile location Player player = handler.GetPlayer(); int gx = (int)(32 - player.GetPositionX() / MapConst.SizeofGrids); int gy = (int)(32 - player.GetPositionY() / MapConst.SizeofGrids); float x, y, z; player.GetPosition(out x, out y, out z); handler.SendSysMessage("{0:D4}{1:D2}{2:D2}.mmtile", player.GetMapId(), gy, gx); handler.SendSysMessage("gridloc [{0}, {1}]", gx, gy); // calculate navmesh tile location uint terrainMapId = PhasingHandler.GetTerrainMapId(player.GetPhaseShift(), player.GetMap(), x, y); Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(terrainMapId); Detour.dtNavMeshQuery navmeshquery = Global.MMapMgr.GetNavMeshQuery(terrainMapId, player.GetInstanceId()); if (navmesh == null || navmeshquery == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } float[] min = navmesh.getParams().orig; float[] location = { y, z, x }; float[] extents = { 3.0f, 5.0f, 3.0f }; int tilex = (int)((y - min[0]) / MapConst.SizeofGrids); int tiley = (int)((x - min[2]) / MapConst.SizeofGrids); handler.SendSysMessage("Calc [{0:D2}, {1:D2}]", tilex, tiley); // navmesh poly . navmesh tile location Detour.dtQueryFilter filter = new Detour.dtQueryFilter(); float[] nothing = new float[3]; ulong polyRef = 0; if (Detour.dtStatusFailed(navmeshquery.findNearestPoly(location, extents, filter, ref polyRef, ref nothing))) { handler.SendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)"); return(true); } if (polyRef == 0) { handler.SendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)"); } else { Detour.dtMeshTile tile = new Detour.dtMeshTile(); Detour.dtPoly poly = new Detour.dtPoly(); if (Detour.dtStatusSucceed(navmesh.getTileAndPolyByRef(polyRef, ref tile, ref poly))) { if (tile != null) { handler.SendSysMessage("Dt [{0:D2},{1:D2}]", tile.header.x, tile.header.y); return(false); } } handler.SendSysMessage("Dt [??,??] (no tile loaded)"); } 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 PathCommand(StringArguments args, CommandHandler handler) { if (Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId()) == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } handler.SendSysMessage("mmap path:"); // units Player player = handler.GetPlayer(); Unit target = handler.getSelectedUnit(); if (player == null || target == null) { handler.SendSysMessage("Invalid target/source selection."); return(true); } string para = args.NextString(); bool useStraightPath = false; if (para.Equals("true")) { useStraightPath = true; } bool useStraightLine = false; if (para.Equals("line")) { useStraightLine = true; } // unit locations float x, y, z; player.GetPosition(out x, out y, out z); // path PathGenerator path = new PathGenerator(target); path.SetUseStraightPath(useStraightPath); bool result = path.CalculatePath(x, y, z, false, useStraightLine); var pointPath = path.GetPath(); handler.SendSysMessage("{0}'s path to {1}:", target.GetName(), player.GetName()); handler.SendSysMessage("Building: {0}", useStraightPath ? "StraightPath" : useStraightLine ? "Raycast" : "SmoothPath"); handler.SendSysMessage("Result: {0} - Length: {1} - Type: {2}", (result ? "true" : "false"), pointPath.Length, path.GetPathType()); var start = path.GetStartPosition(); var end = path.GetEndPosition(); var actualEnd = path.GetActualEndPosition(); handler.SendSysMessage("StartPosition ({0:F3}, {1:F3}, {2:F3})", start.X, start.Y, start.Z); handler.SendSysMessage("EndPosition ({0:F3}, {1:F3}, {2:F3})", end.X, end.Y, end.Z); handler.SendSysMessage("ActualEndPosition ({0:F3}, {1:F3}, {2:F3})", actualEnd.X, actualEnd.Y, actualEnd.Z); if (!player.IsGameMaster()) { handler.SendSysMessage("Enable GM mode to see the path points."); } for (uint i = 0; i < pointPath.Length; ++i) { player.SummonCreature(1, pointPath[i].X, pointPath[i].Y, pointPath[i].Z, 0, TempSummonType.TimedDespawn, 9000); } 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); } 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 PLimit(StringArguments args, CommandHandler handler) { if (!args.Empty()) { string paramStr = args.NextString(); if (string.IsNullOrEmpty(paramStr)) { return(false); } int limit = paramStr.Length; switch (paramStr.ToLower()) { case "player": Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.Player); break; case "moderator": Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.Moderator); break; case "gamemaster": Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.GameMaster); break; case "administrator": Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.Administrator); break; case "reset": Global.WorldMgr.SetPlayerAmountLimit(ConfigMgr.GetDefaultValue <uint>("PlayerLimit", 100)); Global.WorldMgr.LoadDBAllowedSecurityLevel(); break; default: if (!int.TryParse(paramStr, out int value)) { return(false); } if (value < 0) { Global.WorldMgr.SetPlayerSecurityLimit((AccountTypes)(-value)); } else { Global.WorldMgr.SetPlayerAmountLimit((uint)value); } break; } } uint playerAmountLimit = Global.WorldMgr.GetPlayerAmountLimit(); AccountTypes allowedAccountType = Global.WorldMgr.GetPlayerSecurityLimit(); string secName = ""; switch (allowedAccountType) { case AccountTypes.Player: secName = "Player"; break; case AccountTypes.Moderator: secName = "Moderator"; break; case AccountTypes.GameMaster: secName = "Gamemaster"; break; case AccountTypes.Administrator: secName = "Administrator"; break; default: secName = "<unknown>"; break; } handler.SendSysMessage("Player limits: amount {0}, min. security level {1}.", playerAmountLimit, secName); return(true); }