353
|
1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
|
|
2 //
|
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
|
|
4 using System;
|
|
5
|
|
6 namespace IBBoard.WarFoundry.API.Objects.Requirement
|
|
7 {
|
|
8 /// <summary>
|
|
9 /// The requirement handler that tests the validity of armies.
|
|
10 /// </summary>
|
|
11 public class RequirementHandler
|
|
12 {
|
|
13 private RequirementHandler()
|
|
14 {
|
|
15 }
|
|
16
|
|
17 public static Validation ValidateArmy (Army army)
|
|
18 {
|
|
19 Validation result = Validation.Passed;
|
|
20
|
|
21 foreach (IRequirement requirement in army.GetRequirements())
|
|
22 {
|
|
23 if (!Validates.AsOkay(requirement.ValidatesArmy(army)))
|
|
24 {
|
|
25 result = Validation.Failed;
|
|
26 break;
|
|
27 }
|
|
28 }
|
|
29
|
|
30 return result;
|
|
31 }
|
355
|
32
|
|
33 public static Validation AllowsAdding(UnitType unitType, Army army)
|
|
34 {
|
|
35 Validation result = Validation.Passed;
|
|
36
|
|
37 foreach (IRequirement requirement in army.GetRequirements())
|
|
38 {
|
|
39 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
|
|
40 {
|
|
41 result = Validation.Failed;
|
|
42 break;
|
|
43 }
|
|
44 }
|
|
45
|
|
46 return result;
|
|
47 }
|
353
|
48 }
|
|
49 }
|
|
50
|