Module:TowerDefenseWaves: Difference between revisions

From IdleOn MMO Wiki
imported>Kiokurashi
No edit summary
imported>Kiokurashi
No edit summary
Line 25: Line 25:
for i = 1, waves do
for i = 1, waves do
local wavePos
local wavePos
if((i % 30) > 0) then wavePos = i % 30 else wavePos = i / 30 end -- We want to keep 30 instead of getting 0.
if((i % 30) > 0) then wavePos = i % 30 end
if((i % 30) == 0) then wavePos = i / 30 end -- We want to keep 30 instead of getting 0.
local multi = math.floor(i / 31) -- 31 because 30 should still equal 0 so we don't want 30/30.
local multi = math.floor(i / 31) -- 31 because 30 should still equal 0 so we don't want 30/30.
local waveSkull = math.min(skull[wavePos] + (2 * multi), 16) -- 16 skull types. Modular based on wave count.
local waveSkull = math.min(skull[wavePos] + (2 * multi), 16) -- 16 skull types. Modular based on wave count.
Line 33: Line 34:
local sizeW = size[wavePos] -- Enemy size modifier.
local sizeW = size[wavePos] -- Enemy size modifier.
local colorW = color[wavePos] + 1 -- Enemy color/ability modifier.
local colorW = color[wavePos] + 1 -- Enemy color/ability modifier.
if((i > 1) and (wavePos == 1)) then ret = ret .. "\n{{!}}-{{!}}\n" .. i .. "-" .. (i + 29) .."=\n{{TDwaves/head|Waves}}\n" end
if(i > 2 and (wavePos == 1)) then ret = ret .. [[{{!}}-{{!}}
]] .. i .. "-" .. (i + 29) ..[[=
{{TDwaves/head|Waves}}
]] end
-- {{TDwaves/row|31|3|Skull2|Normo|Grey|52|156}}  
-- {{TDwaves/row|31|3|Skull2|Normo|Grey|52|156}}  
Line 43: Line 47:
ret = ret .. "|" .. health  
ret = ret .. "|" .. health  
ret = ret .. "|" .. (health * enemyNum)  
ret = ret .. "|" .. (health * enemyNum)  
ret = ret .. "}}\n";
ret = ret .. [[}}
]];
end
end
ret = ret .. "}}\n"
ret = ret .. "}}\n"

Revision as of 03:57, 29 March 2022

Documentation for this module may be created at Module:TowerDefenseWaves/doc

local p = {}

local function explode(list, delimiter)
    if delimiter == nil then
		delimiter = "%s"
	end
	t = {}
	for str in string.gmatch(list, "([^" .. delimiter .. "]+)") do
		table.insert(t, tonumber(str))
	end
	return t
end

function p.generateWaves(frame)
	local ret = "{{#tag:tabber|\n1-30=\n{{TDwaves/head|Waves}}\n"
	local countList = explode(frame.args.MonsterCount, ",")
	local skull = explode(frame.args.Skull, ",")
	local size = explode(frame.args.Size, ",")
	local color = explode(frame.args.Type, ",")
	local waves = tonumber(frame.args.MaxWave)
	local baseHP = tonumber(frame.args.BaseHealth)
	local sizeText = {"Zoomo", "Normo", "Largo", "Gigao"}
	local colorText = {"Grey", "Red", "Blue", "Green", "Yellow", "Purple"}
	
	for i = 1, waves do
		local wavePos
		if((i % 30) > 0) then wavePos = i % 30 end
		if((i % 30) == 0) then wavePos = i / 30 end -- We want to keep 30 instead of getting 0.
		local multi = math.floor(i / 31) -- 31 because 30 should still equal 0 so we don't want 30/30.
		local waveSkull = math.min(skull[wavePos] + (2 * multi), 16) -- 16 skull types. Modular based on wave count.
		local enemyNum = countList[wavePos] + (math.ceil(countList[wavePos] / 3) * multi) -- Increases every 30 waves.
		local health = math.ceil(baseHP * (3 ^ (size[wavePos] - 2)) * ((3 + 0.3 * waveSkull)^waveSkull)) -- Increases by Skull level.
		-- Ceil(BaseHP * (3 ^ (size - 2)) * ((3 + 0.3 * skull)^skull))
		local sizeW = size[wavePos] -- Enemy size modifier.
		local colorW = color[wavePos] + 1 -- Enemy color/ability modifier.
		if(i > 2 and (wavePos == 1)) then ret = ret .. [[{{!}}-{{!}}
			]] .. i .. "-" .. (i + 29) ..[[=
			{{TDwaves/head|Waves}}
			]] end
		-- {{TDwaves/row|31|3|Skull2|Normo|Grey|52|156}} 
		
		ret = ret .. "{{TDwaves/row|" .. i 
		ret = ret .. "|" .. enemyNum 
		ret = ret .. "|Skull" .. waveSkull 
		ret = ret .. "|" .. sizeText[sizeW] 
		ret = ret .. "|" .. colorText[colorW] 
		ret = ret .. "|" .. health 
		ret = ret .. "|" .. (health * enemyNum) 
		ret = ret .. [[}}
	]];
	end
	ret = ret .. "}}\n"
	return ret
end
	
return p