Beispiel #1
0
        public void FormatGridName(GridStamp result)
        {
            try
            {
                result.GridName = FileSaver.CheckInvalidCharacters(result.GridName);
                // Log.Warn("Running GridName Checks: {" + GridName + "} :" + Test);

                if (AnyGridsMatch(result.GridName))
                {
                    //There is already a grid with that name!
                    bool NameCheckDone = false;
                    int  a             = 1;
                    while (!NameCheckDone)
                    {
                        if (AnyGridsMatch(result.GridName + "[" + a + "]"))
                        {
                            a++;
                        }
                        else
                        {
                            //Hangar.Debug("Name check done! " + a);
                            NameCheckDone = true;
                            break;
                        }
                    }
                    //Main.Debug("Saving grid name: " + GridName);
                    result.GridName = result.GridName + "[" + a + "]";
                }
            }
            catch (Exception e)
            {
                Log.Warn(e);
            }
        }
        public void SaveGrid(string NameOrIdentity = "")
        {
            GridResult Result = new GridResult(true);



            //Gets grids player is looking at
            if (!Result.GetGrids(Chat, AdminUserCharacter, NameOrIdentity))
            {
                return;
            }

            GridStamp stamp = Result.GenerateGridStamp();


            PlayerHangar PlayersHanger = new PlayerHangar(Result.OwnerSteamID, Chat, true);


            GridUtilities.FormatGridName(PlayersHanger, stamp);
            if (PlayersHanger.SaveGridsToFile(Result, stamp.GridName))
            {
                PlayersHanger.SaveGridStamp(stamp, true);
                Chat?.Respond("Save Complete!");
            }
            else
            {
                Chat?.Respond("Saved Failed!");
                return;
            }
        }
Beispiel #3
0
        public static bool TransferGrid(PlayerInfo To, GridStamp Stamp)
        {
            try
            {
                string GridName = Stamp.GridName;
                To.FormatGridName(Stamp);

                //Make sure to create the directory!
                Directory.CreateDirectory(To.PlayerFolderPath);

                File.Copy(Stamp.OriginalGridPath, Path.Combine(To.PlayerFolderPath, Stamp.GridName + ".sbc"));
                Stamp.Transfered();

                To.ServerOfferPurchased(GridName);

                To.Grids.Add(Stamp);
                To.SaveFile();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        public bool CheckLimits(GridStamp Grid, IEnumerable <MyObjectBuilder_CubeGrid> Blueprint)
        {
            if (CheckGridLimits(Grid) == false || BlockLimitChecker(Blueprint) == false)
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public void DetailedReport(int ID)
        {
            StringBuilder Response = new StringBuilder();
            string        Prefix   = "";

            if (ID == 0)
            {
                Prefix = $"HangarSlots: { SelectedPlayerFile.Grids.Count()}/{ MaxHangarSlots}";
                Response.AppendLine("- - Global Limits - -");
                Response.AppendLine($"TotalBlocks: {SelectedPlayerFile.TotalBlocks}/{ Config.TotalMaxBlocks}");
                Response.AppendLine($"TotalPCU: {SelectedPlayerFile.TotalPCU}/{ Config.TotalMaxPCU}");
                Response.AppendLine($"StaticGrids: {SelectedPlayerFile.StaticGrids}/{ Config.TotalMaxStaticGrids}");
                Response.AppendLine($"LargeGrids: {SelectedPlayerFile.LargeGrids}/{ Config.TotalMaxLargeGrids}");
                Response.AppendLine($"SmallGrids: {SelectedPlayerFile.SmallGrids}/{ Config.TotalMaxSmallGrids}");
                Response.AppendLine();
                Response.AppendLine("- - Individual Hangar Slots - -");
                for (int i = 0; i < SelectedPlayerFile.Grids.Count; i++)
                {
                    GridStamp Stamp = SelectedPlayerFile.Grids[i];
                    Response.AppendLine($" * * Slot {i + 1} : {Stamp.GridName} * *");
                    Response.AppendLine($"PCU: {Stamp.GridPCU}/{Config.SingleMaxPCU}");
                    Response.AppendLine($"Blocks: {Stamp.NumberofBlocks}/{Config.SingleMaxBlocks}");
                    Response.AppendLine($"StaticGrids: {Stamp.StaticGrids}/{Config.SingleMaxStaticGrids}");
                    Response.AppendLine($"LargeGrids: {Stamp.LargeGrids}/{Config.SingleMaxLargeGrids}");
                    Response.AppendLine($"SmallGrids: {Stamp.SmallGrids}/{Config.SingleMaxSmallGrids}");
                    Response.AppendLine($"TotalGridCount: {Stamp.NumberOfGrids}");
                    Response.AppendLine($"Mass: {Stamp.GridMass}kg");
                    Response.AppendLine($"Built%: {Stamp.GridBuiltPercent * 100}%");
                    Response.AppendLine($" * * * * * * * * * * * * * * * * ");
                    Response.AppendLine();
                }
            }
            else
            {
                if (!IsInputValid(ID - 1))
                {
                    return;
                }


                GridStamp Stamp = SelectedPlayerFile.Grids[ID - 1];
                Prefix = $"Slot {ID} : {Stamp.GridName}";
                Response.AppendLine($"PCU: {Stamp.GridPCU}/{Config.SingleMaxPCU}");
                Response.AppendLine($"Blocks: {Stamp.NumberofBlocks}/{Config.SingleMaxBlocks}");
                Response.AppendLine($"StaticGrids: {Stamp.StaticGrids}/{Config.SingleMaxStaticGrids}");
                Response.AppendLine($"LargeGrids: {Stamp.LargeGrids}/{Config.SingleMaxLargeGrids}");
                Response.AppendLine($"SmallGrids: {Stamp.SmallGrids}/{Config.SingleMaxSmallGrids}");
                Response.AppendLine($"TotalGridCount: {Stamp.NumberOfGrids}");
                Response.AppendLine($"Mass: {Stamp.GridMass}kg");
                Response.AppendLine($"Built%: {Stamp.GridBuiltPercent * 100}%");
                Response.AppendLine();
            }

            ModCommunication.SendMessageTo(new DialogMessage("Hangar Info", Prefix, Response.ToString()), SteamID);
            //Chat.Respond(Response.ToString());
        }
        public bool SaveGrids(GridResult Grids, GridStamp Stamp)
        {
            List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>();

            foreach (MyCubeGrid grid in Grids.Grids)
            {
                /* Remove characters from cockpits */
                Action P = delegate
                {
                    foreach (var blck in grid.GetFatBlocks().OfType <MyCockpit>())
                    {
                        if (blck.Pilot != null)
                        {
                            blck.RemovePilot();
                        }
                    }
                };

                Task KickPlayers = GameEvents.InvokeActionAsync(P);
                KickPlayers.Wait(5000);


                /* What else should it be? LOL? */
                if (!(grid.GetObjectBuilder() is MyObjectBuilder_CubeGrid objectBuilder))
                {
                    throw new ArgumentException(grid + " has a ObjectBuilder thats not for a CubeGrid");
                }

                objectBuilders.Add(objectBuilder);
            }



            try
            {
                //Need To check grid name

                string GridSavePath = Path.Combine(FolderPath, Stamp.GridName + ".sbc");

                //Log.Info("SavedDir: " + pathForPlayer);
                bool saved = SaveGridToFile(GridSavePath, Stamp.GridName, objectBuilders);

                if (saved)
                {
                    DisposeGrids(Grids.Grids);
                }


                return(saved);
            }
            catch (Exception e)
            {
                //Hangar.Debug("Saving Grid Failed!", e, Hangar.ErrorType.Fatal);
                return(false);
            }
        }
Beispiel #7
0
        public bool TryGetGridStamp(int ID, out GridStamp Stamp)
        {
            if (!SelectedPlayerFile.GetGrid(ID, out Stamp, out string Error))
            {
                Chat.Respond(Error);
                return(false);
            }

            return(true);
        }
Beispiel #8
0
 public bool IsGridForSale(GridStamp Grid, bool Admin = false)
 {
     if (Grid.GridForSale)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #9
0
        public void HangarUpdate(ulong SteamID, bool Saving, GridStamp Stamp)
        {
            //Need to check if this item already exists

            return;

            KeyValuePair <bool, GridStamp> KPair = new KeyValuePair <bool, GridStamp>(Saving, Stamp);

            if (Grids.TrackedGrids.ContainsKey(SteamID))
            {
                Log.Warn("Current GRIDID: " + Stamp.GridID);
                int?Index = Grids.TrackedGrids[SteamID].FindIndex(x => x.Value.GridID == KPair.Value.GridID);
                // Log.Warn("Attempting to Updated GridTracker A! " + KPair.Value.GridName);
                if (Index.HasValue && Index != -1)
                {
                    Log.Warn("Index: " + Index.Value);
                    Grids.TrackedGrids[SteamID].RemoveAt(Index.Value);
                    Log.Warn("Found exsisting gridID in GridTracker! Removing");
                }
                Grids.TrackedGrids[SteamID].Add(KPair);
            }
            else
            {
                //Log.Warn("Attempting to Updated GridTracker B! " + KPair.Value.GridName);
                List <KeyValuePair <bool, GridStamp> > List = new List <KeyValuePair <bool, GridStamp> >();
                List.Add(KPair);
                Grids.TrackedGrids.Add(SteamID, List);
            }


            //We really only care to change it when a player loads a grid
            if (!Saving)
            {
                //If the grid is saving... We need to convert to .bak
                string PlayersFolder = Path.Combine(HangarFolderDir, SteamID.ToString());
                string GridPath      = Path.Combine(PlayersFolder, Stamp.GridName + ".sbc");

                if (File.Exists(GridPath))
                {
                    string   BackupGridPath = Path.Combine(PlayersFolder, Stamp.GridName + Stamp.GridID + ".bak");
                    FileInfo F = new FileInfo(GridPath);
                    F.MoveTo(BackupGridPath);

                    //We need to make sure old one gets removed (TheSBC)
                }
            }



            SaveFile(Grids);
        }
Beispiel #10
0
        public void UpdateHangar()
        {
            if (!Directory.Exists(PlayersFolderPath))
            {
                Chat?.Respond("This players hangar doesnt exsist! Skipping sync!");
                return;
            }

            IEnumerable <string> myFiles = Directory.EnumerateFiles(PlayersFolderPath, "*.*", SearchOption.TopDirectoryOnly).Where(s => Path.GetExtension(s).TrimStart('.').ToLowerInvariant() == "sbc");

            if (myFiles.Count() == 0)
            {
                return;
            }
            //Scan for new grids


            List <GridStamp> NewGrids = new List <GridStamp>();
            int AddedGrids            = 0;

            foreach (var file in myFiles)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                Log.Info(name);
                if (SelectedPlayerFile.AnyGridsMatch(Path.GetFileNameWithoutExtension(name)))
                {
                    continue;
                }

                AddedGrids++;
                GridStamp Stamp = new GridStamp(file);
                NewGrids.Add(Stamp);
            }

            int RemovedGrids = 0;

            for (int i = SelectedPlayerFile.Grids.Count - 1; i >= 0; i--)
            {
                if (!myFiles.Any(x => Path.GetFileNameWithoutExtension(x) == SelectedPlayerFile.Grids[i].GridName))
                {
                    RemovedGrids++;
                    SelectedPlayerFile.Grids.RemoveAt(i);
                }
            }

            SelectedPlayerFile.Grids.AddRange(NewGrids);
            SelectedPlayerFile.SaveFile();

            Chat?.Respond($"Removed {RemovedGrids} grids and added {AddedGrids} new grids to hangar for player {SteamID}");
        }
Beispiel #11
0
        public bool LoadGrid(GridStamp Stamp, out IEnumerable <MyObjectBuilder_CubeGrid> Grids)
        {
            Grids = null;


            if (!Stamp.TryGetGrids(PlayersFolderPath, out Grids))
            {
                return(false);
            }


            PluginDependencies.BackupGrid(Grids.ToList(), Identity.IdentityId);
            GridSerializer.TransferGridOwnership(Grids, Identity.IdentityId, Stamp.TransferOwnerShipOnLoad);

            return(true);
        }
Beispiel #12
0
        public bool GetGrid <T>(T GridNameOrNumber, out GridStamp Stamp, out string Message)
        {
            Message = string.Empty;
            Stamp   = null;

            if (GridNameOrNumber is int)
            {
                int Target = Convert.ToInt32(GridNameOrNumber);
                if (!IsInputValid(Target, out Message))
                {
                    return(false);
                }


                Stamp = Grids[Target - 1];
                return(true);
            }
            else if (GridNameOrNumber is string)
            {
                //IsInputValid(SelectedIndex); ;

                if (!Int32.TryParse(Convert.ToString(GridNameOrNumber), out int SelectedIndex))
                {
                    Stamp = Grids.FirstOrDefault(x => x.GridName == Convert.ToString(GridNameOrNumber));
                    if (Stamp != null)
                    {
                        return(true);
                    }
                }



                if (!IsInputValid(SelectedIndex, out Message))
                {
                    return(false);
                }


                Stamp = Grids[SelectedIndex - 1];
                return(true);
            }
            else
            {
                //Dafuq
                return(false);
            }
        }
Beispiel #13
0
        public async void SaveGrid(string NameOrIdentity = "")
        {
            GridResult Result = new GridResult(true);



            //Gets grids player is looking at
            if (!Result.GetGrids(Chat, AdminUserCharacter, NameOrIdentity))
            {
                return;
            }


            if (Result.OwnerSteamID == 0)
            {
                Chat?.Respond("Unable to get major grid owner!");
                return;
            }


            GridStamp    stamp         = Result.GenerateGridStamp();
            PlayerHangar PlayersHanger = new PlayerHangar(Result.OwnerSteamID, Chat, true);

            string Name = Result.OwnerSteamID.ToString();

            if (MySession.Static.Players.TryGetIdentityFromSteamID(Result.OwnerSteamID, out MyIdentity identity))
            {
                Name = identity.DisplayName;
            }

            PlayersHanger.SelectedPlayerFile.FormatGridName(stamp);

            bool val = await PlayersHanger.SaveGridsToFile(Result, stamp.GridName);

            if (val)
            {
                PlayersHanger.SaveGridStamp(stamp, true);
                Chat?.Respond($"{stamp.GridName} was saved to {Name}'s hangar!");
            }
            else
            {
                Chat?.Respond($"{stamp.GridName} failed to send to {Name}'s hangar!");
                return;
            }
        }
Beispiel #14
0
        private bool CheckGridForSale(GridStamp Stamp, int ID)
        {
            if (!Stamp.GridForSale)
            {
                //if grid is not for sale, remove any confirmations
                PlayerConfirmations.Remove(SteamID);
                return(true);
            }
            else
            {
                if (!PlayerConfirmations.TryGetValue(SteamID, out int Selection))
                {
                    //Prompt user
                    if (Config.RestockAmount != 0)
                    {
                        Chat.Respond($"This grid is for sale! Run this command again to pay {Config.RestockAmount}sc to remove it from the market and load it in!");
                    }
                    else
                    {
                        Chat.Respond("This grid is for sale! Run this command again to confirm removal of sell offer and load it in!");
                    }


                    PlayerConfirmations.Add(SteamID, ID);

                    return(false);
                }
                else
                {
                    if (Selection != ID)
                    {
                        //If this grid is for sale and doesnt match our first selection need to remove it from the list and call this function again.
                        PlayerConfirmations.Remove(SteamID);
                        return(CheckGridForSale(Stamp, ID));
                    }



                    //Remove market offer
                    HangarMarketController.RemoveMarketListing(SteamID, Stamp.GridName);
                    PlayerConfirmations.Remove(SteamID);
                    return(true);
                }
            }
        }
Beispiel #15
0
        public void SaveGridStamp(GridStamp Stamp, bool Admin = false, bool IgnoreSave = false)
        {
            if (!Admin)
            {
                TimeStamp stamp = new TimeStamp();
                stamp.OldTime            = DateTime.Now;
                SelectedPlayerFile.Timer = stamp;
            }



            SelectedPlayerFile.Grids.Add(Stamp);

            if (!IgnoreSave)
            {
                SelectedPlayerFile.SaveFile();
            }
        }
Beispiel #16
0
        public MarketListing(GridStamp Stamp)
        {
            Name = Stamp.GridName;



            GridMass         = Stamp.GridMass;
            SmallGrids       = Stamp.SmallGrids;
            LargeGrids       = Stamp.LargeGrids;
            StaticGrids      = Stamp.StaticGrids;
            NumberofBlocks   = Stamp.NumberofBlocks;
            MaxPowerOutput   = Stamp.MaxPowerOutput;
            GridBuiltPercent = Stamp.GridBuiltPercent;
            JumpDistance     = Stamp.JumpDistance;
            NumberOfGrids    = Stamp.NumberOfGrids;
            PCU         = Stamp.GridPCU;
            MarketValue = Stamp.MarketValue;
        }
Beispiel #17
0
        public void HangarUpdate(ulong SteamID, bool Transition, GridStamp Stamp)
        {
            //Need to check if this item already exists


            KeyValuePair <bool, GridStamp> KPair = new KeyValuePair <bool, GridStamp>(Transition, Stamp);

            if (Grids.TrackedGrids.ContainsKey(SteamID))
            {
                var p = Grids.TrackedGrids[SteamID];
                foreach (var a in p)
                {
                    //  Log.Warn(a.Value.GridName + ":" + a.Value.GridID);
                    //  Log.Warn(a.Key);
                }



                int?Index = Grids.TrackedGrids[SteamID].FindIndex(x => x.Value.GridName.Equals(KPair.Value.GridName));
                // Log.Warn("Attempting to Updated GridTracker A! " + KPair.Value.GridName);
                if (Index.HasValue && Index != -1)
                {
                    // Log.Warn("Index: " + Index.Value);
                    Grids.TrackedGrids[SteamID].RemoveAt(Index.Value);
                    //Log.Warn("Found exsisting grid! Removing!");
                }


                Grids.TrackedGrids[SteamID].Add(KPair);
            }
            else
            {
                //Log.Warn("Attempting to Updated GridTracker B! " + KPair.Value.GridName);
                List <KeyValuePair <bool, GridStamp> > List = new List <KeyValuePair <bool, GridStamp> >();
                List.Add(KPair);
                Grids.TrackedGrids.Add(SteamID, List);
            }



            SaveFile(Grids);
        }
Beispiel #18
0
        public bool SellSelectedGrid(GridStamp Stamp, long Price, string Description)
        {
            Stamp.GridForSale = true;


            MarketListing NewListing = new MarketListing(Stamp);

            NewListing.SetUserInputs(Description, Price);
            NewListing.Seller = Identity.DisplayName;
            //We will set this into the file. (in the block we will dynamically get palyer name and faction)
            NewListing.SetPlayerData(SteamID, Identity.IdentityId);
            HangarMarketController.SaveNewMarketFile(NewListing);



            //Save player file
            SavePlayerFile();

            HangarMarketController.NewGridOfferListed(NewListing);
            return(true);
        }
Beispiel #19
0
        private static void PurchaseServerGrid(MarketListing Offer, ulong Buyer, MyIdentity BuyerIdentity)
        {
            if (!File.Exists(Offer.FileSBCPath))
            {
                Log.Error($"{Offer.FileSBCPath} doesnt exsist! Was this removed prematurely?");
                return;
            }


            var ToInfo = new PlayerInfo();

            ToInfo.LoadFile(Hangar.MainPlayerDirectory, Buyer);

            //Log.Error("TotalBuys: " + ToInfo.GetServerOfferPurchaseCount(Offer.Name));
            if (Offer.TotalPerPlayer != 0 && ToInfo.GetServerOfferPurchaseCount(Offer.Name) >= Offer.TotalPerPlayer)
            {
                Chat.Send($"You have reached your buy limit for this offer!", Buyer);
                return;
            }


            GridStamp Stamp = new GridStamp(Offer.FileSBCPath);

            Stamp.GridName = Offer.Name;



            //Log.Error("C");
            if (PlayerHangar.TransferGrid(ToInfo, Stamp))
            {
                //Log.Error("Changing Balance");
                MyBankingSystem.ChangeBalance(BuyerIdentity.IdentityId, -1 * Offer.Price);

                Chat.Send($"Successfully purchased {Offer.Name}! Check your hangar!", Buyer);

                GridOfferBought(Offer, Buyer);

                //Hangar.Config.RefreshModel();
            }
        }
Beispiel #20
0
        public bool ParseInput(string selection, out int ID)
        {
            if (Int32.TryParse(selection, out ID))
            {
                return(true);
            }
            else
            {
                for (int i = 0; i < SelectedPlayerFile.Grids.Count; i++)
                {
                    GridStamp s = SelectedPlayerFile.Grids[i];
                    if (s.GridName == selection)
                    {
                        ID = i + 1;
                        return(true);
                    }
                }



                return(false);
            }
        }
Beispiel #21
0
        public void UpdateHangar()
        {
            IEnumerable <string> myFiles = Directory.EnumerateFiles(PlayersFolderPath, "*.*", SearchOption.TopDirectoryOnly).Where(s => Path.GetExtension(s).TrimStart('.').ToLowerInvariant() == "sbc");

            //Scan for new grids

            List <GridStamp> NewGrids = new List <GridStamp>();
            int AddedGrids            = 0;

            foreach (var file in myFiles)
            {
                if (SelectedPlayerFile.AnyGridsMatch(Path.GetFileNameWithoutExtension(file)))
                {
                    continue;
                }

                AddedGrids++;
                GridStamp Stamp = new GridStamp(file);
                NewGrids.Add(Stamp);
            }

            int RemovedGrids = 0;

            for (int i = SelectedPlayerFile.Grids.Count - 1; i >= 0; i--)
            {
                if (!myFiles.Any(x => Path.GetFileNameWithoutExtension(x) == SelectedPlayerFile.Grids[i].GridName))
                {
                    RemovedGrids++;
                    SelectedPlayerFile.Grids.RemoveAt(i);
                }
            }

            SelectedPlayerFile.Grids.AddRange(NewGrids);
            SelectedPlayerFile.SaveFile();

            Chat?.Respond("Removed " + RemovedGrids + " grids and added " + AddedGrids + " new grids to hangar");
        }
Beispiel #22
0
        private bool SellOnMarket(string IDPath, GridStamp Grid, PlayerInfo Data, MyIdentity Player, long NumPrice, string Description)
        {
            string path = Path.Combine(IDPath, Grid.GridName + ".sbc");

            if (!File.Exists(path))
            {
                //Context.Respond("Grid doesnt exist! Contact an admin!");
                return(false);
            }



            Parallel.Invoke(() =>
            {
                MyObjectBuilderSerializer.DeserializeXML(path, out MyObjectBuilder_Definitions myObjectBuilder_Definitions);

                var shipBlueprint             = myObjectBuilder_Definitions.ShipBlueprints;
                MyObjectBuilder_CubeGrid grid = shipBlueprint[0].CubeGrids[0];



                byte[] Definition       = MyAPIGateway.Utilities.SerializeToBinary(grid);
                GridsForSale GridSell   = new GridsForSale();
                GridSell.name           = Grid.GridName;
                GridSell.GridDefinition = Definition;


                //Seller faction
                var fc = MyAPIGateway.Session.Factions.GetObjectBuilder();

                MyObjectBuilder_Faction factionBuilder;
                try
                {
                    factionBuilder = fc.Factions.First(f => f.Members.Any(m => m.PlayerId == Player.IdentityId));
                    if (factionBuilder != null || factionBuilder.Tag != "")
                    {
                        Grid.SellerFaction = factionBuilder.Tag;
                    }
                }
                catch
                {
                    try
                    {
                        Hangar.Debug("Player " + Player.DisplayName + " has a bugged faction model! Attempting to fix!");
                        factionBuilder = fc.Factions.First(f => f.Members.Any(m => m.PlayerId == Player.IdentityId));
                        MyObjectBuilder_FactionMember member = factionBuilder.Members.First(x => x.PlayerId == Player.IdentityId);

                        bool IsFounder;
                        bool IsLeader;

                        IsFounder = member.IsFounder;
                        IsLeader  = member.IsLeader;

                        factionBuilder.Members.Remove(member);
                        factionBuilder.Members.Add(member);
                    }
                    catch (Exception a)
                    {
                        Hangar.Debug("Welp tbh fix failed! Please why no fix. :(", a, Hangar.ErrorType.Trace);
                    }

                    //Bugged player!
                }



                MarketList List       = new MarketList();
                List.Name             = Grid.GridName;
                List.Description      = Description;
                List.Seller           = "Auction House";
                List.Price            = NumPrice;
                List.Steamid          = Convert.ToUInt64(IDPath);
                List.MarketValue      = Grid.MarketValue;
                List.SellerFaction    = Grid.SellerFaction;
                List.GridMass         = Grid.GridMass;
                List.SmallGrids       = Grid.SmallGrids;
                List.LargeGrids       = Grid.LargeGrids;
                List.NumberofBlocks   = Grid.NumberofBlocks;
                List.MaxPowerOutput   = Grid.MaxPowerOutput;
                List.GridBuiltPercent = Grid.GridBuiltPercent;
                List.JumpDistance     = Grid.JumpDistance;
                List.NumberOfGrids    = Grid.NumberOfGrids;
                List.BlockTypeCount   = Grid.BlockTypeCount;
                List.PCU = Grid.GridPCU;


                //List item as server offer
                List.ServerOffer = true;



                //We need to send to all to add one item to the list!
                CrossServerMessage SendMessage = new CrossServerMessage();
                SendMessage.Type = CrossServer.MessageType.AddItem;
                SendMessage.GridDefinition.Add(GridSell);
                SendMessage.List.Add(List);


                Servers.Update(SendMessage);
            });

            return(true);
        }
Beispiel #23
0
        public bool RemoveGridStamp(GridStamp Stamp)
        {
            int Index = SelectedPlayerFile.Grids.FindIndex(x => x == Stamp);

            return(RemoveStamp(Index));
        }
Beispiel #24
0
        public void PurchaseGrid(GridsForSale grid)
        {
            //Need to check hangar of the person who bought the grid

            if (!Config.GridMarketEnabled)
            {
                return;
            }
            //Get Item from market list for price
            MarketList Item = null;

            List <MarketList> Allitems = new List <MarketList>();

            //Incluse all offers!
            Allitems.AddRange(GridList);
            Allitems.AddRange(PublicOfferseGridList);


            try
            {
                Item = Allitems.First(x => x.Name == grid.name);
            }
            catch
            {
                _ChatManager.SendMessageAsOther("GridMarket", "Grid has been removed from market!", VRageMath.Color.Yellow, grid.BuyerSteamid);
                return;
            }


            MyPlayer.PlayerId BuyPlayer = new MyPlayer.PlayerId(grid.BuyerSteamid);
            MySession.Static.Players.TryGetPlayerById(BuyPlayer, out MyPlayer Buyer);

            GridMethods BuyerMethods = new GridMethods(grid.BuyerSteamid, Config.FolderDirectory);

            //string BuyerPath = GridMethods.CreatePathForPlayer(Config.FolderDirectory, grid.BuyerSteamid);

            if (Buyer == null)
            {
                Hangar.Debug("Unable to get steamID. Glitched player?");
                return;
                //Some kind of error message directed to player.
            }

            //Debug("Seller SteamID: " + Item.Steamid);
            MyCharacter Player = Buyer.Character;

            Hangar.Debug("Player Buying grid: " + Player.DisplayName + " [" + grid.BuyerSteamid + "]");

            //Start transfer of grids!
            int MaxStorage = Config.NormalHangarAmount;

            if (Player.PromoteLevel >= MyPromoteLevel.Scripter)
            {
                MaxStorage = Config.ScripterHangarAmount;
            }

            PlayerInfo BuyerData = new PlayerInfo();

            //Get PlayerInfo from file
            try
            {
                BuyerData = JsonConvert.DeserializeObject <PlayerInfo>(File.ReadAllText(Path.Combine(BuyerMethods.FolderPath, "PlayerInfo.json")));
                if (BuyerData.Grids.Count >= MaxStorage)
                {
                    _ChatManager.SendMessageAsOther("GridMarket", "Unable to purchase grid! No room in hangar!", VRageMath.Color.Yellow, grid.BuyerSteamid);
                    return;
                }
            }
            catch
            {
                Hangar.Debug("Buyer doesnt have anything stored in their hangar! THIS IS NOT AN ERROR!");
                //ChatManager.SendMessageAsOther("GridMarket", "Unknown error! Contact admin!", MyFontEnum.Red, grid.BuyerSteamid);
                //Debug("Deserialization error! Make sure files exist! \n" + e);
                //New player. Go ahead and create new. Should not have a timer.
            }



            //Adjust player prices (We need to check if buyer has enough moneyies hehe)
            bool RetrieveSuccessful = Utils.TryGetPlayerBalance(grid.BuyerSteamid, out long BuyerBallance);

            if (!RetrieveSuccessful || BuyerBallance < Item.Price)
            {
                _ChatManager.SendMessageAsOther("GridMarket", "Unable to purchase grid! Not enough credits!", VRageMath.Color.Yellow, grid.BuyerSteamid);
                return;
            }



            string NewGridName    = Item.Name;
            bool   FileStilExists = true;
            int    i = 0;

            if (File.Exists(Path.Combine(BuyerMethods.FolderPath, NewGridName + ".sbc")))
            {
                while (FileStilExists)
                {
                    i++;
                    if (!File.Exists(Path.Combine(BuyerMethods.FolderPath, NewGridName + "[" + i + "].sbc")))
                    {
                        FileStilExists = false;
                    }
                    //Turns out there is already a ship with that name in this players hangar!
                    if (i > 50)
                    {
                        _ChatManager.SendMessageAsOther("GridMarket", "Dude what the actual f**k do you need 50 of these for?", VRageMath.Color.Yellow, grid.BuyerSteamid);
                        Hangar.Debug("Dude what the actual f**k do you need 50 of these for? Will not continue due to... security reasons. @" + NewGridName);
                        return;
                    }
                }

                NewGridName = NewGridName + "[" + i + "]";
            }



            if (Item.Steamid == 0)
            {
                //Check to see if the item existis in the dir
                string PublicOfferPath = ServerOffersDir;
                string GridPath        = Path.Combine(PublicOfferPath, Item.Name + ".sbc");

                //Add counter just in case some idiot


                string BuyerGridPath = Path.Combine(BuyerMethods.FolderPath, NewGridName + ".sbc");

                if (!File.Exists(GridPath))
                {
                    _ChatManager.SendMessageAsOther("GridMarket", "Server Offer got manually deleted from folder! Blame admin!", VRageMath.Color.Yellow, grid.BuyerSteamid);
                    Hangar.Debug("Someone tried to buy a ship that doesnt exist! Did you delete it?? @" + GridPath);
                }

                //Need to check if player can buy
                PublicOffers Offer;
                int          Index;
                try
                {
                    Offer = Config.PublicOffers.First(x => x.Name == Item.Name);
                    Index = Config.PublicOffers.IndexOf(Offer);
                }
                catch (Exception e)
                {
                    _ChatManager.SendMessageAsOther("GridMarket", "Unknown error! Contact admin!", VRageMath.Color.Yellow, grid.BuyerSteamid);
                    Hangar.Debug("Unknown error! @" + GridPath, e, ErrorType.Fatal);
                    return;
                    //Something went wrong
                }



                if (Offer.TotalPerPlayer != 0 && !WithinPlayerLimits(Item.PlayerPurchases, grid.BuyerSteamid, Offer.TotalPerPlayer))
                {
                    _ChatManager.SendMessageAsOther("GridMarket", "Youve reached your buy limit on this grid!", VRageMath.Color.Yellow, grid.BuyerSteamid);
                    return;
                }



                //File check complete!
                Hangar.Debug("Old Buyers Balance: " + BuyerBallance);

                //Create PlayerAccount
                PlayerAccount BuyerAccount = new PlayerAccount(Player.DisplayName, grid.BuyerSteamid, BuyerBallance - Item.Price);


                //Need to figure out HOW to get the data in here
                GridStamp stamp = new GridStamp();
                stamp.GridForSale = false;
                stamp.GridName    = NewGridName;


                //Add it to buyers info
                File.Copy(GridPath, BuyerGridPath);
                BuyerData.Grids.Add(stamp);


                //Update ALL blocks
                MyObjectBuilderSerializer.DeserializeXML(BuyerGridPath, out MyObjectBuilder_Definitions myObjectBuilder_Definitions);

                MyObjectBuilder_ShipBlueprintDefinition[] shipBlueprint = myObjectBuilder_Definitions.ShipBlueprints;
                foreach (MyObjectBuilder_ShipBlueprintDefinition definition in myObjectBuilder_Definitions.ShipBlueprints)
                {
                    foreach (MyObjectBuilder_CubeGrid CubeGridDef in definition.CubeGrids)
                    {
                        foreach (MyObjectBuilder_CubeBlock block in CubeGridDef.CubeBlocks)
                        {
                            block.Owner   = Buyer.Identity.IdentityId;
                            block.BuiltBy = Buyer.Identity.IdentityId;
                            //Could turnoff warheads etc here
                        }
                    }
                }

                MyObjectBuilderSerializer.SerializeXML(BuyerGridPath, false, myObjectBuilder_Definitions);


                CrossServerMessage SendAccountUpdate = new CrossServerMessage();
                SendAccountUpdate.Type = CrossServer.MessageType.PlayerAccountUpdated;
                SendAccountUpdate.BalanceUpdate.Add(BuyerAccount);

                MarketServers.Update(SendAccountUpdate);

                _ChatManager.SendMessageAsOther("HangarMarket", Player.DisplayName + " just bought a " + grid.name, VRageMath.Color.Yellow);

                //Write all files!
                FileSaver.Save(Path.Combine(BuyerMethods.FolderPath, "PlayerInfo.json"), BuyerData);
                //File.WriteAllText(Path.Combine(BuyerPath, "PlayerInfo.json"), JsonConvert.SerializeObject(BuyerData));

                Offer.NumberOfBuys++;

                if (Offer.TotalPerPlayer != 0)
                {
                    AddPlayerPurchase(PublicOfferseGridList, Item, grid.BuyerSteamid);
                }

                //Check Total Limit
                if (Offer.NumberOfBuys >= Offer.TotalAmount)
                {
                    Config.PublicOffers[Index].Forsale = false;
                    //Update offers and refresh
                    UpdatePublicOffers();
                }
            }
            else
            {
                //This is a player offer

                GridMethods SellerMethods = new GridMethods(Item.Steamid, Dir);
                //string SellerPath = GridMethods.CreatePathForPlayer(Dir, Item.Steamid);
                Debug("Seller SteamID: " + Item.Steamid);


                PlayerInfo SellerData = new PlayerInfo();


                try
                {
                    SellerData = JsonConvert.DeserializeObject <PlayerInfo>(File.ReadAllText(Path.Combine(SellerMethods.FolderPath, "PlayerInfo.json")));
                }
                catch (Exception e)
                {
                    Hangar.Debug("Seller Hangar Playerinfo is missing! Did they get deleted by admin?", e, ErrorType.Warn);
                    _ChatManager.SendMessageAsOther("GridMarket", "Seller hangar info is missing! Contact admin!", VRageMath.Color.Yellow, grid.BuyerSteamid);
                    return;
                }



                CrossServerMessage SendMessage = new CrossServerMessage();
                SendMessage.Type = CrossServer.MessageType.RemoveItem;
                SendMessage.List.Add(Item);
                MarketServers.Update(SendMessage);


                PlayerAccount BuyerAccount  = new PlayerAccount(Player.DisplayName, grid.BuyerSteamid, BuyerBallance - Item.Price);
                PlayerAccount SellerAccount = new PlayerAccount(Item.Seller, Item.Steamid, Item.Price, true);



                //Get grids
                GridStamp gridsold = SellerData.Grids.FirstOrDefault(x => x.GridName == grid.name);
                //Reset grid for sale and remove it from the sellers hangarplayerinfo
                gridsold.GridForSale          = false;
                gridsold.ForceSpawnNearPlayer = true;
                SellerData.Grids.Remove(gridsold);
                gridsold.GridName = NewGridName;

                //Add it to buyers info
                BuyerData.Grids.Add(gridsold);

                //Move grid in folders!
                string SellerGridPath = Path.Combine(SellerMethods.FolderPath, grid.name + ".sbc");
                string BuyerGridPath  = Path.Combine(BuyerMethods.FolderPath, NewGridName + ".sbc");

                File.Move(SellerGridPath, BuyerGridPath);

                //After move we need to update all block owners and authors! this meanings opening up the grid and deserializing it to iterate the grid! (we dont want the seller to still be the author)

                MyObjectBuilderSerializer.DeserializeXML(BuyerGridPath, out MyObjectBuilder_Definitions myObjectBuilder_Definitions);

                MyObjectBuilder_ShipBlueprintDefinition[] shipBlueprint = myObjectBuilder_Definitions.ShipBlueprints;
                foreach (MyObjectBuilder_ShipBlueprintDefinition definition in myObjectBuilder_Definitions.ShipBlueprints)
                {
                    foreach (MyObjectBuilder_CubeGrid CubeGridDef in definition.CubeGrids)
                    {
                        foreach (MyObjectBuilder_CubeBlock block in CubeGridDef.CubeBlocks)
                        {
                            block.Owner   = Buyer.Identity.IdentityId;
                            block.BuiltBy = Buyer.Identity.IdentityId;
                            //Could turnoff warheads etc here
                        }
                    }
                }

                MyObjectBuilderSerializer.SerializeXML(BuyerGridPath, false, myObjectBuilder_Definitions);

                //byte[] Definition = MyAPIGateway.Utilities.SerializeToBinary(grid);

                //Get grid definition of removed grid. (May not even need to get this lol)
                //GridsForSale RemovedGrid = Main.GridDefinition.FirstOrDefault(x => x.name == Item.Name);


                //We need to send to all to remove the item from the list

                CrossServerMessage SendAccountUpdate = new CrossServerMessage();
                SendAccountUpdate.Type = CrossServer.MessageType.PlayerAccountUpdated;
                SendAccountUpdate.BalanceUpdate.Add(BuyerAccount);
                SendAccountUpdate.BalanceUpdate.Add(SellerAccount);

                MarketServers.Update(SendAccountUpdate);
                _ChatManager.SendMessageAsOther("HangarMarket", Player.DisplayName + " just bought a " + grid.name, VRageMath.Color.Yellow);



                //Write all files!
                FileSaver.Save(Path.Combine(SellerMethods.FolderPath, "PlayerInfo.json"), SellerData);
                FileSaver.Save(Path.Combine(BuyerMethods.FolderPath, "PlayerInfo.json"), BuyerData);
                //File.WriteAllText(Path.Combine(SellerPath, "PlayerInfo.json"), JsonConvert.SerializeObject(SellerData));
                //File.WriteAllText(Path.Combine(BuyerPath, "PlayerInfo.json"), JsonConvert.SerializeObject(BuyerData));
            }
            //Transfer Grid and transfer Author/owner!
        }
Beispiel #25
0
        public bool LoadGrid(int ID, out IEnumerable <MyObjectBuilder_CubeGrid> Grids, out GridStamp Stamp)
        {
            Grids = null;
            Stamp = null;
            if (ID - 1 >= SelectedPlayerFile.Grids.Count || ID < 1)
            {
                Chat?.Respond("Invalid Index! Grid doent exsist in that slot!");
                return(false);
            }


            Stamp = SelectedPlayerFile.GetGrid(ID);
            string GridPath = Path.Combine(PlayersFolderPath, Stamp.GridName + ".sbc");

            Log.Warn("Attempting to load grid @" + GridPath);
            if (!GridSerializer.LoadGrid(GridPath, out Grids))
            {
                return(false);
            }

            PluginDependencies.BackupGrid(Grids.ToList(), IdentityID);
            GridSerializer.TransferGridOwnership(Grids, IdentityID);

            return(true);
        }
Beispiel #26
0
        private bool RequireLoadCurrency(GridStamp Grid)
        {
            //MyObjectBuilder_Definitions(MyParticlesManager)
            if (!Config.RequireCurrency)
            {
                return(true);
            }
            else
            {
                long LoadCost = 0;
                switch (Config.HangarLoadCostType)
                {
                case CostType.BlockCount:
                    //If grid is station
                    LoadCost = Convert.ToInt64(Grid.NumberofBlocks * Config.LoadStaticGridCurrency);
                    break;


                case CostType.Fixed:

                    LoadCost = Convert.ToInt64(Config.LoadStaticGridCurrency);

                    break;


                case CostType.PerGrid:

                    LoadCost += Convert.ToInt64(Grid.StaticGrids * Config.LoadStaticGridCurrency);
                    LoadCost += Convert.ToInt64(Grid.LargeGrids * Config.LoadLargeGridCurrency);
                    LoadCost += Convert.ToInt64(Grid.SmallGrids * Config.LoadSmallGridCurrency);


                    break;
                }

                TryGetPlayerBalance(out long Balance);


                if (Balance >= LoadCost)
                {
                    //Check command status!
                    string command = Grid.GridName;
                    var    confirmationCooldownMap = Hangar.ConfirmationsMap;
                    if (confirmationCooldownMap.TryGetValue(IdentityID, out CurrentCooldown confirmationCooldown))
                    {
                        if (!confirmationCooldown.CheckCommandStatus(command))
                        {
                            //Confirmed command! Update player balance!
                            confirmationCooldownMap.Remove(IdentityID);
                            Chat?.Respond("Confirmed! Loading grid!");

                            ChangeBalance(-1 * LoadCost);
                            return(true);
                        }
                        else
                        {
                            Chat?.Respond("Loading this grid will cost " + LoadCost + " SC. Run this command again within 30 secs to continue!");
                            confirmationCooldown.StartCooldown(command);
                            return(false);
                        }
                    }
                    else
                    {
                        Chat?.Respond("Loading this grid will cost " + LoadCost + " SC. Run this command again within 30 secs to continue!");
                        confirmationCooldown = new CurrentCooldown();
                        confirmationCooldown.StartCooldown(command);
                        confirmationCooldownMap.Add(IdentityID, confirmationCooldown);
                        return(false);
                    }
                }
                else
                {
                    long Remaing = LoadCost - Balance;
                    Chat?.Respond("You need an additional " + Remaing + " SC to perform this action!");
                    return(false);
                }
            }
        }
Beispiel #27
0
        public async void SaveGrid()
        {
            if (!PerformMainChecks(true))
            {
                return;
            }


            if (!PlayersHanger.CheckHanagarLimits())
            {
                return;
            }


            GridResult Result = new GridResult();

            //Gets grids player is looking at
            if (!Result.GetGrids(Chat, UserCharacter))
            {
                return;
            }


            if (IsAnyGridInsideSafeZone(Result))
            {
                return;
            }


            //Calculates incoming grids data
            GridStamp GridData = Result.GenerateGridStamp();


            //PlayersHanger.CheckGridLimits(GridData);

            //Checks for single and all slot block and grid limits
            if (!PlayersHanger.ExtensiveLimitChecker(GridData))
            {
                return;
            }


            if (!CheckEnemyDistance(Config.LoadType, PlayerPosition))
            {
                return;
            }


            if (!RequireSaveCurrency(Result))
            {
                return;
            }


            PlayersHanger.SelectedPlayerFile.FormatGridName(GridData);

            bool val = await PlayersHanger.SaveGridsToFile(Result, GridData.GridName);

            if (val)
            {
                PlayersHanger.SaveGridStamp(GridData);
                Chat?.Respond("Save Complete!");
            }
            else
            {
                Chat?.Respond("Saved Failed!");
                return;
            }
        }
Beispiel #28
0
        private bool CheckGridLimits(GridStamp Grid)
        {
            //Backwards compatibale
            if (Config.OnLoadTransfer)
            {
                return(true);
            }



            if (Grid.ShipPCU.Count == 0)
            {
                MyBlockLimits blockLimits = Identity.BlockLimits;

                MyBlockLimits a = MySession.Static.GlobalBlockLimits;

                if (a.PCU <= 0)
                {
                    //PCU Limits on server is 0
                    //Skip PCU Checks
                    //Log.Debug("PCU Server limits is 0!");
                    return(true);
                }

                //Main.Debug("PCU Limit from Server:"+a.PCU);
                //Main.Debug("PCU Limit from Player: " + blockLimits.PCU);
                //Main.Debug("PCU Built from Player: " + blockLimits.PCUBuilt);

                int CurrentPcu = blockLimits.PCUBuilt;
                //Hangar.Debug("Current PCU: " + CurrentPcu);

                int MaxPcu = blockLimits.PCU + CurrentPcu;

                int pcu = MaxPcu - CurrentPcu;
                //Main.Debug("MaxPcu: " + pcu);
                //Hangar.Debug("Grid PCU: " + Grid.GridPCU);


                //Hangar.Debug("Current player PCU:" + CurrentPcu);

                //Find the difference
                if (MaxPcu - CurrentPcu <= Grid.GridPCU)
                {
                    int Need = Grid.GridPCU - (MaxPcu - CurrentPcu);
                    Chat.Respond("PCU limit reached! You need an additional " + Need + " pcu to perform this action!");
                    return(false);
                }

                return(true);
            }


            foreach (KeyValuePair <long, int> Player in Grid.ShipPCU)
            {
                MyIdentity Identity = MySession.Static.Players.TryGetIdentity(Player.Key);
                if (Identity == null)
                {
                    continue;
                }


                MyBlockLimits blockLimits = Identity.BlockLimits;
                MyBlockLimits a           = MySession.Static.GlobalBlockLimits;

                if (a.PCU <= 0)
                {
                    //PCU Limits on server is 0
                    //Skip PCU Checks
                    //Hangar.Debug("PCU Server limits is 0!");
                    continue;
                }

                //Main.Debug("PCU Limit from Server:"+a.PCU);
                //Main.Debug("PCU Limit from Player: " + blockLimits.PCU);
                //Main.Debug("PCU Built from Player: " + blockLimits.PCUBuilt);

                int CurrentPcu = blockLimits.PCUBuilt;
                //Hangar.Debug("Current PCU: " + CurrentPcu);

                int MaxPcu = blockLimits.PCU + CurrentPcu;

                int pcu = MaxPcu - CurrentPcu;
                //Main.Debug("MaxPcu: " + pcu);
                //Hangar.Debug("Grid PCU: " + Grid.GridPCU);


                //Hangar.Debug("Current player PCU:" + CurrentPcu);

                //Find the difference
                if (MaxPcu - CurrentPcu <= Player.Value)
                {
                    int Need = Player.Value - (MaxPcu - CurrentPcu);
                    Chat.Respond("PCU limit reached! " + Identity.DisplayName + " needs an additional " + Need + " PCU to load this grid!");
                    return(false);
                }
            }

            return(true);
        }
Beispiel #29
0
        public bool ExtensiveLimitChecker(GridStamp Stamp)
        {
            //Begin Single Slot Save!


            if (Config.SingleMaxBlocks != 0)
            {
                if (Stamp.NumberofBlocks > Config.SingleMaxBlocks)
                {
                    int remainder = Stamp.NumberofBlocks - Config.SingleMaxBlocks;
                    Chat?.Respond("Grid is " + remainder + " blocks over the max slot block limit! " + Stamp.NumberofBlocks + "/" + Config.SingleMaxBlocks);
                    return(false);
                }
            }

            if (Config.SingleMaxPCU != 0)
            {
                if (Stamp.GridPCU > Config.SingleMaxPCU)
                {
                    int remainder = Stamp.GridPCU - Config.SingleMaxPCU;
                    Chat?.Respond("Grid is " + remainder + " PCU over the slot hangar PCU limit! " + Stamp.GridPCU + "/" + Config.SingleMaxPCU);
                    return(false);
                }
            }

            if (Config.AllowStaticGrids)
            {
                if (Config.SingleMaxLargeGrids != 0 && Stamp.StaticGrids > Config.SingleMaxStaticGrids)
                {
                    int remainder = Stamp.StaticGrids - Config.SingleMaxStaticGrids;
                    Chat?.Respond("You are " + remainder + " static grid over the hangar slot limit!");
                    return(false);
                }
            }
            else
            {
                if (Stamp.StaticGrids > 0)
                {
                    Chat?.Respond("Saving Static Grids is disabled!");
                    return(false);
                }
            }

            if (Config.AllowLargeGrids)
            {
                if (Config.SingleMaxLargeGrids != 0 && Stamp.LargeGrids > Config.SingleMaxLargeGrids)
                {
                    int remainder = Stamp.LargeGrids - Config.SingleMaxLargeGrids;

                    Chat?.Respond("You are " + remainder + " large grids over the hangar slot limit!");
                    return(false);
                }
            }
            else
            {
                if (Stamp.LargeGrids > 0)
                {
                    Chat?.Respond("Saving Large Grids is disabled!");
                    return(false);
                }
            }

            if (Config.AllowSmallGrids)
            {
                if (Config.SingleMaxSmallGrids != 0 && Stamp.SmallGrids > Config.SingleMaxSmallGrids)
                {
                    int remainder = Stamp.SmallGrids - Config.SingleMaxLargeGrids;

                    Chat?.Respond("You are " + remainder + " small grid over the hangar slot limit!");
                    return(false);
                }
            }
            else
            {
                if (Stamp.SmallGrids > 0)
                {
                    Chat?.Respond("Saving Small Grids is disabled!");
                    return(false);
                }
            }


            int TotalBlocks = 0;
            int TotalPCU    = 0;
            int StaticGrids = 0;
            int LargeGrids  = 0;
            int SmallGrids  = 0;

            //Hangar total limit!
            foreach (GridStamp Grid in SelectedPlayerFile.Grids)
            {
                TotalBlocks += Grid.NumberofBlocks;
                TotalPCU    += Grid.GridPCU;

                StaticGrids += Grid.StaticGrids;
                LargeGrids  += Grid.LargeGrids;
                SmallGrids  += Grid.SmallGrids;
            }

            if (Config.TotalMaxBlocks != 0 && TotalBlocks > Config.TotalMaxBlocks)
            {
                int remainder = TotalBlocks - Config.TotalMaxBlocks;

                Chat?.Respond("Grid is " + remainder + " blocks over the total hangar block limit! " + TotalBlocks + "/" + Config.TotalMaxBlocks);
                return(false);
            }

            if (Config.TotalMaxPCU != 0 && TotalPCU > Config.TotalMaxPCU)
            {
                int remainder = TotalPCU - Config.TotalMaxPCU;
                Chat?.Respond("Grid is " + remainder + " PCU over the total hangar PCU limit! " + TotalPCU + "/" + Config.TotalMaxPCU);
                return(false);
            }


            if (Config.TotalMaxStaticGrids != 0 && StaticGrids > Config.TotalMaxStaticGrids)
            {
                int remainder = StaticGrids - Config.TotalMaxStaticGrids;

                Chat?.Respond("You are " + remainder + " static grid over the total hangar limit!");
                return(false);
            }


            if (Config.TotalMaxLargeGrids != 0 && LargeGrids > Config.TotalMaxLargeGrids)
            {
                int remainder = LargeGrids - Config.TotalMaxLargeGrids;

                Chat?.Respond("You are " + remainder + " large grid over the total hangar limit!");
                return(false);
            }


            if (Config.TotalMaxSmallGrids != 0 && SmallGrids > Config.TotalMaxSmallGrids)
            {
                int remainder = LargeGrids - Config.TotalMaxSmallGrids;

                Chat?.Respond("You are " + remainder + " small grid over the total hangar limit!");
                return(false);
            }

            return(true);
        }