mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 22:03:03 +08:00
Update OpenState protos and rework OpenStateManager
OpenState map no longer contains default openstates, they should not be saved in the database for efficiency reasons.
This commit is contained in:
parent
3eb9a44e51
commit
2e85834e9c
@ -17,9 +17,11 @@ import static emu.grasscutter.game.props.OpenState.*;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class PlayerOpenStateManager {
|
public class PlayerOpenStateManager {
|
||||||
|
|
||||||
@Transient private Player player;
|
@Transient private Player player;
|
||||||
@Getter private Map<Integer,Integer> openStateMap;
|
|
||||||
|
// Map of all open states that this player has. Do not put default values here.
|
||||||
|
private Map<Integer, Integer> map;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//DO NOT MODIFY. Based on conversation of official server and client, game version 2.7
|
//DO NOT MODIFY. Based on conversation of official server and client, game version 2.7
|
||||||
private static Set<OpenState> newPlayerOpenStates = Set.of(OPEN_STATE_DERIVATIVE_MALL,OPEN_STATE_PHOTOGRAPH,OPEN_STATE_BATTLE_PASS,OPEN_STATE_SHOP_TYPE_GENESISCRYSTAL,OPEN_STATE_SHOP_TYPE_RECOMMANDED,
|
private static Set<OpenState> newPlayerOpenStates = Set.of(OPEN_STATE_DERIVATIVE_MALL,OPEN_STATE_PHOTOGRAPH,OPEN_STATE_BATTLE_PASS,OPEN_STATE_SHOP_TYPE_GENESISCRYSTAL,OPEN_STATE_SHOP_TYPE_RECOMMANDED,
|
||||||
@ -27,8 +29,10 @@ public class PlayerOpenStateManager {
|
|||||||
OPEN_STATE_WEAPON_PROMOTE,OPEN_STATE_AVATAR_PROMOTE,OPEN_STATE_AVATAR_TALENT,OPEN_STATE_WEAPON_UPGRADE,OPEN_STATE_RESIN,OPEN_STATE_RELIQUARY_UPGRADE,
|
OPEN_STATE_WEAPON_PROMOTE,OPEN_STATE_AVATAR_PROMOTE,OPEN_STATE_AVATAR_TALENT,OPEN_STATE_WEAPON_UPGRADE,OPEN_STATE_RESIN,OPEN_STATE_RELIQUARY_UPGRADE,
|
||||||
OPEN_STATE_SHOP_TYPE_VIRTUAL_SHOP,OPEN_STATE_RELIQUARY_PROMOTE);
|
OPEN_STATE_SHOP_TYPE_VIRTUAL_SHOP,OPEN_STATE_RELIQUARY_PROMOTE);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// For development. Remove entry when properly implemented
|
// For development. Remove entry when properly implemented
|
||||||
private static Set<OpenState> devOpenStates = Set.of(
|
// TODO - Set as boolean in OpenState
|
||||||
|
public static final Set<OpenState> DEV_OPEN_STATES = Set.of(
|
||||||
OPEN_STATE_PAIMON,
|
OPEN_STATE_PAIMON,
|
||||||
OPEN_STATE_PAIMON_NAVIGATION,
|
OPEN_STATE_PAIMON_NAVIGATION,
|
||||||
OPEN_STATE_AVATAR_PROMOTE,
|
OPEN_STATE_AVATAR_PROMOTE,
|
||||||
@ -75,7 +79,6 @@ public class PlayerOpenStateManager {
|
|||||||
OPEN_STATE_TOWER_FIRST_ENTER,
|
OPEN_STATE_TOWER_FIRST_ENTER,
|
||||||
OPEN_STATE_RESIN,
|
OPEN_STATE_RESIN,
|
||||||
OPEN_STATE_LIMIT_REGION_FRESHMEAT,
|
OPEN_STATE_LIMIT_REGION_FRESHMEAT,
|
||||||
OPEN_STATE_LIMIT_REGION_GLOBAL,
|
|
||||||
OPEN_STATE_MULTIPLAYER,
|
OPEN_STATE_MULTIPLAYER,
|
||||||
OPEN_STATE_GUIDE_MOUSEPC,
|
OPEN_STATE_GUIDE_MOUSEPC,
|
||||||
OPEN_STATE_GUIDE_MULTIPLAYER,
|
OPEN_STATE_GUIDE_MULTIPLAYER,
|
||||||
@ -114,7 +117,7 @@ public class PlayerOpenStateManager {
|
|||||||
OPEN_STATE_GUIDE_RELICRESOLVE,
|
OPEN_STATE_GUIDE_RELICRESOLVE,
|
||||||
OPEN_STATE_GUIDE_GGUIDE,
|
OPEN_STATE_GUIDE_GGUIDE,
|
||||||
OPEN_STATE_GUIDE_GGUIDE_HINT,
|
OPEN_STATE_GUIDE_GGUIDE_HINT,
|
||||||
OPEN_STATE_GUIDE_RIGHT_TEAM, // mobile phone only!
|
OPEN_STATE_GUIDE_QUICK_TEAMMEMBERCHANGE,
|
||||||
OPEN_STATE_CITY_REPUATION_MENGDE,
|
OPEN_STATE_CITY_REPUATION_MENGDE,
|
||||||
OPEN_STATE_CITY_REPUATION_LIYUE,
|
OPEN_STATE_CITY_REPUATION_LIYUE,
|
||||||
OPEN_STATE_CITY_REPUATION_UI_HINT,
|
OPEN_STATE_CITY_REPUATION_UI_HINT,
|
||||||
@ -198,7 +201,6 @@ public class PlayerOpenStateManager {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public PlayerOpenStateManager(Player player) {
|
public PlayerOpenStateManager(Player player) {
|
||||||
this.openStateMap = new HashMap<>();
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,13 +208,19 @@ public class PlayerOpenStateManager {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getOpenState(OpenState openState) {
|
public Map<Integer, Integer> getOpenStateMap() {
|
||||||
return this.openStateMap.getOrDefault(openState.getValue(), 0);
|
if (this.map == null) this.map = new HashMap<>();
|
||||||
|
return this.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getOpenState(OpenState openState) {
|
||||||
|
return this.map.getOrDefault(openState.getValue(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
public void setOpenState(OpenState openState, Integer value) {
|
public void setOpenState(OpenState openState, Integer value) {
|
||||||
Integer previousValue = this.openStateMap.getOrDefault(openState.getValue(),0);
|
Integer previousValue = this.map.getOrDefault(openState.getValue(),0);
|
||||||
if(!(value == previousValue)) {
|
if(!(value == previousValue)) {
|
||||||
this.openStateMap.put(openState.getValue(), value);
|
this.map.put(openState.getValue(), value);
|
||||||
player.getSession().send(new PacketOpenStateChangeNotify(openState.getValue(),value));
|
player.getSession().send(new PacketOpenStateChangeNotify(openState.getValue(),value));
|
||||||
} else {
|
} else {
|
||||||
Grasscutter.getLogger().debug("Warning: OpenState {} is already set to {}!", openState, value);
|
Grasscutter.getLogger().debug("Warning: OpenState {} is already set to {}!", openState, value);
|
||||||
@ -225,22 +233,7 @@ public class PlayerOpenStateManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNewPlayerCreate() {
|
|
||||||
//newPlayerOpenStates.forEach(os -> this.setOpenState(os, 1));
|
|
||||||
//setAllOpenStates();
|
|
||||||
devOpenStates.forEach(os -> this.setOpenState(os, 1));
|
|
||||||
}
|
|
||||||
public void onPlayerLogin() {
|
public void onPlayerLogin() {
|
||||||
/*
|
player.getSession().send(new PacketOpenStateUpdateNotify(this));
|
||||||
//little hack to give all openStates on second login
|
|
||||||
if(openStateMap.containsKey(OPEN_STATE_FRESHMAN_GUIDE.getValue())) {
|
|
||||||
setAllOpenStates();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
player.getSession().send(new PacketOpenStateUpdateNotify(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllOpenStates() {
|
|
||||||
Stream.of(OpenState.values()).forEach(os -> this.setOpenState(os, 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -94,7 +94,12 @@ public enum OpenState {
|
|||||||
OPEN_STATE_GUIDE_RELICRESOLVE (84),
|
OPEN_STATE_GUIDE_RELICRESOLVE (84),
|
||||||
OPEN_STATE_GUIDE_GGUIDE (85),
|
OPEN_STATE_GUIDE_GGUIDE (85),
|
||||||
OPEN_STATE_GUIDE_GGUIDE_HINT (86),
|
OPEN_STATE_GUIDE_GGUIDE_HINT (86),
|
||||||
OPEN_STATE_GUIDE_RIGHT_TEAM(90), // mobile phone only!
|
OPEN_STATE_GUIDE_CHANNELLERSLAB_EQUIP_V2 (87),
|
||||||
|
OPEN_STATE_GUIDE_CHANNELLERSLAB_MP_SOLUTION_V2 (88),
|
||||||
|
OPEN_STATE_GUIDE_CHANNELLERSLAB_POWER_V2 (89),
|
||||||
|
OPEN_STATE_GUIDE_QUICK_TEAMMEMBERCHANGE (90), // Mobile only
|
||||||
|
OPEN_STATE_GGUIDE_FIRSTSHOW (91),
|
||||||
|
OPEN_STATE_GGUIDE_MAINPAGE_ENTRY_DISAPPEAR (92),
|
||||||
OPEN_STATE_CITY_REPUATION_MENGDE (800),
|
OPEN_STATE_CITY_REPUATION_MENGDE (800),
|
||||||
OPEN_STATE_CITY_REPUATION_LIYUE (801),
|
OPEN_STATE_CITY_REPUATION_LIYUE (801),
|
||||||
OPEN_STATE_CITY_REPUATION_UI_HINT (802),
|
OPEN_STATE_CITY_REPUATION_UI_HINT (802),
|
||||||
@ -115,6 +120,7 @@ public enum OpenState {
|
|||||||
OPEN_STATE_SHOP_TYPE_LIYUE_RESTAURANT (1010),
|
OPEN_STATE_SHOP_TYPE_LIYUE_RESTAURANT (1010),
|
||||||
OPEN_STATE_SHOP_TYPE_INAZUMA_SOUVENIR (1011),
|
OPEN_STATE_SHOP_TYPE_INAZUMA_SOUVENIR (1011),
|
||||||
OPEN_STATE_SHOP_TYPE_NPC_TOMOKI (1012),
|
OPEN_STATE_SHOP_TYPE_NPC_TOMOKI (1012),
|
||||||
|
OPEN_STATE_SHOP_TYPE_INAZUMA_SOUVENIR_BLACK_BAR (1013),
|
||||||
OPEN_ADVENTURE_MANUAL (1100),
|
OPEN_ADVENTURE_MANUAL (1100),
|
||||||
OPEN_ADVENTURE_MANUAL_CITY_MENGDE (1101),
|
OPEN_ADVENTURE_MANUAL_CITY_MENGDE (1101),
|
||||||
OPEN_ADVENTURE_MANUAL_CITY_LIYUE (1102),
|
OPEN_ADVENTURE_MANUAL_CITY_LIYUE (1102),
|
||||||
@ -174,7 +180,14 @@ public enum OpenState {
|
|||||||
OPEN_STATE_MICHIAE_CASKET (2500),
|
OPEN_STATE_MICHIAE_CASKET (2500),
|
||||||
OPEN_STATE_MAIL_COLLECT_UNLOCK_RED_POINT (2501),
|
OPEN_STATE_MAIL_COLLECT_UNLOCK_RED_POINT (2501),
|
||||||
OPEN_STATE_LUMEN_STONE (2600),
|
OPEN_STATE_LUMEN_STONE (2600),
|
||||||
OPEN_STATE_GUIDE_CRYSTALLINK_BUFF(2601);
|
OPEN_STATE_GUIDE_CRYSTALLINK_BUFF (2601),
|
||||||
|
OPEN_STATE_GUIDE_MUSIC_GAME_V3 (2700),
|
||||||
|
OPEN_STATE_GUIDE_MUSIC_GAME_V3_REAL_TIME_EDIT (2701),
|
||||||
|
OPEN_STATE_GUIDE_MUSIC_GAME_V3_TIMELINE_EDIT (2702),
|
||||||
|
OPEN_STATE_GUIDE_MUSIC_GAME_V3_SETTING (2703),
|
||||||
|
OPEN_STATE_GUIDE_ROBOTGACHA (2704),
|
||||||
|
OPEN_STATE_GUIDE_FRAGILE_RESIN (2800),
|
||||||
|
OPEN_ADVENTURE_MANUAL_EDUCATION (2801);
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
private static final Int2ObjectMap<OpenState> map = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<OpenState> map = new Int2ObjectOpenHashMap<>();
|
||||||
|
@ -40,8 +40,6 @@ public class HandlerPlayerLoginReq extends PacketHandler {
|
|||||||
|
|
||||||
// Show opening cutscene if player has no avatars
|
// Show opening cutscene if player has no avatars
|
||||||
if (player.getAvatars().getAvatarCount() == 0) {
|
if (player.getAvatars().getAvatarCount() == 0) {
|
||||||
// Set New Player OpenStates
|
|
||||||
player.getOpenStateManager().onNewPlayerCreate();
|
|
||||||
// Pick character
|
// Pick character
|
||||||
session.setState(SessionState.PICKING_CHARACTER);
|
session.setState(SessionState.PICKING_CHARACTER);
|
||||||
session.send(new BasePacket(PacketOpcodes.DoSetPlayerBornDataNotify));
|
session.send(new BasePacket(PacketOpcodes.DoSetPlayerBornDataNotify));
|
||||||
|
@ -1,25 +1,31 @@
|
|||||||
package emu.grasscutter.server.packet.send;
|
package emu.grasscutter.server.packet.send;
|
||||||
|
|
||||||
import emu.grasscutter.game.player.Player;
|
|
||||||
import emu.grasscutter.game.player.PlayerOpenStateManager;
|
import emu.grasscutter.game.player.PlayerOpenStateManager;
|
||||||
import emu.grasscutter.game.props.OpenState;
|
import emu.grasscutter.game.props.OpenState;
|
||||||
import emu.grasscutter.net.packet.BasePacket;
|
import emu.grasscutter.net.packet.BasePacket;
|
||||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
import emu.grasscutter.net.proto.OpenStateUpdateNotifyOuterClass.OpenStateUpdateNotify;
|
import emu.grasscutter.net.proto.OpenStateUpdateNotifyOuterClass.OpenStateUpdateNotify;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
/*
|
/*
|
||||||
Must be sent on login for openStates to work
|
Must be sent on login for openStates to work
|
||||||
Tells the client to update its openStateMap for the keys sent. value is irrelevant
|
Tells the client to update its openStateMap for the keys sent. value is irrelevant
|
||||||
*/
|
*/
|
||||||
public class PacketOpenStateUpdateNotify extends BasePacket {
|
public class PacketOpenStateUpdateNotify extends BasePacket {
|
||||||
|
|
||||||
public PacketOpenStateUpdateNotify(Player player) {
|
public PacketOpenStateUpdateNotify(PlayerOpenStateManager manager) {
|
||||||
super(PacketOpcodes.OpenStateUpdateNotify);
|
super(PacketOpcodes.OpenStateUpdateNotify);
|
||||||
|
|
||||||
OpenStateUpdateNotify.Builder proto = OpenStateUpdateNotify.newBuilder();
|
OpenStateUpdateNotify.Builder proto = OpenStateUpdateNotify.newBuilder();
|
||||||
|
|
||||||
proto.putAllOpenStateMap(player.getOpenStateManager().getOpenStateMap()).build();
|
for (OpenState state : OpenState.values()) {
|
||||||
|
// If the player has an open state stored in their map, then it would always override any default value
|
||||||
|
if (manager.getOpenStateMap().containsKey(state.getValue())) {
|
||||||
|
proto.putOpenStateMap(state.getValue(), manager.getOpenState(state));
|
||||||
|
} else if (PlayerOpenStateManager.DEV_OPEN_STATES.contains(state)) {
|
||||||
|
// Add default value here. TODO properly put default values somewhere
|
||||||
|
proto.putOpenStateMap(state.getValue(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.setData(proto);
|
this.setData(proto);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user