Skip to content

Commit

Permalink
Add diango item retrieval
Browse files Browse the repository at this point in the history
Add overriding inventory length
  • Loading branch information
GregHib committed Aug 6, 2024
1 parent 81f1e73 commit 30be326
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 34 deletions.
9 changes: 8 additions & 1 deletion data/definitions/interfaces.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,14 @@ emotes:
seal_of_approval: 52
diangos_item_retrieval:
id: 468
type: main_screen
type: main_screen
components:
items:
id: 2
inventory: diangos_item_retrieval
options:
Claim: 0
Examine: 9
barbarian_assult_rewards: 473
barbarian_assult_horn: 484
barbarian_assult_attacker: 485
Expand Down
95 changes: 62 additions & 33 deletions data/definitions/inventories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4467,40 +4467,69 @@ inventory_452:
- hunter_cape_2: 1
- quest_point_cape_2: 1
- more: 1
inventory_453:
diangos_item_retrieval:
id: 453
defaults:
- reindeer_hat_2: 1
- jack_lantern_mask_2: 1
- skeleton_boots_2: 1
- skeleton_gloves_2: 1
- skeleton_leggings_2: 1
- skeleton_shirt_2: 1
- skeleton_mask_2: 1
- easter_ring_2: 1
- bobble_hat_2: 1
- bobble_scarf_2: 1
- blue_marionette_2: 1
- zombie_head_2: 1
- rubber_chicken_2: 1
- yo_yo_2: 1
- bunny_ears_2: 1
- scythe_2: 1
- chicken_head_2: 1
- chicken_feet_2: 1
- chicken_wings_2: 1
- chicken_legs_2: 1
- grim_reaper_hood_2: 1
- snow_globe_2: 1
- chocatrice_cape_2: 1
- witch_top_2: 1
- witch_skirt_2: 1
- witch_cloak_2: 1
- cornucopia_2: 1
- santa_costume_top_3: 1
- ice_amulet_2: 1
- easter_carrot_2: 1
- more: 1
length: 58
defaults:
- bunny_ears: 1
- scythe: 1
- yo_yo: 1
- rubber_chicken: 1
- zombie_head: 1
- easter_ring: 1
- bobble_hat: 1
- bobble_scarf: 1
- jester_hat: 1
- jester_scarf: 1
- tri_jester_hat: 1
- tri_jester_scarf: 1
- woolly_hat: 1
- woolly_scarf: 1
- reindeer_hat: 1
- blue_marionette: 1
- jack_lantern_mask: 1
- skeleton_boots: 1
- skeleton_gloves: 1
- skeleton_leggings: 1
- skeleton_shirt: 1
- skeleton_mask: 1
- wintumber_tree: 1
- chicken_feet: 1
- chicken_legs: 1
- chicken_wings: 1
- chicken_head: 1
- grim_reaper_hood: 1
- snow_globe: 1
- chocatrice_cape: 1
- witch_top: 1
- witch_skirt: 1
- witch_cloak: 1
- santa_costume_top: 1
- santa_costume_legs: 1
- santa_costume_gloves: 1
- santa_costume_boots: 1
- ice_amulet: 1
- cornucopia: 1
- easter_carrot: 1
- eek: 1
- web_cloak: 1
- candy_cane: 1
- christmas_ghost_hood: 1
- christmas_ghost_top: 1
- christmas_ghost_bottoms: 1
- squirrel_ears: 1
- bone_brooch: 1
- flagstaff_of_festivities: 1
- magnifying_glass: 1
- investigators_hat: 1
- investigators_trousers: 1
- investigators_coat: 1
- mysterious_book: 1
- salty_claws_hat: 1
- heimland_games_souvenir: 1
- golden_cracker: 1
- tenth_anniversary_cake: 1
- hati_head: 1
inventory_454:
id: 454
defaults:
Expand Down
46 changes: 46 additions & 0 deletions data/definitions/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,49 @@ task_main_list_filter_set: 3986
task_summary_accordion: 4000
task_summary_close: 4001
task_list_button_hide: 4101
set_scroll_height:
id: 1208
params:
- "scroll bar component"
- "interface container"
- "container height"
- "append"
interface_inv_init:
id: 149
params:
- "interface container"
- "interface id"
- "width"
- "height"
- "drag mode"
- "drag start interface id"
- "option 1"
- "option 2"
- "option 3"
- "option 4"
- "option 5"
interface_inv_update:
id: 152
params:
- "interface container"
- "interface id"
- "width"
- "height"
- "drag mode"
- "drag start interface id"
- "option 1"
- "option 2"
- "option 3"
- "option 4"
- "option 5"
scrollbar_resize:
id: 72
params:
- "scroll bar interface id"
- "container interface id"
- "scroll bar height"
scrollbar_vertical:
id: 30
params:
- "scroll bar interface id"
- "container interface id"
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InventoryDefinitions(
return
}
val def = definitions[id]
def.length = map["length"] as? Int ?: def.length
def.ids = IntArray(def.length) { itemDefs.get(value.getOrNull(it)?.keys?.first() ?: "").id }
def.amounts = IntArray(def.length) { value.getOrNull(it)?.values?.first() ?: 0 }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package world.gregs.voidps.world.map.draynor

import world.gregs.voidps.cache.definition.data.InterfaceDefinition
import world.gregs.voidps.engine.client.sendScript
import world.gregs.voidps.engine.client.ui.event.interfaceClose
import world.gregs.voidps.engine.client.ui.event.interfaceOpen
import world.gregs.voidps.engine.client.ui.interfaceOption
import world.gregs.voidps.engine.data.definition.InventoryDefinitions
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.entity.character.player.chat.inventoryFull
import world.gregs.voidps.engine.entity.playerDespawn
import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.inv.add
import world.gregs.voidps.engine.inv.inventory
import world.gregs.voidps.engine.inv.sendInventory
import world.gregs.voidps.engine.inv.transact.operation.AddItem.add
import world.gregs.voidps.engine.inv.transact.operation.ClearItem.clear
import world.gregs.voidps.world.activity.bank.ownsItem

val itemLimit = 48
val container = InterfaceDefinition.pack(468, 2)
val scrollbar = InterfaceDefinition.pack(468, 3)

interfaceOpen("diangos_item_retrieval") { player ->
refreshItems(player)
}

interfaceOption("Claim", "items", "diangos_item_retrieval") {
when (item.id) {
"more" -> {
player["retrieve_more"] = true
player.sendScript("scrollbar_resize", scrollbar, container, 0) // Scroll to top
}

"back" -> player.clear("retrieve_more")
else -> if (!player.inventory.add(item.id)) {
player.inventoryFull()
}
}
refreshItems(player)
}

val inventoryDefinitions: InventoryDefinitions by inject()

fun refreshItems(player: Player) {
val more: Boolean = player["retrieve_more", false]
player.inventories.clear("diangos_item_retrieval")
val inventory = player.inventories.inventory("diangos_item_retrieval")
val defaults = inventoryDefinitions.get("diangos_item_retrieval").getOrNull<List<Map<String, Int>>>("defaults") ?: return
var displayMore = false
inventory.transaction {
clear()
// Add back "button" when displaying excess
if (more) {
add("back")
}
var skipped = 0
for (index in 0 until inventory.size) {
val map = defaults.getOrNull(index) ?: continue
val id = map.keys.firstOrNull() ?: continue
if (!player.ownsItem(id)) {
// Add second screen if itemLimit is reached
if (!more && inventory.count >= itemLimit) {
displayMore = true
break
}
// If displaying second screen skip first X items
if (more && skipped++ < itemLimit) {
continue
}
add(id)
}
}
// Add more "button" when too many to display
if (displayMore) {
add("more")
}
}
player.interfaceOptions.unlockAll("diangos_item_retrieval", "items", 0..inventory.count)
player.sendInventory("diangos_item_retrieval")
if (displayMore) {
player.sendScript("scrollbar_vertical", scrollbar, container)
player.sendScript("set_scroll_height", scrollbar, container, 300, 0)
player.sendScript("interface_inv_init", container, 453, 8, 7, 0, -1, "Claim", "", "", "", "")
} else {
player.sendScript("interface_inv_init", container, 453, 8, 6, 0, -1, "Claim", "", "", "", "")
}
}

playerDespawn { player ->
// Don't want to store in account save
player.inventories.clear("diangos_item_retrieval")
}

interfaceClose("diangos_item_retrieval") { player ->
player.inventories.clear(id)
}

0 comments on commit 30be326

Please sign in to comment.