mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 07:37:43 +00:00
Refactoring (#1660)
* Refactor a couple of iterators * Use side-effect instead of second iterator * Make World::onTick return shouldDelete instead of success * Replace Shop iterator with side effects * Scene * Clean up Expeditions * Refactor Expeditions * Clean up Expeditions, Player * Limit Expeditions by AR * Lombokify props Co-authored-by: AnimeGitB <AnimeGitB@bigblueball.in>
This commit is contained in:
parent
bccf516ca7
commit
dc9cef8ab7
@ -2,32 +2,20 @@ package emu.grasscutter.data.excels;
|
||||
|
||||
import emu.grasscutter.data.GameResource;
|
||||
import emu.grasscutter.data.ResourceType;
|
||||
import lombok.Getter;
|
||||
|
||||
@ResourceType(name = "PlayerLevelExcelConfigData.json")
|
||||
@Getter
|
||||
public class PlayerLevelData extends GameResource {
|
||||
private int level;
|
||||
private int exp;
|
||||
private int rewardId;
|
||||
private int expeditionLimitAdd = 0;
|
||||
private int unlockWorldLevel;
|
||||
|
||||
private long unlockDescTextMapHash;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public int getExp() {
|
||||
return exp;
|
||||
}
|
||||
|
||||
public int getRewardId() {
|
||||
return rewardId;
|
||||
}
|
||||
|
||||
public int getUnlockWorldLevel() {
|
||||
return unlockWorldLevel;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,24 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter @Setter
|
||||
public class ExpeditionInfo {
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getExpId() {
|
||||
return expId;
|
||||
}
|
||||
|
||||
public void setExpId(int expId) {
|
||||
this.expId = expId;
|
||||
}
|
||||
|
||||
public int getHourTime() {
|
||||
return hourTime;
|
||||
}
|
||||
|
||||
public void setHourTime(int hourTime) {
|
||||
this.hourTime = hourTime;
|
||||
}
|
||||
|
||||
public int getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(int startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
private int state;
|
||||
private int expId;
|
||||
private int hourTime;
|
||||
private int startTime;
|
||||
|
||||
public AvatarExpeditionInfo toProto() {
|
||||
return AvatarExpeditionInfo.newBuilder()
|
||||
.setStateValue(this.getState())
|
||||
.setExpId(this.getExpId())
|
||||
.setHourTime(this.getHourTime())
|
||||
.setStartTime(this.getStartTime())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,15 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
import emu.grasscutter.game.inventory.GameItem;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import lombok.Getter;
|
||||
|
||||
public class ExpeditionRewardData {
|
||||
private int itemId;
|
||||
private int minCount;
|
||||
private int maxCount;
|
||||
@Getter private int itemId;
|
||||
@Getter private int minCount;
|
||||
@Getter private int maxCount;
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
public GameItem getReward() {
|
||||
return new GameItem(itemId, Utils.randomRange(minCount, maxCount));
|
||||
}
|
||||
|
||||
public int getMinCount() { return minCount; }
|
||||
|
||||
public int getMaxCount() {
|
||||
return maxCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,20 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ExpeditionRewardDataList {
|
||||
public int getHourTime() {
|
||||
return hourTime;
|
||||
}
|
||||
public List<ExpeditionRewardData> getExpeditionRewardData() {
|
||||
return expeditionRewardData;
|
||||
}
|
||||
import emu.grasscutter.game.inventory.GameItem;
|
||||
import lombok.Getter;
|
||||
|
||||
private int hourTime;
|
||||
private List<ExpeditionRewardData> expeditionRewardData;
|
||||
public class ExpeditionRewardDataList {
|
||||
@Getter private int hourTime;
|
||||
@Getter private List<ExpeditionRewardData> expeditionRewardData;
|
||||
|
||||
public List<GameItem> getRewards() {
|
||||
List<GameItem> rewards = new ArrayList<>();
|
||||
if (expeditionRewardData != null) {
|
||||
expeditionRewardData.forEach(data -> rewards.add(data.getReward()));
|
||||
}
|
||||
return rewards;
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,9 @@ package emu.grasscutter.game.expedition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class ExpeditionRewardInfo {
|
||||
public int getExpId() {
|
||||
return expId;
|
||||
}
|
||||
|
||||
public List<ExpeditionRewardDataList> getExpeditionRewardDataList() {
|
||||
return expeditionRewardDataList;
|
||||
}
|
||||
|
||||
private int expId;
|
||||
private List<ExpeditionRewardDataList> expeditionRewardDataList;
|
||||
@Getter private int expId;
|
||||
@Getter private List<ExpeditionRewardDataList> expeditionRewardDataList;
|
||||
}
|
||||
|
@ -88,33 +88,33 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
public class Player {
|
||||
@Id private int id;
|
||||
@Indexed(options = @IndexOptions(unique = true)) private String accountId;
|
||||
private transient Account account;
|
||||
private transient GameSession session;
|
||||
@Setter private transient Account account;
|
||||
@Getter @Setter private transient GameSession session;
|
||||
|
||||
private String nickname;
|
||||
private String signature;
|
||||
private int headImage;
|
||||
private int nameCardId = 210001;
|
||||
private Position position;
|
||||
private Position rotation;
|
||||
private PlayerBirthday birthday;
|
||||
private PlayerCodex codex;
|
||||
private boolean showAvatars;
|
||||
private List<Integer> showAvatarList;
|
||||
private Map<Integer, Integer> properties;
|
||||
private int currentRealmId;
|
||||
private int widgetId;
|
||||
private int sceneId;
|
||||
private int regionId;
|
||||
private int mainCharacterId;
|
||||
private boolean godmode;
|
||||
private boolean stamina;
|
||||
@Getter private String nickname;
|
||||
@Getter private String signature;
|
||||
@Getter private int headImage;
|
||||
@Getter private int nameCardId = 210001;
|
||||
@Getter private Position position;
|
||||
@Getter private Position rotation;
|
||||
@Getter private PlayerBirthday birthday;
|
||||
@Getter private PlayerCodex codex;
|
||||
@Getter @Setter private boolean showAvatars;
|
||||
@Getter @Setter private List<Integer> showAvatarList;
|
||||
@Getter private Map<Integer, Integer> properties;
|
||||
@Getter @Setter private int currentRealmId;
|
||||
@Getter @Setter private int widgetId;
|
||||
@Getter @Setter private int sceneId;
|
||||
@Getter @Setter private int regionId;
|
||||
@Getter private int mainCharacterId;
|
||||
@Setter private boolean godmode; // Getter is inGodmode
|
||||
private boolean stamina; // Getter is getUnlimitedStamina, Setter is setUnlimitedStamina
|
||||
|
||||
@Getter private Set<Integer> nameCardList;
|
||||
@Getter private Set<Integer> flyCloakList;
|
||||
@Getter private Set<Integer> costumeList;
|
||||
@Getter private Set<Integer> rewardedLevels;
|
||||
@Getter private Set<Integer> realmList;
|
||||
@Getter @Setter private Set<Integer> realmList;
|
||||
@Getter private Set<Integer> unlockedForgingBlueprints;
|
||||
@Getter private Set<Integer> unlockedCombines;
|
||||
@Getter private Set<Integer> unlockedFurniture;
|
||||
@ -128,9 +128,9 @@ public class Player {
|
||||
@Getter @Setter private Map<Integer, List<Integer>> unlockedScenePoints;
|
||||
|
||||
@Transient private long nextGuid = 0;
|
||||
@Transient private int peerId;
|
||||
@Transient private World world;
|
||||
@Transient private Scene scene;
|
||||
@Transient @Getter @Setter private int peerId;
|
||||
@Transient private World world; // Synchronized getter and setter
|
||||
@Transient private Scene scene; // Synchronized getter and setter
|
||||
@Transient @Getter private int weatherId = 0;
|
||||
@Transient @Getter private ClimateType climate = ClimateType.CLIMATE_SUNNY;
|
||||
|
||||
@ -139,9 +139,9 @@ public class Player {
|
||||
@Getter private transient Inventory inventory;
|
||||
@Getter private transient FriendsList friendsList;
|
||||
@Getter private transient MailHandler mailHandler;
|
||||
@Getter private transient MessageHandler messageHandler;
|
||||
@Getter @Setter private transient MessageHandler messageHandler;
|
||||
@Getter private transient AbilityManager abilityManager;
|
||||
@Getter private transient QuestManager questManager;
|
||||
@Getter @Setter private transient QuestManager questManager;
|
||||
@Getter private transient TowerManager towerManager;
|
||||
@Getter private transient SotSManager sotsManager;
|
||||
@Getter private transient MapMarksManager mapMarksManager;
|
||||
@ -158,36 +158,37 @@ public class Player {
|
||||
@Getter private transient PlayerProgressManager progressManager;
|
||||
|
||||
// Manager data (Save-able to the database)
|
||||
private PlayerProfile playerProfile;
|
||||
private TeamManager teamManager;
|
||||
private TowerData towerData;
|
||||
private PlayerGachaInfo gachaInfo;
|
||||
private PlayerCollectionRecords collectionRecordStore;
|
||||
private ArrayList<ShopLimit> shopLimit;
|
||||
private PlayerProfile playerProfile; // Getter has null-check
|
||||
@Getter private TeamManager teamManager;
|
||||
private TowerData towerData; // Getter has null-check
|
||||
@Getter private PlayerGachaInfo gachaInfo;
|
||||
private PlayerCollectionRecords collectionRecordStore; // Getter has null-check
|
||||
@Getter private ArrayList<ShopLimit> shopLimit;
|
||||
|
||||
@Getter private transient GameHome home;
|
||||
|
||||
private boolean moonCard;
|
||||
private Date moonCardStartTime;
|
||||
private int moonCardDuration;
|
||||
private Set<Date> moonCardGetTimes;
|
||||
@Setter private boolean moonCard; // Getter is inMoonCard
|
||||
@Getter @Setter private Date moonCardStartTime;
|
||||
@Getter @Setter private int moonCardDuration;
|
||||
@Getter @Setter private Set<Date> moonCardGetTimes;
|
||||
|
||||
@Transient private boolean paused;
|
||||
@Transient private int enterSceneToken;
|
||||
@Transient private SceneLoadState sceneState;
|
||||
@Transient @Getter private boolean paused;
|
||||
@Transient @Getter @Setter private int enterSceneToken;
|
||||
@Transient @Getter @Setter private SceneLoadState sceneLoadState = SceneLoadState.NONE;
|
||||
@Transient private boolean hasSentLoginPackets;
|
||||
@Transient private long nextSendPlayerLocTime = 0;
|
||||
|
||||
private transient final Int2ObjectMap<CoopRequest> coopRequests;
|
||||
private transient final Queue<AttackResult> attackResults;
|
||||
private transient final Int2ObjectMap<CoopRequest> coopRequests; // Synchronized getter
|
||||
@Getter private transient final Queue<AttackResult> attackResults;
|
||||
@Getter private transient final InvokeHandler<CombatInvokeEntry> combatInvokeHandler;
|
||||
@Getter private transient final InvokeHandler<AbilityInvokeEntry> abilityInvokeHandler;
|
||||
@Getter private transient final InvokeHandler<AbilityInvokeEntry> clientAbilityInitFinishHandler;
|
||||
|
||||
private long springLastUsed;
|
||||
private HashMap<String, MapMark> mapMarks;
|
||||
private int nextResinRefresh;
|
||||
private int lastDailyReset;
|
||||
@Getter @Setter private long springLastUsed;
|
||||
private HashMap<String, MapMark> mapMarks; // Getter makes an empty hashmap - maybe do this elsewhere?
|
||||
@Getter @Setter private int nextResinRefresh;
|
||||
@Getter @Setter private int lastDailyReset;
|
||||
@Getter private transient MpSettingType mpSetting = MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; // TODO
|
||||
|
||||
@Deprecated
|
||||
@SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only!
|
||||
@ -228,7 +229,6 @@ public class Player {
|
||||
this.openStates = new HashMap<>();
|
||||
this.unlockedSceneAreas = new HashMap<>();
|
||||
this.unlockedScenePoints = new HashMap<>();
|
||||
this.sceneState = SceneLoadState.NONE;
|
||||
|
||||
this.attackResults = new LinkedBlockingQueue<>();
|
||||
this.coopRequests = new Int2ObjectOpenHashMap<>();
|
||||
@ -308,18 +308,6 @@ public class Player {
|
||||
return this.account;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public GameSession getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(GameSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return this.getSession() != null && this.getSession().isActive();
|
||||
}
|
||||
@ -366,45 +354,21 @@ public class Player {
|
||||
this.session.send(new PacketSceneAreaWeatherNotify(this));
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickName) {
|
||||
this.nickname = nickName;
|
||||
this.updateProfile();
|
||||
}
|
||||
|
||||
public int getHeadImage() {
|
||||
return headImage;
|
||||
}
|
||||
|
||||
public void setHeadImage(int picture) {
|
||||
this.headImage = picture;
|
||||
this.updateProfile();
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(String signature) {
|
||||
this.signature = signature;
|
||||
this.updateProfile();
|
||||
}
|
||||
|
||||
public Integer getWidgetId() {
|
||||
return widgetId;
|
||||
}
|
||||
|
||||
public void setWidgetId(Integer widgetId) {
|
||||
this.widgetId = widgetId;
|
||||
}
|
||||
|
||||
public void setRealmList(Set<Integer> realmList) {
|
||||
this.realmList = realmList;
|
||||
}
|
||||
|
||||
public void addRealmList(int realmId) {
|
||||
if (this.realmList == null) {
|
||||
this.realmList = new HashSet<>();
|
||||
@ -414,20 +378,16 @@ public class Player {
|
||||
this.realmList.add(realmId);
|
||||
}
|
||||
|
||||
public int getCurrentRealmId() {
|
||||
return currentRealmId;
|
||||
}
|
||||
|
||||
public void setCurrentRealmId(int currentRealmId) {
|
||||
this.currentRealmId = currentRealmId;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Position getRotation() {
|
||||
return rotation;
|
||||
public int getExpeditionLimit() {
|
||||
final int CONST_VALUE_EXPEDITION_INIT_LIMIT = 2; // TODO: pull from ConstValueExcelConfigData.json
|
||||
int expeditionLimit = CONST_VALUE_EXPEDITION_INIT_LIMIT;
|
||||
var levelMap = GameData.getPlayerLevelDataMap();
|
||||
for (int i = 1; i <= this.getLevel(); i++) { // 1-indexed
|
||||
var data = levelMap.get(i);
|
||||
if (data != null)
|
||||
expeditionLimit += data.getExpeditionLimitAdd();
|
||||
}
|
||||
return expeditionLimit;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
@ -576,10 +536,6 @@ public class Player {
|
||||
return !this.hasSentLoginPackets;
|
||||
}
|
||||
|
||||
public TeamManager getTeamManager() {
|
||||
return this.teamManager;
|
||||
}
|
||||
|
||||
public TowerData getTowerData() {
|
||||
if (towerData == null) {
|
||||
// because of mistake, null may be saved as storage at some machine, this if can be removed in future
|
||||
@ -588,10 +544,6 @@ public class Player {
|
||||
return towerData;
|
||||
}
|
||||
|
||||
public void setQuestManager(QuestManager questManager) {
|
||||
this.questManager = questManager;
|
||||
}
|
||||
|
||||
public void onEnterRegion(SceneRegion region) {
|
||||
getQuestManager().forEachActiveQuest(quest -> {
|
||||
if(quest.getTriggers().containsKey("ENTER_REGION_"+ String.valueOf(region.config_id))) {
|
||||
@ -615,11 +567,7 @@ public class Player {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
public PlayerGachaInfo getGachaInfo() {
|
||||
return gachaInfo;
|
||||
}
|
||||
|
||||
public PlayerProfile getProfile() {
|
||||
if (this.playerProfile == null) {
|
||||
@ -628,12 +576,6 @@ public class Player {
|
||||
return playerProfile;
|
||||
}
|
||||
|
||||
// TODO: Based on the proto, property value could be int or float.
|
||||
// Although there's no float value at this moment, our code should be prepared for float values.
|
||||
public Map<Integer, Integer> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public boolean setProperty(PlayerProperty prop, int value) {
|
||||
return setPropertyWithSanityCheck(prop, value, true);
|
||||
}
|
||||
@ -646,39 +588,15 @@ public class Player {
|
||||
return getProperties().get(prop.getId());
|
||||
}
|
||||
|
||||
public MpSettingType getMpSetting() {
|
||||
return MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; // TEMP
|
||||
}
|
||||
|
||||
public Queue<AttackResult> getAttackResults() {
|
||||
return this.attackResults;
|
||||
}
|
||||
|
||||
public synchronized Int2ObjectMap<CoopRequest> getCoopRequests() {
|
||||
return coopRequests;
|
||||
}
|
||||
|
||||
public int getEnterSceneToken() {
|
||||
return enterSceneToken;
|
||||
}
|
||||
|
||||
public void setEnterSceneToken(int enterSceneToken) {
|
||||
this.enterSceneToken = enterSceneToken;
|
||||
}
|
||||
|
||||
public int getNameCardId() {
|
||||
return nameCardId;
|
||||
}
|
||||
|
||||
public void setNameCardId(int nameCardId) {
|
||||
this.nameCardId = nameCardId;
|
||||
this.updateProfile();
|
||||
}
|
||||
|
||||
public int getMainCharacterId() {
|
||||
return mainCharacterId;
|
||||
}
|
||||
|
||||
public void setMainCharacterId(int mainCharacterId) {
|
||||
if (this.mainCharacterId != 0) {
|
||||
return;
|
||||
@ -686,14 +604,6 @@ public class Player {
|
||||
this.mainCharacterId = mainCharacterId;
|
||||
}
|
||||
|
||||
public int getPeerId() {
|
||||
return peerId;
|
||||
}
|
||||
|
||||
public void setPeerId(int peerId) {
|
||||
this.peerId = peerId;
|
||||
}
|
||||
|
||||
public int getClientTime() {
|
||||
return session.getClientTime();
|
||||
}
|
||||
@ -702,10 +612,6 @@ public class Player {
|
||||
return session.getLastPingTime();
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
|
||||
public void setPaused(boolean newPauseState) {
|
||||
boolean oldPauseState = this.paused;
|
||||
this.paused = newPauseState;
|
||||
@ -717,110 +623,18 @@ public class Player {
|
||||
}
|
||||
}
|
||||
|
||||
public long getSpringLastUsed() {
|
||||
return springLastUsed;
|
||||
}
|
||||
|
||||
public void setSpringLastUsed(long val) {
|
||||
springLastUsed = val;
|
||||
}
|
||||
|
||||
public int getNextResinRefresh() {
|
||||
return nextResinRefresh;
|
||||
}
|
||||
|
||||
public void setNextResinRefresh(int value) {
|
||||
this.nextResinRefresh = value;
|
||||
}
|
||||
|
||||
public SceneLoadState getSceneLoadState() {
|
||||
return sceneState;
|
||||
}
|
||||
|
||||
public void setSceneLoadState(SceneLoadState sceneState) {
|
||||
this.sceneState = sceneState;
|
||||
}
|
||||
|
||||
public boolean isInMultiplayer() {
|
||||
return this.getWorld() != null && this.getWorld().isMultiplayer();
|
||||
}
|
||||
|
||||
public int getSceneId() {
|
||||
return sceneId;
|
||||
}
|
||||
|
||||
public void setSceneId(int sceneId) {
|
||||
this.sceneId = sceneId;
|
||||
}
|
||||
|
||||
public int getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
public void setRegionId(int regionId) {
|
||||
this.regionId = regionId;
|
||||
}
|
||||
|
||||
public void setShowAvatars(boolean showAvatars) {
|
||||
this.showAvatars = showAvatars;
|
||||
}
|
||||
|
||||
public boolean isShowAvatars() {
|
||||
return showAvatars;
|
||||
}
|
||||
|
||||
public void setShowAvatarList(List<Integer> showAvatarList) {
|
||||
this.showAvatarList = showAvatarList;
|
||||
}
|
||||
|
||||
public List<Integer> getShowAvatarList() {
|
||||
return showAvatarList;
|
||||
}
|
||||
|
||||
public int getLastDailyReset() {
|
||||
return this.lastDailyReset;
|
||||
}
|
||||
|
||||
public void setLastDailyReset(int value) {
|
||||
this.lastDailyReset = value;
|
||||
}
|
||||
|
||||
public boolean inMoonCard() {
|
||||
return moonCard;
|
||||
}
|
||||
|
||||
public void setMoonCard(boolean moonCard) {
|
||||
this.moonCard = moonCard;
|
||||
}
|
||||
|
||||
public void addMoonCardDays(int days) {
|
||||
this.moonCardDuration += days;
|
||||
}
|
||||
|
||||
public int getMoonCardDuration() {
|
||||
return moonCardDuration;
|
||||
}
|
||||
|
||||
public void setMoonCardDuration(int moonCardDuration) {
|
||||
this.moonCardDuration = moonCardDuration;
|
||||
}
|
||||
|
||||
public Date getMoonCardStartTime() {
|
||||
return moonCardStartTime;
|
||||
}
|
||||
|
||||
public void setMoonCardStartTime(Date moonCardStartTime) {
|
||||
this.moonCardStartTime = moonCardStartTime;
|
||||
}
|
||||
|
||||
public Set<Date> getMoonCardGetTimes() {
|
||||
return moonCardGetTimes;
|
||||
}
|
||||
|
||||
public void setMoonCardGetTimes(Set<Date> moonCardGetTimes) {
|
||||
this.moonCardGetTimes = moonCardGetTimes;
|
||||
}
|
||||
|
||||
public int getMoonCardRemainDays() {
|
||||
Calendar remainCalendar = Calendar.getInstance();
|
||||
remainCalendar.setTime(moonCardStartTime);
|
||||
@ -869,25 +683,21 @@ public class Player {
|
||||
session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays()));
|
||||
}
|
||||
|
||||
public void addExpeditionInfo(long avaterGuid, int expId, int hourTime, int startTime) {
|
||||
public void addExpeditionInfo(long avatarGuid, int expId, int hourTime, int startTime) {
|
||||
ExpeditionInfo exp = new ExpeditionInfo();
|
||||
exp.setExpId(expId);
|
||||
exp.setHourTime(hourTime);
|
||||
exp.setState(1);
|
||||
exp.setStartTime(startTime);
|
||||
expeditionInfo.put(avaterGuid, exp);
|
||||
expeditionInfo.put(avatarGuid, exp);
|
||||
}
|
||||
|
||||
public void removeExpeditionInfo(long avaterGuid) {
|
||||
expeditionInfo.remove(avaterGuid);
|
||||
public void removeExpeditionInfo(long avatarGuid) {
|
||||
expeditionInfo.remove(avatarGuid);
|
||||
}
|
||||
|
||||
public ExpeditionInfo getExpeditionInfo(long avaterGuid) {
|
||||
return expeditionInfo.get(avaterGuid);
|
||||
}
|
||||
|
||||
public List<ShopLimit> getShopLimit() {
|
||||
return shopLimit;
|
||||
public ExpeditionInfo getExpeditionInfo(long avatarGuid) {
|
||||
return expeditionInfo.get(avatarGuid);
|
||||
}
|
||||
|
||||
public ShopLimit getGoodsLimit(int goodsId) {
|
||||
@ -913,20 +723,19 @@ public class Player {
|
||||
}
|
||||
this.save();
|
||||
}
|
||||
|
||||
public boolean getUnlimitedStamina() {
|
||||
return stamina;
|
||||
}
|
||||
|
||||
public void setUnlimitedStamina(boolean stamina) {
|
||||
this.stamina = stamina;
|
||||
}
|
||||
|
||||
public boolean inGodmode() {
|
||||
return godmode;
|
||||
}
|
||||
|
||||
public void setGodmode(boolean godmode) {
|
||||
this.godmode = godmode;
|
||||
}
|
||||
|
||||
public boolean hasSentLoginPackets() {
|
||||
return hasSentLoginPackets;
|
||||
}
|
||||
@ -1067,10 +876,6 @@ public class Player {
|
||||
return onlineInfo.build();
|
||||
}
|
||||
|
||||
public PlayerBirthday getBirthday() {
|
||||
return this.birthday;
|
||||
}
|
||||
|
||||
public void setBirthday(int d, int m) {
|
||||
this.birthday = new PlayerBirthday(d, m);
|
||||
this.updateProfile();
|
||||
@ -1080,10 +885,6 @@ public class Player {
|
||||
return this.birthday.getDay() > 0;
|
||||
}
|
||||
|
||||
public PlayerCodex getCodex() {
|
||||
return this.codex;
|
||||
}
|
||||
|
||||
public void setRewardedLevels(Set<Integer> rewardedLevels) {
|
||||
this.rewardedLevels = rewardedLevels;
|
||||
}
|
||||
@ -1200,6 +1001,15 @@ public class Player {
|
||||
return mapMarks;
|
||||
}
|
||||
|
||||
private boolean expireCoopRequest(CoopRequest req) {
|
||||
if (!req.isExpired()) return false;
|
||||
req.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(
|
||||
this,
|
||||
false,
|
||||
PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify.Reason.REASON_SYSTEM_JUDGE));
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized void onTick() {
|
||||
// Check ping
|
||||
if (this.getLastPingTime() > System.currentTimeMillis() + 60000) {
|
||||
@ -1207,17 +1017,7 @@ public class Player {
|
||||
return;
|
||||
}
|
||||
// Check co-op requests
|
||||
Iterator<CoopRequest> it = this.getCoopRequests().values().iterator();
|
||||
while (it.hasNext()) {
|
||||
CoopRequest req = it.next();
|
||||
if (req.isExpired()) {
|
||||
req.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(
|
||||
this,
|
||||
false,
|
||||
PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify.Reason.REASON_SYSTEM_JUDGE));
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
this.getCoopRequests().values().removeIf(this::expireCoopRequest);
|
||||
// Handle buff
|
||||
this.getBuffManager().onTick();
|
||||
// Ping
|
||||
@ -1240,8 +1040,7 @@ public class Player {
|
||||
// Expedition
|
||||
var timeNow = Utils.getCurrentSeconds();
|
||||
var needNotify = false;
|
||||
for (Long key : expeditionInfo.keySet()) {
|
||||
ExpeditionInfo e = expeditionInfo.get(key);
|
||||
for (ExpeditionInfo e : expeditionInfo.values()) {
|
||||
if (e.getState() == 1) {
|
||||
if (timeNow - e.getStartTime() >= e.getHourTime() * 60 * 60) {
|
||||
e.setState(2);
|
||||
@ -1251,7 +1050,7 @@ public class Player {
|
||||
}
|
||||
if (needNotify) {
|
||||
this.save();
|
||||
this.sendPacket(new PacketAvatarExpeditionDataNotify(this));
|
||||
this.sendPacket(new PacketAvatarExpeditionDataNotify(this.getExpeditionInfo()));
|
||||
}
|
||||
|
||||
// Send updated forge queue data, if necessary.
|
||||
@ -1474,23 +1273,15 @@ public class Player {
|
||||
public enum SceneLoadState {
|
||||
NONE(0), LOADING(1), INIT(2), LOADED(3);
|
||||
|
||||
private final int value;
|
||||
@Getter private final int value;
|
||||
|
||||
private SceneLoadState(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessageHandler(MessageHandler messageHandler) {
|
||||
this.messageHandler = messageHandler;
|
||||
}
|
||||
|
||||
public int getPropertyMin(PlayerProperty prop) {
|
||||
if (prop.getDynamicRange()) {
|
||||
if (prop.isDynamicRange()) {
|
||||
return switch (prop) {
|
||||
default -> 0;
|
||||
};
|
||||
@ -1500,7 +1291,7 @@ public class Player {
|
||||
}
|
||||
|
||||
public int getPropertyMax(PlayerProperty prop) {
|
||||
if (prop.getDynamicRange()) {
|
||||
if (prop.isDynamicRange()) {
|
||||
return switch (prop) {
|
||||
case PROP_CUR_SPRING_VOLUME -> getProperty(PlayerProperty.PROP_MAX_SPRING_VOLUME);
|
||||
case PROP_CUR_PERSIST_STAMINA -> getProperty(PlayerProperty.PROP_MAX_STAMINA);
|
||||
@ -1529,8 +1320,8 @@ public class Player {
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
|
||||
public enum PlayerProperty {
|
||||
PROP_NONE (0),
|
||||
@ -53,8 +54,8 @@ public enum PlayerProperty {
|
||||
PROP_PLAYER_WAIT_SUB_HOME_COIN (10043);
|
||||
|
||||
private static final int inf = Integer.MAX_VALUE; // Maybe this should be something else?
|
||||
private final int id, min, max;
|
||||
private final boolean dynamicRange;
|
||||
@Getter private final int id, min, max;
|
||||
@Getter private final boolean dynamicRange;
|
||||
private static final Int2ObjectMap<PlayerProperty> map = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
static {
|
||||
@ -84,22 +85,6 @@ public enum PlayerProperty {
|
||||
this(id, Integer.MIN_VALUE, inf, dynamicRange);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return this.min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return this.max;
|
||||
}
|
||||
|
||||
public boolean getDynamicRange() {
|
||||
return dynamicRange;
|
||||
}
|
||||
|
||||
public static PlayerProperty getPropById(int value) {
|
||||
return map.getOrDefault(value, null);
|
||||
}
|
||||
|
@ -2,26 +2,28 @@ package emu.grasscutter.game.shop;
|
||||
|
||||
import emu.grasscutter.data.common.ItemParamData;
|
||||
import emu.grasscutter.data.excels.ShopGoodsData;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShopInfo {
|
||||
private int goodsId = 0;
|
||||
private ItemParamData goodsItem;
|
||||
private int scoin = 0;
|
||||
private List<ItemParamData> costItemList;
|
||||
private int boughtNum = 0;
|
||||
private int buyLimit = 0;
|
||||
private int beginTime = 0;
|
||||
private int endTime = 1924992000;
|
||||
private int minLevel = 0;
|
||||
private int maxLevel = 61;
|
||||
private List<Integer> preGoodsIdList = new ArrayList<>();
|
||||
private int mcoin = 0;
|
||||
private int hcoin = 0;
|
||||
private int disableType = 0;
|
||||
private int secondarySheetId = 0;
|
||||
@Getter @Setter private int goodsId = 0;
|
||||
@Getter @Setter private ItemParamData goodsItem;
|
||||
@Getter @Setter private int scoin = 0;
|
||||
@Getter @Setter private List<ItemParamData> costItemList;
|
||||
@Getter @Setter private int boughtNum = 0;
|
||||
@Getter @Setter private int buyLimit = 0;
|
||||
@Getter @Setter private int beginTime = 0;
|
||||
@Getter @Setter private int endTime = 1924992000;
|
||||
@Getter @Setter private int minLevel = 0;
|
||||
@Getter @Setter private int maxLevel = 61;
|
||||
@Getter @Setter private List<Integer> preGoodsIdList = new ArrayList<>();
|
||||
@Getter @Setter private int mcoin = 0;
|
||||
@Getter @Setter private int hcoin = 0;
|
||||
@Getter @Setter private int disableType = 0;
|
||||
@Getter @Setter private int secondarySheetId = 0;
|
||||
|
||||
private String refreshType;
|
||||
|
||||
@ -41,8 +43,8 @@ public class ShopInfo {
|
||||
}
|
||||
}
|
||||
|
||||
private transient ShopRefreshType shopRefreshType;
|
||||
private int shopRefreshParam;
|
||||
@Setter private transient ShopRefreshType shopRefreshType;
|
||||
@Getter @Setter private int shopRefreshParam;
|
||||
|
||||
public ShopInfo(ShopGoodsData sgd) {
|
||||
this.goodsId = sgd.getGoodsId();
|
||||
@ -60,126 +62,6 @@ public class ShopInfo {
|
||||
this.shopRefreshParam = sgd.getRefreshParam();
|
||||
}
|
||||
|
||||
public int getHcoin() {
|
||||
return hcoin;
|
||||
}
|
||||
|
||||
public void setHcoin(int hcoin) {
|
||||
this.hcoin = hcoin;
|
||||
}
|
||||
|
||||
public List<Integer> getPreGoodsIdList() {
|
||||
return preGoodsIdList;
|
||||
}
|
||||
|
||||
public void setPreGoodsIdList(List<Integer> preGoodsIdList) {
|
||||
this.preGoodsIdList = preGoodsIdList;
|
||||
}
|
||||
|
||||
public int getMcoin() {
|
||||
return mcoin;
|
||||
}
|
||||
|
||||
public void setMcoin(int mcoin) {
|
||||
this.mcoin = mcoin;
|
||||
}
|
||||
|
||||
public int getDisableType() {
|
||||
return disableType;
|
||||
}
|
||||
|
||||
public void setDisableType(int disableType) {
|
||||
this.disableType = disableType;
|
||||
}
|
||||
|
||||
public int getSecondarySheetId() {
|
||||
return secondarySheetId;
|
||||
}
|
||||
|
||||
public void setSecondarySheetId(int secondarySheetId) {
|
||||
this.secondarySheetId = secondarySheetId;
|
||||
}
|
||||
|
||||
public int getGoodsId() {
|
||||
return goodsId;
|
||||
}
|
||||
|
||||
public void setGoodsId(int goodsId) {
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
|
||||
public ItemParamData getGoodsItem() {
|
||||
return goodsItem;
|
||||
}
|
||||
|
||||
public void setGoodsItem(ItemParamData goodsItem) {
|
||||
this.goodsItem = goodsItem;
|
||||
}
|
||||
|
||||
public int getScoin() {
|
||||
return scoin;
|
||||
}
|
||||
|
||||
public void setScoin(int scoin) {
|
||||
this.scoin = scoin;
|
||||
}
|
||||
|
||||
public List<ItemParamData> getCostItemList() {
|
||||
return costItemList;
|
||||
}
|
||||
|
||||
public void setCostItemList(List<ItemParamData> costItemList) {
|
||||
this.costItemList = costItemList;
|
||||
}
|
||||
|
||||
public int getBoughtNum() {
|
||||
return boughtNum;
|
||||
}
|
||||
|
||||
public void setBoughtNum(int boughtNum) {
|
||||
this.boughtNum = boughtNum;
|
||||
}
|
||||
|
||||
public int getBuyLimit() {
|
||||
return buyLimit;
|
||||
}
|
||||
|
||||
public void setBuyLimit(int buyLimit) {
|
||||
this.buyLimit = buyLimit;
|
||||
}
|
||||
|
||||
public int getBeginTime() {
|
||||
return beginTime;
|
||||
}
|
||||
|
||||
public void setBeginTime(int beginTime) {
|
||||
this.beginTime = beginTime;
|
||||
}
|
||||
|
||||
public int getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(int endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public int getMinLevel() {
|
||||
return minLevel;
|
||||
}
|
||||
|
||||
public void setMinLevel(int minLevel) {
|
||||
this.minLevel = minLevel;
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
public void setMaxLevel(int maxLevel) {
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
public ShopRefreshType getShopRefreshType() {
|
||||
if (refreshType == null)
|
||||
return ShopRefreshType.NONE;
|
||||
@ -191,15 +73,16 @@ public class ShopInfo {
|
||||
};
|
||||
}
|
||||
|
||||
public void setShopRefreshType(ShopRefreshType shopRefreshType) {
|
||||
this.shopRefreshType = shopRefreshType;
|
||||
private boolean evaluateVirtualCost(ItemParamData item) {
|
||||
return switch (item.getId()) {
|
||||
case 201 -> {this.hcoin += item.getCount(); yield true;}
|
||||
case 203 -> {this.mcoin += item.getCount(); yield true;}
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
public int getShopRefreshParam() {
|
||||
return shopRefreshParam;
|
||||
}
|
||||
|
||||
public void setShopRefreshParam(int shopRefreshParam) {
|
||||
this.shopRefreshParam = shopRefreshParam;
|
||||
public void removeVirtualCosts() {
|
||||
if (this.costItemList != null)
|
||||
this.costItemList.removeIf(item -> evaluateVirtualCost(item));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package emu.grasscutter.game.shop;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.DataLoader;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.common.ItemParamData;
|
||||
import emu.grasscutter.data.excels.ShopGoodsData;
|
||||
import emu.grasscutter.server.game.BaseGameSystem;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
@ -14,7 +13,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ShopSystem extends BaseGameSystem {
|
||||
@ -60,22 +58,7 @@ public class ShopSystem extends BaseGameSystem {
|
||||
List<ShopTable> banners = DataLoader.loadList("Shop.json", ShopTable.class);
|
||||
if (banners.size() > 0) {
|
||||
for (ShopTable shopTable : banners) {
|
||||
for (ShopInfo cost : shopTable.getItems()) {
|
||||
if (cost.getCostItemList() != null) {
|
||||
Iterator<ItemParamData> iterator = cost.getCostItemList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ItemParamData ipd = iterator.next();
|
||||
if (ipd.getId() == 201) {
|
||||
cost.setHcoin(cost.getHcoin() + ipd.getCount());
|
||||
iterator.remove();
|
||||
}
|
||||
if (ipd.getId() == 203) {
|
||||
cost.setMcoin(cost.getMcoin() + ipd.getCount());
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
shopTable.getItems().forEach(ShopInfo::removeVirtualCosts);
|
||||
getShopData().put(shopTable.getShopId(), shopTable.getItems());
|
||||
}
|
||||
Grasscutter.getLogger().debug("Shop data successfully loaded.");
|
||||
|
@ -28,6 +28,7 @@ import emu.grasscutter.utils.Position;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Scene {
|
||||
private final World world;
|
||||
@ -261,12 +262,11 @@ public class Scene {
|
||||
}
|
||||
}
|
||||
|
||||
private void removePlayerAvatars(Player player) {
|
||||
Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator();
|
||||
while (it.hasNext()) {
|
||||
this.removeEntity(it.next(), VisionType.VISION_TYPE_REMOVE);
|
||||
it.remove();
|
||||
}
|
||||
private synchronized void removePlayerAvatars(Player player) {
|
||||
var team = player.getTeamManager().getActiveTeam();
|
||||
// removeEntities(team, VisionType.VISION_TYPE_REMOVE); // List<SubType> isn't cool apparently :(
|
||||
team.forEach(e -> removeEntity(e, VisionType.VISION_TYPE_REMOVE));
|
||||
team.clear();
|
||||
}
|
||||
|
||||
public void spawnPlayer(Player player) {
|
||||
@ -567,40 +567,40 @@ public class Scene {
|
||||
return SceneIndexManager.queryNeighbors(getScriptManager().getBlocksIndex(),
|
||||
player.getPosition().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
|
||||
}
|
||||
public void checkBlocks() {
|
||||
Set<SceneBlock> visible = new HashSet<>();
|
||||
for (Player player : this.getPlayers()) {
|
||||
var blocks = getPlayerActiveBlocks(player);
|
||||
visible.addAll(blocks);
|
||||
}
|
||||
|
||||
Iterator<SceneBlock> it = this.getLoadedBlocks().iterator();
|
||||
while (it.hasNext()) {
|
||||
SceneBlock block = it.next();
|
||||
|
||||
if (!visible.contains(block)) {
|
||||
it.remove();
|
||||
|
||||
onUnloadBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
for (var block : visible) {
|
||||
if (!this.getLoadedBlocks().contains(block)) {
|
||||
this.onLoadBlock(block, this.getPlayers());
|
||||
this.getLoadedBlocks().add(block);
|
||||
}else {
|
||||
// dynamic load the groups for players in a loaded block
|
||||
var toLoad = this.getPlayers().stream()
|
||||
.filter(p -> block.contains(p.getPosition()))
|
||||
.map(p -> playerMeetGroups(p, block))
|
||||
.flatMap(Collection::stream)
|
||||
.toList();
|
||||
onLoadGroup(toLoad);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean unloadBlockIfNotVisible(Collection<SceneBlock> visible, SceneBlock block) {
|
||||
if (visible.contains(block)) return false;
|
||||
this.onUnloadBlock(block);
|
||||
return true;
|
||||
}
|
||||
|
||||
private synchronized boolean loadBlock(SceneBlock block) {
|
||||
if (this.loadedBlocks.contains(block)) return false;
|
||||
this.onLoadBlock(block, this.players);
|
||||
this.loadedBlocks.add(block);
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized void checkBlocks() {
|
||||
Set<SceneBlock> visible = this.players.stream()
|
||||
.map(player -> this.getPlayerActiveBlocks(player))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
this.loadedBlocks.removeIf(block -> unloadBlockIfNotVisible(visible, block));
|
||||
visible.stream()
|
||||
.filter(block -> !this.loadBlock(block))
|
||||
.forEach(block -> {
|
||||
// dynamic load the groups for players in a loaded block
|
||||
var toLoad = this.players.stream()
|
||||
.filter(p -> block.contains(p.getPosition()))
|
||||
.map(p -> this.playerMeetGroups(p, block))
|
||||
.flatMap(Collection::stream)
|
||||
.toList();
|
||||
this.onLoadGroup(toLoad);
|
||||
});
|
||||
}
|
||||
|
||||
public List<SceneGroup> playerMeetGroups(Player player, SceneBlock block) {
|
||||
List<SceneGroup> sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPosition().toDoubleArray(),
|
||||
Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
|
||||
|
@ -330,10 +330,11 @@ public class World implements Iterable<Player> {
|
||||
}
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
for (Scene scene : this.getScenes().values()) {
|
||||
scene.onTick();
|
||||
}
|
||||
// Returns true if the world should be deleted
|
||||
public boolean onTick() {
|
||||
if (this.getPlayerCount() == 0) return true;
|
||||
this.scenes.forEach((k, scene) -> scene.onTick());
|
||||
return false;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
@ -218,21 +218,10 @@ public final class GameServer extends KcpServer {
|
||||
var tickStart = Instant.now();
|
||||
|
||||
// Tick worlds.
|
||||
Iterator<World> it = this.getWorlds().iterator();
|
||||
while (it.hasNext()) {
|
||||
World world = it.next();
|
||||
|
||||
if (world.getPlayerCount() == 0) {
|
||||
it.remove();
|
||||
}
|
||||
|
||||
world.onTick();
|
||||
}
|
||||
this.worlds.removeIf(World::onTick);
|
||||
|
||||
// Tick players.
|
||||
for (Player player : this.getPlayers().values()) {
|
||||
player.onTick();
|
||||
}
|
||||
this.players.values().forEach(Player::onTick);
|
||||
|
||||
// Tick scheduler.
|
||||
this.getScheduler().runTasks();
|
||||
|
@ -10,6 +10,7 @@ import emu.grasscutter.server.packet.send.PacketAvatarExpeditionAllDataRsp;
|
||||
public class HandlerAvatarExpeditionAllDataReq extends PacketHandler {
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
session.send(new PacketAvatarExpeditionAllDataRsp(session.getPlayer()));
|
||||
var player = session.getPlayer();
|
||||
session.send(new PacketAvatarExpeditionAllDataRsp(player.getExpeditionInfo(), player.getExpeditionLimit()));
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,19 @@ import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionCallBackReqOuterClass.AvatarExpeditionCallBackReq;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarExpeditionCallBackRsp;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarExpeditionStartRsp;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
@Opcodes(PacketOpcodes.AvatarExpeditionCallBackReq)
|
||||
public class HandlerAvatarExpeditionCallBackReq extends PacketHandler {
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
AvatarExpeditionCallBackReq req = AvatarExpeditionCallBackReq.parseFrom(payload);
|
||||
var player = session.getPlayer();
|
||||
|
||||
for (int i = 0; i < req.getAvatarGuidCount(); i++) {
|
||||
session.getPlayer().removeExpeditionInfo(req.getAvatarGuid(i));
|
||||
player.removeExpeditionInfo(req.getAvatarGuid(i));
|
||||
}
|
||||
|
||||
session.getPlayer().save();
|
||||
session.send(new PacketAvatarExpeditionCallBackRsp(session.getPlayer()));
|
||||
player.save();
|
||||
session.send(new PacketAvatarExpeditionCallBackRsp(player.getExpeditionInfo()));
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,18 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.game.drop.DropData;
|
||||
import emu.grasscutter.game.expedition.ExpeditionInfo;
|
||||
import emu.grasscutter.game.expedition.ExpeditionRewardData;
|
||||
import emu.grasscutter.game.expedition.ExpeditionRewardDataList;
|
||||
import emu.grasscutter.game.inventory.GameItem;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionGetRewardReqOuterClass.AvatarExpeditionGetRewardReq;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarExpeditionCallBackRsp;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarExpeditionGetRewardRsp;
|
||||
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
|
||||
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@Opcodes(PacketOpcodes.AvatarExpeditionGetRewardReq)
|
||||
@ -29,33 +20,25 @@ public class HandlerAvatarExpeditionGetRewardReq extends PacketHandler {
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
AvatarExpeditionGetRewardReq req = AvatarExpeditionGetRewardReq.parseFrom(payload);
|
||||
var player = session.getPlayer();
|
||||
|
||||
ExpeditionInfo expInfo = session.getPlayer().getExpeditionInfo(req.getAvatarGuid());
|
||||
ExpeditionInfo expInfo = player.getExpeditionInfo(req.getAvatarGuid());
|
||||
List<GameItem> items = new ArrayList<>();
|
||||
List<ExpeditionRewardDataList> expeditionRewardDataLists = session.getServer().getExpeditionSystem().getExpeditionRewardDataList().get(expInfo.getExpId());
|
||||
|
||||
List<GameItem> items = new LinkedList<>();
|
||||
|
||||
if (session.getServer().getExpeditionSystem().getExpeditionRewardDataList().containsKey(expInfo.getExpId())) {
|
||||
for (ExpeditionRewardDataList RewardDataList : session.getServer().getExpeditionSystem().getExpeditionRewardDataList().get(expInfo.getExpId())) {
|
||||
if (RewardDataList.getHourTime() == expInfo.getHourTime()) {
|
||||
if (!RewardDataList.getExpeditionRewardData().isEmpty()) {
|
||||
for (ExpeditionRewardData RewardData :RewardDataList.getExpeditionRewardData()) {
|
||||
int num = RewardData.getMinCount();
|
||||
if (RewardData.getMinCount() != RewardData.getMaxCount()) {
|
||||
num = Utils.randomRange(RewardData.getMinCount(), RewardData.getMaxCount());
|
||||
}
|
||||
items.add(new GameItem(RewardData.getItemId(), num));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (expeditionRewardDataLists != null) {
|
||||
expeditionRewardDataLists.stream()
|
||||
.filter(r -> r.getHourTime() == expInfo.getHourTime())
|
||||
.map(ExpeditionRewardDataList::getRewards)
|
||||
.forEach(items::addAll);
|
||||
}
|
||||
|
||||
session.getPlayer().getInventory().addItems(items);
|
||||
session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.ExpeditionReward));
|
||||
player.getInventory().addItems(items);
|
||||
player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.ExpeditionReward));
|
||||
|
||||
session.getPlayer().removeExpeditionInfo(req.getAvatarGuid());
|
||||
session.getPlayer().save();
|
||||
session.send(new PacketAvatarExpeditionGetRewardRsp(session.getPlayer(), items));
|
||||
player.removeExpeditionInfo(req.getAvatarGuid());
|
||||
player.save();
|
||||
session.send(new PacketAvatarExpeditionGetRewardRsp(player.getExpeditionInfo(), items));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
@ -14,10 +13,11 @@ public class HandlerAvatarExpeditionStartReq extends PacketHandler {
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
AvatarExpeditionStartReq req = AvatarExpeditionStartReq.parseFrom(payload);
|
||||
var player = session.getPlayer();
|
||||
|
||||
int startTime = Utils.getCurrentSeconds();
|
||||
session.getPlayer().addExpeditionInfo(req.getAvatarGuid(), req.getExpId(), req.getHourTime(), startTime);
|
||||
session.getPlayer().save();
|
||||
session.send(new PacketAvatarExpeditionStartRsp(session.getPlayer()));
|
||||
player.addExpeditionInfo(req.getAvatarGuid(), req.getExpId(), req.getHourTime(), startTime);
|
||||
player.save();
|
||||
session.send(new PacketAvatarExpeditionStartRsp(player.getExpeditionInfo()));
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class PacketAllWidgetDataNotify extends BasePacket {
|
||||
// Good luck, my boy.
|
||||
.addAllNormalCoolDownDataList(List.of());
|
||||
|
||||
if (player.getWidgetId() == null) {
|
||||
if (player.getWidgetId() == 0) { // TODO: check this logic later, it was null-checking an int before which made it dead code
|
||||
proto.addAllSlotList(List.of());
|
||||
} else {
|
||||
proto.addSlotList(
|
||||
|
@ -1,33 +1,27 @@
|
||||
package emu.grasscutter.server.packet.send;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.game.expedition.ExpeditionInfo;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionAllDataRspOuterClass.AvatarExpeditionAllDataRsp;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PacketAvatarExpeditionAllDataRsp extends BasePacket {
|
||||
public PacketAvatarExpeditionAllDataRsp(Player player) {
|
||||
public PacketAvatarExpeditionAllDataRsp(Map<Long, ExpeditionInfo> expeditionInfo, int expeditionCountLimit) {
|
||||
super(PacketOpcodes.AvatarExpeditionAllDataRsp);
|
||||
|
||||
List<Integer> openExpeditionList = new ArrayList<>(List.of(306,305,304,303,302,301,206,105,204,104,203,103,202,101,102,201,106,205));
|
||||
Map<Long, AvatarExpeditionInfo> avatarExpeditionInfoList = new HashMap<Long, AvatarExpeditionInfo>();
|
||||
|
||||
var expeditionInfo = player.getExpeditionInfo();
|
||||
for (Long key : player.getExpeditionInfo().keySet()) {
|
||||
ExpeditionInfo e = expeditionInfo.get(key);
|
||||
avatarExpeditionInfoList.put(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build());
|
||||
};
|
||||
|
||||
AvatarExpeditionAllDataRsp.Builder proto = AvatarExpeditionAllDataRsp.newBuilder()
|
||||
.addAllOpenExpeditionList(openExpeditionList)
|
||||
.setExpeditionCountLimit(5)
|
||||
.putAllExpeditionInfoMap(avatarExpeditionInfoList);
|
||||
|
||||
this.setData(proto.build());
|
||||
this.setData(AvatarExpeditionAllDataRsp.newBuilder()
|
||||
.addAllOpenExpeditionList(openExpeditionList)
|
||||
.setExpeditionCountLimit(expeditionCountLimit)
|
||||
.putAllExpeditionInfoMap(
|
||||
expeditionInfo.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
e -> e.getKey(),
|
||||
e -> e.getValue().toProto())))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,18 @@
|
||||
package emu.grasscutter.server.packet.send;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import emu.grasscutter.game.expedition.ExpeditionInfo;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionCallBackRspOuterClass.AvatarExpeditionCallBackRsp;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
|
||||
|
||||
public class PacketAvatarExpeditionCallBackRsp extends BasePacket {
|
||||
public PacketAvatarExpeditionCallBackRsp(Player player) {
|
||||
public PacketAvatarExpeditionCallBackRsp(Map<Long, ExpeditionInfo> expeditionInfo) {
|
||||
super(PacketOpcodes.AvatarExpeditionCallBackRsp);
|
||||
|
||||
AvatarExpeditionCallBackRsp.Builder proto = AvatarExpeditionCallBackRsp.newBuilder();
|
||||
var expeditionInfo = player.getExpeditionInfo();
|
||||
for (Long key : player.getExpeditionInfo().keySet()) {
|
||||
ExpeditionInfo e = expeditionInfo.get(key);
|
||||
proto.putExpeditionInfoMap(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build());
|
||||
};
|
||||
expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto()));
|
||||
|
||||
this.setData(proto.build());
|
||||
}
|
||||
|
@ -1,29 +1,24 @@
|
||||
package emu.grasscutter.server.packet.send;
|
||||
|
||||
import emu.grasscutter.game.expedition.ExpeditionInfo;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionDataNotifyOuterClass.AvatarExpeditionDataNotify;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PacketAvatarExpeditionDataNotify extends BasePacket {
|
||||
public PacketAvatarExpeditionDataNotify(Player player) {
|
||||
public PacketAvatarExpeditionDataNotify(Map<Long, ExpeditionInfo> expeditionInfo) {
|
||||
super(PacketOpcodes.AvatarExpeditionDataNotify);
|
||||
|
||||
Map<Long, AvatarExpeditionInfo> avatarExpeditionInfoList = new HashMap<Long, AvatarExpeditionInfo>();
|
||||
|
||||
var expeditionInfo = player.getExpeditionInfo();
|
||||
for (Long key : player.getExpeditionInfo().keySet()) {
|
||||
ExpeditionInfo e = expeditionInfo.get(key);
|
||||
avatarExpeditionInfoList.put(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build());
|
||||
};
|
||||
|
||||
AvatarExpeditionDataNotify.Builder proto = AvatarExpeditionDataNotify.newBuilder()
|
||||
.putAllExpeditionInfoMap(avatarExpeditionInfoList);
|
||||
|
||||
this.setData(proto.build());
|
||||
this.setData(AvatarExpeditionDataNotify.newBuilder()
|
||||
.putAllExpeditionInfoMap(
|
||||
expeditionInfo.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
e -> e.getKey(),
|
||||
e -> e.getValue().toProto())))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,28 +2,20 @@ package emu.grasscutter.server.packet.send;
|
||||
|
||||
import emu.grasscutter.game.expedition.ExpeditionInfo;
|
||||
import emu.grasscutter.game.inventory.GameItem;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionGetRewardRspOuterClass.AvatarExpeditionGetRewardRsp;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class PacketAvatarExpeditionGetRewardRsp extends BasePacket {
|
||||
public PacketAvatarExpeditionGetRewardRsp(Player player, Collection<GameItem> items) {
|
||||
public PacketAvatarExpeditionGetRewardRsp(Map<Long, ExpeditionInfo> expeditionInfo, Collection<GameItem> items) {
|
||||
super(PacketOpcodes.AvatarExpeditionGetRewardRsp);
|
||||
|
||||
AvatarExpeditionGetRewardRsp.Builder proto = AvatarExpeditionGetRewardRsp.newBuilder();
|
||||
var expeditionInfo = player.getExpeditionInfo();
|
||||
for (Long key : player.getExpeditionInfo().keySet()) {
|
||||
ExpeditionInfo e = expeditionInfo.get(key);
|
||||
proto.putExpeditionInfoMap(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build());
|
||||
};
|
||||
|
||||
for (GameItem item : items) {
|
||||
proto.addItemList(item.toItemParam());
|
||||
}
|
||||
expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto()));
|
||||
items.forEach(item -> proto.addItemList(item.toItemParam()));
|
||||
|
||||
this.setData(proto.build());
|
||||
}
|
||||
|
@ -1,22 +1,18 @@
|
||||
package emu.grasscutter.server.packet.send;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import emu.grasscutter.game.expedition.ExpeditionInfo;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
|
||||
import emu.grasscutter.net.proto.AvatarExpeditionStartRspOuterClass.AvatarExpeditionStartRsp;
|
||||
|
||||
public class PacketAvatarExpeditionStartRsp extends BasePacket {
|
||||
public PacketAvatarExpeditionStartRsp(Player player) {
|
||||
public PacketAvatarExpeditionStartRsp(Map<Long, ExpeditionInfo> expeditionInfo) {
|
||||
super(PacketOpcodes.AvatarExpeditionStartRsp);
|
||||
|
||||
AvatarExpeditionStartRsp.Builder proto = AvatarExpeditionStartRsp.newBuilder();
|
||||
var expeditionInfo = player.getExpeditionInfo();
|
||||
for (Long key : player.getExpeditionInfo().keySet()) {
|
||||
ExpeditionInfo e = expeditionInfo.get(key);
|
||||
proto.putExpeditionInfoMap(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build());
|
||||
};
|
||||
expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto()));
|
||||
|
||||
this.setData(proto.build());
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class PacketGetWidgetSlotRsp extends BasePacket {
|
||||
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.Builder proto =
|
||||
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.newBuilder();
|
||||
|
||||
if (player.getWidgetId() == null) {
|
||||
if (player.getWidgetId() == 0) { // TODO: check this logic later, it was null-checking an int before which made it dead code
|
||||
proto.addAllSlotList(List.of());
|
||||
} else {
|
||||
proto.addSlotList(
|
||||
|
Loading…
Reference in New Issue
Block a user