From f7a8f3671a7518510a0dd06cd8e7c709e614be0c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 16 Nov 2022 17:08:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=A2=E5=BC=83=E6=AD=A6?= =?UTF-8?q?=E5=99=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/human.cc | 62 ++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index f22b1a88..a581416a 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -4207,32 +4207,48 @@ void Human::DropWeapon(int weapon_idx, int num) break; case FRAG_SLOT: { - drop_ok = true; - *weapon = Weapon(); - weapon->weapon_idx = weapon_idx; - if (GetCurrWeapon() == weapon) { - if (weapons[GUN_SLOT1].weapon_id != 0) { - SetCurrWeapon(&weapons[GUN_SLOT1]); - } else if (weapons[GUN_SLOT2].weapon_id != 0) { - SetCurrWeapon(&weapons[GUN_SLOT2]); - } else { - SetCurrWeapon(&weapons[0]); + weapon_ammo = std::min(weapon->ammo, num); + if (weapon_ammo > 0) { + drop_ok = true; + weapon->ammo = std::max(0, weapon->ammo - weapon_ammo); + int slot_id = weapon->meta->i->_inventory_slot(); + DecInventory(slot_id, weapon_ammo); + if (weapon->ammo <= 0) { + *weapon = Weapon(); + weapon->weapon_idx = weapon_idx; + if (GetCurrWeapon() == weapon) { + if (weapons[GUN_SLOT1].weapon_id != 0) { + SetCurrWeapon(&weapons[GUN_SLOT1]); + } else if (weapons[GUN_SLOT2].weapon_id != 0) { + SetCurrWeapon(&weapons[GUN_SLOT2]); + } else { + SetCurrWeapon(&weapons[0]); + } + } } } } break; case SMOKE_SLOT: { - drop_ok = true; - *weapon = Weapon(); - weapon->weapon_idx = weapon_idx; - if (GetCurrWeapon() == weapon) { - if (weapons[GUN_SLOT1].weapon_id != 0) { - SetCurrWeapon(&weapons[GUN_SLOT1]); - } else if (weapons[GUN_SLOT2].weapon_id != 0) { - SetCurrWeapon(&weapons[GUN_SLOT2]); - } else { - SetCurrWeapon(&weapons[0]); + weapon_ammo = std::min(weapon->ammo, num); + if (weapon_ammo > 0) { + drop_ok = true; + weapon->ammo = std::max(0, weapon->ammo - weapon_ammo); + int slot_id = weapon->meta->i->_inventory_slot(); + DecInventory(slot_id, weapon_ammo); + if (weapon->ammo <= 0) { + *weapon = Weapon(); + weapon->weapon_idx = weapon_idx; + if (GetCurrWeapon() == weapon) { + if (weapons[GUN_SLOT1].weapon_id != 0) { + SetCurrWeapon(&weapons[GUN_SLOT1]); + } else if (weapons[GUN_SLOT2].weapon_id != 0) { + SetCurrWeapon(&weapons[GUN_SLOT2]); + } else { + SetCurrWeapon(&weapons[0]); + } + } } } } @@ -4243,6 +4259,8 @@ void Human::DropWeapon(int weapon_idx, int num) if (weapon_ammo > 0) { drop_ok = true; weapon->ammo = std::max(0, weapon->ammo - weapon_ammo); + int slot_id = weapon->meta->i->_inventory_slot(); + DecInventory(slot_id, weapon_ammo); if (weapon->ammo <= 0) { *weapon = Weapon(); weapon->weapon_idx = weapon_idx; @@ -4269,6 +4287,9 @@ void Human::DropWeapon(int weapon_idx, int num) if (weapon_ammo > 0) { MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(weapon_meta->i->use_bullet()); if (bullet_meta && bullet_meta->i->_inventory_slot() > 0) { + #if 1 + int drop_num = weapon_ammo; + #else int volume = GetVolume(bullet_meta->i->_inventory_slot()); int inventory = GetInventory(bullet_meta->i->_inventory_slot()); int add_inventory = std::min(weapon_ammo, volume - std::min(volume, inventory)); @@ -4277,6 +4298,7 @@ void Human::DropWeapon(int weapon_idx, int num) AddInventory(bullet_meta->i->_inventory_slot(), add_inventory); } int drop_num = weapon_ammo - add_inventory; + #endif if (drop_num > 0) { a8::Vec2 drop_dir = a8::Vec2::UP; drop_dir.Rotate(a8::RandAngle());