Fix being able to buy shit you cant afford

This commit is contained in:
Bluzume 2021-11-28 03:15:52 -05:00
parent 520ca3b159
commit 0c89845552
4 changed files with 14 additions and 12 deletions

View file

@ -66,7 +66,7 @@ namespace HISP.Game
public int GetTeardownPrice() public int GetTeardownPrice()
{ {
return (int)Math.Round((float)this.Cost / (100 / 35.0)); return Convert.ToInt32(Math.Round((float)this.Cost / (100 / 35.0)));
} }
} }
public static List<Ranch> Ranches = new List<Ranch>(); public static List<Ranch> Ranches = new List<Ranch>();
@ -84,7 +84,7 @@ namespace HISP.Game
public int GetSellPrice() public int GetSellPrice()
{ {
return (int)Math.Round((float)this.InvestedMoney / (100 / 75.0)); return Convert.ToInt32(Math.Round((double)this.InvestedMoney / (100 / 75.0)));
} }
private void removeDorothyShoes(int Id) private void removeDorothyShoes(int Id)
{ {

View file

@ -25,7 +25,7 @@ namespace HISP.Game.Services
public int BuyPercentage; public int BuyPercentage;
public int CalculateBuyCost(Item.ItemInformation item) public int CalculateBuyCost(Item.ItemInformation item)
{ {
return (int)Math.Floor((float)item.SellPrice * (100.0 / (float)BuyPercentage)); return Convert.ToInt32(Math.Floor((float)item.SellPrice * (100.0 / (float)BuyPercentage)));
} }
public Item.ItemInformation GetStockedItem(int itemId) public Item.ItemInformation GetStockedItem(int itemId)

View file

@ -38,11 +38,11 @@ namespace HISP.Game.Services
public UInt64 CalculateBuyCost(Item.ItemInformation item) public UInt64 CalculateBuyCost(Item.ItemInformation item)
{ {
return (UInt64)Math.Round((float)item.SellPrice * (100.0 / (float)BuyPricePercentage)); return Convert.ToUInt64(Math.Round((double)item.SellPrice * (100.0 / (double)BuyPricePercentage)));
} }
public UInt64 CalculateSellCost(Item.ItemInformation item) public UInt64 CalculateSellCost(Item.ItemInformation item)
{ {
return (UInt64)Math.Round((float)item.SellPrice * (100.0 / (float)SellPricePercentage)); return Convert.ToUInt64(Math.Round((double)item.SellPrice * (100.0 / (double)SellPricePercentage)));
} }
public bool CanSell(Item.ItemInformation item) public bool CanSell(Item.ItemInformation item)

View file

@ -6909,11 +6909,11 @@ namespace HISP.Server
Shop shop = sender.LoggedinUser.LastShoppedAt; Shop shop = sender.LoggedinUser.LastShoppedAt;
if (shop != null) if (shop != null)
{ {
UInt64 sellPrice = (shop.CalculateSellCost(itemInfo) * (UInt64)totalSold); UInt64 sellPrice = Convert.ToUInt32(shop.CalculateSellCost(itemInfo) * Convert.ToUInt32(totalSold));
if (shop.CanSell(itemInfo)) if (shop.CanSell(itemInfo))
{ {
// Check if goes over 2.1b // Check if goes over 2.1b
if ((UInt64)sender.LoggedinUser.Money + sellPrice > 2100000000) if (Convert.ToUInt32(sender.LoggedinUser.Money) + sellPrice > 2100000000)
{ {
byte[] cantSellMoneyCapCheck = PacketBuilder.CreateChat(Messages.CannotSellYoudGetTooMuchMoney, PacketBuilder.CHAT_BOTTOM_RIGHT); byte[] cantSellMoneyCapCheck = PacketBuilder.CreateChat(Messages.CannotSellYoudGetTooMuchMoney, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(cantSellMoneyCapCheck); sender.SendPacket(cantSellMoneyCapCheck);
@ -6928,7 +6928,8 @@ namespace HISP.Server
shop.Inventory.Add(itemInstance); shop.Inventory.Add(itemInstance);
} }
sender.LoggedinUser.AddMoney((int)sellPrice); if (sellPrice < 2147483647) // Sanity Check (yes i checked it earlier)
sender.LoggedinUser.AddMoney(Convert.ToInt32(sellPrice));
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true); UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true);
if(message == 1) if(message == 1)
@ -7059,7 +7060,7 @@ namespace HISP.Server
shop = sender.LoggedinUser.LastShoppedAt; shop = sender.LoggedinUser.LastShoppedAt;
if (shop != null) if (shop != null)
{ {
UInt64 buyCost = (shop.CalculateBuyCost(itemInfo) * (UInt64)count); UInt64 buyCost = Convert.ToUInt64(shop.CalculateBuyCost(itemInfo) * Convert.ToUInt64(count));
if (sender.LoggedinUser.Bids.Length > 0) if (sender.LoggedinUser.Bids.Length > 0)
{ {
byte[] cantBuyWhileAuctioning = PacketBuilder.CreateChat(Messages.AuctionNoOtherTransactionAllowed, PacketBuilder.CHAT_BOTTOM_RIGHT); byte[] cantBuyWhileAuctioning = PacketBuilder.CreateChat(Messages.AuctionNoOtherTransactionAllowed, PacketBuilder.CHAT_BOTTOM_RIGHT);
@ -7067,7 +7068,7 @@ namespace HISP.Server
return; return;
} }
if ((UInt64)sender.LoggedinUser.Money < buyCost) if (Convert.ToUInt64(sender.LoggedinUser.Money) < buyCost)
{ {
byte[] cantAffordMessage = PacketBuilder.CreateChat(Messages.CantAfford1, PacketBuilder.CHAT_BOTTOM_RIGHT); byte[] cantAffordMessage = PacketBuilder.CreateChat(Messages.CantAfford1, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(cantAffordMessage); sender.SendPacket(cantAffordMessage);
@ -7086,7 +7087,7 @@ namespace HISP.Server
if (sender.LoggedinUser.Inventory.HasItemId(itemId)) if (sender.LoggedinUser.Inventory.HasItemId(itemId))
{ {
InventoryItem items = sender.LoggedinUser.Inventory.GetItemByItemId(itemId); InventoryItem items = sender.LoggedinUser.Inventory.GetItemByItemId(itemId);
if (items.ItemInstances.Length + (int)count > Item.MAX_STACK) if (items.ItemInstances.Length + count > Item.MAX_STACK)
{ {
goto showError; goto showError;
} }
@ -7112,7 +7113,8 @@ namespace HISP.Server
shop.Inventory.Remove(itemInstance); shop.Inventory.Remove(itemInstance);
} }
sender.LoggedinUser.TakeMoney((int)buyCost); if(buyCost < 2147483647) // Sanity Check (yes i checked it earlier)
sender.LoggedinUser.TakeMoney(Convert.ToInt32(buyCost));
// Send chat message to client. // Send chat message to client.