Example #1
0
 public void BuyShip(int key, long BuyerId)
 {
     if (items.ContainsKey(key))
     {
         MarketItem item     = items[key];
         MyIdentity SellerId = AlliancePlugin.TryGetIdentity(item.SellerSteamId.ToString());
         if (SellerId != null)
         {
             EconUtils.addMoney(SellerId.IdentityId, item.Price);
             EconUtils.takeMoney(BuyerId, item.Price);
         }
     }
 }
Example #2
0
        public void PayDividend(Int64 amount, List <long> ids, ulong steamid)
        {
            Int64   amountToPay = amount / ids.Count();
            BankLog log         = GetLog();

            foreach (long id in ids)
            {
                BankLogItem item = new BankLogItem();
                EconUtils.addMoney(id, amountToPay);
                bankBalance     -= amountToPay;
                item.SteamId     = steamid;
                item.Amount      = amount;
                item.Action      = "dividend";
                item.PlayerPaid  = MySession.Static.Players.TryGetSteamId(id);
                item.TimeClaimed = DateTime.Now;
                item.BankAmount  = bankBalance;
                log.log.Add(item);
            }
            utils.WriteToJsonFile <BankLog>(AlliancePlugin.path + "//AllianceBankLogs//" + AllianceId + "//log.json", log);
        }
Example #3
0
        public void BuyGrid(int number)
        {
            if (!list.items.ContainsKey(number))
            {
                Context.Respond("There is no item in the market for that slot number.");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }
            MarketItem item = list.items[number];

            if (!File.Exists(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json"))
            {
                Context.Respond("That grid is no longer available for sale.");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }
            if (!File.Exists(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"))
            {
                Context.Respond("This grid should be available, but its file for the grid doesnt exist.");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }
            if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition()))
            {
                Context.Respond("You cannot use this command in natural gravity!");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }

            foreach (DeniedLocation denied in AlliancePlugin.HangarDeniedLocations)
            {
                if (Vector3.Distance(Context.Player.GetPosition(), new Vector3(denied.x, denied.y, denied.z)) <= denied.radius)
                {
                    Context.Respond("Cannot buy here, too close to a denied location.");
                    confirmations.Remove(Context.Player.IdentityId);
                    return;
                }
            }
            if (EconUtils.getBalance(Context.Player.IdentityId) >= item.Price)
            {
                if (confirmations.ContainsKey(Context.Player.IdentityId))
                {
                    if (confirmations[Context.Player.IdentityId] >= DateTime.Now)
                    {
                        if (GridManager.LoadGrid(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml", Context.Player.GetPosition(), false, Context.Player.SteamUserId, item.Name))
                        {
                            EconUtils.takeMoney(Context.Player.IdentityId, item.Price);
                            long sellerId = MySession.Static.Players.TryGetIdentityId(item.SellerSteamId);
                            EconUtils.addMoney(sellerId, item.Price);
                            if (AlliancePlugin.GridBackupInstalled)
                            {
                                AlliancePlugin.BackupGridMethod(GridManager.GetObjectBuilders(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"), Context.Player.IdentityId);
                            }
                            item.Buyer  = Context.Player.SteamUserId;
                            item.soldAt = DateTime.Now;
                            item.Status = ItemStatus.Sold;
                            Context.Respond("The grid should appear near you.");
                            confirmations.Remove(Context.Player.IdentityId);
                            if (!Directory.Exists(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId))
                            {
                                Directory.CreateDirectory(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId);
                            }
                            list.items.Remove(number);

                            File.Delete(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json");
                            utils.WriteToJsonFile <MarketItem>(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId + "//" + item.ItemId, item);
                        }
                        else
                        {
                            Context.Respond("Failed to load the grid! transaction cancelled.");
                            return;
                        }
                    }
                    else
                    {
                        Context.Respond("Time ran out, start again");
                        confirmations[Context.Player.IdentityId] = DateTime.Now.AddSeconds(20);
                    }
                }
                else
                {
                    Context.Respond("Run command again within 20 seconds to confirm. Target grid name is " + item.Name + " Sold by " + AlliancePlugin.GetPlayerName(item.SellerSteamId));
                    confirmations.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(20));
                    Context.Respond("It costs " + String.Format("{0:n0}", item.Price) + " SC.");
                }
            }
            else
            {
                Context.Respond("You cannot afford that. It costs " + String.Format("{0:n0}", item.Price) + " SC.");
            }
        }
Example #4
0
        public void EndListing(int number)
        {
            if (!list.items.ContainsKey(number))
            {
                Context.Respond("There is no item in the market for that slot number.");
                return;
            }
            MarketItem item = list.items[number];

            if (!item.SellerSteamId.Equals(Context.Player.SteamUserId))
            {
                Context.Respond("This listing doesnt belong to you.");
                return;
            }
            if (!File.Exists(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json"))
            {
                Context.Respond("That grid is no longer available for sale.");
                return;
            }
            if (!File.Exists(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"))
            {
                Context.Respond("This grid should be available, but its file for the grid doesnt exist.");
                return;
            }
            if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition()))
            {
                Context.Respond("You cannot use this command in natural gravity!");
                return;
            }

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

            if (GridManager.LoadGrid(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml", Context.Player.GetPosition(), true, Context.Player.SteamUserId, item.Name))
            {
                EconUtils.takeMoney(Context.Player.IdentityId, item.Price);
                long sellerId = MySession.Static.Players.TryGetIdentityId(item.SellerSteamId);
                EconUtils.addMoney(sellerId, item.Price);
                if (AlliancePlugin.GridBackupInstalled)
                {
                    AlliancePlugin.BackupGridMethod(GridManager.GetObjectBuilders(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"), Context.Player.IdentityId);
                }
                item.Buyer  = Context.Player.SteamUserId;
                item.soldAt = DateTime.Now;
                if (!Directory.Exists(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId))
                {
                    Directory.CreateDirectory(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId);
                }
                list.items.Remove(number);
                File.Delete(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json");
                File.Delete(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml");
                Context.Respond("Ended the listing, the grid should appear near you.");
            }
            else
            {
                Context.Respond("Failed to load the grid! transaction cancelled.");
                return;
            }
        }