public Perk Clone() { Perk perk = new Perk(); perk.prefabID = prefabID; perk.icon = icon; perk.name = name; perk.desp = desp; perk.type = type; perk.purchased = purchased; perk.cost = cost; perk.minPerkPoint = minPerkPoint; perk.prereq = new List <int>(prereq); //for(int i=0; i<prereq.Count; i++) perk.prereq.Add(prereq[i]); //for(int i=0; i<itemIDList.Count; i++) perk.itemIDList.Add(itemIDList[i]); perk.unitIDList = new List <int>(unitIDList); perk.unitAbilityIDList = new List <int>(unitAbilityIDList); perk.facAbilityIDList = new List <int>(facAbilityIDList); perk.abCostMod = abCostMod; perk.abCooldownMod = abCooldownMod; perk.abUseLimitMod = abUseLimitMod; perk.abHitChanceMod = abHitChanceMod; perk.abRangeMod = abRangeMod; perk.abAOERangeMod = abAOERangeMod; perk.abHPMod = abHPMod; perk.abAPMod = abAPMod; perk.abDurationMod = abDurationMod; perk.stats = stats.Clone(); perk.addAbilityToAllUnit = addAbilityToAllUnit; perk.newABUnitIDList = newABUnitIDList; perk.newUnitAbilityID = newUnitAbilityID; perk.subUnitAbilityID = subUnitAbilityID; perk.newFacAbilityID = newFacAbilityID; perk.subFacAbilityID = subFacAbilityID; //perk.abilityID=abilityID; //perk.abilityXID=abilityXID; return(perk); }
private void ModifyAbilityModifier(PerkAbilityModifier modifier, Perk perk) { //modifier.duration+=perk.abDurationMod; modifier.cost += perk.abCostMod; modifier.cooldown += perk.abCooldownMod; modifier.useLimit += perk.abUseLimitMod; modifier.hitChance += perk.abHitChanceMod; modifier.range += perk.abRangeMod; modifier.aoeRange += perk.abAOERangeMod; modifier.HP += perk.abHPMod; modifier.AP += perk.abAPMod; modifier.effectDuration += perk.abDurationMod; ModifyUnitStats(modifier.stats, perk.stats); }
private Vector2 DrawPerkConfigurator(float startX, float startY, Perk perk) { TBEditor.DrawSprite(new Rect(startX, startY, 60, 60), perk.icon); startX += 65; cont = new GUIContent("Name:", "The perk name to be displayed in game"); EditorGUI.LabelField(new Rect(startX, startY += spaceY / 4, width, height), cont); perk.name = EditorGUI.TextField(new Rect(startX + spaceX - 65, startY, width - 5, height), perk.name); if (GUI.changed) { UpdateLabel_Perk(); } cont = new GUIContent("Icon:", "The perk icon to be displayed in game, must be a sprite"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); perk.icon = (Sprite)EditorGUI.ObjectField(new Rect(startX + spaceX - 65, startY, width - 5, height), perk.icon, typeof(Sprite), false); cont = new GUIContent("PerkID:", "The ID used to associate a perk item in perk menu to a perk when configuring perk menu manually"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); EditorGUI.LabelField(new Rect(startX + spaceX - 65, startY, width - 5, height), perk.prefabID.ToString()); startX -= 65; startY += 10 + spaceY - spaceY / 2; //cachedY=startY; startY = DrawGeneralSetting(startX, startY + spaceY, perk); startY = DrawPerkProperty(startX, startY + spaceY, perk); startY += 10; GUIStyle style = new GUIStyle("TextArea"); style.wordWrap = true; cont = new GUIContent("Description (for runtime and editor): ", ""); EditorGUI.LabelField(new Rect(startX, startY += spaceY, 400, 20), cont); perk.desp = EditorGUI.TextArea(new Rect(startX, startY + spaceY - 3, 270, 100), perk.desp, style); return(new Vector2(startX, startY + spaceY + 100)); }
int NewItem(int cloneID = -1) { Perk perk = null; if (cloneID == -1) { perk = new Perk(); perk.name = "New Perk"; } else { perk = perkDB.perkList[selectID].Clone(); } perk.prefabID = GenerateNewID(perkIDList); perkIDList.Add(perk.prefabID); perkDB.perkList.Add(perk); UpdateLabel_Perk(); return(perkDB.perkList.Count - 1); }
private void ModifyFactionAbilityModifier(PerkAbilityModifier abilityModifier, Perk perk) { ModifyAbilityModifier(abilityModifier, perk); //ModifyUnitStats(abilityModifier.stats, perk.stats); }
private void ModifyFactionAbilityModifierInList(int index, Perk perk) { ModifyFactionAbilityModifier(factionAbilityModifierList[index], perk); }
private void ModifyUnitAbilityModifierInList(int index, Perk perk) { ModifyUnitAbilityModifier(unitAbilityModifierList[index], perk); }
private void ModifyUnitModifier(PerkUnitModifier unitModifier, Perk perk) { ModifyUnitStats(unitModifier.stats, perk.stats); }
public string _PurchasePerk(Perk perk, bool useCurrency = true) { string text = perk.Purchase(useCurrency); if (text != "") { return(text); } SavePerkProgress(); TBTK.OnPerkPurchased(perk); //process the prereq for other perk for (int i = 0; i < perkList.Count; i++) { Perk perkTemp = perkList[i]; if (perkTemp.purchased || perkTemp.prereq.Count == 0) { continue; } perkTemp.prereq.Remove(perk.prefabID); } perkPoint += 1; TBTK.OnPerkPoint(perkPoint); if (perk.type == _PerkType.NewUnitAbility) { if (perk.addAbilityToAllUnit) { AbilityManagerUnit.PerkUnlockNewAbility(null, perk.newUnitAbilityID, perk.subUnitAbilityID); globalUnitModifier.abilityIDList.Add(perk.newUnitAbilityID); globalUnitModifier.abilityXIDList.Add(perk.subUnitAbilityID); } else { AbilityManagerUnit.PerkUnlockNewAbility(perk.newABUnitIDList, perk.newUnitAbilityID, perk.subUnitAbilityID); for (int i = 0; i < perk.newABUnitIDList.Count; i++) { int index = UnitModifierExist(perk.newABUnitIDList[i]); if (index == -1) { PerkUnitModifier unitModifier = new PerkUnitModifier(); unitModifier.prefabID = perk.newABUnitIDList[i]; unitModifierList.Add(unitModifier); index = unitModifierList.Count - 1; } unitModifierList[index].abilityIDList.Add(perk.newUnitAbilityID); unitModifierList[index].abilityXIDList.Add(perk.subUnitAbilityID); } } } else if (perk.type == _PerkType.NewFactionAbility) { AbilityManagerFaction.PerkUnlockNewAbility(perk.newFacAbilityID, perk.subFacAbilityID); factionAbilityIDList.Add(perk.newFacAbilityID); factionAbilityXIDList.Add(perk.subFacAbilityID); } else if (perk.type == _PerkType.Unit) { for (int i = 0; i < perk.unitIDList.Count; i++) { int index = UnitModifierExist(perk.unitIDList[i]); if (index == -1) { PerkUnitModifier unitModifier = new PerkUnitModifier(); unitModifier.prefabID = perk.unitIDList[i]; unitModifierList.Add(unitModifier); index = unitModifierList.Count - 1; } ModifyUnitModifierInList(index, perk); } } else if (perk.type == _PerkType.Unit_All) { ModifyUnitModifier(globalUnitModifier, perk); } else if (perk.type == _PerkType.UnitAbility) { for (int i = 0; i < perk.unitAbilityIDList.Count; i++) { int index = UnitAbilityModifierExist(perk.unitAbilityIDList[i]); if (index == -1) { PerkAbilityModifier abilityModifier = new PerkAbilityModifier(); abilityModifier.prefabID = perk.unitAbilityIDList[i]; unitAbilityModifierList.Add(abilityModifier); index = unitAbilityModifierList.Count - 1; } ModifyUnitAbilityModifierInList(index, perk); } } else if (perk.type == _PerkType.UnitAbility_All) { ModifyUnitAbilityModifier(globalUnitAbilityModifier, perk); } else if (perk.type == _PerkType.FactionAbility) { for (int i = 0; i < perk.facAbilityIDList.Count; i++) { int index = FactionAbilityModifierExist(perk.facAbilityIDList[i]); if (index == -1) { PerkAbilityModifier abilityModifier = new PerkAbilityModifier(); abilityModifier.prefabID = perk.facAbilityIDList[i]; factionAbilityModifierList.Add(abilityModifier); index = factionAbilityModifierList.Count - 1; } ModifyFactionAbilityModifierInList(index, perk); } } else if (perk.type == _PerkType.FactionAbility_All) { ModifyFactionAbilityModifier(globalFactionAbilityModifier, perk); } return(""); }
public static string PurchasePerk(Perk perk, bool useCurrency = true) { return(instance._PurchasePerk(perk, useCurrency)); }
void DrawPerkList() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("", GUILayout.MaxWidth(10)); showPerkList = EditorGUILayout.Foldout(showPerkList, "Show Perk List"); EditorGUILayout.EndHorizontal(); if (showPerkList) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("EnableAll") && !Application.isPlaying) { instance.unavailableIDList = new List <int>(); } if (GUILayout.Button("DisableAll") && !Application.isPlaying) { instance.purchasedIDList = new List <int>(); instance.unavailableIDList = new List <int>(); for (int i = 0; i < perkDB.perkList.Count; i++) { instance.unavailableIDList.Add(perkDB.perkList[i].prefabID); } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < perkDB.perkList.Count; i++) { Perk perk = perkDB.perkList[i]; GUILayout.BeginHorizontal(); GUILayout.Box("", GUILayout.Width(40), GUILayout.Height(40)); Rect rect = GUILayoutUtility.GetLastRect(); TBEditor.DrawSprite(rect, perk.icon, perk.desp, false); GUILayout.BeginVertical(); EditorGUILayout.Space(); GUILayout.Label(perk.name, GUILayout.ExpandWidth(false)); GUILayout.BeginHorizontal(); bool flag = !instance.unavailableIDList.Contains(perk.prefabID) ? true : false; //if(Application.isPlaying) flag=!flag; //switch it around in runtime EditorGUILayout.LabelField(new GUIContent(" - enabled: ", "check to enable the perk in this level"), GUILayout.Width(70)); flag = EditorGUILayout.Toggle(flag); if (!Application.isPlaying) { if (flag) { instance.unavailableIDList.Remove(perk.prefabID); } else { if (!instance.unavailableIDList.Contains(perk.prefabID)) { instance.unavailableIDList.Add(perk.prefabID); instance.purchasedIDList.Remove(perk.prefabID); } } } if (!instance.unavailableIDList.Contains(perk.prefabID)) { flag = instance.purchasedIDList.Contains(perk.prefabID); EditorGUILayout.LabelField(new GUIContent("- purchased:", "Check to set the perk as purchased right from the start"), GUILayout.Width(75)); flag = EditorGUILayout.Toggle(flag); if (!flag) { instance.purchasedIDList.Remove(perk.prefabID); } else if (!instance.purchasedIDList.Contains(perk.prefabID)) { instance.purchasedIDList.Add(perk.prefabID); } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } }
protected float DrawPerkProperty(float startX, float startY, Perk perk) { string text = "Perk Property " + (!foldProperty ? "(show)" : "(hide)"); foldProperty = EditorGUI.Foldout(new Rect(startX, startY, width, height), foldProperty, text, foldoutStyle); if (foldProperty) { startX += 15; int type = (int)perk.type; cont = new GUIContent("Perk Type:", "What the perk does"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); contL = new GUIContent[perkTypeLabel.Length]; for (int i = 0; i < contL.Length; i++) { contL[i] = new GUIContent(perkTypeLabel[i], perkTypeTooltip[i]); } type = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), new GUIContent(""), type, contL); perk.type = (_PerkType)type; startY += 8; spaceX -= 5; startX += 5; if (perk.type == _PerkType.Unit || perk.type == _PerkType.Unit_All) { if (perk.type == _PerkType.Unit) { cont = new GUIContent("Target Units:", "Unit that will be affected by the perk"); EditorGUI.LabelField(new Rect(startX, startY + spaceY, width, height), cont, perk.unitIDList.Count > 0 ? new GUIStyle("Label") : conflictStyle); for (int i = 0; i < perk.unitIDList.Count + 1; i++) { EditorGUI.LabelField(new Rect(startX + spaceX - 10, startY + spaceY, width, height), "-"); int index = (i < perk.unitIDList.Count) ? TBEditor.GetUnitIndex(perk.unitIDList[i]) : 0; index = EditorGUI.Popup(new Rect(startX + spaceX, startY += spaceY, width - 20, height), index, unitLabel); if (index > 0) { int unitID = unitDB.unitList[index - 1].prefabID; if (!perk.unitIDList.Contains(unitID)) { if (i < perk.unitIDList.Count) { perk.unitIDList[i] = unitID; } else { perk.unitIDList.Add(unitID); } } } else if (i < perk.unitIDList.Count) { perk.unitIDList.RemoveAt(i); i -= 1; } if (i < perk.unitIDList.Count && GUI.Button(new Rect(startX + spaceX + width - 15, startY, 20, height - 1), "-")) { perk.unitIDList.RemoveAt(i); i -= 1; } } } startY = DrawStatsModifier(startX, startY + spaceY + 5, perk.stats); } if (perk.type == _PerkType.UnitAbility || perk.type == _PerkType.UnitAbility_All) { if (perk.type == _PerkType.UnitAbility) { cont = new GUIContent("Target Abilities:", "Unit Abilities that will be affected by the perk"); EditorGUI.LabelField(new Rect(startX, startY + spaceY, width, height), cont, perk.unitAbilityIDList.Count > 0 ? new GUIStyle("Label") : conflictStyle); for (int i = 0; i < perk.unitAbilityIDList.Count + 1; i++) { EditorGUI.LabelField(new Rect(startX + spaceX - 10, startY + spaceY, width, height), "-"); int index = (i < perk.unitAbilityIDList.Count) ? TBEditor.GetUnitAbilityIndex(perk.unitAbilityIDList[i]) : 0; index = EditorGUI.Popup(new Rect(startX + spaceX, startY += spaceY, width - 20, height), index, uAbilityLabel); if (index > 0) { int abID = uAbilityDB.abilityList[index - 1].prefabID; if (!perk.unitAbilityIDList.Contains(abID)) { if (i < perk.unitAbilityIDList.Count) { perk.unitAbilityIDList[i] = abID; } else { perk.unitAbilityIDList.Add(abID); } } } else if (i < perk.unitAbilityIDList.Count) { perk.unitAbilityIDList.RemoveAt(i); i -= 1; } if (i < perk.unitAbilityIDList.Count && GUI.Button(new Rect(startX + spaceX + width - 15, startY, 20, height - 1), "-")) { perk.unitAbilityIDList.RemoveAt(i); i -= 1; } } } startY = DrawAbilityModifier(startX, startY + spaceY + 10, perk, true) + 5; startY = DrawStatsModifier(startX, startY, perk.stats); } if (perk.type == _PerkType.FactionAbility || perk.type == _PerkType.FactionAbility_All) { if (perk.type == _PerkType.FactionAbility) { cont = new GUIContent("Target Abilities:", "Faction Abilities that will be affected by the perk"); EditorGUI.LabelField(new Rect(startX, startY + spaceY, width, height), cont, perk.facAbilityIDList.Count > 0 ? new GUIStyle("Label") : conflictStyle); for (int i = 0; i < perk.facAbilityIDList.Count + 1; i++) { EditorGUI.LabelField(new Rect(startX + spaceX - 10, startY + spaceY, width, height), "-"); int index = (i < perk.facAbilityIDList.Count) ? TBEditor.GetFactionAbilityIndex(perk.facAbilityIDList[i]) : 0; index = EditorGUI.Popup(new Rect(startX + spaceX, startY += spaceY, width - 20, height), index, fAbilityLabel); if (index > 0) { int abID = fAbilityDB.abilityList[index - 1].prefabID; if (!perk.facAbilityIDList.Contains(abID)) { if (i < perk.facAbilityIDList.Count) { perk.facAbilityIDList[i] = abID; } else { perk.facAbilityIDList.Add(abID); } } } else if (i < perk.facAbilityIDList.Count) { perk.facAbilityIDList.RemoveAt(i); i -= 1; } if (i < perk.facAbilityIDList.Count && GUI.Button(new Rect(startX + spaceX + width - 15, startY, 20, height - 1), "-")) { perk.facAbilityIDList.RemoveAt(i); i -= 1; } } } startY = DrawAbilityModifier(startX, startY + spaceY + 10, perk, false) + 5; startY = DrawStatsModifier(startX, startY, perk.stats); } if (perk.type == _PerkType.NewUnitAbility) { int index = TBEditor.GetUnitAbilityIndex(perk.newUnitAbilityID); cont = new GUIContent("New Abilitiy:", "New unit ability to be added to the selected units"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont, index == 0 ? conflictStyle : new GUIStyle("Label")); index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, uAbilityLabel); if (index > 0) { perk.newUnitAbilityID = uAbilityDB.abilityList[index - 1].prefabID; } else { perk.newUnitAbilityID = -1; } cont = new GUIContent("Replacing:", "(Optional) Existing unit ability to be replaced by the new ability."); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); index = TBEditor.GetUnitAbilityIndex(perk.subUnitAbilityID); index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, uAbilityLabel); if (index > 0 && uAbilityDB.abilityList[index - 1].prefabID != perk.newUnitAbilityID) { perk.subUnitAbilityID = uAbilityDB.abilityList[index - 1].prefabID; } else { perk.subUnitAbilityID = -1; } startY += 5; cont = new GUIContent("Add to all Unit:", "Check if the ability is to add to all player unit"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); perk.addAbilityToAllUnit = EditorGUI.Toggle(new Rect(startX + spaceX, startY, widthS, height), perk.addAbilityToAllUnit); if (!perk.addAbilityToAllUnit) { cont = new GUIContent("Target Units:", "Units that will gain the new abilities"); EditorGUI.LabelField(new Rect(startX, startY + spaceY, width, height), cont, perk.newABUnitIDList.Count == 0 ? conflictStyle : new GUIStyle("Label")); for (int i = 0; i < perk.newABUnitIDList.Count + 1; i++) { EditorGUI.LabelField(new Rect(startX + spaceX - 10, startY + spaceY, width, height), "-"); int uIndex = (i < perk.newABUnitIDList.Count) ? TBEditor.GetUnitIndex(perk.newABUnitIDList[i]) : 0; uIndex = EditorGUI.Popup(new Rect(startX + spaceX, startY += spaceY, width - 20, height), uIndex, unitLabel); if (uIndex > 0) { int unitID = unitDB.unitList[uIndex - 1].prefabID; if (!perk.newABUnitIDList.Contains(unitID)) { if (i < perk.newABUnitIDList.Count) { perk.unitIDList[i] = unitID; } else { perk.newABUnitIDList.Add(unitID); } } } else if (i < perk.newABUnitIDList.Count) { perk.newABUnitIDList.RemoveAt(i); i -= 1; } if (i < perk.newABUnitIDList.Count && GUI.Button(new Rect(startX + spaceX + width - 15, startY, 20, height - 1), "-")) { perk.newABUnitIDList.RemoveAt(i); i -= 1; } } } } if (perk.type == _PerkType.NewFactionAbility) { int index = TBEditor.GetFactionAbilityIndex(perk.newFacAbilityID); cont = new GUIContent("New Abilitiy:", "New faction Ability to be added to the game"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont, index == 0 ? conflictStyle : new GUIStyle("Label")); index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, fAbilityLabel); if (index > 0) { perk.newFacAbilityID = fAbilityDB.abilityList[index - 1].prefabID; } else { perk.newFacAbilityID = -1; } cont = new GUIContent("Replacing:", "(Optional) Existing faction ability to be replaced by the new ability."); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); index = TBEditor.GetFactionAbilityIndex(perk.subFacAbilityID); index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, fAbilityLabel); if (index > 0 && fAbilityDB.abilityList[index - 1].prefabID != perk.newFacAbilityID) { perk.subFacAbilityID = fAbilityDB.abilityList[index - 1].prefabID; } else { perk.subFacAbilityID = -1; } } spaceX += 5; startX -= 5; } return(startY + spaceY); }
protected float DrawGeneralSetting(float startX, float startY, Perk perk) { string text = "General Setting " + (!foldGeneral ? "(show)" : "(hide)"); foldGeneral = EditorGUI.Foldout(new Rect(startX, startY, width, height), foldGeneral, text, foldoutStyle); if (foldGeneral) { startX += 15; cont = new GUIContent("Cost:", "How many perk currency is required to purchase the perk"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); perk.cost = EditorGUI.IntField(new Rect(startX + spaceX, startY, widthS, height), perk.cost); cont = new GUIContent("Min PerkPoint req:", "Minimum perk point to have before the perk becoming available"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); perk.minPerkPoint = EditorGUI.IntField(new Rect(startX + spaceX, startY, widthS, height), perk.minPerkPoint); startY += 5; cont = new GUIContent("Prerequisite Perk:", "Perks that needs to be purchased before this perk is unlocked and become available"); EditorGUI.LabelField(new Rect(startX, startY + spaceY, width, height), cont); for (int i = 0; i < perk.prereq.Count + 1; i++) { EditorGUI.LabelField(new Rect(startX + spaceX - 10, startY + spaceY, width, height), "-"); int index = (i < perk.prereq.Count) ? TBEditor.GetPerkIndex(perk.prereq[i]) : 0; index = EditorGUI.Popup(new Rect(startX + spaceX, startY += spaceY, width - 20, height), index, perkLabel); if (index > 0) { int perkID = perkDB.perkList[index - 1].prefabID; if (perkID != perk.prefabID && !perk.prereq.Contains(perkID)) { if (i < perk.prereq.Count) { perk.prereq[i] = perkID; } else { perk.prereq.Add(perkID); } } } else if (i < perk.prereq.Count) { perk.prereq.RemoveAt(i); i -= 1; } if (i < perk.prereq.Count && GUI.Button(new Rect(startX + spaceX + width - 15, startY, 20, height - 1), "-")) { perk.prereq.RemoveAt(i); i -= 1; } } if (perk.prereq.Count > 0) { startY += spaceY + 5; for (int i = 0; i < perk.prereq.Count; i++) { int index = TBEditor.GetPerkIndex(perk.prereq[i]) - 1; TBEditor.DrawSprite(new Rect(startX + (i * 45), startY, 40, 40), perkDB.perkList[index].icon); } startY += 45 - spaceY; } } return(startY + spaceY); }