Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Primed Thrusters upgrade #853

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
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
99 changes: 99 additions & 0 deletions Assets/Scripts/Model/Upgrades/Tech/PrimedThrusters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Upgrade;
using Abilities;
using Ship;
using Tokens;
using ActionsList;
using Movement;
using System.Linq;


namespace UpgradesList
{

public class PrimedThrusters : GenericUpgrade
{
public PrimedThrusters() : base()
{
Types.Add(UpgradeType.Tech);
Name = "Primed Thrusters";
Cost = 1;

UpgradeAbilities.Add(new PrimedThrustersAbility());
}
public override bool IsAllowedForShip(GenericShip ship)
{
return ship.ShipBaseSize == BaseSize.Small;
}
}

}

namespace Abilities
{
public class PrimedThrustersAbility : GenericAbility
{

//Stress Tokens do not prevent you from performing boost or barrel roll actions
//unless you have 3 or more stress tokens.
public override void ActivateAbility()
{
HostShip.OnActionSubPhaseStart += PrimedThrustersBonus;
}

public override void DeactivateAbility()
{
HostShip.OnActionSubPhaseStart -= PrimedThrustersBonus;
}

private void PrimedThrustersBonus(GenericShip ship)
{
//Workaround for Red manuevers skipping actions because of stress
if (ship.AssignedManeuver.ColorComplexity == Movement.ManeuverColor.Red && ship.Tokens.CountTokensByType (typeof(Tokens.StressToken)) < 3)
{
RegisterAbilityTrigger(TriggerTypes.OnShipMovementExecuted, PerformFreeAction);
}

//Allow to perform boost or barrel roll actions even while stressed
ship.OnTryAddAvailableAction -= Rules.Stress.CanPerformActions;
ship.OnTryAddAvailableAction += CanPerformActions;
}

private void PerformFreeAction(object sender, System.EventArgs e)
{

List<GenericAction> freeActions = new List<GenericAction> ();

if (HostShip.GetAvailablePrintedActionsList().Any (n => n.GetType () == typeof(ActionsList.BoostAction)) || HostShip.GetAvailableFreeActionsList().Any( n => n.GetType () == typeof(ActionsList.BarrelRollAction)) ) {
freeActions.Add (new BoostAction ());
}
if (HostShip.GetAvailablePrintedActionsList().Any (n => n.GetType () == typeof(ActionsList.BarrelRollAction)) || HostShip.GetAvailableFreeActionsList().Any( n => n.GetType () == typeof(ActionsList.BarrelRollAction)) ) {
freeActions.Add (new BarrelRollAction ());
}

HostShip.AskPerformFreeAction(freeActions, Triggers.FinishTrigger);
}

public void CanPerformActions (GenericAction action, ref bool result)
{

if (action.Name == "Barrel Roll" || action.Name == "Boost") {
if (HostShip.Tokens.CountTokensByType (typeof(Tokens.StressToken)) < 3) {
result = true;
} else {
Messages.ShowError ("Primed Thrusters: Can't have 3 or more Stress tokens");
result = Selection.ThisShip.CanPerformActionsWhileStressed || action.CanBePerformedWhileStressed;
}
} else {
if (HostShip.Tokens.GetToken (typeof(StressToken)) != null) {
result = Selection.ThisShip.CanPerformActionsWhileStressed || action.CanBePerformedWhileStressed;
}
}
}

}

}
13 changes: 13 additions & 0 deletions Assets/Scripts/Model/Upgrades/Tech/PrimedThrusters.cs.meta

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