Skip to content

Forge and economy

This guide is about the rules that sit around the content: the forge where players enchant equipment, the timers that decide how long orders and rounds take, and the economy that decides what things cost. All of these run once, from your entry script, and all of them assume local sf2 = require("sf2") and a core dependency in mod.toml.

When players enchant a piece of equipment, the forge uses a recipe. A recipe says which equipment categories it can enchant, which enchantments it can pick from (its candidates), and which price profile it uses. A price profile lists how many forge materials (three kinds, numbered 1 to 3) one enchantment costs.

The game ships three recipes, Simple, Medium and Complex, and the price profiles with the same names. Without mods the forge lists only Simple and Medium: Complex appears once an enabled mod patches it with sf2.forge.patch (a candidate, an exclusion, a power range or a choose setup naming the Complex recipe or profile). Out of the box the forge is a lottery:

  • A recipe is offered for an item when it covers the item’s category and at least one candidate fits the item.
  • When the player enchants, the forge shuffles the candidates and keeps the ones that are ready and not already on the item, until it has the number the recipe gives. If nothing qualifies, nothing happens and nothing is spent.
  • A set enchantment is ready only when the player owns every item of its set. Other enchantments are always ready. A combo perk your mod registers has a set only if you give it one (see Your own set enchantment); until then it is always ready.
  • Every candidate has the same chance. Listing an enchantment twice gives it two chances.
  • The power of an enchantment is the level’s base value plus a random amount from the recipe item’s deviation range.

Your mod can add enchantments to this system, add recipes of its own, or change the existing ones.

First register an enchantment (see Perks and enchantments), then a recipe that offers it:

local training_perk = sf2.perks.register {
id = "training_edge",
display_name = sf2.text.get("perk.training_edge"),
description = sf2.text.get("perk.training_edge.description"),
behavior = {
on_damage_dealt = function(_, fighter, event)
fighter:add_magic_charge(0.01)
end,
},
enchantment = { recipe = "simple", item_types = { "weapon" } },
}
local recipe = sf2.forge.register {
id = "training_recipe",
profile = sf2.forge.get("Simple"),
items = { { equipment = "weapon", enchantments = 1 } },
candidates = {
{ perk = training_perk, equipment = "weapon", min_level = 1, max_level = 52 },
},
}

sf2.forge.get returns an existing price profile ("Simple", "Medium" or "Complex"). A recipe is described by:

Field Required? Meaning
id Yes A local ID.
profile Yes The price profile, from sf2.forge.get or one you registered.
items Yes One entry per equipment category the recipe handles: equipment (required), enchantments (how many to give, default 1), min_deviation, max_deviation and random_aspect (the power range).
candidates Yes The enchantments it can pick: perk and equipment are required; min_level and max_level are optional limits on the item’s level.
alias No An alternative name.

Registering a recipe never changes the game’s own recipes. An enchantment still needs to be offered by a recipe (yours or an existing one) before players can obtain it. The forge lists a recipe’s candidates in the order you give them.

A set enchantment (a perk registered with kind = "combo") belongs to a set of items, like the game’s Monk or Sentinel sets. Register that set with the perk in its perk field, and the forge treats your enchantment like the game’s own: it is dimmed in the list of possible enchantments and locked in a choose recipe until the player owns every item of the set.

local tide = sf2.perks.register {
id = "tide", kind = "combo", behavior = tide_behavior,
display_name = sf2.text.get("perk.tide"), description = sf2.text.get("perk.tide.description"),
}
sf2.items.register {
category = "set", id = "tide_set", perk = tide,
title = sf2.text.get("set.tide"), text = sf2.text.get("set.tide.text"),
brief = sf2.text.get("perk.tide.description"),
members = { { item = tide_sword }, { item = tide_armor } },
}

The perk must be one your mod registered earlier, and one set per perk. See sf2.items.register.

Register a price profile to give your recipes their own costs. Each row covers a range of levels and lists 1 to 3 material counts:

local abilities_price = sf2.forge.register {
id = "abilities",
prices = {
{ equipment = "weapon", rows = {
{ max_level = 2, materials = { 38, 10, 5 } }, -- player levels 1 and 2
{ level = 3, materials = { 46, 13, 6 } }, -- exactly player level 3
{ min_level = 4, materials = { 56, 17, 8 } }, -- player level 4 and above
} },
},
}

Each row covers a range of the player’s level, not the item’s. Rows must be in ascending order and not overlap. Use either level or min_level/max_level in a row, and leave max_level out on the last row to cover every higher level. Cover every level: when no row matches, the recipe is free. Every category your recipe uses needs a table in the profile. A profile you register is only used by your own recipes, and orders complete immediately (timers are covered below).

sf2.forge.patch changes the game’s recipes. The fields you give pick what it does.

Let the player choose. Switch a recipe from the random roll to a choose mode, where the player picks the enchantments and a strength tier:

sf2.forge.patch {
recipe = "Simple",
selection = "choose",
tiers = {
{ id = "low", name = sf2.text.get("forge.tier.low"), strength = 1 / 3, price = 0.5 },
{ id = "mid", name = sf2.text.get("forge.tier.mid"), strength = 2 / 3, price = 1.0 },
{ id = "high", name = sf2.text.get("forge.tier.high"), strength = 1.0, price = 2.0 },
},
}

tiers holds 1 to 5 entries, each with a unique id (letters, digits, _ and -, up to 32 characters), a strength from 0 to 1 and an optional price multiplier price from 0.01 to 100. strength is the share of the item’s full enchantment power for its level: the power a shop item of that level carries in list.xml (for example 1049 at level 30). An upgraded item counts at its upgrade’s level, the level the shop shows on it. The recipe’s random power range is not used. For a level 30 item the example gives 350, 699 and 1049, at half, normal and double price. The player sees every candidate once and picks as many as the recipe allows. The price is the profile’s price multiplied by the picked candidate’s and the tier’s multipliers.

A choose recipe treats the item’s current enchantments a little differently from the lottery:

  • A single (non-set) enchantment the item already carries stays in the list, so the player can forge it again at another strength; the new one replaces it. A set or ability enchantment the item already carries is left out, as in the lottery.
  • Most items hold one single enchantment, and a new single replaces it. An item allowed two (the Super Daisho is one) keeps both: a new single replaces the same enchantment if the item has it, otherwise the older of the two. Forging again replaces the other one, so they take turns.

Only one mod can configure a recipe this way. Enchantments already made keep their power, and a timed order already running applies the picks it stored.

Price or lock a candidate of a choose recipe:

sf2.forge.patch {
recipe = "Complex",
perk = "core:perks/perk_hermitstorm",
price = 1.5,
unlock = { defeated = { "core:warrior-templates/hermit_swords" } },
locked_text = sf2.text.get("forge.locked.hermit"),
}

price is a multiplier. unlock.defeated keeps the candidate locked until the player has beaten any one of the listed opponents (1 to 32 entries; core story opponents are named by their fighter template, such as core:warrior-templates/lynx_claws). A set enchantment stays locked until the whole set is owned, whatever unlock says. Add equipment to limit the setting to one category.

Add, remove or retune a candidate of a core recipe, by profile:

-- Let the Shock enchantment roll on Medium weapons, with Medium's usual power range.
sf2.forge.patch {
profile = sf2.forge.get("Medium"),
perk = "core:perks/perk_item_special_shock",
equipment = "weapon",
include = { min_deviation = -30, max_deviation = 30 },
}
-- Take the Monk set enchantment out of Complex weapon rolls.
sf2.forge.patch {
profile = sf2.forge.get("Complex"),
perk = "core:perks/perk_monk_set_whirl",
equipment = "weapon",
exclude = true,
}
-- Make Simple weapon enchantments roll stronger.
sf2.forge.patch {
profile = sf2.forge.get("Simple"),
equipment = "weapon",
deviation = { minimum = 15, maximum = 75 },
}

exclude and include affect only previews and new rolls, not enchantments already on equipment. include takes true or a table with optional min_level, max_level, and min_deviation with max_deviation (given together); it is rejected if the recipe already offers the perk. An included perk is listed after the recipe’s own; give before, one of the recipe’s own perks for that category, to list it just in front of that perk instead (include = { before = sf2.perks.get("core:perks/perk_director_set_plot_twist") }). The list order is what the player sees in a choose recipe and in the list of possible enchantments. deviation replaces the random power range of one category (-10000 to 10000) and only works for categories that already roll a random power (in the base game, Simple and Medium). Keep maximum at 134 or less, because saved enchantments far above the level’s base are reset when a profile loads.

Two patches that target the same recipe, category and perk conflict, even between mods. Different targets coexist. Patches restore the original when the mod is turned off.

sf2.game.timers changes how long things take. One mod may set the policy for each subsystem; a second mod fails to load.

-- Forge orders finish instantly, cannot be "skipped", and orders already
-- paid for finish at once.
sf2.game.timers { subsystem = "forge", seconds = 0, skip_enabled = false, complete_pending = true }
-- Ordinary timed fights get 150 seconds per round.
sf2.game.timers { subsystem = "battle", seconds = 150 }
-- Raid rounds have no time limit.
sf2.game.timers { subsystem = "raid", endless = true }
Field Default Meaning
subsystem required "forge", "battle" or "raid".
seconds required unless endless Forge: 0 to 31,536,000 (0 means instant). Battle and raid: 1 to 86,400 per round.
endless false Battle and raid only: no round time limit. Leave seconds out.
skip_enabled true Forge only: whether the player can finish an order early.
complete_pending false Only with seconds = 0: orders already paid for become ready to complete.

Good to know:

  • The battle timer replaces the positive round time of every timed fight and leaves training and untimed fights alone. It does not change game speed.
  • The "raid" timer overrides the "battle" timer for raid fights (the Underworld, mod Underworld pages and kind = "raid" modes).
  • An endless round hides the clock and ends when a fighter is knocked out or a rule ends it. Rounds of 999 seconds or more also hide the clock but do run out.
  • The forge changes never edit a saved deadline. Orders finish through the normal delivery update, materials are not charged again, and turning the mod off brings the original remaining time back. If no candidate qualifies when an order completes, the order closes and its materials are not returned.

sf2.game.economy scales shop prices, upgrade prices and coin rewards, and sets what the shop pays for items the player sells:

-- Upgrades are paid in coins only, whatever the difficulty.
sf2.game.economy { upgrade_gems = 0 }
-- Prices and rewards that depend on a choice the player made when starting a save.
sf2.game.economy { option = "difficulty", choice = "relaxed",
shop_coins = 0.85, shop_gems = 0.85, upgrade_coins = 0.7 }
sf2.game.economy { option = "difficulty", choice = "brutal",
reward_coins = { survival = 0.9 } }
Field Default Meaning
option, choice none Give both to apply the modifier only while the loaded save has that choice of one of your save options. Give neither to apply it always.
shop_coins, shop_gems 1 Multiplier on shop prices (0.01 to 10).
upgrade_coins 1 Multiplier on coin upgrade prices (0.01 to 10).
upgrade_gems 1 Multiplier on gem upgrade prices (0 to 10). 0 removes the gem price.
reward_coins none A table of fight kind to multiplier (0 to 10) for coins won in that kind of fight: story, survival, tournament, challenge, boss, final, ascension, replayable, periodic, raid, tutorial or other.
reward_gems none Gems added to the reward tally after a fight. See Gems in the reward tally.
sell_coins none The share of an item’s worth (0 to 1) the shop pays when the player sells it. See Selling items.

All modifiers that apply are multiplied together, including other mods’. Prices are rounded to whole numbers and never drop below 1 unless a multiplier of 0 removes them. The shop’s buttons, the confirmation and the charge all use the same scaled price. Changing a choice affects the next price shown and the next reward; past purchases are not refunded. Gems, experience and items are not scaled. A mod can add at most 32 modifiers.

After a fight, the reward tally counts up coins line by line: Perfect, First strike, Combo, Shock and the fight’s style. reward_gems adds gems to three of those lines:

sf2.game.economy {
reward_gems = { perfect = 3, combo = 3, fantastic = 3, except = { "survival" } },
}
Field Default Meaning
perfect 0 Gems for each round the player won without taking damage (0 to 100).
combo 0 Gems, once per fight, when the player’s longest combo reaches combo_hits hits (0 to 100).
combo_hits 10 How many hits that combo needs (2 to 100).
fantastic 0 Gems, once per fight, when the player reaches Fantastic style (0 to 100).
except none Fight kinds (the same names as reward_coins) where none of these gems are given.

These gems are paid only when the player wins the fight. After a loss, a surrender or a raid that runs out of time, the tally shows the usual coins and no gems. The base game’s style coins are not affected.

The gems show next to the coins on their lines and are paid with the rest of the fight’s rewards. If several modifiers with reward_gems apply, their gems add up rather than multiply. Like the other fields, reward_gems can follow a save option with option and choice.

The game has no selling of its own. Set sell_coins and the shop gets a Sell button under the Equip and Enchant buttons for weapons, armor, helmets, ranged weapons and magic the player owns. This sells for a quarter of an item’s worth on easy and normal saves, a tenth on hard ones, and not at all on the hardest:

sf2.game.economy { option = "difficulty", choice = "easy", sell_coins = 0.25 }
sf2.game.economy { option = "difficulty", choice = "normal", sell_coins = 0.25 }
sf2.game.economy { option = "difficulty", choice = "hard", sell_coins = 0.1 }
-- "very_hard" sets no sell_coins, so its saves have no Sell button.

Selling is available only while a modifier that applies sets sell_coins. If several do, their values are multiplied, and 0 switches selling off.

An item’s worth is what the shop would charge to buy it now, plus the coin price of every upgrade from the level the shop sells it at up to the player’s upgrade level. Both use your shop_coins and upgrade_coins multipliers. Items sold only for gems have no coin price, so their base is the usual coin price of the same kind of item at the same level (the middle price of the coin-priced items at the nearest level that has any). The sale price is rounded and is at least 1 coin.

What the player sees:

  • The empty slots (fists, the plain body and head, no ranged weapon or magic) are never offered.
  • A confirmation shows the price, and warns that upgrades and enchantments are lost. A sold item is gone completely, so buying it again gives a fresh copy.
  • If the shop won’t sell the item again (raid, event, quest and other rewards), a separate warning first says the player can’t get it back. There is no warning when a fight the player can fight again, such as a replayable battle or an Eclipse mode boss, still gives the item as a guaranteed reward.
  • Sell explains why it can’t go ahead when the item is equipped, still being delivered or enchanted, or kept by a mod.

The game’s own quests never need the player to own a particular item, so nothing is blocked by default. If your story needs one, keep it with sf2.profile.keep_item and give a reason the player will read. Release it with sf2.profile.release_item when your story is done with it:

local katana = sf2.items.get("core:items/weapon/weapon_katana")
sf2.story.on("item_acquired", function(event)
if event.item == "core:items/weapon/weapon_katana" then
sf2.profile.keep_item { item = katana, reason = "Sensei still needs this katana." }
end
end)
sf2.story.on("fight_end", function(event)
if event.fight == sf2.mod.id .. ":fights/katana_trial_1" and event.result == "win" then
sf2.profile.release_item(katana)
end
end)

The save remembers kept items, so call keep_item when the need starts, not in every session.

sf2.game.enable switches on two optional shop tools. Without it the shop lists items exactly as the game does:

sf2.game.enable { "shop_search", "shop_sort" }

The tools are round buttons on the side panel that slides out from the item list (the one that otherwise shows the player’s stat bars). While a tab has any of the buttons, they replace the stat bars there; a tab without any keeps its stat bars.

  • shop_search adds a Search button. Pressing it opens a search field on the item list’s top roller, where the typed text appears. It narrows the open tab as the player types, matching the item’s name or its type (such as “katana” or “shuriken”) in any case and in part. The X on the roller clears it, and changing tabs starts a new search. The shop only lists what it already would, so a search never reveals locked items.
  • shop_sort adds a Sort button on the equipment tabs and a Filter button on the weapon, ranged and magic tabs. Sort orders the tab by level (highest first, the default, or lowest first), by name (A to Z or Z to A) or, where items have types, by type; the chosen order shows under the button. Filter shows only the types the player ticks, from the types in that tab, and a badge on the button counts the chosen types. Clear filters shows everything again.

While a search or filter narrows the tab, the roller counts the items shown (“3 of 40”). The tools stay hidden until the story tutorial ends, so its shop visit shows the game’s own list. The sort order of each tab is remembered on the player’s device; filters last until they leave the shop. These tools don’t change prices or saves, so they are safe to turn on or off at any time.

These two features only affect the game’s original one-item list, which the shop no longer shows: it always uses the Armory layout, which shows the items of a tab in a grid and always has its own search, type filter, sort orders and Owned / Store views, whether or not a mod enables these features. It lists the same items the original list would.

sf2.game.disable turns off groups of optional services. It takes a list of names from paid_offers, battle_pass, ads, rewarded_video, online_services and payments:

sf2.game.disable { "ads", "battle_pass" }

If several mods disable services, all disables apply. This can only switch features off; it cannot bring a missing service back.

The story map has an Eclipse mode that the player switches on with a button on the map, with its own replay battles. sf2.game.set_eclipse_mode(enabled) presses the map’s own switch from a script and returns whether the mode is now active. sf2.game.refresh_eclipse_battles() re-syncs the normal and Eclipse versions of your battles after you reveal them. Both are meant for story-event handlers; see Story events.

Separate from Lua mods, a PvP balance preset is a small JSON file that sets how much damage versus fights deal, how much blocked damage can be healed back, and that blocking never knocks a fighter out. It applies to local versus, online versus and training, not to the campaign. Choose a preset with BALANCE in the match setup. Presets are edited in the Unity editor under SF2 > Multiplayer > PvP Balance, and a shared file goes in the PvpBalance folder of the game’s data folder (a local file with the same id overrides a bundled one). Online, the fight host’s preset applies, and every player needs a preset with the same values.

{
"schemaVersion": 1,
"id": "practice",
"name": "Practice balance",
"hitDamageScale": 0.5,
"blockedDamageScale": 0.25,
"recoverableBlockedFraction": 1,
"recoverOnHit": 0.5,
"recoverOnBlock": 0.25,
"minimumLifeOnBlock": 0.0001,
"categories": [{ "id": "Unarmed", "hitDamageScale": 0.4 }],
"moves": [{ "id": "HighKick", "blockedDamageScale": 0.2 }]
}

schemaVersion, id (letters, digits, - or _) and name are required; every other field is optional and shows its default above. Damage scales run from 0 to 10. Blocked damage becomes “grey” health the defender can win back: a blocked strike that removes 10 health adds recoverableBlockedFraction x 10 of grey health, and later hits restore recoverOnHit (or recoverOnBlock) x the damage dealt from that pool. Blocking never kills: a fighter keeps at least minimumLifeOnBlock of their health. The categories, equipment and moves lists override the damage scales for a weapon subtype, an exact item or an exact attack animation, applied in the order global, category, equipment, move.

  • Each timer subsystem and each forge recipe can be configured by only one mod.
  • Forge patches change future rolls and previews, not enchantments already made.
  • sf2.game.disable cannot remove ad code from a build; if an offline build has no such service, disabling it may do nothing visible.
  • The economy and forge changes use the game’s own rules. Test the balance for your content.