Balances how much units cost and profit
This commit is contained in:
parent
26b2480b52
commit
0ea4ba320c
@ -107,7 +107,7 @@ contract RaidGeld is ERC20, Ownable {
|
|||||||
|
|
||||||
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units);
|
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units);
|
||||||
// First trigger a raid so player receives what he is due at to this moment
|
// First trigger a raid so player receives what he is due at to this moment
|
||||||
|
|
||||||
uint256 time_past = block.timestamp - players[msg.sender].last_raided_at;
|
uint256 time_past = block.timestamp - players[msg.sender].last_raided_at;
|
||||||
uint256 new_geld = armies[msg.sender].profit_per_second * time_past;
|
uint256 new_geld = armies[msg.sender].profit_per_second * time_past;
|
||||||
require(balanceOf(msg.sender) + new_geld > cost, "Not enough GELD to add this unit");
|
require(balanceOf(msg.sender) + new_geld > cost, "Not enough GELD to add this unit");
|
||||||
|
|||||||
@ -5,18 +5,31 @@ import {Army} from "../src/RaidGeldStructs.sol";
|
|||||||
|
|
||||||
library RaidGeldUtils {
|
library RaidGeldUtils {
|
||||||
uint256 public constant PRECISION = 10000;
|
uint256 public constant PRECISION = 10000;
|
||||||
uint256 constant BASE_PRICE = 380000;
|
|
||||||
uint256 constant PRICE_FACTOR = 11500;
|
uint256 constant PRICE_FACTOR = 11500;
|
||||||
uint256 constant MOLOCH_DENIER_PROFIT = 10000;
|
|
||||||
uint256 constant APPRENTICE_PROFIT = 61000;
|
// base price * (0.00666) * 11 per each next unit
|
||||||
uint256 constant ANOINTED_PROFIT = 6 * 64000;
|
uint256 constant MOLOCH_DENIER_PROFIT = 2533;
|
||||||
uint256 constant CHAMPION_PROFIT = 36 * 67000;
|
uint256 constant APPRENTICE_PROFIT = 27863;
|
||||||
|
uint256 constant ANOINTED_PROFIT = 306493;
|
||||||
|
uint256 constant CHAMPION_PROFIT = 3371423;
|
||||||
|
|
||||||
|
// each costs 10 times plus a bit more
|
||||||
|
uint256 constant MOLOCH_DENIER_BASE_COST = 380000;
|
||||||
|
uint256 constant APPRENTICE_BASE_COST = 3420000;
|
||||||
|
uint256 constant ANOINTED_BASE_COST = 30096000;
|
||||||
|
uint256 constant CHAMPION_BASE_COST = 255816000;
|
||||||
|
|
||||||
function calculateUnitPrice(uint8 unit, uint16 currentLevel, uint16 units) internal pure returns (uint256) {
|
function calculateUnitPrice(uint8 unit, uint16 currentLevel, uint16 units) internal pure returns (uint256) {
|
||||||
require(unit <= 3, "No matching unit found");
|
require(unit <= 3, "No matching unit found");
|
||||||
|
uint256 rollingPriceCalculation = MOLOCH_DENIER_BASE_COST;
|
||||||
uint256 rollingPriceCalculation = uint256(unit + 1) * BASE_PRICE;
|
|
||||||
uint256 price = 0;
|
uint256 price = 0;
|
||||||
|
if (unit == 1) {
|
||||||
|
rollingPriceCalculation = APPRENTICE_BASE_COST;
|
||||||
|
} else if (unit == 2) {
|
||||||
|
rollingPriceCalculation = ANOINTED_BASE_COST;
|
||||||
|
} else if (unit == 3) {
|
||||||
|
rollingPriceCalculation = CHAMPION_BASE_COST;
|
||||||
|
}
|
||||||
|
|
||||||
// Each level costs 15% more than previous
|
// Each level costs 15% more than previous
|
||||||
for (uint256 i = 0; i < currentLevel + units; i++) {
|
for (uint256 i = 0; i < currentLevel + units; i++) {
|
||||||
|
|||||||
@ -161,7 +161,7 @@ contract raid_geldTest is Test {
|
|||||||
uint256 last_raided_at = player.last_raided_at;
|
uint256 last_raided_at = player.last_raided_at;
|
||||||
assertLt(balance, newBalance);
|
assertLt(balance, newBalance);
|
||||||
|
|
||||||
// After wait time passes raid should bring in profits again
|
// After wait time passes raid should bring in profits again
|
||||||
vm.warp(block.timestamp + 15);
|
vm.warp(block.timestamp + 15);
|
||||||
raid_geld.raid();
|
raid_geld.raid();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ contract raid_geldTest is Test {
|
|||||||
function test_0_unit_price() public pure {
|
function test_0_unit_price() public pure {
|
||||||
// buying 1 unit of moloch_denier
|
// buying 1 unit of moloch_denier
|
||||||
uint256 basePriceMolochDenier = RaidGeldUtils.calculateUnitPrice(0, 0, 1);
|
uint256 basePriceMolochDenier = RaidGeldUtils.calculateUnitPrice(0, 0, 1);
|
||||||
assertEq(basePriceMolochDenier, RaidGeldUtils.BASE_PRICE);
|
assertEq(basePriceMolochDenier, RaidGeldUtils.MOLOCH_DENIER_BASE_COST);
|
||||||
|
|
||||||
// buying 3 units
|
// buying 3 units
|
||||||
// has to be a bit more than 3 * 38 = 114
|
// has to be a bit more than 3 * 38 = 114
|
||||||
@ -37,7 +37,7 @@ contract raid_geldTest is Test {
|
|||||||
profit_per_second: 0 // irrelevant for this test
|
profit_per_second: 0 // irrelevant for this test
|
||||||
});
|
});
|
||||||
uint256 profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
uint256 profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
||||||
assertEq(profits_per_second, RaidGeldUtils.PRECISION);
|
assertEq(profits_per_second, RaidGeldUtils.MOLOCH_DENIER_PROFIT);
|
||||||
|
|
||||||
army = Army({
|
army = Army({
|
||||||
moloch_denier: Raider({level: _dLvl}),
|
moloch_denier: Raider({level: _dLvl}),
|
||||||
@ -47,7 +47,7 @@ contract raid_geldTest is Test {
|
|||||||
profit_per_second: 0 // irrelevant for this test
|
profit_per_second: 0 // irrelevant for this test
|
||||||
});
|
});
|
||||||
profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
||||||
uint256 expected = _dLvl * RaidGeldUtils.PRECISION + _apLvl * RaidGeldUtils.APPRENTICE_PROFIT
|
uint256 expected = _dLvl * RaidGeldUtils.MOLOCH_DENIER_PROFIT + _apLvl * RaidGeldUtils.APPRENTICE_PROFIT
|
||||||
+ _anLvl * RaidGeldUtils.ANOINTED_PROFIT + _cLvl * RaidGeldUtils.CHAMPION_PROFIT;
|
+ _anLvl * RaidGeldUtils.ANOINTED_PROFIT + _cLvl * RaidGeldUtils.CHAMPION_PROFIT;
|
||||||
assertEq(profits_per_second, expected);
|
assertEq(profits_per_second, expected);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user