/// <summary> /// /// </summary> public void UpdateGame() { if (!_mapConsole.IsVisible || LastUpdate.Add(GameSpeed) >= DateTime.Now) { return; } LastUpdate = DateTime.Now; // next frame if (Adventure.AdventureLogs.Count == 0 && Adventure.HasNextFrame()) { Adventure.NextFrame(); } if (!Adventure.AdventureLogs.TryDequeue(out AdventureLog adventureLog)) { GameSpeed = TimeSpan.Zero; return; } if (_mogwai.CombatState != CombatState.None) { // combat gamespeed GameSpeed = CombatActionDelay; } else { // gamespeed of unseen entities have no delay GameSpeed = _mogwai.CanSee(Adventure.Map.Entities.FirstOrDefault(p => p.AdventureEntityId == adventureLog.Source)) ? ActionDelay : TimeSpan.Zero; } // redraw map DrawExploMap(); //DrawMap(); adventureLog.SourceFovCoords?.ToList().ForEach(p => _mapConsole[p.X, p.Y].Background = Color.Lerp(Color.Yellow, Color.Black, 0.50f)); // stats _statsConsole.Print(2, 0, Adventure.GetRound.ToString().PadLeft(4), Color.Gold); _statsConsole.Print(2, 1, Adventure.AdventureStats[AdventureStats.Explore].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 2, Adventure.AdventureStats[AdventureStats.Monster].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 3, Adventure.AdventureStats[AdventureStats.Boss].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 4, Adventure.AdventureStats[AdventureStats.Treasure].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 5, Adventure.AdventureStats[AdventureStats.Portal].ToString("0%").PadLeft(4), Color.Gold); switch (adventureLog.Type) { case LogType.Info: //Adventure.Enqueue(AdventureLog.Info(this, target, ActivityLog.Create(ActivityLog.ActivityType.Attack, ActivityLog.ActivityState.Success, new int[] { damage, criticalDamage, (int)DamageType.Weapon }, weaponAttack))); var source = Adventure.Entities[adventureLog.Source]; var target = Adventure.Entities[adventureLog.Target]; var message = ""; var activityLog = adventureLog.ActivityLog; switch (activityLog.Type) { case ActivityLog.ActivityType.Cast: var spell = activityLog.ActivityObject as Spell; message = $"{Coloring.Name(source.Name)} cast " + $"{Coloring.Violet(spell.Name)} on {Coloring.Name(target.Name)} roll " + $"{activityLog.Numbers[0].ToString()}:"; switch (activityLog.State) { case ActivityLog.ActivityState.Success: message = $"{message} {Coloring.Green("success")}!"; break; case ActivityLog.ActivityState.Fail: message = $"{message} {Coloring.Red("failed")}!"; break; case ActivityLog.ActivityState.Init: message = $"{Coloring.Name(source.Name)} starting to cast {Coloring.Violet(spell.Name)}."; break; } break; case ActivityLog.ActivityType.Attack: var weaponAttack = activityLog.ActivityObject as WeaponAttack; message = $"{Coloring.Name(source.Name)} [{Coloring.Orange(activityLog.Numbers[0].ToString())}] " + $"{weaponAttack.GetType().Name.ToLower()}[{Coloring.Gainsboro(weaponAttack.ActionType.ToString().Substring(0, 1))}] " + $"{Coloring.Name(target.Name)} with {Coloring.DarkName(weaponAttack.Weapon.Name)} roll " + $"{Coloring.Attack(activityLog.Numbers[2] > 0 ? "critical" : activityLog.Numbers[1].ToString())}:"; switch (activityLog.State) { case ActivityLog.ActivityState.Success: message = $"{message} {Coloring.Green("hit for")} {Coloring.DoDmg(activityLog.Numbers[3])}[{activityLog.Numbers[4]}] {Coloring.Green("damage!")}"; break; case ActivityLog.ActivityState.Fail: message = $"{message} {Coloring.Red("failed")}!"; break; case ActivityLog.ActivityState.Init: message = $"{Coloring.Name(source.Name)} [{Coloring.Orange(activityLog.Numbers[0].ToString())}]: Initiating Attack"; break; } break; case ActivityLog.ActivityType.Heal: message = $"{Coloring.Name(source.Name)} restores {Coloring.GetHeal(activityLog.Numbers[0])} HP from {((HealType)activityLog.Numbers[1]).ToString()} healing."; break; case ActivityLog.ActivityType.Damage: message = $"{Coloring.Name(source.Name)} suffers {Coloring.GetDmg(activityLog.Numbers[0])} HP from {((DamageType)activityLog.Numbers[1]).ToString()} damage."; break; case ActivityLog.ActivityType.HealthState: var healthState = (HealthState)activityLog.Numbers[0]; switch (healthState) { case HealthState.Dead: message = $"{Coloring.Name(source.Name)} has died, may its soul rest in peace. Its health state is {Coloring.Red(healthState.ToString())}."; break; case HealthState.Dying: message = $"{Coloring.Name(source.Name)} got a deadly hit, health state is {Coloring.Red(healthState.ToString())}."; break; case HealthState.Disabled: message = $"{Coloring.Name(source.Name)} got a deadly hit, health state is {Coloring.Red(healthState.ToString())}."; break; } break; case ActivityLog.ActivityType.Loot: message = $"{Coloring.Name(source.Name)} is looting {Coloring.DarkGrey(target.Name)}."; break; case ActivityLog.ActivityType.Treasure: if (activityLog.State == ActivityLog.ActivityState.Success) { message = $"{Coloring.DarkGrey(_mogwai.Name)} found a treasure!"; } else { message = $"{Coloring.DarkGrey(_mogwai.Name)} found nothing!"; } break; case ActivityLog.ActivityType.Gold: message = $"{Coloring.DarkGrey(_mogwai.Name)} got {Coloring.Gold(activityLog.Numbers[0])} gold"; break; case ActivityLog.ActivityType.LevelClass: message = Coloring.LevelUp($"You feel the power of the {((ClassType)activityLog.Numbers[0])}'s!"); break; case ActivityLog.ActivityType.Exp: message = activityLog.ActivityObject == null ? $"You just earned +{Coloring.Exp(activityLog.Numbers[0])} experience!" : $"The {Coloring.Name((activityLog.ActivityObject as Monster).Name)} gave you +{Coloring.Exp(activityLog.Numbers[0])}!"; break; case ActivityLog.ActivityType.Level: message = $"{Coloring.LevelUp("Congratulations he just made the")} {Coloring.Green(activityLog.Numbers[0].ToString())} {Coloring.LevelUp("th level!")}"; break; } ((PlayScreen)Parent).PushLog(LogType.Info, message); break; case LogType.Move: MoveEntity(_entities[adventureLog.Source], adventureLog.TargetCoord); break; case LogType.Attack: AttackEntity(_entities[adventureLog.Target], adventureLog.TargetCoord); break; case LogType.Died: DiedEntity(_entities[adventureLog.Source]); break; case LogType.Entity: break; default: throw new ArgumentOutOfRangeException(); } foreach (AdventureEntity entity in Adventure.Map.Entities) { if (entity.IsStatic) { continue; } ConsoleEntity consoleEntity = _entities[entity.AdventureEntityId]; consoleEntity.IsVisible = (_mogwai.CanSee(entity) || entity is Combatant combatant && combatant.IsDead) && _mapConsole.ViewPort.Contains(consoleEntity.Position); } }
/// <summary> /// /// </summary> public void UpdateGame() { if (!_mapConsole.IsVisible || LastUpdate.Add(GameSpeed) >= DateTime.Now) { return; } LastUpdate = DateTime.Now; // next frame if (Adventure.AdventureLogs.Count == 0 && Adventure.HasNextFrame()) { Adventure.NextFrame(); } if (!Adventure.AdventureLogs.TryDequeue(out var adventureLog)) { GameSpeed = TimeSpan.Zero; return; } if (_mogwai.CombatState != CombatState.None) { // combat gamespeed GameSpeed = CombatActionDelay; } else { // gamespeed of unseen entities have no delay GameSpeed = _mogwai.CanSee(Adventure.Map.Entities.FirstOrDefault(p => p.AdventureEntityId == adventureLog.Source)) ? ActionDelay : TimeSpan.Zero; } while (Adventure.LogEntries.TryDequeue(out var logEntry)) { if (logEntry.LogType != LogType.AdventureLog) { ((PlayScreen)Parent).PushLog(logEntry); } } // redraw map DrawExploMap(); //DrawMap(); adventureLog.SourceFovCoords?.ToList().ForEach(p => _mapConsole[p.X, p.Y].Background = Color.Lerp(Color.Yellow, Color.Black, 0.50f)); // stats _statsConsole.Print(2, 0, Adventure.GetRound.ToString().PadLeft(4), Color.Gold); _statsConsole.Print(2, 1, Adventure.AdventureStats[AdventureStats.Explore].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 2, Adventure.AdventureStats[AdventureStats.Monster].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 3, Adventure.AdventureStats[AdventureStats.Boss].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 4, Adventure.AdventureStats[AdventureStats.Treasure].ToString("0%").PadLeft(4), Color.Gold); _statsConsole.Print(2, 5, Adventure.AdventureStats[AdventureStats.Portal].ToString("0%").PadLeft(4), Color.Gold); switch (adventureLog.Type) { case AdventureLog.LogType.Info: break; case AdventureLog.LogType.Move: MoveEntity(_entities[adventureLog.Source], adventureLog.TargetCoord); break; case AdventureLog.LogType.Attack: AttackEntity(_entities[adventureLog.Target], adventureLog.TargetCoord); break; case AdventureLog.LogType.Died: DiedEntity(_entities[adventureLog.Source]); break; case AdventureLog.LogType.Entity: break; default: throw new ArgumentOutOfRangeException(); } foreach (var entity in Adventure.Map.Entities) { if (entity.IsStatic) { continue; } ConsoleEntity consoleEntity = _entities[entity.AdventureEntityId]; consoleEntity.IsVisible = (_mogwai.CanSee(entity) || entity is Combatant combatant && combatant.IsDead) && _mapConsole.ViewPort.Contains(consoleEntity.Position); } }