private void LoadStatus(string sampleDataPath, TimeSpan offset) { var files = System.IO.Directory.GetFiles(sampleDataPath, "status-*.json"); foreach (var f in files) { var name = System.IO.Path.GetFileNameWithoutExtension(f).Replace("status-", ""); var statusJson = System.IO.File.ReadAllText(f); var curSt = (BlackMaple.MachineWatchInterface.CurrentStatus)JsonConvert.DeserializeObject( statusJson, typeof(BlackMaple.MachineWatchInterface.CurrentStatus), _jsonSettings ); curSt.TimeOfCurrentStatusUTC = curSt.TimeOfCurrentStatusUTC.Add(offset); foreach (var uniq in curSt.Jobs.Keys) { MockServerBackend.OffsetJob(curSt.Jobs[uniq], offset); } Statuses.Add(name, curSt); } string statusFromEnv = System.Environment.GetEnvironmentVariable("BMS_CURRENT_STATUS"); if (string.IsNullOrEmpty(statusFromEnv) || !Statuses.ContainsKey(statusFromEnv)) { CurrentStatus = Statuses.OrderBy(st => st.Key).First().Value; } else { CurrentStatus = Statuses[statusFromEnv]; } }
public void UpdateStatus(EDEvent edEvent) { if (Statuses != null) { if (Statuses.ContainsKey(edEvent.Commander)) { Statuses[edEvent.Commander].UpdateStatus(edEvent); if (StartTimeFromFirstWaypoint && !_firstWaypointPassed) { if (Statuses[edEvent.Commander].WaypointIndex > 0) { _firstWaypointPassed = true; Start = edEvent.TimeStamp; foreach (string commander in Statuses.Keys) { Statuses[commander].StartTime = Start; Statuses[commander].LapStartTime = Start; } } } if (!_commanderEventHistory.ContainsKey(edEvent.Commander)) { _commanderEventHistory.Add(edEvent.Commander, new List <EDEvent>()); } _commanderEventHistory[edEvent.Commander].Add(edEvent); } } }
public virtual bool RemoveStatus(string status) { if (Statuses.ContainsKey(status)) { var s = Statuses[status]; Statuses.Remove(status); s.OnRemove(this); if (s.SingleTarget) { s.Caster.SingleTargetSpells.Remove(status); } return(true); } return(false); }
public virtual bool AddStatus(string typeName, int rank = 0, int timeLeft = 0, Character caster = null, Character target = null, Dictionary <string, string> args = null, bool instantTick = false) { var s = GameServer.CreateSpell(typeName); if (s == null || Statuses.ContainsKey(s.StatusName)) { return(false); } if (s.RequiresCaster && caster == null) { return(false); } s.NextTick = DateTime.UtcNow.AddMilliseconds(s.Speed); if (timeLeft > 0) { s.TimeLeft = timeLeft; } if (rank > 0) { s.Rank = rank; } if (args != null) { s.Arguments = args; } s.Caster = caster; s.Target = target; Statuses.Add(s.StatusName, s); s.OnAdd(this); if (instantTick) { s.OnTick(this); } return(true); }
public RegisterData(SearchResultItem item) { Id = item.SystemID.ToString(); Name = item.RegisterItemName; Url = ItemUrl(item); Description = item.RegisterItemDescription; Type = item.Type; RegisterName = item.RegisterName; RegisterDescription = item.RegisterDescription; RegisterUrl = item.ParentRegisterUrl; Organization = item.organization; if (Helpers.CultureHelper.IsNorwegian() && Statuses.ContainsKey(item.RegisterItemStatus)) { Status = Statuses[item.RegisterItemStatus]; } else { Status = item.RegisterItemStatus; } }
public override void Update() { if (Alive && Chatter.Count > 0 && DateTime.UtcNow > NextChatter) { int index = ChatterIndex % Chatter.Count; ChatterIndex++; Say(Chatter[index], 0); NextChatter = DateTime.UtcNow.AddSeconds(Program.Random(60, 90)); } var statuses = new string[Statuses.Count]; Statuses.Keys.CopyTo(statuses, 0); foreach (var status in statuses) { if (Statuses.ContainsKey(status)) { var s = Statuses[status]; if (s.RequiresCaster && s.Caster == null) { RemoveStatus(status); } else if (DateTime.UtcNow > s.NextTick) { if (s.Channeled) { Channel(s); } else if (Alive || !s.OnlyTickAlive) { s.OnTick(this); if (s.SpellAnimation != 0 && !s.SingleAnimation) { SpellAnimation(s.SpellAnimation, 100); } } if (--s.TimeLeft < 1) { RemoveStatus(status); } s.NextTick = DateTime.UtcNow.AddMilliseconds(s.Speed); } } } var characters = new Character[ThreatMeter.Count]; ThreatMeter.Keys.CopyTo(characters, 0); foreach (var c in characters) { if (c == null || c.Dead || !WithinRange(c, 12)) { ThreatMeter.Remove(c); } } var enemies = new Character[Enemies.Count]; Enemies.CopyTo(enemies, 0); foreach (var e in enemies) { if (e == null || e.Dead || !WithinRange(e, 12)) { Enemies.Remove(e); } else { foreach (var m in e.Group.Members) { this.Enemies.Add(m); m.Enemies.Add(this); } } } if (SpawnControl != null && SpawnControl.SpecificTime && SpawnControl.SpawnTime != GameServer.Time && !Dead) { LifeStatus = LifeStatus.Dead; Experience = 0; } if (CurrentHP <= 0 && Alive) { if (ShouldComa) { CurrentHP = 1; AddStatus("Spell_Coma", 1, 20, this); } else { CurrentHP = 0; LifeStatus = LifeStatus.Dead; } } switch (LifeStatus) { case LifeStatus.Alive: { if (DateTime.UtcNow > NextTick) { if (IsHostile && Target == null) { var targets = from t in from obj in Map.Objects where obj is Character && WithinRange(obj, HostileRange) select obj as Character where t.Alive && AllegianceTo(t) == Allegiance.Enemy && !t.Hidden && !t.Stealth orderby Point.DistanceFrom(t.Point) ascending select t; if (targets.Count() > 0) { var target = targets.First(); Enemies.Add(target); target.Enemies.Add(this); target.Threaten(this, 1); } } UpdateTarget(); if (IsCasting) { OnTickCasting(); } else { OnTick(); } TickCount++; NextTick = DateTime.UtcNow.AddMilliseconds(TickSpeed); } } break; case LifeStatus.Coma: { if (DateTime.UtcNow > NextTick) { OnTickComa(); TickCount++; NextTick = DateTime.UtcNow.AddMilliseconds(TickSpeed); } } break; case LifeStatus.Dying: { if (DateTime.UtcNow > NextTick) { OnTickDying(); TickCount++; NextTick = DateTime.UtcNow.AddMilliseconds(TickSpeed); } } break; case LifeStatus.Dead: { #region Remove Statuses statuses = new string[Statuses.Count]; Statuses.Keys.CopyTo(statuses, 0); foreach (var s in statuses) { RemoveStatus(s); } #endregion #region Remove Threat characters = new Character[ThreatMeter.Count]; ThreatMeter.Keys.CopyTo(characters, 0); foreach (var c in characters) { ThreatMeter.Remove(c); } #endregion #region Remove Enemies enemies = new Character[Enemies.Count]; Enemies.CopyTo(enemies, 0); foreach (var e in enemies) { Enemies.Remove(e); e.Enemies.Remove(this); } #endregion #region Give EXP / Quest Kill double highestGroupValue = 0; double highestPlayerValue = 0; Group highestGroup = null; Player highestPlayer = null; var groups = new Dictionary <Group, double>(); foreach (var attacker in Attackers) { if (attacker.Key is Player) { var player = attacker.Key as Player; if (groups.ContainsKey(player.Group)) { groups[player.Group] += attacker.Value; } else { groups.Add(player.Group, attacker.Value); } if (groups[player.Group] > highestGroupValue) { highestGroup = player.Group; highestGroupValue = groups[player.Group]; } if (attacker.Value > highestPlayerValue) { highestPlayer = player; highestPlayerValue = attacker.Value; } } } foreach (var group in groups) { if (group.Value < MaximumHP * 0.15) { continue; } long averageLevel = 0; var players = new List <Player>(); foreach (var p in group.Key.Members) { if (p.WithinRange(this, 12) && p is Player) { averageLevel += p.Level; players.Add(p as Player); } } if (players.Count > 0) { averageLevel /= players.Count; } foreach (var p in players) { var difference = Math.Abs(averageLevel - Level); if (difference < 5) { var percent = 1.0 - difference * 0.125; if (Program.Random(100) < p.ExperienceBonusChance) { percent *= p.ExperienceBonus; p.SpellAnimation(341, 100); } p.RewardExperience((long)(Experience * percent)); } foreach (var q in p.Quests) { var qs = q.Value.QuestStep; foreach (var qo in qs.Objectives.Values) { if (qo.Type == QuestObjectiveType.Kill && qo.RequiredKilledTypes.Contains(GetType().Name)) { if (qo.GroupKill || p == highestPlayer) { p.AddQuestCount(q.Key, qo.Name); } } } } } } #endregion #region Close Dialogs foreach (Client c in GameServer.Clients) { if (c.Player != null && c.Player.DialogSession.GameObject == this && c.Player.DialogSession.IsOpen) { c.Player.DialogSession.IsOpen = false; c.Player.DialogSession.Dialog = null; c.Player.DialogSession.GameObject = null; c.Player.DialogSession.Map = null; c.Enqueue(Dialog.ExitPacket()); } } #endregion #region Loot if (SpawnControl != null || CanDropLootWithoutSpawn) { var chest = new Chest(); foreach (Loot loot in Loot) { if (Program.Random(loot.MaximumValue) < loot.MinimumValue) { int value; int index = Program.Random(loot.Items.Count); var item = loot.Items[index]; Item drop = null; if (int.TryParse(item, out value)) { drop = new Gold(value); GameServer.InsertGameObject(drop); } else { drop = GameServer.CreateItem(item); } if (drop != null) { if (drop.LootRollLength > 0 || drop.BindType != BindType.None) { var chestItem = new Chest.ChestItem(); chestItem.Item = drop; chest.Items.Add(chestItem); } else { if (highestGroup != null) { foreach (var member in highestGroup.Members) { drop.ProtectionOwners.Add(member.Name); } drop.ProtectionExpireTime = DateTime.UtcNow.AddSeconds(60); } Map.InsertCharacter(drop, Point); } } } } if (chest.Items.Count > 0 && highestGroup != null) { foreach (var member in highestGroup.Members) { chest.GUIDs.Add(member.GUID); } chest.Direction = Direction.South; GameServer.InsertGameObject(chest); Map.InsertCharacter(chest, Point); } } #endregion this.OnDeath(); this.OnDeath(highestPlayer); Map.RemoveCharacter(this); GameServer.RemoveGameObject(this); } break; } if (DateTime.UtcNow.Subtract(LastHpRegen).TotalSeconds > 1) { if (Alive && CurrentHP < MaximumHP && Target == null) { CurrentHP += (long)(MaximumHP * 0.10); if (CurrentHP > MaximumHP) { CurrentHP = MaximumHP; } } LastHpRegen = DateTime.UtcNow; } if (DateTime.UtcNow.Subtract(LastMpRegen).TotalSeconds > 1) { if (Alive && CurrentMP < MaximumMP && Target == null) { CurrentMP += (long)(MaximumMP * 0.10); if (CurrentMP > MaximumMP) { CurrentMP = MaximumMP; } } LastMpRegen = DateTime.UtcNow; } }
public Dictionary <string, string> ExportRaceStatisticsDict(int maxStatusLength = 40) { List <string> leaderBoard = RacePositions(); Dictionary <string, string> statsTable = new Dictionary <string, string>(); if (leaderBoard == null || leaderBoard.Count < 1) { return(statsTable); } StringBuilder status = new StringBuilder(); StringBuilder commandersExport = new StringBuilder(); StringBuilder positionsExport = new StringBuilder(); StringBuilder speeds = new StringBuilder(); StringBuilder altitudes = new StringBuilder(); StringBuilder maxSpeeds = new StringBuilder(); StringBuilder averageSpeeds = new StringBuilder(); StringBuilder distanceToWaypoint = new StringBuilder(); StringBuilder totalWaypointsVisited = new StringBuilder(); StringBuilder totalDistanceLeft = new StringBuilder(); StringBuilder hullStrengths = new StringBuilder(); StringBuilder pips = new StringBuilder(); StringBuilder shields = new StringBuilder(); StringBuilder cargoScoops = new StringBuilder(); StringBuilder currentLaps = new StringBuilder(); StringBuilder lapCounter = new StringBuilder(); StringBuilder lastLapTime = new StringBuilder(); StringBuilder fastestLapTime = new StringBuilder(); try { for (int i = 0; i < leaderBoard.Count; i++) { positionsExport.AppendLine((i + 1).ToString()); if (leaderBoard[i] == null) { leaderBoard[i] = "Unknown error"; } if (leaderBoard[i].Length > maxStatusLength) { commandersExport.AppendLine(leaderBoard[i].Substring(0, maxStatusLength)); } else { commandersExport.AppendLine(leaderBoard[i]); } if (Statuses != null && Statuses.ContainsKey(leaderBoard[i])) { if (this.Start > DateTime.MinValue) { maxSpeeds.AppendLine($"{Statuses[leaderBoard[i]].MaxSpeedInMS:F0}"); if (!Statuses[leaderBoard[i]].Eliminated && !Statuses[leaderBoard[i]].Finished) { averageSpeeds.AppendLine($"{Statuses[leaderBoard[i]].AverageSpeedInMS:F0}"); speeds.AppendLine($"{Statuses[leaderBoard[i]].SpeedInMS:F0}"); if (Statuses[leaderBoard[i]].Location != null) { altitudes.AppendLine($"{Statuses[leaderBoard[i]].Location.Altitude:F0}"); } else { altitudes.AppendLine($"0"); } } else { speeds.AppendLine(); altitudes.AppendLine(); averageSpeeds.AppendLine(); } } else { speeds.AppendLine(); altitudes.AppendLine(); averageSpeeds.AppendLine(); } lastLapTime.AppendLine(Statuses[leaderBoard[i]].LastLapTime().ToString(@"hh\:mm\:ss\:ff")); fastestLapTime.AppendLine(Statuses[leaderBoard[i]].FastestLapTime().ToString(@"hh\:mm\:ss\:ff")); totalWaypointsVisited.AppendLine(Statuses[leaderBoard[i]].NumberOfWaypointsVisited.ToString()); if (Statuses[leaderBoard[i]].Finished) { status.Append(CustomStatusMessages["Completed"]); status.AppendLine($" ({Statuses[leaderBoard[i]].FinishTime.Subtract(Start):hh\\:mm\\:ss})"); totalDistanceLeft.AppendLine("0"); distanceToWaypoint.AppendLine("0"); currentLaps.AppendLine(CustomStatusMessages["Completed"]); lapCounter.AppendLine(CustomStatusMessages["Completed"]); } else { string s; if (Statuses[leaderBoard[i]].Eliminated) { distanceToWaypoint.AppendLine("-"); totalDistanceLeft.AppendLine("-"); s = CustomStatusMessages["Eliminated"]; currentLaps.AppendLine(s); lapCounter.AppendLine(s); } else { distanceToWaypoint.AppendLine(Statuses[leaderBoard[i]].DistanceToWaypointInKmDisplay); totalDistanceLeft.AppendLine(Statuses[leaderBoard[i]].TotalDistanceLeftInKmDisplay); int lapNumber = Statuses[leaderBoard[i]].Lap; if (lapNumber < 1) { lapNumber = 1; } currentLaps.AppendLine(lapNumber.ToString()); lapCounter.AppendLine($"{lapNumber}/{Laps}"); s = Statuses[leaderBoard[i]].ToString(); } if (s.Length > maxStatusLength) { s = s.Substring(0, maxStatusLength); } status.AppendLine(s); } if (!Statuses[leaderBoard[i]].Eliminated) { hullStrengths.AppendLine(Statuses[leaderBoard[i]].HullDisplay); pips.AppendLine(String.Join(",", Statuses[leaderBoard[i]].Pips)); shields.AppendLine(Statuses[leaderBoard[i]].ShieldStatus()); cargoScoops.AppendLine(Statuses[leaderBoard[i]].CargoScoopStatus()); } else { hullStrengths.AppendLine(" "); pips.AppendLine(" "); shields.AppendLine(" "); cargoScoops.AppendLine(" "); } } else { // We don't have any statuses, so this is pre-race status.AppendLine(CustomStatusMessages["Ready"]); distanceToWaypoint.AppendLine("-"); totalDistanceLeft.AppendLine("-"); hullStrengths.AppendLine("-"); currentLaps.AppendLine("-"); } } } catch (Exception ex) { if (Log != null) { Log(ex.ToString()); } } statsTable.Add("RaceName", Name); statsTable.Add("Positions", positionsExport.ToString()); statsTable.Add("Commanders", commandersExport.ToString()); statsTable.Add("Speeds", speeds.ToString()); statsTable.Add("Altitudes", altitudes.ToString()); statsTable.Add("MaxSpeeds", maxSpeeds.ToString()); statsTable.Add("AverageSpeeds", averageSpeeds.ToString()); statsTable.Add("Status", status.ToString()); statsTable.Add("DistanceToWaypoint", distanceToWaypoint.ToString()); statsTable.Add("TotalWaypointsVisited", totalWaypointsVisited.ToString()); statsTable.Add("TotalDistanceLeft", totalDistanceLeft.ToString()); statsTable.Add("Hull", hullStrengths.ToString()); statsTable.Add("Pips", pips.ToString()); statsTable.Add("Shields", shields.ToString()); statsTable.Add("CargoScoops", cargoScoops.ToString()); if (NotableEvents != null) { statsTable.Add("NotableEvents", String.Join(Environment.NewLine, NotableEvents.EventQueue)); } if (Leader != null) { statsTable.Add("LeaderWaypoint", Leader.WaypointIndex.ToString()); } if (Laps > 0) { statsTable.Add("Lap", currentLaps.ToString()); statsTable.Add("LastLapTime", lastLapTime.ToString()); statsTable.Add("FastestLapTime", fastestLapTime.ToString()); statsTable.Add("LapCounter", lapCounter.ToString()); if (Leader != null) { int leaderLap = Leader.Lap; if (leaderLap < 1) { leaderLap = 1; } statsTable.Add("LeaderLap", leaderLap.ToString()); if (Leader.Finished) { statsTable.Add("LeaderLapCount", CustomStatusMessages["Completed"]); } else { statsTable.Add("LeaderLapCount", $"Lap {leaderLap}/{Laps}"); } } } return(statsTable); }
internal bool ContainsStatus(int id) { //if(st.GetHashCode()<=100) return(Statuses.ContainsKey(id)); }