Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some elements of the anniversary event #83

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions contracts/Clans/LockedBankVaults.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {ISamWitchVRF} from "../interfaces/ISamWitchVRF.sol";
import {AdminAccess} from "../AdminAccess.sol";
import {ItemNFT} from "../ItemNFT.sol";

import {BattleResultEnum, ClanRank, MAX_CLAN_COMBATANTS, CLAN_WARS_GAS_PRICE_WINDOW_SIZE, ClanInfo, Vault, ClanBattleInfo} from "../globals/clans.sol";
import {BattleResultEnum, ClanRank, MAX_CLAN_COMBATANTS, CLAN_WARS_GAS_PRICE_WINDOW_SIZE, VaultClanInfo, Vault, ClanBattleInfo} from "../globals/clans.sol";
import {Item, EquipPosition} from "../globals/players.sol";
import {BoostType, Skill} from "../globals/misc.sol";
import {NONE} from "../globals/items.sol";
Expand Down Expand Up @@ -115,7 +115,7 @@ contract LockedBankVaults is
Skill[] private comparableSkills;
uint64 private nextPendingAttackId;
bool private preventAttacks;
mapping(uint clanId => ClanInfo clanInfo) private clanInfos;
mapping(uint clanId => VaultClanInfo clanInfo) private clanInfos;
mapping(uint pendingAttackId => PendingAttack pendingAttack) private pendingAttacks;
mapping(bytes32 requestId => uint pendingAttackId) private requestToPendingAttackIds;
mapping(uint clanId => mapping(uint otherClanId => ClanBattleInfo battleInfo)) public lastClanBattles; // Always ordered from lowest clanId to highest
Expand Down Expand Up @@ -280,7 +280,7 @@ contract LockedBankVaults is
uint _combatantCooldownTimestamp,
uint _leaderPlayerId
) external override onlyCombatantsHelper {
ClanInfo storage clanInfo = clanInfos[_clanId];
VaultClanInfo storage clanInfo = clanInfos[_clanId];
LockedBankVaultsLibrary.checkCanAssignCombatants(clanInfo, _playerIds);
clanInfo.playerIds = _playerIds;
clanInfo.assignCombatantsCooldownTimestamp = uint40(block.timestamp + combatantChangeCooldown);
Expand Down Expand Up @@ -343,14 +343,13 @@ contract LockedBankVaults is
// Check MMRs are within the list, X ranks above and below. However at the extremes add it to the other end
LockedBankVaultsLibrary.checkWithinRange(sortedClansByMMR, _clanId, _defendingClanId, clans, mmrAttackDistance);

ClanInfo storage clanInfo = clanInfos[_clanId];
VaultClanInfo storage clanInfo = clanInfos[_clanId];
clanInfo.currentlyAttacking = true;

uint64 _nextPendingAttackId = nextPendingAttackId++;

uint40 attackingCooldownTimestamp = uint40(block.timestamp + attackingCooldown);
clanInfo.attackingCooldownTimestamp = attackingCooldownTimestamp;
clanInfo.gasPaid = uint88(msg.value);
if (isUsingSuperAttack) {
clanInfo.superAttackCooldownTimestamp = uint40(superAttackCooldownTimestamp);
}
Expand Down Expand Up @@ -530,7 +529,7 @@ contract LockedBankVaults is

function lockFunds(uint _clanId, address _from, uint _playerId, uint _amount) external onlyTerritories {
_lockFunds(_clanId, _from, _playerId, _amount);
ClanInfo storage clanInfo = clanInfos[_clanId];
VaultClanInfo storage clanInfo = clanInfos[_clanId];
if (!clanInfo.isInMMRArray) {
LockedBankVaultsLibrary.insertMMRArray(sortedClansByMMR, clans.getMMR(_clanId), uint32(_clanId));
clanInfo.isInMMRArray = true;
Expand All @@ -542,7 +541,7 @@ contract LockedBankVaults is

function clanMemberLeft(uint _clanId, uint _playerId) external override onlyClans {
// Remove a player combatant if they are currently assigned in this clan
ClanInfo storage clanInfo = clanInfos[_clanId];
VaultClanInfo storage clanInfo = clanInfos[_clanId];
if (clanInfo.playerIds.length != 0) {
uint searchIndex = EstforLibrary.binarySearch(clanInfo.playerIds, _playerId);
if (searchIndex != type(uint).max) {
Expand Down Expand Up @@ -608,7 +607,7 @@ contract LockedBankVaults is
if (_amount == 0) {
return;
}
ClanInfo storage clanInfo = clanInfos[_clanId];
VaultClanInfo storage clanInfo = clanInfos[_clanId];
uint totalBrushLocked = clanInfo.totalBrushLocked;
clanInfo.totalBrushLocked = uint96(totalBrushLocked + _amount);
uint40 lockingTimestamp = uint40(block.timestamp + lockFundsPeriod);
Expand Down Expand Up @@ -640,7 +639,7 @@ contract LockedBankVaults is
return baseAttackCost + (movingAverageGasPrice * expectedGasLimitFulfill);
}

function getClanInfo(uint _clanId) external view returns (ClanInfo memory) {
function getClanInfo(uint _clanId) external view returns (VaultClanInfo memory) {
return clanInfos[_clanId];
}

Expand Down
26 changes: 13 additions & 13 deletions contracts/Clans/LockedBankVaultsLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.20;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

import {ClanInfo, ClanBattleInfo, Vault, MAX_CLAN_COMBATANTS} from "../globals/clans.sol";
import {VaultClanInfo, ClanBattleInfo, Vault, MAX_CLAN_COMBATANTS} from "../globals/clans.sol";
import {Item, EquipPosition, BoostType} from "../globals/players.sol";
import {IItemNFT} from "../interfaces/IItemNFT.sol";
import {IClans} from "../interfaces/IClans.sol";
Expand Down Expand Up @@ -34,7 +34,7 @@ library LockedBankVaultsLibrary {
function initializeMMR(
uint48[] storage _sortedClansByMMR,
IClans _clans,
mapping(uint clanId => ClanInfo _clanInfo) storage _clanInfos,
mapping(uint clanId => VaultClanInfo _clanInfo) storage _clanInfos,
uint[] calldata _clanIds,
uint16[] calldata _mmrs
) external {
Expand All @@ -52,7 +52,7 @@ library LockedBankVaultsLibrary {
function forceMMRUpdate(
uint48[] storage _sortedClansByMMR,
IClans _clans,
mapping(uint clanId => ClanInfo _clanInfo) storage _clanInfos,
mapping(uint clanId => VaultClanInfo _clanInfo) storage _clanInfos,
uint[] calldata _clanIds
) external returns (uint[] memory clanIdsToDelete) {
// Create an array to mark elements for deletion
Expand Down Expand Up @@ -100,7 +100,7 @@ library LockedBankVaultsLibrary {

function claimFunds(
uint48[] storage _sortedClansByMMR,
ClanInfo storage _clanInfo,
VaultClanInfo storage _clanInfo,
uint256 _clanId
) external returns (uint256 total, uint256 numLocksClaimed) {
uint defendingVaultsOffset = _clanInfo.defendingVaultsOffset;
Expand Down Expand Up @@ -191,7 +191,7 @@ library LockedBankVaultsLibrary {
}
}

function _hasLockedFunds(ClanInfo storage _clanInfo) internal view returns (bool) {
function _hasLockedFunds(VaultClanInfo storage _clanInfo) internal view returns (bool) {
uint length = _clanInfo.defendingVaults.length;
if (length == 0) {
return false;
Expand Down Expand Up @@ -345,7 +345,7 @@ library LockedBankVaultsLibrary {
function blockAttacks(
IItemNFT _itemNFT,
uint16 _itemTokenId,
ClanInfo storage _clanInfo
VaultClanInfo storage _clanInfo
) external returns (uint256 blockAttacksTimestamp) {
Item memory item = _itemNFT.getItem(_itemTokenId);
if (item.equipPosition != EquipPosition.LOCKED_VAULT || item.boostType != BoostType.PVP_BLOCK) {
Expand All @@ -371,7 +371,7 @@ library LockedBankVaultsLibrary {
uint256 _attackingClanId,
uint256 _defendingClanId,
bool _didAttackersWin,
mapping(uint clanId => ClanInfo clanInfo) storage _clanInfos
mapping(uint clanId => VaultClanInfo clanInfo) storage _clanInfos
) external returns (int256 attackingMMRDiff, int256 defendingMMRDiff) {
(uint256 clanIndex, uint256 defendingClanIndex) = _getClanIndices(
_sortedClansByMMR,
Expand Down Expand Up @@ -453,11 +453,11 @@ library LockedBankVaultsLibrary {
uint256 _maxLockedVaults,
uint256 _numPackedVaults,
IItemNFT _itemNFT,
mapping(uint clanId => ClanInfo clanInfo) storage _clanInfos,
mapping(uint clanId => VaultClanInfo clanInfo) storage _clanInfos,
mapping(uint clanId => mapping(uint otherClanId => ClanBattleInfo battleInfo)) storage _lastClanBattles
) external view returns (bool isReattacking, bool isUsingSuperAttack, uint superAttackCooldownTimestamp) {
// Must have at least 1 combatant
ClanInfo storage clanInfo = _clanInfos[_clanId];
VaultClanInfo storage clanInfo = _clanInfos[_clanId];
if (clanInfo.playerIds.length == 0) {
revert NoCombatants();
}
Expand All @@ -467,7 +467,7 @@ library LockedBankVaultsLibrary {
}

// Does this clan have any brush to even attack?
ClanInfo storage defendingClanInfo = _clanInfos[_defendingClanId];
VaultClanInfo storage defendingClanInfo = _clanInfos[_defendingClanId];
if (defendingClanInfo.totalBrushLocked == 0) {
revert NoBrushToAttack();
}
Expand Down Expand Up @@ -574,7 +574,7 @@ library LockedBankVaultsLibrary {

function getIdleClans(
uint48[] storage _sortedClansByMMR,
mapping(uint clanId => ClanInfo _clanInfo) storage _clanInfos,
mapping(uint clanId => VaultClanInfo _clanInfo) storage _clanInfos,
IClans _clans
) external view returns (uint256[] memory clanIds) {
uint256 origLength = _sortedClansByMMR.length;
Expand Down Expand Up @@ -614,7 +614,7 @@ library LockedBankVaultsLibrary {
return low;
}

function checkCanAssignCombatants(ClanInfo storage _clanInfo, uint48[] calldata _playerIds) external view {
function checkCanAssignCombatants(VaultClanInfo storage _clanInfo, uint48[] calldata _playerIds) external view {
if (_clanInfo.currentlyAttacking) {
revert CannotChangeCombatantsDuringAttack();
}
Expand All @@ -632,7 +632,7 @@ library LockedBankVaultsLibrary {
function clearCooldowns(
uint _clanId,
uint[] calldata _otherClanIds,
ClanInfo storage _clanInfo,
VaultClanInfo storage _clanInfo,
mapping(uint clanId => mapping(uint otherClanId => ClanBattleInfo battleInfo)) storage _lastClanBattles
) external {
_clanInfo.attackingCooldownTimestamp = 0;
Expand Down
3 changes: 1 addition & 2 deletions contracts/Clans/Territories.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ contract Territories is
uint40 attackingCooldownTimestamp;
uint40 assignCombatantsCooldownTimestamp;
bool currentlyAttacking;
uint88 gasPaid;
uint88 gasPaid; // TODO remove in migration
uint40 blockAttacksTimestamp;
uint8 blockAttacksCooldownHours; // Have many hours after blockAttacksTimestamp there is a cooldown for
uint48[] playerIds;
Expand Down Expand Up @@ -328,7 +328,6 @@ contract Territories is
uint40 attackingCooldownTimestamp = uint40(block.timestamp + TERRITORY_ATTACKED_COOLDOWN_PLAYER);
ClanInfo storage clanInfo = clanInfos[_clanId];
clanInfo.attackingCooldownTimestamp = attackingCooldownTimestamp;
clanInfo.gasPaid = uint88(msg.value);

clanInfo.currentlyAttacking = true;

Expand Down
4 changes: 2 additions & 2 deletions contracts/globals/clans.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ struct Vault {
uint80 amount1;
}

struct ClanInfo {
struct VaultClanInfo {
IBank bank;
uint96 totalBrushLocked;
// New storage slot
uint40 attackingCooldownTimestamp;
uint40 assignCombatantsCooldownTimestamp;
bool currentlyAttacking;
uint88 gasPaid;
uint88 gasPaid; // TODO remove in migration
uint24 defendingVaultsOffset;
uint40 blockAttacksTimestamp;
uint8 blockAttacksCooldownHours;
Expand Down
2 changes: 1 addition & 1 deletion data/abi/LockedBankVaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@
"type": "uint40"
}
],
"internalType": "struct ClanInfo",
"internalType": "struct VaultClanInfo",
"name": "",
"type": "tuple"
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/addActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ async function main() {

const world = (await ethers.getContractAt("World", WORLD_ADDRESS)).connect(owner) as World;

const _actions = new Set([EstforConstants.ACTION_COMBAT_NIGHTMARE_NATUOW]);
const actions = allActions.filter((action) => _actions.has(action.actionId));
const actionIds = new Set([EstforConstants.ACTION_COMBAT_NIGHTMARE_NATUOW]);
const actions = allActions.filter((action) => actionIds.has(action.actionId));

if (actions.length !== _actions.size) {
if (actions.length !== actionIds.size) {
console.log("Cannot find actions");
} else {
const tx = await world.connect(owner).addActions(actions);
Expand Down
2 changes: 1 addition & 1 deletion scripts/data/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,7 @@ export const allActions: ActionInput[] = [
actionId: EstforConstants.ACTION_COMBAT_NIGHTMARE_NATUOW,
info: {
skill: Skill.COMBAT,
isAvailable: true,
isAvailable: false,
isDynamic: false,
actionChoiceRequired: true,
xpPerHour: 250,
Expand Down
6 changes: 3 additions & 3 deletions scripts/editActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ async function main() {
await tx.wait();
*/

const _actions = new Set([
const actionIds = new Set([
EstforConstants.ACTION_COMBAT_QUARTZ_EAGLE,
EstforConstants.ACTION_COMBAT_ELEMENTAL_DRAGON,
EstforConstants.ACTION_COMBAT_ERKAD,
EstforConstants.ACTION_THIEVING_NEST,
]);
const actions = allActions.filter((action) => _actions.has(action.actionId));
const actions = allActions.filter((action) => actionIds.has(action.actionId));

if (actions.length !== _actions.size) {
if (actions.length !== actionIds.size) {
console.log("Cannot find actions");
} else {
const tx = await world.editActions(actions);
Expand Down
82 changes: 61 additions & 21 deletions scripts/setAvailable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import {ethers} from "hardhat";
import {INSTANT_VRF_ACTIONS_ADDRESS, PASSIVE_ACTIONS_ADDRESS} from "./contractAddresses";
import {InstantVRFActions, PassiveActions} from "../typechain-types";
import {allPassiveActions} from "./data/passiveActions";
import {allInstantVRFActions} from "./data/instantVRFActions";
import {
INSTANT_ACTIONS_ADDRESS,
INSTANT_VRF_ACTIONS_ADDRESS,
PASSIVE_ACTIONS_ADDRESS,
WORLD_ADDRESS,
} from "./contractAddresses";
import {InstantActions, InstantVRFActions, PassiveActions, World} from "../typechain-types";
import {EstforConstants} from "@paintswap/estfor-definitions";
import {InstantActionType} from "@paintswap/estfor-definitions/types";
import {allActions} from "./data/actions";

async function main() {
const [owner] = await ethers.getSigners();
Expand All @@ -12,34 +18,68 @@ async function main() {
} on chain id ${await owner.getChainId()}`
);

const isAvailable = true;
const isAvailable = false;
// DONE
const world = (await ethers.getContractAt("World", WORLD_ADDRESS)).connect(owner) as World;

const actionIds = new Set([EstforConstants.ACTION_COMBAT_NIGHTMARE_NATUOW]);
const actions = allActions.filter((action) => actionIds.has(action.actionId));

if (actions.length !== actionIds.size) {
console.log("Cannot find actions");
return;
} else {
const tx = await world.editActions(actions);
await tx.wait();
console.log("Edit available actions");
}

// Passive actions
// TODO: Don't remove these yet, wait a few months
const passiveActions = (await ethers.getContractAt("PassiveActions", PASSIVE_ACTIONS_ADDRESS)).connect(
owner
) as PassiveActions;

const passiveActionIds = allPassiveActions.map((passiveAction) => {
return passiveAction.actionId;
});
if (passiveActionIds.length !== allPassiveActions.length) {
console.log("Cannot find actions");
} else {
await passiveActions.setAvailable(passiveActionIds, isAvailable);
}
const passiveActionIdsToRemove = [EstforConstants.PASSIVE_ACTION_ANNIV1_EGG_TIER4];
let tx = await passiveActions.setAvailable(passiveActionIdsToRemove, isAvailable);
await tx.wait();
console.log("Set available passive actions");

// Instant VRF actions
// TODO: Don't remove these yet, wait a few months
const instantVRFActionIds = [
EstforConstants.INSTANT_VRF_ACTION_ANNIV1_EGG_TIER1,
EstforConstants.INSTANT_VRF_ACTION_ANNIV1_EGG_TIER2,
EstforConstants.INSTANT_VRF_ACTION_ANNIV1_EGG_TIER3,
EstforConstants.INSTANT_VRF_ACTION_ANNIV1_EGG_TIER4,
EstforConstants.INSTANT_VRF_ACTION_ANNIV1_EGG_TIER5,
EstforConstants.INSTANT_VRF_ACTION_THIEVING_ANNIV1_CHEST,
];

const instantVRFActions = (await ethers.getContractAt("InstantVRFActions", INSTANT_VRF_ACTIONS_ADDRESS)).connect(
owner
) as InstantVRFActions;
tx = await instantVRFActions.setAvailable(instantVRFActionIds, isAvailable);
await tx.wait();
console.log("Set available instant VRF actions");

const instantVRFActionIds = allInstantVRFActions.map((instantVRFAction) => {
return instantVRFAction.actionId;
});
if (instantVRFActionIds.length !== allInstantVRFActions.length) {
console.log("Cannot find actions");
} else {
await instantVRFActions.setAvailable(instantVRFActionIds, isAvailable);
}
// Instant Actions (DONE)
const instantActionIds = [
EstforConstants.INSTANT_ACTION_FORGING_ANNIV1_CHEST,
EstforConstants.INSTANT_ACTION_FORGING_ANNIV1_EGG_TIER1,
EstforConstants.INSTANT_ACTION_FORGING_ANNIV1_KEY,
EstforConstants.INSTANT_ACTION_FORGING_ANNIV1_RING,
];
const instantActions = (await ethers.getContractAt("InstantActions", INSTANT_ACTIONS_ADDRESS)).connect(
owner
) as InstantActions;

tx = await instantActions.removeActions(
[InstantActionType.GENERIC, InstantActionType.GENERIC, InstantActionType.GENERIC, InstantActionType.GENERIC],
instantActionIds
);
await tx.wait();
console.log("Set available instant actions");
}

main().catch((error) => {
Expand Down
Loading