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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user