diff --git a/.gitignore b/.gitignore index 77526939..46c3a781 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,5 @@ crashlytics-build.properties # Temporary auto-generated Android Assets /[Aa]ssets/[Ss]treamingAssets/aa.meta /[Aa]ssets/[Ss]treamingAssets/aa/* +Assets/Plugins/CodeAssist +Assets/Plugins/CodeAssist.meta diff --git a/Assets/Plugins.meta b/Assets/Plugins.meta new file mode 100644 index 00000000..db2e0b0c --- /dev/null +++ b/Assets/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2d709e8bd3e925f43a7a9abd234ea9d5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Units/Berserker 1 Prefab.prefab b/Assets/Prefabs/Units/Berserker 1 Prefab.prefab index 21435d16..6ee84f12 100644 --- a/Assets/Prefabs/Units/Berserker 1 Prefab.prefab +++ b/Assets/Prefabs/Units/Berserker 1 Prefab.prefab @@ -33,7 +33,6 @@ RectTransform: m_Children: - {fileID: 1861695938137843386} m_Father: {fileID: 3581141579412945812} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -57,7 +56,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 @@ -128,6 +129,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3529831287557325137} + 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} @@ -136,7 +138,6 @@ Transform: - {fileID: 8822253660305909731} - {fileID: 2116980308125413923} m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!95 &2356409058739144771 Animator: @@ -235,6 +236,25 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 @@ -275,13 +295,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6208225900686816030} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -1.5, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3581141579412945812} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &2465335289595379705 SpriteRenderer: @@ -366,7 +386,6 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2116980308125413923} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 168f4635..29a567ef 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -104,7 +104,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +117,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -155,7 +155,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 +217,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 +231,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 +447,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 +485,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 +649,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 +690,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 +814,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 +858,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 +900,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 +1001,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 +1136,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 +1344,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 +1388,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 +1452,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 +1471,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 +1485,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 +1650,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 +1673,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 +1728,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 +1863,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 +1961,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 +2049,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 +2169,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 +2189,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 +2239,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 +2280,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 +2429,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 +2466,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 +2602,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 +2721,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 +2779,7 @@ MonoBehaviour: m_EditorClassIdentifier: resultText: {fileID: 1682630446} homeButton: {fileID: 799045267} + replayButton: {fileID: 988327835} --- !u!1 &2089575972 GameObject: m_ObjectHideFlags: 0 @@ -2847,11 +2840,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..fa4b5b92 100644 --- a/Assets/Scripts/Action/ActionService.cs +++ b/Assets/Scripts/Action/ActionService.cs @@ -1,27 +1,28 @@ using Command.Input; using System.Collections.Generic; +using Command.Commands; 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 +30,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..19dbedef 100644 --- a/Assets/Scripts/Action/Actions/AttackAction.cs +++ b/Assets/Scripts/Action/Actions/AttackAction.cs @@ -2,28 +2,29 @@ using Command.Main; using Command.Player; using UnityEngine; - +using Command.Commands; namespace Command.Actions { 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; - - actorUnit.PlayBattleAnimation(ActionType.Attack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + this.isSuccessful = isSuccessful; + actorUnit.PlayBattleAnimation(CommandType.Attack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); } public void OnActionAnimationCompleted() { PlayAttackSound(); - if (IsSuccessful()) + if (isSuccessful) targetUnit.TakeDamage(actorUnit.CurrentPower); else GameService.Instance.UIService.ActionMissed(); diff --git a/Assets/Scripts/Action/Actions/AttackStanceAction.cs b/Assets/Scripts/Action/Actions/AttackStanceAction.cs index 9fc46d34..27656007 100644 --- a/Assets/Scripts/Action/Actions/AttackStanceAction.cs +++ b/Assets/Scripts/Action/Actions/AttackStanceAction.cs @@ -2,35 +2,35 @@ using Command.Input; using Command.Main; using UnityEngine; - +using Command.Commands; namespace Command.Actions { 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..e0fd468d 100644 --- a/Assets/Scripts/Action/Actions/BerserkAttackAction.cs +++ b/Assets/Scripts/Action/Actions/BerserkAttackAction.cs @@ -2,6 +2,7 @@ using Command.Main; using Command.Player; using UnityEngine; +using Command.Commands; namespace Command.Actions { @@ -10,21 +11,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 +36,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..ef60b85d 100644 --- a/Assets/Scripts/Action/Actions/CleanseAction.cs +++ b/Assets/Scripts/Action/Actions/CleanseAction.cs @@ -2,7 +2,7 @@ using Command.Player; using Command.Main; using UnityEngine; - +using Command.Commands; namespace Command.Actions { public class CleanseAction : IAction @@ -10,28 +10,29 @@ 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..deb8463b 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(Command.Commands.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..f2d13015 100644 --- a/Assets/Scripts/Action/Actions/MeditateAction.cs +++ b/Assets/Scripts/Action/Actions/MeditateAction.cs @@ -2,6 +2,7 @@ using Command.Main; using Command.Player; using UnityEngine; +using Command.Commands; namespace Command.Actions { @@ -9,21 +10,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; - - actorUnit.PlayBattleAnimation(ActionType.Meditate, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + this.isSuccessful = isSuccessful; + 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,8 +36,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/Actions/ThirdEyeAction.cs b/Assets/Scripts/Action/Actions/ThirdEyeAction.cs index 8a24ba01..cc8b4597 100644 --- a/Assets/Scripts/Action/Actions/ThirdEyeAction.cs +++ b/Assets/Scripts/Action/Actions/ThirdEyeAction.cs @@ -2,6 +2,7 @@ using Command.Main; using Command.Player; using UnityEngine; +using Command.Commands; namespace Command.Actions { @@ -9,19 +10,20 @@ 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; - - actorUnit.PlayBattleAnimation(ActionType.BerserkAttack, CalculateMovePosition(targetUnit), OnActionAnimationCompleted); + this.isSuccessful = isSuccessful; + 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/ActionType.cs b/Assets/Scripts/Action/CommandType.cs similarity index 73% rename from Assets/Scripts/Action/ActionType.cs rename to Assets/Scripts/Action/CommandType.cs index f6c14302..0a1e430e 100644 --- a/Assets/Scripts/Action/ActionType.cs +++ b/Assets/Scripts/Action/CommandType.cs @@ -1,6 +1,6 @@ -namespace Command.Actions +namespace Command.Commands { - public enum ActionType + public enum CommandType { None, Attack, diff --git a/Assets/Scripts/Action/ActionType.cs.meta b/Assets/Scripts/Action/CommandType.cs.meta similarity index 83% rename from Assets/Scripts/Action/ActionType.cs.meta rename to Assets/Scripts/Action/CommandType.cs.meta index 0c25c443..df5eaadb 100644 --- a/Assets/Scripts/Action/ActionType.cs.meta +++ b/Assets/Scripts/Action/CommandType.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 24ec1f4456a85984898bc624ebcb3f7c +guid: 67003481aa90315478a10967ba738492 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Action/IAction.cs b/Assets/Scripts/Action/IAction.cs index 610560d8..ebc12ccf 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/Battle/BattleService.cs b/Assets/Scripts/Battle/BattleService.cs index 0709f35f..1d9b214f 100644 --- a/Assets/Scripts/Battle/BattleService.cs +++ b/Assets/Scripts/Battle/BattleService.cs @@ -16,7 +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(ReplayButton); + } + + private void ReplayButton() => LoadBattle(currentBattleId); private void LoadBattle(int battleId) { diff --git a/Assets/Scripts/Commands.meta b/Assets/Scripts/Commands.meta new file mode 100644 index 00000000..1d3392cb --- /dev/null +++ b/Assets/Scripts/Commands.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0c5ec2b96cdc7c74aad7d5d4ce44d305 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/AbstractCommands.meta b/Assets/Scripts/Commands/AbstractCommands.meta new file mode 100644 index 00000000..d2eccb2f --- /dev/null +++ b/Assets/Scripts/Commands/AbstractCommands.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 863886b82a0ab444ba3427bfba967c02 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/AbstractCommands/ICommand.cs b/Assets/Scripts/Commands/AbstractCommands/ICommand.cs new file mode 100644 index 00000000..c9bd8e95 --- /dev/null +++ b/Assets/Scripts/Commands/AbstractCommands/ICommand.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Command.Commands +{ + public interface ICommand + { + public void Execute(); + public void Undo(); + } + public class 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; + } + + + } +} diff --git a/Assets/Scripts/Commands/AbstractCommands/ICommand.cs.meta b/Assets/Scripts/Commands/AbstractCommands/ICommand.cs.meta new file mode 100644 index 00000000..5eba8632 --- /dev/null +++ b/Assets/Scripts/Commands/AbstractCommands/ICommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5bc20338a73e1043960d1e4bc230d6e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/AbstractCommands/UnitCommands.cs b/Assets/Scripts/Commands/AbstractCommands/UnitCommands.cs new file mode 100644 index 00000000..2a254f01 --- /dev/null +++ b/Assets/Scripts/Commands/AbstractCommands/UnitCommands.cs @@ -0,0 +1,35 @@ + +using Command.Player; + + +namespace Command.Commands +{ + public abstract class UnitCommands : ICommand + { + public CommandData commandData; + + protected UnitController actorUnit; + protected UnitController targetUnit; + + public abstract void Execute(); + + public abstract bool WillHitTarget(); + + public void SetActorUnit(UnitController actorUnit) + { + this.actorUnit = actorUnit; + } + + public void SetTargetUnit(UnitController targetUnit) + { + this.targetUnit = targetUnit; + } + + + + public UnitController GetActorUnit() => actorUnit; + public UnitController GetTargetUnit() => targetUnit; + + public abstract void Undo(); + } +} diff --git a/Assets/Scripts/Commands/AbstractCommands/UnitCommands.cs.meta b/Assets/Scripts/Commands/AbstractCommands/UnitCommands.cs.meta new file mode 100644 index 00000000..1d0ab857 --- /dev/null +++ b/Assets/Scripts/Commands/AbstractCommands/UnitCommands.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6791915577d6fd04d927814cae9c952c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/CommandData.cs b/Assets/Scripts/Commands/CommandData.cs new file mode 100644 index 00000000..d8c5ae8a --- /dev/null +++ b/Assets/Scripts/Commands/CommandData.cs @@ -0,0 +1,5 @@ + +namespace Assets.Scripts.Commands +{ + +} diff --git a/Assets/Scripts/Commands/CommandData.cs.meta b/Assets/Scripts/Commands/CommandData.cs.meta new file mode 100644 index 00000000..637af35f --- /dev/null +++ b/Assets/Scripts/Commands/CommandData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d1a345a8402296141b19f6d5de9a760e +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..214d7a08 --- /dev/null +++ b/Assets/Scripts/Commands/CommandInvoker.cs @@ -0,0 +1,62 @@ +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Command.Commands; + +public class CommandInvoker +{ + private Stack commandRegistry; + public CommandInvoker() + { + SubscribeToEvents(); + commandRegistry = new Stack(); + } + + public void ProcessCommand(ICommand command) + { + ExecuteCommand(command); + RegisterCommand(command); + } + + public void Undo() + { + + if (RegistryCountCheck() && CheckActivePlayer()) + { + Debug.Log("UndoButtonpressed"); + commandRegistry.Pop().Undo(); + } + } + + private bool RegistryCountCheck() + { + if(commandRegistry.Count > 0) + { + return true; + }return false; + } + + private bool CheckActivePlayer() + { + if((commandRegistry.Peek() as UnitCommands).commandData.ActorPlayerID == GameService.Instance.PlayerService.ActivePlayerID) + { + return true; + } + return false; + } + + private void ExecuteCommand(ICommand command)=>command.Execute(); + private void RegisterCommand(ICommand command)=>commandRegistry.Push(command); + + private void SubscribeToEvents() => GameService.Instance.EventService.OnReplayButtonClicked.AddListener(SetReplayStack); + + private void SetReplayStack() + { + GameService.Instance.ReplayService.SetCommandStack(commandRegistry); + commandRegistry.Clear(); + } + + + +} diff --git a/Assets/Scripts/Commands/CommandInvoker.cs.meta b/Assets/Scripts/Commands/CommandInvoker.cs.meta new file mode 100644 index 00000000..cbb40ba7 --- /dev/null +++ b/Assets/Scripts/Commands/CommandInvoker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 50cc03d0885d4ca4d994473579439186 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands.meta b/Assets/Scripts/Commands/ConcreteCommands.meta new file mode 100644 index 00000000..3e3c9f0d --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 91714cc78160b774fa2b377667622af5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands/Attack.cs b/Assets/Scripts/Commands/ConcreteCommands/Attack.cs new file mode 100644 index 00000000..6caea2d2 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Attack.cs @@ -0,0 +1,40 @@ +using Command.Main; +using Command.Commands; + +namespace Assets.Scripts.Commands.ConcreteCommands +{ + public class Attack: UnitCommands + { + private bool willHitTarget; + + public Attack(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(Command.Commands.CommandType.Attack).PerformAction(actorUnit, targetUnit,willHitTarget); + } + + public override bool WillHitTarget() + { + return true; + } + + public override void Undo() + { + if (willHitTarget) + { + if (!targetUnit.IsAlive()) + { + targetUnit.Revive(); + } + targetUnit.RestoreHealth(actorUnit.CurrentPower); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + + } +} diff --git a/Assets/Scripts/Commands/ConcreteCommands/Attack.cs.meta b/Assets/Scripts/Commands/ConcreteCommands/Attack.cs.meta new file mode 100644 index 00000000..21a0449d --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Attack.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1f5ed67f66086694587356820f7bbabc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands/AttackStance.cs b/Assets/Scripts/Commands/ConcreteCommands/AttackStance.cs new file mode 100644 index 00000000..30c83bde --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/AttackStance.cs @@ -0,0 +1,33 @@ +using Command.Main; +using Command.Commands; + +namespace Assets.Scripts.Commands.ConcreteCommands +{ + public class AttackStance: UnitCommands + { + private bool willHitTarget; + public AttackStance(CommandData commandData) + { + this.commandData=commandData; + willHitTarget = WillHitTarget(); + } + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(Command.Commands.CommandType.AttackStance).PerformAction(actorUnit, targetUnit, willHitTarget); + } + public override bool WillHitTarget() + { + return true; + } + + public override void Undo() + { + if (willHitTarget) + { + targetUnit.CurrentPower -= (int)(targetUnit.CurrentPower * 0.2f); + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + + } +} diff --git a/Assets/Scripts/Commands/ConcreteCommands/AttackStance.cs.meta b/Assets/Scripts/Commands/ConcreteCommands/AttackStance.cs.meta new file mode 100644 index 00000000..e111e4d2 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/AttackStance.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5bca36c5da958ca45996e380824a337d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands/BerserkAttack.cs b/Assets/Scripts/Commands/ConcreteCommands/BerserkAttack.cs new file mode 100644 index 00000000..0c7adb34 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/BerserkAttack.cs @@ -0,0 +1,47 @@ + +using Command.Main; +using Command.Commands; + +namespace Assets.Scripts.Commands.ConcreteCommands +{ + public class BerserkAttack:UnitCommands + { + private bool willHitTarget; + public BerserkAttack(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(Command.Commands.CommandType.BerserkAttack).PerformAction(actorUnit, targetUnit, willHitTarget); + } + public override bool WillHitTarget() + { + return true; + } + + 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(); + } + + } +} diff --git a/Assets/Scripts/Commands/ConcreteCommands/BerserkAttack.cs.meta b/Assets/Scripts/Commands/ConcreteCommands/BerserkAttack.cs.meta new file mode 100644 index 00000000..102ca449 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/BerserkAttack.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0f4111972307514448f2d26b2fd1356b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands/Cleanse.cs b/Assets/Scripts/Commands/ConcreteCommands/Cleanse.cs new file mode 100644 index 00000000..a58dc818 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Cleanse.cs @@ -0,0 +1,34 @@ +using Command.Main; +using Command.Commands; +namespace Assets.Scripts.Commands.ConcreteCommands +{ + public class Cleanse: UnitCommands + { + private bool willHitTarget; + private int previousPower; + public Cleanse(CommandData commandData) + { + this.commandData = commandData; + this.willHitTarget = WillHitTarget(); + } + public override void Execute() + { + previousPower=targetUnit.CurrentPower; + GameService.Instance.ActionService.GetActionByType(Command.Commands.CommandType.Cleanse).PerformAction(actorUnit, targetUnit, willHitTarget); + } + public override bool WillHitTarget() + { + return true; + } + + public override void Undo() + { + if (willHitTarget) + { + targetUnit.CurrentPower = previousPower; + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + + } +} diff --git a/Assets/Scripts/Commands/ConcreteCommands/Cleanse.cs.meta b/Assets/Scripts/Commands/ConcreteCommands/Cleanse.cs.meta new file mode 100644 index 00000000..9a427c84 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Cleanse.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d263cb1bbd7dba349a3400e50e2ca297 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands/Heal.cs b/Assets/Scripts/Commands/ConcreteCommands/Heal.cs new file mode 100644 index 00000000..3c75cb81 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Heal.cs @@ -0,0 +1,42 @@ +using Command.Main; +using Command.Commands; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Assets.Scripts.Commands.ConcreteCommands +{ + public class Heal: UnitCommands + { + private bool willHitTarget; + public Heal(CommandData commandData) + { + this.commandData=commandData; + willHitTarget = WillHitTarget(); + } + + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(Command.Commands.CommandType.Heal).PerformAction(actorUnit, targetUnit, willHitTarget); + } + public override bool WillHitTarget() + { + return true; + } + + public override void Undo() + { + if(willHitTarget) + { + if (targetUnit.CurrentHealth < targetUnit.CurrentMaxHealth) + { + targetUnit.TakeDamage(actorUnit.CurrentPower); + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + } + + } +} diff --git a/Assets/Scripts/Commands/ConcreteCommands/Heal.cs.meta b/Assets/Scripts/Commands/ConcreteCommands/Heal.cs.meta new file mode 100644 index 00000000..c6e194a4 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Heal.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fbb2446917ce87443beff2845c6f7ea5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands/Meditate.cs b/Assets/Scripts/Commands/ConcreteCommands/Meditate.cs new file mode 100644 index 00000000..3d6100ff --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Meditate.cs @@ -0,0 +1,41 @@ +using Command.Main; +using Command.Commands; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Assets.Scripts.Commands.ConcreteCommands +{ + public class Meditate: UnitCommands + { + private bool willHitTarget; + + public Meditate(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(Command.Commands.CommandType.Meditate).PerformAction(actorUnit, targetUnit, willHitTarget); + } + public override bool WillHitTarget() + { + return true; + } + + public override void Undo() + { + if (willHitTarget) + { + var healthToDecrease = (int)(targetUnit.CurrentMaxHealth * 0.2f); + targetUnit.CurrentMaxHealth -= healthToDecrease; + targetUnit.TakeDamage(healthToDecrease); + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + + } +} diff --git a/Assets/Scripts/Commands/ConcreteCommands/Meditate.cs.meta b/Assets/Scripts/Commands/ConcreteCommands/Meditate.cs.meta new file mode 100644 index 00000000..97f669f1 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/Meditate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ecc00a0f21c209843be332f9060fb37d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Commands/ConcreteCommands/ThirdEye.cs b/Assets/Scripts/Commands/ConcreteCommands/ThirdEye.cs new file mode 100644 index 00000000..3e46707f --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/ThirdEye.cs @@ -0,0 +1,34 @@ +using Command.Main; +using Command.Commands; + +namespace Assets.Scripts.Commands.ConcreteCommands +{ + public class ThirdEye: UnitCommands + { + private bool willHitTarget; + public ThirdEye(CommandData commandData) + { + this.commandData = commandData; + willHitTarget = WillHitTarget(); + } + public override void Execute() + { + GameService.Instance.ActionService.GetActionByType(Command.Commands.CommandType.AttackStance).PerformAction(actorUnit, targetUnit, willHitTarget); + } + public override bool WillHitTarget() + { + return true; + } + public override void Undo() + { + if(willHitTarget) + { + int healthToConvert = (int)(targetUnit.CurrentHealth * 0.25f); + targetUnit.RestoreHealth(healthToConvert); + targetUnit.CurrentPower -= healthToConvert; + } + actorUnit.Owner.ResetCurrentActiveUnit(); + } + + } +} diff --git a/Assets/Scripts/Commands/ConcreteCommands/ThirdEye.cs.meta b/Assets/Scripts/Commands/ConcreteCommands/ThirdEye.cs.meta new file mode 100644 index 00000000..8e263245 --- /dev/null +++ b/Assets/Scripts/Commands/ConcreteCommands/ThirdEye.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 924af4d1047a0e341b953c5ae5c5c2ce +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..0afbfef9 100644 --- a/Assets/Scripts/Events/EventService.cs +++ b/Assets/Scripts/Events/EventService.cs @@ -1,4 +1,5 @@ -using Command.Actions; + +using Command.Commands; /** This script demonstrates implementation of the Observer Pattern. * If you're interested in learning about Observer Pattern, @@ -11,12 +12,16 @@ 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..05bc30ca 100644 --- a/Assets/Scripts/Input/InputService.cs +++ b/Assets/Scripts/Input/InputService.cs @@ -1,7 +1,7 @@ using Command.Main; using Command.Player; -using Command.Actions; - +using Command.Commands; +using Assets.Scripts.Commands.ConcreteCommands; namespace Command.Input { public class InputService @@ -9,7 +9,7 @@ public class InputService private MouseInputHandler mouseInputHandler; private InputState currentState; - private ActionType selectedActionType; + private CommandType selectedCommandType; private TargetType targetType; public InputService() @@ -29,9 +29,9 @@ public void UpdateInputService() 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 +43,45 @@ 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 selectedActionType) => targetType = GameService.Instance.ActionService.GetTargetTypeForAction(selectedActionType); public void OnTargetSelected(UnitController targetUnit) { SetInputState(InputState.EXECUTING_INPUT); - GameService.Instance.PlayerService.PerformAction(selectedActionType, targetUnit); + UnitCommands unitCommand=CreateUnitCommand(targetUnit); + GameService.Instance.ProcessUnitCommand(unitCommand); + //GameService.Instance.PlayerService.PerformAction(selectedCommandType, targetUnit); + } + + private UnitCommands CreateUnitCommand(UnitController targetUnit) + { + CommandData commandData = CreateCommandData(targetUnit); + + switch (selectedCommandType) + { + case CommandType.Attack: + return new Attack(commandData); + case CommandType.AttackStance: + return new AttackStance(commandData); + case CommandType.BerserkAttack: + return new BerserkAttack(commandData); + case CommandType.ThirdEye: + return new ThirdEye(commandData); + case CommandType.Heal: + return new Heal(commandData); + case CommandType.Meditate: + return new Meditate(commandData); + case CommandType.Cleanse: + return new Cleanse(commandData); + } + throw new System.Exception("Command Not Found"); } + + private CommandData CreateCommandData(UnitController targetUnit) + { + CommandData newCommandData=new CommandData(GameService.Instance.PlayerService.ActiveUnitID,targetUnit.UnitID,GameService.Instance.PlayerService.ActivePlayerID,targetUnit.Owner.PlayerID); + return newCommandData; + } + } } \ No newline at end of file diff --git a/Assets/Scripts/Main/GameService.cs b/Assets/Scripts/Main/GameService.cs index e8a709be..f5eb8e4e 100644 --- a/Assets/Scripts/Main/GameService.cs +++ b/Assets/Scripts/Main/GameService.cs @@ -8,6 +8,8 @@ using Command.Events; using Command.Battle; using Command.Actions; +using Command.Replay; +using Command.Commands; using UnityEngine.UI; namespace Command.Main @@ -28,6 +30,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 +52,13 @@ 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(UnitCommands unitCommand) => PlayerService.ProcessUnitCommand(unitCommand); } } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 3860582a..48e6ca63 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -1,5 +1,7 @@ +using Command.Main; using System.Collections.Generic; using UnityEngine; +using Command.Commands; namespace Command.Player { @@ -29,6 +31,12 @@ private void CreateUnits(List unitScriptableObjects, List< } } + public void ProcessUnitCommand(UnitCommands unitCommand) + { + GetUnitByID(unitCommand.commandData.ActorUnitID).ProcessUnitCommand(unitCommand); + //GameService.Instance.CommandInvoker.ProcessCommand(unitCommand); + } + public void StartPlayerTurn() { activeUnitIndex = 0; @@ -78,16 +86,29 @@ public void OnUnitTurnEnded() public void DestroyAllUnits() { - units.ForEach(unit => unit.Destroy()); + units.ForEach(unit => unit.DestroyObject()); units.Clear(); } // TODO: What is this?? - public void ResetCurrentActivePlayer() + + public void ResetCurrentActiveUnit() { units[activeUnitIndex].ResetUnitIndicator(); activeUnitIndex--; - units[activeUnitIndex].StartUnitTurn(); + 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..a1de1fde 100644 --- a/Assets/Scripts/Player/PlayerService.cs +++ b/Assets/Scripts/Player/PlayerService.cs @@ -1,5 +1,6 @@ using Command.Actions; using Command.Main; +using Command.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) => GameService.Instance.ActionService.GetActionByType(actionSelected).PerformAction(activePlayer.GetUnitByID(ActiveUnitID), targetUnit,); public void PlayerDied(PlayerController deadPlayer) { @@ -96,5 +97,20 @@ public void CheckGameOver() else if (player2.AllUnitsDead()) PlayerDied(player2); } + + private void SetUnitReferences(UnitCommands unitCommand) + { + var actorUnit = GetPlayerById(unitCommand.commandData.ActorPlayerID).GetUnitByID(unitCommand.commandData.ActorUnitID); + var targetUnit=GetPlayerById(unitCommand.commandData.TargetPlayerID).GetUnitByID(unitCommand.commandData.TargetUnitID); + + unitCommand.SetTargetUnit(targetUnit); + unitCommand.SetActorUnit(actorUnit); + } + + public void ProcessUnitCommand(UnitCommands unitCommand) + { + SetUnitReferences(unitCommand); + GetPlayerById(unitCommand.commandData.ActorPlayerID).ProcessUnitCommand(unitCommand); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Player/Unit/UnitController.cs b/Assets/Scripts/Player/Unit/UnitController.cs index 863dc14f..8c579bd0 100644 --- a/Assets/Scripts/Player/Unit/UnitController.cs +++ b/Assets/Scripts/Player/Unit/UnitController.cs @@ -1,10 +1,9 @@ using UnityEngine; using Command.Main; -using Command.Actions; +using Command.Commands; using System.Collections; using System; using Object = UnityEngine.Object; - namespace Command.Player { public class UnitController @@ -91,19 +90,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 +123,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,19 +146,29 @@ public void OnActionExecuted() public void ResetStats() => CurrentPower = unitScriptableObject.Power; - public void Revive() => SetAliveState(UnitAliveState.ALIVE); - - public void Destroy() => UnityEngine.Object.Destroy(unitView.gameObject); + public void DestroyObject() => Object.Destroy(unitView.gameObject); public void ResetUnitIndicator() => unitView.SetUnitIndicator(false); public Vector3 GetEnemyPosition() { - if (Owner.PlayerID == 1) - return unitView.transform.position + unitScriptableObject.EnemyBattlePositionOffset; - else - return unitView.transform.position - unitScriptableObject.EnemyBattlePositionOffset; + if (unitView != null) + { + if (Owner.PlayerID == 1) + return unitView.transform.position + unitScriptableObject.EnemyBattlePositionOffset; + else + return unitView.transform.position - unitScriptableObject.EnemyBattlePositionOffset; + } + return new Vector3 (0, 0, 0); } + + public void Revive() + { + SetAliveState(UnitAliveState.ALIVE); + unitView.PlayAnimation(UnitAnimations.IDLE); + } + + public void ProcessUnitCommand(UnitCommands 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..6b9fc2fa 100644 --- a/Assets/Scripts/Player/Unit/UnitScriptableObject.cs +++ b/Assets/Scripts/Player/Unit/UnitScriptableObject.cs @@ -1,7 +1,7 @@ using Command.Actions; using System.Collections.Generic; using UnityEngine; - +using Command.Commands; namespace Command.Player { [CreateAssetMenu(fileName = "UnitScriptableObject", menuName = "ScriptableObjects/UnitScriptableObject")] @@ -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/Player/Unit/UnitView.cs b/Assets/Scripts/Player/Unit/UnitView.cs index 863b77ff..412e4ccc 100644 --- a/Assets/Scripts/Player/Unit/UnitView.cs +++ b/Assets/Scripts/Player/Unit/UnitView.cs @@ -16,6 +16,7 @@ private void Awake() unitAnimator = GetComponent(); } + private void Start() { PlayAnimation(UnitAnimations.IDLE); diff --git a/Assets/Scripts/Replay.meta b/Assets/Scripts/Replay.meta new file mode 100644 index 00000000..09bb48b3 --- /dev/null +++ b/Assets/Scripts/Replay.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3177fc16f6f68234781473fe3cc4655f +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..0fac07bf --- /dev/null +++ b/Assets/Scripts/Replay/ReplayService.cs @@ -0,0 +1,47 @@ +using Command.Main; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Command.Commands; + +namespace Command.Replay +{ + public class ReplayService + { + private Stack recordedCommandRegistry; + + public ReplayService() => SetReplayState(ReplayState.DEACTIVE); + + public ReplayState replayState { get; private set; } + + public void SetReplayState(ReplayState replayState) => this.replayState = replayState; + + /* + public void SetCommandStack(Stack commandStack) + { + Debug.Log("Tf the size is:" + commandStack.Count); + recordedCommandRegistry = new Stack(commandStack); + Debug.Log("ff the size is:" + recordedCommandRegistry.Count); + Debug.Log("ff the size is:" + recordedCommandRegistry.Count); + + } + */ + + public void SetCommandStack(Stack commandsToSet) => recordedCommandRegistry = new Stack(commandsToSet); + public IEnumerator ExecuteNext() + { + yield return new WaitForSeconds(1); + if (recordedCommandRegistry.Count > 0) + { + GameService.Instance.ProcessUnitCommand(recordedCommandRegistry.Pop() as UnitCommands); + } + } + + } + public enum ReplayState + { + DEACTIVE, + ACTIVE + } + +} diff --git a/Assets/Scripts/Replay/ReplayService.cs.meta b/Assets/Scripts/Replay/ReplayService.cs.meta new file mode 100644 index 00000000..51bc55dd --- /dev/null +++ b/Assets/Scripts/Replay/ReplayService.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af781e10ff62d4f46ab5ab98740d083e +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..f11dd3fa 100644 --- a/Assets/Scripts/UI/ActionSelectionUI/ActionButtonView.cs +++ b/Assets/Scripts/UI/ActionSelectionUI/ActionButtonView.cs @@ -1,4 +1,5 @@ -using Command.Actions; + +using Command.Commands; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -9,7 +10,7 @@ public class ActionButtonView : MonoBehaviour { [SerializeField] private TextMeshProUGUI buttonText; private ActionSelectionUIController owner; - private ActionType actionType; + private CommandType actionType; private void Start() => GetComponent