-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using BattleTech; | ||
|
||
namespace CustomComponents | ||
{ | ||
[CustomComponent("RequiredCategories")] | ||
public class RequiredCategories : SimpleCustomComponent, IMechValidate | ||
{ | ||
public string[] Categories { get; set; } | ||
public string ErrorMessage { get; set; } | ||
|
||
public void ValidateMech(Dictionary<MechValidationType, List<Localize.Text>> errors, MechValidationLevel validationLevel, MechDef mechDef, | ||
MechComponentRef componentRef) | ||
{ | ||
if (Categories == null || Categories.Length == 0) | ||
return; | ||
|
||
foreach (var category in Categories) | ||
{ | ||
if (mechDef.Inventory.Any(i => i.IsCategory(category))) | ||
return; | ||
} | ||
|
||
errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(string.IsNullOrEmpty(ErrorMessage) ? | ||
$"{Def.Description.Name} requires additional modules to work" : | ||
ErrorMessage)); | ||
} | ||
|
||
public bool ValidateMechCanBeFielded(MechDef mechDef, MechComponentRef componentRef) | ||
{ | ||
if (Categories == null || Categories.Length == 0) | ||
return true; | ||
foreach (var category in Categories) | ||
{ | ||
if (mechDef.Inventory.Any(i => i.IsCategory(category))) | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters