YamlException is now thrown if WeaponInfo can not be found in Ruleset.Weapons

Removed invalid spacing at the end of the line 36 in ThrowsShrapnel

Prevented NullReferenceException in cases where weapons aren't optional
This commit is contained in:
Raffael Zica
2017-10-03 20:45:49 +02:00
committed by reaperrr
parent c8b2a7dc04
commit f2b5040d30
8 changed files with 79 additions and 10 deletions

View File

@@ -56,8 +56,19 @@ namespace OpenRA.Mods.Cnc.Traits
public object Create(ActorInitializer init) { return new MadTank(init.Self, this); }
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
ThumpDamageWeaponInfo = rules.Weapons[ThumpDamageWeapon.ToLowerInvariant()];
DetonationWeaponInfo = rules.Weapons[DetonationWeapon.ToLowerInvariant()];
WeaponInfo thumpDamageWeapon;
WeaponInfo detonationWeapon;
var thumpDamageWeaponToLower = (ThumpDamageWeapon ?? string.Empty).ToLowerInvariant();
var detonationWeaponToLower = (DetonationWeapon ?? string.Empty).ToLowerInvariant();
if (!rules.Weapons.TryGetValue(thumpDamageWeaponToLower, out thumpDamageWeapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(thumpDamageWeaponToLower));
if (!rules.Weapons.TryGetValue(detonationWeaponToLower, out detonationWeapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(detonationWeaponToLower));
ThumpDamageWeaponInfo = thumpDamageWeapon;
DetonationWeaponInfo = detonationWeapon;
}
}