Add shop info .

This commit is contained in:
SilicaAndPina 2020-11-06 21:22:15 +13:00
parent 8763524116
commit 9705e9889f
8 changed files with 253 additions and 43 deletions

View file

@ -74,15 +74,30 @@ namespace HISP.Game
// Inventory
public static string InventoryItemFormat;
public static string InventoryHeaderFormat;
public static string ItemDropButton;
public static string ItemInformationButton;
public static string ItemInformationByIdButton;
public static string ItemConsumeButton;
public static string ItemThrowButton;
public static string ItemUseButton;
public static string ItemReadButton;
public static string ShopEntryFormat;
public static string ShopBuyButton;
public static string ShopBuy5Button;
public static string ShopBuy25Button;
public static string SellButton;
public static string SellAllButton;
// Shop
public static string ThingsIAmSelling;
public static string ThingsYouSellMe;
public static string InfinitySign;
// Npc
public static string NpcStartChatFormat;
public static string NpcChatpointFormat;
@ -123,6 +138,38 @@ namespace HISP.Game
public static string WagonCutscene;
public static string BallonCutscene;
public static string FormatShopEntry(int iconid, string count, string name, int price)
{
return ShopEntryFormat.Replace("%ICONID%", iconid.ToString()).Replace("%COUNT%", count).Replace("%TITLE%", name).Replace("%PRICE%", price.ToString());
}
public static string FormatItemInformationByIdButton(int itemId)
{
return ItemInformationByIdButton.Replace("%ITEMID%", itemId.ToString());
}
public static string FormatBuyItemButton(int itemId)
{
return ShopBuyButton.Replace("%ITEMID%", itemId.ToString());
}
public static string FormatBuy5ItemButton(int itemId)
{
return ShopBuy5Button.Replace("%ITEMID%", itemId.ToString());
}
public static string FormatBuy25ItemButton(int itemId)
{
return ShopBuy25Button.Replace("%ITEMID%", itemId.ToString());
}
public static string ForamtSellButton(int randomId)
{
return SellButton.Replace("%RANDOMID%", randomId.ToString());
}
public static string FormatSellAllButton(int itemId)
{
return SellAllButton.Replace("%ITEMID%", itemId.ToString());
}
public static string FormatNpcInformation(string name, string description)
{
return NpcInformationFormat.Replace("%NAME%", name).Replace("%DESCRIPTION%", description);

View file

@ -74,6 +74,37 @@ namespace HISP.Game
return playersNearby;
}
private static string buildShopInfo(Shop shop)
{
string message = "";
InventoryItem[] itemList = shop.Inventory.GetItemList();
message += Messages.ThingsIAmSelling;
foreach (InventoryItem item in itemList)
{
message += "^R1";
Item.ItemInformation itemInfo = Item.GetItemById(item.ItemId);
int count = item.ItemInstances.Count;
string countStr = count.ToString();
if (item.Infinite)
countStr = Messages.InfinitySign;
message += Messages.FormatShopEntry(itemInfo.IconId, countStr, itemInfo.Name, shop.CalculateBuyCost(itemInfo));
message += Messages.FormatBuyItemButton(itemInfo.Id);
if (count >= 5)
message += Messages.FormatBuy5ItemButton(itemInfo.Id);
if (count >= 25)
message += Messages.FormatBuy25ItemButton(itemInfo.Id);
message += Messages.FormatItemInformationByIdButton(itemInfo.Id);
}
return message;
}
private static string buildCommonInfo(int x, int y)
{
string message = "";
@ -174,34 +205,41 @@ namespace HISP.Game
if (specialTile.Code == null)
message += buildCommonInfo(specialTile.X, specialTile.Y);
else
{
user.MetaPriority = true;
string TileCode = specialTile.Code;
string TileArg = "";
if (TileCode.Contains("-"))
{
string TileCode = specialTile.Code;
TileCode = TileCode.Split('-')[0];
TileArg = TileCode.Split('-')[1];
}
string TileArg = "";
if (TileCode.Contains("-"))
{
TileArg = TileCode.Split('-')[1];
TileCode = TileCode.Split('-')[0];
}
if (TileCode == "TRANSPORT")
{
Transport.TransportPoint point = Transport.GetTransportPoint(specialTile.X, specialTile.Y);
message += Meta.BuildTransportInfo(point)+ "^R1";
}
if (TileCode == "STRAWPILE")
{
if (user.Inventory.HasItemId(Item.Pitchfork))
message += Messages.HasPitchforkMeta;
else
message += Messages.NoPitchforkMeta;
}
if (TileCode == "TRANSPORT")
{
Transport.TransportPoint point = Transport.GetTransportPoint(specialTile.X, specialTile.Y);
message += Meta.BuildTransportInfo(point) + "^R1";
}
if(TileCode == "STORE")
{
if (TileCode == "STRAWPILE")
{
if (user.Inventory.HasItemId(Item.Pitchfork))
message += Messages.HasPitchforkMeta;
else
message += Messages.NoPitchforkMeta;
}
if (TileCode == "STORE")
{
int ShopID = int.Parse(TileArg);
Shop shop = Shop.GetShopById(ShopID);
user.LastShoppedAt = shop;
message += buildShopInfo(shop);
}
}

View file

@ -1,4 +1,5 @@
using System;
using HISP.Server;
using System;
using System.Collections.Generic;
namespace HISP.Game
@ -10,14 +11,22 @@ namespace HISP.Game
public string[] BuysItemTypes;
public int BuyPricePercentage;
public int SellPricePercentage;
public int[] InfniteStocks;
ShopInventory Inventory;
public ShopInventory Inventory;
public Shop()
public Shop(int[] infiniteStocks)
{
Id = shopList.Count;
Inventory = new ShopInventory(this);
shopList.Add(this);
Id = ShopList.Count+1;
this.Inventory = new ShopInventory(this);
foreach(int stock in infiniteStocks)
{
if (Item.ItemIdExist(stock))
this.Inventory.AddInfinity(Item.GetItemById(stock));
else
Logger.WarnPrint("Item ID: " + stock + " Does not exist.");
}
Shop.ShopList.Add(this);
}
public int CalculateBuyCost(Item.ItemInformation item)
@ -29,13 +38,22 @@ namespace HISP.Game
return Math.Abs(item.SellPrice * (100 / SellPricePercentage));
}
public bool CanSell(Item.ItemInformation item)
{
foreach(string ItemType in BuysItemTypes)
{
if(ItemType == item.Type)
{
return true;
}
}
return false;
}
// Static Functions
private static List<Shop> shopList = new List<Shop>();
public static List<Shop> ShopList = new List<Shop>();
public static Shop GetShopById(int id)
{
return shopList[id];
return ShopList[id-1];
}
}

View file

@ -1,6 +1,7 @@
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
namespace HISP.Game
{
@ -20,6 +21,8 @@ namespace HISP.Game
baseShop = shopkeeper;
ItemInstance[] instances = Database.GetShopInventory(baseShop.Id).ToArray();
inventoryItems = new List<InventoryItem>();
foreach (ItemInstance instance in instances)
{
addItem(instance, false);
@ -43,6 +46,7 @@ namespace HISP.Game
InventoryItem inventoryItem = new InventoryItem();
inventoryItem.ItemId = item.ItemId;
inventoryItem.Infinite = false;
inventoryItem.ItemInstances.Add(item);
inventoryItems.Add(inventoryItem);
}
@ -52,8 +56,11 @@ namespace HISP.Game
InventoryItem inventoryItem = new InventoryItem();
inventoryItem.ItemId = itemInfo.Id;
inventoryItem.Infinite = true;
for(int i = 0; i < 25; i++) // add 25
inventoryItem.ItemInstances.Add(new ItemInstance(inventoryItem.ItemId));
inventoryItems.Add(inventoryItem);
}
public void Add(ItemInstance item)
{
@ -62,32 +69,93 @@ namespace HISP.Game
public InventoryItem GetItemByItemId(int itemId)
{
throw new NotImplementedException();
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
if (item.ItemId == itemId)
{
return item;
}
}
throw new KeyNotFoundException("id: " + itemId + " not found in shop inventory");
}
public InventoryItem GetItemByRandomid(int randomId)
{
throw new NotImplementedException();
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
ItemInstance[] instances = item.ItemInstances.ToArray();
foreach (ItemInstance instance in instances)
{
if (instance.RandomId == randomId)
return item;
}
}
throw new KeyNotFoundException("random id: " + randomId + " not found in shop inventory");
}
public InventoryItem[] GetItemList()
{
throw new NotImplementedException();
return inventoryItems.OrderBy(o => o.ItemInstances[0].GetItemInfo().SortBy).OrderBy(o => o.Infinite).ToArray();
}
public bool HasItem(int randomId)
{
throw new NotImplementedException();
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
ItemInstance[] instances = item.ItemInstances.ToArray();
foreach (ItemInstance instance in instances)
{
if (instance.RandomId == randomId)
return true;
}
}
return false;
}
public bool HasItemId(int itemId)
{
throw new NotImplementedException();
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
if (item.ItemId == itemId)
{
return true;
}
}
return false;
}
public void Remove(ItemInstance item)
{
throw new NotImplementedException();
foreach (InventoryItem inventoryItem in inventoryItems)
{
if (item.ItemId == inventoryItem.ItemId)
{
foreach (ItemInstance instance in inventoryItem.ItemInstances)
{
if (instance.RandomId == item.RandomId)
{
inventoryItem.ItemInstances.Remove(instance);
if (inventoryItem.ItemInstances.Count <= 0)
inventoryItems.Remove(inventoryItem);
if (!inventoryItem.Infinite) // no need to bug the database.
Database.RemoveItemFromShopInventory(baseShop.Id, item);
else
inventoryItem.ItemInstances.Add(new ItemInstance(inventoryItem.ItemId)); // Gen new item in inventory to replace it.
return;
}
}
}
}
Logger.ErrorPrint("Tried to remove item : " + item.RandomId + " from inventory when it was not in it");
}
}
}