public static Battlegroup AddMinions(int m_id, int count, int type, Battlegroup bg) { using (var db = new MinionWarsEntities()) { Minion minion = db.Minion.Find(m_id); if (minion != null && bg != null) { BattlegroupAssignment assignment = new BattlegroupAssignment(); assignment.battlegroup_id = bg.id; assignment.minion_id = minion.id; assignment.group_count = count; assignment.line = type; db.BattlegroupAssignment.Add(assignment); /*CalculateAdvancedModifiers(bg, count, minion.passive); * * db.Battlegroup.Attach(bg); * db.Entry(bg).State = System.Data.Entity.EntityState.Modified;*/ db.SaveChanges(); } else { return(null); } return(bg); } }
private static DbGeography GetReturnDestination(Battlegroup bg) { using (var db = new MinionWarsEntities()) { return(db.UserMovementHistory.Where(x => x.users_id == bg.owner_id).OrderByDescending(x => x.occurence).First().location); } }
public static bool RemoveMinions(int a_id) { using (var db = new MinionWarsEntities()) { BattlegroupAssignment ba = db.BattlegroupAssignment.Find(a_id); if (ba != null) { MinionOwnership mo = null; Battlegroup bg = db.Battlegroup.Find(ba.battlegroup_id); mo = db.MinionOwnership.Where(x => x.minion_id == ba.minion_id && x.owner_id == bg.owner_id).First(); mo.available += ba.group_count; db.BattlegroupAssignment.Remove(ba); db.MinionOwnership.Attach(mo); db.Entry(mo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } else { return(false); } } }
//static MinionWarsEntities db = new MinionWarsEntities(); public static Orders GiveNewOrders(Battlegroup bg, string orders, DbGeography destination) { Orders o = new Orders(); o.name = orders; o.desc_text = "test"; //o.lastMovement = DateTime.Now; if (destination != null) { o.location = destination; } else { o.location = GiveRandomDestination(bg, 250); o.directions = Geolocations.Geolocations.GetNewDirections(bg.location, o); } using (var db = new MinionWarsEntities()) { db.Orders.Add(o); db.SaveChanges(); } //ContinueOrders(bg, o); return(o); }
public Character CreateCharacter(string code, object[] stats) { String name = (String)stats[0]; int essence = (int)stats[1]; int willpower = (int)stats[2]; List <String> healthLevels = (List <String>)stats[3]; Boolean isBattlegroup = (Boolean)stats[4]; String drill; int size, might; int persE = CalculatePersonalEssence(code, essence); int periE = CalculatePeripheralEssence(code, essence); if (!isBattlegroup) { CharacterTemplate template = new CharacterTemplate(code, essence, willpower, periE, persE, healthLevels, false); Character newChar = new Character(name, template); return(newChar); } else { drill = (String)stats[5]; size = (int)stats[6]; might = (int)stats[7]; CharacterTemplate template = new CharacterTemplate(code, essence, willpower, periE, persE, healthLevels, true); Battlegroup battleGroup = new Battlegroup(name, template, might, size, drill); return(battleGroup); } }
public static string ProcessAddition(int?o_id, int?amount, int?line, int?bg_id, string name) { if (amount == null) { return("amount is null"); } else if (line == null) { return("line is null"); } else if (o_id == null) { return("ownership is null"); } else if (bg_id == null && (name == null || name == "")) { return("bg error"); } else { Battlegroup bg = null; MinionOwnership mo = null; using (var db = new MinionWarsEntities()) { mo = db.MinionOwnership.Find(o_id); if (mo.available < amount) { return("Too much minions"); } else { if (name != null && name != "") { bg = BattlegroupManager.ConstructBattlegroup(mo.owner_id, 2, name); db.Battlegroup.Add(bg); } else if (bg_id != null) { bg = db.Battlegroup.Find(bg_id.Value); } mo.available -= amount; db.MinionOwnership.Attach(mo); db.Entry(mo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } if (bg != null && mo != null) { BattlegroupManager.AddMinions(mo.minion_id, amount.Value, line.Value, bg); } } return("ok"); }
private void HandleHealthUpdateBattleGroup(int rowIndex, int colIndex, DataGridViewRow row) { Battlegroup bg = (Battlegroup)currentFocus; //Only check current size and magnitude if (colIndex == 0 || colIndex == 2) { //Convert from string Boolean needToParseMag = !(row.Cells[0].Value is int); int rowMagnitude = 0; if (!needToParseMag) { rowMagnitude = (int)row.Cells[0].Value; } Boolean parseSuccesful = needToParseMag ? int.TryParse((string)row.Cells[0].Value, out rowMagnitude) : true; Boolean needToParseSize = !(row.Cells[2].Value is int); int rowSize = 0; if (!needToParseSize) { rowSize = (int)row.Cells[2].Value; } parseSuccesful = parseSuccesful && (needToParseSize ? int.TryParse((string)row.Cells[2].Value, out rowSize) : true); if (parseSuccesful) { //Change values, size first if (rowSize != bg.CurrentSize) { bg.CurrentSize = rowSize; } if (rowMagnitude != bg.CurrentMagnitude) { if (!(rowMagnitude <= 0)) { bg.CurrentMagnitude = rowMagnitude; } else { //If magnitude drops below 0, drop size and restore mag to new max bg.CurrentSize--; if (bg.CurrentSize <= 0) { //Set to 0 for cleanup step bg.CurrentMagnitude = 0; } else { bg.CurrentMagnitude = bg.GetCurrentMaxMagnitude(); } } } } } }
private void populateBattlegroupList() { this.battlegroups = new Battlegroups(); gBattleAPI.BattleNET.Battlegroups battlegroups = api.getBattlegroups(); foreach (gBattleAPI.BattleNET.Battlegroups.Battlegroup bg in battlegroups.battlegroups) { Battlegroup _bg = new Battlegroup(); _bg.name = bg.name; _bg.slug = bg.slug; this.battlegroups.Add(_bg); } battlegroups = null; }
private static DbGeography GiveRandomDestination(Battlegroup bg, int distance) { DbGeography newLoc = null; Random rand = new Random(); double latMove = GenerateRandomDistance(rand, distance); double lonMove = GenerateRandomDistance(rand, distance); var point = string.Format("POINT({1} {0})", (bg.location.Latitude + latMove), (bg.location.Longitude + lonMove)); newLoc = DbGeography.FromText(point); return(newLoc); }
private static async Task DoBattlegroupWork() { while (true) { List <Battlegroup> bgl = MapMovementUpdater.GetAllBattlegroups(); foreach (Battlegroup bg in bgl) { Battlegroup updatedObj = MapMovementUpdater.UpdateBattlegroupPosition(bg); updatedObj = null; } bgl = null; await Task.Delay(1); } }
public void CalculateGroupStats(Battlegroup bg, int line) { GroupCombatStats stats = new GroupCombatStats(); stats.strength += Convert.ToInt32(this.minionData.strength + (this.minionData.strength * bg.str_mod)); stats.dexterity += Convert.ToInt32(this.minionData.dexterity + (this.minionData.dexterity * bg.dex_mod)); stats.vitality += Convert.ToInt32(this.minionData.vitality + (this.minionData.vitality * bg.vit_mod)); stats.health = stats.vitality * 5 * this.initialCount; stats.healthPerMinion = stats.vitality * 5; stats.power += Convert.ToInt32(this.minionData.power + (this.minionData.power * bg.pow_mod)); stats.cooldown += Convert.ToInt32(this.minionData.cooldown); stats.duration += Convert.ToInt32(this.minionData.duration); this.stats = stats; }
public static void SaveToPool(Battlegroup bg) { using (var db = new MinionWarsEntities()) { EvolutionPool ep = new EvolutionPool(); Random r = new Random(); List <BattlegroupAssignment> bga = db.BattlegroupAssignment.Where(x => x.battlegroup_id == bg.id).ToList(); ep.minion_id = bga.OrderBy(x => r.Next()).First().minion_id; ep.last_location = bg.location; ep.stored_date = DateTime.Now; db.EvolutionPool.Add(ep); db.SaveChanges(); } }
public static void CreateNewPersonalBattlegroup(int id) { using (var db = new MinionWarsEntities()) { Battlegroup bg = BattlegroupManager.ConstructBattlegroup(id, 1, "Personal Battlegroup"); Users user = db.Users.Find(id); db.Battlegroup.Add(bg); db.SaveChanges(); user.personal_bg_id = bg.id; db.Users.Attach(user); db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
private static bool CheckForOwnership(int bg1_id, int bg2_id) { using (var db = new MinionWarsEntities()) { Battlegroup bg1 = db.Battlegroup.Find(bg1_id); Battlegroup bg2 = db.Battlegroup.Find(bg2_id); if (bg1.owner_id == bg2.owner_id) { return(false); } else { return(true); } } }
/*public static Battlegroup GetGroupDetails(int bg_id) * { * Battlegroup bg = null; * using (var db = new MinionWarsEntities()) * { * db.Configuration.LazyLoadingEnabled = false; * bg = db.Battlegroup.Find(bg_id); * } * return bg; * }*/ public static Battlegroup GetLastAssigned(int lastAssigned) { Battlegroup newBg = null; while (newBg == null) { using (var db = new MinionWarsEntities()) { do { newBg = db.Battlegroup.Find(lastAssigned); lastAssigned++; } while (newBg.location == null || newBg.orders_id == null); } } return(newBg); }
public static void GenerateGeneticMinionGroup(DbGeography location, List <EvolutionPool> epl) { Random r = new Random(); epl = epl.OrderBy(x => r.Next()).ToList(); Minion WildMinion = MinionGenotype.generateGeneticMinion(epl[0], epl[1]); Battlegroup WildGroup = BattlegroupManager.ConstructBattlegroup(null, 0, "Wild Group"); WildGroup.location = location; using (var db = new MinionWarsEntities()) { db.Battlegroup.Add(WildGroup); db.SaveChanges(); } BattlegroupManager.AddMinions(WildMinion.id, r.Next(2, 13), 0, WildGroup); BattlegroupManager.AddMinions(WildMinion.id, r.Next(2, 13), 1, WildGroup); BattlegroupManager.AddMinions(WildMinion.id, r.Next(2, 13), 2, WildGroup); using (var db = new MinionWarsEntities()) { List <BattlegroupAssignment> bgaList = db.BattlegroupAssignment.Where(x => x.battlegroup_id == WildGroup.id).ToList(); foreach (BattlegroupAssignment bga in bgaList) { BattlegroupManager.CalculateAdvancedModifiers(WildGroup, bga.id, WildMinion.passive); } } //CalculateAdvancedModifiers(bg, count, minion.passive); //orders Orders o = OrdersManager.GiveNewOrders(WildGroup, "roam", null); WildGroup.lastMovement = DateTime.Now; using (var db = new MinionWarsEntities()) { WildGroup.orders_id = o.id; //db.Battlegroup.Add(WildGroup); db.Battlegroup.Attach(WildGroup); db.Entry(WildGroup).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
/*private static void GetTraitModifiers(Users owner, Battlegroup bg, int type) * { * using (var db = new MinionWarsEntities()) * { * UserTraits traits = db.UserTraits.Find(owner.traits_id); * * if (traits != null) * { * bg.movement_mod += traits.cbg_speed * 0.1; * * int sizeModifier = 0; * if (type == 0) sizeModifier = 20 + traits.pbg_size * 4; * else sizeModifier = 10 + traits.cbg_size * 2; * bg.size += sizeModifier; * * bg.build_mod += traits.arch_speed * 0.1; * } * } * }*/ private static void SetBasicModifiers(Battlegroup bg) { bg.str_mod = 0; bg.dex_mod = 0; bg.vit_mod = 0; bg.pow_mod = 0; bg.res_mod = 0; bg.metal_mod = 0; bg.stone_mod = 0; bg.tree_mod = 0; bg.food_mod = 0; bg.build_mod = 0; bg.movement_mod = 0; bg.reproduction_mod = 0; bg.loot_mod = 0; bg.regen_mod = 0; bg.resurrection_mod = 0; bg.defense_mod = 0; }
public static bool SendRemoteGroup(int bg_id, string point, string currentPoint) { Battlegroup bg = null; using (var db = new MinionWarsEntities()) { bg = db.Battlegroup.Find(bg_id); } DbGeography loc = DbGeography.FromText(point); DbGeography currentLoc = DbGeography.FromText(currentPoint); Orders o = OrdersManager.GiveNewOrders(bg, "complete_task", loc); using (var db = new MinionWarsEntities()) { bg.orders_id = o.id; bg.location = currentLoc; db.Battlegroup.Attach(bg); db.Entry(bg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(true); }
public void RedrawHealthLevels() { RedrawingHealthLevels = true; Character currentFocus = combatController.currentFocus; //Adjust table int nrOfColumns = currentFocus.CurrentHealthLevels.Count; dataGridView_Focus_HealthLevels.Rows.Clear(); dataGridView_Focus_HealthLevels.Columns.Clear(); List <String> healthValuesAsString = new List <String>(); if (!currentFocus.Battlegroup) { //set row width and columnheight foreach (KeyValuePair <String, Constants.HealthState> kvp in currentFocus.CurrentHealthLevels) { dataGridView_Focus_HealthLevels.Columns.Add(kvp.Key, kvp.Key); healthValuesAsString.Add(Constants.HealthStateToString(kvp.Value)); } dataGridView_Focus_HealthLevels.Rows.Add(healthValuesAsString.ToArray()); } else { dataGridView_Focus_HealthLevels.Columns.Add("CurrentMagnitude", "Current Magnitude"); dataGridView_Focus_HealthLevels.Columns.Add("MaxMagnitude", "Max Magnitude"); dataGridView_Focus_HealthLevels.Columns.Add("CurrentSize", "Current Size"); dataGridView_Focus_HealthLevels.Columns.Add("MaxSize", "Max Size"); //Current size and magnitude Battlegroup bg = (Battlegroup)currentFocus; String[] values = { "" + bg.CurrentMagnitude, "" + bg.GetCurrentMaxMagnitude(), "" + bg.CurrentSize, "" + bg.Size }; dataGridView_Focus_HealthLevels.Rows.Add(values); } dataGridView_Focus_HealthLevels.CellEndEdit += new DataGridViewCellEventHandler(combatController.handle_focus_health_update); RedrawingHealthLevels = false; }
public static Battlegroup UpdatePosition(Battlegroup bg) { Orders orders = null; using (var db = new MinionWarsEntities()) { orders = db.Orders.Find(bg.orders_id); } bool arrived = false; if (bg.location.Distance(orders.location).Value <= 10) { arrived = true; orders = OrdersManager.ContinueOrders(bg, orders); } //bg.location = Geolocations.Geolocations.PerformMovement(bg.location, bg.lastMovement.Value, orders, bg.group_speed); if (orders.current_step == null) { orders.current_step = Geolocations.GetDirectionMovement(bg.location, orders); if (orders.current_step == null) { orders = OrdersManager.ContinueOrders(bg, orders); } else { using (var db = new MinionWarsEntities()) { db.Orders.Attach(orders); db.Entry(orders).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } if (bg.location.Distance(orders.current_step) <= 10) { orders.current_step = Geolocations.GetDirectionMovement(bg.location, orders); if (orders.current_step == null) { orders = OrdersManager.ContinueOrders(bg, orders); } else { using (var db = new MinionWarsEntities()) { db.Orders.Attach(orders); db.Entry(orders).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } bg.location = Geolocations.PerformDirectionMovement(bg.location, orders.current_step, bg.lastMovement.Value, bg.group_speed); bg.lastMovement = DateTime.Now; using (var db = new MinionWarsEntities()) { db.Battlegroup.Attach(bg); db.Entry(bg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(bg); }
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); } }
public void Remove(Battlegroup battlegroup) { m_queue.Remove(battlegroup); m_size -= (uint)battlegroup.Size; }
public void Add(Battlegroup battlegroup) { m_queue.Add(battlegroup); m_size += (uint)battlegroup.Size; }
public void Add(Group group) { Battlegroup bg = new Battlegroup(group, this); Add(bg); }
public void Add(Character character) { Battlegroup bg = new Battlegroup(character, this); Add(bg); }
public static Battlegroup ConstructBattlegroup(int?owner_id, int type, string name) { Battlegroup bg = new Battlegroup(); SetBasicModifiers(bg); bg.creation = DateTime.Now; if (owner_id != null) { using (var db = new MinionWarsEntities()) { Users owner = db.Users.Find(owner_id); if (owner != null) { bg.owner_id = owner_id.Value; /* types * 1 - personal * 2 - remote * 3 - defensive */ bg.type = type; bg.movement_mod += owner.trait_logistics * 0.1; int sizeModifier = 0; if (type == 1) { sizeModifier = 20 + owner.trait_leadership * 3; bg.loot_mod += owner.trait_leadership * 5; bg.res_mod += owner.trait_leadership * 5; bg.resurrection_mod += owner.trait_leadership; } else if (type == 2) { sizeModifier = 10 + owner.trait_logistics * 2; bg.loot_mod += owner.trait_logistics * 2.5; bg.res_mod += owner.trait_logistics * 2.5; bg.resurrection_mod += owner.trait_logistics; } else if (type == 3) { sizeModifier = 20 + owner.trait_architecture * 2; bg.defense_mod += owner.trait_architecture; bg.build_mod += owner.trait_architecture * 2; } bg.size = 0 + sizeModifier; } else { return(null); } } } else { bg.owner_id = null; } bg.name = name; return(bg); }
public static Battlegroup UpdateBattlegroupPosition(Battlegroup bg) { return(BattlegroupManager.UpdatePosition(bg)); }
public static Battlegroup GetNewAssignment(int lastAssigned) { Battlegroup newBg = BattlegroupManager.GetLastAssigned(lastAssigned); return(newBg); }
public static void CalculateAdvancedModifiers(Battlegroup bg, int count, int passive) { switch (passive) { case 0: bg.str_mod += GetModifierCoeficients(3) * count; break; case 1: bg.dex_mod += GetModifierCoeficients(1) * count; break; case 2: bg.vit_mod += GetModifierCoeficients(2) * count; break; case 3: bg.pow_mod += GetModifierCoeficients(7) * count; break; case 4: bg.res_mod += GetModifierCoeficients(4) * count; break; case 5: bg.metal_mod += GetModifierCoeficients(13) * count; break; case 6: bg.stone_mod += GetModifierCoeficients(9) * count; break; case 7: bg.tree_mod += GetModifierCoeficients(10) * count; break; case 8: bg.food_mod += GetModifierCoeficients(15) * count; break; case 9: bg.build_mod += GetModifierCoeficients(12) * count; break; case 10: bg.movement_mod += GetModifierCoeficients(16) * count; break; case 11: bg.reproduction_mod += GetModifierCoeficients(14) * count; break; case 12: bg.loot_mod += GetModifierCoeficients(6) * count; break; case 13: bg.regen_mod += Convert.ToInt32(Math.Floor(GetModifierCoeficients(11) * count)); break; case 14: bg.resurrection_mod += Convert.ToInt32(Math.Floor(GetModifierCoeficients(5) * count)); break; case 15: bg.defense_mod += Convert.ToInt32(Math.Floor(GetModifierCoeficients(17) * count)); break; } bg.group_speed = Convert.ToInt32(Math.Floor(10 + 10 * bg.movement_mod)); }