diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 168f4635..e54db230 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -38,7 +38,6 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -104,7 +103,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +116,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -155,7 +154,6 @@ RectTransform: m_Children: - {fileID: 144807540} m_Father: {fileID: 940484821} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 1} m_AnchorMax: {x: 0.5, y: 1} @@ -232,7 +230,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 940484821} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1} @@ -449,7 +446,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 22985194} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -488,7 +484,6 @@ RectTransform: m_Children: - {fileID: 780528419} m_Father: {fileID: 1260659848} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} @@ -653,13 +648,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 363944622} + serializedVersion: 2 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_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &459978225 GameObject: @@ -694,7 +689,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1473202746} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0} @@ -819,9 +813,17 @@ Camera: m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 + m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 m_SensorSize: {x: 36, y: 24} m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 m_NormalizedViewPortRect: serializedVersion: 2 x: 0 @@ -855,13 +857,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 519420028} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &522226879 GameObject: @@ -897,7 +899,6 @@ RectTransform: - {fileID: 1242843363} - {fileID: 1654983923} m_Father: {fileID: 940484821} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -999,7 +1000,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 228018905} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -1135,7 +1135,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2089224442} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -1344,13 +1343,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 927446003} + serializedVersion: 2 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_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &940484820 GameObject: @@ -1388,7 +1387,6 @@ RectTransform: - {fileID: 1222372627} - {fileID: 522226880} m_Father: {fileID: 1182275442} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -1453,6 +1451,7 @@ MonoBehaviour: EnemyOverlayColor: {r: 1, g: 0, b: 0, a: 0.23529412} ActionSelectionOverlayColor: {r: 0, g: 0, b: 1, a: 0.23529412} backgroundImage: {fileID: 1331666487} + undoButton: {fileID: 101671528} --- !u!1 &988327833 GameObject: m_ObjectHideFlags: 0 @@ -1485,7 +1484,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2089224442} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -1651,7 +1649,9 @@ Canvas: m_OverrideSorting: 0 m_OverridePixelPerfect: 0 m_SortingBucketNormalizedSize: 0 + m_VertexColorAlwaysGammaSpace: 0 m_AdditionalShaderChannelsFlag: 25 + m_UpdateRectTransformForStandalone: 0 m_SortingLayerID: 0 m_SortingOrder: 0 m_TargetDisplay: 0 @@ -1672,7 +1672,6 @@ RectTransform: - {fileID: 1473202746} - {fileID: 2089224442} m_Father: {fileID: 0} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -1728,7 +1727,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 940484821} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0} m_AnchorMax: {x: 0.5, y: 0} @@ -1864,7 +1862,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 522226880} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -1963,7 +1960,6 @@ RectTransform: - {fileID: 228018905} - {fileID: 1861826649} m_Father: {fileID: 1182275442} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -2052,7 +2048,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1382465449} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -2173,7 +2168,9 @@ Canvas: m_OverrideSorting: 0 m_OverridePixelPerfect: 0 m_SortingBucketNormalizedSize: 0 + m_VertexColorAlwaysGammaSpace: 0 m_AdditionalShaderChannelsFlag: 0 + m_UpdateRectTransformForStandalone: 0 m_SortingLayerID: 0 m_SortingOrder: 0 m_TargetDisplay: 0 @@ -2191,7 +2188,6 @@ RectTransform: m_Children: - {fileID: 1331666486} m_Father: {fileID: 0} - m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -2242,13 +2238,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1409757739} + serializedVersion: 2 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_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1473202745 GameObject: @@ -2283,7 +2279,6 @@ RectTransform: m_Children: - {fileID: 459978226} m_Father: {fileID: 1182275442} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -2433,7 +2428,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 522226880} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -2471,7 +2465,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2089224442} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} @@ -2608,7 +2601,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1260659848} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -2728,7 +2720,6 @@ RectTransform: - {fileID: 988327834} - {fileID: 799045266} m_Father: {fileID: 1182275442} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -2847,11 +2838,22 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2089575972} + serializedVersion: 2 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_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: + - {fileID: 519420032} + - {fileID: 1409757741} + - {fileID: 1182275442} + - {fileID: 363944624} + - {fileID: 927446005} + - {fileID: 2089575975} + - {fileID: 1382465449} diff --git a/Assets/Scripts/Action/ActionService.cs b/Assets/Scripts/Action/ActionService.cs index 957c65c0..3e5c2f04 100644 --- a/Assets/Scripts/Action/ActionService.cs +++ b/Assets/Scripts/Action/ActionService.cs @@ -5,23 +5,23 @@ namespace Command.Actions { public class ActionService { - private Dictionary actions; + private Dictionary actions; public ActionService() => CreateActions(); private void CreateActions() { - actions = new Dictionary(); - actions.Add(ActionType.Attack, new AttackAction()); - actions.Add(ActionType.Heal, new HealAction()); - actions.Add(ActionType.AttackStance, new AttackStanceAction()); - actions.Add(ActionType.Cleanse, new CleanseAction()); - actions.Add(ActionType.Meditate, new MeditateAction()); - actions.Add(ActionType.BerserkAttack, new BerserkAttackAction()); - actions.Add(ActionType.ThirdEye, new ThirdEyeAction()); + actions = new Dictionary(); + actions.Add(CommandType.Attack, new AttackAction()); + actions.Add(CommandType.Heal, new HealAction()); + actions.Add(CommandType.AttackStance, new AttackStanceAction()); + actions.Add(CommandType.Cleanse, new CleanseAction()); + actions.Add(CommandType.Meditate, new MeditateAction()); + actions.Add(CommandType.BerserkAttack, new BerserkAttackAction()); + actions.Add(CommandType.ThirdEye, new ThirdEyeAction()); } - public IAction GetActionByType(ActionType type) + public IAction GetActionByType(CommandType type) { if (actions.ContainsKey(type)) return actions[type]; @@ -29,6 +29,6 @@ public IAction GetActionByType(ActionType type) throw new System.Exception($"No Action found for the type {type} in the dictionary"); } - public TargetType GetTargetTypeForAction(ActionType actionType) => actions[actionType].TargetType; + public TargetType GetTargetTypeForAction(CommandType actionType) => actions[actionType].TargetType; } } \ No newline at end of file diff --git a/Assets/Scripts/Action/Actions/AttackAction.cs b/Assets/Scripts/Action/Actions/AttackAction.cs index 75632f04..fe119884 100644 --- a/Assets/Scripts/Action/Actions/AttackAction.cs +++ b/Assets/Scripts/Action/Actions/AttackAction.cs @@ -9,33 +9,33 @@ public class AttackAction : IAction { private UnitController actorUnit; private UnitController targetUnit; + private bool isSuccessful; public TargetType TargetType => TargetType.Enemy; - public void PerformAction(UnitController actorUnit, UnitController targetUnit) + public void PerformAction(UnitController actorUnit, UnitController targetUnit, bool isSuccessful) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.isSuccessful = isSuccessful; - actorUnit.PlayBattleAnimation(ActionType.Attack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.Attack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } - public void OnActionAnimationCompleted() + public void OnActionAnimationCompleted() { PlayAttackSound(); - if (IsSuccessful()) + if (isSuccessful) targetUnit.TakeDamage(actorUnit.CurrentPower); else GameService.Instance.UIService.ActionMissed(); } - public bool IsSuccessful() => true; - public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition(); private void PlayAttackSound() { - switch(actorUnit.UnitType) + switch (actorUnit.UnitType) { case UnitType.WIZARD: GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.MAGIC_BALL); diff --git a/Assets/Scripts/Action/Actions/AttackStanceAction.cs b/Assets/Scripts/Action/Actions/AttackStanceAction.cs index 9fc46d34..76d5fb4e 100644 --- a/Assets/Scripts/Action/Actions/AttackStanceAction.cs +++ b/Assets/Scripts/Action/Actions/AttackStanceAction.cs @@ -9,14 +9,16 @@ public class AttackStanceAction : IAction { private UnitController actorUnit; private UnitController targetUnit; + private bool isSuccessful; TargetType IAction.TargetType { get => TargetType.Self; } - public void PerformAction(UnitController actorUnit, UnitController targetUnit) + public void PerformAction(UnitController actorUnit, UnitController targetUnit , bool isSuccessful) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.isSuccessful = isSuccessful; - actorUnit.PlayBattleAnimation(ActionType.AttackStance, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.AttackStance, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() diff --git a/Assets/Scripts/Action/Actions/BerserkAttackAction.cs b/Assets/Scripts/Action/Actions/BerserkAttackAction.cs index 42ce5acd..2e672204 100644 --- a/Assets/Scripts/Action/Actions/BerserkAttackAction.cs +++ b/Assets/Scripts/Action/Actions/BerserkAttackAction.cs @@ -10,14 +10,16 @@ public class BerserkAttackAction : IAction private const float hitChance = 0.66f; private UnitController actorUnit; private UnitController targetUnit; + private bool isSuccessful; public TargetType TargetType => TargetType.Enemy; - public void PerformAction(UnitController actorUnit, UnitController targetUnit) + public void PerformAction(UnitController actorUnit, UnitController targetUnit , bool isSuccessful) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.isSuccessful = isSuccessful; - actorUnit.PlayBattleAnimation(ActionType.BerserkAttack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.BerserkAttack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() diff --git a/Assets/Scripts/Action/Actions/CleanseAction.cs b/Assets/Scripts/Action/Actions/CleanseAction.cs index 469071ea..05ff68fd 100644 --- a/Assets/Scripts/Action/Actions/CleanseAction.cs +++ b/Assets/Scripts/Action/Actions/CleanseAction.cs @@ -10,14 +10,16 @@ public class CleanseAction : IAction private const float hitChance = 0.2f; private UnitController actorUnit; private UnitController targetUnit; + private bool isSuccessful; public TargetType TargetType => TargetType.Enemy; - public void PerformAction(UnitController actorUnit, UnitController targetUnit) + public void PerformAction(UnitController actorUnit, UnitController targetUnit , bool isSuccessfull) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.isSuccessful = isSuccessfull; - actorUnit.PlayBattleAnimation(ActionType.Cleanse, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.Cleanse, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() diff --git a/Assets/Scripts/Action/Actions/HealAction.cs b/Assets/Scripts/Action/Actions/HealAction.cs index d05b6d47..9d934140 100644 --- a/Assets/Scripts/Action/Actions/HealAction.cs +++ b/Assets/Scripts/Action/Actions/HealAction.cs @@ -9,14 +9,16 @@ public class HealAction : IAction { private UnitController actorUnit; private UnitController targetUnit; + private bool isSuccessful; public TargetType TargetType => TargetType.Friendly; - public void PerformAction(UnitController actorUnit, UnitController targetUnit) + public void PerformAction(UnitController actorUnit, UnitController targetUnit, bool isSuccessfull) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.isSuccessful = isSuccessfull; - actorUnit.PlayBattleAnimation(ActionType.Heal, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.Heal, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() diff --git a/Assets/Scripts/Action/Actions/MeditateAction.cs b/Assets/Scripts/Action/Actions/MeditateAction.cs index 869e159b..737c213b 100644 --- a/Assets/Scripts/Action/Actions/MeditateAction.cs +++ b/Assets/Scripts/Action/Actions/MeditateAction.cs @@ -9,14 +9,16 @@ public class MeditateAction : IAction { private UnitController actorUnit; private UnitController targetUnit; + private bool isSuccessful; public TargetType TargetType => TargetType.Self; - public void PerformAction(UnitController actorUnit, UnitController targetUnit) + public void PerformAction(UnitController actorUnit, UnitController targetUnit , bool isSuccessfull) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.isSuccessful = isSuccessfull; - actorUnit.PlayBattleAnimation(ActionType.Meditate, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.Meditate, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() diff --git a/Assets/Scripts/Action/Actions/ThirdEyeAction.cs b/Assets/Scripts/Action/Actions/ThirdEyeAction.cs index 8a24ba01..1ba92fdc 100644 --- a/Assets/Scripts/Action/Actions/ThirdEyeAction.cs +++ b/Assets/Scripts/Action/Actions/ThirdEyeAction.cs @@ -9,14 +9,16 @@ public class ThirdEyeAction : IAction { private UnitController actorUnit; private UnitController targetUnit; + private bool isSuccessful; public TargetType TargetType => TargetType.Self; - public void PerformAction(UnitController actorUnit, UnitController targetUnit) + public void PerformAction(UnitController actorUnit, UnitController targetUnit , bool isSuccessfull) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.isSuccessful = isSuccessfull; - actorUnit.PlayBattleAnimation(ActionType.BerserkAttack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.BerserkAttack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() diff --git a/Assets/Scripts/Action/IAction.cs b/Assets/Scripts/Action/IAction.cs index 610560d8..a73327e7 100644 --- a/Assets/Scripts/Action/IAction.cs +++ b/Assets/Scripts/Action/IAction.cs @@ -11,9 +11,7 @@ public interface IAction { public TargetType TargetType { get; } - public void PerformAction(UnitController actorUnit, UnitController targetUnit); - - public bool IsSuccessful(); + public void PerformAction(UnitController actorUnit, UnitController targetUnit, bool isSuccessful); public Vector3 CalculateMovePosition(UnitController targetUnit); } diff --git a/Assets/Scripts/Commands.meta b/Assets/Scripts/Commands.meta new file mode 100644 index 00000000..da56c75e --- /dev/null +++ b/Assets/Scripts/Commands.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cce1ef398ad5252418bf0eddd457e7b1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Abstract Commands.meta b/Assets/Scripts/Commands/Abstract Commands.meta new file mode 100644 index 00000000..2b8ba38f --- /dev/null +++ b/Assets/Scripts/Commands/Abstract Commands.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bee3ef792d25cbb45b170d11ea513c3c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Abstract Commands/CommandData.cs b/Assets/Scripts/Commands/Abstract Commands/CommandData.cs new file mode 100644 index 00000000..b2d4bf57 --- /dev/null +++ b/Assets/Scripts/Commands/Abstract Commands/CommandData.cs @@ -0,0 +1,15 @@ +public struct CommandData +{ + public int ActorUnitID; + public int TargetUnitID; + public int ActorPlayerID; + public int TargetPlayerID; + + public CommandData(int ActorUnitID, int TargetUnitID, int ActorPlayerID, int TargetPlayerID) + { + this.ActorUnitID = ActorUnitID; + this.TargetUnitID = TargetUnitID; + this.ActorPlayerID = ActorPlayerID; + this.TargetPlayerID = TargetPlayerID; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Action/ActionType.cs.meta b/Assets/Scripts/Commands/Abstract Commands/CommandData.cs.meta similarity index 83% rename from Assets/Scripts/Action/ActionType.cs.meta rename to Assets/Scripts/Commands/Abstract Commands/CommandData.cs.meta index 0c25c443..42e80613 100644 --- a/Assets/Scripts/Action/ActionType.cs.meta +++ b/Assets/Scripts/Commands/Abstract Commands/CommandData.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 24ec1f4456a85984898bc624ebcb3f7c +guid: 7a7192f7c17a8c1438498bb68a90a31f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Commands/Abstract Commands/ICommand.cs b/Assets/Scripts/Commands/Abstract Commands/ICommand.cs new file mode 100644 index 00000000..488452c1 --- /dev/null +++ b/Assets/Scripts/Commands/Abstract Commands/ICommand.cs @@ -0,0 +1,8 @@ +namespace Command.Commands +{ + public interface ICommand + { + public void Execute(); + public void Undo(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Abstract Commands/ICommand.cs.meta b/Assets/Scripts/Commands/Abstract Commands/ICommand.cs.meta new file mode 100644 index 00000000..05a1e5aa --- /dev/null +++ b/Assets/Scripts/Commands/Abstract Commands/ICommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 511a7d2f3d54cab44923631c2bb8a0b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Abstract Commands/IUnitCommand.cs b/Assets/Scripts/Commands/Abstract Commands/IUnitCommand.cs new file mode 100644 index 00000000..d0d9632c --- /dev/null +++ b/Assets/Scripts/Commands/Abstract Commands/IUnitCommand.cs @@ -0,0 +1,21 @@ +using Command.Player; + +namespace Command.Commands +{ + public abstract class UnitCommand : ICommand + { + public CommandData commandData; + + protected UnitController actorUnit; + protected UnitController targetUnit; + + public abstract void Execute(); + public abstract void Undo(); + + public abstract bool WillHitTarget(); + + public void SetActorUnit(UnitController actorUnit) => this.actorUnit = actorUnit; + + public void SetTargetUnit(UnitController targetUnit) => this.targetUnit = targetUnit; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Abstract Commands/IUnitCommand.cs.meta b/Assets/Scripts/Commands/Abstract Commands/IUnitCommand.cs.meta new file mode 100644 index 00000000..1e72800e --- /dev/null +++ b/Assets/Scripts/Commands/Abstract Commands/IUnitCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bcd3ec49dc4b374b9341334488055d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/CommandInvoker.cs b/Assets/Scripts/Commands/CommandInvoker.cs new file mode 100644 index 00000000..befc7d0c --- /dev/null +++ b/Assets/Scripts/Commands/CommandInvoker.cs @@ -0,0 +1,30 @@ +using Command.Main; +using System.Collections.Generic; + +namespace Command.Commands +{ + public class CommandInvoker + { + private Stack commandRegistry = new Stack(); + + public void ProcessCommand(ICommand commandToProcess) + { + ExecuteCommand(commandToProcess); + RegisterCommand(commandToProcess); + } + + public void Undo() + { + if (!RegistryEmpty() && CommandBelongsToActivePlayer()) + commandRegistry.Pop().Undo(); + } + + public void ExecuteCommand(ICommand commandToExecute) => commandToExecute.Execute(); + + public void RegisterCommand(ICommand commandToRegister) => commandRegistry.Push(commandToRegister); + + private bool RegistryEmpty() => commandRegistry.Count == 0; + private bool CommandBelongsToActivePlayer() => (commandRegistry.Peek() as UnitCommand).commandData.ActorPlayerID == GameService.Instance.PlayerService.ActivePlayerID; + + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/CommandInvoker.cs.meta b/Assets/Scripts/Commands/CommandInvoker.cs.meta new file mode 100644 index 00000000..7d4ca6ca --- /dev/null +++ b/Assets/Scripts/Commands/CommandInvoker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 91f9529200f0f2547afad4ee613055d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Action/ActionType.cs b/Assets/Scripts/Commands/CommandType.cs similarity index 73% rename from Assets/Scripts/Action/ActionType.cs rename to Assets/Scripts/Commands/CommandType.cs index f6c14302..f6dd2316 100644 --- a/Assets/Scripts/Action/ActionType.cs +++ b/Assets/Scripts/Commands/CommandType.cs @@ -1,6 +1,6 @@ -namespace Command.Actions -{ - public enum ActionType + + + public enum CommandType { None, Attack, @@ -11,4 +11,3 @@ public enum ActionType BerserkAttack, ThirdEye } -} \ No newline at end of file diff --git a/Assets/Scripts/Commands/CommandType.cs.meta b/Assets/Scripts/Commands/CommandType.cs.meta new file mode 100644 index 00000000..cc0ce4a3 --- /dev/null +++ b/Assets/Scripts/Commands/CommandType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0f60400cbc1a69044a275f240dd0a050 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command.meta b/Assets/Scripts/Commands/Concrete Command.meta new file mode 100644 index 00000000..ba0c928c --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dc8b07142943a8044987a666beefdd64 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command/AttackCommand.cs b/Assets/Scripts/Commands/Concrete Command/AttackCommand.cs new file mode 100644 index 00000000..ddb31c17 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/AttackCommand.cs @@ -0,0 +1,31 @@ +using Command.Main; + +namespace Command.Commands +{ + public class AttackCommand : UnitCommand + { + private bool willHitTarget; + + public AttackCommand(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override bool WillHitTarget() => true; + + public override void Execute() => GameService.Instance.ActionService.GetActionByType(CommandType.Attack).PerformAction(actorUnit, targetUnit, willHitTarget); + + public override void Undo() + { + if (willHitTarget) + { + if (!targetUnit.IsAlive()) + targetUnit.Revive(); + + targetUnit.RestoreHealth(actorUnit.CurrentPower); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Concrete Command/AttackCommand.cs.meta b/Assets/Scripts/Commands/Concrete Command/AttackCommand.cs.meta new file mode 100644 index 00000000..fbfc2400 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/AttackCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 454de5a0bdbb21644ad3faf3b75e9179 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command/AttackStance.cs b/Assets/Scripts/Commands/Concrete Command/AttackStance.cs new file mode 100644 index 00000000..93e31a70 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/AttackStance.cs @@ -0,0 +1,26 @@ +using Command.Main; + +namespace Command.Commands +{ + public class AttackStanceCommand : UnitCommand + { + private bool willHitTarget; + + public AttackStanceCommand(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + public override void Undo() + { + if (willHitTarget) + { + targetUnit.CurrentPower -= (int)(targetUnit.CurrentPower * 0.2f); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + public override void Execute() => GameService.Instance.ActionService.GetActionByType(CommandType.AttackStance).PerformAction(actorUnit, targetUnit, willHitTarget); + + public override bool WillHitTarget() => true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Concrete Command/AttackStance.cs.meta b/Assets/Scripts/Commands/Concrete Command/AttackStance.cs.meta new file mode 100644 index 00000000..4aecfa8b --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/AttackStance.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4b7e9825b6a84d844b0cf9b24b4f9e07 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command/BerserkAttackCommand.cs b/Assets/Scripts/Commands/Concrete Command/BerserkAttackCommand.cs new file mode 100644 index 00000000..7ebbd4f2 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/BerserkAttackCommand.cs @@ -0,0 +1,39 @@ +using Command.Main; +using UnityEngine; +namespace Command.Commands +{ + public class BerserkAttackCommand : UnitCommand + { + private bool willHitTarget; + private const float hitChance = 0.66f; + + public BerserkAttackCommand(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override void Undo() + { + if (willHitTarget) + { + if (!targetUnit.IsAlive()) + targetUnit.Revive(); + + targetUnit.RestoreHealth(actorUnit.CurrentPower * 2); + } + else + { + if (!actorUnit.IsAlive()) + actorUnit.Revive(); + + actorUnit.RestoreHealth(actorUnit.CurrentPower * 2); + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + + public override void Execute() => GameService.Instance.ActionService.GetActionByType(CommandType.BerserkAttack).PerformAction(actorUnit, targetUnit, willHitTarget); + + public override bool WillHitTarget() => Random.Range(0f, 1f) < hitChance; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Concrete Command/BerserkAttackCommand.cs.meta b/Assets/Scripts/Commands/Concrete Command/BerserkAttackCommand.cs.meta new file mode 100644 index 00000000..c0a9cf82 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/BerserkAttackCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8286922a883e6714e997837d21eccb32 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command/ClenseCommand.cs b/Assets/Scripts/Commands/Concrete Command/ClenseCommand.cs new file mode 100644 index 00000000..956389a3 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/ClenseCommand.cs @@ -0,0 +1,30 @@ +using Command.Main; +using UnityEngine; + +namespace Command.Commands +{ + public class CleanseCommand : UnitCommand + { + private bool willHitTarget; + private const float hitChance = 0.2f; + private int previousPower; + + public CleanseCommand(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override void Execute() => GameService.Instance.ActionService.GetActionByType(CommandType.Cleanse).PerformAction(actorUnit, targetUnit, willHitTarget); + + public override bool WillHitTarget() => Random.Range(0f, 1f) < hitChance; + + public override void Undo() + { + if (willHitTarget) + targetUnit.CurrentPower = previousPower; + + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Concrete Command/ClenseCommand.cs.meta b/Assets/Scripts/Commands/Concrete Command/ClenseCommand.cs.meta new file mode 100644 index 00000000..67bde09d --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/ClenseCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ca8ab0c4c4d32d141b632413ae9dcd86 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command/HealCommand.cs b/Assets/Scripts/Commands/Concrete Command/HealCommand.cs new file mode 100644 index 00000000..4cdec83e --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/HealCommand.cs @@ -0,0 +1,28 @@ +using Command.Main; + +namespace Command.Commands +{ + public class HealCommand : UnitCommand + { + private bool willHitTarget; + + public HealCommand(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override void Undo() + { + if (willHitTarget) + { + targetUnit.TakeDamage(actorUnit.CurrentPower); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + + public override void Execute() => GameService.Instance.ActionService.GetActionByType(CommandType.Heal).PerformAction(actorUnit, targetUnit, willHitTarget); + + public override bool WillHitTarget() => true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Concrete Command/HealCommand.cs.meta b/Assets/Scripts/Commands/Concrete Command/HealCommand.cs.meta new file mode 100644 index 00000000..7bf3cbb9 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/HealCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c98c70b0879d4824691e0a2fb89bef55 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command/MeditateCommand.cs b/Assets/Scripts/Commands/Concrete Command/MeditateCommand.cs new file mode 100644 index 00000000..6c6a7999 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/MeditateCommand.cs @@ -0,0 +1,32 @@ +using Command.Main; + +namespace Command.Commands +{ + public class MeditateCommand : UnitCommand + { + private bool willHitTarget; + private int previousMaxHealth; + + public MeditateCommand(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override void Undo() + { + if (willHitTarget) + { + var healthToReduce = targetUnit.CurrentMaxHealth - previousMaxHealth; + targetUnit.CurrentMaxHealth = previousMaxHealth; + targetUnit.TakeDamage(healthToReduce); + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + + + public override void Execute() => GameService.Instance.ActionService.GetActionByType(CommandType.Meditate).PerformAction(actorUnit, targetUnit, willHitTarget); + + public override bool WillHitTarget() => true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Concrete Command/MeditateCommand.cs.meta b/Assets/Scripts/Commands/Concrete Command/MeditateCommand.cs.meta new file mode 100644 index 00000000..368d7eb8 --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/MeditateCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ffb6a8430d3ca064189d9fe2307674ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/Concrete Command/ThirdEyeCommand.cs b/Assets/Scripts/Commands/Concrete Command/ThirdEyeCommand.cs new file mode 100644 index 00000000..0a51a81a --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/ThirdEyeCommand.cs @@ -0,0 +1,31 @@ +using Command.Main; + +namespace Command.Commands +{ + public class ThirdEyeCommand : UnitCommand + { + private bool willHitTarget; + private int previousHealth; + + public ThirdEyeCommand(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override void Execute() => GameService.Instance.ActionService.GetActionByType(CommandType.ThirdEye).PerformAction(actorUnit, targetUnit, willHitTarget); + + public override bool WillHitTarget() => true; + + public override void Undo() + { + if (!targetUnit.IsAlive()) + targetUnit.Revive(); + + int healthToRestore = (int)(previousHealth * 0.25f); + targetUnit.RestoreHealth(healthToRestore); + targetUnit.CurrentPower -= healthToRestore; + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Commands/Concrete Command/ThirdEyeCommand.cs.meta b/Assets/Scripts/Commands/Concrete Command/ThirdEyeCommand.cs.meta new file mode 100644 index 00000000..5801096c --- /dev/null +++ b/Assets/Scripts/Commands/Concrete Command/ThirdEyeCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27dc6f5f121b4064a97b693cf3d4e6dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Events/EventService.cs b/Assets/Scripts/Events/EventService.cs index 59b664c2..5c31f24f 100644 --- a/Assets/Scripts/Events/EventService.cs +++ b/Assets/Scripts/Events/EventService.cs @@ -11,12 +11,12 @@ namespace Command.Events public class EventService { public GameEventController OnBattleSelected { get; private set; } - public GameEventController OnActionSelected { get; private set; } + public GameEventController OnActionSelected { get; private set; } public EventService() { OnBattleSelected = new GameEventController(); - OnActionSelected = new GameEventController(); + OnActionSelected = new GameEventController(); } } } \ No newline at end of file diff --git a/Assets/Scripts/Input/InputService.cs b/Assets/Scripts/Input/InputService.cs index de088222..eba7a1cd 100644 --- a/Assets/Scripts/Input/InputService.cs +++ b/Assets/Scripts/Input/InputService.cs @@ -1,6 +1,7 @@ using Command.Main; using Command.Player; using Command.Actions; +using Command.Commands; namespace Command.Input { @@ -9,7 +10,7 @@ public class InputService private MouseInputHandler mouseInputHandler; private InputState currentState; - private ActionType selectedActionType; + private CommandType selectedCommandType; private TargetType targetType; public InputService() @@ -25,13 +26,13 @@ public InputService() public void UpdateInputService() { - if(currentState == InputState.SELECTING_TARGET) + if (currentState == InputState.SELECTING_TARGET) mouseInputHandler.HandleTargetSelection(targetType); } - public void OnActionSelected(ActionType selectedActionType) + public void OnActionSelected(CommandType selectedActionType) { - this.selectedActionType = selectedActionType; + this.selectedCommandType = selectedActionType; SetInputState(InputState.SELECTING_TARGET); TargetType targetType = SetTargetType(selectedActionType); ShowTargetSelectionUI(targetType); @@ -43,12 +44,47 @@ private void ShowTargetSelectionUI(TargetType selectedTargetType) GameService.Instance.UIService.ShowTargetOverlay(playerID, selectedTargetType); } - private TargetType SetTargetType(ActionType selectedActionType) => targetType = GameService.Instance.ActionService.GetTargetTypeForAction(selectedActionType); + private TargetType SetTargetType(CommandType selectedCommandType) => targetType = GameService.Instance.ActionService.GetTargetTypeForAction(selectedCommandType); public void OnTargetSelected(UnitController targetUnit) { SetInputState(InputState.EXECUTING_INPUT); - GameService.Instance.PlayerService.PerformAction(selectedActionType, targetUnit); + UnitCommand commandToProcess = CreateUnitCommand(targetUnit); + GameService.Instance.ProcessUnitCommand(commandToProcess); + } + + private UnitCommand CreateUnitCommand(UnitController targetUnit) + { + + CommandData commandData = CreateCommandData(targetUnit); + + switch (selectedCommandType) + { + case CommandType.Attack: + return new AttackCommand(commandData); + case CommandType.Heal: + return new HealCommand(commandData); + case CommandType.AttackStance: + return new AttackStanceCommand(commandData); + case CommandType.Cleanse: + return new CleanseCommand(commandData); + case CommandType.BerserkAttack: + return new BerserkAttackCommand(commandData); + case CommandType.Meditate: + return new MeditateCommand(commandData); + case CommandType.ThirdEye: + return new ThirdEyeCommand(commandData); + default: + throw new System.Exception($"No Command found of type: {selectedCommandType}"); + } + } + + private CommandData CreateCommandData(UnitController targetUnit) + { + return new CommandData(GameService.Instance.PlayerService.ActiveUnitID, + targetUnit.UnitID, + GameService.Instance.PlayerService.ActivePlayerID, + targetUnit.Owner.PlayerID); } } } \ No newline at end of file diff --git a/Assets/Scripts/Main/GameService.cs b/Assets/Scripts/Main/GameService.cs index e8a709be..71fab410 100644 --- a/Assets/Scripts/Main/GameService.cs +++ b/Assets/Scripts/Main/GameService.cs @@ -9,6 +9,7 @@ using Command.Battle; using Command.Actions; using UnityEngine.UI; +using Command.Commands; namespace Command.Main { @@ -21,13 +22,13 @@ namespace Command.Main public class GameService : GenericMonoSingleton { - // Services: public EventService EventService { get; private set; } public SoundService SoundService { get; private set; } public ActionService ActionService { get; private set; } public InputService InputService { get; private set; } public BattleService BattleService { get; private set; } public PlayerService PlayerService { get; private set; } + public CommandInvoker CommandInvoker { get; private set; } [SerializeField] private UIService uiService; public UIService UIService => uiService; @@ -49,8 +50,11 @@ private void Start() BattleService = new BattleService(battleScriptableObjects); PlayerService = new PlayerService(); uiService.Init(battleScriptableObjects.Count); + CommandInvoker = new CommandInvoker(); } private void Update() => InputService.UpdateInputService(); + + public void ProcessUnitCommand(ICommand commandToProcess) => PlayerService.ProcessUnitCommand(commandToProcess as UnitCommand); } } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 3860582a..0619e52d 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -1,3 +1,4 @@ +using Command.Commands; using System.Collections.Generic; using UnityEngine; @@ -89,5 +90,33 @@ public void ResetCurrentActivePlayer() activeUnitIndex--; units[activeUnitIndex].StartUnitTurn(); } + + public void ResetCurrentActiveUnit() + { + // Reset the unit indicator (Arrow) for the currently active unit. + units[activeUnitIndex].ResetUnitIndicator(); + + // Move to the previous unit in the list. + activeUnitIndex--; + + // Continue searching for a valid, living unit to make active. + while (activeUnitIndex >= 0) + { + // Check if the unit at the current index is not alive (i.e., it's defeated). + if (!units[activeUnitIndex].IsAlive()) + { + // Move to the previous unit in the list. + activeUnitIndex--; + } + else + { + // Activate the next living unit in the list and start its turn. + units[activeUnitIndex].StartUnitTurn(); + break; // Exit the loop once an active unit is found. + } + } + } + + public void ProcessUnitCommand(UnitCommand commandToProcess) => GetUnitByID(commandToProcess.commandData.ActorUnitID).ProcessUnitCommand(commandToProcess); } } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerService.cs b/Assets/Scripts/Player/PlayerService.cs index ec1f8bb4..c5ef122c 100644 --- a/Assets/Scripts/Player/PlayerService.cs +++ b/Assets/Scripts/Player/PlayerService.cs @@ -1,4 +1,5 @@ using Command.Actions; +using Command.Commands; using Command.Main; namespace Command.Player @@ -23,7 +24,7 @@ public void Init(PlayerScriptableObject player1Data, PlayerScriptableObject play private void CleanPlayers() { - if(player1 == null || player2 == null) + if (player1 == null || player2 == null) return; player1.DestroyAllUnits(); @@ -45,13 +46,13 @@ private void StartTurnSequence() private void StartNextTurn() { SetActivePlayer(); - + if (activePlayer == player1) { currentTurnNumber++; GameService.Instance.UIService.UpdateTurnNumber(currentTurnNumber); } - + activePlayer.StartPlayerTurn(); } @@ -59,14 +60,12 @@ private void SetActivePlayer() { if (activePlayer == null) activePlayer = player1; - else + else activePlayer = activePlayer == player1 ? player2 : player1; } public void OnPlayerTurnCompleted() => StartNextTurn(); - public void PerformAction(ActionType actionSelected, UnitController targetUnit) => GameService.Instance.ActionService.GetActionByType(actionSelected).PerformAction(activePlayer.GetUnitByID(ActiveUnitID), targetUnit); - public void PlayerDied(PlayerController deadPlayer) { int winnerId; @@ -79,7 +78,21 @@ public void PlayerDied(PlayerController deadPlayer) GameService.Instance.UIService.ShowBattleEndUI(winnerId); } - private PlayerController GetPlayerById(int playerId) + public void ProcessUnitCommand(UnitCommand commandToProcess) + { + SetUnitReferences(commandToProcess); + GetPlayerById(commandToProcess.commandData.ActorPlayerID).ProcessUnitCommand(commandToProcess); + } + + private void SetUnitReferences(UnitCommand commandToProcess) + { + var actorUnit = GetPlayerById(commandToProcess.commandData.ActorPlayerID).GetUnitByID(commandToProcess.commandData.ActorUnitID); + var targetUnit = GetPlayerById(commandToProcess.commandData.TargetPlayerID).GetUnitByID(commandToProcess.commandData.TargetUnitID); + commandToProcess.SetActorUnit(actorUnit); + commandToProcess.SetTargetUnit(targetUnit); + } + + private PlayerController GetPlayerById(int playerId) { if (player1.PlayerID == playerId) return player1; diff --git a/Assets/Scripts/Player/Unit/UnitController.cs b/Assets/Scripts/Player/Unit/UnitController.cs index 863dc14f..33559373 100644 --- a/Assets/Scripts/Player/Unit/UnitController.cs +++ b/Assets/Scripts/Player/Unit/UnitController.cs @@ -4,6 +4,7 @@ using System.Collections; using System; using Object = UnityEngine.Object; +using Command.Commands; namespace Command.Player { @@ -42,6 +43,8 @@ private void InitializeView(Vector3 positionToSet) unitView.SetUnitIndicator(false); } + public void ProcessUnitCommand(UnitCommand commandToProcess) => GameService.Instance.CommandInvoker.ProcessCommand(commandToProcess); + private void InitializeVariables() { CurrentMaxHealth = CurrentHealth = unitScriptableObject.MaxHealth; @@ -85,25 +88,26 @@ public void RestoreHealth(int healthToRestore) unitView.UpdateHealthBar((float)CurrentHealth / CurrentMaxHealth); } + private void UnitDied() { SetAliveState(UnitAliveState.DEAD); unitView.PlayAnimation(UnitAnimations.DEATH); } - public void PlayBattleAnimation(ActionType actionType, Vector3 battlePosition, Action callback) + public void PlayBattleAnimation(CommandType actionType, Vector3 battlePosition, Action callback) { GameService.Instance.UIService.ResetBattleBackgroundOverlay(); MoveToBattlePosition(battlePosition, callback, true, actionType); } - private void MoveToBattlePosition(Vector3 battlePosition, Action callback = null, bool shouldPlayActionAnimation = true, ActionType actionTypeToExecute = ActionType.None) + private void MoveToBattlePosition(Vector3 battlePosition, Action callback = null, bool shouldPlayActionAnimation = true, CommandType actionTypeToExecute = CommandType.None) { float moveTime = Vector3.Distance(unitView.transform.position, battlePosition) / unitScriptableObject.MovementSpeed; unitView.StartCoroutine(MoveToPositionOverTime(battlePosition, moveTime, callback, shouldPlayActionAnimation, actionTypeToExecute)); } - private IEnumerator MoveToPositionOverTime(Vector3 targetPosition, float time, Action callback, bool shouldPlayActionAnimation, ActionType actionTypeToExecute) + private IEnumerator MoveToPositionOverTime(Vector3 targetPosition, float time, Action callback, bool shouldPlayActionAnimation, CommandType actionTypeToExecute) { float elapsedTime = 0; Vector3 startingPosition = unitView.transform.position; @@ -124,9 +128,9 @@ private IEnumerator MoveToPositionOverTime(Vector3 targetPosition, float time, A callback.Invoke(); } - private void PlayActionAnimation(ActionType actionType) + private void PlayActionAnimation(CommandType actionType) { - if (actionType == ActionType.None) + if (actionType == CommandType.None) return; if (actionType == unitScriptableObject.executableCommands[0]) @@ -147,7 +151,11 @@ public void OnActionExecuted() public void ResetStats() => CurrentPower = unitScriptableObject.Power; - public void Revive() => SetAliveState(UnitAliveState.ALIVE); + public void Revive() + { + SetAliveState(UnitAliveState.ALIVE); + unitView.PlayAnimation(UnitAnimations.IDLE); + } public void Destroy() => UnityEngine.Object.Destroy(unitView.gameObject); diff --git a/Assets/Scripts/Player/Unit/UnitScriptableObject.cs b/Assets/Scripts/Player/Unit/UnitScriptableObject.cs index 3c0b6305..00badda8 100644 --- a/Assets/Scripts/Player/Unit/UnitScriptableObject.cs +++ b/Assets/Scripts/Player/Unit/UnitScriptableObject.cs @@ -12,7 +12,7 @@ public class UnitScriptableObject : ScriptableObject public UnitView UnitPrefab; public int MaxHealth; public int Power; - public List executableCommands; + public List executableCommands; public Vector3 EnemyBattlePositionOffset; public float MovementSpeed; } diff --git a/Assets/Scripts/UI/ActionSelectionUI/ActionButtonView.cs b/Assets/Scripts/UI/ActionSelectionUI/ActionButtonView.cs index f3016d06..ad4697a5 100644 --- a/Assets/Scripts/UI/ActionSelectionUI/ActionButtonView.cs +++ b/Assets/Scripts/UI/ActionSelectionUI/ActionButtonView.cs @@ -9,7 +9,7 @@ public class ActionButtonView : MonoBehaviour { [SerializeField] private TextMeshProUGUI buttonText; private ActionSelectionUIController owner; - private ActionType actionType; + private CommandType actionType; private void Start() => GetComponent