Description of what I am trying to do
I have a situation where I have created a game in ASP.NET. Right now I am working on adding multiplayer functionality so two (or more) players can fight at the same time in "real time".
In short, I have:
- A server (ASP.NET website)
- One or several visitors which are on side A
- One or several visitors which are on side B
The main functionality: One player uses an attack on an another player, this attack has a fire time (both players can see the time before fired) and then after some seconds, the attack is fired.
Right now I handle this in every player. Every player has a list of activities. Activities could be:
- Firing an attack
- A load of an attack is 0 and the attack is fired
- Some stat modifiers: Drinking a potion, being hit, doing some magic which modifies stats
Now, the problem is I want the multiplayer functionality added, and I want this added through a database.
- Please, NO Comet suggestions -
My work so far...
I have a database with some tables:
- One for each fight started
- One with fight participants
- One with all activities added
Every 750ms-1000ms I run the two methods:
- GetNewActivities() which reads all new activities from the database (timestamped)
- FireCurrentTraces() which looks at all current traces and react upon them
But, of course, this gives problems. For instance: Player A fires an attack on player B. While this is counting down the fire timer, both people has this "attack" in their pending attacks list. When timer is down, player A or B will fire it, but in this case, both will end up firing it.
This is just one of MANY problems which will lead to HORRIBLE design.
Which leads to my final question...
What would be a doable way to solve this issue? Please, no Comet or solutions alike. I need something which has great support in ASP.NET and should be simple to work with.
I guess some global list of activities could do wonders, but how in the world would one manage that? Also, this could give some race conditions with several users?
Thanks! :-)