public static void LoadKeepItemPosition(DBKeepPosition pos, IKeepItem item) { item.CurrentRegionID = item.Component.CurrentRegionID; int x, y; LoadXY(item.Component, pos.XOff, pos.YOff, out x, out y); item.Position = new Vector3(x, y, item.Component.Keep.Z + pos.ZOff); item.Heading = (ushort)(item.Component.Heading + pos.HOff); item.DBPosition = pos; }
public static void LoadKeepItemPosition(DBKeepPosition pos, IKeepItem item) { item.CurrentRegionID = item.Component.CurrentRegionID; int x, y; LoadXY(item.Component, pos.XOff, pos.YOff, out x, out y); item.X = x; item.Y = y; item.Z = item.Component.AbstractKeep.Z + pos.ZOff; item.Heading = (ushort)(item.Component.Heading + pos.HOff); item.Position = pos; }
public virtual void FillPositions() { foreach (DBKeepPosition[] positionGroup in this.Positions.Values) { for (int i = this.Height; i >= 0; i--) { DBKeepPosition position = positionGroup[i] as DBKeepPosition; if (position != null) { bool create = false; if (position.ClassType == "DOL.GS.Keeps.GameKeepBanner") { if (this.AbstractKeep.Banners[position.TemplateID] == null) { create = true; } } else if (position.ClassType == "DOL.GS.Keeps.GameKeepDoor") { if (this.AbstractKeep.Doors[position.TemplateID] == null) { create = true; } } else if (position.ClassType == "DOL.GS.Keeps.FrontierTeleportStone") { if (this.AbstractKeep.TeleportStone == null) { create = true; } } else if (position.ClassType == "DOL.GS.Keeps.Patrol") { if (position.KeepType == (int)AbstractGameKeep.eKeepType.Any || position.KeepType == (int)AbstractKeep.KeepType) { if (this.AbstractKeep.Patrols[position.TemplateID] == null) { Patrol p = new Patrol(this); p.SpawnPosition = position; p.PatrolID = position.TemplateID; p.InitialiseGuards(); } } continue; } else { if (this.AbstractKeep.Guards[position.TemplateID] == null) { create = true; } } if (create) { //create the object try { Assembly asm = Assembly.GetExecutingAssembly(); IKeepItem obj = (IKeepItem)asm.CreateInstance(position.ClassType, true); if (obj != null) { obj.LoadFromPosition(position, this); } if (ServerProperties.Properties.ENABLE_DEBUG) { if (obj is GameLiving) { (obj as GameLiving).Name += " is living, component " + obj.Component.ID; } else if (obj is GameObject) { (obj as GameObject).Name += " is object, component " + obj.Component.ID; } } } catch (Exception ex) { log.Error("GameKeepComponent:FillPositions: " + position.ClassType, ex); } } else { //move the object if (position.ClassType == "DOL.GS.Keeps.GameKeepBanner") { IKeepItem banner = this.AbstractKeep.Banners[position.TemplateID] as IKeepItem; if (banner.Position != position) { banner.MoveToPosition(position); } } else if (position.ClassType == "DOL.GS.Keeps.GameKeepDoor") { //doors dont move } else if (position.ClassType == "DOL.GS.Keeps.FrontierPortalStone") { //these dont move } else { IKeepItem guard = this.AbstractKeep.Guards[position.TemplateID] as IKeepItem; guard.MoveToPosition(position); } } break; } } } foreach (GameKeepGuard guard in this.AbstractKeep.Guards.Values) { if (guard.PatrolGroup != null) { continue; } if (guard.HookPoint != null) { continue; } if (guard.Position == null) { continue; } if (guard.Position.Height > guard.Component.Height) { guard.RemoveFromWorld(); } else { if (guard.Position.Height <= guard.Component.Height && guard.ObjectState != GameObject.eObjectState.Active && !guard.IsRespawning) { guard.AddToWorld(); } } } foreach (GameKeepBanner banner in this.AbstractKeep.Banners.Values) { if (banner.Position == null) { continue; } if (banner.Position.Height > banner.Component.Height) { banner.RemoveFromWorld(); } else { if (banner.Position.Height <= banner.Component.Height && banner.ObjectState != GameObject.eObjectState.Active) { banner.AddToWorld(); } } } }
/// <summary> /// Populate GameKeepItems for this component into the keep /// </summary> public virtual void FillPositions() { foreach (DBKeepPosition[] positionGroup in Positions.Values) { for (int i = this.Height; i >= 0; i--) { if (positionGroup[i] is DBKeepPosition position) { bool create = false; string sKey = position.TemplateID + ID; switch (position.ClassType) { case "DOL.GS.Keeps.GameKeepBanner": if (Keep.Banners.ContainsKey(sKey) == false) { create = true; } break; case "DOL.GS.Keeps.GameKeepDoor": if (Keep.Doors.ContainsKey(sKey) == false) { create = true; } break; case "DOL.GS.Keeps.FrontierTeleportStone": if (Keep.TeleportStone == null) { create = true; } break; case "DOL.GS.Keeps.Patrol": if ((position.KeepType == (int)AbstractGameKeep.eKeepType.Any || position.KeepType == (int)Keep.KeepType) && Keep.Patrols.ContainsKey(sKey) == false) { Patrol p = new Patrol(this); p.SpawnPosition = position; p.PatrolID = position.TemplateID; p.InitialiseGuards(); } continue; case "DOL.GS.Keeps.FrontierHastener": if (Keep.HasHastener && log.IsWarnEnabled) { log.Warn($"FillPositions(): KeepComponent_ID {InternalID}, KeepPosition_ID {position.ObjectId}: There is already a {position.ClassType} on Keep {Keep.KeepID}"); } if (Keep.Guards.ContainsKey(sKey) == false) { Keep.HasHastener = true; create = true; } break; case "DOL.GS.Keeps.MissionMaster": if (Keep.HasCommander && log.IsWarnEnabled) { log.Warn($"FillPositions(): KeepComponent_ID {InternalID}, KeepPosition_ID {position.ObjectId}: There is already a {position.ClassType} on Keep {Keep.KeepID}"); } if (Keep.Guards.ContainsKey(sKey) == false) { Keep.HasCommander = true; create = true; } break; case "DOL.GS.Keeps.GuardLord": if (Keep.HasLord && log.IsWarnEnabled) { log.Warn($"FillPositions(): KeepComponent_ID {InternalID}, KeepPosition_ID {position.ObjectId}: There is already a {position.ClassType} on Keep {Keep.KeepID}"); } if (Keep.Guards.ContainsKey(sKey) == false) { Keep.HasLord = true; create = true; } break; default: if (Keep.Guards.ContainsKey(sKey) == false) { create = true; } break; } // switch (position.ClassType) if (create) { //create the object try { Assembly asm = Assembly.GetExecutingAssembly(); IKeepItem obj = (IKeepItem)asm.CreateInstance(position.ClassType, true); if (obj != null) { obj.LoadFromPosition(position, this); } if (ServerProperties.Properties.ENABLE_DEBUG) { if (obj is GameLiving living) { living.Name += " is living, component " + obj.Component.ID; } else if (obj is GameObject game) { game.Name += " is object, component " + obj.Component.ID; } } } catch (Exception ex) { log.Error("FillPositions(): " + position.ClassType, ex); } } else { /* Why move the object? We should notify the server admin of the duplicate and let them figure out what is causing it in their DB. * Otherwise, we're assuming the former position/component combination wasn't valid, and that's an error that should be reported in any case. * //move the object * switch (position.ClassType) * { * case "DOL.GS.Keeps.GameKeepBanner": * if (this.AbstractKeep.Banners[position.TemplateID] is IKeepItem banner && banner.Position != position) * banner.MoveToPosition(position); * break; * case "DOL.GS.Keeps.GameKeepDoor": * case "DOL.GS.Keeps.FrontierPortalStone": * break; // these dont move * default: * if (this.AbstractKeep.Guards[position.TemplateID] is IKeepItem guard) * guard.MoveToPosition(position); * break; * }*/ if (log.IsWarnEnabled) { log.Warn($"FillPositions(): Keep {Keep.KeepID} already has a {position.ClassType} assigned to Position {position.ObjectId} on Component {InternalID}"); } } break; // We found the highest item for that position, move onto the next one } // if (positionGroup[i] is DBKeepPosition position) } // for (int i = this.Height; i >= 0; i--) } // foreach (DBKeepPosition[] positionGroup in this.Positions.Values) foreach (var guard in Keep.Guards.Values) { if (guard.PatrolGroup != null) { continue; } if (guard.HookPoint != null) { continue; } if (guard.Position == null) { continue; } if (guard.Position.Height > guard.Component.Height) { guard.RemoveFromWorld(); } else { if (guard.Position.Height <= guard.Component.Height && guard.ObjectState != GameObject.eObjectState.Active && !guard.IsRespawning) { guard.AddToWorld(); } } } foreach (var banner in Keep.Banners.Values) { if (banner.Position == null) { continue; } if (banner.Position.Height > banner.Component.Height) { banner.RemoveFromWorld(); } else { if (banner.Position.Height <= banner.Component.Height && banner.ObjectState != GameObject.eObjectState.Active) { banner.AddToWorld(); } } } }