GUNS GUNS GUNS
GUESS WHAT
This commit is contained in:
parent
1e273d691e
commit
8aaccac2b5
83 changed files with 15291 additions and 1291 deletions
|
|
@ -2,11 +2,13 @@
|
|||
* 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;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[Union(0, typeof(ProjectileWeaponData)),
|
||||
Union(1, typeof(LauncherData))]
|
||||
Union(1, typeof(LauncherData)),
|
||||
Union(2, typeof(ConstantWeaponData))]
|
||||
public abstract class WeaponData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("damageType"), Key(1)]
|
||||
|
|
@ -17,10 +19,93 @@ public abstract class WeaponData : BehaviorData
|
|||
|
||||
[InspectableField, JsonProperty("range"), Key(3)]
|
||||
public PerformanceStat Range = new PerformanceStat();
|
||||
|
||||
[InspectablePrefab, JsonProperty("effect"), Key(4)]
|
||||
public string EffectPrefab;
|
||||
}
|
||||
|
||||
[InspectableField, JsonProperty("burstCount"), Key(4)]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class InstantWeaponData : WeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("burstCount"), Key(5)]
|
||||
public int BurstCount;
|
||||
|
||||
[InspectableField, JsonProperty("burstTime"), Key(5)]
|
||||
[InspectableField, JsonProperty("burstTime"), Key(6)]
|
||||
public PerformanceStat BurstTime = new PerformanceStat();
|
||||
}
|
||||
|
||||
public class InstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private InstantWeaponData _data;
|
||||
|
||||
public int _burstCount;
|
||||
public float _burstTimer;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public event Action OnFire;
|
||||
|
||||
private float _burstTime;
|
||||
|
||||
public InstantWeapon(ItemManager context, InstantWeaponData c, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
// private void Fire()
|
||||
// {
|
||||
// Hardpoint.Temperature += _projectileWeapon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
|
||||
// var inst = GameObject.Instantiate(_projectileWeapon.BulletPrefab).transform;
|
||||
// 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;
|
||||
// bullet.Lifetime = _projectileWeapon.Range.Evaluate(Hardpoint) / _projectileWeapon.Velocity.Evaluate(Hardpoint);
|
||||
// bullet.Damage = _projectileWeapon.Damage.Evaluate(Hardpoint);
|
||||
// inst.position = Hardpoint.Proxy.position;
|
||||
// inst.rotation = Hardpoint.Proxy.rotation;
|
||||
// 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());
|
||||
// Debug.Log($"Firing bullet {b}");
|
||||
// }
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
_burstTime = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity) / _burstCount;
|
||||
if (_burstTime < .01f)
|
||||
{
|
||||
for(int i=0; i<_data.BurstCount; i++)
|
||||
OnFire?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
_burstCount = _data.BurstCount;
|
||||
Fire();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Fire()
|
||||
{
|
||||
_burstCount--;
|
||||
_burstTimer = _burstTime;
|
||||
OnFire?.Invoke();
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
{
|
||||
if(_burstCount > 0)
|
||||
{
|
||||
_burstTimer -= delta;
|
||||
if(_burstTimer < 0)
|
||||
Fire();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue