Exemplo n.º 1
0
        //this method will be called by when it's character's turn
        public void CharacterAutoTurn(Creature character, Creature target, Score score)
        {
            string message = string.Empty;

            GetNewLoc(character, target);   //will get the character's new location
            Move(character);
            if (!CanHit(character, target)) //check if the character can hit the target
            {
                return;
            }
            bool hit = turn.Attack(character, target);//character attacks the target

            if (hit)
            {
                message = "Character " + character.Name + " attacks " + target.Name;
                Debug.WriteLine(message);

                int damageToDo = turn.DamageToDo(character);    //Damage for the character will be calculated
                int xpToGive   = MC.GiveXP(target, damageToDo); //Experience will be calaculated for the character
                totalXP += xpToGive;
                CC.TestForLevelUp(character, xpToGive);         //Check the Level up
                bool monsterAlive;                              //after the attack it will check if the monster is alive or not
                MC.TakeDamage(target, damageToDo);
                monsterAlive = target.Alive;

                if (monsterAlive == false)//when monsteralive is false that means its dead
                {
                    message = string.Empty;
                    Debug.WriteLine("Monster is dead");
                    score.MonsterSlainNumber++;

                    // Drop Items to item Pool
                    var myItemList = MC.DropItems(target);
                    //Add Items to the Score List
                    message = "Dropped Items";
                    foreach (var item in myItemList)
                    {
                        score.TotalItemsDropped += item.FormatOutput() + "\n";
                        message += "\n" + item.Name;
                    }
                    ItemPool.AddRange(myItemList);//Dropped items will added to the ItemPool

                    Debug.WriteLine(message);

                    //the dead monster will be removed from the turn order, monster's dataset, and the GameBoard
                    TurnOrder.Remove(target);
                    CurrMonsters.Dataset.Remove(target);
                    GameBoardRemove(target);
                    Creature tempMonster = originalMonsters.Where(a => a.Id == target.Id).FirstOrDefault();
                    score.TotalMonstersKilled += tempMonster.FormatOutput(tempMonster) + "\n";//Total monsters killed is calculated

                    message = "Monster Removed :" + target.Name;
                    Debug.WriteLine(message);
                }
            }
        }
        public Score AutoBattle(Score score, int round, int Potions, int miracle)
        {
            //without asking the player for input
            //this will run the turns in a loop until either all the team is dead or all the monsters are
            BattleScreen screen = new BattleScreen();
            string       message;

            message = "Battle Start" + " Characters :" + team.Dataset.Count;
            Debug.WriteLine(message);
            message = "Battle Start" + " Monsters :" + CurrMonsters.Dataset.Count;
            Debug.WriteLine(message);
            while (CurrMonsters.Dataset.Count > 0)
            {
                if (team.Dataset.Count <= 0)
                {
                    break;
                }
                for (int i = 0; i < TurnOrder.Count; i++)
                {
                    //screen.BattleMessages(message);

                    //.WriteLine(Text);

                    //screen.BattleMessages(message);

                    message = "New Turn :" + TurnOrder[i].Name;
                    Debug.WriteLine(message);
                    screen.BattleMessages(message);

                    TurnController turn = new TurnController();
                    turns++;
                    if (TurnOrder[i].Type == 0)
                    {
                        Creature character = TurnOrder[i];
                        //int loc = GetNewLoc(character, GameBoard);
                        //GameBoard = turn.Move(character, loc, GameBoard);

                        Creature target = AutoTarget(character);//get a monster target for the character
                        if (target == null)
                        {
                            break;
                        }
                        if (!CanHit(character, target))
                        {
                            continue;
                        }

                        int hit = turn.Attack(character, target);
                        //Debug.WriteLine(hit.ToString());
                        if (GameGlobals.FocusedAttack == true)
                        {
                            bool          hasItem = false;
                            List <string> ids     = character.GetItemIDs();
                            if (ids.Count > 0)
                            {
                                hasItem = true;
                            }
                            bool wantsTo = false;
                            if (target.CurrHealth > (5 * turn.DamageToDo(character)))//5 must be set to 1 to see in autobattle
                            {
                                wantsTo = true;
                            }
                            if (character.CanFocusAttack && hasItem && wantsTo)
                            {
                                hit = 3;
                                character.CanFocusAttack = false;
                            }
                        }
                        if (GameGlobals.AllowRoundHealing)
                        {
                            if (character.CurrHealth < (character.MaxHealth * .2))
                            {
                                if (Potions > 0)
                                {
                                    character.CurrHealth = character.MaxHealth;
                                    Potions--;
                                    Debug.WriteLine("Potion used, Potions Left " + Potions);
                                    hit = 0;
                                }
                            }
                        }
                        if (hit > 0)
                        {
                            int damageToDo = turn.DamageToDo(character);
                            if (hit == 2)//critical hit
                            {
                                damageToDo = damageToDo * 2;
                                Debug.WriteLine(character.Name + " critical hit " + target.Name);
                            }
                            if (hit == 3)//focused hit
                            {
                                Item          lowValue = null;
                                int           lowest   = 1000;
                                List <string> itemIds  = character.GetItemIDs();
                                var           items    = ItemsViewModel.Instance.Dataset;
                                for (int j = 0; j < itemIds.Count; j++)
                                {
                                    var currItem  = items.Where(a => a.Id == itemIds[j]).FirstOrDefault();
                                    int newLowest = currItem.Value;
                                    if (lowest > newLowest)
                                    {
                                        lowest   = newLowest;
                                        lowValue = currItem;
                                    }
                                }
                                character.DropOneItem(lowValue.Id);
                                damageToDo = damageToDo * 10;
                                bool monsterAliveAfterFocus;
                                MC.TakeDamage(target, damageToDo);
                                Debug.WriteLine(character.Name + " performed a Focused Attack and lost item " + lowValue.Name);
                                monsterAliveAfterFocus = target.Alive;
                                if (monsterAliveAfterFocus == false)
                                {
                                    message = "Monster dead ";
                                    Debug.WriteLine(message);
                                    screen.BattleMessages(message);

                                    TurnOrder.Remove(target);
                                    //score.TotalMonstersKilled.Add(target);
                                    CurrMonsters.Dataset.Remove(target);
                                    GameBoardRemove(target);

                                    message = "Monster Removed :" + target.Name;
                                    Debug.WriteLine(message);
                                    screen.BattleMessages(message);
                                }
                                continue;
                            }
                            int xpToGive = MC.GiveXP(target, damageToDo);
                            totalXP += xpToGive;
                            CC.TestForLevelUp(character, xpToGive);
                            bool monsterAlive;
                            MC.TakeDamage(target, damageToDo);
                            monsterAlive = target.Alive;

                            if (monsterAlive == false)
                            {
                                message = "Monster dead ";
                                Debug.WriteLine(message);
                                screen.BattleMessages(message);

                                ItemPool.AddRange(MC.DropItems(target));
                                message = "Items Dropped :" + ItemPool.Count.ToString();
                                Debug.WriteLine(message);
                                screen.BattleMessages(message);

                                TurnOrder.Remove(target);
                                //score.TotalMonstersKilled.Add(target);
                                CurrMonsters.Dataset.Remove(target);
                                GameBoardRemove(target);

                                message = "Monster Removed :" + target.Name;
                                Debug.WriteLine(message);
                                screen.BattleMessages(message);

                                if (GameGlobals.MonsterHandGrenade == true && GameGlobals.Grenade == true)
                                {
                                    GameGlobals.Grenade = false;
                                    int    dateSeed      = DateTime.Now.Millisecond;
                                    Random rand          = new Random(dateSeed);
                                    int    grenadeDamage = rand.Next(1, 5) * round;
                                    Debug.WriteLine("Grenade!  " + grenadeDamage.ToString() + " damage");
                                    List <Creature> tempList = new List <Creature>();
                                    foreach (Creature tempC in TurnOrder)
                                    {
                                        tempList.Add(tempC);
                                    }
                                    foreach (Creature creature in tempList)
                                    {
                                        int saveMe = creature.Level + rand.Next(1, 21);
                                        if (saveMe >= (rand.Next(1, 21)))
                                        {
                                            Debug.WriteLine(creature.Name + " has been saved");
                                        }
                                        else
                                        {
                                            Debug.WriteLine(creature.Name + " is taking grenade damage, sucks to be them");
                                            if (creature.Type == 0)
                                            {
                                                CC.TakeDamage(creature, grenadeDamage);
                                                bool characterAliveGrenade = creature.Alive;

                                                if (characterAliveGrenade == false)
                                                {
                                                    message = "Character dead ";
                                                    Debug.WriteLine(message);
                                                    screen.BattleMessages(message);

                                                    ItemPool.AddRange(CC.DropItems(creature));
                                                    message = "Items Dropped :" + ItemPool.Count.ToString();
                                                    Debug.WriteLine(message);
                                                    screen.BattleMessages(message);

                                                    TurnOrder.Remove(creature);
                                                    //add dead character to the score list
                                                    team.Dataset.Remove(creature);
                                                    GameBoardRemove(creature);

                                                    message = "Character Removed :" + creature.Name;
                                                    Debug.WriteLine(message);
                                                    screen.BattleMessages(message);
                                                }
                                            }
                                            else
                                            {
                                                MC.TakeDamage(creature, grenadeDamage);
                                                bool monsterAliveGrenade = creature.Alive;

                                                if (monsterAliveGrenade == false)
                                                {
                                                    message = "Monster dead ";
                                                    Debug.WriteLine(message);
                                                    screen.BattleMessages(message);

                                                    ItemPool.AddRange(MC.DropItems(creature));
                                                    message = "Items Dropped :" + ItemPool.Count.ToString();
                                                    Debug.WriteLine(message);
                                                    screen.BattleMessages(message);

                                                    TurnOrder.Remove(creature);
                                                    //score.TotalMonstersKilled.Add(creature);
                                                    CurrMonsters.Dataset.Remove(creature);
                                                    GameBoardRemove(creature);

                                                    message = "Monster Removed :" + creature.Name;
                                                    Debug.WriteLine(message);
                                                    screen.BattleMessages(message);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (hit == -1)
                        {
                            int    dateSeed = DateTime.Now.Millisecond;
                            Random rand     = new Random(dateSeed);
                            int    roll     = rand.Next(1, 11);
                            if (GameGlobals.DisableRandomNumbers)
                            {
                                roll = 10;
                            }
                            if (roll == 1)
                            {
                                character.RHandItemID = null;
                            }
                            else if (roll >= 2 && roll <= 4)
                            {
                                if (character.RHandItemID != null)
                                {
                                    var items = ItemsViewModel.Instance.Dataset;
                                    var item  = items.Where(a => a.Id == character.RHandItemID).FirstOrDefault();
                                    if (item != null)
                                    {
                                        ItemPool.Add(item);
                                    }
                                    character.RHandItemID = null;
                                }
                            }
                            else if (roll == 5 || roll == 6)
                            {
                                var allItems = character.GetItemIDs();//get all of the character's items' ids
                                if (allItems.Count > 0)
                                {
                                    int index = rand.Next(allItems.Count);//get a random index for getting an item id
                                    if (GameGlobals.DisableRandomNumbers)
                                    {
                                        index = 0;
                                    }
                                    if (allItems.Count > index)//check for a bad index
                                    {
                                        string itemID = allItems[index];
                                        var    items  = ItemsViewModel.Instance.Dataset;
                                        var    item   = items.Where(a => a.Id == itemID).FirstOrDefault();
                                        if (item != null)//find the item and make sure it is safe to add to the item pool
                                        {
                                            ItemPool.Add(item);
                                        }
                                        character.DropOneItem(itemID);
                                    }
                                }
                            }
                            Debug.WriteLine("Critical miss, case " + roll.ToString());
                        }
                    }
                    else
                    {
                        Creature monster = TurnOrder[i];
                        //int loc = GetNewLoc(monster, GameBoard);
                        //GameBoard = turn.Move(monster, loc, GameBoard);
                        Creature target = AutoTarget(monster);//get a character target for the monster
                        if (target == null)
                        {
                            break;
                        }
                        if (!CanHit(monster, target))
                        {
                            continue;
                        }

                        int hit = turn.Attack(monster, target);
                        //Debug.WriteLine(hit.ToString());
                        if (hit > 0)
                        {
                            int damageToDo = turn.DamageToDo(monster);
                            if (hit == 2)
                            {
                                damageToDo = damageToDo * 2;
                                Debug.WriteLine(monster.Name + " critical hit " + target.Name);
                            }
                            bool characterAlive = CC.TakeDamage(target, damageToDo);
                            if (GameGlobals.MiracleMax == true)
                            {
                                if (!characterAlive && miracle > 0)
                                {
                                    target.Alive      = true;
                                    target.CurrHealth = target.MaxHealth;
                                    miracle--;
                                    Debug.WriteLine("Miracle Max has revived " + target.Name);
                                    GameGlobals.MiracleMax = false;
                                    characterAlive         = target.Alive;
                                }
                            }
                            if (!characterAlive)
                            {
                                message = "Character dead ";
                                Debug.WriteLine(message);
                                screen.BattleMessages(message);

                                ItemPool.AddRange(CC.DropItems(target));
                                message = "Items Dropped :" + ItemPool.Count.ToString();
                                Debug.WriteLine(message);
                                screen.BattleMessages(message);

                                TurnOrder.Remove(target);
                                //add dead character to the score list
                                team.Dataset.Remove(target);
                                GameBoardRemove(target);

                                message = "Character Removed :" + target.Name;
                                Debug.WriteLine(message);
                                screen.BattleMessages(message);
                            }
                        }
                        if (hit == -1)
                        {
                            int    dateSeed = DateTime.Now.Millisecond;
                            Random rand     = new Random(dateSeed);
                            int    roll     = rand.Next(1, 11);
                            if (GameGlobals.DisableRandomNumbers)
                            {
                                roll = 10;
                            }
                            if (roll == 1)
                            {
                                monster.RHandItemID = null;
                            }
                            else if (roll >= 2 && roll <= 4)
                            {
                                if (monster.RHandItemID != null)
                                {
                                    var items = ItemsViewModel.Instance.Dataset;
                                    var item  = items.Where(a => a.Id == monster.RHandItemID).FirstOrDefault();
                                    if (item != null)
                                    {
                                        ItemPool.Add(item);
                                    }
                                    monster.RHandItemID = null;
                                }
                                else
                                {
                                    var items    = ItemsViewModel.Instance.Dataset;
                                    int randItem = rand.Next(items.Count);//find the random item to add to the pool
                                    if (GameGlobals.DisableRandomNumbers)
                                    {
                                        randItem = 0;
                                    }
                                    Item item = new Item();
                                    if (items.Count > randItem)
                                    {
                                        item.Update(items[randItem]);
                                    }

                                    if (item != null)
                                    {
                                        ItemPool.Add(item);
                                    }
                                }
                            }
                            else if (roll == 5 || roll == 6)
                            {
                                var allItems = monster.GetItemIDs();//get all of the character's items' ids
                                if (allItems.Count > 0)
                                {
                                    int index = rand.Next(allItems.Count);//get a random index for getting an item id
                                    if (GameGlobals.DisableRandomNumbers)
                                    {
                                        index = 0;
                                    }
                                    if (allItems.Count > index)//check for a bad index
                                    {
                                        string itemID = allItems[index];
                                        var    items  = ItemsViewModel.Instance.Dataset;
                                        var    item   = items.Where(a => a.Id == itemID).FirstOrDefault();
                                        if (item != null)//find the item and make sure it is safe to add to the item pool
                                        {
                                            ItemPool.Add(item);
                                        }
                                        monster.DropOneItem(itemID);
                                    }
                                }
                                if (allItems.Count == 0)
                                {
                                    var items    = ItemsViewModel.Instance.Dataset;
                                    int randItem = rand.Next(items.Count);//find the random item to add to the pool
                                    if (GameGlobals.DisableRandomNumbers)
                                    {
                                        randItem = 0;
                                    }
                                    Item item = new Item();
                                    if (items.Count > randItem)
                                    {
                                        item.Update(items[randItem]);
                                    }

                                    if (item != null)
                                    {
                                        ItemPool.Add(item);
                                    }
                                }
                            }
                            Debug.WriteLine("Critical miss, case " + roll.ToString());
                        }
                    }
                }
            }
            score.Turns   += turns;
            score.TotalXP += totalXP;
            message        =
                "Battle Ended" +
                " Total Experience :" + totalXP +

                " Turns :" + turns +
                " Monster Kills :" + CurrMonsters.Dataset.Count;
            Debug.WriteLine(message);
            screen.BattleMessages(message);

            return(score);
        }