Example #1
0
        public bool Step()
        {
            // Check battle end conditions
            if (checkEnd())
            {
                Ended(this, EventArgs.Empty);
                return(false);
            }

            // Fill the turn queue and sort it by speed
            if (turnQueue.Count() == 0)
            {
                if (fighters.Count() == 0)
                {
                    return(true);
                }

                turnQueue = new Queue <Fighter>(fighters);
                turnQueue.OrderBy(fighter => fighter.Stats.Speed);
            }

            // Assign first fighter
            if (currentFighter == null)
            {
                currentFighter = turnQueue.Dequeue();
                currentFighter.PreStep();
            }
            else if (!currentFighter.IsAlive() || currentFighter.Step(this))
            {
                currentFighter = null;
            }

            return(false);
        }
        private void attack(Fighter target)
        {
            if (!target.IsAlive())
            {
                return;
            }

            // Calculate distance modifiers
            float modifier = 1.0f;

            // Get damage count
            int damage = Stats.Attack;

            if (next == this)
            {
                damage += Stats.Attack / 2;
            }

            // Fix this calculation later
            byte elements = (byte)(1 << (int)Style.AttackElement);

            foreach (Fighter c in children)
            {
                if (c != null && c.IsAlive())
                {
                    // Accumulate /something/
                    damage += c.Stats.Magic;

                    // Accumulate attack elements
                    elements |= (byte)(1 << (int)Style.AttackElement);
                }
            }

            // Apply damage modifier
            damage = (int)(damage * modifier);

            // Apply attack skill
            if (Style.AttackSkill != null)
            {
                damage = Style.AttackSkill.Apply(this, target, damage, elements);
            }

            // Unlink
            unlinkAll();

            // Notify observers
            Attacked(this, new FighterEventArgs {
                Target = target,
                Health = -damage
            });
        }
        private void attack(Fighter target)
        {
            if (!target.IsAlive()) {
                return;
            }

            // Calculate distance modifiers
            float modifier = 1.0f;

            // Get damage count
            int damage = Stats.Attack;
            if (next == this) {
                damage += Stats.Attack / 2;
            }

            // Fix this calculation later
            byte elements = (byte)(1 << (int)Style.AttackElement);
            foreach (Fighter c in children) {
                if (c != null && c.IsAlive()) {
                    // Accumulate /something/
                    damage += c.Stats.Magic;

                    // Accumulate attack elements
                    elements |= (byte)(1 << (int)Style.AttackElement);
                }
            }

            // Apply damage modifier
            damage = (int)(damage * modifier);

            // Apply attack skill
            if (Style.AttackSkill != null) {
                damage = Style.AttackSkill.Apply(this, target, damage, elements);
            }

            // Unlink
            unlinkAll();

            // Notify observers
            Attacked(this, new FighterEventArgs {
                Target = target,
                Health = -damage
            });
        }