Improve ranged weapons and use dice rolls to determine range and HP

This commit is contained in:
2022-08-18 15:01:31 +02:00
parent b4f385db5c
commit ffdc9e930a
6 changed files with 31 additions and 11 deletions

View File

@@ -20,7 +20,7 @@ public class EnemyDAO {
.name(result.getString("name"))
.entitySet(result.getString("entset"))
.deadEntitySet(result.getString("dead_entset"))
.hp(result.getInt("hp"))
.hp(result.getString("hp"))
.speed(result.getFloat("speed"))
.animationSpeed(result.getFloat("animation_speed"))
.blocking(result.getBoolean("blocking"))

View File

@@ -22,9 +22,11 @@ public class RangedWeaponDAO {
.cooldown(result.getInt("cooldown"))
.animation(result.getString("animation"))
.sound(result.getString("sound"))
.range(result.getInt("range"))
.range(result.getString("range"))
.punchAnimation(result.getString("punch_animation"))
.punchSound(result.getString("punch_sound"))
.missAnimation(result.getString("miss_animation"))
.missSound(result.getString("miss_sound"))
.build();
items.put(result.getString("id"), weapon);
}

View File

@@ -9,7 +9,7 @@ public class EnemyModel {
private final String name;
private final String entitySet;
private final String deadEntitySet;
private final int hp;
private final String hp;
private final float speed;
private final float animationSpeed;
private final boolean blocking;

View File

@@ -11,7 +11,9 @@ public class RangedWeaponModel {
private final String damage;
private final String animation;
private final String sound;
private final int range;
private final String range;
private final String punchAnimation;
private final String punchSound;
private final String missAnimation;
private final String missSound;
}

View File

@@ -10,6 +10,7 @@ import com.bartlomiejpluta.base.api.move.MoveEvent;
import com.bartlomiejpluta.base.lib.ai.*;
import com.bartlomiejpluta.base.lib.animation.*;
import com.bartlomiejpluta.base.util.random.DiceRoller;
import com.bartlomiejpluta.demo.runner.DemoRunner;
import com.bartlomiejpluta.demo.database.model.EnemyModel;
@@ -30,8 +31,8 @@ public class Enemy extends Character implements NPC {
super(context, context.createEntity(template.getEntitySet()));
this.template = template;
name = template.getName();
hp = template.getHp();
maxHp = hp;
maxHp = DiceRoller.of(template.getHp()).roll();
hp = maxHp;
setSpeed(template.getSpeed());
setAnimationSpeed(template.getAnimationSpeed());
setBlocking(template.isBlocking());

View File

@@ -5,22 +5,27 @@ import java.util.Random;
import lombok.*;
import com.bartlomiejpluta.base.api.context.Context;
import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.api.animation.Animation;
import com.bartlomiejpluta.base.api.move.*;
import com.bartlomiejpluta.base.lib.animation.*;
import com.bartlomiejpluta.base.util.random.DiceRoller;
import com.bartlomiejpluta.demo.database.model.RangedWeaponModel;
import com.bartlomiejpluta.demo.entity.Character;
import com.bartlomiejpluta.demo.util.DiceRoller;
import com.bartlomiejpluta.demo.event.HitEvent;
public class RangedWeapon implements Weapon {
private final Random random = new Random();
private final Context context;
private final DiceRoller roller;
private final DiceRoller dmgRoller;
private final DiceRoller rangeRoller;
private final BulletAnimationRunner animation;
private final String sound;
private final AnimationRunner punchAnimation;
private final String punchSound;
private final AnimationRunner missAnimation;
private final String missSound;
@Getter
private String name;
@@ -31,25 +36,29 @@ public class RangedWeapon implements Weapon {
public RangedWeapon(@NonNull Context context, @NonNull RangedWeaponModel template) {
this.context = context;
this.name = template.getName();
this.roller = DiceRoller.of(template.getDamage());
this.dmgRoller = DiceRoller.of(template.getDamage());
this.rangeRoller = DiceRoller.of(template.getRange());
this.cooldown = template.getCooldown();
this.animation = new BulletAnimationRunner(template.getAnimation())
.range(template.getRange())
.infinite()
.offset(0, -15)
.onHit(this::onHit)
.onMiss(this::onMiss)
.speed(0.25f)
.animationSpeed(0.07f)
.scale(0.6f);
this.sound = template.getSound();
this.punchAnimation = new SimpleAnimationRunner(template.getPunchAnimation());
this.punchSound = template.getPunchSound();
this.missAnimation = new SimpleAnimationRunner(template.getMissAnimation())
.scale(0.4f);
this.missSound = template.getMissSound();
}
private void onHit(Movable attacker, Entity target) {
if(target.isBlocking() && target instanceof Character) {
var character = (Character) target;
var damage = roller.roll();
var damage = dmgRoller.roll();
character.hit(damage);
punchAnimation.run(context, character.getLayer(), character);
context.playSound(punchSound);
@@ -57,11 +66,17 @@ public class RangedWeapon implements Weapon {
}
}
private void onMiss(Movable attacker, Animation animation) {
missAnimation.run(context, ((Character) attacker).getLayer(), animation.getPosition());
context.playSound(missSound);
}
@Override
public boolean attack(Character attacker) {
var direction = attacker.getFaceDirection();
context.playSound(sound);
animation
.range(rangeRoller.roll())
.direction(direction)
.rotation(direction.xAngle - 180)
.run(context, attacker.getLayer(), attacker);