//public static string PurchasePerk(Perk perk, bool useCurrency=true){ return instance._PurchasePerk(perk, useCurrency); } public string PurchasePerk(Perk perk, bool useCurrency = true, bool saving = true) { string text = perk.Purchase(this, useCurrency); if (text != "") { Debug.Log(text); return(text); } for (int i = 0; i < perkList.Count; i++) { Perk perkTemp = perkList[i]; if (perkTemp.purchased > 0 || perkTemp.prereq.Count == 0) { continue; } perkTemp.prereq.Remove(perk.ID); } TDS.PerkPurchased(perk); if (player.SaveUponChange()) { Save(); } if (perk.type == _PerkType.ModifyGeneralStats) { hitPointCap += perk.hitPointCap; energyCap += perk.energyCap; hitPointRegen += perk.hitPointRegen; energyRegen += perk.energyRegen; player.GainHitPoint(perk.hitPoint); player.GainEnergy(perk.energy); moveSpeedMul += perk.moveSpeedMul; damageMul += perk.dmgMul; critMul += perk.critChanceMul; critMulMul += perk.CritMultiplierMul; expGainMul += perk.expGainMul; creditGainMul += perk.creditGainMul; scoreGainMul += perk.scoreGainMul; hitPointGainMul += perk.hitPointGainMul; energyGainMul += perk.energyGainMul; } else if (perk.type == _PerkType.AddWeapon && perk.newWeaponID >= 0) { Weapon newWeapon = WeaponDB.GetPrefab(perk.newWeaponID); if (newWeapon != null) { if (perk.replaceExisting) { player.AddWeapon(newWeapon, true); } else if (perk.replaceWeaponID >= 0) { int replaceIndex = -1; for (int i = 0; i < player.weaponList.Count; i++) { if (perk.replaceWeaponID == player.weaponList[i].ID) { replaceIndex = i; break; } } if (replaceIndex >= 0) { player.SwitchWeapon(replaceIndex); player.AddWeapon(newWeapon, true); } else { player.AddWeapon(newWeapon); } } else { player.AddWeapon(newWeapon); } } for (int i = 0; i < perkList.Count; i++) { if (perkList[i].purchased > 0 && perkList[i].type == _PerkType.ModifyWeapon) { if (perkList[i].appliedToAllWeapon || perkList[i].weaponIDList.Contains(perk.newWeaponID)) { if (perkList[i].weapEffectID >= 0) { player.ChangeWeaponEffect(perk.newWeaponID, perkList[i].weapEffectID); } if (perkList[i].weapAbilityID >= 0) { player.ChangeWeaponAbility(perk.newWeaponID, perkList[i].weapAbilityID); } } } } } else if (perk.type == _PerkType.AddAbility && perk.newAbilityID >= 0) { AbilityManager.AddAbility(perk.newAbilityID, perk.replaceAbilityID); for (int i = 0; i < perkList.Count; i++) { if (perkList[i].purchased > 0 && perkList[i].type == _PerkType.ModifyAbility) { if (perkList[i].appliedToAllAbility || perkList[i].abilityIDList.Contains(perk.newAbilityID)) { if (perkList[i].abEffectID >= 0) { player.ChangeAbilityEffect(perk.newAbilityID, perkList[i].abEffectID); } } } } } else if (perk.type == _PerkType.ModifyWeapon) { if (perk.appliedToAllWeapon) { weapStatG.ModifyWithPerk(perk); if (perk.weapEffectID >= 0) { player.ChangeAllWeaponEffect(perk.weapEffectID); } if (perk.weapAbilityID >= 0) { player.ChangeAllWeaponAbility(perk.weapAbilityID); } } else { for (int i = 0; i < perk.weaponIDList.Count; i++) { WeaponStatMultiplier item = GetWeaponStatMul(perk.weaponIDList[i]); if (item == null) { item = new WeaponStatMultiplier(); item.prefabID = perk.weaponIDList[i]; weapStatList.Add(item); } item.ModifyWithPerk(perk); if (perk.weapEffectID >= 0) { player.ChangeWeaponEffect(perk.weaponIDList[i], perk.weapEffectID); } if (perk.weapAbilityID >= 0) { player.ChangeWeaponAbility(perk.weaponIDList[i], perk.weapAbilityID); } } } } else if (perk.type == _PerkType.ModifyAbility) { if (perk.appliedToAllAbility) { abilityStatG.ModifyWithPerk(perk); if (perk.weapEffectID >= 0) { player.ChangeAllAbilityEffect(perk.weapEffectID); } } else { for (int i = 0; i < perk.abilityIDList.Count; i++) { AbilityStatMultiplier item = GetAbilityStatMul(perk.abilityIDList[i]); if (item == null) { item = new AbilityStatMultiplier(); item.prefabID = perk.abilityIDList[i]; abilityStatList.Add(item); } item.ModifyWithPerk(perk); if (perk.abEffectID >= 0) { player.ChangeAbilityEffect(perk.abilityIDList[i], perk.abEffectID); } } } } else if (perk.type == _PerkType.Custom) { GameObject obj = (GameObject)Instantiate(perk.customObject); obj.name = perk.name + "_CustomObject"; obj.transform.parent = transform; obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; } return(""); }