public static void DeactivateLifeTime(UnitAbility ability, Unit unit) { if (ability.isActive == true) { unit.Shieldbar = 0; unit.Healthbar = 0; foreach (UnitAbility myability in unit.Abilities) { myability.isActive = false; } } }
void OnGUI() { if(window==null) Init(); //if(GUI.Button(new Rect(window.position.width-110, 10, 100, 30), "Save")){ // SaveToXML(); //} int currentAbilityCount=allUAbList.Count; cont=new GUIContent("New UnitAbility", "Create a new unit ability"); if(GUI.Button(new Rect(5, 10, 100, 30), cont)){ UnitAbility UAb=new UnitAbility(); NewUnitAbilityRoutine(UAb); if(onUnitAbilityUpdateE!=null) onUnitAbilityUpdateE(); } cont=new GUIContent("Clone UnitAbility", "Create a new ability by cloning the current selected unit ability"); if(selectedUAbID>=0 && selectedUAbID<allUAbList.Count){ if(GUI.Button(new Rect(115, 10, 100, 30), cont)){ UnitAbility UAb=allUAbList[selectedUAbID].Clone(); NewUnitAbilityRoutine(UAb); if(onUnitAbilityUpdateE!=null) onUnitAbilityUpdateE(); } } //~ Rect visibleRect=; //~ Rect contentRect= GUI.Box(new Rect(5, 50, window.position.width-10, 260), ""); scrollPos = GUI.BeginScrollView(new Rect(5, 55, window.position.width-12, 250), scrollPos, new Rect(5, 50, window.position.width-40, 10+((allUAbList.Count-1)/3)*35)); int row=0; int column=0; for(int i=0; i<allUAbList.Count; i++){ GUIStyle style=GUI.skin.label; style.alignment=TextAnchor.MiddleCenter; if(swapID==i) GUI.color=new Color(.9f, .9f, .0f, 1); else GUI.color=new Color(.8f, .8f, .8f, 1); GUI.Box(new Rect(10+column*210, 50+row*30, 25, 25), ""); if(GUI.Button(new Rect(10+column*210, 50+row*30, 25, 25), "")){ //~ deleteID=-1; //~ if(swapID==i) swapID=-1; //~ else if(swapID==-1) swapID=i; //~ else{ //~ SwapUAbInList(swapID, i); //~ swapID=-1; //~ } } GUI.Label(new Rect(8+column*210, 50+row*30, 25, 25), allUAbList[i].ID.ToString(), style); GUI.color=Color.white; style.alignment=TextAnchor.MiddleLeft; int ID=allUAbList[i].ID; if(selectedUAbID>=0 && allUAbList[selectedUAbID].chainedAbilityIDList.Contains(ID)) GUI.color=new Color(0, 1f, 1f, 1f); else if(selectedUAbID==i) GUI.color = Color.green; style=GUI.skin.button; style.fontStyle=FontStyle.Bold; GUI.SetNextControlName ("AbilityButton"); if(GUI.Button(new Rect(10+27+column*210, 50+row*30, 100, 25), allUAbList[i].name, style)){ GUI.FocusControl ("AbilityButton"); selectedUAbID=i; deleteID=-1; } GUI.color = Color.white; style.fontStyle=FontStyle.Normal; if(deleteID!=i){ if(GUI.Button(new Rect(10+27+102+column*210, 50+row*30, 25, 25), "X")){ deleteID=i; } } else{ GUI.color = Color.red; if(GUI.Button(new Rect(10+27+102+column*210, 50+row*30, 55, 25), "Delete")){ UAbIDList.Remove(allUAbList[i].ID); allUAbList.RemoveAt(i); if(i<=selectedUAbID) selectedUAbID-=1; deleteID=-1; if(onUnitAbilityUpdateE!=null) onUnitAbilityUpdateE(); } GUI.color = Color.white; } column+=1; if(column==3){ column=0; row+=1; } } GUI.EndScrollView(); if(selectedUAbID>-1 && selectedUAbID<allUAbList.Count){ UAbConfigurator(); } if (GUI.changed || currentAbilityCount!=allUAbList.Count){ prefab.unitAbilityList=allUAbList; EditorUtility.SetDirty(prefab); if(onUnitAbilityUpdateE!=null) onUnitAbilityUpdateE(); } }
void NewUnitAbilityRoutine(UnitAbility UAb) { UAb.ID=GenerateNewID(); UAbIDList.Add(UAb.ID); UAb.name="UnitAbility "+allUAbList.Count; allUAbList.Add(UAb); selectedUAbID=allUAbList.Count-1; deleteID=-1; }
void EffectAttrConfigurator(UnitAbility uAB, int ID, int startX, int startY) { EffectAttr effectAttr=uAB.effectAttrs[ID]; if(GUI.Button(new Rect(startX, startY+=18, 70, 14), "Remove")){ uAB.effectAttrs.Remove(effectAttr); return; } int type=(int)effectAttr.type; cont=new GUIContent("Type:", "Type of the effect."); contList=new GUIContent[effectAttrTypeLabel.Length]; for(int i=0; i<contList.Length; i++) contList[i]=new GUIContent(effectAttrTypeLabel[i], effectAttrTypeTooltip[i]); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); type = EditorGUI.Popup(new Rect(startX+40, startY, 80, 16), type, contList); effectAttr.type=(_EffectAttrType)type; if(effectAttr.type==_EffectAttrType.Teleport){ uAB.targetType=_AbilityTargetType.EmptyTile; uAB.requireTargetSelection=true; uAB.targetArea=_TargetArea.Default; uAB.aoeRange=0; } else if(effectAttr.type==_EffectAttrType.SpawnUnit || effectAttr.type==_EffectAttrType.SpawnCollectible){ if(effectAttr.type==_EffectAttrType.SpawnUnit){ cont=new GUIContent("Unit To Spawn:", "The unit prefab to be used spawned"); EditorGUI.LabelField(new Rect(startX, startY+=18, 180, 20), cont); effectAttr.unit=(UnitTB)EditorGUI.ObjectField(new Rect(startX, startY+=18, 125, 17), effectAttr.unit, typeof(UnitTB), false); cont=new GUIContent("Duration:", "The effective duration in which the spawned unit will last\nSet to -ve value for the spawn to be permenant" ); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.duration=EditorGUI.IntField(new Rect(startX+70, startY-1, 50, 16), effectAttr.duration); if(effectAttr.duration==0) effectAttr.duration=-1; } else if(effectAttr.type==_EffectAttrType.SpawnCollectible){ cont=new GUIContent("Collectible To Spawn:", "The collectible prefab to be used spawned"); EditorGUI.LabelField(new Rect(startX, startY+=18, 180, 20), cont); effectAttr.collectible=(CollectibleTB)EditorGUI.ObjectField(new Rect(startX, startY+=18, 125, 17), effectAttr.collectible, typeof(CollectibleTB), false); } uAB.targetType=_AbilityTargetType.EmptyTile; uAB.requireTargetSelection=true; uAB.targetArea=_TargetArea.Default; uAB.aoeRange=0; } else if(effectAttr.type==_EffectAttrType.ChangeTargetFaction){ cont=new GUIContent("Chance:", "The chance of success. Take value from 0 to 1"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.value=EditorGUI.FloatField(new Rect(startX+70, startY-1, 50, 16), effectAttr.value); //~ cont=new GUIContent("Duration:", "The effective duration of the faction change"); //~ EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); //~ effectAttr.duration=EditorGUI.IntField(new Rect(startX+70, startY-1, 50, 16), effectAttr.duration); uAB.targetType=_AbilityTargetType.Hostile; uAB.requireTargetSelection=true; uAB.targetArea=_TargetArea.Default; uAB.aoeRange=0; } else if(effectAttr.type==_EffectAttrType.HPDamage){ cont=new GUIContent("UseDefaultValue:", "Check to use the unit default attack damage value"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.useDefaultDamageValue=EditorGUI.Toggle(new Rect(startX+107, startY-1, 50, 16), effectAttr.useDefaultDamageValue); if(!effectAttr.useDefaultDamageValue){ cont=new GUIContent("ValueMin:", "Minimum value for the effect"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.value=EditorGUI.FloatField(new Rect(startX+70, startY-1, 50, 16), effectAttr.value); cont=new GUIContent("ValueMax:", "Maximum value for the effect"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.valueAlt=EditorGUI.FloatField(new Rect(startX+70, startY-1, 50, 16), effectAttr.valueAlt); } } else if(effectAttr.type==_EffectAttrType.HPGain || effectAttr.type==_EffectAttrType.APGain || effectAttr.type==_EffectAttrType.APDamage){ cont=new GUIContent("ValueMin:", "Minimum value for the effect"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.value=EditorGUI.FloatField(new Rect(startX+70, startY-1, 50, 16), effectAttr.value); effectAttr.value=Mathf.Min(effectAttr.value, effectAttr.valueAlt); cont=new GUIContent("ValueMax:", "Maximum value for the effect"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.valueAlt=EditorGUI.FloatField(new Rect(startX+70, startY-1, 50, 16), effectAttr.valueAlt); effectAttr.valueAlt=Mathf.Max(effectAttr.value, effectAttr.valueAlt); } else{ cont=new GUIContent("Value:", "Value for the effect"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.value=EditorGUI.FloatField(new Rect(startX+70, startY-1, 50, 16), effectAttr.value); } //~ if(type==1){ //~ cont=new GUIContent("Range:", "Effective range of the ability in term of tile"); //~ EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), "use Default Damage:"); //~ effect.useDefaultDamageValue=EditorGUI.Toggle(new Rect(startX+120, startY-1, 50, 16), effect.useDefaultDamageValue); //~ } //~ if(type!=2 || !effectAttr.useDefaultDamageValue){ //~ cont=new GUIContent("Range:", "Effective range of the ability in term of tile"); //~ EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), "value:"); //~ effectAttr.value=EditorGUI.FloatField(new Rect(startX+70, startY-1, 50, 16), effectAttr.value); //~ } if(uAB.effectType==_EffectType.Debuff || uAB.effectType==_EffectType.Buff){ if(effectAttr.type!=_EffectAttrType.SpawnUnit){ cont=new GUIContent("Duration:", "Effective duration of the effect in term of round"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.duration=EditorGUI.IntField(new Rect(startX+70, startY-1, 50, 16), effectAttr.duration); } } //~ int type=(int)effectAttr.type; //~ cont=new GUIContent("Type:", "Type of the effect"); //~ contList=new GUIContent[effectAttrTypeLabel.Length]; //~ for(int i=0; i<contList.Length; i++) contList[i]=new GUIContent(effectAttrTypeLabel[i], effectAttrTypeTooltip[i]); //~ EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); //~ type = EditorGUI.Popup(new Rect(startX+40, startY, 80, 16), type, contList); //~ effectAttr.type=(_EffectAttrType)type; if(effectAttr.type==_EffectAttrType.HPDamage){ if(damageList.Length>0){ contList=new GUIContent[damageTooltipList.Length]; for(int i=0; i<contList.Length; i++) contList[i]=new GUIContent(damageList[i], damageTooltipList[i]); cont=new GUIContent("Type:", "Damage type to be inflicted on target"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); effectAttr.damageType = EditorGUI.Popup(new Rect(startX+40, startY, 80, 16), effectAttr.damageType, contList); } else{ cont=new GUIContent("Type:", "No damage type has been created, use DamageArmorTableEditor to create one"); EditorGUI.LabelField(new Rect(startX, startY+=18, 200, 20), cont); if(GUI.Button(new Rect(startX+40, startY, 80, 15), "OpenEditor")){ DamageArmorTableEditor.Init(); } } } }
public Card() { faceUpMat = Resources.Load("n84", typeof(Material)) as Material; faceDownMat = Resources.Load("FaceDownCard", typeof(Material)) as Material; Material mat = Resources.Load("FaceDownCard", typeof(Material)) as Material; faceDownMat = new Material (Shader.Find ("Diffuse")); faceDownMat.mainTexture = Resources.Load("FaceDownCard") as Texture;//mat.mainTexture; faceDownMat.mainTextureOffset = mat.mainTextureOffset; faceDownMat.mainTextureScale = mat.mainTextureScale; bRest = false; bDoRestAnimation = false; bDoEnemyRestAnimation = false; bDoStandAnimation = false; bDoAnimatedFlip = false; extraPower = 0; extraCritical = 0; endTurnPower = 0; secondaryClan = "None"; unitAbilities = new UnitAbility(this); faceDownMat.color = Color.white; _CardAnimationManager = new CardAnimationManager(this); }
public bool Attack(List<Tile> targetTileList, UnitAbility ability){ //if unit ability is not null, there fore it's not a normal attack if((ability==null && attacked) || stun>0) return false; if(attackDisabled>0) return false; attackRemain-=1; if(attackRemain<=0) attacked=true; UnitControl.MoveUnit(this); if(Random.Range(0f, 1f)<GameControlTB.GetActionCamFrequency()){ CameraControl.ActionCam(this.occupiedTile, targetTileList[0]); } _AttackAPCostRule attackRule=GameControlTB.AttackAPCostRule(); if(attackRule==_AttackAPCostRule.PerAttack) AP-=APCostAttack; //if(attackRule==_AttackAPCostRule.PerAttack) AP-=GameControlTB.GetAttackAPCost(); GridManager.Select(occupiedTile); AttackInstance attInstance=new AttackInstance(); attInstance.unitAbility=ability; attInstance.srcUnit=this; if(attInstance.unitAbility==null){ if(attackMode==_AttackMode.Melee){ attInstance.type=_AttackType.Melee_Normal; StartCoroutine(AttackRoutineMelee(targetTileList, attInstance)); } else if(attackMode==_AttackMode.Range){ attInstance.type=_AttackType.Range_Normal; StartCoroutine(AttackRoutineRange(targetTileList, attInstance)); } else if(attackMode==_AttackMode.Hybrid){ int dist=AStar.Distance(occupiedTile, targetTileList[0]); if(dist<=attackRangeMelee){ attInstance.type=_AttackType.Melee_Normal; StartCoroutine(AttackRoutineMelee(targetTileList, attInstance)); } else{ attInstance.type=_AttackType.Range_Normal; StartCoroutine(AttackRoutineRange(targetTileList, attInstance)); } } } else{ if(attInstance.unitAbility.shootMode!=_AbilityShootMode.None){ attInstance.type=_AttackType.Range_Normal; StartCoroutine(AttackRoutineRange(targetTileList, attInstance)); } else{ attInstance.type=_AttackType.Melee_Normal; StartCoroutine(AttackRoutineMelee(targetTileList, attInstance)); } } if(attacked){ GridManager.ClearHostileList(); if(moved) GridManager.Select(null); } return true; }
public void ApplyAbility(UnitAbility ability){ foreach(EffectAttr effectAttr in ability.effectAttrs){ ApplyAbilityEffect(effectAttr); } if(ability.effectType==_EffectType.Buff || ability.effectType==_EffectType.Debuff){ int countD; if(GameControlTB.GetTurnMode()==_TurnMode.FactionAllUnitPerTurn){ countD=UnitControl.activeFactionCount; } else{ countD=UnitControl.GetAllUnitCount(); } ability.countTillNextTurn=countD; activeUnitAbilityEffectList.Add(ability); } if(onEffectAppliedE!=null) onEffectAppliedE(this); }
void ShowTooltip(UnitAbility ability) { #if mousePos GUIStyle style=new GUIStyle(); style.fontStyle=FontStyle.Bold; int width=500; int w_offset =50; int height=160; float posY = Input.mousePosition.y; float posX = Input.mousePosition.x; for(int i=0; i<3; i++) GUI.Box(new Rect(posX-(width+w_offset)/2, posY-230, width+w_offset, height), ""); style.fontSize=20; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperCenter; GUI.Label(new Rect(posX-width/2, posY-240, width, height), ability.name, style); style.fontSize=16; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperRight; GUI.Label(new Rect(posX-width/2-5, posY-240, width, height), ability.cost+"AP", style); style.fontSize=16; style.normal.textColor=UI.colorN; style.alignment=TextAnchor.UpperCenter; style.wordWrap=true; GUI.Label(new Rect(posX-width/2, posY-190, width, height), ability.desp, style); GUI.color=Color.white; #else GUIStyle style=new GUIStyle(); style.fontStyle=FontStyle.Bold; int width=500; int w_offset =50; int height=160; for(int i=0; i<3; i++) GUI.Box(new Rect(Screen.width/2-(width+w_offset)/2, Screen.height-230, width+w_offset, height), ""); style.fontSize=20; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperCenter; GUI.Label(new Rect(Screen.width/2-width/2, Screen.height-200, width, height), ability.name, style); style.fontSize=16; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperRight; GUI.Label(new Rect(Screen.width/2-width/2-5, Screen.height-200, width, height), ability.cost+"AP", style); style.fontSize=16; style.normal.textColor=UI.colorN; style.alignment=TextAnchor.UpperCenter; style.wordWrap=true; GUI.Label(new Rect(Screen.width/2-width/2, Screen.height-180, width, height), ability.desp, style); GUI.color=Color.white; #endif }
//handle when an ability has been activated, apply the ap cost, cd, audtio effect and what not void AbilityActivated(UnitAbility uAB, bool reselect){ GameControlTB.LockUnitSwitching(); //Debug.Log("ability activated"); abilityTriggered=true; UnitControl.MoveUnit(this); AP-=uAB.cost; uAB.cooldown=uAB.cdDuration; if(GameControlTB.GetTurnMode()==_TurnMode.FactionAllUnitPerTurn){ uAB.countTillNextTurn=UnitControl.activeFactionCount; } else{ uAB.countTillNextTurn=UnitControl.GetAllUnitCount(); } uAB.useCount+=1; if(uAB.effectUse!=null){ StartCoroutine(SpawnAbilityEffect(uAB.effectUse, uAB.effectUseDelay, occupiedTile.pos)); } if(uAB.soundUse!=null){ AudioManager.PlaySound(uAB.soundUse, thisT); } if(!uAB.enableMovementAfter) moved=true; if(!uAB.enableAttackAfter) attacked=true; //for ability with shootObject, select() will be called in attack() if(reselect) GridManager.Select(occupiedTile); }
public void SetActiveAbilityPendingTarget(UnitAbility uAB){ activeAbilityPendingTarget=uAB; }
public void UnitAbilityTargetSelected(List<Tile> list){ //AbilityActivated(activeAbilityPendingTarget, false); //StartCoroutine(UnitAbilityTargetSelectedRoutine(list)); //~ UnitAbility unitAbility=activeAbilityPendingTarget; //~ Debug.Log(unitAbility+" lala"); //~ //Debug.Log(unitAbility.name+" "+unitAbility.chainedAbilityIDList.Count); //~ for(int i=0; i<unitAbility.chainedAbilityIDList.Count; i++){ //~ UnitAbility uAB=AbilityManagerTB.GetUnitAbility(unitAbility.chainedAbilityIDList[i]); //~ if(uAB.requireTargetSelection){ //~ activeAbilityPendingTarget=uAB; //~ GridManager.SetTargetTileSelectMode(occupiedTile, uAB); //~ activeAbilityPendingTarget=uAB; //~ GridManager.OnHoverEnter(occupiedTile); //~ GridManager.Select(occupiedTile); //~ } //~ else{ //~ _ActivateAbility(uAB); //~ } //~ } AbilityActivated(activeAbilityPendingTarget, false); StartCoroutine(UnitAbilityTargetSelectedRoutine(list)); activeAbilityPendingTarget=null; return; }
public int _ActivateAbility(UnitAbility unitAbility){ //first check if the ability is available, return the status //~ int status=IsAbilityAvailable(ID); //~ if(status>0){ //~ return status; //~ } if(!unitAbility.requireTargetSelection){ AbilityActivated(unitAbility, true); if(unitAbility.canFail && Random.Range(0f, 1f)<unitAbility.failChance){ new EffectOverlay(thisT.position+new Vector3(0, 0.5f, 0), "failed", new Color(.6f, 1f, 0, 1)); //UITB.DisplayDamageOverlay(thisT.position+new Vector3(0, 0.5f, 0), "failed", new Color(.6f, 1f, 0, 1)); GridManager.Select(occupiedTile); //this is to reset the UI return 0; } List<Tile> tileList=GridManager.GetTilesWithinRange(occupiedTile, unitAbility.aoeRange); tileList.Add(occupiedTile); foreach(Tile tile in tileList){ Debug.DrawLine(tile.pos, tile.pos+new Vector3(0, 3, 0), Color.red, 5); if(unitAbility.targetType==_AbilityTargetType.AllUnits){ if(tile.unit!=null){ StartCoroutine(tile.unit.ApplyAbilityDelay(unitAbility.Clone())); } } if(unitAbility.targetType==_AbilityTargetType.Friendly){ if(tile.unit!=null && tile.unit.factionID==factionID){ StartCoroutine(tile.unit.ApplyAbilityDelay(unitAbility.Clone())); } } else if(unitAbility.targetType==_AbilityTargetType.Hostile){ if(tile.unit!=null && tile.unit.factionID!=factionID){ StartCoroutine(tile.unit.ApplyAbilityDelay(unitAbility.Clone())); } } else if(unitAbility.targetType==_AbilityTargetType.AllTile){ tile.ApplyAbility(unitAbility.Clone()); } } //launch the chained ability for(int i=0; i<unitAbility.chainedAbilityIDList.Count; i++){ UnitAbility uAB=AbilityManagerTB.GetUnitAbility(unitAbility.chainedAbilityIDList[i]); if(uAB.requireTargetSelection){ activeAbilityPendingTarget=uAB; GridManager.SetTargetTileSelectMode(occupiedTile, uAB); GridManager.OnHoverEnter(occupiedTile); GridManager.Select(occupiedTile); } else{ _ActivateAbility(uAB); } } } else{ GridManager.SetTargetTileSelectMode(occupiedTile, unitAbility); activeAbilityPendingTarget=unitAbility; } return 0; }
public UnitAbility Clone() { UnitAbility UAb=new UnitAbility(); UAb.ID=ID; UAb.name=name; UAb.desp=desp; UAb.icon=icon; UAb.iconUnavailable=iconUnavailable; UAb.iconName=iconName; UAb.iconUnavailableName=iconUnavailableName; UAb.factionID=factionID; UAb.targetArea=targetArea; UAb.targetType=targetType; UAb.requireTargetSelection=requireTargetSelection; UAb.enableMovementAfter=enableMovementAfter; UAb.enableAttackAfter=enableAttackAfter; UAb.effectType=effectType; UAb.enableAOE=enableAOE; UAb.aoeRange=aoeRange; //~ UAb.aoe=aoe; UAb.range=range; //~ UAb.duration=duration; UAb.cost=cost; UAb.totalCost=totalCost; UAb.cdDuration=cdDuration; UAb.cooldown=cooldown; UAb.useLimit=useLimit; UAb.useCount=useCount; foreach(EffectAttr effectAttr in effectAttrs){ UAb.effectAttrs.Add(effectAttr.Clone()); } UAb.delay=delay; //~ UAb.effect=effect; UAb.effectUse=effectUse; UAb.effectTarget=effectTarget; UAb.effectUseDelay=effectUseDelay; UAb.effectTargetDelay=effectTargetDelay; UAb.soundUse=soundUse; UAb.soundHit=soundHit; UAb.shootMode=shootMode; UAb.shootObject=shootObject; UAb.canMiss=canMiss; UAb.canFail=canFail; UAb.missChance=missChance; UAb.failChance=failChance; UAb.chainedAbilityIDList=chainedAbilityIDList; return UAb; }
//calculate the active effect on the tile, called in every new round event bool CalulateEffect(UnitAbility ability) { //loop through all the active effect list for(int j=0; j<ability.effectAttrs.Count; j++){ EffectAttr effectAttr=ability.effectAttrs[j]; effectAttr.duration-=1; //if the effect duration has reach zero, cancel it by changing the modifier if(effectAttr.duration==0){ //commented effect are disabled for tile if(effectAttr.type==_EffectAttrType.HPDamage){ HPGainModifier+=(int)effectAttr.value; } else if(effectAttr.type==_EffectAttrType.HPGain){ HPGainModifier-=(int)effectAttr.value; } else if(effectAttr.type==_EffectAttrType.APDamage){ APGainModifier+=(int)effectAttr.value; } else if(effectAttr.type==_EffectAttrType.APGain){ APGainModifier-=(int)effectAttr.value; } else if(effectAttr.type==_EffectAttrType.Damage){ damageModifier-=(int)effectAttr.value; } //~ else if(effectAttr.type==_EffectAttrType.MovementRange){ //~ movementModifier-=(int)effectAttr.value; //~ } else if(effectAttr.type==_EffectAttrType.AttackRange){ attRangeModifier-=(int)effectAttr.value; } //~ else if(effectAttr.type==_EffectAttrType.Speed){ //~ speedModifier-=(int)effectAttr.value; //~ } else if(effectAttr.type==_EffectAttrType.HitChance){ attackModifier-=effectAttr.value; } else if(effectAttr.type==_EffectAttrType.DodgeChance){ defendModifier-=effectAttr.value; } else if(effectAttr.type==_EffectAttrType.CriticalChance){ criticalModifier-=effectAttr.value; } else if(effectAttr.type==_EffectAttrType.CriticalImmunity){ critDefModifier-=effectAttr.value; } /* //~ else if(effectAttr.type==_EffectAttrType.ExtraAttack){ //~ extraAttackModifier-=1; //~ } //~ else if(effectAttr.type==_EffectAttrType.ExtraCounterAttack){ //~ counterAttackModifier-=1; //~ } //~ else if(effectAttr.type==_EffectAttrType.Stun){ //~ stun-=1; //~ } //~ else if(effectAttr.type==_EffectAttrType.DisableAttack){ //~ attackDisabled-=1; //~ } //~ else if(effectAttr.type==_EffectAttrType.DisableMovement){ //~ movementDisabled-=1; //~ } //~ else if(effectAttr.type==_EffectAttrType.DisableAbility){ //~ abilityDisabled-=1; //~ } */ //remove the effect from the ability ability.effectAttrs.RemoveAt(j); j-=1; } } //if there's no more effect active for the ability, return false, the ability will be removed if(ability.effectAttrs.Count==0){ return false; } return true; }
//apply a unit ability to the tile public void ApplyAbility(UnitAbility ability) { //spawn effect if any if(ability.effectTarget!=null){ StartCoroutine(SpawnAbilityEffect(ability.effectTarget, ability.effectTargetDelay, pos)); } //loop through the effect list and change the modifier //commented effect are disabled for tile foreach(EffectAttr effectAttr in ability.effectAttrs){ if(effectAttr.type==_EffectAttrType.HPDamage){ effectAttr.value=Random.Range(effectAttr.value, effectAttr.valueAlt); HPGainModifier-=(int)effectAttr.value; if(unit!=null) unit.ApplyDamage((int)effectAttr.value); } else if(effectAttr.type==_EffectAttrType.HPGain){ effectAttr.value=Random.Range(effectAttr.value, effectAttr.valueAlt); HPGainModifier+=(int)effectAttr.value; if(unit!=null) unit.ApplyHeal((int)effectAttr.value); } else if(effectAttr.type==_EffectAttrType.APDamage){ effectAttr.value=Random.Range(effectAttr.value, effectAttr.valueAlt); APGainModifier+=(int)effectAttr.value; if(unit!=null) unit.GainAP(-(int)effectAttr.value); } else if(effectAttr.type==_EffectAttrType.APGain){ effectAttr.value=Random.Range(effectAttr.value, effectAttr.valueAlt); APGainModifier-=(int)effectAttr.value; if(unit!=null) unit.GainAP((int)effectAttr.value); } else if(effectAttr.type==_EffectAttrType.Damage){ damageModifier+=(int)effectAttr.value; } //~ else if(effectAttr.type==_EffectAttrType.MovementRange){ //~ movementModifier+=(int)effectAttr.value; //~ } else if(effectAttr.type==_EffectAttrType.AttackRange){ attRangeModifier+=(int)effectAttr.value; } //~ else if(effectAttr.type==_EffectAttrType.Speed){ //~ speedModifier+=(int)effectAttr.value; //~ } else if(effectAttr.type==_EffectAttrType.HitChance){ attackModifier+=effectAttr.value; } else if(effectAttr.type==_EffectAttrType.DodgeChance){ defendModifier+=effectAttr.value; } else if(effectAttr.type==_EffectAttrType.CriticalChance){ criticalModifier+=effectAttr.value; } else if(effectAttr.type==_EffectAttrType.CriticalImmunity){ critDefModifier+=effectAttr.value; } //~ else if(effectAttr.type==_EffectAttrType.ExtraAttack){ //~ } //~ else if(effectAttr.type==_EffectAttrType.ExtraCounterAttack){ //~ } //~ else if(effectAttr.type==_EffectAttrType.Stun){ //~ } //~ else if(effectAttr.type==_EffectAttrType.DisableAttack){ //~ } //~ else if(effectAttr.type==_EffectAttrType.DisableMovement){ //~ } //~ else if(effectAttr.type==_EffectAttrType.DisableAbility){ //~ } //~ else if(effectAttr.type==_EffectAttrType.Teleport){ //~ } } if(activeUnitAbilityEffectList.Count==0){ SubscribeEvent(); if(GameControlTB.GetTurnMode()==_TurnMode.FactionAllUnitPerTurn){ countTillNextTurn=UnitControl.activeFactionCount; } else{ countTillNextTurn=UnitControl.GetAllUnitCount(); } } if(GameControlTB.GetTurnMode()==_TurnMode.FactionAllUnitPerTurn){ ability.countTillNextTurn=UnitControl.activeFactionCount; } else{ ability.countTillNextTurn=UnitControl.GetAllUnitCount(); } //add the ability to the list so it can be keep tracked activeUnitAbilityEffectList.Add(ability); }
/* //obsolete public static void SetTargetTileSelectMode1(Tile tile, int range, _EffectType effType, _AbilityTargetType tgtType, bool aoe, int aoeRange){ targetTileSelectMode=true; targetTileSelectRange=range; targetTileSelectEffectType=effType; targetTileSelectTargetType=tgtType; enableTargetTileAOE=aoe; targetTileAOERange=aoeRange; if(!enableTargetTileAOE) targetTileAOERange=0; //clear all the tile in walkeble and hostile list foreach(Tile walkableTile in walkableList){ walkableTile.SetState(_TileState.Default); } foreach(Tile hostileTile in hostileList){ hostileTile.SetState(_TileState.Default); } //highlight the tile within the ability range List<Tile> list=GetTilesWithinRange(tile, targetTileSelectRange); foreach(Tile tileInRange in list){ if(tileInRange.walkable){ tilesInAbilityRange.Add(tileInRange); tileInRange.SetState(_TileState.AbilityRange); } } } */ //exit alternate tile hover/select mode for target selection of unitAbility public static void ExitTargetTileSelectMode() { targetTileSelectMode=false; currentUAB=null; OnHoverTargetTileExit(); //clear all the current highlighted tiles for ability foreach(Tile tile in tilesInAbilityRange){ tile.SetState(_TileState.Default); } tilesInAbilityRange=new List<Tile>(); //reset and highlight the walkeble and hostile list if(UnitControl.selectedUnit!=null){ foreach(Tile walkableTile in walkableList){ walkableTile.SetState(_TileState.Walkable); } foreach(Tile hostileTile in hostileList){ hostileTile.SetState(_TileState.Hostile); } } }
//activate alternate tile hover/select mode for target selection of unitAbility //when this is called, the selection mode swtich to allow a target for the ability to be selected public static void SetTargetTileSelectMode(Tile tile, UnitAbility uAB) { targetTileSelectMode=true; currentUAB=uAB; uABScrTile=tile; //clear all the tile in walkeble and hostile list foreach(Tile walkableTile in walkableList){ walkableTile.SetState(_TileState.Default); } foreach(Tile hostileTile in hostileList){ hostileTile.SetState(_TileState.Default); } if(uAB.targetArea==_TargetArea.Default){ //highlight the tile within the ability range List<Tile> list=GetTilesWithinRange(tile, currentUAB.range); foreach(Tile tileInRange in list){ if(tileInRange.walkable){ if(uAB.targetType==_AbilityTargetType.AllTile){ if(tileInRange.unit==null){ tilesInAbilityRange.Add(tileInRange); tileInRange.SetState(_TileState.AbilityRange); } } else{ tilesInAbilityRange.Add(tileInRange); tileInRange.SetState(_TileState.AbilityRange); } } } } }
public IEnumerator ApplyAbilityDelay(UnitAbility unitAbility){ if(unitAbility.canMiss){ float missChance=unitAbility.missChance; //if(unitAbility.stackMissWithDodge) missChance+=defend; if(unitAbility.stackMissWithDodge){ //cover bonus does not work with ability //if(GameControlTB.EnableCover()){ // coverDefBonus=targetTile.GetCoverDefendBonus(srcUnit.occupiedTile.pos); //} missChance+=GetDefend();//+coverDefBonus; } if(Random.Range(0f, 1f)<missChance){ //UITB.DisplayDamageOverlay(thisT.position+new Vector3(0, 0.5f, 0), "missed", new Color(.6f, 1f, 0, 1)); new EffectOverlay(thisT.position+new Vector3(0, 0.5f, 0), "missed", new Color(.6f, 1f, 0, 1)); yield break; } } //~ yield return new WaitForSeconds(unitAbility.delay); ApplyAbility(unitAbility); yield return null; }