Пример #1
0
        protected virtual void HandleUpdateGuildAtClient(LiteNetLibMessageHandler messageHandler)
        {
            UpdateGuildMessage message = messageHandler.ReadMessage <UpdateGuildMessage>();

            if (message.type == UpdateGuildMessage.UpdateType.Create)
            {
                ClientGuild = new GuildData(message.id, message.guildName, message.characterId);
            }
            else if (ClientGuild != null && ClientGuild.id == message.id)
            {
                switch (message.type)
                {
                case UpdateGuildMessage.UpdateType.ChangeLeader:
                    ClientGuild.SetLeader(message.characterId);
                    break;

                case UpdateGuildMessage.UpdateType.SetGuildMessage:
                    ClientGuild.guildMessage = message.guildMessage;
                    break;

                case UpdateGuildMessage.UpdateType.SetGuildRole:
                    ClientGuild.SetRole(message.guildRole, message.roleName, message.canInvite, message.canKick, message.shareExpPercentage);
                    break;

                case UpdateGuildMessage.UpdateType.SetGuildMemberRole:
                    ClientGuild.SetMemberRole(message.characterId, message.guildRole);
                    break;

                case UpdateGuildMessage.UpdateType.SetSkillLevel:
                    ClientGuild.SetSkillLevel(message.dataId, message.level);
                    if (BasePlayerCharacterController.OwningCharacter != null)
                    {
                        BasePlayerCharacterController.OwningCharacter.ForceMakeCaches();
                    }
                    break;

                case UpdateGuildMessage.UpdateType.SetGold:
                    ClientGuild.gold = message.gold;
                    break;

                case UpdateGuildMessage.UpdateType.LevelExpSkillPoint:
                    ClientGuild.level      = message.level;
                    ClientGuild.exp        = message.exp;
                    ClientGuild.skillPoint = message.skillPoint;
                    break;

                case UpdateGuildMessage.UpdateType.Terminate:
                    ClientGuild = null;
                    if (BasePlayerCharacterController.OwningCharacter != null)
                    {
                        BasePlayerCharacterController.OwningCharacter.ForceMakeCaches();
                    }
                    break;
                }
            }
            if (onClientUpdateGuild != null)
            {
                onClientUpdateGuild.Invoke(ClientGuild);
            }
        }
Пример #2
0
        public void SendSetGuildMessageToClient(long connectionId, GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            Server.SendSetGuildMessage(connectionId, MsgTypes.UpdateGuild, guild.id, guild.guildMessage);
        }
Пример #3
0
        public void SendChangeGuildLeaderToClient(long connectionId, GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            Server.SendChangeGuildLeader(connectionId, MsgTypes.UpdateGuild, guild.id, guild.leaderId);
        }
Пример #4
0
        public void SendAddGuildMembersToClient(long connectionId, GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            foreach (var member in guild.GetMembers())
            {
                SendAddGuildMemberToClient(connectionId, guild.id, member.id, member.characterName, member.dataId, member.level);
            }
        }
Пример #5
0
        public void SendUpdateGuildMembersToClient(long connectionId, GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            foreach (var member in guild.GetMembers())
            {
                SendUpdateGuildMemberToClient(connectionId, guild.id, guild.IsOnline(member.id), member.id, member.characterName, member.dataId, member.level, member.currentHp, member.maxHp, member.currentMp, member.maxMp);
            }
        }
Пример #6
0
        public void SendRemoveGuildMemberToClients(GuildData guild, string characterId)
        {
            BasePlayerCharacterEntity playerCharacterEntity;

            foreach (var member in guild.GetMembers())
            {
                if (!member.id.Equals(characterId) && TryGetPlayerCharacterById(member.id, out playerCharacterEntity))
                {
                    SendRemoveGuildMemberToClient(playerCharacterEntity.ConnectionId, guild.id, characterId);
                }
            }
        }
Пример #7
0
        public void SendSetGuildSkillLevelsToClient(long connectionId, GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            foreach (var guildSkillLevel in guild.GetSkillLevels())
            {
                SendSetGuildSkillLevelToClient(connectionId, guild.id, guildSkillLevel.Key, guildSkillLevel.Value);
            }
        }
Пример #8
0
 public GuildData IncreaseGuildExp(GuildData guild, int exp)
 {
     CalculateIncreasedGuildExp(
         GuildExpTree,
         guild.level,
         guild.exp + exp,
         guild.skillPoint,
         out guild.level,
         out guild.exp,
         out guild.skillPoint);
     return(guild);
 }
Пример #9
0
        public void SendSetGuildRolesToClient(long connectionId, GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            var           roles = guild.GetRoles();
            GuildRoleData guildRoleData;

            for (byte role = 0; role < roles.Count; ++role)
            {
                guildRoleData = roles[role];
                SendSetGuildRoleToClient(connectionId, guild.id, role, guildRoleData.roleName, guildRoleData.canInvite, guildRoleData.canKick, guildRoleData.shareExpPercentage);
            }
        }
Пример #10
0
        public void SendSetGuildRoleToClients(GuildData guild, byte guildRole, string roleName, bool canInvite, bool canKick, byte shareExpPercentage)
        {
            if (guild == null)
            {
                return;
            }

            BasePlayerCharacterEntity playerCharacterEntity;

            foreach (var member in guild.GetMembers())
            {
                if (TryGetPlayerCharacterById(member.id, out playerCharacterEntity))
                {
                    SendSetGuildRoleToClient(playerCharacterEntity.ConnectionId, guild.id, guildRole, roleName, canInvite, canKick, shareExpPercentage);
                }
            }
        }
Пример #11
0
        public void SendSetGuildMemberRolesToClient(long connectionId, GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            byte role;

            foreach (var member in guild.GetMembers())
            {
                if (guild.TryGetMemberRole(member.id, out role))
                {
                    SendSetGuildMemberRoleToClient(connectionId, guild.id, member.id, role);
                }
            }
        }
Пример #12
0
        public virtual void CreateGuild(BasePlayerCharacterEntity playerCharacterEntity, string guildName, int guildId)
        {
            if (!CanCreateGuild(playerCharacterEntity))
            {
                return;
            }

            gameInstance.SocialSystemSetting.ReduceCreateGuildResource(playerCharacterEntity);
            var guild = new GuildData(guildId, guildName, playerCharacterEntity);

            guilds[guildId] = guild;
            playerCharacterEntity.GuildId        = guildId;
            playerCharacterEntity.GuildRole      = guild.GetMemberRole(playerCharacterEntity.Id);
            playerCharacterEntity.SharedGuildExp = 0;
            SendCreateGuildToClient(playerCharacterEntity.ConnectionId, guild);
            SendAddGuildMembersToClient(playerCharacterEntity.ConnectionId, guild);
        }
Пример #13
0
        public void SendAddGuildMemberToClients(GuildData guild, string characterId, string characterName, int dataId, short level)
        {
            if (guild == null)
            {
                return;
            }

            BasePlayerCharacterEntity playerCharacterEntity;

            foreach (var member in guild.GetMembers())
            {
                if (!member.id.Equals(characterId) && TryGetPlayerCharacterById(member.id, out playerCharacterEntity))
                {
                    SendAddGuildMemberToClient(playerCharacterEntity.ConnectionId, guild.id, characterId, characterName, dataId, level);
                }
            }
        }
Пример #14
0
        public void SendGuildLevelExpSkillPointToClients(GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            BasePlayerCharacterEntity playerCharacterEntity;

            foreach (var member in guild.GetMembers())
            {
                if (TryGetPlayerCharacterById(member.id, out playerCharacterEntity))
                {
                    SendGuildLevelExpSkillPointToClient(playerCharacterEntity.ConnectionId, guild);
                }
            }
        }
Пример #15
0
        public void SendSetGuildMemberRoleToClients(GuildData guild, string characterId, byte guildRole)
        {
            if (guild == null)
            {
                return;
            }

            BasePlayerCharacterEntity playerCharacterEntity;

            foreach (var member in guild.GetMembers())
            {
                if (TryGetPlayerCharacterById(member.id, out playerCharacterEntity))
                {
                    SendSetGuildMemberRoleToClient(playerCharacterEntity.ConnectionId, guild.id, characterId, guildRole);
                }
            }
        }
Пример #16
0
        public void SendSetGuildSkillLevelToClients(GuildData guild, int dataId)
        {
            if (guild == null)
            {
                return;
            }

            var skillLevel = guild.GetSkillLevel(dataId);
            BasePlayerCharacterEntity playerCharacterEntity;

            foreach (var member in guild.GetMembers())
            {
                if (TryGetPlayerCharacterById(member.id, out playerCharacterEntity))
                {
                    SendSetGuildSkillLevelToClient(playerCharacterEntity.ConnectionId, guild.id, dataId, skillLevel);
                }
            }
        }
        public static bool CanLevelUp(this GuildSkill guildSkill, IPlayerCharacterData character, short level)
        {
            if (guildSkill == null || character == null)
            {
                return(false);
            }

            BaseGameNetworkManager gameManager = BaseGameNetworkManager.Singleton;

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

            GuildData guildData = null;

            if (!gameManager.TryGetGuild(character.GuildId, out guildData))
            {
                return(false);
            }

            return(guildData.skillPoint > 0 && level < guildSkill.maxLevel);
        }
Пример #18
0
        private void UpdateGuildUIs(GuildData guild)
        {
            if (guild == null)
            {
                return;
            }

            memberAmount = guild.CountMember();
            UpdateUIs();

            int selectedIdx = MemberSelectionManager.SelectedUI != null?MemberSelectionManager.IndexOf(MemberSelectionManager.SelectedUI) : -1;

            MemberSelectionManager.DeselectSelectedUI();
            MemberSelectionManager.Clear();

            SocialCharacterData[] members;
            byte[] memberRoles;
            guild.GetSortedMembers(out members, out memberRoles);
            MemberList.Generate(members, (index, guildMember, ui) =>
            {
                SocialCharacterEntityTuple guildMemberEntity = new SocialCharacterEntityTuple();
                guildMemberEntity.socialCharacter            = guildMember;

                UIGuildCharacter uiGuildMember = ui.GetComponent <UIGuildCharacter>();
                uiGuildMember.uiSocialGroup    = this;
                uiGuildMember.Setup(guildMemberEntity, memberRoles[index], guild.GetRole(memberRoles[index]));
                uiGuildMember.Show();
                MemberSelectionManager.Add(uiGuildMember);
                if (selectedIdx == index)
                {
                    uiGuildMember.OnClickSelect();
                }
            });

            selectedIdx = RoleSelectionManager.SelectedUI != null?RoleSelectionManager.IndexOf(RoleSelectionManager.SelectedUI) : -1;

            RoleSelectionManager.DeselectSelectedUI();
            RoleSelectionManager.Clear();

            RoleList.Generate(guild.GetRoles(), (index, guildRole, ui) =>
            {
                UIGuildRole uiGuildRole = ui.GetComponent <UIGuildRole>();
                uiGuildRole.Data        = guildRole;
                uiGuildRole.Show();
                RoleSelectionManager.Add(uiGuildRole);
                if (selectedIdx == index)
                {
                    uiGuildRole.OnClickSelect();
                }
            });

            selectedIdx = SkillSelectionManager.SelectedUI != null?SkillSelectionManager.IndexOf(SkillSelectionManager.SelectedUI) : -1;

            SkillSelectionManager.DeselectSelectedUI();
            SkillSelectionManager.Clear();

            SkillList.Generate(GameInstance.GuildSkills.Values, (index, guildSkill, ui) =>
            {
                UIGuildSkill uiGuildSkill = ui.GetComponent <UIGuildSkill>();
                uiGuildSkill.Data         = new GuildSkillTuple(guildSkill, guild.GetSkillLevel(guildSkill.DataId));
                uiGuildSkill.Show();
                SkillSelectionManager.Add(uiGuildSkill);
                if (selectedIdx == index)
                {
                    uiGuildSkill.OnClickSelect();
                }
            });
        }
Пример #19
0
 public virtual bool CanSetGuildMemberRole(BasePlayerCharacterEntity playerCharacterEntity, out int guildId, out GuildData guild)
 {
     guildId = 0;
     guild   = null;
     if (playerCharacterEntity == null || !IsServer)
     {
         return(false);
     }
     guildId = playerCharacterEntity.GuildId;
     if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.NotJoinedGuild);
         return(false);
     }
     if (!guild.IsLeader(playerCharacterEntity))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.GuildRoleNotAvailable);
         return(false);
     }
     return(true);
 }
Пример #20
0
 public bool TryGetGuild(int id, out GuildData result)
 {
     return(guilds.TryGetValue(id, out result));
 }
Пример #21
0
 public virtual bool CanAddGuildMember(BasePlayerCharacterEntity inviteCharacterEntity, BasePlayerCharacterEntity acceptCharacterEntity, out int guildId, out GuildData guild)
 {
     guildId = 0;
     guild   = null;
     if (inviteCharacterEntity == null || acceptCharacterEntity == null || !IsServer)
     {
         return(false);
     }
     if (acceptCharacterEntity.GuildId > 0)
     {
         SendServerGameMessage(acceptCharacterEntity.ConnectionId, GameMessage.Type.JoinedAnotherGuild);
         return(false);
     }
     guildId = inviteCharacterEntity.GuildId;
     if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
     {
         SendServerGameMessage(acceptCharacterEntity.ConnectionId, GameMessage.Type.CharacterNotJoinedGuild);
         return(false);
     }
     if (guild.CountMember() >= guild.MaxMember())
     {
         SendServerGameMessage(acceptCharacterEntity.ConnectionId, GameMessage.Type.GuildMemberReachedLimit);
         return(false);
     }
     return(true);
 }
Пример #22
0
 public void SendGuildLevelExpSkillPointToClient(long connectionId, GuildData guild)
 {
     Server.SendGuildLevelExpSkillPoint(connectionId, MsgTypes.UpdateGuild, guild.id, guild.level, guild.exp, guild.skillPoint);
 }
Пример #23
0
        public virtual bool CanKickFromGuild(BasePlayerCharacterEntity playerCharacterEntity, string characterId, out int guildId, out GuildData guild)
        {
            guildId = 0;
            guild   = null;
            if (playerCharacterEntity == null || !IsServer)
            {
                return(false);
            }
            guildId = playerCharacterEntity.GuildId;
            if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
            {
                SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.NotJoinedGuild);
                return(false);
            }
            if (guild.IsLeader(characterId))
            {
                SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.CannotKickGuildLeader);
                return(false);
            }
            if (!guild.CanKick(playerCharacterEntity.Id))
            {
                SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.CannotKickGuildMember);
                return(false);
            }
            if (playerCharacterEntity.Id.Equals(characterId))
            {
                SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.CannotKickYourSelfFromGuild);
                return(false);
            }
            byte role;

            if (!guild.TryGetMemberRole(characterId, out role) && playerCharacterEntity.GuildRole < role)
            {
                SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.CannotKickHigherGuildMember);
                return(false);
            }
            if (!guild.ContainsMemberId(characterId))
            {
                SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.CharacterNotJoinedGuild);
                return(false);
            }
            return(true);
        }
Пример #24
0
 public virtual bool CanLeaveGuild(BasePlayerCharacterEntity playerCharacterEntity, out int guildId, out GuildData guild)
 {
     guildId = 0;
     guild   = null;
     if (playerCharacterEntity == null || !IsServer)
     {
         return(false);
     }
     guildId = playerCharacterEntity.GuildId;
     if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.NotJoinedGuild);
         return(false);
     }
     return(true);
 }
Пример #25
0
 public virtual bool CanIncreaseGuildExp(BasePlayerCharacterEntity playerCharacterEntity, int exp, out int guildId, out GuildData guild)
 {
     guildId = 0;
     guild   = null;
     if (exp <= 0 || playerCharacterEntity == null || !IsServer)
     {
         return(false);
     }
     guildId = playerCharacterEntity.GuildId;
     if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
     {
         return(false);
     }
     return(true);
 }
Пример #26
0
 public virtual bool CanAddGuildSkill(BasePlayerCharacterEntity playerCharacterEntity, int dataId, out int guildId, out GuildData guild)
 {
     guildId = 0;
     guild   = null;
     if (playerCharacterEntity == null || !IsServer || !GameInstance.GuildSkills.ContainsKey(dataId))
     {
         return(false);
     }
     guildId = playerCharacterEntity.GuildId;
     if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
     {
         return(false);
     }
     if (!guild.IsLeader(playerCharacterEntity))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.NotGuildLeader);
         return(false);
     }
     if (guild.IsSkillReachedMaxLevel(dataId))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.GuildSkillReachedMaxLevel);
         return(false);
     }
     if (guild.skillPoint <= 0)
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.NoGuildSkillPoint);
         return(false);
     }
     return(true);
 }
Пример #27
0
 public virtual bool CanChangeGuildLeader(BasePlayerCharacterEntity playerCharacterEntity, string characterId, out int guildId, out GuildData guild)
 {
     guildId = 0;
     guild   = null;
     if (playerCharacterEntity == null || !IsServer)
     {
         return(false);
     }
     guildId = playerCharacterEntity.GuildId;
     if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.NotJoinedGuild);
         return(false);
     }
     if (!guild.IsLeader(playerCharacterEntity))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.NotGuildLeader);
         return(false);
     }
     if (!guild.ContainsMemberId(characterId))
     {
         SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.CharacterNotJoinedGuild);
         return(false);
     }
     return(true);
 }
Пример #28
0
 public virtual bool CanUseGuildSkill(BasePlayerCharacterEntity playerCharacterEntity, int dataId, out int guildId, out GuildData guild)
 {
     guildId = 0;
     guild   = null;
     if (playerCharacterEntity == null || !IsServer || !GameInstance.GuildSkills.ContainsKey(dataId))
     {
         return(false);
     }
     guildId = playerCharacterEntity.GuildId;
     if (guildId <= 0 || !guilds.TryGetValue(guildId, out guild))
     {
         return(false);
     }
     if (guild.GetSkillLevel(dataId) <= 0)
     {
         return(false);
     }
     if (playerCharacterEntity.IndexOfSkillUsage(dataId, SkillUsageType.GuildSkill) >= 0)
     {
         return(false);
     }
     return(true);
 }