-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement scores via events #33999
Merged
kevingranade
merged 10 commits into
CleverRaven:master
from
jbytheway:scores_via_events
Sep 15, 2019
Merged
Implement scores via events #33999
kevingranade
merged 10 commits into
CleverRaven:master
from
jbytheway:scores_via_events
Sep 15, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's already possible to extract the required fields and their types for an event at compile time. Make it possible to also do so at runtime.
ZhilkinSerg
added
<Enhancement / Feature>
New features, or enhancements on existing
[C++]
Changes (can be) made in C++. Previously named `Code`
[JSON]
Changes (can be) made in JSON
[Markdown]
Markdown issues and PRs
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
labels
Sep 13, 2019
Change event_tracker into event_multiset, because we want it to be a more generic object used for more than just tracking events. It now represents any collection of events of the same type. Introduce three new json-defined objects: - event_transformation, which converts one multiset of events to another. For example, it can filter all kill events to just kill events attributed to the avatar. - event_statistic, which converts a multiset of events into a single value. The simplest case, for example, is counting the number of events. - score, which uses an event_statistic to produce a score, which can be saved as a permanent record of a game. Currently scores' only purpose is to be written to the memorial log.
The new "description" field is expected to include a '%s' field for the value of the score to be inserted into.
This is used for things like total damage received in the game.
Rather than the hardcoded scores we previously had, just iterate over all the json-defined scores. Also, add new json scores to cover all the stats that were previously listed.
Want a test for the new "total" stat feature. Rearrange the other tests into SECTIONs at the same time.
jbytheway
force-pushed
the
scores_via_events
branch
from
September 13, 2019 11:29
3559d2a
to
370630a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
<Enhancement / Feature>
New features, or enhancements on existing
[JSON]
Changes (can be) made in JSON
[Markdown]
Markdown issues and PRs
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Infrastructure "Support json-defined scores as a function of events"
Purpose of change
Working towards #4173.
Use the new events system to allow scores to be defined in json. This provides a flexible framework for scores without needing to hardcode too much, and allows mods to add their own scores where it makes sense (e.g. Magiclysm might want to score how many magical creatures you slay, which the core game would not).
Describe the solution
Introduce three new json structures:
event_transformation
which can take a multiset of events (generally, all events of a given type) and filter them in some way based on the values in those events (more types of transformations can be added in the future).event_statistic
which summarizes a multiset of events into a single number. The simplest statistic is just a count of events, but other options are available.score
which specifies that a particularevent_statistic
should be treated as a score, and provides a human-readable description thereof.These are all calculated using
stats_tracker
(#33782). Some updates to thestats_tracker
code support this.For sanity-checking, we need runtime access to the format of each
event_type
. Previously this was only accessible at compile time. Addevent::get_fields
to this end.Add the avatar's
character_id
to thegame_start
event so that it's possible for these transformations to filter on events pertaining to the avatar (rather than other characters).Add tests and documentation.
Replace the "Lifetime stats" section of the memorial file with values calculated using the new scores. Add scores in a new
data/scores.json
which cover the stats that were previously listed here (and a bit more to test other functionality).Describe alternatives you've considered
You might wonder why
score
andevent_statistic
are separate. This is because the statistics can be used for other things. This is already happening in that you can use statistic values to filter events in anevent_transformation
. In the future I also plan to useevent_statistic
s to implement achievements.Additional context
Currently the only was to actually see your scores is via the memorial file. The next step is to add an in-game UI to see them "live". I also want to save them alongside the memorial file in a machine-readable format so they can be viewed in aggregate to provide the "top scores" feature (#4173).
Here's an example extract from a memorial file for a very short-lived character I created in testing:
Currently all these event multisets and statistics are recalculated on demand every time any score is needed. This is fine for scores, but I don't expect it to be sufficiently performant for achievements. My plan is to allow the
stats_tracker
to cache these various values and update them incrementally, so that each individual event can be processed efficiently but also trigger achievements as appropriate.