示例#1
0
    //called by a support creep to buff this creep
    //~ private List<BuffStat> activeBuffList=new List<BuffStat>();
    //~ public void Buff(BuffStat newBuff){
    //~ if(activeBuffList.Contains(newBuff)) return;

    //~ activeBuffList.Add(newBuff);

    //~ damage=damage*(1+newBuff.damageBuff);
    //~ range=range*(1+newBuff.rangeBuff);
    //~ cooldown=cooldown*(1-newBuff.cooldownBuff);
    //~ if(newBuff.regenHP>0) StartCoroutine(RegenHPRoutine(newBuff));
    //~ }


    //~ //remove buff effect
    //~ public void UnBuff(int buffID){
    //~ BuffStat tempBuff;
    //~ for(int i=0; i<activeBuffList.Count; i++){
    //~ tempBuff=activeBuffList[i];
    //~ if(tempBuff.buffID==buffID){
    //~ damage=damage/(1+tempBuff.damageBuff);
    //~ range=range/(1+tempBuff.rangeBuff);
    //~ cooldown=cooldown/(1-tempBuff.cooldownBuff);

    //~ activeBuffList.RemoveAt(i);

    //~ break;
    //~ }
    //~ }
    //~ }

    //~ IEnumerator RegenHPRoutine(BuffStat buff){
    //~ while(activeBuffList.Contains(buff)){
    //~ //HPAttribute.HP=Mathf.Min(HPAttribute.fullHP, HP+);
    //~ unit.GainHP(Time.deltaTime*buff.regenHP);
    //~ yield return null;
    //~ }
    //~ }


    IEnumerator AttackRoutine()
    {
        if (shootPoint == null || shootPoint.Length == 0)
        {
            shootPoint    = new Transform[1];
            shootPoint[0] = unit.thisT;
        }
        while (true)
        {
            float delay = 0;

            if (target != null && !unit.IsStunned() && !unit.IsDead() && targetInLOS && currentClip > 0)
            {
                Vector3 targetPoint = target.GetTargetT().position;

                if (unit.PlayAttack())
                {
                    delay = aniAttackTimeOffset;
                    yield return(new WaitForSeconds(delay));
                }

                if (target != null)
                {
                    if (attackMethod == _AttackMethod.Range)
                    {
                        if (shootObject != null)
                        {
                            foreach (Transform sPoint in shootPoint)
                            {
                                GameObject  obj      = ObjectPoolManager.Spawn(shootObject, sPoint.position, sPoint.rotation);
                                ShootObject shootObj = obj.GetComponent <ShootObject>();
                                shootObj.Shoot(target, this, sPoint);
                            }
                        }
                    }
                    else if (attackMethod == _AttackMethod.Melee)
                    {
                        ApplyEffect(target);
                    }
                }
                else
                {
                    if (attackMethod == _AttackMethod.Range)
                    {
                        if (shootObject != null)
                        {
                            foreach (Transform sPoint in shootPoint)
                            {
                                GameObject  obj      = ObjectPoolManager.Spawn(shootObject, sPoint.position, sPoint.rotation);
                                ShootObject shootObj = obj.GetComponent <ShootObject>();
                                shootObj.Shoot(targetPoint, this, sPoint);
                            }
                        }
                    }
                }

                if (attackSound != null)
                {
                    AudioManager.PlaySound(attackSound, unit.thisT.position);
                }

                yield return(new WaitForSeconds(cooldown - delay));
            }
            else
            {
                //~ Debug.Log("target:"+target+"  stunned:"+unit.IsStunned()+"  targetInLOS:"+targetInLOS+"   clipSize:"+currentClip);

                if (cdTracking == _CDTracking.Precise)
                {
                    yield return(null);
                }
                else
                {
                    yield return(new WaitForSeconds(Random.Range(0, cooldown)));
                }
            }
        }
    }