Move the core of OpenRA.Mods.RA.Scripting to OpenRA.Mods.Common.Scripting

This commit is contained in:
atlimit8
2014-11-25 20:14:03 -06:00
parent 60cf2d2cae
commit 91b5ac5070
26 changed files with 93 additions and 75 deletions

View File

@@ -1,39 +0,0 @@
#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 Eluant;
using OpenRA.Network;
using OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Diplomacy")]
public class DiplomacyProperties : ScriptPlayerProperties
{
public DiplomacyProperties(ScriptContext context, Player player)
: base(context, player) { }
[Desc("Returns true if the player is allied with the other player.")]
public bool IsAlliedWith(Player targetPlayer)
{
return player.IsAlliedWith(targetPlayer);
}
[Desc("Changes the current stance of the player against the target player. " +
"Allowed keywords for new stance: Ally, Neutral, Enemy.")]
public void SetStance(Player targetPlayer, string newStance)
{
var emergingStance = Enum<Stance>.Parse(newStance);
player.SetStance(targetPlayer, emergingStance);
}
}
}

View File

@@ -9,6 +9,7 @@
#endregion
using Eluant;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.RA.Activities;
using OpenRA.Scripting;
using OpenRA.Traits;

View File

@@ -1,73 +0,0 @@
#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 Eluant;
using OpenRA.Mods.Common.Power;
using OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Power")]
public class PlayerPowerProperties : ScriptPlayerProperties, Requires<PowerManagerInfo>
{
readonly PowerManager pm;
public PlayerPowerProperties(ScriptContext context, Player player)
: base(context, player)
{
pm = player.PlayerActor.Trait<PowerManager>();
}
[Desc("Returns the total of the power the player has.")]
public int PowerProvided
{
get { return pm.PowerProvided; }
}
[Desc("Returns the power used by the player.")]
public int PowerDrained
{
get { return pm.PowerDrained; }
}
[Desc("Returns the player's power state " +
"(\"Normal\", \"Low\" or \"Critical\").")]
public string PowerState
{
get { return pm.PowerState.ToString(); }
}
[Desc("Triggers low power for the chosen amount of ticks.")]
public void TriggerPowerOutage(int ticks)
{
pm.TriggerPowerOutage(ticks);
}
}
[ScriptPropertyGroup("Power")]
public class ActorPowerProperties : ScriptActorProperties, Requires<PowerInfo>
{
readonly PowerInfo pi;
public ActorPowerProperties(ScriptContext context, Actor self)
: base(context, self)
{
pi = self.Info.Traits.GetOrDefault<PowerInfo>();
}
[Desc("Returns the power drained/provided by this actor.")]
public int Power
{
get { return pi.Amount; }
}
}
}

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Scripting;
using OpenRA.Mods.RA.Activities;
using OpenRA.Scripting;
using OpenRA.Traits;

View File

@@ -14,33 +14,6 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("General")]
public class HealthProperties : ScriptActorProperties, Requires<HealthInfo>
{
Health health;
public HealthProperties(ScriptContext context, Actor self)
: base(context, self)
{
health = self.Trait<Health>();
}
[Desc("Current health of the actor.")]
public int Health
{
get { return health.HP; }
set { health.InflictDamage(self, self, health.HP - value, null, true); }
}
[Desc("Maximum health of the actor.")]
public int MaxHealth { get { return health.MaxHP; } }
[Desc("Kill the actor.")]
public void Kill()
{
health.InflictDamage(self, self, health.MaxHP, null, true);
}
}
[ScriptPropertyGroup("General")]
public class RepairableBuildingProperties : ScriptActorProperties, Requires<RepairableBuildingInfo>
{
@@ -70,4 +43,4 @@ namespace OpenRA.Mods.RA.Scripting
rb.RepairBuilding(self, repairer);
}
}
}
}

View File

@@ -1,45 +0,0 @@
#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.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Resources")]
public class ResourceProperties : ScriptPlayerProperties, Requires<PlayerResourcesInfo>
{
readonly PlayerResources pr;
public ResourceProperties(ScriptContext context, Player player)
: base(context, player)
{
pr = player.PlayerActor.Trait<PlayerResources>();
}
[Desc("The amount of harvestable resources held by the player.")]
public int Resources
{
get { return pr.Resources; }
set { pr.Resources = value.Clamp(0, pr.ResourceCapacity); }
}
[Desc("The maximum resource storage of the player.")]
public int ResourceCapacity { get { return pr.ResourceCapacity; } }
[Desc("The amount of cash held by the player.")]
public int Cash
{
get { return pr.Cash; }
set { pr.Cash = Math.Max(0, value); }
}
}
}

View File

@@ -1,51 +0,0 @@
#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 OpenRA.Mods.Common;
using OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("General")]
public class UpgradeProperties : ScriptActorProperties, Requires<UpgradeManagerInfo>
{
UpgradeManager um;
public UpgradeProperties(ScriptContext context, Actor self)
: base(context, self)
{
um = self.Trait<UpgradeManager>();
}
[Desc("Grant an upgrade to this actor.")]
public void GrantUpgrade(string upgrade)
{
um.GrantUpgrade(self, upgrade, this);
}
[Desc("Revoke an upgrade that was previously granted using GrantUpgrade.")]
public void RevokeUpgrade(string upgrade)
{
um.RevokeUpgrade(self, upgrade, this);
}
[Desc("Grant a limited-time upgrade to this actor.")]
public void GrantTimedUpgrade(string upgrade, int duration)
{
um.GrantTimedUpgrade(self, upgrade, duration);
}
[Desc("Check whether this actor accepts a specific upgrade.")]
public bool AcceptsUpgrade(string upgrade)
{
return um.AcceptsUpgrade(self, upgrade);
}
}
}