Skip to content

Commit c03a281

Browse files
committed
重构代码
1 parent d022b65 commit c03a281

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/main/java/org/cneko/justarod/JREnchantments.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class JREnchantments {
1212
public static final RegistryKey<Enchantment> HYSTERECTOMY = of(HYSTERECTOMY_ID);
1313
public static final Identifier UTERUS_INSTALLATION_ID = Identifier.of(MODID,"uterus_installation");
1414
public static final RegistryKey<Enchantment> UTERUS_INSTALLATION = of(UTERUS_INSTALLATION_ID);
15+
public static final Identifier ARTIFICIAL_ABORTION_ID = Identifier.of(MODID,"artificial_abortion");
16+
public static final RegistryKey<Enchantment> ARTIFICIAL_ABORTION = of(ARTIFICIAL_ABORTION_ID);
1517

1618
public static RegistryKey<Enchantment> of(Identifier id) {
1719
return RegistryKey.of(RegistryKeys.ENCHANTMENT, id);

src/main/java/org/cneko/justarod/item/medical/AbortionPillItem.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class AbortionPillItem(settings: Settings) : MedicalItem(settings) {
5353

5454
} else {
5555
// 早/中期:更危险,伴随大出血和绝育风险
56-
val task = TickTaskQueue() // 假设每次使用都应新建实例
57-
target.damage(target.world.damageSources.generic(), 2f) // 初始伤害
56+
val task = TickTaskQueue()
5857

5958
// 安排持续伤害模拟大出血
6059
for (i in 1..10) { // 从1开始产生延迟
@@ -70,7 +69,7 @@ class AbortionPillItem(settings: Settings) : MedicalItem(settings) {
7069
target.addEffect(StatusEffects.NAUSEA, 0, 20 * 15) // 恶心效果持续15秒
7170

7271
// 通知玩家出现并发症
73-
val complicationMsg = "§c并发症!手术对你造成了永久性损伤"
72+
val complicationMsg = "§c并发症!对你造成了永久性损伤"
7473
if (user != target) {
7574
user.sendMessage(Text.of("§e并发症发生了..."), false)
7675
}

src/main/java/org/cneko/justarod/item/medical/ScalpelItem.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import org.cneko.justarod.item.JRItems
1515
import net.minecraft.entity.effect.StatusEffectInstance
1616
import net.minecraft.entity.effect.StatusEffects
1717
import org.cneko.justarod.entity.Pregnant
18+
import org.cneko.justarod.item.addEffect
19+
import org.cneko.toneko.common.mod.util.TickTaskQueue
1820

1921
// 继承自 MedicalItem
2022
class ScalpelItem(settings: Settings) : MedicalItem(settings.maxCount(1).maxDamage(4)) {
@@ -44,6 +46,8 @@ class ScalpelItem(settings: Settings) : MedicalItem(settings.maxCount(1).maxDama
4446
} else if (stack.containsEnchantment(JREnchantments.UTERUS_INSTALLATION)) {
4547
val offHandStack = user.getStackInHand(if (hand == Hand.MAIN_HAND) Hand.OFF_HAND else Hand.MAIN_HAND)
4648
return target.isHysterectomy && offHandStack.isOf(JRItems.UTERUS) // 目标需要安装,且使用者副手持有子宫
49+
}else if (stack.containsEnchantment(JREnchantments.ARTIFICIAL_ABORTION)){
50+
return target.pregnant >0
4751
}
4852

4953
return false // 没有对应附魔,无法使用
@@ -63,6 +67,8 @@ class ScalpelItem(settings: Settings) : MedicalItem(settings.maxCount(1).maxDama
6367
// canApply已经检查过副手,这里为了更明确的消息再次检查
6468
val offHandStack = user.getStackInHand(Hand.OFF_HAND) // 假设主手是手术刀
6569
if (!offHandStack.isOf(JRItems.UTERUS)) return Text.of("§c你的副手必须持有子宫才能执行此操作!")
70+
}else if (stack.containsEnchantment(JREnchantments.ARTIFICIAL_ABORTION)){
71+
return if (user == target) Text.of("§c你没有怀孕!") else Text.of("§c对方没有怀孕")
6672
}
6773

6874
return Text.of("§c不满足使用条件。") // 默认失败消息
@@ -93,6 +99,35 @@ class ScalpelItem(settings: Settings) : MedicalItem(settings.maxCount(1).maxDama
9399
if (offHandStack.isOf(JRItems.UTERUS)) {
94100
offHandStack.decrement(1)
95101
}
102+
}else if (stack.containsEnchantment(JREnchantments.ARTIFICIAL_ABORTION)){
103+
val pre = target.pregnant
104+
if (pre > 20*60*20*5) {
105+
val task = TickTaskQueue()
106+
target.damage(target.world.damageSources.generic(), 2f) // 初始伤害
107+
108+
// 安排持续伤害模拟大出血
109+
for (i in 1..10) { // 从1开始产生延迟
110+
task.addTask(20 * i) {
111+
if (!target.isDead) {
112+
target.damage(target.world.damageSources.generic(), 2f)
113+
}
114+
}
115+
}
116+
// 有20%概率因并发症导致永久绝育和恶心
117+
if (target.random.nextInt(5) == 0) {
118+
target.isSterilization = true
119+
target.addEffect(StatusEffects.NAUSEA, 0, 20 * 15) // 恶心效果持续15秒
120+
121+
// 通知玩家出现并发症
122+
val complicationMsg = "§c并发症!手术对你造成了永久性损伤!"
123+
if (user != target) {
124+
user.sendMessage(Text.of("§e并发症发生了..."), false)
125+
}
126+
target.sendMessage(Text.of(complicationMsg))
127+
}
128+
}
129+
target.pregnant = 0
130+
target.dropStack(JRItems.MOLE.defaultStack)
96131
}
97132
}
98133

0 commit comments

Comments
 (0)