Add ProductionCost/TimeMultiplier
This commit is contained in:
committed by
reaperrr
parent
1f730fbfb9
commit
de7706c98f
@@ -111,6 +111,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
PowerManager playerPower;
|
||||
protected PlayerResources playerResources;
|
||||
protected DeveloperMode developerMode;
|
||||
protected TechTree techTree;
|
||||
|
||||
public Actor Actor { get { return self; } }
|
||||
|
||||
@@ -123,14 +124,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
self = init.Self;
|
||||
Info = info;
|
||||
playerResources = playerActor.Trait<PlayerResources>();
|
||||
developerMode = playerActor.Trait<DeveloperMode>();
|
||||
|
||||
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
||||
IsValidFaction = !info.Factions.Any() || info.Factions.Contains(Faction);
|
||||
Enabled = IsValidFaction;
|
||||
|
||||
CacheProducibles(playerActor);
|
||||
allProducibles = Producible.Where(a => a.Value.Buildable || a.Value.Visible).Select(a => a.Key);
|
||||
buildableProducibles = Producible.Where(a => a.Value.Buildable).Select(a => a.Key);
|
||||
}
|
||||
@@ -141,8 +139,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Created is called before Player.PlayerActor is assigned,
|
||||
// so we must query other player traits from self, knowing that
|
||||
// it refers to the same actor as self.Owner.PlayerActor
|
||||
playerPower = (self.Info.Name == "player" ? self : self.Owner.PlayerActor).TraitOrDefault<PowerManager>();
|
||||
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
|
||||
|
||||
playerPower = playerActor.TraitOrDefault<PowerManager>();
|
||||
playerResources = playerActor.Trait<PlayerResources>();
|
||||
developerMode = playerActor.Trait<DeveloperMode>();
|
||||
techTree = playerActor.Trait<TechTree>();
|
||||
|
||||
productionTraits = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).ToArray();
|
||||
CacheProducibles(playerActor);
|
||||
}
|
||||
|
||||
protected void ClearQueue()
|
||||
@@ -160,6 +165,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
playerPower = newOwner.PlayerActor.TraitOrDefault<PowerManager>();
|
||||
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||
developerMode = newOwner.PlayerActor.Trait<DeveloperMode>();
|
||||
techTree = newOwner.PlayerActor.Trait<TechTree>();
|
||||
|
||||
if (!Info.Sticky)
|
||||
{
|
||||
@@ -170,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Regenerate the producibles and tech tree state
|
||||
oldOwner.PlayerActor.Trait<TechTree>().Remove(this);
|
||||
CacheProducibles(newOwner.PlayerActor);
|
||||
newOwner.PlayerActor.Trait<TechTree>().Update();
|
||||
techTree.Update();
|
||||
}
|
||||
|
||||
void INotifyKilled.Killed(Actor killed, AttackInfo e) { if (killed == self) { ClearQueue(); Enabled = false; } }
|
||||
@@ -187,14 +193,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!Enabled)
|
||||
return;
|
||||
|
||||
var ttc = playerActor.Trait<TechTree>();
|
||||
|
||||
foreach (var a in AllBuildables(Info.Type))
|
||||
{
|
||||
var bi = a.TraitInfo<BuildableInfo>();
|
||||
|
||||
Producible.Add(a, new ProductionState());
|
||||
ttc.Add(a.Name, bi.Prerequisites, bi.BuildLimit, this);
|
||||
techTree.Add(a.Name, bi.Prerequisites, bi.BuildLimit, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,8 +397,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
}
|
||||
|
||||
var valued = unit.TraitInfoOrDefault<ValuedInfo>();
|
||||
var cost = valued != null ? valued.Cost : 0;
|
||||
var cost = GetProductionCost(unit);
|
||||
var time = GetBuildTime(unit, bi);
|
||||
var amountToBuild = Math.Min(fromLimit, order.ExtraData);
|
||||
for (var n = 0; n < amountToBuild; n++)
|
||||
@@ -434,13 +437,26 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var time = bi.BuildDuration;
|
||||
if (time == -1)
|
||||
{
|
||||
var valued = unit.TraitInfoOrDefault<ValuedInfo>();
|
||||
time = valued != null ? valued.Cost : 0;
|
||||
}
|
||||
time = GetProductionCost(unit);
|
||||
|
||||
time = time * bi.BuildDurationModifier * Info.BuildDurationModifier / 10000;
|
||||
return time;
|
||||
var modifiers = unit.TraitInfos<IProductionTimeModifierInfo>()
|
||||
.Select(t => t.GetProductionTimeModifier(techTree, Info.Type))
|
||||
.Append(bi.BuildDurationModifier)
|
||||
.Append(Info.BuildDurationModifier);
|
||||
|
||||
return Util.ApplyPercentageModifiers(time, modifiers);
|
||||
}
|
||||
|
||||
public virtual int GetProductionCost(ActorInfo unit)
|
||||
{
|
||||
var valued = unit.TraitInfoOrDefault<ValuedInfo>();
|
||||
if (valued == null)
|
||||
return 0;
|
||||
|
||||
var modifiers = unit.TraitInfos<IProductionCostModifierInfo>()
|
||||
.Select(t => t.GetProductionCostModifier(techTree, Info.Type));
|
||||
|
||||
return Util.ApplyPercentageModifiers(valued.Cost, modifiers);
|
||||
}
|
||||
|
||||
protected void PauseProduction(string itemName, bool paused)
|
||||
|
||||
Reference in New Issue
Block a user