[Fix] ContentGameTimeTick implenentation in some special cases

* also cleanup HandlerAddQuestContentProgressReq method
This commit is contained in:
hartie95 2023-01-21 04:02:44 +01:00
parent d8c3ed3b85
commit f373884967
2 changed files with 15 additions and 20 deletions

View File

@ -22,12 +22,16 @@ public class ContentGameTimeTick extends BaseContent {
val daysToPass = condition.getParam()[0];
val isTimeMeet = from < to ? currentHour >= from && currentHour <= to
: currentHour <= to || currentHour >= from;
// if to is at the beginning of the day, we need to pass it one more time
val daysMod = to < from && daysToPass > 0 && currentHour < to ? 1 : 0;
val isDaysSinceMet = daysSinceStart >= daysToPass;
val isTimeMet = from < to ? currentHour >= from && currentHour < to
: currentHour < to || currentHour >= from;
return isTimeMeet && isDaysSinceMet;
val isDaysSinceMet = daysSinceStart >= daysToPass+daysMod;
return isTimeMet && isDaysSinceMet;
}
}

View File

@ -1,34 +1,25 @@
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.QuestData;
import emu.grasscutter.game.quest.enums.QuestCond;
import emu.grasscutter.game.quest.enums.QuestContent;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AddQuestContentProgressReqOuterClass;
import emu.grasscutter.net.proto.AddQuestContentProgressReqOuterClass.AddQuestContentProgressReq;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketAddQuestContentProgressRsp;
import java.util.List;
import java.util.stream.Stream;
import lombok.val;
@Opcodes(PacketOpcodes.AddQuestContentProgressReq)
public class HandlerAddQuestContentProgressReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = AddQuestContentProgressReqOuterClass.AddQuestContentProgressReq.parseFrom(payload);
var req = AddQuestContentProgressReq.parseFrom(payload);
//Find all conditions in quest that are the same as the given one
Stream<QuestData.QuestAcceptCondition> acceptCond = GameData.getQuestDataMap().get(req.getParam()).getAcceptCond().stream();
Stream<QuestData.QuestContentCondition> finishCond = GameData.getQuestDataMap().get(req.getParam()).getFinishCond().stream();
Stream<QuestData.QuestContentCondition> failCond = GameData.getQuestDataMap().get(req.getParam()).getFailCond().stream();
List<QuestData.QuestContentCondition> allCondMatch = Stream.concat(failCond,finishCond).filter(p -> p.getType().getValue() == req.getContentType()).toList();
for (QuestData.QuestContentCondition cond : allCondMatch ) {
session.getPlayer().getQuestManager().queueEvent(QuestContent.getContentTriggerByValue(req.getContentType()), cond.getParam());
}
for (QuestData.QuestAcceptCondition cond : acceptCond.toList() ) {
session.getPlayer().getQuestManager().queueEvent(QuestCond.getContentTriggerByValue(req.getContentType()), cond.getParam());
val type = QuestContent.getContentTriggerByValue(req.getContentType());
if(type!=null) {
session.getPlayer().getQuestManager().queueEvent(type, req.getParam());
}
session.send(new PacketAddQuestContentProgressRsp(req.getContentType()));
}