Acquire Great Person Quest implemented (#3210)

* Acquire Great Person Quest implemented

* List to sequence to list
This commit is contained in:
Federico Luongo
2020-10-06 09:48:59 +02:00
committed by GitHub
parent e951ed8324
commit f9ebc8aa0f
4 changed files with 35 additions and 2 deletions

View File

@ -19,11 +19,11 @@
{ {
"name": "Construct Wonder", "name": "Construct Wonder",
"description": "We recommend you to start building [wonder] to show the whole world your civilization strength." "description": "We recommend you to start building [wonder] to show the whole world your civilization strength."
}/*, },
{ {
"name": "Acquire Great Person", "name": "Acquire Great Person",
"description": "Great People can change the course of a Civilization! You will be rewarded for acquiring a new [greatPerson]." "description": "Great People can change the course of a Civilization! You will be rewarded for acquiring a new [greatPerson]."
}, }/*,
{ {
"name": "Conquer City State", "name": "Conquer City State",
"description": "You will be rewarded for conquering the city state of [cityState]!", "description": "You will be rewarded for conquering the city state of [cityState]!",

View File

@ -197,6 +197,7 @@ class CivilizationInfo {
//region Units //region Units
fun getCivUnits(): Sequence<MapUnit> = units.asSequence() fun getCivUnits(): Sequence<MapUnit> = units.asSequence()
fun getCivGreatPeople(): Sequence<MapUnit> = getCivUnits().filter { mapUnit -> mapUnit.hasUnique("Great Person - []") }
fun addUnit(mapUnit: MapUnit, updateCivInfo:Boolean=true){ fun addUnit(mapUnit: MapUnit, updateCivInfo:Boolean=true){
val newList = ArrayList(units) val newList = ArrayList(units)

View File

@ -250,6 +250,7 @@ class QuestManager {
when (quest.name) { when (quest.name) {
QuestName.ConnectResource.value -> data1 = getResourceForQuest(assignee)!!.name QuestName.ConnectResource.value -> data1 = getResourceForQuest(assignee)!!.name
QuestName.ConstructWonder.value -> data1 = getWonderToBuildForQuest(assignee)!!.name QuestName.ConstructWonder.value -> data1 = getWonderToBuildForQuest(assignee)!!.name
QuestName.GreatPerson.value -> data1 = getGreatPersonForQuest(assignee)!!.name
} }
val newQuest = AssignedQuest( val newQuest = AssignedQuest(
@ -287,6 +288,7 @@ class QuestManager {
QuestName.Route.value -> civInfo.hasEverBeenFriendWith(challenger) && !civInfo.isCapitalConnectedToCity(challenger.getCapital()) QuestName.Route.value -> civInfo.hasEverBeenFriendWith(challenger) && !civInfo.isCapitalConnectedToCity(challenger.getCapital())
QuestName.ConnectResource.value -> civInfo.hasEverBeenFriendWith(challenger) && getResourceForQuest(challenger) != null QuestName.ConnectResource.value -> civInfo.hasEverBeenFriendWith(challenger) && getResourceForQuest(challenger) != null
QuestName.ConstructWonder.value -> civInfo.hasEverBeenFriendWith(challenger) && getWonderToBuildForQuest(challenger) != null QuestName.ConstructWonder.value -> civInfo.hasEverBeenFriendWith(challenger) && getWonderToBuildForQuest(challenger) != null
QuestName.GreatPerson.value -> civInfo.hasEverBeenFriendWith(challenger) && getGreatPersonForQuest(challenger) != null
else -> true else -> true
} }
} }
@ -298,6 +300,7 @@ class QuestManager {
QuestName.Route.value -> civInfo.isCapitalConnectedToCity(assignee.getCapital()) QuestName.Route.value -> civInfo.isCapitalConnectedToCity(assignee.getCapital())
QuestName.ConnectResource.value -> assignee.detailedCivResources.map { it.resource }.contains(civInfo.gameInfo.ruleSet.tileResources[assignedQuest.data1]) QuestName.ConnectResource.value -> assignee.detailedCivResources.map { it.resource }.contains(civInfo.gameInfo.ruleSet.tileResources[assignedQuest.data1])
QuestName.ConstructWonder.value -> assignee.cities.any { it.cityConstructions.isBuilt(assignedQuest.data1) } QuestName.ConstructWonder.value -> assignee.cities.any { it.cityConstructions.isBuilt(assignedQuest.data1) }
QuestName.GreatPerson.value -> assignee.getCivGreatPeople().any { it.baseUnit.getReplacedUnit(civInfo.gameInfo.ruleSet).name == assignedQuest.data1 }
else -> false else -> false
} }
} }
@ -367,6 +370,30 @@ class QuestManager {
return null return null
} }
/**
* Returns a Great Person [BaseUnit] that is not owned by both the [challenger] and the [civInfo]
*/
private fun getGreatPersonForQuest(challenger: CivilizationInfo): BaseUnit? {
val ruleSet = civInfo.gameInfo.ruleSet
val challengerGreatPeople = challenger.getCivGreatPeople().map { it.baseUnit.getReplacedUnit(ruleSet) }
val cityStateGreatPeople = civInfo.getCivGreatPeople().map { it.baseUnit.getReplacedUnit(ruleSet) }
val greatPeople = ruleSet.units.values
.asSequence()
.filter { baseUnit -> baseUnit.uniques.any { it.equalsPlaceholderText("Great Person - []") } }
.map { it.getReplacedUnit(ruleSet) }
.distinct()
.filter { !challengerGreatPeople.contains(it) && !cityStateGreatPeople.contains(it) }
.toList()
if (greatPeople.isNotEmpty())
return greatPeople.random()
return null
}
//endregion //endregion
} }

View File

@ -195,4 +195,9 @@ class BaseUnit : INamed, IConstruction {
} }
override fun toString(): String = name override fun toString(): String = name
fun getReplacedUnit(ruleset: Ruleset): BaseUnit {
return if (replaces == null) this
else ruleset.units[replaces!!]!!
}
} }