From c91d2ea249388208725457f58e67e0b8d4530253 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 16 Nov 2023 22:11:39 +0800 Subject: [PATCH] 1 --- server/gameserver/creature.cc | 63 ++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 1cf4a5d4..ea101278 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -32,6 +32,7 @@ #include "team.h" #include "bornpoint.h" #include "compose.h" +#include "player.h" #include "mt/Param.h" #include "mt/Hero.h" @@ -3790,8 +3791,68 @@ void Creature::CheckShotHold() } void Creature::Throw(int throw_uniid, int slot, - const glm::vec3& pos, const glm::vec3& dir, + const glm::vec3& bomb_pos, const glm::vec3& bomb_dir, float fly_distance, int estimated_time) { + if (slot < 0 || slot >= weapons.size()) { + return; + } + Weapon& weapon = weapons.at(slot); + if (weapon.weapon_idx != 0 && + weapon.meta && + weapon.ammo > 0) { + if (HasBuffEffect(kBET_Hide)) { + RemoveHideEffect(kShotReason); + } + if (!nature_recover_hp_idle_timer.expired()) { + room->xtimer.FireEvent + ( + nature_recover_hp_idle_timer, + kRemoveNatureRecoverTimerEvent, + nullptr); + } + --weapon.ammo; + room->frame_event.AddPropChgEx + ( + GetWeakPtrRef(), + kPropWeaponAmmo, + weapon.weapon_idx, + weapon.ammo, + weapon.GetClipVolume(this), + 0, + true + ); + DecInventory(weapon.meta->_inventory_slot(), 1); + if (IsHuman()) { + AsHuman()->SyncVolume(weapon.meta->_inventory_slot()); + } + SetAttackDir(bomb_dir); + int throw_uniid = room->AllocUniid(); + room->frame_event.AddBullet + ( + throw_uniid, + GetWeakPtrRef(), + weapon.meta, + 1, + bomb_pos, + bomb_dir, + fly_distance, + 0, + 1, + nullptr); + //pending_throw_bomb[throw_uniid] = throw_bomb; + room->xtimer.SetTimeoutEx + ( + SERVER_FRAME_RATE * 15, + [this, throw_uniid] (int event, const a8::Args* args) + { + if (a8::TIMER_DELETE_EVENT == event) { + if (IsPlayer()) { + AsPlayer()->ProcThrowDmg(throw_uniid); + } + } + }, + &room->xtimer_attacher_); + } }