//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); }
public void ShootFPS(AttackInstance attInst = null, Transform sp = null) { shootPoint = sp; 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(sp)); } if (type == _ShootObjectType.FPSEffect) { StartCoroutine(FPSEffectRoutine()); } }
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]; tgtList[i].ApplyEffect(attInst); } } } } else { if (hitUnit != null && hitUnit.IsCreep()) { attInstance.tgtUnit = hitUnit; hitUnit.ApplyEffect(attInstance); } } }
IEnumerator MineRoutine() { LayerMask maskTarget = 1 << LayerManager.LayerCreep(); while (true) { if (!dead && !IsInConstruction()) { Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), 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) { ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation); } Dead(); } } yield return(new WaitForSeconds(0.1f)); } }
private void AttackTargets(Collider[] targets) { if (targets.Length > 0) { List <Unit> tgtList = new List <Unit>(); for (int i = 0; i < targets.Length; i++) { Unit unit = targets[i].gameObject.GetComponent <Unit>(); if (unit && !unit.dead) { tgtList.Add(unit); } } if (tgtList.Count > 0) { for (int i = 0; i < tgtList.Count; i++) { if (tgtList[i] == target) { target.ApplyEffect(attInstance); print(attInstance.srcUnit.unitName + " attacks " + target.unitName + " with " + attInstance.damage + " damage"); } else { AttackInstance attInst = attInstance.Clone(); attInst.srcUnit = attInstance.srcUnit; attInst.tgtUnit = tgtList[i]; attInst.Process(); tgtList[i].ApplyEffect(attInst); print(attInst.srcUnit.unitName + " attacks " + attInst.tgtUnit.unitName + " with " + attInst.damage + " damage"); } } } } }
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)ObjectPoolManager.Spawn(currentWeapon.GetShootObject(), shootP.position, shootP.rotation); shootObjT.GetComponent <ShootObject>().ShootFPS(attInstance, shootP); } Recoil(currentWeapon.recoil); if (onFPSShootE != null) { onFPSShootE(); } } }
public void Shoot(AttackInstance attInst = null, Transform sp = null) { if (attInst.tgtUnit == null || attInst.tgtUnit.GetTargetT() == null) { ObjectPoolManager.Unspawn(thisObj); return; } attInstance = attInst; target = attInstance.tgtUnit; //print(attInstance.srcUnit.unitName + " attacks " + attInstance.tgtUnit.unitName + " with " + attInstance.damage + " damage"); targetPos = target.GetTargetT().position; #if Game_2D hitThreshold = Mathf.Max(.01f, target.hitThreshold); #else hitThreshold = Mathf.Max(.1f, target.hitThreshold); #endif shootPoint = sp; if (shootPoint != null) { thisT.rotation = shootPoint.rotation; } if (shootEffect != null && !target.dead) { GameObject shootEffectInstance = ObjectPoolManager.Spawn(shootEffect, thisT.position, thisT.rotation); if (shootEffectInstance) { effectSetting = shootEffectInstance.GetComponent <EffectSettings>(); if (effectSetting == null) { effectSetting = shootEffectInstance.GetComponentInChildren <EffectSettings>(); } if (effectSetting) { if (effectSetting.EffectType == EffectSettings.EffectTypeEnum.Other) { Vector3 direction = (targetPos - thisT.position).normalized; shootEffectInstance.transform.rotation = Quaternion.LookRotation(direction); } effectSetting.Target = target.GetTargetT().gameObject; SelfDeactivator selfDeactivator = shootEffectInstance.GetComponent <SelfDeactivator>(); if (selfDeactivator == null) { selfDeactivator = shootEffectInstance.AddComponent <SelfDeactivator>(); } selfDeactivator.duration = attInstance.srcUnit.CurrentStat.cooldown; } } Unit.onDestroyedE += OnTargetDestroy; } hit = false; if (Ab_Start_Holder) { AbilityManager.instance.ActivateAbility(Ab_Start_Holder.ability, attInstance.srcUnit, targetPos, target); } if (type == _ShootObjectType.Projectile) { StartCoroutine(ProjectileRoutine()); } else if (type == _ShootObjectType.Beam) { StartCoroutine(BeamRoutine()); } else if (type == _ShootObjectType.Missile) { StartCoroutine(MissileRoutine()); } else if (type == _ShootObjectType.Effect && EffectDelay > 0) { StartCoroutine(EffectRoutine()); } else { Hit(); } }
IEnumerator AOETowerRoutine() { if (CurrentStat.customMask > -1) { TargetMask = CurrentStat.customMask; } else if (targetMode == _TargetMode.Hybrid) { LayerMask mask1 = 1 << LayerManager.LayerCreep(); LayerMask mask2 = 1 << LayerManager.LayerCreepF(); TargetMask = mask1 | mask2; } else if (targetMode == _TargetMode.Air) { TargetMask = 1 << LayerManager.LayerCreepF(); } else if (targetMode == _TargetMode.Ground) { TargetMask = 1 << LayerManager.LayerCreep(); } while (true) { yield return(new WaitForSeconds(GetCooldown())); while (stunned || IsInConstruction()) { yield return(null); } Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), TargetMask); if (cols.Length > 0) { Transform soPrefab = GetShootObjectT(); if (soPrefab != null) { ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation); } //SendMessage("OnAttackTargetStarted", SendMessageOptions.DontRequireReceiver); //print("AOE attack"); for (int i = 0; i < cols.Length; i++) { Unit unit = cols[i].transform.GetComponent <Unit>(); //damage all units in its range if (unit == null && !unit.dead) { continue; } AttackInstance attInstance = new AttackInstance(); attInstance.srcUnit = this; attInstance.tgtUnit = unit; attInstance.Process(); unit.ApplyEffect(attInstance); } } else { //SendMessage("OnAttackTargetStopped", SendMessageOptions.DontRequireReceiver); //print("AOE stopped"); } } }