1
0
forked from akanyan/mu3-mods
Files
mu3-mods/Unlockers/UnlockGameEvents/MU3.Client/patch_PacketGetGameEvent.cs
akanyan fefadfc243 fix(UnlockGameEvents): rework mission event cycling
* Iterate in reverse, from latest to oldest.
* Unlock all missions again, unless the server has returned
  exactly one active mission and that mission is present
  on the client's machine..
2025-01-24 20:20:37 +00:00

61 lines
2.2 KiB
C#

using MU3.Data;
using MU3.Operation;
using MU3.Util;
using System;
using System.Linq;
namespace MU3.Client;
class patch_PacketGetGameEvent: Packet {
private Operation.GameEvent _gameEvent;
public extern State orig_proc();
public override State proc() {
State state = orig_proc();
if(state == State.Done) {
DateTime endDate = DateTime.Parse("2099-01-01 05:00:00.0");
_gameEvent ??= new Operation.GameEvent();
bool skipMissions = checkMissionEvents();
foreach(EventData eventData in SingletonStateMachine<DataManager, DataManager.EState>.instance.allEventData) {
IdPeriod idPeriod = Enumerable.FirstOrDefault(_gameEvent.list, (IdPeriod e) => e.id == eventData.id);
if(skipMissions && eventData.itemType == DataStudio.EventType.MissionEvent) {
continue;
}
if(idPeriod != null) {
if(idPeriod.period.endDate < CustomDateTime.Now) {
idPeriod.period.endDate = endDate;
}
} else {
idPeriod = new() {
id = eventData.id,
period = new Period(DateTime.MinValue.Date, endDate)
};
_gameEvent.list.Add(idPeriod);
_gameEvent.lastUpdate = CustomDateTime.Now;
}
}
}
return state;
}
// Check whether there is only one active mission event
private bool checkMissionEvents() {
bool found = false;
foreach(EventData eventData in SingletonStateMachine<DataManager, DataManager.EState>.instance.allEventData) {
if(eventData.itemType == DataStudio.EventType.MissionEvent) {
IdPeriod idPeriod = Enumerable.FirstOrDefault(_gameEvent.list, (IdPeriod e) => e.id == eventData.id);
if(idPeriod?.period.startDate < CustomDateTime.Now && idPeriod?.period.endDate > CustomDateTime.Now) {
if(!found) {
found = true;
} else {
return false;
}
}
}
}
return found;
}
}