继续重构部分伤害perk

This commit is contained in:
17146 2025-05-07 12:25:11 +08:00 committed by Light_Quanta
parent f138f1aaf2
commit 83a309053c
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
7 changed files with 117 additions and 96 deletions

View file

@ -543,9 +543,11 @@ public class ClientEventHandler {
rpm = 600; rpm = 600;
} }
if (GunsTool.getPerkIntTag(tag, "DesperadoTimePost") > 0) { for (Perk.Type type : Perk.Type.values()) {
int perkLevel = data.perk.getLevel(ModPerks.DESPERADO); var instance = data.perk.getInstance(type);
rpm *= (int) (1.285 + 0.015 * perkLevel); if (instance != null) {
rpm = instance.perk().getModifiedRPM(rpm, data, instance);
}
} }
double rps = (double) rpm / 60; double rps = (double) rpm / 60;

View file

@ -416,9 +416,11 @@ public class LivingEventHandler {
newData.charge.timer.reset(); newData.charge.timer.reset();
} }
int level = newData.perk.getLevel(ModPerks.KILLING_TALLY); for (Perk.Type type : Perk.Type.values()) {
if (level != 0) { var instance = newData.perk.getInstance(type);
GunsTool.setPerkIntTag(newTag, "KillingTally", 0); if (instance != null) {
instance.perk().onChangeSlot(newData, instance, player);
}
} }
if (player.level() instanceof ServerLevel) { if (player.level() instanceof ServerLevel) {
@ -497,10 +499,6 @@ public class LivingEventHandler {
} }
} }
if (DamageTypeTool.isGunDamage(source)) {
handleKillingTallyDamage(stack, event);
}
if (source.getDirectEntity() instanceof ProjectileEntity projectile) { if (source.getDirectEntity() instanceof ProjectileEntity projectile) {
if (data.perk.getLevel(ModPerks.FOURTH_TIMES_CHARM) > 0) { if (data.perk.getLevel(ModPerks.FOURTH_TIMES_CHARM) > 0) {
float bypassArmorRate = projectile.getBypassArmorRate(); float bypassArmorRate = projectile.getBypassArmorRate();
@ -548,38 +546,8 @@ public class LivingEventHandler {
} }
if (DamageTypeTool.isGunDamage(source)) { if (DamageTypeTool.isGunDamage(source)) {
handleKillingTallyAddCount(stack);
handleSubsistence(stack, attacker); handleSubsistence(stack, attacker);
} }
if (DamageTypeTool.isHeadshotDamage(source)) {
handleDesperado(stack);
}
}
private static void handleKillingTallyDamage(ItemStack stack, LivingIncomingDamageEvent event) {
var data = GunData.from(stack);
int level = data.perk.getLevel(ModPerks.KILLING_TALLY);
if (level == 0) {
return;
}
int killTally = data.perk.getTag(ModPerks.KILLING_TALLY).getInt("KillingTally");
if (killTally == 0) {
return;
}
event.setAmount(event.getAmount() * (1.0f + (0.1f * level) * killTally));
}
private static void handleKillingTallyAddCount(ItemStack stack) {
var data = GunData.from(stack);
int level = data.perk.getLevel(ModPerks.KILLING_TALLY);
if (level != 0) {
var tag = data.perk.getTag(ModPerks.KILLING_TALLY);
tag.putInt("KillingTally", Math.min(3, tag.getInt("KillingTally") + 1));
data.save();
}
} }
private static void handleFourthTimesCharm(ItemStack stack) { private static void handleFourthTimesCharm(ItemStack stack) {
@ -639,16 +607,6 @@ public class LivingEventHandler {
} }
} }
private static void handleDesperado(ItemStack stack) {
var data = GunData.from(stack);
int level = data.perk.getLevel(ModPerks.DESPERADO);
if (level == 0) return;
var tag = data.perk.getTag(ModPerks.DESPERADO);
tag.putInt("DesperadoTime", 90 + level * 10);
data.save();
}
@SubscribeEvent @SubscribeEvent
public static void onPickup(ItemEntityPickupEvent.Pre event) { public static void onPickup(ItemEntityPickupEvent.Pre event) {
if (!VehicleConfig.VEHICLE_ITEM_PICKUP.get()) return; if (!VehicleConfig.VEHICLE_ITEM_PICKUP.get()) return;

View file

@ -1,11 +1,9 @@
package com.atsuishio.superbwarfare.event; package com.atsuishio.superbwarfare.event;
import com.atsuishio.superbwarfare.api.event.ReloadEvent; import com.atsuishio.superbwarfare.api.event.ReloadEvent;
import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
@ -30,9 +28,6 @@ public class ReloadEventHandler {
instance.perk().preReload(data, instance, player); instance.perk().preReload(data, instance, player);
} }
} }
handleKillingTallyPre(stack);
handleDesperadoPre(stack);
} }
@SubscribeEvent @SubscribeEvent
@ -54,40 +49,5 @@ public class ReloadEventHandler {
instance.perk().postReload(data, instance, player); instance.perk().postReload(data, instance, player);
} }
} }
handleDesperadoPost(stack);
}
private static void handleKillingTallyPre(ItemStack stack) {
var data = GunData.from(stack);
final var tag = data.tag();
int level = data.perk.getLevel(ModPerks.KILLING_TALLY);
if (level == 0) return;
GunsTool.setPerkIntTag(tag, "KillingTally", 0);
data.save();
}
private static void handleDesperadoPre(ItemStack stack) {
var data = GunData.from(stack);
final var tag = data.tag();
int time = GunsTool.getPerkIntTag(tag, "DesperadoTime");
if (time > 0) {
GunsTool.setPerkIntTag(tag, "DesperadoTime", 0);
GunsTool.setPerkBooleanTag(tag, "Desperado", true);
} else {
GunsTool.setPerkBooleanTag(tag, "Desperado", false);
}
data.save();
}
private static void handleDesperadoPost(ItemStack stack) {
var data = GunData.from(stack);
final var tag = data.tag();
if (!GunsTool.getPerkBooleanTag(tag, "Desperado")) return;
int level = data.perk.getLevel(ModPerks.DESPERADO);
GunsTool.setPerkIntTag(tag, "DesperadoTimePost", 110 + level * 10);
data.save();
} }
} }

View file

@ -3,10 +3,7 @@ package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.damage.GutshotStraight; import com.atsuishio.superbwarfare.perk.damage.*;
import com.atsuishio.superbwarfare.perk.damage.HeadSeeker;
import com.atsuishio.superbwarfare.perk.damage.KillClip;
import com.atsuishio.superbwarfare.perk.damage.VorpalWeapon;
import com.atsuishio.superbwarfare.perk.functional.HealClip; import com.atsuishio.superbwarfare.perk.functional.HealClip;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
@ -73,11 +70,11 @@ public class ModPerks {
public static final DeferredHolder<Perk, Perk> KILL_CLIP = DAMAGE_PERKS.register("kill_clip", KillClip::new); public static final DeferredHolder<Perk, Perk> KILL_CLIP = DAMAGE_PERKS.register("kill_clip", KillClip::new);
public static final DeferredHolder<Perk, Perk> GUTSHOT_STRAIGHT = DAMAGE_PERKS.register("gutshot_straight", GutshotStraight::new); public static final DeferredHolder<Perk, Perk> GUTSHOT_STRAIGHT = DAMAGE_PERKS.register("gutshot_straight", GutshotStraight::new);
public static final DeferredHolder<Perk, Perk> KILLING_TALLY = DAMAGE_PERKS.register("killing_tally", () -> new Perk("killing_tally", Perk.Type.DAMAGE)); public static final DeferredHolder<Perk, Perk> KILLING_TALLY = DAMAGE_PERKS.register("killing_tally", KillingTally::new);
public static final DeferredHolder<Perk, Perk> HEAD_SEEKER = DAMAGE_PERKS.register("head_seeker", HeadSeeker::new); public static final DeferredHolder<Perk, Perk> HEAD_SEEKER = DAMAGE_PERKS.register("head_seeker", HeadSeeker::new);
public static final DeferredHolder<Perk, Perk> MONSTER_HUNTER = DAMAGE_PERKS.register("monster_hunter", () -> new Perk("monster_hunter", Perk.Type.DAMAGE)); public static final DeferredHolder<Perk, Perk> MONSTER_HUNTER = DAMAGE_PERKS.register("monster_hunter", () -> new Perk("monster_hunter", Perk.Type.DAMAGE));
public static final DeferredHolder<Perk, Perk> VOLT_OVERLOAD = DAMAGE_PERKS.register("volt_overload", () -> new Perk("volt_overload", Perk.Type.DAMAGE)); public static final DeferredHolder<Perk, Perk> VOLT_OVERLOAD = DAMAGE_PERKS.register("volt_overload", () -> new Perk("volt_overload", Perk.Type.DAMAGE));
public static final DeferredHolder<Perk, Perk> DESPERADO = DAMAGE_PERKS.register("desperado", () -> new Perk("desperado", Perk.Type.DAMAGE)); public static final DeferredHolder<Perk, Perk> DESPERADO = DAMAGE_PERKS.register("desperado", Desperado::new);
public static final DeferredHolder<Perk, Perk> VORPAL_WEAPON = DAMAGE_PERKS.register("vorpal_weapon", VorpalWeapon::new); public static final DeferredHolder<Perk, Perk> VORPAL_WEAPON = DAMAGE_PERKS.register("vorpal_weapon", VorpalWeapon::new);
// public static void registerCompatPerks() { // public static void registerCompatPerks() {

View file

@ -51,6 +51,9 @@ public class Perk {
return result.get(); return result.get();
} }
/**
* 在背包中每Tick触发
*/
public void tick(GunData data, PerkInstance instance, @Nullable LivingEntity living) { public void tick(GunData data, PerkInstance instance, @Nullable LivingEntity living) {
} }
@ -70,6 +73,16 @@ public class Perk {
return damage; return damage;
} }
public int getModifiedRPM(int rpm, GunData data, PerkInstance instance) {
return rpm;
}
/**
* 在切换物品时触发
*/
public void onChangeSlot(GunData data, PerkInstance instance, @Nullable LivingEntity living) {
}
public enum Type { public enum Type {
AMMO("Ammo", ChatFormatting.YELLOW), AMMO("Ammo", ChatFormatting.YELLOW),
FUNCTIONAL("Functional", ChatFormatting.GREEN), FUNCTIONAL("Functional", ChatFormatting.GREEN),

View file

@ -0,0 +1,50 @@
package com.atsuishio.superbwarfare.perk.damage;
import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkInstance;
import com.atsuishio.superbwarfare.tools.DamageTypeTool;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.Nullable;
public class Desperado extends Perk {
public Desperado() {
super("desperado", Perk.Type.DAMAGE);
}
@Override
public int getModifiedRPM(int rpm, GunData data, PerkInstance instance) {
if (data.perk.getTag(this).getInt("DesperadoTimePost") > 0) {
return rpm * (int) (1.285 + 0.015 * instance.level());
}
return super.getModifiedRPM(rpm, data, instance);
}
@Override
public void onKill(GunData data, PerkInstance instance, LivingEntity target, DamageSource source) {
if (DamageTypeTool.isHeadshotDamage(source)) {
data.perk.getTag(this).putInt("DesperadoTime", 90 + instance.level() * 10);
}
}
@Override
public void preReload(GunData data, PerkInstance instance, @Nullable LivingEntity living) {
int time = data.perk.getTag(this).getInt("DesperadoTime");
if (time > 0) {
data.perk.getTag(this).remove("DesperadoTime");
data.perk.getTag(this).putBoolean("Desperado", true);
} else {
data.perk.getTag(this).remove("Desperado");
}
}
@Override
public void postReload(GunData data, PerkInstance instance, @Nullable LivingEntity living) {
if (!data.perk.getTag(this).getBoolean("Desperado")) {
return;
}
data.perk.getTag(this).putInt("DesperadoTimePost", 110 + instance.level() * 10);
}
}

View file

@ -0,0 +1,41 @@
package com.atsuishio.superbwarfare.perk.damage;
import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkInstance;
import com.atsuishio.superbwarfare.tools.DamageTypeTool;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.Nullable;
public class KillingTally extends Perk {
public KillingTally() {
super("killing_tally", Perk.Type.DAMAGE);
}
@Override
public void preReload(GunData data, PerkInstance instance, @Nullable LivingEntity living) {
data.perk.getTag(this).remove("KillingTally");
}
@Override
public void onKill(GunData data, PerkInstance instance, LivingEntity target, DamageSource source) {
if (DamageTypeTool.isGunDamage(source)) {
data.perk.getTag(this).putInt("KillingTally", Math.min(3, data.perk.getTag(this).getInt("KillingTally") + 1));
}
}
@Override
public float getModifiedDamage(float damage, GunData data, PerkInstance instance, @Nullable LivingEntity target, DamageSource source) {
if (DamageTypeTool.isGunDamage(source)) {
return damage * (1.0f + (0.1f * instance.level()) * data.perk.getTag(this).getInt("KillingTally"));
}
return super.getModifiedDamage(damage, data, instance, target, source);
}
@Override
public void onChangeSlot(GunData data, PerkInstance instance, @Nullable LivingEntity living) {
data.perk.getTag(this).remove("KillingTally");
}
}