Пример #1
0
        // Generates a turnlist by grabbing all monsters and characters in the grid then arranging them by speed.
        public List <BattleTile> ComputeTurnList()
        {
            // Visit every tile in the Grid to identify all potential fighters
            List <BattleTile> turnList = new List <BattleTile>();

            for (int i = 0; i < Grid.Count; i++)
            {
                for (int j = 0; j < Grid[i].Count; j++)
                {
                    // If this tile is a fighter
                    BattleTile tempTile = Grid[i][j];
                    if (tempTile.Type != "Tile")
                    {
                        // Identify where in the turnlist this fighter will be inserted.
                        bool insterted = false;
                        for (var k = 0; k < turnList.Count && !insterted; k++)
                        {
                            // If the fighter from the grid is faster than the current fighter in the turnlist, insert the fighter
                            if (tempTile.GetSpeed() > turnList[k].GetSpeed())
                            {
                                insterted = true;
                                turnList.Insert(k, tempTile);
                            }
                            // If the fighter from the grid is of equal speed as the fighter in the turnlist, compare levels
                            else if (tempTile.GetSpeed() == turnList[k].GetSpeed())
                            {
                                // If the fighter from the grid is of a higher level than the current fighter in the turnlist, insert the fighter
                                if (tempTile.GetLevel() > turnList[k].GetLevel())
                                {
                                    insterted = true;
                                    turnList.Insert(k, tempTile);
                                }
                                // If the fighter from the grid is of equal speed as the fighter in the turnlist, compare experience
                                else if (tempTile.GetLevel() == turnList[k].GetLevel())
                                {
                                    // If the fighter from the grid is of a higher experience than the current fighter in the turnlist, insert the fighter
                                    // Experience for characters is their current XP and the experience for monsters is their current ExpToGive.
                                    if (tempTile.GetExperience() > turnList[k].GetExperience())
                                    {
                                        insterted = true;
                                        turnList.Insert(k, tempTile);
                                    }
                                    // If the fighter from the grid is of equal speed as the fighter in the turnlist, compare type
                                    else if (tempTile.GetExperience() == turnList[k].GetExperience())
                                    {
                                        // If the fighter from the grid is a Character and the current fighter in the turnlist is a Monster, insert the fighter
                                        if (tempTile.Type == "Character" && turnList[k].Type == "Monster")
                                        {
                                            insterted = true;
                                            turnList.Insert(k, tempTile);
                                        }
                                        // If the fighter from the grid is of equal type as the fighter in the turnlist, compare name
                                        else if (tempTile.Type == turnList[k].Type)
                                        {
                                            // If the fighter from the grid does not have the same name as the current fighter in the turnlist, check alphabetical order
                                            if (tempTile.Name != turnList[k].Name)
                                            {
                                                List <string> judge = new List <string>
                                                {
                                                    tempTile.Name,
                                                    turnList[k].Name
                                                };
                                                judge.Sort();

                                                // If the fighter from the grid is first based on alphabetical order for both names, insert the fighter
                                                if (tempTile.Name == judge[0])
                                                {
                                                    insterted = true;
                                                    turnList.Insert(k, tempTile);
                                                }
                                                // If the fighter from the grid is second based on alphabetical order for both names, check the next fighter.
                                            }
                                            // If they are equal then check the next fighter because this fighter came first in the list order.
                                        }
                                    }
                                }
                            }
                        }

                        // If the fighter is the slowest among the fighters in the turnlist
                        if (!insterted)
                        {
                            // Insert the fighter to the end of the list.
                            turnList.Add(tempTile);
                        }
                    }
                }
            }
            return(turnList);
        }
Пример #2
0
        // Damage dealing function that works with either monster or character
        public int DealtDamage(BattleTile attacker)
        {
            BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Damage Calculation Begins"));
            // Roll 20 for attack type.
            Random rng  = new Random();
            int    roll = 1 + rng.Next(20);

            BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Rolled: " + roll));

            // Applies to hit Rule
            if (ToHit > 0)
            {
                roll = ToHit;
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("ToHit Applied: " + ToHit));
            }

            // Applies Miss at roll/ToHit 1 Rule
            if (Miss1 && roll == 1)
            {
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Missed"));
                DamageStatus = "Miss";
                return(0);
                // Applies Critical Miss at 1 rule
            }
            else if (CriticalMiss1 && roll == 1)
            {
                DamageStatus = "Critical Miss";
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Critical Miss"));
                return(0);
            }

            // Applies Hit at roll/ToHit 20 Rule
            bool hit           = false;
            bool criticalHit   = false;
            bool focusedAttack = false;

            if (Hit20 && roll == 20)
            {
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Hit20"));
                DamageStatus = "Hit";
                hit          = true;

                // Applies critical hit rule at 20
            }
            else if (Critical20 && roll == 20)
            {
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Critical Hit"));
                DamageStatus = "Critical Hit";
                criticalHit  = true;

                // Applies focused attack rule
            }
            else if (BattleSystemViewModel.Instance.FocusedAttack && BattleSystemViewModel.Instance.UseFocusedAttack)
            {
                if (attacker.Type == "Character" && attacker.Hero.UnequipAllItems().Count > 0)
                {
                    BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Focused Attack Applied"));
                    DamageStatus  = "Focused Attack";
                    FocusedAttack = true;
                }
            }

            BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Attacker Attack: " + attacker.GetAttack()));
            BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Attacker Level: " + attacker.GetLevel()));
            BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Target Defense: " + GetDefense()));
            BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Target Level: " + GetLevel()));
            // Hit Designation
            if (roll + attacker.GetLevel() + attacker.GetAttack() > GetDefense() + GetLevel() || hit || criticalHit || focusedAttack)
            {
                int damage = 0;
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Hit Success"));
                // Level Damage
                int lvlDamage = (int)(attacker.GetLevel() * .25) + 1;
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Level Damage: " + lvlDamage));
                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Weapon Damage: " + attacker.GetDamage()));
                // Applies Disable RNG Rule
                if (DisableRNG)
                {
                    damage = attacker.GetDamage() + lvlDamage + attacker.GetAttack();
                    BattleSystemViewModel.Instance.AddTxt(new StringWrapper("RNG Disabled damage: " + damage));
                }

                // RNG enabled rule
                else
                {
                    Random weaponDamage = new Random();
                    damage = (1 + weaponDamage.Next(attacker.GetDamage() + attacker.GetAttack())) + lvlDamage;
                    BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Resulting Damage: " + damage));
                }

                // Critical hit doubles the damage dealt
                if (criticalHit)
                {
                    damage = 2 * damage;
                    BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Critical Applied damage: " + damage));
                }

                // Focused attack deals 10 times the damage dealt
                if (focusedAttack)
                {
                    damage = 10 * damage;
                    BattleSystemViewModel.Instance.AddTxt(new StringWrapper("Focus Attack Applied damage: " + damage));
                }

                // Update life bar of this Combatant
                UpdateLifeBar(damage);

                BattleSystemViewModel.Instance.AddTxt(new StringWrapper("End Damage"));
                // Return damage delt for recording
                return(damage);
            }
            // Missed
            return(0);
        }