Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Creating storage for points in the DB#192

Merged
JackUrb merged 3 commits intomasterfrom
player-exp-db
Apr 20, 2021
Merged

Creating storage for points in the DB#192
JackUrb merged 3 commits intomasterfrom
player-exp-db

Conversation

@JackUrb
Copy link
Copy Markdown
Contributor

@JackUrb JackUrb commented Apr 16, 2021

Overview

Creates a method to store and load the xp and reward_xp fields on agents when in the main game. This is done directly through the purgatory call to fill a PlayerSoul, so after the call is made these fields should be accessible directly from the player object available in the frontend!

Sorry @JustinPinero, it seems the easiest solution here was to avoid server calls as much as possible, so no remaining python changes.

NOTES

This requires deleting the users_table inside of the LIGHTDatabase to be functional. I'll do this for our core dbs once this is merged.

Implementation

  • Moves the LIGHTDatabase to be accessible throughout all of the web controllers
  • Creates the scores_table to actually store scores. Here we have a global score per player, as well as a character score per player (though at the moment our game doesn't link up to the DB characters by ID yet, so we're only tracking the main score).
  • Creates the initialize_agent_score and store_agent_score methods, which load up the current scores from the database to attach to the current agent (wherein they can be accessed on the frontend!), and then stores them back based on the delta so that we don't run into issues in the future if people are saving from two different worlds.

Testing

Ran locally, gave myself some points, found I still had them later

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 16, 2021
Copy link
Copy Markdown
Contributor

@klshuster klshuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool stuff - most of my questions stem from possibly some lack of context

try:
with self.db as ldb:
user_id = ldb.get_user_id(user_decoded)
except Exception as e:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when does this happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens if we dump the cookies on the backend to reset auth issues. I'll put a note here to that effect.

CREATE TABLE IF NOT EXISTS user_table (
id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
username text UNIQUE NOT NULL);
extern_id text UNIQUE NOT NULL,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is extern_id?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's whatever an external provider may be identifying the user as. With login with facebook, this will be PSID

Comment on lines +3608 to +3610
target_node._base_class_experience = 0
target_node._base_experience = target_node.xp
target_node._base_reward_points = target_node.reward_xp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could be good to have safe access to these private attrs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm really not sure what to do about this. The current design isn't my favorite, but GraphNodes have a set of attributes that we know they'll have in all cases. These extra attributes (which are more game-dependent) aren't necessarily going to be present in all cases, so the _ is referring to the fact that they're not always present. I'd imagine that these attributes would belong in a mapping from the World, but they're always accessed at the level of the node. May be worth discussing this more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh i understand. if you're sure that these specific GraphNodes will always have these attrs, is it possible to define these as like XpGraphNodes? or will that end up exploding the space of types of nodes

Copy link
Copy Markdown
Contributor Author

@JackUrb JackUrb Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the difficulty is more that these attributes are only expected to exist when:

  1. We're using a World that has exp enabled in some form
  2. The given GraphAgent is a player.
    Unfortunately the GraphAgent already exists by the time we'd want to mix in these attributes, as they're NPCs until the moment a player takes over.

Even worse, we have other attributes of this sort that Souls choose to attach to agents as 'metadata' of sorts, and they're all going into this _ view.

Perhaps the right call is to extend GraphAgents with a interfaces attribute, and then we can do something like:

@dataclass
def XPInfo():
  base_experience
  base_class_experience
  base_reward_points
  xp
  reward_xp

...

  some_target_agent.interfaces['xp'] = XPInfo()

And then later places can do optional things with this.

if 'xp' in Agent.interfaces:
   # do EXP stuff
if 'partner_heuristics' in Agent.interfaces:
   # do partner heuristic stuff

How does this look?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the delayed response, yes this looks great, thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I'll be addressing this in a refactor soon!

target_node._base_experience = target_node.xp
target_node._base_reward_points = target_node.reward_xp

if db_id is not None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit confusing - how does the db_id map to a character_id?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The db_id of a GraphAgent should be the id of the character that spawned that GraphAgent.

Comment thread deploy/web/server/tornado_server.py
Comment thread deploy/web/server/tornado_server.py
Copy link
Copy Markdown
Contributor

@JustinPinero JustinPinero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, I think this will be a great way to manage exp across multiple worlds.

@JackUrb JackUrb merged commit a620377 into master Apr 20, 2021
@JackUrb JackUrb deleted the player-exp-db branch April 20, 2021 20:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants