void Factions_FactionStateChanged(MyFactionCollection.MyFactionStateChange change, long fromFactionId, long toFactionId, long playerId, long sender)
 {
     if (change == MyFactionCollection.MyFactionStateChange.RemoveFaction)
     {
         DeleteEmptyFactionChat(fromFactionId);
     }
     if (change == MyFactionCollection.MyFactionStateChange.FactionMemberLeave || change == MyFactionCollection.MyFactionStateChange.FactionMemberKick)
     {
         DeletePendingFactionChat(fromFactionId, playerId);
     }
 }
        private void OnMemberStateChanged(MyFactionCollection.MyFactionStateChange action, IMyFaction fromFaction, long playerId)
        {
            var identity = Sync.Players.TryGetIdentity(playerId);
            System.Diagnostics.Debug.Assert(identity != null, "Identity does not exist!");
            if (identity == null)
            {
                MyLog.Default.WriteLine("ERROR: Faction " + fromFaction.Name + " member " + playerId + " does not exists! ");
                return;
            }

            RemoveMember(playerId);

            switch (action)
            {
                case MyFactionCollection.MyFactionStateChange.FactionMemberPromote:
                    AddMember(playerId, identity.DisplayName, true,  MyMemberComparerEnum.Leader, MyCommonTexts.Leader);
                    break;

                case MyFactionCollection.MyFactionStateChange.FactionMemberCancelJoin:
                case MyFactionCollection.MyFactionStateChange.FactionMemberLeave:
                case MyFactionCollection.MyFactionStateChange.FactionMemberKick: break;

                case MyFactionCollection.MyFactionStateChange.FactionMemberAcceptJoin:
                case MyFactionCollection.MyFactionStateChange.FactionMemberDemote:
                    AddMember(playerId, identity.DisplayName, false, MyMemberComparerEnum.Member, MyCommonTexts.Member);
                    break;

                case MyFactionCollection.MyFactionStateChange.FactionMemberSendJoin:
                    AddMember(playerId, identity.DisplayName, false, MyMemberComparerEnum.Applicant, MyCommonTexts.Applicant, COLOR_CUSTOM_GREY);
                    break;
            }
            RefreshUserInfo();
            RefreshTableFactions();
            m_tableMembers.Sort(false);
        }
        void OnFactionsStateChanged(MyFactionCollection.MyFactionStateChange change, long fromFactionId, long toFactionId, long playerId, long sender)
        {
            if (change == MyFactionCollection.MyFactionStateChange.FactionMemberKick && sender != playerId && LocalPlayerId == playerId)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionKicked),
                    messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextYouHaveBeenKickedFromFaction)));
            }

            if (change == MyFactionCollection.MyFactionStateChange.FactionMemberAcceptJoin && sender != playerId && LocalPlayerId == playerId && !Battle)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionInfo),
                    messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextYouHaveBeenAcceptedToFaction)));
            }

            if (change == MyFactionCollection.MyFactionStateChange.FactionMemberAcceptJoin && (Static.Factions[toFactionId].IsFounder(LocalPlayerId) || Static.Factions[toFactionId].IsLeader(LocalPlayerId)) && playerId != 0)
            {
                var identity = Sync.Players.TryGetIdentity(playerId);
                if (identity != null)
                {
                    var joiningName = identity.DisplayName;
                    var notification = new MyHudNotificationDebug("Player \"" + joiningName + "\" has joined your faction.", 2500);
                    MyHud.Notifications.Add(notification);
                }
            }

            if (change == MyFactionCollection.MyFactionStateChange.FactionMemberLeave && (Static.Factions[toFactionId].IsFounder(LocalPlayerId) || Static.Factions[toFactionId].IsLeader(LocalPlayerId)) && playerId != 0)
            {
                var identity = Sync.Players.TryGetIdentity(playerId);
                if (identity != null)
                {
                    var joiningName = identity.DisplayName;
                    var notification = new MyHudNotificationDebug("Player \"" + joiningName + "\" has left your faction.", 2500);
                    MyHud.Notifications.Add(notification);
                }
            }

            if (change == MyFactionCollection.MyFactionStateChange.FactionMemberSendJoin && (Static.Factions[toFactionId].IsFounder(LocalPlayerId) || Static.Factions[toFactionId].IsLeader(LocalPlayerId)) && playerId != 0)
            {
                var identity = Sync.Players.TryGetIdentity(playerId);
                if (identity != null)
                {
                    var joiningName = identity.DisplayName;
                    var notification = new MyHudNotificationDebug("Player \"" + joiningName + "\" has applied to join your faction.", 2500);
                    MyHud.Notifications.Add(notification);
                }
            }
        }
        private void OnFactionsStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId)
        {
            System.Diagnostics.Debug.Assert(MySession.Static != null);
            if (MySession.Static == null)
                return;

            System.Diagnostics.Debug.Assert(MySession.Static.Factions != null);
            if (MySession.Static.Factions == null)
                return;

            System.Diagnostics.Debug.Assert(m_tableFactions != null);
            if (m_tableFactions == null)
                return;

            var fromFaction = MySession.Static.Factions.TryGetFactionById(fromFactionId);
            var toFaction   = MySession.Static.Factions.TryGetFactionById(toFactionId);

            switch (action)
            {
                case MyFactionCollection.MyFactionStateChange.SendPeaceRequest:
                    {
                        System.Diagnostics.Debug.Assert(m_userFaction != null);
                        if (m_userFaction == null)
                            return;

                        if (m_userFaction.FactionId == fromFactionId)
                        {
                            RemoveFaction(toFactionId);
                            AddFaction(toFaction, COLOR_CUSTOM_RED, MyGuiConstants.TEXTURE_ICON_SENT_WHITE_FLAG, MyTexts.GetString(MySpaceTexts.TerminalTab_Factions_SentPeace));
                        }
                        else if (m_userFaction.FactionId == toFactionId)
                        {
                            RemoveFaction(fromFactionId);
                            AddFaction(fromFaction, COLOR_CUSTOM_RED, MyGuiConstants.TEXTURE_ICON_WHITE_FLAG, MyTexts.GetString(MySpaceTexts.TerminalTab_Factions_PendingPeace));
                        }
                        break;
                    }

                case MyFactionCollection.MyFactionStateChange.AcceptPeace:
                    {
                        System.Diagnostics.Debug.Assert(m_userFaction != null);
                        if (m_userFaction == null)
                            return;

                        if (m_userFaction.FactionId == fromFactionId)
                        {
                            RemoveFaction(toFactionId);
                            AddFaction(toFaction);
                        }
                        else if (m_userFaction.FactionId == toFactionId)
                        {
                            RemoveFaction(fromFactionId);
                            AddFaction(fromFaction);
                        }
                        break;
                    }

                case MyFactionCollection.MyFactionStateChange.CancelPeaceRequest:
                case MyFactionCollection.MyFactionStateChange.DeclareWar:
                    {
                        if (m_userFaction == null)
                            return;

                        if (m_userFaction.FactionId == fromFactionId)
                        {
                            RemoveFaction(toFactionId);
                            AddFaction(toFaction, COLOR_CUSTOM_RED);
                        }
                        else if (m_userFaction.FactionId == toFactionId)
                        {
                            RemoveFaction(fromFactionId);
                            AddFaction(fromFaction, COLOR_CUSTOM_RED);
                        }
                        break;
                    }

                case MyFactionCollection.MyFactionStateChange.RemoveFaction:
                    RemoveFaction(toFactionId);
                    break;

                default:
                    OnMemberStateChanged(action, fromFaction, playerId);
                    break;
            }
            m_tableFactions.Sort(false);
            m_tableFactions.SelectedRowIndex = m_tableFactions.FindIndex((row) => ((MyFaction)row.UserData).FactionId == toFactionId);
            OnFactionsTableItemSelected(m_tableFactions, new Sandbox.Graphics.GUI.MyGuiControlTable.EventArgs());
            Refresh();
        }
 private void OnFactionStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId)
 {
     Refresh();
 }