protected override void Handle(UserPlayerDelete data, PlayerConnection connection)
        {
            var player = gameData.GetPlayer(data.PlayerId);

            if (player == null)
            {
                return;
            }

            worldProcessor.RemovePlayer(player);

            gameData.Remove(gameData.GetAppearance(player.AppearanceId));
            gameData.Remove(gameData.GetTransform(player.TransformId));
            gameData.Remove(gameData.GetAttributes(player.AttributesId));
            gameData.Remove(gameData.GetProfessions(player.ProfessionsId));

            var items = gameData.GetAllPlayerItems(player.Id);

            foreach (var item in items)
            {
                gameData.Remove(item);
            }

            gameData.Remove(player);

            SendPlayerList(connection);
        }
        private void SendPlayerList(PlayerConnection connection)
        {
            var players     = playerProvider.GetPlayers(connection.User).ToArray();
            var appearances = players.Select(x => gameData.GetAppearance(x.AppearanceId)).ToArray();

            connection.Send(UserPlayerList.Create(gameData, players, appearances), SendOption.Reliable);
        }
Пример #3
0
        public bool ToggleHelmet(SessionToken token, string userId)
        {
            var character = GetCharacter(token, userId);

            if (character == null)
            {
                return(false);
            }

            var appearance = gameData.GetAppearance(character.SyntyAppearanceId);

            if (appearance == null)
            {
                return(false);
            }

            appearance.HelmetVisible = !appearance.HelmetVisible;
            return(true);
        }
Пример #4
0
        public static WebsiteAdminPlayer MapForAdmin(this User user, IGameData gameData, Character character)
        {
            var sessionName = "";

            if (character.UserIdLock != null)
            {
                var sessionOwner = gameData.GetUser(character.UserIdLock.GetValueOrDefault());
                if (sessionOwner != null)
                {
                    sessionName = sessionOwner.UserName;
                }
            }

            var clanMembership = gameData.GetClanMembership(character.Id);
            var clan           = clanMembership != null?Map(gameData, gameData.GetClan(clanMembership.ClanId)) : null;

            var clanRole = clanMembership != null?Map(gameData.GetClanRole(clanMembership.ClanRoleId), clanMembership) : null;

            return(new WebsiteAdminPlayer
            {
                Created = user.Created,
                Id = character.Id,
                PasswordHash = user.PasswordHash,
                UserName = user.UserName,
                UserId = user.UserId,
                Name = character.Name,
                IsAdmin = user.IsAdmin.GetValueOrDefault(),
                IsModerator = user.IsModerator.GetValueOrDefault(),
                Appearance = Map(gameData.GetAppearance(character.SyntyAppearanceId)),
                Resources = Map(gameData.GetResources(character.ResourcesId)),
                Skills = Map(gameData.GetCharacterSkills(character.SkillsId)),
                State = Map(gameData.GetCharacterState(character.StateId)),
                InventoryItems = Map(gameData.GetAllPlayerItems(character.Id)),
                Statistics = Map(gameData.GetStatistics(character.StatisticsId)),
                Clan = clan,
                ClanRole = clanRole,
                OriginUserId = character.OriginUserId,
                Revision = character.Revision.GetValueOrDefault(),
                Identifier = character.Identifier,
                CharacterIndex = character.CharacterIndex,
                SessionName = sessionName,
                PatreonTier = user.PatreonTier.GetValueOrDefault(),
                IsHiddenInHighscore = user.IsHiddenInHighscore.GetValueOrDefault()
            });
        }
Пример #5
0
        public static PlayerAdd Create(IGameData gameData, Player player)
        {
            var appearance = gameData.GetAppearance(player.AppearanceId);
            var transform  = gameData.GetTransform(player.TransformId);
            var attributes = gameData.GetAttributes(player.AttributesId);

            return(new PlayerAdd
            {
                PlayerId = player.Id,
                Name = player.Name,
                Endurance = player.Endurance,
                Attributes = attributes,
                Position = transform.GetPosition(),
                Destination = transform.GetDestination(),
                Appearance = appearance,
                Health = player.Health,
                Level = player.Level
            });
        }
Пример #6
0
 public static PlayerExtended MapExtended(this User user, IGameData gameData, Character character)
 {
     return(new PlayerExtended
     {
         UserName = user.UserName,
         UserId = user.UserId,
         Name = character.Name,
         IsAdmin = user.IsAdmin.GetValueOrDefault(),
         IsModerator = user.IsModerator.GetValueOrDefault(),
         Appearance = Map(gameData.GetAppearance(character.SyntyAppearanceId)),
         Resources = Map(gameData.GetResources(character.ResourcesId)),
         Skills = MapExtended(gameData.GetSkills(character.SkillsId)),
         State = Map(gameData.GetState(character.StateId)),
         InventoryItems = Map(gameData.GetAllPlayerItems(character.Id)),
         Statistics = Map(gameData.GetStatistics(character.StatisticsId)),
         Clan = Map(gameData, gameData.GetClan(character.ClanId.GetValueOrDefault())),
         OriginUserId = character.OriginUserId,
         Revision = character.Revision.GetValueOrDefault()
     });
 }
Пример #7
0
        public static MyPlayerAdd Create(
            IGameData gameData,
            Player player,
            IReadOnlyList <InventoryItem> items)
        {
            var appearance  = gameData.GetAppearance(player.AppearanceId);
            var transform   = gameData.GetTransform(player.TransformId);
            var attributes  = gameData.GetAttributes(player.AttributesId);
            var professions = gameData.GetProfessions(player.ProfessionsId);

            var itemIds = new int[items.Count];
            var amounts = new long[items.Count];

            for (var i = 0; i < items.Count; ++i)
            {
                itemIds[i] = items[i].ItemId;
                amounts[i] = items[i].Amount;
            }

            return(new MyPlayerAdd
            {
                PlayerId = player.Id,
                Name = player.Name,
                Experience = player.Experience,
                Level = player.Level,
                Health = player.Health,
                Endurance = player.Endurance,
                Position = transform.GetPosition(),
                Attributes = attributes,
                Professions = professions,
                Appearance = appearance,
                InventoryItemId = itemIds,
                InventoryItemAmount = amounts,
                Coins = player.Coins
            });
        }
Пример #8
0
        public static WebsitePlayer MapForWebsite(this User user, IGameData gameData, Character character)
        {
            var items = gameData.GetAllPlayerItems(character.Id).OrderBy(x => gameData.GetItem(x.ItemId)?.Name).ToList();

            var clanMembership = gameData.GetClanMembership(character.Id);
            var clan           = clanMembership != null?Map(gameData, gameData.GetClan(clanMembership.ClanId)) : null;

            var clanRole = clanMembership != null?Map(gameData.GetClanRole(clanMembership.ClanRoleId), clanMembership) : null;

            var sessionInfo = GetCharacterSessionInfo(gameData, character);

            return(new WebsitePlayer
            {
                Id = character.Id,
                UserName = user.UserName,
                CharacterIndex = character.CharacterIndex,
                UserId = user.UserId,
                Name = character.Name,
                IsAdmin = user.IsAdmin.GetValueOrDefault(),
                IsModerator = user.IsModerator.GetValueOrDefault(),
                Appearance = Map(gameData.GetAppearance(character.SyntyAppearanceId)),
                Resources = Map(gameData.GetResources(character.ResourcesId)),
                Skills = MapForWebsite(gameData.GetCharacterSkills(character.SkillsId)),
                State = Map(gameData.GetCharacterState(character.StateId)),
                InventoryItems = Map(items),
                Statistics = Map(gameData.GetStatistics(character.StatisticsId)),
                Clan = clan,
                ClanRole = clanRole,
                Identifier = character.Identifier,
                OriginUserId = character.OriginUserId,
                SessionInfo = sessionInfo,
                PatreonTier = user.PatreonTier.GetValueOrDefault(),
                Revision = character.Revision.GetValueOrDefault(),
                IsHiddenInHighscore = user.IsHiddenInHighscore.GetValueOrDefault()
            });
        }
Пример #9
0
        public static Player Map(
            this User user,
            IGameData gameData,
            Character character,
            bool rejoin = false,
            bool inGame = false)
        {
            var playItems = gameData.GetAllPlayerItems(character.Id);

            if (inGame && character.UserIdLock != null)
            {
                var targetStreamUser = gameData.GetUser(character.UserIdLock.Value);
                // if we got streamer tokens, only send the ones for the appropriate streamer
                playItems = playItems.Where(x => x.Tag == null || x.Tag == targetStreamUser.UserId).ToList();
            }

            var invItems = Map(playItems);

            if (user == null)
            {
                return(null);
            }

            var clanMembership = gameData.GetClanMembership(character.Id);
            var clan           = clanMembership != null?Map(gameData, gameData.GetClan(clanMembership.ClanId)) : null;

            var clanRole = clanMembership != null?Map(gameData.GetClanRole(clanMembership.ClanRoleId), clanMembership) : null;

            var characterState = gameData.GetCharacterState(character.StateId);

            if (character.StateId == null || characterState == null)
            {
                characterState = new DataModels.CharacterState()
                {
                    Id = Guid.NewGuid()
                };
                character.StateId = characterState.Id;
                gameData.Add(characterState);
            }

            return(new Player
            {
                Id = character.Id,
                UserName = user.UserName,
                UserId = user.UserId,
                Name = character.Name,
                IsRejoin = rejoin,
                IsAdmin = user.IsAdmin.GetValueOrDefault(),
                IsModerator = user.IsModerator.GetValueOrDefault(),
                Appearance = Map(gameData.GetAppearance(character.SyntyAppearanceId)),
                Resources = Map(gameData.GetResources(character.ResourcesId)),
                Skills = Map(gameData.GetCharacterSkills(character.SkillsId)),
                State = Map(characterState),
                InventoryItems = invItems,
                Statistics = Map(gameData.GetStatistics(character.StatisticsId)),
                Clan = clan,
                ClanRole = clanRole,
                OriginUserId = character.OriginUserId,
                Revision = character.Revision.GetValueOrDefault(),
                Identifier = character.Identifier,
                CharacterIndex = character.CharacterIndex,
                PatreonTier = user.PatreonTier.GetValueOrDefault(),
                IsHiddenInHighscore = user.IsHiddenInHighscore.GetValueOrDefault()
            });
        }
Пример #10
0
        public bool AcceptClanInvite(Guid inviteId)
        {
            // invite does not exist
            var invite = gameData.GetClanInvite(inviteId);

            if (invite == null)
            {
                return(false);
            }

            // character does not exist
            var character = gameData.GetCharacter(invite.CharacterId);

            if (character == null)
            {
                return(false);
            }

            var membership = gameData.GetClanMembership(invite.CharacterId);

            if (membership != null)
            {
                // check if the clan still exists.
                var joinedClan = gameData.GetClan(membership.ClanId);
                if (joinedClan != null && gameData.GetUser(joinedClan.UserId) != null)
                {
                    return(false);
                }
            }

            // clan does not exist
            var clan = gameData.GetClan(invite.ClanId);

            if (clan == null)
            {
                return(false);
            }

            var roles = gameData.GetClanRoles(clan.Id);
            var role  = roles.OrderBy(x => x.Level).FirstOrDefault(x => x.Level > 0);

            if (role == null)
            {
                role = roles.FirstOrDefault();
            }

            var appearance = gameData.GetAppearance(character.SyntyAppearanceId);

            if (appearance == null)
            {
                return(false);
            }

            appearance.Cape = 0;

            if (role == null)
            {
                CreateDefaultRoles(clan);
                role = gameData.GetClanRoles(clan.Id).OrderBy(x => x.Level).FirstOrDefault(x => x.Level > 0);
            }

            gameData.Add(new DataModels.CharacterClanMembership
            {
                Id          = Guid.NewGuid(),
                ClanId      = clan.Id,
                CharacterId = character.Id,
                ClanRoleId  = role.Id,
                Joined      = DateTime.UtcNow,
            });
            gameData.Remove(invite);

            notificationManager.ClanInviteAccepted(invite.ClanId, invite.CharacterId, DateTime.UtcNow, invite.InviterUserId);
            return(true);
        }