Murder Satellites
Created TurretController, which performs basic combat for fixed orbital installations Projectiles self-destruct at maximum range Created turret prefab Outfitted turret in game manager Entity position is now 3D Entities responsible for updating their own position and orientation Barrel positions and orientations available from entity code Inventory code will display modal dialog for invalid item moves instead of breaking Yaw articulation working (full 360 rotation still borked)
This commit is contained in:
parent
8aaccac2b5
commit
ef816cc7e0
60 changed files with 2536 additions and 244 deletions
|
|
@ -117,6 +117,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(31, typeof(CapacitorData)),
|
||||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
Union(34, typeof(TurretControllerData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
|
||||
protected Locomotion Locomotion;
|
||||
protected VelocityMatch VelocityMatch;
|
||||
protected Aim Aim;
|
||||
protected Func<float2> TargetPosition;
|
||||
protected Func<float2> TargetVelocity;
|
||||
protected bool MatchVelocity;
|
||||
|
|
@ -80,7 +79,6 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
{
|
||||
Locomotion = new Locomotion(ItemManager, Entity, _controllerData);
|
||||
VelocityMatch = new VelocityMatch(ItemManager, Entity, _controllerData);
|
||||
Aim = new Aim(ItemManager, Entity, _controllerData);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
|
@ -128,7 +126,7 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
Entity.RemoveParent();
|
||||
|
||||
var targetPosition = TargetPosition();
|
||||
var distance = length(targetPosition - Entity.Position);
|
||||
var distance = length(targetPosition - Entity.Position.xz);
|
||||
if (MatchVelocity)
|
||||
{
|
||||
var targetVelocity = TargetVelocity();
|
||||
|
|
@ -203,7 +201,7 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
|
||||
public void MoveTo(Entity entity, bool matchVelocity = true, Action onFinish = null)
|
||||
{
|
||||
TargetPosition = () => entity.Position;
|
||||
TargetPosition = () => entity.Position.xz;
|
||||
TargetVelocity = () => entity.Velocity;
|
||||
MatchVelocity = matchVelocity;
|
||||
_movementPhase = MovementPhase.Locomotion;
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public class MiningController : ControllerBase<Mining>, IBehavior, IPersistentBe
|
|||
|
||||
private void NextAsteroid()
|
||||
{
|
||||
_asteroid = Zone.NearestAsteroid(Task.Asteroids, Entity.Position);
|
||||
_asteroid = Zone.NearestAsteroid(Task.Asteroids, Entity.Position.xz);
|
||||
Entity.SetMessage("Selecting new asteroid.");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class MiningTool : IBehavior
|
|||
var asteroidTransform = Entity.Zone.GetAsteroidTransform(AsteroidBelt, Asteroid);
|
||||
if (AsteroidBelt != Guid.Empty &&
|
||||
Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) &&
|
||||
length(Entity.Position - asteroidTransform.xy) - asteroidTransform.w < Range)
|
||||
length(Entity.Position.xz - asteroidTransform.xz) - asteroidTransform.w < Range)
|
||||
{
|
||||
Entity.Zone.MineAsteroid(
|
||||
Entity,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class PatrolController : IBehavior, IInitializableBehavior
|
|||
_locomotion.Objective = Entity.Zone.GetOrbitPosition(_targetOrbit);
|
||||
_locomotion.Update(delta);
|
||||
|
||||
if(length(Entity.Position - _locomotion.Objective) < _data.TargetDistance)
|
||||
if(length(Entity.Position.xz - _locomotion.Objective) < _data.TargetDistance)
|
||||
RandomTarget();
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
{
|
||||
if(Asteroid > -1 &&
|
||||
Asteroid < beltData.Asteroids.Length &&
|
||||
length(Entity.Position - Entity.Zone.GetAsteroidTransform(ScanTarget, Asteroid).xy) < Range)
|
||||
length(Entity.Position.xz - Entity.Zone.GetAsteroidTransform(ScanTarget, Asteroid).xy) < Range)
|
||||
{
|
||||
_scanTime += delta;
|
||||
if (_scanTime > ScanDuration)
|
||||
|
|
@ -88,7 +88,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
}
|
||||
else
|
||||
{
|
||||
if(length(Entity.Position - Entity.Zone.GetOrbitPosition(planetData.Orbit)) < Range)
|
||||
if(length(Entity.Position.xz - Entity.Zone.GetOrbitPosition(planetData.Orbit)) < Range)
|
||||
{
|
||||
_scanTime += delta;
|
||||
if (_scanTime > ScanDuration)
|
||||
|
|
|
|||
|
|
@ -109,8 +109,8 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
private void NextPlanet()
|
||||
{
|
||||
var planets = Task.Planets.Select(id => Zone.Planets[id]);
|
||||
var nearestPlanet = planets.MinBy(p => lengthsq(Entity.Position - GetPosition(p)));
|
||||
_asteroid = nearestPlanet is AsteroidBeltData ? Zone.NearestAsteroid(nearestPlanet.ID, Entity.Position) : -1;
|
||||
var nearestPlanet = planets.MinBy(p => lengthsq(Entity.Position.xz - GetPosition(p)));
|
||||
_asteroid = nearestPlanet is AsteroidBeltData ? Zone.NearestAsteroid(nearestPlanet.ID, Entity.Position.xz) : -1;
|
||||
_targetPlanet = nearestPlanet.ID;
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position);
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position.xz);
|
||||
return Zone.GetAsteroidTransform(planet.ID, asteroid).xy;
|
||||
}
|
||||
return Zone.GetOrbitPosition(planet.Orbit);
|
||||
|
|
@ -128,7 +128,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position);
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position.xz);
|
||||
return Zone.GetAsteroidVelocity(planet.ID, asteroid);
|
||||
}
|
||||
return Zone.GetOrbitVelocity(planet.Orbit);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersi
|
|||
MoveTo(() =>
|
||||
{
|
||||
var orbitParent = Zone.GetOrbitPosition(Task.OrbitParent);
|
||||
var parentToUs = Entity.Position - orbitParent;
|
||||
var parentToUs = Entity.Position.xz - orbitParent;
|
||||
return orbitParent + normalize(parentToUs) * Task.OrbitDistance;
|
||||
}, () => Zone.GetOrbitVelocity(Task.OrbitParent), OnDelivery);
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersi
|
|||
|
||||
Entity.SetMessage("Target delivered. Returning Home.");
|
||||
|
||||
var orbit = Zone.CreateOrbit(Task.OrbitParent, Entity.Position);
|
||||
var orbit = Zone.CreateOrbit(Task.OrbitParent, Entity.Position.xz);
|
||||
Task.Station.OrbitData = orbit.ID;
|
||||
|
||||
FinishTask();
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ public class Trigger : IBehavior
|
|||
{
|
||||
private TriggerData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
|
|
|
|||
93
Assets/Scripts/ServerShared/Behaviors/TurretController.cs
Normal file
93
Assets/Scripts/ServerShared/Behaviors/TurretController.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class TurretControllerData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new TurretController(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class TurretController : IBehavior
|
||||
{
|
||||
private TurretControllerData _data;
|
||||
private Dictionary<Trigger, WeaponData> _triggers = new Dictionary<Trigger, WeaponData>();
|
||||
|
||||
public Entity EquippedEntity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public TurretController(ItemManager context, TurretControllerData data, Entity equippedEntity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
EquippedEntity = equippedEntity;
|
||||
Item = item;
|
||||
var weapons = equippedEntity.Equipment.Where(e => e.Behaviors.Any(b => b.Data is WeaponData));
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
CheckWeapon(item);
|
||||
}
|
||||
|
||||
equippedEntity.Equipment.ObserveAdd().Subscribe(add => CheckWeapon(add.Value));
|
||||
equippedEntity.Equipment.ObserveRemove().Subscribe(remove =>
|
||||
{
|
||||
foreach (var bg in remove.Value.BehaviorGroups)
|
||||
if (_triggers.ContainsKey(bg.Trigger))
|
||||
_triggers.Remove(bg.Trigger);
|
||||
});
|
||||
}
|
||||
|
||||
private void CheckWeapon(EquippedItem item)
|
||||
{
|
||||
foreach (var bg in item.BehaviorGroups)
|
||||
{
|
||||
if (bg.Trigger != null)
|
||||
{
|
||||
foreach (var b in bg.Behaviors)
|
||||
{
|
||||
if(b.Data is WeaponData weaponData)
|
||||
_triggers.Add(bg.Trigger, weaponData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
if (EquippedEntity.Target != null)
|
||||
{
|
||||
var diff = EquippedEntity.Target.Position - EquippedEntity.Position;
|
||||
EquippedEntity.LookDirection = normalize(diff);
|
||||
var dist = length(diff);
|
||||
|
||||
foreach (var x in _triggers)
|
||||
{
|
||||
if (Context.Evaluate(x.Value.Range, x.Key.Item.EquippableItem, EquippedEntity) > dist &&
|
||||
dot(EquippedEntity.HardpointTransforms[EquippedEntity.Hardpoints[x.Key.Item.Position.x, x.Key.Item.Position.y]].direction,
|
||||
EquippedEntity.LookDirection) > .9f)
|
||||
{
|
||||
x.Key.Pull();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EquippedEntity.Target = EquippedEntity.Zone.Entities.FirstOrDefault(e => e is Ship);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c19f106bac321f34bab3c83bf64e7e77
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue