//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)); } }
//apply the effect to player void ApplyEffectSelf(UnitPlayer player) { //gain life if (life > 0) { GameControl.GainLife(); } //gain hit-point if (hitPoint > 0) { float hitPointGained = player.GainHitPoint(hitPoint); Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(transform.position + offsetPos, "+" + hitPointGained.ToString("f0"), new Color(0.3f, 1f, 0.3f, 1)); } //gain energy if (energy > 0) { float energyGained = player.GainEnergy(energy); Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(transform.position + offsetPos, "+" + energyGained.ToString("f0"), new Color(.3f, .3f, 1f, 1)); } //not in used if (credit > 0) { GameControl.GainCredits(credit); Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(transform.position + offsetPos, "+$" + credit.ToString("f0"), new Color(.5f, .75f, 1, 1)); } //gain score if (score > 0) { GameControl.GainScore(score); Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(transform.position + offsetPos, "+" + score.ToString("f0"), new Color(.1f, 1f, 1, 1)); } //gain ammo if (ammo != 0) { player.GainAmmo(ammoID, ammo); Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(transform.position + offsetPos, "+ammo"); } //gain exp if (exp != 0) { player.GainExp(exp); Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(transform.position + offsetPos, "+exp", new Color(1f, 1f, 1, 1)); } //gain perk currency if (perkCurrency != 0) { player.GainPerkCurrency(perkCurrency); Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0); new TextOverlay(transform.position + offsetPos, "+perk points", new Color(1f, 1f, 1, 1)); } //effects if (effectIdx >= 0) { player.ApplyEffect(Effect_DB.CloneItem(effectIdx)); } //if(effect!=null && effect.duration>0) player.ApplyEffect(effect); //gain weapon if (gainWeapon && weaponList.Count > 0) { int playerWeaponID = player.weaponList[player.weaponID].ID; int rand = randomWeapon ? Random.Range(0, weaponList.Count) : 0; if (randomWeapon && weaponList.Count > 1) { int count = 0; while (weaponList[rand].ID == playerWeaponID) { rand = Random.Range(0, weaponList.Count); count += 1; if (count > 50) { break; } } } bool replaceWeapon = weaponType == _WeaponType.Replacement; bool temporaryWeapon = weaponType == _WeaponType.Temporary; player.AddWeapon(weaponList[rand], replaceWeapon, temporaryWeapon, tempWeapDuration); } }