mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-29 01:35:42 +00:00
remove dependency from PleaseRecruitMeCommand onto GameState proto (#3063)
This commit is contained in:
@@ -646,24 +646,16 @@ scala_library(
|
||||
"//src/main/scala/net/eagle0/eagle/library/actions:__subpackages__",
|
||||
"//src/test/scala/net/eagle0/eagle/library/actions:__subpackages__",
|
||||
],
|
||||
exports = [
|
||||
":command_builder",
|
||||
":deterministic_single_result_command",
|
||||
"//src/main/scala/net/eagle0/eagle/library/actions/impl/common:deterministic_single_result_action",
|
||||
],
|
||||
deps = [
|
||||
":command_builder",
|
||||
":deterministic_single_result_command",
|
||||
"//src/main/protobuf/net/eagle0/eagle/api:available_command_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/api:selected_command_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/common:action_result_type_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/internal:action_result_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/internal:game_state_scala_proto",
|
||||
"//src/main/scala/net/eagle0/eagle:eagle_pkg",
|
||||
"//src/main/scala/net/eagle0/eagle/library/actions/impl/common:action",
|
||||
"//src/main/scala/net/eagle0/eagle/library/actions/impl/common:deterministic_single_result_action",
|
||||
"//src/main/scala/net/eagle0/eagle/library/actions/impl/common:simple_action",
|
||||
"//src/main/scala/net/eagle0/eagle/library/settings",
|
||||
"//src/main/scala/net/eagle0/eagle/library/util:eagle_require",
|
||||
"//src/main/scala/net/eagle0/eagle/model:province_trait",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -258,7 +258,18 @@ class CommandFactory {
|
||||
ac: PleaseRecruitMeAvailableCommand,
|
||||
sc: PleaseRecruitMeSelectedCommand
|
||||
) =>
|
||||
PleaseRecruitMeCommand.make(actingFactionId, gameState, ac, sc)
|
||||
new SimpleActionWrapper(
|
||||
startingState = gameState,
|
||||
simpleAction = PleaseRecruitMeCommand.make(
|
||||
actingFactionId = actingFactionId,
|
||||
availableCommand = ac,
|
||||
selectedCommand = sc,
|
||||
province =
|
||||
ProvinceWrapper(gameState.provinces(ac.actingProvinceId)),
|
||||
currentDate = gameState.currentDate
|
||||
),
|
||||
selectedCommand = sc
|
||||
)
|
||||
|
||||
case (ac: AlmsAvailableCommand, sc: AlmsSelectedCommand) =>
|
||||
new SimpleActionWrapper(
|
||||
|
||||
+15
-19
@@ -9,16 +9,13 @@ import net.eagle0.eagle.internal.action_result.ActionResult
|
||||
import net.eagle0.eagle.internal.changed_hero.ChangedHero
|
||||
import net.eagle0.eagle.internal.changed_hero.ChangedHero.Loyalty
|
||||
import net.eagle0.eagle.internal.changed_province.ChangedProvince
|
||||
import net.eagle0.eagle.internal.game_state.GameState
|
||||
import net.eagle0.eagle.library.actions.impl.common.SimpleAction
|
||||
import net.eagle0.eagle.library.settings.Settings
|
||||
import net.eagle0.eagle.library.util.EagleRequire.commandRequire
|
||||
import net.eagle0.eagle.model.ProvinceT
|
||||
import net.eagle0.eagle.{FactionId, HeroId, ProvinceId, SettingsKeys}
|
||||
|
||||
object PleaseRecruitMeCommand
|
||||
extends CommandBuilder[
|
||||
PleaseRecruitMeAvailableCommand,
|
||||
PleaseRecruitMeSelectedCommand
|
||||
] {
|
||||
object PleaseRecruitMeCommand {
|
||||
def startingLoyalty: Double = Settings.getDouble(SettingsKeys.startingLoyalty)
|
||||
|
||||
private def acceptResult(
|
||||
@@ -72,12 +69,12 @@ object PleaseRecruitMeCommand
|
||||
|
||||
private case class PleaseRecruitMeCommand(
|
||||
sc: PleaseRecruitMeSelectedCommand,
|
||||
gameState: GameState,
|
||||
factionId: FactionId,
|
||||
provinceId: ProvinceId,
|
||||
unaffiliatedHero: UnaffiliatedHero,
|
||||
accept: Boolean
|
||||
) extends DeterministicSingleResultCommand(gameState, sc) {
|
||||
accept: Boolean,
|
||||
currentDate: Date
|
||||
) extends SimpleAction {
|
||||
override def immediateExecute: ActionResult =
|
||||
if (accept) acceptResult(provinceId, factionId, unaffiliatedHero.heroId)
|
||||
else
|
||||
@@ -85,16 +82,17 @@ object PleaseRecruitMeCommand
|
||||
provinceId,
|
||||
factionId,
|
||||
unaffiliatedHero,
|
||||
gameState.currentDate
|
||||
currentDate
|
||||
)
|
||||
}
|
||||
|
||||
override def make(
|
||||
def make(
|
||||
actingFactionId: FactionId,
|
||||
gameState: GameState,
|
||||
availableCommand: PleaseRecruitMeAvailableCommand,
|
||||
selectedCommand: PleaseRecruitMeSelectedCommand
|
||||
): Command = {
|
||||
selectedCommand: PleaseRecruitMeSelectedCommand,
|
||||
province: ProvinceT,
|
||||
currentDate: Date
|
||||
): SimpleAction = {
|
||||
val provinceId = selectedCommand.provinceId
|
||||
val oneProvincePRM =
|
||||
availableCommand.availableProvinces
|
||||
@@ -113,19 +111,17 @@ object PleaseRecruitMeCommand
|
||||
.map(_.getHero.id)}"
|
||||
)
|
||||
|
||||
val uh = gameState
|
||||
.provinces(provinceId)
|
||||
.unaffiliatedHeroes
|
||||
val uh = province.unaffiliatedHeroes
|
||||
.find(_.heroId == heroId)
|
||||
.get
|
||||
|
||||
PleaseRecruitMeCommand(
|
||||
sc = selectedCommand,
|
||||
gameState = gameState,
|
||||
factionId = actingFactionId,
|
||||
provinceId = provinceId,
|
||||
unaffiliatedHero = uh,
|
||||
accept = selectedCommand.accept
|
||||
accept = selectedCommand.accept,
|
||||
currentDate = currentDate
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,11 +487,15 @@ scala_test(
|
||||
deps = [
|
||||
"//src/main/protobuf/net/eagle0/eagle/api:available_command_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/api:selected_command_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/internal:game_state_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/internal:action_result_scala_proto",
|
||||
"//src/main/protobuf/net/eagle0/eagle/internal:province_scala_proto",
|
||||
"//src/main/scala/net/eagle0/eagle:eagle_pkg",
|
||||
"//src/main/scala/net/eagle0/eagle/library:eagle_client_exception",
|
||||
"//src/main/scala/net/eagle0/eagle/library/actions/impl/command:please_recruit_me_command",
|
||||
"//src/main/scala/net/eagle0/eagle/library/actions/impl/common:simple_action",
|
||||
"//src/main/scala/net/eagle0/eagle/library/settings",
|
||||
"//src/main/scala/net/eagle0/eagle/library/util:idable",
|
||||
"//src/main/scala/net/eagle0/eagle/model:province_trait",
|
||||
"//src/main/scala/net/eagle0/eagle/model/wrappers:province_wrapper",
|
||||
"//src/test/scala/net/eagle0/common:proto_matchers",
|
||||
],
|
||||
)
|
||||
|
||||
+35
-57
@@ -20,13 +20,10 @@ import net.eagle0.eagle.common.unaffiliated_hero.UnaffiliatedHero.Type.{
|
||||
RESIDENT,
|
||||
TRAVELER
|
||||
}
|
||||
import net.eagle0.eagle.internal.faction.Faction
|
||||
import net.eagle0.eagle.internal.game_state.GameState
|
||||
import net.eagle0.eagle.internal.hero.Hero
|
||||
import net.eagle0.eagle.internal.province.Province
|
||||
import net.eagle0.eagle.library.EagleCommandException
|
||||
import net.eagle0.eagle.library.settings.Settings
|
||||
import net.eagle0.eagle.library.util.IDable.{mapifyHeroes, mapifyProvinces}
|
||||
import net.eagle0.eagle.model.wrappers.ProvinceWrapper
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
@@ -47,12 +44,12 @@ class PleaseRecruitMeCommandTest
|
||||
val actingFactionId = 13
|
||||
val actingProvinceId = 9
|
||||
|
||||
val expandedUHs: Vector[ExpandedUnaffiliatedHero] = Vector(
|
||||
private val expandedUHs: Vector[ExpandedUnaffiliatedHero] = Vector(
|
||||
ExpandedUnaffiliatedHero(hero = Some(HeroView(id = 18))),
|
||||
ExpandedUnaffiliatedHero(hero = Some(HeroView(id = 14)))
|
||||
)
|
||||
|
||||
private val province = Province(
|
||||
private val provinceProto = Province(
|
||||
id = actingProvinceId,
|
||||
rulingFactionId = Some(actingFactionId),
|
||||
unaffiliatedHeroes = Vector(
|
||||
@@ -77,6 +74,7 @@ class PleaseRecruitMeCommandTest
|
||||
),
|
||||
provinceOrders = ProvinceOrderType.ENTRUST
|
||||
)
|
||||
private val province = ProvinceWrapper(provinceProto)
|
||||
|
||||
private val availableCommand = PleaseRecruitMeAvailableCommand(
|
||||
actingProvinceId = actingProvinceId,
|
||||
@@ -90,13 +88,6 @@ class PleaseRecruitMeCommandTest
|
||||
|
||||
private val currentDate = Date(month = 4, year = 98)
|
||||
|
||||
private val gameState = GameState(
|
||||
heroes = mapifyHeroes(Hero(id = 14), Hero(id = 18)),
|
||||
provinces = mapifyProvinces(province),
|
||||
currentDate = currentDate,
|
||||
factions = Map(actingFactionId -> Faction(id = actingFactionId))
|
||||
)
|
||||
|
||||
"make" should "throw if the selected province is not among available" in {
|
||||
val selectedCommand = PleaseRecruitMeSelectedCommand(
|
||||
provinceId = 4,
|
||||
@@ -107,9 +98,10 @@ class PleaseRecruitMeCommandTest
|
||||
the[EagleCommandException] thrownBy {
|
||||
PleaseRecruitMeCommand.make(
|
||||
actingFactionId = actingFactionId,
|
||||
gameState = gameState,
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = selectedCommand
|
||||
selectedCommand = selectedCommand,
|
||||
province = province,
|
||||
currentDate = currentDate
|
||||
)
|
||||
} should have message "requirement failed: Selected province 4 was not among available Vector(9)"
|
||||
}
|
||||
@@ -124,9 +116,10 @@ class PleaseRecruitMeCommandTest
|
||||
the[EagleCommandException] thrownBy {
|
||||
PleaseRecruitMeCommand.make(
|
||||
actingFactionId = actingFactionId,
|
||||
gameState = gameState,
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = selectedCommand
|
||||
selectedCommand = selectedCommand,
|
||||
province = province,
|
||||
currentDate = currentDate
|
||||
)
|
||||
} should have message "requirement failed: Selected hero 21 was not among available Vector(18, 14)"
|
||||
}
|
||||
@@ -138,19 +131,16 @@ class PleaseRecruitMeCommandTest
|
||||
accept = true
|
||||
)
|
||||
|
||||
val results =
|
||||
val ar =
|
||||
PleaseRecruitMeCommand
|
||||
.make(
|
||||
actingFactionId = actingFactionId,
|
||||
gameState = gameState,
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = selectedCommand
|
||||
selectedCommand = selectedCommand,
|
||||
province = province,
|
||||
currentDate = currentDate
|
||||
)
|
||||
.execute
|
||||
|
||||
results should have size 1
|
||||
|
||||
val ar = results.head.actionResult
|
||||
.immediateExecute
|
||||
|
||||
ar.changedProvinces should have size 1
|
||||
ar.changedProvinces.head.addedRulingPlayerHeroIds shouldBe Vector(14)
|
||||
@@ -163,19 +153,16 @@ class PleaseRecruitMeCommandTest
|
||||
accept = true
|
||||
)
|
||||
|
||||
val results =
|
||||
val ar =
|
||||
PleaseRecruitMeCommand
|
||||
.make(
|
||||
actingFactionId = actingFactionId,
|
||||
gameState = gameState,
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = selectedCommand
|
||||
selectedCommand = selectedCommand,
|
||||
province = province,
|
||||
currentDate = currentDate
|
||||
)
|
||||
.execute
|
||||
|
||||
results should have size 1
|
||||
|
||||
val ar = results.head.actionResult
|
||||
.immediateExecute
|
||||
|
||||
ar.changedHeroes should have size 1
|
||||
ar.changedHeroes.head.newFactionId shouldBe Some(actingFactionId)
|
||||
@@ -188,19 +175,16 @@ class PleaseRecruitMeCommandTest
|
||||
accept = true
|
||||
)
|
||||
|
||||
val results =
|
||||
val ar =
|
||||
PleaseRecruitMeCommand
|
||||
.make(
|
||||
actingFactionId = actingFactionId,
|
||||
gameState = gameState,
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = selectedCommand
|
||||
selectedCommand = selectedCommand,
|
||||
province = province,
|
||||
currentDate = currentDate
|
||||
)
|
||||
.execute
|
||||
|
||||
results should have size 1
|
||||
|
||||
val ar = results.head.actionResult
|
||||
.immediateExecute
|
||||
|
||||
ar.changedProvinces should have size 1
|
||||
ar.changedProvinces.head.removedUnaffiliatedHeroIds shouldBe Vector(14)
|
||||
@@ -213,19 +197,16 @@ class PleaseRecruitMeCommandTest
|
||||
accept = false
|
||||
)
|
||||
|
||||
val results =
|
||||
val ar =
|
||||
PleaseRecruitMeCommand
|
||||
.make(
|
||||
actingFactionId = actingFactionId,
|
||||
gameState = gameState,
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = selectedCommand
|
||||
selectedCommand = selectedCommand,
|
||||
province = province,
|
||||
currentDate = currentDate
|
||||
)
|
||||
.execute
|
||||
|
||||
results should have size 1
|
||||
|
||||
val ar = results.head.actionResult
|
||||
.immediateExecute
|
||||
|
||||
ar.changedProvinces should have size 1
|
||||
ar.changedProvinces.head.removedUnaffiliatedHeroIds shouldBe empty
|
||||
@@ -238,19 +219,16 @@ class PleaseRecruitMeCommandTest
|
||||
accept = false
|
||||
)
|
||||
|
||||
val results =
|
||||
val ar =
|
||||
PleaseRecruitMeCommand
|
||||
.make(
|
||||
actingFactionId = actingFactionId,
|
||||
gameState = gameState,
|
||||
availableCommand = availableCommand,
|
||||
selectedCommand = selectedCommand
|
||||
selectedCommand = selectedCommand,
|
||||
province = province,
|
||||
currentDate = currentDate
|
||||
)
|
||||
.execute
|
||||
|
||||
results should have size 1
|
||||
|
||||
val ar = results.head.actionResult
|
||||
.immediateExecute
|
||||
|
||||
ar.changedProvinces should have size 1
|
||||
ar.changedProvinces.head.changedUnaffiliatedHeroes should have size 1
|
||||
|
||||
Reference in New Issue
Block a user