Пример #1
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);
        }
Пример #2
0
        public void transmit()
        {
            foreach (MyPlayer p in MySession.Static.Players.GetOnlinePlayers())
            {
                List <IMyGps> playergpsList = MyAPIGateway.Session?.GPS.GetGpsList(p.Identity.IdentityId);

                if (playergpsList == null)
                {
                    break;
                }

                foreach (IMyGps gps in playergpsList)
                {
                    if (gps.Description.Contains("Cronch"))
                    {
                        MyAPIGateway.Session?.GPS.RemoveGps(p.Identity.IdentityId, gps);
                    }
                }
            }
            foreach (var group in MyCubeGridGroups.Static.Logical.Groups)
            {
                bool NPC = false;
                foreach (var item in group.Nodes)
                {
                    MyCubeGrid grid = item.NodeData;
                    // TransmitPlugin.Log.Info(grid.DisplayName);
                    if (((int)grid.Flags & 4) != 0)
                    {
                        //concealed
                        break;
                    }
                    if (grid.IsStatic && !TransmitPlugin.config.broadcastStations)
                    {
                        break;
                    }
                    if (MyGravityProviderSystem.IsPositionInNaturalGravity(grid.PositionComp.GetPosition()) && !TransmitPlugin.config.broadcastInGravity)
                    {
                        break;
                    }

                    //this bit requires a fac utils to get the faction tag, you can remove it if you dont need it
                    foreach (long l in grid.BigOwners)
                    {
                        if (FacUtils.GetFactionTag(l) != null && FacUtils.GetFactionTag(l).Length > 3)
                        {
                            NPC = true;
                        }
                    }

                    if (NPC)
                    {
                        break;
                    }
                    int PCU = 0;
                    PCU = grid.BlocksPCU;
                    Vector3 location = grid.PositionComp.GetPosition();
                    //get the gps
                    float           broadcastRange = 0;
                    MyGpsCollection gpsCollection  = (MyGpsCollection)MyAPIGateway.Session?.GPS;


                    broadcastRange = grid.BlocksPCU * TransmitPlugin.config.meterPerPCU;


                    if (PCU < TransmitPlugin.config.minimumPCU)
                    {
                        break;
                    }
                    IMyFaction gridOwner = FacUtils.GetPlayersFaction(FacUtils.GetOwner(grid));

                    foreach (MyPlayer p in MySession.Static.Players.GetOnlinePlayers())
                    {
                        List <MyGps> gpsList  = new List <MyGps>();
                        float        distance = Vector3.Distance(location, p.GetPosition());
                        if (distance <= broadcastRange)
                        {
                            MyGps gps;
                            //add a new gps point if player is in range
                            if (gridOwner != null)
                            {
                                if (gridOwner.IsNeutral(p.Identity.IdentityId) || gridOwner.IsFriendly(p.Identity.IdentityId))
                                {
                                    gps = CreateGps(grid, Color.RoyalBlue, 60, broadcastRange);
                                }
                                else
                                {
                                    gps = CreateGps(grid, Color.Red, 60, broadcastRange);
                                }
                            }
                            else
                            {
                                gps = CreateGps(grid, Color.Red, 60, broadcastRange);
                            }

                            gpsList.Add(gps);
                        }
                        foreach (MyGps gps in gpsList)
                        {
                            MyGps gpsRef   = gps;
                            long  entityId = 0L;
                            entityId = gps.EntityId;
                            gpsCollection.SendAddGps(p.Identity.IdentityId, ref gpsRef, entityId, TransmitPlugin.config.soundForGPS);
                        }
                    }
                }
            }
        }