// Update is called once per frame void Update() { // Make one sprite appears before the others that are UP to the screen spriteR.sortingOrder = Mathf.RoundToInt(transform.position.y * 100f) * -1; // Run combat checks if (isCombat && isAlive) { if (isActive) { if (!isMoving && !isCasting) { // Recuce the time from the attack countdown. foreach (Weapons wep in weapons) { // If the char hasn't attacked for a time, it resets the attack countdown, but just as half of the speed. if (wep.attackCooldown > -wep.attackSpeed / 2) { wep.attackCooldown -= Time.deltaTime * (1 + C.Properties[Properties.AttackSpeed].GetValue() / 100f); } else { wep.attackCooldown += wep.attackSpeed; } } // reduce the time from the casting countdown castingTimer -= Time.deltaTime * (1 + C.Properties[Properties.CastingSpeed].GetValue() / 100f); } // Check each weapon to see if its time to attack foreach (Weapons wep in weapons) { if (wep.attackCooldown <= 0 && !isMoving && isActive && !isCasting) { // Get a list of possibler targets in range of its weapon List <CombatChar> targets = GetTargetsOnRange(wep.range, CombatManager.Targets.Enemies); // ignore weapons attack if there is no target in range. if (targets == null) { //Debug.Log("no target"); continue; } else { // Get one target based on its Threat level. CombatChar target = GetAttackTarget(targets); // Check is has LOS and perform the attack if (InLOS(target.transform)) { StartCoroutine(AttackAnim(wep, target, false)); wep.attackCooldown += wep.attackSpeed; } } } } // Decide which power is going to be used. if (castTarget == null && chargedPower == null && castingTimer <= 0f) { combatAI.CheckPower(); } if (castTarget != null && chargedPower != null && castingTimer <= -0.5f) { castTarget.sprite.GetComponent <SpriteOutline>().enabled = false; castTarget = null; chargedPower = null; combatAI.CheckPower(); } // Show casting spell name and give the chance to be interrupted. if (castTarget != null && chargedPower != null && castingTimer <= 1.5f && !canBeInterruped) { InitCBT(chargedPower.name, "SpellName"); canBeInterruped = true; } // Check is can cast the spell and then cast it if (castingTimer <= 0 && castTarget != null && chargedPower != null && castTarget.isTarget && !isMoving && castTarget.isAlive) { if (checkInRange(castTarget, chargedPower.range) && InLOS(castTarget.transform)) { chargedPower.usePower(this, castTarget); } // Clean ewverything about the power and the target castTarget.sprite.GetComponent <SpriteOutline>().enabled = false; castTarget = null; chargedPower = null; canBeInterruped = false; } } } }