-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from vincent4vx/spell-effect-spell-boosts
Add boost spell effect
- Loading branch information
Showing
27 changed files
with
813 additions
and
21 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...r/quatrevieux/araknemu/game/fight/castable/effect/handler/modifier/BoostSpellHandler.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,89 @@ | ||
/* | ||
* 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-2022 Vincent Quatrevieux | ||
*/ | ||
|
||
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.modifier; | ||
|
||
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.BuffHook; | ||
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.EffectHandler; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter; | ||
import fr.quatrevieux.araknemu.game.spell.boost.SpellsBoosts; | ||
|
||
/** | ||
* Add a spell boost to a fighter | ||
* The boost is applied on buff start, and removed on buff termination | ||
* | ||
* Parameters: | ||
* - The first effect parameter (i.e. min) is the spell id | ||
* - The third effect parameter (i.e. special) is the boost value | ||
* | ||
* Note: There is no game action packet related to this effect | ||
* | ||
* @see fr.quatrevieux.araknemu.game.fight.fighter.FighterSpellList#boost(int, SpellsBoosts.Modifier, int) | ||
* @see BuffHook#onBuffStarted(Buff) Hook used for apply the boost | ||
* @see BuffHook#onBuffTerminated(Buff) Hook used for removed the boost | ||
*/ | ||
public final class BoostSpellHandler implements EffectHandler, BuffHook { | ||
private final SpellsBoosts.Modifier modifier; | ||
|
||
/** | ||
* @param modifier Spell modifier to apply | ||
*/ | ||
public BoostSpellHandler(SpellsBoosts.Modifier modifier) { | ||
this.modifier = modifier; | ||
} | ||
|
||
@Override | ||
public void handle(CastScope cast, CastScope.EffectScope effect) { | ||
throw new UnsupportedOperationException("Boost spell can only be used as buff"); | ||
} | ||
|
||
@Override | ||
public void buff(CastScope cast, CastScope.EffectScope effect) { | ||
for (PassiveFighter target : effect.targets()) { | ||
target.buffs().add(new Buff(effect.effect(), cast.action(), cast.caster(), target, this)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onBuffStarted(Buff buff) { | ||
final PassiveFighter target = buff.target(); | ||
|
||
if (!(target instanceof Fighter)) { | ||
return; | ||
} | ||
|
||
final Fighter fighter = (Fighter) target; | ||
fighter.spells().boost(buff.effect().min(), modifier, buff.effect().special()); | ||
} | ||
|
||
@Override | ||
public void onBuffTerminated(Buff buff) { | ||
final PassiveFighter target = buff.target(); | ||
|
||
if (!(target instanceof Fighter)) { | ||
return; | ||
} | ||
|
||
final Fighter fighter = (Fighter) target; | ||
fighter.spells().boost(buff.effect().min(), modifier, -buff.effect().special()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/fr/quatrevieux/araknemu/game/fight/fighter/BaseFighterSpellList.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,75 @@ | ||
/* | ||
* 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-2022 Vincent Quatrevieux | ||
*/ | ||
|
||
package fr.quatrevieux.araknemu.game.fight.fighter; | ||
|
||
import fr.quatrevieux.araknemu.game.spell.Spell; | ||
import fr.quatrevieux.araknemu.game.spell.SpellList; | ||
import fr.quatrevieux.araknemu.game.spell.boost.SimpleSpellsBoosts; | ||
import fr.quatrevieux.araknemu.game.spell.boost.SpellsBoosts; | ||
|
||
import java.util.Iterator; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** | ||
* Decorate base spell list for handle fighter spell boosts | ||
*/ | ||
public final class BaseFighterSpellList implements FighterSpellList { | ||
private final SpellList list; | ||
private final SpellsBoosts boosts; | ||
|
||
/** | ||
* @param list Base spell list | ||
*/ | ||
public BaseFighterSpellList(SpellList list) { | ||
this(list, new SimpleSpellsBoosts()); | ||
} | ||
|
||
/** | ||
* @param list Base spell list | ||
* @param boosts Boost instance to use | ||
*/ | ||
public BaseFighterSpellList(SpellList list, SpellsBoosts boosts) { | ||
this.list = list; | ||
this.boosts = boosts; | ||
} | ||
|
||
@Override | ||
public Spell get(int spellId) { | ||
return boosts.get(list.get(spellId)); | ||
} | ||
|
||
@Override | ||
public boolean has(int spellId) { | ||
return list.has(spellId); | ||
} | ||
|
||
@Override | ||
public Iterator<Spell> iterator() { | ||
return StreamSupport.stream(list.spliterator(), false) | ||
.map(boosts::get) | ||
.iterator() | ||
; | ||
} | ||
|
||
@Override | ||
public void boost(int spellId, SpellsBoosts.Modifier modifier, int value) { | ||
boosts.boost(spellId, modifier, value); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/fr/quatrevieux/araknemu/game/fight/fighter/FighterSpellList.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,38 @@ | ||
/* | ||
* 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-2022 Vincent Quatrevieux | ||
*/ | ||
|
||
package fr.quatrevieux.araknemu.game.fight.fighter; | ||
|
||
import fr.quatrevieux.araknemu.game.spell.SpellList; | ||
import fr.quatrevieux.araknemu.game.spell.boost.SpellsBoosts; | ||
|
||
/** | ||
* Base type for handle spell list of a fighter | ||
* Add support of spell boost | ||
*/ | ||
public interface FighterSpellList extends SpellList { | ||
/** | ||
* Boost the spell | ||
* | ||
* @param spellId The spell to boost | ||
* @param modifier The effect modifier | ||
* @param value The boosted value. Use a negative value for remove the boost. | ||
*/ | ||
public void boost(int spellId, SpellsBoosts.Modifier modifier, int value); | ||
} |
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.