/// <summary> /// reset the realm when the lord have been killed /// </summary> /// <param name="realm"></param> public virtual void Reset(eRealm realm) { LastAttackedByEnemyTick = 0; StartCombatTick = 0; Realm = realm; PlayerMgr.BroadcastCapture(this); Level = (byte)ServerProperties.Properties.STARTING_KEEP_LEVEL; //if a guild holds the keep, we release it if (Guild != null) { Release(); } //we repair all keep components, but not if it is a tower and is raised foreach (GameKeepComponent component in this.KeepComponents) { if (!component.IsRaized) { component.Repair(component.MaxHealth - component.Health); } foreach (GameKeepHookPoint hp in component.KeepHookPoints.Values) { if (hp.Object != null) { hp.Object.Die(null); } } } //change realm foreach (GameClient client in WorldMgr.GetClientsOfRegion(this.CurrentRegion.ID)) { client.Out.SendKeepComponentUpdate(this, false); } //we reset all doors foreach (GameKeepDoor door in Doors.Values) { door.Reset(realm); } //we make sure all players are not in the air ResetPlayersOfKeep(); //we reset the guards foreach (GameKeepGuard guard in Guards.Values) { if (guard is GuardLord && guard.IsAlive) { this.TemplateManager.GetMethod("RefreshTemplate").Invoke(null, new object[] { guard }); } else if (guard is GuardLord == false) { guard.Die(guard); } } //we reset the banners foreach (GameKeepBanner banner in Banners.Values) { banner.ChangeRealm(); } //update guard level for every keep if (!IsPortalKeep && ServerProperties.Properties.USE_KEEP_BALANCING) { GameServer.KeepManager.UpdateBaseLevels(); } //update the counts of keeps for the bonuses if (ServerProperties.Properties.USE_LIVE_KEEP_BONUSES) { KeepBonusMgr.UpdateCounts(); } SaveIntoDatabase(); GameEventMgr.Notify(KeepEvent.KeepTaken, new KeepEventArgs(this)); }
/// <summary> /// load all keeps from the DB /// </summary> /// <returns></returns> public virtual bool Load() { // first check the regions we manage foreach (Region r in WorldMgr.Regions.Values) { if (r.IsFrontier) { m_frontierRegionsList.Add(r.ID); } } // default to NF if no frontier regions found if (m_frontierRegionsList.Count == 0) { m_frontierRegionsList.Add(DEFAULT_FRONTIERS_REGION); } ClothingMgr.LoadTemplates(); //Dinberg - moved this here, battlegrounds must be loaded before keepcomponents are. LoadBattlegroundCaps(); if (!ServerProperties.Properties.LOAD_KEEPS) { return(true); } lock (m_keepList.SyncRoot) { m_keepList.Clear(); var keeps = GameServer.Database.SelectAllObjects <DBKeep>(); foreach (DBKeep datakeep in keeps) { Region keepRegion = WorldMgr.GetRegion(datakeep.Region); if (keepRegion == null) { continue; } AbstractGameKeep keep; if ((datakeep.KeepID >> 8) != 0 || ((datakeep.KeepID & 0xFF) > 150)) { keep = keepRegion.CreateGameKeepTower(); } else { keep = keepRegion.CreateGameKeep(); } keep.Load(datakeep); RegisterKeep(datakeep.KeepID, keep); } // This adds owner keeps to towers / portal keeps foreach (AbstractGameKeep keep in m_keepList.Values) { GameKeepTower tower = keep as GameKeepTower; if (tower != null) { int index = tower.KeepID & 0xFF; GameKeep ownerKeep = GetKeepByID(index) as GameKeep; if (ownerKeep != null) { ownerKeep.AddTower(tower); } tower.Keep = ownerKeep; tower.OwnerKeepID = index; if (tower.OwnerKeepID < 10) { log.WarnFormat("Tower.OwnerKeepID < 10 for KeepID {0}. Doors on this tower will not be targetable! ({0} & 0xFF < 10). Choose a different KeepID to correct this issue.", tower.KeepID); } } } if (ServerProperties.Properties.USE_NEW_KEEPS == 2) { log.ErrorFormat("ServerProperty USE_NEW_KEEPS is actually set to 2 but it is no longer used. Loading as if he were 0 but please set to 0 or 1 !"); } // var keepcomponents = default(IList<DBKeepComponent>); Why was this done this way rather than being strictly typed? IList <DBKeepComponent> keepcomponents = null; if (ServerProperties.Properties.USE_NEW_KEEPS == 0 || ServerProperties.Properties.USE_NEW_KEEPS == 2) { keepcomponents = DOLDB <DBKeepComponent> .SelectObjects(DB.Column(nameof(DBKeepComponent.Skin)).IsLessThan(20)); } else if (ServerProperties.Properties.USE_NEW_KEEPS == 1) { keepcomponents = DOLDB <DBKeepComponent> .SelectObjects(DB.Column(nameof(DBKeepComponent.Skin)).IsGreatherThan(20)); } if (keepcomponents != null) { keepcomponents .GroupBy(x => x.KeepID) .AsParallel() .ForAll(components => { foreach (DBKeepComponent component in components) { AbstractGameKeep keep = GetKeepByID(component.KeepID); if (keep == null) { //missingKeeps = true; continue; } GameKeepComponent gamecomponent = keep.CurrentRegion.CreateGameKeepComponent(); gamecomponent.LoadFromDatabase(component, keep); keep.KeepComponents.Add(gamecomponent); } }); } /*if (missingKeeps && log.IsWarnEnabled) * { * log.WarnFormat("Some keeps not found while loading components, possibly old/new keeptypes."); * }*/ if (m_keepList.Count != 0) { foreach (AbstractGameKeep keep in m_keepList.Values) { if (keep.KeepComponents.Count != 0) { keep.KeepComponents.Sort(); } } } LoadHookPoints(); log.Info("Loaded " + m_keepList.Count + " keeps successfully"); } if (ServerProperties.Properties.USE_KEEP_BALANCING) { UpdateBaseLevels(); } if (ServerProperties.Properties.USE_LIVE_KEEP_BONUSES) { KeepBonusMgr.UpdateCounts(); } return(true); }
/// <summary> /// load all keeps from the DB /// </summary> /// <returns></returns> public virtual bool Load() { // first check the regions we manage foreach (Region r in WorldMgr.Regions.Values) { if (r.IsFrontier) { m_frontierRegionsList.Add(r.ID); } } // default to NF if no frontier regions found if (m_frontierRegionsList.Count == 0) { m_frontierRegionsList.Add(DEFAULT_FRONTIERS_REGION); } ClothingMgr.LoadTemplates(); //Dinberg - moved this here, battlegrounds must be loaded before keepcomponents are. LoadBattlegroundCaps(); if (!ServerProperties.Properties.LOAD_KEEPS) { return(true); } lock (m_keepList.SyncRoot) { m_keepList.Clear(); var keeps = GameServer.Database.SelectAllObjects <DBKeep>(); foreach (DBKeep datakeep in keeps) { Region keepRegion = WorldMgr.GetRegion(datakeep.Region); if (keepRegion == null) { continue; } //Dinberg - checking whether the keep is old or new. //The only way to do this is to examine the database entries for hookpoints and thus determine //in this manner whether the keep is old, new or 'both'. A keep will be 'both' if it is found to //have components of both sets, which is possible. bool hasOldComponents = false; bool hasNewComponents = false; //I don't want to touch the loading order of hookpoints, as i think they may depend on the //assumption keeps and towers are linked before population. So we will settle for a second //query. It's on server start, so it wont impact running performance. var currentKeepComponents = GameServer.Database.SelectObjects <DBKeepComponent>("`KeepID` = '" + datakeep.KeepID + "'"); //Pass through, and depending on the outcome of the components, determine the 'age' of the keep. foreach (DBKeepComponent comp in currentKeepComponents) { if (comp.Skin >= 0 && comp.Skin <= 20) //these are the min/max ids for old keeps. { hasOldComponents = true; } if (comp.Skin > 20) //any skinID greater than this are ids for new keeps. { hasNewComponents = true; } } if (datakeep.KeepSkinType != eKeepSkinType.Any) { if (datakeep.KeepSkinType == eKeepSkinType.New && hasNewComponents == false) { continue; } else if (datakeep.KeepSkinType == eKeepSkinType.Old && hasOldComponents == false) { continue; } } else { // Use server properties to determine correct keep to load //"use_new_keeps", "Keeps to load. 0 for Old Keeps, 1 for new keeps, 2 for both.", 2 if (ServerProperties.Properties.USE_NEW_KEEPS == 0 && !hasOldComponents) { continue; } if (ServerProperties.Properties.USE_NEW_KEEPS == 1 && !hasNewComponents) { continue; } } //If we've got this far, we are permitted to load as per normal! AbstractGameKeep keep; if ((datakeep.KeepID >> 8) != 0 || ((datakeep.KeepID & 0xFF) > 150)) { keep = keepRegion.CreateGameKeepTower(); } else { keep = keepRegion.CreateGameKeep(); } keep.Load(datakeep); RegisterKeep(datakeep.KeepID, keep); } // This adds owner keeps to towers / portal keeps foreach (AbstractGameKeep keep in m_keepList.Values) { GameKeepTower tower = keep as GameKeepTower; if (tower != null) { int index = tower.KeepID & 0xFF; GameKeep ownerKeep = GetKeepByID(index) as GameKeep; if (ownerKeep != null) { ownerKeep.AddTower(tower); } tower.Keep = ownerKeep; tower.OwnerKeepID = index; if (tower.OwnerKeepID < 10) { log.WarnFormat("Tower.OwnerKeepID < 10 for KeepID {0}. Doors on this tower will not be targetable! ({0} & 0xFF < 10). Choose a different KeepID to correct this issue.", tower.KeepID); } } } bool missingKeeps = false; var keepcomponents = GameServer.Database.SelectAllObjects <DBKeepComponent>(); foreach (DBKeepComponent component in keepcomponents) { AbstractGameKeep keep = GetKeepByID(component.KeepID); if (keep == null) { missingKeeps = true; continue; } if (keep.DBKeep.KeepSkinType != eKeepSkinType.Any) { if (keep.DBKeep.KeepSkinType == eKeepSkinType.New && IsNewKeepComponent(component.Skin) == false) { continue; } else if (keep.DBKeep.KeepSkinType == eKeepSkinType.Old && IsNewKeepComponent(component.Skin)) { continue; } } else { // if use old keeps don't try to load new components if (ServerProperties.Properties.USE_NEW_KEEPS == 0 && IsNewKeepComponent(component.Skin)) { continue; } // if use new keeps don't try and load old components if (ServerProperties.Properties.USE_NEW_KEEPS == 1 && !IsNewKeepComponent(component.Skin)) { continue; } } GameKeepComponent gamecomponent = keep.CurrentRegion.CreateGameKeepComponent(); gamecomponent.LoadFromDatabase(component, keep); keep.KeepComponents.Add(gamecomponent); } if (missingKeeps && log.IsWarnEnabled) { log.WarnFormat("Some keeps not found while loading components, possibly old/new keeptypes."); } if (m_keepList.Count != 0) { foreach (AbstractGameKeep keep in m_keepList.Values) { if (keep.KeepComponents.Count != 0) { keep.KeepComponents.Sort(); } } } LoadHookPoints(); log.Info("Loaded " + m_keepList.Count + " keeps successfully"); } if (ServerProperties.Properties.USE_KEEP_BALANCING) { UpdateBaseLevels(); } if (ServerProperties.Properties.USE_LIVE_KEEP_BONUSES) { KeepBonusMgr.UpdateCounts(); } return(true); }