Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Message
| OK, let's take a look at doing this in Lua, whose table handling makes keeping track of this sort of stuff quite easy.
I haven't played Achaea for a while, and am not familiar with their affliction system, but I gather from the other posts about this that it goes along these lines:
- You can become afflicted by lots of things, where an affliction is indicated by one or more messages, like:
An odd sensation descends upon you.
You feel the urge to slash, cut, and bruise yourself.
With the heel of your palm, you smack *
You drive a clenched fist into your gut.
You use your * foot to stomp on your * as hard as possible.
- When you are cured of that affliction, either by time or the cure, you get another message, like:
You no longer enjoy pain.
- You can eat something to cure the affliction, eg.
eat lobelia
- Once eaten something you can't eat again until you see a message, like:
You may eat another plant.
- You can't eat while afflicted by the "food" affliction, or "anorexia", and other things.
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. I presume when you start a new game the afflictions are cleared, so the table can be a straight Lua table. If not, you could serialize the table into a variable on world disconnect, as described in other posts, and re-import it when you reconnect.
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. I would rather have a table keyed by affliction name, but I gather that you would prefer to cure afflictions in a certain order (most urgent to least urgent) so we'll just have a table keyed in numeric order:
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" routine, that can be called as soon as we become afflicted, and also when an affliction wears off, and we can eat another herb. For example, if the "food" affliction wears off, we can start curing other things.
-- 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
ColourNote ("black", "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 notes we are currently eating.
Next we need a series of triggers to indicate we have an affliction. Since multiple things may indicate the same affliction we call a function with "send to script" to indicate which affliction we now have:
<triggers>
<trigger
enabled="y"
match="You drive a clenched fist into your gut."
send_to="12"
sequence="100"
>
<send>afflicted "masochism"</send>
</trigger>
</triggers>
You would make a similar one for each affliction, where the "match" is what you see (it could be a regular expression), and the "send" text calls the "afflicted" function with the name of the affliction.
-- call this from a trigger to show we are afflicted by something
function afflicted (what)
if afflicted_by [what] then
ColourNote ("white", "red", "Already afflicted by " .. what)
else
afflicted_by [what] = true -- note the affliction
ColourNote ("white", "red", "Now afflicted by " .. what)
end -- if
do_cure () -- try a cure
end -- function afflicted
This function calls "do_cure" to try to cure something straight away, which may be this affliction, or it may not if we are currently eating a herb.
Next we need to know when the affliction is cured.
<triggers>
<trigger
enabled="y"
match="You no longer enjoy pain."
send_to="12"
sequence="100"
>
<send>cured "masochism"</send>
</trigger>
</triggers>
This is similar to the above trigger, except it calls the "cured" function instead.
-- call this from a trigger to show we are cured
function cured (what)
afflicted_by [what] = nil -- note not afflicted
ColourNote ("white", "green", "Now cured of " .. what)
do_cure () -- try a cure for the next affliction if any
end -- function cured
This also calls do_cure to try to cure something else. For example, if we are no longer afflicted by "food" we can start curing other things.
Next we need to know if we can eat another herb:
<triggers>
<trigger
enabled="y"
match="You may eat another plant."
script="can_eat"
sequence="100"
>
</trigger>
</triggers>
This calls the can_eat function:
-- call this from a trigger when we have finished eating
function can_eat ()
eating = false
do_cure () -- now we can cure something else
end -- function can_eat
This also calls do_cure to try to cure something else if necessary.
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.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|