Weapon Scripting Overhaul
Weapons are now monolithic behaviors Various new weapon behavior types implemented All weapons have optional magazine and reload mechanic Visibility now decays globally
This commit is contained in:
parent
48abee4847
commit
357f9db329
95 changed files with 2571 additions and 754 deletions
632
Assets/Scripts/Gameplay/ActionGameManager.cs
Normal file
632
Assets/Scripts/Gameplay/ActionGameManager.cs
Normal file
|
|
@ -0,0 +1,632 @@
|
|||
/* 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/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Cinemachine;
|
||||
using MessagePack;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
public class ActionGameManager : MonoBehaviour
|
||||
{
|
||||
public PlaceUIElementWorldspace ViewDot;
|
||||
public PlaceUIElementWorldspace TargetIndicator;
|
||||
public Prototype LockIndicator;
|
||||
public PlaceUIElementWorldspace[] Crosshairs;
|
||||
public EventLog EventLog;
|
||||
public GameSettings Settings;
|
||||
public SectorRenderer SectorRenderer;
|
||||
// public MapView MapView;
|
||||
public CinemachineVirtualCamera DockCamera;
|
||||
public CinemachineVirtualCamera FollowCamera;
|
||||
public GameObject GameplayUI;
|
||||
public MenuPanel Menu;
|
||||
public MapRenderer MenuMap;
|
||||
public SchematicDisplay SchematicDisplay;
|
||||
public SchematicDisplay TargetSchematicDisplay;
|
||||
public InventoryMenu Inventory;
|
||||
public InventoryPanel ShipPanel;
|
||||
public InventoryPanel TargetShipPanel;
|
||||
public ConfirmationDialog ConfirmationDialog;
|
||||
public float2 Sensitivity;
|
||||
public int Credits = 15000000;
|
||||
|
||||
//public PlayerInput Input;
|
||||
|
||||
// private CinemachineFramingTransposer _transposer;
|
||||
// private CinemachineComposer _composer;
|
||||
|
||||
private DirectoryInfo _filePath;
|
||||
private DirectoryInfo _presetPath;
|
||||
private bool _editMode;
|
||||
private float _time;
|
||||
private AetheriaInput _input;
|
||||
private int _zoomLevelIndex;
|
||||
public List<EntityPack> Loadouts { get; set; } = new List<EntityPack>();
|
||||
|
||||
// private ShipInput _shipInput;
|
||||
private float2 _shipYawPitch;
|
||||
private float3 _viewDirection;
|
||||
private (HardpointData[] hardpoints, Transform[] barrels, PlaceUIElementWorldspace crosshair)[] _articulationGroups;
|
||||
private (LockWeapon targetLock, PlaceUIElementWorldspace indicator, Rotate spin)[] _lockingIndicators;
|
||||
public List<Ship> PlayerShips { get; } = new List<Ship>();
|
||||
public EquippedDockingBay DockingBay { get; private set; }
|
||||
|
||||
public Ship CurrentShip { get; set; }
|
||||
public DatabaseCache ItemData { get; private set; }
|
||||
public ItemManager ItemManager { get; private set; }
|
||||
public Zone Zone { get; private set; }
|
||||
|
||||
private readonly (float2 direction, string name)[] _directions = {
|
||||
(float2(0, 1), "Front"),
|
||||
(float2(1, 0), "Right"),
|
||||
(float2(-1, 0), "Left"),
|
||||
(float2(0, -1), "Rear")
|
||||
};
|
||||
|
||||
public void SaveLoadout(EntityPack pack)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(_presetPath.FullName, $"{pack.Name}.preset"), MessagePackSerializer.Serialize(pack));
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// _transposer = DockCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
|
||||
// _composer = DockCamera.GetCinemachineComponent<CinemachineComposer>();
|
||||
//_lookAt = new GameObject().transform;
|
||||
|
||||
ConsoleController.MessageReceiver = this;
|
||||
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
_presetPath = _filePath.CreateSubdirectory("Presets");
|
||||
ItemData = new DatabaseCache();
|
||||
ItemData.Load(_filePath.FullName);
|
||||
ItemManager = new ItemManager(ItemData, Settings.GameplaySettings, Debug.Log);
|
||||
|
||||
Loadouts.AddRange(_presetPath.EnumerateFiles("*.preset")
|
||||
.Select(fi => MessagePackSerializer.Deserialize<EntityPack>(File.ReadAllBytes(fi.FullName))));
|
||||
|
||||
var zoneFile = Path.Combine(_filePath.FullName, "Home.zone");
|
||||
|
||||
// If the game has already been run, there will be a Home file containing a ZonePack; if not, generate one
|
||||
var zonePack = File.Exists(zoneFile) ?
|
||||
MessagePackSerializer.Deserialize<ZonePack>(File.ReadAllBytes(zoneFile)):
|
||||
ZoneGenerator.GenerateZone(
|
||||
settings: Settings.ZoneSettings,
|
||||
// mapLayers: Context.MapLayers,
|
||||
// resources: Context.Resources,
|
||||
mass: Settings.DefaultZoneMass,
|
||||
radius: Settings.DefaultZoneRadius
|
||||
);
|
||||
|
||||
Zone = new Zone(Settings.PlanetSettings, zonePack);
|
||||
SectorRenderer.ItemManager = ItemManager;
|
||||
SectorRenderer.LoadZone(Zone);
|
||||
|
||||
_input = new AetheriaInput();
|
||||
_input.Player.Enable();
|
||||
_input.Global.Enable();
|
||||
_input.UI.Enable();
|
||||
|
||||
_zoomLevelIndex = Settings.DefaultMinimapZoom;
|
||||
_input.Player.MinimapZoom.performed += context =>
|
||||
{
|
||||
_zoomLevelIndex = (_zoomLevelIndex + 1) % Settings.MinimapZoomLevels.Length;
|
||||
SectorRenderer.MinimapDistance = Settings.MinimapZoomLevels[_zoomLevelIndex];
|
||||
};
|
||||
|
||||
_input.Global.MapToggle.performed += context =>
|
||||
{
|
||||
if (Menu.gameObject.activeSelf && Menu.CurrentTab == MenuTab.Map)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
_input.Player.Enable();
|
||||
Menu.gameObject.SetActive(false);
|
||||
if (CurrentShip != null && CurrentShip.Parent == null)
|
||||
{
|
||||
GameplayUI.SetActive(true);
|
||||
|
||||
SchematicDisplay.ShowShip(CurrentShip);
|
||||
ShipPanel.Display(CurrentShip, true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
_input.Player.Disable();
|
||||
GameplayUI.SetActive(false);
|
||||
Menu.ShowTab(MenuTab.Map);
|
||||
MenuMap.Position = CurrentShip.Position.xz;
|
||||
};
|
||||
|
||||
_input.Global.Inventory.performed += context =>
|
||||
{
|
||||
if (Menu.gameObject.activeSelf && Menu.CurrentTab == MenuTab.Inventory)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
_input.Player.Enable();
|
||||
Menu.gameObject.SetActive(false);
|
||||
if (CurrentShip != null && CurrentShip.Parent == null)
|
||||
{
|
||||
GameplayUI.SetActive(true);
|
||||
|
||||
SchematicDisplay.ShowShip(CurrentShip);
|
||||
ShipPanel.Display(CurrentShip, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
_input.Player.Disable();
|
||||
Menu.ShowTab(MenuTab.Inventory);
|
||||
GameplayUI.SetActive(false);
|
||||
};
|
||||
|
||||
_input.Global.Dock.performed += context =>
|
||||
{
|
||||
if (CurrentShip.Parent == null) Dock();
|
||||
else Undock();
|
||||
};
|
||||
|
||||
_input.Player.TargetReticle.performed += context =>
|
||||
{
|
||||
var underReticle = Zone.Entities.Where(x => x != CurrentShip).MaxBy(x => dot(normalize(x.Position - CurrentShip.Position), CurrentShip.LookDirection));
|
||||
CurrentShip.Target.Value = CurrentShip.Target.Value == underReticle ? null : underReticle;
|
||||
};
|
||||
|
||||
_input.Player.TargetNearest.performed += context =>
|
||||
{
|
||||
CurrentShip.Target.Value = Zone.Entities.Where(x=>x!=CurrentShip).MaxBy(x => length(x.Position - CurrentShip.Position));
|
||||
};
|
||||
|
||||
_input.Player.TargetNext.performed += context =>
|
||||
{
|
||||
var targets = Zone.Entities.Where(x => x != CurrentShip).OrderBy(x => length(x.Position - CurrentShip.Position)).ToArray();
|
||||
var currentTargetIndex = Array.IndexOf(targets, CurrentShip.Target.Value);
|
||||
CurrentShip.Target.Value = targets[(currentTargetIndex + 1) % targets.Length];
|
||||
};
|
||||
|
||||
_input.Player.TargetPrevious.performed += context =>
|
||||
{
|
||||
var targets = Zone.Entities.Where(x => x != CurrentShip).OrderBy(x => length(x.Position - CurrentShip.Position)).ToArray();
|
||||
var currentTargetIndex = Array.IndexOf(targets, CurrentShip.Target.Value);
|
||||
CurrentShip.Target.Value = targets[(currentTargetIndex + targets.Length - 1) % targets.Length];
|
||||
};
|
||||
|
||||
#region Trigger Groups
|
||||
|
||||
_input.Player.PreviousWeaponGroup.performed += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
SchematicDisplay.SelectedGroupIndex--;
|
||||
};
|
||||
|
||||
_input.Player.NextWeaponGroup.performed += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
SchematicDisplay.SelectedGroupIndex++;
|
||||
};
|
||||
|
||||
_input.Player.PreviousWeapon.performed += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
SchematicDisplay.SelectedItemIndex--;
|
||||
};
|
||||
|
||||
_input.Player.NextWeapon.performed += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
SchematicDisplay.SelectedItemIndex++;
|
||||
};
|
||||
|
||||
_input.Player.ToggleWeaponGroup.performed += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
var item = SchematicDisplay.SchematicItems[SchematicDisplay.SelectedItemIndex];
|
||||
if (CurrentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].items.Contains(item.Item))
|
||||
CurrentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].items.Remove(item.Item);
|
||||
else CurrentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].items.Add(item.Item);
|
||||
foreach (var group in item.Item.BehaviorGroups.Values)
|
||||
{
|
||||
var behavior = group.GetBehavior<IActivatedBehavior>();
|
||||
if(behavior != null)
|
||||
{
|
||||
if (CurrentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].behaviors.Contains(behavior))
|
||||
CurrentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].behaviors.Remove(behavior);
|
||||
else CurrentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].behaviors.Add(behavior);
|
||||
}
|
||||
}
|
||||
SchematicDisplay.UpdateTriggerGroups();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup1.started += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[0].behaviors) s.Activate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup1.canceled += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[0].behaviors) s.Deactivate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup2.started += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[1].behaviors) s.Activate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup2.canceled += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[1].behaviors) s.Deactivate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup3.started += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[2].behaviors) s.Activate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup3.canceled += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[2].behaviors) s.Deactivate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup4.started += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[3].behaviors) s.Activate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup4.canceled += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[3].behaviors) s.Deactivate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup5.started += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[4].behaviors) s.Activate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup5.canceled += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[4].behaviors) s.Deactivate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup6.started += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[5].behaviors) s.Activate();
|
||||
};
|
||||
|
||||
_input.Player.FireGroup6.canceled += context =>
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var s in CurrentShip.TriggerGroups[5].behaviors) s.Deactivate();
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
// ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
|
||||
ConsoleController.AddCommand("savezone", args =>
|
||||
{
|
||||
if (args.Length > 0)
|
||||
Zone.Data.Name = args[0];
|
||||
SaveZone();
|
||||
});
|
||||
|
||||
var stationType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Station);
|
||||
var stationHull = ItemManager.CreateInstance(stationType, 0, 1) as EquippableItem;
|
||||
var stationParent = Zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(3);
|
||||
var stationParentOrbit = stationParent.Orbit.Data.ID;
|
||||
var stationParentPos = Zone.GetOrbitPosition(stationParentOrbit);
|
||||
var stationPos = stationParentPos + ItemManager.Random.NextFloat2Direction() * stationParent.GravityWellRadius.Value * .1f;
|
||||
var stationOrbit = Zone.CreateOrbit(stationParentOrbit, stationPos);
|
||||
var station = new OrbitalEntity(ItemManager, Zone, stationHull, stationOrbit.ID);
|
||||
Zone.Entities.Add(station);
|
||||
var dockingBayData = ItemData.GetAll<DockingBayData>().First();
|
||||
var dockingBay = ItemManager.CreateInstance(dockingBayData, 1, 1) as EquippableItem;
|
||||
station.TryEquip(dockingBay);
|
||||
station.Active = true;
|
||||
|
||||
var reactorData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Reactor && x.Shape.Height == 2);
|
||||
var autocannonData = ItemData.GetAll<GearData>().First(x => x.Name == "Autocannon");
|
||||
var ammoData = ItemData.GetAll<SimpleCommodityData>().First(x => x.Name == "AC2 Ammo");
|
||||
|
||||
var turretType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Turret);
|
||||
var controlModuleData = ItemData.GetAll<GearData>().First(x => x.Name == "Murder Module");
|
||||
var cargo1Data = ItemData.GetAll<CargoBayData>().First(x => x.Name == "Cargo Bay 1x1");
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
var turretParent = Zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(5+i);
|
||||
var turretParentOrbit = turretParent.Orbit.Data.ID;
|
||||
var turretParentPos = Zone.GetOrbitPosition(turretParentOrbit);
|
||||
var turretPos = turretParentPos + ItemManager.Random.NextFloat2Direction() * turretParent.GravityWellRadius.Value * .25f;
|
||||
var turretOrbit = Zone.CreateOrbit(turretParentOrbit, turretPos);
|
||||
var turret = new OrbitalEntity(ItemManager, Zone, ItemManager.CreateInstance(turretType, 0, 1) as EquippableItem, turretOrbit.ID);
|
||||
turret.TryEquip(ItemManager.CreateInstance(reactorData, .5f, 1) as EquippableItem);
|
||||
turret.TryEquip(ItemManager.CreateInstance(controlModuleData, .5f, 1) as EquippableItem);
|
||||
turret.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem);
|
||||
turret.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem);
|
||||
turret.TryEquip(ItemManager.CreateInstance(cargo1Data, .5f, 1) as EquippableItem);
|
||||
turret.CargoBays.First().TryStore(ItemManager.CreateInstance(ammoData, 400));
|
||||
turret.Active = true;
|
||||
Zone.Entities.Add(turret);
|
||||
}
|
||||
|
||||
var hullType = ItemData.GetAll<HullData>().First(x=>x.Name == "Djinni");
|
||||
var shipHull = ItemManager.CreateInstance(hullType, 0, 1) as EquippableItem;
|
||||
var ship = new Ship(ItemManager, Zone, shipHull);
|
||||
PlayerShips.Add(ship);
|
||||
CurrentShip = ship;
|
||||
CurrentShip.Target.Subscribe(target =>
|
||||
{
|
||||
TargetIndicator.gameObject.SetActive(CurrentShip.Target.Value != null);
|
||||
TargetShipPanel.gameObject.SetActive(target != null);
|
||||
if (target != null)
|
||||
{
|
||||
TargetShipPanel.Display(target, true);
|
||||
TargetSchematicDisplay.ShowShip(target, CurrentShip);
|
||||
}
|
||||
});
|
||||
ship.ArmorDamage.Subscribe(hit =>
|
||||
{
|
||||
var direction = _directions.MaxBy(d => dot(d.direction, normalize(hit.pos - hullType.Shape.CenterOfMass)));
|
||||
EventLog.LogMessage(
|
||||
$"{direction.name} armor hit for {hit.damage} damage, currently {((int) (ship.Armor[hit.pos.x, hit.pos.y] / hullType.Armor * 100)).ToString()}%",
|
||||
Settings.ArmorHitColor);
|
||||
});
|
||||
ship.HullDamage.Subscribe(hit => EventLog.LogMessage($"Hull Structure hit for {hit} damage"));
|
||||
ship.ItemDamage.Subscribe(hit =>
|
||||
{
|
||||
var data = ItemManager.GetData(hit.item.EquippableItem);
|
||||
EventLog.LogMessage(
|
||||
$"{hit.item.EquippableItem.Name} hit for {hit.damage} damage, currently {((int) (hit.item.EquippableItem.Durability / data.Durability * 100)).ToString()}%",
|
||||
Settings.GearHitColor);
|
||||
});
|
||||
ship.HardpointDamage.Subscribe(hit => EventLog.LogMessage(
|
||||
$"{Enum.GetName(typeof(HardpointType), hit.hardpoint.Type)} hardpoint hit for {hit.damage} damage, currently {((int) (ship.HardpointArmor[hit.hardpoint] / hit.hardpoint.Armor * 100)).ToString()}%",
|
||||
Settings.HardpointHitColor));
|
||||
|
||||
var thrusterData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Thruster && x.Shape.Height == 1);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
ship.TryEquip(ItemManager.CreateInstance(thrusterData, .5f, 1) as EquippableItem);
|
||||
//dockingCargo.TryStore(ItemManager.CreateInstance(thrusterData, .5f, 1));
|
||||
}
|
||||
|
||||
ship.TryEquip(ItemManager.CreateInstance(reactorData, .5f, 1) as EquippableItem);
|
||||
|
||||
var cockpitData = ItemData.GetAll<GearData>().First(x => x.Behaviors.Any(b=>b is CockpitData));
|
||||
ship.TryEquip(ItemManager.CreateInstance(cockpitData, .5f, 1) as EquippableItem);
|
||||
|
||||
ship.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem);
|
||||
ship.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem);
|
||||
|
||||
var lrmmData = ItemData.GetAll<GearData>().First(x => x.Name == "LRMM72");
|
||||
ship.TryEquip(ItemManager.CreateInstance(lrmmData, .5f, 1) as EquippableItem);
|
||||
ship.TryEquip(ItemManager.CreateInstance(lrmmData, .5f, 1) as EquippableItem);
|
||||
|
||||
var cargoData = ItemData.GetAll<CargoBayData>().First(x => x.Name == "Cargo Bay 4x4");
|
||||
ship.TryEquip(ItemManager.CreateInstance(cargoData, .5f, 1) as EquippableItem);
|
||||
|
||||
ship.CargoBays.First().TryStore(ItemManager.CreateInstance(ammoData, 200));
|
||||
//dockingCargo.TryStore(ItemManager.CreateInstance(reactorData, .5f, 1));
|
||||
|
||||
Dock();
|
||||
|
||||
// MapButton.onClick.AddListener(() =>
|
||||
// {
|
||||
// if (_currentMenuTabButton == MapPanel) return;
|
||||
//
|
||||
// _currentMenuTabButton.GetComponent<TextMeshProUGUI>().color = Color.white;
|
||||
// _currentMenuTabButton = MapButton;
|
||||
// });
|
||||
//
|
||||
//InventoryPanel.Display(ItemManager, entity);
|
||||
}
|
||||
|
||||
public void Dock()
|
||||
{
|
||||
if (CurrentShip.Parent != null) return;
|
||||
foreach (var entity in Zone.Entities.ToArray())
|
||||
{
|
||||
if (lengthsq(entity.Position.xz - CurrentShip.Position.xz) <
|
||||
Settings.GameplaySettings.DockingDistance * Settings.GameplaySettings.DockingDistance)
|
||||
{
|
||||
var bay = entity.TryDock(CurrentShip);
|
||||
if (bay != null)
|
||||
{
|
||||
DockingBay = bay;
|
||||
DockCamera.enabled = true;
|
||||
FollowCamera.enabled = false;
|
||||
CurrentShip.Active = false;
|
||||
var orbital = (OrbitalEntity) entity;
|
||||
DockCamera.Follow = SectorRenderer.EntityInstances[orbital].Transform;
|
||||
var parentOrbit = Zone.Orbits[orbital.OrbitData].Data.Parent;
|
||||
var parentPlanet = SectorRenderer.Planets[Zone.Planets.FirstOrDefault(p => p.Value.Orbit == parentOrbit).Key];
|
||||
DockCamera.LookAt = parentPlanet.Body.transform;
|
||||
Menu.ShowTab(MenuTab.Inventory);
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
_input.Player.Disable();
|
||||
GameplayUI.SetActive(false);
|
||||
if(_lockingIndicators!=null) foreach(var (_, indicator, _) in _lockingIndicators)
|
||||
indicator.GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Undock()
|
||||
{
|
||||
if (CurrentShip.Parent == null) return;
|
||||
if (CurrentShip.GetBehavior<Cockpit>() == null)
|
||||
{
|
||||
ConfirmationDialog.Clear();
|
||||
ConfirmationDialog.Title.text = "Can't undock. Missing cockpit component!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
else if (CurrentShip.GetBehavior<Thruster>() == null)
|
||||
{
|
||||
ConfirmationDialog.Clear();
|
||||
ConfirmationDialog.Title.text = "Can't undock. Missing thruster component!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
else if (CurrentShip.GetBehavior<Reactor>() == null)
|
||||
{
|
||||
ConfirmationDialog.Clear();
|
||||
ConfirmationDialog.Title.text = "Can't undock. Missing reactor component!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
else if (CurrentShip.Parent.TryUndock(CurrentShip))
|
||||
{
|
||||
Menu.gameObject.SetActive(false);
|
||||
DockingBay = null;
|
||||
CurrentShip.Active = true;
|
||||
//_shipInput = new ShipInput(_input.Player, _currentShip);
|
||||
DockCamera.enabled = false;
|
||||
FollowCamera.enabled = true;
|
||||
FollowCamera.LookAt = SectorRenderer.EntityInstances[CurrentShip].LookAtPoint;
|
||||
FollowCamera.Follow = SectorRenderer.EntityInstances[CurrentShip].Transform;
|
||||
_articulationGroups = CurrentShip.Equipment
|
||||
.Where(item => item.Behaviors.Any(x => x.Data is WeaponData && !(x.Data is LauncherData)))
|
||||
.GroupBy(item => SectorRenderer.EntityInstances[CurrentShip]
|
||||
.GetBarrel(CurrentShip.Hardpoints[item.Position.x, item.Position.y])
|
||||
.GetComponentInParent<ArticulationPoint>()?.Group ?? -1)
|
||||
.Select((group, index) => {
|
||||
return (
|
||||
group.Select(item => CurrentShip.Hardpoints[item.Position.x, item.Position.y]).ToArray(),
|
||||
group.Select(item => SectorRenderer.EntityInstances[CurrentShip].GetBarrel(CurrentShip.Hardpoints[item.Position.x, item.Position.y])).ToArray(),
|
||||
Crosshairs[index]
|
||||
);
|
||||
}).ToArray();
|
||||
|
||||
foreach (var crosshair in Crosshairs)
|
||||
crosshair.gameObject.SetActive(false);
|
||||
foreach (var group in _articulationGroups)
|
||||
group.crosshair.gameObject.SetActive(true);
|
||||
|
||||
_lockingIndicators = CurrentShip.GetBehaviors<LockWeapon>().Select(x =>
|
||||
{
|
||||
var i = LockIndicator.Instantiate<PlaceUIElementWorldspace>();
|
||||
return (x, i, i.GetComponent<Rotate>());
|
||||
}).ToArray();
|
||||
|
||||
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
GameplayUI.SetActive(true);
|
||||
_input.Player.Enable();
|
||||
ShipPanel.Display(CurrentShip, true);
|
||||
SchematicDisplay.ShowShip(CurrentShip);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfirmationDialog.Title.text = "Can't undock. Must empty docking bay!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveZone() => File.WriteAllBytes(
|
||||
Path.Combine(_filePath.FullName, $"{Zone.Data.Name}.zone"), MessagePackSerializer.Serialize(Zone.Pack()));
|
||||
|
||||
// public void ToggleEditMode()
|
||||
// {
|
||||
// _editMode = !_editMode;
|
||||
// FollowCamera.gameObject.SetActive(!_editMode);
|
||||
// TopDownCamera.gameObject.SetActive(_editMode);
|
||||
// }
|
||||
|
||||
public IEnumerable<EquippedCargoBay> AvailableCargoBays()
|
||||
{
|
||||
if (CurrentShip.Parent != null)
|
||||
{
|
||||
foreach (var bay in CurrentShip.Parent.DockingBays)
|
||||
{
|
||||
if (PlayerShips.Contains(bay.DockedShip)) yield return bay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Ship> AvailableShips()
|
||||
{
|
||||
if (CurrentShip.Parent != null)
|
||||
{
|
||||
foreach (var ship in PlayerShips)
|
||||
{
|
||||
if (CurrentShip.Parent.Children.Contains(ship)) yield return ship;
|
||||
}
|
||||
}
|
||||
else
|
||||
yield return CurrentShip;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(!_editMode)
|
||||
{
|
||||
_time += Time.deltaTime;
|
||||
ItemManager.Time = Time.time;
|
||||
if(CurrentShip.Parent==null)
|
||||
{
|
||||
var look = _input.Player.Look.ReadValue<Vector2>();
|
||||
_shipYawPitch = float2(_shipYawPitch.x + look.x * Sensitivity.x, clamp(_shipYawPitch.y + look.y * Sensitivity.y, -.45f * PI, .45f * PI));
|
||||
_viewDirection = mul(float3(0, 0, 1), Unity.Mathematics.float3x3.Euler(float3(_shipYawPitch.yx, 0), RotationOrder.YXZ));
|
||||
CurrentShip.LookDirection = _viewDirection;
|
||||
CurrentShip.MovementDirection = _input.Player.Move.ReadValue<Vector2>();
|
||||
}
|
||||
}
|
||||
Zone.Update(_time, Time.deltaTime);
|
||||
SectorRenderer.Time = _time;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
UpdateTargetIndicators();
|
||||
}
|
||||
|
||||
private void UpdateTargetIndicators()
|
||||
{
|
||||
if (CurrentShip == null || CurrentShip.Parent != null) return;
|
||||
|
||||
ViewDot.Target = SectorRenderer.EntityInstances[CurrentShip].LookAtPoint.position;
|
||||
if (CurrentShip.Target.Value != null)
|
||||
TargetIndicator.Target = CurrentShip.Target.Value.Position;
|
||||
var distance = length((float3)ViewDot.Target - CurrentShip.Position);
|
||||
foreach (var (_, barrels, crosshair) in _articulationGroups)
|
||||
{
|
||||
var averagePosition = Vector3.zero;
|
||||
foreach (var barrel in barrels)
|
||||
averagePosition += barrel.position + barrel.forward * distance;
|
||||
averagePosition /= barrels.Length;
|
||||
crosshair.Target = averagePosition;
|
||||
}
|
||||
foreach (var (targetLock, indicator, spin) in _lockingIndicators)
|
||||
{
|
||||
var showLockingIndicator = targetLock.Lock > .01f && CurrentShip.Target.Value != null;
|
||||
indicator.gameObject.SetActive(showLockingIndicator);
|
||||
if(showLockingIndicator)
|
||||
indicator.Target = CurrentShip.Target.Value.Position;
|
||||
indicator.NoiseAmplitude = Settings.GameplaySettings.LockIndicatorNoiseAmplitude * (1 - targetLock.Lock);
|
||||
indicator.NoiseFrequency = Settings.GameplaySettings.LockIndicatorFrequency.Evaluate(targetLock.Lock);
|
||||
spin.Speed = Settings.GameplaySettings.LockSpinSpeed.Evaluate(targetLock.Lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/ActionGameManager.cs.meta
Normal file
11
Assets/Scripts/Gameplay/ActionGameManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 39f95af24dd29a645895a57a75460b0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -10
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Scripts/Gameplay/ArticulationPoint.cs
Normal file
47
Assets/Scripts/Gameplay/ArticulationPoint.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class ArticulationPoint : MonoBehaviour
|
||||
{
|
||||
public Transform Target;
|
||||
|
||||
public int Group;
|
||||
|
||||
public float YawMin;
|
||||
public float YawMax;
|
||||
|
||||
public float PitchMin;
|
||||
public float PitchMax;
|
||||
|
||||
public float Speed;
|
||||
|
||||
private float _yaw;
|
||||
private float _pitch;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Target)
|
||||
{
|
||||
var targetLocal = transform.parent.InverseTransformPoint(Target.position);
|
||||
|
||||
var yaw = Vector2.SignedAngle(new Vector2(0, 1), new Vector2(targetLocal.x, targetLocal.z));
|
||||
var pitch = Vector2.SignedAngle(new Vector2(1, 0), new Vector2(targetLocal.z, targetLocal.y));
|
||||
|
||||
var targetYaw = clamp(-yaw, YawMin, YawMax);
|
||||
var targetPitch = clamp(-pitch, PitchMin, PitchMax);
|
||||
|
||||
if (abs(targetYaw - _yaw) < Speed * Time.deltaTime)
|
||||
_yaw = targetYaw;
|
||||
else _yaw = _yaw + sign(targetYaw - _yaw) * Speed * Time.deltaTime;
|
||||
|
||||
if (abs(targetPitch - _pitch) < Speed * Time.deltaTime)
|
||||
_pitch = targetPitch;
|
||||
else _pitch = _pitch + sign(targetPitch - _pitch) * Speed * Time.deltaTime;
|
||||
|
||||
transform.localRotation = Quaternion.Euler(_pitch, _yaw, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/ArticulationPoint.cs.meta
Normal file
11
Assets/Scripts/Gameplay/ArticulationPoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a2c831a00e255547b4261897f5c0b81
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Gameplay/EntityPrefab.cs
Normal file
15
Assets/Scripts/Gameplay/EntityPrefab.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityPrefab : MonoBehaviour
|
||||
{
|
||||
public HullCollider[] HullColliders;
|
||||
|
||||
public ThrusterHardpoint[] ThrusterHardpoints;
|
||||
public WeaponHardpoint[] WeaponHardpoints;
|
||||
public ArticulationPoint[] ArticulationPoints;
|
||||
|
||||
public GameObject DestroyEffect;
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/EntityPrefab.cs.meta
Normal file
11
Assets/Scripts/Gameplay/EntityPrefab.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 170aefb3b5cd0e444826f3561d38a962
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Scripts/Gameplay/HullCollider.cs
Normal file
39
Assets/Scripts/Gameplay/HullCollider.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using UnityEngine;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
public class HullCollider : MonoBehaviour
|
||||
{
|
||||
public Subject<HullHitEventArgs> Hit = new Subject<HullHitEventArgs>();
|
||||
|
||||
public Entity Entity { get; set; }
|
||||
|
||||
public void SendHit(float damage, float penetration, float spread, DamageType damageType, Entity source, RaycastHit hit, Vector3 direction)
|
||||
{
|
||||
Hit.OnNext(new HullHitEventArgs
|
||||
{
|
||||
Damage = damage,
|
||||
Penetration = penetration,
|
||||
Spread = spread,
|
||||
DamageType = damageType,
|
||||
Source = source,
|
||||
Hit = hit,
|
||||
Direction = direction
|
||||
});
|
||||
}
|
||||
|
||||
public class HullHitEventArgs
|
||||
{
|
||||
public float Damage;
|
||||
public float Penetration;
|
||||
public float Spread;
|
||||
public DamageType DamageType;
|
||||
public Entity Source;
|
||||
public RaycastHit Hit;
|
||||
public float3 Direction;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/HullCollider.cs.meta
Normal file
11
Assets/Scripts/Gameplay/HullCollider.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eff043e6f0a5f834ebfbc7f750260ae0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Gameplay/ThrusterHardpoint.cs
Normal file
8
Assets/Scripts/Gameplay/ThrusterHardpoint.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ThrusterHardpoint : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer Emitter;
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/ThrusterHardpoint.cs.meta
Normal file
11
Assets/Scripts/Gameplay/ThrusterHardpoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 50d4c3a9c5db3ce40b91caf2ae88dabe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Gameplay/WeaponHardpoint.cs
Normal file
8
Assets/Scripts/Gameplay/WeaponHardpoint.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponHardpoint : MonoBehaviour
|
||||
{
|
||||
public Transform[] FiringPoint;
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/WeaponHardpoint.cs.meta
Normal file
11
Assets/Scripts/Gameplay/WeaponHardpoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2b6f57d9fe9e78c438112332511e7b07
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Gameplay/Weapons.meta
Normal file
8
Assets/Scripts/Gameplay/Weapons.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89bd1fe14443ac841ba3ad78301769f5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class ConstantWeaponEffectManager : MonoBehaviour
|
||||
{
|
||||
public abstract void Start(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target);
|
||||
public abstract void Stop(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 38df809a0cf4b7748bad88620bb7b3ab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
129
Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs
Normal file
129
Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using Random = UnityEngine.Random;
|
||||
using static Noise1D;
|
||||
|
||||
public class GuidedProjectile : MonoBehaviour
|
||||
{
|
||||
public ParticleSystem Particles;
|
||||
public float FadeOutTime;
|
||||
public AnimationCurve ThrustCurve;
|
||||
public AnimationCurve GuidanceCurve;
|
||||
public AnimationCurve LiftCurve;
|
||||
public float Frequency;
|
||||
public float Thrust;
|
||||
public float TopSpeed;
|
||||
public Transform Source;
|
||||
public Transform Target;
|
||||
|
||||
private float _phase;
|
||||
private float _prevDist;
|
||||
private bool _active;
|
||||
private bool _alive;
|
||||
|
||||
public Vector3 Velocity { get; set; }
|
||||
public float Damage { get; set; }
|
||||
public float Penetration { get; set; }
|
||||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_active = _alive = true;
|
||||
_phase = Random.value * 100;
|
||||
_prevDist = Single.MaxValue;
|
||||
Particles.startColor = Color.white;
|
||||
//var main = Particles.main;
|
||||
//main.startColor = new ParticleSystem.MinMaxGradient { mode = ParticleSystemGradientMode.Color, color = Color.white };
|
||||
Particles.Clear(true);
|
||||
Particles.Play(true);
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (SourceEntity == null) return;
|
||||
|
||||
|
||||
var t = transform;
|
||||
|
||||
if (_active)
|
||||
{
|
||||
if (!Target)
|
||||
{
|
||||
StartCoroutine(FadeOut());
|
||||
return;
|
||||
}
|
||||
|
||||
var diff = Target.position - transform.position;
|
||||
var targetDist = diff.magnitude;
|
||||
|
||||
if (_prevDist < targetDist)
|
||||
{
|
||||
StartCoroutine(FadeOut());
|
||||
}
|
||||
_prevDist = targetDist;
|
||||
|
||||
var position = (float3) t.position;
|
||||
var sourceDist = length((float3) Source.position - position);
|
||||
var curveLerp = 1 - targetDist / (sourceDist + targetDist);
|
||||
var dir = diff.normalized;
|
||||
var right = cross(dir, float3(0, 1, 0));
|
||||
var up = cross(dir, right);
|
||||
var dodge = normalize(lerp(
|
||||
normalize(right * noise(Time.time * Frequency + _phase) + up * noise(Time.time * Frequency + (100 + _phase))),
|
||||
Vector3.up, LiftCurve.Evaluate(curveLerp)));
|
||||
var desired = Vector3.Slerp(dodge, dir, GuidanceCurve.Evaluate(curveLerp)).normalized * TopSpeed;
|
||||
var thrust = Thrust * ThrustCurve.Evaluate(curveLerp);
|
||||
Velocity += (desired-Velocity) * (thrust * Time.deltaTime);
|
||||
}
|
||||
|
||||
var ray = new Ray(t.position, Velocity);
|
||||
if (Physics.Raycast(ray, out var hit, Velocity.magnitude * Time.deltaTime, 1))
|
||||
{
|
||||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, Velocity.normalized);
|
||||
}
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
t.position += Velocity * Time.deltaTime;
|
||||
}
|
||||
|
||||
IEnumerator FadeOut()
|
||||
{
|
||||
_active = false;
|
||||
var startTime = Time.time;
|
||||
while (Time.time - startTime < FadeOutTime)
|
||||
{
|
||||
var lerp = 1 - (Time.time - startTime) / FadeOutTime;
|
||||
Particles.startColor = Color.white * lerp;
|
||||
//var main = Particles.main;
|
||||
//main.startColor = new ParticleSystem.MinMaxGradient { mode = ParticleSystemGradientMode.Color, color = Color.white * lerp };
|
||||
yield return null;
|
||||
}
|
||||
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
|
||||
IEnumerator Kill()
|
||||
{
|
||||
_alive = false;
|
||||
Particles.Stop(true, ParticleSystemStopBehavior.StopEmitting);
|
||||
var startTime = Time.time;
|
||||
var lifetime = Particles.main.startLifetime.constant;
|
||||
while (Time.time - startTime < lifetime)
|
||||
yield return null;
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 56c973b8f3781c848b6530c2e7efce05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Gameplay/Weapons/GuidedProjectileManager.cs
Normal file
35
Assets/Scripts/Gameplay/Weapons/GuidedProjectileManager.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GuidedProjectileManager : InstantWeaponEffectManager
|
||||
{
|
||||
public Prototype ProjectilePrototype;
|
||||
|
||||
public override void Fire(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
if(data is LauncherData launcher)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
||||
p.Source = source.Transform;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.Target = target.Transform;
|
||||
p.Frequency = launcher.DodgeFrequency;
|
||||
p.Thrust = source.Entity.ItemManager.Evaluate(launcher.Thrust, item.EquippableItem, source.Entity);
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.transform.position = barrel.position;
|
||||
p.Velocity = barrel.forward * source.Entity.ItemManager.Evaluate(launcher.LaunchSpeed, item.EquippableItem, source.Entity);
|
||||
p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity);
|
||||
p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity);
|
||||
p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity);
|
||||
p.DamageType = data.DamageType;
|
||||
p.GuidanceCurve = launcher.GuidanceCurve.ToCurve();
|
||||
p.LiftCurve = launcher.LiftCurve.ToCurve();
|
||||
p.ThrustCurve = launcher.ThrustCurve.ToCurve();
|
||||
p.Thrust = source.Entity.ItemManager.Evaluate(launcher.Thrust, item.EquippableItem, source.Entity);
|
||||
p.TopSpeed = source.Entity.ItemManager.Evaluate(launcher.Velocity, item.EquippableItem, source.Entity);
|
||||
}
|
||||
else Debug.LogError($"Weapon {item.EquippableItem.Name} linked to {name} effect, but is not a Launcher!");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee3949bbc28566148b9f661741b6e25d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class InstantWeaponEffectManager : MonoBehaviour
|
||||
{
|
||||
public abstract void Fire(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 947a7d0e9469d724daed03d35a0c1f4e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/Gameplay/Weapons/Laser.cs
Normal file
13
Assets/Scripts/Gameplay/Weapons/Laser.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Laser : MonoBehaviour
|
||||
{
|
||||
public float Damage { get; set; }
|
||||
public float Penetration { get; set; }
|
||||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public float Range { get; set; }
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/Laser.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/Laser.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 166b726996e49bd4b87608739a5af815
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/Gameplay/Weapons/LaserManager.cs
Normal file
25
Assets/Scripts/Gameplay/Weapons/LaserManager.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LaserManager : InstantWeaponEffectManager
|
||||
{
|
||||
public Prototype ProjectilePrototype;
|
||||
|
||||
public override void Fire(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Laser>();
|
||||
p.SourceEntity = source.Entity;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Range = source.Entity.ItemManager.Evaluate(data.Range, item.EquippableItem, source.Entity);
|
||||
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.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity);
|
||||
p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity);
|
||||
p.DamageType = data.DamageType;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/LaserManager.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/LaserManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5745a5be5f0c02b4b88bd094ea609c13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Scripts/Gameplay/Weapons/Projectile.cs
Normal file
89
Assets/Scripts/Gameplay/Weapons/Projectile.cs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using UnityEngine;
|
||||
|
||||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
public TrailRenderer Trail;
|
||||
public float Gravity;
|
||||
public Prototype HitEffect;
|
||||
|
||||
private bool _alive;
|
||||
|
||||
public Zone Zone { get; set; }
|
||||
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 Velocity { get; set; }
|
||||
public float Damage { get; set; }
|
||||
public float Penetration { get; set; }
|
||||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public float Range { get; set; }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_alive = true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (SourceEntity == null) return;
|
||||
|
||||
if(_alive)
|
||||
{
|
||||
var position = transform.position;
|
||||
Velocity += Vector3.up * (Gravity * Time.deltaTime);
|
||||
var ray = new Ray(position, Velocity);
|
||||
if (Physics.Raycast(ray, out var hit, Velocity.magnitude * Time.deltaTime, 1))
|
||||
{
|
||||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
if (hull.Entity != SourceEntity)
|
||||
{
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, Velocity.normalized);
|
||||
transform.position = hit.point;
|
||||
StartCoroutine(Kill());
|
||||
if (HitEffect != null)
|
||||
{
|
||||
var t = HitEffect.Instantiate<Transform>();
|
||||
t.SetParent(hit.collider.transform);
|
||||
t.position = hit.point;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else// if (hit.transform.gameObject.layer == 1)
|
||||
{
|
||||
StartCoroutine(Kill());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
transform.position += Velocity * Time.deltaTime;
|
||||
if((transform.position - StartPosition).magnitude > Range)
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Kill()
|
||||
{
|
||||
_alive = false;
|
||||
var startTime = Time.time;
|
||||
var lifetime = Trail.time;
|
||||
while (Time.time - startTime < lifetime)
|
||||
yield return null;
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/Projectile.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/Projectile.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4528540a139424748a7b6c47bfecc7fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/Scripts/Gameplay/Weapons/ProjectileManager.cs
Normal file
31
Assets/Scripts/Gameplay/Weapons/ProjectileManager.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProjectileManager : InstantWeaponEffectManager
|
||||
{
|
||||
public Prototype ProjectilePrototype;
|
||||
|
||||
public override void Fire(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
if(data is ProjectileWeaponData projectile)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Projectile>();
|
||||
p.SourceEntity = source.Entity;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Range = source.Entity.ItemManager.Evaluate(data.Range, item.EquippableItem, source.Entity);
|
||||
p.StartPosition = p.transform.position = barrel.position;
|
||||
var angle = source.Entity.ItemManager.Evaluate(projectile.Spread, item.EquippableItem, source.Entity) / 2;
|
||||
p.Velocity = (Quaternion.Euler(Random.Range(-angle, angle), Random.Range(-angle, angle), Random.Range(-angle, angle)) * barrel.forward) *
|
||||
source.Entity.ItemManager.Evaluate(projectile.Velocity, item.EquippableItem, source.Entity);
|
||||
p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity);
|
||||
p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity);
|
||||
p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity);
|
||||
p.DamageType = data.DamageType;
|
||||
p.Zone = source.Entity.Zone;
|
||||
p.Trail.Clear();
|
||||
}
|
||||
else Debug.LogError($"Weapon {item.EquippableItem.Name} linked to {name} effect, but is not a Projectile Weapon!");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/ProjectileManager.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/ProjectileManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 49c173e3c2313ca4d9d04d0d87ec0f06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue