Skip to content
Open
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
1 change: 1 addition & 0 deletions src/game_party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/multiplayer/game_multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ void Game_Multiplayer::InitConnection() {
sync_action_events.push_back(p.event_id);
}
});
connection.RegisterHandler<SyncItemPacket>("si", [this] (SyncItemPacket& p) {
int count = (int) Main_Data::game_party->GetItemCount(p.item_id);
if (p.sync_type != -1) {
connection.SendPacketAsync<Messages::C2S::SyncItemPacket>(p.item_id, count);
}
if (p.sync_type >= -1) {
sync_items.push_back(p.item_id);
}
});
connection.RegisterHandler<SyncPicturePacket>("sp", [this] (SyncPicturePacket& p) {
sync_picture_names.push_back(p.picture_name);
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<Messages::C2S::SyncItemPacket>(item_id, count);
}
}

void Game_Multiplayer::ApplyScreenTone() {
ApplyTone(Main_Data::game_screen->GetTone());
}
Expand Down
2 changes: 2 additions & 0 deletions src/multiplayer/game_multiplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -101,6 +102,7 @@ class Game_Multiplayer {
std::vector<PlayerOther> dc_players;
std::vector<int> sync_switches;
std::vector<int> sync_vars;
std::vector<int> sync_items;
std::vector<int> sync_events;
std::vector<int> sync_action_events;
std::vector<std::string> sync_picture_names; // for badge conditions
Expand Down
18 changes: 18 additions & 0 deletions src/multiplayer/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ namespace S2C {
const int trigger_type;
};

class SyncItemPacket : public S2CPacket {
public:
SyncItemPacket(const PL& v)
: item_id(Decode<int>(v.at(0))), sync_type(Decode<int>(v.at(1))) {}

const int item_id;
const int sync_type;
};

class SyncPicturePacket : public S2CPacket {
public:
SyncPicturePacket(const PL& v)
Expand Down Expand Up @@ -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;
};
}
}

Expand Down
Loading