Mercurial > repos > IBBoard.WarFoundry.API
annotate API/Objects/Requirement/RequirementHandler.cs @ 454:def5d333c5e8
Re #379: Fix validation of requirements to check for unit
* Remove custom messages for overrides to reduce verbosity
* Add missing multiplication signs for readability
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 31 Jan 2012 20:58:09 +0000 |
parents | 676f5ce04176 |
children | 248df19652f9 |
rev | line source |
---|---|
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; | |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
5 using System.Collections.Generic; |
353 | 6 |
7 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
8 { | |
9 /// <summary> | |
10 /// The requirement handler that tests the validity of armies. | |
11 /// </summary> | |
12 public class RequirementHandler | |
13 { | |
14 private RequirementHandler() | |
15 { | |
16 } | |
363
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
17 |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
18 |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
19 public static Validation ValidateArmy(Army army) |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
20 { |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
21 ICollection<string> ignored; |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
22 return ValidateArmy(army, out ignored); |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
23 } |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
24 |
363
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
25 public static Validation ValidateArmy(Army army, out ICollection<string> failureMessages) |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
26 { |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
27 Validation result = Validation.Passed; |
363
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
28 failureMessages = new List<string>(); |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
29 |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
30 foreach (IRequirement requirement in army.GetRequirements()) |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
31 { |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
32 if (!Validates.AsOkay(requirement.ValidatesArmy(army))) |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
33 { |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
34 result = Validation.Failed; |
363
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
35 failureMessages.Add(requirement.GetValidationMessage(army)); |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
36 } |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
37 } |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
38 |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
39 return result; |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
40 } |
355 | 41 |
42 public static Validation AllowsAdding(UnitType unitType, Army army) | |
43 { | |
363
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
44 ICollection<string> ignored; |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
45 return AllowsAdding(unitType, army, out ignored); |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
46 } |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
47 |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
48 public static Validation AllowsAdding(UnitType unitType, Army army, out ICollection<string> failureMessages) |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
49 { |
355 | 50 Validation result = Validation.Passed; |
363
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
51 failureMessages = new List<string>(); |
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
52 |
451
676f5ce04176
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
363
diff
changeset
|
53 foreach (IRequirement requirement in army.GetAddingUnitRequirements(unitType)) |
355 | 54 { |
55 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army))) | |
56 { | |
57 result = Validation.Failed; | |
363
506af4cbe3f5
Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
361
diff
changeset
|
58 failureMessages.Add(requirement.GetAllowsAddingMessage(unitType, army)); |
355 | 59 } |
60 } | |
61 | |
62 return result; | |
63 } | |
353 | 64 } |
65 } | |
66 |