-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpr.lua
More file actions
79 lines (66 loc) · 2.53 KB
/
expr.lua
File metadata and controls
79 lines (66 loc) · 2.53 KB
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
-- expr.lua
-- Expression helper functions for spell parameter evaluation
local Constants = require("core.Constants")
local ManaHelpers = require("systems.ManaHelpers")
local expr = {}
-- Choose whichever token is more abundant in the shared pool
function expr.more(a, b)
return function(caster)
local manaPool = caster and caster.manaPool
return ManaHelpers.count(a, manaPool) > ManaHelpers.count(b, manaPool) and b or a
end
end
-- Choose the scarcer token
function expr.less(a, b)
return function(caster)
local manaPool = caster and caster.manaPool
return ManaHelpers.count(a, manaPool) < ManaHelpers.count(b, manaPool) and a or b
end
end
-- Choose a token type based on a condition
function expr.ifCond(condition, trueValue, falseValue)
return function(caster, target, slot)
if condition(caster, target, slot) then
return trueValue
else
return falseValue
end
end
end
-- Choose a value based on elevation state
function expr.byElevation(elevationValues)
return function(caster, target, slot)
local entityToCheck = target or caster
local elevation = entityToCheck and entityToCheck.elevation or "GROUNDED"
return elevationValues[elevation] or elevationValues.default
end
end
-- Choose a value based on range state
function expr.byRange(rangeValues)
return function(caster, target, slot)
local rangeState = caster and caster.gameState and caster.gameState.rangeState or "NEAR"
return rangeValues[rangeState] or rangeValues.default
end
end
-- Choose a value based on which wizard has more tokens
function expr.whoHasMore(tokenType, casterValue, targetValue)
return function(caster, target, slot)
if not caster or not target or not caster.manaPool or not target.manaPool then
return casterValue -- Default to caster value if we can't determine
end
local casterCount = ManaHelpers.count(tokenType, caster.manaPool)
local targetCount = ManaHelpers.count(tokenType, target.manaPool)
return casterCount >= targetCount and casterValue or targetValue
end
end
-- Calculate a value based on the number of tokens
function expr.countScale(tokenType, baseValue, multiplier)
return function(caster, target, slot)
if not caster or not caster.manaPool then
return baseValue
end
local count = ManaHelpers.count(tokenType, caster.manaPool)
return baseValue + (count * multiplier)
end
end
return expr