something is no yes
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using RebootKit.Engine.Extensions;
|
||||
using RebootKit.Engine.Main;
|
||||
using RebootKit.Engine.Network;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using RebootReality.jelycho.Player;
|
||||
using TriInspector;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
@@ -23,6 +25,41 @@ namespace RebootReality.jelycho.Enemies {
|
||||
}
|
||||
}
|
||||
|
||||
public enum ZombieBodyPartType {
|
||||
Body,
|
||||
Head,
|
||||
LeftArm,
|
||||
RightArm,
|
||||
LeftLeg,
|
||||
RightLeg
|
||||
}
|
||||
|
||||
// @TODO: weird naming
|
||||
[Serializable]
|
||||
public class ZombieBodyPart {
|
||||
public Transform root;
|
||||
public Transform[] wearables;
|
||||
public Collider[] colliders;
|
||||
public ParticleSystem bloodStreamParticles;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsAlive() {
|
||||
return root.gameObject.activeSelf;
|
||||
}
|
||||
|
||||
public void HideParts() {
|
||||
root.gameObject.SetActive(false);
|
||||
foreach (Transform wearable in wearables) {
|
||||
wearable.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
foreach (Collider collider in colliders) {
|
||||
collider.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DeclareBoxGroup("Body parts")]
|
||||
public class ZombieActor : Actor, IKillable {
|
||||
static readonly Logger s_Logger = new Logger(nameof(ZombieActor));
|
||||
|
||||
@@ -41,14 +78,19 @@ namespace RebootReality.jelycho.Enemies {
|
||||
|
||||
[SerializeField] NavMeshAgent m_NavAgent;
|
||||
|
||||
[SerializeField] Collider[] m_RagdollColliders;
|
||||
[SerializeField] Collider m_RootCollider;
|
||||
[SerializeField] Rigidbody[] m_RagdollRigidbodies;
|
||||
[SerializeField] Collider[] m_Hitboxes;
|
||||
|
||||
[SerializeField] float m_MaxAttackDistance = 1.0f;
|
||||
[SerializeField] float m_LoseInterestMinDistance = 10.0f;
|
||||
[SerializeField] ulong m_BaseDamage = 10;
|
||||
[SerializeField] float m_AttackDelay = 1.0f;
|
||||
|
||||
[SerializeField, Group("Body parts")] ZombieBodyPart m_Head;
|
||||
[SerializeField, Group("Body parts")] ZombieBodyPart m_LeftArm;
|
||||
[SerializeField, Group("Body parts")] ZombieBodyPart m_RightArm;
|
||||
[SerializeField, Group("Body parts")] ZombieBodyPart m_LeftLeg;
|
||||
[SerializeField, Group("Body parts")] ZombieBodyPart m_RightLeg;
|
||||
|
||||
AIState m_State = AIState.Idle;
|
||||
|
||||
@@ -144,7 +186,7 @@ namespace RebootReality.jelycho.Enemies {
|
||||
SetIdleState();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (distToPlayerSq <= m_MaxAttackDistance * m_MaxAttackDistance) {
|
||||
m_NextAttackTimer -= dt;
|
||||
if (m_NextAttackTimer <= 0.0f) {
|
||||
@@ -181,6 +223,7 @@ namespace RebootReality.jelycho.Enemies {
|
||||
void Die() {
|
||||
s_Logger.Info("Die");
|
||||
EnableRagdoll();
|
||||
m_NavAgent.enabled = false;
|
||||
|
||||
m_State = AIState.Dead;
|
||||
died.Invoke();
|
||||
@@ -235,19 +278,13 @@ namespace RebootReality.jelycho.Enemies {
|
||||
}
|
||||
|
||||
void SetRagdollLocal(bool active) {
|
||||
foreach (Collider ragdollCollider in m_RagdollColliders) {
|
||||
ragdollCollider.enabled = active;
|
||||
}
|
||||
m_RootCollider.enabled = !active;
|
||||
|
||||
foreach (Rigidbody ragdollRigidbody in m_RagdollRigidbodies) {
|
||||
ragdollRigidbody.isKinematic = !active;
|
||||
}
|
||||
|
||||
m_Animator.enabled = !active;
|
||||
|
||||
foreach (Collider hitbox in m_Hitboxes) {
|
||||
hitbox.enabled = !active;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -280,6 +317,70 @@ namespace RebootReality.jelycho.Enemies {
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: damage?
|
||||
//
|
||||
public void HitFeedback(float3 hitPosition) {
|
||||
if (RR.World.Context is WorldContext worldContext) {
|
||||
worldContext.FeedbacksManager.SpawnBloodSplash(hitPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReceiveDamage(ulong damage, ZombieBodyPartType bodyPartType) {
|
||||
if (!IsAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ZombieBodyPart bodyPart = GetBodyParty(bodyPartType);
|
||||
if (!bodyPart.IsAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bodyPart.HideParts();
|
||||
bodyPart.bloodStreamParticles.Play();
|
||||
|
||||
Die();
|
||||
}
|
||||
|
||||
public bool HasBodyPart(ZombieBodyPartType bodyPart) {
|
||||
if (Health <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bodyPart == ZombieBodyPartType.Body) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ZombieBodyPart part = GetBodyParty(bodyPart);
|
||||
if (part == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return part.IsAlive();
|
||||
}
|
||||
|
||||
ZombieBodyPart GetBodyParty(ZombieBodyPartType bodyPart) {
|
||||
return bodyPart switch {
|
||||
ZombieBodyPartType.Body => null,
|
||||
ZombieBodyPartType.Head => m_Head,
|
||||
ZombieBodyPartType.LeftArm => m_LeftArm,
|
||||
ZombieBodyPartType.RightArm => m_RightArm,
|
||||
ZombieBodyPartType.LeftLeg => m_LeftLeg,
|
||||
ZombieBodyPartType.RightLeg => m_RightLeg,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(bodyPart), bodyPart, null)
|
||||
};
|
||||
}
|
||||
|
||||
///
|
||||
/// @MARK: Utility
|
||||
///
|
||||
[Button]
|
||||
void SetupHurtboxes() {
|
||||
foreach (ZombieHurtbox hurtbox in GetComponentsInChildren<ZombieHurtbox>()) {
|
||||
hurtbox.owner = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ZombieActorEvents {
|
||||
|
||||
Reference in New Issue
Block a user