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
17 changes: 17 additions & 0 deletions Maple2.Server.Game/Manager/Field/FieldManager.State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class FieldManager {
private readonly ConcurrentDictionary<string, FieldInteract> fieldInteracts = new();
private readonly ConcurrentDictionary<string, FieldFunctionInteract> fieldFunctionInteracts = new();
private readonly ConcurrentDictionary<string, FieldInteract> fieldAdBalloons = new();
private readonly ConcurrentDictionary<int, FieldInstrument> fieldInstruments = new();
private readonly ConcurrentDictionary<int, FieldItem> fieldItems = new();
private readonly ConcurrentDictionary<int, FieldMobSpawn> fieldMobSpawns = new();
private readonly ConcurrentDictionary<int, FieldSkill> fieldSkills = new();
Expand Down Expand Up @@ -499,6 +500,8 @@ public FieldInstrument SpawnInstrument(IActor<Player> owner, InstrumentMetadata
Rotation = owner.Rotation,
};

fieldInstruments[fieldInstrument.ObjectId] = fieldInstrument;

return fieldInstrument;
}

Expand Down Expand Up @@ -637,6 +640,15 @@ public bool RemovePortal(int objectId) {
Broadcast(PortalPacket.Remove(portal.Value.Id));
return true;
}

public bool RemoveInstrument(int objectId) {
if (!fieldInstruments.TryRemove(objectId, out FieldInstrument? instrument)) {
return false;
}

Broadcast(InstrumentPacket.StopScore(instrument));
return true;
}
#endregion

#region Events
Expand All @@ -649,6 +661,11 @@ public void OnAddPlayer(FieldPlayer added) {
foreach (FieldInteract fieldInteract in fieldAdBalloons.Values) {
added.Session.Send(InteractObjectPacket.Add(fieldInteract.Object));
}
foreach (FieldInstrument fieldInstrument in fieldInstruments.Values) {
if (fieldInstrument.Score != null) {
added.Session.Send(InstrumentPacket.StartScore(fieldInstrument, fieldInstrument.Score));
}
}
if (MapId is Constant.DefaultHomeMapId) {
IEnumerable<PlotCube> interactCubes = Plots.FirstOrDefault().Value.Cubes.Values
.Where(x => x.ItemType.IsInteractFurnishing && x.HousingCategory is not HousingCategory.Ranching and not HousingCategory.Farming);
Expand Down
2 changes: 1 addition & 1 deletion Maple2.Server.Game/Manager/ShopManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public void Buy(int shopItemId, int quantity) {
}
}

if (quantity > shopItem.StockCount - shopItem.StockPurchased) {
if (shopItem.StockCount != 0 && quantity > shopItem.StockCount - shopItem.StockPurchased) {
session.Send(ShopPacket.Error(ShopError.s_err_lack_shopitem));
return;
}
Expand Down
4 changes: 3 additions & 1 deletion Maple2.Server.Game/Model/Field/Entity/FieldInstrument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Maple2.Model.Metadata;
using Maple2.Model.Game;
using Maple2.Model.Metadata;
using Maple2.Server.Game.Manager.Field;

namespace Maple2.Server.Game.Model;
Expand All @@ -8,5 +9,6 @@ public class FieldInstrument(FieldManager field, int objectId, InstrumentMetadat
public bool Improvising { get; set; }
public long StartTick { get; set; }
public bool Ensemble { get; set; }
public Item? Score { get; set; }

}
5 changes: 3 additions & 2 deletions Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private void HandleStartScore(GameSession session, IByteReader packet) {
if (!TryUseInstrument(session, itemUid, Environment.TickCount64, false, out session.Instrument)) {
return;
}
session.Instrument.Score = score;

score.RemainUses--;
session.Field.Broadcast(InstrumentPacket.StartScore(session.Instrument, score));
Expand Down Expand Up @@ -168,7 +169,7 @@ private void HandleStopScore(GameSession session) {
// Modifier is the number of 500ms ticks that have passed.
session.Exp.AddExp(expType, (totalTickTime - 500) / 500);

session.Field.Broadcast(InstrumentPacket.StopScore(session.Instrument));
session.Field.RemoveInstrument(session.Instrument.ObjectId);
session.Instrument = null;
}

Expand Down Expand Up @@ -333,7 +334,7 @@ private bool TryUseInstrument(GameSession session, long itemUid, long startTick,
return false;
}

fieldInstrument = session.Field!.SpawnInstrument(session.Player, metadata);
fieldInstrument = session.Field.SpawnInstrument(session.Player, metadata);
fieldInstrument.StartTick = startTick;
fieldInstrument.Ensemble = ensemble;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected override void Up(MigrationBuilder migrationBuilder) {
name: "InteriorRewardsClaimed",
table: "home",
type: "json",
defaultValue: "[]",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
}
Expand Down