Fix shops

This commit is contained in:
Bluzume 2021-11-09 23:20:55 -05:00
parent 395d86143d
commit 951ca83bed
3 changed files with 27 additions and 17 deletions

View file

@ -21,14 +21,7 @@ namespace HISP.Game.Inventory
public ShopInventory(Shop shopkeeper)
{
baseShop = shopkeeper;
ItemInstance[] instances = Database.GetShopInventory(baseShop.Id).ToArray();
inventoryItems = new List<InventoryItem>();
foreach (ItemInstance instance in instances)
{
addItem(instance, false);
}
}
private void addItem(ItemInstance item, bool addToDatabase)
@ -39,8 +32,13 @@ namespace HISP.Game.Inventory
{
if (invetoryItem.ItemId == item.ItemId)
{
if (invetoryItem.Infinite) // no need to add +1, theres allready infinite quanity.
return;
if (invetoryItem.Infinite)
{
addToDatabase = false;
goto retrn;
}
// no need to add +1, theres allready infinite quanity.
invetoryItem.AddItem(item);
@ -54,7 +52,7 @@ namespace HISP.Game.Inventory
inventoryItem.Infinite = false;
inventoryItem.AddItem(item);
inventoryItems.Add(inventoryItem);
retrn:
{
if (addToDatabase)
@ -78,6 +76,11 @@ namespace HISP.Game.Inventory
inventoryItems.Add(inventoryItem);
}
public void Add(ItemInstance item, bool addToDb)
{
addItem(item, addToDb);
}
public void Add(ItemInstance item)
{
addItem(item, true);
@ -115,7 +118,7 @@ namespace HISP.Game.Inventory
int bias = 1000;
int sortBy = Item.GetItemById(item.ItemId).SortBy;
if (item.Infinite)
sortBy += bias;
sortBy -= bias;
return sortBy;
}
public InventoryItem[] GetItemList()

View file

@ -14,18 +14,25 @@ namespace HISP.Game.Services
public int SellPricePercentage;
public ShopInventory Inventory;
public Shop(int[] infiniteStocks)
public Shop(int[] infiniteStocks, int id)
{
this.Inventory = new ShopInventory(this);
this.Id = id;
foreach(int stock in infiniteStocks)
foreach (int stock in infiniteStocks)
{
if (Item.ItemIdExist(stock))
this.Inventory.AddInfinity(Item.GetItemById(stock));
else
Logger.WarnPrint("Item ID: " + stock + " Does not exist.");
}
ItemInstance[] instances = Database.GetShopInventory(this.Id);
foreach (ItemInstance instance in instances)
{
this.Inventory.Add(instance, false);
}
Shop.ShopList.Add(this);
}

View file

@ -398,9 +398,9 @@ namespace HISP.Server
int totalShops = gameData.shop_list.Count;
for (int i = 0; i < totalShops; i++)
{
Shop shop = new Shop(gameData.shop_list[i].stocks_itemids.ToObject<int[]>());
shop.Id = gameData.shop_list[i].id;
int id = gameData.shop_list[i].id;
int[] item_list = gameData.shop_list[i].stocks_itemids.ToObject<int[]>();
Shop shop = new Shop(item_list, id);
shop.BuyPricePercentage = gameData.shop_list[i].buy_percent;
shop.SellPricePercentage = gameData.shop_list[i].sell_percent;
shop.BuysItemTypes = gameData.shop_list[i].buys_item_types.ToObject<string[]>();