From 1ef895af0b83602bd00ad7c493f76a2931217f33 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 27 Sep 2022 19:42:36 +0800 Subject: [PATCH] 1 --- server/gameserver/creature.cc | 24 ++++++++++++++++++++++++ server/gameserver/creature.h | 1 + server/gameserver/player.cc | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index d9cf19e8..76189453 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -383,6 +383,9 @@ void InternalShot(Creature* c, if (c->HasBuffEffect(kBET_Hide)) { c->RemoveBuffByEffectId(kBET_Hide); } + if (trace_target_uniid) { + c->LockAttackDir(1000); + } if (c->aiming) { c->aiming = false; c->aiming_frameno = 0; @@ -3612,3 +3615,24 @@ void Creature::AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id) }, &xtimer_attacher.timer_list_); } + +void Creature::LockAttackDir(int time) +{ + IncDisableAttackDirTimes(); + room->xtimer.AddDeadLineTimerAndAttach + ( + time / FRAME_RATE_MS, + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Creature* c = (Creature*)param.sender.GetUserData(); + }, + &xtimer_attacher.timer_list_, + [] (const a8::XParams& param) + { + Creature* c = (Creature*)param.sender.GetUserData(); + c->DecDisableAttackDirTimes(); + } + ); +} diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index a5df28b5..86c81018 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -277,6 +277,7 @@ class Creature : public MoveableEntity void RecalcDtoAttr(); void AutoNavigation(a8::Vec2 target_pos, float speed); void AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id); + void LockAttackDir(int time); protected: virtual void OnBuffRemove(Buff& buff); diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 55cd0f7c..68a5b44a 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -547,6 +547,10 @@ void Player::Shot() GetPos().Distance(target->GetPos()) < GetCurrWeapon()->meta->i->trace_range() ) { target_uniid = trace_target_uniid; + a8::Vec2 attack_dir = target->GetPos() - GetPos(); + attack_dir.Normalize(); + SetAttackDir(attack_dir); + target_dir = attack_dir; } } Creature::Shot(target_dir, shot_ok, fly_distance, target_uniid);