2020-12-22 03:13:43 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
|
2021-01-05 02:56:17 +00:00
|
|
|
using System;
|
2021-01-25 05:53:36 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-04-09 07:48:45 +01:00
|
|
|
using MessagePack;
|
2021-02-11 03:14:20 +00:00
|
|
|
using Unity.Mathematics;
|
2021-03-05 14:31:18 +00:00
|
|
|
using static Unity.Mathematics.math;
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable,
|
2021-04-09 14:01:34 +01:00
|
|
|
Union(0, typeof(InstantWeaponData)),
|
2021-01-05 02:56:17 +00:00
|
|
|
Union(1, typeof(LauncherData)),
|
2026-06-13 04:56:50 +01:00
|
|
|
Union(2, typeof(ConstantWeaponData)),
|
|
|
|
|
Union(3, typeof(ChargedWeaponData)),
|
2021-01-31 03:52:32 +00:00
|
|
|
RuntimeInspectable]
|
2020-05-06 04:56:36 +01:00
|
|
|
public abstract class WeaponData : BehaviorData
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(1), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public DamageType DamageType;
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(2), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Damage = new PerformanceStat();
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[InspectableRangedFloat(0,1), Key(3), RuntimeInspectable]
|
2021-01-08 12:44:10 +00:00
|
|
|
public PerformanceStat Penetration = new PerformanceStat();
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[InspectableRangedFloat(0,1), Key(4)]
|
2021-01-08 12:44:10 +00:00
|
|
|
public PerformanceStat DamageSpread = new PerformanceStat();
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(5)]
|
2021-02-11 03:14:20 +00:00
|
|
|
public PerformanceStat MinRange = new PerformanceStat();
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(6)]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Range = new PerformanceStat();
|
2021-02-11 03:14:20 +00:00
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[InspectableAnimationCurve, Key(7)]
|
2021-04-07 01:27:35 +01:00
|
|
|
public BezierCurve DamageCurve;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[InspectablePrefab, Key(8)]
|
2021-01-05 02:56:17 +00:00
|
|
|
public string EffectPrefab;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[InspectablePrefab, Key(9), RuntimeInspectable]
|
2021-01-25 05:53:36 +00:00
|
|
|
public PerformanceStat Energy = new PerformanceStat();
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[InspectablePrefab, Key(10), RuntimeInspectable]
|
2021-01-25 05:53:36 +00:00
|
|
|
public PerformanceStat Heat = new PerformanceStat();
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[InspectablePrefab, Key(11), RuntimeInspectable]
|
2021-01-25 05:53:36 +00:00
|
|
|
public PerformanceStat Visibility = new PerformanceStat();
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[InspectableDatabaseLink(typeof(SimpleCommodityData)), Key(12), RuntimeInspectable]
|
2021-01-25 05:53:36 +00:00
|
|
|
public Guid AmmoType;
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[InspectablePrefab, Key(13)]
|
2021-01-25 05:53:36 +00:00
|
|
|
public int MagazineSize;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[InspectablePrefab, Key(14)]
|
2021-01-25 05:53:36 +00:00
|
|
|
public float ReloadTime = 1;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[InspectablePrefab, Key(15)]
|
2021-01-31 03:52:32 +00:00
|
|
|
public PerformanceStat Spread = new PerformanceStat();
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(16)]
|
2021-01-31 03:52:32 +00:00
|
|
|
public PerformanceStat Velocity = new PerformanceStat();
|
2021-01-05 02:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public abstract class Weapon : Behavior, IActivatedBehavior
|
2021-01-05 02:56:17 +00:00
|
|
|
{
|
2021-01-25 05:53:36 +00:00
|
|
|
private WeaponData _data;
|
|
|
|
|
|
2021-02-26 19:01:47 +00:00
|
|
|
public abstract float DamagePerSecond { get; }
|
|
|
|
|
public abstract float RangeDamagePerSecond(float range);
|
2021-01-25 05:53:36 +00:00
|
|
|
public abstract int Ammo { get; }
|
|
|
|
|
public WeaponData WeaponData => _data;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-01-31 03:52:32 +00:00
|
|
|
public float Damage { get; protected set; }
|
|
|
|
|
public float Penetration { get; protected set; }
|
|
|
|
|
public float DamageSpread { get; protected set; }
|
2021-02-11 03:14:20 +00:00
|
|
|
public float MinRange { get; protected set; }
|
2021-01-31 03:52:32 +00:00
|
|
|
public float Range { get; protected set; }
|
|
|
|
|
public float Energy { get; protected set; }
|
|
|
|
|
public float Heat { get; protected set; }
|
|
|
|
|
public float Visibility { get; protected set; }
|
|
|
|
|
public float Spread { get; protected set; }
|
|
|
|
|
public float Velocity { get; protected set; }
|
2021-01-05 02:56:17 +00:00
|
|
|
|
2021-01-25 05:53:36 +00:00
|
|
|
protected bool _firing;
|
|
|
|
|
|
|
|
|
|
public bool Firing
|
|
|
|
|
{
|
|
|
|
|
get => _firing;
|
|
|
|
|
}
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public Weapon(WeaponData data, EquippedItem item) : base(data, item)
|
|
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
}
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public Weapon(WeaponData data, ConsumableItemEffect item) : base(data, item)
|
2021-01-05 02:56:17 +00:00
|
|
|
{
|
2021-01-25 05:53:36 +00:00
|
|
|
_data = data;
|
2021-01-05 02:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-31 03:52:32 +00:00
|
|
|
protected virtual void UpdateStats()
|
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
Damage = Evaluate(_data.Damage);
|
|
|
|
|
Penetration = Evaluate(_data.Penetration);
|
|
|
|
|
DamageSpread = Evaluate(_data.DamageSpread);
|
|
|
|
|
MinRange = Evaluate(_data.MinRange);
|
|
|
|
|
Range = Evaluate(_data.Range);
|
|
|
|
|
Energy = Evaluate(_data.Energy);
|
|
|
|
|
Heat = Evaluate(_data.Heat);
|
|
|
|
|
Visibility = Evaluate(_data.Visibility);
|
|
|
|
|
Spread = Evaluate(_data.Spread);
|
|
|
|
|
Velocity = Evaluate(_data.Velocity);
|
2021-01-31 03:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override bool Execute(float dt)
|
2021-01-31 03:52:32 +00:00
|
|
|
{
|
|
|
|
|
UpdateStats();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-01-05 02:56:17 +00:00
|
|
|
|
2021-01-25 05:53:36 +00:00
|
|
|
public virtual void Activate()
|
2021-01-05 02:56:17 +00:00
|
|
|
{
|
2021-01-25 05:53:36 +00:00
|
|
|
_firing = true;
|
2021-01-05 02:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-25 05:53:36 +00:00
|
|
|
public virtual void Deactivate()
|
2021-01-05 02:56:17 +00:00
|
|
|
{
|
2021-01-25 05:53:36 +00:00
|
|
|
_firing = false;
|
2021-01-05 02:56:17 +00:00
|
|
|
}
|
2021-01-25 05:53:36 +00:00
|
|
|
}
|