Skip to content

Commit

Permalink
Finish Demolish
Browse files Browse the repository at this point in the history
  • Loading branch information
s5bug committed Aug 14, 2024
1 parent 6fa65f5 commit 5f7dc58
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 21 deletions.
17 changes: 17 additions & 0 deletions src/main/java/tf/bug/alymod/damage/DemolishDamage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tf.bug.alymod.damage;

import net.minecraft.entity.damage.DamageType;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import tf.bug.alymod.Alymod;

public class DemolishDamage {

public static Identifier ID =
Identifier.of(Alymod.ID, "demolish");

public static RegistryKey<DamageType> KEY =
RegistryKey.of(RegistryKeys.DAMAGE_TYPE, DemolishDamage.ID);

}
35 changes: 33 additions & 2 deletions src/main/java/tf/bug/alymod/effect/MonkStatusEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.*;
Expand All @@ -19,7 +20,10 @@
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import net.minecraft.util.Uuids;
import net.minecraft.util.math.random.Random;
import tf.bug.alymod.Alymod;
import tf.bug.alymod.damage.DemolishDamage;
import tf.bug.alymod.item.MonkSoul;
import tf.bug.alymod.monk.DemolishSnapshot;
import tf.bug.alymod.monk.ExtendedStatusEffectInstance;
import tf.bug.alymod.monk.ExtendedStatusEffectType;
Expand Down Expand Up @@ -183,7 +187,8 @@ private static boolean updateMeditativeBrotherhood(

public static final ExtendedStatusEffectType<Map<UUID, DemolishSnapshot>> DEMOLISH_EXTENSION =
new ExtendedStatusEffectType<>(
Codec.unboundedMap(Uuids.CODEC, DemolishSnapshot.CODEC),
// new HashMap so that it's mutable
Codec.unboundedMap(Uuids.CODEC, DemolishSnapshot.CODEC).xmap(HashMap::new, Function.identity()),
PacketCodecs.map(HashMap::new, Uuids.PACKET_CODEC, DemolishSnapshot.PACKET_CODEC),
MonkStatusEffects::mergeDemolishSnapshots,
MonkStatusEffects::updateDemolishSnapshots
Expand Down Expand Up @@ -222,11 +227,37 @@ public boolean canApplyUpdateEffect(int duration, int amplifier) {

@Override
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
if(this == DEMOLISH) {
if(this == DEMOLISH && !entity.getEntityWorld().isClient) {
ExtendedStatusEffectInstance<Map<UUID, DemolishSnapshot>> thisx =
new ExtendedStatusEffectInstance<>(entity.getStatusEffect(this.reference()));
long tickTime = entity.getEntityWorld().getTime();
// 60 ticks in 3 seconds
boolean shouldDotTick = (tickTime % 60L) == 0;

if(shouldDotTick) {
Random r = entity.getRandom();

int totalDamage = 0;
for(DemolishSnapshot snapshot : thisx.getExtension().values()) {
double variance = 0.95d + (0.1d * r.nextDouble());
int d3 = (int) Math.floor(snapshot.d2() * variance);

boolean criticalHit = r.nextDouble() < snapshot.critChance();
boolean directHit = r.nextDouble() < snapshot.dhitChance();

double critBuff = criticalHit ? snapshot.critMul() : 1.0;
double dhBuff = directHit ? 1.25 : 1.0;

int d4 = (int) Math.floor(d3 * critBuff * dhBuff * snapshot.buffSnapshot());
totalDamage += d4;
}

if(totalDamage > 0) entity.damage(
entity.getEntityWorld().getDamageSources().create(DemolishDamage.KEY),
totalDamage / MonkSoul.DAMAGE_SCALING
);
}

return true;
} else {
return super.applyUpdateEffect(entity, amplifier);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tf/bug/alymod/item/MonkSoul.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import tf.bug.alymod.monk.StatusHelpers;

public class MonkSoul extends Item {

public static final float DAMAGE_SCALING = 100.0F;

private MonkSoul(Settings settings) {
super(settings);
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/tf/bug/alymod/monk/ActionTimeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.function.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
Expand All @@ -18,6 +15,7 @@
import org.jetbrains.annotations.Nullable;
import tf.bug.alymod.damage.StrikingDamage;
import tf.bug.alymod.effect.MonkStatusEffects;
import tf.bug.alymod.item.MonkSoul;

public interface ActionTimeline<T extends Entity, S> {

Expand Down Expand Up @@ -90,7 +88,7 @@ public static final record FlatDamage(ToIntBiFunction<ServerPlayerEntity, Entity
Duration applicationDelay,
BiPredicate<ServerPlayerEntity, Entity> guaranteedCrit,
BiPredicate<ServerPlayerEntity, Entity> guaranteedDhit,
BiFunction<ServerPlayerEntity, Entity, @Nullable Supplier<StatusEffectInstance>> debuff) implements ActionTimeline<Entity, FlatDamage.State> {
BiFunction<ServerPlayerEntity, LivingEntity, @Nullable Supplier<StatusEffectInstance>> debuff) implements ActionTimeline<Entity, FlatDamage.State> {
public FlatDamage(ToIntBiFunction<ServerPlayerEntity, Entity> potency, Duration applicationDelay) {
this(potency, applicationDelay, (p, e) -> false);
}
Expand All @@ -110,6 +108,7 @@ public static final class State {
public boolean givenChakra = false;
public final Object2IntMap<Entity> damage = new Object2IntOpenHashMap<>();
public final Set<Entity> crits = new HashSet<>();
public final Map<Entity, Supplier<StatusEffectInstance>> debuffs = new HashMap<>();
}

@Override
Expand All @@ -131,6 +130,12 @@ public void snapshot(ServerPlayerEntity player, MonkStats stats, Entity target,

state.damage.put(target, damage);
if(crit) state.crits.add(target);

if(this.debuff != null && target instanceof LivingEntity le) {
final Supplier<StatusEffectInstance> statusSupplier =
this.debuff.apply(player, le);
if (statusSupplier != null) state.debuffs.put(target, statusSupplier);
}
}

@Override
Expand All @@ -144,8 +149,13 @@ public void apply(ServerPlayerEntity player, Entity target, State state) {
int damage = state.damage.getInt(target);
target.damage(
player.getServerWorld().getDamageSources().create(StrikingDamage.KEY, player),
damage / 50.0F
damage / MonkSoul.DAMAGE_SCALING
);

Supplier<StatusEffectInstance> statusSupplier = state.debuffs.get(target);
if(statusSupplier != null && target instanceof LivingEntity le) {
le.addStatusEffect(statusSupplier.get(), player);
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/tf/bug/alymod/monk/MonkAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ public enum MonkAction {
Duration.ofMillis(1600L),
(p, e) -> false,
(p, e) -> false,
(p, e) -> () -> new StatusEffectInstance(
MonkStatusEffects.DEMOLISH.reference(),
18 * 20
)
(p, e) -> StatusHelpers.supplyDemolish(p, e, MonkStats.Lv70.INSTANCE)
).withCast((player, state) -> {
if(!state.damage.isEmpty()) {
StatusHelpers.giveOpoOpoForm(player);
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/tf/bug/alymod/monk/SoundEffectStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ public static final record Effect(
@Override
public void clientOnSnapshotSelf(ClientPlayerEntity cpe) {
if(this.castVolume <= 0.0f) return;
cpe.playSound(
cpe.clientWorld.playSoundFromEntity(
cpe,
cpe,
this.castEvent,
SoundCategory.PLAYERS,
this.castVolume,
1.0f
);
Expand All @@ -41,11 +44,9 @@ public void clientOnSnapshotSelf(ClientPlayerEntity cpe) {
@Override
public void clientOnSnapshotTarget(ClientPlayerEntity cpe, Entity target) {
if(this.targetVolume <= 0.0f) return;
cpe.clientWorld.playSound(
cpe.clientWorld.playSoundFromEntity(
cpe,
target.getX(),
target.getY(),
target.getZ(),
target,
this.targetEvent,
SoundCategory.PLAYERS,
this.targetVolume,
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/tf/bug/alymod/monk/StatusHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -170,6 +174,37 @@ public static void giveTwinSnakes(PlayerEntity pe) {
), pe);
}

public static Supplier<StatusEffectInstance> supplyDemolish(
PlayerEntity source,
LivingEntity target,
MonkStats stats
) {
// 50 potency DoT
final int d1 = (int) Math.floor(50 * stats.getMultiplierAttackPower() * stats.getMultiplierDetermination());
final int d2 = 1 + (int) Math.floor((d1 * stats.getMultiplierSkillSpeed() * stats.getMultiplierWeaponDamage()) / 100.0d);

final DemolishSnapshot snapshot = new DemolishSnapshot(
18 * 20,
d2,
ActionTimeline.getBuffDamageBonus(source) * ActionTimeline.getDebuffDamageBonus(target),
stats.getProbabilityCriticalHit(),
stats.getMultiplierCrit(),
stats.getProbabilityDirectHit()
);

return () -> {
StatusEffectInstance base = new StatusEffectInstance(
MonkStatusEffects.DEMOLISH.reference(),
18 * 20
);
ExtendedStatusEffectInstance<Map<UUID, DemolishSnapshot>> extended =
new ExtendedStatusEffectInstance<>(base);
extended.setExtension(new HashMap<>());
extended.getExtension().put(source.getUuid(), snapshot);
return base;
};
}

public static boolean hasRiddleOfWind(PlayerEntity pe) {
return pe.hasStatusEffect(MonkStatusEffects.RIDDLE_OF_WIND.reference());
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/data/alymod/damage_type/demolish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0.1,
"message_id": "demolish",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"replace": false,
"values": [
"alymod:burst_into_light"
"alymod:burst_into_light",
"alymod:demolish"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"replace": false,
"values": [
"alymod:striking"
"alymod:striking",
"alymod:demolish"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"replace": false,
"values": [
"alymod:burst_into_light"
"alymod:burst_into_light",
"alymod:demolish"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"replace": false,
"values": [
"alymod:burst_into_light"
"alymod:burst_into_light",
"alymod:demolish"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"alymod:demolish"
]
}

0 comments on commit 5f7dc58

Please sign in to comment.