Module:Sandbox/Hubianzhen/BTD6 rewards
Documentation for this module may be created at Module:Sandbox/Hubianzhen/BTD6 rewards/doc
local p = {}
local cg = mw.ext.cargo
local tower_names = {
DartMonkey = 'Dart Monkey',
BoomerangMonkey = 'Boomerang Monkey',
BombShooter = 'Bomb Shooter',
TackShooter = 'Tack Shooter',
IceMonkey = 'Ice Monkey',
GlueGunner = 'Glue Gunner',
SniperMonkey = 'Sniper Monkey',
MonkeySub = 'Monkey Sub',
MonkeyBuccaneer = 'Monkey Buccaneer',
MonkeyAce = 'Monkey Ace',
HeliPilot = 'Heli Pilot',
MortarMonkey = 'Mortar Monkey',
DartlingGunner = 'Dartling Gunner',
WizardMonkey = 'Wizard Monkey',
SuperMonkey = 'Super Monkey',
NinjaMonkey = 'Ninja Monkey',
Alchemist = 'Alchemist',
Druid = 'Druid',
Mermonkey = 'Mermonkey',
BananaFarm = 'Banana Farm',
SpikeFactory = 'Spike Factory',
MonkeyVillage = 'Monkey Village',
EngineerMonkey = 'Engineer Monkey',
BeastHandler = 'Beast Handler'
}
local towers = {
DartMonkey = '-DartMonkey.png|x20px|link=Dart Monkey (BTD6)]] Dart Monkey',
BoomerangMonkey = '-BoomerangMonkey.png|x20px|link=Boomerang Monkey (BTD6)]] Boomerang Monkey',
BombShooter = '-BombShooter.png|x20px|link=Bomb Shooter (BTD6)]] Bomb Shooter',
TackShooter = '-TackShooter.png|x20px|link=Tack Shooter (BTD6)]] Tack Shooter',
IceMonkey = '-IceMonkey.png|x20px|link=Ice Monkey (BTD6)]] Ice Monkey',
GlueGunner = '-GlueGunner.png|x20px|link=Glue Gunner (BTD6)]] Glue Gunner',
SniperMonkey = '-SniperMonkey.png|x20px|link=Sniper Monkey (BTD6)]] Sniper Monkey',
MonkeySub = '-MonkeySub.png|x20px|link=Monkey Sub (BTD6)]] Monkey Sub',
MonkeyBuccaneer = '-MonkeyBuccaneer.png|x20px|link=Monkey Buccaneer (BTD6)]] Monkey Buccaneer',
MonkeyAce = '-MonkeyAce.png|x20px|link=Monkey Ace (BTD6)]] Monkey Ace',
HeliPilot = '-HeliPilot.png|x20px|link=Heli Pilot (BTD6)]] Heli Pilot',
MortarMonkey = '-MortarMonkey.png|x20px|link=Mortar Monkey (BTD6)]] Mortar Monkey',
DartlingGunner = '-DartlingGunner.png|x20px|link=Dartling Gunner (BTD6)]] Dartling Gunner',
WizardMonkey = '-WIzard.png|x20px|link=Wizard Monkey (BTD6)]] Wizard Monkey',
SuperMonkey = '-SuperMonkey.png|x20px|link=Super Monkey (BTD6)]] Super Monkey',
NinjaMonkey = '-NinjaMonkey.png|x20px|link=Ninja Monkey (BTD6)]] Ninja Monkey',
Alchemist = '-Alchemist.png|x20px|link=Alchemist (BTD6)]] Alchemist',
Druid = '-Druid.png|x20px|link=Druid (BTD6)]] Druid',
Mermonkey = '-Mermonkey.png|x20px|link=Mermonkey (BTD6)]] Mermonkey',
BananaFarm = '-BananaFarm.png|x20px|link=Banana Farm (BTD6)]] Banana Farm',
SpikeFactory = '-SpikeFactory.png|x20px|link=Spike Factory (BTD6)]] Spike Factory',
MonkeyVillage = '-MonkeyVillage.png|x20px|link=Monkey Village (BTD6)]] Monkey Village',
EngineerMonkey = '-EngineerMonkey.png|x20px|link=Engineer Monkey (BTD6)]] Engineer Monkey',
BeastHandler = '-BeastHandler.png|x20px|link=Beast Handler (BTD6)]] Beast Handler'
}
local insta_towers = {
DartMonkey = '-DartMonkeyInsta.png|x20px|link=Dart Monkey (BTD6)',
BoomerangMonkey = '-BoomerangMonkeyInsta.png|x20px|link=Boomerang Monkey (BTD6)',
BombShooter = '-BombShooterInsta.png|x20px|link=Bomb Shooter (BTD6)',
TackShooter = '-TackShooterInsta.png|x20px|link=Tack Shooter (BTD6)',
IceMonkey = '-IceMonkeyInsta.png|x20px|link=Ice Monkey (BTD6)',
GlueGunner = '-GlueGunnerInsta.png|x20px|link=Glue Gunner (BTD6)',
SniperMonkey = '-SniperMonkeyInsta.png|x20px|link=Sniper Monkey (BTD6)',
MonkeySub = '-MonkeySubInsta.png|x20px|link=Monkey Sub (BTD6)',
MonkeyBuccaneer = '-MonkeyBuccaneerInsta.png|x20px|link=Monkey Buccaneer (BTD6)',
MonkeyAce = '-MonkeyAceInsta.png|x20px|link=Monkey Ace (BTD6)',
HeliPilot = '-HeliPilotInsta.png|x20px|link=Heli Pilot (BTD6)',
MortarMonkey = '-MortarMonkeyInsta.png|x20px|link=Mortar Monkey (BTD6)',
DartlingGunner = '-DartlingGunnerInsta.png|x20px|link=Dartling Gunner (BTD6)',
WizardMonkey = '-WIzardInsta.png|x20px|link=Wizard Monkey (BTD6)',
SuperMonkey = '-SuperMonkeyInsta.png|x20px|link=Super Monkey (BTD6)',
NinjaMonkey = '-NinjaMonkeyInsta.png|x20px|link=Ninja Monkey (BTD6)',
Alchemist = '-AlchemistInsta.png|x20px|link=Alchemist (BTD6)',
Druid = '-DruidInsta.png|x20px|link=Druid (BTD6)',
Mermonkey = '-MermonkeyInsta.png|x20px|link=Mermonkey (BTD6)',
BananaFarm = '-BananaFarmInsta.png|x20px|link=Banana Farm (BTD6)',
SpikeFactory = '-SpikeFactoryInsta.png|x20px|link=Spike Factory (BTD6)',
MonkeyVillage = '-MonkeyVillageInsta.png|x20px|link=Monkey Village (BTD6)',
EngineerMonkey = '-EngineerMonkeyInsta.png|x20px|link=Engineer Monkey (BTD6)',
BeastHandler = '-BeastHandlerInsta.png|x20px|link=Beast Handler (BTD6)'
}
local reward_for_type = {
['FullTowerUnlock'] = function(value)
return string.format('[[File:BTD6 %s', towers[value])
end,
['InstaMonkey'] = function(value)
local delimiter = string.find(value, ',')
local top = tonumber(string.sub(value, delimiter + 1, delimiter + 1))
local mid = tonumber(string.sub(value, delimiter + 2, delimiter + 2))
local btm = tonumber(string.sub(value, delimiter + 3, delimiter + 3))
local tower = string.sub(value, 1, delimiter - 1)
--[[ Insta-towers:
If both paths equal, the order is:
Middle, Top, Bottom
exceptions:
Dart middle then bottom (t1 and t2)
Bucc middle then bottom (t2)
can be volatile, so keeping an eye on those changes
]]--
-- Middle
if mid >= top and mid >= btm then
top, btm = 0, 0
-- Top
elseif top >= mid and top >= btm then
if top == btm and (tower ~= "DartMonkey" or (tower ~= "MonkeyBuccaneer" and top == 2)) then top, mid = 0, 0
else
mid, btm = 0, 0
end
-- Bottom
else
top, mid = 0, 0
end
return string.format('[[File:BTD6 %s%s%s%s]] %s-%s-%s',
tostring(top), tostring(mid), tostring(btm), insta_towers[tower],
string.sub(value, delimiter + 1, delimiter + 1), string.sub(value, delimiter + 2, delimiter + 2), string.sub(value, delimiter + 3, delimiter + 3)
)
end,
['RandomInstaMonkey'] = function(value)
local values = {}
for v in string.gmatch(value, '([^,]+)') do
table.insert(values, v)
end
local tier = values[1]
local amt = values[2]
local tower = tower_names[values[3]]
-- tier 0
if values[1] == "0" then
if #values == 3 then
-- random tier 0 of a specific tower
return string.format('[[File:BTD6 InstaRandomTier1.png|x20px|Tier 0 %s Insta Monkey|link=Insta Monkey]] %s ×%s', tower, tower, amt)
else
-- random tier 0
return string.format('[[File:BTD6 InstaRandomTier1.png|x20px|Tier 0 Insta Monkey|link=Insta Monkey]] ×%s', amt)
end
else
if #values == 3 then
-- random tier X of a specific tower
return string.format('[[File:BTD6 InstaRandomTier%s.png|x20px|Tier %s %s Insta Monkey|link=Insta Monkey]] %s ×%s', tier, tier, tower, tower, amt)
else
-- random tier X
return string.format('[[File:BTD6 InstaRandomTier%s.png|x20px|Tier %s Insta Monkey|link=Insta Monkey]] ×%s', tier, tier, amt)
end
end
end,
}
function p.parse(text)
local reward_text = {}
-- split text by '#'
for reward in string.gmatch(text, '([^#]+)') do
-- split reward by ':'
local delimiter = string.find(reward, ':')
if delimiter ~= nil then
table.insert(reward_text, reward_for_type[string.sub(reward, 1, delimiter - 1)](string.sub(reward, delimiter + 1, string.len(reward))))
--[[if string.sub(reward, 1, delimiter - 1) == 'TrophyStoreItem' and source ~= nil then
cg.store('btd6_cosmetic_sources', {
name = source,
item = string.sub(reward, delimiter + 1, string.len(reward))
})
end]]--
else
table.insert(reward_text, reward_for_type[reward]())
end
end
return table.concat(reward_text, ', ')
end
function p.main(frame)
return p.parse(frame.args[1])
end
return p