Files
Server/src/engine/jobs/DeferredPowerJob.java
T

108 lines
4.4 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.jobs;
import engine.gameManager.CombatManager;
import engine.gameManager.PowersManager;
import engine.math.Vector3fImmutable;
import engine.objects.AbstractCharacter;
import engine.objects.AbstractWorldObject;
import engine.objects.Mob;
import engine.objects.PlayerCharacter;
import engine.powers.ActionsBase;
import engine.powers.EffectsBase;
import engine.powers.PowersBase;
import engine.powers.poweractions.ApplyEffectPowerAction;
import engine.powers.poweractions.DeferredPowerPowerAction;
public class DeferredPowerJob extends AbstractEffectJob {
2023-07-15 09:23:48 -04:00
private final DeferredPowerPowerAction def;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public DeferredPowerJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, DeferredPowerPowerAction def) {
super(source, target, stackType, trains, action, power, eb);
this.def = def;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public DeferredPowerJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, ApplyEffectPowerAction def) {
super(source, target, stackType, trains, action, power, eb);
this.def = null;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
protected void doJob() {
//Power ended with no attack, cancel weapon power boost
if (this.source != null && this.source instanceof PlayerCharacter) {
((PlayerCharacter) this.source).setWeaponPower(null);
}
PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
protected void _cancelJob() {
//Attack happened.
PowersManager.cancelEffectTime(this.source, this.target, this.power, this.eb, this.action, this.trains, this);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void attack(AbstractWorldObject tar, float attackRange) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (this.source == null)
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (!AbstractWorldObject.IsAbstractCharacter(tar))
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (this.power == null)
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
switch (this.source.getObjectType()) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
case PlayerCharacter:
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (def == null) {
//No powers applied, just reset weapon power.
((PlayerCharacter) this.source).setWeaponPower(null);
return;
}
float powerRange = this.power.getWeaponRange();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Wtf? Method returns TRUE if rage test fails? Seriously?
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//DO valid range check ONLY for weapon powers with range less than attack range.
if (attackRange > powerRange)
if (CombatManager.NotInRange((AbstractCharacter) this.source, tar, powerRange))
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//Range check passed, apply power and clear weapon power.
((PlayerCharacter) this.source).setWeaponPower(null);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//weapon powers with no deferedpoweraction have null Def, but still have bonuses applied already and will finish here.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
PowersManager.applyPower((AbstractCharacter) this.source, tar, Vector3fImmutable.ZERO, def.getDeferredPowerID(), this.trains, false);
PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains);
break;
case Mob:
((Mob) this.source).setWeaponPower(null);
if (def == null) {
return;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
PowersManager.applyPower((AbstractCharacter) this.source, tar, Vector3fImmutable.ZERO, def.getDeferredPowerID(), this.trains, false);
PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains);
break;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
}