void AttackMiss(AttackInstance inst) { if (_floatingText != null) { _floatingText.ShowText("Missed", Color.white, 1f); } }
public override void OnTimerTick() { if (IsNull()) { return; } IBotHandler AttackInstance; if (GetBotRoleplay().Dead) { return; } if (this.ReturnAttackHandler(out AttackInstance)) { if (AttackInstance.Active) { AttackInstance.ExecuteHandler(); return; } } GetBotRoleplay().HandleRoaming(); }
IEnumerator ShootRoutine() { AttackStats aStats = new AttackStats(); aStats.damageMin = damage; aStats.damageMax = damage; for (int i = 0; i < rounds; i++) { yield return(new WaitForSeconds(shotDelay)); for (int n = 0; n < spinObject.childCount; n++) { Transform sp = spinObject.GetChild(n); UnitPlayer player = GameControl.GetPlayer(); AttackInstance attInstance = new AttackInstance(player, aStats); GameObject soObj = (GameObject)Instantiate(shootObject, sp.position, sp.rotation); soObj.GetComponent <ShootObject>().Shoot(player.thisObj.layer, range, sp, attInstance); } } yield return(null); Destroy(gameObject); }
//shoot at tile public void Shoot(Tile tgt, AttackInstance aInstance) { float val=GridManager.GetTileSize()/4; offsetPos=new Vector3(Random.Range(-val, val), Random.Range(0, val/2), Random.Range(-val, val)); if(tgt.unit!=null) targetUnit=tgt.unit; targetTile=tgt; targetPos=targetTile.pos+offsetPos; Shoot(aInstance); }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "Attack") { AttackInstance script = col.gameObject.GetComponent <AttackInstance>(); if (script.myElementalType == ElementalType.fire) { Die(); } } }
//for ability shootToCenter public void Shoot(Vector3 pos, List <Tile> allTgt, AttackInstance aInstance) { float val = GridManager.GetTileSize() / 4; offsetPos = new Vector3(Random.Range(-val, val), Random.Range(0, val / 2), Random.Range(-val, val)); targetUnit = null; targetTile = null; targetPos = pos + offsetPos; targetTileList = allTgt; Shoot(aInstance); }
public void Shoot(UnitTB tgt, AttackInstance aInstance, bool missed) { attMissed=missed; float val=GridManager.GetTileSize()/(missed ? 2f : 8); offsetPos=new Vector3(Random.Range(-val, val), Random.Range(0, val/2), Random.Range(-val, val)); targetUnit=tgt; if(tgt!=null) targetPos=targetUnit.GetTargetT().position+offsetPos; if(tgt!=null) targetTile=targetUnit.occupiedTile; Shoot(aInstance); }
void OnCollisionEnter2D(Collision2D other) { if (other.transform.tag == "Attack") { AttackInstance attckinst = other.gameObject.GetComponent <AttackInstance>(); if (attckinst.owner == myGameObject) { return; } lastThingToHitMe = attckinst.owner; TakeDam(attckinst.damage); } }
//shoot at tile public void Shoot(Tile tgt, AttackInstance aInstance) { float val = GridManager.GetTileSize() / 4; offsetPos = new Vector3(Random.Range(-val, val), Random.Range(0, val / 2), Random.Range(-val, val)); if (tgt.unit != null) { targetUnit = tgt.unit; } targetTile = tgt; targetPos = targetTile.pos + offsetPos; Shoot(aInstance); }
void OnCollisionEnter2D(Collision2D col) { AttackInstance recievedAttack = col.gameObject.GetComponent("AttackInstance") as AttackInstance; if (recievedAttack == null) { return; } if (recievedAttack.myTeam != myTeam) { currentStats.health -= recievedAttack.damage; } // lastThingToHitMe=recievedAttack.owner; }
private void StartAttacking(GameClient TargetClient) { IBotHandler AttackInstance; if (ReturnAttackHandler(out AttackInstance)) { if (AttackInstance.InteractingUser != TargetClient) { AttackInstance.AssignInteractingUser(TargetClient); } AttackInstance.Active = true; return; } this.GetBotRoleplay().StartHandler(Handlers.ATTACK, out AttackInstance, TargetClient); AttackInstance.SetValues("attack_pos", Convert.ToString(this.GetBotRoleplay().DefaultAttackPosition)); }
public void Shoot(UnitTB tgt, AttackInstance aInstance, bool missed) { attMissed = missed; float val = GridManager.GetTileSize() / (missed ? 2f : 8); offsetPos = new Vector3(Random.Range(-val, val), Random.Range(0, val / 2), Random.Range(-val, val)); targetUnit = tgt; if (tgt != null) { targetPos = targetUnit.GetTargetT().position + offsetPos; } if (tgt != null) { targetTile = targetUnit.occupiedTile; } Shoot(aInstance); }
IEnumerator ShootRoutine() { AttackStats aStats = new AttackStats(); aStats.damageMin = damage; aStats.damageMax = damage; Vector3 offsetPos = new Vector3(0, 0.75f, 0); while (true) { yield return(new WaitForSeconds(Random.Range(0.5f * cooldown, 2f * cooldown))); for (int n = 0; n < 12; n++) { UnitPlayer player = GameControl.GetPlayer(); AttackInstance attInstance = new AttackInstance(player, aStats); GameObject soObj = (GameObject)Instantiate(shootObject, thisT.position + offsetPos, Quaternion.Euler(0, n * 30, 0)); soObj.GetComponent <ShootObject>().Shoot(player.thisObj.layer, range, thisT, attInstance); } } }
public void Shoot(AttackInstance aInstance) { thisT = transform; attInstance = aInstance; if (type == _ShootObjectType.Projectile) { StartCoroutine(ProjectileRoutine()); } else if (type == _ShootObjectType.Missile) { StartCoroutine(MissileRoutine()); } else if (type == _ShootObjectType.Beam) { StartCoroutine(BeamRoutine()); } else if (type == _ShootObjectType.Effect) { StartCoroutine(EffectRoutine()); } }
public void Shoot(AttackInstance aInstance) { thisT=transform; attInstance=aInstance; if(type==_ShootObjectType.Projectile) StartCoroutine(ProjectileRoutine()); else if(type==_ShootObjectType.Missile) StartCoroutine(MissileRoutine()); else if(type==_ShootObjectType.Beam) StartCoroutine(BeamRoutine()); else if(type==_ShootObjectType.Effect) StartCoroutine(EffectRoutine()); }
//coroutine to actually attack a target, called from Attack or CounterAttack //for melee attack (untested) IEnumerator AttackRoutineMelee(List<Tile> targetTileList, AttackInstance attInstance){ while(GameControlTB.ActionCommenced()){ yield return null; } foreach(Tile tile in targetTileList){ if(tile.unit!=null) tile.unit.RotateToUnit(this); } Vector3 targetPos=Vector3.zero; if(targetTileList.Count>1){ foreach(Tile tile in targetTileList){ targetPos+=tile.pos; } targetPos/=targetTileList.Count; } else targetPos=targetTileList[0].pos; targetPos=(thisT.position+targetPos)/2; //rotate to destination Quaternion wantedRot=Quaternion.LookRotation(targetPos-thisT.position); while(true){ thisT.rotation=Quaternion.Slerp(thisT.rotation, wantedRot, Time.deltaTime*rotateSpeed); if(Quaternion.Angle(thisT.rotation, wantedRot)<1){ thisT.rotation=wantedRot; break; } yield return null; } actionQueued+=1; audioTB.PlayMeleeAttack(); float delay=animationTB.PlayMeleeAttack(); yield return new WaitForSeconds(delay); UnitTB targetUnit=null; if(targetTileList.Count>0){ targetUnit=targetTileList[0].unit; if(targetUnit!=null){ attInstance.Process(targetUnit); attInstance=targetUnit.ApplyHitEffect(attInstance); } } thisT.position=occupiedTile.thisT.position; yield return new WaitForSeconds(0.5f); actionQueued-=1; if(actionQueued<=0){ actionQueued=0; if(attInstance!=null){ if(attInstance.type!=_AttackType.Melee_Counter && attInstance.type!=_AttackType.Range_Counter){ //if the attack is not counter attack, complete the action using delay based on if the target is destroyed if(attInstance.destroyed) StartCoroutine(ActionComplete(attInstance.destroyEffectDuration)); else if(!attInstance.counterAttacking){ //complete action is target is not counterAttacking //otherwise waiting for counter attack to complete, CounterAttackComplete will be called StartCoroutine(ActionComplete(0.25f)); } } //if the attack is counter attack, tell the attacker that the counter attack has been completed else { if(targetUnit!=null) targetUnit.CounterAttackComplete(attInstance); } } else{ StartCoroutine(ActionComplete(0.25f)); } } }
//for ability shootToCenter public void Shoot(Vector3 pos, List<Tile> allTgt, AttackInstance aInstance) { float val=GridManager.GetTileSize()/4; offsetPos=new Vector3(Random.Range(-val, val), Random.Range(0, val/2), Random.Range(-val, val)); targetUnit=null; targetTile=null; targetPos=pos+offsetPos; targetTileList=allTgt; Shoot(aInstance); }
//shoot at unit public void Shoot(UnitTB tgt, AttackInstance aInstance) { Shoot(tgt, aInstance, false); }
//called by shootObject when hit the target public void HitTarget(UnitTB target, AttackInstance attInstance){ StartCoroutine(_HitTarget(target, attInstance)); }
//coroutine to actually attack a target, called from Attack or CounterAttack //for range attack IEnumerator AttackRoutineRange(List<Tile> targetTileList, AttackInstance attInstance){ while(GameControlTB.ActionCommenced()){ yield return null; } foreach(Tile tile in targetTileList){ if(tile.unit!=null) tile.unit.RotateToUnit(this); } Vector3 targetPos=Vector3.zero; foreach(Tile tile in targetTileList){ targetPos+=tile.pos; } targetPos/=targetTileList.Count; Vector3 pos=turretObject.position; pos.y=targetPos.y; Quaternion wantedRot=Quaternion.LookRotation(targetPos-pos); actionQueued+=1; while(true){ turretObject.rotation=Quaternion.Slerp(turretObject.rotation, wantedRot, Time.deltaTime*5); if(Quaternion.Angle(turretObject.rotation, wantedRot)<1){ turretObject.rotation=wantedRot; break; } yield return null; } float delay=animationTB.PlayRangeAttack(); yield return new WaitForSeconds(delay); if(attInstance.unitAbility!=null){ GameObject so=shootObject; if(attInstance.unitAbility.shootObject!=null) so=attInstance.unitAbility.shootObject; if(attInstance.unitAbility.shootMode==_AbilityShootMode.ShootToAll){ actionQueued+=(Mathf.Max(0, targetTileList.Count-1)); foreach(Tile tile in targetTileList){ for(int i=0; i<shootPoints.Count; i++){ audioTB.PlayRangeAttack(); Transform sp=shootPoints[i]; GameObject obj=(GameObject)Instantiate(so, sp.position, sp.rotation); ShootObjectTB shootObj=obj.GetComponent<ShootObjectTB>(); if(i==shootPoints.Count-1){ shootObj.Shoot(tile, attInstance); shootObj.SetAbilityTargetTile(abilityTargetTile); } else shootObj.Shoot(tile, null); yield return new WaitForSeconds(0.05f); } yield return new WaitForSeconds(0.05f); } } else if(attInstance.unitAbility.shootMode==_AbilityShootMode.ShootToCenter){ for(int i=0; i<shootPoints.Count; i++){ audioTB.PlayRangeAttack(); Transform sp=shootPoints[i]; GameObject obj=(GameObject)Instantiate(so, sp.position, sp.rotation); ShootObjectTB shootObj=obj.GetComponent<ShootObjectTB>(); if(i==shootPoints.Count-1){ shootObj.Shoot(targetPos, targetTileList, attInstance); shootObj.SetAbilityTargetTile(abilityTargetTile); } else shootObj.Shoot(targetPos, targetTileList, null); yield return new WaitForSeconds(0.05f); } } else{ Debug.Log("ability shoot mode error"); } } else{ actionQueued+=(Mathf.Max(0, targetTileList.Count-1)); foreach(Tile tile in targetTileList){ UnitTB targetUnit=tile.unit; if(targetUnit!=null) attInstance.Process(targetUnit); for(int i=0; i<shootPoints.Count; i++){ audioTB.PlayRangeAttack(); Transform sp=shootPoints[i]; //Debug.DrawLine(sp.position, sp.position+new Vector3(0, 9, 0), Color.red, 4); GameObject obj=(GameObject)Instantiate(shootObject, sp.position, sp.rotation); ShootObjectTB shootObj=obj.GetComponent<ShootObjectTB>(); if(i==shootPoints.Count-1){ if(targetUnit!=null) shootObj.Shoot(targetUnit, attInstance.Clone(), attInstance.missed); //~ else shootObj.Shoot(tile, attInstance.Clone(), attInstance.missed); } else{ if(targetUnit!=null) shootObj.Shoot(targetUnit, null, attInstance.missed); //~ else shootObj.Shoot(tile, null, attInstance.missed); } yield return new WaitForSeconds(0.05f); } yield return new WaitForSeconds(0.05f); } } yield return new WaitForSeconds(0.15f); }
IEnumerator _HitTarget(UnitTB target, AttackInstance attInstance){ //HitResult hitResult=null; //apply the attackInfo to the target, get the hit result info in return if(target!=null){ attInstance=target.ApplyHitEffect(attInstance); } yield return new WaitForSeconds(0.1f); actionQueued-=1; if(actionQueued<=0){ actionQueued=0; if(attInstance!=null){ //~ if(!hitResult.counterAttack){ if(attInstance.type!=_AttackType.Melee_Counter && attInstance.type!=_AttackType.Range_Counter){ //if the attack is not counter attack, complete the action using delay based on if the target is destroyed if(attInstance.destroyed) StartCoroutine(ActionComplete(attInstance.destroyEffectDuration)); else if(!attInstance.counterAttacking){ //complete action if target is not counterAttacking //otherwise waiting for counter attack to complete, CounterAttackComplete will be called StartCoroutine(ActionComplete(0.25f)); } } //if the attack is counter attack, tell the attacker that the counter attack has been completed else target.CounterAttackComplete(attInstance); //~ } } else{ StartCoroutine(ActionComplete(0.25f)); } } }
//similar to attack(), but called when unit is performing an counter attack public void CounterAttack(UnitTB target){ List<Tile> targetTileList=new List<Tile>(); targetTileList.Add(target.occupiedTile); AttackInstance attInstance=new AttackInstance(); attInstance.srcUnit=this; if(attackMode==_AttackMode.Melee){ attInstance.type=_AttackType.Melee_Counter; StartCoroutine(AttackRoutineMelee(targetTileList, attInstance)); } else if(attackMode==_AttackMode.Range){ attInstance.type=_AttackType.Range_Counter; StartCoroutine(AttackRoutineRange(targetTileList, attInstance)); } else if(attackMode==_AttackMode.Hybrid){ int dist=AStar.Distance(occupiedTile, targetTileList[0]); if(dist<=attackRangeMelee){ attInstance.type=_AttackType.Melee_Counter; StartCoroutine(AttackRoutineMelee(targetTileList, attInstance)); } else{ attInstance.type=_AttackType.Range_Counter; StartCoroutine(AttackRoutineRange(targetTileList, attInstance)); } } }
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; }
//function call to calculate the hit stats public void ApplyDamage(AttackInstance attInstance){ if(attInstance.missed){ if(thisObj.layer!=LayerManager.GetLayerUnitAIInvisible()){ new EffectOverlay(thisT.position+new Vector3(0, 0.5f, 0), "missed", new Color(.6f, 1f, 0, 1)); //UITB.DisplayDamageOverlay(thisT.position+new Vector3(0, 0.5f, 0), "missed", new Color(.6f, 1f, 0, 1)); } return; } if(thisObj.layer!=LayerManager.GetLayerUnitAIInvisible()){ if(attInstance.critical){ new EffectOverlay(thisT.position+new Vector3(0, 0.5f, 0), "Critical! ("+attInstance.damageDone.ToString()+")"); //UITB.DisplayDamageOverlay(thisT.position+new Vector3(0, 0.5f, 0), "Critical! ("+attInstance.damageDone.ToString()+")"); } else{ new EffectOverlay(thisT.position+new Vector3(0, 0.5f, 0), attInstance.damageDone.ToString()); //UITB.DisplayDamageOverlay(thisT.position+new Vector3(0, 0.5f, 0), attInstance.damageDone.ToString()); } } ApplyDamage(attInstance.damageDone); }
//shoot at unit public void Shoot(UnitTB tgt, AttackInstance aInstance) { Shoot(tgt, aInstance, false); }
//called by attacker's target when the counter attack is completed public void CounterAttackComplete(AttackInstance attInstance){ if(!attInstance.destroyed) StartCoroutine(ActionComplete(0.25f)); else{ StartCoroutine(ActionComplete(attInstance.destroyEffectDuration)); } }
//called by attacker to apply attackInfo when a unit is attacked and hit public AttackInstance ApplyHitEffect(AttackInstance attInstance){ //HitResult hitResult= ApplyDamage(attInstance); if(attInstance.missed) audioTB.PlayMissed(); else{ audioTB.PlayHit(); animationTB.PlayHit(); } if(!ContainedInAttackerList(attInstance.srcUnit)){ Attacker attacker=new Attacker(attInstance.srcUnit); attackerList.Add(attacker); } triggered=true; //perform counter attack if possible //if the rule allows it if(attInstance.type==_AttackType.Range_Normal || attInstance.type==_AttackType.Melee_Normal){ if(GameControlTB.IsCounterAttackEnabled()){ //if the target is still not destroyed and have a counter attack move remain if(!attInstance.destroyed && counterAttackRemain>0){ //if the attacker is within attack distance float dist=AStar.Distance(occupiedTile, attInstance.srcUnit.occupiedTile); if(dist>=GetAttackRangeMin() && dist<=GetAttackRangeMax()){ attInstance.counterAttacking=true; StartCoroutine(CounterAttackRoutine(attInstance.srcUnit)); } } } } return attInstance; }
public AttackInstance Clone(){ AttackInstance attInst=new AttackInstance(); attInst.type=type; attInst.unitAbility=unitAbility; attInst.shootObj=shootObj; attInst.srcUnit=srcUnit; attInst.targetUnit=targetUnit; attInst.processed=processed; attInst.destroyed=destroyed; attInst.missed=missed; attInst.critical=critical; attInst.counterAttacking=counterAttacking; attInst.damageDone=damageDone; attInst.destroyEffectDuration=destroyEffectDuration; return attInst; }