Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,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
Expand Down Expand Up @@ -1445,6 +1445,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 53b82781cf2fb9a4aa3b0d3e0a71f056, type: 3}
m_Name:
m_EditorClassIdentifier:
undoButton: {fileID: 101671528}
turnText: {fileID: 144807538}
missedText: {fileID: 1222372628}
Player1BackgroundOverlay: {fileID: 1242843364}
Expand Down Expand Up @@ -1885,7 +1886,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.23529412}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
Expand Down Expand Up @@ -2376,7 +2377,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.23529412}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
Expand Down Expand Up @@ -2787,6 +2788,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
resultText: {fileID: 1682630446}
homeButton: {fileID: 799045267}
replayButton: {fileID: 988327835}
--- !u!1 &2089575972
GameObject:
m_ObjectHideFlags: 0
Expand Down
23 changes: 12 additions & 11 deletions Assets/Scripts/Action/ActionService.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
using Command.Input;
using Command.Commands;
using System.Collections.Generic;

namespace Command.Actions
{
public class ActionService
{
private Dictionary<ActionType, IAction> actions;
private Dictionary<CommandType, IAction> actions;

public ActionService() => CreateActions();

private void CreateActions()
{
actions = new Dictionary<ActionType, IAction>();
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<CommandType, IAction>();
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];
else
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;
}
}
11 changes: 6 additions & 5 deletions Assets/Scripts/Action/Actions/AttackAction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Command.Commands;
using Command.Input;
using Command.Main;
using Command.Player;
Expand All @@ -9,28 +10,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();

private void PlayAttackSound()
Expand Down
11 changes: 6 additions & 5 deletions Assets/Scripts/Action/Actions/AttackStanceAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Command.Player;
using Command.Input;
using Command.Main;
using Command.Commands;
using UnityEngine;

namespace Command.Actions
Expand All @@ -9,28 +10,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();
}
}
14 changes: 8 additions & 6 deletions Assets/Scripts/Action/Actions/BerserkAttackAction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Command.Commands;
using Command.Input;
using Command.Main;
using Command.Player;
Expand All @@ -7,34 +8,35 @@ namespace Command.Actions
{
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
{
actorUnit.TakeDamage(actorUnit.CurrentPower * 2);
actorUnit.OnActionExecuted();
Debug.Log("actor unit must be hit now.");
}
}

public bool IsSuccessful() => Random.Range(0f, 1f) < hitChance;

public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition();
}
}
13 changes: 7 additions & 6 deletions Assets/Scripts/Action/Actions/CleanseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
using Command.Player;
using Command.Main;
using UnityEngine;
using Command.Commands;

namespace Command.Actions
{
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();
}
}
11 changes: 6 additions & 5 deletions Assets/Scripts/Action/Actions/HealAction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Command.Commands;
using Command.Input;
using Command.Main;
using Command.Player;
Expand All @@ -9,26 +10,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();
}
}
12 changes: 7 additions & 5 deletions Assets/Scripts/Action/Actions/MeditateAction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Command.Commands;
using Command.Input;
using Command.Main;
using Command.Player;
Expand All @@ -9,21 +10,24 @@ 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;
Expand All @@ -33,8 +37,6 @@ public void OnActionAnimationCompleted()
GameService.Instance.UIService.ActionMissed();
}

public bool IsSuccessful() => true;

public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition();
}
}
12 changes: 7 additions & 5 deletions Assets/Scripts/Action/Actions/ThirdEyeAction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Command.Commands;
using Command.Input;
using Command.Main;
using Command.Player;
Expand All @@ -9,19 +10,22 @@ 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);
Expand All @@ -31,8 +35,6 @@ public void OnActionAnimationCompleted()
GameService.Instance.UIService.ActionMissed();
}

public bool IsSuccessful() => true;

public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition();
}
}
4 changes: 1 addition & 3 deletions Assets/Scripts/Action/IAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading