Esempio n. 1
0
 /// <summary>
 /// Remember, this is only for server-side.
 /// </summary>
 public static void ChangeOwnershipSmart(this IMyCubeGrid Grid, long NewOwnerID, MyOwnershipShareModeEnum ShareMode)
 {
     if (!MyAPIGateway.Session.IsServer)
     {
         return;
     }
     try
     {
         var Subgrids = Grid.GetAllSubgrids();
         Grid.ChangeGridOwnership(NewOwnerID, ShareMode);
         foreach (IMyCubeGrid Subgrid in Subgrids)
         {
             try
             {
                 Subgrid.ChangeGridOwnership(NewOwnerID, ShareMode);
             }
             catch (Exception Scrap)
             {
                 Grid.LogError("ChangeOwnershipSmart.ChangeSubgridOwnership", Scrap);
             }
         }
     }
     catch (Exception Scrap)
     {
         Grid.LogError("ChangeOwnershipSmart", Scrap);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Remember, this is only for server-side.
 /// </summary>
 public static void ChangeOwnershipSmart(this IMyCubeGrid Grid, long newOwnerId, MyOwnershipShareModeEnum shareMode)
 {
     if (!MyAPIGateway.Session.IsServer)
     {
         return;
     }
     try
     {
         List <IMyCubeGrid> subgrids = Grid.GetAllSubgrids();
         Grid.ChangeGridOwnership(newOwnerId, shareMode);
         foreach (IMyCubeGrid subgrid in subgrids)
         {
             try
             {
                 subgrid.ChangeGridOwnership(newOwnerId, shareMode);
                 try
                 {
                     foreach (IMyProgrammableBlock pb in subgrid.GetTerminalSystem().GetBlocksOfType <IMyProgrammableBlock>())
                     {
                         try
                         {
                             //if (!string.IsNullOrEmpty(pb.ProgramData)) continue;
                             //ShowIngameMessage.ShowOverrideMessage($"PB's recompiling... {subgrid.CustomName}");
                             pb.Recompile();
                         }
                         catch (Exception)
                         {
                             //ShowIngameMessage.ShowOverrideMessage($"Recompiling this pb threw and error: {e.TargetSite} {e} ");
                             //	MyAPIGateway.Utilities.InvokeOnGameThread(() => { pb.Recompile(); });
                         }
                     }
                 }
                 catch (Exception)
                 {
                     //ShowIngameMessage.ShowOverrideMessage($"PB's recompile threw: {e} ");
                 }
             }
             catch (Exception scrap)
             {
                 Grid.LogError("ChangeOwnershipSmart.ChangeSubgridOwnership", scrap);
             }
         }
     }
     catch (Exception scrap)
     {
         Grid.LogError("ChangeOwnershipSmart", scrap);
     }
 }
Esempio n. 3
0
        public void SpawnerCallback(EncounterType encounterType, MySpawnGroupDefinition.SpawnGroupPrefab prefab, Vector3D spawnCoord, Vector3D despawnCoords, IMyFaction ownerFaction)
        {
            Util.Log("Searching for spawned Prefab...");
            IMyCubeGrid      spawnedShip  = null;
            double           minDist      = double.MaxValue;
            BoundingSphereD  searchSphere = new BoundingSphereD(spawnCoord, SPAWNER_SEARCH_RADIUS);
            List <IMyEntity> entityList   = MyAPIGateway.Entities.GetEntitiesInSphere(ref searchSphere);

            foreach (IMyEntity entity in entityList)
            {
                IMyCubeGrid targetGrid = entity as IMyCubeGrid;
                if (targetGrid == null)
                {
                    continue;
                }
                //if (targetGrid.CustomName != prefab.SubtypeId) {
                //continue;
                //}
                if ((targetGrid.GetPosition() - spawnCoord).LengthSquared() < minDist)
                {
                    spawnedShip = targetGrid;
                }
            }
            if (spawnedShip == null)
            {
                Util.Error("Error: Could not find ship " + prefab.SubtypeId + " after spawning.");
                return;
            }
            spawnedShip.ChangeGridOwnership(m_empireData.m_faction.FounderId, MyOwnershipShareModeEnum.None);

            IMyGridTerminalSystem   gts    = spawnedShip.GetTerminalSystem();
            List <IMyRemoteControl> blocks = new List <IMyRemoteControl>();

            gts.GetBlocksOfType(blocks);
            IMyRemoteControl firstRemote = blocks.Find(b => b.IsFunctional);

            LaunchDrone(encounterType, firstRemote, spawnedShip, despawnCoords);
        }
Esempio n. 4
0
 //Changes grid ownership of the drone
 public void SetOwner(long id)
 {
     _ownerId = id;
     _cubeGrid.ChangeGridOwnership(id, MyOwnershipShareModeEnum.Faction);
     _cubeGrid.UpdateOwnership(id, true);
 }
Esempio n. 5
0
        // /admin ownership change name gridId
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Length < 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp( ));
                return(true);
            }

            string              name         = words[0].ToLower( );
            long                playerId     = PlayerMap.Instance.GetPlayerIdsFromSteamId(PlayerMap.Instance.GetSteamIdFromPlayerName(name, true)).First( );
            string              gridId       = words[1].ToLower( );
            long                gridEntityId = 0;
            IMyCubeGrid         grid         = null;
            HashSet <IMyEntity> entities     = new HashSet <IMyEntity>( );
            bool                found        = false;

            if (!long.TryParse(gridId, out gridEntityId))
            {
                Wrapper.GameAction(() =>
                {
                    MyAPIGateway.Entities.GetEntities(entities);
                });
                foreach (IMyEntity entity in entities)
                {
                    if (entity == null)
                    {
                        continue;
                    }

                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    if (entity.DisplayName.ToLower( ) == gridId.ToLower( ))
                    {
                        found = true;
                        grid  = (IMyCubeGrid)entity;
                        break;
                    }
                }
                if (!found)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Could not find entity with name {0}", gridId));
                    return(true);
                }
            }

            if (!found)
            {
                IMyEntity tmpEntity;

                if (!MyAPIGateway.Entities.TryGetEntityById(gridEntityId, out tmpEntity))
                {
                    Communication.SendPrivateInformation(userId, string.Format("Could not find entity with id {0}", gridId));
                    return(true);
                }
                grid = (IMyCubeGrid)tmpEntity;
            }

            if (grid == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("Could not find entity with id {0}.", gridId));
                return(true);
            }
            grid.ChangeGridOwnership(playerId, Sandbox.Common.ObjectBuilders.MyOwnershipShareModeEnum.Faction);
            Communication.SendPrivateInformation(userId, string.Format("Ownership changed to player {0}", name));
            return(true);
        }