Example #1
0
    //function to find the closest pick up target
    //GameObject GetClosestPickUp (List<GameObject> PickUps)
    GameObject TargetClosestPickUp()
    {
        GameObject bestTarget         = null;
        float      closestDistanceSqr = Mathf.Infinity;
        Vector3    currentPosition    = transform.position;

        //foreach (GameObject potentialTargetObj in PickUps)
        foreach (KeyValuePair <GameObject, GameObject> potentialTargetObj in PickUpHandler.openPickUpDictionary[allegiance])
        {
            if (potentialTargetObj.Value == null)
            //if (!potentialTargetObj.gameObject.GetComponent<PickUp>().IsCollected())
            {
                //GameObject potentialTarget = potentialTargetObj.Key;
                Vector3 directionToTarget = potentialTargetObj.Key.transform.position - currentPosition;
                //directionToTarget.Normalize();
                float dSqrToTarget = directionToTarget.sqrMagnitude;
                if (dSqrToTarget < closestDistanceSqr)
                {
                    closestDistanceSqr = dSqrToTarget;
                    //bestTarget = potentialTarget;
                    bestTarget = potentialTargetObj.Key;
                }
            }
        }
        if (bestTarget != null)
        {
            PickUpHandler.TargetPickUp(bestTarget, this.gameObject, allegiance);
        }
        aimTarget = bestTarget;
        return(bestTarget);
    }
Example #2
0
 private void PickUpCargo(Collider other)
 {
     PickUpHandler.CarryPickUp(other.gameObject, this.gameObject, allegiance);
     aimTarget = null;
     other.gameObject.GetComponent <PickUp>().PickedUp(this.transform);
     cargo      = other.gameObject;
     atCapacity = true;
 }
Example #3
0
 // Update is called once per frame
 void Update()
 {
     Trigger = Random.Range(Min, Max);
     if (Trigger < spawnChance)
     {
         PickUpHandler.AddToOpenPickUp(SpawnPickUp());
     }
 }
Example #4
0
 public void PickUpIsAddedToOpenList()
 {
     //Arrange
     //Act
     PickUpHandler.AddToOpenPickUp(pickUp);
     //Assert
     Assert.True(PickUpHandler.openPickUpDictionary[GameResources.Allegiance.Team1].ContainsKey(pickUp));
 }
Example #5
0
 private void DeliverCargo()
 {
     //gameScope.RemoveFromAvailPickUps(cargo.transform); //Hopefully not needed
     PickUpHandler.DeliverPickUp(cargo.gameObject, allegiance);
     Destroy(cargo.gameObject);
     atCapacity = false;
     GameResources.AddResource(1, allegiance);
     // TODO Add to global resource count
 }
Example #6
0
 public void PickUpIsRemovedFromOpenList()
 {
     //Arrange
     PickUpHandler.AddToOpenPickUp(pickUp);
     //Act
     PickUpHandler.TargetPickUp(pickUp, worker, GameResources.Allegiance.Team1);
     //Assert
     Assert.False(PickUpHandler.openPickUpDictionary[GameResources.Allegiance.Team1][pickUp] == null);
 }
Example #7
0
 // When this game object intersects a collider with 'is trigger' checked,
 // store a reference to that collider in a variable named 'other'..
 void OnTriggerEnter(Collider other)
 {
     // ..and if the game object we intersect has the tag 'Pick Up' assigned to it..
     if (other.gameObject.CompareTag("Pick Up") && PickUpHandler.IsAvailablePickUp(other.gameObject, allegiance))
     {
         GameResources.AddResource(1, allegiance);
         PickUpHandler.CarryPickUp(other.gameObject, this.gameObject, allegiance);
         PickUpHandler.DeliverPickUp(other.gameObject, allegiance);
         Destroy(other.gameObject);
     }
 }
Example #8
0
    public static GameObject GiveMePickUpZone(Vector3 targetPosition, Quaternion targetRotation)
    {
        GameObject instance = Instantiate <GameObject>(PickUpZone, targetPosition, targetRotation);

        instance.GetComponent <PickUpZone>().Spawn = PickUp;
        GameObject PickUp1 = Instantiate(PickUp, targetPosition + new Vector3(0, 0, (instance.transform.lossyScale.z * 5)), Quaternion.identity);
        GameObject PickUp2 = Instantiate(PickUp, targetPosition, Quaternion.identity);
        GameObject PickUp3 = Instantiate(PickUp, targetPosition + new Vector3(0, 0, (instance.transform.lossyScale.z * -5)), Quaternion.identity);

        PickUpHandler.AddToOpenPickUp(PickUp1);
        PickUpHandler.AddToOpenPickUp(PickUp2);
        PickUpHandler.AddToOpenPickUp(PickUp3);
        return(instance);
    }
Example #9
0
    //Collision effects
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Pick Up") && !atCapacity && (other.gameObject.Equals(aimTarget) || PickUpHandler.IsAvailablePickUp(other.gameObject, allegiance)))
        {
            if (!other.gameObject.Equals(aimTarget))
            {
                PickUpHandler.UntargetPickUp(aimTarget, allegiance);
            }
            PickUpCargo(other);
        }
        else if (other.gameObject.Equals(HomeZone) && atCapacity)
        {
            DeliverCargo();
        }

        //TODO: stolen pickups push notifications from PickUpHandler

        /*
         * if (other.gameObject.CompareTag("Pick Up") && !atCapacity)
         * {
         *  if (!other.gameObject.Equals(aimTarget))
         *  {
         *      if (gameScope.IsAvailablePickUp(other.transform))
         *      {
         *          gameScope.RemoveFromAvailPickUps(other.transform);
         *          gameScope.AddToAvailPickUps(aimTarget);
         *      }
         *      else
         *      {
         *          //gameScope.AddToStolenPickUps(other.transform);
         *          gameScope.AddToAvailPickUps(aimTarget);
         *          //Something
         *      }
         *
         *  }
         *  PickUpCargo(other);
         * }
         * else if (other.gameObject.CompareTag(COLLECTION_ZONE) && atCapacity)
         * {
         *  DeliverCargo();
         * }
         */
    }