Esempio n. 1
0
    private IEnumerator attackTarget(UnitBase from, UnitBase target, bool canFightBack)
    {
        from.CanOperate = false;
        yield return(from.Anim_OnAttack());

        //发射子弹
        ResManager.Get().LoadAsync <GameObject>("Prefabs/Units/Projectile/Projectile", (obj) =>
        {
            //设置起始位置
            Vector3 po             = from.transform.position;
            po.y                   = from.GetComponent <UnitBase>().Height;
            obj.transform.position = po;
            //朝向攻击目标
            obj.transform.LookAt(target.transform);
            Quaternion rotation = obj.transform.rotation;
            //将上下旋转重置为0
            rotation.x             = 0;
            obj.transform.rotation = rotation;
            //初始化子弹逻辑
            obj.GetComponent <Projectile>().Init(target.gameObject, () => {
                //子弹到达攻击目标
                target.CostHP(from.Damage);
                ResManager.Get().LoadAsync <GameObject>("Prefabs/VFX/ParticleExplosion/ParticleExplosion", (vfx) => {
                    vfx.transform.position = obj.transform.position;
                });
                target.Anim_OnDamage();
                //若对方未死亡,则回击
                if (canFightBack && target.GetHP() > 0)
                {
                    target.Attack(from, true, true);
                }
            }, 1f);
        });
    }
Esempio n. 2
0
            public override void Execute()
            {
                int      index = owner.action_queue.Dequeue();
                UnitBase unit  = owner.unit_list[index];

                unit.is_action = false;
                Debug.Log("AttackUnit:" + unit.unit_name + " attack:" + unit.current.attack);
                if (unit.is_player_unit)
                {
                    foreach (UnitBase enemy_unit in owner.unit_list)
                    {
                        if (enemy_unit.is_dead)
                        {
                            continue;
                        }
                        if (!enemy_unit.is_player_unit)
                        {
                            unit.Attack(enemy_unit);
                            break;
                        }
                    }
                }
                else
                {
                    foreach (UnitBase player_unit in owner.unit_list)
                    {
                        if (player_unit.is_dead)
                        {
                            continue;
                        }
                        if (player_unit.is_player_unit)
                        {
                            unit.Attack(player_unit);
                            break;
                        }
                    }
                }

                if (owner.action_queue.Count < 1)
                {
                    owner.ChangeState(BattleState.SetActionOrder);
                }
            }
Esempio n. 3
0
    public override void TryAttack()
    {
        gameController.selectedUnit = this;
        UnitBase unitToAttack = null;
        float    scoreToBeat  = -10;
        float    score;

        List <UnitBase> unitsAvailableForAttack = CheckAvailableAttackFromPosition(toPosition);

        foreach (UnitBase unit in unitsAvailableForAttack)
        {
            if (unit != null)
            {
                score = 0;

                //we only care about attacking friendly units
                if (unit.friendly)
                {
                    //if we can kill this unit
                    if (attackDamage >= unit.health)
                    {
                        score = 20;
                    }
                    else
                    {
                        score = 15;
                    }
                }

                if (score > scoreToBeat)
                {
                    scoreToBeat  = score;
                    unitToAttack = unit;
                }
            }
        }

        if (unitToAttack != null)
        {
            unitToAttack.Attack();
        }
    }
Esempio n. 4
0
    IEnumerator attack(UnitBase from, UnitBase target, bool canFightBack)
    {
        yield return(DT_MoveTo(from, target));

        if (target == null)
        {
            yield break;
        }
        if (from.triumph)
        {
            from.AddHP(1);
        }
        if (from.dualAttack)
        {
            yield return(DT_MoveTo(from, target));
        }
        if (target.GetHP() > 0f && canFightBack)
        {
            target.Attack(from, true, false);
        }
    }
Esempio n. 5
0
    public override void TryAttack()
    {
        gameController.selectedUnit = this;
        UnitBase unitToAttack = null;
        float    scoreToBeat  = -10;
        float    score;

        foreach (UnitBase unit in gameController.boardUnits)
        {
            if (unit != null)
            {
                if (unit.friendly)
                {
                    float distanceToUnit = Vector2.Distance(truePosition.ToVector2(), unit.truePosition.ToVector2());
                    if (distanceToUnit < 1.1f)
                    {
                        if (attackDamage >= unit.health)
                        {
                            score = 20;
                        }
                        else
                        {
                            score = 15;
                        }

                        if (score > scoreToBeat)
                        {
                            scoreToBeat  = score;
                            unitToAttack = unit;
                        }
                    }
                }
            }
        }

        if (unitToAttack != null)
        {
            unitToAttack.Attack();
        }
    }
Esempio n. 6
0
        private void AttackSelection()
        {
            if (Input.GetMouseButtonUp(0))
            {
                if (this.CastRayToWorld(GlobalSettings.LayerValues.groundLayer))
                {
                    UnitBase unit     = this.currentSelected as UnitBase;
                    UnitBase toAttack = this._hitInfo.transform.GetComponent <UnitBase>();
                    float    distance = Vector3.Distance(toAttack.position, unit.position) - (unit.unitRadius - unit.radiusDrawer.width);

                    Debug.DrawLine(unit.position, toAttack.position, Color.blue, 20.0f);
                    Debug.Log("Selection Distance: " + distance);
                    Debug.Log("Unit Attack Radius: " + unit.attackRadius);
                    Debug.Log("Unit Radius: " + unit.unitRadius);

                    if (distance > unit.attackRadius)
                    {
                        Debug.Log("Out Of Unit Attack Radius");
                        return;
                    }
                    else
                    {
                        if (toAttack.IsAlly(unit as IHasHealth))
                        {
                            Debug.Log("CAN NOT ATTACK ALLY");
                            return;
                        }
                        else
                        {
                            Debug.Log("Can Attack " + (toAttack != null ? toAttack.name : "doesn't exist"));
                            unit.Attack(toAttack as IHasHealth);
                            this.DebugText(unit, toAttack);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 private void Attack(UnitBase attacker, UnitBase target)
 {
     attacker.Attack(target);
 }