934 lines
35 KiB
C#
934 lines
35 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using RPGCreationKit;
|
|
using UnityEngine.UI;
|
|
using RPGCreationKit.Player;
|
|
using UnityEngine.InputSystem.Interactions;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace RPGCreationKit
|
|
{
|
|
/// <summary>
|
|
/// Combat system controller for the Player
|
|
/// </summary>
|
|
public class PlayerCombat : MonoBehaviour, IMeleeAttacker
|
|
{
|
|
#region Singleton
|
|
public static PlayerCombat instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance == null)
|
|
instance = this;
|
|
else
|
|
{
|
|
Debug.LogError("Anomaly detected with the Singleton Pattern of 'PlayerCombat', are you using multple PlayerCombats?");
|
|
Destroy(this);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public bool fpsAssigned = false;
|
|
|
|
[Header("References")]
|
|
public WeaponItem defaultWeapon; // This is the weapon that will be equipped if there's none (usually it is fists)
|
|
public WeaponOnHand defaultWeaponOnHand;
|
|
|
|
public SpellsKnowledge spellKnowledge;
|
|
public SpellProjectile currentSpellProjectile;
|
|
|
|
public Transform fpsTransform;
|
|
public PCFPSArms fpsArms;
|
|
public GameObject fpsArmsObject; // This is a reference to the first person arms model
|
|
|
|
[Space(10)]
|
|
|
|
public Transform m_Camera;
|
|
public CameraAnimation cameraAnim;
|
|
public Animator fpcAnim;
|
|
public Animator tpsAnim;
|
|
private Equipment equipment;
|
|
|
|
public RuntimeAnimatorController defaultCameraAnimator;
|
|
|
|
[Space(5)]
|
|
|
|
public PCWeaponUI weaponUI;
|
|
public Image equippedSpellUI;
|
|
|
|
[Space(10)]
|
|
[Header("Status")]
|
|
public bool weaponDrawn = false;
|
|
|
|
public GameObject playerBlockingArea;
|
|
public WeaponOnHand currentWeaponOnHand;
|
|
public Projectile currentProjectile;
|
|
|
|
// Combat System
|
|
[Space(10)]
|
|
[Header("Melee Combat System")]
|
|
public AudioSource combatAudioSource;
|
|
public AudioSource spellsAudioSource;
|
|
|
|
public bool wantsToAttack;
|
|
public bool canAttack = true;
|
|
public bool isAttacking = false; // Is playing attack animation
|
|
public bool isCastingSpell = false;
|
|
|
|
public bool isBlocking = false;
|
|
public bool isUnbalanced = false;
|
|
|
|
public bool lastAttackWasCharged;
|
|
public int curAttackType = 0;
|
|
public int curChargedAttackType = 0;
|
|
[HideInInspector] public int lastAttackIndex = 0;
|
|
[HideInInspector] public int lastChargedAttackIndex = 0;
|
|
|
|
|
|
[Space(10)]
|
|
[Header("Prefabs")]
|
|
public GameObject bloodParticlePrefab;
|
|
|
|
bool inputShootArrow = false;
|
|
|
|
public void INPUT_ArrowShoot(InputAction.CallbackContext value)
|
|
{
|
|
Debug.Log("Attack"); //Schaken
|
|
if (equipment.currentWeapon != null && equipment.currentWeapon.weaponType == WeaponType.Bow)
|
|
{
|
|
if (value.interaction is HoldInteraction)
|
|
{
|
|
if (value.started)
|
|
inputShootArrow = false;
|
|
|
|
if (value.canceled)
|
|
inputShootArrow = true;
|
|
}
|
|
else
|
|
inputShootArrow = true;
|
|
}
|
|
}
|
|
|
|
public bool blockInput;
|
|
public void INPUT_Block(InputAction.CallbackContext value)
|
|
{
|
|
if (value.interaction is HoldInteraction)
|
|
{
|
|
if (value.started)
|
|
blockInput = true;
|
|
|
|
if (value.canceled)
|
|
blockInput = false;
|
|
}
|
|
else
|
|
blockInput = false;
|
|
}
|
|
|
|
public void INPUT_CastSpell(InputAction.CallbackContext value)
|
|
{
|
|
AttackCastSpell();
|
|
}
|
|
|
|
public void INPUT_PutWeaponAway(InputAction.CallbackContext value)
|
|
{
|
|
PutWeaponAway();
|
|
}
|
|
|
|
public void INPUT_Attack(InputAction.CallbackContext value)
|
|
{
|
|
if (value.performed)
|
|
{
|
|
if (value.interaction is HoldInteraction)
|
|
AttackHold();
|
|
else
|
|
AttackTap();
|
|
}
|
|
}
|
|
|
|
// Use this for initialization
|
|
void Start()
|
|
{
|
|
equipment = Equipment.PlayerEquipment;
|
|
spellKnowledge = SpellsKnowledge.Player;
|
|
|
|
SetWeaponUI();
|
|
}
|
|
|
|
public void AttackTap()
|
|
{
|
|
if (equipment.currentWeapon != null && fpcAnim != null)
|
|
{
|
|
if (!isAttacking && canAttack && RckPlayer.instance.charController.isGrounded &&
|
|
!RckPlayer.instance.isInteracting && !RckPlayer.instance.isInConversation &&
|
|
!QuestManagerUI.instance.isUIopened && !InventoryUI.instance.isOpen && !isUnbalanced && !RckPlayer.instance.isLooting &&
|
|
!BookReaderManager.instance.backgroundUI.activeInHierarchy && !RckPlayer.instance.isInCutsceneMode && !TutorialAlertMessage.instance.messageOpened)
|
|
{
|
|
if (!weaponDrawn) {
|
|
DrawWeapon();
|
|
}
|
|
else
|
|
{
|
|
if (equipment.currentWeapon.weaponType == WeaponType.Crossbow)
|
|
CrossbowAttack();
|
|
else if (equipment.currentWeapon.weaponType == WeaponType.Bow)
|
|
{
|
|
BowAttack();
|
|
inputShootArrow = true;
|
|
}
|
|
else
|
|
MeleeAttackEvent();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AttackCastSpell()
|
|
{
|
|
if(spellKnowledge.spellInUse != null)
|
|
{
|
|
if (!isAttacking && canAttack && RckPlayer.instance.charController.isGrounded &&
|
|
!RckPlayer.instance.isInteracting && !RckPlayer.instance.isInConversation &&
|
|
!QuestManagerUI.instance.isUIopened && !InventoryUI.instance.isOpen && !isUnbalanced && !RckPlayer.instance.isLooting &&
|
|
!BookReaderManager.instance.backgroundUI.activeInHierarchy && !RckPlayer.instance.isInCutsceneMode && !TutorialAlertMessage.instance.messageOpened && fpcAnim != null)
|
|
{
|
|
// Check if the player has enough mana
|
|
if(RckPlayer.instance.playerAttributes.CurMana >= spellKnowledge.spellInUse.manaCost)
|
|
AttackCastSpellEvent();
|
|
else
|
|
AlertMessage.instance.InitAlertMessage("You don't have enough mana.", 2f, false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AlertMessage.instance.InitAlertMessage("You don't have any spells equipped.", 2f, false);
|
|
}
|
|
}
|
|
|
|
public void AttackHold()
|
|
{
|
|
if (equipment.currentWeapon != null && fpcAnim != null)
|
|
if (!isAttacking && canAttack && RckPlayer.instance.charController.isGrounded &&
|
|
!RckPlayer.instance.isInteracting && !RckPlayer.instance.isInConversation &&
|
|
!QuestManagerUI.instance.isUIopened && !InventoryUI.instance.isOpen && !isUnbalanced && !RckPlayer.instance.isLooting &&
|
|
!BookReaderManager.instance.backgroundUI.activeInHierarchy && !RckPlayer.instance.isInCutsceneMode)
|
|
{
|
|
if (!weaponDrawn)
|
|
DrawWeapon();
|
|
else
|
|
{
|
|
if (equipment.currentWeapon.weaponType == WeaponType.Crossbow)
|
|
CrossbowAttack();
|
|
else if (equipment.currentWeapon.weaponType == WeaponType.Bow)
|
|
BowAttack();
|
|
else
|
|
MeleeChargedAttack();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PutWeaponAway()
|
|
{
|
|
if (equipment.currentWeapon != null && fpcAnim != null)
|
|
if (weaponDrawn && canAttack && RckPlayer.instance.charController.isGrounded &&
|
|
!RckPlayer.instance.isInteracting && !RckPlayer.instance.isInConversation &&
|
|
!QuestManagerUI.instance.isUIopened && !InventoryUI.instance.isOpen && !isUnbalanced && !RckPlayer.instance.isLooting &&
|
|
!BookReaderManager.instance.backgroundUI.activeInHierarchy)
|
|
UndrawWeapon();
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
// Check for attack
|
|
if (equipment.currentWeapon != null && fpcAnim != null)
|
|
{
|
|
if (equipment.currentWeapon.weaponType == WeaponType.Bow)
|
|
BowAttackCheck();
|
|
|
|
if(equipment.currentWeapon.weaponType != WeaponType.Crossbow)
|
|
BlockCheck();
|
|
|
|
if (!RckPlayer.instance.isInCutsceneMode)
|
|
{
|
|
fpcAnim.SetBool("isMoving", RckPlayer.instance.m_isMoving);
|
|
fpcAnim.SetBool("isSprinting", RckPlayer.instance.isRunning);
|
|
}
|
|
else
|
|
{
|
|
fpcAnim.SetBool("isMoving", false);
|
|
fpcAnim.SetBool("isSprinting", false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnEquipmentChanges()
|
|
{
|
|
// If there is a weapon equipped
|
|
if (equipment.itemsEquipped[(int)EquipmentSlots.RHand] != null && equipment.itemsEquipped[(int)EquipmentSlots.RHand].item != null)
|
|
{
|
|
// Destroy previous weapon equipped if there was a swap
|
|
if (equipment.currentWeapon != null)
|
|
{
|
|
Destroy(equipment.currentWeaponObject);
|
|
equipment.currentWeapon = null;
|
|
}
|
|
|
|
// Instantiate Weapon on hand, assign references
|
|
equipment.currentWeapon = (WeaponItem)equipment.itemsEquipped[(int)EquipmentSlots.RHand].item;
|
|
if (equipment.currentWeapon.weaponType == WeaponType.Bow || equipment.currentWeapon.weaponType == WeaponType.Crossbow)
|
|
{
|
|
equipment.currentWeaponObject = Instantiate(equipment.currentWeapon.WeaponOnHand, fpsArms.lHand);
|
|
// Bow make use of weaponAnimator, set it
|
|
equipment.currentWeaponAnimator = equipment.currentWeaponObject.GetComponent<Animator>();
|
|
}
|
|
else
|
|
equipment.currentWeaponObject = Instantiate(equipment.currentWeapon.WeaponOnHand, fpsArms.rHand);
|
|
|
|
currentWeaponOnHand = equipment.currentWeaponObject.GetComponent<WeaponOnHand>();
|
|
|
|
equipment.currentWeaponObject.SetLayer(RCKLayers.FirstPerson, true);
|
|
defaultWeaponOnHand.gameObject.SetActive(false);
|
|
|
|
equipment.currentWeaponObject.SetActive(false);
|
|
|
|
fpcAnim.GetComponent<Animator>().runtimeAnimatorController = equipment.currentWeapon.fpsAnimatorController;
|
|
fpcAnim.Rebind();
|
|
|
|
curAttackType = 0;
|
|
curChargedAttackType = 0;
|
|
|
|
//cameraAnim.m_Animator.runtimeAnimatorController = equipment.currentWeapon.CameraAnimator;
|
|
|
|
isAttacking = false;
|
|
isBlocking = false;
|
|
isUnbalanced = false;
|
|
canAttack = true;
|
|
|
|
|
|
if (weaponDrawn)
|
|
{
|
|
weaponDrawn = false;
|
|
ThirdPersonPlayer.instance.UpdateAnimator();
|
|
DrawWeapon();
|
|
}
|
|
|
|
}
|
|
else if (equipment.currentWeapon == null)
|
|
{
|
|
// Unequip = destroy previous equipped weapon
|
|
Destroy(equipment.currentWeaponObject);
|
|
equipment.currentWeapon = null;
|
|
|
|
cameraAnim.m_Animator.runtimeAnimatorController = defaultCameraAnimator;
|
|
|
|
isAttacking = false;
|
|
isBlocking = false;
|
|
isUnbalanced = false;
|
|
|
|
equipment.currentWeapon = defaultWeapon;
|
|
|
|
equipment.currentWeaponObject = null;
|
|
currentWeaponOnHand = defaultWeaponOnHand;
|
|
defaultWeaponOnHand.gameObject.SetActive(true);
|
|
|
|
ThirdPersonPlayer.instance.currentWeaponOnHand = ThirdPersonPlayer.instance.defaultWeaponOnHand;
|
|
|
|
fpcAnim.GetComponent<Animator>().runtimeAnimatorController = equipment.currentWeapon.fpsAnimatorController;
|
|
fpcAnim = fpsArmsObject.GetComponent<Animator>();
|
|
|
|
if (weaponDrawn)
|
|
{
|
|
weaponDrawn = false;
|
|
DrawWeapon();
|
|
}
|
|
|
|
canAttack = true;
|
|
}
|
|
|
|
if (!projectileHolder && equipment.currentWeapon != null && equipment.currentWeapon.weaponType == WeaponType.Crossbow)
|
|
projectileHolder = equipment.currentWeaponObject.GetComponent<CrossbowReferences>().projectileHolder;
|
|
|
|
Equipment.PlayerEquipment.OnEquipmentChanges();
|
|
SetWeaponUI();
|
|
|
|
}
|
|
|
|
public void SetWeaponUI()
|
|
{
|
|
if (equipment.currentWeapon != null)
|
|
{
|
|
weaponUI.weaponIcon.sprite = equipment.currentWeapon.ItemIcon;
|
|
if (equipment.currentWeapon.weaponType == WeaponType.Bow || equipment.currentWeapon.weaponType == WeaponType.Crossbow)
|
|
{
|
|
if (equipment.itemsEquipped[(int)EquipmentSlots.Ammo] != null && equipment.itemsEquipped[(int)EquipmentSlots.Ammo].item != null)
|
|
{
|
|
weaponUI.SetAmmoAmount(true, equipment.itemsEquipped[(int)EquipmentSlots.Ammo].Amount.ToString());
|
|
}
|
|
else
|
|
weaponUI.SetAmmoAmount(false);
|
|
}
|
|
else
|
|
weaponUI.SetAmmoAmount(false);
|
|
}
|
|
|
|
if(spellKnowledge.spellInUse != null)
|
|
{
|
|
equippedSpellUI.sprite = spellKnowledge.spellInUse.spellIcon;
|
|
}
|
|
else
|
|
{
|
|
equippedSpellUI.sprite = equippedSpellUI.transform.parent.GetComponent<Image>().sprite;
|
|
}
|
|
}
|
|
|
|
public void RemoveCurrentWeapon()
|
|
{
|
|
if (equipment.currentWeaponObject != null)
|
|
{
|
|
Debug.Log("5k");
|
|
Destroy(equipment.currentWeaponObject);
|
|
equipment.currentWeapon = defaultWeapon;
|
|
cameraAnim.m_Animator.runtimeAnimatorController = defaultCameraAnimator;
|
|
isAttacking = false;
|
|
isBlocking = false;
|
|
isUnbalanced = false;
|
|
canAttack = false;
|
|
|
|
FullComboChainReset();
|
|
|
|
OnEquipmentChanges();
|
|
fpcAnim.SetTrigger("ImmediateReturnToEmpty");
|
|
ThirdPersonPlayer.instance.m_Animator.SetTrigger("ReturnToDefault");
|
|
ThirdPersonPlayer.instance.m_Animator.SetBool("InCombat", false);
|
|
|
|
// If weapon was draw, draw the default as well
|
|
if (weaponDrawn)
|
|
{
|
|
weaponDrawn = false;
|
|
DrawWeapon();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public void BowAttack()
|
|
{
|
|
// Check if there is ammo (and if it's of correct type
|
|
if (equipment.itemsEquipped[(int)EquipmentSlots.Ammo] != null && equipment.itemsEquipped[(int)EquipmentSlots.Ammo].item != null && equipment.itemsEquipped[(int)EquipmentSlots.Ammo].Amount >= 1)
|
|
{
|
|
// Check if the ammo is compatible with the equipped weapon
|
|
if (!((AmmoItem)equipment.itemsEquipped[(int)EquipmentSlots.Ammo].item).type.HasFlag(AmmoItem.AmmoType.Arrow))
|
|
{
|
|
AlertMessage.instance.InitAlertMessage("The equipped ammo cannot be used with the current weapon.", AlertMessage.DEFAULT_MESSAGE_DURATION_SHORT);
|
|
return;
|
|
}
|
|
|
|
// Player wants to nock an arrow
|
|
wantsToAttack = true;
|
|
|
|
isAttacking = true;
|
|
|
|
curAttackType = 0; // you may choose different shot types (ex. for the crouch)
|
|
|
|
fpcAnim.ResetTrigger("Attack");
|
|
equipment.currentWeaponAnimator.ResetTrigger("Load");
|
|
fpcAnim.Play("Load");
|
|
equipment.currentWeaponAnimator.Play("Load");
|
|
|
|
ThirdPersonPlayer.instance.m_Animator.ResetTrigger("Attack");
|
|
ThirdPersonPlayer.instance.currentWeaponAnimator.ResetTrigger("Load");
|
|
ThirdPersonPlayer.instance.currentWeaponAnimator.Play("Load");
|
|
ThirdPersonPlayer.instance.m_Animator.Play("Load (Bow)");
|
|
|
|
fpcAnim.Update(0);
|
|
ThirdPersonPlayer.instance.m_Animator.Update(0);
|
|
|
|
lastAttackIndex = curAttackType;
|
|
RckPlayer.instance.playerAttributes.DamageStamina(equipment.currentWeapon.weaponAttacks[lastAttackIndex].StaminaAmount, true, RCKSettings.DRAIN_STAMINA_ON_ATTACK_SPEEDAMOUNT);
|
|
RckPlayer.instance.StopRecoveringStamina();
|
|
|
|
// audio
|
|
if (equipment.currentWeapon.weaponAttacks[curAttackType].attackSound != null)
|
|
{
|
|
combatAudioSource.clip = equipment.currentWeapon.weaponAttacks[curAttackType].attackSound;
|
|
combatAudioSource.Play();
|
|
}
|
|
|
|
canAttack = false;
|
|
lastAttackWasCharged = false;
|
|
}
|
|
}
|
|
|
|
public void ShootArrow()
|
|
{
|
|
// Set the animation from the AnimatorController
|
|
fpcAnim.SetTrigger("Attack");
|
|
fpcAnim.SetInteger("AttackType", curAttackType + 1);
|
|
|
|
equipment.currentWeaponAnimator.ResetTrigger("Shoot");
|
|
equipment.currentWeaponAnimator.SetTrigger("Shoot");
|
|
|
|
// Set the animation from the AnimatorController
|
|
ThirdPersonPlayer.instance.m_Animator.SetTrigger("Attack");
|
|
ThirdPersonPlayer.instance.m_Animator.SetInteger("AttackType", curAttackType + 1);
|
|
|
|
ThirdPersonPlayer.instance.currentWeaponAnimator.ResetTrigger("Shoot");
|
|
ThirdPersonPlayer.instance.currentWeaponAnimator.SetTrigger("Shoot");
|
|
|
|
projectileNocked = false;
|
|
wantsToAttack = false;
|
|
isAttacking = false;
|
|
|
|
ThirdPersonPlayer.instance.DestroyAmmoProjectile();
|
|
|
|
// Shoot the arrow
|
|
var ray = RckPlayer.instance.mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
|
|
currentProjectile.Shoot(equipment.currentWeapon, (AmmoItem)equipment.itemsEquipped[(int)EquipmentSlots.Ammo].item, Entity.GetPlayerEntity(), ray.direction, true);
|
|
|
|
Inventory.PlayerInventory.RemoveItem(equipment.itemsEquipped[(int)EquipmentSlots.Ammo], 1);
|
|
SetWeaponUI();
|
|
RckPlayer.instance.InvokeResetRecover();
|
|
}
|
|
|
|
public bool projectileNocked = false;
|
|
public void BowAttackCheck()
|
|
{
|
|
if(equipment.currentWeapon != null)
|
|
// Release bow
|
|
if (equipment.currentWeapon.weaponType == WeaponType.Bow &&
|
|
projectileNocked && currentProjectile != null && (RckPlayer.instance.input.currentActionMap.FindAction("Attack").triggered || inputShootArrow))
|
|
{
|
|
ShootArrow();
|
|
inputShootArrow = false;
|
|
}
|
|
}
|
|
|
|
public Transform projectileHolder;
|
|
|
|
public void CrossbowAttack()
|
|
{
|
|
// Check if there is ammo (and if it's of correct type
|
|
if (equipment.itemsEquipped[(int)EquipmentSlots.Ammo] != null && equipment.itemsEquipped[(int)EquipmentSlots.Ammo].item != null && equipment.itemsEquipped[(int)EquipmentSlots.Ammo].Amount >= 1)
|
|
{
|
|
// Check if the ammo is compatible with the equipped weapon
|
|
if (!((AmmoItem)equipment.itemsEquipped[(int)EquipmentSlots.Ammo].item).type.HasFlag(AmmoItem.AmmoType.Dart))
|
|
{
|
|
AlertMessage.instance.InitAlertMessage("The equipped ammo cannot be used with the current weapon.", AlertMessage.DEFAULT_MESSAGE_DURATION_SHORT);
|
|
return;
|
|
}
|
|
|
|
// Player wants to nock an arrow
|
|
wantsToAttack = true;
|
|
|
|
isAttacking = true;
|
|
|
|
curAttackType = 0; // you may choose different shot types (ex. for the crouch)
|
|
|
|
// Check if the fatigue is enough for the current attack
|
|
//if (playerVitals.playerAttributes.CurStamina < equipment.currentWeapon.weaponAttacks[curAttackType].StaminaAmount)
|
|
// curAttackType = 0;
|
|
|
|
fpcAnim.ResetTrigger("Attack");
|
|
equipment.currentWeaponAnimator.ResetTrigger("Load");
|
|
|
|
// Set the animation from the AnimatorController
|
|
//fpcAnim.SetTrigger("Attack");
|
|
//fpcAnim.SetInteger("AttackType", 0);
|
|
|
|
fpcAnim.Play("Reload");
|
|
equipment.currentWeaponAnimator.Play("Reload");
|
|
|
|
//equipment.currentWeaponAnimator.SetTrigger("Load");
|
|
|
|
//cameraAnim.AttackAnimation(equipment.currentWeapon.weaponAttacks[curAttackType].cameraAnim);
|
|
|
|
lastAttackIndex = curAttackType;
|
|
//playerVitals.AttackFatigue(equipment.currentWeapon.weaponAttacks[curAttackType].StaminaAmount);
|
|
|
|
// To reset the combo if the attack is not done fast
|
|
//if (curAttackType + 1 < equipment.currentWeapon.AttackTypes)
|
|
// curAttackType++;
|
|
//else
|
|
// curAttackType = 0;
|
|
|
|
//CancelInvoke("ResetComboChain");
|
|
|
|
//if (curAttackType != 0)
|
|
// Invoke("ResetComboChain", equipment.currentWeapon.attackChainTime);
|
|
|
|
// audio
|
|
if (equipment.currentWeapon.weaponAttacks[curAttackType].attackSound != null)
|
|
{
|
|
combatAudioSource.clip = equipment.currentWeapon.weaponAttacks[curAttackType].attackSound;
|
|
combatAudioSource.Play();
|
|
}
|
|
|
|
canAttack = false;
|
|
lastAttackWasCharged = false;
|
|
}
|
|
|
|
if (weaponDrawn && projectileNocked && currentProjectile != null)
|
|
{
|
|
// Set the animation from the AnimatorController
|
|
fpcAnim.SetTrigger("Attack");
|
|
fpcAnim.SetInteger("AttackType", 1);
|
|
|
|
equipment.currentWeaponAnimator.ResetTrigger("Shoot");
|
|
equipment.currentWeaponAnimator.SetTrigger("Shoot");
|
|
|
|
projectileNocked = false;
|
|
wantsToAttack = false;
|
|
isAttacking = false;
|
|
|
|
// Shoot the arrow
|
|
var ray = RckPlayer.instance.mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
|
|
currentProjectile.Shoot(equipment.currentWeapon, (AmmoItem)equipment.itemsEquipped[(int)EquipmentSlots.Ammo].item, Entity.GetPlayerEntity(), ray.direction, true);
|
|
|
|
Inventory.PlayerInventory.RemoveItem(equipment.itemsEquipped[(int)EquipmentSlots.Ammo], 1);
|
|
SetWeaponUI();
|
|
}
|
|
}
|
|
|
|
public void DrawWeapon()
|
|
{
|
|
fpcAnim.SetTrigger("Draw");
|
|
fpcAnim.SetBool("isDrawn", true);
|
|
fpcAnim.ResetTrigger("Undraw");
|
|
|
|
// Third Person
|
|
ThirdPersonPlayer.instance.combatType = (int)equipment.currentWeapon.weaponType;
|
|
tpsAnim.SetInteger("CombatType", ThirdPersonPlayer.instance.combatType);
|
|
|
|
tpsAnim.SetTrigger("Draw");
|
|
tpsAnim.SetBool("isDrawn", true);
|
|
tpsAnim.ResetTrigger("Undraw");
|
|
|
|
// Force immediate update
|
|
fpcAnim.Update(0);
|
|
|
|
if(tpsAnim != null)
|
|
tpsAnim.Update(0);
|
|
|
|
FullComboChainReset();
|
|
wantsToAttack = false;
|
|
|
|
//weaponDrawn = true; // Handled by PCFPSArms via Animation Event
|
|
}
|
|
|
|
public void UndrawWeapon()
|
|
{
|
|
weaponDrawn = false;
|
|
fpcAnim.SetBool("isDrawn", false);
|
|
fpcAnim.ResetTrigger("Draw");
|
|
fpcAnim.SetTrigger("Undraw");
|
|
|
|
// Third Person
|
|
tpsAnim.SetBool("isDrawn", false);
|
|
tpsAnim.ResetTrigger("Draw");
|
|
tpsAnim.SetTrigger("Undraw");
|
|
|
|
// Force immediate update
|
|
fpcAnim.Update(0);
|
|
tpsAnim.Update(0);
|
|
|
|
FullComboChainReset();
|
|
}
|
|
|
|
public bool wasBlocking = false;
|
|
public void BlockCheck()
|
|
{
|
|
isBlocking = (blockInput && weaponDrawn && canAttack && RckPlayer.instance.charController.isGrounded &&
|
|
!RckPlayer.instance.isInteracting && !RckPlayer.instance.isInConversation &&
|
|
!QuestManagerUI.instance.isUIopened && !InventoryUI.instance.isOpen && !isUnbalanced && !RckPlayer.instance.isLooting &&
|
|
!BookReaderManager.instance.backgroundUI.activeInHierarchy && !RckPlayer.instance.isInCutsceneMode);
|
|
|
|
fpcAnim.SetBool("isBlocking", isBlocking);
|
|
tpsAnim.SetBool("isBlocking", isBlocking);
|
|
|
|
fpcAnim.Update(0);
|
|
tpsAnim.Update(0);
|
|
|
|
if (isBlocking && !wasBlocking)
|
|
{
|
|
fpcAnim.ResetTrigger("hasBlockedAttack");
|
|
fpcAnim.SetTrigger("StartBlocking");
|
|
|
|
tpsAnim.ResetTrigger("hasBlockedAttack");
|
|
tpsAnim.SetTrigger("StartBlocking");
|
|
RckPlayer.instance.StopRecoveringStamina();
|
|
}
|
|
|
|
fpcAnim.Update(0);
|
|
tpsAnim.Update(0);
|
|
|
|
if (isBlocking)
|
|
{
|
|
if (!playerBlockingArea.activeSelf)
|
|
playerBlockingArea.SetActive(true);
|
|
|
|
if (!wasBlocking)
|
|
{
|
|
//playerVitals.BlockingFatigue();
|
|
wasBlocking = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (playerBlockingArea.activeSelf)
|
|
playerBlockingArea.SetActive(false);
|
|
|
|
if (wasBlocking)
|
|
{
|
|
//playerVitals.StopBlockingFatigue();
|
|
wasBlocking = false;
|
|
isBlocking = false;
|
|
RckPlayer.instance.InvokeResetRecover(true, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ResetComboChain()
|
|
{
|
|
curAttackType = 0;
|
|
}
|
|
|
|
public void ResetComboChainCharged()
|
|
{
|
|
curChargedAttackType = 0;
|
|
}
|
|
|
|
public void FullComboChainReset()
|
|
{
|
|
ResetComboChain();
|
|
ResetComboChainCharged();
|
|
CancelInvoke("ResetComboChain");
|
|
CancelInvoke("ResetComboChainCharged");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handled by events on Animations, reset the attack
|
|
/// </summary>
|
|
public void ResetAttackStateEvent()
|
|
{
|
|
canAttack = true;
|
|
}
|
|
|
|
public void MeleeAttackEvent()
|
|
{
|
|
isAttacking = true;
|
|
|
|
// Check if the fatigue is enough for the current attack
|
|
//if (RckPlayer.instance.playerAttributes.CurStamina < equipment.currentWeapon.weaponAttacks[curAttackType].StaminaAmount)
|
|
// curAttackType = 0;
|
|
|
|
fpcAnim.ResetTrigger("Attack");
|
|
|
|
// Set the animation from the AnimatorController, the AnimationsEvents on the 'Swing' animation will do the job
|
|
fpcAnim.SetTrigger("Attack");
|
|
fpcAnim.SetInteger("AttackType", curAttackType);
|
|
|
|
cameraAnim.AttackAnimation(equipment.currentWeapon.weaponAttacks[curAttackType].cameraAnim);
|
|
|
|
// Third Person
|
|
tpsAnim.ResetTrigger("Attack");
|
|
tpsAnim.SetTrigger("Attack");
|
|
tpsAnim.SetInteger("AttackType", curAttackType);
|
|
|
|
// Force immediate update
|
|
fpcAnim.Update(0);
|
|
tpsAnim.Update(0);
|
|
|
|
lastAttackIndex = curAttackType;
|
|
RckPlayer.instance.playerAttributes.DamageStamina(equipment.currentWeapon.weaponAttacks[lastAttackIndex].StaminaAmount, true, RCKSettings.DRAIN_STAMINA_ON_ATTACK_SPEEDAMOUNT);
|
|
RckPlayer.instance.StopRecoveringStamina();
|
|
RckPlayer.instance.InvokeResetRecover();
|
|
|
|
//playerVitals.AttackFatigue(equipment.currentWeapon.weaponAttacks[curAttackType].StaminaAmount);
|
|
|
|
// To reset the combo if the attack is not done fast
|
|
if (curAttackType + 1 < equipment.currentWeapon.AttackTypes)
|
|
curAttackType++;
|
|
else
|
|
curAttackType = 0;
|
|
|
|
CancelInvoke("ResetComboChain");
|
|
|
|
if (curAttackType != 0)
|
|
Invoke("ResetComboChain", equipment.currentWeapon.attackChainTime);
|
|
|
|
canAttack = false;
|
|
wantsToAttack = false;
|
|
lastAttackWasCharged = false;
|
|
}
|
|
|
|
public void AttackCastSpellEvent()
|
|
{
|
|
isAttacking = true;
|
|
isCastingSpell = true;
|
|
|
|
// Check if the fatigue is enough for the current attack
|
|
//if (RckPlayer.instance.playerAttributes.CurStamina < equipment.currentWeapon.weaponAttacks[curAttackType].StaminaAmount)
|
|
// curAttackType = 0;
|
|
|
|
int castHand = (Equipment.PlayerEquipment.isUsingShield || (Equipment.PlayerEquipment.currentWeapon != null &&
|
|
Equipment.PlayerEquipment.currentWeapon.weaponType == WeaponType.Bow)) ? 1 : 0;
|
|
|
|
fpcAnim.ResetTrigger("Attack");
|
|
fpcAnim.ResetTrigger("CastSpell");
|
|
tpsAnim.ResetTrigger("Attack");
|
|
tpsAnim.ResetTrigger("CastSpell");
|
|
|
|
// Set the animation from the AnimatorController
|
|
fpcAnim.SetTrigger("CastSpell");
|
|
fpcAnim.SetInteger("CastType", (int)spellKnowledge.spellInUse.mode);
|
|
fpcAnim.SetInteger("CastHand", castHand);
|
|
|
|
// Third Person
|
|
tpsAnim.SetTrigger("CastSpell");
|
|
tpsAnim.SetInteger("CastType", (int)spellKnowledge.spellInUse.mode);
|
|
tpsAnim.SetInteger("CastHand", castHand);
|
|
|
|
//cameraAnim.AttackAnimation(equipment.currentWeapon.weaponAttacks[curAttackType].cameraAnim);
|
|
|
|
// Third Person
|
|
//tpsAnim.ResetTrigger("Attack");
|
|
//tpsAnim.SetTrigger("Attack");
|
|
//tpsAnim.SetInteger("AttackType", curAttackType);
|
|
|
|
// Force immediate update
|
|
fpcAnim.Update(0);
|
|
tpsAnim.Update(0);
|
|
|
|
RckPlayer.instance.playerAttributes.DamageMana(spellKnowledge.spellInUse.manaCost, true, RCKSettings.DRAIN_MANA_ON_CAST_SPEEDAMOUNT);
|
|
|
|
//playerVitals.AttackFatigue(equipment.currentWeapon.weaponAttacks[curAttackType].StaminaAmount);
|
|
|
|
canAttack = false;
|
|
wantsToAttack = false;
|
|
lastAttackWasCharged = false;
|
|
}
|
|
|
|
public void BlockEvent()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public void OnEnterCombat()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public void UseMelee()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public void OnAttackIsBlocked()
|
|
{
|
|
canAttack = false;
|
|
wantsToAttack = false;
|
|
isAttacking = true;
|
|
isBlocking = false;
|
|
FullComboChainReset();
|
|
|
|
|
|
fpcAnim.SetTrigger("hasBeenBlocked");
|
|
tpsAnim.SetTrigger("hasBeenBlocked");
|
|
|
|
// Force immediate update
|
|
fpcAnim.Update(0);
|
|
tpsAnim.Update(0);
|
|
}
|
|
|
|
public void MeleeChargedAttack()
|
|
{
|
|
// Perform a charged attack
|
|
isAttacking = true;
|
|
// Check if the fatigue is enough for the current attack
|
|
if (RckPlayer.instance.playerAttributes.CurStamina < equipment.currentWeapon.weaponChargedAttacks[curChargedAttackType].StaminaAmount)
|
|
curChargedAttackType = 0;
|
|
|
|
fpcAnim.ResetTrigger("Attack");
|
|
fpcAnim.ResetTrigger("ChargedAttack");
|
|
|
|
// Set the animation from the AnimatorController, the AnimationsEvents on the 'Swing' animation will do the job
|
|
fpcAnim.SetTrigger("ChargedAttack");
|
|
fpcAnim.SetInteger("ChargedAttackType", curChargedAttackType);
|
|
|
|
tpsAnim.ResetTrigger("Attack");
|
|
tpsAnim.ResetTrigger("ChargedAttack");
|
|
|
|
// Set the animation from the AnimatorController, the AnimationsEvents on the 'Swing' animation will do the job
|
|
tpsAnim.SetTrigger("ChargedAttack");
|
|
tpsAnim.SetInteger("ChargedAttackType", curChargedAttackType);
|
|
|
|
// Force immediate update
|
|
fpcAnim.Update(0);
|
|
tpsAnim.Update(0);
|
|
|
|
cameraAnim.AttackAnimation(equipment.currentWeapon.weaponChargedAttacks[curChargedAttackType].cameraAnim);
|
|
|
|
lastChargedAttackIndex = curChargedAttackType;
|
|
RckPlayer.instance.playerAttributes.DamageStamina(equipment.currentWeapon.weaponChargedAttacks[lastChargedAttackIndex].StaminaAmount, true, RCKSettings.DRAIN_STAMINA_ON_ATTACK_SPEEDAMOUNT);
|
|
RckPlayer.instance.StopRecoveringStamina();
|
|
RckPlayer.instance.InvokeResetRecover();
|
|
// To reset the combo if the attack is not done fast
|
|
if (curChargedAttackType + 1 < equipment.currentWeapon.chargedAttackTypes)
|
|
curChargedAttackType++;
|
|
else
|
|
curChargedAttackType = 0;
|
|
|
|
CancelInvoke("ResetComboChainCharged");
|
|
|
|
if (curChargedAttackType != 0)
|
|
Invoke("ResetComboChainCharged", equipment.currentWeapon.chargedAttackChainTime);
|
|
|
|
canAttack = false;
|
|
wantsToAttack = false;
|
|
lastAttackWasCharged = true;
|
|
}
|
|
|
|
void IMeleeAttacker.MeleeAttackCheck()
|
|
{
|
|
}
|
|
|
|
|
|
public void AssignNewFPSArms(GameObject _fpsArms)
|
|
{
|
|
GameObject arms = Instantiate(_fpsArms, fpsTransform);
|
|
|
|
fpsArms = arms.GetComponent<PCFPSArms>();
|
|
|
|
fpsArmsObject = arms;
|
|
fpcAnim = fpsArmsObject.GetComponent<Animator>();
|
|
|
|
defaultWeaponOnHand = arms.GetComponentInChildren<WeaponOnHand>();
|
|
|
|
SwayEffect swayEffect = fpsArmsObject.GetComponent<SwayEffect>();
|
|
|
|
if (swayEffect != null)
|
|
swayEffect.enabled = true;
|
|
|
|
if (!equipment.currentWeapon && defaultWeapon)
|
|
{
|
|
equipment.currentWeapon = defaultWeapon;
|
|
currentWeaponOnHand = defaultWeaponOnHand;
|
|
|
|
defaultWeaponOnHand.gameObject.SetActive(true);
|
|
equipment.currentWeaponObject = null;
|
|
fpcAnim = fpsArmsObject.GetComponent<Animator>();
|
|
fpcAnim.GetComponent<Animator>().runtimeAnimatorController = equipment.currentWeapon.fpsAnimatorController;
|
|
canAttack = true;
|
|
|
|
if (weaponDrawn)
|
|
fpcAnim.SetTrigger("Draw");
|
|
|
|
fpcAnim.SetBool("isDrawn", weaponDrawn);
|
|
}
|
|
|
|
equipment.FP_Arms = fpsArms.hands;
|
|
}
|
|
}
|
|
|
|
} |