Author Topic: Monsters in exploration area  (Read 1391 times)

Offline Sunchaser

  • Game Owner
  • Level 23
  • *
  • Posts: 296
  • Reputation: +3/-0
  • Game Owner
    • View Profile
    • Medieval Europe
Monsters in exploration area
« on: December 17, 2008, 11:25:55 AM »
How will you handle monster distribution in a exploration area?

I came up with two possible ideas:

Configure a fixed number of npc for an area and distribute them randomly in the area rooms
For example, I decide that in the Light Forest Area there will be:

- 10 dogs
- 14 deers
- one orc

etc, and i configure the database linking monsters to rooms. The area will have always the same quantity of monsters but they will be moved in different rooms of the same area when they will revive.

- All players see the same npcs in the same rooms
- If a player is engaged in a combat with a npc, that npc is not attackable by other players
- If a npc is dead, it will not be visible in that room, until the respawn time is finished
- When it revives it can be linked to another room randomly (it it's not a quest npc)
- It is possible that a players wipes npcs from an area, thus other players can't get experience

Once a player enters a room, npcs are randomly created at run-time
- Every players see different npcs distribution respect to other players
- Quest npcs are not created at run-time, they are static
- There are no problems about npc wipeout

I prefer the 1st option (also because i have to do it for quest npcs),
anyone has some thoughts on these solutions?

THX

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Monsters in exploration area
« Reply #1 on: December 17, 2008, 02:12:06 PM »
Solution #1 is probably better. Also, why disallow other players from attacking the monster? Perhaps do something like World of Warcraft does. The first person to damage a monster 'flags' it as 'their' kill. Only them (or members of their party) will receive experience and loot from the kill.

Solution #2 will, basically, prohibit you from allowing player parties if that ever should become an option in the future.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Sunchaser

  • Game Owner
  • Level 23
  • *
  • Posts: 296
  • Reputation: +3/-0
  • Game Owner
    • View Profile
    • Medieval Europe
Re: Monsters in exploration area
« Reply #2 on: December 17, 2008, 02:31:13 PM »
Solution #1 is probably better. Also, why disallow other players from attacking the monster? Perhaps do something like World of Warcraft does. The first person to damage a monster 'flags' it as 'their' kill. Only them (or members of their party) will receive experience and loot from the kill.

Yes, I too prefer the 1st solution.
Flagging the monster is nice, thanks... but i would like to try to make a turn based combat system (every turn the player can choose to attack, flee, heal, change equipment... so i don't know how to handle two interactive fight at one time (well maybe i can do it provided that i use transactions to keep the npc HP values consistent)

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Monsters in exploration area
« Reply #3 on: December 17, 2008, 06:13:41 PM »
And, yes, a transactional database is the answer to your combat scenario :)
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Monsters in exploration area
« Reply #4 on: December 28, 2008, 08:43:16 AM »
Solution #1 is probably better. Also, why disallow other players from attacking the monster? Perhaps do something like World of Warcraft does. The first person to damage a monster 'flags' it as 'their' kill. Only them (or members of their party) will receive experience and loot from the kill.

Yes, I too prefer the 1st solution.
Flagging the monster is nice, thanks... but i would like to try to make a turn based combat system (every turn the player can choose to attack, flee, heal, change equipment... so i don't know how to handle two interactive fight at one time (well maybe i can do it provided that i use transactions to keep the npc HP values consistent)

I am very interested in this... :P
How do you use transactions in your script to handle this situation?

What's your database structure like, if you don't mind sharing? :)
What happens if two players click the 'attack' button at the same time when the npc has 1 life left (if it's possible)? Does one player get a 'you killed it' message while the other gets a 'it is already dead!' message? Or is there an error?

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Monsters in exploration area
« Reply #5 on: December 28, 2008, 11:13:46 AM »
What I'm doing in one of my games is when a player hits an area where there is a NPC they must battle that NPC is moved out of the map and placed into the player's combat table. If another player were to go onto that same tile while the combat was in play they would not see the NPC.

I chose this method because none of the NPC's are powerful enough to need two or more players to kill it. Allowing players to gang up on an NPC would make the game far to easy. Plus I want my players to be able to play by themselves and not be forced into a group to compete in the game. Players can though go into an area and fight NPC's within that area and then collect / divy up the loot that area has to offer.

I do not give the players the ability to run from a fight, you stand there and battle till the battle has ended. The player class looks to see if the player has an entry in the battle table and if so it forces them back to the battle page, thus a player can't jump out of the fight by clicking a menu item or entering a URL in the browser to another "safe" area in the game.
Creating online addictions, one game at a time:

Offline Sunchaser

  • Game Owner
  • Level 23
  • *
  • Posts: 296
  • Reputation: +3/-0
  • Game Owner
    • View Profile
    • Medieval Europe
Re: Monsters in exploration area
« Reply #6 on: December 28, 2008, 11:18:49 AM »
Disclaimer: I used to work with Oracle, I never used transactions with Mysql in a high-concurrent system, so i have still to see if it works :)

Quote
I am very interested in this... Tongue
How do you use transactions in your script to handle this situation?

Probably i will use the solution (let's name it A) that if a player engages a turn-based fight with a monster, no other players will see the monster. I don't want to engage myself in complicated solutions for now. Anyway i think it's possible with mysql/INNODB transactions, even if a bit more complex.

Even in the (A) solution, the first player that attacks the monsters will have to reserve the monster in an exclusive way. I would:

  • declare the table as INNODB (in Mysql). The table should contain a locked_by and locked_timestamp
    fields and the other necessary ones.
  • when a player attack a monster, update the fields locked_by and locked_timestamp

To a player entering the room i will show only the monsters that are not locked, and
free the lock on monsters that are locked by a certain time (timeout)

Quote
What's your database structure like, if you don't mind sharing? Smiley

ATM I am working on my game when i have spare time, and now i am doing phase 2 Churches for BSRPG.
Currently the combat engine is not turn-based because i would like, first of all, to have a proof-of-concept minigame where you can explore, fight, sell objects etc. (When it will be ready i will show it to the forum). After this minigame, I will make the turn-based combat engine. No problem then to share solution and db structure.

Quote
What happens if two players click the 'attack' button at the same time when the npc has 1 life left (if it's possible)? Does one player get a 'you killed it' message while the other gets a 'it is already dead!' message? Or is there an error?

If i implement this solution, there will not be any combat lock on the monster and any player will be able to see it. But, i will have to open a transaction before updating monster's hps and close it when the hp points are updated. The first player that kills the monsters will get the xp, and the other player will, at the next round get a message like 'The monster has been killed by <playername> in the meantime.
If players click attack at the same time, the db engine will decide what transaction serve first.
« Last Edit: December 28, 2008, 11:21:06 AM by Sunchaser »

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Monsters in exploration area
« Reply #7 on: December 28, 2008, 01:08:38 PM »
Ah, okay. I am using something very similar to what you described (turn based battles, npcs can be seen/attacked by any player).

I just want to make sure I get this right... :P This is for a situation when two (or more) players are attacking a monster, and it happens to die when two players click at the exact same time.

I'd have to use SELECT...FOR UPDATE, or serializable transactions, right? Or would there not be a problem with regular transactions?


So... instead of this happening:

thread1 > select `hp` from `battles` where...   --> returns 1
thread2 > select `hp` from `battles` where...   --> returns 1
thread1 > update `battles` set `hp`=hp-1 where...    --> hp=0
thread2 > update `battles` set `hp`=hp-1 where...    --> hp = -1 - ERROR

This is what I want to happen:
thread1 > select `hp` from `battles` where...   --> returns 1
thread2 > select `hp` from `battles` where...   --> WAIT....
thread1 > update `battles` set `hp`=hp-1 where...    --> hp=0
thread2 > returns hp=0
« Last Edit: December 28, 2008, 01:11:56 PM by Zeggy »

Offline Sunchaser

  • Game Owner
  • Level 23
  • *
  • Posts: 296
  • Reputation: +3/-0
  • Game Owner
    • View Profile
    • Medieval Europe
Re: Monsters in exploration area
« Reply #8 on: December 28, 2008, 02:10:47 PM »
I would use select for update. I am not sure if using regular transactions would be enough.

We have a kind of arena in BSRPG that when there are a lot of players something like you described
can happen because we don't use transactions.

In the next months i will fix that situation, I will let you know how/if i fixed it.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal