Skip to content

Commit

Permalink
Shooting Star Distractions and Diversion enhancement (#479)
Browse files Browse the repository at this point in the history
* Add 25% chance to mine extra ore for 15 minutes after talking to star sprite after completion of a crashed star
* Add custom variable to `variables-custom.yml` called `shooting_star_bonus_ore`
* Add check to `mining.kts` if a player is currently eligible for an extra ore chance
* Add player timer to `ShootingStar.kts` to handle the 15-minute extra ore bonus
* Add alternative dialog to `Star Sprite` if the player already has the extra ore buff after completing a crashed star
  • Loading branch information
Syntax2022 authored Mar 14, 2024
1 parent 174bbd6 commit 7b9fce3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
6 changes: 5 additions & 1 deletion data/definitions/variables-custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ skull_sceptre_charges:
format: int
default: 10
persist: true
shooting_star_bonus_ore:
format: int
default: 0
persist: true
al_the_camel:
format: boolean
persist: true
persist: true
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import world.gregs.voidps.engine.entity.character.player.skill.Skill
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.obj.*
import world.gregs.voidps.engine.entity.objectDespawn
import world.gregs.voidps.engine.entity.playerSpawn
import world.gregs.voidps.engine.entity.worldSpawn
import world.gregs.voidps.engine.getPropertyOrNull
import world.gregs.voidps.engine.inject
Expand All @@ -28,6 +29,8 @@ import world.gregs.voidps.engine.inv.remove
import world.gregs.voidps.engine.map.collision.blocked
import world.gregs.voidps.engine.queue.softQueue
import world.gregs.voidps.engine.timer.timerStart
import world.gregs.voidps.engine.timer.timerStop
import world.gregs.voidps.engine.timer.timerTick
import world.gregs.voidps.engine.timer.toTicks
import world.gregs.voidps.type.Direction
import world.gregs.voidps.type.Tile
Expand Down Expand Up @@ -136,6 +139,32 @@ fun calculateRewards(stardust: Int): Map<String, Int> {
)
}

fun givePlayerBonusOreReward(player: Player) {
player["shooting_star_bonus_ore"] = 900
player.timers.start("shooting_star_bonus_ore_timer")
}

playerSpawn { player ->
if (player["shooting_star_bonus_ore", 0] > 0) {
player.timers.restart("shooting_star_bonus_ore_timer")
}
}

timerStart("shooting_star_bonus_ore_timer") { player ->
interval = TimeUnit.SECONDS.toTicks(1)
}

timerTick("shooting_star_bonus_ore_timer") { player ->
if (player.dec("shooting_star_bonus_ore") <= 0) {
cancel()
return@timerTick
}
}

timerStop("shooting_star_bonus_ore_timer") { player ->
player.message("<dark_red>The ability to mine an extra ore has worn off.")
}

objectDespawn("shooting_star_tier_1") {
areaSound("star_meteor_despawn", it.tile, radius = 15)
cleanseEvent(false)
Expand Down Expand Up @@ -191,6 +220,11 @@ npcOperate("Talk-to", "star_sprite") {
messageBuilder.append(", $amount ${reward.replace("_", " ").replace("noted", "").plural(amount)}")
}
}
npc<Cheerful>("I have rewarded you by making it so you can mine extra ore for the next 15 minutes, ${messageBuilder}.")
if(!ShootingStarHandler.rewardPlayerBonusOre(player)) {
npc<Cheerful>("I have rewarded you by making it so you can mine extra ore for the next 15 minutes, ${messageBuilder}.")
givePlayerBonusOreReward(player)
} else {
npc<Cheerful>("You already have the ability to mine an extra ore, ${messageBuilder.replace(0, 4, "However")}.")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package world.gregs.voidps.world.activity.dnd.shootingstar

import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.entity.character.player.skill.Skill
import world.gregs.voidps.engine.entity.obj.GameObject
import world.gregs.voidps.engine.entity.obj.remove
import world.gregs.voidps.engine.entity.obj.replace
import world.gregs.voidps.engine.inv.add
import world.gregs.voidps.engine.inv.inventory
import world.gregs.voidps.engine.timer.toTicks
import world.gregs.voidps.type.Tile
import world.gregs.voidps.type.random
import world.gregs.voidps.world.interact.entity.sound.areaSound
import java.util.concurrent.TimeUnit
import kotlin.random.Random

object ShootingStarHandler {

Expand All @@ -21,6 +27,23 @@ object ShootingStarHandler {
totalCollected++
}

fun rewardPlayerBonusOre(player: Player): Boolean {
return player.timers.contains("shooting_star_bonus_ore_timer")
}

fun extraOreHandler(player: Player, ore: String, xpReward: Double) {
if(getChance() && rewardPlayerBonusOre(player)) {
player.message("<dark_green>You managed to mine an extra ore from the rock.")
player.inventory.add(ore)
player.experience.add(Skill.Mining, xpReward)
}
}

private fun getChance(): Boolean {
val chance = Random.nextInt(100) + 1
return chance <= 25
}

fun handleMinedStarDust(currentMinedStar: GameObject) {
val starPayout = currentMinedStar.def["collect_for_next_layer", -1]
if (totalCollected >= starPayout) {
Expand All @@ -44,4 +67,4 @@ object ShootingStarHandler {
}
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ objectOperate("Mine") {
val ore = itemDefinitions.get(item)["mining", Ore.EMPTY]
if (success(player.levels.get(Skill.Mining), ore.chance)) {
player.experience.add(Skill.Mining, ore.xp)

ShootingStarHandler.extraOreHandler(player, item, ore.xp)
if (!addOre(player, item) || deplete(rock, target)) {
player.clearAnimation()
break
Expand Down

0 comments on commit 7b9fce3

Please sign in to comment.