Skip to content

Commit

Permalink
apply xp multiplier to move
Browse files Browse the repository at this point in the history
  • Loading branch information
dhvanipa committed Oct 17, 2024
1 parent f34b91d commit 6ef5509
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/experience/worlds.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"blockNumber": 1110780
},
"31337": {
"address": "0xcecde2b592e20bccda93e8b5790693b031f1be68"
"address": "0xa3013b185927740238bfac2dc1529834ac393c36"
}
}
2 changes: 1 addition & 1 deletion packages/world/src/systems/BuildSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract BuildSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

// Note: we call this after the build state has been updated, to prevent re-entrancy attacks
callInternalSystem(
Expand Down
10 changes: 5 additions & 5 deletions packages/world/src/systems/ChipSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract ChipSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

// Don't safe call here because we want to revert if the chip doesn't allow the attachment
IChip(chipAddress).onAttached(playerEntityId, entityId);
Expand Down Expand Up @@ -108,7 +108,7 @@ contract ChipSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

safeCallChip(chipData.chipAddress, abi.encodeCall(IChip.onDetached, (playerEntityId, entityId)));
}
Expand Down Expand Up @@ -153,7 +153,7 @@ contract ChipSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

safeCallChip(chipData.chipAddress, abi.encodeCall(IChip.onPowered, (playerEntityId, entityId, numBattery)));
}
Expand Down Expand Up @@ -213,7 +213,7 @@ contract ChipSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

safeCallChip(chipData.chipAddress, abi.encodeCall(IChip.onDetached, (playerEntityId, entityId)));
} else {
Expand All @@ -232,7 +232,7 @@ contract ChipSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

safeCallChip(chipData.chipAddress, abi.encodeCall(IChip.onChipHit, (playerEntityId, entityId)));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/world/src/systems/CraftSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ contract CraftSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);
}
}
4 changes: 2 additions & 2 deletions packages/world/src/systems/DropSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract DropSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);
}

function dropTool(bytes32 toolEntityId, VoxelCoord memory coord) public {
Expand All @@ -84,6 +84,6 @@ contract DropSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);
}
}
2 changes: 1 addition & 1 deletion packages/world/src/systems/MineSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract MineSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

callInternalSystem(
abi.encodeCall(
Expand Down
2 changes: 1 addition & 1 deletion packages/world/src/systems/MoveSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ contract MoveSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 10);
}

function move(
Expand Down
8 changes: 4 additions & 4 deletions packages/world/src/systems/PickupSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract PickupSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);
}

function pickup(uint8 pickupObjectTypeId, uint16 numToPickup, VoxelCoord memory coord) public {
Expand All @@ -75,7 +75,7 @@ contract PickupSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);
}

function pickupTool(bytes32 toolEntityId, VoxelCoord memory coord) public {
Expand All @@ -97,7 +97,7 @@ contract PickupSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);
}

function pickupMultiple(
Expand Down Expand Up @@ -150,6 +150,6 @@ contract PickupSystem is System {
);
}

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);
}
}
4 changes: 2 additions & 2 deletions packages/world/src/systems/TransferSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract TransferSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

// Note: we call this after the transfer state has been updated, to prevent re-entrancy attacks
requireAllowed(
Expand Down Expand Up @@ -148,7 +148,7 @@ contract TransferSystem is System {
})
);

mintXP(playerEntityId, initialGas);
mintXP(playerEntityId, initialGas, 1);

// Note: we call this after the transfer state has been updated, to prevent re-entrancy attacks
requireAllowed(playerEntityId, srcEntityId, dstEntityId, toolObjectTypeId, 1, toolEntityId, extraData);
Expand Down
4 changes: 2 additions & 2 deletions packages/world/src/utils/XPUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pragma solidity >=0.8.24;

import { ExperiencePoints } from "../codegen/tables/ExperiencePoints.sol";

function mintXP(bytes32 playerEntityId, uint256 initialGas) {
function mintXP(bytes32 playerEntityId, uint256 initialGas, uint256 multiplier) {
uint256 gasUsed = initialGas - gasleft();
uint256 txFeeWei = gasUsed * block.basefee;
uint256 xpToMint = txFeeWei / 4200000;
uint256 xpToMint = txFeeWei / (4200000 * multiplier);
uint256 currentXP = ExperiencePoints._get(playerEntityId);
ExperiencePoints._set(playerEntityId, currentXP + xpToMint);
}
2 changes: 1 addition & 1 deletion packages/world/worlds.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"blockNumber": 1110780
},
"31337": {
"address": "0xcecde2b592e20bccda93e8b5790693b031f1be68"
"address": "0xa3013b185927740238bfac2dc1529834ac393c36"
}
}

0 comments on commit 6ef5509

Please sign in to comment.