public async Task PlayerMobEnterZone(long mobId)
        {
            var identityView = IdentityView.FromObjectId(_dbContext, (SHIdentity.FromPrincipal(Context.User)).ObjectId);

            if (identityView.Identity == null)
            {
                return;
            }
            if (!Context.User.Identity.IsAuthenticated)
            {
                return;
            }

            if (mobId < 1)
            {
                return;
            }

            var mob = _dbContext.Mob.FirstOrDefault(e => e.Id == mobId && e.AccountId == identityView.Identity.Id);

            if (mob == null)
            {
                return;
            }

            var zone = _dbContext.Zone.FirstOrDefault(e => e.Id == mob.ZoneId);

            var response = new LoadZoneResponse();

            response.MobId     = mob.Id;
            response.ZoneId    = mob.ZoneId;
            response.SceneName = zone.SceneName;

            await Clients.Client(Context.ConnectionId).SendAsync("LoadZoneResponse", "", JsonConvert.SerializeObject(response));
        }
        public async Task DeleteCharacter(long id)
        {
            var identityView = IdentityView.FromObjectId(_dbContext, (SHIdentity.FromPrincipal(Context.User)).ObjectId);

            if (identityView.Identity == null)
            {
                return;
            }
            if (!Context.User.Identity.IsAuthenticated)
            {
                return;
            }

            if (id < 1)
            {
                return;
            }

            var mob = _dbContext.Mob.FirstOrDefault(e => e.Id == id && e.AccountId == identityView.Identity.Id);

            if (mob == null)
            {
                return;
            }

            _dbContext.Mob.Remove(mob);
            _dbContext.SaveChanges();

            await Clients.Client(Context.ConnectionId).SendAsync("DeleteCharacterResponse", "", JsonConvert.SerializeObject(id));
        }
        public async Task CreateCharacter(CreateCharacterRequest request)
        {
            var identityView = IdentityView.FromObjectId(_dbContext, (SHIdentity.FromPrincipal(Context.User)).ObjectId);

            if (identityView.Identity == null)
            {
                return;
            }
            if (!Context.User.Identity.IsAuthenticated)
            {
                return;
            }

            if (request == null || String.IsNullOrEmpty(request.Name))
            {
                return;
            }

            if (_dbContext.Mob.Count(e => e.AccountId == identityView.Identity.Id) > 2)
            {
                return;
            }

            var mob = new Mob()
            {
                MobClassId = request.MobClassId,
                MobRaceId  = request.MobRaceId,
                AccountId  = identityView.Identity.Id,
                Name       = request.Name,
                ZoneId     = 1
            };

            if (_dbContext.Mob.Any(e => e.AccountId == identityView.Identity.Id && e.Name.Equals(mob.Name)))
            {
                return;
            }

            mob = _dbContext.Mob.Add(mob).Entity;
            _dbContext.SaveChanges();
            var response = new CreateCharacterResponse();

            response.Mob = mob;

            await Clients.Client(Context.ConnectionId).SendAsync("CreateCharacterResponse", "", JsonConvert.SerializeObject(response));
        }
        public async Task GetMobRaces()
        {
            var identityView = IdentityView.FromObjectId(_dbContext, (SHIdentity.FromPrincipal(Context.User)).ObjectId);

            if (identityView.Identity == null)
            {
                return;
            }
            if (!Context.User.Identity.IsAuthenticated)
            {
                return;
            }

            if (_dbContext.MobRace != null)
            {
                await Clients.Client(Context.ConnectionId).SendAsync("MobRacesResponse", "", JsonConvert.SerializeObject(_dbContext.MobRace.ToList()));
            }
            else
            {
                await Clients.Client(Context.ConnectionId).SendAsync("MobRacesResponse", "", JsonConvert.SerializeObject(new List <MobRace>()));
            }
        }
Exemplo n.º 5
0
        public async Task GetMobsByOwnerId()
        {
            var identityView = IdentityView.FromObjectId(_dbContext, (SHIdentity.FromPrincipal(Context.User)).ObjectId);

            if (identityView.Identity == null)
            {
                return;
            }
            if (!Context.User.Identity.IsAuthenticated)
            {
                return;
            }

            var mobs = _dbContext.Mob.Where(e => e.AccountId == identityView.Identity.Id);

            if (mobs != null)
            {
                await Clients.Client(Context.ConnectionId).SendAsync("MobsByOwnerIdResponse", "", JsonConvert.SerializeObject(mobs.ToList()));
            }
            else
            {
                await Clients.Client(Context.ConnectionId).SendAsync("MobsByOwnerIdResponse", "", JsonConvert.SerializeObject(new List <Mob>()));
            }
        }