forked from mico/idle_moloch
session wallet
This commit is contained in:
parent
a49c0e861c
commit
ef1c242471
@ -25,6 +25,8 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
|||||||
mapping(address => Boss) private bosses;
|
mapping(address => Boss) private bosses;
|
||||||
mapping(address => LastBossResult) private lastBossResults;
|
mapping(address => LastBossResult) private lastBossResults;
|
||||||
|
|
||||||
|
mapping(address => address) private sessionWallets;
|
||||||
|
|
||||||
// WETH
|
// WETH
|
||||||
IWETH public immutable weth = IWETH(WETH);
|
IWETH public immutable weth = IWETH(WETH);
|
||||||
// RGCVII token
|
// RGCVII token
|
||||||
@ -92,7 +94,10 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modifier onlyActiveSession() {
|
modifier onlyActiveSession() {
|
||||||
require(players[msg.sender].has_active_session, "Session is not active, you need to buy into the game first");
|
address delegatedPlayer = sessionWallets[msg.sender];
|
||||||
|
require(
|
||||||
|
players[msg.sender].has_active_session ||
|
||||||
|
players[delegatedPlayer].has_active_session, "Session is not active, you need to buy into the game first");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +205,9 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
|||||||
|
|
||||||
// Manual minting for itchy fingers
|
// Manual minting for itchy fingers
|
||||||
function raid() external onlyActiveSession {
|
function raid() external onlyActiveSession {
|
||||||
performRaid(msg.sender);
|
address delegatedPlayer = sessionWallets[msg.sender];
|
||||||
|
address player = delegatedPlayer == address(0) ? msg.sender : delegatedPlayer;
|
||||||
|
performRaid(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper so we can use it when buying units too
|
// Helper so we can use it when buying units too
|
||||||
@ -240,9 +247,11 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
|||||||
|
|
||||||
// Add a unit to your army
|
// Add a unit to your army
|
||||||
function addUnit(uint8 unit, uint16 n_units) external onlyActiveSession {
|
function addUnit(uint8 unit, uint16 n_units) external onlyActiveSession {
|
||||||
|
address delegatedPlayer = sessionWallets[msg.sender];
|
||||||
|
address player = delegatedPlayer == address(0) ? msg.sender : delegatedPlayer;
|
||||||
require(unit <= 3, "Unknown unit");
|
require(unit <= 3, "Unknown unit");
|
||||||
|
|
||||||
Army storage army = armies[msg.sender];
|
Army storage army = armies[player];
|
||||||
uint16 currentLevel = 0;
|
uint16 currentLevel = 0;
|
||||||
if (unit == 0) {
|
if (unit == 0) {
|
||||||
// moloch_denier
|
// moloch_denier
|
||||||
@ -261,13 +270,13 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
|||||||
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units);
|
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units);
|
||||||
|
|
||||||
|
|
||||||
performRaid(msg.sender);
|
performRaid(player);
|
||||||
|
|
||||||
// TODO: Since we are first minting then burning the token, this could be simplified
|
// TODO: Since we are first minting then burning the token, this could be simplified
|
||||||
require(balanceOf(msg.sender) >= cost, "Not enough GELD to add this unit");
|
require(balanceOf(player) >= cost, "Not enough GELD to add this unit");
|
||||||
|
|
||||||
// then burn the cost of the new army
|
// then burn the cost of the new army
|
||||||
_burn(msg.sender, cost);
|
_burn(player, cost);
|
||||||
|
|
||||||
// Increase level
|
// Increase level
|
||||||
if (unit == 0) {
|
if (unit == 0) {
|
||||||
@ -289,7 +298,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
|||||||
|
|
||||||
// Emit event
|
// Emit event
|
||||||
emit UnitAdded(
|
emit UnitAdded(
|
||||||
msg.sender,
|
player,
|
||||||
unit,
|
unit,
|
||||||
n_units,
|
n_units,
|
||||||
cost,
|
cost,
|
||||||
@ -428,6 +437,12 @@ contract RaidGeld is ERC20, Ownable, Constants {
|
|||||||
DAO = _dao;
|
DAO = _dao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function approveSessionWallet(address _wallet) payable external onlyPlayer {
|
||||||
|
require(!isRegistered(_wallet), "Wallet belongs to other player");
|
||||||
|
sessionWallets[msg.sender] = _wallet;
|
||||||
|
payable(_wallet).call{value: msg.value}("");
|
||||||
|
}
|
||||||
|
|
||||||
receive() external payable {
|
receive() external payable {
|
||||||
revert("No plain Ether accepted, use register() function to check in :)");
|
revert("No plain Ether accepted, use register() function to check in :)");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user