From 0d56f2456e327766085441b52d9d4bdd1187edcb Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sun, 10 Mar 2019 03:14:13 -0700 Subject: [PATCH] Added ability to drop items Added ability to drop items (no support for pickup yet) Added ITM entity type Added debug and bounds checking for non-zone entities --- .../com/riiablo/codec/excel/ItemEntry.java | 3 +- core/src/com/riiablo/entity/Entity.java | 5 +- core/src/com/riiablo/entity/ItemHolder.java | 61 +++++++++++++++++++ core/src/com/riiablo/map/MapListener.java | 4 ++ core/src/com/riiablo/map/MapRenderer.java | 7 +++ core/src/com/riiablo/screen/GameScreen.java | 18 ++++-- 6 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 core/src/com/riiablo/entity/ItemHolder.java diff --git a/core/src/com/riiablo/codec/excel/ItemEntry.java b/core/src/com/riiablo/codec/excel/ItemEntry.java index bdb82fec..cbeda929 100644 --- a/core/src/com/riiablo/codec/excel/ItemEntry.java +++ b/core/src/com/riiablo/codec/excel/ItemEntry.java @@ -1,7 +1,5 @@ package com.riiablo.codec.excel; -import com.riiablo.codec.excel.Excel; - public class ItemEntry extends Excel.Entry { @Override public String toString() { @@ -19,6 +17,7 @@ public class ItemEntry extends Excel.Entry { @Column public String type; @Column public String type2; @Column public int component; + @Column public String flippyfile; @Column public String invfile; @Column public String uniqueinvfile; @Column public String setinvfile; diff --git a/core/src/com/riiablo/entity/Entity.java b/core/src/com/riiablo/entity/Entity.java index 484939ab..9116800a 100644 --- a/core/src/com/riiablo/entity/Entity.java +++ b/core/src/com/riiablo/entity/Entity.java @@ -87,7 +87,10 @@ public abstract class Entity { COFD2 getCOFs() { return Riiablo.cofs.chars_cof; } - }; + }, + ITM("ITEMS", + new String[] {"NU"}, + new String[] {"NIL"}); public final String PATH; public final String MODE[]; diff --git a/core/src/com/riiablo/entity/ItemHolder.java b/core/src/com/riiablo/entity/ItemHolder.java new file mode 100644 index 00000000..8fe3858f --- /dev/null +++ b/core/src/com/riiablo/entity/ItemHolder.java @@ -0,0 +1,61 @@ +package com.riiablo.entity; + +import com.badlogic.gdx.assets.AssetDescriptor; +import com.riiablo.Riiablo; +import com.riiablo.codec.Animation; +import com.riiablo.codec.DC; +import com.riiablo.codec.DC6; +import com.riiablo.graphics.PaletteIndexedBatch; +import com.riiablo.item.Item; +import com.riiablo.map.DT1; + +public class ItemHolder extends Entity { + + Item item; + + AssetDescriptor flippyDescriptor; + DC flippy; + + public ItemHolder(Item item) { + super(Type.ITM, "item", null); + this.item = item; + name(item.getName()); + + flippyDescriptor = new AssetDescriptor<>(Type.ITM.PATH + "\\" + item.base.flippyfile + ".dc6", DC6.class); + } + + @Override + public boolean isSelectable() { + return animation.isFinished(); + } + + @Override + public float getLabelOffset() { + return DT1.Tile.SUBTILE_HEIGHT; + } + + @Override + protected void updateCOF() { + Riiablo.assets.load(flippyDescriptor); + Riiablo.assets.finishLoadingAsset(flippyDescriptor); + flippy = Riiablo.assets.get(flippyDescriptor); + animation = Animation.builder() + .layer(flippy) + .build(); + animation.setLooping(false); + animation.updateBox(); + animation.addAnimationListener(new Animation.AnimationListener() { + @Override + public void onFinished(Animation animation) { + Riiablo.audio.play(item.base.dropsound, true); + animation.removeAnimationListener(this); + } + }); + + Riiablo.audio.play("item_flippy", true); + dirty = Dirty.NONE; + } + + @Override + public void drawShadow(PaletteIndexedBatch batch) {} +} diff --git a/core/src/com/riiablo/map/MapListener.java b/core/src/com/riiablo/map/MapListener.java index 7abfb0bc..38ca50d4 100644 --- a/core/src/com/riiablo/map/MapListener.java +++ b/core/src/com/riiablo/map/MapListener.java @@ -37,6 +37,10 @@ public class MapListener { if (entity.over) gameScreen.addLabel(entity.getLabel()); } } + for (Entity entity : gameScreen.entities.values()) { + entity.over = entity.contains(position); + if (entity.over) gameScreen.addLabel(entity.getLabel()); + } } private boolean touchDown() { diff --git a/core/src/com/riiablo/map/MapRenderer.java b/core/src/com/riiablo/map/MapRenderer.java index 27e98a3f..ed48455c 100644 --- a/core/src/com/riiablo/map/MapRenderer.java +++ b/core/src/com/riiablo/map/MapRenderer.java @@ -1114,6 +1114,13 @@ public class MapRenderer { } } } + for (Entity entity : entities.values()) { + Vector2 position = entity.position(); + if ((stx <= position.x && position.x < stx + Tile.SUBTILE_SIZE) + && (sty <= position.y && position.y < sty + Tile.SUBTILE_SIZE)) { + entity.drawDebug(batch, shapes); + } + } tx++; stx += Tile.SUBTILE_SIZE; diff --git a/core/src/com/riiablo/screen/GameScreen.java b/core/src/com/riiablo/screen/GameScreen.java index a7067b45..cddedd18 100644 --- a/core/src/com/riiablo/screen/GameScreen.java +++ b/core/src/com/riiablo/screen/GameScreen.java @@ -30,6 +30,7 @@ import com.badlogic.gdx.utils.viewport.Viewport; import com.riiablo.Keys; import com.riiablo.Riiablo; import com.riiablo.entity.Entity; +import com.riiablo.entity.ItemHolder; import com.riiablo.entity.Player; import com.riiablo.graphics.PaletteIndexedBatch; import com.riiablo.graphics.PaletteIndexedColorDrawable; @@ -108,7 +109,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable //Char character; public Player player; - IntMap entities = new IntMap<>(); + public IntMap entities = new IntMap<>(); Timer.Task updateTask; Socket socket; @@ -361,7 +362,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable break; case Packets.MOVETO: MoveTo moveTo = packet.readValue(MoveTo.class); - Player p = entities.get(moveTo.id); + Entity p = entities.get(moveTo.id); //if (p == player) break; // Disable forced update positions for now if (p != null) { p.setPath(map, new Vector2(moveTo.x, moveTo.y)); @@ -448,7 +449,17 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable } else { stage.screenToStageCoordinates(tmpVec2.set(Gdx.input.getX(), Gdx.input.getY())); Actor hit = stage.hit(tmpVec2.x, tmpVec2.y, true); - if (hit == null) mapListener.update(); + if (hit == null) { + Item cursor = Riiablo.cursor.getItem(); + if (cursor != null && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) { + Riiablo.cursor.setItem(null); + Entity item = new ItemHolder(cursor); + item.position().set(player.position()); + entities.put(entities.size + 1, item); + } else { + mapListener.update(); + } + } else if (DEBUG_HIT) Gdx.app.debug(TAG, hit.toString()); //if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) { // GridPoint2 coords = mapRenderer.coords(); @@ -476,7 +487,6 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable Riiablo.shapes.begin(ShapeRenderer.ShapeType.Line); mapRenderer.drawDebug(Riiablo.shapes); mapRenderer.drawDebugPath(Riiablo.shapes, player.path()); - player.drawDebug(Riiablo.batch, Riiablo.shapes); Riiablo.shapes.end(); b.setProjectionMatrix(Riiablo.viewport.getCamera().combined);