This commit is contained in:
aozhiwei 2022-10-26 16:19:52 +08:00
parent 9c72db9856
commit 586481482a
7 changed files with 80 additions and 21 deletions

View File

@ -1268,25 +1268,6 @@ void Buff::ProcCallFunc()
switch (meta->int_param1) {
case 1:
{
MetaData::Equip* weapon_meta = MetaMgr::Instance()->GetEquip(meta->int_param2);
if (weapon_meta) {
for (int i = 0; meta->param4_int_list.size(); ++i) {
a8::Vec2 bullet_dir = a8::Vec2::UP;
bullet_dir.Rotate(meta->param4_int_list[i] / 180.f);
a8::Vec2 bullet_born_pos = owner->GetPos() + bullet_dir * meta->param3;
int bullet_uniid = owner->room->AllocUniid();
owner->room->frame_event.AddBullet
(bullet_uniid,
owner->GetWeakPtrRef(),
weapon_meta,
1,
bullet_born_pos,
bullet_dir,
0,
0,
0);
}
}
}
break;
case 2:
@ -1320,3 +1301,65 @@ void Buff::ProcRemoveCallFunc()
break;
}
}
void Buff::PreProcess()
{
switch (meta->i->buff_target()) {
case kBET_CallFunc:
{
switch (meta->int_param1) {
case 1:
{
event_handlers_.push_back
(
owner->GetTrigger()->AddListener
(
kTriggerBulletHitBuffEvent,
[this] (const std::vector<std::any>& params)
{
Bullet* bullet = std::any_cast<Bullet*>(params.at(0));
ProcSputteringFunc(bullet);
}));
}
break;
default:
{
}
break;
}
}
break;
default:
{
}
break;
}
}
void Buff::ProcSputteringFunc(Bullet* bullet)
{
MetaData::Equip* weapon_meta = MetaMgr::Instance()->GetEquip(meta->int_param2);
if (!weapon_meta) {
return;
}
for (int i = 0; meta->param4_int_list.size(); ++i) {
a8::Vec2 bullet_dir = a8::Vec2::UP;
bullet_dir.Rotate(meta->param4_int_list[i] / 180.f);
a8::Vec2 bullet_born_pos = owner->GetPos() + bullet_dir * meta->param3;
int bullet_uniid = owner->room->AllocUniid();
owner->room->frame_event.AddBullet
(bullet_uniid,
owner->GetWeakPtrRef(),
weapon_meta,
1,
bullet_born_pos,
bullet_dir,
0,
0,
0);
VirtualBullet* bullet = new VirtualBullet();
owner->room->AddTask(bullet_uniid, bullet);
}
}

View File

@ -26,6 +26,7 @@ struct RemoveBuffCbConext
class Human;
class Creature;
class Bullet;
struct EventHandlerPtr;
struct xtimer_list;
class Buff
@ -94,10 +95,13 @@ class Buff
void CalcPassengerShotOffset();
void PreProcess();
private:
void ClearEventHandlers();
void InternalTimerAddBuff();
void RecoverHoldWeapons();
void ClearEventHandlers();
void ProcSputteringFunc(Bullet* bullet);
private:
int hold_curr_weapon_idx_ = 0;

View File

@ -924,7 +924,6 @@ void Bullet::TriggerHitBuff(Entity* e)
if (!e->IsDead(room) && e->IsCreature(room)) {
Creature* c = (Creature*)e;
for (int buff_id : gun_meta->hit_buff_list) {
int buff_uniid = c->TryAddBuff(
sender.Get(),
buff_id,
@ -934,6 +933,7 @@ void Bullet::TriggerHitBuff(Entity* e)
SkillHelper::ProcBulletHitBuff(this, c, buff_uniid);
}
}
c->GetTrigger()->BulletHitBuff(this);
}
}

View File

@ -186,6 +186,10 @@ int Creature::AddBuff(Creature* caster,
buff->add_frameno = room->GetFrameNo();
buff->xtimer_attacher.xtimer = &room->xtimer;
buff->Init();
buff->PreProcess();
if (on_add_buff) {
on_add_buff(buff);
}
if (buff->meta->i->lock_move()) {
IncDisableMoveTimes();
}

View File

@ -87,6 +87,7 @@ class Creature : public MoveableEntity
long long poisoning_time = 0;
bool playing_skill = false;
int power_idx = -1;
std::function<void(Buff*)> on_add_buff;
Weapon second_weapon;
a8::Vec2 context_pos;

View File

@ -470,3 +470,8 @@ void Trigger::FlyHookDestory()
{
DispatchEvent(kFlyHookDestoryEvent, {});
}
void Trigger::BulletHitBuff(Bullet* bullet)
{
DispatchEvent(kTriggerBulletHitBuffEvent, {bullet});
}

View File

@ -38,6 +38,7 @@ enum EventId_e
kFlyHookDestoryEvent,
kSkillBulletPreCreateEvent,
kUseSkillEvent,
kTriggerBulletHitBuffEvent
};
class Weapon;
@ -72,6 +73,7 @@ public:
void SkillBulletPreCreate(int delay_time, MetaData::Skill* skill_meta);
void FlyHookCreate(Bullet* bullet);
void FlyHookDestory();
void BulletHitBuff(Bullet* bullet);
std::weak_ptr<EventHandlerPtr> AddListener(int event_id, CommonCbProc cb);
void RemoveEventHandler(std::weak_ptr<EventHandlerPtr> handler_ptr);