/// <summary>
    /// Updates the <see cref="state"/> Only modifies the state variable if the
    /// player has died or respawned since last Update.
    /// </summary>
    public void UpdateState()
    {
        if (wasNotDead != hb.isNotDead() && hb.isNotDead())
        {
            state = TankStates.Alive;
        }
        else if (wasNotDead != hb.isNotDead() && !hb.isNotDead())
        {
            state = TankStates.Dead;
        }

        wasNotDead = hb.isNotDead();
    }
    /// <summary>
    /// Detects the targets in range. That is, gets all GameObjects with the
    /// specified layer in range. This method guarantees that no duplicate
    /// GameObjects will be returned.
    /// </summary>
    /// <returns>A List of GameObjects representing the targets in range.</returns>
    public List <GameObject> DetectTargets()
    {
        // Make room for new targets
        targets.Clear();
        //Debug.Log(name + ": clearing targets");

        // Get all of the colliders in range
        Collider[] colliders = Physics.OverlapSphere(transform.position, range, targetLayerMask);
        //Debug.Log(name + ": Found " + colliders.Length + " colliders");
        // Add the GameObjects of the colliders to the targets list
        foreach (Collider c in colliders)
        {
            GameObject target = FindParentObject(c.transform);

            Assert.IsTrue(target != null, "target " + target.name + " is null");
            Assert.IsTrue(targets != null, "targets is null");

            HealthBehavior hb = target.GetComponent <HealthBehavior>();
            Assert.IsTrue(hb != null, "Health behavior of target " + target.name + " is null,\n"
                          + "i.e. " + target.name + " does not have a HealthBehavior");

            //Debug.Log(name + ": Target found: " + target);
            // Make sure we don't add duplicate references to the same GameObject
            // Make sure we don't add dead GameObjects to the targets.
            if (!targets.Contains(target) && hb.isNotDead())
            {
                //Debug.Log(name + ": Target added: " + target);
                targets.Add(target);
            }
        }

        //Debug.Log(name + ": Total targets: " + targets.Count);
        return(targets);
    }
 protected virtual void Update()
 {
     if (!health.isNotDead())
     {
         bulletPool.Destroy();
     }
 }
예제 #4
0
    // If collider is attached to player or minion or just about anything
    // with a HealthBehavior script then heal it.
    // We just don't want this building healing other buildings.
    //private void OnTriggerStay(Collider other)
    //{

    //    HealthBehavior hb = other.gameObject.GetComponent<HealthBehavior>();
    //    if (hb == null) return;

    //}

    /// <summary>
    /// Adds a reference to other's GameObject
    /// if it is eligible for healing.
    /// GameObjects eligible are any objects which have HealthBehaviors,
    /// but are not buildings.
    /// </summary>
    /// <param name="other"></param>
    //protected override void OnTriggerEnter(Collider other) {

    //    GameObject go = other.gameObject;

    //    if (   ( taggyBoi.isP1Tag(this.tag) && taggyBoi.isP1Tag(go.tag))
    //        || ( taggyBoi.isP2Tag(this.tag) && taggyBoi.isP2Tag(go.tag))) {

    //        // TODO: exclude buildings

    //        healables.Add(go);
    //    }
    //}

    /// <summary>
    /// Since other's GameObject is exiting the healing zone,
    /// it is no longer eligible for healing.
    /// If it was previously eligible,
    /// it will be removed
    /// </summary>
    /// <param name="other"></param>
    //private void OnTriggerExit(Collider other) {

    //    GameObject go = other.gameObject;

    //    if (healables.Contains(go)) {

    //        healables.Remove(go);
    //    }
    //}

    /// <summary>
    /// Populates this script's internal healables collection.
    /// Checks colliders in a radius around this object.
    /// If they are eligible to be healed,
    /// adds their GameObject to the healables collection.
    /// Note that this healables collection should be flushed at the end of every frame,
    /// because this function will be called next frame.
    /// </summary>
    private void populateHealables()
    {
        Collider[] overlaps = Physics.OverlapSphere(gameObject.transform.position, healRadius);

        foreach (Collider c in overlaps)
        {
            GameObject     go = NPCShootController.FindParentObject(c.gameObject.transform);
            HealthBehavior hb = (go == null ? null : go.GetComponent <HealthBehavior>());

            // Exclude things which don't have HealthBehaviors
            if (hb == null)
            {
                continue;
            }

            // Exclude buildings (else, healing buildings would be pretty broken)
            if (taggyBoi.isStructure(go.tag))
            {
                continue;
            }

            // Don't heal if they're dead
            if (!hb.isNotDead())
            {
                continue;
            }

            // Only heal if us and go are of the same team
            if ((taggyBoi.isP1Tag(this.gameObject.tag) && taggyBoi.isP1Tag(go.tag)) ||
                (taggyBoi.isP2Tag(this.gameObject.tag) && taggyBoi.isP2Tag(go.tag)))
            {
                healables.Add(go);
            }
        }
    }
    //To be used later maybe when we need to declare other global variables
    // that don't belong in above categories
    #endregion
    // Start is called before the first frame update
    void Start()
    {
        // Determine which OS the game is being run on, and set controller
        // mappings accordingly.
        switch (Application.platform)
        {
        case RuntimePlatform.OSXEditor:
        case RuntimePlatform.OSXPlayer:

            forwardDrive      = (tag == "Player1_obj" ? "forward-drive-1-mac" : "forward-drive-2-mac");
            backwardDrive     = (tag == "Player1_obj" ? "backward-drive-1-mac" : "backward-drive-2-mac");
            reverse           = (tag == "Player1_obj" ? "reverse-1-mac" : "reverse-2-mac");
            buildButton       = (tag == "Player1_obj" ? "build-1-mac" : "build-2-mac");
            selectBuildButton = (tag == "Player1_obj" ? "select-1-mac" : "select-2-mac");
            submitButton      = (tag == "Player1_obj" ? "submit-1-mac" : "submit-2-mac");
            break;

        case RuntimePlatform.WindowsEditor:
        case RuntimePlatform.WindowsPlayer:
            forwardDrive      = (tag == "Player1_obj" ? "forward-drive-1-win" : "forward-drive-2-win");
            backwardDrive     = (tag == "Player1_obj" ? "backward-drive-1-win" : "backward-drive-2-win");
            reverse           = (tag == "Player1_obj" ? "reverse-1-win" : "reverse-2-win");
            buildButton       = (tag == "Player1_obj" ? "build-1-win" : "build-2-win");
            selectBuildButton = (tag == "Player1_obj" ? "select-1-win" : "select-2-win");
            submitButton      = (tag == "Player1_obj" ? "submit-1-win" : "submit-2-win");
            break;

        default:
            Debug.LogError("Mappings not setup for operating systems other than Windows or Mac OS");
            break;
        }
        // Left analog stick is the same mapping on Mac OS and Windows
        xDrive = (tag == "Player1_obj" ? "x-drive-1" : "x-drive-2");
        zDrive = (tag == "Player1_obj" ? "z-drive-1" : "z-drive-2");

        // Define movement starting values
        stickInput = new Vector3();
        rb         = transform.GetComponent <Rigidbody>();
        dir        = 1;

        // Define resource starting values
        Fluff   = 0;
        Plastic = 0;

        // Get the reference to the HealthBehavior script
        hb         = GetComponent <HealthBehavior>();
        state      = TankStates.Alive;
        wasNotDead = hb.isNotDead();
        GetComponent <Rigidbody>().maxAngularVelocity = turnSpeed;
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (healthBehave == null)
        {
            Debug.LogError("healthBehave is null, object with ResourceDrop is " + this.gameObject.name);
        }

        if (!healthBehave.isNotDead() && !died)
        {
            switch (this.gameObject.tag)
            {
            case "P1_Soldier":
            case "P2_Soldier":
                DropResources(ResourceType.Plastic, 1);
                break;

            case "P1_Spawner_Soldier":
            case "P2_Spawner_Soldier":
                DropResources(ResourceType.Plastic, 2);
                break;

            case "P1_Spawner_Teddy":
            case "P2_Spawner_Teddy":
                DropResources(ResourceType.Fluff, 2);
                break;

            case "P1_Teddy":
            case "P2_Teddy":
                DropResources(ResourceType.Fluff, 1);
                break;

            case "P1_Turret":
            case "P2_Turret":
                DropResources(ResourceType.Plastic, 2);
                break;

            case "P1_Healer":
            case "P2_Healer":
                DropResources(ResourceType.Plastic, 2);
                break;

            default:
                Debug.LogError("Object " + this.name +
                               " is not supposed to drop resources");
                break;
            }

            died = true;
        }
    }
예제 #7
0
    // Update is called once per frame
    protected virtual void Update()
    {
        if (!nv_agent.isActiveAndEnabled)
        {
            return;
        }

        if (!health.isNotDead())
        {
            Die();
        }

        if (CanAttack())
        {
            State = MinionStates.Attack;
            Attack();
        }

        if (doNavMeshDemo)
        {
            // NavMeshDemo with mouse controls
            if (useMouseControls)
            {
                #region Mouse Controls
                // Both mouse buttons = stay
                if (Input.GetKey(KeyCode.Mouse0) && Input.GetKey(KeyCode.Mouse1))
                {
                    moveType = MinionMoveTypes.Halt;
                }

                // Right mouse button = attack
                else if (Input.GetKeyDown(KeyCode.Mouse1))
                {
                    moveType = MinionMoveTypes.Attack;
                }

                // Left mouse button = defend
                else if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    moveType = MinionMoveTypes.Defend;
                }
                #endregion
            }

            // NavMeshDemo with pad controls
            else
            {
                #region Pad Controls
                // If down, defend
                if (Input.GetAxisRaw(upDown) < 0)
                {
                    //Debug.Log("Attempting to change move type to DEFEND");
                    moveType = MinionMoveTypes.Defend;
                }

                // Else if up, attack
                else if (Input.GetAxisRaw(upDown) > 0)
                {
                    //Debug.Log("Attempting to change move type to ATTACK");
                    moveType = MinionMoveTypes.Attack;
                }

                // Else if right or altHalt button, halt
                else if ((useAltHalt && Input.GetButtonDown(altHalt)) || (!useAltHalt && Input.GetAxisRaw(leftRight) < 0))
                {
                    //Debug.Log("Attempting to change move type to HALT");
                    moveType = MinionMoveTypes.Halt;
                }



                #endregion
            }
        }
        else
        {
            //DebugMovement();
        }

        UpdateDestination();
        if (anim)
        {
            UpdateAnimator();
        }
    }
예제 #8
0
 /// <summary>
 /// Convenience function that returns the HealthBehavior's isNotDead value.
 /// </summary>
 /// <returns><c>true</c>, if the object's health is greater than 0, <c>false</c>
 /// otherwise.</returns>
 public bool IsNotDead()
 {
     return(health.isNotDead());
 }