2026-08-10 14:57:50 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UniRx;
|
2026-09-14 17:39:12 +02:00
|
|
|
|
using CultMath;
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
|
using CultMath.UnityBridge;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
using UnityEngine;
|
2026-09-14 17:39:12 +02:00
|
|
|
|
using static CultMath.math;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
|
|
|
|
|
|
public class GuidedProjectileManager : InstantWeaponEffectManager
|
|
|
|
|
|
{
|
|
|
|
|
|
public Prototype ProjectilePrototype;
|
|
|
|
|
|
|
|
|
|
|
|
public Subject<(Entity source, Transform target, GuidedProjectile missile)> OnFireGuided = new Subject<(Entity source, Transform target, GuidedProjectile missile)>();
|
|
|
|
|
|
|
|
|
|
|
|
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(weapon.Data is LauncherData launcher)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (target == null) return;
|
|
|
|
|
|
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
|
|
|
|
|
p.Source = source.transform;
|
|
|
|
|
|
p.SourceEntity = source.Entity;
|
|
|
|
|
|
p.Target = target.transform;
|
|
|
|
|
|
p.Frequency = launcher.DodgeFrequency;
|
|
|
|
|
|
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
|
|
|
|
|
var barrel = source.GetBarrel(hp);
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
|
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
|
2026-08-10 14:57:50 +01:00
|
|
|
|
p.Damage = weapon.Damage;
|
|
|
|
|
|
p.Range = weapon.Range;
|
|
|
|
|
|
p.Penetration = weapon.Penetration;
|
|
|
|
|
|
p.Spread = weapon.DamageSpread;
|
|
|
|
|
|
p.DamageType = weapon.WeaponData.DamageType;
|
|
|
|
|
|
p.GuidanceCurve = launcher.GuidanceCurve.ToCurve();
|
|
|
|
|
|
p.LiftCurve = launcher.LiftCurve.ToCurve();
|
|
|
|
|
|
p.ThrustCurve = launcher.ThrustCurve.ToCurve();
|
|
|
|
|
|
p.Velocity = barrel.forward * weapon.Velocity;
|
|
|
|
|
|
p.Thrust = item.Evaluate(launcher.Thrust);
|
|
|
|
|
|
p.TopSpeed = item.Evaluate(launcher.MissileVelocity);
|
|
|
|
|
|
OnFireGuided.OnNext((source.Entity, target.transform, p));
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(weapon.Data is GuidedWeaponData guidance)
|
|
|
|
|
|
{
|
|
|
|
|
|
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
|
|
|
|
|
p.Source = source.transform;
|
|
|
|
|
|
p.SourceEntity = source.Entity;
|
|
|
|
|
|
p.Frequency = guidance.DodgeFrequency;
|
|
|
|
|
|
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
|
|
|
|
|
var barrel = source.GetBarrel(hp);
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
|
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
|
2026-08-10 14:57:50 +01:00
|
|
|
|
p.Damage = weapon.Damage;
|
|
|
|
|
|
p.Range = weapon.Range;
|
|
|
|
|
|
p.Penetration = weapon.Penetration;
|
|
|
|
|
|
p.Spread = weapon.DamageSpread;
|
|
|
|
|
|
p.DamageType = weapon.WeaponData.DamageType;
|
|
|
|
|
|
p.GuidanceCurve = guidance.GuidanceCurve.ToCurve();
|
|
|
|
|
|
p.LiftCurve = guidance.LiftCurve.ToCurve();
|
|
|
|
|
|
p.ThrustCurve = guidance.ThrustCurve.ToCurve();
|
|
|
|
|
|
p.Velocity = barrel.forward * weapon.Velocity;
|
|
|
|
|
|
p.Thrust = item.Evaluate(guidance.Thrust);
|
|
|
|
|
|
p.TopSpeed = item.Evaluate(guidance.MissileVelocity);
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
|
p.TargetPosition = () => (source.Entity.Position + length(source.LookAtPoint.position.ToCultMath() - source.Entity.Position) * source.Entity.LookDirection).ToUnity();
|
2026-08-10 14:57:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
else Debug.LogError($"Weapon {item.Data.Name} linked to {name} effect, but is not a Launcher!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|