andrecronje / rarity

d20srd reference implementation codified in solidity
Other
610 stars 121 forks source link

Optimize xp_required #67

Closed murderteeth closed 2 years ago

murderteeth commented 3 years ago

XP calculation is equivalent to SUM(x) which can be also be calculated with x(x+1)/2.

steveocrypto commented 3 years ago

So would it be safe to use calculate this in the UI (saving an RPC call) since it's not available in the library codex? Such as the following:

(level * (level + 1) / 2) * 1000

Level 1: 1000 Level 2: 3000 Level 3: 6000

murderteeth commented 3 years ago

So would it be safe to use calculate this in the UI (saving an RPC call) since it's not available in the library codex? Such as the following:

(level * (level + 1) / 2) * 1000

Level 1: 1000 Level 2: 3000 Level 3: 6000

Correct, you could use that formula to calculate the xp between levels without calling the contract.