From 9eaf1c84b0d02e3c65eeb79ce62171e8fc3c388f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 29 Dec 2022 14:55:48 +0800 Subject: [PATCH] 1 --- server/gameserver/buff/sprint.cc | 176 ++++++++++++++++--------------- server/gameserver/buff/sprint.h | 1 + 2 files changed, 91 insertions(+), 86 deletions(-) diff --git a/server/gameserver/buff/sprint.cc b/server/gameserver/buff/sprint.cc index a803f7b2..1de06479 100644 --- a/server/gameserver/buff/sprint.cc +++ b/server/gameserver/buff/sprint.cc @@ -28,11 +28,11 @@ void SprintBuff::Activate() { owner->SendDebugMsg(a8::Format("xxxxxxxx move_dir:%d,%d attack_dir:%d,%d speed:%d", { - owner->GetMoveDir().x, - owner->GetMoveDir().y, - owner->GetAttackDir().x, - owner->GetAttackDir().y, - owner->GetSpeed() + owner->GetMoveDir().x, + owner->GetMoveDir().y, + owner->GetAttackDir().x, + owner->GetAttackDir().y, + owner->GetSpeed() })); owner->room->xtimer.SetIntervalEx ( @@ -43,12 +43,12 @@ void SprintBuff::Activate() Human* hum = owner->AsHuman(); hum->SendDebugMsg(a8::Format("xxxxxxxx move_dir:%d,%d attack_dir:%d,%d speed:%d", { - hum->GetMoveDir().x, - hum->GetMoveDir().y, - hum->GetAttackDir().x, - hum->GetAttackDir().y, - hum->GetSpeed() - })); + hum->GetMoveDir().x, + hum->GetMoveDir().y, + hum->GetAttackDir().x, + hum->GetAttackDir().y, + hum->GetSpeed() + })); } }, &xtimer_attacher @@ -56,81 +56,7 @@ void SprintBuff::Activate() } #endif } - Player* hum = (Player*)caster_.Get(); - std::map hited_objects = std::map(); - Position pre_pos; - pre_pos = owner->GetPos(); - owner->room->xtimer.SetIntervalEx - ( - 1, - [this, hited_objects, pre_pos] - (int event, const a8::Args* args) mutable - { - Buff* buff = this; - if (!buff->meta->_param3_int_list.empty() || buff->skill_meta) { - std::set enemys; - Position old_pos = buff->owner->GetPos(); - - if (pre_pos.ManhattanDistance2D(buff->owner->GetPos()) > 2) { - a8::Vec2 dir = buff->owner->GetPos().CalcDir2D(pre_pos); - dir.Normalize(); - float distance = buff->owner->GetPos().Distance2D2(pre_pos); - for (int i = 0; i < (distance + 6); i += 5) { - // 999 - #if 1 - #else - buff->owner->MutablePos.FromVec2((pre_pos) + (dir * i)); - #endif - buff->owner->GetHitEnemys(enemys, buff->meta->_param4); - for (auto& enemy : enemys) { - if (enemy->IsEntityType(ET_Car)) { - continue; - } - auto itr = hited_objects.find(enemy->GetUniId()); - if (itr != hited_objects.end()) { - if ((buff->owner->room->GetFrameNo() - itr->second) * FRAME_RATE_MS < - buff->meta->_int_param5) { - continue; - } - } - hited_objects[enemy->GetUniId()] = buff->owner->room->GetFrameNo(); - for (int buff_id : buff->meta->_param3_int_list) { - enemy->TryAddBuff(buff->owner, buff_id); - } - if (buff->skill_meta) { - switch (buff->skill_meta->GetMagicId()) { - case MAGIC_YMCZ: - { - float dmg = SkillHelper::GetYmczDmg(buff->owner, - enemy, - buff->skill_meta); - if (dmg > 0.0001f) { - enemy->DecHP( - dmg, - buff->owner->GetUniId(), - buff->owner->GetName(), - 0, - buff->owner->GetUniId(), - buff->owner->GetName() - ); - } - } - break; - default: - { - } - break; - } - } - } - } - } - - buff->owner->SetPos(old_pos); - pre_pos = buff->owner->GetPos(); - } - }, - &xtimer_attacher); + CollisionCheck(); } ProcSkill(); } @@ -145,6 +71,84 @@ void SprintBuff::Deactivate() } } +void SprintBuff::CollisionCheck() +{ + std::map hited_objects = std::map(); + Position pre_pos; + pre_pos = owner->GetPos(); + owner->room->xtimer.SetIntervalEx + ( + 1, + [this, hited_objects, pre_pos] + (int event, const a8::Args* args) mutable + { + Buff* buff = this; + if (!buff->meta->_param3_int_list.empty() || buff->skill_meta) { + std::set enemys; + Position old_pos = buff->owner->GetPos(); + + if (pre_pos.ManhattanDistance2D(buff->owner->GetPos()) > 2) { + a8::Vec2 dir = buff->owner->GetPos().CalcDir2D(pre_pos); + dir.Normalize(); + float distance = buff->owner->GetPos().Distance2D2(pre_pos); + for (int i = 0; i < (distance + 6); i += 5) { + // 999 +#if 1 +#else + buff->owner->MutablePos.FromVec2((pre_pos) + (dir * i)); +#endif + buff->owner->GetHitEnemys(enemys, buff->meta->_param4); + for (auto& enemy : enemys) { + if (enemy->IsEntityType(ET_Car)) { + continue; + } + auto itr = hited_objects.find(enemy->GetUniId()); + if (itr != hited_objects.end()) { + if ((buff->owner->room->GetFrameNo() - itr->second) * FRAME_RATE_MS < + buff->meta->_int_param5) { + continue; + } + } + hited_objects[enemy->GetUniId()] = buff->owner->room->GetFrameNo(); + for (int buff_id : buff->meta->_param3_int_list) { + enemy->TryAddBuff(buff->owner, buff_id); + } + if (buff->skill_meta) { + switch (buff->skill_meta->GetMagicId()) { + case MAGIC_YMCZ: + { + float dmg = SkillHelper::GetYmczDmg(buff->owner, + enemy, + buff->skill_meta); + if (dmg > 0.0001f) { + enemy->DecHP( + dmg, + buff->owner->GetUniId(), + buff->owner->GetName(), + 0, + buff->owner->GetUniId(), + buff->owner->GetName() + ); + } + } + break; + default: + { + } + break; + } + } + } + } + } + + buff->owner->SetPos(old_pos); + pre_pos = buff->owner->GetPos(); + } + }, + &xtimer_attacher); +} + void SprintBuff::ProcSkill() { if (skill_meta) { diff --git a/server/gameserver/buff/sprint.h b/server/gameserver/buff/sprint.h index e139c37e..f315b60f 100644 --- a/server/gameserver/buff/sprint.h +++ b/server/gameserver/buff/sprint.h @@ -10,6 +10,7 @@ class SprintBuff : public Buff virtual void Deactivate() override; private: + void CollisionCheck(); void ProcSkill(); };