Add radiant totem spell

This commit is contained in:
Electroblob77
2020-06-26 17:46:47 +01:00
parent 1ea6355a9e
commit 080022127c
29 changed files with 351 additions and 56 deletions
@@ -241,23 +241,12 @@ public class EntityHammer extends EntityMagicConstruct {
public void writeSpawnData(ByteBuf data){
super.writeSpawnData(data);
data.writeBoolean(spin);
if(getCaster() != null) data.writeInt(getCaster().getEntityId());
}
@Override
public void readSpawnData(ByteBuf data){
super.readSpawnData(data);
spin = data.readBoolean();
if(!data.isReadable()) return;
Entity entity = world.getEntityByID(data.readInt());
if(entity instanceof EntityLivingBase){
setCaster((EntityLivingBase)entity);
}else{
Wizardry.logger.warn("Lightning hammer caster with ID in spawn data not found");
}
}
@Override
@@ -35,7 +35,7 @@ import java.util.UUID;
*/
public abstract class EntityMagicConstruct extends Entity implements IEntityOwnable, IEntityAdditionalSpawnData {
/** The UUID of the caster. As of Wizardry 4.2, this <b>is</b> synced, and rather than storing the caster
/** The UUID of the caster. As of Wizardry 4.3, this <b>is</b> synced, and rather than storing the caster
* instance via a weak reference, it is fetched from the UUID each time it is needed in
* {@link EntityMagicConstruct#getCaster()}. */
private UUID casterUUID;
@@ -120,11 +120,26 @@ public abstract class EntityMagicConstruct extends Entity implements IEntityOwna
@Override
public void writeSpawnData(ByteBuf data){
data.writeInt(lifetime);
data.writeInt(getCaster() == null ? -1 : getCaster().getEntityId());
}
@Override
public void readSpawnData(ByteBuf data){
lifetime = data.readInt();
int id = data.readInt();
if(id == -1){
setCaster(null);
}else{
Entity entity = world.getEntityByID(id);
if(entity instanceof EntityLivingBase){
setCaster((EntityLivingBase)entity);
}else{
Wizardry.logger.warn("Construct caster with ID in spawn data not found");
}
}
}
@Nullable
@@ -0,0 +1,130 @@
package electroblob.wizardry.entity.construct;
import electroblob.wizardry.constants.Constants;
import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.spell.RadiantTotem;
import electroblob.wizardry.spell.Spell;
import electroblob.wizardry.util.*;
import electroblob.wizardry.util.BlockUtils.SurfaceCriteria;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.ParticleBuilder.Type;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class EntityRadiantTotem extends EntityMagicConstruct {
private static final int PERIMETER_PARTICLE_DENSITY = 6;
public EntityRadiantTotem(World world){
super(world);
this.setSize(1, 1);
}
@Override
public void onUpdate(){
if(this.ticksExisted % 25 == 1){
// TODO: Sound
}
super.onUpdate();
double radius = Spells.radiant_totem.getProperty(Spell.EFFECT_RADIUS).floatValue(); // TODO: Blast modifiers
if(world.isRemote){
ParticleBuilder.create(Type.DUST, rand, posX, posY + 0.2, posZ, 0.3, false)
.vel(0, -0.02 - world.rand.nextFloat() * 0.01, 0).clr(0xffffff).fade(0xffec90).spawn(world);
for(int i=0; i<PERIMETER_PARTICLE_DENSITY; i++){
float angle = ((float)Math.PI * 2)/PERIMETER_PARTICLE_DENSITY * (i + rand.nextFloat());
double x = posX + radius * MathHelper.sin(angle);
double z = posZ + radius * MathHelper.cos(angle);
Integer y = BlockUtils.getNearestSurface(world, new BlockPos(x, posY, z), EnumFacing.UP, 5, true, SurfaceCriteria.COLLIDABLE);
if(y != null){
ParticleBuilder.create(Type.DUST).pos(x, y, z).vel(0, 0.01, 0).clr(0xffffff).fade(0xffec90).spawn(world);
}
}
}
List<EntityLivingBase> nearby = EntityUtils.getLivingWithinRadius(radius, posX, posY, posZ, world);
nearby.sort(Comparator.comparingDouble(e -> e.getDistanceSq(this)));
List<EntityLivingBase> nearbyAllies = nearby.stream().filter(e -> e == getCaster()
|| AllyDesignationSystem.isAllied(getCaster(), e)).collect(Collectors.toList());
nearby.removeAll(nearbyAllies);
int targetsRemaining = Spells.radiant_totem.getProperty(RadiantTotem.MAX_TARGETS).intValue()
+ (int)((damageMultiplier - 1) / Constants.POTENCY_INCREASE_PER_TIER);
while(!nearbyAllies.isEmpty() && targetsRemaining > 0){
EntityLivingBase ally = nearbyAllies.remove(0);
if(ally.getHealth() < ally.getMaxHealth()){
// Slightly slower than healing aura, and it only does 1 at a time (without potency modifiers)
if(ally.ticksExisted % 8 == 0) ally.heal(Spells.radiant_totem.getProperty(Spell.HEALTH).floatValue());
targetsRemaining--;
if(world.isRemote){
ParticleBuilder.create(Type.BEAM).pos(this.getPositionVector()).target(ally)
.clr(1, 0.6f + 0.3f * world.rand.nextFloat(), 0.2f).spawn(world);
}
}
}
while(!nearby.isEmpty() && targetsRemaining > 0){
EntityLivingBase target = nearby.remove(0);
if(EntityUtils.isLiving(target)){
if(target.ticksExisted % target.maxHurtResistantTime == 1){
float damage = Spells.radiant_totem.getProperty(Spell.DAMAGE).floatValue();
if(target.isEntityUndead()){
target.setFire(Spells.radiant_totem.getProperty(Spell.BURN_DURATION).intValue());
// damage *= getProperty(UNDEAD_DAMAGE_MULTIPLIER).floatValue();
}
EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeIndirectMagicDamage(this,
getCaster(), DamageType.RADIANT), damage);
}
targetsRemaining--;
if(world.isRemote){
ParticleBuilder.create(Type.BEAM).pos(this.getPositionVector().add(0, height/2, 0))
.target(target).clr(1, 0.6f + 0.3f * world.rand.nextFloat(), 0.2f).spawn(world);
}
}
}
}
// Usually damage multipliers don't need syncing, but here we're using it for the non-standard purpose of targeting
@Override
public void writeSpawnData(ByteBuf data){
super.writeSpawnData(data);
data.writeFloat(damageMultiplier);
}
@Override
public void readSpawnData(ByteBuf data){
super.readSpawnData(data);
damageMultiplier = data.readFloat();
}
}
@@ -95,28 +95,4 @@ public class EntityStormcloud extends EntityMagicConstruct {
}
// Need to sync the caster so they don't have particles spawned at them
@Override
public void writeSpawnData(ByteBuf data){
super.writeSpawnData(data);
if(getCaster() != null) data.writeInt(getCaster().getEntityId());
}
@Override
public void readSpawnData(ByteBuf data){
super.readSpawnData(data);
if(!data.isReadable()) return;
Entity entity = world.getEntityByID(data.readInt());
if(entity instanceof EntityLivingBase){
setCaster((EntityLivingBase)entity);
}else{
Wizardry.logger.warn("Stormcloud caster with ID in spawn data not found");
}
}
}