コード例 #1
0
ファイル: Unit.cs プロジェクト: j1mmyto9/TowerDefense
        public void ApplyEffect(AttackInstance attInstance)
        {
            if (dead)
            {
                return;
            }

            HP -= attInstance.damage;
            new TextOverlay(thisT.position, attInstance.damage.ToString("f0"), new Color(1f, 1f, 1f, 1f));

            if (onDamagedE != null)
            {
                onDamagedE(this);
            }
            if (HP <= 0)
            {
                Dead();
                return;
            }

            if (attInstance.stunned)
            {
                ApplyStun(attInstance.stun.duration);
            }
            if (attInstance.slowed)
            {
                ApplySlow(attInstance.slow);
            }
            if (attInstance.dotted)
            {
                ApplyDot(attInstance.dot);
            }
        }
コード例 #2
0
        //clone an instance
        public AttackInstance Clone()
        {
            AttackInstance attInstance = new AttackInstance();

            attInstance.processed = processed;
            attInstance.srcWeapon = srcWeapon;
            attInstance.srcUnit   = srcUnit;
            attInstance.tgtUnit   = tgtUnit;

            attInstance.missed   = missed;
            attInstance.critical = critical;
            attInstance.destroy  = destroy;

            attInstance.stunned = stunned;
            attInstance.slowed  = slowed;
            attInstance.dotted  = dotted;

            attInstance.instantKill  = instantKill;
            attInstance.breakShield  = breakShield;
            attInstance.pierceShield = pierceShield;

            attInstance.damage       = damage;
            attInstance.damageHP     = damageHP;
            attInstance.damageShield = damageShield;

            attInstance.stun = stun;
            attInstance.slow = slow;
            attInstance.dot  = dot;

            return(attInstance);
        }
コード例 #3
0
ファイル: UnitTower.cs プロジェクト: ledotrong/tower-defense
        IEnumerator MineRoutine()
        {
            LayerMask maskTarget = 1 << TDTK.GetLayerCreep();

            while (true)
            {
                if (!destroyed && !IsInConstruction())
                {
                    Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        List <Unit> targetList = TDTK.GetUnitInRange(thisT.position, GetAOERadius(), maskTarget);
                        for (int i = 0; i < targetList.Count; i++)
                        {
                            AttackInstance attInstance = new AttackInstance(this, targetList[i]);
                            attInstance.Process();
                            targetList[i].ApplyEffect(attInstance);
                        }

                        SpawnEffectObject();

                        Destroyed();
                    }
                }
                yield return(new WaitForSeconds(0.1f));
            }
        }
コード例 #4
0
        public void ShootFPS(AttackInstance attInst = null, Transform sp = null)
        {
            shootPoint = sp;
            if (shootPoint != null)
            {
                thisT.rotation = shootPoint.rotation;
            }

            ShootEffect();

            hit         = false;
            attInstance = attInst;
            if (type == _ShootObjectType.FPSProjectile)
            {
                StartCoroutine(FPSProjectileRoutine());
            }
            if (type == _ShootObjectType.FPSBeam)
            {
                StartCoroutine(FPSBeamRoutine(sp));
            }
            if (type == _ShootObjectType.FPSEffect)
            {
                StartCoroutine(FPSEffectRoutine());
            }
        }
コード例 #5
0
        public void Shoot(AttackInstance attInst=null, Transform sp=null)
        {
            if(attInst==null || attInst.tgtUnit==null){
                ObjectPoolManager.Unspawn(thisObj);
                return;
            }

            attInstance=attInst;
            target=attInstance.tgtUnit;
            targetPos=target.GetTargetT().position;
            hitThreshold=Mathf.Max(0.1f, target.hitThreshold);

            shootPoint=sp;
            if(shootPoint!=null) thisT.rotation=shootPoint.rotation;
            shootPointPos=shootPoint!=null ? shootPoint.position : thisT.position ;

            if(shootEffect!=null) ObjectPoolManager.Spawn(shootEffect, thisT.position, thisT.rotation);

            hit=false;

            if(type==_ShootObjectType.Projectile) StartCoroutine(ProjectileRoutine());
            if(type==_ShootObjectType.Beam) StartCoroutine(BeamRoutine());
            if(type==_ShootObjectType.Missile) StartCoroutine(MissileRoutine());
            if(type==_ShootObjectType.Effect) StartCoroutine(EffectRoutine());
        }
コード例 #6
0
        void Hit()
        {
            hit = true;

            if (hitEffect != null)
            {
                ObjectPoolManager.Spawn(hitEffect, targetPos, Quaternion.identity);
            }

            //thisT.position=targetPos;
            attInstance.impactPoint = targetPos;

            if (attInstance.srcUnit.GetAOERadius() > 0)
            {
                LayerMask mask = attInstance.srcUnit.GetTargetMask();

                Collider[] cols = Physics.OverlapSphere(targetPos, attInstance.srcUnit.GetAOERadius(), mask);
                if (cols.Length > 0)
                {
                    List <Unit> tgtList = new List <Unit>();
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].gameObject.GetComponent <Unit>();
                        if (!unit.dead)
                        {
                            tgtList.Add(unit);
                        }
                    }
                    if (tgtList.Count > 0)
                    {
                        for (int i = 0; i < tgtList.Count; i++)
                        {
                            if (tgtList[i] == target)
                            {
                                target.ApplyEffect(attInstance);
                            }
                            else
                            {
                                AttackInstance attInst = new AttackInstance();
                                attInst.srcUnit = attInstance.srcUnit;
                                attInst.tgtUnit = tgtList[i];
                                attInst.Process();
                                tgtList[i].ApplyEffect(attInst);
                            }
                        }
                    }
                }
            }
            else
            {
                if (target != null)
                {
                    target.ApplyEffect(attInstance);
                }
            }

            ObjectPoolManager.Unspawn(thisObj);
            //Destroy(thisObj);
        }
コード例 #7
0
ファイル: Unit.cs プロジェクト: j1mmyto9/TowerDefense
        public IEnumerator TurretRoutine()
        {
            for (int i = 0; i < shootPoints.Count; i++)
            {
                if (shootPoints[i] == null)
                {
                    shootPoints.RemoveAt(i); i -= 1;
                }
            }
            if (shootPoints.Count == 0)
            {
                shootPoints.Add(thisT);
            }

            yield return(null);

            while (true)
            {
                while (target == null || stunned || IsInConstruction() || !targetInLOS)
                {
                    yield return(null);
                }
                turretOnCooldown = true;

                float animationDelay = 0;
                if (playShootAnimation != null)
                {
                    animationDelay = playShootAnimation();
                }
                if (animationDelay > 0)
                {
                    yield return(new WaitForSeconds(animationDelay));
                }

                AttackInstance attInstance = new AttackInstance();
                attInstance.srcUnit = this;
                attInstance.tgtUnit = target;
                attInstance.Process();

                for (int i = 0; i < shootPoints.Count; i++)
                {
                    _shootTf  = (Transform)Instantiate(GetShootObjectT(), shootPoints[i].position, shootPoints[i].rotation);
                    _shootObj = _shootTf.GetComponent <ShootObject>();
                    _shootObj.Shoot(attInstance, shootPoints[i]);

                    if (delayBetweenShootPoint > 0)
                    {
                        yield return(new WaitForSeconds(delayBetweenShootPoint));
                    }
                }

                yield return(new WaitForSeconds(GetCooldown() - animationDelay - shootPoints.Count * delayBetweenShootPoint));

                turretOnCooldown = false;
            }
        }
コード例 #8
0
ファイル: UnitTower.cs プロジェクト: lusia8500/20191111
        IEnumerator AOETowerRoutine()
        {
            if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                maskTarget = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                maskTarget = 1 << LayerManager.LayerCreep();
            }

            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }

                Transform soPrefab = GetShootObjectT();
                if (soPrefab != null)
                {
                    Instantiate(soPrefab, thisT.position, thisT.rotation);
                }

                Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                if (cols.Length > 0)
                {
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].transform.GetComponent <Unit>();
                        if (unit == null && !unit.dead)
                        {
                            continue;
                        }

                        AttackInstance attInstance = new AttackInstance();
                        attInstance.srcUnit = this;
                        attInstance.tgtUnit = unit;
                        attInstance.Process();

                        unit.ApplyEffect(attInstance);
                    }
                }
            }
        }
コード例 #9
0
ファイル: ShootObject.cs プロジェクト: Yaroslavich/Scripts
        public void ShootFPS(AttackInstance attInst=null, Transform srcPoint=null)
        {
            shootPoint = srcPoint;
            if(shootPoint != null) thisT.rotation=shootPoint.rotation;

            if(shootEffect!=null) ObjectPoolManager.Spawn(shootEffect, thisT.position, thisT.rotation);

            hit=false;
            attInstance=attInst;
            if(type==_ShootObjectType.FPSProjectile) StartCoroutine(FPSProjectileRoutine());
            if(type==_ShootObjectType.FPSBeam) StartCoroutine(FPSBeamRoutine(srcPoint));
            if(type==_ShootObjectType.FPSEffect) StartCoroutine(FPSEffectRoutine());
        }
コード例 #10
0
ファイル: Unit.cs プロジェクト: LiShuJun-spec/dumingjun
        public void ApplyEffect(AttackInstance attInstance)
        {
            if (dead)
            {
                return;
            }

            if (attInstance.missed)
            {
                return;
            }

            shield -= attInstance.damageShield;
            HP     -= attInstance.damageHP;
            new TextOverlay(thisT.position, attInstance.damage.ToString("f0"), new Color(1f, 1f, 1f, 1f));

            if (onDamagedE != null)
            {
                onDamagedE(this);
            }

            currentHPStagger     = GetHPStaggerDuration();
            currentShieldStagger = GetShieldStaggerDuration();

            if (attInstance.destroy || HP <= 0)
            {
                Dead();
                return;
            }

            if (attInstance.breakShield)
            {
                fullShield = 0;
            }
            if (attInstance.stunned)
            {
                ApplyStun(attInstance.stun.duration);
            }
            if (attInstance.slowed)
            {
                ApplySlow(attInstance.slow);
            }
            if (attInstance.dotted)
            {
                ApplyDot(attInstance.dot);
            }
        }
コード例 #11
0
ファイル: Unit.cs プロジェクト: ledotrong/tower-defense
        public void ApplyEffect(AttackInstance attInstance)
        {
            if (destroyed)
            {
                return;
            }

            if (attInstance.missed)
            {
                return;
            }

            shield -= attInstance.damageShield;
            HP     -= attInstance.damageHP;
            new TextOverlay(GetTextOverlayPos(), attInstance.damage.ToString("f0"), new Color(1f, 1f, 1f, 1f));

            PlayAnimHit();

            TDTK.OnUnitDamaged(this);

            currentHPStagger     = GetHPStaggerDuration();
            currentShieldStagger = GetShieldStaggerDuration();

            if (attInstance.destroy || HP <= 0)
            {
                Destroyed();
                return;
            }

            if (attInstance.breakShield)
            {
                defaultShield = 0;
                shield        = 0;
            }
            if (attInstance.stunned)
            {
                ApplyStun(attInstance.stun.duration);
            }
            if (attInstance.slowed)
            {
                ApplySlow(attInstance.slow);
            }
            if (attInstance.dotted)
            {
                ApplyDot(attInstance.dot);
            }
        }
コード例 #12
0
        public void Shoot(AttackInstance attInst = null, Transform sp = null)
        {
            if (attInst == null || attInst.tgtUnit == null)
            {
                ObjectPoolManager.Unspawn(thisObj);
                return;
            }

            attInstance  = attInst;
            target       = attInstance.tgtUnit;
            targetPos    = target.GetTargetT().position;
            hitThreshold = Mathf.Max(0.1f, target.hitThreshold);

            shootPoint = sp;
            if (shootPoint != null)
            {
                thisT.rotation = shootPoint.rotation;
            }
            shootPointPos = shootPoint != null ? shootPoint.position : thisT.position;

            if (shootEffect != null)
            {
                ObjectPoolManager.Spawn(shootEffect, thisT.position, thisT.rotation);
            }

            hit = false;

            if (type == _ShootObjectType.Projectile)
            {
                StartCoroutine(ProjectileRoutine());
            }
            if (type == _ShootObjectType.Beam)
            {
                StartCoroutine(BeamRoutine());
            }
            if (type == _ShootObjectType.Missile)
            {
                StartCoroutine(MissileRoutine());
            }
            if (type == _ShootObjectType.Effect)
            {
                StartCoroutine(EffectRoutine());
            }
        }
コード例 #13
0
        void FPSHit(Unit hitUnit, Vector3 hitPoint)
        {
            if (attInstance.srcWeapon.GetAOERange() > 0)
            {
                LayerMask mask1 = 1 << TDTK.GetLayerCreep();
                LayerMask mask2 = 1 << TDTK.GetLayerCreepF();
                LayerMask mask  = mask1 | mask2;

                Collider[] cols = Physics.OverlapSphere(hitPoint, attInstance.srcWeapon.GetAOERange(), mask);
                if (cols.Length > 0)
                {
                    List <Unit> tgtList = new List <Unit>();
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].gameObject.GetComponent <Unit>();
                        if (!unit.IsDestroyed())
                        {
                            tgtList.Add(unit);
                        }
                    }
                    if (tgtList.Count > 0)
                    {
                        for (int i = 0; i < tgtList.Count; i++)
                        {
                            AttackInstance attInst = new AttackInstance();
                            attInst.srcWeapon = attInstance.srcWeapon;
                            attInst.tgtUnit   = tgtList[i];
                            attInst.Process();
                            tgtList[i].ApplyEffect(attInst);
                        }
                    }
                }
            }
            else
            {
                if (hitUnit != null && hitUnit.IsCreep())
                {
                    attInstance.tgtUnit = hitUnit;
                    attInstance.Process();
                    hitUnit.ApplyEffect(attInstance);
                }
            }
        }
コード例 #14
0
ファイル: UnitTower.cs プロジェクト: j1mmyto9/TowerDefense
        IEnumerator MineRoutine()
        {
            LayerMask maskTarget = 1 << LayerManager.LayerCreep();

            while (true)
            {
                if (!dead && !IsInConstruction())
                {
                    Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        Collider[] colls = Physics.OverlapSphere(thisT.position, GetAOERadius(), maskTarget);
                        for (int i = 0; i < colls.Length; i++)
                        {
                            Unit unit = colls[i].transform.GetComponent <Unit>();
                            if (unit == null && !unit.dead)
                            {
                                continue;
                            }

                            AttackInstance attInstance = new AttackInstance();
                            attInstance.srcUnit = this;
                            attInstance.tgtUnit = unit;
                            attInstance.Process();

                            unit.ApplyEffect(attInstance);
                        }

                        Transform soPrefab = GetShootObjectT();
                        if (soPrefab != null)
                        {
                            Instantiate(soPrefab, thisT.position, thisT.rotation);
                        }

                        Dead();
                    }
                }
                yield return(new WaitForSeconds(0.1f));
            }
        }
コード例 #15
0
ファイル: UnitTower.cs プロジェクト: ledotrong/tower-defense
        IEnumerator AOETowerRoutine()
        {
            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }

                List <Unit> targetList = TDTK.GetUnitInRange(thisT.position, GetRange(), maskTarget);
                for (int i = 0; i < targetList.Count; i++)
                {
                    AttackInstance attInstance = new AttackInstance(this, targetList[i]);
                    attInstance.Process();
                    targetList[i].ApplyEffect(attInstance);
                }

                SpawnEffectObject();
            }
        }
コード例 #16
0
        //clone an instance
        public AttackInstance Clone()
        {
            AttackInstance attInstance = new AttackInstance();

            attInstance.processed = processed;
            attInstance.srcUnit   = srcUnit;
            attInstance.tgtUnit   = tgtUnit;

            attInstance.critical = critical;

            attInstance.stunned = stunned;
            attInstance.slowed  = slowed;
            attInstance.dotted  = dotted;

            attInstance.damage = damage;

            attInstance.stun = stun;
            attInstance.slow = slow;
            attInstance.dot  = dot;

            return(attInstance);
        }
コード例 #17
0
ファイル: FPSControl.cs プロジェクト: ledotrong/tower-defense
        public void _Fire()
        {
            //if(!weapon.ReadyToFire()) return;

            if (currentWeapon.Shoot())
            {
                AttackInstance attInstance = new AttackInstance();
                attInstance.srcWeapon = currentWeapon;

                for (int i = 0; i < currentWeapon.shootPoints.Count; i++)
                {
                    Transform shootP    = currentWeapon.shootPoints[i];
                    Transform shootObjT = (Transform)Instantiate(currentWeapon.GetShootObject(), shootP.position, shootP.rotation);
                    shootObjT.GetComponent <ShootObject>().ShootFPS(attInstance, shootP);
                }

                Recoil(currentWeapon.recoil);

                //if(onFPSShootE!=null) onFPSShootE();
                TDTK.OnFPSShoot();
            }
        }
		public AttackInstance Clone(){
			AttackInstance attInstance=new AttackInstance();
			
			attInstance.processed=processed;
			attInstance.srcUnit=srcUnit;
			attInstance.tgtUnit=tgtUnit;
			
			attInstance.critical=critical;
			attInstance.destroy=destroy;
			
			attInstance.stunned=stunned;
			attInstance.slowed=slowed;
			attInstance.dotted=dotted;
			
			attInstance.damage=damage;
			attInstance.damageHP=damageHP;
			attInstance.damageShield=damageShield;
			
			attInstance.stun=stun;
			attInstance.slow=slow;
			attInstance.dot=dot;
			
			return attInstance;
		}
コード例 #19
0
ファイル: UnitTower.cs プロジェクト: Pringlez/Alien-Danger-TD
        IEnumerator AOETowerRoutine()
        {
            if(targetMode==_TargetMode.Hybrid){
                LayerMask mask1=1<<LayerManager.LayerCreep();
                LayerMask mask2=1<<LayerManager.LayerCreepF();
                maskTarget=mask1 | mask2;
            }
            else if(targetMode==_TargetMode.Air){
                maskTarget=1<<LayerManager.LayerCreepF();
            }
            else if(targetMode==_TargetMode.Ground){
                maskTarget=1<<LayerManager.LayerCreep();
            }

            while(true){
                yield return new WaitForSeconds(GetCooldown());

                while(stunned || IsInConstruction()) yield return null;

                Transform soPrefab=GetShootObjectT();
                if(soPrefab!=null) Instantiate(soPrefab, thisT.position, thisT.rotation);

                Collider[] cols=Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                if(cols.Length>0){
                    for(int i=0; i<cols.Length; i++){
                        Unit unit=cols[i].transform.GetComponent<Unit>();
                        if(unit==null && !unit.dead) continue;

                        AttackInstance attInstance=new AttackInstance();
                        attInstance.srcUnit=this;
                        attInstance.tgtUnit=unit;
                        attInstance.Process();

                        unit.ApplyEffect(attInstance);
                    }
                }
            }
        }
コード例 #20
0
        void Hit()
        {
            hit=true;

            if(hitEffect!=null) ObjectPoolManager.Spawn(hitEffect, targetPos, Quaternion.identity);

            //thisT.position=targetPos;
            attInstance.impactPoint=targetPos;

            if(attInstance.srcUnit.GetAOERadius()>0){
                LayerMask mask=attInstance.srcUnit.GetTargetMask();

                Collider[] cols=Physics.OverlapSphere(targetPos, attInstance.srcUnit.GetAOERadius(), mask);
                if(cols.Length>0){
                    List<Unit> tgtList=new List<Unit>();
                    for(int i=0; i<cols.Length; i++){
                        Unit unit=cols[i].gameObject.GetComponent<Unit>();
                        if(!unit.dead) tgtList.Add(unit);
                    }
                    if(tgtList.Count>0){
                        for(int i=0; i<tgtList.Count; i++){
                            if(tgtList[i]==target){
                                target.ApplyEffect(attInstance);
                                if(attInstance.destroy && destroyEffect!=null) ObjectPoolManager.Spawn(destroyEffect, targetPos, Quaternion.identity);
                            }
                            else{
                                AttackInstance attInst=new AttackInstance();
                                attInst.srcUnit=attInstance.srcUnit;
                                attInst.tgtUnit=tgtList[i];
                                attInst.Process();
                                tgtList[i].ApplyEffect(attInst);

                                if(attInst.destroy && destroyEffect!=null) ObjectPoolManager.Spawn(destroyEffect, tgtList[i].thisT.position, Quaternion.identity);
                            }
                        }
                    }
                }
            }
            else{
                if(target!=null) target.ApplyEffect(attInstance);

                if(attInstance.destroy && destroyEffect!=null) ObjectPoolManager.Spawn(destroyEffect, targetPos, Quaternion.identity);
            }

            ObjectPoolManager.Unspawn(thisObj);
            //Destroy(thisObj);
        }
コード例 #21
0
        void FPSHit(Unit hitUnit, Vector3 hitPoint)
        {
            if(attInstance.srcWeapon.GetAOERange()>0){
                LayerMask mask1=1<<LayerManager.LayerCreep();
                LayerMask mask2=1<<LayerManager.LayerCreepF();
                LayerMask mask = mask1 | mask2;

                Collider[] cols=Physics.OverlapSphere(hitPoint, attInstance.srcWeapon.GetAOERange(), mask);
                if(cols.Length>0){
                    List<Unit> tgtList=new List<Unit>();
                    for(int i=0; i<cols.Length; i++){
                        Unit unit=cols[i].gameObject.GetComponent<Unit>();
                        if(!unit.dead) tgtList.Add(unit);
                    }
                    if(tgtList.Count>0){
                        for(int i=0; i<tgtList.Count; i++){
                            AttackInstance attInst=new AttackInstance();
                            attInst.srcWeapon=attInstance.srcWeapon;
                            attInst.tgtUnit=tgtList[i];
                            attInst.Process();
                            tgtList[i].ApplyEffect(attInst);
                        }
                    }
                }
            }
            else{
                if(hitUnit!=null && hitUnit.IsCreep()){
                    attInstance.tgtUnit=hitUnit;
                    attInstance.Process();
                    hitUnit.ApplyEffect(attInstance);
                }
            }
        }
コード例 #22
0
ファイル: Unit.cs プロジェクト: toooooooo/BEER
        public IEnumerator TurretRoutine()
        {
            for (int i = 0; i < shootPoints.Count; i++)
              {
            if (shootPoints[i] == null) { shootPoints.RemoveAt(i); i -= 1; }
              }

              if (shootPoints.Count == 0)
              {
            Debug.LogWarning("ShootPoint not assigned for unit - " + unitName + ", auto assigned", this);
            shootPoints.Add(thisT);
              }

              for (int i = 0; i < stats.Count; i++)
              {
            if (stats[i].shootObjectT != null) ObjectPoolManager.New(stats[i].shootObjectT.gameObject, 3);
              }

              yield return null;

              UnitTower electricitySource;

              while (true)
              {

            // disable shooting while there is no electricity
            electricitySource = getElectricitySource(GetElectricityNeedForShoot());

            while (electricitySource == null)
            {
              // Paint deactivated towers black
              for (int i = 0; i < myRenderers.Length; i++)
              {
            myRenderers[i].material.color = new Color(0.2f, 0.2f, 0.2f);
              }

              electricitySource = getElectricitySource(GetElectricityNeedForShoot());
              yield return null;
            }

            // Restore original color
            for (int i = 0; i < myRenderers.Length; i++)
            {
              myRenderers[i].material.color = myRenderersColors[i];
            }

            // target will shoot so take that energy
            if (electricitySource != null)
              electricitySource.electricityCurrentlyStored -= GetElectricityNeedForShoot();

            while (target == null || stunned || IsInConstruction() || !targetInLOS) yield return null;

            if (!electricitySource.dead)
            {
              Unit currentTarget = target;

              float animationDelay = 0;
              if (playShootAnimation != null) animationDelay = playShootAnimation();
              if (animationDelay > 0) yield return new WaitForSeconds(animationDelay);

              AttackInstance attInstance = new AttackInstance();
              attInstance.srcUnit = this;
              attInstance.tgtUnit = currentTarget;
              attInstance.Process();

              for (int i = 0; i < shootPoints.Count; i++)
              {
            Transform sp = shootPoints[i];
            Transform objT = (Transform)Instantiate(GetShootObjectT(), sp.position, sp.rotation);
            ShootObject shootObj = objT.GetComponent<ShootObject>();
            shootObj.Shoot(attInstance, sp);

            if (delayBetweenShootPoint > 0) yield return new WaitForSeconds(delayBetweenShootPoint);
              }

              yield return new WaitForSeconds(GetCooldown() - animationDelay - shootPoints.Count * delayBetweenShootPoint);
            }

              }
        }
コード例 #23
0
ファイル: Unit.cs プロジェクト: mroslander/BoomBalls
        public IEnumerator TurretRoutine()
        {
            for(int i=0; i<shootPoints.Count; i++){
                if(shootPoints[i]==null){ shootPoints.RemoveAt(i);	i-=1;	}
            }

            if(shootPoints.Count==0){
                Debug.LogWarning("ShootPoint not assigned for unit - "+unitName+", auto assigned", this);
                shootPoints.Add(thisT);
            }

            for(int i=0; i<stats.Count; i++){
                if(stats[i].shootObjectT!=null) ObjectPoolManager.New(stats[i].shootObjectT.gameObject, 3);
            }

            yield return null;

            float t = Time.time;

            while(true){

                    while (shootingTime == 0 || target==null || stunned || IsInConstruction() || !targetInLOS) yield return null;
                turretOnCooldown=true;

                Unit currentTarget=target;

                float animationDelay=0;
                if(playShootAnimation!=null) animationDelay=playShootAnimation();
                if(animationDelay>0) yield return new WaitForSeconds(animationDelay);

                AttackInstance attInstance=new AttackInstance();
                attInstance.srcUnit=this;
                attInstance.tgtUnit=currentTarget;
                attInstance.Process();

                for(int i=0; i<shootPoints.Count; i++){
                    Transform sp=shootPoints[i];

                    Transform objT = null;
                    if (usePoolForShootObjects)
                    {
                        objT = (Transform)ObjectPoolManager.Spawn(GetShootObjectT(), sp.position, sp.rotation);
                    }
                    else
                    {
                        objT = (Transform)Instantiate(GetShootObjectT(), sp.position, sp.rotation);
                    }

                    ShootObject shootObj=objT.GetComponent<ShootObject>();
                    shootObj.Shoot(attInstance, sp);

                    if(delayBetweenShootPoint>0) yield return new WaitForSeconds(delayBetweenShootPoint);
                }

                yield return new WaitForSeconds(GetCooldown()-animationDelay-shootPoints.Count*delayBetweenShootPoint);

                if(GameControl.ResetTargetAfterShoot()) target=null;
                turretOnCooldown=false;
            }
        }
コード例 #24
0
ファイル: Unit.cs プロジェクト: tscheipel/BEER
        public IEnumerator TurretRoutine()
        {
            for (int i = 0; i < shootPoints.Count; i++)
            {
                if (shootPoints[i] == null)
                {
                    shootPoints.RemoveAt(i); i -= 1;
                }
            }

            if (shootPoints.Count == 0)
            {
                Debug.LogWarning("ShootPoint not assigned for unit - " + unitName + ", auto assigned", this);
                shootPoints.Add(thisT);
            }

            for (int i = 0; i < stats.Count; i++)
            {
                if (stats[i].shootObjectT != null)
                {
                    ObjectPoolManager.New(stats[i].shootObjectT.gameObject, 3);
                }
            }

            yield return(null);

            UnitTower electricitySource;

            while (true)
            {
                // disable shooting while there is no electricity
                electricitySource = getElectricitySource(GetElectricityNeedForShoot());

                while (electricitySource == null)
                {
                    // Paint deactivated towers black
                    for (int i = 0; i < myRenderers.Length; i++)
                    {
                        myRenderers[i].material.color = new Color(0.2f, 0.2f, 0.2f);
                    }

                    electricitySource = getElectricitySource(GetElectricityNeedForShoot());
                    yield return(null);
                }

                // Restore original color
                for (int i = 0; i < myRenderers.Length; i++)
                {
                    myRenderers[i].material.color = myRenderersColors[i];
                }

                // target will shoot so take that energy
                if (electricitySource != null)
                {
                    electricitySource.electricityCurrentlyStored -= GetElectricityNeedForShoot();
                }


                while (target == null || stunned || IsInConstruction() || !targetInLOS)
                {
                    yield return(null);
                }

                if (!electricitySource.dead)
                {
                    Unit currentTarget = target;

                    float animationDelay = 0;
                    if (playShootAnimation != null)
                    {
                        animationDelay = playShootAnimation();
                    }
                    if (animationDelay > 0)
                    {
                        yield return(new WaitForSeconds(animationDelay));
                    }

                    AttackInstance attInstance = new AttackInstance();
                    attInstance.srcUnit = this;
                    attInstance.tgtUnit = currentTarget;
                    attInstance.Process();

                    for (int i = 0; i < shootPoints.Count; i++)
                    {
                        Transform   sp       = shootPoints[i];
                        Transform   objT     = (Transform)Instantiate(GetShootObjectT(), sp.position, sp.rotation);
                        ShootObject shootObj = objT.GetComponent <ShootObject>();
                        shootObj.Shoot(attInstance, sp);

                        if (delayBetweenShootPoint > 0)
                        {
                            yield return(new WaitForSeconds(delayBetweenShootPoint));
                        }
                    }

                    yield return(new WaitForSeconds(GetCooldown() - animationDelay - shootPoints.Count * delayBetweenShootPoint));
                }
            }
        }
コード例 #25
0
ファイル: FPSControl.cs プロジェクト: mroslander/BoomBalls
        void Fire()
        {
            //if(!weapon.ReadyToFire()) return;

            if(currentWeapon.Shoot()){

                AttackInstance attInstance=new AttackInstance();
                attInstance.srcWeapon=currentWeapon;

                for(int i=0; i<currentWeapon.shootPoints.Count; i++){
                    Transform shootP=currentWeapon.shootPoints[i];
                    Transform shootObjT=(Transform)Instantiate(currentWeapon.GetShootObject(), shootP.position, shootP.rotation);
                    shootObjT.GetComponent<ShootObject>().ShootFPS(attInstance, shootP);
                }

                Recoil(currentWeapon.recoil);

                if(onFPSShootE!=null) onFPSShootE();

            }
        }
コード例 #26
0
        IEnumerator AOETowerRoutine()
        {
            if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                maskTarget = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                maskTarget = 1 << LayerManager.LayerCreep();
            }

            UnitTower electricitySource;

            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }

                // disable shooting while there is no electricity
                electricitySource = getElectricitySource(GetElectricityNeedForShoot());

                while (electricitySource == null)
                {
                    // Paint deactivated towers black
                    for (int i = 0; i < myRenderers.Length; i++)
                    {
                        myRenderers[i].material.color = new Color(0.2f, 0.2f, 0.2f);
                    }

                    electricitySource = getElectricitySource(GetElectricityNeedForShoot());
                    yield return(null);
                }

                // Restore original color
                for (int i = 0; i < myRenderers.Length; i++)
                {
                    myRenderers[i].material.color = myRenderersColors[i];
                }

                Transform soPrefab = GetShootObjectT();
                if (soPrefab != null)
                {
                    Instantiate(soPrefab, thisT.position, thisT.rotation);
                }

                Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                if (electricitySource != null && !electricitySource.dead && cols.Length > 0)
                {
                    // target will shoot so take that energy
                    electricitySource.electricityCurrentlyStored -= GetElectricityNeedForShoot();

                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].transform.GetComponent <Unit>();
                        if (unit == null && !unit.dead)
                        {
                            continue;
                        }

                        AttackInstance attInstance = new AttackInstance();
                        attInstance.srcUnit = this;
                        attInstance.tgtUnit = unit;
                        attInstance.Process();

                        unit.ApplyEffect(attInstance);
                    }
                }
            }
        }
コード例 #27
0
ファイル: Unit.cs プロジェクト: ledotrong/tower-defense
        public IEnumerator TurretRoutine()
        {
            for (int i = 0; i < shootPoints.Count; i++)
            {
                if (shootPoints[i] == null)
                {
                    shootPoints.RemoveAt(i);      i -= 1;
                }
            }

            if (shootPoints.Count == 0)
            {
                Debug.LogWarning("ShootPoint not assigned for unit - " + unitName + ", auto assigned", this);
                shootPoints.Add(thisT);
            }

            for (int i = 0; i < stats.Count; i++)
            {
                if (stats[i].shootObject != null)
                {
                    ObjectPoolManager.New(stats[i].shootObject.gameObject, 3);
                }
            }

            yield return(null);

            while (true)
            {
                while (target == null || stunned || IsInConstruction() || !targetInLOS)
                {
                    yield return(null);
                }
                turretOnCooldown = true;

                Unit currentTarget = target;

                float animationDelay = PlayAnimAttack();
                if (animationDelay > 0)
                {
                    yield return(new WaitForSeconds(animationDelay));
                }

                AttackInstance attInstance = new AttackInstance();
                attInstance.srcUnit = this;
                attInstance.tgtUnit = currentTarget;
                attInstance.Process();

                for (int i = 0; i < shootPoints.Count; i++)
                {
                    Transform sp = shootPoints[i];
                    //Transform objT=(Transform)Instantiate(GetShootObjectT(), sp.position, sp.rotation);
                    GameObject  sObj     = ObjectPoolManager.Spawn(GetShootObject().gameObject, sp.position, sp.rotation);
                    ShootObject shootObj = sObj.GetComponent <ShootObject>();
                    shootObj.Shoot(attInstance, sp);

                    if (delayBetweenShootPoint > 0)
                    {
                        yield return(new WaitForSeconds(delayBetweenShootPoint));
                    }
                }

                yield return(new WaitForSeconds(GetCooldown() - animationDelay - shootPoints.Count * delayBetweenShootPoint));

                if (GameControl.ResetTargetAfterShoot())
                {
                    target = null;
                }
                turretOnCooldown = false;
            }
        }
コード例 #28
0
ファイル: Unit.cs プロジェクト: Yaroslavich/Scripts
        public void ApplyEffect(AttackInstance attInstance)
        {
            if(dead) return;

            if(attInstance.missed) return;

            if (IsTower() && GetUnitTower().targetMode == _TargetMode.ControlObject) {
                GameControl.ControlObjectHit();
                return;
            }

            HP-=attInstance.damage;
            new TextOverlay(thisT.position, attInstance.damage.ToString("f0"), new Color(1f, 1f, 1f, 1f));

            if(onDamagedE!=null) onDamagedE(this);

            currentHPStagger=GetHPStaggerDuration();
            currentShieldStagger=GetShieldStaggerDuration();

            if(attInstance.destroy){
                Dead();
                return;
            }

            if(attInstance.dotted) ApplyDot(attInstance.dot);
        }
コード例 #29
0
ファイル: FPSControl.cs プロジェクト: Yaroslavich/Scripts
        void Fire()
        {
            if(currentWeapon.Shoot()){

                AttackInstance attInstance=new AttackInstance();
                attInstance.srcWeapon=currentWeapon;

                // из каждого ствола запускаем по снаряду
                for(int i=0; i<currentWeapon.shootPoints.Count; i++){
                    Transform shootPointTransform = currentWeapon.shootPoints[i];
                    Transform shootObjT=(Transform)Instantiate(currentWeapon.GetShootObject(), shootPointTransform.position, shootPointTransform.rotation);
                    shootObjT.GetComponent<ShootObject>().ShootFPS(attInstance, shootPointTransform);
                }

                Recoil(currentWeapon.recoil);

                if(onFPSShootE!=null) onFPSShootE();

            }
        }
コード例 #30
0
ファイル: Unit.cs プロジェクト: mroslander/BoomBalls
        public void ApplyEffect(AttackInstance attInstance)
        {
            if(dead) return;

            if(attInstance.missed) return;

            shield-=attInstance.damageShield;
            HP-=attInstance.damageHP;
            new TextOverlay(thisT.position, attInstance.damage.ToString("f0"), new Color(1f, 1f, 1f, 1f));

            if(onDamagedE!=null) onDamagedE(this);

            currentHPStagger=GetHPStaggerDuration();
            currentShieldStagger=GetShieldStaggerDuration();

            if(attInstance.destroy || HP<=0){
                Dead();
                return;
            }

            if(attInstance.breakShield) fullShield=0;
            if(attInstance.stunned) ApplyStun(attInstance.stun.duration);
            if(attInstance.slowed) ApplySlow(attInstance.slow);
            if(attInstance.dotted) ApplyDot(attInstance.dot);
        }
コード例 #31
0
ファイル: UnitTower.cs プロジェクト: toooooooo/BEER
        IEnumerator AOETowerRoutine()
        {
            if (targetMode == _TargetMode.Hybrid)
              {
            LayerMask mask1 = 1 << LayerManager.LayerCreep();
            LayerMask mask2 = 1 << LayerManager.LayerCreepF();
            maskTarget = mask1 | mask2;
              }
              else if (targetMode == _TargetMode.Air)
              {
            maskTarget = 1 << LayerManager.LayerCreepF();
              }
              else if (targetMode == _TargetMode.Ground)
              {
            maskTarget = 1 << LayerManager.LayerCreep();
              }

              UnitTower electricitySource;

              while (true)
              {
            yield return new WaitForSeconds(GetCooldown());

            while (stunned || IsInConstruction()) yield return null;

            // disable shooting while there is no electricity
            electricitySource = getElectricitySource(GetElectricityNeedForShoot());

            while (electricitySource == null)
            {
              // Paint deactivated towers black
              for (int i = 0; i < myRenderers.Length; i++)
              {
            myRenderers[i].material.color = new Color(0.2f, 0.2f, 0.2f);
              }

              electricitySource = getElectricitySource(GetElectricityNeedForShoot());
              yield return null;
            }

            // Restore original color
            for (int i = 0; i < myRenderers.Length; i++)
            {
              myRenderers[i].material.color = myRenderersColors[i];
            }

            Transform soPrefab = GetShootObjectT();
            if (soPrefab != null) Instantiate(soPrefab, thisT.position, thisT.rotation);

            Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
            if (electricitySource != null && !electricitySource.dead && cols.Length > 0)
            {
              // target will shoot so take that energy
              electricitySource.electricityCurrentlyStored -= GetElectricityNeedForShoot();

              for (int i = 0; i < cols.Length; i++)
              {
            Unit unit = cols[i].transform.GetComponent<Unit>();
            if (unit == null && !unit.dead) continue;

            AttackInstance attInstance = new AttackInstance();
            attInstance.srcUnit = this;
            attInstance.tgtUnit = unit;
            attInstance.Process();

            unit.ApplyEffect(attInstance);
              }
            }
              }
        }
コード例 #32
0
ファイル: UnitTower.cs プロジェクト: Yaroslavich/Scripts
        IEnumerator MineRoutine()
        {
            LayerMask maskTarget=1<<LayerManager.LayerCreep();
            while(true){
                if(!dead && !IsInConstruction()){
                    Collider[] cols=Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                    if(cols.Length>0){

                        Collider[] colls=Physics.OverlapSphere(thisT.position, GetAOERadius(), maskTarget);
                        for(int i=0; i<colls.Length; i++){
                            Unit unit=colls[i].transform.GetComponent<Unit>();
                            if(unit==null && !unit.dead) continue;

                            AttackInstance attInstance=new AttackInstance();
                            attInstance.srcUnit=this;
                            attInstance.tgtUnit=unit;
                            attInstance.Process();

                            unit.ApplyEffect(attInstance);
                        }

                        Transform soPrefab=GetShootObjectT();
                        if(soPrefab!=null) Instantiate(soPrefab, thisT.position, thisT.rotation);

                        Dead();
                    }
                }
                yield return new WaitForSeconds(0.1f);
            }
        }