Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

icantevenname

Sanity From Rain

Recommended Posts

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?

Share this post


Link to post
Share on other sites
pickleplayer    130
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.

Share this post


Link to post
Share on other sites
CarlZalph    1,552

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

 

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
CarlZalph    1,552
1 minute ago, icantevenname said:

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

Items still slip, this is just sanity related goodies.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
CarlZalph    1,552
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.

Share this post


Link to post
Share on other sites
41 minutes ago, CarlZalph said:

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.

Thanks for the help!

Share this post


Link to post
Share on other sites