Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Maple2.Model/Game/User/SkillCooldown.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Maple2.PacketLib.Tools;
using Maple2.Tools;
using Maple2.Tools.Extensions;

namespace Maple2.Model.Game;

Expand All @@ -20,7 +21,7 @@ public SkillCooldown(int skillId, short level) {
public void WriteTo(IByteWriter writer) {
writer.WriteInt(SkillId);
writer.WriteInt(GroupId);
writer.WriteInt((int) EndTick);
writer.WriteInt(EndTick.Truncate32());
writer.WriteInt(Charges);
}
}
6 changes: 3 additions & 3 deletions Maple2.Server.Game/Manager/BuffManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,19 @@ public void RemoveItemBuffs(Item item) {
Remove(buffsToRemove.ToArray());
}

public void SetCacheBuffs(IList<BuffInfo> buffs, long currentTick) {
public void SetCacheBuffs(IList<BuffInfo> cacheBuffs, long currentTick) {
if (Actor is not FieldPlayer player) {
return;
}

foreach (BuffInfo info in buffs) {
foreach (BuffInfo info in cacheBuffs) {
if (!player.Field.SkillMetadata.TryGetEffect(info.Id, (short) info.Level, out AdditionalEffectMetadata? additionalEffect)) {
logger.Error("Invalid buff: {SkillId},{Level}", info.Id, info.Level);
continue;
}

if (additionalEffect.Property.UseInGameTime || info.MsRemaining > 0) {
AddBuff(Actor, Actor, info.Id, (short) info.Level, currentTick, info.MsRemaining);
AddBuff(Actor, Actor, info.Id, (short) info.Level, currentTick, info.Stacks, info.MsRemaining);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Maple2.Server.Game/Manager/DungeonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void EnterInitField() {
}

if (firstField.DungeonRoomRecord.StartTick == 0) {
firstField.DungeonRoomRecord.StartTick = Environment.TickCount;
firstField.DungeonRoomRecord.StartTick = Lobby.FieldTick;
}
session.Send(session.PrepareField(firstField.MapId, roomId: firstField.RoomId) ? FieldEnterPacket.Request(session.Player) :
FieldEnterPacket.Error(MigrationError.s_move_err_default));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ public FieldPortal SpawnPortal(QuestSummonPortal metadata, FieldNpc npc, FieldPl
var fieldPortal = new FieldQuestPortal(owner, this, NextLocalId(), portal) {
Position = portal.Position,
Rotation = portal.Rotation,
EndTick = (int) (FieldTick + TimeSpan.FromSeconds(Constant.QuestPortalKeepTime).TotalMilliseconds),
StartTick = (int) FieldTick,
EndTick = (FieldTick + (long) TimeSpan.FromSeconds(Constant.QuestPortalKeepTime).TotalMilliseconds).Truncate32(),
StartTick = FieldTickInt,
Model = Constant.QuestPortalKeepNif,
};
fieldPortals[fieldPortal.ObjectId] = fieldPortal;
Expand Down Expand Up @@ -625,7 +625,7 @@ private void SetBonusMapPortal(IList<MapMetadata> bonusMaps, Ms2RegionSpawn spaw
Continent.Kritias => "Eff_ks_magichole_portal_A01",
_ => "Eff_event_portal_A01",
};
fieldPortal.EndTick = (int) (FieldTick + TimeSpan.FromSeconds(30).TotalMilliseconds);
fieldPortal.EndTick = (FieldTick + (long) TimeSpan.FromSeconds(30).TotalMilliseconds).Truncate32();
Broadcast(PortalPacket.Add(fieldPortal));
Scheduler.Schedule(() => SetBonusMapPortal(bonusMaps, spawn), delay);
}
Expand Down
7 changes: 7 additions & 0 deletions Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ public virtual void Init() {
// Use this to keep systems in sync. Do not use Environment.TickCount directly
public long FieldTick { get; private set; }

/// <summary>
/// FieldTick truncated to 32-bit int. Use this when sending tick values to the client or when
/// int tick values are required (e.g., TimeSync packets, performance stage).
/// This properly handles overflow to match Environment.TickCount behavior.
/// </summary>
public int FieldTickInt => FieldTick.Truncate32();

public void QueuePacket(FieldPacketHandler handler, GameSession session, ByteReader reader) {
lock (queuedPackets) {
queuedPackets.Add((handler, session, reader));
Expand Down
1 change: 1 addition & 0 deletions Maple2.Server.Game/Manager/Field/FieldManager/IField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public interface IField : IDisposable {

public int MapId { get; init; }
public long FieldTick { get; }
public int FieldTickInt { get; }
public virtual void Init() { }

public void AddSkill(SkillMetadata metadata, int interval, in Vector3 position, in Vector3 rotation = default, int triggerId = 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Maple2.Model.Game;
using Maple2.Server.Game.Model;
using Maple2.Server.Game.Session;
using Maple2.Tools.Extensions;
using Serilog;

namespace Maple2.Server.Game.Manager.Field;
Expand Down
2 changes: 1 addition & 1 deletion Maple2.Server.Game/Manager/FishingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public FishingError Start(Vector3 position) {
fishingTick = Random.Shared.Next(fishingTick + 1, fishingTick * 2); // If tick is over bore duration, it will fail
}

session.Send(FishingPacket.Start(((int) session.Field.FieldTick) + fishingTick, fishFightGame));
session.Send(FishingPacket.Start((session.Field.FieldTick + fishingTick).Truncate32(), fishFightGame));

return FishingError.none;
}
Expand Down
5 changes: 3 additions & 2 deletions Maple2.Server.Game/Model/Field/Buff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Util;
using Maple2.Tools;
using Maple2.Tools.Extensions;
using Serilog;

namespace Maple2.Server.Game.Model;
Expand Down Expand Up @@ -318,8 +319,8 @@ public void WriteTo(IByteWriter writer) {
}

public void WriteAdditionalEffect(IByteWriter writer) {
writer.WriteInt((int) StartTick);
writer.WriteInt((int) EndTick);
writer.WriteInt(StartTick.Truncate32());
writer.WriteInt(EndTick.Truncate32());
writer.WriteInt(Id);
writer.WriteShort(Level);
writer.WriteInt(Stacks);
Expand Down
9 changes: 5 additions & 4 deletions Maple2.Server.Game/Packets/BreakablePacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.Model;
using Maple2.Tools.Extensions;

namespace Maple2.Server.Game.Packets;

Expand All @@ -23,8 +24,8 @@ public static ByteWriter Update(ICollection<FieldBreakable> breakables) {
pWriter.Write<BreakableState>(breakable.State);
pWriter.WriteBool(breakable.Visible);
if (breakable.BaseTick > 0) {
pWriter.WriteInt((int) (currentTick - breakable.BaseTick));
pWriter.WriteInt((int) breakable.BaseTick);
pWriter.WriteInt((currentTick - breakable.BaseTick).Truncate32());
pWriter.WriteInt(breakable.BaseTick.Truncate32());
} else {
pWriter.WriteInt();
pWriter.WriteInt();
Expand All @@ -41,8 +42,8 @@ public static ByteWriter Update(FieldBreakable breakable) {
pWriter.Write<BreakableState>(breakable.State);
pWriter.WriteBool(breakable.Visible);
if (breakable.BaseTick > 0) {
pWriter.WriteInt((int) (Environment.TickCount64 - breakable.BaseTick));
pWriter.WriteInt((int) breakable.BaseTick);
pWriter.WriteInt((Environment.TickCount64 - breakable.BaseTick).Truncate32());
pWriter.WriteInt(breakable.BaseTick.Truncate32());
} else {
pWriter.WriteInt();
pWriter.WriteInt();
Expand Down
2 changes: 1 addition & 1 deletion Maple2.Server.Game/Packets/InstrumentPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static ByteWriter StartScore(FieldInstrument instrument, Item score) {
pWriter.WriteInt(instrument.ObjectId);
pWriter.WriteInt(instrument.OwnerId);
pWriter.Write<Vector3>(instrument.Position);
pWriter.WriteInt((int) instrument.StartTick);
pWriter.WriteInt(instrument.StartTick.Truncate32());
pWriter.WriteInt(instrument.Value.MidiId);
pWriter.WriteInt(instrument.Value.PercussionId);
pWriter.WriteBool(instrument.Ensemble);
Expand Down
3 changes: 2 additions & 1 deletion Maple2.Server.Game/Packets/RegionSkillPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.Model;
using Maple2.Tools.Extensions;

namespace Maple2.Server.Game.Packets;

Expand All @@ -17,7 +18,7 @@ public static ByteWriter Add(FieldSkill fieldSkill) {
pWriter.Write<Command>(Command.Add);
pWriter.WriteInt(fieldSkill.ObjectId);
pWriter.WriteInt(fieldSkill.Caster.ObjectId);
pWriter.WriteInt((int) fieldSkill.NextTick);
pWriter.WriteInt(fieldSkill.NextTick.Truncate32());
pWriter.WriteByte((byte) fieldSkill.Points.Length);
foreach (Vector3 point in fieldSkill.Points) {
pWriter.Write<Vector3>(point);
Expand Down
38 changes: 22 additions & 16 deletions Maple2.Server.Game/Session/GameSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Maple2.Server.Game.Util;
using Maple2.Server.Game.Util.Sync;
using Maple2.Server.World.Service;
using Maple2.Tools.Extensions;
using Maple2.Tools.Scheduler;
using MigrationType = Maple2.Model.Enum.MigrationType;
using WorldClient = Maple2.Server.World.Service.World.WorldClient;
Expand Down Expand Up @@ -809,28 +810,33 @@ void SaveCacheConfig() {

long stopTime = DateTime.Now.ToEpochSeconds();
long fieldTick = fieldTickSnapshot;

try {
PlayerConfigResponse _ = World.PlayerConfig(new PlayerConfigRequest {
Save = new PlayerConfigRequest.Types.Save {
Buffs = {
buffs.Select(buff => new BuffInfo {
Id = buff.Id,
Level = buff.Level,
MsRemaining = (int) (buff.EndTick - fieldTick),
Stacks = buff.Stacks,
Enabled = buff.Enabled,
StopTime = stopTime,
}),
buffs
.Where(buff => buff.EndTick - fieldTick > 0)
.Select(buff => new BuffInfo {
Id = buff.Id,
Level = buff.Level,
MsRemaining = (buff.EndTick - fieldTick).Truncate32(),
Stacks = buff.Stacks,
Enabled = buff.Enabled,
StopTime = stopTime,
}),
},
SkillCooldowns = {
skillCooldowns.Select(cooldown => new SkillCooldownInfo {
SkillId = cooldown.SkillId,
SkillLevel = cooldown.Level,
GroupId = cooldown.GroupId,
MsRemaining = (int) (cooldown.EndTick - fieldTick),
StopTime = stopTime,
Charges = cooldown.Charges,
}),
skillCooldowns
.Where(cooldown => cooldown.EndTick - fieldTick > 0)
.Select(cooldown => new SkillCooldownInfo {
SkillId = cooldown.SkillId,
SkillLevel = cooldown.Level,
GroupId = cooldown.GroupId,
MsRemaining = (cooldown.EndTick - fieldTick).Truncate32(),
StopTime = stopTime,
Charges = cooldown.Charges,
}),
},
DeathInfo = new DeathInfo {
Count = Config.DeathCount,
Expand Down
Loading
Loading