public void Create(float pUsage, float mProduction, types buildingType, tiers buildingTier, float bTime, float adjFactor) { powerUsage = pUsage; moneyProduction = mProduction; tier = buildingTier; buildTime = bTime; buildTimeLeft = bTime; state = states.Upgrading; type = buildingType; adjacencyFactor = adjFactor; }
public void Upgrade() { if (state != states.Upgrading) { Debug.Log(state.ToString() + tier.ToString()); if (Company.money >= costs[1] && tier == tiers.LowTech && buildTimeLeft == 0) { tier += 1; state = states.Upgrading; buildTimeLeft = buildTime * ((float)tier + 1f); pollutionRate = pollutionRate / 2f; powerUsage *= 3f; Company.money -= costs[1]; moneyProduction *= 2f; if (type == types.Factory) { DestroyChildren(this.transform); Debug.Log("L -> M"); GameObject.Instantiate(Resources.Load("Prefabs/Building_Factory_MedTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } if (type == types.Office) { DestroyChildren(this.transform); Debug.Log("L -> M"); GameObject.Instantiate(Resources.Load("Prefabs/Building_Office_MedTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } } if (Company.money >= costs[2] && tier == tiers.MediumTech && buildTimeLeft == 0) { tier += 1; state = states.Upgrading; buildTimeLeft = buildTime * ((float)tier + 1f); pollutionRate = pollutionRate / 2f; powerUsage *= 3f; Company.money -= costs[1]; moneyProduction *= 3f; if (type == types.Factory) { DestroyChildren(this.transform); Debug.Log("M -> H"); GameObject.Instantiate(Resources.Load("Prefabs/Building_Factory_HighTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } if (type == types.Office) { DestroyChildren(this.transform); Debug.Log("L -> M"); GameObject.Instantiate(Resources.Load("Prefabs/Building_Office_HighTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } } } }
public void UpgradeImmediate(tiers t) { switch (t) { case tiers.MediumTech: tier += 1; state = states.Upgrading; buildTimeLeft = buildTime * ((float)tier + 1f); pollutionRate = pollutionRate / 2f; powerUsage *= 3f; moneyProduction *= 2f; if (type == types.Factory) { DestroyChildren(this.transform); GameObject.Instantiate(Resources.Load("Prefabs/Building_Factory_MedTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } if (type == types.Office) { DestroyChildren(this.transform); GameObject.Instantiate(Resources.Load("Prefabs/Building_Office_MedTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } break; case tiers.HighTech: tier += 2; state = states.Upgrading; buildTimeLeft = buildTime * ((float)tier + 2f); pollutionRate = pollutionRate / 4f; powerUsage *= 15f; Company.money -= costs[1]; moneyProduction *= 10f; if (type == types.Factory) { DestroyChildren(this.transform); GameObject.Instantiate(Resources.Load("Prefabs/Building_Factory_HighTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } if (type == types.Office) { DestroyChildren(this.transform); GameObject.Instantiate(Resources.Load("Prefabs/Building_Office_HighTech") as GameObject, this.transform.position, this.transform.rotation, this.transform); } break; } }
public ActionResult Save([Bind(Include = "tiers,conjoint")] tiersconjointModel tier, long phone) { tiers t = tier.tiers; tiers conjoint = tier.conjoint; t.phone = phone; System.Diagnostics.Debug.WriteLine("phone " + t.phone); System.Diagnostics.Debug.WriteLine("phone2 " + t.phone2); try { DateTime localDate = DateTime.Now; if (t.id == 0) { t.age = localDate.Year - t.birth_date.Value.Year; t.id = t.id + 1; db.tiers.Add(t); db.SaveChanges(); } else { t.age = localDate.Year - t.birth_date.Value.Year; db.Entry(t).State = EntityState.Modified; db.SaveChanges(); } if (conjoint.id == 0 && tier.conjoint.lastname != null && tier.conjoint.firstname != null && tier.conjoint.phone != null && tier.conjoint.gender != null && tier.conjoint.phone2 != null && tier.conjoint.birth_date != null) { conjoint.id_folder = t.id_folder; conjoint.age = localDate.Year - conjoint.birth_date.Value.Year; db.tiers.Add(conjoint); db.SaveChanges(); } else if (conjoint.id != 0 && tier.conjoint.lastname != null && tier.conjoint.firstname != null && tier.conjoint.phone != null && tier.conjoint.gender != null && tier.conjoint.phone2 != null && tier.conjoint.birth_date != null) { conjoint.id_folder = t.id_folder; conjoint.age = localDate.Year - conjoint.birth_date.Value.Year; db.Entry(conjoint).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Details", "folders", new { id = t.id_folder })); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }