Ejemplo n.º 1
0
    public static RollResult GetResultFromRoll(IAttacker attacker, IDefender defender, List <int> rolledFaceIndexAttack, List <int> rolledFaceIndexDefense)
    {
        var result = new RollResult();

        if (attacker != null)
        {
            var attackerDice = attacker.AttackDice;
            for (int i = 0; i < attackerDice.Count; ++i)
            {
                var face = attackerDice[i].GetFace(rolledFaceIndexAttack[i]);
                result.heart     += face.heart;
                result.surge     += face.surge;
                result.range     += face.range;
                result.pierce     = attacker.Pierce;
                result.bonusRange = attacker.RangeModifier;
                if (face.IsMiss)
                {
                    result.miss = true;
                }
            }
        }
        if (defender != null)
        {
            var defenderDice = defender.DefenseDice;
            for (int i = 0; i < defenderDice.Count; ++i)
            {
                result.defense += defenderDice[i].GetDefensePerFace(rolledFaceIndexDefense[i]);
            }
        }
        result.defense = Mathf.Max(0, result.defense);

        return(result);
    }
Ejemplo n.º 2
0
        public override void attack(IDefender DefenderVisitor)
        {
            int damage;

            damage = DefenderVisitor.Defend(this);
            this.GetDamage(damage);
        }
Ejemplo n.º 3
0
        public override void attack(IDefender DefenderVisitor)
        {
            int damage;

            damage = DefenderVisitor.Defend(this);

            GetDamage(Math.Max(1, (damage - Armor)));
        }
Ejemplo n.º 4
0
        private bool CalculateHit(IAttacker attacker, IDefender target)
        {
            int armorClass = target.GetArmorClass();
            int hitBonus = attacker.GetHitBonus();
            int roll = rng.RandiRange(1, 20);

            return (roll + hitBonus) >= armorClass;
        }
Ejemplo n.º 5
0
 public void ResolveAttack(IAttacker attacker, IDefender target)
 {
     bool hit = CalculateHit(attacker, target);
     if (hit)
     {
         int damage = CalculateDamage(attacker);
         target.TakeDamage(damage);
     }
 }
Ejemplo n.º 6
0
        public override void attack(IDefender DefenderVisitor)
        {
            int damage;

            damage = DefenderVisitor.Defend(this);
            if (damage != 0)
            {
                Speed++;
            }
            GetDamage(damage);
        }
Ejemplo n.º 7
0
        public override void Attacked(IDefender defender)
        {
            int damage = defender.Attack(this);

            if (damage > Armor)
            {
                damage -= Armor;
            }
            else if (damage > 0)
            {
                damage = 1; //in the .txt it says "but always at least 1 point", not sure if it refers to this
            }
            GetDamage(damage);
        }
        public static void Main()
        {
            SoldierList soldiers = new SoldierList();
            King        king     = new King(Console.ReadLine());

            string[] royalGuardNames = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var name in royalGuardNames)
            {
                RoyalGuard rg = new RoyalGuard(name);
                rg.SoldierDead += soldiers.HandleDeadSoldier;
                rg.SoldierDead += king.OnSoldierDeath;
                soldiers.Add(rg);
                king.KingAttacked += rg.OnKingAttack;
            }

            string[] footmanNames = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var name in footmanNames)
            {
                Footman fm = new Footman(name);
                fm.SoldierDead += soldiers.HandleDeadSoldier;
                fm.SoldierDead += king.OnSoldierDeath;
                soldiers.Add(fm);
                king.KingAttacked += fm.OnKingAttack;
            }

            string command = string.Empty;

            while ((command = Console.ReadLine()) != "End")
            {
                var tokens = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (tokens[0] == "Attack")
                {
                    king.RespondToAttack();
                }
                else if (tokens[0] == "Kill")
                {
                    string    name    = tokens[1];
                    IDefender soldier = soldiers.First(x => x.Name == name);
                    soldier.TakeAttack();
                }
            }
        }
Ejemplo n.º 9
0
        protected Int32 Dmg(IDefender Target)
        {
            Int32 TrueDmg = Dmg();

            if (Scale == Skills.Scale.Ap)
            {
                TrueDmg -= Target.Armor.Int();
            }
            else
            {
                TrueDmg -= Target.Barrier.Int();
            }

            if (TrueDmg < 0)
            {
                TrueDmg = 0;
            }

            return(TrueDmg);
        }
Ejemplo n.º 10
0
    public void Setup(IAttacker attacker, IDefender defender)
    {
        gameObject.SetActive(true);
        ResetResultsText();
        _attacker          = attacker;
        _textAttacker.text = "";
        if (_attacker != null)
        {
            if ((_attacker is ItemWeaponDef))
            {
                _textAttacker.text += Game.PlayerCharacter.name + " (" + _attacker.name + ")";
            }
            else
            {
                _textAttacker.text += _attacker.name;
            }
        }
        else
        {
            _textAttacker.text = "Manually roll attack dice for Attacker.";
        }
        UpdatePierce(_attacker);
        UpdateRangeModifier(_attacker);

        _defender          = defender;
        _textDefender.text = "";
        if (_defender != null)
        {
            _textDefender.text += _defender.name;
        }
        else
        {
            _textDefender.text = "Manually roll defense dice for Defender(s).";

            if (!(_attacker is MonsterDef.Properties))
            {
                _textDefender.text += "\n\n<b>Road to Legend</b>: When targeting multiple monsters, apply half damage (rounded up) to <u>additional</u> targets.";
            }
        }
        _textRange.transform.parent.gameObject.SetActive(_attacker != null && _attacker.AttackType == AttackType.Ranged);
    }
Ejemplo n.º 11
0
    public static RollResult CombatRoll(IAttacker attacker, IDefender defender, out List <int> rolledFaceIndexAttack, out List <int> rolledFaceIndexDefense)
    {
        rolledFaceIndexAttack  = new List <int>();
        rolledFaceIndexDefense = new List <int>();

        if (attacker != null)
        {
            var attackerDice = attacker.AttackDice;
            for (int i = 0; i < attackerDice.Count; ++i)
            {
                rolledFaceIndexAttack.Add(attackerDice[i].Roll());
            }
        }
        if (defender != null)
        {
            var defenderDice = defender.DefenseDice;
            for (int i = 0; i < defenderDice.Count; ++i)
            {
                rolledFaceIndexDefense.Add(defenderDice[i].Roll());
            }
        }

        return(GetResultFromRoll(attacker, defender, rolledFaceIndexAttack, rolledFaceIndexDefense));
    }
Ejemplo n.º 12
0
 public void AddDefender(IDefender def)
 {
     defenders.Add(def);
 }
Ejemplo n.º 13
0
 public override void Attacked(IDefender defender)
 {
     GetDamage(defender.Attack(this));
 }
Ejemplo n.º 14
0
 public abstract void attack(IDefender DefenderVisitor);
Ejemplo n.º 15
0
 public void RegisterObserver(IDefender battleObserver)
 {
     Observers.Add(battleObserver);
 }
Ejemplo n.º 16
0
 abstract public void Attacked(IDefender defender);
Ejemplo n.º 17
0
 public override void AttackedBy(IDefender defender)
 {
     //Console.WriteLine($"{defender.GetType()} {defender.Name} attacked {this.GetType()} {this.Name} ");
     defender.Attack(this);
 }
Ejemplo n.º 18
0
 public abstract void AttackedBy(IDefender defender);
Ejemplo n.º 19
0
 public override void AttackedBy(IDefender defender)
 {
     defender.Attack(this);
 }
 public SoldierArgs(IDefender soldier, KingUnderAttackEventHandler onKingAttack)
 {
     this.Soldier      = soldier;
     this.OnKingAttack = onKingAttack;
 }
Ejemplo n.º 21
0
 public void AddDefender(IDefender defender)
 {
     this.Defenders.Add(defender);
     this.AttackEvent += defender.RespondAttack;
 }
Ejemplo n.º 22
0
 public void AddDefender(IDefender defender)
 {
     this.Defenders.Add(defender);
     this.AttackEvent      += defender.RespondAttack;
     defender.DefenceEvent += this.OnDefenderDie;
 }
Ejemplo n.º 23
0
 public void UnregisterObserver(IDefender observer)
 {
     Observers.Remove(observer);
 }
Ejemplo n.º 24
0
 public void SetDefender(IDefender defender)
 {
     this.defender = defender;
 }