Jump to content

Sanity From Rain


Recommended Posts

1 hour ago, icantevenname said:

A character I'm working on is a plant. So it doesn't make sense if she loses sanity from rain. How do I make it so she gains sanity instead?

 

Well in DST, sanity drop is actually based on the characters moisture (wetness) level, not just on rain. Though I can't find where the sanity drop happens in moisture.lua, one really quick and dirty way to prevent the sanity drop in the rain would be to just make her waterproof.

Link to comment
Share on other sites

Most of the magic happens in the sanity component's Recalc function.

local easing = require("easing")
inst.components.sanity.custom_rate_fn = function(inst)
    local wet_dapperness = 0
    for _,v in pairs(inst.components.inventory.equipslots)
    do
        if v.components.equippable ~= nil
        then
            if v.components.equippable.inst:GetIsWet()
            then
                wet_dapperness = wet_dapperness + TUNING.WET_ITEM_DAPPERNESS
            end
        end
    end
    wet_dapperness = wet_dapperness * inst.components.sanity.dapperness_mult
    local wet_dapper_delta = wet_dapperness * TUNING.SANITY_DAPPERNESS
    local moisture_delta = easing.inSine(inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, inst.components.moisture:GetMaxMoisture())
    return -2.0*(moisture_delta+wet_dapper_delta)
end

-2.0 because by default it'll punish your sanity by a rate of moisture_delta, so it takes 2 to get it to zero and then beneficial.

The formula for moisture_delta ripped straight from the function so be sure to keep it in sync during game updates.

(This hasn't changed in long time.)

 

Also included is the dapperness portion of wet items such that you'll benefit from the wet items.

You can adjust this as you see fit.

Spoiler

-2.0*(moisture_delta+wet_dapper_delta) :: both benefit

-2.0*moisture_delta-wet_dapper_delta :: benefit from moisture, cancel wet items doing anything

-2.0*moisture_delta :: benefit from moisture, do nothing with wet items - should also delete the code portion revolving around the wet items to increase performance

 

Link to comment
Share on other sites

On 3/17/2017 at 0:32 AM, CarlZalph said:

Most of the magic happens in the sanity component's Recalc function.


local easing = require("easing")
inst.components.sanity.custom_rate_fn = function(inst)
    local wet_dapperness = 0
    for _,v in pairs(inst.components.inventory.equipslots)
    do
        if v.components.equippable ~= nil
        then
            if v.components.equippable.inst:GetIsWet()
            then
                wet_dapperness = wet_dapperness + TUNING.WET_ITEM_DAPPERNESS
            end
        end
    end
    wet_dapperness = wet_dapperness * inst.components.sanity.dapperness_mult
    local wet_dapper_delta = wet_dapperness * TUNING.SANITY_DAPPERNESS
    local moisture_delta = easing.inSine(inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, inst.components.moisture:GetMaxMoisture())
    return -2.0*(moisture_delta+wet_dapper_delta)
end

-2.0 because by default it'll punish your sanity by a rate of moisture_delta, so it takes 2 to get it to zero and then beneficial.

The formula for moisture_delta ripped straight from the function so be sure to keep it in sync during game updates.

(This hasn't changed in long time.)

 

Also included is the dapperness portion of wet items such that you'll benefit from the wet items.

You can adjust this as you see fit.

  Hide contents

-2.0*(moisture_delta+wet_dapper_delta) :: both benefit

-2.0*moisture_delta-wet_dapper_delta :: benefit from moisture, cancel wet items doing anything

-2.0*moisture_delta :: benefit from moisture, do nothing with wet items - should also delete the code portion revolving around the wet items to increase performance

 

I still want the item slip chance, so which doesn't affect that?

Link to comment
Share on other sites

6 hours ago, CarlZalph said:

Items still slip, this is just sanity related goodies.

I did something wrong, and I'm not sure what I'm supposed to do.

Line 40 is the

inst.components.sanity.custom_rate_fn = function(inst)

part. What does it mean by it isn't declared?

20170320224252_1.jpg

Link to comment
Share on other sites

1 minute ago, icantevenname said:

I did something wrong, and I'm not sure what I'm supposed to do.

Line 40 is the

inst.components.sanity.custom_rate_fn = function(inst)

part. What does it mean by it isn't declared?

It should be in your master_postinit callback to ensure the component is there, and 'inst' refers to the player prefab instance in this case.

Link to comment
Share on other sites

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
 Share

×
  • Create New...