Dynamic Loot Items + Computed Adventurers Statistics #141
ponderingdemocritus
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here I outline how I think on-chain statistics for the individual Loot items should be stored and computed. This pattern could really be used for any game statistics system.
Loot has ~100 items and since we are creating an on-chain MMO we need an efficient DRY way to store all this information. Then we need an easy way to pull all this information together into one final statistics amount for the Adventurer. Luckily we can leverage the computation of Cairo to do so.
An item could be thought of as having the following properties (this is by no means finished and will require discussion)
Since the number of items is infinite, we need to store minimal state but have the ability to compute values on the fly for gameplay.
We can create an easy way to fetch information by mapping every item to an id like so:
Now we have an index mapping above, we can create a new namespace for each base stat like so:
After this, we need a way to fetch each item's computed values which remember are:
See full file here
Cairo has a very nice way of storing information in labels which can be fetched much like an array. The following function takes in the
ItemId
and will return the agility value of the item.This pattern can be repeated for each statistic.
Now that we can easily fetch each item's base value we can compute them in any way we need. The following is an example (This function is incomplete so it will not work but hopefully explains my thinking.
Now we have these items' statistics we can create a function in the Adventurers contract that pulls all of this information together according to what values the player has equipped. This final value can then be used for gameplay!
We do need to define an Adventurer struct first
Then we compute it all together!
This implementation is by no means complete but is a starting point to creating the structure for a dynamic on-chain statistics system.
See the Loot branch for a deeper dive into the functions and checkout the test suite to see them in action here
Beta Was this translation helpful? Give feedback.
All reactions