Пример #1
0
        private GuildResultInfo GuildOperationRankRename(GuildMember member, Player player, ClientGuildOperation operation)
        {
            GuildRank rank = null;

            GuildResultInfo GetResult()
            {
                if (!member.Rank.HasPermission(GuildRankPermission.RenameRank))
                {
                    return(new GuildResultInfo(GuildResult.RankLacksRankRenamePermission));
                }

                rank = GetRank((byte)operation.Rank);
                if (rank == null)
                {
                    return(new GuildResultInfo(GuildResult.InvalidRank, operation.Rank, operation.TextValue));
                }

                if (member.Rank.Index >= operation.Rank)
                {
                    return(new GuildResultInfo(GuildResult.CanOnlyModifyLowerRanks));
                }

                if (RankExists(operation.TextValue))
                {
                    return(new GuildResultInfo(GuildResult.DuplicateRankName, referenceString: operation.TextValue));
                }

                if (!TextFilterManager.Instance.IsTextValid(operation.TextValue) ||
                    !TextFilterManager.Instance.IsTextValid(operation.TextValue, UserText.GuildRankName))
                {
                    return(new GuildResultInfo(GuildResult.InvalidRankName, referenceString: operation.TextValue));
                }

                return(new GuildResultInfo(GuildResult.Success));
            }

            GuildResultInfo info = GetResult();

            if (info.Result == GuildResult.Success)
            {
                rank.Name = operation.TextValue;
                AnnounceGuildRankChange();
                AnnounceGuildResult(GuildResult.RankRenamed, operation.Rank, operation.TextValue);
            }

            return(info);
        }
Пример #2
0
        private GuildResultInfo GuildOperationRankDelete(GuildMember member, Player player, ClientGuildOperation operation)
        {
            GuildRank rank = null;

            GuildResultInfo GetResult()
            {
                if (!member.Rank.HasPermission(GuildRankPermission.CreateAndRemoveRank))
                {
                    return(new GuildResultInfo(GuildResult.RankLacksRankRenamePermission));
                }

                rank = GetRank((byte)operation.Rank);
                if (rank == null)
                {
                    return(new GuildResultInfo(GuildResult.InvalidRank, operation.Rank, operation.TextValue));
                }

                if (member.Rank.Index >= operation.Rank)
                {
                    return(new GuildResultInfo(GuildResult.CanOnlyModifyLowerRanks));
                }

                if (operation.Rank < 2 || operation.Rank > 8)
                {
                    return(new GuildResultInfo(GuildResult.CannotDeleteDefaultRanks, referenceId: operation.Rank));
                }

                if (rank.Any())
                {
                    return(new GuildResultInfo(GuildResult.CanOnlyDeleteEmptyRanks));
                }

                return(new GuildResultInfo(GuildResult.Success));
            }

            GuildResultInfo info = GetResult();

            if (info.Result == GuildResult.Success)
            {
                RemoveRank((byte)operation.Rank);
                AnnounceGuildRankChange();
                AnnounceGuildResult(GuildResult.RankDeleted, referenceText: operation.TextValue);
            }

            return(info);
        }
Пример #3
0
        private GuildResultInfo GuildOperationMemberDemote(GuildMember member, Player player, ClientGuildOperation operation)
        {
            GuildMember targetMember = null;

            GuildResultInfo GetResult()
            {
                if (!member.Rank.HasPermission(GuildRankPermission.ChangeMemberRank))
                {
                    return(new GuildResultInfo(GuildResult.RankLacksSufficientPermissions));
                }

                targetMember = GetMember(operation.TextValue);
                if (targetMember == null)
                {
                    return(new GuildResultInfo(GuildResult.CharacterNotInYourGuild, referenceString: operation.TextValue));
                }

                if (member.Rank.Index >= targetMember.Rank.Index)
                {
                    return(new GuildResultInfo(GuildResult.CannotDemote));
                }

                if (targetMember.Rank.Index == 9)
                {
                    return(new GuildResultInfo(GuildResult.CannotDemoteLowestRank));
                }

                return(new GuildResultInfo(GuildResult.Success));
            }

            GuildResultInfo info = GetResult();

            if (info.Result == GuildResult.Success)
            {
                GuildRank newRank = GetDemotedRank(targetMember.Rank.Index);
                MemberChangeRank(targetMember, newRank);

                AnnounceGuildMemberChange(targetMember);
                AnnounceGuildResult(GuildResult.DemotedMember, referenceText: operation.TextValue);
            }

            return(info);
        }
Пример #4
0
        private GuildResultInfo GuildOperationRankPermissions(GuildMember member, Player player, ClientGuildOperation operation)
        {
            GuildRank rank = null;

            GuildResultInfo GetResult()
            {
                if (!member.Rank.HasPermission(GuildRankPermission.EditLowerRankPermissions))
                {
                    return(new GuildResultInfo(GuildResult.RankLacksRankRenamePermission));
                }

                rank = GetRank((byte)operation.Rank);
                if (rank == null)
                {
                    return(new GuildResultInfo(GuildResult.InvalidRank, operation.Rank, operation.TextValue));
                }

                // TODO: check if mask options are valid for this guild type

                if (member.Rank.Index >= operation.Rank)
                {
                    return(new GuildResultInfo(GuildResult.CanOnlyModifyLowerRanks));
                }

                return(new GuildResultInfo(GuildResult.Success));
            }

            GuildResultInfo info = GetResult();

            if (info.Result == GuildResult.Success)
            {
                // TODO: research why disabled needs to be removed
                var permissions = (GuildRankPermission)operation.Data.UInt32Data & ~GuildRankPermission.Disabled;
                rank.Permissions = permissions;

                AnnounceGuildRankChange();
                AnnounceGuildResult(GuildResult.RankModified, operation.Rank, operation.TextValue);
            }

            return(info);
        }