Esempio n. 1
0
        public static void RecreateFaction(FactionData data, long requester)
        {
            if (string.IsNullOrEmpty(data?.Tag))
            {
                return;
            }

            IMyFaction current = MyAPIGateway.Session.Factions.TryGetFactionByTag(data.Tag);

            if (current == null)
            {
                MyAPIGateway.Session.Factions.CreateFaction(requester, data.Tag, data.Name, data.Description, data.PrivateInfo);

                IMyFaction current2 = MyAPIGateway.Session.Factions.TryGetFactionByTag(data.Tag);
                MyAPIGateway.Session.Factions.SendJoinRequest(current2.FactionId, requester);
                MyAPIGateway.Session.Factions.AcceptJoin(current2.FactionId, requester);

                return;
            }

            if (current.IsMember(requester))
            {
                return;
            }

            MyAPIGateway.Session.Factions.SendJoinRequest(current.FactionId, requester);
            MyAPIGateway.Session.Factions.AcceptJoin(current.FactionId, requester);
        }
Esempio n. 2
0
        private void SendToFaction(string message, IMyFaction faction, FactionMessageType type)
        {
            var listplayers = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(listplayers);
            foreach (IMyPlayer receiver in listplayers.Where(p => faction.IsMember(p.IdentityId) && p != MyAPIGateway.Session.Player))
            {
                SendFactionMessage(receiver, message, type);
            }
        }
        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;
                    }
                }
            }
        }
 void SendToFaction(string message, IMyFaction plFaction, IMyPlayer Me)
 {
     var listplayers = new List<IMyPlayer>();
     MyAPIGateway.Players.GetPlayers(listplayers);
     IMyPlayer Receiver;
     foreach (IMyPlayer pl in listplayers)
     {
         if (plFaction.IsMember(pl.PlayerID))
         {
             Receiver = pl;
             if (Me.DisplayName != Receiver.DisplayName)
             {
                 if (MyAPIGateway.Players.TryGetPlayer(Receiver.DisplayName, out Receiver))
                 {
                     SendFactionMessage(Receiver, message);
                     break;
                 }
             }
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Returns grid ownership permissions for the player. Access is granted if a grid is unowned
        /// or if at least one big owner is friendly, otherwise, the grid is considered unfriendly.
        /// </summary>
        public static TerminalPermissionStates GetAccessPermissions(this IMyCubeGrid grid, long plyID = -1)
        {
            // Ensure owners are up to date
            grid.UpdateOwnership(0, false);

            if (plyID == -1)
            {
                plyID = MyAPIGateway.Session.LocalHumanPlayer.IdentityId;
            }

            TerminalPermissionStates accessState;
            List <long> bigOwners   = grid.BigOwners;
            bool        gridUnowned = bigOwners.Count == 0;

            if (gridUnowned)
            {
                accessState = TerminalPermissionStates.Granted | TerminalPermissionStates.GridUnowned;
            }
            else
            {
                bool gridFriendly = bigOwners.Contains(plyID);

                if (!gridFriendly)
                {
                    foreach (long owner in bigOwners)
                    {
                        IMyFaction ownerFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(owner);

                        if (ownerFaction != null && (ownerFaction.IsFriendly(plyID) || ownerFaction.IsMember(plyID)))
                        {
                            gridFriendly = true;
                            break;
                        }
                    }
                }

                if (gridFriendly)
                {
                    accessState = TerminalPermissionStates.Granted | TerminalPermissionStates.GridFriendly;
                }
                else
                {
                    accessState = TerminalPermissionStates.Denied | TerminalPermissionStates.GridUnfriendly;
                }
            }

            return(accessState);
        }