The Scoring module (SM) centralizes users’ grading system, providing coin type management, storage for the formulas, a few helper functions to be used in formulas, and detailed history of gained coins.
The coins used in WoUSO are of two types: core and game specific.
An application (a game) define its grading formulas; the SM will register and store these formulas, making them editable by an administrator; when an action finishes, the game asks SM for a formula calculation, with given parameters, and then pushes scores for each user playing the game.
These types of coin are available globally in the game. God defines their names. Each game can modify the amount of these coins for each user.
Their id are kept simple and suggestive.
Right now, only points core type coin is defined.
Each game can define specific types of coin he offers to the user. God can override their names. Only the game defining the coin type can modify the amount for a user.
Their id is prefixed with the owner game, i.e. challenge-stamina.
Given the core coins:
Id: points
Name: Galbeni
1. Qotd registers one simple formula, giving 3 points for a correct answer:
Name: qotd-ok
Formula: points=3
After an user plays Qotd, it asks SM to calculate the points, with no parameters; then save them for the user:
# self - a Qotd game instance
# 'qotd-ok' - the formula id
core.scoring.score(user1, self, 'qotd-ok')
2. Challenge adds a coin type:
Id: challenge-stamina
Name: Fight Stamina
and registers two formulas, one for won challenge, another for lost:
Name: challenge-lost
Formula: points=-3, challenge-stamina=-100
Name: challenge-won
Formula: points=3 + ({level1} - {level2}) * 0.5, challenge-stamina=50
After playing a challenge:
core.scoring.score(user1, self, 'challenge-lost' external_id=challenge.id)
core.scoring.score(user2, self, 'challenge-won', external_id=challenge.id, level1=user1.level, level2=user2.level)
Different scoring categories.
A special coin is ‘points’ since is used for ladder and levels.
A coin is a core coin, if it doesn’t have an owner
Define the way coin amounts are given to the user, based on keyword arguments formulas.
A formula is owned by a game, or by the system (set owner to None)
Scoring history keeps track of scoring events per user, saving the details from source to amount.
Returns a dictionary of coins and amounts for a specific user.
Returns: | a list of (game, points) - distribution of points per source |
---|
Generic loose, fail-proof model with add_if_does_not_exist and get_if_it_isnt_already_an_instance methods
Calculate formula and return a dictionary of coin and amounts
Check if the module has been setup
Return all history entries for given (user, game) pair.
Give amount of coin specified by the formula to the player. The amount can be affected by percents/100.
Give amount of coin to the player.
Prepare database for Scoring
Synchronise points amounts for all players
Synchronise user points with database
Compute a timer value, or return default
Remove all history records by the external_id, formula and game given to the user
Returns a dictionary with user coins