mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
Fix shops
This commit is contained in:
parent
395d86143d
commit
951ca83bed
3 changed files with 27 additions and 17 deletions
|
@ -21,14 +21,7 @@ namespace HISP.Game.Inventory
|
||||||
public ShopInventory(Shop shopkeeper)
|
public ShopInventory(Shop shopkeeper)
|
||||||
{
|
{
|
||||||
baseShop = shopkeeper;
|
baseShop = shopkeeper;
|
||||||
|
|
||||||
ItemInstance[] instances = Database.GetShopInventory(baseShop.Id).ToArray();
|
|
||||||
inventoryItems = new List<InventoryItem>();
|
inventoryItems = new List<InventoryItem>();
|
||||||
|
|
||||||
foreach (ItemInstance instance in instances)
|
|
||||||
{
|
|
||||||
addItem(instance, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addItem(ItemInstance item, bool addToDatabase)
|
private void addItem(ItemInstance item, bool addToDatabase)
|
||||||
|
@ -39,8 +32,13 @@ namespace HISP.Game.Inventory
|
||||||
{
|
{
|
||||||
if (invetoryItem.ItemId == item.ItemId)
|
if (invetoryItem.ItemId == item.ItemId)
|
||||||
{
|
{
|
||||||
if (invetoryItem.Infinite) // no need to add +1, theres allready infinite quanity.
|
if (invetoryItem.Infinite)
|
||||||
return;
|
{
|
||||||
|
addToDatabase = false;
|
||||||
|
goto retrn;
|
||||||
|
}
|
||||||
|
// no need to add +1, theres allready infinite quanity.
|
||||||
|
|
||||||
|
|
||||||
invetoryItem.AddItem(item);
|
invetoryItem.AddItem(item);
|
||||||
|
|
||||||
|
@ -54,7 +52,7 @@ namespace HISP.Game.Inventory
|
||||||
inventoryItem.Infinite = false;
|
inventoryItem.Infinite = false;
|
||||||
inventoryItem.AddItem(item);
|
inventoryItem.AddItem(item);
|
||||||
inventoryItems.Add(inventoryItem);
|
inventoryItems.Add(inventoryItem);
|
||||||
|
|
||||||
retrn:
|
retrn:
|
||||||
{
|
{
|
||||||
if (addToDatabase)
|
if (addToDatabase)
|
||||||
|
@ -78,6 +76,11 @@ namespace HISP.Game.Inventory
|
||||||
|
|
||||||
inventoryItems.Add(inventoryItem);
|
inventoryItems.Add(inventoryItem);
|
||||||
}
|
}
|
||||||
|
public void Add(ItemInstance item, bool addToDb)
|
||||||
|
{
|
||||||
|
addItem(item, addToDb);
|
||||||
|
}
|
||||||
|
|
||||||
public void Add(ItemInstance item)
|
public void Add(ItemInstance item)
|
||||||
{
|
{
|
||||||
addItem(item, true);
|
addItem(item, true);
|
||||||
|
@ -115,7 +118,7 @@ namespace HISP.Game.Inventory
|
||||||
int bias = 1000;
|
int bias = 1000;
|
||||||
int sortBy = Item.GetItemById(item.ItemId).SortBy;
|
int sortBy = Item.GetItemById(item.ItemId).SortBy;
|
||||||
if (item.Infinite)
|
if (item.Infinite)
|
||||||
sortBy += bias;
|
sortBy -= bias;
|
||||||
return sortBy;
|
return sortBy;
|
||||||
}
|
}
|
||||||
public InventoryItem[] GetItemList()
|
public InventoryItem[] GetItemList()
|
||||||
|
|
|
@ -14,18 +14,25 @@ namespace HISP.Game.Services
|
||||||
public int SellPricePercentage;
|
public int SellPricePercentage;
|
||||||
public ShopInventory Inventory;
|
public ShopInventory Inventory;
|
||||||
|
|
||||||
public Shop(int[] infiniteStocks)
|
public Shop(int[] infiniteStocks, int id)
|
||||||
{
|
{
|
||||||
this.Inventory = new ShopInventory(this);
|
this.Inventory = new ShopInventory(this);
|
||||||
|
this.Id = id;
|
||||||
|
|
||||||
|
foreach (int stock in infiniteStocks)
|
||||||
foreach(int stock in infiniteStocks)
|
|
||||||
{
|
{
|
||||||
if (Item.ItemIdExist(stock))
|
if (Item.ItemIdExist(stock))
|
||||||
this.Inventory.AddInfinity(Item.GetItemById(stock));
|
this.Inventory.AddInfinity(Item.GetItemById(stock));
|
||||||
else
|
else
|
||||||
Logger.WarnPrint("Item ID: " + stock + " Does not exist.");
|
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);
|
Shop.ShopList.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -398,9 +398,9 @@ namespace HISP.Server
|
||||||
int totalShops = gameData.shop_list.Count;
|
int totalShops = gameData.shop_list.Count;
|
||||||
for (int i = 0; i < totalShops; i++)
|
for (int i = 0; i < totalShops; i++)
|
||||||
{
|
{
|
||||||
|
int id = gameData.shop_list[i].id;
|
||||||
Shop shop = new Shop(gameData.shop_list[i].stocks_itemids.ToObject<int[]>());
|
int[] item_list = gameData.shop_list[i].stocks_itemids.ToObject<int[]>();
|
||||||
shop.Id = gameData.shop_list[i].id;
|
Shop shop = new Shop(item_list, id);
|
||||||
shop.BuyPricePercentage = gameData.shop_list[i].buy_percent;
|
shop.BuyPricePercentage = gameData.shop_list[i].buy_percent;
|
||||||
shop.SellPricePercentage = gameData.shop_list[i].sell_percent;
|
shop.SellPricePercentage = gameData.shop_list[i].sell_percent;
|
||||||
shop.BuysItemTypes = gameData.shop_list[i].buys_item_types.ToObject<string[]>();
|
shop.BuysItemTypes = gameData.shop_list[i].buys_item_types.ToObject<string[]>();
|
||||||
|
|
Loading…
Add table
Reference in a new issue