public void Trigger(Unit unit) { if (!destroyTriggerEffect) { ObjectPoolManager.Spawn(triggerEffectObj, transform.position, Quaternion.identity); } else { ObjectPoolManager.Spawn(triggerEffectObj, transform.position, Quaternion.identity, triggerEffectDuration); } if (facAbilityIDList.Count > 0) { int facAbilityID = facAbilityIDList[Random.Range(0, facAbilityIDList.Count)]; FactionAbility ability = AbilityManagerFaction.GetFactionAbility(facAbilityID); if (ability != null) { if (!ability.requireTargetSelection) { AbilityManager.ApplyAbilityEffect(null, ability.Clone(), (int)ability.type); } else { AbilityManager.ApplyAbilityEffect(unit.tile, ability.Clone(), (int)ability.type); } } } unit.ApplyEffect(CloneEffect()); CollectibleManager.TriggerCollectible(this); Destroy(gameObject); }
public string _SelectAbility(int index) { AbilityManager.ExitAbilityTargetMode(); FactionAbility ability = GetAbilityFromCurrentFaction(index); if (ability == null) { return("error"); } string exception = ability.IsAvailable(); if (exception != "") { return(exception); } requireTargetSelection = ability.requireTargetSelection; if (!requireTargetSelection) { ActivateAbility(null, ability); } else { ActivateTargetModeFaction(ability.GetAOERange(), ability.targetType, index, this.ActivateAbility, null); } return(""); }
void ShiftItem(int dir) { FactionAbility ability = fAbilityDB.abilityList[selectID]; fAbilityDB.abilityList[selectID] = fAbilityDB.abilityList[selectID + dir]; fAbilityDB.abilityList[selectID + dir] = ability; selectID += dir; }
public void ActivateAbility(Tile tile, FactionAbility ability) { ability.Use(); FactionManager.GetCurrentFaction().abilityInfo.energy -= ability.GetCost(); //CastAbility(ability, tile); ApplyAbilityEffect(tile, ability, (int)ability.type); }
protected float DrawTargetingSetting(float startX, float startY, FactionAbility ability) { string text = "Targeting Setting " + (!foldTargeting ? "(show)" : "(hide)"); foldTargeting = EditorGUI.Foldout(new Rect(startX, startY, width, height), foldTargeting, text, foldoutStyle); if (foldTargeting) { startX += 15; int effTargetType = (int)ability.effTargetType; cont = new GUIContent("Effect Target:", "Specify which target the ability's effect can be applied to"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); contL = new GUIContent[effTargetTypeLabel.Length]; for (int i = 0; i < contL.Length; i++) { contL[i] = new GUIContent(effTargetTypeLabel[i], effTargetTypeTooltip[i]); } effTargetType = EditorGUI.Popup(new Rect(startX + spaceX, startY, width - 40, 15), new GUIContent(""), effTargetType, contL); ability.effTargetType = (_EffectTargetType)effTargetType; startY += 5; cont = new GUIContent("Require Target Selection:", "Check if the ability require target selection. Otherwise the ability will be apply to the unit which uses it."); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); ability.requireTargetSelection = EditorGUI.Toggle(new Rect(startX + spaceX + 30, startY, widthS, height), ability.requireTargetSelection); cont = new GUIContent(" - Target Type:", "Indicate what tile can be constitued as a valid target during target selection"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (ability.requireTargetSelection) { int targetType = (int)ability.targetType; contL = new GUIContent[targetTypeLabel.Length]; for (int i = 0; i < contL.Length; i++) { contL[i] = new GUIContent(targetTypeLabel[i], targetTypeTooltip[i]); } targetType = EditorGUI.Popup(new Rect(startX + spaceX + 30, startY, width - 40, 15), new GUIContent(""), targetType, contL); ability.targetType = (_TargetType)targetType; } else { EditorGUI.LabelField(new Rect(startX + spaceX + 30, startY, widthS, height), "-"); } cont = new GUIContent(" - AOE Range:", "The range of of ability Area-of-Effective"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (ability.requireTargetSelection) { ability.aoeRange = EditorGUI.IntField(new Rect(startX + spaceX + 30, startY, widthS, height), ability.aoeRange); } else { EditorGUI.LabelField(new Rect(startX + spaceX + 30, startY, widthS, height), "-"); } } return(startY + spaceY); }
public virtual FactionAbility Clone(bool useDefaultValue = true) { FactionAbility facAB = new FactionAbility(); facAB.type = type; facAB.Copy(this, useDefaultValue); facAB.effect = effect.Clone(); return(facAB); }
private Vector2 DrawAbilityConfigurator(float startX, float startY, FactionAbility ability) { TBEditor.DrawSprite(new Rect(startX, startY, 60, 60), ability.icon); startX += 65; cont = new GUIContent("Name:", "The ability name to be displayed in game"); EditorGUI.LabelField(new Rect(startX, startY += spaceY / 4, width, height), cont); ability.name = EditorGUI.TextField(new Rect(startX + spaceX - 65, startY, width - 5, height), ability.name); if (GUI.changed) { UpdateLabel_FactionAbility(); } cont = new GUIContent("Icon:", "The ability icon to be displayed in game, must be a sprite"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); ability.icon = (Sprite)EditorGUI.ObjectField(new Rect(startX + spaceX - 65, startY, width - 5, height), ability.icon, typeof(Sprite), false); cont = new GUIContent("AbilityID:", "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), ability.prefabID.ToString()); startX -= 65; startY += 10 + spaceY - spaceY / 2; //cachedY=startY; cont = new GUIContent("Only Available Via Perk:", "Check if the ability can only be added by perk "); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); ability.onlyAvailableViaPerk = EditorGUI.Toggle(new Rect(startX + spaceX + 20, startY, widthS, height), ability.onlyAvailableViaPerk); startY += 10; startY = DrawGeneralSetting(startX, startY + spaceY, ability); startY = DrawTargetingSetting(startX, startY + spaceY, ability); startY = DrawAbilityVisualEffect(startX, startY + spaceY, ability); startY = DrawAbilityEffect(startX, startY + spaceY, ability); 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); ability.desp = EditorGUI.TextArea(new Rect(startX, startY + spaceY - 3, 270, 100), ability.desp, style); return(new Vector2(startX, startY + spaceY + 100)); }
int NewItem(int cloneID = -1) { FactionAbility ability = null; if (cloneID == -1) { ability = new FactionAbility(); ability.name = "New Ability"; } else { ability = fAbilityDB.abilityList[selectID].Clone(); } ability.prefabID = GenerateNewID(fAbilityIDList); fAbilityIDList.Add(ability.prefabID); fAbilityDB.abilityList.Add(ability); UpdateLabel_FactionAbility(); return(fAbilityDB.abilityList.Count - 1); }
protected float DrawGeneralSetting(float startX, float startY, FactionAbility ability) { 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 (AP):", "AP cost to use the ability"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); ability.cost = EditorGUI.FloatField(new Rect(startX + spaceX, startY, widthS, height), ability.cost); cont = new GUIContent("Cooldown:", "The cooldown period (in turn) of the ability after used"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); ability.cooldown = EditorGUI.IntField(new Rect(startX + spaceX, startY, widthS, height), ability.cooldown); cont = new GUIContent("Use Limit:", "How many time the ability can be used in a single battle"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); ability.useLimit = EditorGUI.IntField(new Rect(startX + spaceX, startY, widthS, height), ability.useLimit); } return(startY + spaceY); }
protected float DrawAbilityEffect(float startX, float startY, FactionAbility ability) { string text = "Ability Effects Setting " + (!foldEffect ? "(show)" : "(hide)"); foldEffect = EditorGUI.Foldout(new Rect(startX, startY, width, height), foldEffect, text, foldoutStyle); if (foldEffect) { startX += 15; //~ cont=new GUIContent("Use Default Effect:", "Check if the ability use default TBTK effect.\n\nAlternatively you can use your own custom effect by putting a custom script to on the spawn visual effect object"); //~ EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont); //~ ability.useDefaultEffect=EditorGUI.Toggle(new Rect(startX+spaceX, startY, widthS, height), ability.useDefaultEffect); if (ability.useDefaultEffect) { cont = new GUIContent("Effect Delay:", "Delay in second before the effect actually take place.\nThis is for the visual effect to kicks in"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (ability.type == _AbilityType.None) { EditorGUI.LabelField(new Rect(startX + spaceX, startY, widthS, height), "-"); } ability.effectDelayDuration = EditorGUI.FloatField(new Rect(startX + spaceX, startY, widthS, height), ability.effectDelayDuration); startY += 5; int type = (int)ability.type; cont = new GUIContent("Ability Effect Type:", "Type of the ability's effect. Define what the ability do"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); contL = new GUIContent[abilityTypeLabel.Length]; for (int i = 0; i < contL.Length; i++) { contL[i] = new GUIContent(abilityTypeLabel[i], abilityTypeTooltip[i]); } type = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), new GUIContent(""), type, contL); ability.type = (_AbilityType)type; //startX+=15; spaceX-=15; if (ability.type == _AbilityType.Generic) { startY = DrawEffect(startX, startY + spaceY, ability.effect); } //~ if(ability.type==UnitAbility._AbilityType.Teleport){ //~ GUI.Label(new Rect(startX+spaceX, startY+=spaceY, width, height), "- No input required -"); //~ } if (ability.type == _AbilityType.ScanFogOfWar) { //GUI.Label(new Rect(startX+spaceX, startY+=spaceY, width, height), "- No input required -"); cont = new GUIContent(" - Duration:", ""); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); ability.effect.duration = EditorGUI.IntField(new Rect(startX + spaceX, startY, widthS, height), ability.effect.duration); } if (ability.type == _AbilityType.SpawnNew) { cont = new GUIContent(" - Unit To Spawn:", "Unit to be spawned"); GUI.Label(new Rect(startX, startY += spaceY, width, height), cont); int index = ability.spawnUnit != null?TBEditor.GetUnitIndex(ability.spawnUnit.prefabID) : 0; index = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), index, unitLabel); if (index > 0) { ability.spawnUnit = unitDB.unitList[index - 1]; } else if (index == 0) { ability.spawnUnit = null; } } if (ability.type == _AbilityType.SpawnNew) { if (ability.targetType != _TargetType.EmptyTile) { Debug.LogWarning(ability.type + " ability must have 'EmptyTile' TargetType"); } if (!ability.requireTargetSelection) { Debug.LogWarning(ability.type + " ability requires target selection"); } if (ability.type != _AbilityType.ScanFogOfWar && ability.aoeRange > 0) { Debug.LogWarning(ability.type + " ability's aoe-range must be zero"); } ability.targetType = _TargetType.EmptyTile; ability.requireTargetSelection = true; if (ability.type != _AbilityType.ScanFogOfWar) { ability.aoeRange = 0; } } //startX-=15; spaceX+=15; } } return(startY + spaceY); }
public void _PerkUnlockNewAbility(int ID, int IDX) { int dbIndex = ID >= 0 ? GetPerkDBIndex(ID) : -1; if (dbIndex == -1 && IDX == -1) { return; } List <Faction> facList = FactionManager.GetFactionList(); for (int i = 0; i < facList.Count; i++) { if (!facList[i].isPlayerFaction) { continue; } if (facList[i].abilityInfo == null) { continue; } FactionAbilityInfo abInfo = facList[i].abilityInfo; int replaceIndex = -1; if (IDX >= 0) { for (int n = 0; n < abInfo.abilityList.Count; n++) { if (IDX == abInfo.abilityList[n].prefabID) { replaceIndex = n; break; } } } if (dbIndex > 0) { FactionAbility ability = facAbilityDBList[dbIndex].Clone(); ability.factionID = facList[i].ID; if (replaceIndex >= 0) { abInfo.abilityList[replaceIndex] = ability; } else { abInfo.abilityList.Add(ability); } } else { if (replaceIndex >= 0) { abInfo.abilityList.RemoveAt(replaceIndex); } } } if (dbIndex >= 0) { TBTK.OnNewFactionAbility(facAbilityDBList[dbIndex].Clone()); } }