2020-03-22 19:05:26 +00:00
|
|
|
using MessagePack;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2020-04-09 07:48:45 +01:00
|
|
|
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2020-05-06 04:56:36 +01:00
|
|
|
public class ProjectileWeaponData : WeaponData
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-05-12 01:42:13 +01:00
|
|
|
[InspectablePrefab, JsonProperty("bullet"), Key(6)]
|
2020-03-22 19:05:26 +00:00
|
|
|
public string BulletPrefab;
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
[InspectableField, JsonProperty("spread"), Key(7)]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Spread = new PerformanceStat();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
[InspectableField, JsonProperty("bulletInherit"), Key(8)]
|
2020-03-22 19:05:26 +00:00
|
|
|
public float Inherit;
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
[InspectableField, JsonProperty("bulletVelocity"), Key(9)]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Velocity = new PerformanceStat();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-04-16 03:08:18 +01:00
|
|
|
return new ProjectileWeapon(context, this, entity, item);
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
public class ProjectileWeapon : IBehavior
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-05-11 01:17:10 +01:00
|
|
|
private ProjectileWeaponData _data;
|
|
|
|
|
private Entity Entity { get; }
|
2020-12-10 23:20:38 +00:00
|
|
|
private EquippedItem Item { get; }
|
|
|
|
|
private ItemManager Context { get; }
|
2020-05-11 01:17:10 +01:00
|
|
|
|
|
|
|
|
public BehaviorData Data => _data;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
public ProjectileWeapon(ItemManager context, ProjectileWeaponData c, Entity entity, EquippedItem item)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
|
|
|
|
Context = context;
|
2020-05-11 01:17:10 +01:00
|
|
|
_data = c;
|
2020-04-09 10:33:16 +01:00
|
|
|
Entity = entity;
|
2020-03-22 19:05:26 +00:00
|
|
|
Item = item;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
// private void Fire()
|
|
|
|
|
// {
|
2020-04-16 03:08:18 +01:00
|
|
|
// Hardpoint.Temperature += _projectileWeapon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
|
|
|
|
|
// var inst = GameObject.Instantiate(_projectileWeapon.BulletPrefab).transform;
|
2020-03-22 19:05:26 +00:00
|
|
|
// Physics.IgnoreCollision(Hardpoint.Ship.Ship.GetComponent<Collider>(), inst.GetComponent<Collider>());
|
|
|
|
|
// var bullet = inst.GetComponent<Bullet>();
|
|
|
|
|
// bullet.Target = Hardpoint.Ship.Ship.Target;
|
|
|
|
|
// bullet.Source = Hardpoint.Ship.Ship.Hitpoints;
|
2020-04-16 03:08:18 +01:00
|
|
|
// bullet.Lifetime = _projectileWeapon.Range.Evaluate(Hardpoint) / _projectileWeapon.Velocity.Evaluate(Hardpoint);
|
|
|
|
|
// bullet.Damage = _projectileWeapon.Damage.Evaluate(Hardpoint);
|
2020-03-22 19:05:26 +00:00
|
|
|
// inst.position = Hardpoint.Proxy.position;
|
|
|
|
|
// inst.rotation = Hardpoint.Proxy.rotation;
|
2020-04-16 03:08:18 +01:00
|
|
|
// inst.GetComponent<Rigidbody>().velocity = _projectileWeapon.Velocity.Evaluate(Hardpoint) * Vector3.RotateTowards(-inst.forward, Hardpoint.Ship.Ship.Direction, _projectileWeapon.Deflection * Mathf.Deg2Rad, 1);
|
|
|
|
|
// Hardpoint.Ship.Ship.AudioSource.PlayOneShot(_projectileWeapon.Sounds.RandomElement());
|
2020-03-22 19:05:26 +00:00
|
|
|
// Debug.Log($"Firing bullet {b}");
|
2020-05-12 01:42:13 +01:00
|
|
|
// }
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2020-05-11 01:17:10 +01:00
|
|
|
public bool Update(float delta)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-05-11 01:17:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|