Пример #1
0
 public StatusSkillTarget(StatusSkill statusSkill, Node node)
 {
     m_Skill      = statusSkill;
     m_TargetNode = node;
 }
Пример #2
0
    void DoStatusHeuristic(List <Node> nodesWithUnits, StatusSkill ss, Unit aiUnit)
    {
        foreach (Node nodeWithUnit in nodesWithUnits)
        {
            // Targets AI units.
            if (ss.targets == SkillTargets.Allies)
            {
                // If unit is an AI unit.
                if (nodeWithUnit.unit.m_Allegiance == aiUnit.GetAllegiance())
                {
                    Unit currentUnit = nodeWithUnit.unit;

                    if (currentUnit == aiUnit)
                    {
                        // Edge case when healing self. Don't move;
                        Node castNode = nodeWithUnit;

                        // Try to put a status on the healthiest unit, to get the most value.
                        float newStatusH = currentUnit.GetCurrentHealth() * aiUnit.GetHeuristicCalculator().m_StatusWeighting;
                        if (newStatusH < FindHeuristic(castNode, aiUnit)?.m_StatusValue)
                        {
                            continue;
                        }
                        else
                        {
                            if (castNode != null)
                            {
                                AddOrUpdateHeuristic(
                                    newStatusH * ss.m_CastableDistance,
                                    castNode,
                                    aiUnit,
                                    new StatusSkillTarget(ss, nodeWithUnit));;
                            }
                        }
                    }
                    else
                    {
                        // Get nodes in the area that the AI unit could inflict a status on units from.
                        List <Node> nodesCastable = Grid.m_Instance.GetNodesWithinRadius(ss.m_CastableDistance, nodeWithUnit);

                        // Go through each of the nodes the AI unit could inflict a status from and add the status heuristic to them.
                        for (int j = 0; j < nodesCastable.Count; j++)
                        {
                            Node castNode = nodesCastable[j];

                            // Try to put a status on the healthiest unit, to get the most value.
                            float newStatusH = currentUnit.GetCurrentHealth() * aiUnit.GetHeuristicCalculator().m_StatusWeighting;
                            if (newStatusH < FindHeuristic(castNode, aiUnit)?.m_StatusValue)
                            {
                                continue;
                            }
                            else
                            {
                                if (castNode != null)
                                {
                                    AddOrUpdateHeuristic(
                                        newStatusH * Vector3.Distance(nodeWithUnit.worldPosition, castNode.worldPosition),
                                        castNode,
                                        aiUnit,
                                        new StatusSkillTarget(ss, nodeWithUnit));;
                                }
                            }
                        }
                    }
                }
            }
            // Targets Player units.
            else if (ss.targets == SkillTargets.Foes)
            {
                // If unit is a Player unit.
                if (nodeWithUnit.unit.m_Allegiance != aiUnit.GetAllegiance())
                {
                    Unit currentUnit = nodeWithUnit.unit;

                    // Get nodes in the area that the AI unit could inflict a status on units from.
                    List <Node> nodesCastable = Grid.m_Instance.GetNodesWithinRadius(ss.m_CastableDistance, nodeWithUnit);

                    // Go through each of the nodes the AI unit could inflict a status from and add the status heuristic to them.
                    for (int j = 0; j < nodesCastable.Count; j++)
                    {
                        Node castNode = nodesCastable[j];

                        // Try to put a status on the healthiest unit, to get the most value.
                        float newStatusH = currentUnit.GetCurrentHealth() * aiUnit.GetHeuristicCalculator().m_StatusWeighting;
                        if (newStatusH < FindHeuristic(castNode, aiUnit)?.m_StatusValue)
                        {
                            continue;
                        }
                        else
                        {
                            if (nodesCastable[j] != null)
                            {
                                AddOrUpdateHeuristic(
                                    newStatusH * Vector3.Distance(nodeWithUnit.worldPosition, castNode.worldPosition),
                                    castNode,
                                    aiUnit,
                                    new StatusSkillTarget(ss, nodeWithUnit));
                            }
                        }
                    }
                }
            }
        }
    }