Sync daemon authority migration

This commit is contained in:
Meta Vens 2026-06-21 09:37:54 +01:00
commit 39a0dc8737
295 changed files with 25121 additions and 7360 deletions

View file

@ -1,7 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Unity.Mathematics.math;
public class ConstantLaser : MonoBehaviour
{
@ -70,34 +67,34 @@ public class ConstantLaser : MonoBehaviour
}
LineRenderer.SetPosition(0, transform.position);
bool hitFound = false;
foreach (var hit in Physics.RaycastAll(new Ray(transform.position, transform.forward), Range, 1 | (1 << 17)))
var hitFound = false;
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
ActionGameManager.Instance?.ZoneRenderer,
SourceEntity,
transform.position,
transform.forward,
Range,
0,
out var hits))
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield)
foreach (var hit in hits)
{
if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue;
if (shield.Entity != SourceEntity)
var hull = hit.Hull;
var entity = hull.Entity;
if (entity.Shield != null && entity.Shield.Item.Active.Value)
{
shield.Entity.Shield.TakeHit(DamageType, Damage);
shield.ShowHit(hit.point, sqrt(Damage));
LineRenderer.SetPosition(1, hit.point);
hitFound = true;
break;
}
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity != SourceEntity)
{
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
LineRenderer.SetPosition(1, hit.point);
hit.Shield?.ShowHit(hit.Point, Mathf.Sqrt(Damage));
LineRenderer.SetPosition(1, hit.Point);
hitFound = true;
break;
}
LineRenderer.SetPosition(1, hit.Point);
hitFound = true;
break;
}
}
if(!hitFound)
LineRenderer.SetPosition(1, transform.position + transform.forward * Range);
}

View file

@ -1,7 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Unity.Mathematics.math;
public class ConstantLightning : MonoBehaviour
{
@ -51,28 +48,34 @@ public class ConstantLightning : MonoBehaviour
}
Lightning.FixedEndpoint = false;
var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1 | (1 << 17));
foreach (var hit in hits)
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
Source?.ZoneRenderer,
Source?.Entity,
Barrel.position,
Barrel.forward,
Range,
HitRadius,
out var hits))
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage)))
foreach (var hit in hits)
{
if (shield.Entity == Source.Entity) continue;
shield.Entity.Shield.TakeHit(DamageType, Damage * Time.deltaTime);
shield.ShowHit(hit.point, sqrt(Damage));
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity == Source.Entity) continue;
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward);
}
var hull = hit.Hull;
var entity = hull.Entity;
if (entity.Shield != null && entity.Shield.Item.Active.Value)
{
hit.Shield?.ShowHit(hit.Point, Mathf.Sqrt(Damage));
}
else
{
}
Lightning.FixedEndpoint = true;
Lightning.EndPosition = hit.point;
Lightning.FixedEndpoint = true;
Lightning.EndPosition = hit.Point;
break;
break;
}
}
if(!Lightning.FixedEndpoint)
Lightning.EndPosition = Barrel.position + Barrel.forward * Range;

View file

@ -1,32 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class ConstantParticleWeapon : MonoBehaviour
{
public ParticleSystem[] Particles;
public float CastRadius = 0.25f;
public float Damage { get; set; }
public float Range { get; set; }
public DamageType DamageType { get; set; }
public EntityInstance Source { get; set; }
public EntityInstance Target { get; set; }
private bool _stopping;
private float _emission;
private List<ParticleSystem.Particle> _collisionParticles = new List<ParticleSystem.Particle>();
private HullCollider _hull;
private void Start()
{
_emission = Particles[0].emission.rateOverTime.constant;
}
private void OnEnable()
{
foreach(var p in Particles)
p.enableEmission = true;
{
var emission = p.emission;
emission.enabled = true;
}
_stopping = false;
}
@ -38,18 +32,6 @@ public class ConstantParticleWeapon : MonoBehaviour
main.simulationSpace = ParticleSystemSimulationSpace.Custom;
main.customSimulationSpace = Source.LocalSpace;
}
var trigger = Particles[0].trigger;
while(trigger.colliderCount > 0)
trigger.RemoveCollider(0);
if (Target == null) return;
foreach (var collider in Target.HullColliders)
{
_hull = collider;
trigger.AddCollider(collider.GetComponent<Collider>());
}
}
private void Update()
@ -60,27 +42,32 @@ public class ConstantParticleWeapon : MonoBehaviour
GetComponent<Prototype>().ReturnToPool();
return;
}
}
private void OnParticleTrigger()
{
if (Target == null || !_hull) return;
_collisionParticles.Clear();
Particles[0].GetTriggerParticles(ParticleSystemTriggerEventType.Enter, _collisionParticles);
if(_collisionParticles.Count > 0)
if (_stopping || Target == null || Range <= 0)
return;
if (AetheriaYmirPhysicsBridge.Instance.TryCastTargetHulls(
Target,
transform.position,
transform.forward,
Range,
CastRadius,
out var hits))
{
_hull.SendSplash(
Damage * Time.deltaTime,
DamageType,
Source.Entity,
(transform.position - Target.transform.position).normalized);
foreach (var hit in hits)
{
break;
}
}
}
public void Stop()
{
foreach(var p in Particles)
p.enableEmission = false;
{
var emission = p.emission;
emission.enabled = false;
}
_stopping = true;
}
}

View file

@ -21,6 +21,7 @@ public class ConstantParticleWeaponManager : ConstantWeaponEffectManager
t.position = barrel.position;
p.Damage = weapon.Damage;
p.DamageType = weapon.DamageType;
p.Range = weapon.Range;
_weapons.Add(item, p);
p.Initialize();
}

View file

@ -1,13 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
using Random = UnityEngine.Random;
using static Noise1D;
using float3 = Unity.Mathematics.float3;
public class GuidedProjectile : MonoBehaviour
{
@ -36,7 +31,7 @@ public class GuidedProjectile : MonoBehaviour
private Vector3 _previousTargetPosition;
public Transform Target { get; set; }
public float3 StartPosition { get; set; }
public Vector3 StartPosition { get; set; }
public float Range { get; set; }
public Vector3 Velocity { get; set; }
public float Damage { get; set; }
@ -52,9 +47,7 @@ public class GuidedProjectile : MonoBehaviour
_active = _alive = true;
_phase = Random.value * 100;
_prevDist = Single.MaxValue;
Particles.startColor = Color.white;
//var main = Particles.main;
//main.startColor = new ParticleSystem.MinMaxGradient { mode = ParticleSystemGradientMode.Color, color = Color.white };
SetParticleColor(Color.white);
Particles.Clear(true);
Particles.Play(true);
}
@ -72,18 +65,18 @@ public class GuidedProjectile : MonoBehaviour
StartCoroutine(FadeOut());
return;
}
var position = (float3) t.position;
var position = t.position;
var targetPosition = TargetPosition?.Invoke() ?? Target.position;
_targetVelocity = lerp(_targetVelocity, targetPosition - _previousTargetPosition, saturate(Time.deltaTime * 5));
_targetVelocity = Vector3.Lerp(_targetVelocity, targetPosition - _previousTargetPosition, Mathf.Clamp01(Time.deltaTime * 5));
_previousTargetPosition = targetPosition;
targetPosition = AetheriaMath.FirstOrderIntercept(position,float3.zero, TopSpeed, targetPosition, _targetVelocity);
targetPosition = AetheriaMath.FirstOrderIntercept(position, Vector3.zero, TopSpeed, targetPosition, _targetVelocity);
var diff = targetPosition - transform.position;
var targetDist = diff.magnitude;
var sourceDist = length(StartPosition.xz - position.xz);
var sourceDist = Vector2.Distance(new Vector2(StartPosition.x, StartPosition.z), new Vector2(position.x, position.z));
if (sourceDist > Range || dot(diff,Velocity) < 0)
if (sourceDist > Range || Vector3.Dot(diff, Velocity) < 0)
{
StartCoroutine(FadeOut());
if (HitEffect != null)
@ -98,8 +91,8 @@ public class GuidedProjectile : MonoBehaviour
var targetDistFlat = diff.Flatland().magnitude;
var curveLerp = 1 - targetDistFlat / (sourceDist + targetDistFlat);
var dir = diff.normalized;
var right = cross(dir, float3(0, 1, 0));
var up = cross(dir, right);
var right = Vector3.Cross(dir, Vector3.up);
var up = Vector3.Cross(dir, right);
if (Children > 0 && SplitTime < curveLerp)
{
@ -108,9 +101,9 @@ public class GuidedProjectile : MonoBehaviour
var child = ChildProjectile.Instantiate<GuidedProjectile>();
child.transform.position = t.position;
child.StartPosition = StartPosition;
var randomDirection = normalize(Random.insideUnitCircle);
var randomDirection = Random.insideUnitCircle.normalized;
var perpendicularRandom = randomDirection.x * right + randomDirection.y * up;
child.Velocity = normalize(lerp(perpendicularRandom, dir, SplitSeparationForwardness)) * length(Velocity) * SplitSeparationVelocity;
child.Velocity = Vector3.Lerp(perpendicularRandom, dir, SplitSeparationForwardness).normalized * Velocity.magnitude * SplitSeparationVelocity;
child.Range = Range;
child.Damage = Damage / Children;
child.Penetration = Penetration;
@ -135,56 +128,53 @@ public class GuidedProjectile : MonoBehaviour
}
}
var dodge = normalize(lerp(
normalize(right * noise(Time.time * Frequency + _phase) + up * noise(Time.time * Frequency + (100 + _phase))),
Vector3.up, LiftCurve.Evaluate(curveLerp)));
var dodge = Vector3.Lerp(
(right * noise(Time.time * Frequency + _phase) + up * noise(Time.time * Frequency + (100 + _phase))).normalized,
Vector3.up,
LiftCurve.Evaluate(curveLerp)).normalized;
var desired = Vector3.Slerp(dodge, dir, GuidanceCurve.Evaluate(curveLerp)).normalized * TopSpeed;
var thrustCurve = ThrustCurve.Evaluate(curveLerp);
var thrust = Thrust * thrustCurve;
var c = Color.white * thrustCurve;
c.a = 1;
Particles.startColor = c;
SetParticleColor(c);
Velocity += (desired-Velocity).normalized * (thrust * Time.deltaTime);
}
if(_alive)
{
var ray = new Ray(t.position, Velocity);
foreach (var hit in Physics.RaycastAll(ray, Velocity.magnitude * Time.deltaTime, 1 | (1 << 17)))
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
ActionGameManager.Instance?.ZoneRenderer,
SourceEntity,
t.position,
Velocity,
Velocity.magnitude * Time.deltaTime,
0,
out var hits) &&
hits.Count > 0)
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield)
var hit = hits[0];
var hull = hit.Hull;
var entity = hull.Entity;
if (entity.Shield != null && entity.Shield.Item.Active.Value)
{
if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue;
if (shield.Entity != SourceEntity)
{
shield.Entity.Shield.TakeHit(DamageType, Damage);
shield.ShowHit(hit.point, sqrt(Damage));
}
hit.Shield?.ShowHit(hit.Point, Mathf.Sqrt(Damage));
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
else
{
if (hull.Entity != SourceEntity)
{
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
transform.position = hit.point;
StartCoroutine(Kill());
}
}
else// if (hit.transform.gameObject.layer == 1)
{
StartCoroutine(Kill());
return;
}
transform.position = hit.Point;
StartCoroutine(Kill());
if (HitEffect != null)
{
var ht = HitEffect.Instantiate<Transform>();
ht.SetParent(hit.collider.transform);
ht.position = hit.point;
return;
ht.SetParent(hull.transform);
ht.position = hit.Point;
}
return;
}
t.position += Velocity * Time.deltaTime;
@ -200,15 +190,19 @@ public class GuidedProjectile : MonoBehaviour
var lerp = 1 - (Time.time - startTime) / FadeOutTime;
var c = Color.white * lerp;
c.a = 1;
Particles.startColor = c;
//var main = Particles.main;
//main.startColor = new ParticleSystem.MinMaxGradient { mode = ParticleSystemGradientMode.Color, color = Color.white * lerp };
SetParticleColor(c);
yield return null;
}
StartCoroutine(Kill());
}
private void SetParticleColor(Color color)
{
var main = Particles.main;
main.startColor = color;
}
IEnumerator Kill()
{
_active = false;
@ -223,4 +217,4 @@ public class GuidedProjectile : MonoBehaviour
OnKill?.Invoke();
GetComponent<Prototype>().ReturnToPool();
}
}
}

View file

@ -2,9 +2,8 @@
using System.Collections;
using System.Collections.Generic;
using UniRx;
using Unity.Mathematics;
using UnityEngine;
using static Unity.Mathematics.math;
using cfloat3 = CultMath.float3;
public class GuidedProjectileManager : InstantWeaponEffectManager
{
@ -64,7 +63,13 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
p.Velocity = barrel.forward * weapon.Velocity;
p.Thrust = weapon.EvaluateGuidedProjectileThrust();
p.TopSpeed = weapon.EvaluateGuidedProjectileVelocity();
p.TargetPosition = () => source.Entity.Position + length( (float3)source.LookAtPoint.position - source.Entity.Position) * source.Entity.LookDirection;
p.TargetPosition = () =>
{
var lookPosition = source.LookAtPoint.position;
var lookPoint = new cfloat3(lookPosition.x, lookPosition.y, lookPosition.z);
var lookDistance = CultMath.math.length(lookPoint - source.Entity.CultPosition);
return (Vector3)AetheriaMath.ToUnity(source.Entity.CultPosition + lookDistance * source.Entity.CultLookDirection);
};
}
}
}

View file

@ -1,7 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Unity.Mathematics.math;
public class HitscanEffect : MonoBehaviour
{
@ -27,45 +24,47 @@ public class HitscanEffect : MonoBehaviour
{
_startTime = Time.time;
var hitFound = false;
var ray = new Ray(transform.position, transform.forward);
foreach (var hit in Physics.RaycastAll(ray, Range, 1 | (1 << 17)))
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
ActionGameManager.Instance?.ZoneRenderer,
SourceEntity,
transform.position,
transform.forward,
Range,
0,
out var hits))
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield)
foreach (var hit in hits)
{
if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue;
if (shield.Entity != SourceEntity)
var hull = hit.Hull;
var entity = hull.Entity;
if (entity.Shield != null && entity.Shield.Item.Active.Value)
{
shield.Entity.Shield.TakeHit(DamageType, Damage);
shield.ShowHit(hit.point, sqrt(Damage));
hit.Shield?.ShowHit(hit.Point, Mathf.Sqrt(Damage));
hitFound = true;
}
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull)
{
if (hull.Entity != SourceEntity)
else
{
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
hitFound = true;
}
}
if (hitFound && HitEffect != null)
{
var ht = HitEffect.Instantiate<Transform>();
ht.SetParent(hit.collider.transform);
ht.position = hit.point;
if (hitFound && HitEffect != null)
{
var ht = HitEffect.Instantiate<Transform>();
ht.SetParent(hull.transform);
ht.position = hit.Point;
}
var length = (hit.Point - transform.position).magnitude;
Line.SetPosition(1, Vector3.forward * length);
var emission = LineEffect.emission;
emission.rateOverTimeMultiplier = length;
var shape = LineEffect.shape;
shape.position = Vector3.forward * (length / 2);
shape.scale = Vector3.one * (length / 2);
break;
}
var length = (hit.point - transform.position).magnitude;
Line.SetPosition(1, Vector3.forward * length);
var emission = LineEffect.emission;
emission.rateOverTimeMultiplier = length;
var shape = LineEffect.shape;
shape.position = Vector3.forward * (length / 2);
shape.scale = Vector3.one * (length / 2);
}
if(!hitFound)
{
Line.SetPosition(1, Vector3.forward * Range);

View file

@ -1,8 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Unity.Mathematics.math;
public class Laser : MonoBehaviour
{
@ -36,34 +34,34 @@ public class Laser : MonoBehaviour
}
LineRenderer.SetPosition(0, transform.position);
bool hitFound = false;
foreach (var hit in Physics.RaycastAll(new Ray(transform.position, transform.forward), Range, 1 | (1 << 17)))
var hitFound = false;
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
ActionGameManager.Instance?.ZoneRenderer,
SourceEntity,
transform.position,
transform.forward,
Range,
0,
out var hits))
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield)
foreach (var hit in hits)
{
if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue;
if (shield.Entity != SourceEntity)
var hull = hit.Hull;
var entity = hull.Entity;
if (entity.Shield != null && entity.Shield.Item.Active.Value)
{
shield.Entity.Shield.TakeHit(DamageType, Damage);
shield.ShowHit(hit.point, sqrt(Damage));
LineRenderer.SetPosition(1, hit.point);
hitFound = true;
break;
}
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity != SourceEntity)
{
hull.SendHit(Damage * (Time.deltaTime / Duration), Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
LineRenderer.SetPosition(1, hit.point);
hit.Shield?.ShowHit(hit.Point, Mathf.Sqrt(Damage));
LineRenderer.SetPosition(1, hit.Point);
hitFound = true;
break;
}
LineRenderer.SetPosition(1, hit.Point);
hitFound = true;
break;
}
}
if(!hitFound)
LineRenderer.SetPosition(1, transform.position + transform.forward * Range);

View file

@ -1,12 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
using Random = UnityEngine.Random;
using static Unity.Mathematics.math;
public class Lightning : MonoBehaviour
{
@ -32,37 +25,44 @@ public class Lightning : MonoBehaviour
_colliderHit = false;
LightningCompute.OnLeaderComplete = null;
LightningCompute.FixedEndpoint = false;
var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1 | (1 << 17));
foreach (var hit in hits)
_endpoint = Barrel.position + Barrel.forward * Range;
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
Source?.ZoneRenderer,
Source?.Entity,
Barrel.position,
Barrel.forward,
Range,
HitRadius,
out var hits))
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage)))
foreach (var hit in hits)
{
if (shield.Entity == Source.Entity) continue;
LightningCompute.OnLeaderComplete = () =>
var hull = hit.Hull;
var entity = hull.Entity;
if (entity.Shield != null && entity.Shield.Item.Active.Value)
{
shield.Entity.Shield.TakeHit(DamageType, Damage);
shield.ShowHit(hit.point, sqrt(Damage));
};
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity == Source.Entity) continue;
LightningCompute.OnLeaderComplete = () =>
hull.SendHit(Damage, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward);
}
LightningCompute.OnLeaderComplete = () =>
{
hit.Shield?.ShowHit(hit.Point, Mathf.Sqrt(Damage));
};
}
else
{
LightningCompute.OnLeaderComplete = null;
}
_colliderHit = true;
_colliderLocalPosition = hit.collider.transform.InverseTransformPoint(hit.point);
_colliderTransform = hit.collider.transform;
LightningCompute.FixedEndpoint = true;
break;
_colliderHit = true;
_colliderLocalPosition = hull.transform.InverseTransformPoint(hit.Point);
_colliderTransform = hull.transform;
LightningCompute.FixedEndpoint = true;
_endpoint = hit.Point;
break;
}
}
LightningCompute.OnPulseComplete = () =>
GetComponent<Prototype>().ReturnToPool();
LightningCompute.StartAnimation();
_endpoint = Barrel.position + Barrel.forward * Range;
}
private void Update()

View file

@ -1,8 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using UnityEngine;
using Random = UnityEngine.Random;
@ -51,8 +49,6 @@ public class Mine : MonoBehaviour
// Update is called once per frame
void Update()
{
var position = transform.position;
if (Time.time - _startTime > ActivationDelay && !_active)
{
_active = true;
@ -60,25 +56,11 @@ public class Mine : MonoBehaviour
if(_active)
{
_emission = lerp(_emission, _blastCountdown ? ArmedEmission : ActiveEmission, Time.deltaTime * 10);
_emission = Mathf.Lerp(_emission, _blastCountdown ? ArmedEmission : ActiveEmission, Time.deltaTime * 10);
_pulseLerp += Time.deltaTime / (_blastCountdown ? ArmedCycleDuration : ActiveCycleDuration);
_pulseLerp %= 1;
if(!_blastCountdown)
{
foreach (var collider in Physics.OverlapSphere(position, BlastRange, 1))
{
var hull = collider.GetComponent<HullCollider>();
if (hull)
{
_blastCountdown = true;
_blastTime = Time.time + BlastDelay;
}
}
}
if ((position - Source.transform.position).magnitude > Range ||
Time.time - _startTime > Lifetime ||
_blastCountdown && Time.time > _blastTime)
if (Time.time - _startTime > Lifetime)
{
Explode();
}
@ -89,21 +71,6 @@ public class Mine : MonoBehaviour
public void Explode()
{
var position = transform.position;
foreach (var collider in Physics.OverlapSphere(position, BlastRange, 1 | (1 << 17)))
{
var shield = collider.GetComponent<ShieldManager>();
if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
shield.Entity.Shield.TakeHit(DamageType, Damage);
shield.ShowHit(position, sqrt(Damage));
}
var hull = collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
hull.SendSplash(Damage, DamageType, Source.Entity, (collider.transform.position - position).normalized);
}
}
var ht = HitEffect.Instantiate<Transform>();
ht.position = position;
GetComponent<Prototype>().ReturnToPool();

View file

@ -1,14 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using Random = UnityEngine.Random;
public class MineManager : InstantWeaponEffectManager
{
public Prototype ProjectilePrototype;
public bool InheritVelocity;
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
{
@ -21,11 +18,9 @@ public class MineManager : InstantWeaponEffectManager
p.GridObject.Velocity = Quaternion.Euler(
Random.Range(-angle, angle),
Random.Range(-angle, angle),
Random.Range(-angle, angle)) *
Random.Range(-angle, angle)) *
barrel.forward *
weapon.Velocity;
if(InheritVelocity)
p.GridObject.Velocity += new Vector3(source.Entity.Velocity.x, 0, source.Entity.Velocity.y);
p.Damage = weapon.Damage;
p.Range = weapon.Range;
p.DamageType = weapon.DamageType;

View file

@ -1,6 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ParticleChargeEffect : WeaponChargeEffect
@ -21,7 +19,7 @@ public class ParticleChargeEffect : WeaponChargeEffect
OverchargeEffect.Clear(true);
FailureEffect.Clear(true);
ChargeEffect.Play(true);
ChargeEffect.enableEmission = true;
SetEmission(ChargeEffect, true);
_overloaded = false;
_charge = 0;
@ -30,23 +28,23 @@ public class ParticleChargeEffect : WeaponChargeEffect
public override void StopCharging()
{
if (_overloaded)
OverchargeEffect.enableEmission = false;
SetEmission(OverchargeEffect, false);
else
ChargeEffect.enableEmission = false;
SetEmission(ChargeEffect, false);
StartCoroutine(Kill());
}
public override void Charged()
{
ChargeEffect.enableEmission = false;
SetEmission(ChargeEffect, false);
OverchargeEffect.Play(true);
OverchargeEffect.enableEmission = true;
SetEmission(OverchargeEffect, true);
_overloaded = true;
}
public override void Failed()
{
OverchargeEffect.enableEmission = false;
SetEmission(OverchargeEffect, false);
FailureEffect.Play(true);
}
@ -57,11 +55,18 @@ public class ParticleChargeEffect : WeaponChargeEffect
if (!_overloaded)
{
ChargeEffect.playbackSpeed = _charge;
var main = ChargeEffect.main;
main.simulationSpeed = _charge;
}
}
IEnumerator Kill()
private static void SetEmission(ParticleSystem particleSystem, bool enabled)
{
var emission = particleSystem.emission;
emission.enabled = enabled;
}
private IEnumerator Kill()
{
while (ChargeEffect.particleCount > 0 || OverchargeEffect.particleCount > 0 || FailureEffect.particleCount > 0)
{

View file

@ -1,8 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using UnityEngine;
using Random = UnityEngine.Random;
@ -28,7 +26,9 @@ public class Projectile : MonoBehaviour
public float Spread { get; set; }
public DamageType DamageType { get; set; }
public Entity SourceEntity { get; set; }
public EntityInstance TargetInstance { get; set; }
public float Range { get; set; }
public float YmirWorldTime { get; private set; }
// Start is called before the first frame update
void Start()
@ -51,68 +51,73 @@ public class Projectile : MonoBehaviour
var t = transform;
var position = t.position;
Velocity -= Vector3.up * (Gravity * Time.deltaTime);
Velocity *= max(0, 1 - Drag * Time.deltaTime);
Velocity *= Mathf.Max(0, 1 - Drag * Time.deltaTime);
var forward = Velocity.normalized;
t.forward = forward;
var ray = new Ray(position, Velocity);
foreach (var hit in Physics.RaycastAll(ray, Velocity.magnitude * Time.deltaTime, 1 | (1 << 17)))
if (!AetheriaYmirPhysicsBridge.Instance.TryStepProjectile(this, Time.deltaTime, out var ymirStep))
{
var shield = hit.collider.GetComponent<ShieldManager>();
var hull = hit.collider.GetComponent<HullCollider>();
if (shield)
{
if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue;
if (shield.Entity != SourceEntity)
{
shield.Entity.Shield.TakeHit(DamageType, Damage*DirectHitDamageMultiplier);
shield.ShowHit(hit.point, sqrt(Damage * DirectHitDamageMultiplier));
}
}
else if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity != SourceEntity)
{
hull.SendHit(Damage*DirectHitDamageMultiplier, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, forward);
transform.position = hit.point;
StartCoroutine(Kill());
}
}
else
{
StartCoroutine(Kill());
return;
}
if (HitEffect != null)
{
var ht = HitEffect.Instantiate<Transform>();
ht.SetParent(hit.collider.transform);
ht.position = hit.point;
return;
}
Debug.LogWarning("Ymir projectile step unavailable; projectile killed instead of falling back to Unity physics.");
StartCoroutine(Kill());
return;
}
transform.position += Velocity * Time.deltaTime;
YmirWorldTime += Time.deltaTime;
Velocity = ymirStep.Velocity;
t.position = ymirStep.Position;
if (ymirStep.HasHit)
{
ApplyYmirHit(ymirStep, forward);
return;
}
var distanceTraveled = (transform.position - StartPosition).magnitude;
if(distanceTraveled > Range)
StartCoroutine(Kill());
if (AirburstRange > 1 && distanceTraveled > AirburstDistance)
{
StartCoroutine(Kill());
var ht = HitEffect.Instantiate<Transform>();
ht.position = t.position;
foreach (var collider in Physics.OverlapSphere(t.position, AirburstRange, 1))
if (HitEffect != null)
{
var hull = collider.GetComponent<HullCollider>();
if (hull)
var ht = HitEffect.Instantiate<Transform>();
ht.position = t.position;
}
if (AetheriaYmirPhysicsBridge.Instance.TryOverlapTargetHulls(TargetInstance, t.position, AirburstRange, out var hits))
{
foreach (var hit in hits)
{
hull.SendSplash(Damage, DamageType, SourceEntity, (collider.transform.position - t.position).normalized);
var direction = (hit.Hull.transform.position - t.position).normalized;
}
}
}
}
}
private void ApplyYmirHit(AetheriaYmirProjectileStep step, Vector3 forward)
{
var hull = step.Hit.Hull;
if (hull == null || hull.Entity == SourceEntity)
return;
if (hull.Entity.Shield != null &&
hull.Entity.Shield.Item.Active.Value)
{
}
else
{
}
transform.position = step.Hit.Point;
if (HitEffect != null)
{
var ht = HitEffect.Instantiate<Transform>();
ht.SetParent(hull.transform);
ht.position = step.Hit.Point;
}
StartCoroutine(Kill());
}
IEnumerator Kill()
{
_alive = false;

View file

@ -1,8 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using Random = UnityEngine.Random;
public class ProjectileManager : InstantWeaponEffectManager
@ -17,6 +15,7 @@ public class ProjectileManager : InstantWeaponEffectManager
var barrel = source.GetBarrel(hp);
var angle = weapon.Spread / 2;
p.SourceEntity = source.Entity;
p.TargetInstance = target;
p.Velocity = Quaternion.Euler(
Random.Range(-angle, angle),
Random.Range(-angle, angle),
@ -25,14 +24,16 @@ public class ProjectileManager : InstantWeaponEffectManager
weapon.Velocity;
p.StartPosition = p.transform.position = barrel.position + p.Velocity * (Random.value * Time.deltaTime);
if(InheritVelocity)
p.Velocity += new Vector3(source.Entity.Velocity.x, 0, source.Entity.Velocity.y);
p.Velocity += (Vector3)AetheriaMath.ToUnityXZ(source.Entity.CultVelocity);
p.Damage = weapon.Damage;
p.Range = weapon.Range;
p.Penetration = weapon.Penetration;
p.Spread = weapon.DamageSpread;
p.DamageType = weapon.DamageType;
p.Zone = source.Entity.Zone;
p.AirburstDistance = target != null ? length(source.Entity.Position - target.Entity.Position) : (weapon.Range * .75f);
p.AirburstDistance = target != null
? CultMath.math.length(source.Entity.CultPosition - target.Entity.CultPosition)
: (weapon.Range * .75f);
p.Trail.Clear();
}
}