// ------------------------------------------------------------------------------- // loadTemplate // ------------------------------------------------------------------------------- public void loadTemplate() { if (string.IsNullOrEmpty(name)) { return; } template = DictionaryElement.Get(name); }
// ------------------------------------------------------------------------------- // RefreshElements // ------------------------------------------------------------------------------- public void RefreshElements(TemplateMetaElement element) { foreach (Transform t in ElementContent) { Destroy(t.gameObject); } foreach (var ele in DictionaryElement.dict) { GameObject newObj = (GameObject)Instantiate(ButtonIconPrefab, ElementContent); newObj.GetComponentInChildren <Button>().GetComponentInChildren <Image>().sprite = ele.Value.icon; newObj.GetComponentInChildren <Button>().interactable = (element == ele.Value) ? true : false; } }
// ------------------------------------------------------------------------------- // getElementalRelation // ------------------------------------------------------------------------------- public static float getElementalRelation(TemplateMetaElement sourceElement, CharacterBase target) { float factor = 1; float modifier = 1; if (sourceElement != null) { if (sourceElement.PrimaryRelation != null && target.Element == sourceElement.PrimaryRelation) { factor = sourceElement.PrimaryRelationWeight; } else if (sourceElement.SecondaryRelation != null && target.Element == sourceElement.SecondaryRelation) { factor = sourceElement.SecondaryRelationWeight; } modifier = factor - target.stats.resistances.FirstOrDefault(x => x.template == sourceElement).value; } return(modifier); }
// ------------------------------------------------------------------------------- // CalculateFinalDamage // ------------------------------------------------------------------------------- public static int CalculateFinalDamage(int damage, TemplateMetaCombatStyle attackType, TemplateMetaElement element, CharacterBase target, bool IsRearguard = false) { int defense = 0; damage = (int)(damage * RPGHelper.getElementalRelation(element, target)); defense = target.stats.combatStyles.FirstOrDefault(x => x.template == attackType).defenseValue; if (IsRearguard) { damage = (int)(damage * attackType.rearAttackModifier); } else { damage = (int)(damage * attackType.frontAttackModifier); } if (target.IsRearguard) { defense = (int)(defense * attackType.rearDefenseModifier); } else { defense = (int)(defense * attackType.frontDefenseModifier); } float variance = UnityEngine.Random.Range(1 - Finder.battle.maxDamageVariation, 1 + Finder.battle.maxDamageVariation); damage = (int)(damage * variance); damage -= defense; if (damage <= 0) { damage = 1; } return(damage); }