Ejemplo n.º 1
0
        public override bool Interract(bool isRemoted, AbstractUnit target, Vector3 positionTarget)
        {
            deltaTime += UnitLibData.deltaTime;

            bool result = false;

            if (body.isMoving)
            {
                result = Move(isRemoted, target, positionTarget);
            }

            if (deltaTime >= TickAttack)
            {
                if (target == null)
                {
                    return(result);
                }
                if (Vector3.Distance(body.GetPosition(), target.GetPosition()) <= 3)
                {
                    if (!_playingSound)
                    {
                        GameSingleton.Instance.soundManager.Play("Slash");
                    }

                    body.Attack(target, GetAttackUnit(target));
                }

                deltaTime -= TickAttack;
            }

            return(result);
        }
Ejemplo n.º 2
0
        private bool Move(bool isRemoted, AbstractUnit target, Vector3 positionTarget)
        {
            if (!isRemoted && target == null)
            {
                return(false);
            }

            int ind = 0;

            if (!isRemoted)
            {
                Entity entityTarget = GetFirstLivingEntity();
                if (entityTarget == null)
                {
                    return(false);
                }
                if (Vector3.Distance(entityTarget.transform.position, target.GetPosition()) <= 2.0f)
                {
                    Vector3 destination = TerrainGrid.Instance.GetClosestValidPosition(entityTarget.transform.position);
                    if (destination.x > -0.1f)      // if < 0 not valid
                    {
                        LockPosition(destination);
                    }
                }
            }

            bool isOnDest = false;

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    if (body.entities[ind] != null)
                    {
                        Vector3 position = positionTarget + Vector3.right * x + Vector3.forward * y;
                        if (body.entities[ind].aStarEntity.MoveTo(position, GameSingleton.Instance.aStarHandler, GetVitessUnit()))
                        {
                            body.SetPosition(positionTarget);
                            isOnDest = true;
                        }
                    }
                    ind++;
                }
            }

            return(isOnDest);
        }
Ejemplo n.º 3
0
        private bool Move(bool isRemoted, AbstractUnit target, Vector3 positionTarget)
        {
            if (!isRemoted && target == null)
            {
                return(false);
            }

            int ind = 0;

            if (!isRemoted)
            {
                Entity entityTarget = GetFirstLivingEntity();
                if (entityTarget == null)
                {
                    return(false);
                }
                if (Vector3.Distance(entityTarget.transform.position, target.GetPosition()) <= OptimalDistance)
                {
                    Vector3 destination = TerrainGrid.Instance.GetClosestValidPosition(entityTarget.transform.position);
                    if (destination.x > -0.1f)      // if < 0 not valid
                    {
                        LockPosition(destination);
                    }
                }
            }

            bool isOnDest = false;

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    if (body.entities[ind] != null)
                    {
                        Vector3 position = positionTarget + Vector3.right * x + Vector3.forward * y;
                        if (body.entities[ind].aStarEntity.MoveTo(position, GameSingleton.Instance.aStarHandler, GetVitessUnit()))
                        {
                            body.SetPosition(positionTarget);
                            isOnDest = true;
                        }
                    }
                    ind++;
                }
            }

            Vector3 bodyPos = body.GetPosition();

            if (target == null)
            {
                return(isOnDest);
            }
            Vector3 targetPos = target.GetPosition();
            float   dist      = Vector3.Distance(bodyPos, targetPos);

            if (dist >= OptimalDistance + 2f)
            {
                _canShoot = false;
            }
            else
            {
                _canShoot = true;
            }

            /*else {
             *  Vector3 last = body.GetPosition();
             *  Vector3 posTarget = target.GetPosition();
             *  if (Vector3.Distance(last, posTarget) <= OptimalDistance - 1f) {
             *      body.SetPosition(Vector3.MoveTowards(last, posTarget, -GetVitessUnit()));
             *      _canShoot = false;
             *  }
             *  else if (Vector3.Distance(last, posTarget) >= OptimalDistance + 1f) {
             *      body.SetPosition(Vector3.MoveTowards(last, posTarget, GetVitessUnit()));
             *      _canShoot = false;
             *  }
             *  else {
             *      // Ok
             *      _canShoot = true;
             *  }
             * }*/
            return(isOnDest);
        }