Begin generalizing crates; only give firepower bonus to units with weapons

This commit is contained in:
Paul Chote
2010-03-21 19:52:13 +13:00
parent a489b4aa56
commit 0510a7fb7f
8 changed files with 50 additions and 25 deletions

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Traits
public void OnCrush(Actor crusher)
{
var shares = self.traits.WithInterface<ICrateAction>().Select(a => Pair.New(a, a.SelectionShares));
var shares = self.traits.WithInterface<ICrateAction>().Select(a => Pair.New(a, a.GetSelectionShares(crusher)));
var totalShares = shares.Sum(a => a.Second);
var n = self.World.SharedRandom.Next(totalShares);

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Traits
public interface ICrateAction
{
int SelectionShares { get; }
int GetSelectionShares(Actor collector);
void Activate(Actor collector);
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
@@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA
{
public float Multiplier = 2.0f;
public int SelectionShares = 10;
public string Effect = null;
public string Notification = null;
public object Create(Actor self) { return new ArmorUpgradeCrateAction(self); }
}
@@ -38,19 +40,20 @@ namespace OpenRA.Mods.RA
this.self = self;
}
public int SelectionShares
public int GetSelectionShares(Actor collector)
{
get { return self.Info.Traits.Get<ArmorUpgradeCrateActionInfo>().SelectionShares; }
return self.Info.Traits.Get<ArmorUpgradeCrateActionInfo>().SelectionShares;
}
public void Activate(Actor collector)
{
Sound.PlayToPlayer(collector.Owner, "armorup1.aud");
Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get<ArmorUpgradeCrateActionInfo>().Notification);
collector.World.AddFrameEndTask(w =>
{
var multiplier = self.Info.Traits.Get<ArmorUpgradeCrateActionInfo>().Multiplier;
collector.traits.Add(new ArmorUpgrade(multiplier));
w.Add(new CrateEffect(collector, "armor"));
w.Add(new CrateEffect(collector, self.Info.Traits.Get<ArmorUpgradeCrateActionInfo>().Effect));
});
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -11,7 +11,8 @@ namespace OpenRA.Mods.RA
{
public string Weapon = null;
public int SelectionShares = 5;
public string Effect = null;
public string Notification = null;
public object Create(Actor self) { return new ExplodeCrateAction(self, this); }
}
@@ -26,13 +27,15 @@ namespace OpenRA.Mods.RA
this.info = info;
}
public int SelectionShares
public int GetSelectionShares(Actor collector)
{
get { return info.SelectionShares; }
return info.SelectionShares;
}
public void Activate(Actor collector)
{
Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get<ExplodeCrateActionInfo>().Notification);
self.World.AddFrameEndTask(
w => w.Add(new Bullet(info.Weapon, self.Owner,
self, self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(),

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
@@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA
{
public float Multiplier = 2.0f;
public int SelectionShares = 10;
public string Effect = null;
public string Notification = null;
public object Create(Actor self) { return new FirepowerUpgradeCrateAction(self); }
}
@@ -38,19 +40,22 @@ namespace OpenRA.Mods.RA
this.self = self;
}
public int SelectionShares
public int GetSelectionShares(Actor collector)
{
get { return self.Info.Traits.Get<FirepowerUpgradeCrateActionInfo>().SelectionShares; }
if (collector.GetPrimaryWeapon() == null && collector.GetSecondaryWeapon() == null)
return 0;
return self.Info.Traits.Get<FirepowerUpgradeCrateActionInfo>().SelectionShares;
}
public void Activate(Actor collector)
{
Sound.PlayToPlayer(collector.Owner, "firepo1.aud");
Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get<FirepowerUpgradeCrateActionInfo>().Notification);
collector.World.AddFrameEndTask(w =>
{
var multiplier = self.Info.Traits.Get<FirepowerUpgradeCrateActionInfo>().Multiplier;
collector.traits.Add(new FirepowerUpgrade(multiplier));
w.Add(new CrateEffect(collector, "fpower"));
w.Add(new CrateEffect(collector, self.Info.Traits.Get<FirepowerUpgradeCrateActionInfo>().Effect));
});
}
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
@@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA
{
public int Amount = 2000;
public int SelectionShares = 10;
public string Effect = null;
public string Notification = null;
public object Create(Actor self) { return new GiveCashCrateAction(self); }
}
@@ -38,18 +40,20 @@ namespace OpenRA.Mods.RA
this.self = self;
}
public int SelectionShares
public int GetSelectionShares(Actor collector)
{
get { return self.Info.Traits.Get<GiveCashCrateActionInfo>().SelectionShares; }
return self.Info.Traits.Get<GiveCashCrateActionInfo>().SelectionShares;
}
public void Activate(Actor collector)
{
Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get<GiveCashCrateActionInfo>().Notification);
collector.World.AddFrameEndTask(w =>
{
var amount = self.Info.Traits.Get<GiveCashCrateActionInfo>().Amount;
collector.Owner.GiveCash(amount);
w.Add(new CrateEffect(collector, "dollar"));
w.Add(new CrateEffect(collector, self.Info.Traits.Get<GiveCashCrateActionInfo>().Effect));
});
}
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
@@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA
{
public float Multiplier = 1.7f;
public int SelectionShares = 10;
public string Effect = null;
public string Notification = null;
public object Create(Actor self) { return new SpeedUpgradeCrateAction(self); }
}
@@ -38,19 +40,20 @@ namespace OpenRA.Mods.RA
this.self = self;
}
public int SelectionShares
public int GetSelectionShares(Actor collector)
{
get { return self.Info.Traits.Get<SpeedUpgradeCrateActionInfo>().SelectionShares; }
return self.Info.Traits.Get<SpeedUpgradeCrateActionInfo>().SelectionShares;
}
public void Activate(Actor collector)
{
Sound.PlayToPlayer(collector.Owner, "unitspd1.aud");
Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get<SpeedUpgradeCrateActionInfo>().Notification);
collector.World.AddFrameEndTask(w =>
{
var multiplier = self.Info.Traits.Get<SpeedUpgradeCrateActionInfo>().Multiplier;
collector.traits.Add(new SpeedUpgrade(multiplier));
w.Add(new CrateEffect(collector, "speed"));
w.Add(new CrateEffect(collector, self.Info.Traits.Get<SpeedUpgradeCrateActionInfo>().Effect));
});
}
}

View File

@@ -637,15 +637,22 @@ CRATE:
SpeedUpgradeCrateAction:
Multiplier: 1.7
SelectionShares: 10
Notification: unitspd1.aud
Effect: speed
GiveCashCrateAction:
Amount: 2000
SelectionShares: 50
Effect: dollar
FirepowerUpgradeCrateAction:
Multiplier: 2.0
SelectionShares: 10
Notification: firepo1.aud
Effect: fpower
ArmorUpgradeCrateAction:
Multiplier: 2.0
SelectionShares: 10
Notification: armorup1.aud
Effect: armor
ExplodeCrateAction@fire:
Weapon: Napalm
SelectionShares: 80