mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 08:36:07 +09:00
no-auto-pickup variant of droppeditem
This commit is contained in:
@@ -793,7 +793,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
// #2. If #1 failed, try to pick up the fixture
|
// #2. If #1 failed, try to pick up the fixture
|
||||||
else {
|
else {
|
||||||
mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
||||||
pickupFixture(actor, delta, mwx, mwy, mtx, mty)
|
pickupFixtureOrDroppedItem(actor, delta, mwx, mwy, mtx, mty)
|
||||||
0L
|
0L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1702,13 +1702,16 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
return actorsUnderMouse
|
return actorsUnderMouse
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pickupFixture(actor: ActorWithBody, delta: Float, mwx: Double, mwy: Double, mtx: Int, mty: Int, assignToQuickslot: Boolean = true) {
|
fun pickupFixtureOrDroppedItem(actor: ActorWithBody, delta: Float, mwx: Double, mwy: Double, mtx: Int, mty: Int, assignToQuickslot: Boolean = true) {
|
||||||
val actorsUnderMouse = getActorsUnderMouse(mwx, mwy)
|
val actorsUnderMouse = getActorsUnderMouse(mwx, mwy)
|
||||||
|
|
||||||
val fixture = actorsUnderMouse.firstOrNull {
|
val fixture = actorsUnderMouse.firstOrNull {
|
||||||
it is FixtureBase && it.canBeDespawned &&
|
it is FixtureBase && it.canBeDespawned &&
|
||||||
System.nanoTime() - it.spawnRequestedTime > 500000000 // don't pick up the fixture if it was recently placed (0.5 seconds)
|
System.nanoTime() - it.spawnRequestedTime > 500000000 // don't pick up the fixture if it was recently placed (0.5 seconds)
|
||||||
} as? FixtureBase
|
} as? FixtureBase
|
||||||
|
val droppedItemNoAutoPickup = actorsUnderMouse.firstOrNull {
|
||||||
|
it is DroppedItem && it.noAutoPickup
|
||||||
|
} as? DroppedItem
|
||||||
val mob = actorsUnderMouse.firstOrNull {
|
val mob = actorsUnderMouse.firstOrNull {
|
||||||
it !is FixtureBase && it.physProp.usePhysics && !it.physProp.immobileBody
|
it !is FixtureBase && it.physProp.usePhysics && !it.physProp.immobileBody
|
||||||
} as? ActorWithBody
|
} as? ActorWithBody
|
||||||
@@ -1743,6 +1746,37 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// pickup a dropped item (no auto-pickup variants only)
|
||||||
|
else if (droppedItemNoAutoPickup != null) {
|
||||||
|
val droppedItemID = droppedItemNoAutoPickup.itemID
|
||||||
|
val droppedItemCount = droppedItemNoAutoPickup.itemCount
|
||||||
|
// 0. hide tooltips
|
||||||
|
TooltipManager.tooltipShowing.clear()
|
||||||
|
setTooltipMessage(null)
|
||||||
|
if (!droppedItemNoAutoPickup.flagDespawn) {
|
||||||
|
// 1. put the fixture to the inventory
|
||||||
|
droppedItemNoAutoPickup.flagDespawn()
|
||||||
|
// 2. register this item(fixture) to the quickslot so that the player sprite would be actually lifting the fixture
|
||||||
|
// BUUUUUUUT, only when the slot is already empty this time
|
||||||
|
if (actor is Pocketed) {
|
||||||
|
actor.inventory.add(droppedItemID, droppedItemCount)
|
||||||
|
|
||||||
|
if (assignToQuickslot && actor.inventory.getQuickslotItem(actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)) == null) {
|
||||||
|
actor.equipItem(droppedItemID)
|
||||||
|
actor.inventory.setQuickslotItemAtSelected(droppedItemID)
|
||||||
|
// 2-1. unregister if other slot has the same item
|
||||||
|
for (k in 0..9) {
|
||||||
|
if (actor.inventory.getQuickslotItem(k)?.itm == droppedItemID && k != actor.actorValue.getAsInt(
|
||||||
|
AVKey.__PLAYER_QUICKSLOTSEL
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
actor.inventory.setQuickslotItem(k, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (mob != null) {
|
else if (mob != null) {
|
||||||
// TODO pickup a mob
|
// TODO pickup a mob
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ object WorldSimulator {
|
|||||||
fun collideDroppedItems() {
|
fun collideDroppedItems() {
|
||||||
ingame.actorContainerActive.filter { it is DroppedItem }.forEach { droppedItem0 ->
|
ingame.actorContainerActive.filter { it is DroppedItem }.forEach { droppedItem0 ->
|
||||||
val droppedItem = droppedItem0 as DroppedItem
|
val droppedItem = droppedItem0 as DroppedItem
|
||||||
if (droppedItem.canBePickedUp()) {
|
if (droppedItem.canBePickedUpAutomatically()) {
|
||||||
val actors = ingame.findKNearestActors(droppedItem0 as ActorWithBody, 64) { it is Controllable && it is Pocketed }
|
val actors = ingame.findKNearestActors(droppedItem0 as ActorWithBody, 64) { it is Controllable && it is Pocketed }
|
||||||
for (result in actors) {
|
for (result in actors) {
|
||||||
val actor = result.get()
|
val actor = result.get()
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class ActorInventory() : FixtureInventory() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getQuickslotItem(slot: Int): InventoryPair? = searchByID(quickSlot[slot])
|
fun getQuickslotItem(slot: Int?): InventoryPair? = if (slot == null) null else searchByID(quickSlot[slot])
|
||||||
|
|
||||||
fun consumeItem(item: GameItem, amount: Long = 1L) {
|
fun consumeItem(item: GameItem, amount: Long = 1L) {
|
||||||
val actor = this.actor as Actor
|
val actor = this.actor as Actor
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.gdx.graphics.Cvec
|
import net.torvald.gdx.graphics.Cvec
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.printdbg
|
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
import net.torvald.terrarum.gameactors.*
|
import net.torvald.terrarum.gameactors.*
|
||||||
@@ -39,7 +38,9 @@ class DroppedItem : ActorWithBody {
|
|||||||
|
|
||||||
private var timeSinceSpawned = 0f
|
private var timeSinceSpawned = 0f
|
||||||
|
|
||||||
fun canBePickedUp() = timeSinceSpawned > NO_PICKUP_TIME && !flagDespawn
|
var noAutoPickup = false
|
||||||
|
|
||||||
|
fun canBePickedUpAutomatically() = !noAutoPickup && timeSinceSpawned > NO_PICKUP_TIME && !flagDespawn
|
||||||
|
|
||||||
private val randKey1 = (Math.random() * 256).toInt()
|
private val randKey1 = (Math.random() * 256).toInt()
|
||||||
private val randKey2 = (Math.random() * 256).toInt()
|
private val randKey2 = (Math.random() * 256).toInt()
|
||||||
@@ -53,7 +54,7 @@ class DroppedItem : ActorWithBody {
|
|||||||
* @param topLeftX world-wise coord
|
* @param topLeftX world-wise coord
|
||||||
* @param topLeftY world-wise coord
|
* @param topLeftY world-wise coord
|
||||||
*/
|
*/
|
||||||
constructor(itemID: ItemID, centreX: Double, bottomY: Double, spawnVelo: Vector2? = null) : super(RenderOrder.OVERLAY, PhysProperties.PHYSICS_OBJECT()) {
|
constructor(itemID: ItemID, centreX: Double, bottomY: Double, spawnVelo: Vector2? = null, noAutoPickup: Boolean = false) : super(RenderOrder.OVERLAY, PhysProperties.PHYSICS_OBJECT()) {
|
||||||
this.itemID = itemID
|
this.itemID = itemID
|
||||||
|
|
||||||
if (itemID.isActor())
|
if (itemID.isActor())
|
||||||
@@ -94,6 +95,8 @@ class DroppedItem : ActorWithBody {
|
|||||||
// printdbg(this, "DroppedItem with itemID '${itemID}'")
|
// printdbg(this, "DroppedItem with itemID '${itemID}'")
|
||||||
|
|
||||||
physProp.ignorePlatform = false
|
physProp.ignorePlatform = false
|
||||||
|
|
||||||
|
this.noAutoPickup = noAutoPickup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.printdbg
|
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.gameitems.mouseInInteractableRange
|
import net.torvald.terrarum.gameitems.mouseInInteractableRange
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||||
@@ -107,7 +105,7 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun startSecondaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
override fun startSecondaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
||||||
(INGAME as TerrarumIngame).pickupFixture(actor, delta, mwx, mwy, mtx, mty, false)
|
(INGAME as TerrarumIngame).pickupFixtureOrDroppedItem(actor, delta, mwx, mwy, mtx, mty, false)
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package net.torvald.terrarum.modulebasegame.gameworld
|
||||||
|
|
||||||
|
import net.torvald.terrarum.Point2i
|
||||||
|
import net.torvald.terrarum.gameworld.TerrarumSavegameExtrafieldSerialisable
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2025-03-09.
|
||||||
|
*/
|
||||||
|
class GameConveyorLinkages : TerrarumSavegameExtrafieldSerialisable {
|
||||||
|
|
||||||
|
internal val ledger = ArrayList<ConveyorBeltInstallation>()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ConveyorBeltInstallation(
|
||||||
|
val type: Int,
|
||||||
|
val p: Point2i,
|
||||||
|
val q: Point2i,
|
||||||
|
val installer: UUID?
|
||||||
|
)
|
||||||
@@ -12,6 +12,7 @@ import kotlin.math.ceil
|
|||||||
*/
|
*/
|
||||||
class GamePostalService : TerrarumSavegameExtrafieldSerialisable {
|
class GamePostalService : TerrarumSavegameExtrafieldSerialisable {
|
||||||
|
|
||||||
|
internal val centralPostbox = ArrayList<Post>()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val reXmlTag = Regex("""<[^>]+>""")
|
private val reXmlTag = Regex("""<[^>]+>""")
|
||||||
|
|||||||
Reference in New Issue
Block a user