Beispiel #1
0
        /// <summary>
        /// Checks whether a grid is owned only by one faction
        /// If a single block is owned by another player, returns false
        /// </summary>
        /// <param name="grid">Grid to check</param>
        /// <returns></returns>
        public static bool ownedBySingleFaction(this IMyCubeGrid grid)
        {
            // No one owns the grid
            if (grid.BigOwners.Count == 0)
            {
                return(false);
            }

            // Guaranteed to have at least 1 owner after previous check
            IMyFactionCollection facs = MyAPIGateway.Session.Factions;
            IMyFaction           fac  = facs.TryGetPlayerFaction(grid.BigOwners[0]);

            // Test big owners
            for (int i = 1; i < grid.BigOwners.Count; ++i)
            {
                IMyFaction newF = facs.TryGetPlayerFaction(grid.BigOwners[i]);
                if (newF != fac)
                {
                    return(false);
                }
            }

            // Test small owners
            for (int i = 0; i < grid.SmallOwners.Count; ++i)
            {
                IMyFaction newF = facs.TryGetPlayerFaction(grid.SmallOwners[i]);
                if (newF != fac)
                {
                    return(false);
                }
            }

            // Didn't encounter any factions different from the BigOwner[0] faction
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Is the given player allowed get information or use commands on the grid?
        /// Player is able to interact with the grid if the player is part of a specific
        /// block's faction OR the player owns the block
        /// The block is dependent on the CommandsRequireClassifier setting
        /// </summary>
        /// <param name="playerID"></param>
        /// <param name="grid"></param>
        /// <returns></returns>
        public static bool canInteractWith(this IMyCubeGrid grid, long playerID, HullClassifier bestClassifier = null)
        {
            IMyCubeBlock blockToCheck;

            // Get the type of block to check based on settings
            if (Core.ConquestSettings.getInstance().SimpleOwnership)
            {
                if (bestClassifier != null)
                {
                    blockToCheck = bestClassifier.FatBlock;
                }
                else
                {
                    blockToCheck = grid.getFirstClassifierBlock();
                }
            }
            else
            {
                blockToCheck = grid.getMainCockpit();
            }

            if (blockToCheck != null)
            {
                MyRelationsBetweenPlayerAndBlock relationship = blockToCheck.GetUserRelationToOwner(playerID);
                if (relationship == MyRelationsBetweenPlayerAndBlock.NoOwnership || relationship == MyRelationsBetweenPlayerAndBlock.Enemies)
                {
                    return(false);
                }
                else if (relationship == MyRelationsBetweenPlayerAndBlock.FactionShare || relationship == MyRelationsBetweenPlayerAndBlock.Owner)
                {
                    return(true);
                }
                // Being in a faction doesn't necessarily mean FactionShare, so need to check for faction status
                else
                {
                    IMyFactionCollection factions      = MyAPIGateway.Session.Factions;
                    IMyFaction           blocksFaction = factions.TryGetPlayerFaction(blockToCheck.OwnerId);

                    // Block is either owned by friendly faction or user's faction
                    if (blocksFaction != null)
                    {
                        long owningFactionID = blocksFaction.FactionId;
                        if (owningFactionID == factions.TryGetPlayerFaction(playerID).FactionId)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        public static List <IMyFaction> GetFactions(this IMyFactionCollection FactionCollection)
        {
            List <IMyFaction> AllFactions = new List <IMyFaction>();

            foreach (var FactionBuilder in FactionCollection.GetObjectBuilder().Factions)
            {
                IMyFaction Faction = null;
                Faction = FactionCollection.TryGetFactionById(FactionBuilder.FactionId);
                if (Faction != null)
                {
                    AllFactions.Add(Faction);
                }
            }

            return(AllFactions);
        }