From a9261ccf63befc7cd43e9c933c4ad55bca3acb5e Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 19:42:28 +0200 Subject: [PATCH 1/8] Introducing constants --- .../src/com/interrupt/dungeoneer/entities/Player.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java index 9b72b557..00207298 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java @@ -142,7 +142,10 @@ public class Player extends Actor { private Integer tapLength = null; - public int hotbarSize = 5; + private static final int DEFAULT_HOTBAR_SIZE = 5; + private static final int MAX_HOTBAR_SIZE = 10; + public int hotbarSize = DEFAULT_HOTBAR_SIZE; + public int inventorySize = 23; public Item hovering = null; @@ -285,7 +288,7 @@ public void addInventorySlot() { } public boolean canAddHotbarSlot() { - return hotbarSize < 10; + return hotbarSize < MAX_HOTBAR_SIZE; } public void addHotbarSlot() { @@ -296,7 +299,7 @@ public void addHotbarSlot() { Game.hudManager.backpack.refresh(); Game.hudManager.quickSlots.refresh(); - if(hotbarSize >= 9) { + if(hotbarSize >= MAX_HOTBAR_SIZE - 1) { SteamApi.api.achieve("SQUID4"); } } From b1e5d5e765d32795c916656e18f5c0126fc1b9e4 Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 19:49:57 +0200 Subject: [PATCH 2/8] Introducing backpack size --- .../src/com/interrupt/dungeoneer/entities/Player.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java index 00207298..76e75bd7 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java @@ -146,6 +146,10 @@ public class Player extends Actor { private static final int MAX_HOTBAR_SIZE = 10; public int hotbarSize = DEFAULT_HOTBAR_SIZE; + private static final int DEFAULT_BACKPACK_SIZE = 18; + private static int MAX_BACKPACK_SIZE = 36; + public int backpackSize = DEFAULT_BACKPACK_SIZE; + public int inventorySize = 23; public Item hovering = null; @@ -271,7 +275,7 @@ public Player(Game game) { } public boolean canAddInventorySlot() { - return inventorySize - hotbarSize < 36; + return inventorySize - hotbarSize < MAX_BACKPACK_SIZE; } public void addInventorySlot() { @@ -281,7 +285,7 @@ public void addInventorySlot() { Game.hudManager.backpack.refresh(); Game.hudManager.quickSlots.refresh(); - if(inventorySize - hotbarSize >= 35) { + if(inventorySize - hotbarSize >= MAX_BACKPACK_SIZE - 1) { SteamApi.api.achieve("SQUID3"); } } From e4bab3733be58feb298feba7ff398c3927193cb3 Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 19:52:48 +0200 Subject: [PATCH 3/8] Using backpack size instead of calculation --- .../src/com/interrupt/dungeoneer/entities/Player.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java index 76e75bd7..d874b48b 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java @@ -11,7 +11,6 @@ import com.badlogic.gdx.math.collision.BoundingBox; import com.badlogic.gdx.math.collision.Ray; import com.badlogic.gdx.utils.Array; -import com.badlogic.gdx.utils.IntArray; import com.interrupt.api.steam.SteamApi; import com.interrupt.dungeoneer.Audio; import com.interrupt.dungeoneer.GameInput; @@ -40,7 +39,6 @@ import com.interrupt.dungeoneer.tiles.ExitTile; import com.interrupt.dungeoneer.tiles.Tile; import com.interrupt.helpers.PlayerHistory; -import com.interrupt.managers.HUDManager; import com.interrupt.managers.StringManager; import java.text.MessageFormat; @@ -150,6 +148,7 @@ public class Player extends Actor { private static int MAX_BACKPACK_SIZE = 36; public int backpackSize = DEFAULT_BACKPACK_SIZE; + @Deprecated public int inventorySize = 23; public Item hovering = null; @@ -275,7 +274,7 @@ public Player(Game game) { } public boolean canAddInventorySlot() { - return inventorySize - hotbarSize < MAX_BACKPACK_SIZE; + return backpackSize < MAX_BACKPACK_SIZE; } public void addInventorySlot() { @@ -285,7 +284,7 @@ public void addInventorySlot() { Game.hudManager.backpack.refresh(); Game.hudManager.quickSlots.refresh(); - if(inventorySize - hotbarSize >= MAX_BACKPACK_SIZE - 1) { + if(backpackSize >= MAX_BACKPACK_SIZE - 1) { SteamApi.api.achieve("SQUID3"); } } @@ -298,7 +297,6 @@ public boolean canAddHotbarSlot() { public void addHotbarSlot() { if(canAddHotbarSlot()) { hotbarSize++; - inventorySize++; inventory.add(null); Game.hudManager.backpack.refresh(); Game.hudManager.quickSlots.refresh(); From 07fb73ae01a39d06a053fb3fe65e4bdd7ec8ecc3 Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 19:55:00 +0200 Subject: [PATCH 4/8] Calculating inventory size --- .../interrupt/dungeoneer/entities/Player.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java index d874b48b..4b9741ad 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java @@ -1965,22 +1965,23 @@ public boolean addToInventory(Item item, boolean autoEquip) return true; } - public boolean addToBackpack(Item item) { - - if(inventory.contains(item, true)) return false; - - // Find a spot in the backpack - for(int i = hotbarSize; i < inventorySize; i++) { - if(inventory.get(i) == null) { - inventory.set(i, item); - item.onPickup(); - Game.RefreshUI(); - return true; - } - } + public boolean addToBackpack(Item item) { + if (inventory.contains(item, true)) + return false; + + // Find a spot in the backpack + for (int i = hotbarSize; i < getTargetInventorySize(); i++) { + if (inventory.get(i) == null) { + inventory.set(i, item); + item.onPickup(); + Game.RefreshUI(); + + return true; + } + } - return false; - } + return false; + } public void removeFromInventory(Item item) { @@ -2585,4 +2586,8 @@ public void resetInventoryDrawables() { itm.drawable.refresh(); } } + + public int getTargetInventorySize() { + return hotbarSize + backpackSize; + } } From 765c1b91545a91e41312643f471aed6865a9139d Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 19:58:33 +0200 Subject: [PATCH 5/8] Updating method names --- .../interrupt/dungeoneer/entities/Player.java | 48 ++++++++++--------- .../dungeoneer/entities/items/BagUpgrade.java | 2 +- .../entities/triggers/TriggeredShop.java | 16 +++---- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java index 4b9741ad..a7bf2adc 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java @@ -273,39 +273,41 @@ public Player(Game game) { canStepUpOn = false; } - public boolean canAddInventorySlot() { + public boolean canAddBackpackSlot() { return backpackSize < MAX_BACKPACK_SIZE; } - public void addInventorySlot() { - if(canAddInventorySlot()) { - inventorySize++; - inventory.add(null); - Game.hudManager.backpack.refresh(); - Game.hudManager.quickSlots.refresh(); + public void addBackpackSlot() { + if (!canAddBackpackSlot()) + return; - if(backpackSize >= MAX_BACKPACK_SIZE - 1) { - SteamApi.api.achieve("SQUID3"); - } - } - } + backpackSize++; + inventory.add(null); + Game.hudManager.backpack.refresh(); + Game.hudManager.quickSlots.refresh(); + + if (backpackSize >= MAX_BACKPACK_SIZE - 1) { + SteamApi.api.achieve("SQUID3"); + } + } public boolean canAddHotbarSlot() { return hotbarSize < MAX_HOTBAR_SIZE; } - public void addHotbarSlot() { - if(canAddHotbarSlot()) { - hotbarSize++; - inventory.add(null); - Game.hudManager.backpack.refresh(); - Game.hudManager.quickSlots.refresh(); + public void addHotbarSlot() { + if (!canAddHotbarSlot()) + return; - if(hotbarSize >= MAX_HOTBAR_SIZE - 1) { - SteamApi.api.achieve("SQUID4"); - } - } - } + hotbarSize++; + inventory.add(null); + Game.hudManager.backpack.refresh(); + Game.hudManager.quickSlots.refresh(); + + if (hotbarSize >= MAX_HOTBAR_SIZE - 1) { + SteamApi.api.achieve("SQUID4"); + } + } public void makeStartingInventory() { diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/items/BagUpgrade.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/items/BagUpgrade.java index 1556a4ca..4e7df311 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/items/BagUpgrade.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/items/BagUpgrade.java @@ -48,7 +48,7 @@ public void UpgradeInventory(Player player) { Game.ShowMessage(upgradeStr, 3f); } } else { - player.addInventorySlot(); + player.addBackpackSlot(); String upgradeStr = StringManager.get("message.bagupgrade"); diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java index 64f923c9..238fb70f 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java @@ -20,24 +20,24 @@ import com.interrupt.managers.StringManager; public class TriggeredShop extends Trigger { - + public enum ShopType { upgrades, scrolls, potions, weapons, wands, armor, persistent } @EditorProperty public String messageFile = null; - + @EditorProperty public ShopType shopType = ShopType.upgrades; - + @EditorProperty public String title = StringManager.get("triggers.TriggeredShop.titleText"); - + @EditorProperty public String description = StringManager.get("triggers.TriggeredShop.descriptionText"); @EditorProperty public boolean pausesGame = false; - + public Array items = null; public TriggeredShop() { hidden = true; spriteAtlas = "editor"; tex = 16; isSolid = true; } @@ -69,7 +69,7 @@ public void init(Level level, Level.Source source) { super.init(level, source); } - + @Override public void doTriggerEvent(String value) { @@ -95,7 +95,7 @@ public boolean act(float delta) { else { showShopOverlay(null); } - + super.doTriggerEvent(value); } @@ -151,7 +151,7 @@ else if(shopType == ShopType.armor) { if(items == null) items = new Array(); else items.clear(); - if(Game.instance.player.canAddInventorySlot()) { + if(Game.instance.player.canAddBackpackSlot()) { BagUpgrade inventoryUpgrade = new BagUpgrade(BagUpgrade.BagUpgradeType.INVENTORY, true); inventoryUpgrade.name = "Soulbound Bag Expansion"; inventoryUpgrade.cost = 30; From 91d8082350e6829ee31e9f786210e4163154ceec Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 20:17:08 +0200 Subject: [PATCH 6/8] Making init of inventory player's responsiblity --- .../dungeoneer/entities/EntitySpawner.java | 76 +++++++++---------- .../dungeoneer/entities/ItemSpawner.java | 56 ++++++-------- .../interrupt/dungeoneer/entities/Player.java | 39 +++++++--- .../entities/triggers/TriggeredShop.java | 20 ++--- 4 files changed, 96 insertions(+), 95 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/EntitySpawner.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/EntitySpawner.java index 2a291a3f..82432fd7 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/EntitySpawner.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/EntitySpawner.java @@ -10,7 +10,7 @@ public class EntitySpawner extends DirectionalEntity { public EntitySpawner() { artType = ArtType.hidden; tex = 0; } public enum ItemPlacement { world, player_hotbar, player_inventory, player_equip } - + @EditorProperty(group = "Spawns") public String entityCategory = "Decorations"; @EditorProperty(group = "Spawns") public String entityName = "Skull"; @EditorProperty(group = "Spawns") public float spawnVelocity = 0.1f; @@ -18,25 +18,25 @@ public enum ItemPlacement { world, player_hotbar, player_inventory, player_equip @EditorProperty(group = "Spawns") public boolean destroyAfterSpawn = false; @EditorProperty(group = "Spawns") public String spawnSound = null; @EditorProperty(group = "Spawns") ItemPlacement placement = ItemPlacement.world; - + @Override public void tick(Level level, float delta) { - + } - + @Override public void onTrigger(Entity instigator, String value) { if(!isActive) return; - + Entity spawned = Game.instance.entityManager.getEntity(entityCategory, entityName); if(spawned != null) { Vector3 speed = getDirection(); speed.scl(spawnVelocity); - + spawned.xa = speed.x; spawned.ya = speed.y; spawned.za = speed.z; - + spawned.x = x + (Game.rand.nextFloat() * spawnSpread.x * 0.5f) - spawnSpread.x * 0.5f; spawned.y = y + (Game.rand.nextFloat() * spawnSpread.y * 0.5f) - spawnSpread.y * 0.5f; spawned.z = z + (Game.rand.nextFloat() * spawnSpread.z * 0.5f) - spawnSpread.z * 0.5f; @@ -50,45 +50,37 @@ public void onTrigger(Entity instigator, String value) { if(spawnSound != null) { Audio.playPositionedSound(spawnSound, new Vector3(x,y,z), 1f, 12f); } - + if(destroyAfterSpawn) isActive = false; } - public void placeInInventory(Entity e) { - if(e == null) + public void placeInInventory(Entity entity) { + if(null == entity) return; - if(e instanceof Item) { - Item item = (Item)e; - - if(Game.instance == null || Game.instance.player == null) - return; - - Player p = Game.instance.player; - - // might need to initialize this? - if(p.inventory != null) { - if (p.inventory.size < p.inventorySize) { - for (int i = 0; i < p.inventorySize; i++) - p.inventory.add(null); - } - } - - boolean foundSpot = false; - - if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) { - foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip); - } - else { - foundSpot = p.addToBackpack(item); - if(!foundSpot) { - foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip); - } - } - - if(!foundSpot) { - p.throwItem(item, Game.GetLevel(), 0f, 0f); - } - } + if(!(entity instanceof Item)) + return; + + if(null == Game.instance || null == Game.instance.player) + return; + + Item item = (Item)entity; + Player player = Game.instance.player; + + boolean foundSpot = false; + + if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) { + foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip); + } + else { + foundSpot = player.addToBackpack(item); + if(!foundSpot) { + foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip); + } + } + + if(!foundSpot) { + player.throwItem(item, Game.GetLevel(), 0f, 0f); + } } } diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/ItemSpawner.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/ItemSpawner.java index 00f9f38e..f333f011 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/ItemSpawner.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/ItemSpawner.java @@ -12,14 +12,14 @@ public class ItemSpawner extends DirectionalEntity { public enum ItemType { melee, ranged, armor, wands, potions, scrolls, decorations, unique, junk, food } public enum ItemPlacement { world, player_hotbar, player_inventory, player_equip } - + @EditorProperty(group = "Spawns") public ItemType itemType = ItemType.melee; @EditorProperty(group = "Spawns") public Integer itemLevel = null; @EditorProperty(group = "Spawns") public Item.ItemCondition itemCondition = Item.ItemCondition.normal; @EditorProperty(group = "Spawns") public String itemName = null; @EditorProperty(group = "Spawns") boolean waitForTrigger = false; @EditorProperty(group = "Spawns") ItemPlacement placement = ItemPlacement.world; - + @Override public void init(Level level, Source source) { if(!waitForTrigger && (source == Source.LEVEL_START || source == Source.SPAWNED) && isActive) { @@ -92,42 +92,34 @@ else if(itemType == ItemType.food) { return null; } - public void placeInInventory(Entity e) { - if(e == null) + public void placeInInventory(Entity entity) { + if(null == entity) return; - if(e instanceof Item) { - Item item = (Item)e; + if(!(entity instanceof Item)) + return; - if(Game.instance == null || Game.instance.player == null) - return; + if(null == Game.instance || null == Game.instance.player) + return; - Player p = Game.instance.player; - - // might need to initialize this? - if(p.inventory != null) { - if (p.inventory.size < p.inventorySize) { - for (int i = 0; i < p.inventorySize; i++) - p.inventory.add(null); - } - } + Item item = (Item)entity; + Player player = Game.instance.player; - boolean foundSpot = false; + boolean foundSpot = false; - if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) { - foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip); - } - else { - foundSpot = p.addToBackpack(item); - if(!foundSpot) { - foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip); - } - } + if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) { + foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip); + } + else { + foundSpot = player.addToBackpack(item); + if(!foundSpot) { + foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip); + } + } - if(!foundSpot) { - p.throwItem(item, Game.GetLevel(), 0f, 0f); - } - } + if(!foundSpot) { + player.throwItem(item, Game.GetLevel(), 0f, 0f); + } } @Override @@ -136,4 +128,4 @@ public void onTrigger(Entity instigator, String value) { spawn(Game.GetLevel()); } } -} \ No newline at end of file +} diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java index a7bf2adc..138d7b5c 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java @@ -125,7 +125,7 @@ public class Player extends Actor { public int levelNum = 0; /** Player inventory. */ - public Array inventory = new Array(); + public Array inventory = new Array<>(); public Integer selectedBarItem = null; public Integer heldItem = null; @@ -310,11 +310,7 @@ public void addHotbarSlot() { } public void makeStartingInventory() { - - // initialize the inventory - if(inventory.size < inventorySize) { - for (int i = 0; i < inventorySize; i++) inventory.add(null); - } + initInventory(); if(startingInventory != null && startingInventory.size > 0) { boolean equippedWeapon = false; @@ -1920,12 +1916,15 @@ public boolean addToInventory(Item item) { public boolean addToInventory(Item item, boolean autoEquip) { - if(item instanceof Key) { + initInventory(); + + if(item instanceof Key) { keys++; return true; } - if(inventory.contains(item, true)) return false; + if (inventoryContains(item)) + return false; // this might be a stack if(item instanceof ItemStack) { @@ -1968,7 +1967,9 @@ public boolean addToInventory(Item item, boolean autoEquip) } public boolean addToBackpack(Item item) { - if (inventory.contains(item, true)) + initInventory(); + + if (inventoryContains(item)) return false; // Find a spot in the backpack @@ -1987,8 +1988,10 @@ public boolean addToBackpack(Item item) { public void removeFromInventory(Item item) { - if(!inventory.contains(item, true)) return; - dequip(item); + if (!inventoryContains(item)) + return; + + dequip(item); // save all the equipped items, so we can update their locations when the array changes Item held = GetHeldItem(); @@ -2592,4 +2595,18 @@ public void resetInventoryDrawables() { public int getTargetInventorySize() { return hotbarSize + backpackSize; } + + public void initInventory() { + if (null == inventory) + inventory = new Array<>(); + + if (inventory.size < getTargetInventorySize()) { + for (int i = 0; i < getTargetInventorySize(); i++) + inventory.add(null); + } + } + + private boolean inventoryContains(Item item) { + return inventory.contains(item, true); + } } diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java index 238fb70f..17fbf2ee 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredShop.java @@ -152,18 +152,18 @@ else if(shopType == ShopType.armor) { else items.clear(); if(Game.instance.player.canAddBackpackSlot()) { - BagUpgrade inventoryUpgrade = new BagUpgrade(BagUpgrade.BagUpgradeType.INVENTORY, true); - inventoryUpgrade.name = "Soulbound Bag Expansion"; - inventoryUpgrade.cost = 30; - inventoryUpgrade.cost += (Game.instance.progression.inventoryUpgrades * Game.instance.progression.inventoryUpgrades) * (int) (inventoryUpgrade.cost * 0.75f); - items.add(new ShopItem(inventoryUpgrade, true,"SQUID2")); + BagUpgrade upgrade = new BagUpgrade(BagUpgrade.BagUpgradeType.INVENTORY, true); + upgrade.name = "Soulbound Bag Expansion"; + upgrade.cost = 30; + upgrade.cost += (Game.instance.progression.inventoryUpgrades * Game.instance.progression.inventoryUpgrades) * (int) (upgrade.cost * 0.75f); + items.add(new ShopItem(upgrade, true,"SQUID2")); } if(Game.instance.player.canAddHotbarSlot()) { - BagUpgrade hotbarUpgrade = new BagUpgrade(BagUpgrade.BagUpgradeType.HOTBAR, true); - hotbarUpgrade.name = "Soulbound Belt Expansion"; - hotbarUpgrade.cost = 60; - hotbarUpgrade.cost += (Game.instance.progression.hotbarUpgrades * Game.instance.progression.hotbarUpgrades) * (int) (hotbarUpgrade.cost); - items.add(new ShopItem(hotbarUpgrade, true, "SQUID1")); + BagUpgrade upgrade = new BagUpgrade(BagUpgrade.BagUpgradeType.HOTBAR, true); + upgrade.name = "Soulbound Belt Expansion"; + upgrade.cost = 60; + upgrade.cost += (Game.instance.progression.hotbarUpgrades * Game.instance.progression.hotbarUpgrades) * (int) (upgrade.cost); + items.add(new ShopItem(upgrade, true, "SQUID1")); } // No upgrades, sell scrolls instead From 87f455453322cebbe5eb635015035cb739cc64c4 Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 20:27:55 +0200 Subject: [PATCH 7/8] Init backpack size --- .../interrupt/dungeoneer/entities/Player.java | 27 +++++++------------ .../com/interrupt/dungeoneer/game/Game.java | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java index 138d7b5c..f9c65b55 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/Player.java @@ -1914,8 +1914,7 @@ public boolean addToInventory(Item item) { return addToInventory(item, true); } - public boolean addToInventory(Item item, boolean autoEquip) - { + public boolean addToInventory(Item item, boolean autoEquip) { initInventory(); if(item instanceof Key) { @@ -1940,21 +1939,15 @@ public boolean addToInventory(Item item, boolean autoEquip) } } - if(inventory.size < inventorySize) inventory.add(item); - else - { - // find an open spot - boolean foundSpot = false; - for(int i = 0; i < inventorySize && !foundSpot; i++) - { - if(inventory.get(i) == null) - { - inventory.set(i, item); - foundSpot = true; - } - } - if(!foundSpot) return false; - } + // find an open spot + boolean foundSpot = false; + for(int i = 0; i < inventory.size && !foundSpot; i++) { + if(inventory.get(i) == null) { + inventory.set(i, item); + foundSpot = true; + } + } + if(!foundSpot) return false; if((item instanceof Weapon || item instanceof Decoration || item instanceof FusedBomb) && heldItem == null && autoEquip) { equip(item); diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/game/Game.java b/Dungeoneer/src/com/interrupt/dungeoneer/game/Game.java index b96d6e00..fd157b7f 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/game/Game.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/game/Game.java @@ -438,8 +438,8 @@ public void Start(int saveLoc) // Set progression player.randomSeed = rand.nextInt(); player.gold = progression.gold; - player.inventorySize += (progression.inventoryUpgrades + progression.hotbarUpgrades); player.hotbarSize += progression.hotbarUpgrades; + player.backpackSize += progression.inventoryUpgrades; player.startPlaytime(); // maybe make the game harder after the player has won before? From e571942b64b2baf292ae564bafbfcd2c59910976 Mon Sep 17 00:00:00 2001 From: Felix Siebeneicker Date: Mon, 20 Jun 2022 21:26:12 +0200 Subject: [PATCH 8/8] Using computed inventory size --- Dungeoneer/src/com/interrupt/dungeoneer/ui/Hotbar.java | 10 +++++----- Dungeoneer/src/com/interrupt/dungeoneer/ui/Hud.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hotbar.java b/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hotbar.java index 9d2d00ce..99715a3b 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hotbar.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hotbar.java @@ -62,15 +62,15 @@ public void refresh() { columns = Game.instance.player.hotbarSize; } else if (this == Game.hudManager.backpack) { invOffset = Game.instance.player.hotbarSize; - rows = (int) Math.ceil((Game.instance.player.inventorySize - invOffset) / columns) + 1; - if ((Game.instance.player.inventorySize - invOffset) % columns == 0) + rows = (int) Math.ceil((Game.instance.player.getTargetInventorySize() - invOffset) / columns) + 1; + if ((Game.instance.player.getTargetInventorySize() - invOffset) % columns == 0) rows--; } for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { final int btnLoc = x + (y * columns) + invOffset; - if (btnLoc < Game.instance.player.inventorySize) { + if (btnLoc < Game.instance.player.getTargetInventorySize()) { Item itm = Game.instance.player.inventory.get(btnLoc); if (itm != null) { MultiTouchButton itmButton = new MultiTouchButton( @@ -107,7 +107,7 @@ private void initButtons() { for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { final int i = x + (y * columns) + invOffset; - if (i < Game.instance.player.inventorySize) { + if (i < Game.instance.player.getTargetInventorySize()) { if (itemButtons.containsKey(i)) { MultiTouchButton hb = itemButtons.get(i); @@ -157,7 +157,7 @@ else if (lastUiTouchPointer != null) && yCursorPos <= ((y + 1) * uiSize) + (yOffset * uiSize) && yCursorPos > (y * uiSize) + (yOffset * uiSize)) { final int btnLoc = x + (y * columns) + invOffset; - if (btnLoc < Game.instance.player.inventorySize) { + if (btnLoc < Game.instance.player.getTargetInventorySize()) { mouseOverSlot = i; } } diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hud.java b/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hud.java index 6609c150..76bc8525 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hud.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/ui/Hud.java @@ -199,7 +199,7 @@ else if(equipOverSlot != null) { else if(Game.instance.input.getPointerX(uiTouchPointer) > Gdx.graphics.getWidth() - uiSize && Game.instance.input.getPointerY(uiTouchPointer) < uiSize) { // dropping item into inventory boolean foundSlot = false; - for(int i = 6; i < Game.instance.player.inventorySize; i++) { + for(int i = 6; i < Game.instance.player.getTargetInventorySize(); i++) { if(Game.instance.player.inventory.get(i) == null) { foundSlot = true; Game.instance.player.inventory.set(i, dragging);