public static bool combineObjects(Player player, List <InventoryObject> materialsUsed) { int auxCount = 0; bool success = false; ObjectCombination chosenCombination = null; List <InventoryObject> materialsUsedClone = new List <InventoryObject>(); materialsUsedClone.AddRange(materialsUsed); foreach (ObjectCombination combination in InventoryObject.ObjectCombinations) { success = true; foreach (KeyValuePair <InventoryObject.ObjectTypes, int> material in combination.materials) { auxCount = 0; foreach (InventoryObject obj in materialsUsed) { if (material.Key.Equals(obj.Type)) { auxCount++; } } if (auxCount != material.Value) { //cantidad de objetos errónea success = false; break; } } if (success) { chosenCombination = combination; break; } } //pasó todos los controles -> OK if (null != chosenCombination) { //remuevo los objetos y le agrego el objeto final foreach (InventoryObject element in materialsUsedClone) { player.removeInventoryObject(element); } player.addInventoryObject(new InventoryObject(chosenCombination.result)); return(true); } else { return(false); } }
/// <summary> /// inicializo las distintas combinaciones posibles /// </summary> static InventoryObject() { //Daño por tipo de objeto DamagePerType.Add(ObjectTypes.Axe, 2); //Categorías CategoryPerType.Add(ObjectTypes.Axe, Categories.Tool); CategoryPerType.Add(ObjectTypes.WoodArmor, Categories.Armor); CategoryPerType.Add(ObjectTypes.Potion, Categories.Drink); CategoryPerType.Add(ObjectTypes.Water, Categories.Drink); CategoryPerType.Add(ObjectTypes.AlienMeat, Categories.Food); CategoryPerType.Add(ObjectTypes.Seed, Categories.Food); CategoryPerType.Add(ObjectTypes.Leaf, Categories.Food); CategoryPerType.Add(ObjectTypes.Rock, Categories.Other); CategoryPerType.Add(ObjectTypes.Wood, Categories.Other); //Combinaciones InventoryObject.ObjectCombinations = new List <ObjectCombination>(); //Defino el hacha ObjectCombination axe = new ObjectCombination(InventoryObject.ObjectTypes.Axe); axe.materials.Add(ObjectTypes.Wood, 2); axe.materials.Add(ObjectTypes.Rock, 1); InventoryObject.ObjectCombinations.Add(axe); //Defino la armadura de madera ObjectCombination armor = new ObjectCombination(InventoryObject.ObjectTypes.WoodArmor); armor.materials.Add(ObjectTypes.Wood, 4); armor.materials.Add(ObjectTypes.Leaf, 2); InventoryObject.ObjectCombinations.Add(armor); //Defino la poción ObjectCombination potion = new ObjectCombination(InventoryObject.ObjectTypes.Potion); potion.materials.Add(ObjectTypes.Seed, 2); potion.materials.Add(ObjectTypes.Water, 1); InventoryObject.ObjectCombinations.Add(potion); }