Now that the test server has been running for some days I wanted to get battling implemented so that players have more to do other than using SBOL as a chat room. The option to battle other players wasn’t appearing. So began reversing the function that displays the opponents handle above the car. As “Battle” should appear above the players handle when within range. I found a flag which is used to check for whether or not “battle” should appear. Manually editing this flag briefly displayed “battle” but it disappeared and the flag reverted. So looking into what sets this flag it turns out that if the GM flag is set battle isn’t possible. In addition to that collisions also aren’t possible, when the GM flag isn’t set cars can now collide with one another.
While testing I made all users GM’s. As GM’s have an instant 399km/h feature having players GM’s while battling anyway isn’t ideal. So I’ve now made all users standard users.
Now that battling is possible I made a start on the packets. Battle packets are of the 0x500 type. Packets 0x1300 are also related but I suspect these are for survival mode. There are around 8 packets used in battle. Some are for Survival, and NPC battles and around 5 are used in PvP battles. These packets are for Battle Get ready, Battle Abort, Battle Start, Battle Finish and Battle SP.
The Get Ready packet 0x580 is sent in response to 0x500 to the initiator and the opponent which needs to contain the player ID and their positions (which I keep track of). If battle isn’t possible a battle abort is sent 0x501 by the client and responded with 0x581 which should be also sent to the other player in the battle. When a player is ready to start a battle start 0x502 packet is sent from each player which I wait for both players to send before sending the response of 0x582 to both to start the battle. During the battle the players send their SP value with the battle SP packet 0x503. Now the response to this you would have thought is 0x583 but 0x583 is actually Battle finish. We don’t actually respond to 0x503 packets until are happy the battle has ended.
The battle finish packet contains less information than the battle finish packet for NPC battles. The PvP battle finish packet contain 2 tables one for each players the table contains the player ID, EXP Earned, Player Level, Level Percentage and ranking. There is no data for CP or Item. So it would seem that winning CP or items when PvP isn’t intended.
If a player quits mid battle and the usual client leave course packet is sent to the other players in the course. But if that player is in the battle with the leaving player it will crash their game client. So we need to check for if a client is in battle and if so who with and notify them that the battle is over. We can then safely send the client leave course packet.
The game contains no infomation about EXP tables. So I have no idea how much EXP to award or how much of a grand the game was. So for the moment I’ve created a quick EXP level table and set the level cap to 50.
I’ve implemented the EXP reward as follows:
Lose: Battle distance / 1000. So essentially 1 EXP per KM
Win: (Battle disance / 1000) + (Opponent Level * 10) + ((Opponent Wins – Opponent Losses) * 3)
This will need to be adjusted as I go.