Healing System Basic How-To

Post Reply
Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Healing System Basic How-To

Post by Delrayne »

Credit for this method goes to Nick Gammon

The first thing we need is a table of what we are currently afflicted by, and a flag to show if we are currently eating a cure.
Code: [show] | [select all] lua
afflicted_by = {}  -- table of current afflictions
eating = false  -- are we currently eating a cure?
Next, we want a table of the various afflictions and their cures. We'll use a numerically indexed table to make prioritising afflictions easier.
Code: [show] | [select all] lua
cures = {
    { name =  "stupidity"       , cure =  "goldenseal" },
    { name =  "slickness"       , cure =  "bloodroot" },
    { name =  "paralysis"       , cure =  "bloodroot" },
    { name =  "confusion"       , cure =  "ash" },
    { name =  "scytherus"       , cure =  "ginseng" },
    { name =  "epilepsy"        , cure =  "goldenseal" },
    { name =  "masochism"       , cure =  "lobelia" },
    { name =  "dizziness"       , cure =  "goldenseal" },
    { name =  "recklessness"    , cure =  "lobelia" },
    { name =  "heroism"         , cure =  "lobelia" },
    { name =  "justice"         , cure =  "bellwort" },
    { name =  "paranoia"        , cure =  "ash" },
    { name =  "shyness"         , cure =  "lobelia" },
    { name =  "hallucinations"  , cure =  "ash" },
    { name =  "generosity"      , cure =  "bellwort" },
    { name =  "loneliness"      , cure =  "lobelia" },
    { name =  "impatience"      , cure =  "goldenseal" },
-- and so on --
  } -- end of cures
Now we want a "cure me" function, that can be called on the prompt. I prefer to cure off the prompt, rather than on the affliction/eat/balance lines, so that you can have as much information as possible for your function to choose the best course of action.
Code: [show] | [select all] lua
-- find an affliction we have, and try to cure it
function do_cure ()
  -- can't eat more if just ate, or can't eat food
  if eating or 
    afflicted_by.food or 
    afflicted_by.anorexia then
    return
  end -- if can't do it yet

  -- find most urgent one to cure  

  for _, v in ipairs (cures) do
    if afflicted_by [v.name] then
      if v.cure ~= "" then  -- some afflictions might not have cures
        Send ("outb " .. v.cure)  -- get out of bag
        Send ("eat " .. v.cure)   -- eat it
        cecho("<yellow>[Curing " .. v.name .. " with " .. v.cure .. "]")
        eating = true
        return  -- done 
      end -- of having a cure for it
    end -- found one
  end -- for

end -- function do_cure
What this does is first test for whether we can cure anything right now (eg. if we have just eaten we can't).

Then it goes through the cures table in sequence, and for each one, checks to see if we are afflicted by that thing. That way the most important things get cured first.

When it finds one, it pulls the herb out of the bag and eats it, and echo's what we are currently eating.
----------------------------------------------------------------------------------------------------------------------------------------

Next we need to gather the healing balance triggers. Examples, "You may eat another herb." or "You may apply another salve." etc... and set eating to false so that when we regain herb balance the function do_cure() will attempt to cure another herb affliction.
Code: [show] | [select all] lua
eating = false
Next we gather affliction and cure triggers, to use these functions in.
Code: [show] | [select all] lua
-- call this from a trigger to show we are afflicted by something

function afflicted (what)
  if afflicted_by[what] then
    return
  else
    afflicted_by[what] = true  -- add the affliction to the afflicted_by table
    cecho("<red>Now afflicted by " .. what)
  end -- if
end -- function afflicted 


-- call this from a trigger to show we are cured

function cured (what)
  afflicted_by[what] = nil  -- remove the affliction from the afflicted_by table
  cecho("<green>Now cured of " .. what)
end -- function cured 
The above techniques won't be perfect, for one thing it doesn't check if you actually have the herb in your inventory. You might maintain another table of the herbs you are carrying, which could be updated when you buy them, and when you use them. However it should be enough to give you some ideas.

Again this is just a rough basic outline of how you could do this. It isn't intended to be a complete system build. Its intended purpose is to open you up to a method of doing things. To give you an idea of where to start and how to get there. I hope and encourage others to post similar methods, assuming they don't have a monetary investment in them, like Vadi.

Post Reply