aether-legacy/src/main/java/com/gildedgames/the_aether/entities/bosses/EntityValkyrie.java

390 lines
11 KiB
Java
Raw Normal View History

2020-08-14 08:29:22 +02:00
package com.gildedgames.the_aether.entities.bosses;
2016-12-17 16:28:16 +01:00
2020-08-14 08:29:22 +02:00
import com.gildedgames.the_aether.Aether;
import com.gildedgames.the_aether.entities.hostile.EntityAetherMob;
import com.gildedgames.the_aether.items.ItemsAether;
2016-12-17 16:28:16 +01:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
2018-12-07 05:33:43 +01:00
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
2016-12-17 16:28:16 +01:00
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.player.EntityPlayer;
2017-08-10 20:51:38 +02:00
import net.minecraft.item.ItemStack;
2016-12-17 16:28:16 +01:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
2021-01-01 04:09:39 +01:00
import net.minecraft.util.StatCollector;
2016-12-17 16:28:16 +01:00
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
2018-12-07 05:33:43 +01:00
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
2018-12-07 06:32:48 +01:00
public class EntityValkyrie extends EntityAetherMob {
2016-12-17 16:28:16 +01:00
private int attackTime;
2018-12-07 06:32:48 +01:00
public int angerLevel;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public int timeLeft, chatTime;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public double safeX, safeY, safeZ;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public float sinage;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public double lastMotionY;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public int teleTimer;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public EntityValkyrie(World world) {
super(world);
setSize(0.8F, 1.6F);
this.teleTimer = this.rand.nextInt(250);
this.timeLeft = 1200;
this.safeX = this.posX;
this.safeY = this.posY;
this.safeZ = this.posZ;
this.tasks.addTask(2, new EntityAIWander(this, 0.5D));
this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 0.65D, true));
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
@Override
protected void applyEntityAttributes() {
2016-12-17 16:28:16 +01:00
super.applyEntityAttributes();
2018-12-07 05:33:43 +01:00
this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(8.0D);
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5);
this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10.0D);
2018-12-07 06:32:48 +01:00
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(50.0D);
}
public void swingArm() {
if (!this.isSwingInProgress) {
this.isSwingInProgress = true;
}
}
private void becomeAngryAt(EntityLivingBase entity) {
this.setAttackTarget(entity);
this.angerLevel = 200 + rand.nextInt(200);
2016-12-17 16:28:16 +01:00
}
2018-12-07 06:32:48 +01:00
private void chatItUp(EntityPlayer player, String s) {
2016-12-17 16:28:16 +01:00
Side side = FMLCommonHandler.instance().getEffectiveSide();
2018-12-07 06:32:48 +01:00
if (this.chatTime <= 0) {
if (side.isClient()) {
Aether.proxy.sendMessage(player, s);
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
this.chatTime = 60;
}
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
@Override
public boolean interact(EntityPlayer entityplayer) {
2018-12-07 05:33:43 +01:00
this.faceEntity(entityplayer, 180F, 180F);
ItemStack stack = entityplayer.getCurrentEquippedItem();
2017-08-10 20:51:38 +02:00
2018-12-07 06:32:48 +01:00
if (stack != null && stack.getItem() == ItemsAether.victory_medal && stack.stackSize >= 0) {
if (stack.stackSize >= 10) {
2021-01-01 04:09:39 +01:00
this.chatItUp(entityplayer, StatCollector.translateToLocal("gui.valkyrie.dialog.medal.1"));
2018-12-07 06:32:48 +01:00
} else if (stack.stackSize >= 5) {
2021-01-01 04:09:39 +01:00
this.chatItUp(entityplayer, StatCollector.translateToLocal("gui.valkyrie.dialog.medal.2"));
2018-12-07 06:32:48 +01:00
} else {
2021-01-01 04:09:39 +01:00
this.chatItUp(entityplayer, StatCollector.translateToLocal("gui.valkyrie.dialog.medal.3"));
2017-08-10 20:51:38 +02:00
}
2018-12-07 06:32:48 +01:00
} else {
2018-12-07 05:33:43 +01:00
int line = rand.nextInt(3);
2018-12-07 06:32:48 +01:00
if (line == 2) {
2021-01-01 04:09:39 +01:00
this.chatItUp(entityplayer, StatCollector.translateToLocal("gui.valkyrie.dialog.1"));
2018-12-07 06:32:48 +01:00
} else if (line == 1) {
2021-01-01 04:09:39 +01:00
this.chatItUp(entityplayer, StatCollector.translateToLocal("gui.valkyrie.dialog.2"));
2018-12-07 06:32:48 +01:00
} else {
2021-01-01 04:09:39 +01:00
this.chatItUp(entityplayer, StatCollector.translateToLocal("gui.valkyrie.dialog.3"));
2018-12-07 05:33:43 +01:00
}
2017-08-10 20:51:38 +02:00
}
return true;
2018-12-07 06:32:48 +01:00
}
public void teleport(double x, double y, double z, int rad) {
int a = this.rand.nextInt(rad + 1);
int b = this.rand.nextInt(rad / 2);
int c = rad - a;
a *= ((this.rand.nextInt(2) * 2) - 1);
b *= ((this.rand.nextInt(2) * 2) - 1);
c *= ((this.rand.nextInt(2) * 2) - 1);
x += (double) a;
y += (double) b;
z += (double) c;
int newX = (int) Math.floor(x - 0.5D);
int newY = (int) Math.floor(y - 0.5D);
int newZ = (int) Math.floor(z - 0.5D);
boolean flag = false;
for (int q = 0; q < 32 && !flag; q++) {
this.rand.nextInt(rad / 2);
this.rand.nextInt(rad / 2);
int j = newY + (this.rand.nextInt(rad / 2) - this.rand.nextInt(rad / 2));
this.rand.nextInt(rad / 2);
this.rand.nextInt(rad / 2);
if (j > 124 || j < 5) {
continue;
}
}
if (!flag) {
teleFail();
} else {
spawnExplosionParticle();
setPosition((double) newX + 0.5D, (double) newY + 0.5D, (double) newZ + 0.5D);
this.motionX = this.motionY = this.motionZ = 0.0D;
this.moveForward = this.moveStrafing = this.rotationPitch = this.rotationYaw = 0.0F;
this.isJumping = false;
this.renderYawOffset = this.rand.nextFloat() * 360F;
spawnExplosionParticle();
this.teleTimer = this.rand.nextInt(40);
}
}
public void teleFail() {
this.teleTimer -= (this.rand.nextInt(40) + 40);
if (this.posY <= 0D) {
this.teleTimer = 446;
}
}
@Override
public void onEntityUpdate() {
super.onEntityUpdate();
this.teleTimer++;
--this.attackTime;
if (this.teleTimer >= 450) {
if (this.getAttackTarget() != null) {
teleport(this.getAttackTarget().posX, this.getAttackTarget().posY, this.getAttackTarget().posZ, 7);
} else if (!this.onGround) {
teleport(this.safeX, this.safeY, this.safeZ, 6);
}
} else if (this.teleTimer < 446 && (this.posY <= 0D || this.posY <= (this.safeY - 16D))) {
this.teleTimer = 446;
} else if ((this.teleTimer % 5) == 0 && this.getAttackTarget() != null && !canEntityBeSeen(this.getAttackTarget())) {
this.teleTimer += 100;
}
if (this.onGround && this.teleTimer % 10 == 0) {
this.safeX = this.posX;
this.safeY = this.posY;
this.safeZ = this.posZ;
}
if (this.getAttackTarget() != null && this.getAttackTarget().isDead) {
this.setAttackTarget(null);
this.angerLevel = 0;
}
if (this.chatTime > 0) {
this.chatTime--;
}
}
@Override
public void onUpdate() {
this.lastMotionY = motionY;
super.onUpdate();
if (!this.onGround && this.getAttackTarget() != null && this.lastMotionY >= 0.0D && this.motionY < 0.0D && getDistanceToEntity(this.getAttackTarget()) <= 16F && canEntityBeSeen(this.getAttackTarget())) {
double a = this.getAttackTarget().posX - posX;
double b = this.getAttackTarget().posZ - posZ;
double angle = Math.atan2(a, b);
this.motionX = Math.sin(angle) * 0.25D;
this.motionZ = Math.cos(angle) * 0.25D;
}
if (!this.onGround && !isOnLadder() && Math.abs(this.motionY - this.lastMotionY) > 0.07D && Math.abs(this.motionY - this.lastMotionY) < 0.09D) {
this.motionY += 0.055F;
if (this.motionY < -0.275F) {
this.motionY = -0.275F;
}
}
if (this.worldObj.difficultySetting == EnumDifficulty.PEACEFUL && (this.getAttackTarget() != null || this.angerLevel > 0)) {
this.angerLevel = 0;
this.setAttackTarget(null);
}
if (!this.onGround) {
this.sinage += 0.75F;
} else {
this.sinage += 0.15F;
}
if (this.sinage > 3.141593F * 2F) {
this.sinage -= (3.141593F * 2F);
}
if (this.getAttackTarget() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) this.getAttackTarget();
if (this.getHealth() <= 0) {
int pokey = rand.nextInt(3);
if (pokey == 2) {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.defeated.1"));
2018-12-07 06:32:48 +01:00
} else if (pokey == 1) {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.defeated.2"));
2018-12-07 06:32:48 +01:00
} else {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.defeated.3"));
2018-12-07 06:32:48 +01:00
}
this.setDead();
}
if (player.getHealth() <= 0 && player.isDead) {
int pokey = rand.nextInt(3);
if (pokey == 2) {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.playerdead.1"));
2018-12-07 06:32:48 +01:00
} else if (pokey == 1) {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocalFormatted("gui.valkyrie.dialog.playerdead.2", player.getDisplayName()));
2018-12-07 06:32:48 +01:00
} else {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.playerdead.3"));
2018-12-07 06:32:48 +01:00
}
this.setAttackTarget(null);
this.angerLevel = this.chatTime = 0;
}
}
}
@Override
protected Entity findPlayerToAttack() {
return null;
}
@Override
public void writeEntityToNBT(NBTTagCompound compound) {
super.writeEntityToNBT(compound);
compound.setInteger("angerLevel", this.angerLevel);
compound.setInteger("teleTimer", this.teleTimer);
compound.setInteger("timeLeft", this.timeLeft);
compound.setDouble("safePosX", this.safeX);
compound.setDouble("safePosY", this.safeY);
compound.setDouble("safePosZ", this.safeZ);
}
@Override
public void readEntityFromNBT(NBTTagCompound compound) {
super.readEntityFromNBT(compound);
this.angerLevel = compound.getInteger("angerLevel");
this.teleTimer = compound.getInteger("teleTimer");
this.timeLeft = compound.getInteger("timeLeft");
this.safeX = compound.getInteger("safePosX");
this.safeY = compound.getInteger("safePosY");
this.safeZ = compound.getInteger("safePosZ");
}
public boolean attackEntityFrom(DamageSource ds, float i) {
if (ds.getEntity() instanceof EntityPlayer && worldObj.difficultySetting != EnumDifficulty.PEACEFUL) {
EntityPlayer player = (EntityPlayer) ds.getEntity();
if (this.getAttackTarget() == null) {
this.chatTime = 0;
int pokey = rand.nextInt(3);
if (pokey == 2) {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.attack.1"));
2018-12-07 06:32:48 +01:00
} else if (pokey == 1) {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.attack.2"));
2018-12-07 06:32:48 +01:00
} else {
2021-01-01 04:09:39 +01:00
chatItUp(player, StatCollector.translateToLocal("gui.valkyrie.dialog.attack.3"));
2018-12-07 06:32:48 +01:00
}
this.setAttackTarget(player);
} else {
this.teleTimer -= 10;
}
if (ds.getEntity() instanceof EntityLivingBase) {
becomeAngryAt((EntityLivingBase) ds.getEntity());
}
} else {
teleport(this.posX, this.posY, this.posZ, 8);
extinguish();
return false;
}
boolean flag = super.attackEntityFrom(ds, i);
if (flag && this.getHealth() <= 0) {
spawnExplosionParticle();
this.setDead();
}
2016-12-17 16:28:16 +01:00
return flag;
2018-12-07 06:32:48 +01:00
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
@Override
public boolean attackEntityAsMob(Entity entity) {
boolean flag = false;
if (this.attackTime <= 0 && entity.boundingBox.maxY > this.boundingBox.minY && entity.boundingBox.minY < this.boundingBox.maxY) {
this.attackTime = 20;
swingArm();
flag = entity.attackEntityFrom(DamageSource.causeMobDamage(this), 7);
if (entity != null && this.getAttackTarget() != null && entity == getAttackTarget() && entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (player.getHealth() <= 0) {
int pokey = this.rand.nextInt(3);
if (pokey == 2) {
2021-01-01 04:09:39 +01:00
chatItUp((EntityPlayer) this.getAttackTarget(), StatCollector.translateToLocal("gui.valkyrie.dialog.playerdead.1"));
2018-12-07 06:32:48 +01:00
} else if (pokey == 1) {
2021-01-01 04:09:39 +01:00
chatItUp((EntityPlayer) this.getAttackTarget(), StatCollector.translateToLocalFormatted("gui.valkyrie.dialog.playerdead.2", player.getDisplayName()));
2018-12-07 06:32:48 +01:00
} else {
2021-01-01 04:09:39 +01:00
chatItUp((EntityPlayer) this.getAttackTarget(), StatCollector.translateToLocal("gui.valkyrie.dialog.playerdead.3"));
2018-12-07 06:32:48 +01:00
}
this.setAttackTarget(null);
this.angerLevel = this.chatTime = 0;
}
}
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
return flag;
}
@Override
protected void dropFewItems(boolean var1, int var2) {
dropItem(ItemsAether.victory_medal, 1);
}
@Override
public void fall(float distance) {
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
@Override
public boolean canDespawn() {
return true;
}
2016-12-17 16:28:16 +01:00
2018-12-07 05:33:43 +01:00
@Override
2018-12-07 06:32:48 +01:00
protected String getHurtSound() {
return "game.player.hurt";
}
2018-12-07 05:33:43 +01:00
@Override
2018-12-07 06:32:48 +01:00
protected String getDeathSound() {
return "game.player.hurt.fall.big";
}
2016-12-17 16:28:16 +01:00
}