private void HandleGatherInteraction(string[] commandWords, Person actor)
 {
     if (actor.Location is Forest && actor.ListInventory().Any(item => item is Weapon))
     {
        this.AddToPerson(actor, new Wood(commandWords[2]));
     }
     else if (actor.Location is Mine && actor.ListInventory().Any(item => item is Armor))
     {
         this.AddToPerson(actor, new Iron(commandWords[2]));
     }
 }
 private void CraftWeapon(string newItemName, Person actor)
 {
     var ironItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Iron);
     var woodItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Wood);
     if (ironItems != null && woodItems != null && ironItems.Count() > 0 && woodItems.Count() > 0)
     {
         var item = new Weapon(newItemName, null);
         actor.AddToInventory(item);
         ownerByItem.Add(item, actor);
         item.UpdateWithInteraction("craft");
     }                       
 }
        private void HandleCraftInteraction(string itemNameString, string itemTypeString, Person actor)
        {
            if (itemTypeString == "weapon" && actor.ListInventory().Any(item => item is Iron) && (actor.ListInventory().Any(item => item is Wood)))
            {
                this.AddToPerson(actor, new Weapon(itemNameString));
            }

            if (itemTypeString == "armor" && actor.ListInventory().Any(item => item is Iron))
            {
                this.AddToPerson(actor, new Armor(itemNameString));
            }
        }
 private void HandleCraftInteraction(string[] commandWords, Person actor)
 {
     if (actor.ListInventory().Any(item => item is Iron))
     {
         if (commandWords[2] == "weapon" && actor.ListInventory().Any(item => item is Wood))
         {
             this.AddToPerson(actor, new Weapon(commandWords[3]));
         }
         else if (commandWords[2] == "armor")
         {
             this.AddToPerson(actor, new Armor(commandWords[3]));
         }
     }
 }
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            var craftedItemType = commandWords[2];
            string craftedItemName = commandWords[3];
            Item theNewCraftedItem = null;
            var actorInventory = actor.ListInventory();

            if (craftedItemType == "weapon")
            {
                bool hasWood = PossessTheRequiredItem(actorInventory, ItemType.Wood);
                bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron);

                if (hasWood && hasIron)
                {
                    theNewCraftedItem = new Weapon(craftedItemName);
                    this.AddToPerson(actor, theNewCraftedItem);
                    theNewCraftedItem.UpdateWithInteraction("craft");
                }
            }
            else if (craftedItemType == "armor")
            {
                bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron);

                if (hasIron)
                {
                    theNewCraftedItem = new Armor(craftedItemName);
                    this.AddToPerson(actor, theNewCraftedItem);
                    theNewCraftedItem.UpdateWithInteraction("craft");
                }
            }
        }
        private void HandleCraftInteraction(Person actor, string[] commandWords)
        {
            var inventory = actor.ListInventory();

            bool hasIron = false;
            bool hasWood = false;

            foreach (var item in inventory)
            {
                if (item is Iron)
                {
                    hasIron = true;
                }
                else if (item is Wood)
                {
                    hasWood = true;
                }
            }

            if (commandWords[2] == "armor" && hasIron)
            {
                this.AddToPerson(actor, new Armor(commandWords[3], actor.Location));
            }
            else if (commandWords[2] == "weapon" && hasIron && hasWood)
            {
                this.AddToPerson(actor, new Weapon(commandWords[3], "weapon", actor.Location));
            }
        }
Ejemplo n.º 7
0
        private void HandleCraftInteraction(Person actor, string itemTypeAsString, string newItemName)
        {
            var actorInventory = actor.ListInventory();
            Item itemToAdd = null;
            var listOfNeededItems = null;

            switch (itemTypeAsString)
            {
                case "weapon" :
                    if (actorInventory.Any(x => x.ItemType == ItemType.Wood) && actorInventory.Any(x => x.ItemType == ItemType.Iron))
                    {
                        itemToAdd = new Weapon(newItemName);
                    }
                    break;
                case "armor" :
                    if (actorInventory.Any(x => x.ItemType == ItemType.Iron))
                    {
                        itemToAdd = new Armor(newItemName);
                    }
                    break;
                default:
                    break;
            }

            if (itemToAdd != null)
            {
                this.AddToPerson(actor, itemToAdd);
            }
        }
 private void HandleGatherInteraction(string itemNameString, Person actor)
 {
     var gatherLoc = actor.Location as IGatheringLocation;   
     if (gatherLoc != null && actor.ListInventory().Any(item => item.ItemType == gatherLoc.RequiredItem))
     {
         this.AddToPerson(actor, gatherLoc.ProduceItem(itemNameString));
     }
 }
 public void HandleGatherInteraction(Person person, string newItemName)
 {
     if (person.Location.LocationType == LocationType.Forest)
     {
         if (person.ListInventory().Exists(x => x.ItemType == ItemType.Weapon))
         {
             this.AddToPerson(person, new Wood(newItemName, null));
         }
     }
     else if (person.Location.LocationType == LocationType.Mine)
     {
         if (person.ListInventory().Exists(x => x.ItemType == ItemType.Armor))
         {
             this.AddToPerson(person, new Iron(newItemName, null));
         }
     }
 }
 private void CraftArmor(Person actor, string craftedItemName)
 {
     var actorInventory = actor.ListInventory();
     if (actorInventory.Any((item) => item.ItemType == ItemType.Iron))
     {
         this.AddToPerson(actor, new Armor(craftedItemName));
     }
 }
 public void HandleCraftInteraction(Person person, string itemType, string newItemName)
 {
     if (itemType == "weapon")
     {
         if (person.ListInventory().Exists(x => x.ItemType == ItemType.Iron) && person.ListInventory().Exists(x => x.ItemType == ItemType.Wood))
         {
             this.AddToPerson(person, new Weapon(newItemName, null));
         }
     }
     else if (itemType == "armor")
     {
         if (person.ListInventory().Exists(x => x.ItemType == ItemType.Iron))
         {
             this.AddToPerson(person, new Armor(newItemName, null));
         }
     }
 }
 private void HandleCraftInteraction(Person actor, string name)
 {
     if (actor.ListInventory().Exists(x => x is Iron))
     {
         if (actor.ListInventory().Exists(x => x is Weapon))
         {
             var item = new Weapon(name);
             actor.AddToInventory(item);
             this.AddToPerson(actor, item);
             return;
         }
         else
         {
             var item = new Armor(name);
             actor.AddToInventory(item);
             this.AddToPerson(actor, item);
         }
     }
 }
        protected void HandleGatherInteraction(Person actor, string newName)
        {
            if (actor.Location is IGatheringLocation)
            { 
                var gatheringLocation = actor.Location as IGatheringLocation;

                if (actor.ListInventory().Any(x => x.ItemType == gatheringLocation.RequiredItem))
                {
                    this.AddToPerson(actor, gatheringLocation.ProduceItem(newName));
                }
            }
        }
        private void HandleGatherInteraction(string name, Person actor)
        {
            if (actor.Location is IGatheringLocation)
            {
                var location = actor.Location as IGatheringLocation;

                if (actor.ListInventory().Any(i => i.ItemType == location.RequiredItem))
                {
                    AddToPerson(actor, location.ProduceItem(name));
                }
            }
        }
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            string craftItemType = commandWords[2];
            string craftItemName = commandWords[3];

            if (craftItemType == "armor")
            {
                bool hasIron = false;

                foreach (var item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Iron)
                    {
                        hasIron = true;
                        break;
                    }
                }

                if (hasIron)
                {
                    var addedItem = new Armor(craftItemName);
                    this.AddToPerson(actor, addedItem);
                    addedItem.UpdateWithInteraction("craft");
                }
            }

            if (craftItemType == "weapon")
            {
                bool hasWood = false;
                bool hasIron = false;

                foreach (var item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Wood)
                    {
                        hasWood = true;
                    }
                    else if (item.ItemType == ItemType.Iron)
                    {
                        hasIron = true;
                    }
                }

                if (hasWood && hasIron)
                {
                    var addedItem = new Weapon(craftItemName);
                    this.AddToPerson(actor, addedItem);
                    addedItem.UpdateWithInteraction("craft");
                }
            }
        }
Ejemplo n.º 16
0
        private void HandleTravelInteraction(string[] commandWords, Person actor)
        {
            var traveller = actor as ITraveller;
            if (traveller != null)
            {
                var targetLocation = this.locationByName[commandWords[2]];
                peopleByLocation[traveller.Location].Remove(actor);
                traveller.TravelTo(targetLocation);
                peopleByLocation[traveller.Location].Add(actor);

                foreach (var item in actor.ListInventory())
                {
                    item.UpdateWithInteraction("travel");
                }
            }
        }
Ejemplo n.º 17
0
        private void HandleTravelInteraction(string[] commandWords, Person actor)
        {
            var traveller = actor as ITraveller;

            if (traveller != null)
            {
                var targetLocation = this.locationByName[commandWords[2]];
                peopleByLocation[traveller.Location].Remove(actor);
                traveller.TravelTo(targetLocation);
                peopleByLocation[traveller.Location].Add(actor);

                foreach (var item in actor.ListInventory())
                {
                    item.UpdateWithInteraction("travel");
                }
            }
        }
        private void HandleListInventoryInteraction(Person actor)
        {
            var inventory = actor.ListInventory();
            foreach (var item in inventory)
            {
                if (ownerByItem[item] == actor)
                {
                    Console.WriteLine(item.Name);
                    item.UpdateWithInteraction("inventory");
                }
            }

            if (inventory.Count == 0)
            {
                Console.WriteLine("empty");
            }
        }
        private void HandleCraftInteraction(Person actor, string itemType, string itemName)
        {
            if (actor.ListInventory().Count > 0)
            {
                if (itemType == "weapon" && actor.ListInventory().Any(x => x.ItemType == ItemType.Iron) && actor.ListInventory().Any(x => x.ItemType == ItemType.Wood))
                {
                    var weapon = new Weapon(itemName);
                    AddToPerson(actor, weapon);
                }
                else if (itemType == "armor" && actor.ListInventory().Any(x => x.ItemType == ItemType.Iron))
                {
                    var armor = new Armor(itemName);
                    AddToPerson(actor, armor);
                }

            }
        }
Ejemplo n.º 20
0
        private void GetItemFromMine(Person actor, string itemName)
        {
            bool hasArmor = false;

            foreach (var item in actor.ListInventory())
            {
                if (item.ItemType == ItemType.Armor)
                {
                    hasArmor = true;
                }
            }

            if (hasArmor)
            {
                Iron iron = new Iron(itemName);
                this.AddToPerson(actor, iron);
            }
        }
Ejemplo n.º 21
0
        private void GetItemFromForest(Person actor, string itemName)
        {
            bool hasWeapon = false;

            foreach (var item in actor.ListInventory())
            {
                if (item.ItemType == ItemType.Weapon)
                {
                    hasWeapon = true;
                }
            }

            if (hasWeapon)
            {
                Wood wood = new Wood(itemName);
                this.AddToPerson(actor, wood);
            }
        }
Ejemplo n.º 22
0
        private void CraftArmor(Person actor, string itemName)
        {
            bool hasIron = false;

            foreach (var item in actor.ListInventory())
            {
                if (item.ItemType == ItemType.Iron)
                {
                    hasIron = true;
                }
            }

            if (hasIron)
            {
                Armor armor = new Armor(itemName);
                this.AddToPerson(actor, armor);
            }
        }
Ejemplo n.º 23
0
        private void HadleGatherInteraction(Person actor, string ItemName)
        {
            var actorInventory = actor.ListInventory();
            var IsGatherType   = actor.Location as IGatheringLocation;

            if (IsGatherType != null)
            {
                foreach (var actorInv in actorInventory)
                {
                    if (actorInv.ItemType == IsGatherType.RequiredItem)
                    {
                        var createItem = IsGatherType.ProduceItem(ItemName);
                        this.AddToPerson(actor, createItem);
                        break;
                    }
                }
            }
        }
        private void HandleArmorCrafting(string armorName, Person actor)
        {
            bool actorHasIron = false;

            foreach (Item inventoryItem in actor.ListInventory())
            {
                if (inventoryItem.ItemType == ItemType.Iron)
                {
                    actorHasIron = true;
                    break;
                }
            }

            if (actorHasIron)
            {
                base.AddToPerson(actor, new Armor(armorName, null));
            }
        }
        private void HandleGatherInteraction(Person actor, string gatheredItemName)
        {
            var gatheringLocation = actor.Location as IGatheringLocation;

            if (gatheringLocation != null)
            {
                var  actorInventory  = actor.ListInventory();
                bool hasRequiredItem = actorInventory.Any(it => it
                                                          .ItemType == gatheringLocation.RequiredItem
                                                          );

                if (hasRequiredItem)
                {
                    var producedItem = gatheringLocation.ProduceItem(gatheredItemName);
                    this.AddToPerson(actor, producedItem);
                }
            }
        }
        private void HandleListInventoryInteraction(Person actor)
        {
            var inventory = actor.ListInventory();

            foreach (var item in inventory)
            {
                if (this.ownerByItem[item] == actor)
                {
                    Console.WriteLine(item.Name);
                    item.UpdateWithInteraction("inventory");
                }
            }

            if (inventory.Count == 0)
            {
                Console.WriteLine("empty");
            }
        }
Ejemplo n.º 27
0
        private void HandleGatherInteraction(string[] commandWords, Person actor)
        {
            List <Item> actorsItems = actor.ListInventory();

            foreach (var item in actorsItems)
            {
                if (item.ItemType == ItemType.Weapon && actor.Location.LocationType == LocationType.Forest)
                {
                    this.AddToPerson(actor, new Wood(commandWords[2]));
                    //actor.AddToInventory(new Wood(commandWords[2]));
                }
                else if (item.ItemType == ItemType.Armor && actor.Location.LocationType == LocationType.Mine)
                {
                    this.AddToPerson(actor, new Iron(commandWords[2]));
                    //actor.AddToInventory(new Iron(commandWords[2]));
                }
            }
        }
        private void HandleGatherInteraction(string[] commandWords, Person actor)
        {
            string itemName = commandWords[2];

            var gatheringLocation = actor.Location as IGatheringLocation;

            if (gatheringLocation != null)
            {
                var requiredItemType = gatheringLocation.RequiredItem;
                var actorInventory   = actor.ListInventory();

                bool hasItem = InventoryHasItemType(requiredItemType, actorInventory);

                if (hasItem)
                {
                    this.AddToPerson(actor, gatheringLocation.ProduceItem(itemName));
                }
            }
        }
        private void HandleGatherInteraction(Person actor, string newItemName)
        {
            var currentLocation = actor.Location as IGatheringLocation;

            if (currentLocation != null)
            {
                var inventory = actor.ListInventory();

                foreach (var item in inventory)
                {
                    if (item.ItemType == currentLocation.RequiredItem)
                    {
                        var producedItem = currentLocation.ProduceItem(newItemName);

                        this.AddToPerson(actor, producedItem);
                        break;
                    }
                }
            }
        }
 private void HandleCraftInteraction(string[] commandWords, Person actor)
 {
     string itemTypeToCraft = commandWords[2];
     string chosenItemName = commandWords[3];
     var actorInventory = actor.ListInventory();
     if (itemTypeToCraft == "armor")
     {
         if (actorInventory.Any(i => i.ItemType == ItemType.Iron))
         {
             AddToPerson(actor, new Armor(chosenItemName));
         }
     }
     else if (itemTypeToCraft == "weapon")
     {
         if (actorInventory.Any(i => i.ItemType == ItemType.Iron) &&
             actorInventory.Any(i => i.ItemType == ItemType.Wood))
         {
             AddToPerson(actor, new Weapon(chosenItemName));
         }
     }
 }
        private void HandleGatherInteraction(string itemName, Person actor)
        {
            if (actor.Location is IGatheringLocation)
            {
                bool hasRequiredItem = false;

                foreach (Item inventoryItem in actor.ListInventory())
                {
                    if (inventoryItem.ItemType == (actor.Location as IGatheringLocation).RequiredItem)
                    {
                        hasRequiredItem = true;
                        break;
                    }
                }

                if (hasRequiredItem)
                {
                    base.AddToPerson(actor, (actor.Location as IGatheringLocation).ProduceItem(itemName));
                }
            }
        }
Ejemplo n.º 32
0
        private void HandleGatherInteraction(Person actor, string itemName)
        {
            if (actor.Location.LocationType == LocationType.Mine || actor.Location.LocationType == LocationType.Forest)
            {
                var gatheringLocation = actor.Location as IGatheringLocation;

                if (actor.ListInventory().Any(i => i.ItemType == gatheringLocation.RequiredItem))
                {
                    this.AddToPerson(actor, gatheringLocation.ProduceItem(itemName));
                }
            }

            //if (actor.Location.LocationType == LocationType.Forest && actor.ListInventory().Any(i => i.ItemType == ItemType.Weapon))
            //{
            //    this.AddToPerson(actor, new Wood(itemName));
            //}

            //if (actor.Location.LocationType == LocationType.Mine && actor.ListInventory().Any(i => i.ItemType == ItemType.Armor))
            //{
            //    this.AddToPerson(actor, new Iron(itemName));
            //}
        }
Ejemplo n.º 33
0
        private void HandleGatherInteraction(Person actor, string itemName)
        {
            var actorItems = actor.ListInventory();

            for (int i = 0; i < actorItems.Count; i++)
            {
                if (actorItems[i] is Weapon && actor.Location is Forest)
                {
                    var item = new Wood(itemName);
                    actor.AddToInventory(item);
                    this.ownerByItem.Add(item, actor);
                    return;
                }
                else if (actorItems[i] is Armor && actor.Location is Mine)
                {
                    var item = new Iron(itemName);
                    actor.AddToInventory(item);
                    this.ownerByItem.Add(item, actor);
                    return;
                }
            }
        }
Ejemplo n.º 34
0
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            string itemTypeToCraft = commandWords[2];
            string chosenItemName  = commandWords[3];
            var    actorInventory  = actor.ListInventory();

            if (itemTypeToCraft == "armor")
            {
                if (actorInventory.Any(i => i.ItemType == ItemType.Iron))
                {
                    AddToPerson(actor, new Armor(chosenItemName));
                }
            }
            else if (itemTypeToCraft == "weapon")
            {
                if (actorInventory.Any(i => i.ItemType == ItemType.Iron) &&
                    actorInventory.Any(i => i.ItemType == ItemType.Wood))
                {
                    AddToPerson(actor, new Weapon(chosenItemName));
                }
            }
        }
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            string itemTypeToCraft = commandWords[2];
            string itemName        = commandWords[3];

            var inventory = actor.ListInventory();

            if (itemTypeToCraft == ArmorItemToCraft)
            {
                if (InventoryHasItemType(ItemType.Iron, inventory))
                {
                    this.AddToPerson(actor, new Armor(itemName));
                }
            }

            if (itemTypeToCraft == WeaponItemToCraft)
            {
                if (InventoryHasItemType(ItemType.Iron, inventory) && InventoryHasItemType(ItemType.Wood, inventory))
                {
                    this.AddToPerson(actor, new Weapon(itemName));
                }
            }
        }
Ejemplo n.º 36
0
        private void HandeCraftWeaponInteraction(string newItemName, Person actor)
        {
            var inventory = actor.ListInventory();

            if (inventory.Any(item => item.GetType() == typeof(Iron)) &&
                inventory.Any(item => item.GetType() == typeof(Wood)))
            {
                // TODO: Remove iron ?
                //var itemToRemove = inventory
                //    .Where(item => item.GetType() == typeof(Iron))
                //    .First();

                //base.RemoveFromPerson(actor, itemToRemove);

                //itemToRemove = inventory
                //    .Where(item => item.GetType() == typeof(Wood))
                //    .First();

                //base.RemoveFromPerson(actor, itemToRemove);

                base.AddToPerson(actor, new Weapon(newItemName));
            }
        }
        private void HandleGatherInteraction(string[] commandWords, Person actor)
        {
            var itemsInInventory = actor.ListInventory();

            bool[] hasItemTypes = this.CheckActorInventoryForItem(itemsInInventory);

            if (actor.Location is Forest)
            {
                if (hasItemTypes[2])
                {
                    var gatheredWood = new Wood(commandWords[2], actor.Location);
                    this.AddToPerson(actor, gatheredWood);
                }
            }
            else if (actor.Location is Mine)
            {
                if (hasItemTypes[3])
                {
                    var gatheredIron = new Iron(commandWords[2], actor.Location);
                    this.AddToPerson(actor, gatheredIron);
                }
            }
        }
 private void HandleCraftInteraction(string[] commandWords, Person actor)
 {
     switch (commandWords[2])
     {
         case "armor":
             if (actor.ListInventory().Exists(x => x.ItemType == ItemType.Iron))
             {
                 this.AddToPerson(actor, new Armor(commandWords[3]));
             }
             break;
         case "weapon":
             if (actor.ListInventory().Exists(x => x.ItemType == ItemType.Iron))
             {
                 if (actor.ListInventory().Exists(x => x.ItemType == ItemType.Wood))
                 {
                     this.AddToPerson(actor, new Weapon(commandWords[3]));
                 }
             }
             break;
         default:
             break;
     }
 }
Ejemplo n.º 39
0
        private void CraftWeapon(Person actor, string itemName)
        {
            bool hasIron = false;
            bool hasWood = false;

            foreach (var item in actor.ListInventory())
            {
                if (item.ItemType == ItemType.Iron)
                {
                    hasIron = true;
                }

                if (item.ItemType == ItemType.Wood)
                {
                    hasWood = true;
                }
            }

            if (hasIron && hasWood)
            {
                Weapon weapon = new Weapon(itemName);
                this.AddToPerson(actor, weapon);
            }
        }
 private void HandleGatherInteraction(Person actor, string itemName)
 {
     if (actor.Location.LocationType == LocationType.Forest && actor.ListInventory().Any(x => x.ItemType == ItemType.Weapon))
     {
         var wood = new Wood(itemName);
         AddToPerson(actor, wood);
     }
     else if (actor.Location.LocationType == LocationType.Mine && actor.ListInventory().Any(x => x.ItemType == ItemType.Armor))
     {
         var iron = new Iron(itemName);
         AddToPerson(actor, iron);
     }
 }
        private void HandleGatherInteraction(Person actor, string gatheredItemName)
        {
            var gatheringLocation = actor.Location as IGatheringLocation;
            if (gatheringLocation != null)
            {
                var actorInventory = actor.ListInventory();
                bool hasRequiredItem = actorInventory.Any(
                    (item) => item.ItemType == gatheringLocation.RequiredItem
                    );

                if (hasRequiredItem)
                {
                    var producedItem = gatheringLocation.ProduceItem(gatheredItemName);
                    this.AddToPerson(actor, producedItem);
                }

                //same as above:
                //foreach (var item in actorInventory)
                //{
                //    if (item.ItemType == gatheringLocation.RequiredItem)
                //    {
                //        var producedItem = gatheringLocation.ProduceItem(gatheredItemName);

                //        this.AddToPerson(actor, producedItem);

                //        break;
                //    }
                //}
            }
        }
Ejemplo n.º 42
0
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            Item craftedItem = null;
            string itemType = commandWords[2];
            string itemName = commandWords[3];
            switch (itemType)
            {
                case "armor" :
                    foreach (var item in actor.ListInventory())
                    {
                        if (item.ItemType == ItemType.Iron)
                        {
                            craftedItem = new Armor(itemName);
                            this.AddToPerson(actor, craftedItem);
                            return;
                        }
                    }

                    break;
                case "weapon" :
                    bool hasIron = new bool();
                    bool hasWood = new bool();

                    foreach (var item in actor.ListInventory())
                    {
                        if (item.ItemType == ItemType.Iron)
                        {
                            hasIron = true;
                        }
                        else if (item.ItemType == ItemType.Wood)
                        {
                            hasWood = true;
                        }

                        if (hasIron && hasWood)
                        {
                            craftedItem = new Weapon(itemName);
                            this.AddToPerson(actor, craftedItem);
                            return;
                        }
                    }

                    break;
                default:
                    break;
            }

        }
Ejemplo n.º 43
0
        private void HandleGatherInteraction(string[] commandWords, Person actor)
        {
            Item gatherItem = null;
            string itemName = commandWords[2];
            switch (actor.Location.LocationType)
            {
                case LocationType.Mine:
                    foreach (var item in actor.ListInventory())
                    {
                        if (item.ItemType == ItemType.Armor)
                        {
                            gatherItem = new Iron(itemName);
                            this.AddToPerson(actor, gatherItem);
                            return;
                        }
                    }

                    break;
                case LocationType.Forest:
                    foreach (var item in actor.ListInventory())
                    {
                        if (item.ItemType == ItemType.Weapon)
                        {
                            gatherItem = new Wood(itemName);
                            this.AddToPerson(actor, gatherItem);
                            return;
                        }
                    }

                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 44
0
 public static bool HasItemInInventory(this Person actor, ItemType itemType)
 {
     return(actor.ListInventory().Any(i => i.ItemType == itemType));
 }
Ejemplo n.º 45
0
        private void HandleSellInteraction(string[] commandWords, Person actor)
        {
            Item saleItem = null;
            string saleItemName = commandWords[2];
            foreach (var item in actor.ListInventory())
            {
                if (ownerByItem[item] == actor && saleItemName == item.Name)
                {
                    saleItem = item;
                }
            }

            var buyer = personByName[commandWords[3]] as Shopkeeper;
            if (buyer != null &&
                peopleByLocation[actor.Location].Contains(buyer))
            {
                var price = buyer.CalculateBuyingPrice(saleItem);
                moneyByPerson[buyer] -= price;
                moneyByPerson[actor] += price;
                this.RemoveFromPerson(actor, saleItem);
                this.AddToPerson(buyer, saleItem);

                saleItem.UpdateWithInteraction("sell");
            }
        }
Ejemplo n.º 46
0
        private void HandleDropInteraction(Person actor)
        {
            foreach (var item in actor.ListInventory())
            {
                if (ownerByItem[item] == actor)
                {
                    strayItemsByLocation[actor.Location].Add(item);
                    this.RemoveFromPerson(actor, item);

                    item.UpdateWithInteraction("drop");
                }
            }
        }
        private void HandleCraftItem(string[] commandWords, Person actor)
        {
            // Syntax: kiro craft weapon craftedWeapon
            // 
            // A Person should be able to craft Weapons and Armor
            //
            // Crafting an Armor requires that the Person has Iron in his inventory
            // Results in adding an Armor item in the Person’s inventory
            //
            // Crafting a Weapon requires that the Person has Iron and Wood in his inventory
            bool hasIron = false;
            bool hasWood = false;

            var inventory = actor.ListInventory();
            foreach (var item in inventory)
            {
                if (item is Iron)
                {
                    hasIron = true;
                }
                else if (item is Wood)
                {
                    hasWood = true;
                }
            }

            if (commandWords[2] == "weapon")
            {
                if (hasIron && hasWood)
                {
                    this.AddToPerson(actor, new Weapon(commandWords[3]));
                    return;
                }
            }

            if (commandWords[2] == "armor")
            {
                if (hasIron)
                {
                    this.AddToPerson(actor, new Armor(commandWords[3]));
                    return;
                }
            }
        }
Ejemplo n.º 48
0
 private void HandleGatherInteraction(string[] commandWords, Person actor)
 {
     var location = actor.Location as IGatheringLocation;
     if (location != null)
     {
         if (actor.ListInventory().Exists(x => x.ItemType == location.RequiredItem))
         {
             this.AddToPerson(actor, location.ProduceItem(commandWords[2]));
         }
     }
 }
        private void HandleGatherInteraction(Person actor, string itemName)
        {
            //Gathering means a Person takes an item from a special location
            //A Person should be able to gather from mines and from forests
            //A Person can gather from a forest only if he has a Weapon in his inventory
            //Gathering from a forests results in adding a Wood item in the Person’s inventory
            //A Person can gather from a mine only if he has an Armor in his inventory
            //Gathering from a mine results in adding an Iron item in the Person’s inventory
            //Syntax: Joro gather newItemName – gathers an item, naming it newItemName if the Person Joro is at a mine or forest, and respectively has an Armor or Weapon

            if (actor.Location.LocationType == LocationType.Forest && actor.ListInventory().Any(a => a.GetType() == typeof(Weapon)))
            {
                Wood a = new Wood(itemName);
                base.AddToPerson(actor, a);
                actor.AddToInventory(new Wood(itemName));
            }

            if (actor.Location.LocationType == LocationType.Mine && actor.ListInventory().Any(a => a.GetType() == typeof(Armor)))
            {
                Iron a = new Iron(itemName);
                base.AddToPerson(actor, a);
                actor.AddToInventory(new Iron(itemName));
            }
        }
 private void HandleCraftInteraction(Person actor, string itemToCraft, string itemName)
 {
     //A Person can craft items, provided he has some items in his inventory
     //A Person should be able to craft Weapons and Armor
     //Crafting an Armor requires that the Person has Iron in his inventory
     //Results in adding an Armor item in the Person’s inventory
     //Crafting a Weapon requires that the Person has Iron and Wood in his inventory
     //Syntax: Joro craft weapon/armor newItemName - gathers an item, naming it newItemName if the Person Joro has the necessary
     switch (itemToCraft)
     {
         case "armor":
             if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron)))
             {
                 Armor armor = new Armor(itemName);
                 base.AddToPerson(actor, armor);
                 actor.AddToInventory(new Armor(itemName));
             }
             break;
         case "weapon":
             if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron)) && actor.ListInventory().Any(a => a.GetType() == typeof(Wood)))
             {
                 Weapon weapon = new Weapon(itemName);
                 base.AddToPerson(actor, weapon);
                 actor.AddToInventory(new Weapon(itemName));
             }
             break;
         default:
             break;
     }
 }