mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 09:25:06 +01:00
Implement Avatar Expedition System
Co-Authored-By: ShigemoriHakura <62388797+ShigemoriHakura@users.noreply.github.com> Co-Authored-By: KanyeWestc <104547412+KanyeWestc@users.noreply.github.com> Co-Authored-By: QAQ 天小络 <72185326+XTL676@users.noreply.github.com> Co-Authored-By: nkxingxh <25559053+nkxingxh@users.noreply.github.com> Co-Authored-By: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Co-Authored-By: wuwuwu223 <81224214+wuwuwu223@users.noreply.github.com> Co-Authored-By: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Co-Authored-By: Sakura <104815797+Sakura@users.noreply.github.com> Co-Authored-By: NewNeko-2022 <104819344+NewNeko-2022@users.noreply.github.com> Co-Authored-By: JimWails <30657653+JimWails@users.noreply.github.com> Co-Authored-By: buttercookies <19878609+ButterCookies@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
|
||||
@Entity
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ExpeditionManager {
|
||||
public GameServer getGameServer() {
|
||||
return gameServer;
|
||||
}
|
||||
|
||||
private final GameServer gameServer;
|
||||
|
||||
public Int2ObjectMap<List<ExpeditionRewardDataList>> getExpeditionRewardDataList() { return expeditionRewardData; }
|
||||
|
||||
private final Int2ObjectMap<List<ExpeditionRewardDataList>> expeditionRewardData;
|
||||
|
||||
public ExpeditionManager(GameServer gameServer) {
|
||||
this.gameServer = gameServer;
|
||||
this.expeditionRewardData = new Int2ObjectOpenHashMap<>();
|
||||
this.load();
|
||||
}
|
||||
|
||||
public synchronized void load() {
|
||||
try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "ExpeditionReward.json")) {
|
||||
getExpeditionRewardDataList().clear();
|
||||
List<ExpeditionRewardInfo> banners = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, ExpeditionRewardInfo.class).getType());
|
||||
if(banners.size() > 0) {
|
||||
for (ExpeditionRewardInfo di : banners) {
|
||||
getExpeditionRewardDataList().put(di.getExpId(), di.getExpeditionRewardDataList());
|
||||
}
|
||||
Grasscutter.getLogger().info("Expedition reward successfully loaded.");
|
||||
} else {
|
||||
Grasscutter.getLogger().error("Unable to load expedition reward. Expedition reward size is 0.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error("Unable to load expedition reward.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
public class ExpeditionRewardData {
|
||||
private int itemId;
|
||||
private int minCount;
|
||||
private int maxCount;
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public int getMinCount() { return minCount; }
|
||||
|
||||
public int getMaxCount() {
|
||||
return maxCount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExpeditionRewardDataList {
|
||||
public int getHourTime() {
|
||||
return hourTime;
|
||||
}
|
||||
public List<ExpeditionRewardData> getExpeditionRewardData() {
|
||||
return expeditionRewardData;
|
||||
}
|
||||
|
||||
private int hourTime;
|
||||
private List<ExpeditionRewardData> expeditionRewardData;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package emu.grasscutter.game.expedition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExpeditionRewardInfo {
|
||||
public int getExpId() {
|
||||
return expId;
|
||||
}
|
||||
|
||||
public List<ExpeditionRewardDataList> getExpeditionRewardDataList() {
|
||||
return expeditionRewardDataList;
|
||||
}
|
||||
|
||||
private int expId;
|
||||
private List<ExpeditionRewardDataList> expeditionRewardDataList;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import emu.grasscutter.game.avatar.AvatarStorage;
|
||||
import emu.grasscutter.game.entity.EntityGadget;
|
||||
import emu.grasscutter.game.entity.EntityItem;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.expedition.ExpeditionInfo;
|
||||
import emu.grasscutter.game.friends.FriendsList;
|
||||
import emu.grasscutter.game.friends.PlayerProfile;
|
||||
import emu.grasscutter.game.gacha.PlayerGachaInfo;
|
||||
@@ -50,6 +51,7 @@ import emu.grasscutter.server.packet.send.*;
|
||||
import emu.grasscutter.utils.DateHelper;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import emu.grasscutter.utils.MessageHandler;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
@@ -101,6 +103,7 @@ public class Player {
|
||||
private ArrayList<AvatarProfileData> shownAvatars;
|
||||
private Set<Integer> rewardedLevels;
|
||||
private ArrayList<ShopLimit> shopLimit;
|
||||
private Map<Long, ExpeditionInfo> expeditionInfo;
|
||||
|
||||
private int sceneId;
|
||||
private int regionId;
|
||||
@@ -170,6 +173,7 @@ public class Player {
|
||||
this.moonCardGetTimes = new HashSet<>();
|
||||
|
||||
this.shopLimit = new ArrayList<>();
|
||||
this.expeditionInfo = new HashMap<>();
|
||||
this.messageHandler = null;
|
||||
this.mapMarksManager = new MapMarksManager();
|
||||
this.movementManager = new MovementManager(this);
|
||||
@@ -673,6 +677,28 @@ public class Player {
|
||||
session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays()));
|
||||
}
|
||||
|
||||
public Map<Long, ExpeditionInfo> getExpeditionInfo() {
|
||||
return expeditionInfo;
|
||||
}
|
||||
|
||||
public void addExpeditionInfo(long avaterGuid, 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);
|
||||
}
|
||||
|
||||
public void removeExpeditionInfo(long avaterGuid){
|
||||
expeditionInfo.remove(avaterGuid);
|
||||
}
|
||||
|
||||
public ExpeditionInfo getExpeditionInfo(long avaterGuid){
|
||||
return expeditionInfo.get(avaterGuid);
|
||||
}
|
||||
|
||||
|
||||
public List<ShopLimit> getShopLimit() {
|
||||
return shopLimit;
|
||||
}
|
||||
@@ -1029,6 +1055,22 @@ public class Player {
|
||||
this.resetSendPlayerLocTime();
|
||||
}
|
||||
}
|
||||
// Expedition
|
||||
var timeNow = Utils.getCurrentSeconds();
|
||||
var needNotify = false;
|
||||
for (Long key : expeditionInfo.keySet()) {
|
||||
ExpeditionInfo e = expeditionInfo.get(key);
|
||||
if(e.getState() == 1){
|
||||
if(timeNow - e.getStartTime() >= e.getHourTime() * 60 * 60){
|
||||
e.setState(2);
|
||||
needNotify = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(needNotify){
|
||||
this.save();
|
||||
this.sendPacket(new PacketAvatarExpeditionDataNotify(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user