2023-08-21 18:08:11 +00:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
namespace BlueWaterProject
|
|
|
|
{
|
2023-08-28 19:52:23 +00:00
|
|
|
public class CloseWeapon : MonoBehaviour
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
|
|
|
#region Property and variable
|
|
|
|
|
|
|
|
private bool isAttacked;
|
|
|
|
|
2023-09-04 07:31:04 +00:00
|
|
|
private EAttackerType eAttackerType;
|
2023-08-21 18:08:11 +00:00
|
|
|
private AiStat attackerStat;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Unity built-in function
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
if (isAttacked) return;
|
|
|
|
|
|
|
|
if (other.gameObject.layer == LayerMask.NameToLayer("HitBox"))
|
|
|
|
{
|
2023-09-04 07:31:04 +00:00
|
|
|
switch (eAttackerType)
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
2023-09-04 07:31:04 +00:00
|
|
|
case EAttackerType.NONE:
|
2023-08-21 18:08:11 +00:00
|
|
|
break;
|
2023-09-04 07:31:04 +00:00
|
|
|
case EAttackerType.OFFENSE:
|
2023-08-21 18:08:11 +00:00
|
|
|
if (!other.gameObject.CompareTag("Enemy") && !other.gameObject.CompareTag("House"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2023-09-04 07:31:04 +00:00
|
|
|
case EAttackerType.DEFENSE:
|
2023-08-21 18:08:11 +00:00
|
|
|
if (!other.gameObject.CompareTag("Player") && !other.gameObject.CompareTag("Pirate"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
var iDamageable = other.GetComponentInParent<IDamageable>();
|
|
|
|
|
2023-08-31 07:38:08 +00:00
|
|
|
iDamageable.TakeDamage(attackerStat.Atk, attackerStat.ShieldPenetrationRate);
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
isAttacked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Custom function
|
|
|
|
|
|
|
|
public void SetIsAttacked(bool value) => isAttacked = value;
|
2023-09-04 07:31:04 +00:00
|
|
|
public void SetAttackerType(EAttackerType value) => eAttackerType = value;
|
2023-08-21 18:08:11 +00:00
|
|
|
public void SetAttackerStat(AiStat value) => attackerStat = value;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|