예제 #1
0
    public void addOrder(OrderInfo orderInfo)
    {
        User    user        = CurrentUser.Current;
        Kingdom userKingdom = new KingdomDAO().GetByUserId(user.UserId);

        OrderType orderType = new OrderTypeDAO().GetByName(orderInfo.orderType);

        Order orderToAdd = new Order();

        orderToAdd.Count              = orderInfo.unitCount;
        orderToAdd.KingdomId          = userKingdom.KingdomId;
        orderToAdd.Epoch              = new EpochDAO().GetCurrentByMapId(userKingdom.MapId).EpochId;
        orderToAdd.FieldId            = orderInfo.sourceTileId;
        orderToAdd.FieldIdDestination = orderInfo.destinationTileId;
        orderToAdd.OrderTypeId        = orderType.OrderTypeId;
        orderToAdd.UnitTypeId         = 1; //Na razie mamy hardcode na piechote

        //db.AddInParameter(cmd, "OrderTypeId", DbType.Int32, this.DataObject.OrderTypeId);
        //db.AddInParameter(cmd, "FieldId", DbType.Int32, this.DataObject.FieldId);
        //db.AddInParameter(cmd, "FieldIdDestination", DbType.Int32, this.DataObject.FieldIdDestination);
        //db.AddInParameter(cmd, "Epoch", DbType.Int32, this.DataObject.Epoch);
        //db.AddInParameter(cmd, "Count", DbType.Int32, this.DataObject.Count);
        //db.AddInParameter(cmd, "UnitTypeId", DbType.Int32, this.DataObject.UnitTypeId);
        // db.AddInParameter(cmd, "KingdomId", DbType.Int32, this.DataObject.KingdomId);


        new OrderDAO().Add(orderToAdd);
    }
예제 #2
0
        public void Buy(int kingdomId, int technologyId)
        {
            KingdomTechnology kt = new KingdomTechnology()
            {
                 KingdomId = kingdomId,
                 TechnologyId = technologyId
            };
            KingdomTechnology old = new KingdomTechnologyDAO().GetByKingdomAndTechnology(kingdomId, technologyId);

            if(old.KingdomTechnologyId == 0)
            {
                new KingdomTechnologyDAO().Add(kt);
                Kingdom k = new KingdomDAO().GetByUserId(CurrentUser.UserId);
                Technology t = new TechnologyDAO().GetById(technologyId);
                k.KingdomResources -= t.TechnologyCost;
                new KingdomDAO().Update(k);
            }
        }
예제 #3
0
        public void Buy(int kingdomId, int technologyId)
        {
            KingdomTechnology kt = new KingdomTechnology()
            {
                KingdomId    = kingdomId,
                TechnologyId = technologyId
            };
            KingdomTechnology old = new KingdomTechnologyDAO().GetByKingdomAndTechnology(kingdomId, technologyId);

            if (old.KingdomTechnologyId == 0)
            {
                new KingdomTechnologyDAO().Add(kt);
                Kingdom    k = new KingdomDAO().GetByUserId(CurrentUser.UserId);
                Technology t = new TechnologyDAO().GetById(technologyId);
                k.KingdomResources -= t.TechnologyCost;
                new KingdomDAO().Update(k);
            }
        }
예제 #4
0
        public static void LoadCurrentUser(string userName, HttpContext context)
        {
            User User = (new UserDAO()).GetByUserName(userName, null);
            Kingdom kingdom = new KingdomDAO().GetByUserId(User.UserId);

            context.Session.Add("KingdomId", kingdom.KingdomId);
            context.Session.Add("CurrentUser", User);
            context.Session.Add("UserId", User.UserId);

            IList<Role> roles = new RoleDAO().GetByUserId(User.UserId);

            Dictionary<string, int> roleNames = new Dictionary<string, int>();
            foreach (Role role in roles)
            {
                if (roleNames.ContainsKey(role.RoleName.ToLower()) == false)
                {
                    roleNames.Add(role.RoleName.ToLower(), role.RoleId);
                }
            }
            context.Session.Add("UserRoles", roleNames);
        }
예제 #5
0
        public static void LoadCurrentUser(string userName, HttpContext context)
        {
            User    User    = (new UserDAO()).GetByUserName(userName, null);
            Kingdom kingdom = new KingdomDAO().GetByUserId(User.UserId);

            context.Session.Add("KingdomId", kingdom.KingdomId);
            context.Session.Add("CurrentUser", User);
            context.Session.Add("UserId", User.UserId);

            IList <Role> roles = new RoleDAO().GetByUserId(User.UserId);

            Dictionary <string, int> roleNames = new Dictionary <string, int>();

            foreach (Role role in roles)
            {
                if (roleNames.ContainsKey(role.RoleName.ToLower()) == false)
                {
                    roleNames.Add(role.RoleName.ToLower(), role.RoleId);
                }
            }
            context.Session.Add("UserRoles", roleNames);
        }
예제 #6
0
    public MapModel GetMapModel()
    {
        User    user        = CurrentUser.Current;
        Kingdom userKingdom = new KingdomDAO().GetByUserId(user.UserId);

        IList <Kingdom> kingdoms = new KingdomDAO().GetByMapId(userKingdom.MapId);

        List <Owner> players = new List <Owner>();

        Random random = new Random();



        foreach (Kingdom k in kingdoms)
        {
            if (k.KingdomId == userKingdom.KingdomId)
            {
                players.Add(new Owner(userKingdom.KingdomId, userKingdom.KingdomName, "#FF0000"));
            }
            else
            {
                players.Add(new Owner(k.KingdomId, k.KingdomName, String.Format("#{0:X6}", random.Next(0x1000000))));
            }
        }



        List <TileInfo> tiles = new List <TileInfo>();

        IList <Field> fields = new FieldDAO().GetByMapId(userKingdom.MapId);


        foreach (Field field in fields)
        {
            IList <Unit> units     = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1);
            int          unitCount = 0;
            foreach (Unit u in units)
            {
                unitCount += u.Count;
            }

            tiles.Add(new TileInfo(field.FieldId, field.FieldX, field.FieldY, field.FieldName, field.KingdomId, unitCount));
        }


        //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Orders need to be taken away from the database too !!!!!!!!!!!!!!!!!!1
        List <OrderInfo> orders   = new List <OrderInfo>();
        IList <Order>    ordersDB = new OrderDAO().GetByKingdomEpoch(userKingdom.KingdomId, new EpochDAO().GetCurrentByMapId(userKingdom.MapId).EpochId);

        Dictionary <int, UnitType> unitTypes = new Dictionary <int, UnitType>();

        IList <UnitType> unitTypesAll = new UnitTypeDAO().GetAll();

        foreach (UnitType ut in unitTypesAll)
        {
            unitTypes.Add(ut.UnitTypeId, ut);
        }

        foreach (Order o in ordersDB)
        {
            if (o.OrderTypeName.Equals("Buy"))
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, unitTypes[o.UnitTypeId].UnitTypeCost * o.Count));
            }
            else
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, 0));
            }
        }

        //orders.Add(new OrderInfo("Defend",1,1,5,0));
        //int rice = 1000;

        //List<Owner> players = new List<Owner>();

        //Owner owner1 = new Owner(1, "Moose", "#ff0000");
        //Owner owner2 = new Owner(2, "Lucas", "#00ff00");

        //players.Add(owner1);
        //players.Add(owner2);

        //List<TileInfo> tiles = new List<TileInfo>();

        //tiles.Add(new TileInfo(1,1,1,"Krwawe wzgórza", owner1.playerId, 5));
        //tiles.Add(new TileInfo(2,2,1,"MooseVille", owner1.playerId, 5));
        //tiles.Add(new TileInfo(3,2,2,"Grunwald", owner1.playerId, 5));
        //tiles.Add(new TileInfo(4,1,2,"Bździochy dolne", null, 5));
        //tiles.Add(new TileInfo(5,3,4,"Cukierkowa Dolina", owner2.playerId, 10));
        //tiles.Add(new TileInfo(6,5,5,"Wilczy Szaniec", owner2.playerId, 10));
        //List<OrderInfo> orders = new List<OrderInfo>();


        //orders.Add(new OrderInfo("Defend",1,1,5,0));
        return(new MapModel(userKingdom.KingdomResources, tiles, players, orders));
    }
예제 #7
0
	public void addOrder(OrderInfo orderInfo)
	{
        User user = CurrentUser.Current;
        Kingdom userKingdom = new KingdomDAO().GetByUserId(user.UserId);

		OrderType orderType = new OrderTypeDAO().GetByName(orderInfo.orderType);

		Order orderToAdd = new Order();

		orderToAdd.Count = orderInfo.unitCount;
        orderToAdd.KingdomId = userKingdom.KingdomId;
		orderToAdd.Epoch = new EpochDAO().GetCurrentByMapId(userKingdom.MapId).EpochId;
		orderToAdd.FieldId = orderInfo.sourceTileId;
		orderToAdd.FieldIdDestination = orderInfo.destinationTileId;
        orderToAdd.OrderTypeId = orderType.OrderTypeId;
        orderToAdd.UnitTypeId = 1; //Na razie mamy hardcode na piechote

        //db.AddInParameter(cmd, "OrderTypeId", DbType.Int32, this.DataObject.OrderTypeId);
        //db.AddInParameter(cmd, "FieldId", DbType.Int32, this.DataObject.FieldId);
        //db.AddInParameter(cmd, "FieldIdDestination", DbType.Int32, this.DataObject.FieldIdDestination);
        //db.AddInParameter(cmd, "Epoch", DbType.Int32, this.DataObject.Epoch);
        //db.AddInParameter(cmd, "Count", DbType.Int32, this.DataObject.Count);
        //db.AddInParameter(cmd, "UnitTypeId", DbType.Int32, this.DataObject.UnitTypeId);
       // db.AddInParameter(cmd, "KingdomId", DbType.Int32, this.DataObject.KingdomId);


		new OrderDAO().Add(orderToAdd);
	}
예제 #8
0
	public MapModel GetMapModel() 
	{
        User user = CurrentUser.Current;
        Kingdom userKingdom = new KingdomDAO().GetByUserId(user.UserId);

        IList<Kingdom> kingdoms = new KingdomDAO().GetByMapId(userKingdom.MapId);

        List<Owner> players = new List<Owner>();

        Random random = new Random();

        

        foreach (Kingdom k in kingdoms)
        {
            if (k.KingdomId == userKingdom.KingdomId)
            {
                players.Add(new Owner(userKingdom.KingdomId, userKingdom.KingdomName, "#FF0000"));
            }
            else
            {
                players.Add(new Owner(k.KingdomId, k.KingdomName, String.Format("#{0:X6}", random.Next(0x1000000))));
            }
        }

        

        List<TileInfo> tiles = new List<TileInfo>();

        IList<Field> fields = new FieldDAO().GetByMapId(userKingdom.MapId);


        foreach (Field field in fields)
        {
            IList<Unit> units = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1);
            int unitCount = 0;
            foreach (Unit u in units)
            {
                unitCount += u.Count;
            }

            tiles.Add(new TileInfo(field.FieldId, field.FieldX, field.FieldY, field.FieldName, field.KingdomId, unitCount));
        }
	
	
		//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Orders need to be taken away from the database too !!!!!!!!!!!!!!!!!!1
		List<OrderInfo> orders = new List<OrderInfo>();
        IList<Order> ordersDB = new OrderDAO().GetByKingdomEpoch(userKingdom.KingdomId, new EpochDAO().GetCurrentByMapId(userKingdom.MapId).EpochId);

        Dictionary<int,UnitType> unitTypes = new Dictionary<int,UnitType>();
         
        IList<UnitType> unitTypesAll = new UnitTypeDAO().GetAll();

        foreach (UnitType ut in unitTypesAll)
        {
           unitTypes.Add(ut.UnitTypeId,ut);
        }

        foreach (Order o in ordersDB)
        {     
            if (o.OrderTypeName.Equals("Buy"))
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, unitTypes[o.UnitTypeId].UnitTypeCost * o.Count));
            }
            else
            {
                orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, 0));
            }
        }

        //orders.Add(new OrderInfo("Defend",1,1,5,0));
        //int rice = 1000;

        //List<Owner> players = new List<Owner>();
		
        //Owner owner1 = new Owner(1, "Moose", "#ff0000");
        //Owner owner2 = new Owner(2, "Lucas", "#00ff00");

        //players.Add(owner1);
        //players.Add(owner2);

        //List<TileInfo> tiles = new List<TileInfo>();

        //tiles.Add(new TileInfo(1,1,1,"Krwawe wzgórza", owner1.playerId, 5));
        //tiles.Add(new TileInfo(2,2,1,"MooseVille", owner1.playerId, 5));
        //tiles.Add(new TileInfo(3,2,2,"Grunwald", owner1.playerId, 5));
        //tiles.Add(new TileInfo(4,1,2,"Bździochy dolne", null, 5));
        //tiles.Add(new TileInfo(5,3,4,"Cukierkowa Dolina", owner2.playerId, 10));
        //tiles.Add(new TileInfo(6,5,5,"Wilczy Szaniec", owner2.playerId, 10));
        //List<OrderInfo> orders = new List<OrderInfo>();


        //orders.Add(new OrderInfo("Defend",1,1,5,0));
		return new MapModel(userKingdom.KingdomResources, tiles, players, orders);
	}
예제 #9
0
        public String Update(int MapId)
        {
            IList<Field> fields = new FieldDAO().GetByMapId(MapId);
            Epoch epoch = new EpochDAO().GetCurrentByMapId(MapId);

            // wypuszczenie wojsk z pól
            IList<Order> orders = new OrderDAO().GetByEpoch(epoch.EpochId);
            foreach (Order o in orders)
            {
                if (o.OrderTypeName.Equals("Move") || o.OrderTypeName.Equals("Defend"))
                {
                    Field f = new FieldDAO().GetById(o.FieldId);

                    Dictionary<int, int> unitModifier = new Dictionary<int, int>();
                    unitModifier[o.UnitTypeId] = -o.Count;
                    UnitUpdate(f.KingdomId, f, unitModifier);
                }
            }
            
            Dictionary<int,UnitType> unitTypes = new Dictionary<int,UnitType>();
            
            foreach(UnitType ut in new UnitTypeDAO().GetAll())
            {
                unitTypes.Add(ut.UnitTypeId,ut);
            }

            // rozpatrywanie rozkazów
            foreach (Field field in fields)
            {
                IList<Order> ordersAll = new OrderDAO().GetByFieldEpoch(epoch.EpochId, field.FieldId);
                if (ordersAll.Count > 0)
                {
                    IList<Order> orderMove = new List<Order>();
                    IList<Order> orderDefend = new List<Order>();
                    IList<Order> orderBuy = new List<Order>();
                    IList<Order> orderGather = new List<Order>();


                    // Podział rozkazów według rodzaju
                    foreach (Order order in ordersAll)
                    {
                        if (order.OrderTypeName.Equals("Move"))
                        {
                            orderMove.Add(order);
                        }
                        else if (order.OrderTypeName.Equals("Defend"))
                        {
                            orderDefend.Add(order);
                        }
                        else if (order.OrderTypeName.Equals("Buy"))
                        {
                            orderBuy.Add(order);
                        }
                        else if (order.OrderTypeName.Equals("Gather"))
                        {
                            orderGather.Add(order);
                        }
                    }

                    // królestwo do którego naley pole na początku tury
                    Kingdom startKingdom = new KingdomDAO().GetInfoById(field.KingdomId);

                    if (startKingdom.KingdomId!=0)
                    {

                        // zbieranie ryżu
                        int collectedRice = 0;
                        foreach (Order o in orderGather)
                        {
                            collectedRice += o.Count * RICE_BY_ONE_MAN;
                        }
                        startKingdom.KingdomResources += collectedRice;
                        



                        // rekrutacja 
                        Dictionary<int, int> unitModifier = new Dictionary<int, int>();
                        int toPay = 0;
                        foreach (Order o in orderBuy)
                        {
                            if (unitModifier.ContainsKey(o.UnitTypeId))
                            {
                                unitModifier[o.UnitTypeId] += o.Count;
                            }
                            else
                            {
                                unitModifier[o.UnitTypeId] = o.Count;
                            }
                            toPay += o.Count * unitTypes[o.UnitTypeId].UnitTypeCost;
                        }
                        UnitUpdate(startKingdom.KingdomId, field, unitModifier);
                        
                        startKingdom.KingdomResources -= toPay;
                        new KingdomDAO().Update(startKingdom);
                    }

                    // af[kingdom][unitType] = count
                    Dictionary<int, Dictionary<int, int>> attackForces = new Dictionary<int, Dictionary<int, int>>();
                    foreach (Order o in orderDefend.Concat(orderMove))
                    {
                        if (!attackForces.ContainsKey(o.KingdomId))
                        {
                            attackForces[o.KingdomId] = new Dictionary<int, int>();
                        }

                        if (attackForces[o.KingdomId].ContainsKey(o.UnitTypeId))
                        {
                            attackForces[o.KingdomId][o.UnitTypeId] += o.Count;
                        }
                        else
                        {
                            attackForces[o.KingdomId][o.UnitTypeId] = o.Count;
                        }
                    }
                     

                    int winner = Battle(attackForces);

                    if (winner == 0)
                    {
                        // nic sie nie dzieje
                        // wszyscy bioracy udzial w walkach zostali wycieci w pień, więc nie ma kto wrócić na pole
                    }
                    else if (winner == startKingdom.KingdomId)
                    {
                        UnitUpdate(startKingdom.KingdomId, field, attackForces[startKingdom.KingdomId]);
                    }
                    else
                    {
                        field.KingdomId = winner;
                        new FieldDAO().Update(field);
                        UnitUpdate(winner, field, attackForces[winner]);
                    }

                }


                
            }
            new EpochDAO().Add(MapId);

            this.DiplomacyStatusUpdate(MapId,fields);
            return "Hello world";

            // 1: wyciągnąc z bazy wszystkie pola danej mapy
            // 2: Dla każdego pola wyciągnąc jego rozkazy
            // 3: Rozdzielić rozkazy według typu
            // 4: Rozpatrzyć zbieranie ryżu
            // 5: Rozpatrzyc rekrutacje
            // 6: Rozpatrzec ataki i obrone
        }
예제 #10
0
        public void DiplomacyStatusUpdate(int mapId, IList<Field> fields)
        {
            IList<Kingdom> kingdoms = new KingdomDAO().GetByMapId(mapId);

            Dictionary<int, Rectangle> kingdomsArea = new Dictionary<int, Rectangle>();

            foreach (Field field in fields)
            {
                if (!kingdomsArea.ContainsKey(field.KingdomId))
                {
                    kingdomsArea[field.KingdomId] = new Rectangle();
                }

                if (field.FieldX > kingdomsArea[field.KingdomId].maxX) kingdomsArea[field.KingdomId].maxX = field.FieldX;
                if (field.FieldY > kingdomsArea[field.KingdomId].maxY) kingdomsArea[field.KingdomId].maxY = field.FieldY;

                if (field.FieldX < kingdomsArea[field.KingdomId].minX) kingdomsArea[field.KingdomId].minX = field.FieldX;
                if (field.FieldY < kingdomsArea[field.KingdomId].minY) kingdomsArea[field.KingdomId].minY = field.FieldY;
            }


            foreach (Kingdom kingdom in kingdoms)
            {
                IList<Diplomacy> diplomacy = new DiplomacyDAO().GetByUserId(kingdom.UserId);

                foreach (Kingdom kingdomA in kingdoms)
                {
                    if(kingdomsArea[kingdom.KingdomId].CollidesWith(kingdomsArea[kingdomA.KingdomId],2)){
                        bool mustAdd = true;
                        foreach (Diplomacy dip in diplomacy)
                        {
                            if (dip.SecondaryUserId == kingdomA.UserId) mustAdd = false;
                        }

                        if (mustAdd)
                        {
                            Diplomacy dip = new Diplomacy();
                            dip.MainUserId = kingdom.UserId;
                            dip.SecondaryUserId = kingdomA.UserId;
                            dip.DiplomacyStatusId = 1;// hardcode, nie che mi sie znowu do bazy dodawac pierdolowatej metody, w bazie najlepiej by pod tym id byla wojna

                            new DiplomacyDAO().Add(dip);
                        }
                    }
                }

            }

        }
예제 #11
0
        public String Update(int MapId)
        {
            IList <Field> fields = new FieldDAO().GetByMapId(MapId);
            Epoch         epoch  = new EpochDAO().GetCurrentByMapId(MapId);

            // wypuszczenie wojsk z pól
            IList <Order> orders = new OrderDAO().GetByEpoch(epoch.EpochId);

            foreach (Order o in orders)
            {
                if (o.OrderTypeName.Equals("Move") || o.OrderTypeName.Equals("Defend"))
                {
                    Field f = new FieldDAO().GetById(o.FieldId);

                    Dictionary <int, int> unitModifier = new Dictionary <int, int>();
                    unitModifier[o.UnitTypeId] = -o.Count;
                    UnitUpdate(f.KingdomId, f, unitModifier);
                }
            }

            Dictionary <int, UnitType> unitTypes = new Dictionary <int, UnitType>();

            foreach (UnitType ut in new UnitTypeDAO().GetAll())
            {
                unitTypes.Add(ut.UnitTypeId, ut);
            }

            // rozpatrywanie rozkazów
            foreach (Field field in fields)
            {
                IList <Order> ordersAll = new OrderDAO().GetByFieldEpoch(epoch.EpochId, field.FieldId);
                if (ordersAll.Count > 0)
                {
                    IList <Order> orderMove   = new List <Order>();
                    IList <Order> orderDefend = new List <Order>();
                    IList <Order> orderBuy    = new List <Order>();
                    IList <Order> orderGather = new List <Order>();


                    // Podział rozkazów według rodzaju
                    foreach (Order order in ordersAll)
                    {
                        if (order.OrderTypeName.Equals("Move"))
                        {
                            orderMove.Add(order);
                        }
                        else if (order.OrderTypeName.Equals("Defend"))
                        {
                            orderDefend.Add(order);
                        }
                        else if (order.OrderTypeName.Equals("Buy"))
                        {
                            orderBuy.Add(order);
                        }
                        else if (order.OrderTypeName.Equals("Gather"))
                        {
                            orderGather.Add(order);
                        }
                    }

                    // królestwo do którego naley pole na początku tury
                    Kingdom startKingdom = new KingdomDAO().GetInfoById(field.KingdomId);

                    if (startKingdom.KingdomId != 0)
                    {
                        // zbieranie ryżu
                        int collectedRice = 0;
                        foreach (Order o in orderGather)
                        {
                            collectedRice += o.Count * RICE_BY_ONE_MAN;
                        }
                        startKingdom.KingdomResources += collectedRice;



                        // rekrutacja
                        Dictionary <int, int> unitModifier = new Dictionary <int, int>();
                        int toPay = 0;
                        foreach (Order o in orderBuy)
                        {
                            if (unitModifier.ContainsKey(o.UnitTypeId))
                            {
                                unitModifier[o.UnitTypeId] += o.Count;
                            }
                            else
                            {
                                unitModifier[o.UnitTypeId] = o.Count;
                            }
                            toPay += o.Count * unitTypes[o.UnitTypeId].UnitTypeCost;
                        }
                        UnitUpdate(startKingdom.KingdomId, field, unitModifier);

                        startKingdom.KingdomResources -= toPay;
                        new KingdomDAO().Update(startKingdom);
                    }

                    // af[kingdom][unitType] = count
                    Dictionary <int, Dictionary <int, int> > attackForces = new Dictionary <int, Dictionary <int, int> >();
                    foreach (Order o in orderDefend.Concat(orderMove))
                    {
                        if (!attackForces.ContainsKey(o.KingdomId))
                        {
                            attackForces[o.KingdomId] = new Dictionary <int, int>();
                        }

                        if (attackForces[o.KingdomId].ContainsKey(o.UnitTypeId))
                        {
                            attackForces[o.KingdomId][o.UnitTypeId] += o.Count;
                        }
                        else
                        {
                            attackForces[o.KingdomId][o.UnitTypeId] = o.Count;
                        }
                    }


                    int winner = Battle(attackForces);

                    if (winner == 0)
                    {
                        // nic sie nie dzieje
                        // wszyscy bioracy udzial w walkach zostali wycieci w pień, więc nie ma kto wrócić na pole
                    }
                    else if (winner == startKingdom.KingdomId)
                    {
                        UnitUpdate(startKingdom.KingdomId, field, attackForces[startKingdom.KingdomId]);
                    }
                    else
                    {
                        field.KingdomId = winner;
                        new FieldDAO().Update(field);
                        UnitUpdate(winner, field, attackForces[winner]);
                    }
                }
            }
            new EpochDAO().Add(MapId);

            this.DiplomacyStatusUpdate(MapId, fields);
            return("Hello world");

            // 1: wyciągnąc z bazy wszystkie pola danej mapy
            // 2: Dla każdego pola wyciągnąc jego rozkazy
            // 3: Rozdzielić rozkazy według typu
            // 4: Rozpatrzyć zbieranie ryżu
            // 5: Rozpatrzyc rekrutacje
            // 6: Rozpatrzec ataki i obrone
        }
예제 #12
0
        public void DiplomacyStatusUpdate(int mapId, IList <Field> fields)
        {
            IList <Kingdom> kingdoms = new KingdomDAO().GetByMapId(mapId);

            Dictionary <int, Rectangle> kingdomsArea = new Dictionary <int, Rectangle>();

            foreach (Field field in fields)
            {
                if (!kingdomsArea.ContainsKey(field.KingdomId))
                {
                    kingdomsArea[field.KingdomId] = new Rectangle();
                }

                if (field.FieldX > kingdomsArea[field.KingdomId].maxX)
                {
                    kingdomsArea[field.KingdomId].maxX = field.FieldX;
                }
                if (field.FieldY > kingdomsArea[field.KingdomId].maxY)
                {
                    kingdomsArea[field.KingdomId].maxY = field.FieldY;
                }

                if (field.FieldX < kingdomsArea[field.KingdomId].minX)
                {
                    kingdomsArea[field.KingdomId].minX = field.FieldX;
                }
                if (field.FieldY < kingdomsArea[field.KingdomId].minY)
                {
                    kingdomsArea[field.KingdomId].minY = field.FieldY;
                }
            }


            foreach (Kingdom kingdom in kingdoms)
            {
                IList <Diplomacy> diplomacy = new DiplomacyDAO().GetByUserId(kingdom.UserId);

                foreach (Kingdom kingdomA in kingdoms)
                {
                    if (kingdomsArea[kingdom.KingdomId].CollidesWith(kingdomsArea[kingdomA.KingdomId], 2))
                    {
                        bool mustAdd = true;
                        foreach (Diplomacy dip in diplomacy)
                        {
                            if (dip.SecondaryUserId == kingdomA.UserId)
                            {
                                mustAdd = false;
                            }
                        }

                        if (mustAdd)
                        {
                            Diplomacy dip = new Diplomacy();
                            dip.MainUserId        = kingdom.UserId;
                            dip.SecondaryUserId   = kingdomA.UserId;
                            dip.DiplomacyStatusId = 1;// hardcode, nie che mi sie znowu do bazy dodawac pierdolowatej metody, w bazie najlepiej by pod tym id byla wojna

                            new DiplomacyDAO().Add(dip);
                        }
                    }
                }
            }
        }