Example #1
0
        public override void Attack(AbstractUnit anotherUnit, float damage)
        {
            int    indexEntityAttack = Random.Range(1, entityCount);
            Entity entityAttack      = GetEntity(indexEntityAttack);

            float coef          = GetEfficientCoef(this, anotherUnit);
            int   efficientCoef = GetEfficiencyType(coef);

            if (anotherUnit.GetNumberAlive() > 0)
            {
                int    indexEntityDefense = Random.Range(0, entityCount);
                Entity entityDefense      = anotherUnit.GetEntity(indexEntityDefense);

                if (entityAttack == null || entityDefense == null)
                {
                    return;
                }

                int life = entityAttack.Attack(entityDefense, (int)(-1 * entityAttack.GetStrength() * damage * coef), efficientCoef);
                if (life == 0)
                {
                    anotherUnit.PopEntity(indexEntityDefense);
                }
            }
            else if (anotherUnit.GetNumberAlive() == 0)
            {
                if (entityAttack != null)
                {
                    entityAttack.Attack(anotherUnit.GetEntity(0), -100, efficientCoef);
                    anotherUnit.PopEntity(0); // Le leader est attrapé
                    unitTarget = null;        //important pour indiquer à l'IA de commencer de nouvelles recherches
                }
            }
        }
Example #2
0
        public override void UpdateUnit()
        {
            if (!initialized)
            {
                return;
            }

            _timeLeft -= Time.deltaTime;
            if (unitTarget == null || _timeLeft <= 0)
            {
                _previousTarget = unitTarget;

                unitTarget = GuessTheBestUnitToTarget();
                if (unitTarget != _previousTarget)
                {
                    brain.UnlockPosition();
                }
            }
            else
            {
                if (!brain.positionLocked)
                {
                    targetPosition = unitTarget.GetPosition();
                    isMoving       = true;
                }
            }

            brain.Interract(false, unitTarget, targetPosition);

            UpdateTimeoutEffects();

            UpdateGameObject();
        }
Example #3
0
        protected static float GetEfficientCoef(AbstractUnit from, AbstractUnit to)
        {
            var matrixEfficient = new float[3][];

            matrixEfficient[0] = new [] { 1.0f, 1.25f, 0.75f };
            matrixEfficient[1] = new [] { 0.75f, 1.0f, 1.25f };
            matrixEfficient[2] = new [] { 1.25f, 0.75f, 1.0f };
            return(matrixEfficient[(int)from._native][(int)to._native]);
        }
Example #4
0
        public Transform SpawnUnit(EntityType unitType, AbstractUnit unit, Vector3 position)
        {
            var newUnit = Instantiate(unit, position, Quaternion.identity);

            newUnit.Init(unitType, entityDict.GetEntityType(unitType), sizeUnit);
            newUnit.SetPosition(position);
            units.Add(newUnit);
            UnitLibData.units = units;
            return(newUnit.transform);
        }
Example #5
0
        public IEnumerator AttackCoroutine(AbstractUnit attackReceiver, bool bUnitAlive)
        {
            Vector3 endPos        = attackReceiver.transform.position;
            Vector3 startPos      = transform.position;
            float   distance      = (startPos - endPos).magnitude;
            Vector3 directionNorm = (endPos - startPos).normalized;
            float   speed         = 0.3f;

            while (distance > 0.2f)
            {
                Vector3 position = transform.position;

                directionNorm = (endPos - position).normalized;
                distance      = (endPos - position).magnitude;

                transform.position += directionNorm * speed * Time.fixedDeltaTime;


                yield return(null);
            }


            if (bUnitAlive)
            {
                attackReceiver.DealDamageToHealthBar(powerLevel);
            }
            else
            {
                StartCoroutine(attackReceiver.DieCoroutine(directionNorm));
            }



            distance = (transform.position - startPos).magnitude;
            while (distance > 0.01f)
            {
                Vector3 position = transform.position;

                directionNorm = (startPos - position).normalized;
                distance      = (startPos - position).magnitude;

                transform.position += directionNorm * speed * Time.fixedDeltaTime;

                yield return(null);
            }
        }
Example #6
0
        public override void Attack(AbstractUnit anotherUnit, float damage)
        {
            int    indexEntityAttack = Random.Range(1, entityCount);
            Entity entityAttack      = GetEntity(indexEntityAttack);

            float coef          = GetEfficientCoef(this, anotherUnit);
            int   efficientCoef = GetEfficiencyType(coef);

            if (anotherUnit.GetNumberAlive() > 0)
            {
                int    indexEntityDefense = Random.Range(0, entityCount);
                Entity entityDefense      = anotherUnit.GetEntity(indexEntityDefense);

                if (entityAttack == null || entityDefense == null)
                {
                    return;
                }

                int life = entityAttack.Attack(entityDefense, (int)(-1 * entityAttack.GetStrength() * damage * coef),
                                               efficientCoef);
                if (life == 0)
                {
                    GameSingleton.Instance.GetPlayer().currentScore += (int)
                                                                       (GetEfficientCoef(this, anotherUnit) * 200f *
                                                                        anotherUnit.brain.MultiplierScore); // ajouter les types complexes
                    anotherUnit.PopEntity(indexEntityDefense);
                }
            }

            else if (anotherUnit.GetNumberAlive() == 0)
            {
                if (entityAttack != null)
                {
                    unitTarget = null; //important pour indiquer à l'IA de commencer de nouvelles recherches
                }
            }
        }
Example #7
0
 public abstract void Attack(AbstractUnit anotherUnit, float damage);
 private void Awake()
 {
     velocity = 1f;
     unit     = GetComponent <UnitController>().unit;
 }