tcr/java/src/game/entity/npc/EntityMage.java
2025-03-12 18:13:11 +01:00

162 lines
4.8 KiB
Java
Executable file

package game.entity.npc;
import java.util.List;
import game.entity.attributes.AttributeInstance;
import game.entity.attributes.Attributes;
import game.entity.effect.EntityLightning;
import game.entity.types.EntityLiving;
import game.init.Items;
import game.item.ItemStack;
import game.potion.Potion;
import game.potion.PotionEffect;
import game.rng.Random;
import game.world.World;
public class EntityMage extends EntityNPC
{
private int attackTimer;
private boolean drinking;
public EntityMage(World worldIn)
{
super(worldIn);
}
// public boolean isRangedWeapon(ItemStack stack) {
// return stack != null && stack.getItem() == Items.potion;
// }
public void onLivingUpdate()
{
if (!this.worldObj.client)
{
if (this.drinking)
{
if (this.attackTimer-- <= 0)
{
this.drinking = false;
ItemStack itemstack = this.getHeldItem();
this.setItem(0, null);
if (itemstack != null && itemstack.getItem() == Items.potion)
{
List<PotionEffect> list = Items.potion.getEffects(itemstack);
if (list != null)
{
for (PotionEffect potioneffect : list)
{
this.addEffect(new PotionEffect(potioneffect));
}
}
}
this.getEntityAttribute(Attributes.MOVEMENT_SPEED).removeModifier(Attributes.MAGE_POTSPEED_MOD);
}
}
else
{
int i = -1;
// if (this.rand.floatv() < 0.15F && this.isInsideOfLiquid() && !this.hasEffect(Potion.waterBreathing))
// {
// i = 8237;
// }
// else
if (this.rand.floatv() < 0.15F && this.isBurning() && !this.hasEffect(Potion.fireResistance))
{
i = 16307;
}
else if (this.rand.floatv() < 0.05F && this.getHealth() < this.getMaxHealth())
{
i = 16341;
}
else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
{
i = 16274;
}
else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
{
i = 16274;
}
if (i > -1)
{
this.setItem(0, new ItemStack(Items.potion, 1, i));
this.attackTimer = this.getHeldItem().getMaxItemUseDuration();
this.drinking = true;
AttributeInstance iattributeinstance = this.getEntityAttribute(Attributes.MOVEMENT_SPEED);
iattributeinstance.removeModifier(Attributes.MAGE_POTSPEED_MOD);
iattributeinstance.applyModifier(Attributes.MAGE_POTSPEED_MOD);
}
else if(this.rand.chance(80)) {
boolean far = this.getAttackTarget() != null && this.getAttackTarget().getDistanceSqToEntity(this) >= 256.0;
this.setItem(0, far || this.rand.chance() ? new ItemStack(Items.potion, 1, 16384) : null);
}
}
}
super.onLivingUpdate();
}
public void attackEntityWithRangedAttack(EntityLiving target, float range) {
if(!this.drinking)
super.attackEntityWithRangedAttack(target, range);
}
public int getColor() {
return 0x9b58c8;
}
public void onStruckByLightning(EntityLightning lightningBolt) {
}
public boolean isMagnetic() {
return true;
}
// public boolean isAggressive() {
// return true;
// }
//
// public boolean isPeaceful() {
// return false;
// }
public boolean isAggressive(Class<? extends EntityNPC> clazz) {
return clazz == EntityElf.class;
}
// public boolean isPeaceful(Class<? extends EntityNPC> clazz) {
// return false;
// }
// public boolean canInfight(Alignment align) {
// return true;
// }
//
// public boolean canMurder(Alignment align) {
// return false;
// }
public boolean canUseMagic() {
return true;
}
public int getBaseHealth(Random rand) {
return rand.range(26, 66);
}
// public int getBaseEnergy(Random rand) {
// return 0;
// }
public float getHeightDeviation(Random rand) {
return rand.frange(-0.2f, 0.2f);
}
public Alignment getNaturalAlign(Random rand) {
return rand.pick(Alignment.EVIL, Alignment.CHAOTIC_EVIL);
}
}