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
242 changes: 239 additions & 3 deletions Assets/Scripts/Model/Upgrades/Elite/Daredevil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
using Upgrade;
using UnityEngine;
using Abilities;
using ActionsList;
using GameModes;
using Ship;
using SubPhases;
using System;
using System.Linq;
using Tokens;
using Upgrade;

namespace UpgradesList
{
Expand All @@ -11,7 +18,236 @@ public Daredevil() : base()
Name = "Daredevil";
Cost = 3;

IsHidden = true;
UpgradeAbilities.Add(new DaredevilAbility());
}
}
}

namespace Abilities
{
public class DaredevilAbility : GenericAbility
{
public override void ActivateAbility()
{
HostShip.AfterGenerateAvailableActionsList += DaredevilAddAction;
}

public override void DeactivateAbility()
{
HostShip.AfterGenerateAvailableActionsList -= DaredevilAddAction;
}

private void DaredevilAddAction(GenericShip host)
{
GenericAction newAction = new DaredevilAction
{
ImageUrl = HostUpgrade.ImageUrl,
Host = HostShip
};
host.AddAvailableAction(newAction);
}
}
}

namespace ActionsList
{
public class DaredevilAction : GenericAction
{
private bool _hasOneTurns = false;

public DaredevilAction()
{
Name = EffectName = "Daredevil";
}

public override void ActionTake()
{
Phases.CurrentSubPhase.Pause();

Triggers.RegisterTrigger(new Trigger
{
Name = "Daredevil turn",
TriggerType = TriggerTypes.OnAbilityDirect,
TriggerOwner = Selection.ThisShip.Owner.PlayerNo,
EventHandler = SelectDaredevilManeuver
});

Triggers.ResolveTriggers(TriggerTypes.OnAbilityDirect, RegisterDaredevilExecutionTrigger);
}

private void SelectDaredevilManeuver(object sender, EventArgs e)
{
TryAddManeuversForDaredevil("1.L.T");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to add maneuvers temporarily to a ship?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is first ability that requires this.
But maybe this will be needed to add Ryad and Juno Eclipse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into implementing a more usable solution.

TryAddManeuversForDaredevil("1.R.T");

Selection.ThisShip.Owner.SelectManeuver(GameMode.CurrentGameMode.AssignManeuver, IsOneTurn);
}

private void RegisterDaredevilExecutionTrigger()
{
Triggers.RegisterTrigger(new Trigger
{
Name = "Daredevil Execution",
TriggerType = TriggerTypes.OnManeuver,
TriggerOwner = Selection.ThisShip.Owner.PlayerNo,
EventHandler = PerformDaredevilManeuver
});

Triggers.ResolveTriggers(TriggerTypes.OnManeuver, ReceiveStress);
}

private void PerformDaredevilManeuver(object sender, EventArgs e)
{
Messages.ShowInfoToHuman(string.Format("Performing Daredevil: {0} receives one stress token", Selection.ThisShip.PilotName));
Selection.ThisShip.AssignedManeuver.Perform();

if (!_hasOneTurns)
{
RemoveManeuversForDaredevil("1.L.T");
RemoveManeuversForDaredevil("1.R.T");
}
}

private void ReceiveStress()
{
Selection.ThisShip.Tokens.AssignToken(new StressToken(Selection.ThisShip), DoesHaveBoost);
}

private void DoesHaveBoost()
{
if (Selection.ThisShip.GetAvailableActionsList().Any(action => action is BoostAction))
{
PhaseCleanup();
}
else
{
Messages.ShowInfoToHuman("This ship does not have the boost action, rolling for damage");
DiceRollCheck(
delegate
{
Phases.FinishSubPhase(typeof(DaredevilSubPhase));
PhaseCleanup();
});
}
}

private void PhaseCleanup()
{
Phases.FinishSubPhase(typeof(ActionDecisonSubPhase));
Triggers.FinishTrigger();
}

private void DiceRollCheck(Action callback)
{
Selection.ActiveShip = Selection.ThisShip;
DaredevilSubPhase dieSubPhase = (DaredevilSubPhase)Phases.StartTemporarySubPhaseNew(
Name,
typeof(DaredevilSubPhase),
callback);

dieSubPhase.RequiredPlayer = Selection.ThisShip.Owner.PlayerNo;
dieSubPhase.Start();
}

private void TryAddManeuversForDaredevil(string maneuver)
{
if (Selection.ThisShip.Maneuvers.ContainsKey(maneuver))
{
_hasOneTurns = true;
return;
}
Selection.ThisShip.Maneuvers.Add(maneuver, Movement.ManeuverColor.White);
}

private void RemoveManeuversForDaredevil(string maneuver)
{
Selection.ThisShip.Maneuvers.Remove(maneuver);
}

private bool IsOneTurn(string maneuverString)
{
bool result = true;
Movement.MovementStruct movement = new Movement.MovementStruct(maneuverString);
if (movement.Speed != Movement.ManeuverSpeed.Speed1)
{
result = false;
}

if (movement.Bearing != Movement.ManeuverBearing.Turn)
{
result = false;
}

return result;
}

public override int GetActionPriority()
{
int result = 0;
return result;
}
}
}

namespace SubPhases
{
public class DaredevilSubPhase : DiceRollCheckSubPhase
{
public override void Prepare()
{
diceType = DiceKind.Attack;
diceCount = 2;

finishAction = FinishAction;
}

protected override void FinishAction()
{
HideDiceResultMenu();

CurrentDiceRoll.RemoveAllFailures();
if (!CurrentDiceRoll.IsEmpty)
{
foreach (Die die in CurrentDiceRoll.DiceList)
{
if (die.Side == DieSide.Crit || die.Side == DieSide.Success)
{
SufferDamage();
break;
}
}
}

CallBack();
}

private void NoDamage()
{
CallBack();
}

private void SufferDamage()
{
for (int i = 0; i < CurrentDiceRoll.DiceList.Count; i++)
{
Selection.ActiveShip.AssignedDamageDiceroll.AddDice(CurrentDiceRoll.DiceList[i].Side);

Triggers.RegisterTrigger(new Trigger()
{
Name = "Suffer Daredevil damage",
TriggerType = TriggerTypes.OnDamageIsDealt,
TriggerOwner = Selection.ActiveShip.Owner.PlayerNo,
EventHandler = Selection.ActiveShip.SufferDamage,
EventArgs = new DamageSourceEventArgs()
{
Source = "Daredevil",
DamageType = DamageTypes.CardAbility
},
Skippable = true
});
}

Triggers.ResolveTriggers(TriggerTypes.OnDamageIsDealt, Phases.CurrentSubPhase.Resume);
}
}
}
124 changes: 124 additions & 0 deletions Assets/Scripts/Model/Upgrades/Elite/Decoy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using Abilities;
using Board;
using Ship;
using SubPhases;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Upgrade;

namespace UpgradesList
{
public class Decoy : GenericUpgrade
{
public Decoy() : base()
{
Type = UpgradeType.Elite;
Name = "Decoy";
Cost = 1;

UpgradeAbilities.Add(new DecoyAbility());
}
}
}

namespace Abilities
{
//At the start of the Combat phase, you may choose 1 friendly ship at Range 1-2.
//Exchange your pilot skill with that ship's pilot skill until end of the phase.
public class DecoyAbility : GenericAbility
{
FriendlyPilotSkillModifier _hostShip;
FriendlyPilotSkillModifier _friendlyShip;

public override void ActivateAbility()
{
Phases.OnCombatPhaseStart += CheckTrigger;

Phases.OnCombatPhaseEnd += RegisterPilotSkillReset;
}

public override void DeactivateAbility()
{
Phases.OnCombatPhaseStart -= CheckTrigger;

Phases.OnCombatPhaseEnd -= RegisterPilotSkillReset;
}

private void CheckTrigger()
{
List<GenericShip> shipsInRange = BoardManager.GetShipsAtRange(HostShip, new Vector2(1, 2), Team.Type.Friendly);
shipsInRange.Remove(HostShip);

if (shipsInRange.Count <= 0)
{
return;
}

RegisterAbilityTrigger(TriggerTypes.OnCombatPhaseStart, delegate { AskToSwapPilotSkills(shipsInRange); });
}

private void RegisterPilotSkillReset()
{
RegisterAbilityTrigger(TriggerTypes.OnCombatPhaseEnd, ResetPilotSkills);
}

private void ResetPilotSkills(object sender, EventArgs e)
{
_hostShip.RemoveModifier();
_friendlyShip.RemoveModifier();

_friendlyShip = null;
_hostShip = null;

Triggers.FinishTrigger();
}

private void AskToSwapPilotSkills(List<GenericShip> shipsInRange)
{
SelectTargetForAbility(SwitchPilotSkills, new List<TargetTypes> { TargetTypes.OtherFriendly }, new Vector2(1, 2), Triggers.FinishTrigger);
}

private void SwitchPilotSkills()
{
_hostShip = new FriendlyPilotSkillModifier(HostShip, TargetShip.PilotSkill);
_friendlyShip = new FriendlyPilotSkillModifier(TargetShip, HostShip.PilotSkill);

_hostShip.AddPilotSkill();
_friendlyShip.AddPilotSkill();

Messages.ShowInfoToHuman(string.Format("Swapped pilot skills of {0} and {1}",
HostShip.PilotName, TargetShip.PilotName));

DecisionSubPhase.ConfirmDecision();
}

private class FriendlyPilotSkillModifier : IModifyPilotSkill
{
private GenericShip _host;
private int _newPilotSkill;

public FriendlyPilotSkillModifier(GenericShip host, int newPilotSkill)
{
_host = host;
_newPilotSkill = newPilotSkill;
}

public void AddPilotSkill()
{
_host.AddPilotSkillModifier(this);
}

public void ModifyPilotSkill(ref int pilotSkill)
{
pilotSkill = _newPilotSkill;
}

public void RemoveModifier()
{
_host.RemovePilotSkillModifier(this);
}
}
}
}
13 changes: 13 additions & 0 deletions Assets/Scripts/Model/Upgrades/Elite/Decoy.cs.meta

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

Loading