diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 168f4635..3e1f10f9 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} @@ -218,7 +216,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &101671527 RectTransform: m_ObjectHideFlags: 0 @@ -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 @@ -1471,7 +1470,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &988327834 RectTransform: 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} @@ -2787,6 +2778,7 @@ MonoBehaviour: m_EditorClassIdentifier: resultText: {fileID: 1682630446} homeButton: {fileID: 799045267} + replayButton: {fileID: 988327835} --- !u!1 &2089575972 GameObject: m_ObjectHideFlags: 0 @@ -2847,11 +2839,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/ActionType.cs b/Assets/Scripts/Action/ActionType.cs index f6c14302..5d65fb64 100644 --- a/Assets/Scripts/Action/ActionType.cs +++ b/Assets/Scripts/Action/ActionType.cs @@ -1,6 +1,6 @@ namespace Command.Actions { - public enum ActionType + public enum CommandType { None, Attack, diff --git a/Assets/Scripts/Action/Actions/AttackAction.cs b/Assets/Scripts/Action/Actions/AttackAction.cs index 75632f04..82f76dd6 100644 --- a/Assets/Scripts/Action/Actions/AttackAction.cs +++ b/Assets/Scripts/Action/Actions/AttackAction.cs @@ -9,27 +9,28 @@ 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() { 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(); diff --git a/Assets/Scripts/Action/Actions/AttackStanceAction.cs b/Assets/Scripts/Action/Actions/AttackStanceAction.cs index 9fc46d34..ff546182 100644 --- a/Assets/Scripts/Action/Actions/AttackStanceAction.cs +++ b/Assets/Scripts/Action/Actions/AttackStanceAction.cs @@ -9,28 +9,28 @@ 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() { GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.ATTACK_STANCE); - if (IsSuccessful()) + if (IsSuccessful) targetUnit.CurrentPower += (int)(targetUnit.CurrentPower * 0.2f); else GameService.Instance.UIService.ActionMissed(); } - public bool IsSuccessful() => true; - public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition(); } } \ No newline at end of file diff --git a/Assets/Scripts/Action/Actions/BerserkAttackAction.cs b/Assets/Scripts/Action/Actions/BerserkAttackAction.cs index 42ce5acd..d49bc3d9 100644 --- a/Assets/Scripts/Action/Actions/BerserkAttackAction.cs +++ b/Assets/Scripts/Action/Actions/BerserkAttackAction.cs @@ -10,21 +10,23 @@ 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() { GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.BERSERK_ATTACK); - if (IsSuccessful()) + if (IsSuccessful) targetUnit.TakeDamage(actorUnit.CurrentPower * 2); else { @@ -33,8 +35,6 @@ public void OnActionAnimationCompleted() } } - public bool IsSuccessful() => Random.Range(0f, 1f) < hitChance; - public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition(); } } \ No newline at end of file diff --git a/Assets/Scripts/Action/Actions/CleanseAction.cs b/Assets/Scripts/Action/Actions/CleanseAction.cs index 469071ea..926e844f 100644 --- a/Assets/Scripts/Action/Actions/CleanseAction.cs +++ b/Assets/Scripts/Action/Actions/CleanseAction.cs @@ -10,28 +10,28 @@ 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 IsSuccessful) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.IsSuccessful = IsSuccessful; - actorUnit.PlayBattleAnimation(ActionType.Cleanse, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.Cleanse, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() { GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.CLEANSE); - if (IsSuccessful()) + if (IsSuccessful) targetUnit.ResetStats(); else GameService.Instance.UIService.ActionMissed(); } - public bool IsSuccessful() => Random.Range(0f, 1f) < hitChance; - public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition(); } } diff --git a/Assets/Scripts/Action/Actions/HealAction.cs b/Assets/Scripts/Action/Actions/HealAction.cs index d05b6d47..a950e9db 100644 --- a/Assets/Scripts/Action/Actions/HealAction.cs +++ b/Assets/Scripts/Action/Actions/HealAction.cs @@ -9,26 +9,26 @@ 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 IsSuccessful) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.IsSuccessful = IsSuccessful; - actorUnit.PlayBattleAnimation(ActionType.Heal, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.Heal, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() { GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.HEAL); - if (IsSuccessful()) + if (IsSuccessful) targetUnit.RestoreHealth(actorUnit.CurrentPower); } - public bool IsSuccessful() => true; - public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition(); } } \ No newline at end of file diff --git a/Assets/Scripts/Action/Actions/MeditateAction.cs b/Assets/Scripts/Action/Actions/MeditateAction.cs index 869e159b..bac541bf 100644 --- a/Assets/Scripts/Action/Actions/MeditateAction.cs +++ b/Assets/Scripts/Action/Actions/MeditateAction.cs @@ -9,21 +9,23 @@ 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 IsSuccessful) { this.actorUnit = actorUnit; this.targetUnit = targetUnit; + this.IsSuccessful = IsSuccessful; - actorUnit.PlayBattleAnimation(ActionType.Meditate, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + actorUnit.PlayBattleAnimation(CommandType.Meditate, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() { GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.MEDITATE); - if (IsSuccessful()) + if (IsSuccessful) { var healthToIncrease = (int)(targetUnit.CurrentMaxHealth * 0.2f); targetUnit.CurrentMaxHealth += healthToIncrease; @@ -33,7 +35,6 @@ public void OnActionAnimationCompleted() GameService.Instance.UIService.ActionMissed(); } - public bool IsSuccessful() => true; public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition(); } diff --git a/Assets/Scripts/Action/Actions/ThirdEyeAction.cs b/Assets/Scripts/Action/Actions/ThirdEyeAction.cs index 8a24ba01..88de3543 100644 --- a/Assets/Scripts/Action/Actions/ThirdEyeAction.cs +++ b/Assets/Scripts/Action/Actions/ThirdEyeAction.cs @@ -9,19 +9,21 @@ 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 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() { - if (IsSuccessful()) + if (IsSuccessful) { int healthToConvert = (int)(targetUnit.CurrentHealth * 0.25f); targetUnit.TakeDamage(healthToConvert); @@ -31,8 +33,6 @@ public void OnActionAnimationCompleted() GameService.Instance.UIService.ActionMissed(); } - public bool IsSuccessful() => true; - public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition(); } } \ No newline at end of file diff --git a/Assets/Scripts/Action/IAction.cs b/Assets/Scripts/Action/IAction.cs index 610560d8..4061a118 100644 --- a/Assets/Scripts/Action/IAction.cs +++ b/Assets/Scripts/Action/IAction.cs @@ -11,9 +11,8 @@ public interface IAction { public TargetType TargetType { get; } - public void PerformAction(UnitController actorUnit, UnitController targetUnit); + public void PerformAction(UnitController actorUnit, UnitController targetUnit, bool IsSuccessful); - public bool IsSuccessful(); public Vector3 CalculateMovePosition(UnitController targetUnit); } diff --git a/Assets/Scripts/Battle/BattleService.cs b/Assets/Scripts/Battle/BattleService.cs index 0709f35f..78c1393c 100644 --- a/Assets/Scripts/Battle/BattleService.cs +++ b/Assets/Scripts/Battle/BattleService.cs @@ -16,8 +16,13 @@ public BattleService(List battleScriptableObjects) SubscribeToEvents(); } - private void SubscribeToEvents() => GameService.Instance.EventService.OnBattleSelected.AddListener(LoadBattle); + private void SubscribeToEvents() + { + GameService.Instance.EventService.OnBattleSelected.AddListener(LoadBattle); + GameService.Instance.EventService.OnReplayButtonClicked.AddListener(ReplayBattle); + } + private void LoadBattle(int battleId) { currentBattleId = battleId; @@ -29,5 +34,6 @@ private void LoadBattle(int battleId) } private BattleScriptableObject GetBattleDataByID(int battleId) => battleScriptableObjects.Find(battleSO => battleSO.BattleID == battleId); + private void ReplayBattle() => LoadBattle(currentBattleId); } } diff --git a/Assets/Scripts/Command.meta b/Assets/Scripts/Command.meta new file mode 100644 index 00000000..6c27f793 --- /dev/null +++ b/Assets/Scripts/Command.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 73e321aadba73f042af7a2655e124fae +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/AttackCommand.cs b/Assets/Scripts/Command/AttackCommand.cs new file mode 100644 index 00000000..f34248e5 --- /dev/null +++ b/Assets/Scripts/Command/AttackCommand.cs @@ -0,0 +1,40 @@ +using Command.Actions; +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public class AttackCommand : UnitCommand + { + private bool hitTargert; + + public AttackCommand(CommandData commandData) + { + this.commandData = commandData; + hitTargert = WillHitTarget(); + + } + + public override bool WillHitTarget() => true; + + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(CommandType.Attack).PerformAction(actorUnit,targetUnit,hitTargert); + } + + public override void Undo() + { + if (hitTargert) + { + if (!targetUnit.IsAlive()) + targetUnit.Revive(); + + targetUnit.RestoreHealth(actorUnit.CurrentPower); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + } +} + diff --git a/Assets/Scripts/Command/AttackCommand.cs.meta b/Assets/Scripts/Command/AttackCommand.cs.meta new file mode 100644 index 00000000..eed6be31 --- /dev/null +++ b/Assets/Scripts/Command/AttackCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 592b0b67f185e434ba9f83df942823f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/AttackStanceCommand.cs b/Assets/Scripts/Command/AttackStanceCommand.cs new file mode 100644 index 00000000..0a0b67fb --- /dev/null +++ b/Assets/Scripts/Command/AttackStanceCommand.cs @@ -0,0 +1,37 @@ +using Command.Actions; +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public class AttackStanceCommand : UnitCommand + { + private bool hitTargert; + + public AttackStanceCommand(CommandData commandData) + { + this.commandData = commandData; + hitTargert = WillHitTarget(); + + } + + public override bool WillHitTarget() => true; + + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(CommandType.AttackStance).PerformAction(actorUnit,targetUnit,hitTargert); + } + + public override void Undo() + { + if (hitTargert) + { + targetUnit.CurrentPower -= (int)(targetUnit.CurrentPower * 0.2f); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + } +} + diff --git a/Assets/Scripts/Command/AttackStanceCommand.cs.meta b/Assets/Scripts/Command/AttackStanceCommand.cs.meta new file mode 100644 index 00000000..e97bbceb --- /dev/null +++ b/Assets/Scripts/Command/AttackStanceCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 43dac02bf273a0742a52955499852828 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/BerserkAttackCommand.cs b/Assets/Scripts/Command/BerserkAttackCommand.cs new file mode 100644 index 00000000..3216d884 --- /dev/null +++ b/Assets/Scripts/Command/BerserkAttackCommand.cs @@ -0,0 +1,47 @@ +using Command.Actions; +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public class BerserkAttackCommand : UnitCommand + { + private bool hitTargert; + + public BerserkAttackCommand(CommandData commandData) + { + this.commandData = commandData; + hitTargert = WillHitTarget(); + + } + + public override bool WillHitTarget() => true; + + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(CommandType.BerserkAttack).PerformAction(actorUnit,targetUnit,hitTargert); + } + + public override void Undo() + { + if (hitTargert) + { + if (!targetUnit.IsAlive()) + targetUnit.Revive(); + + targetUnit.RestoreHealth(actorUnit.CurrentPower * 2); + } + else + { + if (!actorUnit.IsAlive()) + actorUnit.Revive(); + + actorUnit.RestoreHealth(actorUnit.CurrentPower * 2); + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } +} + diff --git a/Assets/Scripts/Command/BerserkAttackCommand.cs.meta b/Assets/Scripts/Command/BerserkAttackCommand.cs.meta new file mode 100644 index 00000000..920c4ed9 --- /dev/null +++ b/Assets/Scripts/Command/BerserkAttackCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c6fafe98686dd0e4480ece2c2152016d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/CleanseCommand.cs b/Assets/Scripts/Command/CleanseCommand.cs new file mode 100644 index 00000000..816f22be --- /dev/null +++ b/Assets/Scripts/Command/CleanseCommand.cs @@ -0,0 +1,38 @@ +using Command.Actions; +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public class CleanseCommand : UnitCommand + { + private bool hitTargert; + private int previousPower; + + public CleanseCommand(CommandData commandData) + { + this.commandData = commandData; + hitTargert = WillHitTarget(); + + } + + public override bool WillHitTarget() => true; + + public override void Execute() + { + previousPower = targetUnit.CurrentPower; + GameService.Instance.ActionService.GetActionByType(CommandType.Cleanse).PerformAction(actorUnit,targetUnit,hitTargert); + } + + public override void Undo() + { + if (hitTargert) + targetUnit.CurrentPower = previousPower; + + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } +} + diff --git a/Assets/Scripts/Command/CleanseCommand.cs.meta b/Assets/Scripts/Command/CleanseCommand.cs.meta new file mode 100644 index 00000000..4471e796 --- /dev/null +++ b/Assets/Scripts/Command/CleanseCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fdfac285170c36644b4162f3d66b13e2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/CommandInvoker.cs b/Assets/Scripts/Command/CommandInvoker.cs new file mode 100644 index 00000000..5b6e6fa1 --- /dev/null +++ b/Assets/Scripts/Command/CommandInvoker.cs @@ -0,0 +1,55 @@ +using Command.Main; +using Commands; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace Commands +{ + public class CommandInvoker + { + + + public CommandInvoker() + { + SubscribeToEvents(); + } + + private void SubscribeToEvents() + { + GameService.Instance.EventService.OnReplayButtonClicked.AddListener(SetReplayStack); + } + + private Stack commandRegistry = new Stack(); + + public void ExecuteCommand(ICommand command) => command.Execute(); + + public void RegisterCommand(ICommand command) => commandRegistry.Push(command); + + public void ProcessCommand(ICommand command) + { + ExecuteCommand(command); + RegisterCommand(command); + } + + public void Undo() + { + if (!RegistryEmpty() && CommandBelongsToActivePlayer()) + commandRegistry.Pop().Undo(); + } + private bool RegistryEmpty() => commandRegistry.Count == 0; + + private bool CommandBelongsToActivePlayer() + { + return (commandRegistry.Peek() as UnitCommand).commandData.ActorPlayerID == GameService.Instance.PlayerService.ActivePlayerID; + } + + private void SetReplayStack() + { + GameService.Instance.ReplayService.SetCommandStack(commandRegistry); + commandRegistry.Clear(); + } + } +} + diff --git a/Assets/Scripts/Command/CommandInvoker.cs.meta b/Assets/Scripts/Command/CommandInvoker.cs.meta new file mode 100644 index 00000000..d22f4b73 --- /dev/null +++ b/Assets/Scripts/Command/CommandInvoker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a5f6e4aa5e8ae784da2fa506c11b3f59 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/HealCommand.cs b/Assets/Scripts/Command/HealCommand.cs new file mode 100644 index 00000000..0933e46e --- /dev/null +++ b/Assets/Scripts/Command/HealCommand.cs @@ -0,0 +1,37 @@ +using Command.Actions; +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public class HealCommand : UnitCommand + { + private bool hitTargert; + + public HealCommand(CommandData commandData) + { + this.commandData = commandData; + hitTargert = WillHitTarget(); + + } + + public override bool WillHitTarget() => true; + + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(CommandType.Heal).PerformAction(actorUnit,targetUnit,hitTargert); + } + + public override void Undo() + { + if (hitTargert) + { + targetUnit.TakeDamage(actorUnit.CurrentPower); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + } +} + diff --git a/Assets/Scripts/Command/HealCommand.cs.meta b/Assets/Scripts/Command/HealCommand.cs.meta new file mode 100644 index 00000000..75078efb --- /dev/null +++ b/Assets/Scripts/Command/HealCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea408cb28ee1bca46ad75a30936b64a3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/ICommand.cs b/Assets/Scripts/Command/ICommand.cs new file mode 100644 index 00000000..c4cd3ade --- /dev/null +++ b/Assets/Scripts/Command/ICommand.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public interface ICommand + { + public void Execute(); + + public void Undo(); + } + +} diff --git a/Assets/Scripts/Command/ICommand.cs.meta b/Assets/Scripts/Command/ICommand.cs.meta new file mode 100644 index 00000000..0291f7f1 --- /dev/null +++ b/Assets/Scripts/Command/ICommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 83e041ddb833dd04283d5901bd24f4c5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/MeditateCommand.cs b/Assets/Scripts/Command/MeditateCommand.cs new file mode 100644 index 00000000..ed7cb036 --- /dev/null +++ b/Assets/Scripts/Command/MeditateCommand.cs @@ -0,0 +1,41 @@ +using Command.Actions; +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public class MeditateCommand : UnitCommand + { + private bool hitTargert; + private int previousMaxHealth; + + public MeditateCommand(CommandData commandData) + { + this.commandData = commandData; + hitTargert = WillHitTarget(); + + } + + public override bool WillHitTarget() => true; + + public override void Execute() + { + previousMaxHealth = targetUnit.CurrentMaxHealth; + GameService.Instance.ActionService.GetActionByType(CommandType.Meditate).PerformAction(actorUnit,targetUnit,hitTargert); + } + + public override void Undo() + { + if (hitTargert) + { + var healthToReduce = targetUnit.CurrentMaxHealth - previousMaxHealth; + targetUnit.CurrentMaxHealth = previousMaxHealth; + targetUnit.TakeDamage(healthToReduce); + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } +} + diff --git a/Assets/Scripts/Command/MeditateCommand.cs.meta b/Assets/Scripts/Command/MeditateCommand.cs.meta new file mode 100644 index 00000000..5f1e4ae6 --- /dev/null +++ b/Assets/Scripts/Command/MeditateCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7b994041c9fdb324c9dbd3c8f6fd58d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/ThirdEyeCommand.cs b/Assets/Scripts/Command/ThirdEyeCommand.cs new file mode 100644 index 00000000..985fda61 --- /dev/null +++ b/Assets/Scripts/Command/ThirdEyeCommand.cs @@ -0,0 +1,41 @@ +using Command.Actions; +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + public class ThirdEyeCommand : UnitCommand + { + private bool hitTargert; + private int previousHealth; + + public ThirdEyeCommand(CommandData commandData) + { + this.commandData = commandData; + hitTargert = WillHitTarget(); + + } + + public override bool WillHitTarget() => true; + + public override void Execute() + { + previousHealth = targetUnit.CurrentHealth; + GameService.Instance.ActionService.GetActionByType(CommandType.ThirdEye).PerformAction(actorUnit,targetUnit,hitTargert); + } + + public override void Undo() + { + if (!targetUnit.IsAlive()) + targetUnit.Revive(); + + int healthToRestore = (int)(previousHealth * 0.25f); + targetUnit.RestoreHealth(healthToRestore); + targetUnit.CurrentPower -= healthToRestore; + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } +} + diff --git a/Assets/Scripts/Command/ThirdEyeCommand.cs.meta b/Assets/Scripts/Command/ThirdEyeCommand.cs.meta new file mode 100644 index 00000000..32cb9716 --- /dev/null +++ b/Assets/Scripts/Command/ThirdEyeCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 94e7ad9ef1616734ea4e457218b163d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Command/UnitCommand.cs b/Assets/Scripts/Command/UnitCommand.cs new file mode 100644 index 00000000..cd1979b1 --- /dev/null +++ b/Assets/Scripts/Command/UnitCommand.cs @@ -0,0 +1,48 @@ +using Command.Player; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Commands +{ + 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; + } + } + public abstract class UnitCommand : ICommand + { + + public CommandData commandData; + + protected UnitController actorUnit; + protected UnitController targetUnit; + + public abstract void Execute(); + public abstract bool WillHitTarget(); + + public abstract void Undo(); + + public void setActorUnit(UnitController actorUnit) + { + this.actorUnit = actorUnit; + } + + public void setTargetUnit(UnitController targetUnit) + { + this.targetUnit = targetUnit; + } + } + + +} diff --git a/Assets/Scripts/Command/UnitCommand.cs.meta b/Assets/Scripts/Command/UnitCommand.cs.meta new file mode 100644 index 00000000..837e28d8 --- /dev/null +++ b/Assets/Scripts/Command/UnitCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c504bce7fe891bb44a62c3abd88513cb +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..f1e34433 100644 --- a/Assets/Scripts/Events/EventService.cs +++ b/Assets/Scripts/Events/EventService.cs @@ -11,12 +11,15 @@ 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 GameEventController OnReplayButtonClicked { get; private set; } public EventService() { OnBattleSelected = new GameEventController(); - OnActionSelected = new GameEventController(); + OnActionSelected = new GameEventController(); + OnReplayButtonClicked = new GameEventController(); } } } \ No newline at end of file diff --git a/Assets/Scripts/Input/InputService.cs b/Assets/Scripts/Input/InputService.cs index de088222..aa1969f5 100644 --- a/Assets/Scripts/Input/InputService.cs +++ b/Assets/Scripts/Input/InputService.cs @@ -1,6 +1,8 @@ using Command.Main; using Command.Player; using Command.Actions; +using Commands; +using System; namespace Command.Input { @@ -9,7 +11,7 @@ public class InputService private MouseInputHandler mouseInputHandler; private InputState currentState; - private ActionType selectedActionType; + private CommandType selectedCommandType; private TargetType targetType; public InputService() @@ -29,11 +31,11 @@ public void UpdateInputService() mouseInputHandler.HandleTargetSelection(targetType); } - public void OnActionSelected(ActionType selectedActionType) + public void OnActionSelected(CommandType selectedCommandType) { - this.selectedActionType = selectedActionType; + this.selectedCommandType = selectedCommandType; SetInputState(InputState.SELECTING_TARGET); - TargetType targetType = SetTargetType(selectedActionType); + TargetType targetType = SetTargetType(selectedCommandType); ShowTargetSelectionUI(targetType); } @@ -43,12 +45,51 @@ 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 unitCommand = CreateUnitCommand(targetUnit); + GameService.Instance.ProcessUnitCommand(unitCommand); + } + + public CommandData createCommandData(UnitController targetUnit) + { + return new CommandData( + GameService.Instance.PlayerService.ActiveUnitID, + targetUnit.UnitID, + GameService.Instance.PlayerService.ActivePlayerID, + targetUnit.Owner.PlayerID + + ); + + } + + private UnitCommand CreateUnitCommand(UnitController targetUnit) + { + CommandData commandData = createCommandData(targetUnit); + + switch(selectedCommandType) + { + case CommandType.Attack: + return new AttackCommand(commandData); + case CommandType.AttackStance: + return new AttackStanceCommand(commandData); + case CommandType.BerserkAttack: + return new BerserkAttackCommand(commandData); + case CommandType.Heal: + return new HealCommand(commandData); + case CommandType.Cleanse: + return new CleanseCommand(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}"); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/Main/GameService.cs b/Assets/Scripts/Main/GameService.cs index e8a709be..5f016d9e 100644 --- a/Assets/Scripts/Main/GameService.cs +++ b/Assets/Scripts/Main/GameService.cs @@ -9,6 +9,10 @@ using Command.Battle; using Command.Actions; using UnityEngine.UI; +using System.Windows.Input; +using Commands; +using Command.Replay; + namespace Command.Main { @@ -28,6 +32,8 @@ public class GameService : GenericMonoSingleton public InputService InputService { get; private set; } public BattleService BattleService { get; private set; } public PlayerService PlayerService { get; private set; } + public CommandInvoker CommandInvoker { get; private set; } + public ReplayService ReplayService { get; private set; } [SerializeField] private UIService uiService; public UIService UIService => uiService; @@ -48,9 +54,16 @@ private void Start() InputService = new InputService(); BattleService = new BattleService(battleScriptableObjects); PlayerService = new PlayerService(); + CommandInvoker = new CommandInvoker(); + ReplayService = new ReplayService(); uiService.Init(battleScriptableObjects.Count); } private void Update() => InputService.UpdateInputService(); + + public void ProcessUnitCommand(Commands.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..2d6f1cc1 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using Commands; using UnityEngine; namespace Command.Player @@ -89,5 +91,30 @@ public void ResetCurrentActivePlayer() activeUnitIndex--; units[activeUnitIndex].StartUnitTurn(); } + + public void ProcessToUnit(UnitCommand commandToProcess) + { + GetUnitByID(commandToProcess.commandData.ActorUnitID).ProcessUnitCommand(commandToProcess); + } + + public void ResetCurrentActiveUnit() + { + units[activeUnitIndex].ResetUnitIndicator(); + + activeUnitIndex--; + + while(activeUnitIndex>=0) + { + if(!units[activeUnitIndex].IsAlive()) + { + activeUnitIndex--; + } + else + { + units[activeUnitIndex].StartUnitTurn(); + break; + } + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerService.cs b/Assets/Scripts/Player/PlayerService.cs index ec1f8bb4..8f2b14ef 100644 --- a/Assets/Scripts/Player/PlayerService.cs +++ b/Assets/Scripts/Player/PlayerService.cs @@ -1,5 +1,6 @@ using Command.Actions; using Command.Main; +using Commands; namespace Command.Player { @@ -65,7 +66,7 @@ private void SetActivePlayer() public void OnPlayerTurnCompleted() => StartNextTurn(); - public void PerformAction(ActionType actionSelected, UnitController targetUnit) => GameService.Instance.ActionService.GetActionByType(actionSelected).PerformAction(activePlayer.GetUnitByID(ActiveUnitID), targetUnit); + public void PerformAction(CommandType actionSelected, UnitController targetUnit,bool IsSuccessful) => GameService.Instance.ActionService.GetActionByType(actionSelected).PerformAction(activePlayer.GetUnitByID(ActiveUnitID), targetUnit,IsSuccessful); public void PlayerDied(PlayerController deadPlayer) { @@ -96,5 +97,20 @@ public void CheckGameOver() else if (player2.AllUnitsDead()) PlayerDied(player2); } + + public void ProcessUnitCommand(UnitCommand commandToProcess) + { + SetUnitReference(commandToProcess); + GetPlayerById(commandToProcess.commandData.ActorPlayerID).ProcessToUnit(commandToProcess); + } + + public void SetUnitReference(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); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Player/Unit/UnitController.cs b/Assets/Scripts/Player/Unit/UnitController.cs index 863dc14f..3fa45ce2 100644 --- a/Assets/Scripts/Player/Unit/UnitController.cs +++ b/Assets/Scripts/Player/Unit/UnitController.cs @@ -4,6 +4,8 @@ using System.Collections; using System; using Object = UnityEngine.Object; +using System.Windows.Input; +using Commands; namespace Command.Player { @@ -91,19 +93,19 @@ private void UnitDied() 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 +126,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 +149,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); @@ -160,6 +166,12 @@ public Vector3 GetEnemyPosition() else return unitView.transform.position - unitScriptableObject.EnemyBattlePositionOffset; } + + + public void ProcessUnitCommand(UnitCommand commandToProcess) + { + GameService.Instance.CommandInvoker.ProcessCommand(commandToProcess); + } } public enum UnitUsedState 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/Replay.meta b/Assets/Scripts/Replay.meta new file mode 100644 index 00000000..f1f5df3b --- /dev/null +++ b/Assets/Scripts/Replay.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 162bbff1249fa934dbcf0a9052478b30 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Replay/ReplayService.cs b/Assets/Scripts/Replay/ReplayService.cs new file mode 100644 index 00000000..f66dde2b --- /dev/null +++ b/Assets/Scripts/Replay/ReplayService.cs @@ -0,0 +1,34 @@ +using Command.Main; +using Commands; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Command.Replay +{ + public class ReplayService + { + private Stack replayCommandStack; + public ReplayState ReplayState { get; private set; } + + public ReplayService() => SetReplayState(ReplayState.DEACTIVE); + + public void SetReplayState(ReplayState stateToSet) => ReplayState = stateToSet; + + public void SetCommandStack(Stack commandsToSet) => replayCommandStack = new Stack(commandsToSet); + + public IEnumerator ExecuteNext() + { + + yield return new WaitForSeconds(1); + if (replayCommandStack.Count > 0) + GameService.Instance.ProcessUnitCommand(replayCommandStack.Pop()); + } + } + + public enum ReplayState + { + ACTIVE, + DEACTIVE + } +} \ No newline at end of file diff --git a/Assets/Scripts/Replay/ReplayService.cs.meta b/Assets/Scripts/Replay/ReplayService.cs.meta new file mode 100644 index 00000000..1c233d47 --- /dev/null +++ b/Assets/Scripts/Replay/ReplayService.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 10e9e05c0236a024a9f4323903b45dee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: 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