10 Replies - 1036 Views - Last Post: 24 August 2019 - 03:54 PM Rate Topic: -----

#1 Splashsky   User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 352
  • Joined: 25-August 13

What DB for this RPG Use Case

Posted 23 August 2019 - 09:02 AM

I'm working on a text-based RPG in PHP/JS. I'm using the Laravel framework. I've come to a dilemma I wasn't quite sure how to proceed on, and that's combat. When a player finds an enemy, a database entry needs to be made so the fight is persistent across sessions. Before, I handled this via RDB and had HP/MP values for both opponents, opponent info etc. Kinda clunky but it worked. Now, I want to increase complexity with various status-inflicting skills, but this isn't something I figured could be applied in a Relational sense very easily or cleanly. That being the case, I remembered MongoDB and how it uses fluid document-based databasing.

Would it be viable to make my game a hybrid between MariaDB and MongoDB, where Maria handles user accounts, forum posts, auction listings etc and then Mongo handles dynamic content such as combat? Is this how you would handle it?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: What DB for this RPG Use Case

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,583
  • Joined: 12-June 08

Re: What DB for this RPG Use Case

Posted 23 August 2019 - 09:12 AM

I am not following why it would get clunky?
Was This Post Helpful? 0
  • +
  • -

#3 baavgai   User is online

  • Dreaming Coder
  • member icon


Reputation: 7501
  • View blog
  • Posts: 15,544
  • Joined: 16-October 07

Re: What DB for this RPG Use Case

Posted 23 August 2019 - 09:41 AM

Honestly, there's nothing that can't be be modeled in SQL tables, or json, or xml, or anything that offers some foundation structure. If you can model it in code, then you should be able to map it to a data store.

If you're having an issue getting your head around SQL, and are more comfortable with json, I'd suggest a NoSQL store, like your mentioned MongoDB. However, I would discourage a mutli store fusion approach. Pick a single datastore solution and commit.
Was This Post Helpful? 0
  • +
  • -

#4 Splashsky   User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 352
  • Joined: 25-August 13

Re: What DB for this RPG Use Case

Posted 23 August 2019 - 10:36 AM

In that case, using the SQL structure, how would you accomplish varied "status effects" in one instance of a fight?
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,583
  • Joined: 12-June 08

Re: What DB for this RPG Use Case

Posted 23 August 2019 - 10:59 AM

Elaborate on an example or two of a 'status effect'.
Was This Post Helpful? 0
  • +
  • -

#6 baavgai   User is online

  • Dreaming Coder
  • member icon


Reputation: 7501
  • View blog
  • Posts: 15,544
  • Joined: 16-October 07

Re: What DB for this RPG Use Case

Posted 23 August 2019 - 11:04 AM

Well, first, how are you representing it in a programming language?

This post has been edited by baavgai: 23 August 2019 - 11:05 AM

Was This Post Helpful? 0
  • +
  • -

#7 Splashsky   User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 352
  • Joined: 25-August 13

Re: What DB for this RPG Use Case

Posted 24 August 2019 - 07:49 AM

Well, in an attempt to answer both of your questions I was finally able to get home and find the flow chart I'm working from. For status effects, these could be 4-turn bleeds, 6-turn poisons, 2 turn stuns, etc. Programmatically, it would make sense to me that when an ability is used it created an entry in the database, including a timer sort of column that tracks the number of turns it lasts. The combat engine would recognize the status effect entry and take care of actually implementing that in the fight. However, the conclusion I wasn't able to come to was whether it was better to do the combat system in a document-based NoSQL way or if it would also be alright to do it in a relational SQL way. To me, I suppose I could create a table for status effects, have a foreign key pointing to the fight and use 1 or 2 to signify player or monster.

Anywho, here's the flow chart.
Posted Image
Was This Post Helpful? 0
  • +
  • -

#8 baavgai   User is online

  • Dreaming Coder
  • member icon


Reputation: 7501
  • View blog
  • Posts: 15,544
  • Joined: 16-October 07

Re: What DB for this RPG Use Case

Posted 24 August 2019 - 09:09 AM

Amazingly, for all your flowchartiness, you've supplied no actual data structure! It can be inferred that an entity, at the very least, has the attribute of speed. That such entities have abilities and, that an ability has a duration.

Hmm... let's assume bite is a normal attack, sword is a normal attack, and poison is a special ability. An ability lasts for a time. An attack also lasts for a time, it's just that this time is one round.

My hero attacks a snake. The data might look like:
round seq entity ability effect amount duration
1     1   hero   sword   dmg    5       1
1     2   snake  bite    dmg    3       1
1     3   snake  poison  dmg    1       3
2     1   hero   sword   dmg    0 (miss)
2     1   snake bite     dmg    0 (miss)
2     3   snake  poison  dmg    1       2
....


Was This Post Helpful? 0
  • +
  • -

#9 Splashsky   User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 352
  • Joined: 25-August 13

Re: What DB for this RPG Use Case

Posted 24 August 2019 - 09:44 AM

So I could see how this would work if I were to use a table/array programmatically but what about the scenario in which a player closes their session mid-fight then comes back and logs in, expecting to pick it up where they left off? Would I make these same rows but foreign key them to the fight itself?
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,583
  • Joined: 12-June 08

Re: What DB for this RPG Use Case

Posted 24 August 2019 - 10:31 AM

I don't see why the table of data wouldn't exist when they came back or the 'end of fight' condition happened. I presume 'status effects' are relative to the combat rounds and not actual real time.


Side note - amusing tracking the data in a db and set of collections.

Round: 1
================
~ Start of Round ~
id: 1, type: Player, health: 20, attack: 3, name: Foo PC
id: 2, type: Monster, health: 10, attack: 1, name: Monster 1

~ ClearSE ~

~ Apply Status Effects ~

~ Exchange Damage ~

~ End of Round ~
id: 1, type: Player, health: 19, attack: 3, name: Foo PC
id: 2, type: Monster, health: 7, attack: 1, name: Monster 1
-------------

~ Add Status ~    Actor: 1, Text: bleed, Damage: 1

Round: 2
================
~ Start of Round ~
id: 1, type: Player, health: 19, attack: 3, name: Foo PC
id: 2, type: Monster, health: 7, attack: 1, name: Monster 1
Status Effect: id: 1, actor_ID: 1, text: bleed, turns_left: 2, damage: 1

~ ClearSE ~

~ Apply Status Effects ~
ID: 1 Damage: 1 Actor Id: 1

~ Exchange Damage ~

~ End of Round ~
id: 1, type: Player, health: 17, attack: 3, name: Foo PC
id: 2, type: Monster, health: 4, attack: 1, name: Monster 1
Status Effect: id: 1, actor_ID: 1, text: bleed, turns_left: 1, damage: 1
-------------

Round: 3
================
~ Start of Round ~
id: 1, type: Player, health: 17, attack: 3, name: Foo PC
id: 2, type: Monster, health: 4, attack: 1, name: Monster 1
Status Effect: id: 1, actor_ID: 1, text: bleed, turns_left: 1, damage: 1

~ ClearSE ~

~ Apply Status Effects ~
ID: 1 Damage: 1 Actor Id: 1

~ Exchange Damage ~

~ End of Round ~
id: 1, type: Player, health: 15, attack: 3, name: Foo PC
id: 2, type: Monster, health: 1, attack: 1, name: Monster 1
Status Effect: id: 1, actor_ID: 1, text: bleed, turns_left: 0, damage: 1
-------------

~ Add Status ~    Actor: 2, Text: bleed, Damage: 1

Round: 4
================
~ Start of Round ~
id: 1, type: Player, health: 15, attack: 3, name: Foo PC
id: 2, type: Monster, health: 1, attack: 1, name: Monster 1
Status Effect: id: 1, actor_ID: 1, text: bleed, turns_left: 0, damage: 1
Status Effect: id: 2, actor_ID: 2, text: bleed, turns_left: 1, damage: 1

~ ClearSE ~
Removed Status Effect: 1

~ Apply Status Effects ~
ID: 2 Damage: 1 Actor Id: 2

~ Exchange Damage ~

~ End of Round ~
id: 1, type: Player, health: 14, attack: 3, name: Foo PC
id: 2, type: Monster, health: -3, attack: 1, name: Monster 1
Status Effect: id: 2, actor_ID: 2, text: bleed, turns_left: 0, damage: 1
**** **** ****
 Winner ID: 1
**** **** ****

-------------



Was This Post Helpful? 0
  • +
  • -

#11 baavgai   User is online

  • Dreaming Coder
  • member icon


Reputation: 7501
  • View blog
  • Posts: 15,544
  • Joined: 16-October 07

Re: What DB for this RPG Use Case

Posted 24 August 2019 - 03:54 PM

View PostSplashsky, on 24 August 2019 - 11:44 AM, said:

closes their session mid-fight

This is a different requirement, isn't it? You could reasonably say, you close, you loose... However, you seem to have answered your own question.

Anything related to a user would need to be attached to that user somehow, yes? You'll likely have either a session_id or a user_id associated with any data you store.

Rather than session, you might simply look at the last activity related to a user and see if they completed a current open action. Indeed, the data you store during an open session could be thought of a continuous save game function. The screen shown to a user reflects the current game state. If a user logs back in, the very next screen they should should reflect the state as it currently stands.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1