Skip to content

Commit

Permalink
Fix satchel empty behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
GregHib committed May 1, 2024
1 parent 5caf9fc commit dbbd370
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package world.gregs.voidps.world.activity.quest.toweroflife
import net.pearx.kasechange.toLowerSpaceCase
import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.client.ui.interact.itemOnItem
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.inv.charges
import world.gregs.voidps.engine.inv.inventory
import world.gregs.voidps.engine.inv.transact.operation.AddItem.add
Expand All @@ -25,23 +26,24 @@ inventoryItem("Inspect", "*_satchel") {

inventoryItem("Empty", "*_satchel") {
var charges = player.inventory.charges(player, slot)
player.inventory.transaction {
if (charges and cake != 0) {
add("cake")
charges = charges and cake.inv()
setCharge(slot, charges)
}
if (!failed && charges and banana != 0 && inventory.spaces > 0) {
add("banana")
charges = charges and banana.inv()
setCharge(slot, charges)
charges = withdraw(player, slot, charges, "banana", banana)
charges = withdraw(player, slot, charges, "cake", cake)
withdraw(player, slot, charges, "triangle_sandwich", sandwich)
}

fun withdraw(player: Player, slot: Int, charges: Int, id: String, food: Int): Int {
if (charges and food != 0) {
val success = player.inventory.transaction {
add(id)
setCharge(slot, charges and food.inv())
}
if (!failed && charges and sandwich != 0 && inventory.spaces > 0) {
add("triangle_sandwich")
charges = charges and sandwich.inv()
setCharge(slot, charges)
if (success) {
return charges and food.inv()
} else {
player.message("You don't have enough free space to empty your satchel.")
}
}
return charges
}

itemOnItem("cake", "*_satchel") { player ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ internal class SatchelTest : WorldTest() {

player.itemOption("Empty", "plain_satchel")

assertEquals(6, player.inventory.charges(player, 0))
assertTrue(player.inventory.contains("cake"))
assertFalse(player.inventory.contains("banana"))
assertEquals(5, player.inventory.charges(player, 0))
assertTrue(player.inventory.contains("banana"))
assertFalse(player.inventory.contains("cake"))
assertFalse(player.inventory.contains("triangle_sandwich"))
}

@ParameterizedTest
@ValueSource(strings = [ "cake", "banana", "triangle_sandwich" ])
@ValueSource(strings = ["cake", "banana", "triangle_sandwich"])
fun `Add item to food satchel`(item: String) {
val player = createPlayer("player")
player.inventory.set(0, "plain_satchel", 0)
Expand All @@ -57,7 +57,7 @@ internal class SatchelTest : WorldTest() {
}

@ParameterizedTest
@ValueSource(strings = [ "cake", "banana", "triangle_sandwich" ])
@ValueSource(strings = ["cake", "banana", "triangle_sandwich"])
fun `Can't add item to full satchel`(item: String) {
val player = createPlayer("player")
player.inventory.set(0, "plain_satchel", 7)
Expand Down

0 comments on commit dbbd370

Please sign in to comment.