--RechargeableGems v0.9 by GraySloth 2014-May-05 ----Config----- local very_dapper_blue_amulet_baseDS = false --For base Don't Starve only, gives the blue amulet the dapperness equivalent of being Maxwell. local very_dapper_blue_amulet_RoG = false --For Realm of Giants local No_Deplete = true --if true Gem items are not destroyed when they reach zero they are just unusable until recharged. if false gem items act as they normally would local Science_Staffs = true --if true the Morning Star and Weather Pain can be repaired with Electrical Doodads. TUNING.PHILOSOPHERS_STONE_lose_sanity = true --if true you lose a point of sanity for every point absorbed by the philosophers stone. local blacklist = {"balloons_empty","philosophers_stone","transistor"} --put item prefab names here for items that the philosophers stone that should not be able to absorbed. TUNING.PHILOSOPHERS_STONE_ABSORB_LOWGAIN = 1 --percent philosophers stone goes up by when absorbing items TUNING.PHILOSOPHERS_STONE_ABSORB_MIDGAIN = 17 --Primary raw gems, nightmare fuel, gold, meat, and living logs. TUNING.PHILOSOPHERS_STONE_ABSORB_HIGHGAIN = 34 --Secondary raw gems, thulecite, and living creatures. --------------- PrefabFiles = { "philosophers_stone", } STRINGS = GLOBAL.STRINGS ACTIONS = GLOBAL.ACTIONS STRINGS.ACTIONS.GRAYSLOTH_RECHARGE = "Recharge" ACTIONS.GRAYSLOTH_RECHARGE = GLOBAL.Action(2, true, true) ACTIONS.GRAYSLOTH_RECHARGE.fn = function(act) if act.target and act.invobject and act.invobject.components.graysloth_recharge then return act.invobject.components.graysloth_recharge:Dorecharge(act.target, act.doer) end end STRINGS.ACTIONS.GRAYSLOTH_ABSORB = "Absorb" ACTIONS.GRAYSLOTH_ABSORB = GLOBAL.Action(2, true, true) ACTIONS.GRAYSLOTH_ABSORB.fn = function(act) if act.target and act.invobject and act.invobject.components.graysloth_absorb then return act.invobject.components.graysloth_absorb:Doabsorb(act.target, act.doer) end end for k,v in pairs(ACTIONS) do if k == "GRAYSLOTH_RECHARGE" or "GRAYSLOTH_ABSORB" then v.str = STRINGS.ACTIONS[k] or "ACTION" v.id = k end end RECIPETABS = GLOBAL.RECIPETABS function makeRecipe() local philosophers_stone = GLOBAL.Recipe("philosophers_stone", {Ingredient("goldnugget", 6), Ingredient("thulecite", 6), Ingredient("nightmarefuel", 6)}, RECIPETABS.ANCIENT, {ANCIENT=4}, nil, nil, true) philosophers_stone.atlas = "images/inventoryimages/philosophers_stone.xml" end AddGamePostInit(makeRecipe) local function onfinished(inst) local replacement = GLOBAL.SpawnPrefab(inst.prefab) if replacement then local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil local pt = GLOBAL.Vector3(inst.Transform:GetWorldPosition()) local holder = owner and ( owner.components.inventory or owner.components.container) local slot = holder and holder:GetItemSlot(inst) inst:Remove() replacement:RemoveComponent("equippable") replacement:RemoveComponent("fueled") replacement:RemoveComponent("spellcaster") replacement:AddComponent("finiteuses") replacement.components.finiteuses:SetUses(0) replacement.nopower = true if holder then holder:GiveItem(replacement,slot) else replacement.Transform:SetPosition(pt:Get()) end end end local function OnLoad(inst, data) if data then if data.nopower then inst:DoTaskInTime(0.1, function() onfinished(inst) end) end end end local function OnSave(inst, data) if inst.nopower then data.nopower = inst.nopower end end local magicstuff = { {name = "amulet"},{name = "blueamulet"},{name = "purpleamulet"},{name = "orangeamulet"},{name = "greenamulet"},{name = "yellowamulet"}, {name = "icestaff"},{name = "firestaff"},{name = "telestaff"},{name = "orangestaff"},{name = "greenstaff"},{name = "yellowstaff"}, } if Science_Staffs then table.insert(magicstuff, {name = "nightstick", type = "SCIENCE"}) table.insert(magicstuff, {name = "staff_tornado", type = "SCIENCE"}) end for k,v in pairs(magicstuff) do local function addmagic(inst) if v.type then inst.chargeType = "GRAYSLOTH_"..v.type else inst.chargeType = "GRAYSLOTH_MAGIC" end inst:AddTag("GRAYSLOTH_INADSORBABLE") if No_Deplete then inst:DoTaskInTime(1, function() if inst.components.finiteuses then inst.components.finiteuses:SetOnFinished( onfinished ) elseif inst.components.fueled then inst.components.fueled:SetDepletedFn(onfinished) end end) inst.OnLoad = OnLoad inst.OnSave = OnSave end end AddPrefabPostInit(v.name, addmagic) end if very_dapper_blue_amulet_baseDS then AddPrefabPostInit("blueamulet", function(inst) if inst.components.dapperness then inst.components.dapperness.dapperness = TUNING.DAPPERNESS_HUGE end end) end if very_dapper_blue_amulet_RoG then AddPrefabPostInit("blueamulet", function(inst) if inst.components.equippable then inst.components.equippable.dapperness = TUNING.DAPPERNESS_HUGE end end) end local function oncharge(inst, target, doer) if doer.SoundEmitter then doer.SoundEmitter:PlaySound("dontstarve/common/teleportato/teleportato_addpart") doer.SoundEmitter:PlaySound("dontstarve/HUD/repair_clothing") end end function makefuel(inst) inst:AddComponent("graysloth_recharge") end AddPrefabPostInit("nightmarefuel", makefuel) function makeEnergizer(inst) inst:AddComponent("graysloth_recharge") inst.components.graysloth_recharge.chargeType = "GRAYSLOTH_SCIENCE" inst.components.graysloth_recharge.oncharge = oncharge end AddPrefabPostInit("transistor", makeEnergizer) for i=1,#blacklist do function setblacklist(inst) inst:AddTag("GRAYSLOTH_INADSORBABLE") end AddPrefabPostInit(blacklist[i], setblacklist) end