Example #1
0
    /// <summary>
    /// Attempt's to find a target for the AI to attack.
    /// Grabs the closest chicken not on it's team.
    /// </summary>
    void findTarget()
    {
        ChickenControlBehavior[] chickens = GameState.getInstance().getAllCharactersNotOnTeam(control.getChickensTeam());

        if (chickens == null || chickens.Length == 0)
        {
            return;
        }

        ChickenControlBehavior closestChicken = null;
        float closestDistance = float.PositiveInfinity;

        for (int i = 0; i < chickens.Length; i++)
        {
            float curDist = Vector3.Distance(chickens[i].transform.position, control.transform.position);

            if (curDist < closestDistance)
            {
                closestChicken  = chickens[i];
                closestDistance = curDist;
            }
        }

        this.setTarget(closestChicken);
    }
    /// <summary>
    /// This is called when one of our hitboxes collides with something while we're attacking.
    /// </summary>
    /// <param name="collision">Collision, the collision that took place</param>
    void hitBoxCollisionEnter(Collision collision)
    {
        //If we hit ourself some how...
        if (collision.gameObject.transform == this.transform)
        {
            return;
        }


        if (currentState == ChickenState.Dashing && dashingDirection == Vector3.forward)
        {
            ChickenControlBehavior otherChicken = collision.gameObject.GetComponent <ChickenControlBehavior>();

            if (otherChicken != null && (otherChicken.team != team || otherChicken.team == ChickenTeam.None))             //added here disables friendly fire

            {
                if (otherChicken.gameObject.GetComponent <NetworkChickenCharacter>() != null)
                {
                    SpecialEffectsFactory.createEffect(otherChicken.gameObject.transform.position, SpecialEffectType.TakeDamage);
                    otherChicken.gameObject.GetComponent <PhotonView>().RPC("takeDamage", otherChicken.gameObject.GetComponent <PhotonView>().owner, power);
                    //otherChicken.gameObject.GetComponent<PhotonView>().RPC("takeDamage",PhotonTargets.All,power);
                }
                else
                {
                    otherChicken.takeDamage(power);
                }
            }
            else if (collision.transform.tag == "Hitbox")
            {
                //play a ting noise like in smashbros.
            }

            stopDashing();
        }
    }
    /// <summary>
    /// Adds a character to the current game state.
    /// </summary>
    /// <param name="chicken">Chicken.</param>
    public void addCharacter(ChickenControlBehavior chicken)
    {
        if(chicken == null){
            return;
        }

        charactersInScene.Add (chicken);
    }
    void takeDamage(int amount)
    {
        ChickenControlBehavior chicken = gameObject.GetComponent <ChickenControlBehavior> ();

        if (chicken != null)
        {
            chicken.takeDamage(amount);
        }
    }
    /// <summary>
    /// Adds a character to the current game state.
    /// </summary>
    /// <param name="chicken">Chicken.</param>
    public void addCharacter(ChickenControlBehavior chicken)
    {
        if (chicken == null)
        {
            return;
        }

        charactersInScene.Add(chicken);
    }
    /// <summary>
    /// Changes whatever the chickens target is.
    /// </summary>
    /// <param name="chickenControl">Chicken control.</param>
    public void setTarget(ChickenControlBehavior target)
    {
        if (target == null) {
            return;
        }

        control.setTarget (target.gameObject);
        this.target = target;
    }
Example #7
0
    /// <summary>
    /// Changes whatever the chickens target is.
    /// </summary>
    /// <param name="chickenControl">Chicken control.</param>
    public void setTarget(ChickenControlBehavior target)
    {
        if (target == null)
        {
            return;
        }

        control.setTarget(target.gameObject);
        this.target = target;
    }
Example #8
0
    // Use this for initialization
    void Start()
    {
        //spawn players
        GameObject enemy  = ChickenFactory.createChicken(new Vector3(-5, 2, 0), ChickenTeam.Red, 0f);
        GameObject player = ChickenFactory.createPlayerChicken(new Vector3(5, 2, 0), ChickenTeam.Blue);

        ChickenControlBehavior playerChickenBehavior = player.GetComponent <ChickenControlBehavior> ();

        playerChickenBehavior.setTarget(enemy);

        enemy.GetComponent <ChickenControlBehavior> ().setTarget(player);
        // Disable enemy attack AI.
        enemy.GetComponent <ChickenAttackAIBehavior>().enabled = false;
    }
    public void onLivingThingDeath(ChickenControlBehavior chicken)
    {
        Vector3 spawnLocation = spawnPoints [Random.Range(0, spawnPoints.Length)].point.transform.position;

        if (chicken.getChickensTeam () == ChickenTeam.Blue) {
            teamTwoPoints ++;
        } else {
            teamOnePoints ++;
        }

        if (chicken.gameObject.GetComponent<PlayerBehavior> () != null) {
            ChickenFactory.createPlayerChicken(spawnLocation, chicken.getChickensTeam());
        } else {
            ChickenFactory.createChicken(spawnLocation, chicken.getChickensTeam(), 0);
        }
    }
    /// <summary>
    /// Removes a character from the current game state.
    /// Generally moved upon death
    /// </summary>
    /// <param name="chicken">Chicken.</param>
    public void removeCharacter(ChickenControlBehavior chicken)
    {
        if (chicken == null)
        {
            return;
        }

        if (charactersInScene.Contains(chicken))
        {
            //If we're playing a game right now..
            if (gameModeBeingPlayed != null)
            {
                gameModeBeingPlayed.onLivingThingDeath(chicken);
            }

            charactersInScene.Remove(chicken);
        }
    }
Example #11
0
    public void onLivingThingDeath(ChickenControlBehavior chicken)
    {
        Vector3 spawnLocation = spawnPoints [Random.Range(0, spawnPoints.Length)].point.transform.position;

        if (chicken.getChickensTeam() == ChickenTeam.Blue)
        {
            teamTwoPoints++;
        }
        else
        {
            teamOnePoints++;
        }

        if (chicken.gameObject.GetComponent <PlayerBehavior> () != null)
        {
            ChickenFactory.createPlayerChicken(spawnLocation, chicken.getChickensTeam());
        }
        else
        {
            ChickenFactory.createChicken(spawnLocation, chicken.getChickensTeam(), 0);
        }
    }
    void targetModeToggle()
    {
        if (chickenController.getTarget() != null)
        {
            // Set the target to null.
            chickenController.setTarget(null);
            Debug.Log("Target has been set to null.");

            // Enable free-look camera.
            // There is no target, so allow the chicken to rotate on the x-axis using mouse movement.
        }
        else if (chickenController.getTarget() == null)
        {
            // Set the target.
            ChickenControlBehavior[] chickens = GameState.getInstance().getAllCharactersNotOnTeam(chickenController.getChickensTeam());

            if (chickens == null || chickens.Length == 0)
            {
                return;
            }

            ChickenControlBehavior closestChicken = null;
            float closestDistance = float.PositiveInfinity;
            for (int i = 0; i < chickens.Length; i++)
            {
                float curDist = Vector3.Distance(chickens[i].transform.position, transform.position);

                if (curDist < closestDistance)
                {
                    closestChicken  = chickens[i];
                    closestDistance = curDist;
                }
            }

            chickenController.setTarget(closestChicken.gameObject);
            Debug.Log("Target has been set to closest chicken.");
        }
    }
 // Use this for initialization
 void Start()
 {
     chickenController = gameObject.GetComponent <ChickenControlBehavior>();
 }
 // Use this for initialization
 void Start()
 {
     chickenController = gameObject.GetComponent<ChickenControlBehavior>();
 }
    /// <summary>
    /// Removes a character from the current game state.
    /// Generally moved upon death
    /// </summary>
    /// <param name="chicken">Chicken.</param>
    public void removeCharacter(ChickenControlBehavior chicken)
    {
        if(chicken == null){
            return;
        }

        if(charactersInScene.Contains(chicken)){

            //If we're playing a game right now..
            if(gameModeBeingPlayed != null){
                gameModeBeingPlayed.onLivingThingDeath(chicken);
            }

            charactersInScene.Remove(chicken);
        }
    }