From 8104378b9586ae0602fd4fdc3ae6d8bebf707e3b Mon Sep 17 00:00:00 2001 From: GanyusLeftHorn <1244229+GanyusLeftHorn@users.noreply.github.com> Date: Mon, 27 Jun 2022 00:54:17 -0700 Subject: [PATCH] Add daily and weekly mission reset. --- .../game/battlepass/BattlePassManager.java | 45 +++++++++++++++++-- .../game/battlepass/BattlePassMission.java | 4 ++ .../emu/grasscutter/game/player/Player.java | 14 +++++- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java b/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java index 167d5a027..017d3366d 100644 --- a/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java +++ b/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java @@ -1,5 +1,12 @@ package emu.grasscutter.game.battlepass; +import java.time.DayOfWeek; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,6 +39,7 @@ import emu.grasscutter.net.proto.BattlePassScheduleOuterClass.BattlePassSchedule import emu.grasscutter.server.packet.send.PacketBattlePassCurScheduleUpdateNotify; import emu.grasscutter.server.packet.send.PacketBattlePassMissionUpdateNotify; import emu.grasscutter.server.packet.send.PacketTakeBattlePassRewardRsp; +import emu.grasscutter.utils.Utils; import lombok.Getter; @Entity(value = "battlepass", useDiscriminator = false) @@ -255,15 +263,42 @@ public class BattlePassManager { } public void resetDailyMissions() { - // TODO + var resetMissions = new ArrayList(); + + for (var mission : this.missions.values()) { + if (mission.getData().getRefreshType() == null || mission.getData().getRefreshType() == BattlePassMissionRefreshType.BATTLE_PASS_MISSION_REFRESH_DAILY) { + mission.setStatus(BattlePassMissionStatus.MISSION_STATUS_UNFINISHED); + mission.setProgress(0); + + resetMissions.add(mission); + } + } + + this.getPlayer().sendPacket(new PacketBattlePassMissionUpdateNotify(resetMissions)); + this.getPlayer().sendPacket(new PacketBattlePassCurScheduleUpdateNotify(this.getPlayer())); } public void resetWeeklyMissions() { - // TODO + var resetMissions = new ArrayList(); + + for (var mission : this.missions.values()) { + if (mission.getData().getRefreshType() == BattlePassMissionRefreshType.BATTLE_PASS_MISSION_REFRESH_CYCLE_CROSS_SCHEDULE) { + mission.setStatus(BattlePassMissionStatus.MISSION_STATUS_UNFINISHED); + mission.setProgress(0); + + resetMissions.add(mission); + } + } + + this.getPlayer().sendPacket(new PacketBattlePassMissionUpdateNotify(resetMissions)); + this.getPlayer().sendPacket(new PacketBattlePassCurScheduleUpdateNotify(this.getPlayer())); } // public BattlePassSchedule getScheduleProto() { + var nextSundayDate = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.SUNDAY)); + var nextSundayTime = LocalDateTime.of(nextSundayDate.getYear(), nextSundayDate.getMonthValue(), nextSundayDate.getDayOfMonth(), 23, 59, 59); + BattlePassSchedule.Builder schedule = BattlePassSchedule.newBuilder() .setScheduleId(2700) .setLevel(this.getLevel()) @@ -274,7 +309,11 @@ public class BattlePassManager { .setUnlockStatus(this.isPaid() ? BattlePassUnlockStatus.BATTLE_PASS_UNLOCK_STATUS_PAID : BattlePassUnlockStatus.BATTLE_PASS_UNLOCK_STATUS_FREE) .setJPFMGBEBBBJ(2) // Not bought on Playstation. .setCurCyclePoints(this.getCyclePoints()) - .setCurCycle(BattlePassCycle.newBuilder().setBeginTime(0).setEndTime(2059483200).setCycleIdx(3)); + .setCurCycle(BattlePassCycle.newBuilder() + .setBeginTime(0) + .setEndTime((int)nextSundayTime.atZone(ZoneId.systemDefault()).toEpochSecond()) + .setCycleIdx(3) + ); for (BattlePassReward reward : getTakenRewards().values()) { schedule.addRewardTakenList(reward.toProto()); diff --git a/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java b/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java index be870b911..cb47d7d47 100644 --- a/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java +++ b/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java @@ -37,6 +37,10 @@ public class BattlePassMission { return progress; } + public void setProgress(int value) { + this.progress = value; + } + public void addProgress(int addProgress, int maxProgress) { this.progress = Math.min(addProgress + this.progress, maxProgress); } diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 17d35d103..1b486ad97 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -77,6 +77,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.Getter; +import java.time.DayOfWeek; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; @@ -1368,7 +1369,7 @@ public class Player { this.getResinManager().rechargeResin(); } - private void doDailyReset() { + private synchronized void doDailyReset() { // Check if we should execute a daily reset on this tick. int currentTime = Utils.getCurrentSeconds(); @@ -1383,6 +1384,14 @@ public class Player { // Reset forge points. this.setForgePoints(300_000); + // Reset daily BP missions. + this.getBattlePassManager().resetDailyMissions(); + + // Reset weekly BP missions. + if (currentDate.getDayOfWeek() == DayOfWeek.MONDAY) { + this.getBattlePassManager().resetWeeklyMissions(); + } + // Done. Update last reset time. this.setLastDailyReset(currentTime); } @@ -1455,6 +1464,9 @@ public class Player { this.setProperty(PlayerProperty.PROP_PLAYER_MP_SETTING_TYPE, this.getMpSetting().getNumber(), false); this.setProperty(PlayerProperty.PROP_IS_MP_MODE_AVAILABLE, 1, false); + // Execute daily reset logic if this is a new day. + this.doDailyReset(); + // Packets session.send(new PacketPlayerDataNotify(this)); // Player data session.send(new PacketStoreWeightLimitNotify());