/// <summary> /// Method to Initialise the Guards /// /// Here we create the instances of the guard /// We add to the local array of guards /// We assign a Guard ID which is the Patrol ID /// We assign the guards component /// </summary> public void InitialiseGuards() { Component.Keep.Patrols[PatrolID] = this; //need this here becuase it's checked in add to world PatrolPath = PositionMgr.LoadPatrolPath(PatrolID, Component); int guardsOnPatrol = 1; if (Component != null && Component.Keep != null && Component.Keep is GameKeep) { guardsOnPatrol++; if (Component.Keep.Level > 4) guardsOnPatrol++; } if (PatrolGuards.Count < guardsOnPatrol) { for (int i = 0; i < guardsOnPatrol; i++) { CreatePatrolGuard(i); } } // tolakram - this might be redundant foreach (GameKeepGuard guard in PatrolGuards) { PositionMgr.LoadGuardPosition(SpawnPosition, guard); } ChangePatrolLevel(); }
/// <summary> /// Add living to the aggrolist /// save path of player before attack to walk back to way point after fight /// </summary> /// <param name="living"></param> /// <param name="aggroamount"></param> public override void AddToAggroList(GameLiving living, int aggroamount) { //save current position in path go to here and reload path point //insert path in pathpoint PathPoint temporaryPathPoint = new PathPoint(Body.X, Body.Y, Body.Z, Body.CurrentSpeed, Body.CurrentWayPoint.Type); temporaryPathPoint.Next = Body.CurrentWayPoint; temporaryPathPoint.Prev = Body.CurrentWayPoint.Prev; Body.CurrentWayPoint = temporaryPathPoint; //this path point will be not available after the following point because no link to itself base.AddToAggroList(living, aggroamount); }
private void CreateTempPathObject(GameClient client, PathPoint pp, String name) { //Create a new object GameStaticItem obj = new GameStaticItem(); //Fill the object variables obj.X = pp.X; obj.Y = pp.Y; obj.Z = pp.Z + 1; // raise a bit off of ground level obj.CurrentRegion = client.Player.CurrentRegion; obj.Heading = client.Player.Heading; obj.Name = name; obj.Model = 488; obj.Emblem = 0; obj.AddToWorld(); ArrayList objs = (ArrayList)client.Player.TempProperties.getProperty<object>(TEMP_PATH_OBJS, null); if (objs == null) objs = new ArrayList(); objs.Add(obj); client.Player.TempProperties.setProperty(TEMP_PATH_OBJS, objs); }
/// <summary> /// Searches for the first point in the waypoints chain /// </summary> /// <param name="path">One of the pathpoints</param> /// <returns>The first pathpoint in the chain or null</returns> public static PathPoint FindFirstPathPoint(PathPoint path) { PathPoint root = path; // avoid circularity int iteration = 50000; while (path.Prev != null && path.Prev != root) { path = path.Prev; iteration--; if (iteration <= 0) { if (log.IsErrorEnabled) { log.Error("Path cannot be saved, it seems endless"); } return(null); } } return(path); }
/// <summary> /// loads a path from the cache /// </summary> /// <param name="pathID">path to load</param> /// <returns>first pathpoint of path or null if not found</returns> public static PathPoint LoadPath(string pathID) { if (m_pathCache.Count == 0) { FillPathCache(); } DBPath dbpath = null; if (m_pathCache.ContainsKey(pathID)) { dbpath = m_pathCache[pathID]; } // even if path entry not found see if pathpoints exist and try to use it ePathType pathType = ePathType.Once; if (dbpath != null) { pathType = (ePathType)dbpath.PathType; } SortedList<int, DBPathPoint> pathPoints = null; if (m_pathpointCache.ContainsKey(pathID)) { pathPoints = m_pathpointCache[pathID]; } else { pathPoints = new SortedList<int, DBPathPoint>(); } PathPoint prev = null; PathPoint first = null; foreach (DBPathPoint pp in pathPoints.Values) { PathPoint p = new PathPoint(pp.X, pp.Y, pp.Z, pp.MaxSpeed, pathType); p.WaitTime = pp.WaitTime; if (first == null) { first = p; } p.Prev = prev; if (prev != null) { prev.Next = p; } prev = p; } return first; }
/// <summary> /// Method to start a Patrol patroling /// It sets a patrol leader /// And starts moving on Patrol /// </summary> public void StartPatrol() { if (PatrolPath == null) PatrolPath = PositionMgr.LoadPatrolPath(PatrolID, Component); foreach (GameKeepGuard guard in PatrolGuards) { if (guard.CurrentWayPoint == null) guard.CurrentWayPoint = PatrolPath; guard.MoveOnPath(PATROL_SPEED); } }
/// <summary> /// Method to Change a Patrol's Level /// /// This method handles the add and removing of guards /// </summary> public void ChangePatrolLevel() { int guardsToPatrol = 1; if (Component != null && Component.Keep != null && Component.Keep is GameKeep) { guardsToPatrol++; if (Component.Keep.Level > 4) guardsToPatrol++; } PatrolPath = PositionMgr.LoadPatrolPath(PatrolID, Component); // Console.WriteLine(PatrolID + " guardstopatrol = " + guardsToPatrol + ", count = " + PatrolGuards.Count); while (guardsToPatrol > PatrolGuards.Count) { CreatePatrolGuard(PatrolGuards.Count); } int x = 0; int y = 0; List<GameKeepGuard> guardsToKeep = new List<GameKeepGuard>(); for (int i = 0; i < PatrolGuards.Count; i++) { GameKeepGuard guard = PatrolGuards[i] as GameKeepGuard; // Console.WriteLine(PatrolID + " loading guard " + guard.Name); if (i < guardsToPatrol) { // we need to reposition the patrol at their spawn point plus variation if (x == 0) { x = guard.SpawnPoint.X; y = guard.SpawnPoint.Y; } else { x += Util.Random(250, 350); y += Util.Random(250, 350); } if (guard.IsAlive) { if (guard.IsMovingOnPath) guard.StopMovingOnPath(); guard.MoveTo(guard.CurrentRegionID, x, y, guard.SpawnPoint.Z, guard.SpawnHeading); } guardsToKeep.Add(guard); } else { guard.Delete(); } } PatrolGuards = guardsToKeep; StartPatrol(); }
/// <summary> /// Method to save the Patrol Path using the Patrol ID and the Component /// </summary> /// <param name="pathID"></param> /// <param name="path"></param> /// <param name="component"></param> public static void SavePatrolPath(string pathID, PathPoint path, GameKeepComponent component) { if (path == null) return; pathID.Replace('\'', '/'); // we must replace the ', found no other way yet foreach (DBPath pp in GameServer.Database.SelectObjects<DBPath>("PathID='" + GameServer.Database.Escape(pathID) + "'")) { GameServer.Database.DeleteObject(pp); } PathPoint root = MovementMgr.FindFirstPathPoint(path); //Set the current pathpoint to the rootpoint! path = root; DBPath dbp = new DBPath(pathID, ePathType.Loop); GameServer.Database.AddObject(dbp); int i = 1; do { DBPathPoint dbpp = new DBPathPoint(path.X, path.Y, path.Z, path.MaxSpeed); int x, y; SaveXY(component, dbpp.X, dbpp.Y, out x, out y); dbpp.X = x; dbpp.Y = y; dbpp.Z = dbpp.Z - component.Z; dbpp.Step = i++; dbpp.PathID = pathID; dbpp.WaitTime = path.WaitTime; GameServer.Database.AddObject(dbpp); path = path.Next; } while (path != null && path != root); }
/// <summary> /// Method to retrieve the Patrol Path from the Patrol ID and Component /// /// We need this because we store this all using our offset system /// </summary> /// <param name="pathID">The path ID, which is the Patrol ID</param> /// <param name="component">The Component object</param> /// <returns>The Patrol path</returns> public static PathPoint LoadPatrolPath(string pathID, GameKeepComponent component) { SortedList sorted = new SortedList(); pathID.Replace('\'', '/'); // we must replace the ', found no other way yet DBPath dbpath = GameServer.Database.SelectObject<DBPath>("PathID='" + GameServer.Database.Escape(pathID) + "'"); IList<DBPathPoint> pathpoints = null; ePathType pathType = ePathType.Once; if (dbpath != null) { pathType = (ePathType)dbpath.PathType; } if (pathpoints == null) { pathpoints = GameServer.Database.SelectObjects<DBPathPoint>("PathID='" + GameServer.Database.Escape(pathID) + "'"); } foreach (DBPathPoint point in pathpoints) { sorted.Add(point.Step, point); } PathPoint prev = null; PathPoint first = null; for (int i = 0; i < sorted.Count; i++) { DBPathPoint pp = (DBPathPoint)sorted.GetByIndex(i); PathPoint p = new PathPoint(pp.X, pp.Y, pp.Z, pp.MaxSpeed, pathType); int x, y; LoadXY(component, pp.X, pp.Y, out x, out y); p.X = x; p.Y = y; p.Z = component.AbstractKeep.Z + p.Z; p.WaitTime = pp.WaitTime; if (first == null) { first = p; } p.Prev = prev; if (prev != null) { prev.Next = p; } prev = p; } return first; }
public PathPoint(PathPoint pp) : this(pp, pp.MaxSpeed,pp.Type) {}
/// <summary> /// Searches for the first point in the waypoints chain /// </summary> /// <param name="path">One of the pathpoints</param> /// <returns>The first pathpoint in the chain or null</returns> public static PathPoint FindFirstPathPoint(PathPoint path) { PathPoint root = path; // avoid circularity int iteration = 50000; while (path.Prev != null && path.Prev != root) { path = path.Prev; iteration--; if (iteration <= 0) { if (log.IsErrorEnabled) log.Error("Path cannot be saved, it seems endless"); return null; } } return path; }
/// <summary> /// Saves the path into the database /// </summary> /// <param name="pathID">The path ID</param> /// <param name="path">The path waypoint</param> public static void SavePath(string pathID, PathPoint path) { if (path == null) return; pathID.Replace('\'', '/'); // First delete any path with this pathID from the database DBPath dbpath = GameServer.Database.SelectObject<DBPath>("PathID='" + GameServer.Database.Escape(pathID) + "'"); if (dbpath != null) { GameServer.Database.DeleteObject(dbpath); } foreach (DBPathPoint pp in GameServer.Database.SelectObjects<DBPathPoint>("PathID='" + GameServer.Database.Escape(pathID) + "'")) { GameServer.Database.DeleteObject(pp); } // Now add this path and iterate through the PathPoint linked list to add all the path points PathPoint root = FindFirstPathPoint(path); //Set the current pathpoint to the rootpoint! path = root; dbpath = new DBPath(pathID, root.Type); GameServer.Database.AddObject(dbpath); int i = 1; do { DBPathPoint dbpp = new DBPathPoint(path.X, path.Y, path.Z, path.MaxSpeed); dbpp.Step = i++; dbpp.PathID = pathID; dbpp.WaitTime = path.WaitTime; GameServer.Database.AddObject(dbpp); path = path.Next; } while (path != null && path != root); UpdatePathInCache(pathID); }
private void PathAdd(GameClient client, string[] args) { PathPoint path = (PathPoint)client.Player.TempProperties.getProperty<object>(TEMP_PATH_LAST, null); if (path == null) { DisplayMessage(client, "No path created yet! Use /path create first!"); return; } int speedlimit = 1000; int waittime = 0; if (args.Length > 2) { try { speedlimit = int.Parse(args[2]); } catch { DisplayMessage(client, "No valid speedlimit '{0}'!", args[2]); return; } if (args.Length > 3) { try { waittime = int.Parse(args[3]); } catch { DisplayMessage(client, "No valid wait time '{0}'!", args[3]); } } } PathPoint newpp = new PathPoint(client.Player.X, client.Player.Y, client.Player.Z, speedlimit, path.Type); newpp.WaitTime = waittime * 10; 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, "Pathpoint added. Current pathlength = {0}", len); }
private void PathCreate(GameClient client) { //Remove old temp objects RemoveAllTempPathObjects(client); PathPoint startpoint = new PathPoint(client.Player.X, client.Player.Y, client.Player.Z, 5000, ePathType.Once); client.Player.TempProperties.setProperty(TEMP_PATH_FIRST, startpoint); client.Player.TempProperties.setProperty(TEMP_PATH_LAST, startpoint); client.Player.Out.SendMessage("Path creation started! You can add new pathpoints via /path add now!", eChatType.CT_System, eChatLoc.CL_SystemWindow); CreateTempPathObject(client, startpoint, "TMP PP 1"); }
public PathPoint(PathPoint pp) : this(pp.Position, pp.MaxSpeed, pp.Type) { }
/// <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 } }
private void CreateTempPathObject(GameClient client, PathPoint pp, string name) { GameStaticItem obj = new GameStaticItem(); obj.X = pp.X; obj.Y = pp.Y; obj.Z = pp.Z; obj.CurrentRegion = client.Player.CurrentRegion; obj.Heading = client.Player.Heading; obj.Name = name; obj.Model = 488; obj.Emblem = 0; obj.AddToWorld(); ArrayList objs = (ArrayList)client.Player.TempProperties.getProperty<object>(TEMP_PATH_OBJS, null); if (objs == null) objs = new ArrayList(); objs.Add(obj); client.Player.TempProperties.setProperty(TEMP_PATH_OBJS, objs); }
public PathPoint(PathPoint pp) : this(pp, pp.MaxSpeed, pp.Type) { }