Enable collecting items from map to equipment
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package com.bartlomiejpluta.demo.world.item;
|
||||
|
||||
import com.bartlomiejpluta.base.api.icon.Icon;
|
||||
|
||||
public interface Item extends Icon {
|
||||
String getName();
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.bartlomiejpluta.base.api.context.ContextHolder;
|
||||
import com.bartlomiejpluta.base.api.icon.Icon;
|
||||
import com.bartlomiejpluta.base.lib.animation.AnimationRunner;
|
||||
import com.bartlomiejpluta.base.lib.animation.RandomAnimationsRunner;
|
||||
import com.bartlomiejpluta.base.lib.icon.IconDelegate;
|
||||
import com.bartlomiejpluta.base.util.random.DiceRoller;
|
||||
import com.bartlomiejpluta.demo.entity.Creature;
|
||||
import com.bartlomiejpluta.demo.event.HitEvent;
|
||||
@@ -14,15 +15,12 @@ import org.joml.Vector2i;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MeleeWeapon implements Weapon {
|
||||
private final Random random = new Random();
|
||||
public class MeleeWeapon extends IconDelegate implements Weapon {
|
||||
private final Context context;
|
||||
private final DiceRoller roller;
|
||||
private final AnimationRunner animation;
|
||||
private final String sound;
|
||||
@Getter
|
||||
private final Icon icon;
|
||||
@Getter
|
||||
private final String name;
|
||||
@Getter
|
||||
private final int cooldown;
|
||||
@@ -32,22 +30,21 @@ public class MeleeWeapon implements Weapon {
|
||||
}
|
||||
|
||||
public MeleeWeapon(@NonNull DB.model.MeleeWeaponModel template) {
|
||||
super(createIcon(template));
|
||||
|
||||
this.context = ContextHolder.INSTANCE.getContext();
|
||||
this.name = template.getName();
|
||||
this.roller = DiceRoller.of(template.getDamage());
|
||||
this.cooldown = template.getCooldown();
|
||||
this.animation = new RandomAnimationsRunner(2).nRange(0, 2f).nScale(0.2f, 0.15f).uAnimationSpeed(0.5f, 1f).nRotation(0, 10).offset(0, -10).uDelay(250, 500).with(A.animations.get(template.getAnimation()).uid);
|
||||
this.sound = A.sounds.get(template.getSound()).uid;
|
||||
var icons = template.getIcon().split(",");
|
||||
this.icon = context.createIcon(A.iconsets.get(icons[0]).uid, Integer.valueOf(icons[1]), Integer.valueOf(icons[2]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attack(Creature attacker) {
|
||||
var facingNeighbour = attacker.getCoordinates().add(attacker.getFaceDirection().vector, new Vector2i());
|
||||
for (var entity : attacker.getLayer().getEntities()) {
|
||||
if (entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Creature) {
|
||||
var character = (Creature) entity;
|
||||
if (entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Creature character) {
|
||||
var damage = roller.roll();
|
||||
character.hit(attacker, damage);
|
||||
animation.run(context, character.getLayer(), character);
|
||||
@@ -59,4 +56,9 @@ public class MeleeWeapon implements Weapon {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Icon createIcon(DB.model.MeleeWeaponModel template) {
|
||||
var icons = template.getIcon().split(",");
|
||||
return ContextHolder.INSTANCE.getContext().createIcon(A.iconsets.get(icons[0]).uid, Integer.parseInt(icons[1]), Integer.parseInt(icons[2]));
|
||||
}
|
||||
}
|
||||
@@ -9,16 +9,14 @@ import com.bartlomiejpluta.base.api.move.Movable;
|
||||
import com.bartlomiejpluta.base.lib.animation.AnimationRunner;
|
||||
import com.bartlomiejpluta.base.lib.animation.BulletAnimationRunner;
|
||||
import com.bartlomiejpluta.base.lib.animation.SimpleAnimationRunner;
|
||||
import com.bartlomiejpluta.base.lib.icon.IconDelegate;
|
||||
import com.bartlomiejpluta.base.util.random.DiceRoller;
|
||||
import com.bartlomiejpluta.demo.entity.Creature;
|
||||
import com.bartlomiejpluta.demo.event.HitEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RangedWeapon implements Weapon {
|
||||
private final Random random = new Random();
|
||||
public class RangedWeapon extends IconDelegate implements Weapon {
|
||||
private final Context context;
|
||||
private final DiceRoller dmgRoller;
|
||||
private final DiceRoller rangeRoller;
|
||||
@@ -29,8 +27,6 @@ public class RangedWeapon implements Weapon {
|
||||
private final AnimationRunner missAnimation;
|
||||
private final String missSound;
|
||||
@Getter
|
||||
private final Icon icon;
|
||||
@Getter
|
||||
private final String name;
|
||||
@Getter
|
||||
private final int cooldown;
|
||||
@@ -40,6 +36,8 @@ public class RangedWeapon implements Weapon {
|
||||
}
|
||||
|
||||
public RangedWeapon(@NonNull DB.model.RangedWeaponModel template) {
|
||||
super(createIcon(template));
|
||||
|
||||
this.context = ContextHolder.INSTANCE.getContext();
|
||||
this.name = template.getName();
|
||||
this.dmgRoller = DiceRoller.of(template.getDamage());
|
||||
@@ -51,14 +49,11 @@ public class RangedWeapon implements Weapon {
|
||||
this.punchSound = A.sounds.get(template.getPunchSound()).uid;
|
||||
this.missAnimation = new SimpleAnimationRunner(A.animations.get(template.getMissAnimation()).uid).scale(0.4f);
|
||||
this.missSound = A.sounds.get(template.getMissSound()).uid;
|
||||
var icons = template.getIcon().split(",");
|
||||
this.icon = context.createIcon(A.iconsets.get(icons[0]).uid, Integer.valueOf(icons[1]), Integer.valueOf(icons[2]));
|
||||
}
|
||||
|
||||
private void onHit(Movable attacker, Entity target) {
|
||||
if (target.isBlocking() && target instanceof Creature) {
|
||||
if (target.isBlocking() && target instanceof Creature character) {
|
||||
var namedAttacker = (Creature) attacker;
|
||||
var character = (Creature) target;
|
||||
var damage = dmgRoller.roll();
|
||||
character.hit(namedAttacker, damage);
|
||||
punchAnimation.run(context, character.getLayer(), character);
|
||||
@@ -79,4 +74,9 @@ public class RangedWeapon implements Weapon {
|
||||
animation.range(rangeRoller.roll()).direction(direction).rotation(direction.xAngle - 180).run(context, attacker.getLayer(), attacker);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Icon createIcon(DB.model.RangedWeaponModel template) {
|
||||
var icons = template.getIcon().split(",");
|
||||
return ContextHolder.INSTANCE.getContext().createIcon(A.iconsets.get(icons[0]).uid, Integer.parseInt(icons[1]), Integer.parseInt(icons[2]));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.bartlomiejpluta.demo.world.weapon;
|
||||
|
||||
import com.bartlomiejpluta.base.api.icon.Icon;
|
||||
import com.bartlomiejpluta.demo.entity.Creature;
|
||||
import com.bartlomiejpluta.demo.world.item.Item;
|
||||
|
||||
public interface Weapon {
|
||||
String getName();
|
||||
|
||||
Icon getIcon();
|
||||
public interface Weapon extends Item {
|
||||
|
||||
int getCooldown();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user