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)); }
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); }