Ejemplo n.º 1
0
        public ActionResult CreateLeaderPost(LeaderModel model)
        {
            model.Valid = ModelState.IsValid;
            if (model.Valid)
            {
                var weapon = MvcApplication.WeaponsFactory.FindWeaponTemplate("Rifle");
                var factory = MvcApplication.SessionFactory;
                NhSession = factory.OpenSession();
                var identity = NhSession.Get<Identity>(model.Id);
                var existingAccount = NhSession.QueryOver<Identity>().Where(i => i.Email == identity.Email && i.Registered).List();
                if (existingAccount.IsEmpty())
                {
                    using (var transaction = NhSession.BeginTransaction())
                    {

                        identity.Gang.Leader =
                            MvcApplication.CombatantFactory.CreateCombatant<Leader>(CombatantType.Leader) as Leader;
                        identity.Gang.Leader.Name = model.Leader.Name;
                        identity.Gang.Leader.Agi = model.Leader.Agi;
                        identity.Gang.Leader.End = model.Leader.End;
                        identity.Gang.Leader.Str = model.Leader.Str;
                        identity.Gang.Leader.Weapon = weapon;

                        identity.Registered = true;

                        NhSession.Save(identity);
                        transaction.Commit();
                    }
                }
            }

            EditCookie("profileComplete", true.ToString());

            return PartialView("LeaderPartial", model);
        }
        public void AddLeaderEntry(string zoneHashId, LeaderModel leader)
        {
            if (string.IsNullOrWhiteSpace(zoneHashId))
            {
                throw HttpResponseExceptionHelper.Create("Empty map hash id specified", HttpStatusCode.BadRequest);
            }

            if (!LeaderModelHelper.IsValid(leader))
            {
                throw HttpResponseExceptionHelper.Create("Invalid leader entry specified", HttpStatusCode.BadRequest);
            }

            using (var db = new SystemDBContext())
            {
                var leaderboard = db.Leaderboards.FirstOrDefault(x => x.ZoneHashId == zoneHashId);

                if (leaderboard == null)
                {
                    throw HttpResponseExceptionHelper.Create("Invalid map hash id provided. No related map.",
                                                             HttpStatusCode.BadRequest);
                }

                leaderboard.Leaders = GetLeaderString(InsertLeader(leaderboard, leader));
                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 public static void Add(LeaderModel model)
 {
     var l = Leaderboard;
     if (l.Any(x => x.Score < model.Score))
     {
         for (int i = 0; i < l.Count; i++)
             if (l.ElementAt(i).Score < model.Score)
             {
                 l.Insert(i, model);
                 break;
             }
         while (l.Count > 10)
             l.RemoveAt(10);
         Leaderboard = l;
     }
     l = PersonalHighscores;
     LeaderModel a = l.FirstOrDefault(x => x.Name == model.Name);
     if (a != null && a.Score < model.Score)
     {
         l.Remove(a);
         l.Add(model);
         PersonalHighscores = l;
     }
     else if (a == null) { l.Add(model); PersonalHighscores = l; }
 }
        /// <summary>
        /// Add an entry to the leaderboard of the specified zone hash id
        /// </summary>
        /// <param name="zoneHashId"></param>
        /// <param name="leader"></param>
        public void AddLeaderEntry(string zoneHashId, LeaderModel leader)
        {
            var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/" + zoneHashId, leader, UserToken.Token).Result;
            var body         = HttpRequestHelper.GetContent(httpResponse).Result;
            var statusCode   = HttpRequestHelper.GetStatusCode(httpResponse);

            if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent)
            {
                throw new Exception(body);
            }
        }
        public static bool IsValid(LeaderModel leader)
        {
            if (leader == null)
            {
                return(false);
            }
            if (string.IsNullOrWhiteSpace(leader.PlayerHashId))
            {
                return(false);
            }
            if (string.IsNullOrWhiteSpace(leader.PlayerName))
            {
                return(false);
            }
            if (leader.Points < 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        public ActionResult CreateLeaderPost(LeaderModel model)
        {
            model.Valid = ModelState.IsValid;
            if (model.Valid)
            {
                using (var transaction = NhSession.BeginTransaction())
                {
                    var identity = NhSession.Get<Identity>(model.Id);

                    var leader = model.Leader;
                    leader.Hp = 100;
                    leader.CombatantType = CombatantType.Leader;
                    identity.Gang.Leader = leader;
                    leader.Weapon = WeaponFactory.Fabricate(StandardWeapons.Knives);

                    NhSession.Save(identity);
                    transaction.Commit();
                }

            }
            return PartialView("LeaderPartial", model);
        }
Ejemplo n.º 7
0
        public void Initialize()
        {
            try
            {
                Token = UserAccess.Register(DefaultUser.Username, DefaultUser.Password);
            }
            catch (Exception)
            {
                Token = UserAccess.Login(DefaultUser.Username, DefaultUser.Password);
            }

            var userToken = JwtHelper.DecodeToken(Token);

            // Delete all zones
            var zones = ZoneAccess.GetMyZones();

            foreach (var zone in zones)
            {
                ZoneAccess.DeleteMap(zone.HashId);
            }

            DefaultZone = new MapModel()
            {
                Content = "Default Content",
                Level   = 0,
                Name    = "newZone2134321"
            };

            DefaultLeader = new LeaderModel()
            {
                PlayerHashId = userToken.UserId,
                PlayerName   = userToken.Username,
                Points       = 100
            };
            DefaultZone.HashId = ZoneAccess.CreateMap(DefaultZone.Name, DefaultZone.Content, DefaultZone.Level);
        }
Ejemplo n.º 8
0
 public void AddLeaderEntry(string zoneHashId, LeaderModel leader)
 {
     _leaderboardService.AddLeaderEntry(zoneHashId, leader);
 }
Ejemplo n.º 9
0
 public LeaderWindow(User user)
 {
     InitializeComponent();
     this.user   = user;
     leaderModel = new LeaderModel();
 }
Ejemplo n.º 10
0
 public void InitItem(LeaderModel leader)
 {
     model          = leader;
     TextName.text  = model.Name;
     TextScore.text = model.Score.ToString();
 }