My questions are rather to the point, but I guess I’d better explain where I’m going with all this:
The ultimate goal here is to create a system of random encounters similar to a basic RPG video game. That is, when wandering into a certain area, there should be a random chance of certain monsters being moved into the area and attacking the player until they are killed. I have… quite a load of stuff to figure out before I can get all the mechanics down and this is mostly proof of concept just to see If I can do it, but for the moment I at least succeeded in creating a killable monster to attack my character. This is the map and player character:
[rant][code]startRoom: Room ‘Starting Room’
"This is the start room. "
west = activeBattleRoom
east = randomEncounterRoom
;
activeBattleRoom: Room ‘Active Battle Room’
"This is the active battle room. "
east = startRoom
;
randomEncounterRoom: Room ‘Random Encounter Room’
"This is the testing area for random encounters. "
west = startRoom
;
me: Actor
location = startRoom
;
+myHP: Component ‘my hp/health/life/pointpoints’ ‘your HP’
desc = “Current Health: <>”
CurrentHP = 2000
LoseHP(Damage)
{
CurrentHP -= Damage;
if (CurrentHP <= 0)
finishGameMsg(‘You lose!’, [finishOptionUndo]);
}
;
+myATK: Component 'my attack/pointpoints’
desc = “ATK: <>”
CurrentATK = 100
;[/code][/rant]
Slime here :[rant][code]slime: UntakeableActor ‘blue slime’ ‘Slime’ @activeBattleRoom
"It looks like a small gelatinous puddle of blue sludge with eyes. "
HP = 1000
MaxHP = 1000
ATK = 100
LoseHP(Damage)
{
HP -= Damage;
}
HealHP(Amount)
{
HP += Amount;
HP = min(HP, MaxHP);
}
dobjFor(Attack)
{
action()
{
LoseHP(myATK.CurrentATK);
"You strike the Slime. ";
if (HP <= 0)
{
moveInto(nil);
"You defeated the Slime. ";
HP = MaxHP;
}
else
"The Slime has <> HP left. ";
}
}
;
+slimeAttackAgenda: AgendaItem
isReady = (inherited() && me.location == slime.location)
initiallyActive = true
invokeItem()
{
"The Slime charges at you! ";
myHP.LoseHP(slime.ATK);
}
;[/code][/rant]
just sits on its ass until I walk into its room and it attacks me. If it wins, I lose, if I win, Slime is moved to nil and its HP is returned to full (1000). The idea is to, coding-wise, only have a single of each monster that will be moved to nil upon defeat, healed completely and randomly have a chance of being moved back into a certain area whenever I step into it.
This approach… may very likely not be optimal, and I need to work out a way to prevent the player from leaving an area before killing the monster (stop him from fleeing, basically), but there are other issues to work out before then so I’ll ignore that and a slew of other problems I’m thinking of for now.
Right now, my first order of business is to figure out how to trigger a method when I step the into randomEcnounterRoom area (some form of EventList perhaps?). I created a clone of Slime for this:
[code]redSlime: UntakeableActor ‘red slime’ ‘Red Slime’ @nil
"It looks like a small gelatinous puddle of red sludge with eyes. "
HP = 1000
MaxHP = 1000
ATK = 100
LoseHP(Damage)
{
HP -= Damage;
}
HealHP(Amount)
{
HP += Amount;
HP = min(HP, MaxHP);
}
dobjFor(Attack)
{
action()
{
LoseHP(myATK.CurrentATK);
"You strike the Red Slime. ";
if (HP <= 0)
{
moveInto(nil);
"You defeated the Red Slime. ";
HP = MaxHP;
}
else
"The Red Slime has <> HP left. ";
}
}
;
+redSlimeAttackAgenda: AgendaItem
isReady = (inherited() && me.location == redSlime.location)
initiallyActive = true
invokeItem()
{
"The Red Slime charges at you! ";
myHP.LoseHP(redSlime.ATK);
}
;[/code]
So I need to find a way to call redSlime.moveInto(randomEncounterRoom) when I step into the room.
With that done, I’d need to figure out how to make it so that this method is called sometimes and not others, thus making Red Slime’s appearance a random occurrence. And I’d need to add a check to make sure that the method isn’t called if (me.location == redSlime.location) return true, so that the game doesn’t keep trying to summon Red Slime when it’s already fighting me.