Restore the stable legacy Unity project
This commit is contained in:
parent
56a156ee87
commit
7006a6b0dd
2070 changed files with 180490 additions and 169303 deletions
|
|
@ -1,29 +1,44 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
/* 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 static CultMath.math;
|
||||
using cfloat3 = CultMath.float3;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using float3 = Unity.Mathematics.float3;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class TurretControllerData : BehaviorData
|
||||
{
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new TurretController(this, item);
|
||||
}
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new TurretController(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class TurretController : Behavior, IInitializableBehavior
|
||||
{
|
||||
private TurretControllerData _data;
|
||||
private List<Weapon> _weapons = new List<Weapon>();
|
||||
private float _shotSpeed;
|
||||
private bool _predictShots;
|
||||
|
||||
public int WeaponCount => _weapons.Count;
|
||||
public float ShotSpeed => _shotSpeed;
|
||||
public bool PredictShots => _predictShots;
|
||||
|
||||
public TurretController(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
public TurretController(TurretControllerData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public TurretController(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
public TurretController(TurretControllerData data, ConsumableItemEffect item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
|
@ -31,7 +46,7 @@ public class TurretController : Behavior, IInitializableBehavior
|
|||
foreach (var weapon in Entity.GetBehaviors<Weapon>())
|
||||
{
|
||||
_weapons.Add(weapon);
|
||||
var vel = weapon.EvaluateVelocity();
|
||||
var vel = weapon.Evaluate(weapon.WeaponData.Velocity);
|
||||
if (vel > .1f)
|
||||
{
|
||||
_predictShots = true;
|
||||
|
|
@ -44,30 +59,29 @@ public class TurretController : Behavior, IInitializableBehavior
|
|||
{
|
||||
if (Entity.Target.Value != null)
|
||||
{
|
||||
var entityPosition = Entity.CultPosition;
|
||||
var targetPosition = Entity.Target.Value.CultPosition;
|
||||
var diff = targetPosition - entityPosition;
|
||||
var diff = Entity.Target.Value.Position - Entity.Position;
|
||||
if (_predictShots)
|
||||
{
|
||||
var targetHull = Entity.ItemManager.GetRuntimeItem(Entity.Target.Value.Hull);
|
||||
var targetVelocity = new cfloat3(Entity.Target.Value.CultVelocity.x, 0, Entity.Target.Value.CultVelocity.y);
|
||||
var targetHullData = Entity.ItemManager.GetData(Entity.Target.Value.Hull) as HullData;
|
||||
var targetVelocity = float3(Entity.Target.Value.Velocity.x, 0, Entity.Target.Value.Velocity.y);
|
||||
var predictedPosition = AetheriaMath.FirstOrderIntercept(
|
||||
entityPosition, cfloat3.zero, _shotSpeed,
|
||||
targetPosition, targetVelocity
|
||||
Entity.Position, float3.zero, _shotSpeed,
|
||||
Entity.Target.Value.Position, targetVelocity
|
||||
);
|
||||
predictedPosition.y = Entity.Zone.GetHeight(predictedPosition.xz) + (float)(targetHull?.HullGridOffset ?? 0);
|
||||
Entity.CultLookDirection = normalize(predictedPosition - entityPosition);
|
||||
predictedPosition.y = Entity.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
|
||||
Entity.LookDirection = normalize(predictedPosition - Entity.Position);
|
||||
}
|
||||
else
|
||||
Entity.CultLookDirection = normalize(diff);
|
||||
Entity.LookDirection = normalize(diff);
|
||||
var dist = length(diff);
|
||||
|
||||
foreach (var x in _weapons)
|
||||
{
|
||||
var data = x.Data as WeaponData;
|
||||
var fire = dot(
|
||||
x.Direction,
|
||||
Entity.CultLookDirection) > .99f;
|
||||
if (x.EvaluateRange() > dist && fire)
|
||||
Entity.LookDirection) > .99f;
|
||||
if (x.Evaluate(data.Range) > dist && fire)
|
||||
{
|
||||
x.Activate();
|
||||
}
|
||||
|
|
@ -86,10 +100,4 @@ public class TurretController : Behavior, IInitializableBehavior
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RestoreRuntimeState(float shotSpeed, bool predictShots)
|
||||
{
|
||||
_shotSpeed = shotSpeed;
|
||||
_predictShots = predictShots;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue