forked from mico/idle_moloch
Fixes the issue with adding units not minting token straight away, fixes overlay issues so the tower is clickable again
This commit is contained in:
parent
e993067360
commit
b153e4b6bd
@ -5,6 +5,8 @@
|
||||
bottom: 22px;
|
||||
top: 22px;
|
||||
overflow: hidden;
|
||||
user-select: none;
|
||||
pointer-events: none;
|
||||
}
|
||||
.army-gathering {
|
||||
position: absolute;
|
||||
@ -23,8 +25,6 @@
|
||||
}
|
||||
.marchingGroup {
|
||||
position: absolute;
|
||||
user-select: none;
|
||||
pointer-events: none;
|
||||
left: 0;
|
||||
bottom: 84px;
|
||||
animation: marching 20s linear;
|
||||
|
||||
@ -73,15 +73,19 @@ contract RaidGeld is ERC20, Ownable {
|
||||
// Manual minting for itchy fingers
|
||||
function raid() external onlyPlayer {
|
||||
require(block.timestamp >= players[msg.sender].last_raided_at + RAID_WAIT, "Tried minting too soon");
|
||||
performRaid(msg.sender);
|
||||
}
|
||||
|
||||
uint256 time_past = block.timestamp - players[msg.sender].last_raided_at;
|
||||
uint256 new_geld = armies[msg.sender].profit_per_second * time_past * 10 ** decimals();
|
||||
// Helper so we can use it when buying units too
|
||||
function performRaid(address player) private {
|
||||
uint256 time_past = block.timestamp - players[player].last_raided_at;
|
||||
uint256 new_geld = armies[player].profit_per_second * time_past * 10 ** decimals();
|
||||
|
||||
// TODO: Pink noise, make it so sometimes its better than expected
|
||||
|
||||
_mint(msg.sender, new_geld);
|
||||
players[msg.sender].last_raided_at = block.timestamp;
|
||||
players[msg.sender].total_minted = new_geld;
|
||||
_mint(player, new_geld);
|
||||
players[player].last_raided_at = block.timestamp;
|
||||
players[player].total_minted = new_geld;
|
||||
}
|
||||
|
||||
// Function to get Player struct
|
||||
@ -103,6 +107,9 @@ contract RaidGeld is ERC20, Ownable {
|
||||
function addUnit(uint8 unit, uint16 n_units) external onlyPlayer {
|
||||
require(unit <= 3, "Unknown unit");
|
||||
|
||||
// First trigger a raid so player receives what he is due at to this moment
|
||||
performRaid(msg.sender);
|
||||
|
||||
Army storage army = armies[msg.sender];
|
||||
uint16 currentLevel = 0;
|
||||
if (unit == 0) {
|
||||
@ -119,7 +126,7 @@ contract RaidGeld is ERC20, Ownable {
|
||||
currentLevel = army.champion.level;
|
||||
}
|
||||
|
||||
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units);
|
||||
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units) * 10 ** decimals();
|
||||
require(balanceOf(msg.sender) > cost, "Not enough GELD to add this much");
|
||||
_burn(msg.sender, cost);
|
||||
|
||||
|
||||
@ -13,10 +13,8 @@ contract raid_geldTest is Test {
|
||||
function setUp() public {
|
||||
owner = address(0x126);
|
||||
player1 = address(0x123);
|
||||
player2 = address(0x124);
|
||||
vm.deal(owner, 10 ether);
|
||||
vm.deal(player1, 10 ether);
|
||||
vm.deal(player2, 10 ether);
|
||||
vm.prank(owner);
|
||||
raid_geld = new RaidGeld();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user