Hi again.
I’m trying to stick as much repetitive code as possible into custom classes, but I hit a snag as to how to, or whether it is possible, to make small modifications to relatively long objects. I know how to use Inherited() to add something to the end of a pre-existing method, but not how to mess with chunks from the middle.
For instance, here is Slime’s behaviour, represented by the agenda item slimeAttackAgenda:
+slimeAttackAgenda: AgendaItem
isReady = (inherited() && player.location == slime.location)
initiallyActive = true
invokeItem()
{
local roll = rand(100);
if (roll >= 50)
"The Slime stares blankly and loses its turn. ";
else
{
local roll = rand(100);
local hitChance = 100 - player.SPD;
if (hitChance >= roll)
{
"The Slime charges at you! ";
player.LoseHP(slime.ATK);
}
else
"The Slime charges at you, but its attack missed! ";
}
}
;
Suppose I want a lot of this to work much the same for other monsters, more or less like this:
class MonsterAttackAgenda: AgendaItem
isReady = (inherited() && player.location == slime.location)
initiallyActive = true
invokeItem()
{
local roll = rand(100);
local hitChance = 100 - player.SPD;
if (hitChance >= roll)
{
"Monster attacks you message. ";
player.LoseHP(slime.ATK);
}
else
"Monster missed message. ";
}
;
This would be generic monster behaviour. From here, I would want to customize the two double quoted strings for each monster, as well as the “slime” in
player.LoseHP(slime.ATK);
since I would need to change that to point to each respective monster, else all of them would be using slime’s ATK property to calculate damage.
Additionally Slime has another random 50/50 chance of just staring blankly and doing nothing instead of following with all the hitChance and attack behaviour. That’s there just as a placeholder for some other customized behaviour I might want to implement.
Basically, the point of this exercise is that I want to keep a block of code in a class definition and freely mess with chunks of the content on individual instances. Is this doable?