Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs @ 453:dace3b7779ca
Re #379: Fix validation of requirements to check for unit
* Restructure all validation messages to a common base system that will translate better
* Update "No More Than" texts to differentiate two contexts (adding and validating)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 29 Jan 2012 20:05:25 +0000 |
parents | 71fceea2725b |
children | def5d333c5e8 |
comparison
equal
deleted
inserted
replaced
452:b671085871b7 | 453:dace3b7779ca |
---|---|
15 private UnitType requirementOnType; | 15 private UnitType requirementOnType; |
16 | 16 |
17 public UnitRequiresNoMoreThanNOfUnitTypeRequirement(UnitType requirementOn) : base() | 17 public UnitRequiresNoMoreThanNOfUnitTypeRequirement(UnitType requirementOn) : base() |
18 { | 18 { |
19 requirementOnType = requirementOn; | 19 requirementOnType = requirementOn; |
20 FailureStringPrefix = "Army contains " + requirementOn.Name + " and so cannot contain more than: "; | |
21 } | 20 } |
22 | 21 |
23 /// <summary> | 22 /// <summary> |
24 /// Checks whether the supplied WarFoundryObject can be added to the supplied army. | 23 /// Checks whether the supplied WarFoundryObject can be added to the supplied army. |
25 /// </summary> | 24 /// </summary> |
35 public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) | 34 public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) |
36 { | 35 { |
37 return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; | 36 return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; |
38 } | 37 } |
39 | 38 |
40 | |
41 protected override bool IsApplicable(WarFoundryObject toObject, Army toArmy) | 39 protected override bool IsApplicable(WarFoundryObject toObject, Army toArmy) |
42 { | 40 { |
43 return IsApplicable(toArmy) || IsApplicable(toObject); | 41 return IsApplicable(toArmy) || IsApplicable(toObject); |
44 } | 42 } |
45 | |
46 | 43 |
47 protected override bool IsApplicable(Army toArmy) | 44 protected override bool IsApplicable(Army toArmy) |
48 { | 45 { |
49 return toArmy.GetUnitTypeCount(requirementOnType) > 0; | 46 return toArmy.GetUnitTypeCount(requirementOnType) > 0; |
50 } | 47 } |
51 | 48 |
52 | |
53 protected override bool IsApplicable(WarFoundryObject toObject) | 49 protected override bool IsApplicable(WarFoundryObject toObject) |
54 { | 50 { |
55 return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType)); | 51 return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType)); |
56 } | 52 } |
53 | |
54 protected override string ValidationFailedMessage | |
55 { | |
56 get | |
57 { | |
58 return "Army contains " + requirementOnType.Name + " and so cannot contain more than: {0}."; | |
59 } | |
60 } | |
61 | |
62 protected override string AllowsAddingFailedMessage | |
63 { | |
64 get | |
65 { | |
66 return "Army would contain " + requirementOnType.Name + " and so cannot contain more than: {0}."; | |
67 } | |
68 } | |
57 } | 69 } |
58 } | 70 } |
59 | 71 |