From 38644f52c1aefca67cf2a540a9277861b969833e Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Tue, 22 Oct 2024 17:53:21 +0200 Subject: [PATCH] Added utils for calculating price and unit cost --- src/RaidGeld.sol | 2 +- src/RaidGeldUtils.sol | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/RaidGeldUtils.sol diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 010a8e4..c989af1 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.13; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/access/ownable.sol"; struct Raider { uint16 level; diff --git a/src/RaidGeldUtils.sol b/src/RaidGeldUtils.sol new file mode 100644 index 0000000..92883ee --- /dev/null +++ b/src/RaidGeldUtils.sol @@ -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; + } +}