From eac8e243ec2db9f2cda6ca725a1e582d69dc2ebc Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 31 Jul 2020 16:06:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=BA=E7=94=B2=E8=A3=85?= =?UTF-8?q?=E5=BC=B9=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 | 98 +++++++++++++++++++++++++------------- server/gameserver/human.h | 1 + 2 files changed, 66 insertions(+), 33 deletions(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 61132a5..e8ea74f 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -470,6 +470,22 @@ void Human::CarShot(a8::Vec2& target_dir) return; } + if (car_weapon.weapon_idx != 0 && + car_weapon.ammo <= 0) { + AutoLoadingBullet(); + return; + } + + if (action_type == AT_Reload) { + CancelAction(); + } + if (action_type == AT_Reload || + action_type == AT_Rescue || + action_type == AT_UseItem || + action_type == AT_Relive) { + CancelAction(); + } + InternalShot(this, car_weapon.meta, car_weapon.GetUpgradeMeta(), @@ -479,6 +495,7 @@ void Human::CarShot(a8::Vec2& target_dir) 5, false); + --car_weapon.ammo; last_shot_frameno_ = room->GetFrameNo(); } @@ -797,11 +814,15 @@ void Human::SyncAroundPlayers(const char* file, int line, const char* func) void Human::AutoLoadingBullet(bool manual) { - if (curr_weapon->weapon_idx != 0 && - (curr_weapon->ammo <= 0 || - (manual && curr_weapon->ammo < curr_weapon->GetClipVolume())) + Weapon* p_weapon = curr_weapon; + if (car_weapon.meta) { + p_weapon = &car_weapon; + } + if (p_weapon->weapon_idx != 0 && + (p_weapon->ammo <= 0 || + (manual && p_weapon->ammo < p_weapon->GetClipVolume())) ) { - MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet()); + MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(p_weapon->meta->i->use_bullet()); if (bullet_meta && bullet_meta->i->_inventory_slot() >= 0 && bullet_meta->i->_inventory_slot() < (int)inventory_.size() @@ -811,9 +832,9 @@ void Human::AutoLoadingBullet(bool manual) on_loading_bullet(); } StartAction(AT_Reload, - curr_weapon->meta->i->reload_time(), - curr_weapon->weapon_id, - curr_weapon->weapon_idx); + p_weapon->meta->i->reload_time(), + p_weapon->weapon_id, + p_weapon->weapon_idx); } } return; @@ -1695,32 +1716,7 @@ void Human::UpdateAction() switch (action_type) { case AT_Reload: { - if (curr_weapon->weapon_idx == action_target_id && - curr_weapon->weapon_id == action_item_id && - curr_weapon->weapon_idx != 0) { - MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet()); - if (bullet_meta) { - int ammo = curr_weapon->ammo; - if (ammo < curr_weapon->GetClipVolume()) { - if (bullet_meta->i->_inventory_slot() >= 0 && - bullet_meta->i->_inventory_slot() < IS_END) { - if (GetInventory(bullet_meta->i->_inventory_slot()) > 0) { - int add_num = 0; - if (GetInventory(bullet_meta->i->_inventory_slot()) <= - curr_weapon->GetClipVolume() - ammo) { - add_num = GetInventory(bullet_meta->i->_inventory_slot()); - DecInventory(bullet_meta->i->_inventory_slot(), add_num); - } else { - add_num = curr_weapon->GetClipVolume() - ammo; - DecInventory(bullet_meta->i->_inventory_slot(), add_num); - } - curr_weapon->ammo += add_num; - need_sync_active_player = true;; - } - } - } - } - } + ProcReloadAction(); } break; case AT_UseItem: @@ -3952,3 +3948,39 @@ void Human::OnChgToTerminator() SyncAroundPlayers(__FILE__, __LINE__, __func__); } } + +void Human::ProcReloadAction() +{ + Weapon* p_weapon = curr_weapon; + if (car_weapon.meta) { + p_weapon = &car_weapon; + } + + if (p_weapon->weapon_idx == action_target_id && + p_weapon->weapon_id == action_item_id && + p_weapon->weapon_idx != 0) { + MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(p_weapon->meta->i->use_bullet()); + if (bullet_meta) { + int ammo = p_weapon->ammo; + if (ammo < p_weapon->GetClipVolume()) { + if (bullet_meta->i->_inventory_slot() >= 0 && + bullet_meta->i->_inventory_slot() < IS_END) { + if (GetInventory(bullet_meta->i->_inventory_slot()) > 0) { + int add_num = 0; + if (GetInventory(bullet_meta->i->_inventory_slot()) <= + p_weapon->GetClipVolume() - ammo) { + add_num = GetInventory(bullet_meta->i->_inventory_slot()); + DecInventory(bullet_meta->i->_inventory_slot(), add_num); + } else { + add_num = p_weapon->GetClipVolume() - ammo; + DecInventory(bullet_meta->i->_inventory_slot(), add_num); + } + p_weapon->ammo += add_num; + need_sync_active_player = true;; + } + } + } + } + + } +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index ec29464..695a3e3 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -331,6 +331,7 @@ private: void AddPassiveSkillBuff(MetaData::Skill* skill_meta); void OnMetaChange(); void OnChgToTerminator(); + void ProcReloadAction(); protected: int level_ = 0;