Add shop inventory (0/1)

This commit is contained in:
SilicaAndPina 2020-11-06 13:32:46 +13:00
parent e22eca485d
commit 8763524116
12 changed files with 383 additions and 43 deletions

View file

@ -4,16 +4,6 @@ using System.Collections.Generic;
namespace HISP.Game
{
class InventoryItem
{
public InventoryItem()
{
ItemInstances = new List<ItemInstance>();
}
public int ItemId;
public List<ItemInstance> ItemInstances;
}
interface IInventory
{

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace HISP.Game
{
class InventoryItem
{
public InventoryItem()
{
ItemInstances = new List<ItemInstance>();
Infinite = false;
ItemId = 0;
}
public int ItemId;
public bool Infinite;
public List<ItemInstance> ItemInstances;
}
}

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace HISP.Game
{

View file

@ -24,6 +24,10 @@ namespace HISP.Game
// Records
public static string ProfileSavedMessage;
// Hay Pile
public static string HasPitchforkMeta;
public static string NoPitchforkMeta;
// Chat
public static string GlobalChatFormat;
public static string AdsChatFormat;

View file

@ -173,14 +173,37 @@ namespace HISP.Game
if (specialTile.Code == null)
message += buildCommonInfo(specialTile.X, specialTile.Y);
if (specialTile.Code == "TRANSPORT")
else
user.MetaPriority = true;
string TileCode = specialTile.Code;
string TileArg = "";
if (TileCode.Contains("-"))
{
TileCode = TileCode.Split('-')[0];
TileArg = TileCode.Split('-')[1];
}
if (TileCode == "TRANSPORT")
{
Transport.TransportPoint point = Transport.GetTransportPoint(specialTile.X, specialTile.Y);
message += Meta.BuildTransportInfo(point)+ "^R1";
}
if (specialTile.ExitX != 0 && specialTile.ExitY != 0)
message += Messages.ExitThisPlace + Messages.MetaTerminator;
if (TileCode == "STRAWPILE")
{
if (user.Inventory.HasItemId(Item.Pitchfork))
message += Messages.HasPitchforkMeta;
else
message += Messages.NoPitchforkMeta;
}
if(TileCode == "STORE")
{
}
return message;
@ -233,6 +256,7 @@ namespace HISP.Game
Quest.QuestEntry quest = Quest.GetQuestById(chatpoint.ActivateQuestId);
if (Quest.ActivateQuest(user, quest, true))
{
user.MetaPriority = true;
if(quest.GotoNpcChatpoint != -1)
chatpoint = Npc.GetNpcChatpoint(npc,quest.GotoNpcChatpoint);
if (quest.SuccessNpcChat != null)

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
namespace HISP.Game
{
class Shop
{
public int Id;
public string[] BuysItemTypes;
public int BuyPricePercentage;
public int SellPricePercentage;
public int[] InfniteStocks;
ShopInventory Inventory;
public Shop()
{
Id = shopList.Count;
Inventory = new ShopInventory(this);
shopList.Add(this);
}
public int CalculateBuyCost(Item.ItemInformation item)
{
return Math.Abs(item.SellPrice * (100 / BuyPricePercentage));
}
public int CalculateSellCost(Item.ItemInformation item)
{
return Math.Abs(item.SellPrice * (100 / SellPricePercentage));
}
// Static Functions
private static List<Shop> shopList = new List<Shop>();
public static Shop GetShopById(int id)
{
return shopList[id];
}
}
}

View file

@ -0,0 +1,93 @@
using HISP.Server;
using System;
using System.Collections.Generic;
namespace HISP.Game
{
class ShopInventory : IInventory
{
private Shop baseShop;
private List<InventoryItem> inventoryItems;
public int Count
{
get
{
return inventoryItems.Count;
}
}
public ShopInventory(Shop shopkeeper)
{
baseShop = shopkeeper;
ItemInstance[] instances = Database.GetShopInventory(baseShop.Id).ToArray();
foreach (ItemInstance instance in instances)
{
addItem(instance, false);
}
}
private void addItem(ItemInstance item, bool addToDatabase)
{
if (addToDatabase)
Database.AddItemToInventory(baseShop.Id, item);
foreach (InventoryItem invetoryItem in inventoryItems)
{
if (invetoryItem.ItemId == item.ItemId)
{
invetoryItem.ItemInstances.Add(item);
return;
}
}
InventoryItem inventoryItem = new InventoryItem();
inventoryItem.ItemId = item.ItemId;
inventoryItem.ItemInstances.Add(item);
inventoryItems.Add(inventoryItem);
}
public void AddInfinity(Item.ItemInformation itemInfo)
{
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));
}
public void Add(ItemInstance item)
{
addItem(item, true);
}
public InventoryItem GetItemByItemId(int itemId)
{
throw new NotImplementedException();
}
public InventoryItem GetItemByRandomid(int randomId)
{
throw new NotImplementedException();
}
public InventoryItem[] GetItemList()
{
throw new NotImplementedException();
}
public bool HasItem(int randomId)
{
throw new NotImplementedException();
}
public bool HasItemId(int itemId)
{
throw new NotImplementedException();
}
public void Remove(ItemInstance item)
{
throw new NotImplementedException();
}
}
}