Mines and Flamethrowers
This commit is contained in:
parent
8d10e33db0
commit
79b0c036cb
36 changed files with 10594 additions and 18 deletions
|
|
@ -13,7 +13,7 @@ public class HullCollider : MonoBehaviour
|
|||
|
||||
public Entity Entity { get; set; }
|
||||
|
||||
public void SendHit(float damage, float penetration, float spread, DamageType damageType, Entity source, RaycastHit hit, Vector3 direction)
|
||||
public void SendHit(float damage, float penetration, float spread, DamageType damageType, Entity source, Vector2 texCoord, Vector3 direction)
|
||||
{
|
||||
Hit.OnNext(new HullHitEventArgs
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ public class HullCollider : MonoBehaviour
|
|||
Spread = spread,
|
||||
DamageType = damageType,
|
||||
Source = source,
|
||||
Hit = hit,
|
||||
TexCoord = texCoord,
|
||||
Direction = direction
|
||||
});
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ public class HullCollider : MonoBehaviour
|
|||
public float Spread;
|
||||
public DamageType DamageType;
|
||||
public Entity Source;
|
||||
public RaycastHit Hit;
|
||||
public float2 TexCoord;
|
||||
public float3 Direction;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class ConstantLaser : MonoBehaviour
|
|||
{
|
||||
if (hull.Entity != SourceEntity)
|
||||
{
|
||||
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, SourceEntity, hit, transform.forward);
|
||||
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
|
||||
}
|
||||
}
|
||||
LineRenderer.SetPosition(1, hit.point);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class ConstantLightning : MonoBehaviour
|
|||
if (hull)
|
||||
{
|
||||
if (hull.Entity == Source.Entity) continue;
|
||||
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, Source.Entity, hit, Barrel.forward);
|
||||
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward);
|
||||
}
|
||||
|
||||
Lightning.FixedEndpoint = true;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
guid: b184352ea3694b8d892f1402b8d51153
|
||||
timeCreated: 1612491884
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 54
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
|
|||
90
Assets/Scripts/Gameplay/Weapons/ConstantParticleWeapon.cs
Normal file
90
Assets/Scripts/Gameplay/Weapons/ConstantParticleWeapon.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConstantParticleWeapon : MonoBehaviour
|
||||
{
|
||||
public ParticleSystem[] Particles;
|
||||
|
||||
public float Damage { 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 Transform _simulationSpace;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_emission = Particles[0].emission.rateOverTime.constant;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
foreach(var p in Particles)
|
||||
p.enableEmission = true;
|
||||
_stopping = false;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_simulationSpace = new GameObject($"{gameObject.name} Sim Space").transform;
|
||||
foreach(var p in Particles)
|
||||
{
|
||||
var main = p.main;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.Custom;
|
||||
main.customSimulationSpace = _simulationSpace;
|
||||
}
|
||||
|
||||
var trigger = Particles[0].trigger;
|
||||
while(trigger.colliderCount > 0)
|
||||
trigger.RemoveCollider(0);
|
||||
|
||||
if (Target == null) return;
|
||||
|
||||
foreach (var collider in Target.Prefab.HullColliders)
|
||||
{
|
||||
_hull = collider;
|
||||
trigger.AddCollider(collider.GetComponent<Collider>());
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Source == null) return;
|
||||
_simulationSpace.position = Source.Prefab.transform.position;
|
||||
if (_stopping && Particles.All(p=>p.particleCount == 0))
|
||||
{
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
Destroy(_simulationSpace.gameObject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnParticleTrigger()
|
||||
{
|
||||
if (Target == null || !_hull) return;
|
||||
_collisionParticles.Clear();
|
||||
Particles[0].GetTriggerParticles(ParticleSystemTriggerEventType.Enter, _collisionParticles);
|
||||
if(_collisionParticles.Count > 0)
|
||||
{
|
||||
_hull.SendSplash(
|
||||
Damage * Time.deltaTime,
|
||||
DamageType,
|
||||
Source.Entity,
|
||||
(transform.position - Target.Prefab.transform.position).normalized);
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
foreach(var p in Particles)
|
||||
p.enableEmission = false;
|
||||
_stopping = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 200b7ae77af3480e98184bdffe2c0103
|
||||
timeCreated: 1612570252
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConstantParticleWeaponManager : ConstantWeaponEffectManager
|
||||
{
|
||||
public Prototype WeaponPrototype;
|
||||
|
||||
private Dictionary<EquippedItem, ConstantParticleWeapon> _weapons = new Dictionary<EquippedItem, ConstantParticleWeapon>();
|
||||
|
||||
public override void StartFiring(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
var p = WeaponPrototype.Instantiate<ConstantParticleWeapon>();
|
||||
p.Source = source;
|
||||
p.Target = target;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = p.transform;
|
||||
t.SetParent(barrel);
|
||||
t.forward = barrel.forward;
|
||||
t.position = barrel.position;
|
||||
p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity);
|
||||
p.DamageType = data.DamageType;
|
||||
_weapons.Add(item, p);
|
||||
p.Initialize();
|
||||
}
|
||||
|
||||
public override void StopFiring(EquippedItem item)
|
||||
{
|
||||
_weapons[item].Stop();
|
||||
_weapons.Remove(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7559cc5b68bf4495ae2643dc8d1b742b
|
||||
timeCreated: 1612570303
|
||||
|
|
@ -175,7 +175,7 @@ public class GuidedProjectile : MonoBehaviour
|
|||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, Velocity.normalized);
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, Velocity.normalized);
|
||||
}
|
||||
|
||||
StartCoroutine(Kill());
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class HitscanEffect : MonoBehaviour
|
|||
{
|
||||
if (hull.Entity != SourceEntity)
|
||||
{
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, transform.forward);
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
|
||||
}
|
||||
}
|
||||
var length = (hit.point - transform.position).magnitude;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class Laser : MonoBehaviour
|
|||
{
|
||||
if (hull.Entity != SourceEntity)
|
||||
{
|
||||
hull.SendHit(Damage * (Time.deltaTime / Duration), Penetration, Spread, DamageType, SourceEntity, hit, transform.forward);
|
||||
hull.SendHit(Damage * (Time.deltaTime / Duration), Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
|
||||
}
|
||||
}
|
||||
LineRenderer.SetPosition(1, hit.point);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class Lightning : MonoBehaviour
|
|||
{
|
||||
if (hull.Entity == Source.Entity) continue;
|
||||
LightningCompute.OnLeaderComplete = () =>
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, Source.Entity, hit, Barrel.forward);
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward);
|
||||
}
|
||||
|
||||
_colliderHit = true;
|
||||
|
|
|
|||
125
Assets/Scripts/Gameplay/Weapons/Mine.cs
Normal file
125
Assets/Scripts/Gameplay/Weapons/Mine.cs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Mine : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer MeshRenderer;
|
||||
public int EmissionSubmesh;
|
||||
public AnimationCurve EmissionCurve;
|
||||
public float ActiveCycleDuration;
|
||||
public float ArmedCycleDuration;
|
||||
public float ActiveEmission;
|
||||
public float ArmedEmission;
|
||||
public float RotationSpeed;
|
||||
public float GridOffset;
|
||||
public float GridAttraction;
|
||||
public float Gravity;
|
||||
public float Drag = .1f;
|
||||
public float LaunchDrag;
|
||||
public Prototype HitEffect;
|
||||
public float Lifetime;
|
||||
|
||||
public float ActivationDelay;
|
||||
public float BlastRange;
|
||||
public float BlastDelay;
|
||||
|
||||
private float2 _selfVelocity;
|
||||
private float _startTime;
|
||||
private float _blastTime;
|
||||
private bool _blastCountdown;
|
||||
private bool _active;
|
||||
private Material _material;
|
||||
private float _pulseLerp;
|
||||
private float _emission;
|
||||
|
||||
public Zone Zone { get; set; }
|
||||
public Vector3 Velocity { get; set; }
|
||||
public float Damage { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public EntityInstance Source { get; set; }
|
||||
public float Range { get; set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_material = MeshRenderer.materials[EmissionSubmesh];
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_startTime = Time.time;
|
||||
_blastCountdown = false;
|
||||
_active = false;
|
||||
_emission = 0;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Zone == null) return;
|
||||
|
||||
var t = transform;
|
||||
var position = t.position;
|
||||
var gridHeight = Zone.GetHeight(position.Flatland()) + GridOffset;
|
||||
Velocity += Vector3.up * (sign(gridHeight - position.y) * GridAttraction * Time.deltaTime);
|
||||
Velocity *= max(0, 1 - LaunchDrag * Time.deltaTime);
|
||||
var normal = Zone.GetNormal(position.Flatland());
|
||||
var force = new float2(normal.x, normal.z);
|
||||
var forceMagnitude = lengthsq(force);
|
||||
if (forceMagnitude > .001f)
|
||||
{
|
||||
var fa = 1 / (1 - forceMagnitude) - 1;
|
||||
_selfVelocity += normalize(force) * Zone.Settings.GravityStrength * fa * Gravity;
|
||||
}
|
||||
_selfVelocity *= max(0, 1 - Drag * Time.deltaTime);
|
||||
t.position = position + (Velocity + new Vector3(_selfVelocity.x,0,_selfVelocity.y)) * Time.deltaTime;
|
||||
t.localRotation = Quaternion.Euler(sin(Time.time-_startTime * RotationSpeed) * 90, 0, cos(Time.time-_startTime * RotationSpeed) * 90);
|
||||
|
||||
if (Time.time - _startTime > ActivationDelay && !_active)
|
||||
{
|
||||
_active = true;
|
||||
}
|
||||
|
||||
if(_active)
|
||||
{
|
||||
_emission = lerp(_emission, _blastCountdown ? ArmedEmission : ActiveEmission, Time.deltaTime * 10);
|
||||
_pulseLerp += Time.deltaTime / (_blastCountdown ? ArmedCycleDuration : ActiveCycleDuration);
|
||||
_pulseLerp %= 1;
|
||||
if(!_blastCountdown)
|
||||
{
|
||||
foreach (var collider in Physics.OverlapSphere(t.position, BlastRange, 1))
|
||||
{
|
||||
var hull = collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
_blastCountdown = true;
|
||||
_blastTime = Time.time + BlastDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((position - Source.Prefab.transform.position).magnitude > Range ||
|
||||
Time.time - _startTime > Lifetime ||
|
||||
_blastCountdown && Time.time > _blastTime)
|
||||
{
|
||||
foreach (var collider in Physics.OverlapSphere(t.position, BlastRange, 1))
|
||||
{
|
||||
var hull = collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
hull.SendSplash(Damage, DamageType, Source.Entity, (collider.transform.position - t.position).normalized);
|
||||
}
|
||||
}
|
||||
|
||||
var ht = HitEffect.Instantiate<Transform>();
|
||||
ht.position = t.position;
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
_material.SetFloat("_Emission", _emission * EmissionCurve.Evaluate(_pulseLerp));
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Gameplay/Weapons/Mine.cs.meta
Normal file
3
Assets/Scripts/Gameplay/Weapons/Mine.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f190191fe8c8419f85767868c50cde5f
|
||||
timeCreated: 1612545564
|
||||
34
Assets/Scripts/Gameplay/Weapons/MineManager.cs
Normal file
34
Assets/Scripts/Gameplay/Weapons/MineManager.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Mine>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var angle = weapon.Spread / 2;
|
||||
p.Source = source;
|
||||
p.transform.position = barrel.position;
|
||||
p.Velocity = Quaternion.Euler(
|
||||
Random.Range(-angle, angle),
|
||||
Random.Range(-angle, angle),
|
||||
Random.Range(-angle, angle)) *
|
||||
barrel.forward *
|
||||
weapon.Velocity;
|
||||
if(InheritVelocity)
|
||||
p.Velocity += new Vector3(source.Entity.Velocity.x, 0, source.Entity.Velocity.y);
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.DamageType = weapon.WeaponData.DamageType;
|
||||
p.Zone = source.Entity.Zone;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Gameplay/Weapons/MineManager.cs.meta
Normal file
3
Assets/Scripts/Gameplay/Weapons/MineManager.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e048d9c74a84343befd496907ee2126
|
||||
timeCreated: 1612545538
|
||||
|
|
@ -51,7 +51,7 @@ public class Projectile : MonoBehaviour
|
|||
{
|
||||
var t = transform;
|
||||
var position = t.position;
|
||||
Velocity += Vector3.up * (Gravity * Time.deltaTime);
|
||||
Velocity -= Vector3.up * (Gravity * Time.deltaTime);
|
||||
Velocity *= max(0, 1 - Drag * Time.deltaTime);
|
||||
var forward = Velocity.normalized;
|
||||
t.forward = forward;
|
||||
|
|
@ -63,7 +63,7 @@ public class Projectile : MonoBehaviour
|
|||
{
|
||||
if (hull.Entity != SourceEntity)
|
||||
{
|
||||
hull.SendHit(Damage*DirectHitDamageMultiplier, Penetration, Spread, DamageType, SourceEntity, hit, forward);
|
||||
hull.SendHit(Damage*DirectHitDamageMultiplier, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, forward);
|
||||
transform.position = hit.point;
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ public class ProjectileManager : InstantWeaponEffectManager
|
|||
Random.Range(-angle, angle)) *
|
||||
barrel.forward *
|
||||
weapon.Velocity;
|
||||
if(InheritVelocity)
|
||||
p.Velocity += new Vector3(source.Entity.Velocity.x, 0, source.Entity.Velocity.y);
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ public class SectorRenderer : MonoBehaviour
|
|||
|
||||
collider.Hit.Subscribe(hit =>
|
||||
{
|
||||
var hardpointIndex = (int) hit.Hit.textureCoord.x - 1;
|
||||
var hardpointIndex = (int) hit.TexCoord.x - 1;
|
||||
|
||||
var hitShape = new Shape(hullData.Shape.Width, hullData.Shape.Height);
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ public class SectorRenderer : MonoBehaviour
|
|||
float2 hitPos = float2.zero;
|
||||
if (hardpointIndex < 0)
|
||||
{
|
||||
hitPos = float2(hit.Hit.textureCoord.x * hullData.Shape.Width, hit.Hit.textureCoord.y * hullData.Shape.Height);
|
||||
hitPos = float2(hit.TexCoord.x * hullData.Shape.Width, hit.TexCoord.y * hullData.Shape.Height);
|
||||
// Search all schematic border cells for the cell which is closest to the hit position
|
||||
var hitCell = int2(-1);
|
||||
var distance = float.MaxValue;
|
||||
|
|
|
|||
Loading…
Reference in a new issue