Hi, i am in the making of a pokemon like browser based game. I almost got everything set up but i still can get the battle system to work properly, which should cover both PvP and PvM.
So what i did was check if a player click an action button (chose an attack, an item or another pokemon), send it to the server with ajax and then insert the choosen action in a mysql table. So then i did an timer and make an ajax call to the server and check if both players made an action. If they did, then battle_engine.php is called, and by reading the actions they choose and their stats it makes all the fighting and then it outputs the result, how much damage player1 did to player2 and viceversa. Then with that data i use jquery to make the attack animations, hp bar drops and stuff.
I'll like to know what do you think about this way and please tell me if you know about a better one. The mayor problem is i have to constantly make ajax's calls to ask which attack move was used to determine what animation make, check for buffs and to animate again and goes on.
Pokemon style battle system
Re: Pokemon style battle system
Hello,
Interesting subject!
What my first thoughts go directly to the part where the battle_engine.php is initiated, would this be server-side initiation?
I'm just saying that, I would do the battle calcs out of player browser.
00:00 :: Start battle
00:03 :: Player1 >> Do an action >> AJAX update MySQL >> Give player information that 'Waiting for Player 2" or something.
00:05 :: Battle_engine.php initiated by server, checking through MySQL for battles which have both player actions ready >> Non found >> exiting.
00:10 :: Battle_engine.php initiated by server, checking through MySQL for battles which have both player actions ready >> Non found >> exiting.
00:12 :: Player2 >> Do an action >> AJAX update MySQL >> Give player information that Waiting for Player 1" or something.
00:15 :: Battle_engine.php initiated by server, checking through MySQL for battles which have both player actions ready >> Found battle, calculating result >> exiting.
00:30 :: AJAX refreshes results for both players, or browser refresh would also give results for both players.
Now that's like in 30 seconds, but just an example.
This would make the players more of client users and the server to act on itself when it has something to do.
And the battle_engine.php would be scheduled to execute every 5 seconds or more if it's not already running.
Just an idea, and a note, I have never done any PHP battle system so my idea might be full of holes
Interesting subject!
What my first thoughts go directly to the part where the battle_engine.php is initiated, would this be server-side initiation?
I'm just saying that, I would do the battle calcs out of player browser.
00:00 :: Start battle
00:03 :: Player1 >> Do an action >> AJAX update MySQL >> Give player information that 'Waiting for Player 2" or something.
00:05 :: Battle_engine.php initiated by server, checking through MySQL for battles which have both player actions ready >> Non found >> exiting.
00:10 :: Battle_engine.php initiated by server, checking through MySQL for battles which have both player actions ready >> Non found >> exiting.
00:12 :: Player2 >> Do an action >> AJAX update MySQL >> Give player information that Waiting for Player 1" or something.
00:15 :: Battle_engine.php initiated by server, checking through MySQL for battles which have both player actions ready >> Found battle, calculating result >> exiting.
00:30 :: AJAX refreshes results for both players, or browser refresh would also give results for both players.
Now that's like in 30 seconds, but just an example.
This would make the players more of client users and the server to act on itself when it has something to do.
And the battle_engine.php would be scheduled to execute every 5 seconds or more if it's not already running.
Just an idea, and a note, I have never done any PHP battle system so my idea might be full of holes

Why so serious?
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Re: Pokemon style battle system
Yep, thats actually what i think is the best. Do all the battle server-side and then show(animate the attacks, get hit and be wounded) the results client-side.
What might be a problem is deciding who goes first, i guess that would be calculated in battle_engine.php and then just return to the client to make the right player attack first.
What might be a problem is deciding who goes first, i guess that would be calculated in battle_engine.php and then just return to the client to make the right player attack first.
Re: Pokemon style battle system
You could do like a skill or initiation based 'who goes first' logic.
Or simple as challenger goes first, goes well in PvM also.
With skills you could play around having a dexterity or some kind of perk on 'quick attack' in order to get the first blow in.
Or simple as challenger goes first, goes well in PvM also.
With skills you could play around having a dexterity or some kind of perk on 'quick attack' in order to get the first blow in.
Why so serious?
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Re: Pokemon style battle system
Currently it first checks the actions so if both players choose to attack then the faster(highest speed stat) pokemon goes first and when if one choose to change the pokemon or used an item it'll always goes first despite the speed.
Thank you very much for answering, here is another question for you, how would you check when one monster dies and the other player wins?
Thank you very much for answering, here is another question for you, how would you check when one monster dies and the other player wins?
Re: Pokemon style battle system
After each attack/before each attack (whichever wording you prefer), check if either of the pokemon's healths are 0 or below.Sendoh wrote:Currently it first checks the actions so if both players choose to attack then the faster(highest speed stat) pokemon goes first and when if one choose to change the pokemon or used an item it'll always goes first despite the speed.
Thank you very much for answering, here is another question for you, how would you check when one monster dies and the other player wins?
if(p1health <= 0){
p2wins
}
Re: Pokemon style battle system
But what if the player accidentally closes the window? He wont see the animation attack so the ajax call made by the attack function wont happen.Xaos wrote:After each attack/before each attack (whichever wording you prefer), check if either of the pokemon's healths are 0 or below.Sendoh wrote:Currently it first checks the actions so if both players choose to attack then the faster(highest speed stat) pokemon goes first and when if one choose to change the pokemon or used an item it'll always goes first despite the speed.
Thank you very much for answering, here is another question for you, how would you check when one monster dies and the other player wins?
if(p1health <= 0){
p2wins
}
Re: Pokemon style battle system
Sendoh wrote:But what if the player accidentally closes the window? He wont see the animation attack so the ajax call made by the attack function wont happen.Xaos wrote:After each attack/before each attack (whichever wording you prefer), check if either of the pokemon's healths are 0 or below.Sendoh wrote:Currently it first checks the actions so if both players choose to attack then the faster(highest speed stat) pokemon goes first and when if one choose to change the pokemon or used an item it'll always goes first despite the speed.
Thank you very much for answering, here is another question for you, how would you check when one monster dies and the other player wins?
if(p1health <= 0){
p2wins
}
You're already running the battle, then showing the battle right? Then it won't matter, because the battle will already be run. The player is just SOL for closing the window.
*I know nothing about Ajax specifically
Re: Pokemon style battle system
If you have the battle-engine running as serverside, the result is calculated even if both of the players computers explode drasticly after they have confirmed their next move.
When making a battle system, Player commands might have several minutes in delay.
So imagine this functionality,
Battle starts:
Battle entry marking current status to database. Linking the battle to another table the pets/pokemons attending of the players.
Player 1 is given the option of action.
Player 2 is given the option of action.
the battle-engine.php waits for Player 1 and Player 2 to commit their action. (or the engine does nothing until both players have given their orders).
Player 1 gives action.
Player 2 gives action.
the battle-engine.php calculates the outcome of the first phase of the battle.
Battle-entry is updated in database. Pets/pokemons are updated on hp/whatever in the secondary battle table.
And then back to square one.
**
The point being that the only thing that is required from the player is to initiate the action of its pokemon, after that he/she can close down browser etc.
But this allows the other player to continue.
You might also add a timeout or forfeit if, other player from the battle doesn't initiate action within 15/30 minutes.
This will also allow players to reoccupy the fights if something unrelated to the game happens, laptop battery runs out, internet blackout, bluescreen.
What do you think?
When making a battle system, Player commands might have several minutes in delay.
So imagine this functionality,
Battle starts:
Battle entry marking current status to database. Linking the battle to another table the pets/pokemons attending of the players.
Player 1 is given the option of action.
Player 2 is given the option of action.
the battle-engine.php waits for Player 1 and Player 2 to commit their action. (or the engine does nothing until both players have given their orders).
Player 1 gives action.
Player 2 gives action.
the battle-engine.php calculates the outcome of the first phase of the battle.
Battle-entry is updated in database. Pets/pokemons are updated on hp/whatever in the secondary battle table.
And then back to square one.
**
The point being that the only thing that is required from the player is to initiate the action of its pokemon, after that he/she can close down browser etc.
But this allows the other player to continue.
You might also add a timeout or forfeit if, other player from the battle doesn't initiate action within 15/30 minutes.
This will also allow players to reoccupy the fights if something unrelated to the game happens, laptop battery runs out, internet blackout, bluescreen.
What do you think?
Why so serious?
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Re: Pokemon style battle system
Nice approach, and it could be exactly the same engine for PvM except the opponent action would be random and uploaded when.. the player gives action?