Adding bosses to the game #6
@ -12,7 +12,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
||||
uint256 public constant MANTISSA = 1e4;
|
||||
uint256 public constant BUY_IN_AMOUNT = 0.00005 ether;
|
||||
uint256 public immutable BUY_IN_DAO_TOKEN_AMOUNT;
|
||||
uint256 public constant INITIAL_GELD = 500 * MANTISSA;
|
||||
uint256 public constant INITIAL_GELD = 50 * MANTISSA;
|
||||
mapping(address => Player) private players;
|
||||
mapping(address => Army) private armies;
|
||||
mapping(address => Boss) private bosses;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import {Army} from "../src/RaidGeldStructs.sol";
|
||||
import {console} from "forge-std/Test.sol";
|
||||
|
||||
library RaidGeldUtils {
|
||||
uint256 public constant PRECISION = 10000;
|
||||
@ -109,7 +110,7 @@ library RaidGeldUtils {
|
||||
// Relative power as in, you can only put in 800 geld to defeat 900 geld boss,
|
||||
// but you will get exponentially worse chances
|
||||
uint256 relativePower = ((geldBurnt ** 2) * 100) / bossPower ** 2;
|
||||
uint256 roll = random_n * relativePower / 1e2;
|
||||
uint256 roll = 1e2 - (random_n * relativePower / 1e2);
|
||||
return roll < bossRoll;
|
||||
}
|
||||
|
||||
|
||||
@ -264,6 +264,9 @@ contract raid_geldTest is Test, Constants {
|
||||
registerPlayerWithDaoToken();
|
||||
raid_geld.addUnit(0, 1);
|
||||
|
||||
uint256 initialDaoBalance = raid_geld.daoToken().balanceOf(player1);
|
||||
uint256 initialContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld));
|
||||
|
||||
Boss memory boss = raid_geld.getBoss(player1);
|
||||
// assert boss is initialized
|
||||
assertEq(boss.level, 0);
|
||||
@ -272,14 +275,47 @@ contract raid_geldTest is Test, Constants {
|
||||
|
||||
// Make a lot of time pass so user deffo has GELD to attack the boss
|
||||
vm.warp(1200000);
|
||||
|
||||
bool[2] memory results = raid_geld.battle_with_boss();
|
||||
console.log(results[0]);
|
||||
console.log(results[1]);
|
||||
|
||||
// Should almost always defeat first boss
|
||||
assertEq(results[0], true);
|
||||
// First boss doesnt grant a new prestige level (ascension)
|
||||
assertEq(results[1], false);
|
||||
|
||||
uint256 afterBossDaoBalance = raid_geld.daoToken().balanceOf(player1);
|
||||
uint256 afterBossContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld));
|
||||
|
||||
// User should receive funs, contract should lose them
|
||||
assertLt(initialDaoBalance, afterBossDaoBalance);
|
||||
assertGt(initialContractBalance, afterBossContractBalance);
|
||||
|
||||
Player memory player = raid_geld.getPlayer(player1);
|
||||
// Players total rewards should increase
|
||||
assertGt(player.total_rewards, 0);
|
||||
}
|
||||
|
||||
function test_07_attack_boss_fail() public {
|
||||
// Let some time pass so we dont start at block timestamp 0
|
||||
vm.warp(120);
|
||||
|
||||
// Register player 1
|
||||
vm.startPrank(player1);
|
||||
registerPlayerWithDaoToken();
|
||||
raid_geld.addUnit(0, 1);
|
||||
|
||||
bool[2] memory results = raid_geld.battle_with_boss();
|
||||
// Should lose with just starting GELD
|
||||
assertEq(results[0], false);
|
||||
// First boss doesnt grant a new prestige level (ascension)
|
||||
assertEq(results[1], false);
|
||||
|
||||
Player memory player = raid_geld.getPlayer(player1);
|
||||
Army memory army = raid_geld.getArmy(player1);
|
||||
|
||||
// player sessions should end
|
||||
assertEq(player.has_active_session, false);
|
||||
// player should lose all geld
|
||||
assertEq(raid_geld.balanceOf(player1), 0);
|
||||
// Units should reset
|
||||
assertEq(army.moloch_denier.level, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user