Esempio n. 1
0
        protected virtual void OnGangMemberRemoved(Gang gang, Character member)
        {
            try
            {
                var members = gang.GetMembers().ToArray();

                if (members.Length <= 0)
                {
                    DisbandGang(gang);
                    return;
                }

                if (gang.Leader != member)
                {
                    return;
                }

                // nincs leader
                var newLeader = members.FirstOrDefault(mm => gang.HasRole(mm, GangRole.Assistant)) ?? Character.None;
                if (newLeader == Character.None)
                {
                    var firstMember = members.First();
                    newLeader = firstMember;
                }

                ChangeLeader(gang, newLeader);
            }
            finally
            {
                GangMemberRemoved?.Invoke(gang, member);
            }
        }
Esempio n. 2
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();
            }
        }