/// <summary> /// Actions to be taken on each Think pulse /// </summary> public override void Think() { if (guard == null) { guard = Body as GameKeepGuard; } if (guard == null) { Stop(); return; } if (guard is GuardArcher || guard is GuardLord) { if (guard.AttackState && guard.CanUseRanged) { guard.SwitchToRanged(guard.TargetObject); } } // if we are not doing an action, let us see if we should move somewhere if (guard.CurrentSpellHandler == null && !guard.IsMoving && !guard.AttackState && !guard.InCombat) { // Tolakram - always clear the aggro list so if this is done by mistake the list will correctly re-fill on next think ClearAggroList(); if (guard.GetDistanceTo(guard.SpawnPoint, 0) > 50) { guard.WalkToSpawn(); } } // Eden - Portal Keeps Guards max distance if (guard.Level > 200 && !guard.IsWithinRadius(guard.SpawnPoint, 2000)) { ClearAggroList(); guard.WalkToSpawn(); } else if (guard.InCombat == false && guard.IsWithinRadius(guard.SpawnPoint, 6000) == false) { ClearAggroList(); guard.WalkToSpawn(); } // We want guards to check aggro even when they are returning home, which StandardMobBrain does not, so add checks here if (guard.CurrentSpellHandler == null && !guard.AttackState && !guard.InCombat) { CheckPlayerAggro(); CheckNPCAggro(); if (HasAggro && Body.IsReturningHome) { Body.StopMoving(); AttackMostWanted(); } } base.Think(); }
public void GetArmorAbsorb_AnySlot_L30Guard_27Percent() { var guard = new GameKeepGuard(); guard.Level = 30; guard.Constitution = 60; var actual = guard.GetArmorAbsorb(eArmorSlot.NOTSET); Assert.AreEqual(0.27, actual, 0.001); }
/// <summary> /// The command handler itself /// </summary> /// <param name="client">The client using the command</param> /// <param name="args">The command arguments</param> public void OnCommand(GameClient client, string[] args) { if (args.Length == 1) { DisplaySyntax(client); return; } switch (args[1].ToLower()) { #region Create case "create": { GameKeepGuard guard = null; if (args.Length < 3) { DisplaySyntax(client); return; } switch (args[2].ToLower()) { #region Lord case "lord": { guard = new GuardLord(); break; } #endregion Lord #region Fighter case "fighter": { guard = new GuardFighter(); break; } #endregion Fighter #region Archer case "archer": { if (args.Length > 3) { guard = new GuardStaticArcher(); } else { guard = new GuardArcher(); } break; } #endregion Archer #region Healer case "healer": { guard = new GuardHealer(); break; } #endregion Healer #region Stealther case "stealther": { guard = new GuardStealther(); break; } #endregion Stealther #region Caster case "caster": { if (args.Length > 3) { guard = new GuardStaticCaster(); } else { guard = new GuardCaster(); } break; } #endregion Caster #region Hastener case "hastener": { guard = new FrontierHastener(); break; } #endregion Hastener #region Mission case "mission": { guard = new MissionMaster(); break; } #endregion Mission #region Patrol case "patrol": { if (args.Length < 4) { DisplayMessage(client, "You need to provide a name for this patrol."); return; } AbstractGameKeep.eKeepType keepType = AbstractGameKeep.eKeepType.Any; if (args.Length < 5) { DisplayMessage(client, "You need to provide the type of keep this patrol works with."); int i = 0; foreach (string str in Enum.GetNames(typeof(Keeps.AbstractGameKeep.eKeepType))) { DisplayMessage(client, "#" + i + ": " + str); i++; } return; } try { keepType = (AbstractGameKeep.eKeepType)Convert.ToInt32(args[4]); } catch { DisplayMessage(client, "Type of keep specified was not valid."); return; } if (client.Player.TargetObject is GameKeepComponent == false) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Create.NoKCompTarget")); return; } GameKeepComponent c = client.Player.TargetObject as GameKeepComponent;; Patrol p = new Patrol(c); p.PatrolID = args[3]; p.KeepType = keepType; p.SpawnPosition = PositionMgr.CreatePatrolPosition(p.PatrolID, c, client.Player, keepType); p.PatrolID = p.SpawnPosition.TemplateID; p.InitialiseGuards(); DisplayMessage(client, "Patrol created for Keep Type " + Enum.GetName(typeof(AbstractGameKeep.eKeepType), keepType)); return; } #endregion Patrol } if (guard == null) { DisplaySyntax(client); return; } GameKeepComponent component = client.Player.TargetObject as GameKeepComponent; if (component != null) { int height = component.Height; if (args.Length > 4) { int.TryParse(args[4], out height); } DBKeepPosition pos = PositionMgr.CreatePosition(guard.GetType(), height, client.Player, Guid.NewGuid().ToString(), component); //PositionMgr.AddPosition(pos); //PositionMgr.FillPositions(); DBKeepPosition[] list = component.Positions[pos.TemplateID] as DBKeepPosition[]; if (list == null) { list = new DBKeepPosition[4]; component.Positions[pos.TemplateID] = list; } list[pos.Height] = pos; component.LoadPositions(); component.FillPositions(); } else { guard.CurrentRegion = client.Player.CurrentRegion; guard.X = client.Player.X; guard.Y = client.Player.Y; guard.Z = client.Player.Z; guard.Heading = client.Player.Heading; guard.Realm = guard.CurrentZone.Realm; guard.LoadedFromScript = false; guard.SaveIntoDatabase(); foreach (AbstractArea area in guard.CurrentAreas) { if (area is KeepArea) { AbstractGameKeep keep = (area as KeepArea).Keep; guard.Component = new GameKeepComponent(); guard.Component.Keep = keep; break; } } TemplateMgr.RefreshTemplate(guard); guard.AddToWorld(); if (guard.Component != null && guard.Component.Keep != null) { guard.Component.Keep.Guards.Add(DOL.Database.UniqueID.IDGenerator.GenerateID(), guard); } } PositionMgr.FillPositions(); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Create.GuardAdded")); break; } #endregion Create #region Position case "position": { switch (args[2].ToLower()) { #region Add case "add": { if (!(client.Player.TargetObject is GameKeepGuard)) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.TargetGuard")); return; } if (args.Length != 4) { DisplaySyntax(client); return; } byte height = byte.Parse(args[3]); //height = KeepMgr.GetHeightFromLevel(height); GameKeepGuard guard = client.Player.TargetObject as GameKeepGuard; if (PositionMgr.GetPosition(guard) != null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.PAlreadyAss", height)); return; } DBKeepPosition pos = PositionMgr.CreatePosition(guard.GetType(), height, client.Player, guard.TemplateID, guard.Component); PositionMgr.AddPosition(pos); PositionMgr.FillPositions(); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.GuardPAdded")); break; } #endregion Add #region Remove case "remove": { if (!(client.Player.TargetObject is GameKeepGuard)) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.TargetGuard")); return; } GameKeepGuard guard = client.Player.TargetObject as GameKeepGuard; DBKeepPosition pos = guard.Position; if (pos != null) { PositionMgr.RemovePosition(pos); if (guard.LoadedFromScript) { if (guard.PatrolGroup != null) { foreach (GameKeepGuard g in guard.PatrolGroup.PatrolGuards) { g.Delete(); } } else { guard.Delete(); } } } PositionMgr.FillPositions(); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.GuardRemoved")); break; } #endregion Remove #region Default default: { DisplaySyntax(client); return; } #endregion Default } break; } #endregion Position #region Path case "path": { switch (args[2].ToLower()) { #region Create case "create": { RemoveAllTempPathObjects(client); PathPoint startpoint = new PathPoint(client.Player.X, client.Player.Y, client.Player.Z, 100000, ePathType.Once); client.Player.TempProperties.setProperty(TEMP_PATH_FIRST, startpoint); client.Player.TempProperties.setProperty(TEMP_PATH_LAST, startpoint); client.Player.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.CreationStarted"), eChatType.CT_System, eChatLoc.CL_SystemWindow); CreateTempPathObject(client, startpoint, "TMP PP 1"); break; } #endregion Create #region Add case "add": { PathPoint path = (PathPoint)client.Player.TempProperties.getProperty <object>(TEMP_PATH_LAST, null); if (path == null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.NoPathCreatedYet")); return; } int speedlimit = 1000; if (args.Length == 4) { try { speedlimit = int.Parse(args[3]); } catch { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.NoValidSpLimit", args[2])); return; } } PathPoint newpp = new PathPoint(client.Player.X, client.Player.Y, client.Player.Z, speedlimit, path.Type); path.Next = newpp; newpp.Prev = path; client.Player.TempProperties.setProperty(TEMP_PATH_LAST, newpp); int len = 0; while (path.Prev != null) { len++; path = path.Prev; } len += 2; CreateTempPathObject(client, newpp, "TMP PP " + len); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.PPAdded", len)); break; } #endregion Add #region Save case "save": { PathPoint path = (PathPoint)client.Player.TempProperties.getProperty <object>(TEMP_PATH_LAST, null); if (path == null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.NoPathCreatedYet")); return; } GameKeepGuard guard = client.Player.TargetObject as GameKeepGuard; if (guard == null || guard.PatrolGroup == null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.TargPatrolGuard")); return; } path.Type = ePathType.Loop; PositionMgr.SavePatrolPath(guard.TemplateID, path, guard.Component); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.Saved")); RemoveAllTempPathObjects(client); guard.PatrolGroup.InitialiseGuards(); PositionMgr.FillPositions(); DisplayMessage(client, "Patrol groups initialized!"); break; } #endregion Save #region Default default: { DisplaySyntax(client); return; } #endregion Default } break; } #endregion Path #region Default default: { DisplaySyntax(client); return; } #endregion Default } }
public void OnCommand(GameClient client, string[] args) { if (IsSpammingCommand(client.Player, "assist")) { return; } if (args.Length > 1) { // This makes absolutely no sense, but it's one of the weird features of the live servers if (args[1].ToLower() == client.Player.Name.ToLower()) // ToLower() is correct, don't change it! { // We cannot assist our target when it has no target. if (!HasTarget(client, client.Player)) { return; } YouAssist(client, client.Player.Name, client.Player.TargetObject); return; } GamePlayer assistPlayer = null; // Should be faster then WorldMgr.GetClientByPlayerName foreach (GamePlayer plr in client.Player.GetPlayersInRadius(2048)) { // ToLower() is correct, don't change it! if (plr.Name.ToLower() != args[1].ToLower()) { continue; } assistPlayer = plr; break; } if (assistPlayer != null) { // Each server type handles the assist command on it's own way. switch (GameServer.Instance.Configuration.ServerType) { case eGameServerType.GST_Normal: { // We cannot assist players of an enemy realm. if (!SameRealm(client, assistPlayer, false)) { return; } // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } case eGameServerType.GST_PvE: { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } case eGameServerType.GST_PvP: { // Note: // I absolutely don't have experience with pvp servers - change it when something is wrong. // Lets check if the client and it's targeted player are in the same alliance. if (client.Player.Guild != null) { if (client.Player.Guild.alliance != null && client.Player.Guild.alliance.Contains(assistPlayer.Guild)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } // They are no alliance members, maybe guild members? if (client.Player.Guild.GetOnlineMemberByID(assistPlayer.InternalID) != null) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } } // They are no alliance or guild members - maybe group members? if (client.Player.Group != null && client.Player.Group.IsInTheGroup(assistPlayer)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } // Ok, they are not in the same alliance, guild or group - maybe in the same battle group? BattleGroup clientBattleGroup = client.Player.TempProperties.getProperty <BattleGroup>(BattleGroup.BATTLEGROUP_PROPERTY, null); if (clientBattleGroup != null) { if (clientBattleGroup.Members.Contains(assistPlayer)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } } // Ok, they are not in the same alliance, guild, group or battle group - maybe in the same chat group? ChatGroup clientChatGroup = client.Player.TempProperties.getProperty <ChatGroup>(ChatGroup.CHATGROUP_PROPERTY, null); if (clientChatGroup != null) { if (clientChatGroup.Members.Contains(assistPlayer)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } } // They are not in the same alliance, guild, group, battle group or chat group. And now? Well, they are enemies! NoValidTarget(client, assistPlayer); return; } } } client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Assist.MemberNotFound"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (client.Player.TargetObject != null) { // This makes absolutely no sense, but it's one of the weird features of the live servers if (client.Player.TargetObject == client.Player) { YouAssist(client, client.Player.Name, client.Player.TargetObject); return; } // Only assist npc's or players! if (client.Player.TargetObject is GameNPC || client.Player.TargetObject is GamePlayer) { // We cannot assist game objects! if (client.Player.TargetObject is GameMovingObject) { NoValidTarget(client, client.Player.TargetObject as GameLiving); return; } // Each server type handles the assist command on it's own way. switch (GameServer.Instance.Configuration.ServerType) { case eGameServerType.GST_Normal: { GameLiving targetLiving = (GameLiving)client.Player.TargetObject; // We cannot assist npc's or players of an enemy realm. if (!SameRealm(client, targetLiving, false)) { return; } // We cannot assist our target when it has no target. if (!HasTarget(client, targetLiving)) { return; } YouAssist(client, client.Player.TargetObject.GetName(0, true), targetLiving.TargetObject); return; } case eGameServerType.GST_PvE: { if (client.Player.TargetObject is GamePlayer) { // We cannot assist our target when it has no target. if (!HasTarget(client, client.Player.TargetObject as GameLiving)) { return; } YouAssist(client, client.Player.TargetObject.Name, (client.Player.TargetObject as GameLiving).TargetObject); return; } if (client.Player.TargetObject is GameNPC) { if (!SameRealm(client, client.Player.TargetObject as GameNPC, true)) { return; } else { // We cannot assist our target when it has no target. if (!HasTarget(client, client.Player.TargetObject as GameNPC)) { return; } YouAssist(client, client.Player.TargetObject.GetName(0, true), (client.Player.TargetObject as GameLiving).TargetObject); return; } } } break; case eGameServerType.GST_PvP: { // Note: // I absolutely don't have experience with pvp servers - change it when something is wrong. if (client.Player.TargetObject is GamePlayer) { GamePlayer targetPlayer = client.Player.TargetObject as GamePlayer; // Lets check if the client and it's targeted player are in the same alliance. if (client.Player.Guild != null && client.Player.Guild.alliance != null && client.Player.Guild.alliance.Contains(targetPlayer.Guild)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } // They are no alliance members, maybe guild members? if (client.Player.Guild != null && client.Player.Guild.GetOnlineMemberByID(targetPlayer.InternalID) != null) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } // They are no alliance or guild members - maybe group members? if (client.Player.Group != null && client.Player.Group.IsInTheGroup(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } // Ok, they are not in the same alliance, guild or group - maybe in the same battle group? BattleGroup clientBattleGroup = (BattleGroup)client.Player.TempProperties.getProperty <object>(BattleGroup.BATTLEGROUP_PROPERTY, null); if (clientBattleGroup != null) { if (clientBattleGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } } // Ok, they are not in the same alliance, guild, group or battle group - maybe in the same chat group? ChatGroup clientChatGroup = client.Player.TempProperties.getProperty <ChatGroup>(ChatGroup.CHATGROUP_PROPERTY, null); if (clientChatGroup != null) { if (clientChatGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } } // They are not in the same alliance, guild, group, battle group or chat group. And now? Well, they are enemies! NoValidTarget(client, targetPlayer); return; } if (client.Player.TargetObject is GameNPC) { if (client.Player.TargetObject is GamePet) { GamePet targetPet = client.Player.TargetObject as GamePet; if (targetPet.Owner is GamePlayer) { GamePlayer targetPlayer = targetPet.Owner as GamePlayer; // Lets check if the client and it's targeted pets owner are in the same alliance. if (client.Player.Guild != null && client.Player.Guild.alliance != null && client.Player.Guild.alliance.Contains(targetPlayer.Guild)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } // They are no alliance members, maybe guild members? if (client.Player.Guild != null && client.Player.Guild.GetOnlineMemberByID(targetPlayer.InternalID) != null) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } // They are no alliance or guild members - maybe group members? if (client.Player.Group != null && client.Player.Group.IsInTheGroup(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } // Ok, they are not in the same alliance, guild or group - maybe in the same battle group? BattleGroup clientBattleGroup = client.Player.TempProperties.getProperty <BattleGroup>(BattleGroup.BATTLEGROUP_PROPERTY, null); if (clientBattleGroup != null) { if (clientBattleGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } } // Ok, they are not in the same alliance, guild, group or battle group - maybe in the same chat group? ChatGroup clientChatGroup = client.Player.TempProperties.getProperty <ChatGroup>(ChatGroup.CHATGROUP_PROPERTY, null); if (clientChatGroup != null) { if (clientChatGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } } // They are not in the same alliance, guild, group, battle group or chat group. And now? Well, they are enemies! NoValidTarget(client, targetPet); return; } if (targetPet.Owner is GameNPC) { if (!SameRealm(client, targetPet.Owner as GameNPC, true)) { return; } else { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } } } if (client.Player.TargetObject is GameKeepGuard) { // Note: // We do not check if the targeted guard is attacking us, because this can be a bug! GameKeepGuard targetGuard = client.Player.TargetObject as GameKeepGuard; Guild targetedGuardGuild = GuildMgr.GetGuildByName(targetGuard.GuildName); // We can assist guards of an unclaimed keep! if (targetedGuardGuild == null) { // We cannot assist our target when it has no target if (!HasTarget(client, targetGuard)) { return; } YouAssist(client, targetGuard.GetName(0, false), targetGuard.TargetObject); return; } // Is the guard of our guild? if (client.Player.Guild == targetedGuardGuild) { // We cannot assist our target when it has no target if (!HasTarget(client, targetGuard)) { return; } YouAssist(client, targetGuard.GetName(0, false), targetGuard.TargetObject); return; } // Is the guard of one of our alliance guilds? if (client.Player.Guild.alliance.Contains(targetedGuardGuild)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetGuard)) { return; } YouAssist(client, targetGuard.GetName(0, false), targetGuard.TargetObject); return; } // The guard is not of one of our alliance guilds and our guild. And now? Well, he is an enemy and we cannot assist enemies! NoValidTarget(client, targetGuard); return; } // We cannot assist npc's of an enemy realm. if (!SameRealm(client, client.Player.TargetObject as GameNPC, true)) { return; } // We cannot assist our target when it has no target if (!HasTarget(client, client.Player.TargetObject as GameNPC)) { return; } YouAssist(client, (client.Player.TargetObject as GameNPC).GetName(0, false), (client.Player.TargetObject as GameNPC).TargetObject); return; } } break; } } } client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Assist.SelectMember"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return; }