From d097a6fd24ae4c2f4eaa89daad13c93e5f44c3ed Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 6 Sep 2021 13:14:33 +0800 Subject: [PATCH] 1 --- server/gameserver/constant.h | 1 + server/gameserver/human.cc | 122 +++++++++++++++++++++++++++++++++++ server/gameserver/human.h | 1 + server/gameserver/player.cc | 100 +--------------------------- 4 files changed, 125 insertions(+), 99 deletions(-) diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index 3a00e33..369b88b 100644 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -426,6 +426,7 @@ const int NEXT_FRAME_TIMER = 2; const int MAX_WEAPON_NUM = 14; const int MAX_SKIN_LV = 9; +const int GUN_SLOT0 = 0; const int GUN_SLOT1 = 1; const int GUN_SLOT2 = 2; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 8e9837c..d5dab6f 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -3757,3 +3757,125 @@ void Human::ProcAddItemDto(AddItemDTO& dto) break; } } + +void Human::DropWeapon(int weapon_idx) +{ + if (weapon_idx < 0 || + weapon_idx >= weapons.size()) { + return; + } + bool drop_ok = false; + Weapon* weapon = &weapons[weapon_idx]; + int weapon_id = weapon->weapon_id; + int weapon_lv = weapon->weapon_lv; + int weapon_ammo = weapon->ammo; + MetaData::Equip* weapon_meta = weapon->meta; + if (weapon->weapon_id != 0) { + switch (weapon->weapon_idx) { + case GUN_SLOT0: + { + if (weapon->weapon_id != default_weapon.weapon_id) { + drop_ok = true; + *weapon = default_weapon; + } + } + break; + case GUN_SLOT1: + { + drop_ok = true; + *weapon = Weapon(); + weapon->weapon_idx = weapon_idx; + if (GetCurrWeapon() == weapon) { + if (weapons[GUN_SLOT2].weapon_id != 0) { + SetCurrWeapon(&weapons[GUN_SLOT2]); + } else { + SetCurrWeapon(&weapons[0]); + } + } + } + break; + case GUN_SLOT2: + { + 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 { + SetCurrWeapon(&weapons[0]); + } + } + } + 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]); + } + } + } + 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]); + } + } + } + break; + default: + { + } + break; + } + if (drop_ok) { + { + a8::Vec2 dir = a8::Vec2::UP; + dir.Rotate(a8::RandAngle()); + room->CreateLoot(weapon_id, GetPos() + dir * (40 + rand() % 50), 1, weapon_lv); + } + 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) { + 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)); + if (add_inventory > 0 && + !(weapon_idx == FRAG_SLOT || weapon_idx == SMOKE_SLOT)) { + AddInventory(bullet_meta->i->_inventory_slot(), add_inventory); + } + int drop_num = weapon_ammo - add_inventory; + if (drop_num > 0) { + a8::Vec2 drop_dir = a8::Vec2::UP; + drop_dir.Rotate(a8::RandAngle()); + a8::Vec2 drop_pos = GetPos() + drop_dir * (25 + rand() % 50); + if (bullet_meta->i->_inventory_slot() == IS_FRAG || + bullet_meta->i->_inventory_slot() == IS_SMOKE) { + //只有手雷和烟雾弹会掉落 + room->DropItem(drop_pos, bullet_meta->i->id(), drop_num, 1); + } + } + } + } + need_sync_active_player = true; + SyncAroundPlayers(__FILE__, __LINE__, __func__); + } + } +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 9d43312..42c7e27 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -284,6 +284,7 @@ protected: Weapon* TakeonWeapon(MetaData::Equip* equip_meta); void LootInteraction(Loot* entity); void ProcAddItemDto(AddItemDTO& dto); + void DropWeapon(int weapon_idx); private: void ClearFrameData(); diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index bdcd358..a34facd 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -855,105 +855,7 @@ void Player::UpdateDropWeapon() drop_weapon_idx < weapons.size() && !HasBuffEffect(kBET_Terminator) && !FreezeOperate()) { - bool drop_ok = false; - Weapon* weapon = &weapons[drop_weapon_idx]; - int weapon_id = weapon->weapon_id; - int weapon_lv = weapon->weapon_lv; - int weapon_ammo = weapon->ammo; - MetaData::Equip* weapon_meta = weapon->meta; - if (weapon->weapon_id != 0) { - if (weapon->weapon_idx == 0) { - if (weapon->weapon_id != default_weapon.weapon_id) { - drop_ok = true; - *weapon = default_weapon; - } - } else if (weapon->weapon_idx == GUN_SLOT1) { - drop_ok = true; - *weapon = Weapon(); - weapon->weapon_idx = drop_weapon_idx; - if (GetCurrWeapon() == weapon) { - if (weapons[GUN_SLOT2].weapon_id != 0) { - SetCurrWeapon(&weapons[GUN_SLOT2]); - } else { - SetCurrWeapon(&weapons[0]); - } - } - } else if (weapon->weapon_idx == GUN_SLOT2) { - drop_ok = true; - *weapon = Weapon(); - weapon->weapon_idx = drop_weapon_idx; - if (GetCurrWeapon() == weapon) { - if (weapons[GUN_SLOT1].weapon_id != 0) { - SetCurrWeapon(&weapons[GUN_SLOT1]); - } else { - SetCurrWeapon(&weapons[0]); - } - } - } else if (weapon->weapon_idx == FRAG_SLOT) { - drop_ok = true; - *weapon = Weapon(); - weapon->weapon_idx = drop_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]); - } - } - } else if (weapon->weapon_idx == SMOKE_SLOT) { - drop_ok = true; - *weapon = Weapon(); - weapon->weapon_idx = drop_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]); - } - } - } - if (drop_ok) { - if (drop_weapon_idx == 0 || - drop_weapon_idx == GUN_SLOT1 || - drop_weapon_idx == GUN_SLOT2 || - drop_weapon_idx == FRAG_SLOT || - drop_weapon_idx == SMOKE_SLOT - ) { - a8::Vec2 dir = a8::Vec2::UP; - dir.Rotate(a8::RandAngle()); - room->CreateLoot(weapon_id, GetPos() + dir * (40 + rand() % 50), 1, weapon_lv); - } - 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) { - 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)); - if (add_inventory > 0 && - !(drop_weapon_idx == FRAG_SLOT || drop_weapon_idx == SMOKE_SLOT)) { - AddInventory(bullet_meta->i->_inventory_slot(), add_inventory); - } - int drop_num = weapon_ammo - add_inventory; - if (drop_num > 0) { - a8::Vec2 drop_dir = a8::Vec2::UP; - drop_dir.Rotate(a8::RandAngle()); - a8::Vec2 drop_pos = GetPos() + drop_dir * (25 + rand() % 50); - if (bullet_meta->i->_inventory_slot() == IS_FRAG || - bullet_meta->i->_inventory_slot() == IS_SMOKE) { - //只有手雷和烟雾弹会掉落 - room->DropItem(drop_pos, bullet_meta->i->id(), drop_num, 1); - } - } - } - } - need_sync_active_player = true; - SyncAroundPlayers(__FILE__, __LINE__, __func__); - } - } + DropWeapon(drop_weapon_idx); } ResetAction(); AutoLoadingBullet();