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
22 changes: 11 additions & 11 deletions Assets/Scripts/Action/ActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ 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;
}
}
2 changes: 1 addition & 1 deletion Assets/Scripts/Action/ActionType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Command.Actions
{
public enum ActionType
public enum CommandType
{
None,
Attack,
Expand Down
9 changes: 5 additions & 4 deletions Assets/Scripts/Action/Actions/AttackAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Action/Actions/AttackStanceAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
10 changes: 5 additions & 5 deletions Assets/Scripts/Action/Actions/BerserkAttackAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -33,8 +35,6 @@ public void OnActionAnimationCompleted()
}
}

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

public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition();
}
}
10 changes: 5 additions & 5 deletions Assets/Scripts/Action/Actions/CleanseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
10 changes: 5 additions & 5 deletions Assets/Scripts/Action/Actions/HealAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
9 changes: 5 additions & 4 deletions Assets/Scripts/Action/Actions/MeditateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +35,6 @@ public void OnActionAnimationCompleted()
GameService.Instance.UIService.ActionMissed();
}

public bool IsSuccessful() => true;

public Vector3 CalculateMovePosition(UnitController targetUnit) => targetUnit.GetEnemyPosition();
}
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Action/Actions/ThirdEyeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -31,8 +33,6 @@ public void OnActionAnimationCompleted()
GameService.Instance.UIService.ActionMissed();
}

public bool IsSuccessful() => true;

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Assets/Scripts/Command/AttackCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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);
}
}
}

11 changes: 11 additions & 0 deletions Assets/Scripts/Command/AttackCommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Assets/Scripts/Command/AttackStanceCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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);
}
}
}

11 changes: 11 additions & 0 deletions Assets/Scripts/Command/AttackStanceCommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading