31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using RebootKit.Engine.Simulation;
|
|
using RebootReality.jelycho.Enemies;
|
|
using RebootReality.jelycho.Player;
|
|
using UnityEngine;
|
|
|
|
namespace RebootReality.jelycho.Items {
|
|
public class ItemQuickAttackAction : IItemQuickAttackAction {
|
|
static readonly Collider[] s_CollidersBuffer = new Collider[512];
|
|
|
|
public void Attack(Actor attacker, ItemActor itemActor) {
|
|
PlayerActor playerActor = attacker as PlayerActor;
|
|
if (playerActor == null) {
|
|
return;
|
|
}
|
|
|
|
Vector3 attackPosition = playerActor.GetAttackPosition();
|
|
|
|
int count = Physics.OverlapSphereNonAlloc(attackPosition, 3.0f, s_CollidersBuffer);
|
|
for (int i = 0; i < count; ++i) {
|
|
if (s_CollidersBuffer[i].TryGetComponent(out IKillable killable)) {
|
|
Actor killableActor = killable as Actor;
|
|
if (killableActor == attacker) {
|
|
continue;
|
|
}
|
|
|
|
playerActor.DealDamage(killable);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |