Skip to content

Commit

Permalink
[fight] Arakne#27 Add steal points effects
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent4vx committed Dec 21, 2021
1 parent dcaf3d7 commit af24d7c
Show file tree
Hide file tree
Showing 15 changed files with 1,032 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,33 @@
public final class BuffEffect implements SpellEffect {
private final SpellEffect baseEffect;

private final int min;
private final int max;
private final int special;
private final String text;
private final int effect;
private final int value;

public BuffEffect(SpellEffect baseEffect, int min) {
this(baseEffect, min, 0, 0);
}

public BuffEffect(SpellEffect baseEffect, int min, int max) {
this(baseEffect, min, max, 0);
}

public BuffEffect(SpellEffect baseEffect, int min, int max, int special) {
this(baseEffect, min, max, special, null);
}

public BuffEffect(SpellEffect baseEffect, int min, int max, int special, String text) {
private BuffEffect(SpellEffect baseEffect, int effect, int value) {
this.baseEffect = baseEffect;
this.min = min;
this.max = max;
this.special = special;
this.text = text;
this.effect = effect;
this.value = value;
}

@Override
public int effect() {
return baseEffect.effect();
return effect;
}

@Override
public int min() {
return min;
return value;
}

@Override
public int max() {
return max;
return 0;
}

@Override
public int special() {
return special;
return 0;
}

@Override
Expand All @@ -86,7 +70,7 @@ public int probability() {

@Override
public String text() {
return text;
return null;
}

@Override
Expand All @@ -98,4 +82,25 @@ public SpellEffectArea area() {
public EffectTarget target() {
return baseEffect.target();
}

/**
* Set a fixed effect value
*
* @param baseEffect The spell effect
* @param value The applied value
*/
public static BuffEffect fixed(SpellEffect baseEffect, int value) {
return new BuffEffect(baseEffect, baseEffect.effect(), value);
}

/**
* Define an effect with custom effect id and a fixed value
*
* @param baseEffect The spell effect
* @param effect The overridden effect id
* @param value The applied value
*/
public static BuffEffect withCustomEffect(SpellEffect baseEffect, int effect, int value) {
return new BuffEffect(baseEffect, effect, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public void onBuffTerminated(Buff buff) {
private SpellEffect computeBuffEffect(CastScope cast, SpellEffect effect) {
final EffectValue value = new EffectValue(effect);

return new BuffEffect(effect, value.value());
return BuffEffect.fixed(effect, value.value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,22 @@
* See: https://forums.jeuxonline.info/sujet/801243/les-formules-de-calcul-dans-dofus#titre_7
*/
public abstract class AbstractPointLostApplier {
public static final int USE_SPELL_EFFECT = 0;

private final Fight fight;
private final AlterPointHook hook;
private final Characteristic characteristic;
private final Characteristic resistance;
private final int removalPointEffect;

private final RandomUtil random = new RandomUtil();

protected AbstractPointLostApplier(Fight fight, AlterPointHook hook, Characteristic characteristic, Characteristic resistance) {
protected AbstractPointLostApplier(Fight fight, AlterPointHook hook, Characteristic characteristic, Characteristic resistance, int removalPointEffect) {
this.fight = fight;
this.hook = hook;
this.characteristic = characteristic;
this.resistance = resistance;
this.removalPointEffect = removalPointEffect;
}

/**
Expand All @@ -79,7 +83,7 @@ public final int apply(CastScope cast, PassiveFighter target, SpellEffect effect
}

if (lost > 0) {
target.buffs().add(new Buff(new BuffEffect(effect, lost), cast.action(), caster, target, hook));
target.buffs().add(new Buff(buffEffect(effect, lost), cast.action(), caster, target, hook));
}

return lost;
Expand All @@ -90,6 +94,16 @@ public final int apply(CastScope cast, PassiveFighter target, SpellEffect effect
*/
protected abstract ActionEffect dodgeMessage(PassiveFighter caster, PassiveFighter target, int value);

/**
* Create the buff effect for the given point lost
*/
private SpellEffect buffEffect(SpellEffect baseEffect, int pointLost) {
return removalPointEffect == USE_SPELL_EFFECT
? BuffEffect.fixed(baseEffect, pointLost)
: BuffEffect.withCustomEffect(baseEffect, removalPointEffect, pointLost)
;
}

/**
* Compute how many points will be loose
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* This file is part of Araknemu.
*
* Araknemu is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Araknemu is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright (c) 2017-2021 Vincent Quatrevieux
*/

package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.point;

import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.BuffEffect;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.EffectHandler;
import fr.quatrevieux.araknemu.game.fight.fighter.ActiveFighter;
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
import fr.quatrevieux.araknemu.game.fight.turn.Turn;
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffect;

/**
* Base effect for steal turn points
*
* @see StealActionPointHandler
* @see StealMovementPointHandler
*/
public abstract class AbstractStealPointHandler implements EffectHandler {
private final Fight fight;
private final AbstractPointLostApplier removePointApplier;
private final AlterPointHook addPointHook;
private final int addPointEffect;

/**
* @param fight Fight where the effect will be applied
* @param removePointApplier Applied use to remove points from targets
* @param addPointHook Applied use to add points to caster
* @param addPointEffect Effect id used by the "add point" buff
*/
public AbstractStealPointHandler(Fight fight, AbstractPointLostApplier removePointApplier, AlterPointHook addPointHook, int addPointEffect) {
this.fight = fight;
this.removePointApplier = removePointApplier;
this.addPointHook = addPointHook;
this.addPointEffect = addPointEffect;
}

@Override
public void handle(CastScope cast, CastScope.EffectScope effect) {
final ActiveFighter caster = cast.caster();
final int stolen = apply(cast, effect);

if (stolen > 0) {
fight.turnList().current()
.filter(turn -> turn.fighter().equals(caster))
.ifPresent(turn -> applyOnCurrentTurn(fight, turn, caster, stolen))
;
}
}

@Override
public void buff(CastScope cast, CastScope.EffectScope effect) {
final ActiveFighter caster = cast.caster();
final int stolen = apply(cast, effect);

if (stolen > 0) {
caster.buffs().add(
new Buff(
BuffEffect.withCustomEffect(effect.effect(), addPointEffect, stolen),
cast.action(),
caster,
caster,
addPointHook
)
);
}
}

/**
* Apply the add point effect to the current turn
* This method is called only if the effect is used as direct effect (i.e. without duration)
* This method should update turn points and send to client the current turn point modification
*
* @param fight The active fight
* @param turn The active turn
* @param toAdd Number of points to add. This value is always >= 1
*/
protected abstract void applyOnCurrentTurn(Fight fight, Turn turn, ActiveFighter caster, int toAdd);

/**
* Apply to all targets and compute the stolen points
*
* @return Stolen action points. 0 if target has dodged
*/
private int apply(CastScope cast, CastScope.EffectScope effect) {
final ActiveFighter caster = cast.caster();
final SpellEffect baseEffect = effect.effect();

int stolen = 0;

for (PassiveFighter target : effect.targets()) {
if (!target.equals(caster)) {
stolen += removePointApplier.apply(cast, target, baseEffect);
}
}

return stolen;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@
*/
public final class ActionPointLostApplier extends AbstractPointLostApplier {
public ActionPointLostApplier(Fight fight) {
super(fight, AlterPointHook.removeActionPoint(fight), Characteristic.ACTION_POINT, Characteristic.RESISTANCE_ACTION_POINT);
this(fight, USE_SPELL_EFFECT);
}

/**
* @param fight The fight where the effect should be applied
* @param removalPointEffect Overrides the spell effect used by the buff
*/
public ActionPointLostApplier(Fight fight, int removalPointEffect) {
super(
fight,
AlterPointHook.removeActionPoint(fight),
Characteristic.ACTION_POINT,
Characteristic.RESISTANCE_ACTION_POINT,
removalPointEffect
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@
*/
public final class MovementPointLostApplier extends AbstractPointLostApplier {
public MovementPointLostApplier(Fight fight) {
super(fight, AlterPointHook.removeMovementPoint(fight), Characteristic.MOVEMENT_POINT, Characteristic.RESISTANCE_MOVEMENT_POINT);
this(fight, USE_SPELL_EFFECT);
}

/**
* @param fight The fight where the effect should be applied
* @param removalPointEffect Overrides the spell effect used by the buff
*/
public MovementPointLostApplier(Fight fight, int removalPointEffect) {
super(
fight,
AlterPointHook.removeMovementPoint(fight),
Characteristic.MOVEMENT_POINT,
Characteristic.RESISTANCE_MOVEMENT_POINT,
removalPointEffect
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of Araknemu.
*
* Araknemu is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Araknemu is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright (c) 2017-2021 Vincent Quatrevieux
*/

package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.point;

import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.fighter.ActiveFighter;
import fr.quatrevieux.araknemu.game.fight.turn.Turn;
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;

/**
* Effect for steal action points
*
* Like {@link ActionPointLostHandler} the removal can be dodged
* This effect is equivalent to apply {@link ActionPointLostHandler} chained with {@link fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.AddActionPointsHandler}
*
* In case of direct effect (i.e. without duration), action points will simply be added to the current turn
*/
public final class StealActionPointHandler extends AbstractStealPointHandler {
/**
* @param fight Fight where the effect will be applied
* @param removeActionPointEffect Effect id used by the "remove action point" buff
* @param addActionPointEffect Effect id used by the "add action point" buff
*/
public StealActionPointHandler(Fight fight, int removeActionPointEffect, int addActionPointEffect) {
super(
fight,
new ActionPointLostApplier(fight, removeActionPointEffect),
AlterPointHook.addActionPoint(fight),
addActionPointEffect
);
}

@Override
protected void applyOnCurrentTurn(Fight fight, Turn turn, ActiveFighter caster, int toAdd) {
turn.points().addActionPoints(toAdd);
fight.send(ActionEffect.addActionPoints(caster, toAdd));
}
}
Loading

0 comments on commit af24d7c

Please sign in to comment.