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

Added terror drone interaction with vehicles #709

Open
wants to merge 2 commits into
base: master
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
162 changes: 162 additions & 0 deletions OpenRA.Mods.RA2/Activities/Infect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA2.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.RA2.Activities
{
class Infect : Enter
{
readonly AttackInfect attackInfect;
readonly Target target;

bool isPlayingInfectAnimation;

public Infect(Actor self, Target target, AttackInfect attackInfect, Color? targetLineColor)
: base(self, target, targetLineColor)
{
this.target = target;
this.attackInfect = attackInfect;
}

protected override void OnFirstRun(Actor self)
{
attackInfect.IsAiming = true;
}

protected override void OnLastRun(Actor self)
{
attackInfect.IsAiming = false;
}

protected override void OnEnterComplete(Actor self, Actor targetActor)
{
self.World.AddFrameEndTask(w =>
{
if (self.IsDead || attackInfect.IsTraitDisabled)
return;

if (isPlayingInfectAnimation)
{
attackInfect.RevokeJoustCondition(self);
isPlayingInfectAnimation = false;
}

attackInfect.DoAttack(self, target);

var infectable = targetActor.TraitOrDefault<Infectable>();
if (infectable == null || infectable.IsTraitDisabled || infectable.Infector != null)
return;

w.Remove(self);

infectable.Infector = self;
infectable.AttackInfect = attackInfect;

infectable.FirepowerMultipliers = self.TraitsImplementing<IFirepowerModifier>()
.Select(a => a.GetFirepowerModifier()).ToArray();

var info = attackInfect.InfectInfo;
infectable.Ticks = info.DamageInterval;
infectable.GrantCondition(targetActor);
infectable.RevokeCondition(targetActor, self);
});
}

void CancelInfection(Actor self)
{
if (isPlayingInfectAnimation)
{
attackInfect.RevokeJoustCondition(self);
isPlayingInfectAnimation = false;
}

if (target.Type != TargetType.Actor)
return;

if (target.Actor.IsDead)
return;

var infectable = target.Actor.TraitOrDefault<Infectable>();
if (infectable == null || infectable.IsTraitDisabled || infectable.Infector != null)
return;

infectable.RevokeCondition(target.Actor, self);
}

bool IsValidInfection(Actor self, Actor targetActor)
{
if (attackInfect.IsTraitDisabled)
return false;

if (targetActor.IsDead)
return false;

if (!target.IsValidFor(self) || !attackInfect.HasAnyValidWeapons(target))
return false;

var infectable = targetActor.TraitOrDefault<Infectable>();
if (infectable == null || infectable.IsTraitDisabled || infectable.Infector != null)
return false;

return true;
}

bool CanStartInfect(Actor self, Actor targetActor)
{
if (!IsValidInfection(self, targetActor))
return false;

// IsValidInfection validated the lookup, no need to check here.
var infectable = targetActor.Trait<Infectable>();
return infectable.TryStartInfecting(targetActor, self);
}

protected override bool TryStartEnter(Actor self, Actor targetActor)
{
var canStartInfect = CanStartInfect(self, targetActor);
if (!canStartInfect)
{
CancelInfection(self);
Cancel(self, true);
}

// Can't leap yet
if (attackInfect.Armaments.All(a => a.IsReloading))
return false;

return true;
}

protected override void TickInner(Actor self, in Target target, bool targetIsDeadOrHiddenActor)
{
if (target.Type != TargetType.Actor || !IsValidInfection(self, target.Actor))
{
CancelInfection(self);
Cancel(self, true);
return;
}

var info = attackInfect.InfectInfo;
if (!isPlayingInfectAnimation && !IsCanceling && (self.CenterPosition - target.CenterPosition).Length < info.JumpRange.Length)
{
isPlayingInfectAnimation = true;
attackInfect.GrantJoustCondition(self);
IsInterruptible = false;
}
}
}
}
87 changes: 87 additions & 0 deletions OpenRA.Mods.RA2/Traits/AttackInfect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA2.Activities;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.RA2.Traits
{
[Desc("Move onto the target then execute the attack.")]
public class AttackInfectInfo : AttackFrontalInfo, Requires<MobileInfo>
{
[Desc("Range of the final jump of the infector.")]
public readonly WDist JumpRange = WDist.Zero;

[Desc("Conditions that last from start of the joust until the attack.")]
[GrantedConditionReference]
public readonly string JumpCondition = "jumping";

[FieldLoader.Require]
[Desc("How much damage to deal.")]
public readonly int Damage = 0;

[FieldLoader.Require]
[Desc("How often to deal the damage.")]
public readonly int DamageInterval = 0;

[Desc("Damage types for the infection damage.")]
public readonly BitSet<DamageType> DamageTypes = default(BitSet<DamageType>);

[Desc("Damage types which allows the infector survive when it's host dies.")]
public readonly BitSet<DamageType> SurviveHostDamageTypes = default(BitSet<DamageType>);

public override object Create(ActorInitializer init) { return new AttackInfect(init.Self, this); }
}

public class AttackInfect : AttackFrontal
{
public readonly AttackInfectInfo InfectInfo;

int joustToken = Actor.InvalidConditionToken;

public AttackInfect(Actor self, AttackInfectInfo info)
: base(self, info)
{
InfectInfo = info;
}

protected override bool CanAttack(Actor self, in Target target)
{
if (target.Type != TargetType.Actor)
return false;

if (self.Location == target.Actor.Location && HasAnyValidWeapons(target))
return true;

return base.CanAttack(self, target);
}

public void GrantJoustCondition(Actor self)
{
if (!string.IsNullOrEmpty(InfectInfo.JumpCondition))
joustToken = self.GrantCondition(InfectInfo.JumpCondition);
}

public void RevokeJoustCondition(Actor self)
{
if (joustToken != Actor.InvalidConditionToken)
joustToken = self.RevokeCondition(joustToken);
}

public override Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
{
return new Infect(self, newTarget, this, targetLineColor);
}
}
}
Loading