enemy spawner
This commit is contained in:
@@ -11,7 +11,14 @@ namespace MegaKoop.Game.Networking
|
||||
CharacterTransform = 3,
|
||||
WeaponFire = 4,
|
||||
HealthSync = 5,
|
||||
ProjectileSpawn = 6
|
||||
ProjectileSpawn = 6,
|
||||
ProjectileImpact = 7
|
||||
}
|
||||
|
||||
public enum ProjectileImpactKind : byte
|
||||
{
|
||||
Hero = 0,
|
||||
Enemy = 1
|
||||
}
|
||||
|
||||
public readonly struct NetworkMessage
|
||||
@@ -213,4 +220,36 @@ namespace MegaKoop.Game.Networking
|
||||
return new ProjectileSpawnMessage(networkId, index, position, direction, speed, life, damage);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct ProjectileImpactMessage
|
||||
{
|
||||
public readonly ProjectileImpactKind Kind;
|
||||
public readonly Vector3 Position;
|
||||
public readonly Vector3 Normal;
|
||||
|
||||
public ProjectileImpactMessage(ProjectileImpactKind kind, Vector3 position, Vector3 normal)
|
||||
{
|
||||
Kind = kind;
|
||||
Position = position;
|
||||
Normal = normal;
|
||||
}
|
||||
|
||||
public static byte[] Serialize(ProjectileImpactMessage message)
|
||||
{
|
||||
using var writer = new NetworkWriter();
|
||||
writer.Write((byte)message.Kind);
|
||||
writer.Write(message.Position);
|
||||
writer.Write(message.Normal);
|
||||
return writer.ToArray();
|
||||
}
|
||||
|
||||
public static ProjectileImpactMessage Deserialize(byte[] buffer)
|
||||
{
|
||||
using var reader = new NetworkReader(buffer);
|
||||
ProjectileImpactKind kind = (ProjectileImpactKind)reader.ReadByte();
|
||||
Vector3 position = reader.ReadVector3();
|
||||
Vector3 normal = reader.ReadVector3();
|
||||
return new ProjectileImpactMessage(kind, position, normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,7 @@ namespace MegaKoop.Game.Networking
|
||||
|
||||
weaponController.ProjectileSpawned += OnProjectileSpawned;
|
||||
|
||||
if (!IsAuthoritative() && disableLocalFiringWhenClient)
|
||||
{
|
||||
weaponController.enabled = false;
|
||||
}
|
||||
ApplyLocalAuthoritySetting();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -62,9 +59,9 @@ namespace MegaKoop.Game.Networking
|
||||
{
|
||||
weaponController.ProjectileSpawned -= OnProjectileSpawned;
|
||||
|
||||
if (!IsAuthoritative() && disableLocalFiringWhenClient)
|
||||
if (disableLocalFiringWhenClient)
|
||||
{
|
||||
weaponController.enabled = true;
|
||||
weaponController.SetLocalAuthority(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,5 +121,16 @@ namespace MegaKoop.Game.Networking
|
||||
|
||||
weaponController.SpawnNetworkProjectile(spawnMessage.WeaponIndex, spawnMessage.Position, spawnMessage.Direction, spawnMessage.Speed, spawnMessage.Life, spawnMessage.Damage);
|
||||
}
|
||||
|
||||
private void ApplyLocalAuthoritySetting()
|
||||
{
|
||||
if (weaponController == null || !disableLocalFiringWhenClient)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool allowLocalControl = IsAuthoritative();
|
||||
weaponController.SetLocalAuthority(allowLocalControl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user