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 9b72b557..f9c65b55 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; @@ -127,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; @@ -142,7 +140,15 @@ 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; + + private static final int DEFAULT_BACKPACK_SIZE = 18; + private static int MAX_BACKPACK_SIZE = 36; + public int backpackSize = DEFAULT_BACKPACK_SIZE; + + @Deprecated public int inventorySize = 23; public Item hovering = null; @@ -267,47 +273,44 @@ public Player(Game game) { canStepUpOn = false; } - public boolean canAddInventorySlot() { - return inventorySize - hotbarSize < 36; + 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(inventorySize - hotbarSize >= 35) { - 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 < 10; + return hotbarSize < MAX_HOTBAR_SIZE; } - public void addHotbarSlot() { - if(canAddHotbarSlot()) { - hotbarSize++; - inventorySize++; - inventory.add(null); - Game.hudManager.backpack.refresh(); - Game.hudManager.quickSlots.refresh(); + public void addHotbarSlot() { + if (!canAddHotbarSlot()) + return; - if(hotbarSize >= 9) { - SteamApi.api.achieve("SQUID4"); - } - } - } + hotbarSize++; + inventory.add(null); + Game.hudManager.backpack.refresh(); + Game.hudManager.quickSlots.refresh(); - public void makeStartingInventory() { + if (hotbarSize >= MAX_HOTBAR_SIZE - 1) { + SteamApi.api.achieve("SQUID4"); + } + } - // initialize the inventory - if(inventory.size < inventorySize) { - for (int i = 0; i < inventorySize; i++) inventory.add(null); - } + public void makeStartingInventory() { + initInventory(); if(startingInventory != null && startingInventory.size > 0) { boolean equippedWeapon = false; @@ -1911,14 +1914,16 @@ public boolean addToInventory(Item item) { return addToInventory(item, true); } - public boolean addToInventory(Item item, boolean autoEquip) - { - if(item instanceof Key) { + public boolean addToInventory(Item item, boolean autoEquip) { + 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) { @@ -1934,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); @@ -1960,27 +1959,32 @@ public boolean addToInventory(Item item, boolean autoEquip) return true; } - public boolean addToBackpack(Item item) { + public boolean addToBackpack(Item item) { + initInventory(); - if(inventory.contains(item, true)) return false; + if (inventoryContains(item)) + 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; - } - } + // 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 false; - } + return true; + } + } + + return false; + } 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(); @@ -2580,4 +2584,22 @@ public void resetInventoryDrawables() { itm.drawable.refresh(); } } + + 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/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..17fbf2ee 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,19 +151,19 @@ else if(shopType == ShopType.armor) { if(items == null) items = new Array(); else items.clear(); - if(Game.instance.player.canAddInventorySlot()) { - 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")); + if(Game.instance.player.canAddBackpackSlot()) { + 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 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? 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);