Ejemplo n.º 1
0
        public Ally(BattleState battle, int index, int e)
            : base(battle)
        {
            _c = battle.Party[index];

            // the (index * 1) is for separation for targeting purposes.
            _x = (index * 1) + (_c.BackRow ? X_BACK_ROW : X_FRONT_ROW);
            _y = (index * 1) + y0 + (index * ys);

            GetMagicSpells();
            GetSummons();

            if (HP == 0)
            {
                Kill();
            }

            V_Timer   = new BattleClock(battle.SpeedValue * 2);
            TurnTimer = new AllyTurnTimer(this, e);

            PrimaryAttack   = new WeaponAttack(this);
            PrimaryAttackX2 = new WeaponAttack(this, 2);
            PrimaryAttackX4 = new WeaponAttack(this, 4);
        }
Ejemplo n.º 2
0
        public Ally(BattleState battle, int index, int e)
            : base(battle)
        {
            _c = battle.Party[index];

            // the (index * 1) is for separation for targeting purposes.
            _x = (index * 1) + (_c.BackRow ? X_BACK_ROW : X_FRONT_ROW);
            _y = (index * 1) + y0 + (index * ys);

            GetMagicSpells();
            GetSummons();

            if (HP == 0)
            {
                Kill();
            }

            V_Timer = new BattleClock(battle.SpeedValue * 2);
            TurnTimer = new AllyTurnTimer(this, e);

            PrimaryAttack = new WeaponAttack(this);
            PrimaryAttackX2 = new WeaponAttack(this, 2);
            PrimaryAttackX4 = new WeaponAttack(this, 4);
        }
Ejemplo n.º 3
0
        public Enemy(BattleState battle, XmlNode node, int x, int y, int row, int e, string designation = "")
            : base(battle)
        {
            _x = x;
            _y = y;

            _weak   = new List <Element>();
            _halve  = new List <Element>();
            _void   = new List <Element>();
            _absorb = new List <Element>();
            _immune = new List <Status>();

            _win   = new List <EnemyItem>();
            _steal = new List <EnemyItem>();

            Attacks   = new Dictionary <string, EnemyAbility>();
            Variables = new Dictionary <string, object>();

            _name           = node.SelectSingleNode("name").InnerText;
            _attack         = Int32.Parse(node.SelectSingleNode("atk").InnerText);
            _defense        = Int32.Parse(node.SelectSingleNode("def").InnerText);
            _defensePercent = Int32.Parse(node.SelectSingleNode("defp").InnerText);
            _dexterity      = Int32.Parse(node.SelectSingleNode("dex").InnerText);
            _magicAttack    = Int32.Parse(node.SelectSingleNode("mat").InnerText);
            _magicDefense   = Int32.Parse(node.SelectSingleNode("mdf").InnerText);
            _luck           = Int32.Parse(node.SelectSingleNode("lck").InnerText);

            _level = Int32.Parse(node.SelectSingleNode("lvl").InnerText);
            _maxhp = _hp = Int32.Parse(node.SelectSingleNode("hp").InnerText);
            _maxmp = _mp = Int32.Parse(node.SelectSingleNode("mp").InnerText);

            Exp = Int32.Parse(node.SelectSingleNode("exp").InnerText);
            AP  = Int32.Parse(node.SelectSingleNode("ap").InnerText);
            Gil = Int32.Parse(node.SelectSingleNode("gil").InnerText);

            _row = row;

            if (!String.IsNullOrEmpty(designation))
            {
                _name += " " + designation;
            }

            foreach (XmlNode weak in node.SelectNodes("weaks/weak"))
            {
                _weak.Add((Element)Enum.Parse(typeof(Element), weak.InnerText));
            }
            foreach (XmlNode halve in node.SelectNodes("halves/halve"))
            {
                _halve.Add((Element)Enum.Parse(typeof(Element), halve.InnerText));
            }

            foreach (XmlNode v in node.SelectNodes("voids/void"))
            {
                _void.Add((Element)Enum.Parse(typeof(Element), v.InnerText));
            }
            foreach (XmlNode absorb in node.SelectNodes("absorbs/absorb"))
            {
                _absorb.Add((Element)Enum.Parse(typeof(Element), absorb.InnerText));
            }
            foreach (XmlNode immunity in node.SelectNodes("immunities/immunity"))
            {
                _immune.Add((Status)Enum.Parse(typeof(Status), immunity.InnerText));
            }

            foreach (XmlNode win in node.SelectNodes("win/item"))
            {
                _win.Add(new EnemyItem(win));
            }
            foreach (XmlNode steal in node.SelectNodes("steal/item"))
            {
                _steal.Add(new EnemyItem(steal));
            }
            foreach (XmlNode morph in node.SelectNodes("morph/item"))
            {
                _morph = new EnemyItem(morph);
            }

            foreach (XmlNode attackNode in node.SelectNodes("attacks/attack"))
            {
                EnemyAbility attack = new EnemyAbility(attackNode, battle.Lua);

                Attacks.Add(attack.Name, attack);
            }


            // AI: Setup

            XmlNode setupNode = node.SelectSingleNode("ai/setup");

            if (setupNode != null)
            {
                string setup = String.Format("return function (self) {0} end", setupNode.InnerText);

                try
                {
                    AISetup = (LuaFunction)battle.Lua.DoString(setup).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI setup script; enemy = " + Name, ex);
                }
            }


            // AI: Main

            string main = String.Format("return function (self) {0} end", node.SelectSingleNode("ai/main").InnerText);

            try
            {
                AIMain = (LuaFunction)battle.Lua.DoString(main).First();
            }
            catch (Exception ex)
            {
                throw new ImplementationException("Error loading enemy AI main script; enemy = " + Name, ex);
            }


            // AI: Counter

            XmlNode counterNode = node.SelectSingleNode("ai/counter");

            if (counterNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterNode.InnerText);

                try
                {
                    AICounter = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter script; enemy = " + Name, ex);
                }
            }


            // AI: Counter - Physical

            XmlNode counterPhysicalNode = node.SelectSingleNode("ai/counter-physical");

            if (counterPhysicalNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterPhysicalNode.InnerText);

                try
                {
                    AICounterPhysical = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter-physical script; enemy = " + Name, ex);
                }
            }


            // AI: Counter - Magical

            XmlNode counterMagicalNode = node.SelectSingleNode("ai/counter-physical");

            if (counterMagicalNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterMagicalNode.InnerText);

                try
                {
                    AICounterMagical = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter-magical script; enemy = " + Name, ex);
                }
            }


            // AI: Counter - Death

            XmlNode counterDeathNode = node.SelectSingleNode("ai/counter-death");

            if (counterDeathNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterDeathNode.InnerText);

                try
                {
                    AICounterDeath = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter-death script; enemy = " + Name, ex);
                }
            }


            // Confusion Attack

            XmlNode confuAttackNode = node.SelectSingleNode("ai/confuAttack");

            if (confuAttackNode != null)
            {
                string confuAttack = confuAttackNode.InnerText;

                if (!Attacks.ContainsKey(confuAttack))
                {
                    throw new GameDataException("Specified confu attack '{0}' is not configured; enemy = {1}", confuAttack, Name);
                }

                AIConfu = (LuaFunction)battle.Lua.DoString(String.Format("return function (self) a = chooseRandomEnemy(); self:Attack(\"{0}\", a) end", confuAttack)).First();
            }
            else
            {
                if (!Immune(Status.Confusion))
                {
                    throw new GameDataException("No confusion attack specified and not immune to confusion: {0}", Name);
                }
            }



            // Berserk Attack

            XmlNode berserkAttackNode = node.SelectSingleNode("ai/berserkAttack");

            if (berserkAttackNode != null)
            {
                string berserkAttack = berserkAttackNode.InnerText;

                if (!Attacks.ContainsKey(berserkAttack))
                {
                    throw new GameDataException("Specified berserk attack '{0}' is not configured; enemy = {1}", berserkAttack, Name);
                }

                AIBerserk = (LuaFunction)battle.Lua.DoString(String.Format("return function (self) a = chooseRandomAlly(); self:Attack(\"{0}\", a) end", berserkAttack)).First();
            }
            else
            {
                if (!Immune(Status.Berserk))
                {
                    throw new GameDataException("No berserk attack specified and not immune to berserk: {0}", Name);
                }
            }


            // Timers


            V_Timer   = new BattleClock(battle.SpeedValue * 2);
            TurnTimer = new EnemyTurnTimer(this, e);
        }
Ejemplo n.º 4
0
 protected Combatant(BattleState battle)
 {
     CurrentBattle = battle;
     C_Timer       = new BattleClock(136);
 }
Ejemplo n.º 5
0
        protected override void InternalInit()
        {
            ScreenState state = new ScreenState
            {
                Width  = Seven.Configuration.WindowWidth,
                Height = Seven.Configuration.WindowHeight
            };

            _victoryEvent = new EndOfBattleEvent("Victory!");
            _lossEvent    = new EndOfBattleEvent("Annihilated!");

            Screen = new BattleScreen(this, state);

            SpeedValue = (32768 / (120 + (Seven.Party.BattleSpeed * 15 / 8)));

            GlobalClock = new BattleClock(SpeedValue);

            Allies = new Ally[Party.PARTY_SIZE];

            int[] e = _formation.GetAllyTurnTimersElapsed(Party);

            for (int i = 0; i < Party.PARTY_SIZE; i++)
            {
                if (Party[i] != null)
                {
                    Allies[i] = new Ally(this, i, e[i]);
                    Allies[i].InitMenu(state);
                }
            }

            if (Allies.All(a => a == null))
            {
                throw new GameDataException("Must have at least one ally in battle.");
            }

            EnemyList = _formation.GetEnemyList(this);

            foreach (Ally ally in Allies)
            {
                if (ally != null)
                {
                    CombatantClocks.Add(ally.TurnTimer);
                    CombatantClocks.Add(ally.V_Timer);
                    CombatantClocks.Add(ally.C_Timer);
                    ally.TurnTimer.Unpause();
                }
            }

            foreach (Enemy enemy in EnemyList)
            {
                CombatantClocks.Add(enemy.TurnTimer);
                CombatantClocks.Add(enemy.V_Timer);
                CombatantClocks.Add(enemy.C_Timer);
                enemy.EnterBattle();
            }

            foreach (Enemy enemy in EnemyList)
            {
                enemy.TurnTimer.Unpause();
            }
        }
Ejemplo n.º 6
0
 protected Combatant(BattleState battle)
 {
     CurrentBattle = battle;
     C_Timer = new BattleClock(136);
 }