Apply BASE engine improvements

This commit is contained in:
2022-08-18 14:55:01 +02:00
parent dd7a4bf304
commit b4f385db5c
4 changed files with 4 additions and 34 deletions

View File

@@ -20,7 +20,7 @@ public class AnimalAI implements AI {
this.animal = animal;
this.character = character;
this.range = range;
this.idleAI = new RandomMovementAI(animal, 4);
this.idleAI = new RandomMovementAI<>(animal, 4);
this.runawayAI = new RunawayAI<>(animal, character);
}

View File

@@ -18,7 +18,7 @@ public class SimpleEnemyAI extends FollowEntityAI<Enemy, Character> {
public SimpleEnemyAI(Enemy enemy, Character target, int range) {
super(new AstarPathFinder(ASTAR_MAX_NODES), enemy, target);
this.range = range;
this.idle = new RandomMovementAI(enemy, IDLE_MOVEMENT_INTERVAL);
this.idle = new RandomMovementAI<>(enemy, IDLE_MOVEMENT_INTERVAL);
}
@Override

View File

@@ -1,31 +0,0 @@
package com.bartlomiejpluta.demo.util;
import lombok.*;
import java.util.*;
import java.util.regex.*;
@Data
@AllArgsConstructor
public class DiceRoller {
private static final Pattern CODE_PATTERN = Pattern.compile("(\\d+)d(\\d+)([+-]\\d+)?");
private final Random random = new Random();
private int rolls;
private int dice;
private int modifier;
public int roll() {
var sum = modifier;
for(int i=0; i<rolls; ++i) {
sum += random.nextInt(dice) + 1;
}
return Math.max(0, sum);
}
public static DiceRoller of(String code) {
var matcher = CODE_PATTERN.matcher(code);
matcher.matches();
return new DiceRoller(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)));
}
}

View File

@@ -6,9 +6,10 @@ import lombok.*;
import org.joml.Vector2i;
import com.bartlomiejpluta.base.api.context.Context;
import com.bartlomiejpluta.base.lib.animation.*;
import com.bartlomiejpluta.base.util.random.DiceRoller;
import com.bartlomiejpluta.demo.database.model.MeleeWeaponModel;
import com.bartlomiejpluta.demo.entity.Character;
import com.bartlomiejpluta.demo.util.DiceRoller;
import com.bartlomiejpluta.demo.event.HitEvent;