private void RemoveFromContainer(int index) { ContainerComponent cc = (ContainerComponent)selectedContainer.GetComponent(TypeOfComponent.CONTAINER); actor.Inventory.Add(cc.GetItems[index]); cc.Contains.Remove(cc.GetItems[index]); if (cc.IsEmpty) { SwitchDisplayState(InventoryState.InventoryDisplay); } }
private void PutIntoContainer(int index) { if (ContainerList[index].GetComponent(TypeOfComponent.CONTAINER) != null) { ContainerComponent cc = (ContainerComponent)ContainerList[index].GetComponent(TypeOfComponent.CONTAINER); if (selected != ContainerList[index]) { if (!cc.IsFull) { cc.Contains.Add(selected); actor.Inventory.Remove(selected); } } } SwitchDisplayState(InventoryState.InventoryDisplay); }
private void IdentifyContainers() { ContainerList.Clear(); foreach (Item item in actor.Inventory) { if (item.GetComponent(TypeOfComponent.CONTAINER) != null) { ContainerComponent cc = (ContainerComponent)item.GetComponent(TypeOfComponent.CONTAINER); if (!cc.IsFull && item != selected) { ContainerList.Add(item); } } } if (ContainerList.Count > 0) { SwitchDisplayState(InventoryState.ContainerEnterDisplay); } }
private void ChooseItem(Item item) { selected = item; int i = 0; InteractionChoices.Clear(); InteractionChoices.Add(i++, new Choice() { text = "Drop", keyword = "drop" }); InteractionChoices.Add(i++, new Choice() { text = "Put in container", keyword = "put" }); if (selected.GetComponent(TypeOfComponent.WEAPON) != null) { InteractionChoices.Add(i++, new Choice() { text = "Wield", keyword = "wield" }); } if (selected.GetComponent(TypeOfComponent.CONTAINER) != null) { ContainerComponent cc = (ContainerComponent)selected.GetComponent(TypeOfComponent.CONTAINER); if (!cc.IsEmpty) { InteractionChoices.Add(i++, new Choice() { text = "Remove item", keyword = "remove" }); } } SwitchDisplayState(InventoryState.ItemInteraction); }
public override void Draw(SpriteBatch spriteBatch) { Color c; renderer.display.ClearText(); // switching between the different states of display switch (displayState) { case InventoryState.InventoryDisplay: { renderer.display.WriteLine("=== INVENTORY ===", Color.Yellow); for (int i = 0; i < actor.Inventory.Count; i++) { if (i == index) { c = Color.Red; } else { c = Color.White; } renderer.display.WriteLine(actor.Inventory[i].ToString(), c); } break; } case InventoryState.ItemInteraction: { renderer.display.WriteLine("=== I T E M ===", Color.Yellow); renderer.display.WriteLine(" "); renderer.display.WriteLine(selected.ToString().PadLeft(5)); renderer.display.WriteLine("-----------------------"); if (selected.GetComponent(TypeOfComponent.WEAPON) != null) { WeaponComponent wc = (WeaponComponent)selected.GetComponent(TypeOfComponent.WEAPON); renderer.display.WriteLine("Wielded : " + wc.wielded.ToString()); } renderer.display.WriteLine("---------------------------"); for (int i = 0; i < InteractionChoices.Count; i++) { if (i == index) { c = Color.Red; } else { c = Color.White; } renderer.display.WriteLine(InteractionChoices[i].text, c); } break; } case InventoryState.ContainerEnterDisplay: { renderer.display.WriteLine("=== AVAILABLE CONTAINERS ===", Color.Yellow); renderer.display.WriteLine(" "); for (int i = 0; i < ContainerList.Count; i++) { if (i == index) { c = Color.Red; } else { c = Color.White; } renderer.display.WriteLine(ContainerList[i].Name, c); } break; } case InventoryState.ContainerExitDisplay: { renderer.display.WriteLine("=== ITEMS IN CONTAINER ===", Color.Yellow); renderer.display.WriteLine(" "); ContainerComponent cc = (ContainerComponent)selectedContainer.GetComponent(TypeOfComponent.CONTAINER); for (int i = 0; i < cc.GetItems.Count; i++) { if (i == index) { c = Color.Red; } else { c = Color.White; } renderer.display.WriteLine(cc.GetItems[i].Name, c); } break; } } renderer.Draw(spriteBatch); }
private static List <ItemPrefab> CreateItems(Dictionary <int, string[]> dict) { List <ItemPrefab> itemPrefabs = new List <ItemPrefab>(); for (int i = 0; i < dict.Count; i++) { ItemPrefab Prefab = new ItemPrefab(); Prefab.Components = new List <Component>(); foreach (string s in dict[i]) { string[] tokens = s.Split(':'); if (tokens[0].Trim() == "NAME") { Prefab.Name = tokens[1].Trim(); } if (tokens[0].Trim() == "GLYPH") { Prefab.Glyph = Convert.ToInt32(tokens[1].Trim()); } if (tokens[0].Trim() == "COLOR") { string[] values = tokens[1].Split(','); Prefab.Color = new int[3] { Convert.ToInt32(values[0].Trim()), Convert.ToInt32(values[1].Trim()), Convert.ToInt32(values[2].Trim()) }; } if (tokens[0].Trim() == "MASS") { Prefab.Mass = Convert.ToInt32(tokens[1].Trim()); } if (tokens[0].Trim() == "WEAPON") { WeaponComponent WC = new WeaponComponent(TypeOfComponent.WEAPON, null); foreach (string weaponString in dict[i]) { string[] weaponTokens = weaponString.Split(':'); if (weaponTokens[0].Trim() == "EDGE") { string[] weaponvalues = weaponTokens[1].Split(','); WC.Attacks.Add( new Attack("EDGE", Convert.ToInt32(weaponvalues[0].Trim()), Convert.ToInt32(weaponvalues[1].Trim()) ) ); } } Prefab.Components.Add(WC); } if (tokens[0].Trim() == "CONTAINER") { ContainerComponent CC = new ContainerComponent(TypeOfComponent.CONTAINER, null); foreach (string containerString in dict[i]) { string[] containerTokens = containerString.Split(':'); if (containerTokens[0].Trim() == "CAPACITY") { CC.MaxCapacity = Convert.ToInt32(containerTokens[1]); } } Prefab.Components.Add(CC); } } itemPrefabs.Add(Prefab); } return(itemPrefabs); }