This commit is contained in:
aozhiwei 2022-11-14 20:33:27 +08:00
parent bfb6d6a5df
commit c804e9093d
4 changed files with 99 additions and 38 deletions

View File

@ -296,7 +296,8 @@ int Creature::TryAddBuffAndSetTime(Creature* caster, int buff_id, int time, Meta
return buff_uniid; return buff_uniid;
} }
std::weak_ptr<a8::XTimerPtr> Creature::TryDelayAddBuff(Creature* caster, int buff_id, int time) std::weak_ptr<a8::XTimerPtr> Creature::TryDelayAddBuff(Creature* caster, int buff_id, int time,
DelayAddBuffHandle* handle)
{ {
xtimer_list* timer = room->xtimer.AddDeadLineTimerAndAttach xtimer_list* timer = room->xtimer.AddDeadLineTimerAndAttach
( (
@ -304,17 +305,29 @@ std::weak_ptr<a8::XTimerPtr> Creature::TryDelayAddBuff(Creature* caster, int buf
a8::XParams() a8::XParams()
.SetSender(this) .SetSender(this)
.SetParam1(caster->GetUniId()) .SetParam1(caster->GetUniId())
.SetParam2(buff_id), .SetParam2(buff_id)
.SetParam3(handle),
[] (const a8::XParams& param) [] (const a8::XParams& param)
{ {
Creature* c = (Creature*)param.sender.GetUserData(); Creature* c = (Creature*)param.sender.GetUserData();
Entity* e = c->room->GetEntityByUniId(param.param1); Entity* e = c->room->GetEntityByUniId(param.param1);
DelayAddBuffHandle* handle = (DelayAddBuffHandle*)param.param3.GetUserData();
if (e->IsCreature(c->room) && !c->IsDead(c->room)) { if (e->IsCreature(c->room) && !c->IsDead(c->room)) {
c->TryAddBuff((Creature*)e, param.param2); if (handle && handle->pre_add_cb) {
handle->pre_add_cb(c);
}
int buff_uniid = c->TryAddBuff((Creature*)e, param.param2);
if (handle && handle->post_add_cb) {
handle->post_add_cb(c, buff_uniid);
}
} }
}, },
&xtimer_attacher.timer_list_ &xtimer_attacher.timer_list_,
); [] (const a8::XParams& param)
{
DelayAddBuffHandle* handle = (DelayAddBuffHandle*)param.param3.GetUserData();
delete handle;
});
return room->xtimer.GetTimerPtr(timer); return room->xtimer.GetTimerPtr(timer);
} }

View File

@ -65,6 +65,7 @@ class Hero;
class Team; class Team;
class Car; class Car;
class Trigger; class Trigger;
class DelayAddBuffHandle;
class Creature : public MoveableEntity class Creature : public MoveableEntity
{ {
public: public:
@ -139,7 +140,13 @@ class Creature : public MoveableEntity
bool no_check_immune = false); bool no_check_immune = false);
bool IsImmuneBuffEffect(int buff_effect); bool IsImmuneBuffEffect(int buff_effect);
int MustBeAddBuff(Creature* caster, int buff_id); int MustBeAddBuff(Creature* caster, int buff_id);
std::weak_ptr<a8::XTimerPtr> TryDelayAddBuff(Creature* caster, int buff_id, int time); std::weak_ptr<a8::XTimerPtr> TryDelayAddBuff
(
Creature* caster,
int buff_id,
int time,
DelayAddBuffHandle* handle = nullptr
);
int TryAddBuff(Creature* caster, int buff_id, MetaData::Skill* skill_meta = nullptr); int TryAddBuff(Creature* caster, int buff_id, MetaData::Skill* skill_meta = nullptr);
int TryAddBuffAndSetTime(Creature* caster, int buff_id, int time, MetaData::Skill* skill_meta = nullptr); int TryAddBuffAndSetTime(Creature* caster, int buff_id, int time, MetaData::Skill* skill_meta = nullptr);
int TryAddBuffWithTarget(Creature* caster, int buff_id); int TryAddBuffWithTarget(Creature* caster, int buff_id);

View File

@ -272,6 +272,69 @@ static void InternalCreateBullet(BulletInfo& bullet_info)
} }
} }
static void ProcMissile(Creature* c,
MetaData::Equip* weapon_meta,
MetaData::Equip* bullet_meta,
MetaData::Skill* skill_meta,
float fly_distance,
long long weapon_uniid,
int trace_target_uniid)
{
if (!skill_meta) {
c->room->frame_event.AddShot(c->GetWeakPtrRef());
}
if (c->aiming) {
if (weapon_meta->i->aiming_cast_time() > 0) {
int buff_uniid = c->TryAddBuff(c, kVertigoBuffId);
Buff* buff = c->GetBuffByUniId(buff_uniid);
if (buff && buff->remover_timer) {
c->room->xtimer.ModifyTimer(buff->remover_timer, weapon_meta->i->aiming_cast_time() / FRAME_RATE_MS);
}
}
} else {
if (weapon_meta->i->cast_time() > 0) {
int buff_uniid = c->TryAddBuff(c, kVertigoBuffId);
Buff* buff = c->GetBuffByUniId(buff_uniid);
if (buff && buff->remover_timer) {
c->room->xtimer.ModifyTimer(buff->remover_timer, weapon_meta->i->cast_time() / FRAME_RATE_MS);
}
}
}
if (weapon_meta->bullet_born_offset.empty()) {
return;
}
MetaData::Buff * buff_meta = MetaMgr::Instance()->GetBuff(bullet_meta->i->buffid());
if (buff_meta) {
typedef struct {
a8::Vec2 old_context_dir;
a8::Vec2 old_context_pos;
} _T;
auto context = std::make_shared<_T>();
DelayAddBuffHandle* handle = new DelayAddBuffHandle;
handle->pre_add_cb =
[fly_distance, context] (Creature* c)
{
context->old_context_dir = c->context_dir;
context->old_context_pos = c->context_pos;
c->context_dir = c->GetAttackDir();
c->context_pos = c->GetPos() + c->GetAttackDir() * fly_distance;
};
handle->post_add_cb =
[context] (Creature* c, int buff_uniid)
{
c->context_dir = context->old_context_dir;
c->context_pos = context->old_context_pos;
};
auto tuple = weapon_meta->bullet_born_offset.at(0);
c->TryDelayAddBuff(c,
bullet_meta->i->buffid(),
std::get<3>(tuple),
handle);
}
}
void InternalShot(Creature* c, void InternalShot(Creature* c,
MetaData::Equip* weapon_meta, MetaData::Equip* weapon_meta,
MetaData::Equip* bullet_meta, MetaData::Equip* bullet_meta,
@ -282,38 +345,7 @@ void InternalShot(Creature* c,
{ {
if (weapon_meta->i->_inventory_slot() == IS_TRAP || if (weapon_meta->i->_inventory_slot() == IS_TRAP ||
weapon_meta->i->_inventory_slot() == IS_MINE) { weapon_meta->i->_inventory_slot() == IS_MINE) {
if (!skill_meta) { ProcMissile(c, weapon_meta, bullet_meta, skill_meta, fly_distance, weapon_uniid, trace_target_uniid);
c->room->frame_event.AddShot(c->GetWeakPtrRef());
}
if (c->aiming) {
if (weapon_meta->i->aiming_cast_time() > 0) {
int buff_uniid = c->TryAddBuff(c, kVertigoBuffId);
Buff* buff = c->GetBuffByUniId(buff_uniid);
if (buff && buff->remover_timer) {
c->room->xtimer.ModifyTimer(buff->remover_timer, weapon_meta->i->aiming_cast_time() / FRAME_RATE_MS);
}
}
} else {
if (weapon_meta->i->cast_time() > 0) {
int buff_uniid = c->TryAddBuff(c, kVertigoBuffId);
Buff* buff = c->GetBuffByUniId(buff_uniid);
if (buff && buff->remover_timer) {
c->room->xtimer.ModifyTimer(buff->remover_timer, weapon_meta->i->cast_time() / FRAME_RATE_MS);
}
}
}
a8::Vec2 old_context_dir = c->context_dir;
a8::Vec2 old_context_pos = c->context_pos;
c->context_dir =c->GetAttackDir();
c->context_pos = c->GetPos() + c->GetAttackDir() * fly_distance;
MetaData::Buff * buff_meta = MetaMgr::Instance()->GetBuff(bullet_meta->i->buffid());
if (buff_meta) {
c->AddBuff(c,
buff_meta
);
}
c->context_dir = old_context_dir;
c->context_pos = old_context_pos;
return; return;
} }
for (auto& tuple : weapon_meta->bullet_born_offset) { for (auto& tuple : weapon_meta->bullet_born_offset) {

View File

@ -14,6 +14,8 @@ namespace cs
} }
class Room; class Room;
class Buff;
class Creature;
struct AddItemDTO struct AddItemDTO
{ {
@ -46,3 +48,10 @@ class ITask
virtual void Update(int delta_time) = 0; virtual void Update(int delta_time) = 0;
virtual bool IsDone() = 0; virtual bool IsDone() = 0;
}; };
class DelayAddBuffHandle
{
public:
std::function<void(Creature*)> pre_add_cb;
std::function<void(Creature*, int)> post_add_cb;
};