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-05 07:17:24 +00:00
|
|
|
private EAiType attackerAiType;
|
2023-09-12 14:46:57 +00:00
|
|
|
private EnemyStat attackerStat;
|
2023-09-05 07:17:24 +00:00
|
|
|
private bool isInit;
|
|
|
|
private bool canAttack;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Unity built-in function
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
2023-09-05 07:17:24 +00:00
|
|
|
if (!isInit || !canAttack || isAttacked) return;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
if (other.gameObject.layer == LayerMask.NameToLayer("HitBox"))
|
|
|
|
{
|
2023-09-05 07:17:24 +00:00
|
|
|
switch (attackerAiType)
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
2023-09-05 07:17:24 +00:00
|
|
|
case EAiType.NONE:
|
|
|
|
print("attackerAiType == NONE Error");
|
2023-08-21 18:08:11 +00:00
|
|
|
break;
|
2023-09-05 07:17:24 +00:00
|
|
|
case EAiType.PLAYER:
|
|
|
|
case EAiType.PIRATE:
|
|
|
|
if (other.gameObject.CompareTag("Enemy"))
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
2023-09-05 07:17:24 +00:00
|
|
|
break;
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
2023-09-05 07:17:24 +00:00
|
|
|
return;
|
|
|
|
case EAiType.ENEMY:
|
|
|
|
if (other.gameObject.CompareTag("Pirate") || other.gameObject.CompareTag("Player"))
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
2023-09-05 07:17:24 +00:00
|
|
|
break;
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
2023-09-05 07:17:24 +00:00
|
|
|
return;
|
2023-08-21 18:08:11 +00:00
|
|
|
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
|
|
|
|
|
2023-09-05 07:17:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-08-21 18:08:11 +00:00
|
|
|
public void SetIsAttacked(bool value) => isAttacked = value;
|
2023-09-05 07:17:24 +00:00
|
|
|
public void SetAttackerAiType(EAiType value) => attackerAiType = value;
|
2023-09-12 14:46:57 +00:00
|
|
|
public void SetAttackerStat(EnemyStat value) => attackerStat = value;
|
2023-09-05 07:17:24 +00:00
|
|
|
public void SetCanAttack(bool value) => canAttack = value;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|