1
This commit is contained in:
parent
bfb6d6a5df
commit
c804e9093d
@ -296,7 +296,8 @@ int Creature::TryAddBuffAndSetTime(Creature* caster, int buff_id, int time, Meta
|
||||
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
|
||||
(
|
||||
@ -304,17 +305,29 @@ std::weak_ptr<a8::XTimerPtr> Creature::TryDelayAddBuff(Creature* caster, int buf
|
||||
a8::XParams()
|
||||
.SetSender(this)
|
||||
.SetParam1(caster->GetUniId())
|
||||
.SetParam2(buff_id),
|
||||
.SetParam2(buff_id)
|
||||
.SetParam3(handle),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Creature* c = (Creature*)param.sender.GetUserData();
|
||||
Entity* e = c->room->GetEntityByUniId(param.param1);
|
||||
DelayAddBuffHandle* handle = (DelayAddBuffHandle*)param.param3.GetUserData();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@ class Hero;
|
||||
class Team;
|
||||
class Car;
|
||||
class Trigger;
|
||||
class DelayAddBuffHandle;
|
||||
class Creature : public MoveableEntity
|
||||
{
|
||||
public:
|
||||
@ -139,7 +140,13 @@ class Creature : public MoveableEntity
|
||||
bool no_check_immune = false);
|
||||
bool IsImmuneBuffEffect(int buff_effect);
|
||||
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 TryAddBuffAndSetTime(Creature* caster, int buff_id, int time, MetaData::Skill* skill_meta = nullptr);
|
||||
int TryAddBuffWithTarget(Creature* caster, int buff_id);
|
||||
|
@ -272,7 +272,7 @@ static void InternalCreateBullet(BulletInfo& bullet_info)
|
||||
}
|
||||
}
|
||||
|
||||
void InternalShot(Creature* c,
|
||||
static void ProcMissile(Creature* c,
|
||||
MetaData::Equip* weapon_meta,
|
||||
MetaData::Equip* bullet_meta,
|
||||
MetaData::Skill* skill_meta,
|
||||
@ -280,8 +280,6 @@ void InternalShot(Creature* c,
|
||||
long long weapon_uniid,
|
||||
int trace_target_uniid)
|
||||
{
|
||||
if (weapon_meta->i->_inventory_slot() == IS_TRAP ||
|
||||
weapon_meta->i->_inventory_slot() == IS_MINE) {
|
||||
if (!skill_meta) {
|
||||
c->room->frame_event.AddShot(c->GetWeakPtrRef());
|
||||
}
|
||||
@ -302,18 +300,52 @@ void InternalShot(Creature* c,
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
if (weapon_meta->bullet_born_offset.empty()) {
|
||||
return;
|
||||
}
|
||||
MetaData::Buff * buff_meta = MetaMgr::Instance()->GetBuff(bullet_meta->i->buffid());
|
||||
if (buff_meta) {
|
||||
c->AddBuff(c,
|
||||
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);
|
||||
}
|
||||
c->context_dir = old_context_dir;
|
||||
c->context_pos = old_context_pos;
|
||||
}
|
||||
|
||||
void InternalShot(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 (weapon_meta->i->_inventory_slot() == IS_TRAP ||
|
||||
weapon_meta->i->_inventory_slot() == IS_MINE) {
|
||||
ProcMissile(c, weapon_meta, bullet_meta, skill_meta, fly_distance, weapon_uniid, trace_target_uniid);
|
||||
return;
|
||||
}
|
||||
for (auto& tuple : weapon_meta->bullet_born_offset) {
|
||||
|
@ -14,6 +14,8 @@ namespace cs
|
||||
}
|
||||
|
||||
class Room;
|
||||
class Buff;
|
||||
class Creature;
|
||||
|
||||
struct AddItemDTO
|
||||
{
|
||||
@ -46,3 +48,10 @@ class ITask
|
||||
virtual void Update(int delta_time) = 0;
|
||||
virtual bool IsDone() = 0;
|
||||
};
|
||||
|
||||
class DelayAddBuffHandle
|
||||
{
|
||||
public:
|
||||
std::function<void(Creature*)> pre_add_cb;
|
||||
std::function<void(Creature*, int)> post_add_cb;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user