Ejemplo n.º 1
0
    protected IAttackable[] GetObjectsInMelee(MeleeAttackData data)
    {
        HashSet <IAttackable> res = new HashSet <IAttackable>();

        float dir  = (Direction == UnitDirection.Right ? 1 : -1);
        var   hits = Physics2D.OverlapBoxAll(GetMeleeHitPosition(data, dir), GetMeleeHitSize(data), 0, hitMask);

        foreach (var hit in hits)
        {
            var i  = hit.transform.GetComponent <IAttackable>();
            var cp = hit.transform.GetComponent <ColliderParent>();
            if (i == null && cp != null)
            {
                i = cp.parent.GetComponent <IAttackable>();
            }
            if (i != null && i.IsValidTarget && IsTargetInRealisticY(hit.transform.position))
            {
                if (hit.gameObject == this.gameObject)
                {
                    continue;
                }
                res.Add(i);
            }
        }
        var final = new IAttackable[res.Count];

        res.CopyTo(final);
        return(final);
    }
Ejemplo n.º 2
0
        public override ActionStatus Execute()
        {
            if (meleeAttacks.Length > 0)
            {
                int             attackIndex = Random.Range(0, meleeAttacks.Length);
                MeleeAttackData attackData  = meleeAttacks[attackIndex];
                blackboard.Set <float>(BlackboardKey.AttackRange, attackData.AttackRange);
                blackboard.Set <string>(BlackboardKey.AnimTrigger, attackData.AnimatorTrigger);
            }

            return(ActionStatus.Finished);
        }
Ejemplo n.º 3
0
    private void Attack(int index)
    {
        MeleeAttackData meleeAttack    = meleeAttacks[index];
        float           attackDistance = meleeAttack.AttackRange * meleeAttack.AttackRange;
        List <Entity>   targets        = new List <Entity>(detectionTrigger.Targets);

        foreach (Entity entity in targets)
        {
            if (entity.IsAlive)
            {
                float entityDir  = GetFacingDirection(entity.transform);
                float entityDist = GetDistance(entity.transform);
                if (entityDir > meleeAttack.DirectionThreshold && entityDist < attackDistance)
                {
                    DoDamage(entity, meleeAttack.HitClip, meleeAttack.HitEffect);
                }
            }
        }
    }
Ejemplo n.º 4
0
    public virtual IEnumerator DoAttack(MeleeAttackData attack)
    {
        float duration             = attack.clip.length;
        float timingBegin          = attack.swingBegin / duration;
        float timingTrigger        = attack.swingTrigger / duration;
        float timingReleaseControl = attack.swingReleaseControl / duration;

        duration              = duration / unit.AnimationScale;
        timingBegin          *= duration;
        timingTrigger        *= duration;
        timingReleaseControl *= duration;

        //Debug.Log(timingBegin);
        //Debug.Log(timingTrigger);
        //Debug.Log(timingReleaseControl);


        PreAttack();
        events.Emit(Events.Anim.PlayCombatAnimation, GameEvent.Create(this, attack.animationLabel));

        yield return(new WaitForSeconds(attack.swingBegin));

        events.Emit(Events.Audio.Combat_Swing);

        yield return(new WaitForSeconds(timingTrigger - timingBegin));

        if (unit.IsAlive)
        {
            var hits = GetObjectsInMelee(attack);
            foreach (var hit in hits)
            {
                hit.ReceiveAttack(UnityEngine.Random.Range(6, 12), unit);
                if (hit is Unit)
                {
                    events.Emit(Events.Audio.Combat_Connect);
                }
            }
        }

        yield return(new WaitForSeconds(timingReleaseControl - timingTrigger - timingBegin));

        PostAttack();
    }
Ejemplo n.º 5
0
    private GameObject newAttack;                  //创建的普通攻击判定



    void Start()
    {
        rb           = GetComponent <Rigidbody2D>();
        RAD          = GetComponent <RangeAttackData>();
        MAD          = GetComponent <MeleeAttackData>();
        isHang       = false;
        isDown       = false;
        isAttack     = false;
        isDodge      = false;
        isInvincible = false;
        isMagic      = false;
        canBlock     = true;
        canShoot     = true;
        lastAttack   = 0;
        //远程攻击武器初始化
        normalRangeAttack = RAD.rangeAttackWeapons[normalRangeAttackNum];
        magicRangeAttack  = RAD.rangeAttackWeapons[magicRangeAttackNum];
        //近战攻击武器初始化
        normalMeleeAttack = MAD.meleeAttackWeapons[normalMeleeAttackNum];
        magicMeleeAttack  = MAD.meleeAttackWeapons[magicMeleeAttackNum];
    }
Ejemplo n.º 6
0
 private Vector3 GetMeleeHitPosition(MeleeAttackData data, float dir)
 {
     return(transform.position + (Vector3.right * data.right * dir) + (Vector3.up * data.up));
 }
Ejemplo n.º 7
0
 private Vector2 GetMeleeHitSize(MeleeAttackData data)
 {
     return((Vector2.right * data.width) + (Vector2.up * data.height));
 }