diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 356f11e..db1b771 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -2146,9 +2146,9 @@ void Human::SendBattleReport() delete params; } -void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcLootSkin(AddItemDTO& dto) { - switch (item_meta->i->equip_subtype()) { + switch (dto.item_meta->i->equip_subtype()) { case 11: { //装饰 @@ -2161,7 +2161,7 @@ void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta, bool& handled } *old_skin = Skin(); - old_skin->skin_id = item_meta->i->id(); + old_skin->skin_id = dto.item_meta->i->id(); old_skin->skin_lv = 1; SyncAroundPlayers(__FILE__, __LINE__, __func__); } @@ -2179,37 +2179,37 @@ void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta, bool& handled } *old_skin = Skin(); - old_skin->skin_id = item_meta->i->id(); + old_skin->skin_id = dto.item_meta->i->id(); old_skin->skin_lv = 1; SyncAroundPlayers(__FILE__, __LINE__, __func__); } } break; } - handled = true; + dto.handled = true; } -void Human::ProcLootCar(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcLootCar(AddItemDTO& dto) { - DoGetOn(entity->GetUniId()); - handled = true; + DoGetOn(dto.uniid); + dto.handled = true; } -void Human::ProcCamoutflage(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcCamoutflage(AddItemDTO& dto) { - AddItem(item_meta->i->id(), 1); - handled = true; + AddItem(dto.item_meta->i->id(), 1); + dto.handled = true; } -void Human::ProcSpoils(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcSpoils(AddItemDTO& dto) { - if (spoils_items.find(item_meta->i->id()) != + if (spoils_items.find(dto.item_meta->i->id()) != spoils_items.end()) { - spoils_items[item_meta->i->id()] += entity->count; + spoils_items[dto.item_meta->i->id()] += dto.count; } else { - spoils_items[item_meta->i->id()] = entity->count; + spoils_items[dto.item_meta->i->id()] = dto.count; } - handled = true; + dto.handled = true; } void Human::OnDie() @@ -3153,119 +3153,15 @@ void Human::GMAddItem(int item_id, int item_num) if (!item_meta) { return; } - if (item_meta->i->equip_type() == EQUIP_TYPE_WEAPON) { - if (item_meta->i->equip_subtype() == 1) { - if (default_weapon.weapon_id != weapons[0].weapon_id) { - } else { - weapons[0].weapon_idx = 0; - weapons[0].weapon_id = item_id; - weapons[0].weapon_lv = std::max(1, 1); - weapons[0].ammo = 0; - weapons[0].meta = item_meta; - weapons[0].Recalc(); - } - } else { - Weapon* weapon = weapon = TakeonWeapon(item_meta); - if (weapon) { - if (GetCurrWeapon() != weapon) { - SetCurrWeapon(weapon); - } - weapon->weapon_id = item_id; - weapon->weapon_lv = std::max(1, 1); - weapon->ammo = 0; - weapon->meta = item_meta; - weapon->Recalc(); - } - } - } else { - if (item_meta->i->_inventory_slot() >= 0 && - item_meta->i->_inventory_slot() < IS_END) { - if (GetInventory(item_meta->i->_inventory_slot()) >= - GetVolume(item_meta->i->_inventory_slot()) - ) { - /* - cs::SMPickup notifymsg; - notifymsg.set_error_code(1); - SendNotifyMsg(notifymsg); - */ - return; - } - int add_num = GetVolume(item_meta->i->_inventory_slot()) - - GetInventory(item_meta->i->_inventory_slot()); - add_num = std::min(item_num, add_num); - - AddInventory(item_meta->i->_inventory_slot(), add_num); - switch (item_meta->i->_inventory_slot()) { - case IS_FRAG: - case IS_SMOKE: - { - Weapon* weapon = &weapons[SPEC1_SLOT_BEGIN + - (item_meta->i->_inventory_slot() - SPEC1_IS_BEGIN) - ]; - weapon->weapon_id = item_id; - weapon->weapon_lv = 1; - weapon->ammo += item_num; - weapon->meta = item_meta; - weapon->Recalc(); - DecInventory(item_meta->i->_inventory_slot(), add_num); - } - break; - case IS_1XSCOPE: - case IS_2XSCOPE: - case IS_4XSCOPE: - case IS_8XSCOPE: - case IS_15XSCOPE: - { - if (item_meta->i->_inventory_slot() - IS_1XSCOPE > curr_scope_idx) { - curr_scope_idx = item_meta->i->_inventory_slot() - IS_1XSCOPE; - } - } - break; - case IS_POSION_GAS_BOMB: - case IS_MOLOTOR_COCKTAIL: - case IS_TRAP: - case IS_MINE: - { - Weapon* weapon = &weapons[SPEC2_SLOT_BEGIN + - (item_meta->i->_inventory_slot() - SPEC2_IS_BEGIN) - ]; - weapon->weapon_id = item_id; - weapon->weapon_lv = 1; - weapon->ammo += item_num; - weapon->meta = item_meta; - weapon->Recalc(); - DecInventory(item_meta->i->_inventory_slot(), add_num); - } - break; - case IS_C4: - case IS_SHIELD_WALL: - case IS_SINGAL_GUN: - case IS_OIL_BUCKET: - { - Weapon* weapon = &weapons[SPEC3_SLOT_BEGIN + - (item_meta->i->_inventory_slot() - SPEC3_IS_BEGIN) - ]; - weapon->weapon_id = item_id; - weapon->weapon_lv = 1; - weapon->ammo += item_num; - weapon->meta = item_meta; - weapon->Recalc(); - DecInventory(item_meta->i->_inventory_slot(), add_num); - } - break; - default: - { -#if 0 - abort(); -#endif - } - break; - } - } else { - AddItem(item_id, item_num); - } - } + AddItemDTO dto; + dto.uniid = 0; + dto.item_id = item_id; + dto.count = item_num; + dto.item_level = 1; + dto.handled = false; + dto.item_meta = item_meta; need_sync_active_player = true; + SyncAroundPlayers(__FILE__, __LINE__, __func__); } @@ -3576,76 +3472,76 @@ void Human::StartRefreshViewTimer() }); } -void Human::ProcLootBag(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcLootBag(AddItemDTO& dto) { MetaData::Equip* old_item_meta = MetaMgr::Instance()->GetEquip(backpack); if (old_item_meta) { - if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) { + if (old_item_meta->i->equip_lv() >= dto.item_meta->i->equip_lv()) { return; } room->DropItem(GetPos(), old_item_meta->i->id(), 1, 1); } - backpack = item_meta->i->id(); + backpack = dto.item_meta->i->id(); RecalcVolume(); - handled = true; + dto.handled = true; } -void Human::ProcLootProtection(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcLootProtection(AddItemDTO& dto) { - if (item_meta->i->equip_subtype() == 1) { + if (dto.item_meta->i->equip_subtype() == 1) { //盔甲 MetaData::Equip* old_item_meta = MetaMgr::Instance()->GetEquip(chest); if (old_item_meta) { - if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) { + if (old_item_meta->i->equip_lv() >= dto.item_meta->i->equip_lv()) { return; } room->DropItem(GetPos(), old_item_meta->i->id(), 1, 1); } - chest = item_meta->i->id(); + chest = dto.item_meta->i->id(); RecalcBaseAttr(); - } else if (item_meta->i->equip_subtype() == 2) { + } else if (dto.item_meta->i->equip_subtype() == 2) { //头盔 MetaData::Equip* old_item_meta = MetaMgr::Instance()->GetEquip(helmet); if (old_item_meta) { - if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) { + if (old_item_meta->i->equip_lv() >= dto.item_meta->i->equip_lv()) { return; } room->DropItem(GetPos(), old_item_meta->i->id(), 1, 1); } - helmet = item_meta->i->id(); + helmet = dto.item_meta->i->id(); RecalcBaseAttr(); } - handled = true; + dto.handled = true; } -void Human::ProcLootSpecItem(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcLootSpecItem(AddItemDTO& dto) { - if (item_meta->i->_inventory_slot() >= 0 && - item_meta->i->_inventory_slot() < IS_END) { - if (GetInventory(item_meta->i->_inventory_slot()) >= - GetVolume(item_meta->i->_inventory_slot()) + if (dto.item_meta->i->_inventory_slot() >= 0 && + dto.item_meta->i->_inventory_slot() < IS_END) { + if (GetInventory(dto.item_meta->i->_inventory_slot()) >= + GetVolume(dto.item_meta->i->_inventory_slot()) ) { return; } - int add_num = GetVolume(item_meta->i->_inventory_slot()) - - GetInventory(item_meta->i->_inventory_slot()); - add_num = std::min(entity->count, add_num); + int add_num = GetVolume(dto.item_meta->i->_inventory_slot()) - + GetInventory(dto.item_meta->i->_inventory_slot()); + add_num = std::min(dto.count, add_num); - AddInventory(item_meta->i->_inventory_slot(), add_num); - switch (item_meta->i->_inventory_slot()) { + AddInventory(dto.item_meta->i->_inventory_slot(), add_num); + switch (dto.item_meta->i->_inventory_slot()) { case IS_FRAG: case IS_SMOKE: { Weapon* weapon = &weapons[SPEC1_SLOT_BEGIN + - (item_meta->i->_inventory_slot() - SPEC1_IS_BEGIN) + (dto.item_meta->i->_inventory_slot() - SPEC1_IS_BEGIN) ]; - weapon->weapon_id = entity->item_id; + weapon->weapon_id = dto.item_id; weapon->weapon_lv = 1; - weapon->ammo += entity->count; - weapon->meta = item_meta; + weapon->ammo += dto.count; + weapon->meta = dto.item_meta; weapon->Recalc(); #if 0 - DecInventory(item_meta->i->_inventory_slot(), add_num); + DecInventory(dto.item_meta->i->_inventory_slot(), add_num); #endif } break; @@ -3655,8 +3551,8 @@ void Human::ProcLootSpecItem(Loot* entity, MetaData::Equip* item_meta, bool& han case IS_8XSCOPE: case IS_15XSCOPE: { - if (item_meta->i->_inventory_slot() - IS_1XSCOPE > curr_scope_idx) { - curr_scope_idx = item_meta->i->_inventory_slot() - IS_1XSCOPE; + if (dto.item_meta->i->_inventory_slot() - IS_1XSCOPE > curr_scope_idx) { + curr_scope_idx = dto.item_meta->i->_inventory_slot() - IS_1XSCOPE; } } break; @@ -3666,15 +3562,15 @@ void Human::ProcLootSpecItem(Loot* entity, MetaData::Equip* item_meta, bool& han case IS_MINE: { Weapon* weapon = &weapons[SPEC2_SLOT_BEGIN + - (item_meta->i->_inventory_slot() - SPEC2_IS_BEGIN) + (dto.item_meta->i->_inventory_slot() - SPEC2_IS_BEGIN) ]; - weapon->weapon_id = entity->item_id; + weapon->weapon_id = dto.item_id; weapon->weapon_lv = 1; - weapon->ammo += entity->count; - weapon->meta = item_meta; + weapon->ammo += dto.count; + weapon->meta = dto.item_meta; weapon->Recalc(); #if 0 - DecInventory(item_meta->i->_inventory_slot(), add_num); + DecInventory(dto.item_meta->i->_inventory_slot(), add_num); #endif } break; @@ -3684,15 +3580,15 @@ void Human::ProcLootSpecItem(Loot* entity, MetaData::Equip* item_meta, bool& han case IS_OIL_BUCKET: { Weapon* weapon = &weapons[SPEC3_SLOT_BEGIN + - (item_meta->i->_inventory_slot() - SPEC3_IS_BEGIN) + (dto.item_meta->i->_inventory_slot() - SPEC3_IS_BEGIN) ]; - weapon->weapon_id = entity->item_id; + weapon->weapon_id = dto.item_id; weapon->weapon_lv = 1; - weapon->ammo += entity->count; - weapon->meta = item_meta; + weapon->ammo += dto.count; + weapon->meta = dto.item_meta; weapon->Recalc(); #if 0 - DecInventory(item_meta->i->_inventory_slot(), add_num); + DecInventory(dto.item_meta->i->_inventory_slot(), add_num); #endif } break; @@ -3705,10 +3601,13 @@ void Human::ProcLootSpecItem(Loot* entity, MetaData::Equip* item_meta, bool& han } break; } - if (add_num < entity->count) { + if (add_num < dto.count) { //刷新数量 - entity->count -= add_num; - entity->BroadcastFullState(room); + Entity* entity = room->GetEntityByUniId(dto.uniid); + if (entity && entity->IsEntityType(ET_Loot)) { + ((Loot*)entity)->count -= add_num; + ((Loot*)entity)->BroadcastFullState(room); + } return; } } @@ -3717,22 +3616,22 @@ void Human::ProcLootSpecItem(Loot* entity, MetaData::Equip* item_meta, bool& han } need_sync_active_player = true; SyncAroundPlayers(__FILE__, __LINE__, __func__); - handled = true; + dto.handled = true; } -void Human::ProcLootWeapon(Loot* entity, MetaData::Equip* item_meta, bool& handled) +void Human::ProcLootWeapon(AddItemDTO& dto) { //装备 - if (item_meta->i->equip_subtype() == 1) { + if (dto.item_meta->i->equip_subtype() == 1) { //近战 if (default_weapon.weapon_id != weapons[0].weapon_id) { return; } else { weapons[0].weapon_idx = 0; - weapons[0].weapon_id = entity->item_id; - weapons[0].weapon_lv = std::max(1, entity->item_level); + weapons[0].weapon_id = dto.item_id; + weapons[0].weapon_lv = std::max(1, dto.item_level); weapons[0].ammo = 0; - weapons[0].meta = item_meta; + weapons[0].meta = dto.item_meta; weapons[0].Recalc(); } need_sync_active_player = true; @@ -3742,17 +3641,17 @@ void Human::ProcLootWeapon(Loot* entity, MetaData::Equip* item_meta, bool& handl return; } bool switch_gun = false; - Weapon* weapon = TakeonWeapon(item_meta); + Weapon* weapon = TakeonWeapon(dto.item_meta); if (weapon && GetCurrWeapon() != weapon) { switch_gun = true; } if (!weapon) { return; } - weapon->weapon_id = entity->item_id; - weapon->weapon_lv = std::max(1, entity->item_level); + weapon->weapon_id = dto.item_id; + weapon->weapon_lv = std::max(1, dto.item_level); weapon->ammo = 0; - weapon->meta = item_meta; + weapon->meta = dto.item_meta; weapon->Recalc(); if (HasBuffEffect(kBET_Car)) { } else { @@ -3764,5 +3663,92 @@ void Human::ProcLootWeapon(Loot* entity, MetaData::Equip* item_meta, bool& handl need_sync_active_player = true; SyncAroundPlayers(__FILE__, __LINE__, __func__); } - handled = true; + dto.handled = true; +} + +void Human::LootInteraction(Loot* entity) +{ + if (entity->pickuped || + entity->count <= 0) { + return; + } + AddItemDTO dto; + dto.uniid = entity->GetUniId(); + dto.item_id = entity->item_id; + dto.count = entity->count; + dto.item_level = entity->item_level; + dto.handled = false; + dto.item_meta = MetaMgr::Instance()->GetEquip(entity->item_id); + + if (dto.handled) { + entity->pickuped = true; + room->RemoveObjectLater(entity); + if (entity->dummy_thing_uniid != 0) { + Entity* dummy_obj = room->GetEntityByUniId(entity->dummy_thing_uniid); + if (dummy_obj && dummy_obj->GetEntityType() == ET_Obstacle) { + Obstacle* obstacle = (Obstacle*)dummy_obj; + if (!obstacle->IsPermanent()) { + if (!obstacle->IsDead(room)) { + obstacle->Die(room); + obstacle->BroadcastFullState(room); + } + room->RemoveObjectLater((RoomObstacle*)obstacle); + } + } + } + } +} + +void Human::ProcAddItemDto(AddItemDTO& dto) +{ + if (!dto.item_meta) { + return; + } + switch (dto.item_meta->i->equip_type()) { + case EQUIP_TYPE_WEAPON: + { + ProcLootWeapon(dto); + } + break; + case EQUIP_TYPE_PROTECTION: + { + ProcLootProtection(dto); + } + break; + case EQUIP_TYPE_BAG: + { + ProcLootBag(dto); + } + break; + case EQUIP_TYPE_OLDSKIN: + { + abort(); + } + break; + case EQUIP_TYPE_SKIN: + { + ProcLootSkin(dto); + } + break; + case EQUIP_TYPE_CAR: + { + ProcLootCar(dto); + } + break; + case EQUIP_TYPE_CAMOUFLAGE: + { + ProcCamoutflage(dto); + } + break; + case EQUIP_TYPE_SPOILS: + { + ProcSpoils(dto); + } + break; + default: + { + ProcLootSpecItem(dto); + } + break; + } } diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 6866929..9d43312 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -272,16 +272,18 @@ class Human : public Creature protected: void _InternalUpdateMove(float speed); - void ProcLootWeapon(Loot* entity, MetaData::Equip* item_meta, bool& handled); - void ProcLootSkin(Loot* entity, MetaData::Equip* item_meta, bool& handled); - void ProcLootCar(Loot* entity, MetaData::Equip* item_meta, bool& handled); - void ProcCamoutflage(Loot* entity, MetaData::Equip* item_meta, bool& handled); - void ProcSpoils(Loot* entity, MetaData::Equip* item_meta, bool& handled); - void ProcLootBag(Loot* entity, MetaData::Equip* item_meta, bool& handled); - void ProcLootProtection(Loot* entity, MetaData::Equip* item_meta, bool& handled); - void ProcLootSpecItem(Loot* entity, MetaData::Equip* item_meta, bool& handled); + void ProcLootWeapon(AddItemDTO& dto); + void ProcLootSkin(AddItemDTO& dto); + void ProcLootCar(AddItemDTO& dto); + void ProcCamoutflage(AddItemDTO& dto); + void ProcSpoils(AddItemDTO& dto); + void ProcLootBag(AddItemDTO& dto); + void ProcLootProtection(AddItemDTO& dto); + void ProcLootSpecItem(AddItemDTO& dto); void CancelRevive(); Weapon* TakeonWeapon(MetaData::Equip* equip_meta); + void LootInteraction(Loot* entity); + void ProcAddItemDto(AddItemDTO& dto); private: void ClearFrameData(); diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index c02b36c..2cf54c2 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -499,85 +499,6 @@ void Player::ObstacleInteraction(Obstacle* entity) entity->DoInteraction(this); } -void Player::LootInteraction(Loot* entity) -{ - if (entity->pickuped || - entity->count <= 0) { - return; - } - MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquip(entity->item_id); - if (!item_meta) { - return; - } - bool handled = false; - switch (item_meta->i->equip_type()) { - case EQUIP_TYPE_WEAPON: - { - ProcLootWeapon(entity, item_meta, handled); - } - break; - case EQUIP_TYPE_PROTECTION: - { - ProcLootProtection(entity, item_meta, handled); - } - break; - case EQUIP_TYPE_BAG: - { - ProcLootBag(entity, item_meta, handled); - } - break; - case EQUIP_TYPE_OLDSKIN: - { - abort(); - } - break; - case EQUIP_TYPE_SKIN: - { - ProcLootSkin(entity, item_meta, handled); - } - break; - case EQUIP_TYPE_CAR: - { - ProcLootCar(entity, item_meta, handled); - } - break; - case EQUIP_TYPE_CAMOUFLAGE: - { - ProcCamoutflage(entity, item_meta, handled); - } - break; - case EQUIP_TYPE_SPOILS: - { - - ProcSpoils(entity, item_meta, handled); - } - break; - default: - { - ProcLootSpecItem(entity, item_meta, handled); - } - break; - } - - if (handled) { - entity->pickuped = true; - room->RemoveObjectLater(entity); - if (entity->dummy_thing_uniid != 0) { - Entity* dummy_obj = room->GetEntityByUniId(entity->dummy_thing_uniid); - if (dummy_obj && dummy_obj->GetEntityType() == ET_Obstacle) { - Obstacle* obstacle = (Obstacle*)dummy_obj; - if (!obstacle->IsPermanent()) { - if (!obstacle->IsDead(room)) { - obstacle->Die(room); - obstacle->BroadcastFullState(room); - } - room->RemoveObjectLater((RoomObstacle*)obstacle); - } - } - } - } -} - void Player::HumanInteraction(Human* hum) { if (downed) { diff --git a/server/gameserver/player.h b/server/gameserver/player.h index 3a85b69..0cc2e81 100644 --- a/server/gameserver/player.h +++ b/server/gameserver/player.h @@ -93,7 +93,6 @@ class Player : public Human void Shot(); void ProcInteraction(); void ObstacleInteraction(Obstacle* entity); - void LootInteraction(Loot* entity); void HumanInteraction(Human* hum); void ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& prepare_items); diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 6f70f09..032ec7c 100644 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -1 +1,16 @@ #pragma once + +namespace MetaData +{ + struct Equip; +} + +struct AddItemDTO +{ + int uniid = 0; + int item_id = 0; + int count = 0; + int item_level = 0; + MetaData::Equip* item_meta = nullptr; + bool handled = false; +};