private void SetupUnitTurn(ref TurnBasedCharacterTemplate template) { if (template.TurnBased.InitiativeRoll < 0) { template.TurnBased.InitiativeRoll = RulesSystem.CalculateD20Roll(1); template.TurnBased.InitiativeStatBonus = RulesSystem.CalculateStatsWithLog(template.Stats.Get(Stats.Dexterity), (int)template.Stats.GetValue(Stats.Level)); var resultEvent = World.Get <RulesSystem>().Post(new RollInitiativeEvent(template, template.TurnBased.InitiativeRoll, template.TurnBased.InitiativeStatBonus)); template.TurnBased.InitiativeStatBonus = resultEvent.Bonus; var logSystem = World.Get <GameLogSystem>(); logSystem.StartNewMessage(out var logMsg, out var hoverMsg); logMsg.Append(template.GetName()); logMsg.Append(" initiative: "); logMsg.Append(resultEvent.Total); logMsg.Append(" "); hoverMsg.AppendNewLine(RulesSystem.LastQueryString.ToString()); logSystem.PostCurrentStrings(GameLogSystem.NormalColor); } else { template.TurnBased.InitiativeStatBonus = RulesSystem.CalculateStatsWithLog(template.Stats.Get(Stats.Dexterity), (int)template.Stats.GetValue(Stats.Level)); var resultEvent = World.Get <RulesSystem>().Post(new RollInitiativeEvent(template, template.TurnBased.InitiativeRoll, template.TurnBased.InitiativeStatBonus)); template.TurnBased.InitiativeStatBonus = resultEvent.Bonus; } template.TurnBased.StandardActions = 1; template.TurnBased.MinorActions = 1; template.TurnBased.MoveActions = 1; template.TurnBased.TurnNumber = TurnNumber; }
public void CommandComplete(TurnBasedCharacterTemplate template) { if (template == null || template.TurnBased.ActionPoints == 0) { if (_current != null) { _current.Entity.Post(new EndTurnEvent(_current.Entity)); if (_current.IsPlayer()) { World.Get <PlayerTurnBasedSystem>().TurnEnd(_current); } else { World.Get <NpcTurnBasedSystem>().TurnEnd(_current); } } _turnTemplates.Run(_findCurrentFastest); if (_current == null) { NewTurn(); } } else { if (_current != template) { _current = template; StartTurn(); } else { RunTurn(); } } }
private void FindCurrent(ref TurnBasedCharacterTemplate template) { if (template.TurnBased.TurnNumber != TurnNumber) { SetupUnitTurn(ref template); } if (template.TurnBased.ActionPoints <= 0) { return; } if (_current == null || template.TurnBased.Speed > _current.TurnBased.Speed) { _current = template; } }
public static T GetCommand <T>(TurnBasedCharacterTemplate character) where T : Command, new() { var type = typeof(T); if (!_commandPool.TryGetValue(type, out var queue)) { queue = new Queue <Command>(); _commandPool.Add(type, queue); } T cmd; if (queue.Count == 0) { cmd = new T(); } else { cmd = (T)queue.Dequeue(); } cmd.Owner = character; return(cmd); }