OldBlueWater/BlueWater/Assets/02.Scripts/Weapon/CloseWeapon.cs
NTG_Lenovo 4a70315d56 Spine 런타임 에셋 추가
+ iDamageable 관통률 삭제
+ #44 스킬 시스템 구성 및 임시 스킬 FireBoom 작업
2023-11-01 16:39:12 +09:00

104 lines
3.1 KiB
C#

using System;
using UnityEngine;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
public class CloseWeapon : MonoBehaviour
{
#region Property and variable
private bool isAttacked;
private bool isOffense;
private EAiType attackerAiType;
private float atk;
private float shieldPenetrationRate;
private bool isInit;
private bool canAttack;
#endregion
#region Unity built-in function
private void OnTriggerEnter(Collider other)
{
if (!isInit || !canAttack || isAttacked) return;
if (other.gameObject.layer == LayerMask.NameToLayer("HitBox"))
{
switch (attackerAiType)
{
case EAiType.NONE:
print("attackerAiType == NONE Error");
break;
case EAiType.PLAYER:
case EAiType.PIRATE:
if (other.gameObject.CompareTag("Enemy"))
{
break;
}
return;
case EAiType.ENEMY:
if (other.gameObject.CompareTag("Pirate") || other.gameObject.CompareTag("Player"))
{
break;
}
return;
default:
throw new ArgumentOutOfRangeException();
}
var iDamageable = other.GetComponentInParent<IDamageable>();
iDamageable.TakeDamage(atk);
isAttacked = true;
}
else if (other.gameObject.layer == LayerMask.NameToLayer("Props"))
{
if (!isOffense) return;
if (other.gameObject.CompareTag("House") || other.gameObject.CompareTag("Tower"))
{
var iDamageable = other.GetComponentInParent<IDamageable>();
iDamageable.TakeDamage(atk);
isAttacked = true;
}
}
}
#endregion
#region Custom function
public void SetBoxCollider()
{
var col = GetComponent<Collider>();
if (col)
{
col.isTrigger = true;
isInit = true;
return;
}
var boxCollider = gameObject.AddComponent<BoxCollider>();
boxCollider.isTrigger = true;
isInit = true;
}
public void SetWeaponStat(float atkStat, float shieldPenetrationRateStat, bool isOffense)
{
atk = atkStat;
shieldPenetrationRate = shieldPenetrationRateStat;
this.isOffense = isOffense;
}
public void SetIsAttacked(bool value) => isAttacked = value;
public void SetAttackerAiType(EAiType value) => attackerAiType = value;
public void SetCanAttack(bool value) => canAttack = value;
#endregion
}
}