-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add overriding inventory length
- Loading branch information
Showing
5 changed files
with
214 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
game/src/main/kotlin/world/gregs/voidps/world/map/draynor/DiangoItemRetrieval.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |