tdauth / wowr

Warcraft III: Reforged funmap World of Warcraft Reforged.
https://wowreforged.org
8 stars 0 forks source link

Create and release Item Craft System as separate map #1041

Open tdauth opened 1 year ago

tdauth commented 1 year ago
function CreateRecipe takes integer itemTypeId, integer researchId returns integer
function AddReceipeRequirement takes integer itemTypeId, integer charges returns nothing

// Stores a group of units which are used for crafting items.
function AddItemCraftInventory takes unit whichUnit returns nothing
function RemoveItemCraftInventory takes unit whichUnit returns nothing

function CraftItem takes integer recipe, unit crafter, unit buyingUnit returns item
// For only 1 charge
function ConsumeRecipeRequirements takes integer recipe, unit crafter returns integer
// For all charges available
function ConsumeAllRecipeRequirements takes integer recipe, unit crafter returns integer

This system here seems to be interesting: https://www.hiveworkshop.com/threads/recipe-system.326370/ It is very minimalistic and easy to use. It does not store the resulting itemTypeId for the crafted item, only the components.

tdauth commented 1 year ago

The callback trigger and function should exist only once in a list. Not per requirement and not per recipe. Also add callbacks for crafting items: function TriggerRegisterItemCraftEvent takes trigger whichTrigger returns nothing

The callback triggers for conditions can be used to allow certain recipes for certain units only. They should return a count. If the count is negative than the UI won't even be shown. Add a constants like:

constant integer ITEM_CRAFT_CHECK_RESULT_HIDE = -1 constant integer ITEM_CRAFT_CHECK_RESULT_NOT_AVAILABLE = 0

tdauth commented 1 year ago

Maybe add an optional feature to store item types per inventory in a hashtable with a count which makes the checks much faster:

hashtable itemCraftInventoryHashTable = InitHashTable()

function GetItemCraftInventoryCharges takes integer itemTypeId returns integer ... endfunction

The hashtable is always updated on picking up and dropping items.

It would save one inner loop per requirement and the complexity is only O(n*m): We have a loop via all recipes and an inner loop via all requirements.

The hashtable caching would only work if an item is never removed with RemoveItem etc.

tdauth commented 1 year ago

Allow combining multiple inventories:

function CombineItemCrafters takes unit crafter1, unit crafter2 returns group
function GetItemCrafters takes unit crafter returns group
function SplitItemCrafters takes unit crafter1, unit crafter2 returns group
function SplitItemCrafters takes unit crafter returns integer

This will allow using more than 6 different items to craft something really special.

tdauth commented 1 year ago

Allow specifying where the crafted item is put:

function SetRecipeTarget takes integer recipe, integer target returns nothing
constant integer RECIPE_TARGET_SELF = 0
constant integer RECIPE_TARGET_BUYING_UNIT = 1
constant integer RECIPE_TARGET_BUYING_GROUND = 2
tdauth commented 1 year ago

Allow an option for recipes if UI is shown even for recipe not possible. Hiding it would help to have more free slots:

function SetRecipeHideUIOnMissingRequirement takes integer recipe, boolean hide returns nothing
tdauth commented 1 month ago

Use structs for the Stashes and not too many hash table keys: