mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 20:55:44 +00:00
Change prisoner management options from an enum to a sealed one of (#2469)
* replace the prisoner management enum with a oneof * fix error message * format * make the available options per-prisoner * start updating client * apply editorconfig Former-commit-id: 9c54d1b9f778ce2f25c6f853e7c8e20d3616a7e5
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# This file is the top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# All Files
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = false
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.cs]
|
||||
csharp_new_line_before_open_brace = none
|
||||
max_line_length = 80
|
||||
+35
-44
@@ -4,22 +4,21 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
using System.Linq;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class ManagePrisonersCommandSelector : CommandSelector
|
||||
{
|
||||
public class ManagePrisonersCommandSelector : CommandSelector {
|
||||
// Unity accessors
|
||||
public Toggle RecruitToggle;
|
||||
public Toggle ImprisonToggle;
|
||||
public Toggle ReleaseToggle;
|
||||
public Toggle MoveToggle;
|
||||
public Toggle ExileToggle;
|
||||
public Toggle ExecuteToggle;
|
||||
public Toggle ReturnToggle;
|
||||
|
||||
public RawImage RecruitIcon;
|
||||
public RawImage ImprisonIcon;
|
||||
public RawImage ReleaseIcon;
|
||||
public RawImage MoveIcon;
|
||||
public RawImage ExileIcon;
|
||||
public RawImage ExecuteIcon;
|
||||
public RawImage ReturnIcon;
|
||||
@@ -30,14 +29,14 @@ namespace eagle
|
||||
|
||||
public Button NextHeroButton;
|
||||
|
||||
public HeroView SelectedHero => SelectedPrisoner.Hero;
|
||||
public HeroView SelectedHero => SelectedPrisonerToManage.Prisoner.Hero;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ManagePrisonerCommand;
|
||||
public override string HeaderString => "Manage Prisoners";
|
||||
public override string CommitButtonString => $"Commit {DisplayNames.PrisonerManagementTypeNames[SelectedOption]}";
|
||||
public override string CommitButtonString => $"Commit {DisplayNames.PrisonerManagementTypeName(SelectedOption)}";
|
||||
|
||||
private int _selectedHeroIndex;
|
||||
private ExpandedUnaffiliatedHero SelectedPrisoner => ManagePrisonersCommand.Prisoners[_selectedHeroIndex];
|
||||
private PrisonerToManage SelectedPrisonerToManage => ManagePrisonersCommand.Prisoners[_selectedHeroIndex];
|
||||
|
||||
private ManagePrisonersAvailableCommand ManagePrisonersCommand => _availableCommand.ManagePrisonerCommand;
|
||||
private ProvinceId ActingProvinceId => ManagePrisonersCommand.ActingProvinceId;
|
||||
@@ -45,68 +44,61 @@ namespace eagle
|
||||
public override bool WarnOnCommitButton => false;
|
||||
public override string CommitWarningText => $"This will create a treaty with {_model.FactionName(SelectedHero.FactionId.Value)}";
|
||||
|
||||
private PrisonerManagementType SelectedOption
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ExecuteToggle.isOn) return PrisonerManagementType.ManagePrisonerExecute;
|
||||
private PrisonerManagementOption SelectedOption {
|
||||
get {
|
||||
if (ExecuteToggle.isOn)
|
||||
return SelectedPrisonerToManage
|
||||
.AvailableOptions
|
||||
.First(opt => opt.SealedValueCase == PrisonerManagementOption.SealedValueOneofCase.Execute);
|
||||
else throw new ArgumentOutOfRangeException("Unknown prisoner management option");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
if (_selectedHeroIndex >= ManagePrisonersCommand.Prisoners.Count) _selectedHeroIndex = 0;
|
||||
NextHeroButton.gameObject.SetActive(ManagePrisonersCommand.Prisoners.Count > 1);
|
||||
DisplaySelectedHero();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
ManagePrisonersCommand = new ManagePrisonersSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ManagePrisonersCommand = new ManagePrisonersSelectedCommand {
|
||||
PrisonerHeroId = SelectedHero.Id,
|
||||
ChosenType = SelectedOption
|
||||
ChosenOption = SelectedOption
|
||||
}
|
||||
};
|
||||
|
||||
public void NextHeroButtonClicked()
|
||||
{
|
||||
public void NextHeroButtonClicked() {
|
||||
_selectedHeroIndex++;
|
||||
if (_selectedHeroIndex >= ManagePrisonersCommand.Prisoners.Count)
|
||||
{
|
||||
if (_selectedHeroIndex >= ManagePrisonersCommand.Prisoners.Count) {
|
||||
_selectedHeroIndex = 0;
|
||||
}
|
||||
|
||||
DisplaySelectedHero();
|
||||
}
|
||||
|
||||
private void DisplaySelectedHero()
|
||||
{
|
||||
private void DisplaySelectedHero() {
|
||||
heroDetails.SetHero(SelectedHero, _model);
|
||||
|
||||
MessageText.text = "";
|
||||
|
||||
// The order here is important: the last available toggle in this list
|
||||
// will be on by default
|
||||
ConditionallyEnable(ExecuteToggle, ExecuteIcon, PrisonerManagementType.ManagePrisonerExecute);
|
||||
ConditionallyEnable(ExileToggle, ExileIcon, PrisonerManagementType.ManagePrisonerUnknown);
|
||||
ConditionallyEnable(ReturnToggle, ReturnIcon, PrisonerManagementType.ManagePrisonerUnknown);
|
||||
ConditionallyEnable(ImprisonToggle, ImprisonIcon, PrisonerManagementType.ManagePrisonerUnknown);
|
||||
ConditionallyEnable(RecruitToggle, RecruitIcon, PrisonerManagementType.ManagePrisonerUnknown);
|
||||
ConditionallyEnable(ExecuteToggle, ExecuteIcon, PrisonerManagementOption.SealedValueOneofCase.Execute);
|
||||
ConditionallyEnable(ExileToggle, ExileIcon, PrisonerManagementOption.SealedValueOneofCase.Exile);
|
||||
ConditionallyEnable(ReturnToggle, ReturnIcon, PrisonerManagementOption.SealedValueOneofCase.Return);
|
||||
ConditionallyEnable(MoveToggle, MoveIcon, PrisonerManagementOption.SealedValueOneofCase.Move);
|
||||
ConditionallyEnable(ReleaseToggle, ReleaseIcon, PrisonerManagementOption.SealedValueOneofCase.Release);
|
||||
}
|
||||
|
||||
private bool ConditionallyEnable(Toggle toggle, PrisonerManagementType option)
|
||||
{
|
||||
bool enable = ManagePrisonersCommand.AvailableOptions.Contains(option);
|
||||
private bool ConditionallyEnable(Toggle toggle, PrisonerManagementOption.SealedValueOneofCase option) {
|
||||
bool enable = SelectedPrisonerToManage.AvailableOptions.Any(opt => opt.SealedValueCase == option);
|
||||
toggle.gameObject.SetActive(enable);
|
||||
|
||||
if (enable)
|
||||
{
|
||||
if (enable) {
|
||||
ExecuteToggle.isOn = false;
|
||||
ExileToggle.isOn = false;
|
||||
ImprisonToggle.isOn = false;
|
||||
RecruitToggle.isOn = false;
|
||||
MoveToggle.isOn = false;
|
||||
ReleaseToggle.isOn = false;
|
||||
ReturnToggle.isOn = false;
|
||||
|
||||
toggle.isOn = true;
|
||||
@@ -116,8 +108,7 @@ namespace eagle
|
||||
return enable;
|
||||
}
|
||||
|
||||
private void ConditionallyEnable(Toggle toggle, RawImage img, PrisonerManagementType option)
|
||||
{
|
||||
private void ConditionallyEnable(Toggle toggle, RawImage img, PrisonerManagementOption.SealedValueOneofCase option) {
|
||||
bool enable = ConditionallyEnable(toggle, option);
|
||||
|
||||
Color color = img.color;
|
||||
@@ -125,4 +116,4 @@ namespace eagle
|
||||
img.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,10 +66,14 @@ namespace eagle
|
||||
{ CapturedHeroOption.ReturnCapturedHeroOption, "Return" }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<PrisonerManagementType, string> PrisonerManagementTypeNames = new Dictionary<PrisonerManagementType, string>
|
||||
public static string PrisonerManagementTypeName(PrisonerManagementOption option)
|
||||
{
|
||||
{ PrisonerManagementType.ManagePrisonerExecute, "Execute" },
|
||||
};
|
||||
switch (option.SealedValueCase)
|
||||
{
|
||||
case PrisonerManagementOption.SealedValueOneofCase.Execute: return "Execute";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static string QuestStringFromName(string name, Quest quest, GameModel model)
|
||||
{
|
||||
|
||||
@@ -29473,7 +29473,7 @@ GameObject:
|
||||
- component: {fileID: 352506441}
|
||||
- component: {fileID: 352506440}
|
||||
m_Layer: 0
|
||||
m_Name: Recruit Image
|
||||
m_Name: Release Image
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@@ -29519,7 +29519,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Texture: {fileID: 2800000, guid: 3767d852153ff48488d9a0cbbc573cca, type: 3}
|
||||
m_Texture: {fileID: 2800000, guid: c6a8126b603abcc49940ef0c1272f22a, type: 3}
|
||||
m_UVRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
@@ -73892,13 +73892,13 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
ButtonImage: {fileID: 2800000, guid: 3d922670b3e95194ebb641a2b782a3af, type: 3}
|
||||
RecruitToggle: {fileID: 1517366774}
|
||||
ImprisonToggle: {fileID: 1403311574}
|
||||
ReleaseToggle: {fileID: 1517366774}
|
||||
MoveToggle: {fileID: 1403311574}
|
||||
ExileToggle: {fileID: 968657356}
|
||||
ExecuteToggle: {fileID: 1780944705}
|
||||
ReturnToggle: {fileID: 1396500727}
|
||||
RecruitIcon: {fileID: 352506440}
|
||||
ImprisonIcon: {fileID: 1206167568}
|
||||
ReleaseIcon: {fileID: 352506440}
|
||||
MoveIcon: {fileID: 1206167568}
|
||||
ExileIcon: {fileID: 33807229}
|
||||
ExecuteIcon: {fileID: 386265151}
|
||||
ReturnIcon: {fileID: 1745311348}
|
||||
@@ -112235,7 +112235,7 @@ GameObject:
|
||||
- component: {fileID: 1206167569}
|
||||
- component: {fileID: 1206167568}
|
||||
m_Layer: 0
|
||||
m_Name: Imprison Image
|
||||
m_Name: Move Image
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@@ -128267,7 +128267,7 @@ GameObject:
|
||||
- component: {fileID: 1403311573}
|
||||
- component: {fileID: 1403311574}
|
||||
m_Layer: 0
|
||||
m_Name: Imprison
|
||||
m_Name: Move
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@@ -137723,7 +137723,7 @@ GameObject:
|
||||
- component: {fileID: 1517366773}
|
||||
- component: {fileID: 1517366774}
|
||||
m_Layer: 0
|
||||
m_Name: Recruit
|
||||
m_Name: Release
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
||||
@@ -13,6 +13,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleFileBrowser.Editor",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "protos", "protos\protos.csproj", "{407E123C-34B3-4039-956A-B8A9DAEA0EAD}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F0DFFFCB-6CD9-4415-8498-25C9D495EBAC}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
||||
@@ -225,12 +225,15 @@ message ImproveAvailableCommand {
|
||||
int32 acting_province_id = 4;
|
||||
}
|
||||
|
||||
message PrisonerToManage {
|
||||
.net.eagle0.eagle.api.command.util.ExpandedUnaffiliatedHero prisoner = 1;
|
||||
repeated .net.eagle0.eagle.api.command.util.PrisonerManagementOption available_options = 2;
|
||||
}
|
||||
|
||||
message ManagePrisonersAvailableCommand {
|
||||
int32 acting_province_id = 1;
|
||||
|
||||
repeated net.eagle0.eagle.api.command.util.ExpandedUnaffiliatedHero prisoners = 2;
|
||||
|
||||
repeated .net.eagle0.eagle.api.command.util.PrisonerManagementType available_options = 3;
|
||||
repeated PrisonerToManage prisoners = 2;
|
||||
}
|
||||
|
||||
message MarchCommandFromOneProvince {
|
||||
|
||||
@@ -11,7 +11,33 @@ option java_package = "net.eagle0.eagle.api.command.util";
|
||||
option java_outer_classname = "PrisonerManagementType";
|
||||
option objc_class_prefix = "E0G";
|
||||
|
||||
enum PrisonerManagementType {
|
||||
MANAGE_PRISONER_UNKNOWN = 0;
|
||||
MANAGE_PRISONER_EXECUTE = 1;
|
||||
message PrisonerManagementOption {
|
||||
oneof sealed_value {
|
||||
PrisonerManagementOptionExecute execute = 1;
|
||||
PrisonerManagementOptionRelease release = 2;
|
||||
PrisonerManagementOptionExile exile = 3;
|
||||
PrisonerManagementOptionReturn return = 4;
|
||||
PrisonerManagementOptionMove move = 5;
|
||||
}
|
||||
}
|
||||
|
||||
message PrisonerManagementOptionExecute {
|
||||
|
||||
}
|
||||
|
||||
message PrisonerManagementOptionRelease {
|
||||
|
||||
}
|
||||
|
||||
message PrisonerManagementOptionExile {
|
||||
|
||||
}
|
||||
|
||||
message PrisonerManagementOptionReturn {
|
||||
|
||||
}
|
||||
|
||||
message PrisonerManagementOptionMove {
|
||||
int32 to_province_id = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ message ImproveSelectedCommand {
|
||||
|
||||
message ManagePrisonersSelectedCommand {
|
||||
int32 prisoner_hero_id = 1;
|
||||
.net.eagle0.eagle.api.command.util.PrisonerManagementType chosen_type = 2;
|
||||
.net.eagle0.eagle.api.command.util.PrisonerManagementOption chosen_option = 2;
|
||||
}
|
||||
|
||||
message MarchSelectedCommand {
|
||||
|
||||
+22
-8
@@ -1,14 +1,25 @@
|
||||
package net.eagle0.eagle.library.actions.availability
|
||||
import net.eagle0.common.MoreOption
|
||||
import net.eagle0.eagle.{FactionId, ProvinceId}
|
||||
import net.eagle0.eagle.api.available_command.ManagePrisonersAvailableCommand
|
||||
import net.eagle0.eagle.api.available_command.{
|
||||
ManagePrisonersAvailableCommand,
|
||||
PrisonerToManage
|
||||
}
|
||||
import net.eagle0.eagle.common.unaffiliated_hero.UnaffiliatedHero
|
||||
import net.eagle0.eagle.common.unaffiliated_hero.UnaffiliatedHero.Type.PRISONER
|
||||
import net.eagle0.eagle.internal.game_state.GameState
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.PrisonerManagementType
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.{
|
||||
PrisonerManagementOption,
|
||||
PrisonerManagementOptionExecute
|
||||
}
|
||||
|
||||
object AvailableManagePrisonersCommandFactory
|
||||
extends AvailableCommandsFactoryForType {
|
||||
private def optionsForPrisoner(
|
||||
prisoner: UnaffiliatedHero
|
||||
): Vector[PrisonerManagementOption] =
|
||||
Vector(PrisonerManagementOptionExecute())
|
||||
|
||||
override def availableCommand(
|
||||
gameState: GameState,
|
||||
factionId: FactionId,
|
||||
@@ -27,13 +38,16 @@ object AvailableManagePrisonersCommandFactory
|
||||
ManagePrisonersAvailableCommand(
|
||||
actingProvinceId = provinceId,
|
||||
prisoners = prisoners.map { prisoner =>
|
||||
ExpandedUnaffiliatedHeroUtils.expandedUnaffiliatedHero(
|
||||
gs = gameState,
|
||||
uh = prisoner
|
||||
PrisonerToManage(
|
||||
prisoner = Some(
|
||||
ExpandedUnaffiliatedHeroUtils.expandedUnaffiliatedHero(
|
||||
gs = gameState,
|
||||
uh = prisoner
|
||||
)
|
||||
),
|
||||
availableOptions = optionsForPrisoner(prisoner)
|
||||
)
|
||||
},
|
||||
availableOptions =
|
||||
Vector(PrisonerManagementType.MANAGE_PRISONER_EXECUTE)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+28
-18
@@ -1,7 +1,14 @@
|
||||
package net.eagle0.eagle.library.actions.impl.command
|
||||
|
||||
import net.eagle0.eagle.{FactionId, HeroId, ProvinceId}
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.PrisonerManagementType
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.{
|
||||
PrisonerManagementOption,
|
||||
PrisonerManagementOptionExecute,
|
||||
PrisonerManagementOptionExile,
|
||||
PrisonerManagementOptionMove,
|
||||
PrisonerManagementOptionRelease,
|
||||
PrisonerManagementOptionReturn
|
||||
}
|
||||
import net.eagle0.eagle.api.available_command.ManagePrisonersAvailableCommand
|
||||
import net.eagle0.eagle.api.selected_command.ManagePrisonersSelectedCommand
|
||||
import net.eagle0.eagle.common.action_result_notification_details.PrisonerExecutedDetails
|
||||
@@ -24,17 +31,17 @@ object ManagePrisonersCommand
|
||||
startingState: GameState,
|
||||
provinceId: ProvinceId,
|
||||
prisonerId: HeroId,
|
||||
selectedOption: PrisonerManagementType
|
||||
selectedOption: PrisonerManagementOption
|
||||
) extends SingleResultCommand(
|
||||
startingState = startingState,
|
||||
selectedCommand = sc
|
||||
) {
|
||||
override def immediateExecute: ActionResult = selectedOption match {
|
||||
case PrisonerManagementType.MANAGE_PRISONER_UNKNOWN =>
|
||||
throw new EagleCommandException(
|
||||
"Must specify a prisoner management option"
|
||||
)
|
||||
case PrisonerManagementType.MANAGE_PRISONER_EXECUTE =>
|
||||
case PrisonerManagementOptionRelease() => ???
|
||||
case PrisonerManagementOptionExile() => ???
|
||||
case PrisonerManagementOptionReturn() => ???
|
||||
case PrisonerManagementOptionMove(toProvinceId) => ???
|
||||
case PrisonerManagementOptionExecute() =>
|
||||
ActionResult(
|
||||
`type` = PRISONER_EXECUTED,
|
||||
player = Some(actingFactionId),
|
||||
@@ -57,9 +64,9 @@ object ManagePrisonersCommand
|
||||
.flatMap(_.lastFaction)
|
||||
)
|
||||
)
|
||||
case PrisonerManagementType.Unrecognized(value) =>
|
||||
case PrisonerManagementOption.Empty =>
|
||||
throw new EagleCommandException(
|
||||
s"Unknown prisoner management option $value"
|
||||
"Must specify a prisoner management option"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -70,17 +77,20 @@ object ManagePrisonersCommand
|
||||
availableCommand: ManagePrisonersAvailableCommand,
|
||||
selectedCommand: ManagePrisonersSelectedCommand
|
||||
): Command = {
|
||||
commandRequire(
|
||||
availableCommand.prisoners.exists(
|
||||
_.getHero.id == selectedCommand.prisonerHeroId
|
||||
),
|
||||
s"Selected prisoner hero id ${selectedCommand.prisonerHeroId} was not among available prisoners ${availableCommand.prisoners
|
||||
.map(_.getHero.id)}"
|
||||
val availablePrisonerToManage = availableCommand.prisoners.find(
|
||||
_.getPrisoner.getHero.id == selectedCommand.prisonerHeroId
|
||||
)
|
||||
|
||||
commandRequire(
|
||||
availableCommand.availableOptions.contains(selectedCommand.chosenType),
|
||||
s"Selected management type ${selectedCommand.chosenType} was not among available options ${availableCommand.availableOptions}"
|
||||
availablePrisonerToManage.isDefined,
|
||||
s"Selected prisoner hero id ${selectedCommand.prisonerHeroId} was not among available prisoners ${availableCommand.prisoners
|
||||
.map(_.getPrisoner.getHero.id)}"
|
||||
)
|
||||
|
||||
commandRequire(
|
||||
availablePrisonerToManage.get.availableOptions
|
||||
.contains(selectedCommand.chosenOption),
|
||||
s"Selected management type ${selectedCommand.chosenOption} was not among available options ${availablePrisonerToManage.get.availableOptions}"
|
||||
)
|
||||
|
||||
ManagePrisonersCommand(
|
||||
@@ -89,7 +99,7 @@ object ManagePrisonersCommand
|
||||
startingState = gameState,
|
||||
provinceId = availableCommand.actingProvinceId,
|
||||
prisonerId = selectedCommand.prisonerHeroId,
|
||||
selectedOption = selectedCommand.chosenType
|
||||
selectedOption = selectedCommand.chosenOption
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,10 +310,18 @@ object RandomCommands {
|
||||
def managePrisoners(
|
||||
gs: GameState,
|
||||
ac: ManagePrisonersAvailableCommand
|
||||
): SelectedCommand = ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = ac.prisoners.randomElement.getHero.id,
|
||||
chosenType = ac.availableOptions.randomElement
|
||||
)
|
||||
): SelectedCommand = {
|
||||
ac.prisoners.randomElement match {
|
||||
case PrisonerToManage(Some(prisoner), availableOptions) =>
|
||||
ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = prisoner.getHero.id,
|
||||
chosenOption = availableOptions.randomElement
|
||||
)
|
||||
|
||||
case _ =>
|
||||
throw new EagleInternalException("Illegal prisoner management options")
|
||||
}
|
||||
}
|
||||
|
||||
def attackDecision(
|
||||
gs: GameState,
|
||||
|
||||
+46
-27
@@ -1,10 +1,13 @@
|
||||
package net.eagle0.eagle.library.actions.availability
|
||||
|
||||
import net.eagle0.common.ProtoMatchers.equalProto
|
||||
import net.eagle0.eagle.api.available_command.ManagePrisonersAvailableCommand
|
||||
import net.eagle0.eagle.api.available_command.{
|
||||
ManagePrisonersAvailableCommand,
|
||||
PrisonerToManage
|
||||
}
|
||||
import net.eagle0.eagle.api.command.util.expanded_unaffiliated_hero.ExpandedUnaffiliatedHero
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.PrisonerManagementOptionExecute
|
||||
import net.eagle0.eagle.api.hero_view.HeroView
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.PrisonerManagementType
|
||||
import net.eagle0.eagle.api.stat_with_condition.StatWithCondition
|
||||
import net.eagle0.eagle.common.recruitment_info.RecruitmentInfo
|
||||
import net.eagle0.eagle.common.recruitment_info.RecruitmentStatus.{
|
||||
@@ -86,39 +89,55 @@ class AvailableManagePrisonerCommandsFactoryTest
|
||||
ManagePrisonersAvailableCommand(
|
||||
actingProvinceId = actingProvinceId,
|
||||
prisoners = Vector(
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(
|
||||
HeroView(
|
||||
id = 17,
|
||||
loyalty = Some(
|
||||
StatWithCondition(condition = StatWithCondition.Condition.LOW)
|
||||
PrisonerToManage(
|
||||
prisoner = Some(
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(
|
||||
HeroView(
|
||||
id = 17,
|
||||
loyalty = Some(
|
||||
StatWithCondition(condition =
|
||||
StatWithCondition.Condition.LOW
|
||||
)
|
||||
),
|
||||
vigor = Some(
|
||||
StatWithCondition(condition =
|
||||
StatWithCondition.Condition.LOW
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
vigor = Some(
|
||||
StatWithCondition(condition = StatWithCondition.Condition.LOW)
|
||||
)
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
)
|
||||
),
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
availableOptions = Vector(PrisonerManagementOptionExecute())
|
||||
),
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(
|
||||
HeroView(
|
||||
id = 19,
|
||||
loyalty = Some(
|
||||
StatWithCondition(condition = StatWithCondition.Condition.LOW)
|
||||
PrisonerToManage(
|
||||
prisoner = Some(
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(
|
||||
HeroView(
|
||||
id = 19,
|
||||
loyalty = Some(
|
||||
StatWithCondition(condition =
|
||||
StatWithCondition.Condition.LOW
|
||||
)
|
||||
),
|
||||
vigor = Some(
|
||||
StatWithCondition(condition =
|
||||
StatWithCondition.Condition.LOW
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
vigor = Some(
|
||||
StatWithCondition(condition = StatWithCondition.Condition.LOW)
|
||||
)
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
)
|
||||
),
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
availableOptions = Vector(PrisonerManagementOptionExecute())
|
||||
)
|
||||
),
|
||||
availableOptions =
|
||||
Vector(PrisonerManagementType.MANAGE_PRISONER_EXECUTE)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+35
-25
@@ -1,17 +1,18 @@
|
||||
package net.eagle0.eagle.library.actions.impl.command
|
||||
|
||||
import net.eagle0.eagle.api.available_command.ManagePrisonersAvailableCommand
|
||||
import net.eagle0.eagle.api.available_command.{
|
||||
ManagePrisonersAvailableCommand,
|
||||
PrisonerToManage
|
||||
}
|
||||
import net.eagle0.eagle.api.command.util.expanded_unaffiliated_hero.ExpandedUnaffiliatedHero
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.PrisonerManagementType.{
|
||||
MANAGE_PRISONER_EXECUTE,
|
||||
MANAGE_PRISONER_UNKNOWN
|
||||
import net.eagle0.eagle.api.command.util.prisoner_management_type.{
|
||||
PrisonerManagementOption,
|
||||
PrisonerManagementOptionExecute,
|
||||
PrisonerManagementOptionRelease
|
||||
}
|
||||
import net.eagle0.eagle.api.hero_view.HeroView
|
||||
import net.eagle0.eagle.api.selected_command.ManagePrisonersSelectedCommand
|
||||
import net.eagle0.eagle.common.action_result_notification_details.{
|
||||
PrisonerExchangeDetails,
|
||||
PrisonerExecutedDetails
|
||||
}
|
||||
import net.eagle0.eagle.common.action_result_notification_details.PrisonerExecutedDetails
|
||||
import net.eagle0.eagle.common.action_result_type.ActionResultType.PRISONER_EXECUTED
|
||||
import net.eagle0.eagle.common.recruitment_info.{
|
||||
RecruitmentInfo,
|
||||
@@ -82,24 +83,33 @@ class ManagePrisonersCommandTest
|
||||
ManagePrisonersAvailableCommand(
|
||||
actingProvinceId = actingProvinceId,
|
||||
prisoners = Vector(
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(HeroView(id = 97)),
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
PrisonerToManage(
|
||||
prisoner = Some(
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(HeroView(id = 97)),
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
)
|
||||
),
|
||||
availableOptions = Vector(PrisonerManagementOptionExecute())
|
||||
),
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(HeroView(id = 103)),
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
PrisonerToManage(
|
||||
prisoner = Some(
|
||||
ExpandedUnaffiliatedHero(
|
||||
hero = Some(HeroView(id = 103)),
|
||||
`type` = PRISONER,
|
||||
quest = None
|
||||
)
|
||||
),
|
||||
availableOptions = Vector(PrisonerManagementOptionExecute())
|
||||
)
|
||||
),
|
||||
availableOptions = Vector(MANAGE_PRISONER_EXECUTE)
|
||||
)
|
||||
)
|
||||
|
||||
"make" should "throw if the selected hero id was not in available list" in {
|
||||
val sc = ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = 105,
|
||||
chosenType = MANAGE_PRISONER_EXECUTE
|
||||
chosenOption = PrisonerManagementOptionExecute()
|
||||
)
|
||||
the[EagleCommandException] thrownBy {
|
||||
ManagePrisonersCommand.make(
|
||||
@@ -114,7 +124,7 @@ class ManagePrisonersCommandTest
|
||||
it should "throw if the selected option was not in the available list" in {
|
||||
val sc = ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = 103,
|
||||
chosenType = MANAGE_PRISONER_UNKNOWN
|
||||
chosenOption = PrisonerManagementOptionRelease()
|
||||
)
|
||||
the[EagleCommandException] thrownBy {
|
||||
ManagePrisonersCommand.make(
|
||||
@@ -123,13 +133,13 @@ class ManagePrisonersCommandTest
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = sc
|
||||
)
|
||||
} should have message "requirement failed: Selected management type MANAGE_PRISONER_UNKNOWN was not among available options Vector(MANAGE_PRISONER_EXECUTE)"
|
||||
} should have message "requirement failed: Selected management type PrisonerManagementOptionRelease() was not among available options Vector(PrisonerManagementOptionExecute())"
|
||||
}
|
||||
|
||||
"execute" should "set the basics" in {
|
||||
val sc = ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = 103,
|
||||
chosenType = MANAGE_PRISONER_EXECUTE
|
||||
chosenOption = PrisonerManagementOptionExecute()
|
||||
)
|
||||
|
||||
val results = ManagePrisonersCommand
|
||||
@@ -152,7 +162,7 @@ class ManagePrisonersCommandTest
|
||||
it should "remove the hero from the game" in {
|
||||
val sc = ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = 103,
|
||||
chosenType = MANAGE_PRISONER_EXECUTE
|
||||
chosenOption = PrisonerManagementOptionExecute()
|
||||
)
|
||||
|
||||
val results = ManagePrisonersCommand
|
||||
@@ -174,7 +184,7 @@ class ManagePrisonersCommandTest
|
||||
it should "remove the unaffiliated hero from the province" in {
|
||||
val sc = ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = 103,
|
||||
chosenType = MANAGE_PRISONER_EXECUTE
|
||||
chosenOption = PrisonerManagementOptionExecute()
|
||||
)
|
||||
|
||||
val results = ManagePrisonersCommand
|
||||
@@ -200,7 +210,7 @@ class ManagePrisonersCommandTest
|
||||
it should "generate a notification" in {
|
||||
val sc = ManagePrisonersSelectedCommand(
|
||||
prisonerHeroId = 103,
|
||||
chosenType = MANAGE_PRISONER_EXECUTE
|
||||
chosenOption = PrisonerManagementOptionExecute()
|
||||
)
|
||||
|
||||
val results = ManagePrisonersCommand
|
||||
|
||||
Reference in New Issue
Block a user