Пример #1
0
        public void ChangeLeader(Gang gang, Character newLeader)
        {
            if (!gang.IsMember(newLeader))
            {
                throw new PerpetuumException(ErrorCodes.CharacterNotInTheCurrentGang);
            }

            _gangRepository.UpdateLeader(gang, newLeader);

            void Finish()
            {
                gang.Leader = newLeader;
                Message.Builder.SetCommand(Commands.GangSetLeader).WithData(new Dictionary <string, object>
                {
                    { k.leaderId, newLeader.Id }
                }).ToCharacters(gang.GetMembers()).Send();
                _channelManager.SetMemberRole(gang.ChannelName, newLeader, ChannelMemberRole.Operator);
                GangLeaderChanged?.Invoke(gang);
            }

            if (Transaction.Current != null)
            {
                Transaction.Current.OnCommited(Finish);
            }
            else
            {
                Finish();
            }
        }
Пример #2
0
        public static bool IsMember(this Gang gang, Player player)
        {
            if (gang == null)
            {
                return(false);
            }

            return(player != null && gang.IsMember(player.Character));
        }
Пример #3
0
        public void RemoveMember(Gang gang, Character member, bool isKick)
        {
            if (gang == null)
            {
                return;
            }

            if (!gang.IsMember(member))
            {
                throw new PerpetuumException(ErrorCodes.CharacterNotInTheCurrentGang);
            }

            _gangRepository.DeleteMember(gang, member);

            void Finish()
            {
                var data = new Dictionary <string, object>
                {
                    { k.data, gang.GetGangData() },
                    { k.memberID, member.Id }
                };

                var cmd = isKick ? Commands.GangKickMember : Commands.GangRemoveMember;

                Message.Builder.SetCommand(cmd).WithData(data).ToCharacters(gang.GetMembers()).Send();

                gang.RemoveMember(member);

                _channelManager.LeaveChannel(gang.ChannelName, member);

                OnGangMemberRemoved(gang, member);
            }

            if (Transaction.Current != null)
            {
                Transaction.Current.OnCommited(Finish);
            }
            else
            {
                Finish();
            }
        }
Пример #4
0
        public void SetRole(Gang gang, Character member, GangRole newRole)
        {
            if (gang.Leader == member)
            {
                return;
            }

            if (!gang.IsMember(member))
            {
                throw new PerpetuumException(ErrorCodes.CharacterNotInTheCurrentGang);
            }

            _gangRepository.UpdateMemberRole(gang, member, newRole);

            void Finish()
            {
                gang.SetMember(member, newRole);
                Message.Builder.SetCommand(Commands.GangSetRole).WithData(new Dictionary <string, object>
                {
                    { k.memberID, member.Id },
                    { k.role, (int)newRole }
                }).ToCharacters(gang.GetMembers()).Send();

                var channelMemberRole = gang.HasRole(member, GangRole.Assistant) ? ChannelMemberRole.Operator : ChannelMemberRole.Undefined;

                _channelManager.SetMemberRole(gang.ChannelName, member, channelMemberRole);
            }

            if (Transaction.Current == null)
            {
                Transaction.Current.OnCommited(Finish);
            }
            else
            {
                Finish();
            }
        }