Example #1
0
    float damageScore(AbilitySpot damageSpot, Vector3 targetPosition)
    {
        RaycastHit2D healthCast = Physics2D.Raycast(targetPosition, Vector3.zero, 0f, ~LayerMask.NameToLayer("Object"));

        if (healthCast.collider != null && healthCast.collider.GetComponent <Health>() != null)
        {
            float damageDoneEffectiviness     = ((healthCast.collider.GetComponent <Health>().health - (healthCast.collider.GetComponent <Health>().health - damageSpot.damageValues[0])) / healthCast.collider.GetComponent <Health>().health) * 1;
            float targetKillEffectiviness     = (healthCast.collider.GetComponent <Health>().health - damageSpot.damageValues[0]) <= 0 ? 1 : 0;
            float targetStrengthEffectiviness = healthCast.collider.GetComponent <Unit>().movementAreaListed.Count + healthCast.collider.GetComponent <Unit>().damageAreaListed.Sum(spot => spot.damageValues[0]);

            newScoredAction.effectivityScore =
        }
    }
Example #2
0
    public AbilitySpot Clone()
    {
        AbilitySpot newSpot = new AbilitySpot();

        newSpot.source           = source;
        newSpot.location         = location;
        newSpot.worldLocation    = worldLocation;
        newSpot.damageValues     = damageValues;
        newSpot.damageTarget     = damageTarget;
        newSpot.distanceFromSide = distanceFromSide;
        newSpot.effectivityScore = effectivityScore;

        return(newSpot);
    }
Example #3
0
    public List <AbilitySpot> getModularDamage()
    {
        if (currentModularDamage == null)
        {
            List <AbilitySpot> combinedSpots = new List <AbilitySpot>();

            foreach (Unit unit in Object.FindObjectsOfType <Unit>())
            {
                if (unit.GetComponent <SideDefine>() != null && unit.GetComponent <SideDefine>().side == sideSettings.side)
                {
                    combinedSpots.AddRange(unit.damageAreaListed);
                }
            }

            List <AbilitySpot> collapsedCombinedSpots = new List <AbilitySpot>();

            combinedSpots.GroupBy(spot => spot.source.transform.position + spot.location).ToList().ForEach(group =>
            {
                List <int> damageValuesList = new List <int>();
                foreach (AbilitySpot spot in group)
                {
                    damageValuesList.Add(spot.damageValues[0]);
                    //group.ToList().Remove(spot)
                }

                AbilitySpot damageSpot   = new AbilitySpot(null, group.Key, damageValuesList);
                damageSpot.worldLocation = group.Key;

                collapsedCombinedSpots.Add(damageSpot);
            });

            currentModularDamage = collapsedCombinedSpots;

            return(collapsedCombinedSpots);
        }
        else
        {
            return(currentModularDamage);
        }
    }
Example #4
0
    public void doAction()
    {
        List <AbilitySpot> actions = new List <AbilitySpot>();

        foreach (AbilitySpot movementSpot in Unit_Comp.movementAreaListed)
        {
            if (Unit_Comp.checkMovable(transform.position + movementSpot.location))
            {
                ///////// score can be negative!
                //form movement score (based on distance, damagable spots next, danger damage)

                float damagableSpotsNextEffectiviness = 0;
                foreach (AbilitySpot damageSpot in Unit_Comp.damageAreaListed)
                {
                    if (Unit_Comp.checkDamagable(transform.position + movementSpot.location, (transform.position + movementSpot.location) + damageSpot.location))
                    {
                        ;
                    }
                    {
                        damageScore(damageSpot, (transform.position + movementSpot.location) + damageSpot.location);
                    }
                }
            }
        }

        foreach (AbilitySpot damageSpot in Unit_Comp.damageAreaListed)
        {
            if (Unit_Comp.checkDamagable(transform.position + damageSpot.location))
            {
                //form damage score (based on target health, damage done, will kill unit)


                damageScore(damageSpot, transform.position + damageSpot.location);
            }
        }

        if (actions.Count <= 0)
        {
            return;
        }

        /* might not work due to always danger damage
         *
         * int badActionCount = 0;
         * foreach (AbilitySpot action in actions)
         * {
         *  if (action.effectivityScore <= 0)
         *  {
         *      badActionCount++;
         *  }
         * }
         * if (badActionCount == actions.Count)
         * {
         *  return;
         * }*/

        // do good actions
        actions = actions.OrderBy(spot => spot.effectivityScore).ToList();
        AbilitySpot chosenAction = actions[Random.Range((actions.Count - (possibleActionsChosen - 1)) - 1, actions.Count)];

        if (chosenAction.damageValues.Count <= 0)
        {
            Unit_Comp.move(transform.position + chosenAction.location);
        }
        else if (chosenAction.damageValues.Count > 0)
        {
            Unit_Comp.attack(transform.position + chosenAction.location);
        }
    }
Example #5
0
    public void attack()
    {
        Debug.Log("I'm attacking!");

        List <AbilitySpot> damagableSpots = new List <AbilitySpot>();

        foreach (AbilitySpot spot in Unit_Comp.damageAreaListed)
        {
            if (Unit_Comp.checkDamagable(transform.position + spot.location))
            {
                AbilitySpot damageSpot = new AbilitySpot(this, spot.location, spot.damageValues[0]);
                damageSpot.worldLocation = transform.position + spot.location;

                RaycastHit2D enemyCast = Physics2D.Raycast(transform.position + spot.location, Vector3.zero, 0f, ~LayerMask.NameToLayer("Object"));

                /*if (enemyCast.collider != null && enemyCast.collider.GetComponent<Health>() != null)
                 * {*/
                damageSpot.damageTarget = enemyCast.collider.GetComponent <Health>();
                //}

                damagableSpots.Add(damageSpot);
            }
        }

        if (damagableSpots.Count <= 0)
        {
            Debug.Log("I cant attack?");
            return;
        }

        damagableSpots.OrderBy(spot => spot.damageTarget.health / spot.damageTarget.maxHealth).ToList();

        float lowHighAggresive_Picker = Random.Range(0f, 100f);

        if (lowHighAggresive_Picker <= Unit_Comp.lowAggressive)
        {
            //attack low health

            /*List<AbilitySpot> targetDamageSpots = new List<AbilitySpot>();
             *
             * foreach (AbilitySpot spot in damagableSpots)
             * {
             *  RaycastHit2D enemyCast = Physics2D.Raycast(spot.worldLocation, Vector3.zero, 0f, ~LayerMask.NameToLayer("Object"));
             *  if (enemyCast.collider != null && enemyCast.collider.GetComponent<Health>() != null && enemyCast.collider.GetComponent<Health>().health <= Mathf.FloorToInt(enemyCast.collider.GetComponent<Health>().maxHealth / 2))
             *  {
             *      targetDamageSpots.Add(spot);
             *  }
             * }
             *
             * if (targetDamageSpots.Count <= 0)
             * {
             *  return;
             * }
             *
             * Unit_Comp.attack(targetDamageSpots[Random.Range(0, targetDamageSpots.Count - 1)].worldLocation);*/
            Unit_Comp.attack(damagableSpots[Random.Range(0, Tools.underZero(Mathf.FloorToInt((Unit_Comp.lowAggressive / 100f) * (damagableSpots.Count - 1))) + 1)].worldLocation);
            Debug.Log("I just attacked!");
            /////////add damage and health score
        }
        else if (lowHighAggresive_Picker > Unit_Comp.lowAggressive)
        {
            //attack high health

            /*List<AbilitySpot> targetDamageSpots = new List<AbilitySpot>();
             *
             * foreach (AbilitySpot spot in damagableSpots)
             * {
             *  RaycastHit2D enemyCast = Physics2D.Raycast(spot.worldLocation, Vector3.zero, 0f, ~LayerMask.NameToLayer("Object"));
             *  if (enemyCast.collider != null && enemyCast.collider.GetComponent<Health>() != null && enemyCast.collider.GetComponent<Health>().health > Mathf.FloorToInt(enemyCast.collider.GetComponent<Health>().maxHealth / 2))
             *  {
             *      targetDamageSpots.Add(spot);
             *  }
             * }
             *
             * if (targetDamageSpots.Count <= 0)
             * {
             *  return;
             * }
             *
             * Unit_Comp.attack(targetDamageSpots[Random.Range(0, targetDamageSpots.Count - 1)].worldLocation);*/
            Unit_Comp.attack(damagableSpots[Random.Range(Mathf.CeilToInt((Unit_Comp.lowAggressive / 100f) * (damagableSpots.Count - 1)), damagableSpots.Count)].worldLocation);
            Debug.Log("I just attacked!");
            /////////add damage and health score
        }
    }