Skip to content

Commit

Permalink
Make incremental playerId daily rewards more random
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSamWitch committed Jul 19, 2023
1 parent fb89f5a commit 176a1d7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ contract World is VRFConsumerBaseV2Upgradeable, UUPSUpgradeable, OwnableUpgradea
}

function _getRewardIndex(uint _playerId, uint _day, uint _length) private view returns (uint) {
return uint((thisWeeksRandomWordSegment >> (_day * 8)) ^ bytes32(_playerId)) % _length;
return uint(keccak256(abi.encodePacked(thisWeeksRandomWordSegment, _playerId)) >> (_day * 8)) % _length;
}

function _setAction(Action calldata _action) private {
Expand Down
3 changes: 0 additions & 3 deletions test/Players/Rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,6 @@ describe("Rewards", function () {
const randomChanceFraction = randomChanceFractions[i];
const expectedTotal = numRepeats * randomChanceFraction * numHours;
// Have 2 queued actions so twice as much

console.log(itemTokenId, expectedTotal);

expect(balanceMap.get(itemTokenId)).to.not.eq(expectedTotal * 2); // Very unlikely to be exact, but possible. This checks there is at least some randomness
expect(balanceMap.get(itemTokenId)).to.be.gte(expectedTotal * 0.75 * 2); // Within 25% below
expect(balanceMap.get(itemTokenId)).to.be.lte(expectedTotal * 1.25 * 2); // Within 25% above
Expand Down
2 changes: 1 addition & 1 deletion test/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe("World", function () {
let dailyRewards1 = await world.getActiveDailyAndWeeklyRewards(1, playerId + 1);
let dailyRewards2 = await world.getActiveDailyAndWeeklyRewards(1, playerId + 2);

// Check that the dailyRewards are different
// TODO: Check that incremental playerIds don't have rewards that have incremental indices in the reward pool tier
expect(dailyRewards).to.not.eql(dailyRewards1);
expect(dailyRewards).to.not.eql(dailyRewards2);
expect(dailyRewards1).to.not.eql(dailyRewards2);
Expand Down

0 comments on commit 176a1d7

Please sign in to comment.