Skip to content

Commit

Permalink
Meret Market Search & Improvements (AlanMorel#544)
Browse files Browse the repository at this point in the history
* Meret Market Search

* Update MeretMarketItem.cs

* PR fixes
  • Loading branch information
Zintixx authored and gwagwaflamingo committed Aug 20, 2022
1 parent ef0d705 commit e1c2516
Show file tree
Hide file tree
Showing 18 changed files with 577 additions and 451 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3dc0c0165dad06442c382a2d0d273149
ff00f66718f6050ba229b5f280d02546
36 changes: 15 additions & 21 deletions GameDataParser/Parsers/MeretMarketCategoryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,37 @@ protected override List<MeretMarketCategoryMetadata> Parse()

MeretMarketSection section = (MeretMarketSection) int.Parse(node.Attributes["id"].Value);

// Temporary solution to display regular Meret Market items
if (section == MeretMarketSection.RedMeretMarket)
MeretMarketCategoryMetadata metadata = new()
{
continue;
}
Section = section,
};

foreach (XmlNode tabNode in node)
{
MeretMarketCategoryMetadata metadata = new()
MeretMarketTab tab = new()
{
Section = section,
CategoryId = int.Parse(tabNode.Attributes["id"].Value)
Id = int.Parse(tabNode.Attributes["id"].Value),
};

foreach (XmlNode subTabNode in tabNode.ChildNodes)
{
MeretMarketCategoryMetadata subTab = new()
{
Section = section,
CategoryId = int.Parse(subTabNode.Attributes["id"].Value)
};
if (subTabNode.Attributes["category"] is not null)
{
List<string> itemCategories = new();
itemCategories.AddRange(subTabNode.Attributes["category"].Value.Split(",").ToList());
subTab.ItemCategories = itemCategories;
metadata.ItemCategories.AddRange(itemCategories);
List<string> categoryList = subTabNode.Attributes["category"].Value.Split(",").ToList();
MeretMarketTab subTab = new()
{
Id = int.Parse(subTabNode.Attributes["id"].Value),
ItemCategories = categoryList
};
tab.ItemCategories.AddRange(categoryList);
metadata.Tabs.Add(subTab);
}

categories.Add(subTab);
}

categories.Add(metadata);
metadata.Tabs.Add(tab);
}
categories.Add(metadata);
}
}

return categories;
}
}
12 changes: 12 additions & 0 deletions Maple2Storage/Enums/MeretMarket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum MeretMarketSection
{
All = 0,
PremiumMarket = 100000,
RedMeretMarket = 100001,
UgcMarket = 110000
Expand Down Expand Up @@ -38,3 +39,14 @@ public enum MeretMarketPromoFlag
PinkGift = 1,
BlueGift = 2
}

public enum MeretMarketSort : short
{
None = 0,
MostPopularUgc = 1,
PriceLowest = 2,
PriceHighest = 3,
MostRecent = 4,
MostPopularPremium = 5,
TopSeller = 6
}
13 changes: 10 additions & 3 deletions Maple2Storage/Types/Metadata/MeretMarketCategoryMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ namespace Maple2Storage.Types.Metadata;
public class MeretMarketCategoryMetadata
{
[XmlElement(Order = 1)]
public int CategoryId;
[XmlElement(Order = 2)]
public MeretMarketSection Section;
[XmlElement(Order = 3)]
[XmlElement(Order = 2)]
public List<MeretMarketTab> Tabs = new();
}

[XmlType]
public class MeretMarketTab
{
[XmlElement(Order = 1)]
public int Id;
[XmlElement(Order = 2)]
public List<string> ItemCategories = new();
}
10 changes: 6 additions & 4 deletions MapleServer2/Data/Static/MeretMarketCategoryMetadataStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Maple2Storage.Types;
using Maple2Storage.Enums;
using Maple2Storage.Types;
using Maple2Storage.Types.Metadata;
using ProtoBuf;

Expand All @@ -14,12 +15,13 @@ public static void Init()
List<MeretMarketCategoryMetadata> items = Serializer.Deserialize<List<MeretMarketCategoryMetadata>>(stream);
foreach (MeretMarketCategoryMetadata item in items)
{
MeretMarketCategoryMetadatas[item.CategoryId] = item;
MeretMarketCategoryMetadatas[(int) item.Section] = item;
}
}

public static MeretMarketCategoryMetadata GetMetadata(int categoryId)
public static MeretMarketTab GetTabMetadata(MeretMarketSection section, int categoryId)
{
return MeretMarketCategoryMetadatas.GetValueOrDefault(categoryId);
MeretMarketCategoryMetadata metadata = MeretMarketCategoryMetadatas.GetValueOrDefault((int) section);
return metadata.Tabs.FirstOrDefault(x => x.Id == categoryId);
}
}
48 changes: 39 additions & 9 deletions MapleServer2/Database/Classes/DatabaseMeretMarket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Maple2Storage.Enums;
using MapleServer2.Database.Types;
using MapleServer2.Data.Static;
using MapleServer2.Enums;
using MapleServer2.PacketHandlers.Game.Helpers;
using MapleServer2.Types;
using SqlKata.Execution;

namespace MapleServer2.Database.Classes;
Expand All @@ -8,17 +11,44 @@ public class DatabaseMeretMarket : DatabaseTable
{
public DatabaseMeretMarket() : base("meret_market_items") { }

public List<MeretMarketItem> FindAllByCategoryId(MeretMarketCategory category)
public List<PremiumMarketItem> FindAllByCategory(MeretMarketSection section, MeretMarketCategory category, GenderFlag gender, JobFlag jobFlag, string searchString)
{
List<MeretMarketItem> items = new();
IEnumerable<dynamic> results = QueryFactory.Query(TableName).Where("category", (int) category).Get();
List<PremiumMarketItem> items = new();
IEnumerable<dynamic> results = QueryFactory.Query(TableName).Get();
if (section != MeretMarketSection.All)
{
results = QueryFactory.Query(TableName).Where("section", (int) section).Get();
}

foreach (dynamic data in results)
{
if (category != MeretMarketCategory.None && (MeretMarketCategory) data.category != category)
{
continue;
}

if (data.parent_market_id != 0)
{
continue;
}
MeretMarketItem meretMarketItem = ReadMeretMarketItem(data);
PremiumMarketItem meretMarketItem = ReadMeretMarketItem(data);

if (!meretMarketItem.ItemName.ToLower().Contains(searchString.ToLower()))
{
continue;
}

List<Job> jobs = ItemMetadataStorage.GetRecommendJobs(meretMarketItem.ItemId);
if (!JobHelper.CheckJobFlagForJob(jobs, jobFlag))
{
continue;
}

if (!MeretMarketHelper.CheckGender(gender, meretMarketItem.ItemId))
{
continue;
}

if (meretMarketItem.BannerId != 0)
{
meretMarketItem.Banner = DatabaseManager.Banners.FindById(meretMarketItem.BannerId);
Expand All @@ -30,27 +60,27 @@ public List<MeretMarketItem> FindAllByCategoryId(MeretMarketCategory category)
return items;
}

public MeretMarketItem FindById(int id)
public PremiumMarketItem FindById(int id)
{
return ReadMeretMarketItem(QueryFactory.Query(TableName).Where("market_id", id).Get().FirstOrDefault());
}

private MeretMarketItem ReadMeretMarketItem(dynamic data)
{
MeretMarketItem item = new(data);
PremiumMarketItem item = new(data);

//Find additional quantities
IEnumerable<dynamic> results = QueryFactory.Query(TableName).Where("parent_market_id", item.MarketId).Get();
foreach (dynamic result in results)
{
MeretMarketItem meretMarketItem = ReadAdditionalQuantityMarketItem(result);
PremiumMarketItem meretMarketItem = ReadAdditionalQuantityMarketItem(result);
item.AdditionalQuantities.Add(meretMarketItem);
}

return item;
}

private static MeretMarketItem ReadAdditionalQuantityMarketItem(dynamic data)
private static PremiumMarketItem ReadAdditionalQuantityMarketItem(dynamic data)
{
return new(data);
}
Expand Down
4 changes: 2 additions & 2 deletions MapleServer2/Database/Classes/DatabaseUgcMarketItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public long Insert(UgcMarketItem item)
{
return QueryFactory.Query(TableName).InsertGetId<long>(new
{
id = item.Id,
id = item.MarketId,
price = item.Price,
item_uid = item.Item.Uid,
status = item.Status,
Expand All @@ -31,7 +31,7 @@ public long Insert(UgcMarketItem item)

public void Update(UgcMarketItem item)
{
QueryFactory.Query(TableName).Where("id", item.Id).Update(new
QueryFactory.Query(TableName).Where("id", item.MarketId).Update(new
{
sales_count = item.SalesCount,
status = (byte) item.Status,
Expand Down
3 changes: 2 additions & 1 deletion MapleServer2/Database/SQL/Database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ CREATE TABLE `ugc_market_items`
CONSTRAINT `fk_ugc_market_listing_account_id` FOREIGN KEY (`seller_account_id`) REFERENCES `characters` (`character_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;
COLLATE = utf8mb4_0900_ai_ci
AUTO_INCREMENT = 100000;

--
-- Table structure for table `ugc_market_sales`
Expand Down
Loading

0 comments on commit e1c2516

Please sign in to comment.