bcressey wrote:
This is complete overkill if all you want is a list of monster objects, but comes in handy if you also need lists of armor, weapons, rooms, and so forth.
Yes, I can already see how that’ll come in handy. Thank you very much.
bcressey wrote:
To generalize this a little more, you could have a RandomMonster subclass of Monster and make your random encounters descend from that class. Then instead of rolling 100 and breaking down the choice by hand, you could roll for the length of the allRandomMonsters list, and summon the monster corresponding to the index of the rolled value in the list.
I did that but with a Room class. That way I can easily designate whole areas to have the exact same monster encounters:
Finally, I really wanted to say that “This will last me for a while”; but I ran into another weird problem right away:
This time, it was implementing a system for accuracy and dodging attacks. Its rather simple, I just gave the player character a numerical property to designate his accuracy:
Code:
+myACC: Component 'my accuracy'
desc = "ACC: <<CurrentACC>> "
CurrentACC = 100
;
I gave the monster another to designate its speed:
Code:
slime: Monster 'blue slime monster' 'Slime' @activeBattleRoom
"It looks like a small gelatinous puddle of blue sludge with eyes. "
HP = 1000
MaxHP = 1000
ATK = 100
SPD = 10 //Here
;
And then added the following check to the dobjFor(Attack) method in the Monster class definition:
Code:
local roll = rand(100);
local hitChance = (myACC.CurrentACC -= SPD);
if (hitChance >= roll)
So it looks like this:
Code:
dobjFor(Attack)
{
action()
{
local roll = rand(100);
local hitChance = (myACC.CurrentACC -= SPD);
if (hitChance >= roll)
{
LoseHP(myATK.CurrentATK);
"You strike the <<theName>>. ";
if (HP <= 0)
{
moveInto(nil);
"You defeated the <<theName>>. ";
HP = MaxHP;
}
else
"\^<<theName>> has <<HP>> HP left. ";
}
else
"\^<<theName>> dodged your attack! ";
}
}
The formula should be rather simple: Get a random roll between 0 and 99, then subtract the target monster’s speed (10) from the player’s accuracy (100) to get the hit chance value. If the hit chance value is lower than the roll, the attack misses. Otherwise, it hits and the attack method triggers as before. With these values, any roll between 0 and 90 will ensure a hit, whereas anything between 91 and 99 will be a miss.
Also, I did call the randomize() function on game startup:
Code:
gameMain: GameMainDef
showIntro()
{
"Welcome to the testing arena for a theoretical combat system. Soon to be Spaghetti Code Clusterfuck. ";
randomize();
}
initialPlayerChar = me
;
It works… at first. I hit most of the time and miss others, but eventually I miss and I just keep missing forever in statistically impossible ways. Somehow, the roll result gets jammed at >90 at some point. No matter what, I never hit after the 9th attack.
So I’m drawing a blank on what-
NEVERMIND, I'M A MORON, I GOT THE PROBLEM, I just don't know how to solve it even though it's probably really simple. Obviously, each time I call
Code:
local hitChance = (myACC.CurrentACC -= SPD);
the game actually sustracts SPD from myACC.CurrentACC instead of using them as stable values, so obviously I can't hit past the ninth because by then myACC.CurrentACC = 10 and so myACC.CurrentACC -= SPD is always 10 -= 10, which is obviously going to be lower than the roll... problem is, I don't recall how to tell the game to just use those values to get a number instead of changing them.