diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index da42f6c..fee0ac6 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -2243,6 +2243,13 @@ void Human::AddItem(int item_id, int item_num) #if 0 room->frame_event.AddItemChg(GetWeakPtrRef(), item_id, items_[item_id]); #endif + if (IsPlayer()) { + cs::SMGetItemNotify notify_msg; + auto pair = notify_msg.add_items(); + pair->set_key(item_id); + pair->set_value(item_num); + SendNotifyMsg(notify_msg); + } } else { if (item_num <= 0) { battling_items_.insert(item_id); diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index a146380..8f22bec 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -481,6 +481,7 @@ void Player::ProcInteraction() if (HasBuffEffect(kBET_Jump)) { return; } + cs::SMGetItemNotify notify_msg; for (auto obj_id : interaction_objids) { Entity* entity = room->GetEntityByUniId(obj_id); #ifdef DEBUG @@ -504,7 +505,26 @@ void Player::ProcInteraction() if (entity->GetPos().Distance(GetPos()) > 150) { break; } - LootInteraction((Loot*)entity); + Loot* loot = (Loot*)entity; + int old_count = loot->count; + LootInteraction(loot); + if (loot->pickuped || loot->count < old_count) { + bool real_get_count = loot->count < old_count ? old_count - loot->count : loot->count; + bool found = false; + for (int i = 0; i < notify_msg.items().size(); ++i) { + auto pair = notify_msg.mutable_items(i); + if (pair->key() == loot->item_id) { + pair->set_value(pair->value() + real_get_count); + found = true; + break; + } + } + if (!found) { + auto pair = notify_msg.add_items(); + pair->set_key(loot->item_id); + pair->set_value(real_get_count); + } + } } break; case ET_Player: @@ -524,6 +544,9 @@ void Player::ProcInteraction() } } interaction_objids.Clear(); + if (notify_msg.items().size() > 0) { + SendNotifyMsg(notify_msg); + } } void Player::ObstacleInteraction(Obstacle* entity) diff --git a/server/tools/protobuild/cs_msgid.proto b/server/tools/protobuild/cs_msgid.proto index 6ad186b..2d9cf2d 100644 --- a/server/tools/protobuild/cs_msgid.proto +++ b/server/tools/protobuild/cs_msgid.proto @@ -55,4 +55,5 @@ enum SMMessageId_e _SMShowCountdown = 1015; _SMShowTeamUI = 1016; _SMUpdateMatchInfo = 1017; + _SMGetItemNotify = 1018; } diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index 8238adb..b31ee33 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -1336,3 +1336,9 @@ message SMUpdateMatchInfo { optional MFMatchInfo info = 1; //匹配信息 } + +//获得物品 +message SMGetItemNotify +{ + repeated MFPair items = 8; //key:道具id value:数量 +} \ No newline at end of file