private void OnDealDamage_UCE_Elements(Entity target, UCE_ElementTemplate element, int damageDealt, MutableWrapper <int> damageBonus) { if (target == null || element == null || damageDealt <= 0) { return; } damageBonus.Value += (int)(damageDealt * target.UCE_CalculateElementalResistance(element)); }
public float GetResistance(UCE_ElementTemplate element) { if (elementalResistances.Any(x => x.template == element)) { return(elementalResistances.FirstOrDefault(x => x.template == element).value); } else { return(0); } }
// ----------------------------------------------------------------------------------- // UCE_CalculateElementalResistance // ----------------------------------------------------------------------------------- public virtual float UCE_CalculateElementalResistance(UCE_ElementTemplate element, bool bCache = true) { float fResistance = 1.0f; // 1.0f = 100% damage by default float fValue = 0f; UCE_ElementCache elementCache = null; // -- Check Caching if (bCache && _elementsCache.TryGetValue(element.name, out elementCache) && Time.time < elementCache.timer) { return(elementCache.value); } // ------------------------------- Calculation ----------------------------------- // -- Bonus: Base Resistance float fBase = fResistance; // 1.0f = 100% damage by default foreach (LevelBasedElement ele in elementalResistances) { if (ele.template == element) { fBase += ele.Get(level); } } // -- Bonus: Passive Skills float fPassiveBonus = (from skill in skills where skill.level > 0 && skill.data is PassiveSkill select((PassiveSkill)skill.data).GetResistance(element, skill.level)).Sum(); // -- Bonus: Buffs float fBuffBonus = buffs.Sum(buff => buff.GetResistance(element)); fValue = fResistance - (fBase + fPassiveBonus + fBuffBonus); // ----------------------------- Calculation End --------------------------------- // -- Update Caching if (bCache && elementCache != null) { elementCache.timer = Time.time + cacheTimerInterval; elementCache.value = fValue; _elementsCache[element.name] = elementCache; } else if (bCache) { elementCache = new UCE_ElementCache(); elementCache.timer = Time.time + cacheTimerInterval; elementCache.value = fValue; _elementsCache.Add(element.name, elementCache); } return(fValue); }
// ----------------------------------------------------------------------------------- // setBonusElementComplete // ----------------------------------------------------------------------------------- #if _iMMOELEMENTS public float setBonusElementComplete(ItemSlot slot, SyncListItemSlot equipment, UCE_ElementTemplate element) { float fPoints = 0; // -- Complete Bonus (Applied Once) if (slot.amount > 0 && UCE_hasCompleteSetBonus() && UCE_validCompleteSetBonus(equipment)) { foreach (UCE_ElementModifier modifier in ((EquipmentItem)data).equipmentSet.completeStatModifiers.elementalResistances) { if (modifier.template == element) { fPoints += modifier.value; break; } } } return(fPoints); }
// ----------------------------------------------------------------------------------- // UpdateElements // ----------------------------------------------------------------------------------- #if _iMMOELEMENTS protected void UpdateElements() { Player player = Player.localPlayer; if (!player) { return; } UIUtils.BalancePrefabs(slotElementPrefab.gameObject, UCE_ElementTemplate.dict.Count, elementsContent); for (int i = 0; i < UCE_ElementTemplate.dict.Count; ++i) { UCE_UI_ElementSlot slot2 = elementsContent.GetChild(i).GetComponent <UCE_UI_ElementSlot>(); UCE_ElementTemplate ele = UCE_ElementTemplate.dict.Values.ElementAt(i); float points = 1.0f - player.UCE_CalculateElementalResistance(ele); slot2.tooltip.enabled = true; slot2.tooltip.text = ele.toolTip; slot2.image.sprite = ele.image; slot2.label.text = ele.name + ":"; slot2.points.text = (points * 100).ToString("F0") + "%"; } }
// GetResistance public float GetResistance(UCE_ElementTemplate element, int level) { return(elementalResistances.FirstOrDefault(x => x.template == element).Get(level)); }
// ----------------------------------------------------------------------------------- // OnDealDamage_UCE_Elements // ----------------------------------------------------------------------------------- public override float UCE_CalculateElementalResistance(UCE_ElementTemplate element, bool bCache = true) { float fValue = 0f; UCE_ElementCache elementCache = null; // -- Check Caching if (_elementsCache != null) { _elementsCache.TryGetValue(element.name, out elementCache); } if (bCache && elementCache != null && Time.time < elementCache.timer) { return(elementCache.value); } // ------------------------------- Calculation ----------------------------------- // -- Bonus: Base Resistance float fResistance = base.UCE_CalculateElementalResistance(element, false); // -- Bonus: Equipment float fEquipmentBonus = (from slot in equipment where slot.amount > 0 select((EquipmentItem)slot.item.data).GetResistance(element)).Sum(); // -- Bonus: Equipment Sets float fSetBonus = 0f; #if _iMMOTRAITS && _iMMOEQUIPMENTSETS && _iMMOELEMENTS // -- Equipment Bonus (Set Bonus) foreach (ItemSlot slot in equipment) { fSetBonus += slot.item.setBonusElementIndividual(slot, equipment, element); } // -- Equipment Bonus (Set Bonus) foreach (ItemSlot slot in equipment) { float tmpPointsP = slot.item.setBonusElementPartial(slot, equipment, element); fSetBonus += tmpPointsP; if (tmpPointsP > 0) { break; } } // -- Equipment Bonus (Set Bonus) foreach (ItemSlot slot in equipment) { float tmpPointsC = slot.item.setBonusElementComplete(slot, equipment, element); fSetBonus += tmpPointsC; if (tmpPointsC > 0) { break; } } #endif // -- Bonus: Traits float fTraitBonus = 0f; #if _iMMOTRAITS && _iMMOELEMENTS fTraitBonus = UCE_Traits.Sum(trait => trait.GetResistance(element)); #endif fValue = fResistance - (fEquipmentBonus + fTraitBonus + fSetBonus); // ----------------------------- Calculation End --------------------------------- // -- Update Caching if (bCache && elementCache != null) { elementCache.timer = Time.time + cacheTimerInterval; elementCache.value = fValue; _elementsCache[element.name] = elementCache; } else if (bCache) { elementCache = new UCE_ElementCache(); elementCache.timer = Time.time + cacheTimerInterval; elementCache.value = fValue; _elementsCache.Add(element.name, elementCache); } return(fValue); }
// ----------------------------------------------------------------------------------- // setBonusElementIndividual // ----------------------------------------------------------------------------------- #if _iMMOELEMENTS public float setBonusElementIndividual(ItemSlot slot, SyncListItemSlot equipment, UCE_ElementTemplate element) { float fPoints = 0; // -- Individual Bonus (Applied per Item) if (slot.amount > 0 && UCE_hasIndividualSetBonus() && UCE_validIndividualSetBonus(equipment)) { foreach (UCE_ElementModifier modifier in ((EquipmentItem)data).individualStatModifiers.elementalResistances) { if (modifier.template == element) { fPoints += modifier.value; } } } return(fPoints); }
public virtual void DealDamageAt(Entity entity, int amount, float stunChance = 0, float stunTime = 0) { int damageDealt = 0; DamageType damageType = DamageType.Normal; if (entity && !entity.invincible && entity.isAlive && (amount > 0 || stunChance > 0 || stunTime > 0)) { int target_Defense = entity.defense - Convert.ToInt32(entity.defense * defenseBreakFactor); float target_BlockChance = entity.blockChance - Convert.ToInt32(entity.blockChance * blockBreakFactor); float self_critChance = criticalChance - Convert.ToInt32(criticalChance * entity.criticalEvasion); // -- Base Damage if (UCE_relationalDamage) { damageDealt = Convert.ToInt32((amount * (100 - Mathf.Sqrt(target_Defense)) / 100)); } else { damageDealt = Mathf.Max(amount - target_Defense, 1); } // -- Elemental Modifiers UCE_ElementTemplate element = null; #if _iMMOELEMENTS if (damageDealt > 0) { if (currentSkill != -1 && skills[currentSkill].data is DamageSkill) { element = ((DamageSkill)skills[currentSkill].data).element; } #if _iMMOPROJECTILES || _iMMOMELEE if (currentSkill != -1 && skills[currentSkill].data is UCE_DamageSkill) { element = ((UCE_DamageSkill)skills[currentSkill].data).element; } #endif if (element == null && this is Player) { element = ((Player)this).UCE_getAttackElement(); } } #endif // -- Custom Hook for Modifiers if (damageDealt > 0) { MutableWrapper <int> damageBonus = new MutableWrapper <int>(0); Utils.InvokeMany(typeof(Entity), this, "OnDealDamage_", entity, element, damageDealt, damageBonus); damageDealt += damageBonus.Value; } // -- Randomized Variance if (damageDealt > 0 && UCE_randomDamageDeviation != 0) { int minDamage = (int)UnityEngine.Random.Range((int)damageDealt * (1 - UCE_randomDamageDeviation), damageDealt); int maxDamage = (int)UnityEngine.Random.Range(damageDealt, (int)damageDealt * (1 + UCE_randomDamageDeviation)); damageDealt = UnityEngine.Random.Range(minDamage, maxDamage); } // -- Block if (UnityEngine.Random.value < target_BlockChance) { damageDealt -= Convert.ToInt32(damageDealt * blockFactor); damageType = DamageType.Block; } else { // -- Crit if (UnityEngine.Random.value < self_critChance) { damageDealt = Convert.ToInt32(damageDealt * criticalFactor); damageType = DamageType.Crit; } // -- Deal Damage entity.health -= damageDealt; // -- Check Stun if (UnityEngine.Random.value <= stunChance) { double newStunEndTime = NetworkTime.time + stunTime; entity.stunTimeEnd = Math.Max(newStunEndTime, stunTimeEnd); } } entity.OnAggro(this); entity.RpcOnDamageReceived(damageDealt, damageType); // reset last combat time for both lastCombatTime = NetworkTime.time; entity.lastCombatTime = NetworkTime.time; Utils.InvokeMany(typeof(Entity), this, "DealDamageAt_", entity, amount, stunChance, stunTime); } }