public CraftResult Craft(Craftable c, int amount) { CraftResult result = new CraftResult(); result.atomsUsed = new List <AtomAmo>(); var atoms = c.GetAtomsForProduction(); for (int i = 0; i < atoms.Length; i++) // Find Minumum { var atomAmo = atoms[i]; AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber()); int needed = atomAmo.amo * amount; if (data.GetCurrAmo() < needed) { amount = data.GetCurrAmo() / atomAmo.amo; } } for (int i = 0; i < atoms.Length; i++) { var atomAmo = atoms[i]; AtomData data = Game.Instance.gameData.FindAtomData(atomAmo.atom.GetAtomicNumber()); int needed = atomAmo.amo * amount; data.Lose(needed); AtomAmo atomUsed = new AtomAmo(); atomUsed.atom = atomAmo.atom; atomUsed.amo = needed; result.atomsUsed.Add(atomUsed); } result.amountCreated = amount; int amoOfCraftables; if (!craftables.TryGetValue(c, out amoOfCraftables)) { craftables[c] = amount; } else { craftables[c] = amoOfCraftables + amount; } if (OnCraftableProduced != null) { OnCraftableProduced(c, amount); } return(result); }
public bool Upgrade() { bool success = CanUpgrade(); if (success) { for (int i = 0; i < data.cost.Count; i++) // Use { AtomAmo atomCost = data.cost[i]; if (atomCost.atom == null) { continue; } AtomData atomData = Game.Instance.gameData.FindAtomData(data.cost[i].atom.GetAtomicNumber()); atomData.Lose(data.cost[i].amo); } data.level++; data.value = valueProgression.Evaluate(data.level); data.cost.Clear(); if (!IsMaxLevel()) { AtomAmo amo = new AtomAmo(); for (int i = 0; i < atomProgression.Count; i++) { amo.amo = (int)amoProgression[i].Evaluate(data.level); int index = (int)atomProgression[i].Evaluate(data.level); if (index == 0) { amo.atom = null; } else { amo.atom = Game.Instance.gameData.FindAtom(index); } data.cost.Add(amo); } } } return(success); }
public void Use(Atom atom, int amo) { if (amo == 0) { return; } AtomData data = FindAtomData(atom.GetAtomicNumber()); if (data == null) { return; } data.Lose(amo); if (OnAtomUse != null) { OnAtomUse(atom, amo); } }