mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 01:54:04 +09:00
1
assets/modules/basegame/KotlinScriptTest.kts
Normal file
1
assets/modules/basegame/KotlinScriptTest.kts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
println("Hello, script !")
|
||||||
@@ -19,17 +19,17 @@ object AmmoMeterProxy {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
meter.vitalGetterVal = {
|
meter.vitalGetterVal = {
|
||||||
if (ItemCodex[currentItem.id].consumable)
|
if (ItemCodex[currentItem.originalID].consumable)
|
||||||
actor.inventory.getByID(currentItem.id)!!.amount.toFloat()
|
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
|
||||||
else
|
else
|
||||||
actor.inventory.getByID(currentItem.id)!!.item.durability
|
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.item.durability
|
||||||
}
|
}
|
||||||
|
|
||||||
meter.vitalGetterMax = {
|
meter.vitalGetterMax = {
|
||||||
if (ItemCodex[currentItem.id].consumable)
|
if (ItemCodex[currentItem.originalID].consumable)
|
||||||
500f
|
500f
|
||||||
else
|
else
|
||||||
actor.inventory.getByID(currentItem.id)!!.item.maxDurability.toFloat()
|
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.item.maxDurability.toFloat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,17 +217,17 @@ class StateInGame : BasicGameState() {
|
|||||||
uiAliases = arrayListOf(
|
uiAliases = arrayListOf(
|
||||||
uiPieMenu,
|
uiPieMenu,
|
||||||
uiQuickBar,
|
uiQuickBar,
|
||||||
uiInventoryPlayer,
|
|
||||||
//uiInventoryContainer,
|
|
||||||
uiVitalPrimary,
|
uiVitalPrimary,
|
||||||
uiVitalSecondary,
|
uiVitalSecondary,
|
||||||
uiVitalItem
|
uiVitalItem
|
||||||
)
|
)
|
||||||
uiAlasesPausing = arrayListOf(
|
uiAlasesPausing = arrayListOf(
|
||||||
|
uiInventoryPlayer,
|
||||||
|
//uiInventoryContainer,
|
||||||
consoleHandler
|
consoleHandler
|
||||||
)
|
)
|
||||||
uiAlasesPausing.forEach { uiContainer.add(it) } // put them all to the UIContainer
|
uiAlasesPausing.forEach { addUI(it) } // put them all to the UIContainer
|
||||||
uiAliases.forEach { uiContainer.add(it) } // put them all to the UIContainer
|
uiAliases.forEach { addUI(it) } // put them all to the UIContainer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -795,6 +795,15 @@ class StateInGame : BasicGameState() {
|
|||||||
particlesContainer.add(particle)
|
particlesContainer.add(particle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addUI(ui: UIHandler) {
|
||||||
|
// check for exact duplicates
|
||||||
|
if (uiContainer.contains(ui)) {
|
||||||
|
throw IllegalArgumentException("Exact copy of the UI already exists: The instance of ${ui.UI.javaClass.simpleName}")
|
||||||
|
}
|
||||||
|
|
||||||
|
uiContainer.add(ui)
|
||||||
|
}
|
||||||
|
|
||||||
fun getActorByID(ID: Int): Actor {
|
fun getActorByID(ID: Int): Actor {
|
||||||
if (actorContainer.size == 0 && actorContainerInactive.size == 0)
|
if (actorContainer.size == 0 && actorContainerInactive.size == 0)
|
||||||
throw IllegalArgumentException("Actor with ID $ID does not exist.")
|
throw IllegalArgumentException("Actor with ID $ID does not exist.")
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class StateUITest : BasicGameState() {
|
|||||||
init {
|
init {
|
||||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER
|
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER
|
||||||
}
|
}
|
||||||
override var id: Int = 5656
|
override var dynamicID: Int = 5656
|
||||||
|
override val originalID = dynamicID
|
||||||
override val isUnique: Boolean = true
|
override val isUnique: Boolean = true
|
||||||
override var originalName: String = "Test tool"
|
override var originalName: String = "Test tool"
|
||||||
override var baseMass: Double = 12.0
|
override var baseMass: Double = 12.0
|
||||||
@@ -56,25 +57,28 @@ class StateUITest : BasicGameState() {
|
|||||||
override var maxDurability: Int = 143
|
override var maxDurability: Int = 143
|
||||||
override var durability: Float = 64f
|
override var durability: Float = 64f
|
||||||
override var consumable = false
|
override var consumable = false
|
||||||
|
override val isDynamic = true
|
||||||
})
|
})
|
||||||
actor.inventory.getByID(5656)!!.item.name = "Test tool"
|
actor.inventory.getByDynamicID(5656)!!.item.name = "Test tool"
|
||||||
|
|
||||||
actor.inventory.add(object : InventoryItem() {
|
actor.inventory.add(object : InventoryItem() {
|
||||||
init {
|
init {
|
||||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT
|
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT
|
||||||
}
|
}
|
||||||
override var id: Int = 4633
|
override var dynamicID: Int = 4633
|
||||||
|
override val originalID = dynamicID
|
||||||
override val isUnique: Boolean = true
|
override val isUnique: Boolean = true
|
||||||
override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN"
|
override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN"
|
||||||
override var baseMass: Double = 1.4
|
override var baseMass: Double = 1.4
|
||||||
override var baseToolSize: Double? = null
|
override var baseToolSize: Double? = null
|
||||||
override var inventoryCategory: String = InventoryItem.Category.MISC
|
override var inventoryCategory: String = InventoryItem.Category.MISC
|
||||||
override var consumable = false
|
override var consumable = false
|
||||||
|
override val isDynamic = false
|
||||||
})
|
})
|
||||||
|
|
||||||
actor.inventory.add(ItemCodex[16], 543)
|
actor.inventory.add(ItemCodex[16], 543)
|
||||||
|
|
||||||
actor.inventory.getByID(Tile.STONE)!!.item equipTo actor
|
actor.inventory.getByDynamicID(Tile.STONE)!!.item equipTo actor
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ class UIItemInventoryElem(
|
|||||||
// this one-liner sets color
|
// this one-liner sets color
|
||||||
g.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol
|
g.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol
|
||||||
g.drawString(
|
g.drawString(
|
||||||
item!!.name + (if (amount > 0 && !item!!.isUnique) "${0x3000.toChar()}($amount)" else "") +
|
"${item!!.dynamicID}/${item!!.originalID}" + (if (amount > 0 && !item!!.isUnique) "${0x3000.toChar()}($amount)" else "") +
|
||||||
|
//item!!.name + (if (amount > 0 && !item!!.isUnique) "${0x3000.toChar()}($amount)" else "") +
|
||||||
(if (equippedSlot != null) " ${0xE081.toChar()}\$$equippedSlot" else ""),
|
(if (equippedSlot != null) " ${0xE081.toChar()}\$$equippedSlot" else ""),
|
||||||
posX + textOffsetX,
|
posX + textOffsetX,
|
||||||
posY + textOffsetY
|
posY + textOffsetY
|
||||||
@@ -135,6 +136,7 @@ class UIItemInventoryElem(
|
|||||||
|
|
||||||
override fun mousePressed(button: Int, x: Int, y: Int) {
|
override fun mousePressed(button: Int, x: Int, y: Int) {
|
||||||
if (item != null && Terrarum.ingame != null) {
|
if (item != null && Terrarum.ingame != null) {
|
||||||
|
|
||||||
// equip da shit
|
// equip da shit
|
||||||
val itemEquipSlot = item!!.equipPosition
|
val itemEquipSlot = item!!.equipPosition
|
||||||
val player = Terrarum.ingame!!.player
|
val player = Terrarum.ingame!!.player
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ internal object Inventory : ConsoleCommand {
|
|||||||
else {
|
else {
|
||||||
target!!.inventory.forEach {
|
target!!.inventory.forEach {
|
||||||
if (it.amount == 0) {
|
if (it.amount == 0) {
|
||||||
EchoError("Unexpected zero-amounted item: ID ${it.item.id}")
|
EchoError("Unexpected zero-amounted item: ID ${it.item.dynamicID}")
|
||||||
}
|
}
|
||||||
Echo("ID ${it.item.id}${if (it.amount > 1) " ($it.second)" else ""}")
|
Echo("ID ${it.item.dynamicID}${if (it.amount > 1) " ($it.second)" else ""}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import net.torvald.terrarum.Terrarum
|
|||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
|
|
||||||
|
typealias ActorID = Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param renderOrder invisible/technical must use "Actor.RenderOrder.MIDDLE"
|
* @param renderOrder invisible/technical must use "Actor.RenderOrder.MIDDLE"
|
||||||
*
|
*
|
||||||
@@ -26,7 +28,7 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
|
|||||||
* Valid RefID is equal to or greater than 16777216.
|
* Valid RefID is equal to or greater than 16777216.
|
||||||
* @return Reference ID. (16777216-0x7FFF_FFFF)
|
* @return Reference ID. (16777216-0x7FFF_FFFF)
|
||||||
*/
|
*/
|
||||||
open var referenceID: Int = generateUniqueReferenceID()
|
open var referenceID: ActorID = generateUniqueReferenceID()
|
||||||
var actorValue = ActorValue()
|
var actorValue = ActorValue()
|
||||||
@Volatile var flagDespawn = false
|
@Volatile var flagDespawn = false
|
||||||
|
|
||||||
@@ -46,8 +48,8 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
|
|||||||
*
|
*
|
||||||
* override var referenceID: Int = generateUniqueReferenceID()
|
* override var referenceID: Int = generateUniqueReferenceID()
|
||||||
*/
|
*/
|
||||||
fun generateUniqueReferenceID(): Int {
|
fun generateUniqueReferenceID(): ActorID {
|
||||||
fun hasCollision(value: Int) =
|
fun hasCollision(value: ActorID) =
|
||||||
try {
|
try {
|
||||||
Terrarum.ingame!!.theGameHasActor(value) ||
|
Terrarum.ingame!!.theGameHasActor(value) ||
|
||||||
value < ItemCodex.ACTOR_ID_MIN ||
|
value < ItemCodex.ACTOR_ID_MIN ||
|
||||||
|
|||||||
@@ -138,13 +138,15 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
|||||||
|
|
||||||
|
|
||||||
private val nullItem = object : InventoryItem() {
|
private val nullItem = object : InventoryItem() {
|
||||||
override var id: Int = 0
|
override var dynamicID: Int = 0
|
||||||
|
override val originalID = dynamicID
|
||||||
override val isUnique: Boolean = false
|
override val isUnique: Boolean = false
|
||||||
override var baseMass: Double = 0.0
|
override var baseMass: Double = 0.0
|
||||||
override var baseToolSize: Double? = null
|
override var baseToolSize: Double? = null
|
||||||
override var inventoryCategory = "should_not_be_seen"
|
override var inventoryCategory = "should_not_be_seen"
|
||||||
override val originalName: String = actorValue.getAsString(AVKey.NAME) ?: "(no name)"
|
override val originalName: String = actorValue.getAsString(AVKey.NAME) ?: "(no name)"
|
||||||
override var consumable = false
|
override var consumable = false
|
||||||
|
override val isDynamic = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(gc: GameContainer, delta: Int) {
|
override fun update(gc: GameContainer, delta: Int) {
|
||||||
|
|||||||
@@ -35,26 +35,33 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
|||||||
|
|
||||||
fun add(itemID: Int, count: Int = 1) = add(ItemCodex[itemID], count)
|
fun add(itemID: Int, count: Int = 1) = add(ItemCodex[itemID], count)
|
||||||
fun add(item: InventoryItem, count: Int = 1) {
|
fun add(item: InventoryItem, count: Int = 1) {
|
||||||
if (item.id == Player.PLAYER_REF_ID || item.id == 0x51621D) // do not delete this magic
|
|
||||||
|
if (item.dynamicID == Player.PLAYER_REF_ID || item.dynamicID == 0x51621D) // do not delete this magic
|
||||||
throw IllegalArgumentException("Attempted to put human player into the inventory.")
|
throw IllegalArgumentException("Attempted to put human player into the inventory.")
|
||||||
if (Terrarum.ingame != null &&
|
if (Terrarum.ingame != null &&
|
||||||
(item.id == Terrarum.ingame?.player?.referenceID))
|
(item.dynamicID == Terrarum.ingame?.player?.referenceID))
|
||||||
throw IllegalArgumentException("Attempted to put active player into the inventory.")
|
throw IllegalArgumentException("Attempted to put active player into the inventory.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If we already have the item, increment the amount
|
// If we already have the item, increment the amount
|
||||||
// If not, add item with specified amount
|
// If not, add item with specified amount
|
||||||
val existingItem = getByID(item.id)
|
val existingItem = getByDynamicID(item.dynamicID)
|
||||||
|
|
||||||
if (existingItem != null) { // if the item already exists
|
// if the item already exists
|
||||||
val newCount = getByID(item.id)!!.amount + count
|
if (existingItem != null) {
|
||||||
|
val newCount = getByDynamicID(item.dynamicID)!!.amount + count
|
||||||
itemList.remove(existingItem)
|
itemList.remove(existingItem)
|
||||||
itemList.add(InventoryPair(existingItem.item, newCount))
|
itemList.add(InventoryPair(existingItem.item, newCount))
|
||||||
}
|
}
|
||||||
else { // new item
|
// new item
|
||||||
|
else {
|
||||||
if (item.isDynamic) {
|
if (item.isDynamic) {
|
||||||
// assign new ID
|
// assign new ID
|
||||||
item.originalID = item.id
|
|
||||||
item.id = InventoryItem.generateNewDynamicID(this)
|
println("[ActorInventory] new dynamic item detected: ${item.originalID}")
|
||||||
|
|
||||||
|
item.dynamicID = InventoryItem.generateNewDynamicID(this)
|
||||||
}
|
}
|
||||||
itemList.add(InventoryPair(item, count))
|
itemList.add(InventoryPair(item, count))
|
||||||
}
|
}
|
||||||
@@ -63,11 +70,11 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
|||||||
|
|
||||||
fun remove(itemID: Int, count: Int = 1) = remove(ItemCodex[itemID], count)
|
fun remove(itemID: Int, count: Int = 1) = remove(ItemCodex[itemID], count)
|
||||||
fun remove(item: InventoryItem, count: Int = 1) {
|
fun remove(item: InventoryItem, count: Int = 1) {
|
||||||
val existingItem = getByID(item.id)
|
val existingItem = getByDynamicID(item.dynamicID)
|
||||||
if (existingItem != null) { // if the item already exists
|
if (existingItem != null) { // if the item already exists
|
||||||
val newCount = getByID(item.id)!!.amount - count
|
val newCount = getByDynamicID(item.dynamicID)!!.amount - count
|
||||||
if (newCount < 0) {
|
if (newCount < 0) {
|
||||||
throw Error("Tried to remove $count of $item, but the inventory only contains ${getByID(item.id)!!.amount} of them.")
|
throw Error("Tried to remove $count of $item, but the inventory only contains ${getByDynamicID(item.dynamicID)!!.amount} of them.")
|
||||||
}
|
}
|
||||||
else if (newCount > 0) {
|
else if (newCount > 0) {
|
||||||
// decrement count
|
// decrement count
|
||||||
@@ -141,6 +148,8 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
|||||||
item.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat()
|
item.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat()
|
||||||
if (item.durability <= 0)
|
if (item.durability <= 0)
|
||||||
remove(item, 1)
|
remove(item, 1)
|
||||||
|
|
||||||
|
println("[ActorInventory] consumed; ${item.durability}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,13 +159,13 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun contains(item: InventoryItem) = contains(item.id)
|
fun contains(item: InventoryItem) = contains(item.dynamicID)
|
||||||
fun contains(id: Int) =
|
fun contains(id: Int) =
|
||||||
if (itemList.size == 0)
|
if (itemList.size == 0)
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
itemList.binarySearch(id) >= 0
|
itemList.binarySearch(id) >= 0
|
||||||
fun getByID(id: Int): InventoryPair? {
|
fun getByDynamicID(id: Int): InventoryPair? {
|
||||||
if (itemList.size == 0)
|
if (itemList.size == 0)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
@@ -187,9 +196,9 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
|||||||
|
|
||||||
val midVal = get(mid).item
|
val midVal = get(mid).item
|
||||||
|
|
||||||
if (ID > midVal.id)
|
if (ID > midVal.dynamicID)
|
||||||
low = mid + 1
|
low = mid + 1
|
||||||
else if (ID < midVal.id)
|
else if (ID < midVal.dynamicID)
|
||||||
high = mid - 1
|
high = mid - 1
|
||||||
else
|
else
|
||||||
return mid // key found
|
return mid // key found
|
||||||
|
|||||||
@@ -12,17 +12,17 @@ import org.newdawn.slick.Graphics
|
|||||||
class DroppedItem(private val item: InventoryItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) {
|
class DroppedItem(private val item: InventoryItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (item.id >= ItemCodex.ACTOR_ID_MIN)
|
if (item.dynamicID >= ItemCodex.ACTOR_ID_MIN)
|
||||||
throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.")
|
throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.")
|
||||||
|
|
||||||
isVisible = true
|
isVisible = true
|
||||||
|
|
||||||
avBaseMass = if (item.id < TileCodex.TILE_UNIQUE_MAX)
|
avBaseMass = if (item.dynamicID < TileCodex.TILE_UNIQUE_MAX)
|
||||||
TileCodex[item.id].density / 1000.0
|
TileCodex[item.dynamicID].density / 1000.0
|
||||||
else
|
else
|
||||||
ItemCodex[item.id].mass
|
ItemCodex[item.dynamicID].mass
|
||||||
|
|
||||||
scale = ItemCodex[item.id].scale
|
scale = ItemCodex[item.dynamicID].scale
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(gc: GameContainer, delta: Int) {
|
override fun update(gc: GameContainer, delta: Int) {
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ open class HumanoidNPC(
|
|||||||
|
|
||||||
// we're having InventoryItem data so that this class could be somewhat universal
|
// we're having InventoryItem data so that this class could be somewhat universal
|
||||||
override var itemData: InventoryItem = object : InventoryItem() {
|
override var itemData: InventoryItem = object : InventoryItem() {
|
||||||
override var id = referenceID
|
override var dynamicID = referenceID
|
||||||
|
override val originalID = dynamicID
|
||||||
override val isUnique = true
|
override val isUnique = true
|
||||||
override var baseMass: Double
|
override var baseMass: Double
|
||||||
get() = actorValue.getAsDouble(AVKey.BASEMASS)!!
|
get() = actorValue.getAsDouble(AVKey.BASEMASS)!!
|
||||||
@@ -57,6 +58,7 @@ open class HumanoidNPC(
|
|||||||
override var inventoryCategory = "npc"
|
override var inventoryCategory = "npc"
|
||||||
override val originalName: String = actorValue.getAsString(AVKey.NAME) ?: "NPC"
|
override val originalName: String = actorValue.getAsString(AVKey.NAME) ?: "NPC"
|
||||||
override var consumable = true
|
override var consumable = true
|
||||||
|
override val isDynamic = false
|
||||||
|
|
||||||
override fun secondaryUse(gc: GameContainer, delta: Int): Boolean {
|
override fun secondaryUse(gc: GameContainer, delta: Int): Boolean {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ object PlayerBuilderSigrid {
|
|||||||
Tile.SANDSTONE_RED, Tile.STONE, Tile.STONE_BRICKS,
|
Tile.SANDSTONE_RED, Tile.STONE, Tile.STONE_BRICKS,
|
||||||
Tile.STONE_QUARRIED, Tile.STONE_TILE_WHITE, Tile.TORCH
|
Tile.STONE_QUARRIED, Tile.STONE_TILE_WHITE, Tile.TORCH
|
||||||
)
|
)
|
||||||
tiles.forEach { p.inventory.add(it, 999) }
|
tiles.forEach { p.addItem(it, 999) }
|
||||||
p.inventory.add(ItemCodex.ITEM_STATIC.first)
|
p.inventory.add(ItemCodex.ITEM_STATIC.first)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ interface Pocketed {
|
|||||||
fun removeItem(itemID: Int, count: Int = 1) = inventory.remove(ItemCodex[itemID], count)
|
fun removeItem(itemID: Int, count: Int = 1) = inventory.remove(ItemCodex[itemID], count)
|
||||||
fun removeItem(item: InventoryItem, count: Int = 1) = inventory.remove(item, count)
|
fun removeItem(item: InventoryItem, count: Int = 1) = inventory.remove(item, count)
|
||||||
|
|
||||||
fun hasItem(item: InventoryItem) = inventory.contains(item.id)
|
fun hasItem(item: InventoryItem) = inventory.contains(item.dynamicID)
|
||||||
fun hasItem(id: Int) = inventory.contains(id)
|
fun hasItem(id: Int) = inventory.contains(id)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import java.util.HashSet
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-02-15.
|
* Created by minjaesong on 16-02-15.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typealias FactionID = Int
|
||||||
|
|
||||||
class Faction(name: String) : Comparable<Faction> {
|
class Faction(name: String) : Comparable<Faction> {
|
||||||
|
|
||||||
var factionName: String = name
|
var factionName: String = name
|
||||||
@@ -14,7 +17,7 @@ class Faction(name: String) : Comparable<Faction> {
|
|||||||
lateinit var factionNeutral: HashSet<String>
|
lateinit var factionNeutral: HashSet<String>
|
||||||
lateinit var factionHostile: HashSet<String>
|
lateinit var factionHostile: HashSet<String>
|
||||||
lateinit var factionFearful: HashSet<String>
|
lateinit var factionFearful: HashSet<String>
|
||||||
var referenceID: Long = generateUniqueID()
|
var referenceID: FactionID = generateUniqueID()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
factionAmicable = HashSet<String>()
|
factionAmicable = HashSet<String>()
|
||||||
@@ -59,10 +62,11 @@ class Faction(name: String) : Comparable<Faction> {
|
|||||||
factionFearful.remove(faction)
|
factionFearful.remove(faction)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateUniqueID(): Long {
|
/** Valid range: -2147483648..-1 (all the negative number) */
|
||||||
var ret: Long
|
private fun generateUniqueID(): Int {
|
||||||
|
var ret: Int
|
||||||
do {
|
do {
|
||||||
ret = HQRNG().nextLong().or(0x80000000L).and(0xFFFFFFFFL) // guaranteed to be 2147483648..4294967295
|
ret = HQRNG().nextInt(2147483647).plus(1).unaryMinus()
|
||||||
} while (FactionCodex.hasFaction(ret)) // check for collision
|
} while (FactionCodex.hasFaction(ret)) // check for collision
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.*
|
|||||||
object FactionCodex {
|
object FactionCodex {
|
||||||
val factionContainer = ArrayList<Faction>()
|
val factionContainer = ArrayList<Faction>()
|
||||||
|
|
||||||
fun hasFaction(ID: Long): Boolean =
|
fun hasFaction(ID: FactionID): Boolean =
|
||||||
if (factionContainer.size == 0)
|
if (factionContainer.size == 0)
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
@@ -22,7 +22,7 @@ object FactionCodex {
|
|||||||
insertionSortLastElem(factionContainer) // we can do this as we are only adding single actor
|
insertionSortLastElem(factionContainer) // we can do this as we are only adding single actor
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFactionByID(ID: Long): Faction {
|
fun getFactionByID(ID: FactionID): Faction {
|
||||||
if (factionContainer.size == 0) throw IllegalArgumentException("Faction with ID $ID does not exist.")
|
if (factionContainer.size == 0) throw IllegalArgumentException("Faction with ID $ID does not exist.")
|
||||||
|
|
||||||
val index = factionContainer.binarySearch(ID)
|
val index = factionContainer.binarySearch(ID)
|
||||||
@@ -45,7 +45,7 @@ object FactionCodex {
|
|||||||
arr[j + 1] = x
|
arr[j + 1] = x
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ArrayList<Faction>.binarySearch(ID: Long): Int {
|
private fun ArrayList<Faction>.binarySearch(ID: FactionID): Int {
|
||||||
// code from collections/Collections.kt
|
// code from collections/Collections.kt
|
||||||
var low = 0
|
var low = 0
|
||||||
var high = factionContainer.size - 1
|
var high = factionContainer.size - 1
|
||||||
|
|||||||
29
src/net/torvald/terrarum/gameworld/GameEconomy.kt
Normal file
29
src/net/torvald/terrarum/gameworld/GameEconomy.kt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
|
import net.torvald.terrarum.gameactors.ActorID
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This world is economically isolated system. Economy will be important to make player keep playing,
|
||||||
|
* when all the necessary contents are set and implemented to the production.
|
||||||
|
*
|
||||||
|
* Created by SKYHi14 on 2017-04-23.
|
||||||
|
*/
|
||||||
|
class GameEconomy {
|
||||||
|
|
||||||
|
val transactionHistory = TransanctionHistory()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TransanctionHistory {
|
||||||
|
|
||||||
|
private val entries = ArrayList<TransanctionHistory>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param to set 0 to indicate the money was lost to void
|
||||||
|
*/
|
||||||
|
data class TransactionEntry(val from: ActorID, val to: ActorID, val amount: Long) {
|
||||||
|
override fun toString() = "$from -> $to; $amount"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -34,10 +34,18 @@ class GameWorld(val width: Int, val height: Int) {
|
|||||||
var gravitation: Vector2 = Vector2(0.0, 9.8)
|
var gravitation: Vector2 = Vector2(0.0, 9.8)
|
||||||
/** RGB in Integer */
|
/** RGB in Integer */
|
||||||
var globalLight: Int = 0
|
var globalLight: Int = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val time: WorldTime
|
val time: WorldTime
|
||||||
|
val economy = GameEconomy()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var generatorSeed: Long = 0
|
var generatorSeed: Long = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.spawnX = width / 2
|
this.spawnX = width / 2
|
||||||
this.spawnY = 200
|
this.spawnY = 200
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ import org.newdawn.slick.GameContainer
|
|||||||
*/
|
*/
|
||||||
abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
||||||
|
|
||||||
abstract var id: Int
|
abstract var dynamicID: Int
|
||||||
|
abstract val originalID: Int // WUT?! using init does not work!!
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -60,7 +62,7 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
|||||||
*
|
*
|
||||||
* The opposite of this is called STATIC and their example is a Block.
|
* The opposite of this is called STATIC and their example is a Block.
|
||||||
*/
|
*/
|
||||||
open val isDynamic = false
|
abstract val isDynamic: Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where to equip the item
|
* Where to equip the item
|
||||||
@@ -90,7 +92,6 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
|||||||
else
|
else
|
||||||
throw NullPointerException("null input; nullify baseToolSize instead :p")
|
throw NullPointerException("null input; nullify baseToolSize instead :p")
|
||||||
}
|
}
|
||||||
var originalID = id
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scale of the item.
|
* Scale of the item.
|
||||||
@@ -165,16 +166,16 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
|||||||
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return id.toString()
|
return dynamicID.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return id
|
return dynamicID
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (other == null) return false
|
if (other == null) return false
|
||||||
return id == (other as InventoryItem).id
|
return dynamicID == (other as InventoryItem).dynamicID
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unsetCustomName() {
|
fun unsetCustomName() {
|
||||||
@@ -183,7 +184,7 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
|||||||
nameColour = Color.white
|
nameColour = Color.white
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun compareTo(other: InventoryItem): Int = (this.id - other.id).sign()
|
override fun compareTo(other: InventoryItem): Int = (this.dynamicID - other.dynamicID).sign()
|
||||||
|
|
||||||
fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0
|
fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ object ItemCodex {
|
|||||||
// tile items (blocks and walls are the same thing basically)
|
// tile items (blocks and walls are the same thing basically)
|
||||||
for (i in ITEM_TILES + ITEM_WALLS) {
|
for (i in ITEM_TILES + ITEM_WALLS) {
|
||||||
itemCodex[i] = object : InventoryItem() {
|
itemCodex[i] = object : InventoryItem() {
|
||||||
override var id: Int = i
|
override var dynamicID: Int = i
|
||||||
|
override val originalID = dynamicID
|
||||||
override val isUnique: Boolean = false
|
override val isUnique: Boolean = false
|
||||||
override var baseMass: Double = TileCodex[i].density / 1000.0
|
override var baseMass: Double = TileCodex[i].density / 1000.0
|
||||||
override var baseToolSize: Double? = null
|
override var baseToolSize: Double? = null
|
||||||
@@ -54,7 +55,7 @@ object ItemCodex {
|
|||||||
override val originalName = TileCodex[i % ITEM_WALLS.first].nameKey
|
override val originalName = TileCodex[i % ITEM_WALLS.first].nameKey
|
||||||
override var consumable = true
|
override var consumable = true
|
||||||
override var inventoryCategory = Category.BLOCK
|
override var inventoryCategory = Category.BLOCK
|
||||||
override var isDynamic = true
|
override var isDynamic = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
itemProperties[IVKey.ITEMTYPE] = if (i in ITEM_TILES)
|
itemProperties[IVKey.ITEMTYPE] = if (i in ITEM_TILES)
|
||||||
@@ -77,7 +78,7 @@ object ItemCodex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return false if the tile is already there
|
// return false if the tile is already there
|
||||||
if (this.id == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY))
|
if (this.dynamicID == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
// filter passed, do the job
|
// filter passed, do the job
|
||||||
@@ -104,16 +105,19 @@ object ItemCodex {
|
|||||||
|
|
||||||
// test copper pickaxe
|
// test copper pickaxe
|
||||||
itemCodex[ITEM_STATIC.first] = object : InventoryItem() {
|
itemCodex[ITEM_STATIC.first] = object : InventoryItem() {
|
||||||
override var id = ITEM_STATIC.first
|
override var dynamicID = ITEM_STATIC.first
|
||||||
|
override val originalID = dynamicID
|
||||||
override val isUnique = false
|
override val isUnique = false
|
||||||
override val originalName = "Test Pick"
|
override val originalName = ""
|
||||||
override var baseMass = 10.0
|
override var baseMass = 10.0
|
||||||
override var baseToolSize: Double? = 10.0
|
override var baseToolSize: Double? = 10.0
|
||||||
override var consumable = false
|
override var consumable = false
|
||||||
override var maxDurability = 64//606 // this much tiles before breaking
|
override var maxDurability = 147//606 // this much tiles before breaking
|
||||||
override var durability = maxDurability.toFloat()
|
override var durability = maxDurability.toFloat()
|
||||||
override var equipPosition = EquipPosition.HAND_GRIP
|
override var equipPosition = EquipPosition.HAND_GRIP
|
||||||
override var inventoryCategory = Category.TOOL
|
override var inventoryCategory = Category.TOOL
|
||||||
|
override val isDynamic = true
|
||||||
|
|
||||||
|
|
||||||
private val testmaterial = Material(
|
private val testmaterial = Material(
|
||||||
0,0,0,0,0,0,0,0,1,0.0 // quick test material Stone
|
0,0,0,0,0,0,0,0,1,0.0 // quick test material Stone
|
||||||
@@ -121,7 +125,7 @@ object ItemCodex {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK
|
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK
|
||||||
name = "Steel pickaxe"
|
name = "Stone pickaxe"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun primaryUse(gc: GameContainer, delta: Int): Boolean {
|
override fun primaryUse(gc: GameContainer, delta: Int): Boolean {
|
||||||
@@ -184,16 +188,21 @@ object ItemCodex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getItemImage(code: Int): Image {
|
fun getItemImage(item: InventoryItem): Image {
|
||||||
if (code <= ITEM_TILES.endInclusive)
|
// terrain
|
||||||
return TilesDrawer.tilesTerrain.getSubImage((code % 16) * 16, code / 16)
|
if (item.originalID in ITEM_TILES) {
|
||||||
else if (code <= ITEM_WALLS.endInclusive) {
|
return TilesDrawer.tilesTerrain.getSubImage((item.dynamicID % 16) * 16, item.originalID / 16)
|
||||||
val img = TilesDrawer.tilesTerrain.getSubImage((code % 16) * 16, code / 16)
|
}
|
||||||
|
// wall
|
||||||
|
else if (item.originalID in ITEM_WALLS) {
|
||||||
|
val img = TilesDrawer.tilesTerrain.getSubImage((item.originalID % 16) * 16, item.originalID / 16)
|
||||||
img.setImageColor(wallOverlayColour.r, wallOverlayColour.g, wallOverlayColour.b)
|
img.setImageColor(wallOverlayColour.r, wallOverlayColour.g, wallOverlayColour.b)
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
else if (code <= ITEM_WIRES.endInclusive)
|
// wire
|
||||||
return TilesDrawer.tilesWire.getSubImage((code % 16) * 16, code / 16)
|
else if (item.originalID in ITEM_WIRES) {
|
||||||
|
return TilesDrawer.tilesWire.getSubImage((item.originalID % 16) * 16, item.originalID / 16)
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return itemImagePlaceholder
|
return itemImagePlaceholder
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ object LandUtil {
|
|||||||
/**
|
/**
|
||||||
* Get owner ID as an Actor/Faction
|
* Get owner ID as an Actor/Faction
|
||||||
*/
|
*/
|
||||||
fun resolveOwner(id: TileAddress): Any =
|
fun resolveOwner(id: Int): Any =
|
||||||
if (id < 0x80000000L)
|
if (id >= 0)
|
||||||
Terrarum.ingame!!.getActorByID(id.toInt())
|
Terrarum.ingame!!.getActorByID(id)
|
||||||
else
|
else
|
||||||
FactionCodex.getFactionByID(id)
|
FactionCodex.getFactionByID(id)
|
||||||
}
|
}
|
||||||
@@ -175,11 +175,11 @@ class UIInventory(
|
|||||||
val sortListItem = inventorySortList[k + itemsScrollOffset]
|
val sortListItem = inventorySortList[k + itemsScrollOffset]
|
||||||
items[k].item = sortListItem.item
|
items[k].item = sortListItem.item
|
||||||
items[k].amount = sortListItem.amount
|
items[k].amount = sortListItem.amount
|
||||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item.id)
|
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
|
||||||
|
|
||||||
// set quickslot number
|
// set quickslot number
|
||||||
for (qs in 1..QUICKSLOT_MAX) {
|
for (qs in 1..QUICKSLOT_MAX) {
|
||||||
if (-sortListItem.item.id == actorValue.getAsInt(AVKey.__PLAYER_QSPREFIX + qs)) {
|
if (-sortListItem.item.dynamicID == actorValue.getAsInt(AVKey.__PLAYER_QSPREFIX + qs)) {
|
||||||
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user