|
|
| Line 1: |
Line 1: |
| local data = mw.loadJsonData("Data:AbilityCards.json")
| |
| local raw_ability_data = mw.loadJsonData("Data:AbilityData.json")
| |
|
| |
| local p = {} | | local p = {} |
|
| |
|
| -- returns the table of a specific ability from Data:AbilityCards.json | | -- Get NPC data values (you may need to adjust these based on your wiki's implementation) |
| function get_ability(hero_key, ability_num)
| | local baseValue = 20 -- This should match {{NpcData|neutral_sinners_sacrifice|GoldReward}} |
| local ui_data = data[hero_key]
| | local bonusPercentPerMinute = 0.02 -- This should match {{NpcData|neutral_sinners_sacrifice|GoldRewardBonusPercentPerMinute}} / 100 |
| if(ui_data == nil) then return "Hero Not Found" end
| |
| return ui_data[tonumber(ability_num)]
| |
| end
| |
| | |
| -- Returns the table of a specific ability from Data:AbilityData.json by its Key or Name
| |
| -- It first attempts a direct lookup by key for efficiency. If that fails, it iterates
| |
| -- through the data to find a matching Name property.
| |
| -- @function find_json_ability
| |
| -- @param {string} identifier - The ability's key or name
| |
| -- @return {table} or nil
| |
| local function find_json_ability(identifier) | |
| -- First, try a direct lookup by key (most efficient method)
| |
| if raw_ability_data[identifier] then
| |
| return raw_ability_data[identifier]
| |
| end
| |
|
| |
| -- If not found by key, loop through and search by the "Name" property as a fallback
| |
| -- Skip any ability that is explicitly disabled
| |
| for _, v in pairs(raw_ability_data) do
| |
| if v.Name == identifier and not v.IsDisabled then
| |
| return v
| |
| end
| |
| end
| |
|
| |
| -- If not found by either method, return nil
| |
| return nil
| |
| end
| |
| | |
| --{{#invoke:AbilityData|get_ability_name|HERO_NAME|ABILITY_NUM}}-- | |
| p.get_ability_name = function(frame)
| |
| local hero_name = frame.args[1]
| |
| local ability_num = frame.args[2]
| |
|
| |
| local ability = get_ability(hero_name, ability_num)
| |
| if(ability == nil) then return "Ability Not Found" end
| |
| return ability.Name
| |
| end
| |
| | |
| --{{#invoke:AbilityData|get_ability_prop|ability_key_or_name|prop}}-- | |
| p.get_ability_prop = function(frame)
| |
| local ability_identifier = frame.args[1]
| |
| local prop = frame.args[2]
| |
|
| |
| -- Use the new, more flexible lookup function
| |
| local ability = find_json_ability(ability_identifier)
| |
| if(ability == nil) then return "Ability Not Found" end
| |
| | |
| local element = ability[prop]
| |
| if element == nil then return "" end
| |
| | |
| -- if the property is a table, return its Value field
| |
| if type(element) == "table" then
| |
| return element.Value or ""
| |
| end
| |
|
| |
|
| -- otherwise return the scalar value
| | function p.calculatePayouts(frame) |
| return element
| | local time = tonumber(frame.args[1]) or 0 |
| | |
| | -- Calculate total soul value |
| | local totalValue = math.floor((baseValue + (baseValue * bonusPercentPerMinute * time)) * 2) |
| | |
| | -- Calculate individual payouts |
| | local lightMelee = math.floor(totalValue / 20 + 0.5) -- Adding 0.5 for proper rounding |
| | local heavyMelee = math.floor(totalValue / 10 + 0.5) |
| | local finalHit = math.floor(totalValue / 2 + 0.5) + math.floor(totalValue / 10 + 0.5) |
| | |
| | -- Return JSON format for easy parsing by JavaScript |
| | return mw.text.jsonEncode({ |
| | total = totalValue, |
| | light = lightMelee, |
| | heavy = heavyMelee, |
| | final = finalHit |
| | }) |
| end | | end |
|
| |
| --{{#invoke:AbilityData|get_ability_upgrade_prop|ability_key_or_name|upgrade_num|prop}}--
| |
| -- Gets a specific property from a specific upgrade of an ability.
| |
| -- @param {string} frame.args[1] - The ability's key (e.g., "ability_afterburn") or name (e.g., "Afterburn").
| |
| -- @param {string|number} frame.args[2] - The upgrade number (1, 2, or 3).
| |
| -- @param {string} frame.args[3] - The name of the property to retrieve.
| |
| p.get_ability_upgrade_prop = function(frame)
| |
| local ability_identifier = frame.args[1]
| |
| local upgrade_num_str = frame.args[2]
| |
| local prop = frame.args[3]
| |
| local debug = frame.args.debug -- ← NEW
| |
|
| |
| if not (ability_identifier and upgrade_num_str and prop) then
| |
| return debug and "Missing args" or ""
| |
| end
| |
|
| |
| local ability = find_json_ability(ability_identifier)
| |
| if not ability then
| |
| return debug and "Ability not found" or ""
| |
| end
| |
|
| |
| local upgrades = ability.Upgrades
| |
| if type(upgrades) ~= "table" then
| |
| return debug and "No upgrades" or ""
| |
| end
| |
|
| |
| local upgrade_num = tonumber(upgrade_num_str)
| |
| if not upgrade_num or not upgrades[upgrade_num] then
| |
| return debug and "Upgrade not found" or ""
| |
| end
| |
|
| |
| local element = upgrades[upgrade_num][prop]
| |
| if element == nil then
| |
| return debug and "Prop missing" or ""
| |
| end
| |
|
| |
| -- return the value (number or string) directly
| |
| local out = type(element) == "table" and (element.Value or "") or tostring(element)
| |
| return debug and ("→"..out.."←") or out
| |
| end
| |
|
| |
|
| |
|
| return p | | return p |