Ejemplo n.º 1
0
 public static void DropWeaponAndPickupNew(Character.Models.Character player, Room.Models.Room room,
                                           WeaponItem weaponToAddToPlayer)
 {
     room.RoomItems.WeaponItems.Add(player.WeaponItem);
     AttributeHandler.UpdatePlayerAttributesFromWeaponItem(player, player.WeaponItem, true);
     AttributeHandler.UpdatePlayerAttributesFromWeaponItem(player, weaponToAddToPlayer);
     weaponToAddToPlayer.InOriginalLocation = false;
     player.WeaponItem = weaponToAddToPlayer;
     room.RoomItems.WeaponItems.Remove(weaponToAddToPlayer);
 }
        public void UpdatePlayerAttributesFromWeaponItem_ShouldRemoveTraitPointToPlayer()
        {
            var player = MockCharacters.MockPlayerAlbert;

            player.Attributes = MockAttributes.MockPlayerAttrBeforeUpdate;
            MockAttributes.MockPlayerAttrBeforeUpdate.Dexterity = 6;

            var expectedOutput = MockAttributes.MockPlayerAttrAfterRemoveDexterity;

            AttributeHandler.UpdatePlayerAttributesFromWeaponItem(player, MockItems.MockItemKatana, true);

            Assert.AreEqual(expectedOutput.Dexterity, player.Attributes.Dexterity);
        }
Ejemplo n.º 3
0
        // This updates the room and/or player when the exchange of an item occurs
        public static void HandleItemAddOrRemove(Character.Models.Character player, Room.Models.Room currentRoom,
                                                 Items foundItem, bool removeItemFromRoom = false)
        {
            switch (removeItemFromRoom)
            {
            // We are removing an item from a room, adding it to player inventory
            case true:
                if (foundItem?.InventoryItems?.First() != null)
                {
                    var           meetsAnyRequirement          = false;
                    var           needsToDropSameTypeItemFirst = false;
                    InventoryItem carriedItemOfSameType        = null;
                    var           inventoryItemToAddToPlayer   = foundItem.InventoryItems.First();

                    if (inventoryItemToAddToPlayer?.AttributeRequirementToTake == null)
                    {
                        meetsAnyRequirement = true;
                    }

                    else if (inventoryItemToAddToPlayer?.AttributeRequirementToTake != null &&
                             CanPickupItemWithAttributeRequirement(player, inventoryItemToAddToPlayer))
                    {
                        meetsAnyRequirement = true;
                    }

                    if (inventoryItemToAddToPlayer.TreatItemAs == ItemUseTypes.Bag ||
                        inventoryItemToAddToPlayer.TreatItemAs == ItemUseTypes.Wearable)
                    {
                        foreach (var item in player.CarriedItems)
                        {
                            if (item.TreatItemAs == ItemUseTypes.Bag && inventoryItemToAddToPlayer.TreatItemAs == ItemUseTypes.Bag ||
                                item.WearableType != "" && item.WearableType == inventoryItemToAddToPlayer.WearableType)
                            {
                                carriedItemOfSameType        = item;
                                needsToDropSameTypeItemFirst = true;
                                break;
                            }
                        }
                    }

                    if (PickupOrDropItemIsOk(player, foundItem) && meetsAnyRequirement)
                    {
                        Console.WriteLine();
                        if (needsToDropSameTypeItemFirst)
                        {
                            TypingAnimation.Animate("You need to drop your " + carriedItemOfSameType.ItemName + " before you can take the " + inventoryItemToAddToPlayer?.ItemName + ".\n",
                                                    Color.ForestGreen);
                        }
                        else
                        {
                            AttributeHandler.UpdatePlayerAttributesFromInventoryItem(player, inventoryItemToAddToPlayer);
                            inventoryItemToAddToPlayer.InOriginalLocation = false;
                            player.CarriedItems.Add(inventoryItemToAddToPlayer);
                            player.Attributes.CarriedItemsCount += inventoryItemToAddToPlayer.InventorySpaceConsumed;
                            currentRoom.RoomItems.InventoryItems.Remove(inventoryItemToAddToPlayer);
                            TypingAnimation.Animate("You take the " + inventoryItemToAddToPlayer.ItemName + ".\n", Color.ForestGreen);
                        }
                    }

                    else
                    {
                        if (meetsAnyRequirement)
                        {
                            Console.WriteLine();
                            TypingAnimation.Animate("Your inventory is full! \n" +
                                                    "Drop or use an item to pick up the " + inventoryItemToAddToPlayer?.ItemName + ".\n", Color.DarkOliveGreen);
                        }
                    }
                }
                else
                if (foundItem?.WeaponItems != null)
                {
                    var weaponItemToAddToPlayer = foundItem.WeaponItems.First();
                    if (string.IsNullOrEmpty(player.WeaponItem.WeaponName))
                    {
                        AttributeHandler.UpdatePlayerAttributesFromWeaponItem(player, weaponItemToAddToPlayer);
                        weaponItemToAddToPlayer.InOriginalLocation = false;
                        player.WeaponItem = weaponItemToAddToPlayer;
                        currentRoom.RoomItems.WeaponItems.Remove(weaponItemToAddToPlayer);
                        Console.WriteLine();
                        TypingAnimation.Animate("You take the " + weaponItemToAddToPlayer?.WeaponName + ".\n", Color.ForestGreen);
                    }
                    else
                    {
                        var oldWeapon = player.WeaponItem.WeaponName.Clone();
                        DropWeaponAndPickupNew(player, currentRoom, weaponItemToAddToPlayer);
                        player.WeaponItem = weaponItemToAddToPlayer;
                        currentRoom.RoomItems.WeaponItems.Remove(weaponItemToAddToPlayer);
                        Console.WriteLine();
                        TypingAnimation.Animate("You drop your " + oldWeapon + " for the " + weaponItemToAddToPlayer?.WeaponName + ".\n",
                                                Color.ForestGreen);
                    }
                }

                break;

            // We are adding an item to a room, removing/dropping it from player inventory
            case false:
                if (foundItem?.InventoryItems != null)
                {
                    var inventoryItemToRemoveFromPlayer = foundItem.InventoryItems.First();

                    DropItemInRoom(player, currentRoom, inventoryItemToRemoveFromPlayer);
                    Console.WriteLine();
                    TypingAnimation.Animate("You drop the " + inventoryItemToRemoveFromPlayer?.ItemName + ".\n", Color.ForestGreen);
                }
                else if (foundItem?.WeaponItems != null)
                {
                    var weaponItemToRemoveFromPlayer = foundItem.WeaponItems.First();

                    DropWeaponInRoom(player, currentRoom);
                    Console.WriteLine();
                    TypingAnimation.Animate("You drop the " + weaponItemToRemoveFromPlayer?.WeaponName + ".\n", Color.ForestGreen);
                }

                break;
            }
        }
Ejemplo n.º 4
0
 public static void DropWeaponInRoom(Character.Models.Character player, Room.Models.Room room)
 {
     room.RoomItems.WeaponItems.Add(player.WeaponItem);
     AttributeHandler.UpdatePlayerAttributesFromWeaponItem(player, player.WeaponItem, true);
     player.WeaponItem = new WeaponItem();
 }
        // This updates the room and/or player when the exchange of an item occurs
        public static void HandleItemAddOrRemove(Character.Models.Character player, Room.Models.Room currentRoom,
                                                 Items foundItem, bool removeItemFromRoom = false)
        {
            switch (removeItemFromRoom)
            {
            // We are removing an item from a room, adding it to player inventory
            case true:
                if (foundItem?.InventoryItems != null)
                {
                    var inventoryItemToAdd = foundItem.InventoryItems.First();
                    if (player.Attributes.CarriedItemsCount + 1 <= player.Attributes.MaximumCarryingCapacity)
                    {
                        AttributeHandler.UpdatePlayerAttributesFromInventoryItem(player, inventoryItemToAdd);
                        inventoryItemToAdd.InOriginalLocation = false;
                        player.CarriedItems.Add(inventoryItemToAdd);
                        player.Attributes.CarriedItemsCount += 1;
                        currentRoom.RoomItems.InventoryItems.Remove(inventoryItemToAdd);
                        Console.WriteLine();
                        TypingAnimation.Animate("You take the " + inventoryItemToAdd.ItemName + ".\n", Color.ForestGreen);
                    }
                    else
                    {
                        Console.WriteLine();
                        TypingAnimation.Animate("Your inventory is full! \n" +
                                                "Drop an item to pick up the " + inventoryItemToAdd?.ItemName + ".\n", Color.DarkOliveGreen);
                    }
                }
                else if (foundItem?.WeaponItems != null)
                {
                    var weaponItemToAdd = foundItem.WeaponItems.First();
                    if (string.IsNullOrEmpty(player.WeaponItem.WeaponName))
                    {
                        AttributeHandler.UpdatePlayerAttributesFromWeaponItem(player, weaponItemToAdd);
                        weaponItemToAdd.InOriginalLocation = false;
                        player.WeaponItem = weaponItemToAdd;
                        currentRoom.RoomItems.WeaponItems.Remove(weaponItemToAdd);
                        Console.WriteLine();
                        TypingAnimation.Animate("You take the " + weaponItemToAdd?.WeaponName + ".\n", Color.ForestGreen);
                    }
                    else
                    {
                        var oldWeapon = player.WeaponItem.WeaponName.Clone();
                        DropWeaponAndPickupNew(player, currentRoom, weaponItemToAdd);
                        AttributeHandler.UpdatePlayerAttributesFromWeaponItem(player, weaponItemToAdd);
                        player.WeaponItem = weaponItemToAdd;
                        currentRoom.RoomItems.WeaponItems.Remove(weaponItemToAdd);
                        Console.WriteLine();
                        TypingAnimation.Animate("You drop your " + oldWeapon + " for the " + weaponItemToAdd?.WeaponName + ".\n",
                                                Color.ForestGreen);
                    }
                }

                break;

            // We are adding an item to a room, removing/dropping it from player inventory
            case false:
                if (foundItem?.InventoryItems != null)
                {
                    var inventoryItemToRemove = foundItem.InventoryItems.First();
                    DropItemInRoom(player, currentRoom, inventoryItemToRemove);
                    Console.WriteLine();
                    TypingAnimation.Animate("You drop the " + inventoryItemToRemove?.ItemName + ".\n", Color.ForestGreen);
                }
                else if (foundItem?.WeaponItems != null)
                {
                    var weaponItemToRemove = foundItem.WeaponItems.First();
                    DropWeaponInRoom(player, currentRoom);
                    Console.WriteLine();
                    TypingAnimation.Animate("You drop the " + weaponItemToRemove?.WeaponName + ".\n", Color.ForestGreen);
                }

                break;
            }
        }