Skip to content

Commit

Permalink
Merge pull request #261 from vincent4vx/spell-effect-spell-boosts
Browse files Browse the repository at this point in the history
Add boost spell effect
  • Loading branch information
vincent4vx authored May 15, 2022
2 parents db9a293 + 5f25dba commit 2cc3a0b
Show file tree
Hide file tree
Showing 27 changed files with 813 additions and 21 deletions.
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());
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import fr.quatrevieux.araknemu.game.listener.fight.fighter.ApplyLeaveReward;
import fr.quatrevieux.araknemu.game.listener.fight.fighter.LeaveOnDisconnect;
import fr.quatrevieux.araknemu.game.listener.fight.fighter.SendFightLeaved;
import fr.quatrevieux.araknemu.game.listener.fight.fighter.SendSpellBoosted;
import fr.quatrevieux.araknemu.game.listener.fight.fighter.SendStats;
import fr.quatrevieux.araknemu.game.listener.fight.fighter.StopFightSession;
import fr.quatrevieux.araknemu.game.player.GamePlayer;
Expand All @@ -52,6 +53,7 @@ public PlayerFighter create(GamePlayer player) {
fighter.dispatcher().add(new LeaveOnDisconnect(fighter));
fighter.dispatcher().add(new ApplyLeaveReward(fighter));
fighter.dispatcher().add(new SendStats(fighter));
fighter.dispatcher().add(new SendSpellBoosted(fighter));

dispatcher.dispatch(new PlayerFighterCreated(fighter));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public default void attach(Object value) {
@Override
public BuffList buffs();

@Override
public FighterSpellList spells();

/**
* Join the fight
*
Expand Down
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import fr.quatrevieux.araknemu.game.fight.exception.FightException;
import fr.quatrevieux.araknemu.game.fight.fighter.AbstractFighter;
import fr.quatrevieux.araknemu.game.fight.fighter.BaseFighterLife;
import fr.quatrevieux.araknemu.game.fight.fighter.BaseFighterSpellList;
import fr.quatrevieux.araknemu.game.fight.fighter.FighterCharacteristics;
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife;
import fr.quatrevieux.araknemu.game.fight.fighter.FighterSpellList;
import fr.quatrevieux.araknemu.game.fight.fighter.operation.FighterOperation;
import fr.quatrevieux.araknemu.game.fight.team.FightTeam;
import fr.quatrevieux.araknemu.game.fight.team.MonsterGroupTeam;
import fr.quatrevieux.araknemu.game.monster.Monster;
import fr.quatrevieux.araknemu.game.monster.reward.MonsterReward;
import fr.quatrevieux.araknemu.game.spell.SpellList;
import fr.quatrevieux.araknemu.game.world.creature.Sprite;
import org.checkerframework.checker.index.qual.Positive;

Expand All @@ -45,6 +46,7 @@ public final class MonsterFighter extends AbstractFighter {
private final BaseFighterLife life;
private final MonsterFighterCharacteristics characteristics;
private final MonsterFighterSprite sprite;
private final FighterSpellList spells;

@SuppressWarnings({"assignment", "argument"})
public MonsterFighter(int id, Monster monster, MonsterGroupTeam team) {
Expand All @@ -55,6 +57,7 @@ public MonsterFighter(int id, Monster monster, MonsterGroupTeam team) {
this.life = new BaseFighterLife(this, monster.life());
this.characteristics = new MonsterFighterCharacteristics(monster, this);
this.sprite = new MonsterFighterSprite(this, monster);
this.spells = new BaseFighterSpellList(monster.spells());
}

@Override
Expand All @@ -78,8 +81,8 @@ public FighterCharacteristics characteristics() {
}

@Override
public SpellList spells() {
return monster.spells();
public FighterSpellList spells() {
return spells;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@
import fr.quatrevieux.araknemu.game.fight.event.FighterReadyStateChanged;
import fr.quatrevieux.araknemu.game.fight.exception.FightException;
import fr.quatrevieux.araknemu.game.fight.fighter.AbstractFighter;
import fr.quatrevieux.araknemu.game.fight.fighter.BaseFighterSpellList;
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter;
import fr.quatrevieux.araknemu.game.fight.fighter.FighterCharacteristics;
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife;
import fr.quatrevieux.araknemu.game.fight.fighter.FighterSpellList;
import fr.quatrevieux.araknemu.game.fight.fighter.operation.FighterOperation;
import fr.quatrevieux.araknemu.game.fight.team.FightTeam;
import fr.quatrevieux.araknemu.game.item.type.Weapon;
import fr.quatrevieux.araknemu.game.player.GamePlayer;
import fr.quatrevieux.araknemu.game.player.PlayerSessionScope;
import fr.quatrevieux.araknemu.game.player.inventory.slot.WeaponSlot;
import fr.quatrevieux.araknemu.game.spell.SpellList;
import fr.quatrevieux.araknemu.game.spell.boost.DispatcherSpellsBoosts;
import fr.quatrevieux.araknemu.game.spell.boost.SimpleSpellsBoosts;
import fr.quatrevieux.araknemu.game.world.creature.Sprite;
import fr.quatrevieux.araknemu.network.game.GameSession;
import org.checkerframework.checker.index.qual.Positive;
Expand All @@ -45,16 +48,21 @@ public final class PlayerFighter extends AbstractFighter implements Fighter, Pla
private final GamePlayer player;
private final PlayerFighterProperties properties;
private final PlayerFighterSprite sprite;
private final FighterSpellList spells;

private boolean ready = false;
private @MonotonicNonNull CastableWeapon weapon;
private @MonotonicNonNull FightTeam team;

@SuppressWarnings({"assignment", "argument"})
@SuppressWarnings({"assignment", "argument", "method.invocation"})
public PlayerFighter(GamePlayer player) {
this.player = player;
this.properties = new PlayerFighterProperties(this, player.properties());
this.sprite = new PlayerFighterSprite(this, player.spriteInfo());
this.spells = new BaseFighterSpellList(
properties.spells(),
new DispatcherSpellsBoosts(new SimpleSpellsBoosts(), dispatcher())
);
}

@Override
Expand Down Expand Up @@ -100,8 +108,8 @@ public PlayerFighterProperties properties() {
}

@Override
public SpellList spells() {
return properties.spells();
public FighterSpellList spells() {
return spells;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.shifting.SwitchPositionHandler;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.shifting.SwitchPositionOnAttackHandler;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.shifting.TeleportHandler;
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.modifier.BoostSpellHandler;
import fr.quatrevieux.araknemu.game.spell.boost.SpellsBoosts;

/**
* Module for register common fight effects
Expand Down Expand Up @@ -228,6 +230,13 @@ public void effects(EffectsHandler handler) {

handler.register(135, new DecreaseCasterSightHandler(fight));
handler.register(136, new BoostCasterSightHandler(fight));

handler.register(284, new BoostSpellHandler(SpellsBoosts.Modifier.HEAL));
handler.register(285, new BoostSpellHandler(SpellsBoosts.Modifier.AP_COST));
handler.register(286, new BoostSpellHandler(SpellsBoosts.Modifier.REDUCE_DELAY));
handler.register(287, new BoostSpellHandler(SpellsBoosts.Modifier.CRITICAL));
handler.register(290, new BoostSpellHandler(SpellsBoosts.Modifier.LAUNCH_PER_TURN));
handler.register(293, new BoostSpellHandler(SpellsBoosts.Modifier.BASE_DAMAGE));
}

@Override
Expand Down
Loading

0 comments on commit 2cc3a0b

Please sign in to comment.