Exemple #1
0
        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");
        }
Exemple #2
0
        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();
            }
        }