Module:Sandbox/User:Sfoxrs/combineddevo: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (1 revision imported) |
(No difference)
|
Latest revision as of 21:23, 4 November 2021
Documentation for this module may be created at Module:Sandbox/User:Sfoxrs/combineddevo/doc
-- <pre>
local p = {}
local perk_link = require('Module:Perk link')._main
local htnmlext = require('Module:Mw.html extension')
local yesno = require ("Module:Yesno")
local lang = mw.getContentLanguage()
function p.main(frame)
math.randomseed(os.time())
local args = frame:getParent().args
local debugMode = false
local pvmorpvp = args.pvmorpvp
local edevRank = args.edevRank
local devRank = args.devRank
local level20edev = yesno(args.level20edev) or false
local level20dev = yesno(args.level20dev) or false
local t_AR = args.t_AR
local runSpeed = args.runSpeed
--define new variables
local enhancedDevotedRank = -1
if(edevRank == "0") then enhancedDevotedRank = 0
elseif(edevRank == "1") then enhancedDevotedRank = 1
elseif(edevRank == "2") then enhancedDevotedRank = 2
elseif(edevRank == "3") then enhancedDevotedRank = 3
elseif(edevRank == "4") then enhancedDevotedRank = 4 --testing
end
local devotedRank = -1
if(devRank == "0") then devotedRank = 0
elseif(devRank == "1") then devotedRank = 1
elseif(devRank == "2") then devotedRank = 2
elseif(devRank == "3") then devotedRank = 3
elseif(devRank == "4") then devotedRank = 4 --testing
end
local attackRate = -1
if(t_AR == "1") then attackRate = 1
elseif(t_AR == "2") then attackRate = 2
elseif(t_AR == "3 or 4") then attackRate = 4
elseif(t_AR == "5+") then attackRate = 5
end
local nHits = -1; local nHitsText = "-1"
if(runSpeed == "Moderate") then nHits = 10^6; nHitsText = "10^6"
elseif(runSpeed == "Slow (higher precision)") then nHits = 10^7; nHitsText = "10^7"
elseif(runSpeed == "Fast (lower precision)") then nHits = 10^5; nHitsText = "10^5"
end
local damage = 10000 --should be a high number compared to damage taken under either perk (which is a 1).
local enhancedDevotedProcChance = .045*enhancedDevotedRank
local devotedProcChance = .03*devotedRank
if (level20edev) then enhancedDevotedProcChance = enhancedDevotedProcChance*1.1 end
if (level20dev) then devotedProcChance = devotedProcChance*1.1 end
local cooldown = 5 --Each perk has an internal cooldown of 5 ticks (which is exactly how long the perk is active - this means either perk cannot proc again while active)
local turnOff = math.ceil(cooldown/attackRate) --how many hits the proc can block.
local enhancedDevotedCooldown = 0 --will become 0 in the condition it equals math.ceil(cooldown/attackrate)
local devotedCooldown = 0 --will become 0 in the condition it equals math.ceil(cooldown/attackrate)
--random variables
local randProcEnhancedDevoted = 0
local randProcDevoted = 0
--damage tracking
local totalDamage=0
local combinedDamage=0
local enhancedDevotedDamage=0 --for debug mode
local nProcsEnhancedDevoted=0 --for debug mode
local nProcsDevoted=0 --for debug mode
--damage reduction
local combinedDamageReduction = 0
local enhancedDevotedDamageReduction = 0 --for debug mode
--check if perk is active
local enhancedDevotedActive = 0
local devotedActive = 0
--output
local res = ""
for hit = 1,nHits do
randProcEnhancedDevoted = math.random()
totalDamage = totalDamage + damage
--If Devoted has been active for 5 ticks, it has run out
if(devotedCooldown == turnOff) then
devotedActive = 0
devotedCooldown = 0
end
--If Enhanced Devoted is already active, increment the cooldown by 1
if((enhancedDevotedActive == 1) or (enhancedDevotedRank == 0)) then
enhancedDevotedCooldown = enhancedDevotedCooldown + 1
--Devoted may only proc given Enhanced Devoted is already active
if((enhancedDevotedCooldown < turnOff) or (enhancedDevotedRank == 0)) then
randProcDevoted = math.random()
if(randProcDevoted<=devotedProcChance) then
devotedActive = 1
nProcsDevoted = nProcsDevoted + 1
end
end
end
--If Devoted is already active, increment the cooldown by 1
if(devotedActive == 1) then
devotedCooldown = devotedCooldown + 1
end
--If Enhanced Devoted has been active for 5 ticks, it has run out
if(enhancedDevotedCooldown == turnOff) then
enhancedDevotedActive = 0
enhancedDevotedCooldown = 0
end
--Does Enhanced Devoted proc?
if(randProcEnhancedDevoted<=enhancedDevotedProcChance) then
enhancedDevotedActive = 1
nProcsEnhancedDevoted = nProcsEnhancedDevoted + 1
end
--Calculate the damages
if(enhancedDevotedActive == 0) then
enhancedDevotedDamage = enhancedDevotedDamage + damage
end
if(enhancedDevotedActive == 1 and pvmorpvp == "PvP") then
enhancedDevotedDamage = enhancedDevotedDamage + damage/2
end
if((enhancedDevotedActive == 1 or devotedActive == 1) and pvmorpvp == "PvP") then
combinedDamage = combinedDamage + damage/2
end
if((enhancedDevotedActive == 0) and (devotedActive == 0)) then
combinedDamage = combinedDamage + damage
end
end
enhancedDevotedDamageReduction = (1-enhancedDevotedDamage/totalDamage)*100
combinedDamageReduction = (1-combinedDamage/totalDamage)*100
--table for output
local resultsDiv = mw.html.create( 'div' )
local resultsTable = mw.html.create( 'table' )
resultsTable:addClass( 'wikitable' )
:addClass( 'align-center-1 align-center-2' )
:tag( 'caption' )
:wikitext( '' )
:tag( 'tr' )
:tag( 'th' )
:wikitext( 'Average Damage Reduction (enemy attack rate of ' .. t_AR ..")<br/>" )
:wikitext( 'Averaged over ' .. frame:extensionTag{ name = 'math', content = nHitsText } .. ' hits' )
:attr( 'colspan', 2 )
:done()
:done()
:tag( 'tr' )
:tag( 'th' )
:wikitext( 'Perk(s)' )
:done()
:tag( 'th' )
:wikitext( 'Average Damage Reduction' )
:done()
:done()
:tag( 'tr' )
:tag( 'td' )
:wikitext(perk_link{ 'Enhanced devoted', enhancedDevotedRank, link = 'no' } )
:IF(level20edev)
:wikitext( string.format("[[File:Perk_increased_activation_chance.png]]") )
:END()
:wikitext(perk_link{ 'Devoted', devotedRank, link = 'no' } )
:IF(level20dev)
:wikitext( string.format("[[File:Perk_increased_activation_chance.png]]") )
:END()
:done()
:tag( 'td' )
:wikitext(string.format("%.2f",combinedDamageReduction) .. "%")
:done()
:done()
:done()
if debugMode then
res = res .. "___________________________________" .. "<br/>"
res = res .. "DEBUG MODE" .. "<br/>"
res = res .. "___________________________________" .. "<br/>"
res = res .. "<div style=\"font-weight:bold\">Average Damage reduction from Enhanced Devoted " .. enhancedDevotedRank .. " and Devoted " .. devotedRank .. ": " .. string.format("%.2f",combinedDamageReduction) .. "%</div>"
res = res .. "Average Damage reduction from Enhanced Devoted " .. enhancedDevotedRank .. ": " .. string.format("%.2f",enhancedDevotedDamageReduction) .. "%<br/>"
res = res .. "Total Damage = " .. totalDamage .. "<br/>"
res = res .. "Combined Damage = " .. combinedDamage .. "<br/>"
res = res .. "Enhanced Devoted Damage = " .. enhancedDevotedDamage .. "<br/>"
res = res .. "Number of hits per proc (turnOff variable): " .. turnOff .. "<br/>"
res = res .. "Final state of Enhanced devoted (0 is inactive): " .. enhancedDevotedActive .. "<br/>"
res = res .. "Final state of Devoted (0 is inactive): " .. devotedActive .. "<br/>"
res = res .. "Number of Enhanced Devoted procs: " .. nProcsEnhancedDevoted .. "<br/>"
res = res .. "Number of Devoted procs: " .. nProcsDevoted .. "<br/>"
res = res .. "Enhanced Devoted proc chance: " .. enhancedDevotedProcChance .. "<br/>"
res = res .. "Devoted proc chance: " .. devotedProcChance .. "<br/>"
res = res .. "PvM or PvP? " .. pvmorpvp .. "<br/>"
res = res .. "Enhanced Devoted rank: " .. enhancedDevotedRank .. "<br/>"
res = res .. "Devoted rank: " .. devotedRank .. "<br/>"
res = res .. "Is Enhanced Devoted on level 20 gear? " .. level20edev .. "<br/>"
res = res .. "Is Devoted on level 20 gear? " .. level20dev .. "<br/>"
res = res .. "Enemy attack rate (game ticks): " .. t_AR .. "<br/>"
res = res .. "Selected speed of simulator: " .. runSpeed .. "<br/>"
res = res .. "___________________________________" .. "<br/>"
res = res .. "<br/>"
return res
end
--return results (table)
resultsDiv:node(tostring(resultsTable))
return resultsDiv
end
return p
-- </pre>