Module:Ushabti

From WIDEVERSE Wiki
Jump to navigation Jump to search

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

local data = mw.loadData('Module:Ushabti/data')
local yn = require('Module:Yesno')
local lang = mw.getContentLanguage()
local p = {}

function p.main(frame)
	return p._main(frame:getParent().args)
end

function p._main(args)
	local player_level = math.floor(tonumber(args.level) or 1)
	local _monster_name = args.monstername or ''
	_monster_name = _monster_name:gsub('&', "&"):gsub('&#0?39;', "'")
	local monster_name
	local monster_data = data[_monster_name]
	local monster_level
	if monster_data then
		monster_level = monster_data[1]
		monster_name = monster_data.name or _monster_name.."'s"
	else
		monster_name = 'Monster'
		monster_level = math.floor(tonumber(args.monster) or 1)
	end
	local on_task_raw = yn(args.task)
	local on_task = player_level >= 120 or on_task_raw
	local corrupted_helm = yn(args.helm)
	local cursed_ushabti = yn(args.cursed)
	local summer_weekend = yn(args.summer)
	
	local buffs = {string.format("* Your Slayer level: %s; %s Slayer level: %s; diff: %s", player_level, monster_name, monster_level,player_level-monster_level)}
	if monster_data then
		if monster_data.fake then
			table.insert(buffs, "** This monster uses a different level (given above) to the normal requirement when calculating soul capture chance")
		end
	else
		table.insert(buffs, "** Using the custom monster Slayer level provided")
	end
		
	
	local chance
	if player_level < monster_level then
		chance = 1000
	else 
		chance = math.pow(player_level - monster_level, 2) * 5
	end
	
	chance = math.max(1000, chance)
	table.insert(buffs, '* Base target: '..chance)
	
	if on_task then
		if player_level >= 120 then
			table.insert(buffs, '* You are 120 Slayer so count as on-task: target is not changed')
		else
			table.insert(buffs, '* You are on-task: target is not changed')
		end
		if corrupted_helm then
			chance = math.floor(chance * 1.05)
			table.insert(buffs, '* You are on-task with a corrupted slayer helm active: target is now '..chance)
		end
	else
		chance = math.max(1000, math.floor(chance/2))
		table.insert(buffs, '* You are not on-task and not 120 Slayer: target is now '..chance)
	end
	
	if cursed_ushabti then
		chance = math.floor(chance * 1.5)
		table.insert(buffs, '* You are using a cursed ushabti: target is now '..chance)
	end
	
	if summer_weekend then
		chance = math.floor(chance * 1.1)
		table.insert(buffs, '* You are slaying during the Summer Escape combat weekend: target is now '..chance)
	end
	
	table.insert(buffs, '* After all checks, final target is '..chance)
	
	
	return string.format('Your chance to catch this soul is %s/500,000 (%s%%, %s1/%s) with these buffs:\n%s', lang:formatNum(chance), 100*chance/500000, (500000/chance == math.floor(500000/chance) and '' or '≈'), math.floor(500000/chance), table.concat(buffs, '\n'))
end

function p.list()
	local l = {}
	for k,v in pairs(data) do
		table.insert(l, k)
	end
	table.sort(l)
	return table.concat(l, ',')
end

return p