public void addInformation(ItemVariables data) { str = ""; foreach (KeyValuePair <string, string> item in data.getStrings()) { if (data.shouldShow(item.Key)) { str += item.Key + ": " + item.Value + " \n"; } } foreach (KeyValuePair <string, float> item in data.getFloats()) { if (data.shouldShow(item.Key)) { str += item.Key + ": " + item.Value + " \n"; } } foreach (KeyValuePair <string, int> item in data.getInts()) { if (data.shouldShow(item.Key)) { str += item.Key + ": " + item.Value + " \n"; } } }
public ItemVariables generateVariables() { ItemVariables variables = new ItemVariables(); foreach (FieldInfo field in this.GetType().GetFields()) { if (field.FieldType == typeof(int)) { variables.addInt(field.Name, (int)field.GetValue(this)); } if (field.FieldType == typeof(float)) { variables.addFloat(field.Name, (int)field.GetValue(this)); } if (field.FieldType == typeof(string)) { variables.addString(field.Name, (string)field.GetValue(this)); } if (field.FieldType == typeof(string[]) && field.Name == "show") { variables.setToShow((string[])field.GetValue(this)); } } return(variables); }
private void AddVariable() { ItemVariables itemVariable = new ItemVariables(); itemVariable.index = variables.Count - 1; itemVariable.dataType = typeof(int); itemVariable.data = 0; itemVariable.uid = Guid.NewGuid().ToString(); variables.Add(itemVariable); SaveData(); }
public ItemVariables useItem(Item item) { //hämtar items variablar. ItemVariables pot = ItemDataProvider.getInstance().getStats(item.getID()); //kollar om det är en use så den läser in rätt variablar if (item.getID().isItemType(e_itemTypes.USE)) { //ökar hpet på spelare och manan. this.getPlayerStats().health = Mathf.Min(this.getPlayerStats().health + pot.getInt("health"), getPlayerStats().maxHealth); this.getPlayerStats().mana = Mathf.Min(this.getPlayerStats().mana + pot.getInt("mana"), getPlayerStats().maxMana); //gör så att mängden minskar med 1. item.setQuantity(item.getQuantity() - 1); } return(pot); }
private InventoryInformationString displayInfo() { int itemID = item.getID(); ItemVariables info = ItemDataProvider.getInstance().getStats(item.getID()); InventoryInformationString data = new InventoryInformationString(); data.setName(info.getString("name")); data.setDescription(info.getString("description")); if (itemID.isItemType(e_itemTypes.EQUIP)) { data.setString("Stats \n Watt: " + item.getDamage() + " \n Matt: " + item.getMagicAttack() + " \n Luk: " + item.getLuk() + ""); } else { data.addInformation(info); } return(data); }
void onItemUse(NetworkMessage netMsg) { ItemInfo info = netMsg.ReadMessage <ItemInfo>(); Item item = (Item)Tools.byteArrayToObject(info.item); ItemVariables vars = (ItemVariables)Tools.byteArrayToObject(info.itemVariables); Item orgItem = (Item)Tools.byteArrayToObject(info.oldItem); if (item.getInventoryType() != (int)e_ItemTypes.EQUIP) { if (item.getID().isItemType(e_itemTypes.USE)) { onPotUse(vars); } if (item.getQuantity() == 0) { player.getInventory().removeItem(orgItem); return; } player.getInventory().updateItem(orgItem, item); } }
public ItemVariables getMobStats(int mobID) { if (itemValues.ContainsKey(mobID)) { return(itemValues[mobID]); } FileInfo file = this.directory.getFileContainingString(mobID); StreamReader reader = file.OpenText(); string fileContents = ""; string line = ""; while ((line = reader.ReadLine()) != null) { fileContents += line + Environment.NewLine; } reader.Close(); ItemDataAll ItemDataAll = mobDataConverter(mobID, fileContents); ItemVariables variables = ItemDataAll.generateVariables(); itemValues.Add(mobID, variables); return(variables); }
void TryToInteract() { Ray ray = playerCam.GetComponent <Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit, pickupRange)) { objectInteract = hit.collider.gameObject; if (objectInteract.tag == itemTag) { // pick up // chek if inventory is full if (inventorySlots.childCount == slotsCount) { Debug.Log("inventory is full"); } else { // faire disparaitre l'item objectInteract.SetActive(false); // intégrer l'item dans l'inventaire Transform newItem; newItem = Instantiate(itemPrefab, Vector3.zero, Quaternion.identity) as Transform; newItem.SetParent(inventorySlots, false); // transférer les données de l'item ItemSlots itemInventory = newItem.GetComponent <ItemSlots>(); ItemVariables itemScene = objectInteract.GetComponent <ItemVariables>(); itemInventory.itemType = itemScene.itemType; itemInventory.itemID = itemScene.itemID; itemInventory.itemSprite = itemScene.itemSprite; itemInventory.itemDescription = itemScene.itemDescription; } } } }
public ItemVariables getItemStats(int itemID) { if (itemValues.ContainsKey(itemID)) { return(itemValues[itemID]); } FileInfo file = this.directory.getFileContainingString(itemID); StreamReader reader = file.OpenText(); string fileContents = ""; string line = ""; while ((line = reader.ReadLine()) != null) { fileContents += line + Environment.NewLine; } reader.Close(); ItemDataAll ItemDataAll = itemDataConverter(itemID, fileContents); //Debug.Log("ITEM ID!!!: " + itemID); ItemVariables variables = ItemDataAll.generateVariables(); itemValues.Add(itemID, variables); Debug.Log("dictionary size: " + itemValues.Count); return(variables); }
private void AddVariable(ItemVariables variable) { variables.Add(variable); }
public static Sprite getSprite(this int itemID) { ItemVariables vars = ItemDataProvider.getInstance().getStats(itemID); return((Sprite)sprites[vars.getInt("imageIndex")]); }
public void setItemVariables(ItemVariables dataDisplay) { this.dataDisplay = dataDisplay; }
void onPotUse(ItemVariables vars) { this.player.setHealth(Mathf.Min(this.player.stats.health + vars.getInt("health"), player.stats.maxHealth)); this.player.setMana(Mathf.Min(this.player.stats.mana + vars.getInt("mana"), player.stats.maxMana)); }