Advice, please.

Starzie
29 Jul 2005, 15:55
Okay, so I've worked out a simple skeleton of a battle system I'd like to use in my game. It all starts when the player enters the attack command:


command <attack #@enemy#> {
if type <#enemy#; enemy> then {
flag off <battleOver>
do <battle>
}
if type <#enemy#; ally> then msg <Attacking is not one of your brighter ideas.>
}


That starts off the procedure...


define procedure <battle>
repeat while not flag <battleOver> for each object in <#quest.currentroom#> {
if flag <playerGone> and flag <monsterGone> then {
flag off <playerGone>
flag off <monsterGone>
}
if type <#enemy#; enemy> and ( #player:spd# < #enemy:spd# ) or flag <playerGone> then {
do <monsterAttack>
wait <Press any key to continue...>
flag on <monsterGone>
}
else {
do <playerAttack>
wait <Press any key to continue...>
flag on <playerGone>
}
}

end define


Now, it works like dream... against one enemy at a time. I want to be able to have the player be able to battle up to five different enemies at once, and have the option of choosing which enemy to attack. How the heck would I go about adapting my current code to handle that?

Here are the playerAttack and monsterAttack procedures if you want to see them for whatever reason.


define procedure <monsterAttack>
if ( $objectproperty(#enemy#; hp)$ <= 0 ) then {
doaction <#enemy#; die>
flag on <battleOver>
hide <#enemy#>
}
else {
set numeric <dam; $objectproperty(#enemy#; str)$ - #player:def#>
if ( %dam% < 0 ) then set numeric <dam; 1>
set numeric <newPlayerHp; #player:hp# - %dam%>
property <player; hp=%newPlayerHp%>
doaction <#enemy#; flavortext>
}
end define



define procedure <playerAttack>
set numeric <dam; #player:str# - $objectproperty(#enemy#; def)$>
if ( %dam% <= 0 ) then set numeric <dam; 1>
set numeric <newEnemyHp; $objectproperty(#enemy#; hp)$ - %dam%>
property <#enemy#; hp=%newEnemyHp%>
doaction <player; flavortext>
end define

GameBoy
29 Jul 2005, 18:40
I haven't used ASL in a long time so this could be completely wrong, but you could try using an if statement if there is more than one #@enemy# in the room. Then use a dialog box to select which enemy you want to battle against.

You will probably need to add something which counts how many attackable enemies are in the same room also.

Starzie
29 Jul 2005, 22:02
I suppose to count the enemies in the room I could use some kind of for statement. Like For every object in the room that is of type enemy (my attackables) increment a monsterCount var? Actually, doing that will allow me to get rid of my battle flags, and I can just end the combat when monsterCount hits zero. (I hate using flags because I forget them half-way through coding... :roll: )

And in my first attempt of a battle system, I used a good deal of if statements to determine order of attack between the player and the monsters based on their spd stat, but there's just so many of them and in that system I had a cap of four attackables at once. I litterally had to check player vs. monster1 vs. monster2 vs. monster3 vs. monster4 every turn. What was frustrating about that, and ultimately made me kick it and start over, was it would either always make the highest spd go continually, or, when it got to the player's turn, it let the player go continually. I just couldn't figure out how to keep track of who had gone and who hadn't.