Ejemplo n.º 1
0
        /**
         * Command that allows player to purchase an item.
         * @params: (Player) current player of the game.
         * @return: (bool) true/false value whether game is over or not.
         **/
        public override bool execute(Player player)
        {
            if (this.Words.Count > 0)
            {
                string itemName = "";
                while (this.Words.Count > 0)
                {
                    itemName += Words.Dequeue() + " ";
                }
                itemName = itemName.TrimEnd();

                Merchant npc = (Merchant)player.currentRoom.getNPC("merchant");
                if (npc != null)
                {
                    I_Item item = null;
                    npc.Inventory.TryGetValue(itemName, out item);

                    if (item != null)
                    {
                        if (player.Backpack.spaceInBag(item) && player.hasEnoughCoins(item.PurchasePrice))
                        {
                            player.spendCoins(item.PurchasePrice);
                            player.Backpack.giveItem(item);
                            NotificationCenter.Instance.postNotification(new Notification("PlayerPurchaseMessage"));
                        }
                    }
                }
            }
            else
            {
                player.outputMessage("\nWhat do you want to buy!!!");
                NotificationCenter.Instance.postNotification(new Notification("ViewInventory", this));
            }
            return(false);
        }
Ejemplo n.º 2
0
        /**
         * Picks up an item to be placed in backpack if it will fit in the bag and notifies subscribers.
         * @params: (String) name of the item to be picked up.
         **/
        public void pickUpItem(string itemName)
        {
            I_Item item = currentRoom.takeItem(itemName);

            if (item != null)
            {
                NotificationCenter.Instance.postNotification(new Notification("PickedUpItem", this));
                if ((Backpack.weightInBag() + item.Weight) >= Backpack.Capacity)
                {
                    Console.WriteLine("Backpack is full.");
                    currentRoom.giveItem(item);
                }
                else if (item.ItemTypes.Contains(ItemType.Weapon) && Weapon == null)
                {
                    setWeapon((IWeapon)item);
                    Console.WriteLine("\nYour weapon has been set to the " + itemName + "!\n");
                }

                else
                {
                    Backpack.giveItem(item);
                    Console.WriteLine("\nYou picked up a " + itemName + "!\n");
                }
            }
        }
Ejemplo n.º 3
0
        /**
         * Retrieves an item from the merchant's inventory that they have available for purchase.
         * @params: (String) The name of the item to be retrieved.
         * @returns: (I_Item) The item that is in the inventory if available.
         **/
        public I_Item itemFromInventory(string name)
        {
            I_Item item = null;

            Inventory.TryGetValue(name, out item);
            return(item);
        }
Ejemplo n.º 4
0
 /**
  * Indicates whether there is sufficient space to add an item to the backpack.
  * @params: (I_Item) The item that we are checking space in backpack for.
  * @returns: (bool) Whether the item checked will fit in the backpack without going over capacity.
  **/
 public bool spaceInBag(I_Item item)
 {
     if (this.Weight + item.Weight > capacity)
     {
         Console.WriteLine("You don't have room in your backpack");
         return(false);
     }
     return(true);
 }
Ejemplo n.º 5
0
        /**
         * Command that initiates sale of current player's chosen item to the merchant.
         * @params: (Player) current player of the game.
         * @return: (bool) true/false value whether game is over or not.
         **/
        public override bool execute(Player player)
        {
            string itemName = "";

            while (this.Words.Count > 0)
            {
                itemName += Words.Dequeue() + " ";
            }
            itemName = itemName.TrimEnd();

            if (!player.Backpack.itemInBag(itemName))
            {
                player.outputMessage("\nYou don't have that item!");
            }
            else if (player.Backpack.checkItem(itemName).ItemTypes.Contains(ItemType.KeyItem))
            {
                player.outputMessage("\nI wouldn't sell that, you may need it later!");
            }

            //Checks whether an item is a weapon or not, for weapons user may want to sell a specific one, for other items
            //it does not matter.
            else
            {
                if (player.Backpack.checkItem(itemName).ItemTypes.Contains(ItemType.Weapon))
                {
                    player.outputMessage("Which weapon would you like to sell? (Enter weapon's numbered position to sell)\n");
                    player.outputMessage(player.Backpack.displayWeapons(itemName));
                    int    position;
                    I_Item item = null;
                    try
                    {
                        position = Convert.ToInt32(Console.ReadLine());
                        item     = player.takeFromBackpack(itemName, position);
                    }
                    catch (Exception e) {
                        player.outputMessage("\nNot a valid weapon position");
                        return(false);
                    }
                    player.receiveCoins(item.SellPrice);
                    player.outputMessage("\nYou received " + item.SellPrice + " coins!");
                }
                else
                {
                    I_Item item = player.takeFromBackpack(itemName);
                    player.receiveCoins(item.SellPrice);
                    player.outputMessage("\nYou received " + item.SellPrice + " coins!");
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        /**
         * Item is added to the backpacks inventory of individual items.
         * @params: (I_Item) item to be added to inventory
         * @returns: void
         **/
        public void giveItem(I_Item item)
        {
            List <I_Item> check = null;

            Inventory.TryGetValue(item.Name, out check);
            if (check == null)
            {
                Inventory[item.Name] = new List <I_Item>();
                Inventory[item.Name].Add(item);
            }
            else
            {
                Inventory[item.Name].Add(item);
            }
        }
Ejemplo n.º 7
0
    override public void WorkBuilding()
    {
        isWorking   = false;
        activeTimer = workTime;

        I_Inventory inventory = baseManager.GetInventory();

        I_Item itemInterface = chosenItem;

        itemInterface.CalculateBaseStats(workingVillagers[0]);

        inventory.AddItem(chosenItem);

        SetUpInfoPanel();
    }
Ejemplo n.º 8
0
        //Methods to give an item to the room and take it from the room.
        public void giveItem(I_Item item)
        {
            LinkedList <I_Item> check = null;

            RoomItems.TryGetValue(item.Name, out check);
            if (check == null)
            {
                RoomItems[item.Name] = new LinkedList <I_Item>();
                RoomItems[item.Name].AddFirst(item);
            }
            else
            {
                RoomItems[item.Name].AddLast(item);
            }
        }
Ejemplo n.º 9
0
        /**
         * Command that tells the player to call method using specific item in their posession.
         * @params: (Player) current player of the game.
         * @return: (bool) true/false value whether game is over or not.
         **/
        public override bool execute(Player player)
        {
            //In this method will write how a player will use an item they have in their bag.
            if (this.Words.Count > 0)
            {
                string item = "";
                while (this.Words.Count > 0)
                {
                    item += this.Words.Dequeue() + " ";
                }
                item = item.TrimEnd();
                I_Item itemToUse = player.Backpack.takeItem(item);
                if (itemToUse == null)
                {
                    player.outputMessage("\nYou don't have a " + item + " to use");
                }
                else
                {
                    itemToUse.useItem(player);

                    //For player who is in battle
                    IEnemy enemy = player.currentRoom.CurrentEnemy;
                    if (itemToUse.ItemTypes.Contains(ItemType.BattleItem) && enemy != null)
                    {
                        enemy.attackPlayer(player);
                        if (player.playerDefeated())
                        {
                            return(true);
                        }
                        player.currentStats();
                        player.getEnemy().currentStats();
                        NotificationCenter.Instance.postNotification(new Notification("PopCommands"));
                    }
                }

                player.outputMessage(player.Backpack.displayItems());
            }
            else
            {
                player.outputMessage("\nUse What\n");
                player.outputMessage(player.Backpack.displayItems());
            }
            return(false);
        }
Ejemplo n.º 10
0
        /**
         * Takes an item from the backpacks inventory of that individual item. The first item in the list of that specific item
         * is removed.
         * @params: (string) The name of the item to be removed.
         * @returns: (I_Item) The item that was removed.
         **/
        public I_Item takeItem(string item)
        {
            List <I_Item> check = null;

            Inventory.TryGetValue(item, out check);
            if (check != null && check.Count != 0)
            {
                I_Item temp = check.First();
                Inventory[item].Remove(temp);
                if (Inventory[item].Count == 0)
                {
                    Inventory.Remove(item);
                }
                return(temp);
            }
            else
            {
                Console.WriteLine("Item does not exist in your backpack!");
                return(null);
            }
        }
Ejemplo n.º 11
0
        public I_Item takeItem(string item)
        {
            LinkedList <I_Item> check = null;

            RoomItems.TryGetValue(item, out check);
            if (check != null && check.Count != 0)
            {
                I_Item temp = check.First.Value;
                RoomItems[item].RemoveFirst();
                if (RoomItems[item].Count == 0)
                {
                    RoomItems.Remove(item);
                }
                return(temp);
            }
            else
            {
                Console.WriteLine("Item does not exist in the room!");
                return(null);
            }
        }
Ejemplo n.º 12
0
 /**
  * Places item in the backpack
  * @param: (I_Item) item object to be placed in backpack.
  * @returns: void
  **/
 public void addToBackpack(I_Item item)
 {
     Backpack.giveItem(item);
 }