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.
Merge pull request Arakne#290 from vincent4vx/feature-fight-handle-ph…
…ysical-magical-damage-effects handle physical magical damage effects
- Loading branch information
Showing
9 changed files
with
415 additions
and
0 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
109 changes: 109 additions & 0 deletions
109
...quatrevieux/araknemu/game/fight/castable/effect/handler/armor/AlterResistanceHandler.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,109 @@ | ||
/* | ||
* 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.armor; | ||
|
||
import fr.quatrevieux.araknemu.game.fight.castable.FightCastScope; | ||
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.buff.BuffEffect; | ||
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.castable.effect.handler.damage.Damage; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; | ||
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffect; | ||
|
||
/** | ||
* Buff effect for increasing or decrease magical or physical resistance | ||
* | ||
* Like {@link fr.quatrevieux.araknemu.game.fight.castable.effect.handler.characteristic.AddCharacteristicHandler}, | ||
* the effect value will be computed before the buff is applied, so the resistance is fixed | ||
* | ||
* Unlike {@link ReduceDamageHandler}, this effect reduce all damage, not only direct damage | ||
*/ | ||
public final class AlterResistanceHandler implements EffectHandler, BuffHook { | ||
private final boolean physical; | ||
private final int multiplier; | ||
|
||
/** | ||
* @param physical Does this effect alter physical resistance ? If false, it alters magical resistance | ||
* @param multiplier The multiplier to apply to the resistance. 1 for adding resistance, -1 for reducing resistance | ||
*/ | ||
public AlterResistanceHandler(boolean physical, int multiplier) { | ||
this.physical = physical; | ||
this.multiplier = multiplier; | ||
} | ||
|
||
@Override | ||
public void handle(FightCastScope cast, FightCastScope.EffectScope effect) { | ||
throw new UnsupportedOperationException("AlterResistanceHandler can only be used as buff"); | ||
} | ||
|
||
@Override | ||
public void buff(FightCastScope cast, FightCastScope.EffectScope effect) { | ||
final SpellEffect spellEffect = effect.effect(); | ||
final Fighter caster = cast.caster(); | ||
|
||
EffectValue.forEachTargets( | ||
spellEffect, | ||
caster, | ||
effect.targets(), | ||
(target, effectValue) -> target.buffs().add(new Buff( | ||
BuffEffect.fixed(spellEffect, effectValue.value()), | ||
cast.action(), | ||
caster, | ||
target, | ||
this | ||
)) | ||
); | ||
} | ||
|
||
@Override | ||
public void onDamage(Buff buff, Damage value) { | ||
if (value.element().physical() != physical) { | ||
return; | ||
} | ||
|
||
value.fixed(buff.effect().min() * multiplier); | ||
} | ||
|
||
/** | ||
* Create effect handler for adding physical resistance | ||
* So, it will reduce all suffered damage with element neutral or earth | ||
*/ | ||
public static AlterResistanceHandler increasePhysical() { | ||
return new AlterResistanceHandler(true, 1); | ||
} | ||
|
||
/** | ||
* Create effect handler for adding magical resistance | ||
* So, it will reduce all suffered damage with element air, fire or water | ||
*/ | ||
public static AlterResistanceHandler increaseMagical() { | ||
return new AlterResistanceHandler(false, 1); | ||
} | ||
|
||
/** | ||
* Create effect handler for reducing magical resistance | ||
* So, it will increase all suffered damage with element air, fire or water | ||
*/ | ||
public static AlterResistanceHandler reduceMagical() { | ||
return new AlterResistanceHandler(false, -1); | ||
} | ||
} |
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
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.