DEADSOFTWARE

Game action modules generation
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / actions / useitem / UseBedAction.kt
1 package ru.deadsoftware.cavedroid.game.actions.useitem
3 import ru.deadsoftware.cavedroid.game.GameItemsHolder
4 import ru.deadsoftware.cavedroid.game.GameScope
5 import ru.deadsoftware.cavedroid.game.mobs.MobsController
6 import ru.deadsoftware.cavedroid.game.model.item.Item
7 import ru.deadsoftware.cavedroid.game.world.GameWorld
8 import javax.inject.Inject
10 @GameScope
11 @UseItemAction(UseBedAction.ACTION_KEY)
12 class UseBedAction @Inject constructor(
13 private val gameWorld: GameWorld,
14 private val mobsController: MobsController,
15 private val gameItemsHolder: GameItemsHolder,
16 ) : IUseItemAction {
18 override fun perform(item: Item.Usable, x: Int, y: Int) {
19 val bedLeft = gameItemsHolder.getBlock("bed_l")
20 val bedRight = gameItemsHolder.getBlock("bed_r")
22 if (gameWorld.canPlaceToForeground(x, y, bedLeft) && gameWorld.canPlaceToForeground(x + 1, y, bedRight)) {
23 gameWorld.placeToForeground(x, y, bedLeft)
24 gameWorld.placeToForeground(x + 1, y, bedRight)
25 mobsController.player.inventory.decreaseCurrentItemAmount()
26 }
27 }
29 companion object {
30 const val ACTION_KEY = "use_bed_action"
31 }
32 }