AttackBase porting
This commit is contained in:
@@ -16,6 +16,7 @@ namespace OpenRa.Game.Traits
|
||||
public readonly int[] PrimaryOffset = { 0, 0 };
|
||||
public readonly int[] SecondaryOffset = null;
|
||||
public readonly bool MuzzleFlash = false;
|
||||
public readonly int FireDelay = 0;
|
||||
|
||||
public virtual object Create(Actor self) { return new AttackBase(self); }
|
||||
}
|
||||
@@ -37,8 +38,10 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
public AttackBase(Actor self)
|
||||
{
|
||||
var primaryWeapon = self.LegacyInfo.Primary != null ? Rules.WeaponInfo[self.LegacyInfo.Primary] : null;
|
||||
var secondaryWeapon = self.LegacyInfo.Secondary != null ? Rules.WeaponInfo[self.LegacyInfo.Secondary] : null;
|
||||
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||
|
||||
var primaryWeapon = info.PrimaryWeapon != null ? Rules.WeaponInfo[info.PrimaryWeapon] : null;
|
||||
var secondaryWeapon = info.SecondaryWeapon != null ? Rules.WeaponInfo[info.SecondaryWeapon] : null;
|
||||
|
||||
primaryBurst = primaryWeapon != null ? primaryWeapon.Burst : 1;
|
||||
secondaryBurst = secondaryWeapon != null ? secondaryWeapon.Burst : 1;
|
||||
@@ -87,19 +90,20 @@ namespace OpenRa.Game.Traits
|
||||
public void DoAttack(Actor self)
|
||||
{
|
||||
var unit = self.traits.GetOrDefault<Unit>();
|
||||
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||
|
||||
if (self.LegacyInfo.Primary != null && CheckFire(self, unit, self.LegacyInfo.Primary, ref primaryFireDelay,
|
||||
self.LegacyInfo.PrimaryOffset, ref primaryBurst, self.LegacyInfo.PrimaryLocalOffset))
|
||||
if (info.PrimaryWeapon != null && CheckFire(self, unit, info.PrimaryWeapon, ref primaryFireDelay,
|
||||
info.PrimaryOffset, ref primaryBurst, info.PrimaryLocalOffset))
|
||||
{
|
||||
secondaryFireDelay = Math.Max(4, secondaryFireDelay);
|
||||
primaryRecoil = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.LegacyInfo.Secondary != null && CheckFire(self, unit, self.LegacyInfo.Secondary, ref secondaryFireDelay,
|
||||
self.LegacyInfo.SecondaryOffset ?? self.LegacyInfo.PrimaryOffset, ref secondaryBurst, self.LegacyInfo.SecondaryLocalOffset))
|
||||
if (info.SecondaryWeapon != null && CheckFire(self, unit, info.SecondaryWeapon, ref secondaryFireDelay,
|
||||
info.SecondaryOffset ?? info.PrimaryOffset, ref secondaryBurst, info.SecondaryLocalOffset))
|
||||
{
|
||||
if (self.LegacyInfo.SecondaryOffset != null) secondaryRecoil = 1;
|
||||
if (info.SecondaryOffset != null) secondaryRecoil = 1;
|
||||
else primaryRecoil = 1;
|
||||
return;
|
||||
}
|
||||
@@ -140,8 +144,9 @@ namespace OpenRa.Game.Traits
|
||||
var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, fireOffset, 0f).ToInt2();
|
||||
var thisTarget = target; // closure.
|
||||
var destUnit = thisTarget.traits.GetOrDefault<Unit>();
|
||||
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||
|
||||
ScheduleDelayedAction(self.LegacyInfo.FireDelay, () =>
|
||||
ScheduleDelayedAction(info.FireDelay, () =>
|
||||
{
|
||||
var srcAltitude = unit != null ? unit.Altitude : 0;
|
||||
var destAltitude = destUnit != null ? destUnit.Altitude : 0;
|
||||
@@ -175,10 +180,14 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
if (mi.Button == MouseButton.Left || underCursor == null) return null;
|
||||
if (self == underCursor) return null;
|
||||
var isHeal = Rules.WeaponInfo[self.LegacyInfo.Primary].Damage < 0;
|
||||
|
||||
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||
var isHeal = Rules.WeaponInfo[info.PrimaryWeapon].Damage < 0;
|
||||
if (((underCursor.Owner == self.Owner) ^ isHeal)
|
||||
&& !mi.Modifiers.HasModifier( Modifiers.Ctrl )) return null;
|
||||
|
||||
if (!Combat.HasAnyValidWeapons(self, underCursor)) return null;
|
||||
|
||||
return new Order(isHeal ? "Heal" : "Attack", self, underCursor, int2.Zero, null);
|
||||
}
|
||||
|
||||
@@ -198,9 +207,10 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
protected virtual void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
|
||||
/* todo: choose the appropriate weapon, when only one works against this target */
|
||||
var weapon = order.Subject.LegacyInfo.Primary ?? order.Subject.LegacyInfo.Secondary;
|
||||
var weapon = info.PrimaryWeapon ?? info.SecondaryWeapon;
|
||||
|
||||
self.QueueActivity(new Activities.Attack(order.TargetActor,
|
||||
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));
|
||||
|
||||
Reference in New Issue
Block a user