Module:AbilityData: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Saag (talk | contribs)
build ability card template inside script
Saag (talk | contribs)
load data from HeroData.json
Line 1: Line 1:
local p = {};
local p = {};
local data = mw.loadJsonData("Data:ItemData.json")
local data = mw.loadJsonData("Data:HeroData.json")


-- returns the table of a specific item
-- returns the table of a specific item
function get_json_item(name)
function get_ability(hero_name, ability_number)
for i,v in pairs(data) do
for i,v in pairs(data) do
if (v["Name"] == name) then
if (v["Name"] == hero_name) then
return v
return v["BoundAbilities"][tonumber(ability_number)]
end
end
end
end
Line 12: Line 12:
end
end


local abilities = {
--{{#invoke:AbilityData|get_ability_card|HERO_NAME|ABILITY_NUMBER}}--
    shoulderCharge = {
p.get_ability_card = function(frame)
        name = "Shoulder Charge",
    local hero_name = frame.args[1]
        duration = "1.2s",
    local ability_num = frame.args[2]
        cooldown = "35s",
        description = "'''Charge forward''', colliding with enemies and dragging them along. Hitting a '''wall''' will '''Stun''' enemies caught by Abrams. Speed increased after colliding with enemy Heroes.",
        effect1 = "'''Damage:''' 40 {{ss|2.1}}",
        effect2 = "'''Stun Duration:''' 0.85s",
        upgrade1 = "'''-20s''' Cooldown",
        upgrade2 = "'''+0.5s''' Duration",
        upgrade3 = "'''+5.5''' Weapon Damage for '''8s''' after colliding with an enemy"
    }
}


--{{#invoke:ItemData|get_cost|ITEM_NAME}}--
     local ability = get_ability(hero_name, ability_num)
p.test = function(frame)
    local abilityName = frame.args[1]
     local ability = abilities[abilityName]


     if ability then
     if ability then
Line 36: Line 24:
             title = "Ability card",
             title = "Ability card",
             args = {
             args = {
                 name = ability.name,
                 name = ability.Name,
                 duration = ability.duration,
                 duration = ability.AbilityDuration,
                 cooldown = ability.cooldown,
                 cooldown = ability.AbilityCooldown,
                 description = ability.description,
                 description = ability.Description,
                 effect1 = ability.effect1,
                 -- effect1 = ability.effect1,
                 effect2 = ability.effect2,
                 -- effect2 = ability.effect2,
                 upgrade1 = ability.upgrade1,
                 upgrade1 = ability.Upgrades[1].Description,
                 upgrade2 = ability.upgrade2,
                 upgrade2 = ability.Upgrades[2].Description,
                 upgrade3 = ability.upgrade3
                 upgrade3 = ability.Upgrades[3].Description
             }
             }
         }
         }
     else
     else
        return "Ability data not found."
    return "Ability data not found for hero " .. hero_name .. " and num " .. ability_num
     end
     end
end
end


return p
return p

Revision as of 21:09, 13 September 2024

Deprecated

This module is being replaced by multiple modules in Module:Abilities. Any new functions should be created there


local p = {};
local data = mw.loadJsonData("Data:HeroData.json")

-- returns the table of a specific item
function get_ability(hero_name, ability_number)
	for i,v in pairs(data) do
		if (v["Name"] == hero_name) then
			return v["BoundAbilities"][tonumber(ability_number)]
		end
	end
	return nil
end

--{{#invoke:AbilityData|get_ability_card|HERO_NAME|ABILITY_NUMBER}}--
p.get_ability_card = function(frame)
    local hero_name = frame.args[1]
    local ability_num = frame.args[2]

    local ability = get_ability(hero_name, ability_num)

    if ability then
        -- Pass the table fields to the template
        return frame:expandTemplate{
            title = "Ability card",
            args = {
                name = ability.Name,
                duration = ability.AbilityDuration,
                cooldown = ability.AbilityCooldown,
                description = ability.Description,
                -- effect1 = ability.effect1,
                -- effect2 = ability.effect2,
                upgrade1 = ability.Upgrades[1].Description,
                upgrade2 = ability.Upgrades[2].Description,
                upgrade3 = ability.Upgrades[3].Description
            }
        }
    else
    	return "Ability data not found for hero " .. hero_name .. " and num " .. ability_num
    end
end

return p