// ATTACK public void attack(AbstractEntity enemy, Vector3 enemyPos){ this.lookAt(enemyPos); if(this.isAlive() && enemy.isAlive()){ if (timeForNextAction<=0){ float randomNumber = Random.Range(0f,100f); if (randomNumber<25){ if (animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", false); if (!animator.GetBool("critical")) animator.SetBool ("critical", true); PNJAudio.PlayCriticalAttack(); // PlayAttackOK enemy.onAttackReceived (4*DMG); timeForNextAction = timecost_perAction; }else{ if (animator.GetBool("critical")) animator.SetBool ("critical", false); if (!animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", true); PNJAudio.PlayAttackOK(); // PlayCriticalAttack enemy.onAttackReceived (DMG); timeForNextAction = timecost_perAction; } } }else if (animator.GetBool("attack_enabled")){ animator.SetBool("attack_enabled",false); }else if (animator.GetBool("critical")){ animator.SetBool("critical",false); } }
//Update is called once per frame void FixedUpdate() { if (!this.paused) { if (freeze <= 0.0) { //Magia de Foc apretant la tecla 1 if (Input.GetKeyDown(KeyCode.Alpha1)) { Debug.Log("Apretat 1"); nextMagicAttack = 1; } if (Input.GetMouseButton(0)) { this.clickPressed = true; } else { if (Input.GetMouseButtonUp(0)) { this.clickPressed = false; } } if (this.leftPressedMouse()) { anim.SetBool("Walk", true); if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, ~(1 << 8))) { if (hit.transform) { targetPosition = hit.point; targetPosition.y = 0; anim.SetBool("attackMelee", false); if (this.isAlive()) { PJAudio.PlayWalkSounds(); } } } } //RaycastHit hit; // cast a ray from mouse pointer: Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // if enemy hit... if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, ~(1 << 8)) && hit.transform.CompareTag("Enemy") && Input.GetMouseButtonDown(1)) { //distancia entre el personatge principal i l'enemic //es calcula en metres //obtinc la aranya AbstractEntity Aranya = (AbstractEntity)hit.collider.GetComponent("AbstractEntity"); float z = transform.rotation.z; transform.LookAt(hit.point); Quaternion r = transform.rotation; r.z = z; transform.rotation = r; float distancia = (transform.position - Aranya.transform.position).magnitude - Aranya.distanceRadiusReduction; Debug.Log("Distancia:" + distancia); switch (nextMagicAttack) { case 1: if (distancia > 90) { Debug.Log("Cal fer una magia de foc pero estas massa lluny"); } else { //anim.setBool("spellFire",true); if (this.substractManaSpell((int)(manaSpellCost * this.getMAXMP()))) { //so de llencar la magia de foc //animacio de la magia Magia.throwParticle(this.gameObject, hit.point); //Merge devel anim.SetBool("magic", true); Aranya.onAttackReceived(Random.Range(minAP, maxAP)); } else { //so de que no te magia suficient? } Debug.Log("Magia de foc!"); nextMagicAttack = 0; } break; case 0: if (distancia > physicalAttackRange) { //cal restar vida de l'aranya, parlar amb Jordi Debug.Log("Distancia: " + distancia); Debug.Log("No puc atacar cos a cos"); } else { //ataco a l'aranya Aranya.onAttackReceived(this.getDMG()); int probFailAttack = Random.Range(0, 10); //si falla (10% dels cops fallara) if (probFailAttack < 1) { PJAudio.PlayAttackFAIL(); } else { PJAudio.PlayAttackOK(); Aranya.onAttackReceived(Random.Range(this.getDMG() / 2, this.getDMG())); } anim.SetBool("attackMelee", true); Debug.Log("Atac cos a cos"); } break; } } MoveTowardsTarget(targetPosition); } else { this.freeze -= Time.deltaTime; if (freeze <= 0) { Renderer[] renderers = gameObject.GetComponentsInChildren <Renderer> (); for (int i = 0; i < renderers.Length; i++) { renderers[i].enabled = true; } } } } //Debug.Log ("Actual pos:"+transform.position + "target pos:"+targetPosition); }
// ATTACK public void attack(AbstractEntity enemy, Vector3 enemyPos){ if(this.isAlive() && enemy.isAlive()){ this.lookAt (enemyPos); if (timeForNextAction<=0){ if (animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", false); if (animator.GetBool("walk_enabled")) animator.SetBool ("walk_enabled", false); if (!animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", true); PNJAudio.PlayOgreHit(); enemy.onAttackReceived (DMG); timeForNextAction = timecost_perAction; } }else if (animator.GetBool("attack_enabled")){ animator.SetBool("attack_enabled",false); } }