diff --git a/Assets/Materials/UI/Map Gravity Lines.mat b/Assets/Materials/UI/Map Gravity Lines.mat index 913368cbf..0d9aadfbe 100644 --- a/Assets/Materials/UI/Map Gravity Lines.mat +++ b/Assets/Materials/UI/Map Gravity Lines.mat @@ -86,7 +86,7 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 - - _Scale: 5.396003 + - _Scale: 2.8484566 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 diff --git a/Assets/Resources/Aetheria.inputactions b/Assets/Resources/Aetheria.inputactions index 69c58c533..2a0963e99 100644 --- a/Assets/Resources/Aetheria.inputactions +++ b/Assets/Resources/Aetheria.inputactions @@ -164,6 +164,14 @@ "expectedControlType": "Button", "processors": "", "interactions": "" + }, + { + "name": "Toggle Shield", + "type": "Button", + "id": "5566504f-ee89-4eb9-9bbb-03f4b22dfe7d", + "expectedControlType": "Button", + "processors": "", + "interactions": "" } ], "bindings": [ @@ -573,6 +581,17 @@ "action": "EnterWormhole", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "d59fb542-6ac5-466d-a668-67fd8c890232", + "path": "/#(G)", + "interactions": "", + "processors": "", + "groups": "", + "action": "Toggle Shield", + "isComposite": false, + "isPartOfComposite": false } ] }, diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index 5a0bd17e7..a42239c6e 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:caa407a313b4aca849d2e92d32552c3202bb09e790e4dcadf813102cb37a39bf -size 7879 +oid sha256:d36bc575eff8aa453ae459076b9dbde85fac0c1b918c19ca69dd68e3e0aa857e +size 7880 diff --git a/Assets/Scenes/ARPG.unity b/Assets/Scenes/ARPG.unity index 136c0ff61..68afe8c2c 100644 --- a/Assets/Scenes/ARPG.unity +++ b/Assets/Scenes/ARPG.unity @@ -220,6 +220,118 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8750545} m_CullTransparentMesh: 0 +--- !u!1 &19222411 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 19222412} + - component: {fileID: 19222416} + - component: {fileID: 19222415} + - component: {fileID: 19222414} + - component: {fileID: 19222413} + m_Layer: 5 + m_Name: Shield Icon + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &19222412 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 19222411} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 7628189704016736659} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -6, y: -8} + m_SizeDelta: {x: 16, y: 16} + m_Pivot: {x: 1, y: 1} +--- !u!114 &19222413 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 19222411} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3} + m_Name: + m_EditorClassIdentifier: + m_EffectColor: {r: 0, g: 0, b: 0, a: 1} + m_EffectDistance: {x: 1, y: -1} + m_UseGraphicAlpha: 1 +--- !u!114 &19222414 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 19222411} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreLayout: 1 + m_MinWidth: -1 + m_MinHeight: -1 + m_PreferredWidth: -1 + m_PreferredHeight: -1 + m_FlexibleWidth: -1 + m_FlexibleHeight: -1 + m_LayoutPriority: 1 +--- !u!114 &19222415 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 19222411} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 0.44583336, b: 0.050000012, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: 71cca4a0fa4916444a6c798b69903e39, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &19222416 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 19222411} + m_CullTransparentMesh: 1 --- !u!1 &23420356 GameObject: m_ObjectHideFlags: 0 @@ -2878,10 +2990,10 @@ RectTransform: m_Father: {fileID: 746825913} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 90.5, y: -8} - m_SizeDelta: {x: 181, y: 16} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &232470598 MonoBehaviour: @@ -4007,7 +4119,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &346000247 RectTransform: m_ObjectHideFlags: 0 @@ -4549,6 +4661,7 @@ MonoBehaviour: TriggerGroupPrototype: {fileID: 1564656282} HeaderElementEnabledColor: {r: 0, g: 0, b: 0, a: 0} HeaderElementDisabledColor: {r: 0, g: 0, b: 0, a: 0} + ShieldIcon: {fileID: 0} HeatsinkBackground: {fileID: 0} EnergyLabel: {fileID: 0} CockpitTemperatureLabel: {fileID: 0} @@ -15433,10 +15546,10 @@ RectTransform: m_Father: {fileID: 204301710} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 92, y: -220} - m_SizeDelta: {x: 184, y: 16} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1277237367 MonoBehaviour: @@ -16414,7 +16527,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} m_AnchoredPosition: {x: 439, y: 204} - m_SizeDelta: {x: 128, y: 16} + m_SizeDelta: {x: 128, y: 0} m_Pivot: {x: 0, y: 1} --- !u!114 &1399423351 MonoBehaviour: @@ -18033,7 +18146,7 @@ PrefabInstance: - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} propertyPath: m_AnchoredPosition.x - value: 0 + value: 55.675 objectReference: {fileID: 0} - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} @@ -18687,10 +18800,10 @@ RectTransform: m_Father: {fileID: 1399423350} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 63.5, y: -8} - m_SizeDelta: {x: 127, y: 16} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1564656282 MonoBehaviour: @@ -18786,7 +18899,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0} m_AnchoredPosition: {x: 0, y: -224} - m_SizeDelta: {x: 0, y: 325.58} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0} --- !u!114 &1590553660 MonoBehaviour: @@ -18964,7 +19077,7 @@ PrefabInstance: - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} propertyPath: m_AnchoredPosition.x - value: 0 + value: 60.98 objectReference: {fileID: 0} - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} @@ -21622,10 +21735,10 @@ RectTransform: m_Father: {fileID: 1359207439} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 127, y: -130} - m_SizeDelta: {x: 16, y: 16} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1889622744 MonoBehaviour: @@ -28502,10 +28615,10 @@ RectTransform: m_Father: {fileID: 7628189704016736659} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 127, y: -130} - m_SizeDelta: {x: 16, y: 16} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &7628189703197605887 MonoBehaviour: @@ -28549,6 +28662,7 @@ RectTransform: m_Children: - {fileID: 2851244030680155772} - {fileID: 7628189703197605886} + - {fileID: 19222412} m_Father: {fileID: 7628189704109037581} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -29473,6 +29587,7 @@ MonoBehaviour: TriggerGroupPrototype: {fileID: 1564656282} HeaderElementEnabledColor: {r: 1, g: 1, b: 1, a: 0.078431375} HeaderElementDisabledColor: {r: 1, g: 1, b: 1, a: 0.011764706} + ShieldIcon: {fileID: 19222411} HeatsinkBackground: {fileID: 661332569} EnergyLabel: {fileID: 804489113} CockpitTemperatureLabel: {fileID: 212527384} diff --git a/Assets/Scripts/AetheriaInput.cs b/Assets/Scripts/AetheriaInput.cs index 6538fc5dc..765313dd1 100644 --- a/Assets/Scripts/AetheriaInput.cs +++ b/Assets/Scripts/AetheriaInput.cs @@ -177,6 +177,14 @@ public class @AetheriaInput : IInputActionCollection, IDisposable ""expectedControlType"": ""Button"", ""processors"": """", ""interactions"": """" + }, + { + ""name"": ""Toggle Shield"", + ""type"": ""Button"", + ""id"": ""5566504f-ee89-4eb9-9bbb-03f4b22dfe7d"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """" } ], ""bindings"": [ @@ -586,6 +594,17 @@ public class @AetheriaInput : IInputActionCollection, IDisposable ""action"": ""EnterWormhole"", ""isComposite"": false, ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""d59fb542-6ac5-466d-a668-67fd8c890232"", + ""path"": ""/#(G)"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Toggle Shield"", + ""isComposite"": false, + ""isPartOfComposite"": false } ] }, @@ -1172,6 +1191,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable m_Player_TargetNearest = m_Player.FindAction("Target Nearest", throwIfNotFound: true); m_Player_ToggleHeatsinks = m_Player.FindAction("Toggle Heatsinks", throwIfNotFound: true); m_Player_EnterWormhole = m_Player.FindAction("EnterWormhole", throwIfNotFound: true); + m_Player_ToggleShield = m_Player.FindAction("Toggle Shield", throwIfNotFound: true); // UI m_UI = asset.FindActionMap("UI", throwIfNotFound: true); m_UI_Navigate = m_UI.FindAction("Navigate", throwIfNotFound: true); @@ -1257,6 +1277,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable private readonly InputAction m_Player_TargetNearest; private readonly InputAction m_Player_ToggleHeatsinks; private readonly InputAction m_Player_EnterWormhole; + private readonly InputAction m_Player_ToggleShield; public struct PlayerActions { private @AetheriaInput m_Wrapper; @@ -1281,6 +1302,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable public InputAction @TargetNearest => m_Wrapper.m_Player_TargetNearest; public InputAction @ToggleHeatsinks => m_Wrapper.m_Player_ToggleHeatsinks; public InputAction @EnterWormhole => m_Wrapper.m_Player_EnterWormhole; + public InputAction @ToggleShield => m_Wrapper.m_Player_ToggleShield; public InputActionMap Get() { return m_Wrapper.m_Player; } public void Enable() { Get().Enable(); } public void Disable() { Get().Disable(); } @@ -1350,6 +1372,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable @EnterWormhole.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnEnterWormhole; @EnterWormhole.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnEnterWormhole; @EnterWormhole.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnEnterWormhole; + @ToggleShield.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleShield; + @ToggleShield.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleShield; + @ToggleShield.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleShield; } m_Wrapper.m_PlayerActionsCallbackInterface = instance; if (instance != null) @@ -1414,6 +1439,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable @EnterWormhole.started += instance.OnEnterWormhole; @EnterWormhole.performed += instance.OnEnterWormhole; @EnterWormhole.canceled += instance.OnEnterWormhole; + @ToggleShield.started += instance.OnToggleShield; + @ToggleShield.performed += instance.OnToggleShield; + @ToggleShield.canceled += instance.OnToggleShield; } } } @@ -1613,6 +1641,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable void OnTargetNearest(InputAction.CallbackContext context); void OnToggleHeatsinks(InputAction.CallbackContext context); void OnEnterWormhole(InputAction.CallbackContext context); + void OnToggleShield(InputAction.CallbackContext context); } public interface IUIActions { diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 8be70f818..c24e44be1 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -225,6 +225,15 @@ public class ActionGameManager : MonoBehaviour AkSoundEngine.PostEvent(CurrentShip.HeatsinksEnabled ? "UI_Success" : "UI_Fail", gameObject); }; + _input.Player.ToggleShield.performed += context => + { + if (CurrentShip.Shield != null) + { + CurrentShip.Shield.Item.Enabled = !CurrentShip.Shield.Item.Enabled; + AkSoundEngine.PostEvent(CurrentShip.Shield.Item.Enabled ? "UI_Success" : "UI_Fail", gameObject); + } + }; + #region Targeting _input.Player.TargetReticle.performed += context => diff --git a/Assets/Scripts/Gameplay/Weapons/ConstantLaser.cs b/Assets/Scripts/Gameplay/Weapons/ConstantLaser.cs index d3e21a190..81b925a8f 100644 --- a/Assets/Scripts/Gameplay/Weapons/ConstantLaser.cs +++ b/Assets/Scripts/Gameplay/Weapons/ConstantLaser.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using static Unity.Mathematics.math; public class ConstantLaser : MonoBehaviour { @@ -69,20 +70,34 @@ public class ConstantLaser : MonoBehaviour } LineRenderer.SetPosition(0, transform.position); - RaycastHit hit; - if (Physics.Raycast(new Ray(transform.position, transform.forward), out hit, Range, 1)) + bool hitFound = false; + foreach (var hit in Physics.RaycastAll(new Ray(transform.position, transform.forward), Range, 1 | (1 << 17))) { + var shield = hit.collider.GetComponent(); + if (shield) + { + if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue; + if (shield.Entity != SourceEntity) + { + shield.Entity.Shield.TakeHit(DamageType, Damage); + shield.ShowHit(hit.point, sqrt(Damage)); + LineRenderer.SetPosition(1, hit.point); + hitFound = true; + } + } var hull = hit.collider.GetComponent(); if (hull) { if (hull.Entity != SourceEntity) { hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward); + transform.position = hit.point; + LineRenderer.SetPosition(1, hit.point); + hitFound = true; } } - LineRenderer.SetPosition(1, hit.point); } - else + if(!hitFound) LineRenderer.SetPosition(1, transform.position + transform.forward * Range); } diff --git a/Assets/Scripts/Gameplay/Weapons/ConstantLightning.cs b/Assets/Scripts/Gameplay/Weapons/ConstantLightning.cs index 7a270bcce..7f2446b55 100644 --- a/Assets/Scripts/Gameplay/Weapons/ConstantLightning.cs +++ b/Assets/Scripts/Gameplay/Weapons/ConstantLightning.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using static Unity.Mathematics.math; public class ConstantLightning : MonoBehaviour { @@ -50,11 +51,18 @@ public class ConstantLightning : MonoBehaviour } Lightning.FixedEndpoint = false; - var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1); + var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1 | (1 << 17)); foreach (var hit in hits) { + var shield = hit.collider.GetComponent(); + if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) + { + if (shield.Entity == Source.Entity) continue; + shield.Entity.Shield.TakeHit(DamageType, Damage * Time.deltaTime); + shield.ShowHit(hit.point, sqrt(Damage)); + } var hull = hit.collider.GetComponent(); - if (hull) + if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active && hull.Entity.Shield.CanTakeHit(DamageType, Damage))) { if (hull.Entity == Source.Entity) continue; hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward); diff --git a/Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs b/Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs index ccd4fbcc4..8fd55340d 100644 --- a/Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs +++ b/Assets/Scripts/Gameplay/Weapons/GuidedProjectile.cs @@ -12,12 +12,6 @@ public class GuidedProjectile : MonoBehaviour { public Prototype HitEffect; public Prototype ChildProjectile; - public Prototype AirburstProjectile; - public int AirburstCount; - public float AirburstDirectionality; - public float AirburstDistance; - public float AirburstRange; - public float AirburstVelocity; public int Children; public float SplitTime; public float SplitSeparationForwardness; @@ -81,7 +75,7 @@ public class GuidedProjectile : MonoBehaviour var position = (float3) t.position; var sourceDist = length(StartPosition.xz - position.xz); - if (sourceDist > Range || dot(diff,Velocity) < 0 || AirburstCount > 0 && targetDist < AirburstDistance) + if (sourceDist > Range || dot(diff,Velocity) < 0) { StartCoroutine(FadeOut()); if (HitEffect != null) @@ -89,27 +83,6 @@ public class GuidedProjectile : MonoBehaviour var ht = HitEffect.Instantiate(); ht.position = t.position; } - - if (AirburstCount > 0 && AirburstProjectile) - { - var targetDiff = Target.position - transform.position; - if (targetDiff.magnitude < AirburstRange) - { - for (int i = 0; i < AirburstCount; i++) - { - var child = AirburstProjectile.Instantiate(); - child.StartPosition = child.transform.position = t.position; - var randomDirection = Random.onUnitSphere; - child.Velocity = Vector3.Lerp(randomDirection, targetDiff.normalized, AirburstDirectionality).normalized * AirburstVelocity; - child.Range = AirburstRange; - child.Damage = Damage / AirburstCount; - child.Penetration = Penetration; - child.Spread = Spread; - child.DamageType = DamageType; - child.SourceEntity = SourceEntity; - } - } - } return; } _prevDist = targetDist; @@ -169,15 +142,34 @@ public class GuidedProjectile : MonoBehaviour if(_alive) { var ray = new Ray(t.position, Velocity); - if (Physics.Raycast(ray, out var hit, Velocity.magnitude * Time.deltaTime, 1)) + foreach (var hit in Physics.RaycastAll(ray, Velocity.magnitude * Time.deltaTime, 1 | (1 << 17))) { - var hull = hit.collider.GetComponent(); - if (hull) + var shield = hit.collider.GetComponent(); + if (shield) { - hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, Velocity.normalized); + if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue; + if (shield.Entity != SourceEntity) + { + shield.Entity.Shield.TakeHit(DamageType, Damage); + shield.ShowHit(hit.point, sqrt(Damage)); + } } - - StartCoroutine(Kill()); + var hull = hit.collider.GetComponent(); + if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active && hull.Entity.Shield.CanTakeHit(DamageType, Damage))) + { + if (hull.Entity != SourceEntity) + { + hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward); + transform.position = hit.point; + StartCoroutine(Kill()); + } + } + else// if (hit.transform.gameObject.layer == 1) + { + StartCoroutine(Kill()); + return; + } + if (HitEffect != null) { var ht = HitEffect.Instantiate(); diff --git a/Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs b/Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs index 553aefd91..68e1bfd74 100644 --- a/Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs +++ b/Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using static Unity.Mathematics.math; public class HitscanEffect : MonoBehaviour { @@ -25,17 +26,39 @@ public class HitscanEffect : MonoBehaviour public void Fire() { _startTime = Time.time; - RaycastHit hit; - if (Physics.Raycast(new Ray(transform.position, transform.forward), out hit, Range, 1)) + var hitFound = false; + var ray = new Ray(transform.position, transform.forward); + foreach (var hit in Physics.RaycastAll(ray, Range, 1 | (1 << 17))) { + var shield = hit.collider.GetComponent(); + if (shield) + { + if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue; + if (shield.Entity != SourceEntity) + { + shield.Entity.Shield.TakeHit(DamageType, Damage); + shield.ShowHit(hit.point, sqrt(Damage)); + hitFound = true; + } + } var hull = hit.collider.GetComponent(); if (hull) { if (hull.Entity != SourceEntity) { hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward); + transform.position = hit.point; + hitFound = true; } } + + if (hitFound && HitEffect != null) + { + var ht = HitEffect.Instantiate(); + ht.SetParent(hit.collider.transform); + ht.position = hit.point; + } + var length = (hit.point - transform.position).magnitude; Line.SetPosition(1, Vector3.forward * length); var emission = LineEffect.emission; @@ -44,7 +67,7 @@ public class HitscanEffect : MonoBehaviour shape.position = Vector3.forward * (length / 2); shape.scale = Vector3.one * (length / 2); } - else + if(!hitFound) { Line.SetPosition(1, Vector3.forward * Range); var emission = LineEffect.emission; diff --git a/Assets/Scripts/Gameplay/Weapons/Laser.cs b/Assets/Scripts/Gameplay/Weapons/Laser.cs index b7c6338f7..9c34d7c09 100644 --- a/Assets/Scripts/Gameplay/Weapons/Laser.cs +++ b/Assets/Scripts/Gameplay/Weapons/Laser.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using static Unity.Mathematics.math; public class Laser : MonoBehaviour { @@ -35,20 +36,34 @@ public class Laser : MonoBehaviour } LineRenderer.SetPosition(0, transform.position); - RaycastHit hit; - if (Physics.Raycast(new Ray(transform.position, transform.forward), out hit, Range, 1)) + bool hitFound = false; + foreach (var hit in Physics.RaycastAll(new Ray(transform.position, transform.forward), Range, 1 | (1 << 17))) { + var shield = hit.collider.GetComponent(); + if (shield) + { + if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue; + if (shield.Entity != SourceEntity) + { + shield.Entity.Shield.TakeHit(DamageType, Damage); + shield.ShowHit(hit.point, sqrt(Damage)); + LineRenderer.SetPosition(1, hit.point); + hitFound = true; + } + } var hull = hit.collider.GetComponent(); if (hull) { if (hull.Entity != SourceEntity) { hull.SendHit(Damage * (Time.deltaTime / Duration), Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward); + transform.position = hit.point; + LineRenderer.SetPosition(1, hit.point); + hitFound = true; } } - LineRenderer.SetPosition(1, hit.point); } - else + if(!hitFound) LineRenderer.SetPosition(1, transform.position + transform.forward * Range); LineRenderer.widthMultiplier = IntensityCurve.Evaluate(lerp); diff --git a/Assets/Scripts/Gameplay/Weapons/Lightning.cs b/Assets/Scripts/Gameplay/Weapons/Lightning.cs index 85270fd4b..cb63b3a86 100644 --- a/Assets/Scripts/Gameplay/Weapons/Lightning.cs +++ b/Assets/Scripts/Gameplay/Weapons/Lightning.cs @@ -6,6 +6,7 @@ using Unity.Mathematics; using static Unity.Mathematics.math; using static Unity.Mathematics.noise; using Random = UnityEngine.Random; +using static Unity.Mathematics.math; public class Lightning : MonoBehaviour { @@ -31,11 +32,21 @@ public class Lightning : MonoBehaviour _colliderHit = false; LightningCompute.OnLeaderComplete = null; LightningCompute.FixedEndpoint = false; - var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1); + var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1 | (1 << 17)); foreach (var hit in hits) { + var shield = hit.collider.GetComponent(); + if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) + { + if (shield.Entity == Source.Entity) continue; + LightningCompute.OnLeaderComplete = () => + { + shield.Entity.Shield.TakeHit(DamageType, Damage); + shield.ShowHit(hit.point, sqrt(Damage)); + }; + } var hull = hit.collider.GetComponent(); - if (hull) + if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active && hull.Entity.Shield.CanTakeHit(DamageType, Damage))) { if (hull.Entity == Source.Entity) continue; LightningCompute.OnLeaderComplete = () => diff --git a/Assets/Scripts/Gameplay/Weapons/Mine.cs b/Assets/Scripts/Gameplay/Weapons/Mine.cs index 6740bc777..cad1114d3 100644 --- a/Assets/Scripts/Gameplay/Weapons/Mine.cs +++ b/Assets/Scripts/Gameplay/Weapons/Mine.cs @@ -106,10 +106,16 @@ public class Mine : MonoBehaviour Time.time - _startTime > Lifetime || _blastCountdown && Time.time > _blastTime) { - foreach (var collider in Physics.OverlapSphere(t.position, BlastRange, 1)) + foreach (var collider in Physics.OverlapSphere(t.position, BlastRange, 1 | (1 << 17))) { + var shield = collider.GetComponent(); + if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) + { + shield.Entity.Shield.TakeHit(DamageType, Damage); + shield.ShowHit(t.position, sqrt(Damage)); + } var hull = collider.GetComponent(); - if (hull) + if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active && hull.Entity.Shield.CanTakeHit(DamageType, Damage))) { hull.SendSplash(Damage, DamageType, Source.Entity, (collider.transform.position - t.position).normalized); } diff --git a/Assets/Scripts/Gameplay/Weapons/Projectile.cs b/Assets/Scripts/Gameplay/Weapons/Projectile.cs index aa97c91c7..f5c4f7400 100644 --- a/Assets/Scripts/Gameplay/Weapons/Projectile.cs +++ b/Assets/Scripts/Gameplay/Weapons/Projectile.cs @@ -55,10 +55,20 @@ public class Projectile : MonoBehaviour var forward = Velocity.normalized; t.forward = forward; var ray = new Ray(position, Velocity); - if (Physics.Raycast(ray, out var hit, Velocity.magnitude * Time.deltaTime, 1)) + foreach (var hit in Physics.RaycastAll(ray, Velocity.magnitude * Time.deltaTime, 1 | (1 << 17))) { + var shield = hit.collider.GetComponent(); var hull = hit.collider.GetComponent(); - if (hull) + if (shield) + { + if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue; + if (shield.Entity != SourceEntity) + { + shield.Entity.Shield.TakeHit(DamageType, Damage*DirectHitDamageMultiplier); + shield.ShowHit(hit.point, sqrt(Damage * DirectHitDamageMultiplier)); + } + } + else if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active && hull.Entity.Shield.CanTakeHit(DamageType, Damage))) { if (hull.Entity != SourceEntity) { @@ -67,7 +77,7 @@ public class Projectile : MonoBehaviour StartCoroutine(Kill()); } } - else// if (hit.transform.gameObject.layer == 1) + else { StartCoroutine(Kill()); return; diff --git a/Assets/Scripts/ServerShared/Behaviors/Shield.cs b/Assets/Scripts/ServerShared/Behaviors/Shield.cs index 4ce0a41da..ca7207e5d 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Shield.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Shield.cs @@ -13,8 +13,8 @@ public class ShieldData : BehaviorData [InspectableField, JsonProperty("efficiency"), Key(1), RuntimeInspectable] public PerformanceStat Efficiency = new PerformanceStat(); - [InspectableField, JsonProperty("shielding"), Key(2), RuntimeInspectable] - public PerformanceStat Shielding = new PerformanceStat(); + [InspectableField, JsonProperty("energy"), Key(2), RuntimeInspectable] + public PerformanceStat EnergyUsage = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) { @@ -27,6 +27,9 @@ public class Shield : IBehavior public Entity Entity { get; } public EquippedItem Item { get; } public ItemManager Context { get; } + + public float Efficiency { get; private set; } + public float EnergyUsage { get; private set; } public BehaviorData Data => _data; @@ -38,12 +41,23 @@ public class Shield : IBehavior _data = data; Entity = entity; Item = item; - - // TODO: Detect hits on Ship, keep a list of callbacks that modify the hit by reference } public bool Execute(float delta) { + Efficiency = Context.Evaluate(_data.Efficiency, Item); + EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item); return true; } + + public bool CanTakeHit(DamageType type, float damage) + { + return Entity.CanConsumeEnergy(damage * EnergyUsage); + } + + public void TakeHit(DamageType type, float damage) + { + Entity.TryConsumeEnergy(damage * EnergyUsage); + Item.AddHeat(damage / Efficiency); + } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 0194a0c70..e6bcba3ef 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -96,13 +96,11 @@ public abstract class Entity get => _weapons; } + public Shield Shield { get; private set; } + public float TargetRange { get; private set; } public float MaxTemp { get; private set; } public float MinTemp { get; private set; } - public bool ShieldEnabled // TODO: MAKE SHIELDS - { - get => true; - } public ItemManager ItemManager { get; } public int AssignedPopulation => PopulationAssignments.Sum(pa => pa.AssignedPopulation); public float Mass { get; private set; } @@ -349,12 +347,14 @@ public abstract class Entity { if (b is Weapon weapon) _weapons.Remove(weapon); - if(b is Capacitor capacitor) + if (b is Capacitor capacitor) _capacitors.Remove(capacitor); - if(b is Reactor reactor) + if (b is Reactor reactor) _reactors.Remove(reactor); - if(b is Radiator heatsink) + if (b is Radiator heatsink) _heatsinks.Remove(heatsink); + if (b is Shield) + Shield = null; } return item.EquippableItem; @@ -531,6 +531,8 @@ public abstract class Entity _reactors.Add(reactor); if(b is Radiator heatsink) _heatsinks.Add(heatsink); + if (b is Shield shield) + Shield = shield; } equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem); @@ -584,6 +586,13 @@ public abstract class Entity return true; } + public bool CanConsumeEnergy(float energy) + { + var capEnergy = _capacitors.Sum(cap => cap.Charge); + int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online); + return capEnergy > energy || onlineReactors > 0; + } + public bool TryConsumeEnergy(float energy) { if (energy < .01f) return true; @@ -860,6 +869,11 @@ public class EquippedItem public Shape InsetShape { get; } public int SortPosition; + + public bool Active + { + get => _online && Enabled; + } public bool Online { @@ -937,7 +951,7 @@ public class EquippedItem if (!previouslyOnline && _online) OnOnline?.Invoke(); if (previouslyOnline && !_online) OnOffline?.Invoke(); - if (Enabled && _online) + if (Active) { foreach (var group in BehaviorGroups.Values) { diff --git a/Assets/Scripts/UI/SchematicDisplay.cs b/Assets/Scripts/UI/SchematicDisplay.cs index 1e819e905..221eeef09 100644 --- a/Assets/Scripts/UI/SchematicDisplay.cs +++ b/Assets/Scripts/UI/SchematicDisplay.cs @@ -18,6 +18,7 @@ public class SchematicDisplay : MonoBehaviour public Color HeaderElementEnabledColor; public Color HeaderElementDisabledColor; + public GameObject ShieldIcon; public Image HeatsinkBackground; public TextMeshProUGUI EnergyLabel; @@ -215,6 +216,7 @@ public class SchematicDisplay : MonoBehaviour { if (!_enemy) { + ShieldIcon.SetActive(_entity.Shield!=null && _entity.Shield.Item.Active); if (_radiators.Length == 1) RadiatorTemperatureLabel.text = $"{((int)(_radiators[0].Temperature - 273.15f)).ToString()}°C"; else if (_radiators.Length > 1) diff --git a/Assets/ShieldManager.cs b/Assets/ShieldManager.cs index 962f7c5b5..68ff6105f 100644 --- a/Assets/ShieldManager.cs +++ b/Assets/ShieldManager.cs @@ -30,7 +30,7 @@ public class ShieldManager : MonoBehaviour var v1np = PostCollisionVelocity(v1n, Entity.Mass, v2n, otherShield.Entity.Mass); Entity.Velocity = tangent * v1t + normal * v1np; - if(Entity.ShieldEnabled) ShowHit(contact.point, CollisionHitDuration); + if(Entity.Shield != null && Entity.Shield.Item.Active) ShowHit(contact.point, CollisionHitDuration); } private float PostCollisionVelocity(float v1, float m1, float v2, float m2) @@ -41,7 +41,7 @@ public class ShieldManager : MonoBehaviour public void ShowHit(Vector3 point, float duration) { var shield = ShieldPrototype.Instantiate(); - shield.Direction = shield.transform.InverseTransformPoint(point); + shield.Direction = normalize(shield.transform.InverseTransformPoint(point)); shield.Duration = duration; } } diff --git a/GameData/AetherDB.msgpack b/GameData/AetherDB.msgpack index d9f22ffe9..dd15db465 100644 Binary files a/GameData/AetherDB.msgpack and b/GameData/AetherDB.msgpack differ