private void Factions_FactionStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId)
        {
            if (MySession.Static.LocalHumanPlayer == null)
            {
                return;
            }
            // get player id
            long localPlayerID = MySession.Static.LocalHumanPlayer.Identity.IdentityId;

            // get player faction
            IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalHumanPlayer.Identity.IdentityId);

            if (myFaction == null)
            {
                return;
            }

            if ((myFaction.IsLeader(localPlayerID) || myFaction.IsFounder(localPlayerID)) &&    // is leader or founder
                (myFaction.FactionId == fromFactionId || myFaction.FactionId == toFactionId) && // its our faction in this deal
                action == MyFactionCollection.MyFactionStateChange.AcceptPeace)                 // is it peace?
            {
                NotifyAchieved();
                MySession.Static.Factions.FactionStateChanged -= Factions_FactionStateChanged;
            }
        }
Exemple #2
0
        private void Factions_FactionStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId)
        {
            if (MySession.Static.LocalHumanPlayer == null)
            {
                return;
            }
            // get player id
            long localPlayerID = MySession.Static.LocalHumanPlayer.Identity.IdentityId;

            // get player faction
            IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(localPlayerID);

            if (myFaction == null)
            {
                return;
            }

            // Player declaring war
            if ((myFaction.IsFounder(localPlayerID) || myFaction.IsLeader(localPlayerID)) && // is player leader/fouder of faction
                myFaction.FactionId == fromFactionId &&                                      // is sending war not recieving
                action == MyFactionCollection.MyFactionStateChange.DeclareWar)               // is it war?
            {
                NotifyAchieved();
                MySession.Static.Factions.FactionStateChanged -= Factions_FactionStateChanged;
            }
        }
        private void RefreshUserInfo()
        {
            m_userIsFounder = false;
            m_userIsLeader  = false;
            m_userFaction   = MySession.Static.Factions.TryGetPlayerFaction(MySession.LocalPlayerId);

            if (m_userFaction != null)
            {
                m_userIsFounder = m_userFaction.IsFounder(MySession.LocalPlayerId);
                m_userIsLeader  = m_userFaction.IsLeader(MySession.LocalPlayerId);
            }
        }
        private void RefreshRightSideButtons(MyGuiControlTable.Row selected)
        {
            m_buttonPromote.Enabled    = false;
            m_buttonKick.Enabled       = false;
            m_buttonAcceptJoin.Enabled = false;
            m_buttonDemote.Enabled     = false;

            if (selected != null)
            {
                var data = (MyFactionMember)selected.UserData;
                m_selectedUserId = data.PlayerId;
                var identity = Sync.Players.TryGetIdentity(data.PlayerId);
                m_selectedUserName = identity.DisplayName;

                if (m_selectedUserId != MySession.LocalPlayerId)
                {
                    if (m_userIsFounder && m_userFaction.IsLeader(m_selectedUserId))
                    {
                        m_buttonKick.Enabled   = true;
                        m_buttonDemote.Enabled = true;
                    }
                    else if (m_userIsFounder && m_userFaction.IsMember(m_selectedUserId))
                    {
                        m_buttonKick.Enabled    = true;
                        m_buttonPromote.Enabled = true;
                    }
                    else if (m_userIsLeader &&
                             m_userFaction.IsMember(m_selectedUserId) &&
                             !m_userFaction.IsLeader(m_selectedUserId) &&
                             !m_userFaction.IsFounder(m_selectedUserId))
                    {
                        m_buttonKick.Enabled = true;
                    }
                    else if ((m_userIsLeader || m_userIsFounder) && m_userFaction.JoinRequests.ContainsKey(m_selectedUserId))
                    {
                        m_buttonAcceptJoin.Enabled = true;
                    }
                }
            }
        }
        private void RefreshTableMembers()
        {
            m_tableMembers.Clear();

            foreach (var entry in m_selectedFaction.Members)
            {
                var member = entry.Value;

                var identity = Sync.Players.TryGetIdentity(member.PlayerId);
                System.Diagnostics.Debug.Assert(identity != null, "Faction member is not known identity!");
                if (identity == null)
                {
                    continue;
                }

                var   row        = new MyGuiControlTable.Row(member);
                var   compare    = MyMemberComparerEnum.Member;
                var   statusEnum = MySpaceTexts.Member;
                Color?txtColor   = null;

                if (m_selectedFaction.IsFounder(member.PlayerId))
                {
                    compare    = MyMemberComparerEnum.Founder;
                    statusEnum = MySpaceTexts.Founder;
                }
                else if (m_selectedFaction.IsLeader(member.PlayerId))
                {
                    compare    = MyMemberComparerEnum.Leader;
                    statusEnum = MySpaceTexts.Leader;
                }
                else if (m_selectedFaction.JoinRequests.ContainsKey(member.PlayerId))
                {
                    txtColor   = COLOR_CUSTOM_GREY;
                    compare    = MyMemberComparerEnum.Applicant;
                    statusEnum = MySpaceTexts.Applicant;
                }

                row.AddCell(new MyGuiControlTable.Cell(text:    new StringBuilder(identity.DisplayName),
                                                       toolTip: identity.DisplayName,
                                                       userData: entry, textColor: txtColor));
                row.AddCell(new MyGuiControlTable.Cell(text: MyTexts.Get(statusEnum), userData: compare, textColor: txtColor));
                m_tableMembers.Add(row);
            }

            foreach (var entry in m_selectedFaction.JoinRequests)
            {
                var request = entry.Value;
                var row     = new MyGuiControlTable.Row(request);

                var identity = Sync.Players.TryGetIdentity(request.PlayerId);
                System.Diagnostics.Debug.Assert(identity != null, "Player is not in allplayers list!");
                if (identity != null)
                {
                    row.AddCell(new MyGuiControlTable.Cell(text: new StringBuilder(identity.DisplayName),
                                                           toolTip: identity.DisplayName,
                                                           userData: entry, textColor: COLOR_CUSTOM_GREY));

                    row.AddCell(new MyGuiControlTable.Cell(text: MyTexts.Get(MySpaceTexts.Applicant),
                                                           userData: MyMemberComparerEnum.Applicant,
                                                           textColor: COLOR_CUSTOM_GREY));
                    m_tableMembers.Add(row);
                }
            }
        }
        private void RefreshUserInfo()
        {
            m_userIsFounder = false;
            m_userIsLeader  = false;
            m_userFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId);

            if (m_userFaction != null)
            {
                m_userIsFounder = m_userFaction.IsFounder(MySession.Static.LocalPlayerId);
                m_userIsLeader = m_userFaction.IsLeader(MySession.Static.LocalPlayerId);
            }
        }