Page 1 of 1

Battle Formula

Posted: Sat Mar 19, 2005 4:48 pm
by cbrian
I'm working on a PHP text-based game, and I'm working on the battle formula. It will be something like

x = player agility/opponent agility

If x = 1.65, then Player would attack 1.65 times for every time the opponent attacks.

How could I put this into PHP?

Posted: Sat Mar 19, 2005 4:56 pm
by John Cartwright

Code: Select all

$your_attack = $your_agility / $opponent_agility;
Am i missing something??

Posted: Sat Mar 19, 2005 4:57 pm
by cbrian
What I mean is how would I put it into PHP that for every 1 attack the opponent gets, the player would get 1.65(or whatever)?

But it would be a little random, too.

Posted: Sat Mar 19, 2005 5:03 pm
by John Cartwright
Your going to have to give us more information.

Specifically what is random?
Where is their agility coming from?
etc.

Posted: Sat Mar 19, 2005 5:06 pm
by Chris Corbyn
I don't really know what you want but how about.

Code: Select all

$player1_attacks = $player1_agility / $player2_agility;
$player2_attacks = $player2_agility / $player1_agility;

$possible_offset = 0.1; //10%

$player1_offset = $possible_offset * $player1_attacks;

$plus_min_array = array(1, -1);
shuffle ($plus_min_array);

$player1_this_move = ($player1_attacks + ($player1_offset * $plus_min_array[0]));

Posted: Sat Mar 19, 2005 5:12 pm
by cbrian
Something like that, and it would keep going.

Posted: Sat Mar 19, 2005 5:15 pm
by Chris Corbyn
Well if we knew what the player agility was based upon it may help :lol:

Posted: Sat Mar 19, 2005 5:17 pm
by cbrian
I get it from a database.

Posted: Sat Mar 19, 2005 5:24 pm
by Chris Corbyn
cbrian wrote:I get it from a database.
So it never changes?

How much have this game have you written so far? It seems that we have answered your question but you need some more help?

I'm guessing that when a player makes an attack there is some sort of calculation to deduct points from the opponent depending upon what the attack was and various other factors?? What exactly do you need help with :?:

Posted: Sat Mar 19, 2005 5:27 pm
by cbrian
I have written a lot of the game so far. It does change, by going to a Training Field and training your stats.

I have only just started on the battle engine, and I just need help on how to calculate who attacks when, and how many HP has been deducted, and that stuff.

Posted: Sat Mar 19, 2005 5:52 pm
by Cronikeys
Are the attacks whole numbers? if so then you can do it like this (change it to php yourself ;) ):


badguy attack
badguy attack + (random integer from -5 through 5 ) = meh
player hp - meh = new player hp

you attack
your attack power / enemy defense = moh
enemy hp - moh = new enemy hp

---
also, is it me or should this be in "PHP - Theory and Design" forum?

Posted: Sat Mar 19, 2005 6:20 pm
by Archy
I would use a while statement, and keep looping it until one of the players dies.

To see whos player's turn it is, I would look at the current battle turn, and use a formula to see whos go it should be, and then let that person have his go. Once (s)he has had his/her go, the loop continues.

Too late, and tired to provide you with any sample code.

Posted: Sat Mar 19, 2005 6:23 pm
by John Cartwright
Archy wrote:I would use a while statement, and keep looping it until one of the players dies.

To see whos player's turn it is, I would look at the current battle turn, and use a formula to see whos go it should be, and then let that person have his go. Once (s)he has had his/her go, the loop continues.

Too late, and tired to provide you with any sample code.
I believe it is a turned based game...
and perhaps different attacks can be applied during the battle itself and whatnot..

so I don't think the whole fight should be automated.