Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs @ 456:52baffdd2ab9
Re #379: Fix validation of requirements to check for unit
* Default to not being applicable - make requirements say when they are
* Fix UnitRequiresNUnitsForMUnitsRequirement to not be applicable when adding unrelated units (even if army itself fails the rule)
* Fix type casting issues in equality check
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 25 Feb 2012 16:35:31 +0000 |
parents | afc6410e4efc |
children | 8e01c3174cc3 |
comparison
equal
deleted
inserted
replaced
455:afc6410e4efc | 456:52baffdd2ab9 |
---|---|
37 return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; | 37 return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; |
38 } | 38 } |
39 | 39 |
40 protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy) | 40 protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy) |
41 { | 41 { |
42 return IsApplicable(toArmy) || IsApplicable(toObject); | 42 return IsApplicable(toObject) || IsApplicableForRequiredType(toObject, toArmy); |
43 } | |
44 | |
45 protected override bool IsApplicable(Army toArmy) | |
46 { | |
47 return toArmy.GetUnitTypeCount(AllowedObject) > 0; | |
48 } | 43 } |
49 | 44 |
50 protected override bool IsApplicable(IWarFoundryObject toObject) | 45 protected override bool IsApplicable(IWarFoundryObject toObject) |
51 { | 46 { |
52 return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType)); | 47 return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType)); |
48 } | |
49 | |
50 private bool IsApplicableForRequiredType(IWarFoundryObject toObject, Army toArmy) | |
51 { | |
52 bool isApplicable = false; | |
53 UnitType addedType = toObject as UnitType; | |
54 | |
55 if (addedType == null) | |
56 { | |
57 addedType = (toObject is Unit) ? ((Unit)toObject).UnitType : null; | |
58 } | |
59 | |
60 if (addedType != null && toArmy.GetUnitTypeCount(AllowedObject) > 0) | |
61 { | |
62 foreach (UnitCountRequirementData limit in RequiredTypes) | |
63 { | |
64 if (Arrays.Contains(limit.UnitTypes, addedType)) | |
65 { | |
66 isApplicable = true; | |
67 break; | |
68 } | |
69 } | |
70 } | |
71 | |
72 return isApplicable; | |
53 } | 73 } |
54 | 74 |
55 public override string RequirementID | 75 public override string RequirementID |
56 { | 76 { |
57 get | 77 get |