Health Up modifier for non-red characters + misc (#710)

* Health up / different effect modifiers

* ClosestPlayerTo, move utility functions

* ClosestPlayer adds to DifferentEffectPlayers table

* More data tables for Health Ups

* useless Lost items, comment the health mod atm

* HealingRed, RedToX

* HealingRed added

* Moving Pluralize

* oops

* Move Pluralize

* Move Pluralize

* allow choosing the position of modifiers in the table

* default layer to 0

* Changes to no red char conditions

* Support healing items in the modifier

* tweaks to health up data

* Support {1} in Result Header

* {1} in ResultHeader

* Tweak binge eater wording

* reword comment
This commit is contained in:
Buurazu authored and GitHub committed 2024-08-19 19:52:56 +02:00
1 parent 9d8a2ae730
commit e271302f69
29 files changed
+355 -230

No files matched your search

+39 -2
View File
@@ -1167,7 +1167,8 @@ end
-- Adds Description object modifiers.
-- Used for altering descriptions. Example: Spindown dice, Tarot Cloth, ...
function EID:addDescriptionModifier(modifierName, condition, callback)
function EID:addDescriptionModifier(modifierName, condition, callback, position)
position = position or #EID.DescModifiers + 1
for _,v in ipairs(EID.DescModifiers) do
if v["name"] == modifierName then
v["condition"] = condition
@@ -1175,7 +1176,7 @@ function EID:addDescriptionModifier(modifierName, condition, callback)
return
end
end
table.insert(EID.DescModifiers, {
table.insert(EID.DescModifiers, position, {
name = modifierName,
condition = condition,
callback = callback
@@ -2411,6 +2412,21 @@ function EID:CopyTable(orig)
end
return copy
end
-- super simple table concatenation: https://www.tutorialspoint.com/concatenation-of-tables-in-lua-programming
function EID:ConcatTables(t1, t2)
for i = 1, #t2 do
t1[#t1 + 1] = t2[i]
end
return t1
end
-- thing to fix find/replace pairs with hyphens (like "1-2") or pluses (like +1 Health) breaking because of special characters
-- https://stackoverflow.com/questions/29072601/lua-string-gsub-with-a-hyphen
function EID:SimpleReplace(str, what, with, count)
what = string.gsub(what, "[%(%)%.%+%-%*%?%[%]%^%$%%]", "%%%1") -- escape pattern
with = string.gsub(with, "[%%]", "%%%%") -- escape replacement
return string.gsub(str, what, with, count)
end
-- simple decimal rounding, instead of just floor or ceil
function EID:SimpleRound(num, dp)
@@ -2425,3 +2441,24 @@ function EID:ArrayContains(t, value)
end
return false
end
-- Find the closest player to the given entity
function EID:ClosestPlayerTo(entity)
local closestDist = 9999999
local closestPlayer = EID.player
local numPlayers = game:GetNumPlayers()
if EID.InsideItemReminder then return EID.ItemReminderPlayerEntity end
if entity == nil or numPlayers == 1 then return closestPlayer end
for i = 1, #EID.coopAllPlayers do
local player = EID.coopAllPlayers[i]
local dist = player.Position:Distance(entity.Position)
if dist < closestDist then
closestDist = dist
closestPlayer = player
end
end
return closestPlayer
end