Throw a LuaException when placing a beacon without the player trait

This commit is contained in:
abcdefg30
2019-04-13 13:11:53 +02:00
committed by reaperrr
parent db68c6e264
commit c93dc1424c

View File

@@ -9,6 +9,7 @@
*/
#endregion
using Eluant;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting;
@@ -20,16 +21,21 @@ namespace OpenRA.Mods.Common.Scripting
{
readonly RadarPings radarPings;
public BeaconGlobal(ScriptContext context) : base(context)
public BeaconGlobal(ScriptContext context)
: base(context)
{
radarPings = context.World.WorldActor.TraitOrDefault<RadarPings>();
}
[Desc("Creates a new beacon that stays for the specified time at the specified WPos. " +
"Does not remove player set beacons, nor gets removed by placing them.")]
"Does not remove player set beacons, nor gets removed by placing them. " +
"Requires the 'PlaceBeacon' trait on the player actor.")]
public Beacon New(Player owner, WPos position, int duration = 30 * 25, bool showRadarPings = true)
{
var beacon = owner.PlayerActor.Info.TraitInfo<PlaceBeaconInfo>();
var beacon = owner.PlayerActor.Info.TraitInfoOrDefault<PlaceBeaconInfo>();
if (beacon == null)
throw new LuaException("The player actor has no 'PlaceBeacon' trait.");
var playerBeacon = new Beacon(owner, position, duration, beacon.Palette, beacon.IsPlayerPalette,
beacon.BeaconImage, beacon.BeaconSequence, beacon.ArrowSequence, beacon.CircleSequence);