<commit_before>package util;

import agents.Agent;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 * Abstract class for defining weapons used by agents.
 * @author <NAME>
 * @version 1.0
 */
public abstract class AbstractWeapon {
    /**
     * Name of weapon.
     */
    protected String name;
    /**
     * Name of agent to whom weapon is added.
     */
    protected Agent agent;
    /**
     * Maximum range of weapon.
     */
    protected float maxAttackRange;
    /**
     * Minimum range of weapon.
     */
    protected float minAttackRange = 0;
    /**
     * Attack damage of weapon.
     */
    protected float attackDamage;
    /**
     * Number of bullet that this weapon have left.
     */
    protected int numberOfBullets;
    /**
     * Spatial for weapon.
     */
    protected Spatial spatial;
    /**
     * One weapon have one type of bullet. Each fired bullet can be in it's own
     * update().
     */
    protected Bullet bullet;

    /**
     * Check if enemy agent is in range of weapon.
     * @param target
     * @return 
     */
    public boolean isInRange(Agent target) {
        if (agent.getLocalTranslation().distance(target.getLocalTranslation()) > maxAttackRange) {
            return false;
        }
        if (agent.getLocalTranslation().distance(target.getLocalTranslation()) < minAttackRange) {
            return false;
        }
        return true;
    }

    /**
     * Check if there is any bullets in weapon.
     * @return true - has, false - no, it doesn't
     */
    public boolean hasBullets(){
        if (numberOfBullets == 0) {
            return false;
        }
        return true;
    }
    
    /**
     * Method for creating bullets and setting them to move.
     * @param target agent that should be shoot at
     * @param tpf time per frame
     * @throws Exception when there is no more bullets left
     */
    public void shootAt(Agent target, float tpf) throws Exception{
        if (numberOfBullets == 0) {
            throw new Exception("No more bullets");
        }
        Bullet firedBullet = controlShootAt(target, tpf);
        ((Node) agent.getSpatial()).attachChild(firedBullet.getSpatial());
        Game.getInstance().addBullet(firedBullet);
        if (numberOfBullets != -1) {
            numberOfBullets--;
        }
    }
    
    protected abstract Bullet controlShootAt(Agent target, float tpf);
    
    /**
     * Method for creating bullets and setting them to move.
     * @param direction direction of bullets to go
     * @param tpf time per frame
     * @throws Exception when hasBullets()== false
     */
    public void shootAt(Vector3f direction, float tpf) throws Exception{
        if (numberOfBullets == 0) {
            throw new Exception("No more bullets");
        }
        Bullet firedBullet = controlShootAt(direction, tpf);
        //((Node) Game.getInstance().getRootNode()).attachChild(firedBullet.getSpatial());
        Game.getInstance().addBullet(firedBullet);
        if (numberOfBullets != -1) {
            numberOfBullets--;
        }
    }
    
    protected abstract Bullet controlShootAt(Vector3f direction, float tpf);

    public String getName() {
        return name;<commit_msg>Base class for all weapons for agents<commit_after>package com.jme3.ai.agents.util;

import com.jme3.ai.agents.Agent;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 * Abstract class for defining weapons used by agents.
 * @author <NAME>
 * @version 1.0
 */
public abstract class AbstractWeapon {
    /**
     * Name of weapon.
     */
    protected String name;
    /**
     * Name of agent to whom weapon is added.
     */
    protected Agent agent;
    /**
     * Maximum range of weapon.
     */
    protected float maxAttackRange;
    /**
     * Minimum range of weapon.
     */
    protected float minAttackRange = 0;
    /**
     * Attack damage of weapon.
     */
    protected float attackDamage;
    /**
     * Number of bullet that this weapon have left.
     */
    protected int numberOfBullets;
    /**
     * Spatial for weapon.
     */
    protected Spatial spatial;
    /**
     * One weapon have one type of bullet. Each fired bullet can be in it's own
     * update().
     */
    protected Bullet bullet;

    /**
     * Check if enemy agent is in range of weapon.
     * @param target
     * @return 
     */
    public boolean isInRange(Agent target) {
        if (agent.getLocalTranslation().distance(target.getLocalTranslation()) > maxAttackRange) {
            return false;
        }
        if (agent.getLocalTranslation().distance(target.getLocalTranslation()) < minAttackRange) {
            return false;
        }
        return true;
    }

    /**
     * Check if there is any bullets in weapon.
     * @return true - has, false - no, it doesn't
     */
    public boolean hasBullets(){
        if (numberOfBullets == 0) {
            return false;
        }
        return true;
    }
    
    /**
     * Method for creating bullets and setting them to move.
     * @param target agent that should be shoot at
     * @param tpf time per frame
     * @throws Exception when there is no more bullets left
     */
    public void shootAt(Agent target, float tpf) throws Exception{
        if (numberOfBullets == 0) {
            throw new Exception("No more bullets");
        }
        Bullet firedBullet = controlShootAt(target, tpf);
        Game.getInstance().addBullet(firedBullet);
        if (numberOfBullets != -1) {
            numberOfBullets--;
        }
    }
    
    protected abstract Bullet controlShootAt(Agent target, float tpf);
    
    /**
     * Method for creating bullets and setting them to move.
     * @param direction direction of bullets to go
     * @param tpf time per frame
     * @throws Exception when hasBullets()== false
     */
    public void shootAt(Vector3f direction, float tpf) throws Exception{
        if (numberOfBullets == 0) {
            throw new Exception("No more bullets");
        }
        Bullet firedBullet = controlShootAt(direction, tpf);
        //((Node) Game.getInstance().getRootNode()).attachChild(firedBullet.getSpatial());
        Game.getInstance().addBullet(firedBullet);
        if (numberOfBullets != -1) {
            numberOfBullets--;
        }
    }
    
    protected abstract Bullet controlShootAt(Vector3f direction, float tpf);

    public String getName() {
        return name;
{'fraction_non_alphanumeric': 0.09938366718027734, 'fraction_numerical': 0.004622496147919877, 'mean_word_length': 2.128192771084337, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '363520', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1791, 'n_words': 571}