public void AddItem(Item item) { // search for existing item Item myItem = null; if (item != null) { if (inventory.ContainsKey(item.uuid)) { // item gefunden myItem = inventory[item.uuid]; if (myItem.stackable) { // item darf gestackt werden myItem.amount += item.amount; } } else { // item nicht gefunden, hinzufuegen myItem = new Item(item); inventory.Add(myItem.uuid, myItem); } UpdateEffectToPlayerStatistics(myItem, true); CheckMaxValuesInInventory(myItem); } // publish all statistic data to all depending components statistics.PublishBaseData(); UpdateSelectedItem(myItem); }
public void RefreshSaveData(PlayerSaveData saveData) { lives = saveData.lives; health = saveData.health; inventoryManager.selectedPotionUuid = saveData.selectedPotionUuid; inventoryManager.selectedAmmoUuid = saveData.selectedAmmoUuid; ModifyPoints(saveData.points - points); currentStamina = saveData.currentStamina; if (saveData.hasSquareKey) { ModifyKeys(CollectableKeys.KEY_TYPE.SQUARE, true); } if (saveData.hasCircleKey) { ModifyKeys(CollectableKeys.KEY_TYPE.CIRCLE, true); } if (saveData.hasTriangleKey) { ModifyKeys(CollectableKeys.KEY_TYPE.TRIANGLE, true); } DictionaryOfUuidAndItem inventoryItems = new DictionaryOfUuidAndItem(); foreach (KeyValuePair <string, int> kvp in saveData.inventoryItems) { Item originalItem = ItemManager.GetInstance().FindItem(kvp.Key); Item myItem = new Item(originalItem); myItem.amount = kvp.Value; inventoryItems.Add(myItem.uuid, myItem); } inventoryManager.InitInventory(inventoryItems); }