Search in sources :

Example 1 with EntityHumanoid

use of io.xol.chunkstories.core.entity.EntityHumanoid in project chunkstories-core by Hugobros3.

the class ZombieAI method tick.

public void tick() {
    super.tick();
    if (entity.isDead())
        return;
    if (attackEntityCooldown > 0)
        attackEntityCooldown--;
    // Find entities to attack
    if (!(this.currentTask instanceof AiTaskAttackEntity) && entity.stage().aggroRadius > 0.0 && attackEntityCooldown == 0) {
        // Only look for them once in 2s
        attackEntityCooldown = (int) (Math.random() * 60 * 2);
        for (Entity entityToLook : entity.getWorld().getEntitiesInBox(entity.getLocation(), new Vector3d(entity.stage().aggroRadius * 2f))) {
            float visibilityModifier = 1f;
            if (entityToLook instanceof EntityPlayer) {
                EntityPlayer player = (EntityPlayer) entityToLook;
                // Crouched players are 70% less visible
                if (player.stance.get().equals(EntityHumanoidStance.CROUCHING))
                    visibilityModifier -= 0.7f;
                // If the entity is sprinting
                if (player.getVelocityComponent().getVelocity().length() > 0.7)
                    visibilityModifier += 1.0f;
            }
            if (!entityToLook.equals(entity) && entityToLook.getLocation().distance(entity.getLocation()) * visibilityModifier <= entity.stage().aggroRadius && entityToLook instanceof EntityHumanoid && !((EntityHumanoid) entityToLook).isDead()) {
                // Check target is in set
                if (targetsTypes.contains(entityToLook.getClass())) {
                    // Play a borking sound
                    // .setPitch();
                    entity.getWorld().getSoundManager().playSoundEffect("sounds/entities/zombie/grunt.ogg", Mode.NORMAL, entity.getLocation(), (float) (1.5 + Math.random() * 0.2), 1.5f);
                    // .setPitch();
                    entity.getWorld().getSoundManager().playSoundEffect("sounds/entities/zombie/grunt.ogg", Mode.NORMAL, entity.getLocation(), (float) (1.5 + Math.random() * 0.2), 1.5f);
                    // Set new task
                    setAiTask(new AiTaskAttackEntity((EntityHumanoid) entityToLook, 10f, 15f, currentTask, entity.stage().attackCooldown, entity.stage().attackDamage));
                    return;
                }
            }
        }
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Vector3d(org.joml.Vector3d) EntityHumanoid(io.xol.chunkstories.core.entity.EntityHumanoid) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer)

Aggregations

Entity (io.xol.chunkstories.api.entity.Entity)1 EntityHumanoid (io.xol.chunkstories.core.entity.EntityHumanoid)1 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)1 Vector3d (org.joml.Vector3d)1