Skip to content

Commit

Permalink
Quest rebalancing/bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa committed Jul 26, 2021
1 parent ad6d457 commit b6f4150
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 27 deletions.
4 changes: 2 additions & 2 deletions 1.3/Defs/Duties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<thinkNode Class="ThinkNode_Priority">
<subNodes>
<li Class="JobGiver_AIFightEnemies">
<targetAcquireRadius>80</targetAcquireRadius>
<targetKeepRadius>100</targetKeepRadius>
<targetAcquireRadius>60</targetAcquireRadius>
<targetKeepRadius>80</targetKeepRadius>
</li>
<li Class="JobGiver_AIGotoNearestHostile" />
<li Class="ThinkNode_Subtree">
Expand Down
6 changes: 3 additions & 3 deletions 1.3/Defs/Incidents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<messageType>NegativeEvent</messageType>
</li>
</questParts>
<baseChance>0.1</baseChance>
<baseChance>0.08</baseChance>
</IncidentDef>

<IncidentDef Class="Cities.QuestDef">
Expand Down Expand Up @@ -131,7 +131,7 @@
<messageType>NegativeEvent</messageType>
</li>
</questParts>
<baseChance>0.02</baseChance>
<baseChance>0.03</baseChance>
<EnterCityLabel>Defend City</EnterCityLabel>
</IncidentDef>

Expand All @@ -156,7 +156,7 @@
<messageType>NegativeEvent</messageType>
</li>
</questParts>
<baseChance>0.1</baseChance>
<baseChance>0.05</baseChance>
<EnterCityLabel>Prison Break</EnterCityLabel>
</IncidentDef>

Expand Down
17 changes: 11 additions & 6 deletions Source/Incident/IncidentWorker_Quest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ public class IncidentWorker_Quest : IncidentWorker_Cached {
public override LookTargets LetterTargets => quest.Targets;
public override NamedArgument[] LetterParams => quest.FormatArgs;

public override bool CheckIncident(IncidentParms parms) {
if (!Config_Cities.Instance.enableQuestSystem) {
return false;
}

void SetupQuest(IncidentParms parms) {
if (quest == null || quest.Started) {
var questDef = Def;
quest = (Quest) System.Activator.CreateInstance(questDef.questClass);
quest.def = questDef;
}

quest.ChooseParts();
}

public override bool CheckIncident(IncidentParms parms) {
if (!Config_Cities.Instance.enableQuestSystem) {
return false;
}
SetupQuest(parms);
return quest.CanReceiveRandomly();
}

public override bool StartIncident(IncidentParms parms) {
if (quest == null || quest.Started) {
SetupQuest(parms);
}
if (quest.AllPartsValid()) {
quest.Start();
return true;
Expand Down
14 changes: 6 additions & 8 deletions Source/Quest/City/Quest_Assassinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public override void ExposeData() {
Scribe_References.Look(ref city, "city");
Scribe_References.Look(ref pawn, "pawn");

if (pawn == null && city?.Faction != null && handle != null)
{
if (pawn == null && city?.Faction != null && handle != null) {
GeneratePawn();

// regenerate quest description
handle.description = DetailText;

// remove any QuestParts
foreach (var part in handle.PartsListForReading.ToArray())
foreach (var part in handle.PartsListForReading.ToArray()) {
handle.RemovePart(part);
}

// add new QuestParts
OnSetupHandle(handle);
Expand All @@ -39,19 +39,17 @@ public override void ChooseParts() {
base.ChooseParts();
city = Find.WorldObjects.Settlements
.OfType<City>()
.Where(s => s.Visitable && !s.Abandoned && !s.HasMap && !(s is Citadel))
.Where(s => s.Visitable && !s.Abandoned && !s.HasMap && !(s is Citadel) && s.FindQuests().Count == 0)
.RandomByDistance(HomeMap?.Parent, 80);
if (city == null)
return;

GeneratePawn();
}

private void GeneratePawn()
{
void GeneratePawn() {
var faction = city.Faction;
pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(faction.RandomPawnKind(), faction,
PawnGenerationContext.NonPlayer, city.Tile));
pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(faction.RandomPawnKind(), faction, PawnGenerationContext.NonPlayer, city.Tile));
}

public override bool AllPartsValid() {
Expand Down
2 changes: 1 addition & 1 deletion Source/Quest/City/Quest_Assault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void ChooseParts() {
alliedFaction = Find.FactionManager.RandomAlliedFaction(minTechLevel: TechLevel.Industrial);
target = Find.WorldObjects.Settlements
.OfType<City>()
.Where(s => s.Faction.HostileTo(Faction.OfPlayer) && !s.HasMap && !(s is Citadel))
.Where(s => s.Faction.HostileTo(Faction.OfPlayer) && !s.HasMap && !(s is Citadel) && s.FindQuests().Count == 0)
.RandomByDistance(HomeMap?.Parent, 80);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Quest/City/Quest_Defend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void ChooseParts() {
enemyFaction = Find.FactionManager.RandomEnemyFaction(minTechLevel: TechLevel.Industrial);
city = Find.WorldObjects.Settlements
.OfType<City>()
.Where(s => s.Visitable && !s.Abandoned && !s.HasMap && !(s is Citadel))
.Where(s => s.Visitable && !s.Abandoned && !s.HasMap && !(s is Citadel) && s.FindQuests().Count == 0)
.RandomByDistance(HomeMap?.Parent, 80);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Quest/City/Quest_Hostages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void ChooseParts() {
base.ChooseParts();
city = Find.WorldObjects.Settlements
.OfType<City>()
.Where(s => s.Visitable && !s.Abandoned && !s.HasMap && !(s is Citadel))
.Where(s => s.Visitable && !s.Abandoned && !s.HasMap && !(s is Citadel) && s.FindQuests().Count == 0)
.RandomByDistance(HomeMap?.Parent, Rand.RangeInclusive(20, 100));
if (city == null) {
return;
Expand Down
4 changes: 3 additions & 1 deletion Source/Quest/City/Quest_PrisonBreak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Quest_PrisonBreak : Quest {
City city;

public override int MinCapableColonists => 1;
public override int ChallengeRating => 3;

public override LookTargets Targets => city;

Expand All @@ -23,7 +24,8 @@ public override void ExposeData() {
public override void ChooseParts() {
base.ChooseParts();
city = Find.WorldObjects.Settlements
.Where(s => s is City city && city.Visitable && city.inhabitantFaction != null && city.inhabitantFaction.PlayerGoodwill < 50 && !(s is Citadel)
.OfType<City>()
.Where(s => s.Visitable && s.inhabitantFaction != null && s.inhabitantFaction.PlayerGoodwill < 50 && !(s is Citadel) && s.FindQuests().Count == 0
&& QuestUtility.Reachable(HomeMap?.Parent, s, 80)
&& !s.HasMap)
.RandomElementWithFallback() as City;
Expand Down
2 changes: 1 addition & 1 deletion Source/Quest/City/Quest_Sabotage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void ChooseParts() {
base.ChooseParts();
target = Find.WorldObjects.Settlements
.OfType<City>()
.Where(s => s.Visitable && s.inhabitantFaction != null && s.inhabitantFaction.PlayerGoodwill < 50 && !s.HasMap && !(s is Citadel))
.Where(s => s.Visitable && s.inhabitantFaction != null && s.inhabitantFaction.PlayerGoodwill < 50 && !s.HasMap && !(s is Citadel) && s.FindQuests().Count == 0)
.RandomByDistance(HomeMap?.Parent, 80);
}

Expand Down
3 changes: 1 addition & 2 deletions Source/Quest/Quest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public virtual void ExposeData() {
}

protected virtual bool IsValidHome(Map map) {
return map?.Parent?.Faction != null && !map.ParentFaction.HostileTo(Faction.OfPlayer) &&
HasSufficientColonists(map);
return map?.Parent?.Faction != null && !map.ParentFaction.HostileTo(Faction.OfPlayer) && HasSufficientColonists(map);
}

protected virtual bool HasSufficientColonists(Map map) {
Expand Down
3 changes: 2 additions & 1 deletion Source/Util/GenCity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using RimWorld.BaseGen;
using Verse;
Expand Down
6 changes: 6 additions & 0 deletions Source/World/City.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,11 @@ public virtual IntVec3 ChooseMapSize(IntVec3 mapSize) {
}
return mapSize;
}

public List<Quest> FindQuests() {
return Find.World.GetComponent<WorldComponent_QuestTracker>().quests
.Where(quest => !quest.Ended && quest.Targets.targets.Any(target => target.WorldObject == this))
.ToList();
}
}
}

0 comments on commit b6f4150

Please sign in to comment.