Jump to content

Sanity Drain over time / Sanity gain from holding Gems


Recommended Posts

So, I am attempting to have a similar mechanic to how Wurt gains sanity from holding fish for my boy Cass as well as have him lose sanity over time (He's suppose to be not too sound of mind, having a low max sanity of 100 and losing it over time, but able to have a permanent sanity source by holding a gem in his inventory) . However, neither mechanic seems to be working. The desire is for him to be able to counter his sanity drain by holding a gem, but since he also would want to use those gems to make magic items (Staves, amulets, ect) it sort of balances out a bit.

Here's the code I have in his prefab / Character.lua file:

First for Gaining Sanity from Gems:

Spoiler

inst:AddComponent("itemaffinity")
    inst.components.itemaffinity:AddAffinity(nil, "redgem", -TUNING.DAPPERNESS_TINY, 1)
    inst.components.itemaffinity:AddAffinity(nil, "bluegem", -TUNING.DAPPERNESS_TINY, 1)
    inst.components.itemaffinity:AddAffinity(nil, "purplegem", -TUNING.DAPPERNESS_MED, 1)
    inst.components.itemaffinity:AddAffinity(nil, "orangegem", -TUNING.DAPPERNESS_LARGE, 1)
    inst.components.itemaffinity:AddAffinity(nil, "yellowgem", -TUNING.DAPPERNESS_MED, 1)
    inst.components.itemaffinity:AddAffinity(nil, "greengem", -TUNING.DAPPERNESS_MED, 1)
    inst.components.itemaffinity:AddAffinity(nil, "opalpreciousgem", -TUNING.DAPPERNESS_LARGE, 1)

and the code I tried to use for sanity loss over time:

Spoiler

-- Hunger rate (optional)
    inst.components.hunger.hungerrate = 0.25
    inst.components.sanity.sanityrate = 0.10

I'm pretty sure I did something wrong here, maybe I need a tag or something. If anybody could help that'd be awesome!

Link to comment
Share on other sites

function ItemAffinity:AddAffinity(prefab, tag, sanity_bonus, priority)
    table.insert(self.affinities, {prefab = prefab, tag= tag, sanity_bonus = sanity_bonus, priority = priority})
    self:RefreshAffinity()
end

You may have your tags and prefabs in the wrong order so 
like this instead:

"inst.components.itemaffinity:AddAffinity("redgem", nil, -TUNING.DAPPERNESS_TINY, 1)" 

Edited by thomas4846
Link to comment
Share on other sites

21 hours ago, thomas4846 said:

You may have your tags and prefabs in the wrong order so 
like this instead:

"inst.components.itemaffinity:AddAffinity("redgem", nil, -TUNING.DAPPERNESS_TINY, 1)" 

Thanks! That worked, though I realized I needed to remove the - in front of TUNING.DAPPERNESS because it was draining instead of gaining.

That being said, I need to figure out how to tweak the priority so that it favors the larger bonuses over the smaller ones. This is what I have set up so far:

Spoiler

inst:AddComponent("itemaffinity")
    inst.components.itemaffinity:AddAffinity("redgem", nil, TUNING.DAPPERNESS_TINY, 4)
    inst.components.itemaffinity:AddAffinity("bluegem", nil, TUNING.DAPPERNESS_TINY, 4)
    inst.components.itemaffinity:AddAffinity("purplegem", nil, TUNING.DAPPERNESS_SMALL, 3)
    inst.components.itemaffinity:AddAffinity("yellowgem", nil, TUNING.DAPPERNESS_MED, 2)
    inst.components.itemaffinity:AddAffinity("greengem", nil, TUNING.DAPPERNESS_MED, 2)
    inst.components.itemaffinity:AddAffinity("orangegem", nil, TUNING.DAPPERNESS_LARGE, 1)
    inst.components.itemaffinity:AddAffinity("opalpreciousgem", nil, TUNING.DAPPERNESS_LARGE, 1)

 

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