Esempio n. 1
0
 public void UsePotion(Potion p)
 {
     ChatBot.WriteLineToChat("/w " + name + " You drank a " + p.Name + ".  HP: " + health[0] + " / " + health[1]);
     if (p.Count == 1)
     {
         bag.RemoveItem(p);
         ChatBot.WriteLineToChat("/w " + name + " You have 0 " + p.Name + " left.");
     }
     else
     {
         p.Count--;
         ChatBot.WriteLineToChat("/w " + name + " " + p.Count + " " + p.Name + "'s left.");
     }
     health[0] += p.value;
 }
Esempio n. 2
0
        public void Battle()
        {
            if (target != null)
            {
                //Player stuff
                Random rng           = new Random();
                float  dmgMitigation = 65 / (65 + (defense * ChatBot.faythBlessings[2]));

                float rngCrit = rng.Next(0, 101);
                //Console.WriteLine("target rng-crit: " + rngCrit);
                bool doesCrit = rngCrit < crit;


                float damageDealt, critMultiplier;
                if (doesCrit)
                {
                    critMultiplier = 2.5f;
                }
                else
                {
                    critMultiplier = 1;
                }
                damageDealt = (float)Math.Round(((target.DPS * ChatBot.faythBlessings[1]) * critMultiplier) * dmgMitigation, 1, MidpointRounding.AwayFromZero);

                //player dies
                if (health[0] - damageDealt <= 0)
                {
                    //Call a function from chatBot to display the message of how many rats you killed.
                    target    = null;
                    health[0] = 0;
                    ChatBot.WriteLineToChat("/w " + name + " You got " + adventureGil + " gil from killing " + slainEnemies + " enemies on your adventure.");
                    isAdventuring = false;
                    ChatBot.adventurers.Remove(this);
                    ChatBot.healing.Add(this);
                    slainEnemies = 0;
                    adventureGil = 0;
                }
                else
                {
                    health[0] -= damageDealt;

                    //Potions
                    if ((health[0] / health[1]) <= 0.25f)
                    {
                        if (bag.IsInInventory(0))
                        {
                            UsePotion((Potion)bag.GetItemByID(0));
                        }
                        else if (bag.IsInInventory(1))
                        {
                            //use the potion.
                            UsePotion((Potion)bag.GetItemByID(1));
                        }
                        else if (bag.IsInInventory(2))
                        {
                            //use the potion.
                            UsePotion((Potion)bag.GetItemByID(2));
                        }
                    }
                    //Console.WriteLine(name + " Defense: " + defense);
                    //Console.WriteLine(target.Name + " DPS: " + target.DPS);

                    /*
                     * if (!doesCrit)
                     * {
                     *  Console.WriteLine(target.Name + " dealt " + Math.Round(((target.DPS * critMultiplier) * dmgMitigation), 1, MidpointRounding.AwayFromZero) + " damage.");
                     * } else
                     * {
                     *  Console.WriteLine(target.Name + " dealt " + Math.Round(((target.DPS * critMultiplier) * dmgMitigation), 1, MidpointRounding.AwayFromZero) + " damage!!!");
                     * }
                     * Console.WriteLine(name + " Health: " + health[0]);
                     */
                }

                //Target stuff
                if (target != null)
                {
                    dmgMitigation = 65 / (65 + target.Defense);
                    rngCrit       = rng.Next(0, 101);
                    //Console.WriteLine("player rng-crit: " + rngCrit);
                    doesCrit = rngCrit < (target.crit * ChatBot.faythBlessings[3]);
                    if (doesCrit)
                    {
                        critMultiplier = 2.5f;
                    }
                    else
                    {
                        critMultiplier = 1;
                    }
                    damageDealt = (float)Math.Round((dps * critMultiplier) * dmgMitigation, 1, MidpointRounding.AwayFromZero);
                    if (target.CurrentHealth - damageDealt <= 0)
                    {
                        Console.WriteLine("Enemy Killed.");
                        // the target dies
                        // get a new target
                        slainEnemies++;
                        totalSlain++;
                        gil          += (int)(target.GilDropped * ChatBot.faythBlessings[4]);
                        adventureGil += (int)(target.GilDropped * ChatBot.faythBlessings[4]);
                        if (exp + (target.Exp * ChatBot.faythBlessings[4]) >= expToLvl)
                        {
                            LevelUp();
                            ChatBot.WriteLineToChat("/w " + name + " You are now level " + lvl + ".");
                        }
                        else
                        {
                            exp += (int)(target.Exp * ChatBot.faythBlessings[4]);
                        }
                        if (lvl > 1)
                        {
                            target = ChatBot.enemyDB[rng.Next(0, ChatBot.enemyDB.Length)].GrowEnemy(rng.Next(lvl - 1, lvl + 2));
                        }
                        else
                        {
                            target = ChatBot.enemyDB[rng.Next(0, ChatBot.enemyDB.Length)].GrowEnemy(rng.Next(lvl, lvl + 2));
                        }
                    }
                    else
                    {
                        //critchance

                        target.CurrentHealth -= damageDealt;

                        /*
                         * if (!doesCrit)
                         * {
                         *  Console.WriteLine(name + " dealt " + Math.Round((dps * critMultiplier) * dmgMitigation, 1, MidpointRounding.AwayFromZero) + " damage.");
                         * } else
                         * {
                         *  Console.WriteLine(name + " dealt " + Math.Round((dps * critMultiplier) * dmgMitigation, 1, MidpointRounding.AwayFromZero) + " damage!!!");
                         * }
                         */
                        Console.WriteLine("Target CH: " + target.CurrentHealth);
                    }
                }
            }
        }
Esempio n. 3
0
        public void AddItem(Item i, int numItems)
        {
            int recievedCount = numItems;

            if (!bag.IsInInventory(i.ID) && bag.Count == bag.Size)
            {
                ChatBot.WriteLineToChat("/w " + name + " Inventory is full.");
            }
            else
            {
                // Create a list of the incoming items?
                // say you are adding 500 potions each at a stack of 99
                // Make 5 full stacks of potions and a partial stack of 5 potions.
                // Then add the full stacks to the inventory (if inventory size allows) and look for a partial stack in the inventory to combine the partial stacks

                //single items will be changed into multiple in stacks.
                i.Count = 1;
                int loopCounter = numItems / i.StackSize;
                if (numItems % i.StackSize != 0)
                {
                    loopCounter = (i.Count / i.StackSize) + 1;
                }


                if (i is Potion)
                {
                    Potion tempItem = (Potion)i;
                    if (bag.IsInInventory(i.ID))
                    {
                        // Item is in the inventory already.  We need to make sure the item count is not at max.  If its at max just make a new item.
                        List <Item> items = bag.GetItemsByID(i.ID);
                        for (int j = 0; j < items.Count; j++)
                        {
                            // i.stacksize - items[j].count = amount to refill

                            if (items[j].Count < tempItem.StackSize)
                            {
                                int fillAmount = tempItem.StackSize - items[j].Count;
                                // If the fill amount is larger than the item count being added, just add the new items count.
                                // else fill the stack and continue pulling items
                                if (fillAmount > numItems)
                                {
                                    // Adding items to a stack so it doesn't add to bagsize
                                    items[j].Count += numItems;
                                    break;
                                }
                                else
                                {
                                    //Fill the partial item stack
                                    items[j].Count = tempItem.StackSize;
                                    numItems      -= fillAmount;

                                    //divide the rest into stacks and add them to the inventory
                                    for (int k = 0; k < loopCounter; k++)
                                    {
                                        if (bag.Count == bag.Size)
                                        {
                                            break;
                                        }
                                        Item temp = tempItem.Copy();
                                        temp.Count = temp.StackSize;
                                        bag.AddItem(temp);
                                        numItems -= temp.StackSize;
                                    }

                                    //if there are any items left make a new partial item stack
                                    if (numItems != 0)
                                    {
                                        if (bag.Count == bag.Size)
                                        {
                                            break;
                                        }
                                        Item temp = tempItem.Copy();
                                        temp.Count = numItems;
                                        bag.AddItem(temp);
                                    }
                                    break;
                                }
                            }
                        }
                        if (numItems > 0)
                        {
                            if (i.StackSize > numItems)
                            {
                                Item temp = tempItem.Copy();
                                temp.Count = numItems;
                                bag.AddItem(temp);
                            }
                            else
                            {
                                for (int k = 0; k < loopCounter; k++)
                                {
                                    if (bag.Count == bag.Size)
                                    {
                                        break;
                                    }
                                    Item temp = tempItem.Copy();
                                    temp.Count = temp.StackSize;
                                    bag.AddItem(temp);
                                    numItems -= temp.StackSize;
                                }

                                if (numItems > 0)
                                {
                                    Item temp = tempItem.Copy();
                                    temp.Count = numItems;
                                    bag.AddItem(temp);
                                }
                            }
                        }
                    }

                    //IF the item is not in the inventory
                    else
                    {
                        //divide the rest into stacks and add them to the inventory
                        if (numItems >= tempItem.StackSize)
                        {
                            for (int j = 0; j < loopCounter; j++)
                            {
                                if (bag.Count == bag.Size)
                                {
                                    break;
                                }
                                Item temp = tempItem.Copy();
                                temp.Count = temp.StackSize;
                                bag.AddItem(temp);
                                numItems -= temp.StackSize;
                            }
                        }
                        //if there are any items left make a new partial item stack
                        if (numItems != 0)
                        {
                            if (bag.Count != bag.Size)
                            {
                                Item temp = tempItem.Copy();
                                temp.Count = numItems;
                                bag.AddItem(temp);
                            }
                        }
                    }
                }
                else if (i is Weapon)
                {
                    Weapon tempItem = (Weapon)i;
                    if (bag.IsInInventory(i.ID))
                    {
                        // Item is in the inventory already.  We need to make sure the item count is not at max.  If its at max just make a new item.
                        List <Item> items = bag.GetItemsByID(i.ID);
                        for (int j = 0; j < items.Count; j++)
                        {
                            // i.stacksize - items[j].count = amount to refill

                            if (items[j].Count < tempItem.StackSize)
                            {
                                int fillAmount = tempItem.StackSize - items[j].Count;
                                // If the fill amount is larger than the item count being added, just add the new items count.
                                // else fill the stack and continue pulling items
                                if (fillAmount > numItems)
                                {
                                    // Adding items to a stack so it doesn't add to bagsize
                                    items[j].Count += numItems;
                                    break;
                                }
                                else
                                {
                                    //Fill the partial item stack
                                    items[j].Count = tempItem.StackSize;
                                    numItems      -= fillAmount;

                                    //divide the rest into stacks and add them to the inventory
                                    for (int k = 0; k < loopCounter; k++)
                                    {
                                        if (bag.Count == bag.Size)
                                        {
                                            break;
                                        }
                                        Item temp = tempItem.Copy();
                                        temp.Count = temp.StackSize;
                                        bag.AddItem(temp);
                                        numItems -= temp.StackSize;
                                    }

                                    //if there are any items left make a new partial item stack
                                    if (numItems != 0)
                                    {
                                        if (bag.Count == bag.Size)
                                        {
                                            break;
                                        }
                                        Item temp = tempItem.Copy();
                                        temp.Count = numItems;
                                        bag.AddItem(temp);
                                    }
                                    break;
                                }
                            }
                        }
                        if (numItems > 0)
                        {
                            if (i.StackSize > numItems)
                            {
                                Item temp = tempItem.Copy();
                                temp.Count = numItems;
                                bag.AddItem(temp);
                            }
                            else
                            {
                                for (int k = 0; k < loopCounter; k++)
                                {
                                    if (bag.Count == bag.Size)
                                    {
                                        break;
                                    }
                                    Item temp = tempItem.Copy();
                                    temp.Count = temp.StackSize;
                                    bag.AddItem(temp);
                                    numItems -= temp.StackSize;
                                }

                                if (numItems > 0)
                                {
                                    Item temp = tempItem.Copy();
                                    temp.Count = numItems;
                                    bag.AddItem(temp);
                                }
                            }
                        }
                    }

                    //IF the item is not in the inventory
                    else
                    {
                        //divide the rest into stacks and add them to the inventory
                        if (numItems >= tempItem.StackSize)
                        {
                            for (int j = 0; j < loopCounter; j++)
                            {
                                if (bag.Count == bag.Size)
                                {
                                    break;
                                }
                                Item temp = tempItem.Copy();
                                temp.Count = temp.StackSize;
                                bag.AddItem(temp);
                                numItems -= temp.StackSize;
                            }
                        }
                        //if there are any items left make a new partial item stack
                        if (numItems != 0)
                        {
                            if (bag.Count != bag.Size)
                            {
                                Item temp = tempItem.Copy();
                                temp.Count = numItems;
                                bag.AddItem(temp);
                            }
                        }
                    }
                }
                else if (i is Armor)
                {
                    Armor tempItem = (Armor)i;
                    if (bag.IsInInventory(i.ID))
                    {
                        // Item is in the inventory already.  We need to make sure the item count is not at max.  If its at max just make a new item.
                        List <Item> items = bag.GetItemsByID(i.ID);
                        for (int j = 0; j < items.Count; j++)
                        {
                            // i.stacksize - items[j].count = amount to refill

                            if (items[j].Count < tempItem.StackSize)
                            {
                                int fillAmount = tempItem.StackSize - items[j].Count;
                                // If the fill amount is larger than the item count being added, just add the new items count.
                                // else fill the stack and continue pulling items
                                if (fillAmount > numItems)
                                {
                                    // Adding items to a stack so it doesn't add to bagsize
                                    items[j].Count += numItems;
                                    break;
                                }
                                else
                                {
                                    //Fill the partial item stack
                                    items[j].Count = tempItem.StackSize;
                                    numItems      -= fillAmount;

                                    //divide the rest into stacks and add them to the inventory
                                    for (int k = 0; k < loopCounter; k++)
                                    {
                                        if (bag.Count == bag.Size)
                                        {
                                            break;
                                        }
                                        Item temp = tempItem.Copy();
                                        temp.Count = temp.StackSize;
                                        bag.AddItem(temp);
                                        numItems -= temp.StackSize;
                                    }

                                    //if there are any items left make a new partial item stack
                                    if (numItems != 0)
                                    {
                                        if (bag.Count == bag.Size)
                                        {
                                            break;
                                        }
                                        Item temp = tempItem.Copy();
                                        temp.Count = numItems;
                                        bag.AddItem(temp);
                                    }
                                    break;
                                }
                            }
                        }
                        if (numItems > 0)
                        {
                            if (i.StackSize > numItems)
                            {
                                Item temp = tempItem.Copy();
                                temp.Count = numItems;
                                bag.AddItem(temp);
                            }
                            else
                            {
                                for (int k = 0; k < loopCounter; k++)
                                {
                                    if (bag.Count == bag.Size)
                                    {
                                        break;
                                    }
                                    Item temp = tempItem.Copy();
                                    temp.Count = temp.StackSize;
                                    bag.AddItem(temp);
                                    numItems -= temp.StackSize;
                                }

                                if (numItems > 0)
                                {
                                    Item temp = tempItem.Copy();
                                    temp.Count = numItems;
                                    bag.AddItem(temp);
                                }
                            }
                        }
                    }

                    //IF the item is not in the inventory
                    else
                    {
                        //divide the rest into stacks and add them to the inventory
                        if (numItems >= tempItem.StackSize)
                        {
                            for (int j = 0; j < loopCounter; j++)
                            {
                                if (bag.Count == bag.Size)
                                {
                                    break;
                                }
                                Item temp = tempItem.Copy();
                                temp.Count = temp.StackSize;
                                bag.AddItem(temp);
                                numItems -= temp.StackSize;
                            }
                        }
                        //if there are any items left make a new partial item stack
                        if (numItems != 0)
                        {
                            if (bag.Count != bag.Size)
                            {
                                Item temp = tempItem.Copy();
                                temp.Count = numItems;
                                bag.AddItem(temp);
                            }
                        }
                    }
                }
                if (recievedCount > 1)
                {
                    ChatBot.WriteLineToChat("/w " + name + " Received " + recievedCount + " " + i.Name + "s");
                }
                else
                {
                    ChatBot.WriteLineToChat("/w " + name + " Received " + recievedCount + " " + i.Name);
                }
                if (i is Weapon)
                {
                    Weapon temp = (Weapon)i;
                    dps += temp.attack * numItems;
                }
                else if (i is Armor)
                {
                    Armor temp = (Armor)i;
                    defense += temp.defense * numItems;
                }
            }
        }