forked from Arakne/Araknemu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fight): End turn glyph effect Arakne#27
- Loading branch information
1 parent
09b13b6
commit 60a6027
Showing
14 changed files
with
677 additions
and
64 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...java/fr/quatrevieux/araknemu/game/fight/castable/effect/handler/object/AbstractGlyph.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,112 @@ | ||
/* | ||
* 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-2023 Vincent Quatrevieux | ||
*/ | ||
|
||
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.object; | ||
|
||
import fr.quatrevieux.araknemu.game.fight.Fight; | ||
import fr.quatrevieux.araknemu.game.fight.castable.FightCastScope; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; | ||
import fr.quatrevieux.araknemu.game.fight.map.BattlefieldObject; | ||
import fr.quatrevieux.araknemu.game.fight.map.FightCell; | ||
import fr.quatrevieux.araknemu.game.spell.Spell; | ||
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect; | ||
import fr.quatrevieux.araknemu.network.game.out.fight.battlefield.RemoveZone; | ||
import org.checkerframework.checker.index.qual.GTENegativeOne; | ||
import org.checkerframework.checker.index.qual.NonNegative; | ||
|
||
/** | ||
* Base glyph object. | ||
* Implementations must call {@link #trigger(Fighter)} on the hook method corresponding to the glyph type (start or end turn) | ||
*/ | ||
abstract class AbstractGlyph implements BattlefieldObject { | ||
private final Fight fight; | ||
private final FightCell cell; | ||
private final Fighter caster; | ||
private final @NonNegative int size; | ||
private final int color; | ||
private final Spell spell; | ||
private @GTENegativeOne int remainingTurns; | ||
|
||
/** | ||
* @param fight The current fight | ||
* @param cell The cell where the glyph is | ||
* @param caster The caster of the glyph | ||
* @param size The size of the glyph. 0 is for a single cell glyph | ||
* @param color The color of the glyph. Used by the client as layer for identifying the glyph | ||
* @param remainingTurns The remaining turns of the glyph. -1 for infinite. | ||
* @param spell The spell that is applied when a fighter is on the glyph at the start of his turn | ||
*/ | ||
public AbstractGlyph(Fight fight, FightCell cell, Fighter caster, @NonNegative int size, int color, @GTENegativeOne int remainingTurns, Spell spell) { | ||
this.fight = fight; | ||
this.cell = cell; | ||
this.caster = caster; | ||
this.size = size; | ||
this.color = color; | ||
this.remainingTurns = remainingTurns; | ||
this.spell = spell; | ||
} | ||
|
||
@Override | ||
public final FightCell cell() { | ||
return cell; | ||
} | ||
|
||
@Override | ||
public final Fighter caster() { | ||
return caster; | ||
} | ||
|
||
@Override | ||
public final @NonNegative int size() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public final int color() { | ||
return color; | ||
} | ||
|
||
@Override | ||
public final boolean refresh() { | ||
if (remainingTurns == -1) { | ||
return true; | ||
} | ||
|
||
if (remainingTurns == 0) { | ||
return false; | ||
} | ||
|
||
return --remainingTurns > 0; | ||
} | ||
|
||
@Override | ||
public final void disappear() { | ||
fight.send(new RemoveZone(this)); | ||
} | ||
|
||
/** | ||
* Trigger the glyph effects on the given fighter | ||
*/ | ||
protected final void trigger(Fighter fighter) { | ||
final FightCastScope castScope = FightCastScope.fromCell(spell, caster, cell, fighter.cell(), spell.effects()); | ||
|
||
fight.send(ActionEffect.glyphTriggered(caster, fighter, cell, spell)); | ||
fight.effects().apply(castScope); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...uatrevieux/araknemu/game/fight/castable/effect/handler/object/AddEndTurnGlyphHandler.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,86 @@ | ||
/* | ||
* 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-2023 Vincent Quatrevieux | ||
*/ | ||
|
||
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.object; | ||
|
||
import fr.quatrevieux.araknemu.game.fight.Fight; | ||
import fr.quatrevieux.araknemu.game.fight.castable.BaseCastScope; | ||
import fr.quatrevieux.araknemu.game.fight.castable.FightCastScope; | ||
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.EffectHandler; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; | ||
import fr.quatrevieux.araknemu.game.fight.map.FightCell; | ||
import fr.quatrevieux.araknemu.game.spell.SpellService; | ||
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffect; | ||
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect; | ||
import fr.quatrevieux.araknemu.network.game.out.fight.battlefield.AddZones; | ||
import fr.quatrevieux.araknemu.util.Asserter; | ||
|
||
/** | ||
* Add a glyph on the target cell | ||
* The glyph will trigger the related spell on end turn of each fighter in its area | ||
* | ||
* Arguments: | ||
* - min: spell ID | ||
* - max: spell level | ||
* - special: glyph color | ||
* | ||
* This effect will also take in account: | ||
* - The effect duration as glyph duration | ||
* - The effect area as glyph size | ||
* | ||
* Remaining turns of the glyph are decreased at the start of the caster turn. | ||
* So it will disappear just before the caster turn. | ||
* | ||
* @see EndTurnGlyph | ||
*/ | ||
public final class AddEndTurnGlyphHandler implements EffectHandler { | ||
private final Fight fight; | ||
private final SpellService spellService; | ||
|
||
public AddEndTurnGlyphHandler(Fight fight, SpellService spellService) { | ||
this.fight = fight; | ||
this.spellService = spellService; | ||
} | ||
|
||
@Override | ||
public void handle(FightCastScope cast, BaseCastScope<Fighter, FightCell>.EffectScope effect) { | ||
throw new UnsupportedOperationException("AddEndTurnGlyphHandler must have a duration"); | ||
} | ||
|
||
@Override | ||
public void buff(FightCastScope cast, BaseCastScope<Fighter, FightCell>.EffectScope effect) { | ||
final Fighter caster = cast.caster(); | ||
final SpellEffect spellEffect = effect.effect(); | ||
|
||
final EndTurnGlyph glyph = new EndTurnGlyph( | ||
fight, | ||
cast.target(), | ||
caster, | ||
spellEffect.area().size(), | ||
spellEffect.special(), | ||
spellEffect.duration(), | ||
spellService | ||
.get(spellEffect.min()) | ||
.level(Asserter.assertPositive(spellEffect.max())) | ||
); | ||
|
||
fight.map().objects().add(glyph); | ||
fight.send(ActionEffect.packet(caster, new AddZones(glyph))); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../java/fr/quatrevieux/araknemu/game/fight/castable/effect/handler/object/EndTurnGlyph.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,50 @@ | ||
/* | ||
* 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-2023 Vincent Quatrevieux | ||
*/ | ||
|
||
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.object; | ||
|
||
import fr.quatrevieux.araknemu.game.fight.Fight; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; | ||
import fr.quatrevieux.araknemu.game.fight.map.FightCell; | ||
import fr.quatrevieux.araknemu.game.spell.Spell; | ||
import org.checkerframework.checker.index.qual.GTENegativeOne; | ||
import org.checkerframework.checker.index.qual.NonNegative; | ||
|
||
/** | ||
* Glyph object which is triggered at end of turn, created by {@link AddEndTurnGlyphHandler} | ||
*/ | ||
final class EndTurnGlyph extends AbstractGlyph { | ||
/** | ||
* @param fight The current fight | ||
* @param cell The cell where the glyph is | ||
* @param caster The caster of the glyph | ||
* @param size The size of the glyph. 0 is for a single cell glyph | ||
* @param color The color of the glyph. Used by the client as layer for identifying the glyph | ||
* @param remainingTurns The remaining turns of the glyph. -1 for infinite. | ||
* @param spell The spell that is applied when a fighter is on the glyph at the start of his turn | ||
*/ | ||
public EndTurnGlyph(Fight fight, FightCell cell, Fighter caster, @NonNegative int size, int color, @GTENegativeOne int remainingTurns, Spell spell) { | ||
super(fight, cell, caster, size, color, remainingTurns, spell); | ||
} | ||
|
||
@Override | ||
public void onEndTurnInArea(Fighter fighter) { | ||
trigger(fighter); | ||
} | ||
} |
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
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
Oops, something went wrong.