예제 #1
0
    public static object GetCamps(DataTableAjaxPostModel model)
    {
        var cols = new List <string>()
        {
            "LOWER(TRIM(cp.title))", "LOWER(TRIM(cp.description))", "LOWER(TRIM(cp.address))", "LOWER(TRIM(cp.timing))", "LOWER(TRIM(cm.city_name))"
        };
        // Initialization.
        DataTableData <CampModel> result = new DataTableData <CampModel>();

        try
        {
            // Initialization.
            string draw     = model.draw.ToString();
            int    startRec = model.start;
            int    pageSize = model.length;

            var c_order = "";
            foreach (var o in model.order)
            {
                var columnName = cols[o.column];
                c_order += string.IsNullOrWhiteSpace(c_order) ? columnName + " " + o.dir : ", " + columnName + " " + o.dir;
            }
            if (!string.IsNullOrWhiteSpace(c_order))
            {
                c_order = " order by " + c_order;
            }

            var c_search = "";
            foreach (var s in model.columns)
            {
                if (!string.IsNullOrWhiteSpace(s.search.value) && s.searchable)
                {
                    var i          = model.columns.IndexOf(s);
                    var columnName = cols[i];
                    c_search += i == 1 ? " and " + columnName + " like '%" + s.search.value.Trim().ToLower() + "%'" : " and " + columnName + " like '%" + s.search.value + "%'";
                }
            }
            var camps = new CampManager().GetAllCampsPaginated(startRec, pageSize, c_order, c_search);

            var campList = camps.Data;
            foreach (var camp in campList)
            {
                camp.Link = "<a href='javascript:void(0);' style='margin-right:10px' class='edit-cp' data-id='" + camp.Id + "'>Edit</a><a href='javascript:void(0);' class='add-cp-images' data-id='" + camp.Id + "'>Add Images</a><a href='javascript:void(0);' style='margin-left:10px' class='delete-cp' data-id='" + camp.Id + "'>Delete</a>";
            }

            int recFilter = camps.Data.Count;

            result.draw            = Convert.ToInt32(draw);
            result.recordsTotal    = camps.TotalCount;
            result.recordsFiltered = camps.TotalCount;
            result.data            = campList;
        }
        catch (Exception ex)
        {
            // Info
            Console.Write(ex);
        }
        // Return info.
        return(result);
    }
예제 #2
0
        public ActionResult ConsumeCaravan(int target_id)
        {
            string res     = CampManager.ConsumeCaravan(Convert.ToInt32(Session["UserId"]), target_id);
            string message = "You gained 30 " + res + "!";

            return(Json(message));
        }
예제 #3
0
        public UserDataModel(int id)
        {
            this.userModel = UsersManager.GetUserData(id);

            minions = new List <MinionModel>();
            List <MinionOwnership> ownership = OwnershipManager.GetOwnershipData(id);

            foreach (MinionOwnership mo in ownership)
            {
                Minion      m  = OwnershipManager.GetMinionsData(mo.minion_id);
                MinionType  mt = OwnershipManager.GetTypeData(m.mtype_id);
                MinionModel mm = new MinionModel(m, mo, mt, null);

                minions.Add(mm);
            }

            if (userModel.personal_bg_id != null)
            {
                personalBg = new BattlegroupModel(userModel.personal_bg_id.Value);
            }
            else
            {
                userModel.personal_bg_id = -1;
            }

            this.remoteBgs = new List <BattlegroupModel>();
            List <Battlegroup> remote_bgs = OwnershipManager.GetRemoteBattlegroups(userModel.id, userModel.personal_bg_id.Value);

            foreach (Battlegroup b in remote_bgs)
            {
                remoteBgs.Add(new BattlegroupModel(b.id));
            }

            this.treasury = new List <TreasuryModel>();
            List <UserTreasury> ut = ResourceManager.GetUserTreasury(userModel.id);

            foreach (UserTreasury u in ut)
            {
                TreasuryModel tm = new TreasuryModel(u.ResourceType.name, u.amount.Value, u.ResourceType.category);
                this.treasury.Add(tm);
            }

            this.personalCamps = OwnershipManager.GetUserCamps(id);

            this.reputation = new List <ReputationModel>();
            List <Reputation> repList = OwnershipManager.GetUserReputation(id);

            foreach (Reputation r in repList)
            {
                Camp            c  = CampManager.GetCampInfo(r.camp_id);
                ReputationModel rm = new ReputationModel(c, r);
                this.reputation.Add(rm);
            }

            this.buildings = CampManager.GetAllBuildings();
        }
예제 #4
0
        private static void CaravanGenerationEvent(object source, ElapsedEventArgs e)
        {
            Console.WriteLine("Caravan generation started");
            List <Caravan> list = CampManager.GenerateCaravans();

            foreach (Caravan c in list)
            {
                Console.WriteLine("Caravan generated: " + c.location.Latitude + " | " + c.location.Longitude);
            }
        }
예제 #5
0
        public static List <Camp> InitiateDiscovery(DbGeography loc, string locType)
        {
            string             places   = GetPlaces(loc.Latitude.Value, loc.Longitude.Value, 1000, locType).Result;
            List <Camp>        newCamps = new List <Camp>();
            List <DbGeography> newLocs  = new List <DbGeography>();
            //parse, create new camp
            dynamic obj = JsonConvert.DeserializeObject(places);

            //dynamic obj = JObject.Parse(places);
            if (obj["results"] != null)
            {
                for (int i = 0; i < obj["results"].Count; i++)
                {
                    dynamic     place  = obj["results"][i];
                    var         point  = string.Format("POINT({1} {0})", place["geometry"]["location"]["lat"], place["geometry"]["location"]["lng"]);
                    DbGeography newLoc = DbGeography.FromText(point);
                    newLocs.Add(newLoc);
                }
            }

            string name = "";

            if (locType.Equals("restaurant"))
            {
                name = "Neutral Camp";
            }
            else if (locType.Equals("gas_station"))
            {
                name = "Message Board";
            }
            else if (locType.Equals("bank"))
            {
                name = "Neutral Trader";
            }

            using (var db = new MinionWarsEntities())
            {
                foreach (DbGeography l in newLocs)
                {
                    Console.WriteLine("Discovery found: " + name);
                    List <Camp> check = new List <Camp>();
                    check = db.Camp.Where(x => x.location.Distance(l) <= 250).ToList();
                    if (check.Count == 0)
                    {
                        Camp nc = CampManager.CreateCamp(-1, l, name);
                        newCamps.Add(nc);
                    }
                }
            }

            return(newCamps);
        }
예제 #6
0
        public ActionResult BuildCamp(double lat, double lon, string name)
        {
            var  point = string.Format("POINT({1} {0})", lat, lon);
            Camp c     = CampManager.CreateUserCamp(point, Convert.ToInt32(Session["UserId"]), name);

            if (c == null)
            {
                return(Json("Camp couldn't be built!"));
            }
            else
            {
                return(Json("Camp built!"));
            }
        }
예제 #7
0
        public ActionResult AttachMinions(int m_id, int ob_id)
        {
            string message = "Initial";
            bool   result  = CampManager.AttachMinions(ob_id, m_id);

            if (result)
            {
                message = "Minions attached!";
            }
            else
            {
                message = "Error attaching minions!";
            }

            return(Json(message));
        }
예제 #8
0
        public ActionResult BuildMinions(int ob_id, int amount)
        {
            string message = "Initial";
            bool   result  = CampManager.BuildMinions(ob_id, Convert.ToInt32(Session["UserId"]), amount);

            if (result)
            {
                message = "Minions succesfully built!";
            }
            else
            {
                message = "Error building minions!";
            }

            return(Json(message));
        }
예제 #9
0
        public ActionResult AddNewBuilding(int camp_id, int building_id)
        {
            bool   result  = CampManager.CreateBuilding(camp_id, building_id);
            string message = "";

            if (result)
            {
                message = "Building created!";
            }
            else
            {
                message = "Insufficient resources!";
            }

            return(Json(message));
        }
예제 #10
0
        public ActionResult SendUserCaravan(int source, int destination)
        {
            string  message = "Initial";
            Caravan car     = CampManager.GenerateUserCaravan(source, destination);

            if (car == null)
            {
                message = "Error sending Caravan!";
            }
            else
            {
                message = "Caravan sent!";
            }

            return(Json(message));
        }
예제 #11
0
        public static void UpdateActivitySaturations()
        {
            DateTime now = DateTime.Now;

            using (var db = new MinionWarsEntities())
            {
                List <UserMovementHistory> history = db.UserMovementHistory.Where(x => x.activity_saturation > 0).ToList();
                foreach (UserMovementHistory h in history)
                {
                    var difference = now - h.occurence;
                    var value      = Math.Floor((difference.TotalSeconds - 300 * difference.TotalMinutes) / 5);
                    h.activity_saturation -= 0.01 * value;
                    if (h.activity_saturation <= 0)
                    {
                        db.UserMovementHistory.Remove(h);
                    }
                    else
                    {
                        db.UserMovementHistory.Attach(h);
                        db.Entry(h).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                //check last activity;
                history = history.OrderByDescending(x => x.occurence).ToList();
                if ((now - history.First().occurence).TotalMinutes >= 15)
                {
                    Users user = db.Users.Find(history.First().users_id);
                    user.online = 0;

                    if ((now - history.First().occurence).TotalHours >= 24)
                    {
                        user.online = -1;
                    }

                    db.Users.Attach(user);
                    db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                }

                //check for discovery
                CampManager.CheckForDiscovery(history.First().location, 5000);

                db.SaveChanges();
            }
        }
예제 #12
0
        public ActionResult GetCampCaravan(int camp_id, double lat, double lon)
        {
            Caravan             car = CampManager.GetCampCaravan(camp_id);
            CaravanDisplayModel cdm;

            if (car == null)
            {
                var         point = string.Format("POINT({1} {0})", lat, lon);
                List <Camp> cl    = CampManager.ReturnCamps(point, 1000);
                cdm = new CaravanDisplayModel(0, camp_id, null, cl, Convert.ToInt32(Session["UserId"]));
            }
            else
            {
                cdm = new CaravanDisplayModel(1, camp_id, car, null, Convert.ToInt32(Session["UserId"]));
            }

            return(Json(cdm));
        }
예제 #13
0
    public static object GetImagesById(string id)
    {
        var files      = new List <FileInfoModel>();
        var campImages = new CampManager().GetCampImagesById(id);

        var response = new JsonResponse()
        {
            IsSuccess = true, Message = "Files found successfully.", Data = files
        };

        if (!string.IsNullOrEmpty(campImages))
        {
            try
            {
                var images = campImages.Split(' ');
                foreach (var item in images)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        string absFile = HttpContext.Current.Server.MapPath("/photo/" + item);
                        //var f = File.Open(absFile, FileMode.Open);
                        var fs = new FileStream(absFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        using (var sr = new StreamReader(fs))
                        {
                            var size = fs.Length;
                            files.Add(new FileInfoModel()
                            {
                                Name = item,
                                Size = size.ToString(),
                                Type = "image"
                            });
                        }
                    }
                }
                response.Data = files;
            }
            catch (Exception e)
            {
                response.IsSuccess = false;
                response.Message   = e.Message;
            }
        }
        return(response);
    }
예제 #14
0
        public static Caravan UpdateCaravanPosition(Caravan car)
        {
            Camp destination;

            using (var db = new MinionWarsEntities())
            {
                destination = db.Camp.Find(car.destination_id);
            }

            if (car.directions == null)
            {
                Geolocations.GetCaravanDirections(car.location, destination.location);
            }

            if (car.location.Distance(destination.location) <= 50)
            {
                car = CampManager.CaravanArrival(car);
            }
            else
            {
                if (car.current_step == null)
                {
                    car.current_step = Geolocations.GetCaravanDirectionMovement(car, destination.location);
                    if (car.current_step == null)
                    {
                        car.directions = Geolocations.GetCaravanDirections(car.location, destination.location);
                    }
                    else
                    {
                        using (var db = new MinionWarsEntities())
                        {
                            db.Caravan.Attach(car);
                            db.Entry(car).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                if (car.location.Distance(car.current_step) <= 10)
                {
                    car.current_step = Geolocations.GetCaravanDirectionMovement(car, destination.location);
                    if (car.current_step == null)
                    {
                        car.directions = Geolocations.GetCaravanDirections(car.location, destination.location);
                    }
                    else
                    {
                        using (var db = new MinionWarsEntities())
                        {
                            db.Caravan.Attach(car);
                            db.Entry(car).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }

                car.location      = Geolocations.PerformDirectionMovement(car.location, car.current_step, car.last_movement.Value, 2);
                car.last_movement = DateTime.Now;

                using (var db = new MinionWarsEntities())
                {
                    db.Caravan.Attach(car);
                    db.Entry(car).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }

            return(car);
        }
예제 #15
0
        static void Main(string[] args)
        {
            //SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            Console.WriteLine("TEST");
            //46.318565799999995 16.34576590000006
            var         point = string.Format("POINT({1} {0})", 46.31856579999999, 16.34576590000006);
            DbGeography loc   = DbGeography.FromText(point);

            /*MapDataModel mdm = MapManager.GetMapData(11, point, 1000);
             * Console.WriteLine(mdm.objectList.Count);
             * foreach(MapObject m in mdm.objectList)
             * {
             *  Console.WriteLine(m.type);
             * }*/

            /*HiveNode h = HiveManager.generateRandomHive(loc);
             * UsersManager.UpdateEventSaturations(loc, -5);
             * Console.WriteLine("Hive generated: " + h.location.Latitude + " | " + h.location.Longitude);*/

            //UsersManager.UpdateActivitySaturations();

            /*List<Caravan> list = CampManager.GenerateCaravans();
             * foreach (Caravan c in list)
             * {
             *  Console.WriteLine("Caravan generated: " + c.location.Latitude + " | " + c.location.Longitude);
             * }*/

            //Console.WriteLine(UserDataManager.GetUserData(1).user.username);

            /*var point2 = string.Format("POINT({1} {0})", 46.31856579999999, 17.34576590000006);
             * DbGeography l1 = DbGeography.FromText(point);
             * DbGeography l2 = DbGeography.FromText(point2);
             * Console.WriteLine(l1.ToString());
             * Console.WriteLine(l1.Distance(l2));*/

            //Console.WriteLine(UserDataManager.GetUserData(1).user.username);
            //WildMinionsTest.Generate(point);

            /*decimal movement = 1000m / (1852m * 60m);
             * double m = (double)movement;
             * Console.WriteLine("MOVEMENT: " + m);*/

            /*CombatLog log = CombatManager.StartCombat(32, 34);
             * Console.WriteLine("winner: " + log.winner.id);*/

            //Console.WriteLine(StructuresManager.GetPlaces(46.31856579999999, 16.34576590000006, 5000, "restaurant").Result);

            /*string test = Geolocations.GetDirections(46.31856579999999, 16.34576590000006, 46.310833627601156, 16.332077980041504).Result;
             * string directions = OrdersParser.ParseDirections(test);
             * Console.WriteLine(OrdersParser.ParseNextLoc(directions));*/

            /*dynamic ds = JsonConvert.DeserializeObject(test);
             * Console.WriteLine(ds.routes[0].legs[0].steps.Count);
             * Console.WriteLine(ds.routes[0].legs[0].steps[0].end_location.lat);*/

            /*List<Camp> camps = CampManager.ReturnCamps(loc, 1000);
             * Console.WriteLine(camps.Count);*/

            CampManager.CheckForDiscovery(loc, 1000);
            //CampManager.CreateCamp(17, loc, "Throne");

            /*string places = Geolocations.GetPlaces(loc.Latitude.Value, loc.Longitude.Value, 1000, "restaurant").Result;
             * dynamic obj = JsonConvert.DeserializeObject(places);
             * Console.WriteLine(obj.results.Count);
             * for (int i = 0; i < obj.results.Count; i++)
             * {
             *  dynamic place = obj.results[i];
             *  var p = string.Format("POINT({1} {0})", place.geometry.location.lat, place.geometry.location.lng);
             *  Console.WriteLine("p: " + p);
             * }*/

            /*List<UserTreasury> ut = ResourceManager.GetUserTreasury(8);
             * Console.WriteLine(ut[0].ResourceType.name);
             * Console.WriteLine(ut[0].amount);*/

            /*using (var db = new MinionWarsEntities())
             * {
             *  List<CostsBuilding> cbl = db.CostsBuilding.Where(x => x.b_id == 1).ToList();
             *  List<UserTreasury> utl = db.UserTreasury.Where(x => x.user_id == 17).ToList();
             *
             *  foreach (CostsBuilding cb in cbl)
             *  {
             *      UserTreasury ut = utl.Where(x => x.res_id == cb.r_id).First();
             *      Console.WriteLine("Amount: " + cb.amount.Value);
             *  }
             *
             *  Console.Write("ok");
             * }*/

            /*List<Camp> cl = CampManager.ReturnCamps(point, 1000);
             * foreach(Camp c in cl)
             * {
             *  Console.WriteLine(c.name);
             * }*/

            //CampManager.GenerateUserCaravan(43, 44);

            //CampManager.AttachMinions(1, 89);

            //List<Trading> tl = TradeManager.CheckTradingPost(43);

            Console.WriteLine("DONE");
            Console.ReadKey();
        }
예제 #16
0
 public static List <Caravan> GetAllCaravans()
 {
     return(CampManager.GetAllActiveGroups());
 }
예제 #17
0
    public static object DeleteCampById(string id)
    {
        var resp = new CampManager().DeleteCamp(id);

        return(resp);
    }
예제 #18
0
    public static object GetCampById(string id)
    {
        var camp = new CampManager().GetCampById(id);

        return(camp);
    }
예제 #19
0
 public static Caravan UpdateCaravanPosition(Caravan car)
 {
     return(CampManager.UpdatePosition(car));
 }
예제 #20
0
        public ActionResult DestroyBuilding(int camp_id, int building_id, int type)
        {
            CampManager.DestroyBuilding(camp_id, building_id, type);

            return(Json("Building destroyed"));
        }