public void Callback(object custom) { foreach (IStronghold stronghold in strongholdManager.Where(s => s.StrongholdState == StrongholdState.Inactive && strongholdActivationCondition.ShouldActivate(s))) { locker.Lock(stronghold).Do(() => strongholdManager.Activate(stronghold)); } // Activate stronghold with highest score if there are no neutral strongholds var lastNeutralActivationTimeVar = systemVariableManager["Stronghold.neutral_check"]; var lastNeutralActivationTime = (DateTime)lastNeutralActivationTimeVar.Value; if (SystemClock.Now.Subtract(lastNeutralActivationTime).TotalHours >= 8) { if (strongholdManager.All(s => s.StrongholdState != StrongholdState.Neutral)) { var mapCenter = new Position(Config.map_width / 2, Config.map_height / 2); var stronghold = strongholdManager.Where(s => s.StrongholdState == StrongholdState.Inactive && s.NearbyCitiesCount > 0) .OrderByDescending(s => strongholdActivationCondition.Score(s)) .ThenBy(s => tileLocator.TileDistance(s.PrimaryPosition, 1, mapCenter, 1)) .FirstOrDefault(); // Do the same check for a SH but w/o nearby cities restriction if (stronghold == null) { stronghold = strongholdManager.Where(s => s.StrongholdState == StrongholdState.Inactive) .OrderByDescending(s => strongholdActivationCondition.Score(s)) .ThenBy(s => tileLocator.TileDistance(s.PrimaryPosition, 1, mapCenter, 1)) .FirstOrDefault(); } if (stronghold != null) { locker.Lock(stronghold).Do(() => strongholdManager.Activate(stronghold)); } } using (dbManager.GetThreadTransaction()) { lastNeutralActivationTimeVar.Value = SystemClock.Now; dbManager.Save(lastNeutralActivationTimeVar); } } Time = DateTime.UtcNow.Add(TimeSpan); scheduler.Put(this); }
private string CmdStrongholdActivate(Session session, string[] parms) { bool help = false; string strongholdName = string.Empty; try { var p = new OptionSet { { "?|help|h", v => help = true }, { "stronghold=", v => strongholdName = v.TrimMatchingQuotes() }, }; p.Parse(parms); } catch (Exception) { help = true; } if (help || string.IsNullOrEmpty(strongholdName)) { return("StrongholdActivate --stronghold=stronghold_name"); } IStronghold stronghold; if (!strongholdManager.TryGetStronghold(strongholdName, out stronghold)) { return("Stronghold not found"); } return(locker.Lock(stronghold).Do(() => { if (stronghold.StrongholdState != StrongholdState.Inactive) { return "Stronghold already active."; } strongholdManager.Activate(stronghold); return "OK!"; })); }