protected bool AddTarget(Transform other, bool dontHitIfInPermTracker = true) { if (!_initialised) { return(false); } if (other.CompareTag("Enemy") || other.CompareTag("NPC") || other.CompareTag("Player")) { var baseMono = other.GetComponent <BaseCharacterMono>(); var foundTarget = !Caster.IsFriendly(baseMono.Character); if (baseMono != null && baseMono.Character.CharacterType == CharacterType.NPC) { if (!Rm_RPGHandler.Instance.Combat.NPCsCanFight) { foundTarget = false; } else if (Caster.CharacterType == CharacterType.Player) { if (!Rm_RPGHandler.Instance.Combat.CanAttackNPcs) { foundTarget = false; } else { var npcChar = baseMono.Character as NonPlayerCharacter; if (npcChar.CanBeKilled && !Rm_RPGHandler.Instance.Combat.CanAttackUnkillableNPCs) { foundTarget = false; } } } } if (foundTarget) { HandleHitOnTarget(_damage, baseMono); return(true); } } return(false); }
public DamageOutcome TakeDamage(BaseCharacter attacker, Damage damage, bool evaluateDamageToDeal = true) { if (attacker != null && attacker.IsFriendly(Character)) { return(new DamageOutcome(new Damage() { MinDamage = 0, MaxDamage = 0, ElementalDamages = new List <ElementalDamage>() }, new DamageDealt(0, new Dictionary <string, int>()), AttackOutcome.FriendlyFire, false)); } if (Character.ImmuneTo(damage.SkillMetaID)) { return(new DamageOutcome(new Damage() { MinDamage = 0, MaxDamage = 0, ElementalDamages = new List <ElementalDamage>() }, new DamageDealt(0, new Dictionary <string, int>()), AttackOutcome.Immune, false)); } Damage damageObj = null; DamageDealt damageToDeal; DamageOutcome result = null; DamageDealt damageDealt = null; result = CombatCalcEvaluator.Instance.Evaluate(attacker, Character, damage); var killedTarget = false; if (result.AttackOutcome == AttackOutcome.Success || result.AttackOutcome == AttackOutcome.Critical) { damageObj = result.DamageToDeal; damageToDeal = result.DamageDealt; if (!string.IsNullOrEmpty(damageObj.SkillMetaID)) { var susceptibility = Character.AllSusceptibilites.Where(s => s.ID == damageObj.SkillMetaID).Sum(s => s.AdditionalDamage); var multiplier = Mathf.Max(0, 1 + susceptibility); damageToDeal.ApplyMultiplier(multiplier); } if (Character is PlayerCharacter) { var difficulty = GetObject.PlayerSave.Difficulty; var diffMultiplier = Rm_RPGHandler.Instance.Player.Difficulties.FirstOrDefault(d => d.ID == difficulty); if (diffMultiplier != null) { damageToDeal.ApplyMultiplier(diffMultiplier.DamageMultiplier); } } damageDealt = damageToDeal; Health.CurrentValue -= damageDealt.Total; killedTarget = false; if (Health.CurrentValue <= 0) { Health.CurrentValue = 0; Character.Alive = false; killedTarget = true; } } //todo:enemies to player only if (Rm_RPGHandler.Instance.Combat.EnableFloatingCombatText && !(Character.CharacterMono is PlayerMono)) { var pos = Character.CharacterMono.transform; //Default damage if (result.AttackOutcome == AttackOutcome.Success || result.AttackOutcome == AttackOutcome.Critical) { if (damageDealt.Physical > 0) { var go = Object.Instantiate(_floatingCombatText, pos.position + pos.up, Quaternion.identity) as GameObject; go.GetComponent <FloatingCombatText>().SetUp(damageDealt.Physical.ToString()); } var distanceBetweenValuesconst = Rm_RPGHandler.Instance.Combat.FloatDistBetweenVals; var distanceBetweenValues = distanceBetweenValuesconst; foreach (var dmg in damageDealt.Elementals) { var eleDef = GetElement(dmg.Key); if (eleDef != null && dmg.Value > 0) { var eleGo = Object.Instantiate(_floatingCombatText, pos.position + pos.up + new Vector3(0, distanceBetweenValues, 0), Quaternion.identity) as GameObject; eleGo.GetComponent <FloatingCombatText>().SetUp(string.Format("<color={0}>{1}</color>", eleDef.Color.ToString(), dmg.Value)); distanceBetweenValues += distanceBetweenValuesconst; } } } else { if (result.AttackOutcome != AttackOutcome.FriendlyFire && result.AttackOutcome != AttackOutcome.Critical && result.AttackOutcome != AttackOutcome.Success) { var go = Object.Instantiate(_floatingCombatText, pos.position + pos.up, Quaternion.identity) as GameObject; go.GetComponent <FloatingCombatText>().SetUp(result.AttackOutcome.ToString()); } } //add delay and iterate through damages to deal > 0 that are elemental, adding more delay for each one displayed //add random X/Y pos on the floating text } return(new DamageOutcome(damageObj, damageDealt, AttackOutcome.Success, killedTarget)); }