public IMediatorCommand UndoLastCommand()
        {
            IMediatorCommand command = _history.Pop();

            base.Undo(command);
            return(command);
        }
        public override ValidableResponse <NoResponse> Execute(IMediatorCommand command)
        {
            CastSpellCommand _command = base.cast_command(command);
            PlayableEntity   caster   = fighterProvider.Value.GetFighterByDisplayName(_command.CasterName);

            if (spellLevelSelected(_command) == false)
            {
                return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse));
            }
            if (targetsSelected(_command) == false)
            {
                return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse));
            }

            if (_command.Spell.IsAnAttack)
            {
                if (castAttackSpell(_command) == false)
                {
                    return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse));
                }
            }
            else
            {
                if (castNonAttackSpell(_command) == false)
                {
                    return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse));
                }
            }

            return(new ValidableResponse <NoResponse>(true, MediatorCommandResponses.NoResponse));
        }
Esempio n. 3
0
        public override NoResponse Execute(IMediatorCommand command)
        {
            HealCommand    _command = this.cast_command(command);
            PlayableEntity target   = _command.GetEntity();

            if (_command.Amount < 0)
            {
                Console.WriteLine($"WARNING : Trying to heal {target.DisplayName} for {_command.Amount}, will be set to 0 instead");
                _command.Amount = 0;
            }

            console.Value.AddEntry($"{target.DisplayName} regains {_command.Amount} HPs.\r\n", fontWeightProvider.Value.Bold);

            _command.From = target.Hp;

            if (target.Hp + _command.Amount > target.MaxHp)
            {
                target.Hp = (int)target.MaxHp;
            }
            else
            {
                target.Hp += _command.Amount;
            }

            _command.To = target.Hp;
            return(MediatorCommandResponses.NoResponse);
        }
 protected TCommand cast_command(IMediatorCommand command)
 {
     if (command is TCommand _command)
     {
         return(_command);
     }
     Console.WriteLine($"ERROR : Wrong kind of command recieved for the MediatorHandler {this.GetType()}");
     throw new InvalidOperationException($"Wrong kind of command recieved for the MediatorHandler {this.GetType()}");
 }
Esempio n. 5
0
        public override ApplyDamageResultListResponse Execute(IMediatorCommand command)
        {
            ApplyDamageResultListCommand _command = base.cast_command(command);

            if (false == _command.DamageList.Any())
            {
                return(null);
            }

            PlayableEntity target = _command.GetEntity();
            int            total  = 0;

            console.Value.AddEntry($"{target.DisplayName}", fontWeightProvider.Value.Bold);
            console.Value.AddEntry(" takes ");

            int i = 1;

            foreach (Damage damage in _command.DamageList)
            {
                int final_damage = damage.RawAmount;

                if (final_damage < 0)
                {
                    Console.WriteLine($"WARNING : Trying to inflict {final_damage} damage on {target.DisplayName}," +
                                      $" will be treated as 0.");
                    final_damage = 0;
                }

                applyDamageAffinity(ref final_damage, damage.TypeAffinity);

                if (_command.LastSavingWasSuccessfull)
                {
                    applySavingModifier(ref final_damage, damage.SavingModifer);
                }

                total += final_damage;

                if (i == _command.DamageList.Count && i != 1)
                {
                    console.Value.AddEntry("and ");
                }
                console.Value.AddEntry($"{final_damage} {damage.Type}", fontWeightProvider.Value.Bold, colorProvider.Value.GetColorByKey(damage.Type.ToString()));
                console.Value.AddEntry($"{(i == _command.DamageList.Count ? " damage" : " damage, ")}");

                i += 1;
            }
            console.Value.AddEntry("\r\n");

            TakeDamageCommand inner_command = new TakeDamageCommand(target, total);

            base._mediator.Value.Execute(inner_command);
            _command.AddToInnerCommands(inner_command);

            return(new ApplyDamageResultListResponse(total));
        }
Esempio n. 6
0
        public override NoResponse Execute(IMediatorCommand command)
        {
            ApplyHitAttackResultCommand _command = base.cast_command(command);

            if (_command.HitAttackResult.RollResult.Hits)
            {
                apply_damage(_command);

                apply_on_hit(_command);
            }

            return(MediatorCommandResponses.NoResponse);
        }
Esempio n. 7
0
        public override void Undo(IMediatorCommand command)
        {
            HealCommand _command = this.cast_command(command);

            if (false == _command.To.HasValue || false == _command.From.HasValue)
            {
                Console.WriteLine($"ERROR : Trying to undo a {this.GetType()} command that was not executed first");
                throw new NullReferenceException($"Trying to undo a {this.GetType()} command that was not executed first");
            }

            PlayableEntity target = _command.GetEntity();

            target.Hp = _command.From.Value;
        }
        public override ValidableResponse <TOutput> Execute(IMediatorCommand command)
        {
            Window window = HandlerToUILinker.GetWindow(this.GetType()) as Window;
            IResultWindow <TInput, TOutput> result_window = window as IResultWindow <TInput, TOutput>;
            TInput _command = base.cast_command(command);

            result_window.LoadContext(_command);

            window.ShowCentered();

            return(new ValidableResponse <TOutput>(
                       result_window.Validated,
                       result_window.GetResult()));
        }
Esempio n. 9
0
        protected IMediatorHandler get_handler_from_command(IMediatorCommand command)
        {
            KeyValuePair <Type, IMediatorHandler> pair = _handlerCommandBinding.FirstOrDefault(x => x.Key == command.GetType());

            if (pair.Key == null)
            {
                Console.WriteLine("ERROR : trying to handle a command that was not detected by BaseMediator");
                throw new NullReferenceException("Trying to handle a command that was not detected by BaseMediator");
            }
            if (pair.Value == null)
            {
                Console.WriteLine("ERROR : trying to handle a command that has no corresponding Handler in BaseMediator");
                throw new NullReferenceException("Trying to handle a command that has no corresponding Handler in BaseMediator");
            }
            return(pair.Value);
        }
        public override NoResponse Execute(IMediatorCommand command)
        {
            TempHealCommand _command = this.cast_command(command);
            PlayableEntity  target   = _command.GetEntity();

            console.Value.AddEntry($"{target.DisplayName} regains {_command.Amount} temporary HPs.\r\n", fontWeightProvider.Value.Bold);

            _command.From = target.TempHp;

            if (_command.Amount > target.TempHp)
            {
                target.TempHp = _command.Amount;
            }

            _command.To = target.TempHp;
            return(MediatorCommandResponses.NoResponse);
        }
Esempio n. 11
0
        public override NoResponse Execute(IMediatorCommand command)
        {
            LooseHpCommand _command = this.cast_command(command);
            PlayableEntity target   = _command.GetEntity();

            console.Value.AddEntry($"{target.DisplayName} looses {_command.Amount} HPs.\r\n", fontWeightProvider.Value.Bold);

            _command.From = target.Hp;

            target.Hp -= _command.Amount;
            if (target.Hp < 0)
            {
                target.Hp = 0;
            }

            _command.To = target.Hp;
            return(MediatorCommandResponses.NoResponse);
        }
Esempio n. 12
0
        public override NoResponse Execute(IMediatorCommand command)
        {
            LooseTempHpCommand _command = this.cast_command(command);
            PlayableEntity     target   = _command.GetEntity();

            console.Value.AddEntry($"{target.DisplayName} looses {_command.Amount} temporary HPs.\r\n", fontWeightProvider.Value.Bold);

            _command.From = target.TempHp;

            target.TempHp -= _command.Amount;
            if (target.TempHp < 0)
            {
                throw new InvalidOperationException($"WARNING : Trying to remove more TempHps than what {target.DisplayName} has. TempsHps will be set to 0");
            }

            _command.To = target.TempHp;
            return(MediatorCommandResponses.NoResponse);
        }
Esempio n. 13
0
        public override NoResponse Execute(IMediatorCommand command)
        {
            TakeDamageCommand _command = base.cast_command(command);

            if (_command.Amount == 0)
            {
                return(MediatorCommandResponses.NoResponse);
            }

            PlayableEntity target    = _command.GetEntity();
            int            remaining = _command.Amount;

            console.Value.AddEntry($"Total: {remaining} Damages\r\n", fontWeightProvider.Value.Bold);

            if (target.TempHp != 0)
            {
                remaining = handleTempHp(_command, target, remaining);
            }
            handleHp(_command, target, remaining);
            return(MediatorCommandResponses.NoResponse);
        }
Esempio n. 14
0
        public IMediatorCommandResponse Execute(IMediatorCommand command)
        {
            IMediatorHandler handler = get_handler_from_command(command);

            return(handler.Execute(command));
        }
 public abstract void Undo(IMediatorCommand command);
 public override void Undo(IMediatorCommand command)
 {
     // undoing a user input won't do much
 }
 IMediatorCommandResponse IMediatorHandler.Execute(IMediatorCommand command)
 {
     return(this.Execute(command));
 }
 public abstract TResponse Execute(IMediatorCommand command);
 public void AddToHistory(IMediatorCommand command)
 {
     base.Execute(command);
     _history.Push(command);
 }
 public void AddToInnerCommands(IMediatorCommand command)
 {
     InnerCommands.Push(command);
 }
Esempio n. 21
0
        public void Undo(IMediatorCommand command)
        {
            IMediatorHandler handler = get_handler_from_command(command);

            handler.Undo(command);
        }