Call onRemoved() in StatusEffect.java when an effect is removed (#9801)

* Call onRemoved() in StatusEffect.java when an effect is removed

* Call onRemoved() in StatusEffect.java when an effect is removed

* cleanup

* cleanup
This commit is contained in:
Uenhe 2024-05-02 21:41:59 +08:00 committed by GitHub
parent 0e618a2f71
commit d9ea8beae2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -73,6 +73,7 @@ abstract class StatusComp implements Posc, Flyingc{
}
void clearStatuses(){
statuses.each(e -> e.effect.onRemoved(self()));
statuses.clear();
}
@ -80,6 +81,7 @@ abstract class StatusComp implements Posc, Flyingc{
void unapply(StatusEffect effect){
statuses.remove(e -> {
if(e.effect == effect){
e.effect.onRemoved(self());
Pools.free(e);
return true;
}
@ -189,6 +191,10 @@ abstract class StatusComp implements Posc, Flyingc{
entry.time = Math.max(entry.time - Time.delta, 0);
if(entry.effect == null || (entry.time <= 0 && !entry.effect.permanent)){
if(entry.effect != null){
entry.effect.onRemoved(self());
}
Pools.free(entry);
index --;
statuses.remove(index);

View File

@ -142,6 +142,11 @@ public class StatusEffect extends UnlockableContent{
}
}
/** Called when status effect is removed. */
public void onRemoved(Unit unit){
}
protected void trans(StatusEffect effect, TransitionHandler handler){
transitions.put(effect, handler);
}