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): Start base for static invocation (Arakne#27)
- Loading branch information
1 parent
65c0089
commit e520a4e
Showing
61 changed files
with
843 additions
and
236 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
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
126 changes: 126 additions & 0 deletions
126
src/main/java/fr/quatrevieux/araknemu/game/fight/FighterList.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,126 @@ | ||
/* | ||
* 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; | ||
|
||
import fr.quatrevieux.araknemu.game.fight.event.FighterRemoved; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; | ||
import fr.quatrevieux.araknemu.game.fight.map.FightCell; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Handle the fighters list of a fight | ||
*/ | ||
public final class FighterList implements Iterable<Fighter> { | ||
private final Fight fight; | ||
private final Set<Fighter> fighters = new LinkedHashSet<>(); | ||
|
||
public FighterList(Fight fight) { | ||
this.fight = fight; | ||
} | ||
|
||
@Override | ||
public @NonNull Iterator<Fighter> iterator() { | ||
return fighters.iterator(); | ||
} | ||
|
||
/** | ||
* Get all fighters as collection. | ||
*/ | ||
public Collection<Fighter> all() { | ||
return Collections.unmodifiableCollection(fighters); | ||
} | ||
|
||
/** | ||
* Add a fighter to the fight | ||
* | ||
* @param fighter The fighter to add | ||
* @param cell The cell where the fighter will be placed | ||
* | ||
* @see Fighter#joinFight(Fight, FightCell) Will be called by this method | ||
* @see #joinTurnList(Fighter, FightCell) Call this method if you want to add the fighter to the turn list | ||
*/ | ||
public void join(Fighter fighter, FightCell cell) { | ||
fighter.joinFight(fight, cell); | ||
fighters.add(fighter); | ||
} | ||
|
||
/** | ||
* Add a fighter to the fight and to the turn list | ||
* | ||
* Note: this method can only be called if the fight is active, during placement state, use {@link #join(Fighter, FightCell)} instead | ||
* | ||
* @param fighter The fighter to add | ||
* @param cell The cell where the fighter will be placed | ||
* | ||
* @see fr.quatrevieux.araknemu.game.fight.turn.FightTurnList#add(Fighter) Will be called by this method | ||
*/ | ||
public void joinTurnList(Fighter fighter, FightCell cell) { | ||
join(fighter, cell); | ||
fight.turnList().add(fighter); | ||
} | ||
|
||
/** | ||
* Remove a fighter from the fight | ||
* Will trigger {@link FighterRemoved} event | ||
* | ||
* Note: if the fighter is on the turn list, it will be removed too | ||
* | ||
* @param fighter The fighter to remove | ||
*/ | ||
public void leave(Fighter fighter) { | ||
fighters.remove(fighter); | ||
|
||
if (fight.active()) { | ||
fight.turnList().remove(fighter); // @todo discriminate active vs static fighter | ||
} | ||
|
||
fight.dispatch(new FighterRemoved(fighter, fight)); | ||
} | ||
|
||
/** | ||
* Get a sequential {@code Stream} with this fighter list as its source. | ||
*/ | ||
public Stream<Fighter> stream() { | ||
return fighters.stream(); | ||
} | ||
|
||
/** | ||
* Get all alive fighters as stream | ||
* | ||
* @see Fighter#dead() | ||
*/ | ||
public Stream<Fighter> alive() { | ||
return fighters.stream().filter(fighter -> !fighter.dead()); | ||
} | ||
|
||
/** | ||
* Internal method for clear all fighters objects. | ||
*/ | ||
void clear() { | ||
fighters.clear(); | ||
} | ||
} |
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
74 changes: 74 additions & 0 deletions
74
...ieux/araknemu/game/fight/castable/effect/handler/invocations/StaticInvocationHandler.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,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 Jean-Alexandre Valentin | ||
*/ | ||
|
||
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.invocations; | ||
|
||
import fr.quatrevieux.araknemu.game.fight.Fight; | ||
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.fighter.FighterFactory; | ||
import fr.quatrevieux.araknemu.game.fight.fighter.invocation.InvocationFighter; | ||
import fr.quatrevieux.araknemu.game.monster.MonsterService; | ||
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect; | ||
|
||
/** | ||
* Handle invocation of a static creature | ||
* Unlike {@link MonsterInvocationHandler}, the invoked monster does not appear in timeline, and cannot perform any action | ||
* | ||
* A new fighter will be created and added to fight but not in timeline | ||
* | ||
* Effect parameters : | ||
* - #1 (min) : monster id | ||
* - #2 (max) : grade number | ||
* | ||
* @see InvocationFighter Invoked fighter @todo change | ||
*/ | ||
public final class StaticInvocationHandler implements EffectHandler { | ||
private final MonsterService monsterService; | ||
private final FighterFactory fighterFactory; | ||
private final Fight fight; | ||
|
||
public StaticInvocationHandler(MonsterService monsterService, FighterFactory fighterFactory, Fight fight) { | ||
this.monsterService = monsterService; | ||
this.fighterFactory = fighterFactory; | ||
this.fight = fight; | ||
} | ||
|
||
@Override | ||
public void buff(FightCastScope cast, FightCastScope.EffectScope effect) { | ||
throw new UnsupportedOperationException("StaticInvocationHandler cannot be used as buff"); | ||
} | ||
|
||
@Override | ||
public void handle(FightCastScope cast, FightCastScope.EffectScope effect) { | ||
// @todo do not use InvocationFighter | ||
final Fighter invocation = fighterFactory.generate(id -> new InvocationFighter( | ||
id, | ||
monsterService.load(effect.effect().min()).get(effect.effect().max()), | ||
cast.caster().team(), | ||
cast.caster() | ||
)); | ||
|
||
fight.fighters().join(invocation, cast.target()); | ||
invocation.init(); | ||
|
||
fight.send(ActionEffect.addStaticInvocation(cast.caster(), invocation)); | ||
} | ||
} |
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.