1
0
forked from mico/idle_moloch

Added utils for calculating price and unit cost

This commit is contained in:
mic0 2024-10-22 17:53:21 +02:00
parent 5010a7b00d
commit 38644f52c1
Signed by: mico
GPG Key ID: A3F8023524CF1C8D
2 changed files with 29 additions and 1 deletions

View File

@ -2,7 +2,7 @@
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/access/ownable.sol";
struct Raider { struct Raider {
uint16 level; uint16 level;

28
src/RaidGeldUtils.sol Normal file
View File

@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Army} from "../src/RaidGeld.sol"
library RaidGeldUtils {
function calculateUnitPrice(uint8 unit, uint16 units) internal pure returns (uint256) {
require(unit <= 3, "No matching unit found");
uint256 price = uint256(unit);
uint256 unitsAlready = uint256(units);
// Each level costs 15% more than previous
uint256 PERCENT_INCREASE = 115;
for (uint256 i = 0; i < n; i++) {
newPrice = newPrice * PERCENT_INCREASE / 100;
}
return unitBaseCost + (unitBaseCost * 15 / 100);
}
function calculateProfitsPerSecond(Army army) internal pure returns (uint256) {
// Each next unit scales progressivelly better
uint256 moloch_denier_profit = army.moloch_denier.level;
uint256 apprentice_profit = army.apprentice.level * 61 / 10;
uint256 annointed_profit = army.annointed.level * 6 * 64 / 10;
uint256 champion_profit = army.champion.level * 61 / 10 * 64 / 10 * 67 / 10;
return moloch_denier_profit + apprentice_profit + annointed_profit + champion_profit;
}
}