Пример #1
0
        public static void PurchaseGridOffer(ulong Buyer, ulong Owner, string GridName)
        {
            Log.Error($"BuyerRequest: {Buyer}, Owner {Owner}, GridName {GridName}");

            if (!ValidGrid(Owner, GridName, out MarketListing Offer, out string GridPath))
            {
                return;
            }



            if (!MySession.Static.Players.TryGetIdentityFromSteamID(Buyer, out MyIdentity BuyerIdentity))
            {
                return;
            }


            long BuyerBalance = MyBankingSystem.GetBalance(BuyerIdentity.IdentityId);

            if (BuyerBalance < Offer.Price)
            {
                //Yell shit at player for trying to cheat those bastards
                MyMultiplayer.Static.BanClient(Buyer, true);
                return;
            }

            if (Offer.ServerOffer)
            {
                PurchaseServerGrid(Offer, Buyer, BuyerIdentity);
            }
            else
            {
                PurchasePlayerGrid(Offer, Buyer, BuyerIdentity, Owner);
            }
        }
Пример #2
0
        public void PurgeIdentity(string playername)
        {
            int count;
            var playerGpss = GpsDicField.GetValue(MySession.Static.Gpss) as Dictionary <long, Dictionary <int, MyGps> >;
            var id         = Utilities.GetIdentityByNameOrIds(playername);

            if (id == null)
            {
                Context.Respond($"No Identity found for {playername}.  Try Again");
                return;
            }

            var PlayerSteamID = MySession.Static.Players.TryGetSteamId(id.IdentityId);

            if (PlayerSteamID > 0 && !MySession.Static.IsUserAdmin(PlayerSteamID))
            {
                MyBankingSystem.RemoveAccount_Clients(id.IdentityId);
            }

            if (playerGpss.ContainsKey(id.IdentityId))
            {
                playerGpss.Remove(id.IdentityId);
            }

            count = FixGridOwnership(new List <long> {
                id.IdentityId
            });
            RemoveEmptyFactions();
            Context.Respond($"Removed identity and {count} grids owned by them, also bank account and GPS Inventory.");
        }
Пример #3
0
 public void EcoSet(string Player, long amount)
 {
     if (Player != "*")
     {
         var p = Utilities.GetPlayerByNameOrId(Player);
         if (p == null)
         {
             Context.Respond("Player not found");
             return;
         }
         p.TryGetBalanceInfo(out long balance);
         long difference = (balance - amount);
         p.RequestChangeBalance(-difference);
         ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount} credits!", 10000, "Blue"), p.SteamUserId);
     }
     else
     {
         foreach (var p in MySession.Static.Players.GetAllPlayers())
         {
             long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
             long balance    = MyBankingSystem.GetBalance(IdentityID);
             long difference = (balance - amount);
             MyBankingSystem.ChangeBalance(IdentityID, -difference);
             ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount} credits!", 10000, "Blue"), p.SteamId);
         }
     }
     Context.Respond($"Balance(s) set to {amount}");
 }
Пример #4
0
 public void EcoGive(string Player, long amount)
 {
     if (Player != "*")
     {
         var p = Utilities.GetPlayerByNameOrId(Player);
         if (p == null)
         {
             Context.Respond("Player not found");
             return;
         }
         p.TryGetBalanceInfo(out long balance);
         Context.Respond($"new bal will be {balance + amount}");
         p.RequestChangeBalance(amount);
         ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been added to your virtual account", 10000, "Blue"), p.SteamUserId);
     }
     else
     {
         foreach (var p in MySession.Static.Players.GetAllPlayers())
         {
             long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
             MyBankingSystem.ChangeBalance(IdentityID, amount);
             ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been added to your virtual account", 10000, "Blue"), p.SteamId);
         }
     }
     Context.Respond($"{amount} credits given to account(s)");
 }
Пример #5
0
 public void EcoTake(string Player, long amount)
 {
     if (Player != "*")
     {
         var p = Utilities.GetPlayerByNameOrId(Player);
         if (p == null)
         {
             Context.Respond("Player not found");
             return;
         }
         long changefactor = 0 - amount;
         p.RequestChangeBalance(changefactor);
         ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been taken to your virtual account", 10000, "Blue"), p.SteamUserId);
     }
     else
     {
         foreach (var p in MySession.Static.Players.GetAllPlayers())
         {
             long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
             long balance    = MyBankingSystem.GetBalance(IdentityID);
             MyBankingSystem.ChangeBalance(IdentityID, -amount);
             ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been taken to your virtual account", 10000, "Blue"), p.SteamId);
         }
     }
     Context.Respond($"{amount} credits taken from account(s)");
 }
Пример #6
0
        public void EcoTop()
        {
            StringBuilder ecodata = new StringBuilder();

            ecodata.AppendLine("Summary of balanaces accross the server");
            Dictionary <ulong, long> balances = new Dictionary <ulong, long>();

            foreach (var p in MySession.Static.Players.GetAllPlayers())
            {
                long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
                long balance    = MyBankingSystem.GetBalance(IdentityID);
                balances.Add(p.SteamId, balance);
            }
            var sorted = balances.OrderByDescending(x => x.Value).ThenBy(x => x.Key);

            foreach (var value in sorted)
            {
                var test = MySession.Static.Players.TryGetIdentityNameFromSteamId(value.Key);
                ecodata.AppendLine($"Player: {MySession.Static.Players.TryGetIdentityNameFromSteamId(value.Key).ToString()} - Balance: {value.Value.ToString()}");
            }

            if (Context.Player == null)
            {
                Context.Respond(ecodata.ToString());
                return;
            }
            ModCommunication.SendMessageTo(new DialogMessage("Public balance list", "List of players and their credit balances", ecodata.ToString()), Context.Player.SteamUserId);
        }
Пример #7
0
        public void DeliverContract()
        {
            Contract      contract        = TruckingPlugin.getActiveContract(Context.Player.SteamUserId);
            StringBuilder contractDetails = new StringBuilder();

            if (contract != null)
            {
                Vector3D coords   = contract.GetDeliveryLocation().Coords;
                float    distance = Vector3.Distance(coords, Context.Player.Character.PositionComp.GetPosition());
                if (distance <= 1000)
                {
                    List <VRage.ModAPI.IMyEntity> l = new List <VRage.ModAPI.IMyEntity>();

                    BoundingSphereD sphere = new BoundingSphereD(Context.Player.Character.PositionComp.GetPosition(), 1000);
                    l = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

                    Dictionary <MyDefinitionId, int> itemsToRemove = new Dictionary <MyDefinitionId, int>();
                    int pay = 0;
                    foreach (ContractItems item in contract.getItemsInContract())
                    {
                        if (MyDefinitionId.TryParse("MyObjectBuilder_" + item.ItemType, item.SubType, out MyDefinitionId id))
                        {
                            itemsToRemove.Add(id, item.AmountToDeliver);
                            pay += item.AmountToDeliver * item.GetPrice();
                        }
                        else
                        {
                            Context.Respond("Theres an error in the config for this item, report in a ticket " + id.SubtypeName + " " + id.TypeId);
                        }
                    }

                    foreach (IMyEntity entity in l)
                    {
                        if (entity is MyCubeGrid grid)
                        {
                            List <VRage.Game.ModAPI.IMyInventory> inventories = TakeTheItems.GetInventories(grid);
                            if (FacUtils.IsOwnerOrFactionOwned(grid, Context.Player.IdentityId, true))
                            {
                                if (TakeTheItems.ConsumeComponents(inventories, itemsToRemove, Context.Player.SteamUserId))
                                {
                                    MyBankingSystem.ChangeBalance(Context.Player.Identity.IdentityId, pay);
                                    Database.RemoveContract(Context.Player.SteamUserId, true, contract, Context.Player.IdentityId);
                                    TruckingPlugin.SendMessage("The Boss", "Contract Complete, Payment delivered to bank account.", Color.Purple, Context.Player.SteamUserId);
                                    return;
                                }
                            }
                        }
                    }
                    Context.Respond("Could not find owned grid in vicinity with the required items.", "The Boss");
                }
                else
                {
                    Context.Respond("You arent close enough to the delivery point! Must be within 1km of signal", "The Boss");
                }
            }
            else
            {
                Context.Respond("You dont have an active contract.", "The Boss");
            }
        }
Пример #8
0
 public static void takeMoney(long walletID, Int64 amount)
 {
     if (getBalance(walletID) >= amount)
     {
         amount = amount * -1;
         MyBankingSystem.ChangeBalance(walletID, amount);
     }
     return;
 }
Пример #9
0
 public static void doPayment2Players(long walletIDSender, long walletIDRecipient, Int64 amount)
 {
     if (getBalance(walletIDSender) > amount)
     {
         MyBankingSystem.ChangeBalance(walletIDSender, amount);
         // Int64 amountTaxApplied = amount * tax;
         Int64 amountTaxApplied = amount;
         MyBankingSystem.ChangeBalance(walletIDRecipient, amountTaxApplied);
     }
     return;
 }
Пример #10
0
 private bool TryGetPlayerBalance(out long balance)
 {
     try
     {
         balance = MyBankingSystem.GetBalance(IdentityID);
         return(true);
     }
     catch (Exception e)
     {
         balance = 0;
         return(false);
     }
 }
Пример #11
0
        public void EcoCheck(string Player)
        {
            var p = Utilities.GetPlayerByNameOrId(Player);

            if (p == null)
            {
                Context.Respond("Player is not online or cannot be found!");
                return;
            }
            long balance = MyBankingSystem.GetBalance(p.Identity.IdentityId);

            Context.Respond($"{p.DisplayName}'s balance is {balance} credits");
        }
Пример #12
0
        public static Boolean StorePatchMethod(MyStoreBlock __instance, long id, int amount, long targetEntityId, MyPlayer player, MyAccountInfo playerAccountInfo)
        {
            MyStoreItem storeItem = (MyStoreItem)null;
            bool        proceed   = false;

            foreach (MyStoreItem playerItem in __instance.PlayerItems)
            {
                MyCubeGrid grid = __instance.CubeGrid;
                if (FacUtils.GetFactionTag(FacUtils.GetOwner(grid)) != null && FacUtils.GetFactionTag(FacUtils.GetOwner(grid)).Length > 3 && TruckingPlugin.config.NPCGridContracts)
                {
                    proceed = true;
                }
                if (!grid.Editable || !grid.DestructibleBlocks)
                {
                    proceed = true;
                }

                if (__instance.DisplayNameText != null && __instance.DisplayNameText.ToLower().Contains("hauling contracts") && proceed)
                {
                    if (playerItem.Id == id)
                    {
                        storeItem = playerItem;
                        break;
                    }
                }
            }
            //this does things
            if (storeItem != null && proceed)
            {
                if (MyBankingSystem.GetBalance(player.Identity.IdentityId) >= storeItem.PricePerUnit)
                {
                    //if it cant generate a contract, return false
                    if (!TruckingPlugin.GenerateContract(player.Id.SteamId, player.Identity.IdentityId))
                    {
                        return(false);
                    }
                    else
                    {
                        //do the money transfers then return false so the item stays in the store
                        MyBankingSystem.ChangeBalance(player.Identity.IdentityId, (storeItem.PricePerUnit * -1));
                        MyBankingSystem.ChangeBalance(__instance.OwnerId, storeItem.PricePerUnit);
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #13
0
 public static bool TryGetPlayerBalance(ulong steamID, out long balance)
 {
     try
     {
         //PlayerId Player = new MyPlayer.PlayerId(steamID);
         //Hangar.Debug("SteamID: " + steamID);
         long IdentityID = MySession.Static.Players.TryGetIdentityId(steamID);
         //Hangar.Debug("IdentityID: " + IdentityID);
         balance = MyBankingSystem.GetBalance(IdentityID);
         return(true);
     }
     catch (Exception e)
     {
         //Hangar.Debug("Unkown keen player error!", e, Hangar.ErrorType.Fatal);
         balance = 0;
         return(false);
     }
 }
Пример #14
0
        public void EcoPay(string Player, long amount)
        {
            if (Context.Player == null)
            {
                Context.Respond("Console cannot execute this command");
                return;
            }
            var p = Utilities.GetPlayerByNameOrId(Player);

            if (p == null)
            {
                Context.Respond("Player is not online or cannot be found!");
                return;
            }
            MyBankingSystem.RequestTransfer(Context.Player.Identity.IdentityId, p.IdentityId, amount);
            ModCommunication.SendMessageTo(new NotificationMessage($"Your have recieved {amount} credits from {Context.Player}!", 10000, "Blue"), p.SteamUserId);
            ModCommunication.SendMessageTo(new NotificationMessage($"Your have sent {amount} credits to {p.DisplayName}!", 10000, "Blue"), Context.Player.SteamUserId);
        }
Пример #15
0
        private static void PurchasePlayerGrid(MarketListing Offer, ulong Buyer, MyIdentity BuyerIdentity, ulong Owner)
        {
            //Log.Error("A");


            if (!MySession.Static.Players.TryGetIdentityFromSteamID(Owner, out MyIdentity OwnerIdentity))
            {
                return;
            }

            //Have a successfull buy
            RemoveMarketListing(Owner, Offer.Name);

            //Transfer grid
            if (PlayerHangar.TransferGrid(Owner, Buyer, Offer.Name))
            {
                Chat.Send($"Successfully purchased {Offer.Name} from {OwnerIdentity.DisplayName}! Check your hangar!", Buyer);
                MyBankingSystem.ChangeBalance(BuyerIdentity.IdentityId, -1 * Offer.Price);
                MyBankingSystem.ChangeBalance(OwnerIdentity.IdentityId, Offer.Price);
            }
        }
Пример #16
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();
            }
        }
Пример #17
0
        public static bool TryUpdatePlayerBalance(PlayerAccount Account)
        {
            try
            {
                long IdentityID = MySession.Static.Players.TryGetIdentityId(Account.SteamID);

                if (IdentityID == 0)
                {
                    return(false);
                }


                if (Account.AccountAdjustment)
                {
                    MyBankingSystem.ChangeBalance(IdentityID, Account.AccountBalance);
                    return(true);
                }


                long OriginalBalance = MyBankingSystem.GetBalance(IdentityID);
                long BalanceAdjuster = Account.AccountBalance - OriginalBalance;

                if (BalanceAdjuster == 0)
                {
                    return(true);
                }

                MyBankingSystem.ChangeBalance(IdentityID, BalanceAdjuster);
                //Hangar.Debug("Player " + IdentityID + " account has been updated! ");

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public static bool GivePlayerCredits(long accountNumber, long playerCredit)
        {
            try
            {
                MyAccountInfo playerAccount;
                if (bank.TryGetAccountInfo(accountNumber, out playerAccount))
                {
                    if (playerCredit > 0)
                    {
                        if (MyBankingSystem.ChangeBalance(accountNumber, playerCredit))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (playerAccount.Balance < playerCredit)
                        {
                            MyBankingSystem.ChangeBalance(accountNumber, playerAccount.Balance);
                            playerAccount.Balance = 0;
                            return(true);
                        }
                        if (MyBankingSystem.ChangeBalance(accountNumber, playerCredit))
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Log.Error("failed to pay");
            }

            return(false);
        }
Пример #19
0
        public override void Update()
        {
            try
            {
                //slow this shit down so it doesnt lag out console, 32 is fine but i dont think it needs to check that often
                ++this.tick;


                if (this.tick % 128 == 0)
                {
                    if (DateTime.Now >= nextUpdate && config.UsingWhitelist)
                    {
                        nextUpdate = DateTime.Now.AddMinutes(5);
                        Whitelist.Clear();
                        Database.LoadWhitelist();
                    }
                    foreach (MyPlayer onlinePlayer in MySession.Static.Players.GetOnlinePlayers())
                    {
                        MyPlayer playerOnline = onlinePlayer;
                        if (onlinePlayer.Character != null && onlinePlayer?.Controller.ControlledEntity is MyCockpit controller)
                        {
                            MyCubeGrid grid = controller.CubeGrid;
                            if (TruckingPlugin.getActiveContract(onlinePlayer.Id.SteamId) != null)
                            {
                                Contract contract = TruckingPlugin.getActiveContract(onlinePlayer.Id.SteamId);
                                Vector3D coords   = contract.GetDeliveryLocation().Coords;
                                float    distance = Vector3.Distance(coords, onlinePlayer.Character.PositionComp.GetPosition());
                                if (distance <= 300)
                                {
                                    List <VRage.ModAPI.IMyEntity> l = new List <VRage.ModAPI.IMyEntity>();

                                    BoundingSphereD sphere = new BoundingSphereD(onlinePlayer.Character.PositionComp.GetPosition(), 1000);
                                    l = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

                                    Dictionary <MyDefinitionId, int> itemsToRemove = new Dictionary <MyDefinitionId, int>();
                                    int pay = 0;
                                    //calculate the pay since we only show the player the minimum they can get, this could be removed if the pay is made part of the contract
                                    //when its generated and stored in the db, reputation when completed could give a bonus percent
                                    foreach (ContractItems item in contract.getItemsInContract())
                                    {
                                        if (MyDefinitionId.TryParse("MyObjectBuilder_" + item.ItemType, item.SubType, out MyDefinitionId id))
                                        {
                                            itemsToRemove.Add(id, item.AmountToDeliver);
                                            pay += item.AmountToDeliver * item.GetPrice();
                                        }
                                    }


                                    List <VRage.Game.ModAPI.IMyInventory> inventories = TakeTheItems.GetInventories(grid);

                                    if (FacUtils.IsOwnerOrFactionOwned(grid, onlinePlayer.Identity.IdentityId, true) && Vector3.Distance(coords, grid.PositionComp.GetPosition()) <= 300)
                                    {
                                        if (TakeTheItems.ConsumeComponents(inventories, itemsToRemove, onlinePlayer.Id.SteamId))
                                        {
                                            MyBankingSystem.ChangeBalance(onlinePlayer.Identity.IdentityId, pay);
                                            Database.RemoveContract(onlinePlayer.Id.SteamId, true, contract, onlinePlayer.Identity.IdentityId);
                                            TruckingPlugin.SendMessage("The Boss", "Contract Complete, Payment delivered to bank account.", Color.Purple, onlinePlayer.Id.SteamId);
                                            //if (TruckingPlugin.config.DoBonusRewards)
                                            //{
                                            //    List<ContractItems> SortedList = bonusRewards.OrderByDescending(o => o.chance).ToList();
                                            //    Random random = new Random();
                                            //    foreach (ContractItems item in SortedList)
                                            //    {

                                            //        int chance = random.Next(101);
                                            //        if (chance <= item.chance)
                                            //        {

                                            //        }
                                            //    }
                                            //}
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TruckingPlugin.Log.Info("Space trucking error " + ex.ToString());
            }
        }
        private void BuyInternal(long price, PurchaseMode mode)
        {
            if (Context.Player == null)
            {
                Context.Respond("Only an actual player can buy GPS!");
                return;
            }

            if (price < 0)
            {
                Context.Respond("This command was disabled in the settings. Use '!gps list commands' to see which commands are active!");
                return;
            }

            var player   = Context.Player;
            var identity = PlayerUtils.GetIdentityById(player.IdentityId);

            price = GetAdjustedPriceForPlayer(price, identity);

            if (Plugin.Config.MustBeInFactionToBuy)
            {
                var faction = FactionUtils.GetPlayerFaction(identity.IdentityId);

                if (faction == null)
                {
                    Context.Respond("You must be part of a Faction to buy GPS!");
                    return;
                }
            }

            if (mode == PurchaseMode.ONLINE || mode == PurchaseMode.RANDOM)
            {
                var minPlayersOnline = Plugin.Config.MinPlayerOnlineToBuy;

                int onlineCount = MySession.Static.Players.GetOnlinePlayerCount();

                if (onlineCount < minPlayersOnline)
                {
                    Context.Respond("For Online/Random gps at least " + minPlayersOnline + " players must be online!");
                    return;
                }
            }

            var minOnlineTime = Plugin.Config.MinOnlineMinutesToBuy;

            if (minOnlineTime > 0)
            {
                var lastSeen      = Plugin.getLastLoginDate(identity.IdentityId);
                var minOnlineDate = DateTime.Now.AddMinutes(-Plugin.Config.MinOnlineMinutesToBuy);

                if (lastSeen > minOnlineDate)
                {
                    int differenceSeconds = (int)lastSeen.Subtract(minOnlineDate).TotalSeconds;

                    int minutes = (differenceSeconds / 60);
                    int seconds = differenceSeconds % 60;

                    Context.Respond("You are not online for long enough! You must be online for at least " + minutes.ToString("00") + ":" + seconds.ToString("00") + " more minutes!");

                    return;
                }
            }

            var minPCUToBuy = Plugin.Config.MinPCUToBuy;

            if (minPCUToBuy > 0)
            {
                var pcuBuilt  = identity.BlockLimits.PCUBuilt;
                var neededPcu = Plugin.Config.MinPCUToBuy;

                if (neededPcu > pcuBuilt)
                {
                    Context.Respond("You dont have enough PCU to buy! You need at least " + (neededPcu - pcuBuilt) + " more!");

                    return;
                }
            }

            var cooldownManager        = Plugin.CooldownManager;
            var cooldownManagerFaction = Plugin.CooldownManagerFactionChange;
            var steamId = new SteamIdCooldownKey(player.SteamUserId);

            long currentBalance = MyBankingSystem.GetBalance(player.IdentityId);

            if (currentBalance < price)
            {
                Context.Respond("You dont have enough credits to effort a GPS! You need at least " + price.ToString("#,##0") + " SC.");
                return;
            }

            if (!cooldownManagerFaction.CheckCooldown(steamId, GpsRoulettePlugin.COOLDOWN_COMMAND, out long remainingSecondsFaction))
            {
                Log.Info("Faction Cooldown for Player " + player.DisplayName + " still running! " + remainingSecondsFaction + " seconds remaining!");
                Context.Respond("Command is still on cooldown after you changed Factions for " + remainingSecondsFaction + " seconds.");
                return;
            }

            if (!cooldownManager.CheckCooldown(steamId, GpsRoulettePlugin.COOLDOWN_COMMAND, out long remainingSeconds))
            {
                Log.Info("Cooldown for Player " + player.DisplayName + " still running! " + remainingSeconds + " seconds remaining!");
                Context.Respond("Command is still on cooldown for " + remainingSeconds + " seconds.");
                return;
            }

            var buyables = FindFilteredBuyablesForPlayer(mode);

            if (buyables.Count == 0)
            {
                Context.Respond("Currently there is no GPS available for purchase. Please try again later!");
                return;
            }

            if (!CheckConformation(steamId, mode, price))
            {
                return;
            }

            if (BuyRandomFromDict(buyables))
            {
                var config     = Plugin.Config;
                var cooldownMs = config.CooldownMinutes * 60 * 1000L;

                MyBankingSystem.ChangeBalance(player.IdentityId, -price);

                cooldownManager.StartCooldown(steamId, GpsRoulettePlugin.COOLDOWN_COMMAND, cooldownMs);

                Context.Respond("Purchase successful!");
            }
            else
            {
                Context.Respond("The location of the selected player could not be retrieved. The purchase was cancelled. Please try again.");
            }
        }
Пример #21
0
        public void CleanSandboxBankAccounts(int days)
        {
            if (days <= 0)
            {
                Context?.Respond($"Input number of days player have not logged on in");
                return;
            }

            int count         = 0;
            int Lostcount     = 0;
            var OldIdentities = new HashSet <long>();
            var AllIdentities = new HashSet <long>();
            var idents        = MySession.Static.Players.GetAllIdentities().ToList();
            var cutoff        = DateTime.Now - TimeSpan.FromDays(days);

            foreach (var identity in idents)
            {
                if (identity == null || MySession.Static.Players.IdentityIsNpc(identity.IdentityId))
                {
                    continue;
                }

                var PlayerSteamID = MySession.Static.Players.TryGetSteamId(identity.IdentityId);

                if (PlayerSteamID > 0 && MySession.Static.IsUserAdmin(PlayerSteamID))
                {
                    continue;
                }

                AllIdentities.Add(identity.IdentityId);

                if (identity.LastLoginTime < cutoff)
                {
                    OldIdentities.Add(identity.IdentityId);
                }
            }

            if (OldIdentities.Count > 0)
            {
                foreach (var id in OldIdentities.ToList())
                {
                    MyBankingSystem.RemoveAccount_Clients(id);
                    count++;
                }
            }

            if (AllIdentities.Count > 0)
            {
                foreach (var id in AllIdentities.ToList())
                {
                    if (!AllIdentities.ToList().Contains(id))
                    {
                        MyBankingSystem.RemoveAccount_Clients(id);
                        Lostcount++;
                    }
                }
            }

            OldIdentities.Clear();
            AllIdentities.Clear();

            Context?.Respond($"Removed {count} old Bank Accounts for existing players that have not logged on in {days} days, and {Lostcount} for no longer existing players.");
        }
Пример #22
0
        public static void addMoney(long walletID, Int64 amount)
        {
            MyBankingSystem.ChangeBalance(walletID, amount);

            return;
        }
Пример #23
0
 private void ChangeBalance(long Amount)
 {
     MyBankingSystem.ChangeBalance(IdentityID, Amount);
 }
Пример #24
0
        public void Buy(string orderNumber)
        {
            if (!CheckIsPlayer(out var player))
            {
                return;
            }

            if (!Plugin.PurchaseOrders.TryGetValue(orderNumber, out var purchaseOrder))
            {
                Respond("No such purchase order");
                return;
            }

            var sellerIdentityId = purchaseOrder.SellerIdentityId;
            var isSelfOrder      = sellerIdentityId == player.IdentityId;

            if (!Config.CanRepurchaseOwnOrder && isSelfOrder)
            {
                Respond("Can't repurchase your own order");
                return;
            }

            var sellerNotExist = !MySession.Static.Players.HasIdentity(sellerIdentityId);

            if (sellerNotExist)
            {
                Log.Error($"Seller {sellerIdentityId} of order <{orderNumber}> not exists!");
            }
            else if (!Config.CanRepurchaseFactionOrder && !isSelfOrder &&
                     MySession.Static.Factions.GetPlayerFaction(sellerIdentityId)?.IsMember(player.IdentityId) == true)
            {
                Respond("Can't repurchase your faction order");
                return;
            }

            if (!player.TryGetBalanceInfo(out var balance) || balance < purchaseOrder.Price)
            {
                Respond($"No enough money, need {purchaseOrder.Price} but you only have {balance}");
                return;
            }

            if (!MyDefinitionId.TryParse(purchaseOrder.ItemType, purchaseOrder.ItemSubType, out var definitionId) ||
                !MyDefinitionManager.Static.TryGetPhysicalItemDefinition(definitionId, out _))
            {
                Respond(
                    $"The order <{orderNumber}> contains invalid DefinitionId, may cause by mod changing or data corruption, please contact GM"
                    );
                return;
            }

            var playerInventory         = GetPlayerInventory();
            var canAddToPlayerInventory = playerInventory?.ComputeAmountThatFits(definitionId) ?? MyFixedPoint.Zero;
            var cargoInventory          = GetAimedHavePermissionCargoInventory();
            var canAddToCargoInventory  = cargoInventory?.ComputeAmountThatFits(definitionId) ?? MyFixedPoint.Zero;

            //totalCanAdd may overflow
            if (canAddToCargoInventory < purchaseOrder.Amount &&
                canAddToPlayerInventory < purchaseOrder.Amount &&
                canAddToPlayerInventory + canAddToCargoInventory < purchaseOrder.Amount)
            {
                Respond("No enough inventory space");
                return;
            }

            MyFixedPoint addToPlayerInventory;
            MyFixedPoint addToCargoInventory;

            if (canAddToCargoInventory > purchaseOrder.Amount)
            {
                addToCargoInventory  = purchaseOrder.Amount;
                addToPlayerInventory = MyFixedPoint.Zero;
            }
            else
            {
                addToCargoInventory  = canAddToCargoInventory;
                addToPlayerInventory = purchaseOrder.Amount - canAddToCargoInventory;
            }

            if (!Plugin.TryFinishOrder(orderNumber, out _))
            {
                Respond("No such purchase order");
                return;
            }

            player.RequestChangeBalance(-purchaseOrder.Price);
            var objectBuilder = MyObjectBuilderSerializer.CreateNewObject(definitionId);

            playerInventory?.AddItems(addToPlayerInventory, objectBuilder);
            cargoInventory?.AddItems(addToCargoInventory, objectBuilder);
            Respond($"You bought {definitionId} ({purchaseOrder.Amount}) for ${purchaseOrder.Price}");

            var tax = (long)(Config.IllegalTaxRateDouble * purchaseOrder.Price);
            var s   = $"<{orderNumber}> purchased by '{player.DisplayName}' for ${purchaseOrder.Price}(tax ${tax})";

            if (Config.BroadcastOnBuy)
            {
                SendMessage($"The order {s}");
            }

            if (sellerNotExist)
            {
                return;
            }
            MyBankingSystem.ChangeBalance(sellerIdentityId, purchaseOrder.Price - tax);

            if (!Config.BroadcastOnBuy && Config.NotifySellerOnBuy &&
                MySession.Static.Players.TryGetPlayerId(sellerIdentityId, out var sellerPlayerId) &&
                MySession.Static.Players.IsPlayerOnline(ref sellerPlayerId))
            {
                SendMessage(
                    $"Your order {s}",
                    sellerPlayerId.SteamId
                    );
            }
        }