Skip to content

Commit 5ac0dc6

Browse files
committed
opening and final strike, no visuals yet
1 parent ba5d809 commit 5ac0dc6

File tree

3 files changed

+88
-35
lines changed

3 files changed

+88
-35
lines changed

src/main/kotlin/dev/sterner/common/components/VoidBoundPlayerItemAbilityComponent.kt

+81-20
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ import team.lodestar.lodestone.registry.common.LodestoneAttributeRegistry
2323
class VoidBoundPlayerItemAbilityComponent(private val player: Player) : AutoSyncedComponent, CommonTickingComponent {
2424

2525
private var vampirismCooldown: Int = 0
26-
private var wrathCooldown: Int = 0
27-
private val wrathCooldownMax = 20 * 60
26+
private var wrathStackKiller: Int = 0
27+
private val wrathStackKillerMax = 20 * 60
2828
private var finalStrike = false
2929
private val finalStrikeCooldownMax = 20 * 20
3030
private var finalStrikeDuration = 0
3131
private var wrathCounter = 0
3232

33-
fun tryUseVampirism(target: LivingEntity){
33+
//VAMPIRISM start
34+
/**
35+
* If the cooldown is 0, perform Vamp, if vamp is successful, heal and play sound
36+
*/
37+
fun tryUseVampirism(target: LivingEntity, amount: Float) : Float{
3438
if (vampirismCooldown <= 0) {
3539
val healing = performVampirism(target)
3640
if (healing > 0) {
@@ -40,8 +44,12 @@ class VoidBoundPlayerItemAbilityComponent(private val player: Player) : AutoSync
4044
sync()
4145
}
4246
}
47+
return amount
4348
}
4449

50+
/**
51+
* Get amount of health to heal, healing is dependent on amount of spirits or a players armor value. Defaults at half a heart
52+
*/
4553
private fun performVampirism(target: LivingEntity): Int {
4654
var healing = 0
4755
if (target is Player) {
@@ -54,46 +62,79 @@ class VoidBoundPlayerItemAbilityComponent(private val player: Player) : AutoSync
5462
healing += it.count
5563
}
5664
} else {
57-
healing += 2
65+
healing += 1
5866
}
5967
}
6068

6169
return healing
6270
}
6371

72+
//VAMPIRISM end
73+
74+
//OPENER - FINALE start
75+
76+
/**
77+
* If final strike is not active, increase the wrath counter and start the cooldown
78+
*/
6479
fun increaseWrath() {
6580
if (!finalStrike) {
6681
wrathCounter++
67-
wrathCooldown = wrathCooldownMax
82+
wrathStackKiller = wrathStackKillerMax
6883
}
6984
sync()
7085
}
7186

72-
override fun readFromNbt(tag: CompoundTag) {
73-
vampirismCooldown = tag.getInt("vampirismCooldown")
74-
wrathCooldown = tag.getInt("wrathCooldown")
75-
wrathCounter = tag.getInt("wrathCounter")
76-
finalStrike = tag.getBoolean("finalStrike")
87+
/**
88+
* if wrath is not maxed out and target has more than 95% health, increase wrath and increase the damage
89+
*/
90+
fun tryUseOpener(target: LivingEntity, amount: Float) : Float {
91+
var outDamage = amount
92+
if (wrathCounter < 10 && target.health / target.maxHealth > 0.95) {
93+
increaseWrath()
94+
outDamage *= 1.2f
95+
}
96+
return outDamage
7797
}
7898

79-
override fun writeToNbt(tag: CompoundTag) {
80-
tag.putInt("vampirismCooldown", vampirismCooldown)
81-
tag.putInt("wrathCooldown", wrathCooldown)
82-
tag.putInt("wrathCounter", wrathCounter)
83-
tag.putBoolean("finalStrike", finalStrike)
99+
/**
100+
* if final strike is active, multiply output damage with wrath and reset
101+
*/
102+
fun tryUseFinale(entity: LivingEntity?, amount: Float): Float {
103+
var outAmount = amount
104+
if (finalStrike) {
105+
finalStrike = false
106+
outAmount *= (wrathCounter / 2)
107+
wrathCounter = 0
108+
}
109+
return outAmount
84110
}
85111

112+
//OPENER - FINALE end
113+
86114
override fun tick() {
115+
//Count down vampirism only when vampirism ability is selected
87116
if (vampirismCooldown > 0 && VoidBoundItemUtils.getActiveAbility(player.mainHandItem) == ItemAbility.VAMPIRISM) {
88117
vampirismCooldown--
89118
sync()
90119
}
91120

121+
if (VoidBoundItemUtils.getActiveAbility(player.mainHandItem) != ItemAbility.OPENER) {
122+
if (finalStrike) {
123+
finalStrike = false
124+
sync()
125+
}
126+
if (wrathCounter > 0) {
127+
wrathCounter = 0
128+
sync()
129+
}
130+
}
131+
92132
if (!finalStrike) {
93133
// Wrath logic
94134
if (wrathCounter in 1..9) {
95-
if (wrathCooldown > 0) {
96-
wrathCooldown--
135+
//if cooldown hits 0
136+
if (wrathStackKiller > 0) {
137+
wrathStackKiller--
97138
} else {
98139
// If cooldown hits 0, reset the wrath counter
99140
wrathCounter = 0
@@ -104,28 +145,46 @@ class VoidBoundPlayerItemAbilityComponent(private val player: Player) : AutoSync
104145
// FinalStrike logic when wrathCounter reaches 10
105146
if (wrathCounter == 10) {
106147
finalStrike = true
107-
wrathCounter = 0
108-
wrathCooldown = 0
148+
wrathStackKiller = 0
109149
finalStrikeDuration = finalStrikeCooldownMax
110150
sync()
111151
}
152+
112153
} else {
113154
// Handle ticking down the finalStrike duration
114155
if (finalStrikeDuration > 0) {
115156
finalStrikeDuration--
116157
} else {
158+
wrathCounter = 0
117159
finalStrike = false
118160
}
119161
sync()
120162
}
121163
}
122164

165+
override fun readFromNbt(tag: CompoundTag) {
166+
vampirismCooldown = tag.getInt("vampirismCooldown")
167+
wrathStackKiller = tag.getInt("wrathCooldown")
168+
wrathCounter = tag.getInt("wrathCounter")
169+
finalStrike = tag.getBoolean("finalStrike")
170+
finalStrikeDuration = tag.getInt("finalStrikeDuration")
171+
}
172+
173+
override fun writeToNbt(tag: CompoundTag) {
174+
tag.putInt("vampirismCooldown", vampirismCooldown)
175+
tag.putInt("wrathCooldown", wrathStackKiller)
176+
tag.putInt("wrathCounter", wrathCounter)
177+
tag.putBoolean("finalStrike", finalStrike)
178+
tag.putInt("finalStrikeDuration", finalStrikeDuration)
179+
}
180+
181+
123182
private fun sync(){
124183
VoidBoundComponentRegistry.VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT.sync(player)
125184
}
126185

127186
companion object {
128-
fun onRightClickItem(player: ServerPlayer, interactionHand: InteractionHand?, stack: ItemStack): Boolean {
187+
fun onRightClickItem(player: ServerPlayer, interactionHand: InteractionHand, stack: ItemStack): Boolean {
129188
if (VoidBoundItemUtils.getActiveAbility(stack) == ItemAbility.TRIPLE_REBOUND) {
130189
val level = player.level()
131190
if (!level.isClientSide) {
@@ -157,5 +216,7 @@ class VoidBoundPlayerItemAbilityComponent(private val player: Player) : AutoSync
157216

158217
return false
159218
}
219+
220+
160221
}
161222
}

src/main/kotlin/dev/sterner/common/item/equipment/ichor/IchoriumVorpal.kt

-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import net.minecraft.world.item.ItemStack
2323
import net.minecraft.world.item.Tier
2424
import net.minecraft.world.item.context.UseOnContext
2525
import net.minecraft.world.level.Level
26-
import net.minecraft.world.level.block.Blocks
2726
import net.minecraft.world.level.block.state.BlockState
2827
import net.minecraft.world.level.levelgen.structure.BoundingBox
2928
import net.minecraft.world.phys.BlockHitResult
@@ -48,13 +47,6 @@ class IchoriumVorpal(
4847
return 72000
4948
}
5049

51-
override fun hurtEnemy(stack: ItemStack, target: LivingEntity, attacker: LivingEntity): Boolean {
52-
if (attacker is Player && VoidBoundItemUtils.getActiveAbility(stack) == ItemAbility.VAMPIRISM) {
53-
VoidBoundComponentRegistry.VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT.get(attacker).tryUseVampirism(target)
54-
}
55-
return super.hurtEnemy(stack, target, attacker)
56-
}
57-
5850
override fun canAttackBlock(state: BlockState?, level: Level?, pos: BlockPos?, player: Player): Boolean {
5951
return VoidBoundItemUtils.getActiveAbility(player.mainHandItem) == ItemAbility.HARVEST
6052
}

src/main/kotlin/dev/sterner/registry/VoidBoundEvents.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ object VoidBoundEvents {
4646
val attacker = it.source.entity
4747
if (attacker is Player) {
4848
val item = attacker.mainHandItem
49-
val bl = VoidBoundItemUtils.getActiveAbility(item) == ItemAbility.VAMPIRISM
50-
if (bl) {
51-
attacker.heal(attacker.random.nextInt(2).toFloat())
52-
}
49+
val component = VoidBoundComponentRegistry.VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT.get(attacker)
5350

54-
val bl2 = VoidBoundItemUtils.getActiveAbility(item) == ItemAbility.OPENER
55-
if (bl2 && it.entity.health / it.entity.maxHealth > 0.95) {
56-
it.amount *= 1.5f
51+
if (VoidBoundItemUtils.getActiveAbility(item) == ItemAbility.OPENER) {
52+
it.amount = component.tryUseOpener(it.entity, it.amount)
53+
} else if (VoidBoundItemUtils.getActiveAbility(item) == ItemAbility.VAMPIRISM) {
54+
it.amount = component.tryUseVampirism(it.entity, it.amount)
55+
} else if (VoidBoundItemUtils.getActiveAbility(item) == ItemAbility.FINALE) {
56+
it.amount = component.tryUseFinale(it.entity, it.amount)
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)