Skip to content

Commit

Permalink
Fix with validations for attack and attacked observers
Browse files Browse the repository at this point in the history
After talking with neon made fixes for what was before the commit that cause the bug
  • Loading branch information
jvbhidalgo authored Sep 17, 2024
1 parent 2581d79 commit d3e7f67
Showing 1 changed file with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,29 @@ public void applyEffect(Effect effect) {
@Override
public void startEffect(Effect effect) {
Creature effector = effect.getEffector();
ActionObserver observer;
ObserverType observerType = hitType == HitType.NMLATK || hitType == HitType.BACKATK ? ObserverType.ATTACK : ObserverType.ATTACKED;
effect.addObserver(effect.getEffected(), new ActionObserver(observerType) {

if (hitType == HitType.EVERYHIT) {
observer = new ActionObserver(ObserverType.ATTACKED) {
@Override
public void attacked(Creature attacker, int attackSkillId) {
if (shouldApply(effector, attacker, attackSkillId)) {
if (effector instanceof Player player) {
PacketSendUtility.sendPacket(player,
SM_SYSTEM_MESSAGE.STR_SKILL_PROC_EFFECT_OCCURRED(DataManager.SKILL_DATA.getSkillTemplate(skillId).getL10n()));
}
SkillEngine.getInstance().applyEffectDirectly(skillId, effector, getProvokeTarget(effector, attacker));
}
}
};
} else {
observer = new ActionObserver(ObserverType.ATTACK) {
@Override
public void attack(Creature attacked, int attackSkillId) {
if (shouldApply(effector, attacked, attackSkillId)) {
if (effector instanceof Player player) {
PacketSendUtility.sendPacket(player,
SM_SYSTEM_MESSAGE.STR_SKILL_PROC_EFFECT_OCCURRED(DataManager.SKILL_DATA.getSkillTemplate(skillId).getL10n()));
}
SkillEngine.getInstance().applyEffectDirectly(skillId, effector, getProvokeTarget(effector, attacked));
@Override
public void attack(Creature attacked, int attackSkillId) {
tryApplyEffect(attacked, attackSkillId, effector);
}

@Override
public void attacked(Creature attacker, int attackSkillId) {
tryApplyEffect(attacker, attackSkillId, effector);
}

private void tryApplyEffect(Creature target, int attackSkillId, Creature effector) {
if (shouldApply(effector, target, attackSkillId)) {
if (effector instanceof Player player) {
PacketSendUtility.sendPacket(player,
SM_SYSTEM_MESSAGE.STR_SKILL_PROC_EFFECT_OCCURRED(DataManager.SKILL_DATA.getSkillTemplate(skillId).getL10n()));
}
SkillEngine.getInstance().applyEffectDirectly(skillId, effector, getProvokeTarget(effector, target));
}
};
}

effect.addObserver(effect.getEffected(), observer);
}
});
}

private boolean shouldApply(Creature effector, Creature target, int attackSkillId) {
Expand Down

0 comments on commit d3e7f67

Please sign in to comment.