Skip to content

Commit

Permalink
[fight] Arakne#27 Add action and movement point lost effect
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent4vx committed Dec 20, 2021
1 parent b7407fb commit 65f6197
Show file tree
Hide file tree
Showing 40 changed files with 2,388 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

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

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
Expand All @@ -29,18 +27,15 @@
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.EffectHandler;
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffect;
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;

/**
* Alter a characteristic with buff effect
*/
public abstract class AbstractAlterCharacteristicHandler implements EffectHandler, BuffHook {
private final Fight fight;
private final Characteristic characteristic;
private final AlterCharacteristicHook hook;

public AbstractAlterCharacteristicHandler(Fight fight, Characteristic characteristic) {
this.fight = fight;
this.characteristic = characteristic;
public AbstractAlterCharacteristicHandler(AlterCharacteristicHook hook) {
this.hook = hook;
}

@Override
Expand All @@ -57,30 +52,22 @@ public void buff(CastScope cast, CastScope.EffectScope effect) {
}
}

/**
* Compute the buff value
* @fixme One dice for all targets, or one dice per target ?
*/
private SpellEffect computeBuffEffect(CastScope cast, SpellEffect effect) {
final EffectValue value = new EffectValue(effect);

return new BuffEffect(effect, value.value());
}

@Override
public void onBuffStarted(Buff buff) {
buff.target().characteristics().alter(characteristic, value(buff));
fight.send(ActionEffect.buff(buff, value(buff)));
hook.onBuffStarted(buff);
}

@Override
public void onBuffTerminated(Buff buff) {
buff.target().characteristics().alter(characteristic, -value(buff));
hook.onBuffTerminated(buff);
}

/**
* Get the buff effect value
* Compute the buff value
*/
protected abstract int value(Buff buff);
private SpellEffect computeBuffEffect(CastScope cast, SpellEffect effect) {
final EffectValue value = new EffectValue(effect);

return new BuffEffect(effect, value.value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@

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

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.point.AlterPointHook;
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;

/**
* Buff effect for adding action points
* If this effect is not used as buff, it will add actions points to the current turn
*/
public final class AddActionPointsHandler extends AddCharacteristicHandler {
public final class AddActionPointsHandler extends AbstractAlterCharacteristicHandler {
private final Fight fight;

public AddActionPointsHandler(Fight fight) {
super(fight, Characteristic.ACTION_POINT);
super(AlterPointHook.addActionPoint(fight));

this.fight = fight;
}
Expand All @@ -49,14 +48,4 @@ public void handle(CastScope cast, CastScope.EffectScope effect) {
fight.send(ActionEffect.addActionPoints(turn.fighter(), ap));
});
}

@Override
public void onBuffStarted(Buff buff) {
super.onBuffStarted(buff);

fight.turnList().current()
.filter(turn -> turn.fighter().equals(buff.target()))
.ifPresent(turn -> turn.points().addActionPoints(value(buff)))
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;

/**
* Buff effect for adding characteristic points
*/
public class AddCharacteristicHandler extends AbstractAlterCharacteristicHandler {
public AddCharacteristicHandler(Fight fight, Characteristic characteristic) {
super(fight, characteristic);
}

@Override
protected int value(Buff buff) {
return buff.effect().min();
super(AlterCharacteristicHook.add(fight, characteristic));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@

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

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.point.AlterPointHook;
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;

/**
* Buff effect for adding movement points
* If this effect is not used as buff, it will add movement points to the current turn
*/
public final class AddMovementPointsHandler extends AddCharacteristicHandler {
public final class AddMovementPointsHandler extends AbstractAlterCharacteristicHandler {
private final Fight fight;

public AddMovementPointsHandler(Fight fight) {
super(fight, Characteristic.MOVEMENT_POINT);
super(AlterPointHook.addMovementPoint(fight));

this.fight = fight;
}
Expand All @@ -49,14 +48,4 @@ public void handle(CastScope cast, CastScope.EffectScope effect) {
fight.send(ActionEffect.addMovementPoints(turn.fighter(), mp));
});
}

@Override
public void onBuffStarted(Buff buff) {
super.onBuffStarted(buff);

fight.turnList().current()
.filter(turn -> turn.fighter().equals(buff.target()))
.ifPresent(turn -> turn.points().addMovementPoints(value(buff)))
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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;

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.BuffHook;
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;

/**
* Buff hook for handle a characteristic change effect
* The characteristic modification can be positive (add) or negative (remove)
*
* Use factory methods for create the hook instance
*
* @see AlterCharacteristicHook#add(Fight, Characteristic) For add a characteristic
* @see AlterCharacteristicHook#remove(Fight, Characteristic) For remove a characteristic
*/
public class AlterCharacteristicHook implements BuffHook {
private final Fight fight;
private final Characteristic characteristic;
private final int multiplier;

protected AlterCharacteristicHook(Fight fight, Characteristic characteristic, int multiplier) {
this.fight = fight;
this.characteristic = characteristic;
this.multiplier = multiplier;
}

@Override
public void onBuffStarted(Buff buff) {
final int value = buff.effect().min() * multiplier;

buff.target().characteristics().alter(characteristic, value);
fight.send(ActionEffect.buff(buff, value));
}

@Override
public void onBuffTerminated(Buff buff) {
buff.target().characteristics().alter(characteristic, -buff.effect().min() * multiplier);
}

/**
* Create the buff hook for add the given characteristic to the fighter
*/
public static AlterCharacteristicHook add(Fight fight, Characteristic characteristic) {
return new AlterCharacteristicHook(fight, characteristic, 1);
}

/**
* Create the buff hook for remove the given characteristic to the fighter
*/
public static AlterCharacteristicHook remove(Fight fight, Characteristic characteristic) {
return new AlterCharacteristicHook(fight, characteristic, -1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@

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

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.point.AlterPointHook;
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;

/**
* Buff effect for adding action points
* If this effect is not used as buff, it will remove actions points to the current turn
*/
public final class RemoveActionPointsHandler extends RemoveCharacteristicHandler {
public final class RemoveActionPointsHandler extends AbstractAlterCharacteristicHandler {
private final Fight fight;

public RemoveActionPointsHandler(Fight fight) {
super(fight, Characteristic.ACTION_POINT);
super(AlterPointHook.removeActionPoint(fight));

this.fight = fight;
}
Expand All @@ -48,14 +47,4 @@ public void handle(CastScope cast, CastScope.EffectScope effect) {
fight.send(ActionEffect.removeActionPoints(turn.fighter(), ap));
});
}

@Override
public void onBuffStarted(Buff buff) {
super.onBuffStarted(buff);

fight.turnList().current()
.filter(turn -> turn.fighter().equals(buff.target()))
.ifPresent(turn -> turn.points().removeActionPoints(buff.effect().min()))
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;

/**
* Buff effect for removing characteristic points
*/
public class RemoveCharacteristicHandler extends AbstractAlterCharacteristicHandler {
public RemoveCharacteristicHandler(Fight fight, Characteristic characteristic) {
super(fight, characteristic);
}

@Override
protected int value(Buff buff) {
return -buff.effect().min();
super(AlterCharacteristicHook.remove(fight, characteristic));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@

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

import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectValue;
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.point.AlterPointHook;
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;

/**
* Buff effect for removing action points
* If this effect is not used as buff, it will remove movement points to the current turn
*/
public final class RemoveMovementPointsHandler extends RemoveCharacteristicHandler {
public final class RemoveMovementPointsHandler extends AbstractAlterCharacteristicHandler {
private final Fight fight;

public RemoveMovementPointsHandler(Fight fight) {
super(fight, Characteristic.MOVEMENT_POINT);
super(AlterPointHook.removeMovementPoint(fight));

this.fight = fight;
}
Expand All @@ -48,14 +47,4 @@ public void handle(CastScope cast, CastScope.EffectScope effect) {
fight.send(ActionEffect.removeMovementPoints(turn.fighter(), mp));
});
}

@Override
public void onBuffStarted(Buff buff) {
super.onBuffStarted(buff);

fight.turnList().current()
.filter(turn -> turn.fighter().equals(buff.target()))
.ifPresent(turn -> turn.points().removeMovementPoints(buff.effect().min()))
;
}
}
Loading

0 comments on commit 65f6197

Please sign in to comment.