示例#1
0
        private void DeleteUploadedGrids(MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group relevantGroup)
        {
            foreach (var node in relevantGroup.Nodes)
            {
                MyCubeGrid grid = node.NodeData;

                /* We wanna Skip Projections... always */
                if (grid.Physics == null)
                {
                    continue;
                }

                grid.Close();
            }
        }
示例#2
0
 public void Close()
 {
     // Closing stuff happens here
     if (_isClosed)
     {
         return;
     }
     _isClosed = true;
     WriteToLog($"Close", $"Oh, bye! {_thisCubeGrid.DisplayName} | {_gridType} | {_ownerType} | Closed for: {_closeReason} | Grid Info: {_lastPassInformation}", LogType.General);
     _thisCubeGrid.OnClose -= Close;
     _thisCubeGrid.OnBlockOwnershipChanged -= OwnershipChanged;
     _thisCubeGrid.OnBlockAdded            -= BlockCountChanged;
     _thisCubeGrid.OnBlockRemoved          -= BlockCountChanged;
     _thisCubeGrid.OnGridSplit             -= GridSplit;
     OnClose?.Invoke(ThisId);
     _thisCubeGrid.Close();
 }
示例#3
0
        public static MyObjectBuilder_CubeGrid ConvertFracturedBlocksToComponents(MyObjectBuilder_CubeGrid gridBuilder)
        {
            bool flag = false;

            using (List <MyObjectBuilder_CubeBlock> .Enumerator enumerator = gridBuilder.CubeBlocks.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current is MyObjectBuilder_FracturedBlock)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag)
            {
                return(gridBuilder);
            }
            bool enableSmallToLargeConnections = gridBuilder.EnableSmallToLargeConnections;

            gridBuilder.EnableSmallToLargeConnections = false;
            bool createPhysics = gridBuilder.CreatePhysics;

            gridBuilder.CreatePhysics = true;
            MyCubeGrid grid = Sandbox.Game.Entities.MyEntities.CreateFromObjectBuilder(gridBuilder, false) as MyCubeGrid;

            if (grid == null)
            {
                return(gridBuilder);
            }
            grid.ConvertFracturedBlocksToComponents();
            gridBuilder.EnableSmallToLargeConnections = enableSmallToLargeConnections;
            MyObjectBuilder_CubeGrid objectBuilder = (MyObjectBuilder_CubeGrid)grid.GetObjectBuilder(false);

            objectBuilder.EnableSmallToLargeConnections = enableSmallToLargeConnections;
            gridBuilder.CreatePhysics   = createPhysics;
            objectBuilder.CreatePhysics = createPhysics;
            grid.Close();
            Sandbox.Game.Entities.MyEntities.RemapObjectBuilder(objectBuilder);
            return(objectBuilder);
        }
        public override void BeforeStart()
        {
            base.BeforeStart();

            MyFaction pirateFaction = MySession.Static.Factions.TryGetFactionByTag(PIRATE_FACTION_TAG);

            Debug.Assert(pirateFaction != null, "No pirate faction in the world. Pirate antenan needs it.");

            if (pirateFaction != null)
            {
                // Make sure that the pirate identity exists
                if (m_piratesIdentityId != 0)
                {
                    if (Sync.IsServer)
                    {
                        MyIdentity pirateIdentity = Sync.Players.TryGetIdentity(m_piratesIdentityId);
                        Debug.Assert(pirateIdentity != null, "The pirate identity does not exist, although its ID was saved!");

                        if (pirateIdentity == null)
                        {
                            Sync.Players.CreateNewIdentity(IDENTITY_NAME, m_piratesIdentityId, null);
                        }

                        pirateIdentity.LastLoginTime = DateTime.Now;

                        // Check if he is already in a faction.
                        MyFaction oldPirateFaction = MySession.Static.Factions.GetPlayerFaction(m_piratesIdentityId);
                        if (oldPirateFaction == null)
                        {
                            MyFactionCollection.SendJoinRequest(pirateFaction.FactionId, m_piratesIdentityId);
                        }
                    }
                }
                else
                {
                    m_piratesIdentityId = pirateFaction.FounderId;
                }

                if (!Sync.Players.IdentityIsNpc(m_piratesIdentityId))
                {
                    Sync.Players.MarkIdentityAsNPC(m_piratesIdentityId);
                }
            }

            // Make sure that all the drone entities exist
            foreach (var drone in m_droneInfos)
            {
                MyEntity entity;
                MyEntities.TryGetEntityById(drone.Key, out entity);
                if (entity == null)
                {
                    DroneInfo.Deallocate(drone.Value);
                    m_droneInfos.Remove(drone.Key);
                }
                else
                {
                    if (!MySession.Static.Settings.EnableDrones)
                    {
                        MyCubeGrid grid   = entity as MyCubeGrid;
                        var        remote = entity as MyRemoteControl;
                        if (grid == null)
                        {
                            grid = remote.CubeGrid;
                        }

                        UnregisterDrone(entity, immediate: false);
                        grid.Close();
                        //grid.SyncObject.SendCloseRequest();
                    }
                    else
                    {
                        RegisterDrone(drone.Value.AntennaEntityId, entity, immediate: false);
                    }
                }
            }
            m_droneInfos.ApplyRemovals();
        }
示例#5
0
        public void Sell(string price, string name)
        {
            if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition()))
            {
                Context.Respond("You cannot use this command in natural gravity!");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }

            foreach (DeniedLocation denied in AlliancePlugin.HangarDeniedLocations)
            {
                if (Vector3.Distance(Context.Player.GetPosition(), new Vector3(denied.x, denied.y, denied.z)) <= denied.radius)
                {
                    Context.Respond("Cannot sell here, too close to a denied location.");
                    confirmations.Remove(Context.Player.IdentityId);
                    return;
                }
            }
            Int64 amount;

            price = price.Replace(",", "");
            price = price.Replace(".", "");
            price = price.Replace(" ", "");
            try
            {
                amount = Int64.Parse(price);
            }
            catch (Exception)
            {
                Context.Respond("Error parsing amount", Color.Red, "Bank Man");
                return;
            }
            if (amount < 0 || amount == 0)
            {
                Context.Respond("Must be a positive amount", Color.Red, "Bank Man");
                return;
            }
            ConcurrentBag <MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Group> gridWithSubGrids = GridFinder.FindLookAtGridGroupMechanical(Context.Player.Character);

            List <MyCubeGrid> grids = new List <MyCubeGrid>();


            foreach (var item1 in gridWithSubGrids)
            {
                foreach (MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Node groupNodes in item1.Nodes)
                {
                    MyCubeGrid grid = groupNodes.NodeData;

                    if (FacUtils.IsOwnerOrFactionOwned(grid, Context.Player.IdentityId, false))
                    {
                        if (!grids.Contains(grid))
                        {
                            foreach (MySurvivalKit block in grid.GetFatBlocks().OfType <MySurvivalKit>())
                            {
                                block.CustomData = "Custom Data was cleared.";
                            }
                            foreach (MyMedicalRoom block in grid.GetFatBlocks().OfType <MyMedicalRoom>())
                            {
                                block.CustomData = "Custom Data was cleared.";
                            }
                            List <MyProgrammableBlock> removeThese = new List <MyProgrammableBlock>();
                            foreach (MyProgrammableBlock block in grid.GetFatBlocks().OfType <MyProgrammableBlock>())
                            {
                                removeThese.Add(block);
                            }
                            foreach (MyProgrammableBlock block in removeThese)
                            {
                                grid.RemoveBlock(block.SlimBlock);
                            }
                            grids.Add(grid);
                        }
                    }
                }
            }
            if (grids.Count == 0)
            {
                Context.Respond("Could not find any grids you own. Are you looking directly at it?");
                return;
            }
            MarketItem item = new MarketItem();

            item.Setup(grids, name, amount, Context.Player.SteamUserId);
            if (list.AddItem(item))
            {
                if (GridManager.SaveGridNoDelete(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml", item.ItemId.ToString(), false, false, grids))
                {
                    Context.Respond("Added the item to the market!");

                    utils.WriteToJsonFile <MarketItem>(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json", item);
                    foreach (MyCubeGrid grid in grids)
                    {
                        if (grid != null)
                        {
                            grid.Close();
                        }
                    }
                }
            }
            else
            {
                Context.Respond("Failed to add the grid to the market. Try again.");
            }
        }
        public void SaveToHangar()
        {
            if (!AlliancePlugin.config.HangarEnabled)
            {
                Context.Respond("Alliance hangar is not enabled.");
                return;
            }
            if (MySession.Static.IsSaveInProgress)
            {
                Context.Respond("World is saving! Try again soon.");
                return;
            }
            if (cooldowns.TryGetValue(Context.Player.IdentityId, out DateTime value))
            {
                if (DateTime.Now <= value)
                {
                    Context.Respond(GetCooldownMessage(value));
                    return;
                }
                else
                {
                    cooldowns[Context.Player.IdentityId] = DateTime.Now.AddSeconds(60);
                }
            }
            else
            {
                cooldowns.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(60));
            }
            if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition()))
            {
                Context.Respond("You cannot use this command in natural gravity!");
                return;
            }

            foreach (DeniedLocation denied in AlliancePlugin.HangarDeniedLocations)
            {
                if (Vector3.Distance(Context.Player.GetPosition(), new Vector3(denied.x, denied.y, denied.z)) <= denied.radius)
                {
                    Context.Respond("Cannot hangar here! Too close to a denied location.");
                    return;
                }
            }
            Boolean console = false;

            if (Context.Player == null)
            {
                console = true;
            }
            MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId);

            if (fac == null)
            {
                Context.Respond("You must be in a faction to use alliance features.");
                return;
            }
            Alliance alliance = AlliancePlugin.GetAlliance(fac);

            if (alliance == null)
            {
                Context.Respond("You are not a member of an alliance.");
                return;
            }
            if (AlliancePlugin.HasFailedUpkeep(alliance))
            {
                Context.Respond("Alliance failed to pay upkeep. Upgrades disabled.");
                return;
            }
            if (!alliance.HasAccess(Context.Player.SteamUserId, AccessLevel.HangarSave))
            {
                Context.Respond("Current rank does not have access to hangar save.");
                return;
            }
            if (alliance.hasUnlockedHangar)
            {
                HangarData hangar = alliance.LoadHangar();
                if (hangar == null)
                {
                    Context.Respond("Error loading the hangar.");
                    return;
                }
                string name = "";
                int    pcu  = 0;
                if (hangar.getAvailableSlot() > 0)
                {
                    ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> gridWithSubGrids = GridFinder.FindLookAtGridGroup(Context.Player.Character);
                    List <MyCubeGrid> grids = new List <MyCubeGrid>();
                    foreach (var item in gridWithSubGrids)
                    {
                        foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in item.Nodes)
                        {
                            MyCubeGrid grid = groupNodes.NodeData;



                            if (grid.Projector != null)
                            {
                                continue;
                            }
                            if (FacUtils.IsOwnerOrFactionOwned(grid, Context.Player.IdentityId, true))
                            {
                                pcu += grid.BlocksPCU;
                                foreach (MyProjectorBase proj in grid.GetFatBlocks().OfType <MyProjectorBase>())
                                {
                                    proj.Clipboard.Clear();
                                }
                                grids.Add(grid);

                                if (name == "")
                                {
                                    name = grid.DisplayName;
                                    name = name.Replace("/", "");
                                    name = name.Replace("-", "");
                                    name = name.Replace("\\", "");
                                }
                            }
                            else
                            {
                                Context.Respond("The grid you are looking at includes a grid that isnt owned by you or a faction member.");
                                return;
                            }
                        }
                    }
                    if (grids.Count == 0)
                    {
                        Context.Respond("Could not find grid.");
                        return;
                    }
                    if (name == "")
                    {
                        name = "Temporary Name";
                    }
                    if (pcu >= AlliancePlugin.config.MaxHangarSlotPCU)
                    {
                        Context.Respond("PCU is greater than the configured maximum");
                        return;
                    }
                    bool result = hangar.SaveGridToHangar(name + "_" + string.Format("{0:yyyy-MM-dd_HH-mm-ss-fff}", DateTime.Now), Context.Player.SteamUserId, alliance, Context.Player.Character.PositionComp.GetPosition(), fac, grids, Context.Player.IdentityId);
                    if (!result)
                    {
                        Context.Respond("Could not save. Are enemies within 15km?");
                    }
                    else
                    {
                        Context.Respond("Grid saved.");

                        foreach (MyCubeGrid grid in grids)
                        {
                            if (grid != null)
                            {
                                grid.Close();
                            }
                        }
                    }
                }
                else
                {
                    Context.Respond("Hangar is full, to upgrade use !ah upgrade true.");
                }
            }
            else
            {
                Context.Respond("Alliance has not unlocked the hangar to unlock use !ah unlock.");
            }
        }