Skip to content

Commit

Permalink
Who's a good ward-- NO, I'M NOT TALKIN' TO YOU
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarWitch7 committed Jul 6, 2024
1 parent ff1c986 commit 1090939
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 34 deletions.
9 changes: 6 additions & 3 deletions src/main/java/dev/enjarai/trickster/cca/WardComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.List;

public class WardComponent implements Component {
private static final KeyedEndec<SpellPart> SPELL = SpellPart.ENDEC.keyed("handler", () -> null);
private static final KeyedEndec<SpellPart> SPELL = SpellPart.ENDEC.keyed("ward_handler", () -> null);

private final PlayerEntity player;
@Nullable
Expand All @@ -35,11 +35,14 @@ public WardComponent(PlayerEntity player) {
public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
if (spell != null)
tag.put(SPELL, spell);
else
tag.putBoolean("is_null", true);
}

@Override
public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
spell = tag.get(SPELL);
if (!tag.contains("is_null") || !tag.getBoolean("is_null"))
spell = tag.get(SPELL);
}

public void register(SpellPart spell) {
Expand All @@ -56,7 +59,7 @@ public List<Fragment> run(SpellContext triggerCtx, Trick source, List<Fragment>
boolean applyBacklashIfModified = true;

try {
var ctx = new PlayerSpellContext((ServerPlayerEntity)this.player, EquipmentSlot.MAINHAND);
var ctx = new PlayerSpellContext(triggerCtx.getRecursions(), (ServerPlayerEntity)this.player, EquipmentSlot.MAINHAND);
ctx.pushPartGlyph(List.of(new PatternGlyph(source.getPattern()), new ListFragment(inputs)));

var result = spell.run(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
var spell = stack.get(ModComponents.SPELL);
if (spell != null) {
var singleUseManaPool = SimpleManaPool.getSingleUse(meta.mana());
spell.spell().runSafely(new PlayerSpellContext((ServerPlayerEntity) user, singleUseManaPool, slot));
spell.spell().runSafely(new PlayerSpellContext(singleUseManaPool, (ServerPlayerEntity) user, slot));
((ServerPlayerEntity) user).getServerWorld().playSoundFromEntity(
null, user, ModSounds.CAST, SoundCategory.PLAYERS, 1f, ModSounds.randomPitch(0.8f, 0.2f));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BlockSpellContext extends SpellContext {
public final SpellCircleBlockEntity blockEntity;

public BlockSpellContext(ServerWorld world, BlockPos pos, SpellCircleBlockEntity blockEntity) {
super(blockEntity.manaPool);
super(blockEntity.manaPool, 0);
this.world = world;
this.pos = pos;
this.blockEntity = blockEntity;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/dev/enjarai/trickster/spell/ManaPool.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package dev.enjarai.trickster.spell;

public interface ManaPool {
float FACTOR = 25;

static float healthFromMana(float mana) {
return mana / FACTOR;
return mana / 2;
}

static float manaFromHealth(float health) {
return health * FACTOR;
return health * 12;
}

void set(float value);
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/dev/enjarai/trickster/spell/PlayerSpellContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ public class PlayerSpellContext extends SpellContext {
private final EquipmentSlot slot;

public PlayerSpellContext(ServerPlayerEntity player, EquipmentSlot slot) {
this(player, ModEntityCumponents.MANA.get(player), slot);
this(0, player, slot);
}

public PlayerSpellContext(ServerPlayerEntity player, ManaPool manaPool, EquipmentSlot slot) {
super(manaPool);
public PlayerSpellContext(int recursions, ServerPlayerEntity player, EquipmentSlot slot) {
this(ModEntityCumponents.MANA.get(player), recursions, player, slot);
}

public PlayerSpellContext(ManaPool manaPool, ServerPlayerEntity player, EquipmentSlot slot) {
this(manaPool, 0, player, slot);
}

public PlayerSpellContext(ManaPool manaPool, int recursions, ServerPlayerEntity player, EquipmentSlot slot) {
super(manaPool, recursions);
this.player = player;
this.slot = slot;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/dev/enjarai/trickster/spell/SpellContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public abstract class SpellContext {
protected final ManaPool manaPool;
protected final List<ManaLink> manaLinks = new ArrayList<>();

protected SpellContext(ManaPool manaPool) {
protected SpellContext(ManaPool manaPool, int recursions) {
this.manaPool = manaPool;
this.recursions = recursions;
}

public void pushPartGlyph(List<Fragment> fragments) throws BlunderException {
Expand Down Expand Up @@ -96,6 +97,10 @@ public void addManaLink(Trick source, ManaLink link) throws BlunderException {
manaLinks.add(link);
}

public int getRecursions() {
return recursions;
}

public Optional<ServerPlayerEntity> getPlayer() {
return Optional.empty();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/enjarai/trickster/spell/tricks/Trick.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.enjarai.trickster.spell.fragment.EntityFragment;
import dev.enjarai.trickster.spell.fragment.FragmentType;
import dev.enjarai.trickster.spell.tricks.blunder.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
Expand Down Expand Up @@ -97,13 +98,12 @@ protected void expectCanBuild(SpellContext ctx, BlockPos... positions) {
}
}

protected List<Fragment> tryWard(SpellContext ctx, EntityFragment target, List<Fragment> fragments) throws BlunderException {
var entity = target.getEntity(ctx);

if (entity.isPresent() && entity.get() instanceof PlayerEntity player) {
protected List<Fragment> tryWard(SpellContext ctx, Entity target, List<Fragment> fragments) throws BlunderException {
if (target instanceof PlayerEntity player) {
return ModEntityCumponents.WARD.get(player)
.run(ctx, this, fragments);
}

return fragments;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws Blun
var entity = expectInput(fragments, FragmentType.ENTITY, 0);
var target = entity.getEntity(ctx).orElseThrow(() -> new UnknownEntityBlunder(this));

fragments = tryWard(ctx, entity, fragments);
fragments = tryWard(ctx, target, fragments);

var velocity = expectInput(fragments, FragmentType.VECTOR, 1);
ctx.useMana(this, (float)velocity.vector().length() * 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws Blun
return BooleanFragment.TRUE;
}
}

return BooleanFragment.FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ public LeechEntityManaTrick() {

@Override
public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws BlunderException {
var entity = expectInput(fragments, FragmentType.ENTITY, 0).getEntity(ctx);
var limit = expectInput(fragments, FragmentType.NUMBER, 1).number();
var entity = expectInput(fragments, FragmentType.ENTITY, 0);
var target = entity.getEntity(ctx).orElseThrow(() -> new UnknownEntityBlunder(this));

if (entity.isPresent()) {
var entity2 = entity.get();
fragments = tryWard(ctx, target, fragments);

if (entity2 instanceof LivingEntity living) {
ctx.addManaLink(this, new ManaLink(ModEntityCumponents.MANA.get(living), (float)limit));
return VoidFragment.INSTANCE;
}
var limit = expectInput(fragments, FragmentType.NUMBER, 1).number();

throw new EntityInvalidBlunder(this);
if (target instanceof LivingEntity living) {
ctx.addManaLink(this, new ManaLink(ModEntityCumponents.MANA.get(living), (float)limit));
return VoidFragment.INSTANCE;
}

throw new UnknownEntityBlunder(this);
throw new EntityInvalidBlunder(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ public PolymorphTrick() {

@Override
public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws BlunderException {
var target = expectInput(fragments, FragmentType.ENTITY, 0);
var source = expectInput(fragments, FragmentType.ENTITY, 1);
var realSource = source.getEntity(ctx).orElseThrow(() -> new UnknownEntityBlunder(this));

fragments = tryWard(ctx, realSource, fragments);

var target = expectInput(fragments, FragmentType.ENTITY, 0);
var realTarget = target.getEntity(ctx).orElseThrow(() -> new UnknownEntityBlunder(this));
var realSource = source.getEntity(ctx).orElseThrow(() -> new UnknownEntityBlunder(this));

if (realTarget instanceof ServerPlayerEntity targetPlayer && realSource instanceof ServerPlayerEntity sourcePlayer) {
ctx.useMana(this, 480);

var cumpoonent = targetPlayer.getComponent(ModEntityCumponents.DISGUISE);

var uuid = sourcePlayer.getUuid();
var sourceCumponent = sourcePlayer.getComponent(ModEntityCumponents.DISGUISE);
var uuid = sourcePlayer.getUuid();

if (sourceCumponent.getUuid() != null) {
uuid = sourceCumponent.getUuid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
```

Mana is what fuels your ploys. It's the cost of manipulating the world.
Mana is what fuels your ploys. It's the cost of manipulating the world.


As is tradition, amounts of mana are measured in gandalfs, or G.
Expand Down Expand Up @@ -45,7 +45,7 @@ When there are mana sources linked to your spell, they will be prioritised when
Mana links with greater limits provide a greater ratio of mana so that all sources are drawn from equally.
Mana links are lossy, with a tax of 70% incurred on the mana source.
The limit on mana links is the amount of mana drained post-tax.
The amount of mana actually provided to your spell is mana link limit divided by 1.7.
The amount of mana actually provided to your spell is the mana link's limit divided by 1.7.

;;;;;

Expand Down

0 comments on commit 1090939

Please sign in to comment.