Skip to content

Commit

Permalink
floran regen fix for NPC
Browse files Browse the repository at this point in the history
  • Loading branch information
sayterdarkwynd committed Jan 29, 2019
1 parent e719f1f commit aca03db
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
16 changes: 12 additions & 4 deletions stats/effects/regeneration/foodregen.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
function init()
local bounds = mcontroller.boundBox()
script.setUpdateDelta(5)
local foodvalue = status.resource("food")
if world.entityType(entity.id()) == "npc" then
local foodvalue = 35
else
local foodvalue = status.resource("food")
end

end

function update(dt)

if self.foodvalue == nil then
foodvalue=1
foodvalue=1
end

self.foodvalue = status.resource("food")
if world.entityType(entity.id()) == "npc" then
self.foodvalue = 35
else
self.foodvalue = status.resource("food")
end

if self.foodvalue > 50 then
self.healingRate = 1.0005 / config.getParameter("healTime", 140)
Expand Down
60 changes: 39 additions & 21 deletions stats/effects/regeneration/lightregenfloran.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ function init()
-- regen default
self.healingRate = 1.01 / config.getParameter("healTime", 220)
--food defaults
hungerMax = { pcall(status.resourceMax, "food") }
hungerMax = hungerMax[1] and hungerMax[2]
hungerLevel = status.resource("food")
baseValue = config.getParameter("healthDown",0)*(status.resourceMax("food"))
if not world.entityType(entity.id()) == "npc" then
hungerMax = { pcall(status.resourceMax, "food") }
hungerMax = hungerMax[1] and hungerMax[2]
hungerLevel = status.resource("food")
else
hungerMax = 70
hungerLevel = 30
end

baseValue = config.getParameter("healthDown",0)*(hungerLevel)

self.tickTime = 1.0
self.tickTimePenalty = 5.0
self.tickTimer = self.tickTime
Expand Down Expand Up @@ -47,32 +54,39 @@ function update(dt)
hungerLevel = 50
end
--food defaults
hungerMax = { pcall(status.resourceMax, "food") }
hungerMax = { pcall(status.resourceMax, self.foodValue) }
hungerMax = hungerMax[1] and hungerMax[2]


baseValue = config.getParameter("healthDown",0)*(status.resourceMax("food"))
self.tickTimer = self.tickTimer - dt
self.tickTimerPenalty = self.tickTimerPenalty - dt
self.foodValue = status.resource("food")
self.foodValue = status.resource("food") or 30

baseValue = config.getParameter("healthDown",0)*(self.foodValue)

-- Night penalties
if not daytime then -- Florans lose HP and Energy when the sun is not out
status.setPersistentEffects("nightpenalty", {
{stat = "maxHealth", baseMultiplier = 0.90 },
{stat = "maxEnergy", baseMultiplier = 0.70 }
})
-- when the sun is down, florans lose food
if (hungerLevel < hungerMax) and ( self.tickTimerPenalty <= 0 ) then
self.tickTimerPenalty = self.tickTimePenalty
--reduce the hunger drain if bathed in light
if lightLevel > 25 then --you can reduce the drain with light
adjustedHunger = hungerLevel - (hungerLevel * 0.0095)
status.setResource("food", adjustedHunger)
else
-- otherwise we lose normal amount
adjustedHunger = hungerLevel - (hungerLevel * 0.016)
status.setResource("food", adjustedHunger)
end
if not world.entityType(entity.id()) == "npc" then
if (hungerLevel < hungerMax) and ( self.tickTimerPenalty <= 0 ) then
self.tickTimerPenalty = self.tickTimePenalty
--reduce the hunger drain if bathed in light
if lightLevel > 25 then --you can reduce the drain with light
adjustedHunger = hungerLevel - (hungerLevel * 0.0095)
if not world.entityType(entity.id()) == "npc" then
status.setResource("food", adjustedHunger)
end
else
-- otherwise we lose normal amount
adjustedHunger = hungerLevel - (hungerLevel * 0.016)
if not world.entityType(entity.id()) == "npc" then
status.setResource("food", adjustedHunger)
end
end
end
end
end

Expand All @@ -96,7 +110,9 @@ function update(dt)
if (hungerLevel < hungerMax) and ( self.tickTimer <= 0 ) then
self.tickTimer = self.tickTime
adjustedHunger = hungerLevel + (hungerLevel * 0.008)
status.setResource("food", adjustedHunger)
if not world.entityType(entity.id()) == "npc" then
status.setResource("food", adjustedHunger)
end
end

-- When it is sunny and they are well fed, florans regenerate
Expand All @@ -105,7 +121,9 @@ function update(dt)
self.healingRate = 0
status.modifyResourcePercentage("health", self.healingRate * dt)
elseif underground and lightLevel > 60 then -- we cant do it well underground and it costs food
status.modifyResource("food", (status.resource("food") * -0.005) )
if not world.entityType(entity.id()) == "npc" then
status.modifyResource("food", (status.resource("food") * -0.005) )
end
self.healingRate = 1.00005 / config.getParameter("healTime", 320)
status.modifyResourcePercentage("health", self.healingRate * dt)
elseif lightLevel > 95 then
Expand Down

0 comments on commit aca03db

Please sign in to comment.