Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into spell-effect-turn…
Browse files Browse the repository at this point in the history
…-points-removal
  • Loading branch information
vincent4vx committed Dec 20, 2021
2 parents 65f6197 + 6700dd2 commit dcaf3d7
Show file tree
Hide file tree
Showing 22 changed files with 160 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>fr.quatrevieux.araknemu</groupId>
<artifactId>araknemu</artifactId>
<version>0.9-alpha</version>
<version>0.9.1-alpha</version>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
Expand All @@ -57,7 +57,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.16.0</version>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
* Base class for implements a fighter
Expand Down Expand Up @@ -135,6 +136,15 @@ public final FightTurn turn() {
return turn;
}

@Override
public final void perform(Consumer<FightTurn> action) {
final FightTurn turn = this.turn;

if (turn != null) {
action.accept(turn);
}
}

@Override
public final void attach(Object key, Object value) {
attachments.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import fr.quatrevieux.araknemu.game.fight.turn.FightTurn;
import fr.quatrevieux.araknemu.game.world.creature.Creature;

import java.util.function.Consumer;

/**
* Base fighter
*/
Expand All @@ -56,9 +58,21 @@ public interface Fighter extends Creature<FightCell>, Dispatcher, ActiveFighter
* Get the current fighter turn
*
* @throws FightException If it's not the turn of the current fighter
*
* @see Fighter#perform(Consumer) For perform action on fighter in a safe way (no exception)
*/
public FightTurn turn();

/**
* Perform an action on the current active turn
* The action will take as parameter the current turn
*
* If it's not the turn of the fighter, this method will not call the action
*
* @param action Action to perform
*/
public void perform(Consumer<FightTurn> action);

/**
* Attach an attribute to the fighter
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@

package fr.quatrevieux.araknemu.game.handler.account;

import fr.quatrevieux.araknemu.core.network.exception.ErrorPacket;
import fr.quatrevieux.araknemu.core.network.parser.PacketHandler;
import fr.quatrevieux.araknemu.network.game.GameSession;
import fr.quatrevieux.araknemu.network.game.in.account.AskBoost;
import fr.quatrevieux.araknemu.network.game.out.basic.Noop;

/**
* Boost player characteristic
*/
public final class BoostCharacteristic implements PacketHandler<GameSession, AskBoost> {
@Override
public void handle(GameSession session, AskBoost packet) throws Exception {
session.player()
.properties()
.characteristics()
.boostCharacteristic(packet.characteristic())
;
try {
session.player()
.properties()
.characteristics()
.boostCharacteristic(packet.characteristic())
;
} catch (RuntimeException e) {
throw new ErrorPacket(new Noop(), e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package fr.quatrevieux.araknemu.game.handler.fight;

import fr.quatrevieux.araknemu.core.network.parser.PacketHandler;
import fr.quatrevieux.araknemu.game.fight.turn.FightTurn;
import fr.quatrevieux.araknemu.network.game.GameSession;
import fr.quatrevieux.araknemu.network.game.in.fight.TurnEnd;

Expand All @@ -29,7 +30,7 @@
public final class EndFighterTurn implements PacketHandler<GameSession, TurnEnd> {
@Override
public void handle(GameSession session, TurnEnd packet) {
session.fighter().turn().stop();
session.fighter().perform(FightTurn::stop);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package fr.quatrevieux.araknemu.game.handler.fight;

import fr.quatrevieux.araknemu.core.network.parser.PacketHandler;
import fr.quatrevieux.araknemu.game.fight.turn.FightTurn;
import fr.quatrevieux.araknemu.network.game.GameSession;
import fr.quatrevieux.araknemu.network.game.in.game.action.GameActionAcknowledge;

Expand All @@ -29,7 +30,7 @@
public final class TerminateTurnAction implements PacketHandler<GameSession, GameActionAcknowledge> {
@Override
public void handle(GameSession session, GameActionAcknowledge packet) {
session.fighter().turn().terminate();
session.fighter().perform(FightTurn::terminate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public void spawn() {
map.add(factory.create(data, this));
}

/**
* Respawn a group on the map
*
* Unlike {@link LivingMonsterGroupPosition#spawn()} the maximum number of groups is checked,
* and this method will do nothing if the map is already full
*/
public void respawn() {
if (groupStream().count() < data.maxCount()) {
map.add(factory.create(data, this));
}
}

/**
* Get list of available monster groups on the map
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public Collection<LivingMonsterGroupPosition> byMap(int mapId) {
*/
void respawn(LivingMonsterGroupPosition position, Duration delay) {
activityService.execute(
new SimpleTask(logger -> position.spawn())
new SimpleTask(logger -> position.respawn())
.setDelay(delay.dividedBy(configuration.monsterRespawnSpeedFactor()))
.setMaxTries(2)
.setName("Respawn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public SpecialEffects specials() {

/**
* Boost a characteristic
*
* @throws IllegalStateException When the character has no enough points for boost the required characteristic
*/
public void boostCharacteristic(Characteristic characteristic) {
final BoostStatsData.Interval interval = race.boost(
Expand All @@ -103,7 +105,7 @@ public void boostCharacteristic(Characteristic characteristic) {
final int points = entity.boostPoints() - interval.cost();

if (points < 0) {
throw new IllegalArgumentException("Not enough points for boost stats");
throw new IllegalStateException("Not enough points for boost stats");
}

entity.setBoostPoints(points);
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<Filters>
<ThresholdFilter level="TRACE"/>
<ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
</RollingFile>

Expand All @@ -63,7 +63,7 @@

<Filters>
<ThresholdFilter level="TRACE"/>
<ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
</RollingFile>

Expand All @@ -79,7 +79,7 @@

<Filters>
<ThresholdFilter level="TRACE"/>
<ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
</RollingFile>

Expand All @@ -99,7 +99,7 @@
</Logger>
<Root level="INFO">
<AppenderRef ref="STDOUT" level="TRACE"/>
<AppenderRef ref="errors" level="WARN" />
<AppenderRef ref="errors" level="ERROR" />
</Root>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,23 @@ void playStop() throws Exception {
Fight fight = createFight();
fighter.joinFight(fight, fight.map().get(123));

FightTurn turn = new FightTurn(fighter, fight, Duration.ZERO);
FightTurn turn = new FightTurn(fighter, fight, Duration.ofSeconds(10));
turn.start();

AtomicReference<FightTurn> ref = new AtomicReference<>();
fighter.play(turn);

assertSame(turn, fighter.turn());

fighter.perform(ref::set);
assertSame(turn, ref.get());

ref.set(null);
fighter.stop();

fighter.perform(ref::set);

assertNull(ref.get());
assertThrows(FightException.class, () -> fighter.turn());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,22 @@ void turnNotSet() {

@Test
void playAndStop() {
FightTurn turn = new FightTurn(fighter, fight, Duration.ZERO);
FightTurn turn = new FightTurn(fighter, fight, Duration.ofSeconds(10));
turn.start();

AtomicReference<FightTurn> ref = new AtomicReference<>();
fighter.play(turn);

assertSame(turn, fighter.turn());
fighter.perform(ref::set);
assertSame(turn, ref.get());

ref.set(null);
fighter.stop();

fighter.perform(ref::set);

assertNull(ref.get());
assertThrows(FightException.class, () -> fighter.turn());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -175,6 +176,9 @@ public FightTurn turn() {
return null;
}

@Override
public void perform(Consumer<FightTurn> action) {}

@Override
public boolean dead() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import fr.quatrevieux.araknemu.game.fight.state.PlacementState;
import fr.quatrevieux.araknemu.game.handler.event.Disconnected;
import fr.quatrevieux.araknemu.game.player.GamePlayer;
import io.github.artsok.RepeatedIfExceptionsTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -237,7 +238,7 @@ public Class<Disconnected> event() {
assertFalse(map.creatures().contains(player));
}

@Test
@RepeatedIfExceptionsTest
void saveCorrectLifeWhenSessionClosed() throws Exception{
ExplorationPlayer explorationPlayer = explorationPlayer();
explorationPlayer.player().properties().life().set(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
package fr.quatrevieux.araknemu.game.handler.account;

import fr.quatrevieux.araknemu.core.di.ContainerException;
import fr.quatrevieux.araknemu.core.network.exception.ErrorPacket;
import fr.quatrevieux.araknemu.data.constant.Characteristic;
import fr.quatrevieux.araknemu.data.living.entity.player.Player;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.FightBaseCase;
import fr.quatrevieux.araknemu.network.game.in.account.AskBoost;
import fr.quatrevieux.araknemu.network.game.out.account.Stats;
import fr.quatrevieux.araknemu.network.game.out.basic.Noop;
import fr.quatrevieux.araknemu.network.game.out.info.Error;
import fr.quatrevieux.araknemu.network.game.out.object.InventoryWeight;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -67,12 +69,11 @@ void handleSuccess() throws Exception {
}

@Test
void handleError() throws SQLException, ContainerException, NoSuchFieldException, IllegalAccessException {
void handleError() throws Exception {
this.<Player>readField(gamePlayer(), "entity").setBoostPoints(0);
requestStack.clear();

assertThrows(IllegalArgumentException.class, () -> handler.handle(session, new AskBoost(Characteristic.INTELLIGENCE)));

requestStack.assertEmpty();
assertThrows(ErrorPacket.class, () -> handler.handle(session, new AskBoost(Characteristic.INTELLIGENCE)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public void setUp() throws Exception {

@Test
void notActiveTurn() {
assertThrows(FightException.class, () -> handler.handle(session, new TurnEnd()));
requestStack.clear();
handler.handle(session, new TurnEnd());
requestStack.assertEmpty();
}

@Test
Expand Down
Loading

0 comments on commit dcaf3d7

Please sign in to comment.