コード例 #1
0
        private void OnLeaveAllianceMessageReceived(LeaveAllianceMessage message)
        {
            if (this.m_session.Alliance != null)
            {
                Alliance            alliance    = this.m_session.Alliance;
                AllianceMemberEntry memberEntry = alliance.Members[this.m_session.AccountId];

                if (memberEntry.GetAllianceRole() == LogicAvatarAllianceRole.LEADER)
                {
                    AllianceMemberEntry     higherMemberEntry = null;
                    LogicAvatarAllianceRole higherMemberRole  = 0;

                    foreach (AllianceMemberEntry member in alliance.Members.Values)
                    {
                        if (member != memberEntry && (higherMemberEntry == null || !member.HasLowerRoleThan(higherMemberRole)))
                        {
                            higherMemberEntry = member;
                            higherMemberRole  = member.GetAllianceRole();
                        }
                    }

                    if (higherMemberEntry != null)
                    {
                        alliance.ChangeMemberRole(higherMemberEntry, LogicAvatarAllianceRole.LEADER, memberEntry.GetAvatarId(), memberEntry.GetName());
                    }
                }

                AllianceEventStreamEntry allianceEventStreamEntry = new AllianceEventStreamEntry();
                AllianceStreamEntryUtil.SetSenderInfo(allianceEventStreamEntry, memberEntry);

                allianceEventStreamEntry.SetEventType(AllianceEventStreamEntryType.LEFT);
                allianceEventStreamEntry.SetEventAvatarId(memberEntry.GetAvatarId());
                allianceEventStreamEntry.SetEventAvatarName(memberEntry.GetName());

                StreamManager.Create(alliance.Id, allianceEventStreamEntry);

                alliance.AddStreamEntry(allianceEventStreamEntry);
                alliance.RemoveMember(this.m_session.AccountId);

                ServerMessageManager.SendMessage(new AllianceLeavedMessage
                {
                    AccountId  = this.m_session.AccountId,
                    AllianceId = alliance.Id
                }, 9);

                AllianceManager.Save(alliance);
            }
        }