Jump to content

Recommended Posts

I'm looking at alwaysontikitorch and it gives sanity aura... the code:

 

inst:AddComponent("sanityaura")
    inst.components.sanityaura.aura = TUNING.SANITYAURA_TINY
 
The sanityaura component lua is:
local SanityAura = Class(function(self, inst)
    self.inst = inst
    self.aura = 0
    self.aurafn = nil
    self.penalty = nil
end)
 
function SanityAura:GetAura(observer)
if self.aurafn then
return self.aurafn(self.inst, observer)
end
return self.aura
end
 
return SanityAura
 
Nothing about giving or taking away sanity.
How does it work?

 

Thanks.

@SenL, The sanityaura component doesn't take away sanity by itself. Instead, the sanity component looks at the values of the sanityaura components of entities around you and add them to the the character's overall sanity drop/gain rate.

 

It all happens in the Recalc method of sanity:

local aura_delta = 0	local x,y,z = self.inst.Transform:GetWorldPosition()	local ents = TheSim:FindEntities(x,y,z, TUNING.SANITY_EFFECT_RANGE, nil, {"FX", "NOCLICK", "DECOR","INLIMBO"} ) -- this looks for all mobs around the player    for k,v in pairs(ents) do 		if v.components.sanityaura and v ~= self.inst then -- checks if they have a sanity aura			local distsq = self.inst:GetDistanceSqToInst(v)			local aura_val = v.components.sanityaura:GetAura(self.inst)/math.max(1, distsq)			if aura_val < 0 then				aura_val = aura_val * self.neg_aura_mult			end			aura_delta = aura_delta + aura_val		end    end
self.rate = (dapper_delta + light_delta + aura_delta + rain_delta) -- this adds the sum of all sanity auras to the overall sanity rate

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...