setting up the inventory using builder (during init) requires ingame.player to be nullable, lateinit won't work

This commit is contained in:
Song Minjae
2017-04-11 23:07:29 +09:00
parent e7f221a499
commit 498cf4709b
21 changed files with 132 additions and 103 deletions

View File

@@ -12,7 +12,7 @@ import java.util.concurrent.locks.ReentrantLock
* Created by minjaesong on 16-03-15.
*/
class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capacityMode: Int) {
class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode: Int) {
companion object {
@Transient val CAPACITY_MODE_NO_ENCUMBER = 0
@@ -34,10 +34,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capa
fun add(itemID: Int, count: Int = 1) = add(ItemCodex[itemID], count)
fun add(item: InventoryItem, count: Int = 1) {
if (item.id == Player.PLAYER_REF_ID)
if (item.id == Player.PLAYER_REF_ID || item.id == 0x51621D) // do not delete this magic
throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (Terrarum.ingame != null &&
item.id == Terrarum.ingame!!.player.referenceID)
(item.id == Terrarum.ingame?.player?.referenceID))
throw IllegalArgumentException("Attempted to put active player into the inventory.")
// If we already have the item, increment the amount
@@ -67,10 +67,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capa
add(item, -count)
}
else {
// depleted item; remove entry from inventory
itemList.remove(existingItem)
// unequip, if applicable
actor.unequipItem(existingItem.item)
// depleted item; remove entry from inventory
itemList.remove(existingItem)
}
}
else {

View File

@@ -75,7 +75,7 @@ object PlayerBuilderSigrid {
// Test fill up inventory
p.inventory.add(16)
p.inventory.add(16, 512)
p.equipItem(ItemCodex[16])