Exemplo n.º 1
0
 protected override void finishPathUnit()
 {
     if (heroState == HeroState.ToCrime)
     {
         if (currentFocusedCrime.GetIsActive())
         {
             if (crimeManager.OnCrimeScene(currentTile, currentFocusedCrime.tiles))
             {
                 currentFocusedCrime.AddHeroToScene(hero);
                 SetHeroState(HeroState.Fighting);
             }
             else
             {
                 // if somehow finished on wrong tile, reroute to the actual crime tile
                 GoToTile(crimeManager.GetCrimeInRange(currentTile, currentFocusedCrime.tiles).closestTile);
             }
         }
         else
         {
             // if crime already not active, go back to patrol
             currentFocusedCrime = null;
             SetHeroState(HeroState.Patrol);
             StopPath();
         }
     }
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        MovementUpdate();

        if ((villainState == VillainState.Planning || villainState == VillainState.Fleeing) && !isMoving)
        {
            GoToTile(city.GetRandomTile());
        }
        else if (villainState == VillainState.Planning)
        {
            // if planning is complete, create new crime to travel towards and start
            if (villain.planningCounter > villain.planningTimeNeeded)
            {
                villain.planningCounter = 0f;

                Crime newCrime = crimeManager.SpawnNewVillainCrime(villain);
                currentFocusedCrime = newCrime;

                GoToTile(crimeManager.GetCrimeInRange(currentTile, newCrime.tiles).closestTile);
                SetVillainState(VillainState.ToCrime);
            }
            else
            {
                // progress planning counter if still planning
                villain.planningCounter += Time.deltaTime;
            }
        }
        else if (villainState == VillainState.Criming)
        {
            if (!currentFocusedCrime.crimeComplete)
            {
                // if got hero on scene, handle fighting
                List <Hero> targetableHeroes = currentFocusedCrime.GetTargetableHeroes();
                if (targetableHeroes.Count > 0)
                {
                    // if attack is ready
                    if (villain.nextAttackCounter > villain.attackCooldown)
                    {
                        // select random hero?
                        Hero heroToTarget = targetableHeroes [Random.Range(0, targetableHeroes.Count)];
                        unitManager.HandleUnitDamage(villain, heroToTarget);

                        villain.nextAttackCounter = 0f;
                    }
                    else
                    {
                        villain.nextAttackCounter += Time.deltaTime;
                    }
                }
                else
                {
                    // if no targetable heroes
                    return;
                }
            }
            else
            {
                // plan new crime if crime is complete
                SetVillainState(VillainState.Planning);
            }
        }
    }