Esempio n. 1
0
        private Node GetMinInfluenceNode()
        {
            InfluenceMapComponent influenceMapComponent = Object.FindObjectOfType <InfluenceMapComponent>();
            float       minInfluence       = int.MaxValue;
            Node        minInfluenceNode   = null;
            List <Node> sameInfluencesNode = new List <Node>();

            foreach (var possibleMovement in troopToMove.GetComponent <Troop>().possibleMovements)
            {
                float tempInfluence = influenceMapComponent.GetNodeAtLocation(possibleMovement.WorldPosition)
                                      .GetTotalInfluenceAtNode();

                //intentamos movernos al de menor influencia y que no lo haya elegido otro.
                if (tempInfluence < minInfluence && !(_levelController.chosenNodesToMoveIA.Contains(possibleMovement)))
                {
                    minInfluenceNode = possibleMovement;
                    minInfluence     = tempInfluence;
                }
                else if (tempInfluence == minInfluence && !(_levelController.chosenNodesToMoveIA.Contains(possibleMovement)))
                {
                    sameInfluencesNode.Add(possibleMovement);
                }
            }

            if (sameInfluencesNode.Count > 0)
            {
                return(sameInfluencesNode[Random.Range(0, sameInfluencesNode.Count)]);
            }

            return(minInfluenceNode);
        }
 private void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent <CustomPathfinding.Node>() && PNode == null)
     {
         PNode = other.GetComponent <CustomPathfinding.Node>();
         //other.GetComponent<CustomPathfinding.Node>().cell = this;
     }
 }
Esempio n. 3
0
    public void SetAffectedCells()
    {
        int offset = 0;

        if (this.owner == Entity.Owner.Player)
        {
            offset = GetComponent <AreaAttack>().offset + 2;
        }
        else if (this.owner == Entity.Owner.AI)
        {
            offset = GetComponent <AreaAttack>().offset - 2;
        }

        CustomPathfinding.Node node = null;
        switch (CurrentRotation)
        {
        case TROTATION.Front:
            node = this.cell.PNode.FindNodeFromThis(offset, 0);
            break;

        case TROTATION.Right:
            node = this.cell.PNode.FindNodeFromThis(0, -offset);
            break;

        case TROTATION.Back:
            node = this.cell.PNode.FindNodeFromThis(-offset, 0);
            break;

        case TROTATION.Left:
            node = this.cell.PNode.FindNodeFromThis(0, offset);
            break;
        }

        if (node != null)
        {
            nodeAffectedList = _pathfindingManager.RequestNodesAtRadius(GetComponent <AreaAttack>().areaSize, node.WorldPosition);

            for (int i = 0; i < nodeAffectedList.Count; i++)
            {
                //nodeAffectedList[i].ColorAsPossibleTurretExplosion();
                nodeAffectedList[i].cell.gameObject.transform.Find("ProjectilePlacement").gameObject.SetActive(true);
                this.CellsUnderMyAttack.Add(nodeAffectedList[i].GetOurCell());
                nodeAffectedList[i].cell.explosionBelongsTo.Add(this);
            }

            //node.ColorAsPossibleTurretExplosion();
            node.cell.gameObject.transform.Find("ProjectilePlacement").gameObject.SetActive(true);
            this.CellsUnderMyAttack.Add(node.GetOurCell());
            node.cell.explosionBelongsTo.Add(this);

            Debug.Log("el nodo en " + node.GridX + ", " + node.GridZ + " se pinta?");
        }



        for (int i = 0; i < CellsUnderMyAttack.Count; i++)
        {
            if (CellsUnderMyAttack[i].entityIn != null && CellsUnderMyAttack[i].entityIn.owner != this.owner)
            {
                CellsUnderMyAttack[i].entityIn.GetComponent <Health>().ReceiveDamage(this.GetComponent <AreaAttack>().damage);
            }
        }
    }