public static void IncreaseExperience(int id, int amount) { using (var db = new MinionWarsEntities()) { Users user = db.Users.Find(id); ModifierCoeficients maxLvl = db.ModifierCoeficients.Find(22); if (user.lvl == Convert.ToInt32(maxLvl.value)) { return; } else { user.experience += amount; ModifierCoeficients threshold = db.ModifierCoeficients.Find(21); if (user.experience > Convert.ToInt32(threshold.value)) { user.experience -= Convert.ToInt32(threshold.value); user.lvl++; if (user.points == null) { user.points = 0; } else { user.points++; } } db.Users.Attach(user); db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public static Orders ContinueOrders(Battlegroup bg, Orders o) { bool death = false; using (var db = new MinionWarsEntities()) { ModifierCoeficients ttl = db.ModifierCoeficients.Find(26); var difference = (DateTime.Now - bg.creation.Value).TotalMinutes; if (difference > ttl.value) { WildMinionGeneratorManager.SaveToPool(bg); bg.location = null; bg.orders_id = null; death = true; db.Battlegroup.Attach(bg); db.Entry(bg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } if (!death) { DbGeography newLoc = o.location; switch (o.name) { case "roam": o.name = "wait"; break; case "wait": var waitTime = (DateTime.Now - bg.lastMovement.Value).TotalMinutes; if (waitTime < 5) { o.name = "wait"; } else { o.name = "roam"; newLoc = GiveRandomDestination(bg, 250); } break; case "complete_task": o.name = "return"; newLoc = GetReturnDestination(bg); break; case "return": newLoc = GetReturnDestination(bg); if (bg.location.Distance(newLoc) < 10) { bg.location = null; bg.orders_id = null; newLoc = null; using (var db = new MinionWarsEntities()) { db.Battlegroup.Attach(bg); db.Entry(bg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } break; } o.location = newLoc; o.directions = Geolocations.Geolocations.GetNewDirections(bg.location, o); o.current_step = Geolocations.Geolocations.GetDirectionMovement(bg.location, o); using (var db = new MinionWarsEntities()) { db.Orders.Attach(o); db.Entry(o).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(o); } else { return(null); } }