DEADSOFTWARE

a479a4f7280c2ad8d5fd936dd78546a01f13bf74
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / model / item / Item.kt
1 package ru.deadsoftware.cavedroid.game.model.item
3 import com.badlogic.gdx.graphics.g2d.Sprite
4 import ru.deadsoftware.cavedroid.game.model.block.Block
5 import kotlin.contracts.ExperimentalContracts
6 import kotlin.contracts.contract
8 @OptIn(ExperimentalContracts::class)
9 sealed class Item {
11 abstract val params: CommonItemParams
12 abstract val sprite: Sprite
14 override fun hashCode(): Int {
15 return params.key.hashCode()
16 }
18 override fun equals(other: Any?): Boolean {
19 return params.key == (other as Item).params.key
20 }
22 fun isPlaceable(): Boolean {
23 contract { returns(true) implies (this@Item is Placeable) }
24 return this is Placeable
25 }
27 fun isTool(): Boolean {
28 contract { returns(true) implies (this@Item is Tool) }
29 return this is Tool
30 }
32 fun isUsable(): Boolean {
33 contract { returns(true) implies (this@Item is Placeable) }
34 return this is Placeable
35 }
37 sealed class Tool : Item() {
38 abstract val mobDamageMultiplier: Float
39 abstract val blockDamageMultiplier: Float
40 }
42 sealed class Usable : Item() {
43 abstract val useActionKey: String
44 }
46 data class Placeable(
47 override val params: CommonItemParams,
48 val block: Block
49 ) : Item() {
50 override val sprite: Sprite get() = block.sprite
51 }
53 data class Sword(
54 override val params: CommonItemParams,
55 override val sprite: Sprite,
56 override val mobDamageMultiplier: Float,
57 override val blockDamageMultiplier: Float,
58 ) : Tool()
60 data class Shovel(
61 override val params: CommonItemParams,
62 override val sprite: Sprite,
63 override val mobDamageMultiplier: Float,
64 override val blockDamageMultiplier: Float,
65 ) : Tool()
67 data class Bucket(
68 override val params: CommonItemParams,
69 override val sprite: Sprite,
70 override val useActionKey: String
71 ) : Usable()
73 }