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();
}
}
}

View file

@ -72,7 +72,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Game\InventoryItem.cs" />
<Compile Include="Game\Quest.cs" />
<Compile Include="Game\Shop.cs" />
<Compile Include="Game\ShopInventory.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>

View file

@ -21,6 +21,7 @@ namespace HISP.Server
string BuddyTable = "CREATE TABLE BuddyList(Id INT, IdFriend INT, Pending BOOL)";
string WorldTable = "CREATE TABLE World(Time INT,Day INT, Year INT, Weather TEXT(64))";
string InventoryTable = "CREATE TABLE Inventory(PlayerID INT, RandomID INT, ItemID INT)";
string ShopInventory = "CREATE TABLE ShopInventroy(ShopID INT, RandomID INT, ItemID INT)";
string DroppedItems = "CREATE TABLE DroppedItems(X INT, Y INT, RandomID INT, ItemID INT, DespawnTimer INT)";
string TrackedQuest = "CREATE TABLE TrackedQuest(playerId INT, questId INT, timesCompleted INT)";
@ -102,10 +103,21 @@ namespace HISP.Server
Logger.WarnPrint(e.Message);
};
try
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = ShopInventory;
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
catch (Exception e)
{
Logger.WarnPrint(e.Message);
};
try
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = TrackedQuest;
sqlCommand.ExecuteNonQuery();
@ -259,28 +271,6 @@ namespace HISP.Server
}
}
public static List<ItemInstance> GetPlayerInventory(int playerId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT ItemId,RandomId FROM Inventory WHERE PlayerId=@playerId";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Prepare();
MySqlDataReader reader = sqlCommand.ExecuteReader();
List<ItemInstance> instances = new List<ItemInstance>();
while(reader.Read())
{
instances.Add(new ItemInstance(reader.GetInt32(0), reader.GetInt32(1)));
}
sqlCommand.Dispose();
return instances;
}
}
public static int GetTrackedQuestCompletedCount(int playerId, int questId)
{
if(CheckTrackeQuestExists(playerId,questId))
@ -389,6 +379,83 @@ namespace HISP.Server
sqlCommand.Dispose();
}
}
public static List<ItemInstance> GetShopInventory(int shopId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT ItemId,RandomId FROM ShopInventory WHERE ShopID=@shopId";
sqlCommand.Parameters.AddWithValue("@shopId", shopId);
sqlCommand.Prepare();
MySqlDataReader reader = sqlCommand.ExecuteReader();
List<ItemInstance> instances = new List<ItemInstance>();
while (reader.Read())
{
instances.Add(new ItemInstance(reader.GetInt32(0), reader.GetInt32(1)));
}
sqlCommand.Dispose();
return instances;
}
}
public static void AddItemToShopInventory(int shopId, ItemInstance instance)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO ShopInventory VALUES(@shopId,@randomId,@itemId)";
sqlCommand.Parameters.AddWithValue("@shopId", shopId);
sqlCommand.Parameters.AddWithValue("@randomId", instance.RandomId);
sqlCommand.Parameters.AddWithValue("@itemId", instance.ItemId);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static void RemoveItemFromShopInventory(int shopId, ItemInstance instance)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "DELETE FROM ShopInventory WHERE (ShopID=@shopId AND RandomId=@randomId)";
sqlCommand.Parameters.AddWithValue("@shopId", shopId);
sqlCommand.Parameters.AddWithValue("@randomId", instance.RandomId);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static List<ItemInstance> GetPlayerInventory(int playerId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT ItemId,RandomId FROM Inventory WHERE PlayerId=@playerId";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Prepare();
MySqlDataReader reader = sqlCommand.ExecuteReader();
List<ItemInstance> instances = new List<ItemInstance>();
while (reader.Read())
{
instances.Add(new ItemInstance(reader.GetInt32(0), reader.GetInt32(1)));
}
sqlCommand.Dispose();
return instances;
}
}
public static void AddItemToInventory(int playerId, ItemInstance instance)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))

View file

@ -204,6 +204,7 @@ namespace HISP.Server
return;
}
}
}

View file

@ -437,6 +437,10 @@ namespace HISP.Server
Messages.South = gameData.messages.meta.nearby.south;
Messages.West = gameData.messages.meta.nearby.west;
Messages.NoPitchforkMeta = gameData.messages.meta.hay_pile.no_pitchfork;
Messages.HasPitchforkMeta = gameData.messages.meta.hay_pile.pitchfork;
// Inventory
Messages.InventoryHeaderFormat = gameData.messages.meta.inventory.header_format;