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);
        }
Beispiel #2
0
        public ItemCollection GetAllItems(SessionToken token, string userId)
        {
            var itemCollection = new ItemCollection();
            var character      = GetCharacter(token, userId);

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

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

            if (items == null || items.Count == 0)
            {
                return(itemCollection);
            }

            foreach (var inv in items)
            {
                var item = gameData.GetItem(inv.ItemId);
                if (item != null)
                {
                    itemCollection.Add(ModelMapper.Map(gameData, item));
                }
            }

            return(itemCollection);
        }
        private List <InventoryItem> GetInventoryItems(Guid characterId)
        {
            var output   = new List <InventoryItem>();
            var invItems = gameData?.GetAllPlayerItems(characterId)?.ToList() ?? new List <InventoryItem>();

            foreach (var i in invItems)
            {
                output.Add(i);
            }
            return(output);
        }
Beispiel #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()
            });
        }
Beispiel #5
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()
     });
 }
Beispiel #6
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()
            });
        }
Beispiel #7
0
        public bool MergePlayerAccounts(string userId)
        {
            var user = gameData.GetUserByTwitchId(userId);

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

            var characters = gameData
                             .GetCharacters(x => x.Name.Equals(user.UserName, StringComparison.OrdinalIgnoreCase))
                             .OrderByDescending(x => x.Revision)
                             .ToList();

            var main = gameData.GetCharacterByUserId(user.Id, "1");

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

            var mainSkills    = gameData.GetCharacterSkills(main.SkillsId);
            var mainResources = gameData.GetResources(main.ResourcesId);

            var mainInventory  = gameData.GetInventoryItems(main.Id);
            var mainStatistics = gameData.GetStatistics(main.StatisticsId);

            foreach (var alt in characters)
            {
                if (alt.Id == main.Id || alt.UserId == main.UserId)
                {
                    continue;
                }

                var altSkills = gameData.GetCharacterSkills(alt.SkillsId);
                if (altSkills != null)
                {
                    MergeSkills(mainSkills, altSkills);
                    gameData.Remove(altSkills);
                }

                var altResources = gameData.GetResources(alt.ResourcesId);
                if (altResources != null)
                {
                    MergeResources(mainResources, altResources);
                    gameData.Remove(altResources);
                }

                var altItems = gameData.GetAllPlayerItems(alt.Id);
                foreach (var altItem in altItems)
                {
                    var mainItem = mainInventory.FirstOrDefault(x => x.ItemId == altItem.ItemId);
                    if (mainItem != null)
                    {
                        mainItem.Amount += altItem.Amount;
                    }
                    else
                    {
                        if (altItem.Amount > 0)
                        {
                            gameData.Add(new DataModels.InventoryItem
                            {
                                Id          = Guid.NewGuid(),
                                Amount      = altItem.Amount,
                                CharacterId = main.Id,
                                Equipped    = false,
                                ItemId      = altItem.ItemId
                            });
                        }
                    }
                    gameData.Remove(altItem);
                }

                var altStatistics = gameData.GetStatistics(alt.StatisticsId);
                if (altStatistics != null)
                {
                    MergeStatistics(mainStatistics, altStatistics);
                    gameData.Remove(altStatistics);
                }

                gameData.Remove(alt);

                var altUser = gameData.GetUser(alt.UserId);
                if (altUser != null)
                {
                    gameData.Remove(altUser);
                }
            }

            return(FixCharacterIndices(user));
        }
Beispiel #8
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()
            });
        }