Skip to content

Commit

Permalink
Merge pull request #132 from gamrguy/master
Browse files Browse the repository at this point in the history
Fix apexRageBonus, utility changes
  • Loading branch information
sayterdarkwynd authored Jan 21, 2019
2 parents 0b47266 + 0e76174 commit f096fe6
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 15 deletions.
17 changes: 11 additions & 6 deletions scripts/FRHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ function FRHelper:new(species,gender)
end

-- Applies the given status parameters (name is required for setting persistent effects)
-- Is a combination of applying persistent effects, control modifiers, and scripts all in one
-- Extra arguments are sent to any scripts run
function FRHelper:applyStats(stats, name, ...)
if name then
if not compare(stats.stats or {},self.persistentEffects[name]) then
status.setPersistentEffects(name, stats.stats or {})
self.persistentEffects[name] = stats.stats or {}
end
end
if name then self:applyPersistent(stats.stats, name) end
self:applyControlModifiers(stats.controlModifiers, stats.controlParameters)
if stats.scripts then
for _,script in ipairs(stats.scripts) do
Expand All @@ -72,6 +68,15 @@ function FRHelper:checkStatusApplied(name)
return #status.getPersistentEffects(name) > 0 and true or false
end

-- Apply the given persistent effect with the given name
function FRHelper:applyPersistent(stats, name)
-- Don't reapply an identical persistent effect
if not compare(stats or {},self.persistentEffects[name]) then
status.setPersistentEffects(name, stats or {})
self.persistentEffects[name] = stats or {}
end
end

-- Function for clearing applied persistent effects added through applyStats()
-- With name, it clears the effect with the matching name. Otherwise, clears all.
function FRHelper:clearPersistent(name)
Expand Down
50 changes: 50 additions & 0 deletions scripts/fr_scripts/apexRageBonus.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require("/scripts/vec2.lua")
require("/scripts/util.lua")

--[[
This script gives a scaling status effect based on health lost.
The effects increase starting from healthRange[1] and reach their maximum at healthRange[2].
Arguments:
"args" : {
"healthRange" : [0.8, 0.1] -- % of health when this effect starts and stops increasing
"stats" : [ -- Which stats this applies, and their maximum values
{ "stat" : "maxEnergy", "effectiveMultiplier" : 0.3 },
{ "stat" : "powerMultiplier", "effectiveMultiplier" : 1.3 },
...
]
}
]]

function FRHelper:call(args, ...)
if not args or not args.healthRange then return end

local healthRange = args.healthRange
local health = status.resourcePercentage("health")
if health > healthRange[1] then return end

-- Scale the current health % to the area of interest
local healthRelative = math.max(0, (health - healthRange[2]) / (healthRange[1] - healthRange[2]))
local scale = 1 - healthRelative

local scaleMultiplier = function (mult, scaleThing)
if mult >= 1 then
return 1 + (mult - 1) * scaleThing
elseif mult < 1 then
return mult + (1 - mult) * healthRelative
end
end

local stats = util.map(args.stats,
function (v)
return {
stat = v.stat,
amount = v.amount and v.amount * scale,
baseMultiplier = v.baseMultiplier and scaleMultiplier(v.baseMultiplier, scale),
effectiveMultiplier = v.effectiveMultiplier and scaleMultiplier(v.effectiveMultiplier, scale)
}
end
)

self:applyPersistent(stats, "FR_speciesRageBonus")
end
15 changes: 13 additions & 2 deletions species/apex.raceeffect
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@
]
}
],
"special": [
"apexRageBonus"
"scripts": [
{
"script" : "/scripts/fr_scripts/apexRageBonus.lua",
"args" : {
"healthRange" : [ 0.8, 0.1 ],
"stats" : [
{ "stat" : "maxEnergy", "effectiveMultiplier" : 0.3 },
{ "stat" : "powerMultiplier", "effectiveMultiplier" : 1.3 },
{ "stat" : "protection", "effectiveMultiplier" : 1.2 },
{ "stat" : "critChance", "amount" : 5 }
]
}
}
]
}
12 changes: 5 additions & 7 deletions stats/raceability.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@ function init()
self.helper:loadScript({script=path, args=self.helper.speciesConfig[map]})
end
end

-- Add the stats
self.statID = effect.addStatModifierGroup(self.helper.stats or {})
for _,script in pairs(self.helper.speciesConfig.scripts or {}) do
self.helper:loadScript(script)
end

script.setUpdateDelta(10)
end

function update(dt)
if not self.species then init() end

self.helper:applyControlModifiers()
self.helper:clearPersistent()
self.helper:applyControlModifiers()
self.helper:applyPersistent(self.helper.speciesConfig.stats, "FR_racialStats")
self.helper:runScripts("racialscript", self, dt)
end

function uninit()
if self.statID then
effect.removeStatModifierGroup(self.statID)
end
if self.helper then
self.helper:clearPersistent()
end
Expand Down

0 comments on commit f096fe6

Please sign in to comment.