2020-09-25 20:24:48 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.AwaitTickQueue;
|
|
|
|
import com.minelittlepony.unicopia.EquinePredicates;
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
|
|
|
import com.minelittlepony.unicopia.USounds;
|
|
|
|
import com.minelittlepony.unicopia.ability.data.Hit;
|
2021-11-05 14:18:32 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
2021-08-19 14:43:15 +02:00
|
|
|
import com.minelittlepony.unicopia.advancement.UCriteria;
|
2023-04-30 13:58:39 +02:00
|
|
|
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
|
2022-09-26 21:11:28 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.Living;
|
2023-06-02 21:20:30 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
2020-09-25 20:24:48 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2023-04-30 13:58:39 +02:00
|
|
|
import com.minelittlepony.unicopia.util.VecHelper;
|
2020-09-25 20:24:48 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
2023-04-30 13:58:39 +02:00
|
|
|
import net.minecraft.particle.ParticleTypes;
|
2020-09-25 20:24:48 +02:00
|
|
|
import net.minecraft.sound.SoundCategory;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
2022-06-25 00:19:55 +02:00
|
|
|
import net.minecraft.util.math.random.Random;
|
2020-09-25 20:24:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A magic casting ability for unicorns.
|
|
|
|
* (only shields for now)
|
|
|
|
*/
|
|
|
|
public class BatEeeeAbility implements Ability<Hit> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWarmupTime(Pony player) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCooldownTime(Pony player) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:05:12 +02:00
|
|
|
@Override
|
|
|
|
public double getCostEstimate(Pony player) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-25 20:24:48 +02:00
|
|
|
@Override
|
|
|
|
public boolean canUse(Race race) {
|
|
|
|
return race == Race.BAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Hit tryActivate(Pony player) {
|
|
|
|
return Hit.INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Hit.Serializer<Hit> getSerializer() {
|
|
|
|
return Hit.SERIALIZER;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void apply(Pony player, Hit data) {
|
2022-12-19 18:13:15 +01:00
|
|
|
Random rng = player.asWorld().random;
|
2020-09-25 20:24:48 +02:00
|
|
|
int count = 1 + rng.nextInt(10);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2022-12-19 18:13:15 +01:00
|
|
|
player.asWorld().playSound(null, player.getOrigin(), USounds.ENTITY_PLAYER_BATPONY_SCREECH, SoundCategory.PLAYERS,
|
2020-09-25 20:24:48 +02:00
|
|
|
0.9F + (rng.nextFloat() - 0.5F) / 2F,
|
|
|
|
1.6F + (rng.nextFloat() - 0.5F)
|
|
|
|
);
|
|
|
|
}
|
2022-12-19 18:13:15 +01:00
|
|
|
AwaitTickQueue.scheduleTask(player.asWorld(), w -> {
|
2020-09-25 20:24:48 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2022-12-19 18:13:15 +01:00
|
|
|
player.asWorld().playSound(null, player.getOrigin(), USounds.ENTITY_PLAYER_BATPONY_SCREECH, SoundCategory.PLAYERS,
|
2020-09-25 20:24:48 +02:00
|
|
|
0.9F + (rng.nextFloat() - 0.5F) / 2F,
|
|
|
|
1.6F + (rng.nextFloat() - 0.5F)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, rng.nextInt(10));
|
|
|
|
|
2023-04-30 13:58:39 +02:00
|
|
|
if (!player.getPhysics().isFlying()) {
|
|
|
|
player.setAnimation(Animation.SPREAD_WINGS);
|
|
|
|
}
|
|
|
|
|
2020-09-25 20:24:48 +02:00
|
|
|
Vec3d origin = player.getOriginVector();
|
|
|
|
|
|
|
|
if (rng.nextInt(20000) == 0) {
|
2023-06-02 21:20:30 +02:00
|
|
|
player.asEntity().damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), 0.1F);
|
2022-12-19 16:03:35 +01:00
|
|
|
UCriteria.SCREECH_SELF.trigger(player.asEntity());
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
|
2021-08-19 14:43:15 +02:00
|
|
|
int total = player.findAllEntitiesInRange(5).mapToInt(e -> {
|
2022-09-26 21:11:28 +02:00
|
|
|
if (e instanceof LivingEntity living && !SpellType.SHIELD.isOn(e)) {
|
2020-09-25 20:24:48 +02:00
|
|
|
boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(e);
|
2023-06-02 21:20:30 +02:00
|
|
|
e.damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F);
|
2020-09-25 20:24:48 +02:00
|
|
|
|
|
|
|
Vec3d knockVec = origin.subtract(e.getPos());
|
2022-09-26 21:11:28 +02:00
|
|
|
living.takeKnockback(isEarthPony ? 0.3F : 0.5F, knockVec.getX(), knockVec.getZ());
|
2020-09-25 20:24:48 +02:00
|
|
|
if (!isEarthPony) {
|
|
|
|
e.addVelocity(0, 0.1, 0);
|
|
|
|
}
|
2022-09-26 21:11:28 +02:00
|
|
|
Living.updateVelocity(e);
|
2023-01-21 01:33:26 +01:00
|
|
|
return 1;
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
2023-01-21 01:33:26 +01:00
|
|
|
return 0;
|
2021-08-19 14:43:15 +02:00
|
|
|
}).sum();
|
|
|
|
|
|
|
|
if (total >= 20) {
|
2022-12-19 16:03:35 +01:00
|
|
|
UCriteria.SCREECH_TWENTY_MOBS.trigger(player.asEntity());
|
2021-08-19 14:43:15 +02:00
|
|
|
}
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void preApply(Pony player, AbilitySlot slot) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postApply(Pony player, AbilitySlot slot) {
|
2023-04-30 13:58:39 +02:00
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
player.addParticle(ParticleTypes.BUBBLE_POP, player.getPhysics().getHeadPosition().toCenterPos(), VecHelper.supply(() -> player.asWorld().getRandom().nextGaussian() - 0.5));
|
|
|
|
}
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
}
|