Пример #1
0
 void AttackMiss(AttackInstance inst)
 {
     if (_floatingText != null)
     {
         _floatingText.ShowText("Missed", Color.white, 1f);
     }
 }
Пример #2
0
        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();
        }
Пример #3
0
    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);
    }
Пример #4
0
    //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);
    }
Пример #5
0
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag == "Attack")
     {
         AttackInstance script = col.gameObject.GetComponent <AttackInstance>();
         if (script.myElementalType == ElementalType.fire)
         {
             Die();
         }
     }
 }
Пример #6
0
    //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);
    }
Пример #7
0
    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);
    }
Пример #8
0
 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);
     }
 }
Пример #9
0
    //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);
    }
Пример #10
0
    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;
    }
Пример #11
0
        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));
        }
Пример #12
0
    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);
    }
Пример #13
0
    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);
            }
        }
    }
Пример #14
0
    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());
        }
    }
Пример #15
0
    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());
    }
Пример #16
0
	//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));
			}
		}
	}
Пример #17
0
    //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);
    }
Пример #18
0
 //shoot at unit
 public void Shoot(UnitTB tgt, AttackInstance aInstance)
 {
     Shoot(tgt, aInstance, false);
 }
Пример #19
0
	//called by shootObject when hit the target
	public void HitTarget(UnitTB target, AttackInstance attInstance){
		StartCoroutine(_HitTarget(target, attInstance));
	}
Пример #20
0
	//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);
	}
Пример #21
0
	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));
			}
		}
	}
Пример #22
0
	//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));
			}
		}
	}
Пример #23
0
	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;
	}
Пример #24
0
	//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);
	}
Пример #25
0
 //shoot at unit
 public void Shoot(UnitTB tgt, AttackInstance aInstance)
 {
     Shoot(tgt, aInstance, false);
 }
Пример #26
0
	//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));
		}
	}
Пример #27
0
	//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;
	}
Пример #28
0
	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;
	}