For the last two years I worked almost only on the foundation of this project, e.g. networking, how servers communicate, database back end, different network protocols. Now that this works more or less, I started to work on the gameplay.
Party
Cooperation is a big thing in this game. You meet in outposts, form a party and enter a game instance with this party and do stuff together, e.g save the world.
Implementing this was quite tricky for several reasons:
- A lot of communication between the server and the clients is needed.
- Player and Party objects exist only on the game server.
- The clients party window is complex and needs to handle many events.
- There are many situations a party must behave differently.
Client/Server communication
First a player must invite another player. The invited player can accept or decline the invitation.
If the player accepts the invitation, it will be added to the party.
Of course, party members can leave the party, and party leaders (the first player in the window) has special rights. They can kick party members and invite new players.
Entering a game as party
As mentioned earlier, when a player enters a game, it disconnects from the game server and reconnects to it telling the server what map it wants to enter. Since party objects only exist on the game server, these are destroyed when the players disconnect. But to be able to reconstruct the party when entering the new game instance, this information must be saved. I decided to (ab)use the data server for that.
Mapping
The are two distinct map types:
- Outposts. People can meet there and make a party.
- Battle areas. People face foes there and fight them.
You can map from one outpost to another outpost. Party members can not do that anymore, except the party leader. If other members want to map to another outpost, they must leave the party first.
If there is a portal that brings players to a battle area, all members can go through it, and all members of the party will enter the same battle area instance as a party.
Once in a battle area, players can not leave the party anymore, but they can map to an outpost. This will cause that these players will leave the party in the battle area. If all players of a party in a battle area type /resign they will be brought back to the last outpost. Also the leader can not kick members anymore.
There are probably more edge cases I'm not aware of at the moment.
Melee attacks
When players are in a battle area, they can fight foes. However, identification friend or foe does not work great yet. At the moment you can attack anyone not in your party.
The damage depends on many different things:
- The weapon that is used by the attacker
- Any effects that increase damage of the attacker
- The armor of the attacked
- Any effects of the target that reduces damage
At the moment the damage is always 5, that's because equipment is not implemented yet, so the attacker does not have any weapon (just their fists), and the target does not have an armor.
Once the target is dead, the attacker stop attacking.
Now that all foes are dead, we can resign.
Oh, by the way, I celebrated the 1000th commit some days ago! Next celebration is the 1337th commit ?. Some other stats (only code I wrote, no third party libraries, STL etc.):
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C++ 308 6804 2209 47292
C/C++ Header 395 3049 1558 18012
LESS 15 833 7 5069
Lua 74 301 329 1384
XML 12 0 1 1354
HTML 12 90 24 1032
JavaScript 1 28 24 183
DOS Batch 6 9 8 22
Markdown 3 6 0 12
CSS 1 0 7 2
-------------------------------------------------------------------------------
SUM: 827 11120 4167 74362
-------------------------------------------------------------------------------