-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
MissionObjectiveProperties.cs
118 lines (100 loc) · 3.77 KB
/
MissionObjectiveProperties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#region Copyright & License Information
/*
* Copyright 2007-2015 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.Traits;
using OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Scripting
{
[ScriptPropertyGroup("MissionObjectives")]
public class MissionObjectiveProperties : ScriptPlayerProperties
{
readonly MissionObjectives mo;
public MissionObjectiveProperties(ScriptContext context, Player player)
: base(context, player)
{
mo = player.PlayerActor.Trait<MissionObjectives>();
}
[ScriptActorPropertyActivity]
[Desc("Add a primary mission objective for this player. The function returns the " +
"ID of the newly created objective, so that it can be referred to later.")]
public int AddPrimaryObjective(string description)
{
return mo.Add(Player, description, ObjectiveType.Primary);
}
[ScriptActorPropertyActivity]
[Desc("Add a secondary mission objective for this player. The function returns the " +
"ID of the newly created objective, so that it can be referred to later.")]
public int AddSecondaryObjective(string description)
{
return mo.Add(Player, description, ObjectiveType.Secondary);
}
[ScriptActorPropertyActivity]
[Desc("Mark an objective as completed. This needs the objective ID returned " +
"by AddObjective as argument. When this player has completed all primary " +
"objectives, (s)he has won the game.")]
public void MarkCompletedObjective(int id)
{
if (id < 0 || id >= mo.Objectives.Count)
throw new LuaException("Objective ID is out of range.");
mo.MarkCompleted(Player, id);
}
[ScriptActorPropertyActivity]
[Desc("Mark an objective as failed. This needs the objective ID returned " +
"by AddObjective as argument. Secondary objectives do not have any " +
"influence whatsoever on the outcome of the game.")]
public void MarkFailedObjective(int id)
{
if (id < 0 || id >= mo.Objectives.Count)
throw new LuaException("Objective ID is out of range.");
mo.MarkFailed(Player, id);
}
[ScriptActorPropertyActivity]
[Desc("Returns true if the objective has been successfully completed, false otherwise.")]
public bool IsObjectiveCompleted(int id)
{
if (id < 0 || id >= mo.Objectives.Count)
throw new LuaException("Objective ID is out of range.");
return mo.Objectives[id].State == ObjectiveState.Completed;
}
[ScriptActorPropertyActivity]
[Desc("Returns true if the objective has been failed, false otherwise.")]
public bool IsObjectiveFailed(int id)
{
if (id < 0 || id >= mo.Objectives.Count)
throw new LuaException("Objective ID is out of range.");
return mo.Objectives[id].State == ObjectiveState.Failed;
}
[ScriptActorPropertyActivity]
[Desc("Returns the description of an objective.")]
public string GetObjectiveDescription(int id)
{
if (id < 0 || id >= mo.Objectives.Count)
throw new LuaException("Objective ID is out of range.");
return mo.Objectives[id].Description;
}
[ScriptActorPropertyActivity]
[Desc("Returns the type of an objective.")]
public string GetObjectiveType(int id)
{
if (id < 0 || id >= mo.Objectives.Count)
throw new LuaException("Objective ID is out of range.");
return mo.Objectives[id].Type == ObjectiveType.Primary ? "Primary" : "Secondary";
}
[ScriptActorPropertyActivity]
[Desc("Returns true if this player has lost all units/actors that have " +
"the MustBeDestroyed trait (according to the short game option).")]
public bool HasNoRequiredUnits()
{
return Player.HasNoRequiredUnits();
}
}
}