Initial support for individual unit upgrade crates
This commit is contained in:
51
OpenRA.Mods.RA/Crates/UnitUpgradeCrateAction.cs
Normal file
51
OpenRA.Mods.RA/Crates/UnitUpgradeCrateAction.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 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. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Crates
|
||||||
|
{
|
||||||
|
public class UnitUpgradeCrateActionInfo : CrateActionInfo
|
||||||
|
{
|
||||||
|
public readonly UnitUpgrade? Upgrade = null;
|
||||||
|
public readonly int Levels = 1;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new UnitUpgradeCrateAction(init.self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UnitUpgradeCrateAction : CrateAction
|
||||||
|
{
|
||||||
|
UnitUpgradeCrateActionInfo crateInfo;
|
||||||
|
|
||||||
|
public UnitUpgradeCrateAction(Actor self, UnitUpgradeCrateActionInfo info)
|
||||||
|
: base(self, info)
|
||||||
|
{
|
||||||
|
crateInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetSelectionShares(Actor collector)
|
||||||
|
{
|
||||||
|
var up = collector.TraitOrDefault<GainsUnitUpgrades>();
|
||||||
|
return up != null && up.CanGainUnitUpgrade(crateInfo.Upgrade) ? info.SelectionShares : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Activate(Actor collector)
|
||||||
|
{
|
||||||
|
collector.World.AddFrameEndTask(w =>
|
||||||
|
{
|
||||||
|
var gainsStatBonuses = collector.TraitOrDefault<GainsUnitUpgrades>();
|
||||||
|
if (gainsStatBonuses != null)
|
||||||
|
gainsStatBonuses.GiveUnitUpgrade(crateInfo.Upgrade, crateInfo.Levels);
|
||||||
|
});
|
||||||
|
|
||||||
|
base.Activate(collector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
86
OpenRA.Mods.RA/GainsUnitUpgrades.cs
Normal file
86
OpenRA.Mods.RA/GainsUnitUpgrades.cs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 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. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
public class GainsUnitUpgradesInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public readonly int FirepowerMaxLevel = 15;
|
||||||
|
public readonly float FirepowerModifier = .2f;
|
||||||
|
public readonly int ArmorMaxLevel = 15;
|
||||||
|
public readonly float ArmorModifier = .2f;
|
||||||
|
public readonly int SpeedMaxLevel = 15;
|
||||||
|
public readonly decimal SpeedModifier = .2m;
|
||||||
|
// TODO: weapon range, rate of fire modifiers. potentially a vision modifier.
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new GainsUnitUpgrades(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GainsUnitUpgrades : IFirepowerModifier, IDamageModifier, ISpeedModifier
|
||||||
|
{
|
||||||
|
GainsUnitUpgradesInfo info;
|
||||||
|
[Sync] public int FirepowerLevel = 0;
|
||||||
|
[Sync] public int SpeedLevel = 0;
|
||||||
|
[Sync] public int ArmorLevel = 0;
|
||||||
|
|
||||||
|
public GainsUnitUpgrades(GainsUnitUpgradesInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanGainUnitUpgrade(UnitUpgrade? upgrade)
|
||||||
|
{
|
||||||
|
if (upgrade == UnitUpgrade.Firepower)
|
||||||
|
return FirepowerLevel < info.FirepowerMaxLevel;
|
||||||
|
if (upgrade == UnitUpgrade.Armor)
|
||||||
|
return ArmorLevel < info.ArmorMaxLevel;
|
||||||
|
if (upgrade == UnitUpgrade.Speed)
|
||||||
|
return SpeedLevel < info.SpeedMaxLevel;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GiveUnitUpgrade(UnitUpgrade? upgrade, int numLevels)
|
||||||
|
{
|
||||||
|
if (upgrade == UnitUpgrade.Firepower)
|
||||||
|
FirepowerLevel = Math.Min(FirepowerLevel + numLevels, info.FirepowerMaxLevel);
|
||||||
|
else if (upgrade == UnitUpgrade.Armor)
|
||||||
|
ArmorLevel = Math.Min(ArmorLevel + numLevels, info.ArmorMaxLevel);
|
||||||
|
else if (upgrade == UnitUpgrade.Speed)
|
||||||
|
SpeedLevel = Math.Min(SpeedLevel + numLevels, info.SpeedMaxLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetFirepowerModifier()
|
||||||
|
{
|
||||||
|
return FirepowerLevel > 0 ? (1 + FirepowerLevel * info.FirepowerModifier) : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetDamageModifier(Actor attacker, WarheadInfo warhead)
|
||||||
|
{
|
||||||
|
return ArmorLevel > 0 ? (1 / (1 + ArmorLevel * info.ArmorModifier)) : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public decimal GetSpeedModifier()
|
||||||
|
{
|
||||||
|
return SpeedLevel > 0 ? (1m + SpeedLevel * info.SpeedModifier) : 1m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum UnitUpgrade
|
||||||
|
{
|
||||||
|
Firepower = 0,
|
||||||
|
Armor = 1,
|
||||||
|
Speed = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -123,6 +123,7 @@
|
|||||||
<Compile Include="Air\Aircraft.cs" />
|
<Compile Include="Air\Aircraft.cs" />
|
||||||
<Compile Include="Air\AttackHeli.cs" />
|
<Compile Include="Air\AttackHeli.cs" />
|
||||||
<Compile Include="Air\AttackPlane.cs" />
|
<Compile Include="Air\AttackPlane.cs" />
|
||||||
|
<Compile Include="Crates\UnitUpgradeCrateAction.cs" />
|
||||||
<Compile Include="EjectOnDeath.cs" />
|
<Compile Include="EjectOnDeath.cs" />
|
||||||
<Compile Include="Air\FallsToEarth.cs" />
|
<Compile Include="Air\FallsToEarth.cs" />
|
||||||
<Compile Include="Air\Fly.cs" />
|
<Compile Include="Air\Fly.cs" />
|
||||||
@@ -237,6 +238,7 @@
|
|||||||
<Compile Include="Fake.cs" />
|
<Compile Include="Fake.cs" />
|
||||||
<Compile Include="FreeActor.cs" />
|
<Compile Include="FreeActor.cs" />
|
||||||
<Compile Include="GainsExperience.cs" />
|
<Compile Include="GainsExperience.cs" />
|
||||||
|
<Compile Include="GainsUnitUpgrades.cs" />
|
||||||
<Compile Include="GivesBounty.cs" />
|
<Compile Include="GivesBounty.cs" />
|
||||||
<Compile Include="GivesExperience.cs" />
|
<Compile Include="GivesExperience.cs" />
|
||||||
<Compile Include="Guard.cs" />
|
<Compile Include="Guard.cs" />
|
||||||
|
|||||||
BIN
mods/cnc/bits/ss/armorcrate.shp
Normal file
BIN
mods/cnc/bits/ss/armorcrate.shp
Normal file
Binary file not shown.
BIN
mods/cnc/bits/ss/armorup.aud
Normal file
BIN
mods/cnc/bits/ss/armorup.aud
Normal file
Binary file not shown.
BIN
mods/cnc/bits/ss/firepowercrate.shp
Normal file
BIN
mods/cnc/bits/ss/firepowercrate.shp
Normal file
Binary file not shown.
BIN
mods/cnc/bits/ss/firepowerup.aud
Normal file
BIN
mods/cnc/bits/ss/firepowerup.aud
Normal file
Binary file not shown.
BIN
mods/cnc/bits/ss/rangeup.aud
Normal file
BIN
mods/cnc/bits/ss/rangeup.aud
Normal file
Binary file not shown.
BIN
mods/cnc/bits/ss/rateoffireup.aud
Normal file
BIN
mods/cnc/bits/ss/rateoffireup.aud
Normal file
Binary file not shown.
BIN
mods/cnc/bits/ss/speedcrate.shp
Normal file
BIN
mods/cnc/bits/ss/speedcrate.shp
Normal file
Binary file not shown.
BIN
mods/cnc/bits/ss/speedup.aud
Normal file
BIN
mods/cnc/bits/ss/speedup.aud
Normal file
Binary file not shown.
@@ -8,6 +8,7 @@ Folders:
|
|||||||
.
|
.
|
||||||
./mods/cnc
|
./mods/cnc
|
||||||
./mods/cnc/bits
|
./mods/cnc/bits
|
||||||
|
./mods/cnc/bits/ss
|
||||||
./mods/cnc/uibits
|
./mods/cnc/uibits
|
||||||
~^/Content/cnc
|
~^/Content/cnc
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,15 @@ crate-effects:
|
|||||||
Start: 0
|
Start: 0
|
||||||
Length: *
|
Length: *
|
||||||
Tick: 200
|
Tick: 200
|
||||||
|
firepowerup: firepowercrate
|
||||||
|
Start: 0
|
||||||
|
Length: *
|
||||||
|
armorup: armorcrate
|
||||||
|
Start: 0
|
||||||
|
Length: *
|
||||||
|
speedup: speedcrate
|
||||||
|
Start: 0
|
||||||
|
Length: *
|
||||||
|
|
||||||
atomicup:
|
atomicup:
|
||||||
idle:
|
idle:
|
||||||
|
|||||||
Reference in New Issue
Block a user