Example #1
0
 public CombatActionQueueItem(ICombatAction action, SimpleChar target, bool shouldSetTarget, double timeoutOffset = 1)
 {
     CombatAction    = action;
     Target          = target;
     ShouldSetTarget = shouldSetTarget;
     Timeout         = Time.NormalTime + timeoutOffset;
 }
        public override void OnWhen()
        {
            base.OnWhen();

            _monster.SetTargetStrategy(new RandomTargetStrategy());
            _action = _monster.GetCombatAction(_players.Cast<ICombatMember>());
        }
        public override void OnWhen()
        {
            base.OnWhen();

            _monster.SetCombatActionStrategy(new RegularAttackStrategy());
            _action = _monster.GetCombatAction(_players.Cast<ICombatMember>());
        }
Example #4
0
 //Returns the index number of the action (used above)
 public int registerAction(ICombatAction action)
 {
     if (this._combatActions.Contains(action))
         throw new ArgumentException("The Action is already registered with this character");
     this._combatActions.Add(action);
     return this._combatActions.Count - 1;
 }
Example #5
0
        public List <IAction> Update(IAction action)
        {
            if (!(action is ICombatAction))
            {
                return(new List <IAction>());
            }
            ICombatAction combatAction = (ICombatAction)action;

            return(Update(combatAction));
        }
Example #6
0
 public void ResetUnitState()
 {
     FinalizedFight        = null;
     PendingAction         = null;
     CurrentMovementPath   = null;
     SelectedCombatant     = null;
     AvailableActions      = null;
     FightForecast         = null;
     SelectedAttackTarget  = null;
     EventsThisActionPhase = new List <string>();
 }
Example #7
0
        public void SubmitAction(ICombatAction action)
        {
            var validationError = action.GetValidationError(_currentTurn);

            if (validationError != null)
            {
                throw new InvalidActionException(validationError);
            }

            action.Perform(_currentTurn);
        }
Example #8
0
 private void AnimateAction(ICombatAction action)
 {
     if (action is MoveAction)
     {
         var move = action as MoveAction;
         StartCoroutine(AnimateMove(move));
     }
     else if (action is FightAction)
     {
         var fight = action as FightAction;
         StartCoroutine(AnimateFight(fight));
     }
 }
Example #9
0
        private List <IAction> Update(ICombatAction action)
        {
            List <IAction> results = new List <IAction>();

            results.Add(action);
            action.CalculateEffect();
            if (action.EndsEntityTurn())
            {
                _entityTurn++;
                if (isEnemyTurn())
                {
                    foreach (ICombatAIEntity enemy in EnemyTeam)
                    {
                        ICombatAction enemyAction = enemy.CombatAIComponent.GenerateCombatAction(enemy, PlayerTeam);
                        enemyAction.CalculateEffect();
                        results.Add(enemyAction);
                    }
                    _entityTurn = 0;
                }
            }
            return(results);
        }
Example #10
0
 public void ApplyPlayerAction(ICombatAction combatAction)
 {
     combatAction.Execute(_dice, CombatContext.Player, CombatContext.Monster, CombatContext.CombatLog);
     _hasPlayerActionBeenApplied = true;
 }
Example #11
0
        private async Task Encounter_ActionExecuted(IEncounter encounter, ICombatAction action)
        {
            // this whole thing can be optimized to send way smaller replacement segments later

            var combatView = MudLikeOperationBuilder.Start($"enc_{encounter.Id}")
                             .StartContainer($"enc_{encounter.Id}")
                             .AddTextLine("");

            var gridEncounter = (GridEncounter)encounter;
            var entityAction  = (GridTargetAction)action;

            //var dmgDone = encounter.ActionLog.Select((a) => (ICombatAction<GridEntity>)a)
            //      .GroupBy(a => new { a.SourceEntity })
            //      .Select(a => new { Attacker = a.Key.SourceEntity, Damage = a.Sum(s => s.DamageDone) })
            //  .ToList();

            //var dmgTaken = encounter.ActionLog.Select((a) => (GridSingleTargetAction)a)
            //                            .GroupBy(a => new { a.TargetEntity })
            //                            .Select(a => new { Attacked = a.Key.TargetEntity, Damage = a.Sum(s => s.DamageDone) })
            //                        .ToList();

            foreach (var factionName in gridEncounter.Factions.Keys)
            {
                var factionEntities = gridEncounter.Factions[factionName];


                foreach (var entity in factionEntities)
                {
                    combatView
                    .AddText(entity.Name, (entity.IsAlive && !encounter.Dead.Contains(entity) ? TextColor.Normal : TextColor.Red));
                    if (entity.IsAlive && !encounter.Dead.Contains(entity))
                    {
                        combatView
                        .AddText($" {entity.Stats.FirstOrDefault(s => s.Name == "health")?.Value}", TextColor.Green)
                        .AddText($" {entity.Stats.FirstOrDefault(s => s.Name == "mana")?.Value}", TextColor.Blue)
                        .AddText($" {entity.Stats.FirstOrDefault(s => s.Name == "stamina")?.Value}", TextColor.Yellow)
                        ;
                    }
                    else
                    {
                        combatView.AddText(" Dead", TextColor.Red, TextSize.Small);
                    }

                    //var entityDmgDone = dmgDone.FirstOrDefault(d => d.Attacker == entity);
                    //if (entityDmgDone != null)
                    //{
                    //    combatView
                    //        .AddText($" Dmg {entityDmgDone.Damage}", TextColor.Teal);
                    //    ;
                    //}
                    //var entityDmgTaken = dmgTaken.FirstOrDefault(d => d.Attacked == entity);
                    //if (entityDmgTaken != null)
                    //{
                    //    combatView
                    //        .AddText($" Taken {entityDmgTaken.Damage}", TextColor.Teal);
                    //    ;
                    //}

                    combatView.AddLineBreak();
                }

                combatView.AddTextLine("---------------------------");
            }


            // add last X actions
            var actions = encounter.ActionLog.OrderByDescending(a => a.ExecutedTime).Take(10).OrderBy(a => a.ExecutedTime).ToList();

            actions.ForEach((a) => a.AppendToOperation(combatView));

            combatView.EndContainer($"enc_{encounter.Id}");

            var view = MudLikeViewBuilder.Start()
                       .AddOperation(combatView.Build()
                                     ).Build();


            if (entityAction.TargetEntities.Contains(entityAction.SourceEntity) || entityAction.TargetEntities.Count == 0)
            {
                await Game.Network.SendViewCommandsToMapAsync(entityAction.SourceEntity.Map, view);
            }
            else
            {
                var maps = new List <IMap>()
                {
                    entityAction.SourceEntity.Map
                };
                maps.AddRange(entityAction.TargetEntities.Where(t => t.Map != entityAction.SourceEntity.Map).Select(t => t.Map).Distinct());

                maps.ForEach(async m => await Game.Network.SendViewCommandsToMapAsync(m, view));
            }
        }
Example #12
0
 public PlayerActionMessage(IPlayerCombatMember player,
                            ICombatAction action)
 {
     Player = player;
     Action = action;
 }
Example #13
0
 public Move(float duration, [NotNull] ICombatAction finishAction)
 {
     Duration     = duration;
     StartAction  = null;
     FinishAction = finishAction ?? throw new ArgumentNullException(nameof(finishAction));
 }
        public override void OnWhen()
        {
            base.OnWhen();

            _action = new RegularAttackStrategy().GetCombatAction(null);
        }
 public GenericEntityIntelligence(List <ICombatAction> actions, ICombatAction defaultAction)
 {
     _actions       = actions.Select(a => (GridTargetAction)a).ToList();
     _defaultAction = (GridTargetAction)defaultAction;
 }