forked from Arakne/Araknemu
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fight] Arakne#27 Add steal points effects
- Loading branch information
1 parent
dcaf3d7
commit af24d7c
Showing
15 changed files
with
1,032 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...mu/game/fight/castable/effect/handler/characteristic/point/AbstractStealPointHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...nemu/game/fight/castable/effect/handler/characteristic/point/StealActionPointHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.