irpagan
May 18th, 2015, 15:41
I'm missing something here, pretty sure its simple but for the life of me I'm missing it.
The short of it is, I have a function called performRestRecovery(rActor) which is supposed to perform some calculations based on the health of a character and then update the appropriate window controls which would then trigger the onValueChanged() function for those fields. Updating the value of lethal or subdual values triggers the onValueChanged() and updates current. Modifying the HP value also triggers an onValueChanged() which recalculates everything.
In template_char.xml I defined the button control as
<template name="button_char_rest">
<button_roll>
<tooltip textres="spell_tooltip_cc" />
<script>
function onButtonPress()
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
ActorManager2.performRestRecovery(rActor));
end
</script>
</button_roll>
</template>
Then in manager_actor2.lua I defined my function
-- @comment: Talislanta 5e
-- Recover Hit Points after rest and Recovery
function performRestRecovery(rActor)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
if not nodeActor then
return 0;
end
local ttlHp, hpDelta, sbdl, lthl, currHp = 0;
local newCurrHp, hpHealed, pCon = 0;
if sActorType == "pc" then
ttlHp = DB.getValue(nodeActor, "abilities.hitpoints.score", 0);
sbdl = DB.getValue(nodeActor, "health.subdual.score", 0);
lthl = DB.getValue(nodeActor, "health.lethal.score", 0);
currHp = DB.getValue(nodeActor, "health.currenthitpoints.score", 0);
pCon = DB.getValue(nodeActor, "abilities.constitution.score", 0);
end
-- calculations
hpHealed = 5 + pCon;
hpDelta = ttlHp - currHp;
-- if a neg or zero make 1
if hpHealed <= 0 then
hpHealed = 1;
end
-- Make sure we have something to heal
if hpDelta > 0 then
-- subdual damage should heal first
if sbdl > 0 then
if sbdl <= hpHealed then
--[[ If subdual damage is less than the hpHealed, subtract subdual from Hp Healed, set db value for
subdual to 0 which should trigger updateCurrentHitpoints(rActor) I think* ]]--
hpHealed = hpHealed - sbdl;
sbdl = 0;
else
--[[ other wise same thing excapt we still have damage to heal after this set ]]--
sbdl = sbdl - hpHealed;
end
--DB.setValue(nodeChar, "health.subdual.score", "number", tonumber(sbdl));
charsheet_main.hpsubdual.setValue(tonumber(sbdl));
end
--[[ Subdual damage was 0 or subdual was less than hp Healed and we still have hp to heal ]]--
if sbdl == 0 and lthl > 0 then
if lthl <= hpHealed then
--[[ If LETHAL damage is less than the hpHealed, subtract LETHAL from Hp Healed, set db value for
lthl to 0 which should trigger updateCurrentHitpoints(rActor) I think* ]]--
hpHealed = hpHealed - lthl;
lthl = 0;
else
--[[ other wise same thing excapt we still have damage to heal after this set ]]--
lthl = lthl - hpHealed;
end
--DB.setValue(nodeChar, "health.lethal.score", "number", tonumber(lthl));
window.hplethal.setValue(tonumber(lthl));
end
end
end
I did try updating the underlying db with a DB.setValue() but the only thing I accomplished was corrupting the character record and it did not trigger any onValueChanged() event.
Any advice would be welcome.
Regards,
-d0gb0y
The short of it is, I have a function called performRestRecovery(rActor) which is supposed to perform some calculations based on the health of a character and then update the appropriate window controls which would then trigger the onValueChanged() function for those fields. Updating the value of lethal or subdual values triggers the onValueChanged() and updates current. Modifying the HP value also triggers an onValueChanged() which recalculates everything.
In template_char.xml I defined the button control as
<template name="button_char_rest">
<button_roll>
<tooltip textres="spell_tooltip_cc" />
<script>
function onButtonPress()
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
ActorManager2.performRestRecovery(rActor));
end
</script>
</button_roll>
</template>
Then in manager_actor2.lua I defined my function
-- @comment: Talislanta 5e
-- Recover Hit Points after rest and Recovery
function performRestRecovery(rActor)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
if not nodeActor then
return 0;
end
local ttlHp, hpDelta, sbdl, lthl, currHp = 0;
local newCurrHp, hpHealed, pCon = 0;
if sActorType == "pc" then
ttlHp = DB.getValue(nodeActor, "abilities.hitpoints.score", 0);
sbdl = DB.getValue(nodeActor, "health.subdual.score", 0);
lthl = DB.getValue(nodeActor, "health.lethal.score", 0);
currHp = DB.getValue(nodeActor, "health.currenthitpoints.score", 0);
pCon = DB.getValue(nodeActor, "abilities.constitution.score", 0);
end
-- calculations
hpHealed = 5 + pCon;
hpDelta = ttlHp - currHp;
-- if a neg or zero make 1
if hpHealed <= 0 then
hpHealed = 1;
end
-- Make sure we have something to heal
if hpDelta > 0 then
-- subdual damage should heal first
if sbdl > 0 then
if sbdl <= hpHealed then
--[[ If subdual damage is less than the hpHealed, subtract subdual from Hp Healed, set db value for
subdual to 0 which should trigger updateCurrentHitpoints(rActor) I think* ]]--
hpHealed = hpHealed - sbdl;
sbdl = 0;
else
--[[ other wise same thing excapt we still have damage to heal after this set ]]--
sbdl = sbdl - hpHealed;
end
--DB.setValue(nodeChar, "health.subdual.score", "number", tonumber(sbdl));
charsheet_main.hpsubdual.setValue(tonumber(sbdl));
end
--[[ Subdual damage was 0 or subdual was less than hp Healed and we still have hp to heal ]]--
if sbdl == 0 and lthl > 0 then
if lthl <= hpHealed then
--[[ If LETHAL damage is less than the hpHealed, subtract LETHAL from Hp Healed, set db value for
lthl to 0 which should trigger updateCurrentHitpoints(rActor) I think* ]]--
hpHealed = hpHealed - lthl;
lthl = 0;
else
--[[ other wise same thing excapt we still have damage to heal after this set ]]--
lthl = lthl - hpHealed;
end
--DB.setValue(nodeChar, "health.lethal.score", "number", tonumber(lthl));
window.hplethal.setValue(tonumber(lthl));
end
end
end
I did try updating the underlying db with a DB.setValue() but the only thing I accomplished was corrupting the character record and it did not trigger any onValueChanged() event.
Any advice would be welcome.
Regards,
-d0gb0y