This commit is contained in:
aozhiwei 2023-02-25 09:33:14 +08:00
parent 05ce89b99b
commit c77bf62645
2 changed files with 19 additions and 0 deletions

View File

@ -2743,6 +2743,24 @@ std::weak_ptr<Effect> Creature::AddEffect(int effect_id)
return effect; return effect;
} }
std::weak_ptr<Effect> Creature::AddEffectAndSetTime(int effect_id, int time)
{
auto p = AddEffect(effect_id);
room->xtimer.SetTimeoutEx
(
time / FRAME_RATE_MS,
[this, p] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
if (!p.expired()) {
p.lock()->RemoveFromOwner();
}
}
},
&xtimer_attacher);
return p;
}
void Creature::RemoveEffect(int effect_uniid) void Creature::RemoveEffect(int effect_uniid)
{ {
effect_hash_.erase(effect_uniid); effect_hash_.erase(effect_uniid);

View File

@ -182,6 +182,7 @@ class Creature : public MoveableEntity
Team* GetTeam() { return team_; } Team* GetTeam() { return team_; }
void SetTeam(Team* team) { team_ = team; } void SetTeam(Team* team) { team_ = team; }
std::weak_ptr<Effect> AddEffect(int effect_id); std::weak_ptr<Effect> AddEffect(int effect_id);
std::weak_ptr<Effect> AddEffectAndSetTime(int effect_id, int time);
void RemoveEffect(std::weak_ptr<Effect> effect); void RemoveEffect(std::weak_ptr<Effect> effect);
void RemoveEffect(int effect_uniid); void RemoveEffect(int effect_uniid);
void RemoveEffects(std::vector<int> effect_uniids); void RemoveEffects(std::vector<int> effect_uniids);