working on enemies
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
using RebootKit.Engine.Main;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RebootKit.Engine.Main;
|
||||
using RebootKit.Engine.Network;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using RebootReality.jelycho.InfectedArea;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class BaseManagerActorData : IActorData {
|
||||
public void Serialize(NetworkBufferWriter writer) {
|
||||
}
|
||||
|
||||
public void Deserialize(NetworkBufferReader reader) {
|
||||
}
|
||||
public void Serialize(NetworkBufferWriter writer) { }
|
||||
|
||||
public void Deserialize(NetworkBufferReader reader) { }
|
||||
|
||||
public int GetMaxBytes() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum BaseManagerActorCommands : byte {
|
||||
None = 0x00,
|
||||
SpawnBeacon = 0x01,
|
||||
@@ -24,11 +27,11 @@ namespace RebootReality.jelycho.Beacons {
|
||||
|
||||
public struct SpawnBeaconCommandData : ISerializableEntity {
|
||||
public Vector3 Position;
|
||||
|
||||
|
||||
public void Serialize(NetworkBufferWriter writer) {
|
||||
writer.Write(Position);
|
||||
}
|
||||
|
||||
|
||||
public void Deserialize(NetworkBufferReader reader) {
|
||||
reader.Read(out Position);
|
||||
}
|
||||
@@ -37,8 +40,12 @@ namespace RebootReality.jelycho.Beacons {
|
||||
return sizeof(float) * 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class BaseManagerActor : Actor {
|
||||
static readonly Logger s_Logger = new Logger(nameof(BaseManagerActor));
|
||||
|
||||
[field: SerializeField] public MotherActor Mother { get; private set; }
|
||||
|
||||
[SerializeField] AssetReferenceGameObject m_BeaconPrefab;
|
||||
[SerializeField] float m_ConnectionRopeLength = 10.0f;
|
||||
[SerializeField] float m_BeaconSpawnRadius = 15.0f;
|
||||
@@ -47,21 +54,44 @@ namespace RebootReality.jelycho.Beacons {
|
||||
[SerializeField] float m_BeaconSpawnShakeRadius = 20.0f;
|
||||
[SerializeField] float m_BeaconSpawnShakeDuration = 1.0f;
|
||||
|
||||
readonly List<Beacon> m_Beacons = new List<Beacon>();
|
||||
|
||||
void Start() {
|
||||
if (RR.World.Context is WorldContext worldContext) {
|
||||
worldContext.InfectedAreaManager.Add(Mother.transform.position, m_BeaconSpawnRadius);
|
||||
}
|
||||
}
|
||||
|
||||
protected override IActorData CreateActorData() {
|
||||
return new BaseManagerActorData();
|
||||
}
|
||||
|
||||
protected override void OnActorCommandServer(ulong senderID, ActorCommand actorCommand) {
|
||||
if (actorCommand.CommandID == (byte)BaseManagerActorCommands.SpawnBeacon) {
|
||||
if (actorCommand.CommandID == (byte) BaseManagerActorCommands.SpawnBeacon) {
|
||||
SpawnBeaconCommandData commandData = new SpawnBeaconCommandData();
|
||||
DataSerializationUtils.Deserialize(actorCommand.Data, ref commandData);
|
||||
RR.SpawnActor(m_BeaconPrefab, commandData.Position, Quaternion.identity);
|
||||
|
||||
Transform closestGutConnector = FindClosestGutConnector(commandData.Position);
|
||||
if (closestGutConnector == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Actor beaconActor = RR.SpawnActor(m_BeaconPrefab, commandData.Position, Quaternion.identity);
|
||||
if (beaconActor is not Beacon beacon) {
|
||||
s_Logger.Info($"Cannot spawn beacon at position: {commandData.Position}");
|
||||
return;
|
||||
}
|
||||
|
||||
m_Beacons.Add(beacon);
|
||||
|
||||
ConnectGut(beacon.GutConnector, closestGutConnector);
|
||||
|
||||
if (RR.World.Context is WorldContext worldContext) {
|
||||
worldContext.FeedbacksManager.ShakeCamera(commandData.Position,
|
||||
m_BeaconSpawnRadius,
|
||||
m_BeaconSpawnShakeIntensity,
|
||||
m_BeaconSpawnShakeDuration);
|
||||
worldContext.InfectedAreaManager.Add(commandData.Position, m_BeaconSpawnRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +101,34 @@ namespace RebootReality.jelycho.Beacons {
|
||||
Position = position
|
||||
};
|
||||
|
||||
SendActorCommand((byte)BaseManagerActorCommands.SpawnBeacon, ref commandData);
|
||||
SendActorCommand((byte) BaseManagerActorCommands.SpawnBeacon, ref commandData);
|
||||
}
|
||||
|
||||
Transform FindClosestGutConnector(float3 position) {
|
||||
float spawnRadiusSq = m_BeaconSpawnRadius * m_BeaconSpawnRadius;
|
||||
|
||||
float closestDistanceSq = math.distancesq(position, Mother.transform.position);
|
||||
Transform connector = null;
|
||||
|
||||
if (closestDistanceSq < spawnRadiusSq) {
|
||||
connector = Mother.GutConnector;
|
||||
}
|
||||
|
||||
foreach (Beacon beacon in m_Beacons) {
|
||||
float beaconDistSq = math.distancesq(position, beacon.transform.position);
|
||||
if (beaconDistSq < closestDistanceSq) {
|
||||
closestDistanceSq = beaconDistSq;
|
||||
connector = beacon.GutConnector;
|
||||
}
|
||||
}
|
||||
|
||||
return connector;
|
||||
}
|
||||
|
||||
void ConnectGut(Transform connectorA, Transform connectorB) {
|
||||
if (RR.World.Context is WorldContext worldContext) {
|
||||
worldContext.RopesManager.SpawnRope(connectorA.position, connectorB.position, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class Beacon : Actor {
|
||||
[SerializeField] BeaconGraphics m_Graphics;
|
||||
[field: SerializeField] public Transform RopeConnectionPoint { get; private set; }
|
||||
[field: SerializeField] public Transform GutConnector { get; private set; }
|
||||
|
||||
void Start() {
|
||||
m_Graphics.Grow();
|
||||
|
||||
50
Assets/jelycho/Code/Beacons/MotherActor.cs
Normal file
50
Assets/jelycho/Code/Beacons/MotherActor.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using RebootKit.Engine.Network;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using RebootReality.jelycho.Enemies;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class MotherActorData : IActorData {
|
||||
public ulong Health;
|
||||
public float HungerLevel;
|
||||
|
||||
public int GetMaxBytes() {
|
||||
return sizeof(ulong) +
|
||||
sizeof(float);
|
||||
}
|
||||
|
||||
public void Serialize(NetworkBufferWriter writer) {
|
||||
writer.Write(Health);
|
||||
writer.Write(HungerLevel);
|
||||
}
|
||||
|
||||
public void Deserialize(NetworkBufferReader reader) {
|
||||
reader.Read(out Health);
|
||||
reader.Read(out HungerLevel);
|
||||
}
|
||||
}
|
||||
|
||||
public class MotherActor : Actor, IKillable {
|
||||
MotherActorData m_ActorData = new MotherActorData();
|
||||
|
||||
[field: SerializeField] public Transform GutConnector { get; private set; }
|
||||
|
||||
//
|
||||
// @MARK: Actor
|
||||
//
|
||||
protected override IActorData CreateActorData() {
|
||||
return m_ActorData;
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: IKillable
|
||||
//
|
||||
public bool IsAlive() {
|
||||
return m_ActorData.Health > 0;
|
||||
}
|
||||
|
||||
public ulong OnHit(Actor attacker, ulong damage) {
|
||||
return damage;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/jelycho/Code/Beacons/MotherActor.cs.meta
Normal file
3
Assets/jelycho/Code/Beacons/MotherActor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18d3888d591847098197a645fe279b2f
|
||||
timeCreated: 1754955025
|
||||
Reference in New Issue
Block a user