public static void UseItemFromInventoryAction(List <TWEntity> roomEntities, List <TWEntity> itemEntities, TWEntity playerEntity, TWEntity outputEntity, ItemActionComponent component) { // look at player inventory to make sure item exists var inventoryComponent = playerEntity.GetComponentByType <InventoryComponent>(); if (inventoryComponent != null) { // create a variable that is the item name, it's stored in the itemActionComponent.CommandComponent.Args var itemName = component.CommandComponent.ArgsJoined; // search inventoryComponent.Items for itemName var itemInInventory = inventoryComponent.Items.FirstOrDefault(x => x.Name == itemName); // if item exists then look the item up in the itemEntities if (itemInInventory != null) { // get the item entity from the itemEntities var itemEntity = itemEntities.FirstOrDefault(x => x.GetComponentByType <ItemComponent>()?.Item.Name == itemName); if (itemEntity != null) { var itemComponent = itemEntity.GetComponentByType <ItemComponent>(); if (itemComponent != null) { var item = itemComponent.Item; item.Use(playerEntity, itemEntities, outputEntity); //outputEntity.AddComponent(new OutputComponent("output for item used", $"You used {itemName}", OutputType.Regular)); // if the item is consumable then execute it's Use function if (item.Consumable) { Helper.RemoveOrDecrementItemFromPlayersInventory(playerEntity, playerEntity, itemInInventory); } //else //{ // outputEntity.AddComponent(new OutputComponent("output for item not used", $"You can't use {itemName}", OutputType.Regular)); //} } } } else { outputEntity.AddComponent(new OutputComponent("output for item not found", $"You don't have a {itemName}", OutputType.Regular)); } } }
public static void DropAllItemsAction(List <TWEntity> roomEntities, List <TWEntity> itemEntities, TWEntity playerEntity, TWEntity outputEntity, ItemActionComponent component) { throw new NotImplementedException(); }
public static void TakeAllItemsAction(List <TWEntity> roomEntities, List <TWEntity> itemEntities, TWEntity playerEntity, TWEntity outputEntity, ItemActionComponent component) { var roomEntity = GetPlayersCurrentRoom(playerEntity, roomEntities); var roomItems = roomEntity !.GetComponentsByType <ItemDropComponent>(); if (roomItems.Count > 0) { roomItems.ForEach(item => { Helper.AddItemToPlayersInventory(playerEntity, roomEntity !, item); outputEntity.AddComponent(new OutputComponent("output for item taken", $"You've taken {item.Item.Name}", OutputType.Regular)); }); } else { outputEntity.AddComponent(new OutputComponent("output for non existant item", $"Can't find any items here.", OutputType.Regular)); } }
public static void TakeItemAction(List <TWEntity> roomEntities, List <TWEntity> itemEntities, TWEntity playerEntity, TWEntity outputEntity, ItemActionComponent component) { var roomEntity = GetPlayersCurrentRoom(playerEntity, roomEntities); var takeItem = Helper.GetItemDropComponentFromEntity(roomEntity !, component.ItemName ?? string.Empty); if (takeItem != null) { Helper.AddItemToPlayersInventory(playerEntity, roomEntity !, takeItem); outputEntity.AddComponent(new OutputComponent("output for item taken", $"You've taken {component.ItemName}", OutputType.Regular)); } else { var itemName = string.IsNullOrEmpty(component.ItemName) ? "that item" : component.ItemName; outputEntity.AddComponent(new OutputComponent("output for non existant item", $"{itemName} does not exist here.", OutputType.Regular)); } }
public static void ShowAllItemAction(List <TWEntity> roomEntities, List <TWEntity> itemEntities, TWEntity playerEntity, TWEntity outputEntity, ItemActionComponent component) { var roomEntity = GetPlayersCurrentRoom(playerEntity, roomEntities); var itemDropComponents = roomEntity !.GetComponentsByType <ItemDropComponent>(); var items = new List <string>(); itemDropComponents.ForEach(item => items.Add($"{item.Item.Name} ({item.Item.Quantity})")); if (items.Count > 0) { outputEntity.AddComponent(new OutputComponent("output for items in room", $"The following items are here: {string.Join(", ", items.ToArray())}", OutputType.Regular)); } else { outputEntity.AddComponent(new OutputComponent("output for no items in room", "There are no items here.", OutputType.Regular)); } }
public static void ShowItemAction(List <TWEntity> roomEntities, List <TWEntity> itemEntities, TWEntity playerEntity, TWEntity outputEntity, ItemActionComponent component) { var roomEntity = GetPlayersCurrentRoom(playerEntity, roomEntities); var showItem = Helper.GetItemDropComponentFromEntity(roomEntity !, component.ItemName ?? string.Empty); if (showItem != null) { outputEntity.AddComponent(new OutputComponent("output for item in room", $"{showItem.Item.Name} ({showItem.Item.Quantity})", OutputType.Regular)); } else { outputEntity.AddComponent(new OutputComponent("output for item in room", "That item does not exist here", OutputType.Regular)); } }