diff --git a/src/game_party.cpp b/src/game_party.cpp index 9696eb9e1..01085da81 100644 --- a/src/game_party.cpp +++ b/src/game_party.cpp @@ -202,6 +202,7 @@ void Game_Party::AddItem(int item_id, int amount) { } int total_items = data.item_counts[idx] + amount; + GMI().ItemSet(item_id, total_items); if (total_items <= 0) { data.item_ids.erase(data.item_ids.begin() + idx); diff --git a/src/multiplayer/game_multiplayer.cpp b/src/multiplayer/game_multiplayer.cpp index ccd8688e9..c567b3a45 100644 --- a/src/multiplayer/game_multiplayer.cpp +++ b/src/multiplayer/game_multiplayer.cpp @@ -213,6 +213,15 @@ void Game_Multiplayer::InitConnection() { sync_action_events.push_back(p.event_id); } }); + connection.RegisterHandler("si", [this] (SyncItemPacket& p) { + int count = (int) Main_Data::game_party->GetItemCount(p.item_id); + if (p.sync_type != -1) { + connection.SendPacketAsync(p.item_id, count); + } + if (p.sync_type >= -1) { + sync_items.push_back(p.item_id); + } + }); connection.RegisterHandler("sp", [this] (SyncPicturePacket& p) { sync_picture_names.push_back(p.picture_name); }); @@ -535,6 +544,7 @@ void Game_Multiplayer::Initialize() { players.clear(); sync_switches.clear(); sync_vars.clear(); + sync_items.clear(); sync_events.clear(); sync_action_events.clear(); sync_picture_names.clear(); @@ -767,6 +777,12 @@ void Game_Multiplayer::VariableSet(int var_id, int value) { } } +void Game_Multiplayer::ItemSet(int item_id, int count) { + if (std::find(sync_items.begin(), sync_items.end(), item_id) != sync_items.end()) { + connection.SendPacketAsync(item_id, count); + } +} + void Game_Multiplayer::ApplyScreenTone() { ApplyTone(Main_Data::game_screen->GetTone()); } diff --git a/src/multiplayer/game_multiplayer.h b/src/multiplayer/game_multiplayer.h index c3435c3a3..d4dbd9ad0 100644 --- a/src/multiplayer/game_multiplayer.h +++ b/src/multiplayer/game_multiplayer.h @@ -47,6 +47,7 @@ class Game_Multiplayer { void ApplyScreenTone(); void SwitchSet(int switch_id, int value); void VariableSet(int var_id, int value); + void ItemSet(int item_id, int count); void UpdateNBPlayers(); void UpdateCUTime(); void UpdateCUWeather(); @@ -101,6 +102,7 @@ class Game_Multiplayer { std::vector dc_players; std::vector sync_switches; std::vector sync_vars; + std::vector sync_items; std::vector sync_events; std::vector sync_action_events; std::vector sync_picture_names; // for badge conditions diff --git a/src/multiplayer/messages.h b/src/multiplayer/messages.h index 9a4ebbccc..2bdc2e1ed 100644 --- a/src/multiplayer/messages.h +++ b/src/multiplayer/messages.h @@ -331,6 +331,15 @@ namespace S2C { const int trigger_type; }; + class SyncItemPacket : public S2CPacket { + public: + SyncItemPacket(const PL& v) + : item_id(Decode(v.at(0))), sync_type(Decode(v.at(1))) {} + + const int item_id; + const int sync_type; + }; + class SyncPicturePacket : public S2CPacket { public: SyncPicturePacket(const PL& v) @@ -616,6 +625,15 @@ namespace C2S { int action_bin; }; + class SyncItemPacket : public C2SPacket { + public: + SyncItemPacket(int _item_id, int _count) : C2SPacket("si"), + item_id(_item_id), count(_count) {} + std::string ToBytes() const override { return Build(item_id, count); } + protected: + int item_id; + int count; + }; } }