Ejemplo n.º 1
0
    /*
     * ApplyTileTint
     * private void function
     *
     * this starts off the adding of tiles to the texture image
     *
     * @returns nothing
     */
    private void ApplyTileTint()
    {
        //first set values to default
        List <Tiles> holder2 = new List <Tiles>();

        m_notInSightTiles.Clear();
        m_sightTiles.Clear();

        //go through and gather all tiles the player can "see"
        for (int i = 0; i < m_activeplayer.units.Count; i++)
        {
            if (m_activeplayer.units[i] != null)
            {
                holder2 = GetArea.GetAreaOfAttack(map.GetTileAtPos(m_activeplayer.units[i].transform.position), (int)m_activeplayer.units[i].AOV, map);
                for (int u = 0; u < holder2.Count; u++)
                {
                    if (CheckInSightTiles(holder2[u].indexPos) == false)
                    {
                        m_sightTiles.Add(holder2[u]);
                    }
                }
            }
        }

        //set not in sight tiles to be equal to all tiles
        List <Tiles> holder = map.mapTiles;

        //in all the not in sight tiles
        for (int i = 0; i < holder.Count; i++)
        {
            m_notInSightTiles.Add(holder[i]);
        }

        //go through and remove all of the sight tiles from the not in sight tiles
        for (int i = 0; i < m_sightTiles.Count; i++)
        {
            m_notInSightTiles.Remove(m_sightTiles[i]);
        }

        //function to apply the tiles to the texture
        MakeMapTextureOfTiles();
    }
Ejemplo n.º 2
0
    /*
     * Update
     * overrides UnitCommand's Update()
     *
     * called once per frame while the command is active
     *
     * @returns void
     */
    public override void Update()
    {
        unit.hasAttacked    = true;
        unit.movementPoints = 0;

        //count-down the attack timer
        attackTimer -= Time.deltaTime;

        if (attackTimer < 0.0f)
        {
            attackTimer = 0.0f;
        }
        else
        {
            return;
        }

        //only apply the direction once
        if (!applied)
        {
            int maxDistance = Mathf.CeilToInt(attackRadius);

            //get the surrounding tiles, not considering obstacles
            List <Tiles> area = GetArea.GetAreaOfAttack(endTile, maxDistance, map);

            //get the size of the area tiles list
            int areaSize = area.Count;

            //track the amount of enemies hit
            int enemiesHit = 0;

            //iterate through all of the tiles in the area, applying damage to all
            for (int i = 0; i < areaSize; i++)
            {
                Unit defendingUnit = area[i].unit;

                //if the defending unit exists and isn't a friendly unit
                if (defendingUnit != null && defendingUnit.playerID != unit.playerID)
                {
                    //relative vector from the start to the end
                    Vector3 relative = area[i].pos - endTile.pos;

                    //manhattan distance
                    int manhattDistance = (int)(relative.x + relative.z);

                    //damage fall-off
                    float ratio = 1 - ((float)(manhattDistance) / (float)(maxDistance + 1.0f));

                    unit.Attack(defendingUnit, ratio);

                    enemiesHit++;
                }
            }
            if (unit.ArtLink != null)
            {
                unit.ArtLink.SetBool("ActionsAvailable", false);
            }

            //reset the explosion
            ParticleLibrary.explosionSystem.transform.position = endTile.transform.position;
            ParticleLibrary.explosionSystem.time = 0.0f;
            ParticleLibrary.explosionSystem.Play();

            //test if the enemies hit is higher than the most damaged in a single attack record previously
            if (unit.playerID == 0 && enemiesHit > StatisticsTracker.mostUnitsDamagedWithOneAttack)
            {
                StatisticsTracker.mostUnitsDamagedWithOneAttack = enemiesHit;
            }

            applied = true;
        }

        AnimatorStateInfo info = unit.ArtLink.GetCurrentAnimatorStateInfo(0);

        //check that the attack animation has ended
        if (info.normalizedTime >= 1.0f)
        {
            //reset the direction override
            unit.GetComponentInChildren <FaceMovement>().directionOverride = Vector3.zero;
            successCallback();
        }
    }
Ejemplo n.º 3
0
    /*
     * ExecAttack
     *
     * fuzzy function for attacking the enemy with the (most health x potential DPS)
     *
     * @param BaseInput inp - the object containing useful data that the function uses to determine what to do
     * @returns void
     */
    public void ExecAttack(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //don't do anything if the unit cannot attack
        if (minp.unit.hasAttacked)
        {
            return;
        }

        //get a list of walkable tiles around the unit
        List <Tiles> attackable = GetArea.GetAreaOfAttack(map.GetTileAtPos(minp.unit.transform.position), minp.unit.attackRange, map);

        //worst possible score to start
        float bestScore = -1.0f;

        //reference to the best tile that has been found
        Tiles bestTile = null;

        //get the size of the walkable list
        int attackSize = attackable.Count;

        //iterate through all walkable tiles
        for (int i = 0; i < attackSize; i++)
        {
            //store in a temp variable
            Tiles tile = attackable[i];

            //does the tile contain an enemy
            if (tile.unit != null)
            {
                if (tile.unit.playerID != playerID)
                {
                    //health ratio * damage per turn / max health
                    float threatScore = (tile.unit.health / tile.unit.maxHealth) * tile.unit.damage / tile.unit.maxHealth;

                    if (bestScore < threatScore)
                    {
                        //reassign the best score
                        bestTile  = tile;
                        bestScore = threatScore;
                    }
                }
            }
        }

        //attack the best tile if one is found
        if (bestTile != null)
        {
            Attack(minp.unit, bestTile.pos);
        }
        else
        {
            //get the worst threat and move towards it
            Unit  bestTarget      = null;
            float bestThreatScore = -1.0f;

            //get the size of the players list
            int playerSize = minp.manager.players.Count;

            //iterate through all players except for this one, getting the average of all enemies
            for (int i = 0; i < playerSize; i++)
            {
                //store in a temp variable
                BasePlayer bp = minp.manager.players[i];

                if (bp.playerID == playerID)
                {
                    continue;
                }

                //get the size of the player's units array
                int unitCount = bp.units.Count;

                //check for visibility and count
                for (int j = 0; j < unitCount; j++)
                {
                    if (bp.units[j].inSight)
                    {
                        //store in a temp variable
                        Unit unit = bp.units[j];

                        //the unit is in sight, consider it a threat
                        float threatScore = (unit.health / unit.maxHealth) * unit.damage;

                        //reset the score
                        if (bestThreatScore < threatScore)
                        {
                            bestTarget      = unit;
                            bestThreatScore = threatScore;
                        }
                    }
                }
            }

            if (bestTarget != null)
            {
                //don't do anything if the unit has run out of points
                if (minp.unit.movementPoints == 0)
                {
                    return;
                }

                ExecuteMovementGivenTarget(minp.unit, bestTarget.transform.position);
            }
        }
    }