Jump to content

Recommended Posts

I just realized that changing your nighttime sanity rating doesn’t seem to affect your Lunacy sanity rating, but I’m having trouble figuring out how to edit it, since it’s a part of sanity, but it seems like it’s meant to stay at the original default value.  Does anyone see a way to edit the value, because I don’t.

Link to comment
https://forums.kleientertainment.com/forums/topic/128446-lunacy-rating/
Share on other sites

In components/sanity.lua

I think Sanity:OnUpdate (336) is the main update function.

This calls Sanity:Recalc(dt) (386)

This is the part that calculates the light delta

    local light_sanity_drain = LIGHT_SANITY_DRAINS[self.mode]
    local light_delta = 0

    if not self.light_drain_immune then
        if TheWorld.state.isday and not TheWorld:HasTag("cave") then
            light_delta = light_sanity_drain.DAY
        else
            local lightval = CanEntitySeeInDark(self.inst) and .9 or self.inst.LightWatcher:GetLightValue()
            light_delta =
                (   (lightval > TUNING.SANITY_HIGH_LIGHT and light_sanity_drain.NIGHT_LIGHT) or
                    (lightval < TUNING.SANITY_LOW_LIGHT and light_sanity_drain.NIGHT_DARK) or
                    light_sanity_drain.NIGHT_DIM
                ) * self.night_drain_mult
        end
    end

In components/sanity.lua:364

local LIGHT_SANITY_DRAINS =
{
	[SANITY_MODE_INSANITY] = {
		DAY = TUNING.SANITY_DAY_GAIN,
		NIGHT_LIGHT = TUNING.SANITY_NIGHT_LIGHT,
		NIGHT_DIM = TUNING.SANITY_NIGHT_MID,
		NIGHT_DARK = TUNING.SANITY_NIGHT_DARK,
	},
	[SANITY_MODE_LUNACY] = {
		DAY = TUNING.SANITY_LUNACY_DAY_GAIN,
		NIGHT_LIGHT = TUNING.SANITY_LUNACY_NIGHT_LIGHT,
		NIGHT_DIM = TUNING.SANITY_LUNACY_NIGHT_MID,
		NIGHT_DARK = TUNING.SANITY_LUNACY_NIGHT_DARK,
	},
}

In Tuning.lua:1830

        SANITY_DAY_GAIN = 0,--100/(day_time*32),

        SANITY_NIGHT_LIGHT = -100/(night_time*20),
        SANITY_NIGHT_MID = -100/(night_time*20),
        SANITY_NIGHT_DARK = -100/(night_time*2),

        SANITY_LUNACY_DAY_GAIN = 100/(day_time*32),
        SANITY_LUNACY_NIGHT_LIGHT = 0,
        SANITY_LUNACY_NIGHT_MID = 0,
        SANITY_LUNACY_NIGHT_DARK = -100/(night_time*10),

As far as I can tell,

Lunacy dusk (NIGHT_LIGHT), and night (NIGHT_MID) values are 0. So you can't really multiply them.

Also, the "day" light delta (lunacy) has no multiplier in that part of the code.

So if you wanted to use a day lunacy "multiplier" or apply dusk/night lunacy to a character, I think you'd have to use

components/sanity.lua:456

    if self.custom_rate_fn ~= nil then
        --NOTE: dt param was added for wormwood's custom rate function
        --      dt shouldn't have been applied to the return value yet
        self.rate = self.rate + self.custom_rate_fn(self.inst, dt)
    end

As seen with Wormwood/Walter/... etc

prefabs/wormwood.lua:607

    inst.components.sanity.custom_rate_fn = SanityRateFn

prefabs/walter.lua:230

    inst.components.sanity.custom_rate_fn = CustomSanityFn

And code it (back) in yourself :O

 

Hope this helps!

Edited by Bigfootmech
  • Like 1

@Bigfootmech
lol, so I was right!  It can’t be manipulated like the other rates (glad I was able to understand that.)  Coding a custom sanity function specifically so I can affect the player’s Lunacy may not be worth it, unless it’s super basic.  I’ll take a look at Wormwood and Walter’s prefabs, but both characters are so complex compared to the rest that I expect it won’t be worth the effort. (Maybe I’m wrong, idk)

13 hours ago, FurryEskimo said:

unless it’s super basic.

Shouldn't be too hard.

components/sanity.lua:459

self.rate = self.rate + self.custom_rate_fn(self.inst, dt)

The function gets "inst" passed, which is probably either the player, or the sanity component itself.

Copying part of the light delta

But accounting for the fact that normal lunacy light delta would have already been applied.

Also, paying attention to the fact that caves lunacy is always 0? And we're only tweaking the Lunar island one as far as I can tell.

So maybe something like


local function CustomDrainFunc(self, dt) -- assuming self is the sanity component. If it's the player, replace self with self.components.sanity, or self.inst.replica.sanity??
	if not self.light_drain_immune TheWorld.state.isday and not TheWorld:HasTag("cave") and self.mode == SANITY_MODE_LUNACY then
		local myNewLuncayRedo = - TUNING.SANITY_DAY_GAIN + TUNING.SANITY_DAY_GAIN * mySecretMultiplier -- normal lunacy already applied. Remove it, and then reapply with multiplier.
		local myNewLunacyAdjust = TUNING.SANITY_DAY_GAIN * mySecretMultiplier -- value to be added to existing lunacy, to save a bit of calculation, but makes it look more confusing in code.
		return myNewLuncay
	else
		return 0
	end
end

 

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...