public void ProduceUnit(unitCreation c, Owner b, bool avoid = false) { var we = new DeployementOrder(c, deplToUse.stat, deplToUse.ExtraExperience); if (avoid) { we = new DeployementOrder(c, new SpecialUnit.stats(), 0); } if (!GameManager.DEBUG_GODMODE) { if (!HasEnoughRessource(we, b.Inventory)) { if (b.IsPlayer) { GameManager.ShowMessage("Not enough materials for unit!"); } return; } } b.Pay(c.unit.gameObject.GetComponent <unit>().GoldCost + we.extraGold); foreach (var item in we.Unit.Costs) { we.AdditionalCost.Add(item); } b.Pay(we.AdditionalCost.ToArray()); QUI.CreateNewIcon(we); UnitsToDeploy.Enqueue(we); }
public bool HasEnoughRessource(DeployementOrder x, Dictionary <string, Goods> c) { if (GetOwner.Gold < (x.Unit.goldCost + x.extraGold)) { return(false); } var et = x.AdditionalCost; foreach (var item in x.Unit.Costs) { et.Add(item); } if (et.Count == 0) { return(true); } foreach (var item in et) { bool ok = false; if (c.ContainsKey(item.Name)) { ok = c[item.Name].getAmount >= item.getAmount; } if (!ok) { return(false); } } return(true); }
void ActuallyDeploy(DeployementOrder de, Owner b) { var e = Instantiate(de.Unit.unit, transform.position + transform.forward, Quaternion.identity).GetComponent <unit>(); e.TransferOwner(b); b.AddFighter(de.Unit.civilianCost); if (!e.Ordered) { e.MoveTo(WhereToGo.transform.position); } if (e is SpecialUnit) { var s = e as SpecialUnit; s.GainEXP(de.ExtraExperience); s.Stat += de.stat; } OnCompletedUnit?.Invoke(e); }