DEADSOFTWARE

Game action modules generation
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / actions / useitem / UsePigSpawnEggAction.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.mobs.Pig
7 import ru.deadsoftware.cavedroid.game.model.item.Item
8 import ru.deadsoftware.cavedroid.misc.utils.px
9 import javax.inject.Inject
11 @GameScope
12 @UseItemAction(UsePigSpawnEggAction.ACTION_KEY)
13 class UsePigSpawnEggAction @Inject constructor(
14 private val mobsController: MobsController,
15 private val gameItemsHolder: GameItemsHolder,
16 ) : IUseItemAction {
18 override fun perform(item: Item.Usable, x: Int, y: Int) {
19 Pig(mobsController.player.cursorX.px, mobsController.player.cursorY.px)
20 .apply {
21 attachToController(mobsController)
22 }
24 mobsController.player.decreaseCurrentItemCount(gameItemsHolder)
25 }
27 companion object {
28 const val ACTION_KEY = "use_spawn_egg_pig"
29 }
30 }