Firstborn/Assets/RPG Creation Kit/Scripts/Combat System/Player/Scripts/PCFPSArms.cs
Schaken-Mods 959e80cf72 assets upload
assets upload description.
2023-03-28 12:16:30 -05:00

214 lines
8.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPGCreationKit;
namespace RPGCreationKit
{
/// <summary>
/// This class is used on the WeaponInHand of the Player to send a message to PlayerCombat when an animation event is triggered.
/// </summary>
public class PCFPSArms : MonoBehaviour
{
public Transform rHand;
public Transform lHand;
public SkinnedMeshRenderer hands;
public SkinnedMeshRenderer arms;
PlayerCombat playerCombat;
GameObject projectile;
GameObject spellProjectile;
Equipment playerEquipment;
// Use this for initialization
void Start()
{
playerCombat = PlayerCombat.instance;
playerEquipment = Equipment.PlayerEquipment;
}
public void AttackAnimationEvent()
{
playerCombat.currentWeaponOnHand.StartCasting(false, playerCombat.lastAttackIndex);
}
public void ChargedAttackAnimationEvent()
{
if (!RPGCreationKit.Player.RckPlayer.instance.isInThirdPerson && playerCombat.currentWeaponOnHand != playerCombat.defaultWeapon)
playerCombat.currentWeaponOnHand.StartCasting(true, playerCombat.lastChargedAttackIndex);
}
public void EndAttackAnimationEvent()
{
playerCombat.currentWeaponOnHand.StopCasting();
}
public void PlayAttackSound()
{
if(!RPGCreationKit.Player.RckPlayer.instance.isInThirdPerson && playerCombat.currentWeaponOnHand != playerCombat.defaultWeapon)
playerCombat.currentWeaponOnHand.PlayOneShot(playerCombat.currentWeaponOnHand.weaponItem.weaponAttacks[playerCombat.curAttackType].attackSound);
}
public void PlayChargedAttackSound()
{
if (!RPGCreationKit.Player.RckPlayer.instance.isInThirdPerson && playerCombat.currentWeaponOnHand != playerCombat.defaultWeapon)
playerCombat.currentWeaponOnHand.PlayOneShot(playerCombat.currentWeaponOnHand.weaponItem.weaponChargedAttacks[playerCombat.curChargedAttackType].attackSound);
}
public void ResetAttackStateEvent()
{
playerCombat.ResetAttackStateEvent();
playerCombat.isAttacking = false;
}
public void SetIsBlockingEvent()
{
playerCombat.isBlocking = true;
}
public void ResetIsUnbalancedEvent()
{
playerCombat.isUnbalanced = false;
}
/// <summary>
/// Called when the player sheats the sword
/// </summary>
public void OnDrawWeaponEvent()
{
if (playerEquipment == null)
playerEquipment = Equipment.PlayerEquipment;
if(playerEquipment.currentWeaponObject != null)
playerEquipment.currentWeaponObject.SetActive(true);
}
/// <summary>
/// Called when the player unsheats the sword
/// </summary>
public void OnUndrawWeaponEvent()
{
if (playerEquipment == null)
playerEquipment = Equipment.PlayerEquipment;
if (playerEquipment.currentWeaponObject != null)
playerEquipment.currentWeaponObject.SetActive(false);
}
/// <summary>
/// Called when the sword has been sheated and is ready to attack
/// </summary>
public void OnWeaponIsDrawn()
{
playerCombat.weaponDrawn = true;
}
public void FPSSpawnAmmoOnRHand()
{
projectile = Instantiate(((AmmoItem)Equipment.PlayerEquipment.itemsEquipped[(int)EquipmentSlots.Ammo].item).projectile, rHand);
projectile.SetLayer(RCKLayers.FirstPerson);
playerCombat.currentProjectile = projectile.GetComponent<Projectile>();
}
public void SetProjectileOnHolder()
{
playerCombat.currentProjectile.transform.SetParent(playerCombat.projectileHolder);
CrossbowReferences cbR = playerEquipment.currentWeaponObject.GetComponent<CrossbowReferences>();
playerCombat.currentProjectile.transform.localPosition = cbR.projectileInHolderPos;
playerCombat.currentProjectile.transform.localRotation = Quaternion.Euler(cbR.projectileInHolderRot);
}
public void FPSAmmoReady()
{
playerCombat.projectileNocked = true;
}
/// <summary>
/// With the crossbow we can jump, run and undraw even if the weapon is loaded
/// </summary>
public void FPSAmmoReadyCrossbow()
{
playerCombat.projectileNocked = true;
playerCombat.isAttacking = false;
playerCombat.canAttack = true;
}
public void PlayCastSpellSound()
{
playerCombat.spellsAudioSource.PlayOneShot(SpellsKnowledge.Player.spellInUse.sOnCast);
}
public void CastSpellInit()
{
Spell curSpell = SpellsKnowledge.Player.spellInUse;
Transform handT = (Equipment.PlayerEquipment.isUsingShield || (Equipment.PlayerEquipment.currentWeapon != null && Equipment.PlayerEquipment.currentWeapon.weaponType == WeaponType.Bow)) ? rHand : lHand;
switch (curSpell.mode)
{
case SpellModes.Projectile:
spellProjectile = Instantiate(curSpell.magicProjectile, handT);
spellProjectile.SetLayer(RCKLayers.FirstPerson, true);
playerCombat.currentSpellProjectile = spellProjectile.GetComponent<SpellProjectile>();
break;
case SpellModes.Touch:
spellProjectile = Instantiate(curSpell.magicProjectile, handT);
spellProjectile.SetLayer(RCKLayers.FirstPerson, true);
playerCombat.currentSpellProjectile = spellProjectile.GetComponent<SpellProjectile>();
playerCombat.currentSpellProjectile.Init(Entity.GetPlayerEntity(), true);
break;
case SpellModes.Self:
spellProjectile = Instantiate(curSpell.magicProjectile, handT);
spellProjectile.SetLayer(RCKLayers.FirstPerson, true);
playerCombat.currentSpellProjectile = spellProjectile.GetComponent<SpellProjectile>();
playerCombat.currentSpellProjectile.Init(Entity.GetPlayerEntity(), true);
break;
}
}
public void CastSpellAttackEvent()
{
// Instantiate/Do Stuff
Spell curSpell = SpellsKnowledge.Player.spellInUse;
Ray ray;
switch (curSpell.mode)
{
case SpellModes.Projectile:
ray = Player.RckPlayer.instance.mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
playerCombat.currentSpellProjectile.Shoot(Entity.GetPlayerEntity(), ray.direction, true);
playerCombat.currentSpellProjectile.ExecuteOnCasterEffects();
break;
case SpellModes.Touch:
ray = Player.RckPlayer.instance.mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
if(playerCombat.currentSpellProjectile != null)
{
playerCombat.currentSpellProjectile.Shoot(Entity.GetPlayerEntity(), ray.direction, true);
playerCombat.currentSpellProjectile.ExecuteOnCasterEffects();
}
break;
case SpellModes.Self:
playerCombat.currentSpellProjectile.Explode();
playerCombat.currentSpellProjectile.ExecuteOnCasterEffects();
break;
}
}
public void CastSpellEndAndDestroy()
{
}
public void CastSpellResetEvent()
{
playerCombat.ResetAttackStateEvent();
playerCombat.isAttacking = false;
playerCombat.isCastingSpell = false;
}
}
}