Exemplo n.º 1
0
 public AttackState(Unit unit, HitPoints target)
 {
     this.unit = unit;
     Debug.Log($"{unit.name} started attacking {target.name}.");
     this.target  = target;
     targetRadius = target.GetComponent <ObjectRadius>();
 }
Exemplo n.º 2
0
 public void Initialize(HitPoints target, float damage, float speed, Color color)
 {
     this.target = target;
     this.damage = damage;
     this.speed  = speed;
     renderer.material.SetColor("_Color", color);
 }
Exemplo n.º 3
0
        public void ShootProjectile(HitPoints target)
        {
            // TODO: Pool projectiles.
            var projectile = Instantiate(CurrentJob.projectilePrefab, transform.position, Quaternion.identity);

            projectile.Initialize(target, CurrentJob.damage, CurrentJob.projectileSpeed, UnitTeam.teamColor);
        }
Exemplo n.º 4
0
        public override void Update()
        {
            var       potentialTargets = GameController.Instance.GetEnemyTeam(unit.UnitTeam).GetAllPotentialTargets();
            HitPoints closestTarget    = null;
            var       distance         = AggroRadius;

            foreach (var potentialTarget in potentialTargets)
            {
                var monoBeh     = (MonoBehaviour)potentialTarget;
                var newDistance = Vector3.Distance(unit.transform.position, monoBeh.transform.position);
                if (newDistance > distance)
                {
                    continue;
                }
                distance      = newDistance;
                closestTarget = potentialTarget;
            }

            if (closestTarget == null)
            {
                return;
            }
            unit.AttackTarget(closestTarget);
            StopState();
        }
Exemplo n.º 5
0
 public ChaseState(Unit unit, HitPoints target, float stopDistance)
 {
     this.target       = target;
     this.stopDistance = stopDistance;
     agent             = unit.Agent;
     agent.speed       = unit.CurrentJob.movementSpeed;
     path         = new NavMeshPath();
     targetRadius = target.GetComponent <ObjectRadius>();
 }
Exemplo n.º 6
0
        public void AttackTarget(HitPoints target)
        {
            // HACK: Clearing stack to fix strange behaviour causing
            ClearMovementFromStack();
            var attackState = new AttackState(unit, target);

            attackState.OnStateFinish += (x) => StartSearchingForEnemies();
            PushNewStateHandler(attackState);
        }
Exemplo n.º 7
0
 public void Initialize(Team team, bool isFinished = false)
 {
     HitPoints          = GetComponent <HitPoints>();
     HitPoints.OnDeath += DeathHandler;
     Team            = team;
     this.isFinished = isFinished;
     foreach (var renderer in renderers)
     {
         renderer.material.SetColor("_Color", team.teamColor);
     }
     HitPoints.Initialize(maxHP);
 }
Exemplo n.º 8
0
 public void Initialize(Team team, int unitID, Color color, string playerName)
 {
     HitPoints      = GetComponent <HitPoints>();
     UnitTeam       = team;
     nameplate.text = playerName;
     IsPlayer       = string.IsNullOrEmpty(playerName) == false;
     UnitID         = unitID;
     name           = IsPlayer ? playerName : $"{team.teamName} {unitID}";
     renderer.material.SetColor("_Color", color);
     ChangeJob(defaultJob, true);
     unitBehaviour.Initialize(this);
     HitPoints.OnDeath += DeathHandler;
 }
Exemplo n.º 9
0
 public void Initialize(Team team, Building buildingPrefab, MapTile tile, TileDirection direction)
 {
     HitPoints          = GetComponent <HitPoints>();
     HitPoints.OnDeath += DeathHandler;
     Tile     = tile;
     Team     = team;
     Building = Instantiate(buildingPrefab, transform.position, Quaternion.Euler(0, (int)direction * 90, 0), transform);
     Building.Initialize(team);
     buildingPoints = 0;
     progressBar.SetProgress(buildingPoints / Building.buildingPointsCost);
     resourcesLeftToCollect = new ResourceCollection(Building.cost);
     State      = ConstructionState.GatheringResources;
     deliveries = new List <Delivery>();
     HitPoints.Initialize(maxHP);
 }
Exemplo n.º 10
0
        private IEnumerator Attack(HitPoints target)
        {
            while (target != null && target.IsAlive && target.IsInRange(transform.position, attackRadius))


            {
                if (timeSinceLastAttack < attackCooldown)
                {
                    yield return(new WaitForSeconds(attackCooldown - timeSinceLastAttack));
                }
                ShootProjectile(target);
                timeSinceLastAttack = 0;
                yield return(new WaitForSeconds(attackCooldown));
            }

            currentAttack = null;
        }
Exemplo n.º 11
0
 public void AttackTarget(HitPoints target) => unitBehaviour.AttackTarget(target);
Exemplo n.º 12
0
        private void ShootProjectile(HitPoints target)
        {
            var projectile = Instantiate(projectilePrefab, shootingOrigin.position, Quaternion.identity);

            projectile.Initialize(target, attackDamage, projectileSpeed, Team.teamColor);
        }