Adding bosses to the game #6

Merged
mico merged 21 commits from feature/boss-mechanic into main 2024-10-31 13:56:05 +00:00
2 changed files with 47 additions and 1 deletions
Showing only changes of commit ae8cf3781a - Show all commits

View File

@ -75,6 +75,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
reset_player(player); reset_player(player);
players[player].has_active_session = true; players[player].has_active_session = true;
players[player].is_registered = true; players[player].is_registered = true;
players[player].n_runs += 1;
if (existing_player) { if (existing_player) {
// TODO: Emit new run // TODO: Emit new run
@ -86,7 +87,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
function reset_player(address addr) private { function reset_player(address addr) private {
Player memory player = players[addr]; Player memory player = players[addr];
uint32 current_n_runs = player.n_runs + 1; uint32 current_n_runs = player.n_runs;
uint256 current_total_rewards = player.total_rewards; uint256 current_total_rewards = player.total_rewards;
bool current_is_registered = player.is_registered; bool current_is_registered = player.is_registered;
uint32 current_prestige_level = player.prestige_level; uint32 current_prestige_level = player.prestige_level;

View File

@ -350,4 +350,49 @@ contract raid_geldTest is Test, Constants {
uint256 balance3 = raid_geld.daoToken().balanceOf(address(raid_geld)); uint256 balance3 = raid_geld.daoToken().balanceOf(address(raid_geld));
assertLt(balance2, balance3); assertLt(balance2, balance3);
} }
function test_09_player_can_gain_prestige(uint256 prevrandao) public {
vm.assume(prevrandao < type(uint256).max - 1e4);
vm.startPrank(player1);
stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(player1).checked_write(10000000 ether);
stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(address(raid_geld)).checked_write(10000000 ether);
bool success = false;
uint256 tries = 0;
uint256 streak = 0;
for (uint i = 0; i < 1000; i++) {
vm.prevrandao(prevrandao + i * 59);
bool[2] memory results;
bool alreadyLost = false;
uint256 newStreak = 0;
tries += 1;
console.log("NEW TRY, number: ", tries);
registerPlayerWithDaoToken();
// Give bajillion GELD to player so player can battle boss after boss
stdstore.target(address(raid_geld)).sig("balanceOf(address)").with_key(player1).checked_write(10000000 ether);
for (uint j = 0; j < 6; j++) {
vm.prevrandao(prevrandao + j * 7 + i * 59);
newStreak += 1;
results = raid_geld.battle_with_boss();
if (results[0] == false) {
alreadyLost = true;
break;
}
}
if (alreadyLost) {
if (newStreak > streak) {
streak = newStreak;
}
continue;
}
results = raid_geld.battle_with_boss();
if (results[0] == true && results[1] == true) {
success = true;
Player memory player = raid_geld.getPlayer(player1);
vm.assertEq(player.prestige_level, 1);
vm.assertEq(player.n_runs, tries);
break;
}
}
require(success, "Player should eventually succeed");
}
} }