//modify the attackStats to active effect protected AttackStats ModifyAttackStatsToExistingEffect(AttackStats aStats) { aStats.damageMin *= activeEffect.damageMul; aStats.damageMax *= activeEffect.damageMul; aStats.critChance *= activeEffect.critChanceMul; aStats.critMultiplier *= activeEffect.critMultiplierMul; return(aStats); }
//for applying force from 1 shootobject to its impact target public static void ApplyAttackForce(Vector3 impactPoint, Vector3 impactDir, GameObject hitObj, AttackStats aStats) { float impactForce=aStats.impactForce*10; if(impactForce>0){ Rigidbody rigidbody=hitObj.GetComponent<Rigidbody>(); if(rigidbody!=null) rigidbody.AddForce(impactDir*impactForce, ForceMode.Impulse); } ApplyExplosionForce(impactPoint, aStats); }
//for explosion public static void ApplyExplosionForce(Vector3 impactPoint, AttackStats aStats, bool ignorePlayer=false) { float explosionForce=aStats.explosionForce*10; float explosionRadius=explosionForce>0 ? aStats.explosionRadius : 0; if(explosionRadius>0){ LayerMask mask=ignorePlayer ? ~(1<<TDS.GetLayerPlayer()) : ~0; Collider[] cols=Physics.OverlapSphere(impactPoint, explosionRadius, mask); for(int i=0; i<cols.Length; i++){ Rigidbody rd=cols[i].gameObject.GetComponent<Rigidbody>(); if(rd!=null) rd.AddExplosionForce(explosionForce, impactPoint, explosionRadius, 0, ForceMode.Impulse); } } }
public override void OnTriggerEnter(Collider collider) { if (collider.gameObject.GetComponent <UnitPlayer>() != null) { AttackStats aStats = new AttackStats(); aStats.damageMin = damageMin; aStats.damageMax = damageMax; AttackInstance aInstance = new AttackInstance(null, aStats); collider.gameObject.GetComponent <UnitPlayer>().ApplyAttack(aInstance); //collider.gameObject.GetComponent<UnitPlayer>().GainHitPoint(-damage); Triggered(); } }
public AttackStats ModifyAttackStatsToPerk(AttackStats aStats) // { if (perk == null) { return(aStats); } aStats.damageMin *= (1 + perk.GetWeaponDamageMul(ID)); aStats.damageMax *= (1 + perk.GetWeaponDamageMul(ID)); aStats.critChance *= (1 + perk.GetWeaponCritMul(ID)); aStats.critMultiplier *= (1 + perk.GetWeaponCritMulMul(ID)); aStats.aoeRadius *= (1 + perk.GetWeaponAOEMul(ID)); return(aStats); }
protected AttackStats ModifyAttackStatsToLevel(AttackStats aStats) { if (progress == null) { return(aStats); } float dmgMul = GetDamageMultiplier(); aStats.damageMin *= dmgMul; aStats.damageMax *= dmgMul; aStats.critChance *= GetCritChanceMultiplier(); aStats.critMultiplier *= GetCritMulMultiplier(); return(aStats); }
//for explosion public static void ApplyExplosionForce(Vector3 impactPoint, AttackStats aStats, bool ignorePlayer = false) { float explosionForce = aStats.explosionForce * 10; float explosionRadius = explosionForce > 0 ? aStats.explosionRadius : 0; if (explosionRadius > 0) { LayerMask mask = ignorePlayer ? ~(1 << TDS.GetLayerPlayer()) : ~0; Collider[] cols = Physics.OverlapSphere(impactPoint, explosionRadius, mask); for (int i = 0; i < cols.Length; i++) { Rigidbody rd = cols[i].gameObject.GetComponent <Rigidbody>(); if (rd != null) { rd.AddExplosionForce(explosionForce, impactPoint, explosionRadius, 0, ForceMode.Impulse); } } } }
public AttackStats Clone() { AttackStats stats=new AttackStats(); stats.damageMin=damageMin; stats.damageMax=damageMax; stats.aoeRadius=aoeRadius; stats.dimishingAOE=dimishingAOE; stats.critChance=critChance; stats.critMultiplier=critMultiplier; stats.impactForce=impactForce; stats.explosionRadius=explosionRadius; stats.explosionForce=explosionForce; stats.effectID=effectID; stats.effect=effect!=null ? effect.Clone() : null; return stats; }
public AttackStats Clone() { AttackStats stats = new AttackStats(); stats.damageMin = damageMin; stats.damageMax = damageMax; stats.aoeRadius = aoeRadius; //stats.dimishingAOE=dimishingAOE; stats.diminishingAOE = diminishingAOE; stats.critChance = critChance; stats.critMultiplier = critMultiplier; stats.impactForce = impactForce; stats.explosionRadius = explosionRadius; stats.explosionForce = explosionForce; stats.effectID = effectID; stats.effectIdx = effectIdx; //stats.effect=effect!=null ? effect.Clone() : null; return(stats); }
//modify the attackStats to active effect protected AttackStats ModifyAttackStatsToExistingEffect(AttackStats aStats) { aStats.damageMin*=activeEffect.damageMul; aStats.damageMax*=activeEffect.damageMul; aStats.critChance*=activeEffect.critChanceMul; aStats.critMultiplier*=activeEffect.critMultiplierMul; return aStats; }
//not in used, wip /* * protected Vector2 DrawAttackStats(string propertyName, float startX, float startY, SerializedObject aStats, bool showAOE=true, bool showPhysics=true, string label="Attack Stats"){ * * EditorGUI.LabelField(new Rect(startX, startY, width+50, height), label, headerStyle); startY+=spaceY; * * string pf="attackStats."; * //SerializedProperty spas= aStats.FindProperty("attackStats"); * SerializedProperty spas= aStats.FindProperty(propertyName); * string lbSp=" - "; * * cont=new GUIContent(lbSp+"Damage Type:", "The damage type of the unit\nDamage type can be configured in Damage Armor Table Editor"); * EditorGUI.LabelField(new Rect(startX, startY, width, height), cont); * if(damageTypeLabel.Length>0){ * srlPpt=spas.FindPropertyRelative("damageType"); * EditorGUI.showMixedValue=srlPpt.hasMultipleDifferentValues; * //Debug.Log(srlPpt.intValue+" "+srlPpt.hasMultipleDifferentValues); * EditorGUI.BeginChangeCheck(); * int value=EditorGUI.Popup(new Rect(startX+spaceX, startY, width, height), srlPpt.intValue, damageTypeLabel); * if(EditorGUI.EndChangeCheck()) srlPpt.intValue=value; * EditorGUI.showMixedValue=false; * * //aStats.damageType=EditorGUI.Popup(new Rect(startX+spaceX, startY, width, height), aStats.damageType, damageTypeLabel); * } * else{ * if(GUI.Button(new Rect(startX+spaceX, startY, 83, height-2), "Add Type")) DamageTableEditorWindow.Init(); * } * * cont=new GUIContent(lbSp+"Damage (Min/Max):", "Damage value done to the target's hit-point."); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"damageMin"), contN); * EditorGUI.PropertyField(new Rect(startX+spaceX+42, startY, 40, height), aStats.FindProperty(pf+"damageMax"), contN); * * startY+=10; * * if(showAOE){ * cont=new GUIContent(lbSp+"AOE Radius:", "Area of effect radius of the attack. Any hostile unit within the area is affected by the attack"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"aoeRadius"), contN); * * cont=new GUIContent(lbSp+"Diminishing AOE22:", "Check if damage value diminished the further away the target is from the center of the aoe"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * if(aStats.FindProperty(pf+"aoeRadius").floatValue>0) * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"diminishingAOE")); * else EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); * * startY+=10; * } * * cont=new GUIContent(lbSp+"Critical Chance:", "The chance of the attack to score a critical. Takes value from 0-1 with 0.3 being 30% to score a critical"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"critChance"), contN); * * cont=new GUIContent(lbSp+"Critical Multiplier:", "The multiplier to be applied to damage if the attack scores a critical.\n - 1.5 for 150% of normal damage, 2 for 200% and so on"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"critChance"), contN); * if(aStats.FindProperty(pf+"critChance").floatValue>0) * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"critMultiplier"), contN); * else EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); * * startY+=10; * * if(showPhysics){ * cont=new GUIContent(lbSp+"Impact Force:", "If the attack will applies a knock back force to the target\nOnly applies if the attack is a direct hit from a shoot object"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"impactForce"), contN); * * cont=new GUIContent(lbSp+"Explosion Radius:", "The radius in which all unit is affected by explosion force"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"explosionRadius"), contN); * * cont=new GUIContent(lbSp+"Explosion Force:", "The force of the explosion which pushes all affect unit away from the impact point"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); * if(aStats.FindProperty(pf+"explosionRadius").floatValue>0) * EditorGUI.PropertyField(new Rect(startX+spaceX, startY, 40, height), aStats.FindProperty(pf+"explosionRadius"), contN); * else EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); * } * * startY+=30; * * srlPpt=aStats.FindProperty(pf+"effectID"); * EditorGUI.showMixedValue=srlPpt.hasMultipleDifferentValues; * int effectIdx=srlPpt.intValue>=0 ? TDSEditor.GetEffectIndex(srlPpt.intValue) : 0 ; * * if(!srlPpt.hasMultipleDifferentValues) * TDSEditorUtility.DrawSprite(new Rect(startX+spaceX+width-40, startY+spaceY-45, 40, 40), effectIdx>0 ? effectDB.effectList[effectIdx-1].icon : null); * if(GUI.Button(new Rect(startX+spaceX, startY-2, 40, height-2), "Edit")) EffectEditorWindow.Init(); * * cont=new GUIContent(lbSp+"Attack Effect:", "Special effect that applies with each hit (optional)"); * EditorGUI.LabelField(new Rect(startX, startY+=spaceY-5, width, height), cont); * * EditorGUI.BeginChangeCheck(); * effectIdx=EditorGUI.Popup(new Rect(startX+spaceX, startY, width, height), effectIdx, effectLabel); * if(EditorGUI.EndChangeCheck()){ * if(effectIdx>0) srlPpt.intValue=effectDB.effectList[effectIdx-1].ID; * else srlPpt.intValue=-1; * } * EditorGUI.showMixedValue=false; * * return new Vector2(startX, startY); * } */ protected Vector2 DrawAttackStats1(float startX, float startY, AttackStats aStats, bool showAOE = true, bool showPhysics = true, string label = "Attack Stats") { EditorGUI.LabelField(new Rect(startX, startY, width + 50, height), label, headerStyle); startY += spaceY; string lbSp = " - "; cont = new GUIContent(lbSp + "Damage Type:", "The damage type of the unit\nDamage type can be configured in Damage Armor Table Editor"); EditorGUI.LabelField(new Rect(startX, startY, width, height), cont); if (damageTypeLabel.Length > 0) { aStats.damageType = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), aStats.damageType, damageTypeLabel); } else { if (GUI.Button(new Rect(startX + spaceX, startY, 83, height - 2), "Add Type")) { DamageTableEditorWindow.Init(); } } cont = new GUIContent(lbSp + "Damage (Min/Max):", "Damage value done to the target's hit-point."); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); aStats.damageMin = EditorGUI.FloatField(new Rect(startX + spaceX, startY, 40, height), aStats.damageMin); aStats.damageMax = EditorGUI.FloatField(new Rect(startX + spaceX + 42, startY, 40, height), aStats.damageMax); startY += 10; if (showAOE) { cont = new GUIContent(lbSp + "AOE Radius:", "Area of effect radius of the attack. Any hostile unit within the area is affected by the attack"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); aStats.aoeRadius = EditorGUI.FloatField(new Rect(startX + spaceX, startY, 40, height), aStats.aoeRadius); //used in pre-version1.2, dimishingAOE is wrongly spelt //cont=new GUIContent(lbSp+"Diminishing AOE:", "Check if damage value diminished the further away the target is from the center of the aoe"); //EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); //if(aStats.aoeRadius>0) aStats.dimishingAOE=EditorGUI.Toggle(new Rect(startX+spaceX, startY, 40, height), aStats.dimishingAOE); //else EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); cont = new GUIContent(lbSp + "Diminishing AOE:", "Check if damage value diminished the further away the target is from the center of the aoe"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (aStats.aoeRadius > 0) { aStats.diminishingAOE = EditorGUI.Toggle(new Rect(startX + spaceX, startY, 40, height), aStats.diminishingAOE); } else { EditorGUI.LabelField(new Rect(startX + spaceX, startY, 40, height), "-"); } startY += 10; } cont = new GUIContent(lbSp + "Critical Chance:", "The chance of the attack to score a critical. Takes value from 0-1 with 0.3 being 30% to score a critical"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); aStats.critChance = EditorGUI.FloatField(new Rect(startX + spaceX, startY, 40, height), aStats.critChance); cont = new GUIContent(lbSp + "Critical Multiplier:", "The multiplier to be applied to damage if the attack scores a critical.\n - 1.5 for 150% of normal damage, 2 for 200% and so on"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (aStats.critChance > 0) { aStats.critMultiplier = EditorGUI.FloatField(new Rect(startX + spaceX, startY, 40, height), aStats.critMultiplier); } else { EditorGUI.LabelField(new Rect(startX + spaceX, startY, 40, height), "-"); } startY += 10; if (showPhysics) { cont = new GUIContent(lbSp + "Impact Force:", "If the attack will applies a knock back force to the target\nOnly applies if the attack is a direct hit from a shoot object"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); aStats.impactForce = EditorGUI.FloatField(new Rect(startX + spaceX, startY, 40, height), aStats.impactForce); cont = new GUIContent(lbSp + "Explosion Radius:", "The radius in which all unit is affected by explosion force"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); aStats.explosionRadius = EditorGUI.FloatField(new Rect(startX + spaceX, startY, 40, height), aStats.explosionRadius); cont = new GUIContent(lbSp + "Explosion Force:", "The force of the explosion which pushes all affect unit away from the impact point"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (aStats.explosionRadius > 0) { aStats.explosionForce = EditorGUI.FloatField(new Rect(startX + spaceX, startY, 40, height), aStats.explosionForce); } else { EditorGUI.LabelField(new Rect(startX + spaceX, startY, 40, height), "-"); } } startY += 30; int effectIdx = aStats.effectID >= 0 ? TDSEditor.GetEffectIndex(aStats.effectID) : 0; TDSEditorUtility.DrawSprite(new Rect(startX + spaceX + width - 40, startY + spaceY - 45, 40, 40), effectIdx > 0 ? effectDB.effectList[effectIdx - 1].icon : null); if (GUI.Button(new Rect(startX + spaceX, startY - 2, 40, height - 2), "Edit")) { EffectEditorWindow.Init(); } cont = new GUIContent(lbSp + "Attack Effect:", "Special effect that applies with each hit (optional)"); EditorGUI.LabelField(new Rect(startX, startY += spaceY - 5, width, height), cont); effectIdx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), effectIdx, effectLabel); if (effectIdx > 0) { aStats.effectID = effectDB.effectList[effectIdx - 1].ID; } else { aStats.effectID = -1; } return(new Vector2(startX, startY)); }
public AttackStats aStats; //contain all the stats //create a new attackInstance, given the AttackStats (the set of stats for the attack unit or ability) public AttackInstance(Unit src = null, AttackStats aSt = null) { srcUnit = src; aStats = aSt; }
//applies the effect of an attack public void ApplyAttack(AttackInstance attInstance) { if (immunityCounter > 0) { return; } //if unit is invincible, do nothing if (IsInvincible()) { Debug.Log("Immuned"); Vector3 osPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(thisT.position + osPos, "Immuned"); return; } AttackStats aStats = attInstance.aStats; //check if the attack is an aoe and modify the damage value is dimishingAOE is enabled float damage = Random.Range(aStats.damageMin, aStats.damageMax); if (attInstance.isAOE && aStats.diminishingAOE) { damage *= Mathf.Clamp(1 - attInstance.aoeDistance / aStats.aoeRadius, 0, 1); } //check for cirtical and modify the damage based on critical multiplier bool critical = Random.value < aStats.critChance; if (critical) { damage *= aStats.critMultiplier; } //modify the damage based on damage and armor type damage *= DamageTable.GetModifier(armorType, aStats.damageType); //if damage is valid, modify the hit point if (damage > 0) { //show the overlay (for UI) Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); if (!critical) { new TextOverlay(thisT.position + offsetPos, damage.ToString("f0")); } else { new TextOverlay(thisT.position + offsetPos, damage.ToString("f0"), new Color(1f, 0.9f, 0.9f, 1f), 1.5f); } //if the unit is player, fire event to inform UI if (thisObj.layer == TDS.GetLayerPlayer()) { TDS.PlayerDamaged(damage); } //register the stagger hpRegenStaggerCounter = hpRegenStagger; hitPoint -= damage; //damage the hitpoint if (hitPoint <= 0) { Destroyed(attInstance.GetSrcPlayer()); } if (hitPoint > 0 && uAnimation != null) { uAnimation.Hit(); } } //apply effect if there's any //if(aStats.effect!=null) ApplyEffect(aStats.effect); if (hitPoint > 0 && aStats.effectIdx >= 0) { ApplyEffect(Effect_DB.CloneItem(aStats.effectIdx)); } }
protected Vector2 DrawAttackStats(float startX, float startY, AttackStats aStats, bool showAOE=true, bool showPhysics=true, string label="Attack Stats") { EditorGUI.LabelField(new Rect(startX, startY, width+50, height), label, headerStyle); startY+=spaceY; string lbSp=" - "; cont=new GUIContent(lbSp+"Damage Type:", "The damage type of the unit\nDamage type can be configured in Damage Armor Table Editor"); EditorGUI.LabelField(new Rect(startX, startY, width, height), cont); if(damageTypeLabel.Length>0) aStats.damageType=EditorGUI.Popup(new Rect(startX+spaceX, startY, width, height), aStats.damageType, damageTypeLabel); else{ if(GUI.Button(new Rect(startX+spaceX, startY, 83, height-2), "Add Type")) DamageTableEditorWindow.Init(); } cont=new GUIContent(lbSp+"Damage (Min/Max):", "Damage value done to the target's hit-point."); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); aStats.damageMin=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), aStats.damageMin); aStats.damageMax=EditorGUI.FloatField(new Rect(startX+spaceX+42, startY, 40, height), aStats.damageMax); startY+=10; if(showAOE){ cont=new GUIContent(lbSp+"AOE Radius:", "Area of effect radius of the attack. Any hostile unit within the area is affected by the attack"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); aStats.aoeRadius=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), aStats.aoeRadius); cont=new GUIContent(lbSp+"Diminishing AOE:", "Check if damage value diminished the further away the target is from the center of the aoe"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); if(aStats.aoeRadius>0) aStats.dimishingAOE=EditorGUI.Toggle(new Rect(startX+spaceX, startY, 40, height), aStats.dimishingAOE); else EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); startY+=10; } cont=new GUIContent(lbSp+"Critical Chance:", "The chance of the attack to score a critical. Takes value from 0-1 with 0.3 being 30% to score a critical"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); aStats.critChance=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), aStats.critChance); cont=new GUIContent(lbSp+"Critical Multiplier:", "The multiplier to be applied to damage if the attack scores a critical.\n - 1.5 for 150% of normal damage, 2 for 200% and so on"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); if(aStats.critChance>0) aStats.critMultiplier=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), aStats.critMultiplier); else EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); startY+=10; if(showPhysics){ cont=new GUIContent(lbSp+"Impact Force:", "If the attack will applies a knock back force to the target\nOnly applies if the attack is a direct hit from a shoot object"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); aStats.impactForce=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), aStats.impactForce); cont=new GUIContent(lbSp+"Explosion Radius:", "The radius in which all unit is affected by explosion force"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); aStats.explosionRadius=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), aStats.explosionRadius); cont=new GUIContent(lbSp+"Explosion Force:", "The force of the explosion which pushes all affect unit away from the impact point"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); if(aStats.explosionRadius>0) aStats.explosionForce=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), aStats.explosionForce); else EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-"); } startY+=30; int effectIdx=aStats.effectID>=0 ? TDSEditor.GetEffectIndex(aStats.effectID) : 0 ; TDSEditorUtility.DrawSprite(new Rect(startX+spaceX+width-40, startY+spaceY-45, 40, 40), effectIdx>0 ? effectDB.effectList[effectIdx-1].icon : null); if(GUI.Button(new Rect(startX+spaceX, startY-2, 40, height-2), "Edit")) EffectEditorWindow.Init(); cont=new GUIContent(lbSp+"Attack Effect:", "Special effect that applies with each hit (optional)"); EditorGUI.LabelField(new Rect(startX, startY+=spaceY-5, width, height), cont); effectIdx=EditorGUI.Popup(new Rect(startX+spaceX, startY, width, height), effectIdx, effectLabel); if(effectIdx>0) aStats.effectID=effectDB.effectList[effectIdx-1].ID; else aStats.effectID=-1; return new Vector2(startX, startY); }
public bool isAOE = false; //marked if the attack is AOE #endregion Fields #region Constructors //create a new attackInstance, given the AttackStats (the set of stats for the attack unit or ability) public AttackInstance(Unit src=null, AttackStats aSt=null) { aStats=aSt; }
IEnumerator ShootRoutine(ShootObject.AimInfo aimInfo = null) { if (uAnimation != null) { uAnimation.AttackRange(); } AttackStats aStats = ModifyAttackStatsToLevel(weaponList[weaponID].GetRuntimeAttackStats()); aStats = ModifyAttackStatsToExistingEffect(aStats); //aStats=ModifyAttackStatsToExistingEffect(weaponList[weaponID].GetRuntimeAttackStats()); AttackInstance aInstance = new AttackInstance(this, aStats); int weapID = weaponID; //to prevent weapon switch and state change while delay and firing multiple so int spread = weaponList[weapID].spread; if (spread > 1) { aInstance.aStats.damageMin /= spread; aInstance.aStats.damageMax /= spread; } float startAngle = spread > 1 ? -weaponList[weapID].spreadAngle / 2f : 0; float angleDelta = spread > 1 ? weaponList[weapID].spreadAngle / (spread - 1) : 0; List <Collider> soColliderList = new List <Collider>(); //colliders of all the so fired, used to tell each so to ignore each other for (int i = 0; i < weaponList[weapID].shootPointList.Count; i++) { Transform shootPoint = weaponList[weapID].shootPointList[i]; float recoilSign = (Random.value < recoilSignTH ? -1 : 1); recoilSignTH = Mathf.Clamp(recoilSignTH + (recoilSign > 0 ? 0.25f : -0.25f), 0, 1); float recoilValue = recoilSign * Random.Range(0.1f, 1f) * GetRecoil(); Quaternion baseShootRot = shootPoint.rotation * Quaternion.Euler(0, recoilValue, 0); for (int m = 0; m < Mathf.Max(1, spread); m++) { Vector3 shootPos = shootPoint.position; if (spread > 1) { shootPos = shootPoint.TransformPoint(new Vector3(0, 0, Random.Range(-1.5f, 1.5f))); } Quaternion shootRot = baseShootRot * Quaternion.Euler(0, startAngle + (m * angleDelta), 0); //GameObject soObj=(GameObject)Instantiate(weaponList[weapID].shootObject, shootPos, shootRot); GameObject soObj = ObjectPoolManager.Spawn(weaponList[weapID].shootObject, shootPos, shootRot); ShootObject soInstance = soObj.GetComponent <ShootObject>(); soInstance.IgnoreCollider(GetCollider()); for (int n = 0; n < soColliderList.Count; n++) { soInstance.IgnoreCollider(soColliderList[n]); } if (soInstance.GetCollider() != null) { soColliderList.Add(soInstance.GetCollider()); } soInstance.Shoot(thisObj.layer, GetRange(), shootPoint, aInstance.Clone(), aimInfo); //soInstance.Shoot(thisObj.layer, GetRange(), shootPoint, aInstance.Clone(), hit); } TDS.CameraShake(weaponList[weapID].recoilCamShake); if (weaponList[weapID].shootPointDelay > 0) { yield return(new WaitForSeconds(weaponList[weapID].shootPointDelay)); } if (weapID >= weaponList.Count) { break; } } }
//for applying force from 1 shootobject to its impact target public static void ApplyAttackForce(Vector3 impactPoint, Vector3 impactDir, GameObject hitObj, AttackStats aStats) { float impactForce = aStats.impactForce * 10; if (impactForce > 0) { Rigidbody rigidbody = hitObj.GetComponent <Rigidbody>(); if (rigidbody != null) { rigidbody.AddForce(impactDir * impactForce, ForceMode.Impulse); } } ApplyExplosionForce(impactPoint, aStats); }