parent
91fab0848f
commit
9fa2aa46cd
@ -148,6 +148,26 @@ object ServerConfig {
|
||||
.comment("If this is disabled, any (technically) excess hunger will be nullified, unless playing on peaceful difficulty.")
|
||||
.define("regenerateEnergy", true)
|
||||
|
||||
object NanobotsRegeneration {
|
||||
val COOLDOWN: List<Int> by specBuilder
|
||||
.comment("In ticks, time between heal ticks")
|
||||
.comment("One heal tick restores 1 heart (2 health points) at most")
|
||||
.comment("If not getting hurt in specified period of ticks, heal tick takes place, tick timer resets to zero and THIS array' index advances by 1")
|
||||
.comment("Index inside this array can not exceed of one of ability's")
|
||||
.comment("")
|
||||
.comment("Wording in pseudocode:")
|
||||
.comment("if (ticksSinceTakingDamage >= cooldownConfigOption[healTicks /* or config's biggest index, whichever is smaller */]) {")
|
||||
.comment(" healTicks = min(healTicks + 1, this.level /* ability level */)")
|
||||
.comment(" ticksSinceTakingDamage = 0")
|
||||
.comment(" this.ply.heal(...)")
|
||||
.comment("}")
|
||||
.defineList("cooldown", { mutableListOf(80, 60, 40, 20) }) { it is Int }
|
||||
|
||||
val ENERGY_PER_HITPOINT by specBuilder
|
||||
.comment("Energy required to regenerate 1 health point (half a heart)")
|
||||
.defineImpreciseFraction("energyPerHitpoint", ImpreciseFraction(800))
|
||||
}
|
||||
|
||||
val ANDROID_ENERGY_PER_HUNGER_POINT by specBuilder.defineImpreciseFraction("energyPerHunger", ImpreciseFraction(2000), ImpreciseFraction.ZERO)
|
||||
val ANDROID_MAX_ENERGY by specBuilder.comment("Internal battery of every android has this much storage").defineImpreciseFraction("capacity", ImpreciseFraction(80_000), ImpreciseFraction.ZERO)
|
||||
val NIGHT_VISION_POWER_DRAW by specBuilder.defineImpreciseFraction("nightVisionPowerDraw", ImpreciseFraction(8), ImpreciseFraction.ZERO)
|
||||
@ -223,6 +243,7 @@ object ServerConfig {
|
||||
|
||||
init {
|
||||
// access instances so spec is built
|
||||
NanobotsRegeneration
|
||||
EnderTeleporter
|
||||
AndroidJumpBoost
|
||||
AndroidItemMagnet
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.android.feature
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent
|
||||
import ru.dbotthepony.mc.otm.ServerConfig
|
||||
import ru.dbotthepony.mc.otm.android.AndroidFeature
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
@ -19,16 +20,16 @@ class NanobotsRegenerationFeature(android: MatteryPlayerCapability) : AndroidFea
|
||||
if (ply.health > 0f && ply.health < ply.maxHealth) {
|
||||
ticksPassed++
|
||||
|
||||
val waitTime = TICKS_BETWEEN_HEAL.getOrElse(healTicks) { TICKS_BETWEEN_HEAL.last() }
|
||||
val waitTime = ServerConfig.NanobotsRegeneration.COOLDOWN.getOrElse(healTicks) { ServerConfig.NanobotsRegeneration.COOLDOWN.last() }
|
||||
|
||||
if (ticksPassed > waitTime) {
|
||||
val missingHealth = (ply.maxHealth - ply.health).coerceAtMost(2f)
|
||||
val power = ENERGY_PER_HITPOINT * missingHealth
|
||||
val power = ServerConfig.NanobotsRegeneration.ENERGY_PER_HITPOINT * missingHealth
|
||||
val extracted = android.androidEnergy.extractEnergyInner(power, false)
|
||||
|
||||
if (extracted.isPositive) {
|
||||
healTicks = (healTicks + 1).coerceAtMost(level)
|
||||
val healed = (extracted / ENERGY_PER_HITPOINT).toFloat()
|
||||
val healed = (extracted / ServerConfig.NanobotsRegeneration.ENERGY_PER_HITPOINT).toFloat()
|
||||
ply.heal(healed)
|
||||
(ply as ServerPlayer?)?.awardStat(StatNames.HEALTH_REGENERATED, (healed * 10f).roundToInt())
|
||||
ticksPassed = 0
|
||||
@ -59,15 +60,4 @@ class NanobotsRegenerationFeature(android: MatteryPlayerCapability) : AndroidFea
|
||||
ticksPassed = nbt.getInt("ticksPassed")
|
||||
healTicks = nbt.getInt("healTicks")
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ENERGY_PER_HITPOINT = ImpreciseFraction(800)
|
||||
|
||||
private val TICKS_BETWEEN_HEAL = listOf(
|
||||
100, // 5 seconds
|
||||
80, // 4 seconds
|
||||
60, // 3 seconds
|
||||
40, // 2 seconds
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user