-
Notifications
You must be signed in to change notification settings - Fork 0
/
apfcritandfumble.lua
80 lines (72 loc) · 2.6 KB
/
apfcritandfumble.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
--
-- Please see the LICENSE.md file included with this distribution for attribution and copyright information.
--
-- Determine weapon name
local function getWeaponName(s)
local sWeaponName = s:gsub('%[ATTACK %(%u%)%]', '');
sWeaponName = sWeaponName:gsub('%[ATTACK #%d+ %(%u%)%]', '');
sWeaponName = sWeaponName:gsub('%[%u+%]', '');
if sWeaponName:match('%[USING ') then sWeaponName = sWeaponName:match('%[USING (.-)%]'); end
sWeaponName = sWeaponName:gsub('%[.+%]', '');
sWeaponName = sWeaponName:gsub(' %(vs%. .+%)', '');
sWeaponName = StringManager.trim(sWeaponName);
return sWeaponName or ''
end
-- Check for Extended Automation and whether the attack is tagged as a spell or spell-like ability
local function kelSpell(rRoll)
return rRoll.tags and (rRoll.tags:match('spell') or rRoll.tags:match('spelllike'))
end
-- Check if Advanced Effects is loaded and whether the attack has a Weapon attached
local function advEffectsSpell(rSource)
return AdvancedEffects and not rSource.nodeWeapon
end
-- Determine attack type
local function attackType(rSource, rRoll)
for kDmgType, _ in pairs(DataCommon.naturaldmgtypes) do
if string.find(getWeaponName(rRoll.sDesc):lower(), kDmgType) then
return "Natural";
end
end
if kelSpell(rRoll) or advEffectsSpell(rSource) then
return "Magic";
elseif string.match(rRoll.sDesc, "%[ATTACK.*%((%w+)%)%]") == "R" then
return "Ranged";
else
return "Melee";
end
end
-- Determine damage type
local function damageType(rSource, rRoll)
local sWeapon = getWeaponName(rRoll.sDesc);
local aDmgTypes = { DataCommon.naturaldmgtypes, DataCommon.weapondmgtypes };
for _, tDmgTypes in pairs(aDmgTypes) do
for kDmgType, vDmgType in pairs(tDmgTypes) do
if string.find(sWeapon:lower(), kDmgType) then
if type(vDmgType) == 'string' then
return vDmgType:gsub(',.*', '');
else
return vDmgType['*'];
end
end
end
end
if kelSpell(rRoll) or advEffectsSpell(rSource, rRoll) then
return "Magic";
else
return 'bludgeoning'
end
end
local function onPostAttackResolve_new(rSource, _, rRoll)
-- HANDLE FUMBLE/CRIT HOUSE RULES
local sOptionHRFC = OptionsManager.getOption("HRFC");
if rRoll.sResult == "fumble" and ((sOptionHRFC == "both") or (sOptionHRFC == "fumble")) then
AutoPFCritFumbleOOB.notifyApplyHRFC('Fumble - ' .. attackType(rSource, rRoll));
end
if rRoll.sResult == "crit" and ((sOptionHRFC == "both") or (sOptionHRFC == "criticalhit")) then
AutoPFCritFumbleOOB.notifyApplyHRFC('Critical - ' .. StringManager.titleCase(damageType(rSource, rRoll)));
end
end
-- Function Overrides
function onInit()
ActionAttack.onPostAttackResolve = onPostAttackResolve_new;
end