mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 01:15:52 +01:00
Read Open States from Excels (#1557)
* Make sure we never access PlayerOpenStateManager::map directly. * Read OpenStates from excels. * Add defaultState * Replace hardcoded open states with the ones read from excels. * Don't send change notify when unlocking on login. * Add open state blacklist for default unlocks. * Add a way to temporarily set open states for dev * Remove old OpenState.java * Fix UnlockAllCommand * Change condType to an enum.
This commit is contained in:
@@ -9,6 +9,7 @@ import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.tower.TowerLevelRecord;
|
||||
import emu.grasscutter.server.packet.send.PacketOpenStateChangeNotify;
|
||||
|
||||
@Command(label = "setProp", aliases = {"prop"}, usage = {"<prop> <value>"}, permission = "player.setprop", permissionTargeted = "player.setprop.others")
|
||||
public final class SetPropCommand implements CommandHandler {
|
||||
@@ -19,7 +20,9 @@ public final class SetPropCommand implements CommandHandler {
|
||||
BP_LEVEL,
|
||||
GOD_MODE,
|
||||
NO_STAMINA,
|
||||
UNLIMITED_ENERGY
|
||||
UNLIMITED_ENERGY,
|
||||
SET_OPENSTATE,
|
||||
UNSET_OPENSTATE
|
||||
}
|
||||
|
||||
static class Prop {
|
||||
@@ -90,6 +93,14 @@ public final class SetPropCommand implements CommandHandler {
|
||||
Prop unlimitedenergy = new Prop("unlimitedenergy", PseudoProp.UNLIMITED_ENERGY);
|
||||
this.props.put("unlimitedenergy", unlimitedenergy);
|
||||
this.props.put("ue", unlimitedenergy);
|
||||
|
||||
Prop setopenstate = new Prop("setopenstate", PseudoProp.SET_OPENSTATE);
|
||||
this.props.put("setopenstate", setopenstate);
|
||||
this.props.put("so", setopenstate);
|
||||
|
||||
Prop unsetopenstate = new Prop("unsetopenstate", PseudoProp.UNSET_OPENSTATE);
|
||||
this.props.put("unsetopenstate", unsetopenstate);
|
||||
this.props.put("uo", unsetopenstate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,6 +137,8 @@ public final class SetPropCommand implements CommandHandler {
|
||||
case BP_LEVEL -> targetPlayer.getBattlePassManager().setLevel(value);
|
||||
case TOWER_LEVEL -> this.setTowerLevel(sender, targetPlayer, value);
|
||||
case GOD_MODE, NO_STAMINA, UNLIMITED_ENERGY -> this.setBool(sender, targetPlayer, prop.pseudoProp, value);
|
||||
case SET_OPENSTATE -> this.setOpenState(targetPlayer, value, 1);
|
||||
case UNSET_OPENSTATE -> this.setOpenState(targetPlayer, value, 0);
|
||||
default -> targetPlayer.setProperty(prop.prop, value);
|
||||
};
|
||||
|
||||
@@ -202,4 +215,9 @@ public final class SetPropCommand implements CommandHandler {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setOpenState(Player targetPlayer, int state, int value) {
|
||||
targetPlayer.sendPacket(new PacketOpenStateChangeNotify(state, value));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package emu.grasscutter.command.commands;
|
||||
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.OpenState;
|
||||
import emu.grasscutter.game.player.PlayerOpenStateManager;
|
||||
import emu.grasscutter.server.packet.send.PacketOpenStateChangeNotify;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -18,13 +19,16 @@ public final class UnlockAllCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
Map<Integer, Integer> changed = new HashMap<>();
|
||||
|
||||
for (OpenState state : OpenState.values()) {
|
||||
if (state == OpenState.OPEN_STATE_NONE || state == OpenState.OPEN_STATE_LIMIT_REGION_GLOBAL) continue;
|
||||
|
||||
if (targetPlayer.getOpenStateManager().getOpenStateMap().getOrDefault(state.getValue(), 0) == 0) {
|
||||
targetPlayer.getOpenStateManager().getOpenStateMap().put(state.getValue(), 1);
|
||||
changed.put(state.getValue(), 1);
|
||||
|
||||
for (var state : GameData.getOpenStateList()) {
|
||||
// Don't unlock blacklisted open states.
|
||||
if (PlayerOpenStateManager.BLACKLIST_OPEN_STATES.contains(state.getId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (targetPlayer.getOpenStateManager().getOpenState(state.getId()) == 0) {
|
||||
targetPlayer.getOpenStateManager().getOpenStateMap().put(state.getId(), 1);
|
||||
changed.put(state.getId(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user