Skip to content

Commit

Permalink
better check changed game conditions causing the trader request actio…
Browse files Browse the repository at this point in the history
…n to become invalid
  • Loading branch information
Arakos committed Aug 28, 2022
1 parent 16b10da commit ac93118
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 16 deletions.
10 changes: 8 additions & 2 deletions Languages/English/Keyed/CallATrader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@

<acat.job.infomessage.success>A trading request was send to the Orbital Traders Hub. They will not answer any requests from you for {0}.</acat.job.infomessage.success>

<!-- Incident refusal (due to game conditions) -->
<acat.incident.refusal.label>Refusal notice from Orbital Traders Hub</acat.incident.refusal.label>
<acat.incident.refusal.base>The Orbital Traders Hub has to decline your trading request.</acat.incident.refusal.base>
<acat.incident.refusal.toomanytraders>This is because there are too many ({0}) tradeships at your location already.</acat.incident.refusal.toomanytraders>
<acat.incident.refusal.noorbitaltradersavailable>This is because they currently have no traders available near your colony.</acat.incident.refusal.noorbitaltradersavailable>

<!-- Trader offer letter -->
<acat.traderletter.label>Offer from Orbital Traders Hub</acat.traderletter.label>
<acat.traderletter.text>The Orbital Traders Hub offers to send an orbital trader ship to your location in {0}.\n\nThey request an upfront fee of {1} silver to cover their costs for adjusting the ships route.\n\nThe silver will be teleported to the hub immediately - if you accept.\n</acat.traderletter.text>
<acat.traderletter.accept>Request {0}</acat.traderletter.accept>
<acat.traderletter.refuse>Decline the offer</acat.traderletter.refuse>
<acat.traderletter.disabled>{0}/{1} silver</acat.traderletter.disabled>
<acat.traderletter.toomanytraders>The requested trader refuses to show up because there are too many tradeships at your location already.</acat.traderletter.toomanytraders>
<acat.traderletter.error.ok>Wait there are no traders to select ...</acat.traderletter.error.ok>
<acat.traderletter.payed>The fee of {0} Silver was yeeted to the Orbital Traders Hub</acat.traderletter.payed>

<!-- Mod options menu -->
<acat.costsrange>Cost range (silver)</acat.costsrange>
<acat.costsrange.description>Range of silver the Orbital Traders Hub will request to send a ship</acat.costsrange.description>
Expand Down
10 changes: 8 additions & 2 deletions Languages/German/Keyed/CallATrader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@

<acat.job.infomessage.success>Es wurde eine Handelsanfrage an die Fliegenden Hausierer gestellt. Sie werden für {0} keine weiteren Anfragen akzeptieren.</acat.job.infomessage.success>

<!-- Incident refusal (due to game conditions) -->
<acat.incident.refusal.label>Ablehnung der Fliegenden Hausierer</acat.incident.refusal.label>
<acat.incident.refusal.base>Die Fliegenden Hausierer haben deine Anfrage einen Händler zu schicken abgelehnt.</acat.incident.refusal.base>
<acat.incident.refusal.toomanytraders>Dies begründen sie damit, dass bereits zu viele ({0}) Handelsshiffe in deiner Kolonie zugegen sind.</acat.incident.refusal.toomanytraders>
<acat.incident.refusal.noorbitaltradersavailable>Dies begründen sie damit, dass sie aktuell aus Gründen keine Handelsshiffe zu deiner Kolonie senden können.</acat.incident.refusal.noorbitaltradersavailable>

<!-- Trader offer letter -->
<acat.traderletter.label>Angebot der Fliegenden Hausierer</acat.traderletter.label>
<acat.traderletter.text>Die Fliegenden Hausierer bieten dir an eines ihrer Schiffe zu deiner Kolonie zu senden. Dies wird {0} dauern.\n\nSie fordern allerdings eine Sofortzahlung von {1} Silber um die Kosten der Routenanpassung zu decken.\n\nBei Angebotsannahme wird diese Summe sofort zur Zentrale der Fliegenden Hausierer teleportiert.\n</acat.traderletter.text>
<acat.traderletter.accept>Frage {0} an</acat.traderletter.accept>
<acat.traderletter.refuse>Angebot ablehnen</acat.traderletter.refuse>
<acat.traderletter.disabled>{0}/{1} Silber</acat.traderletter.disabled>
<acat.traderletter.toomanytraders>Der angeforderte Händler verweigert die Anreise, da aktuell zu viele Handelsshiffe in der Region sind.</acat.traderletter.toomanytraders>
<acat.traderletter.error.ok>Warte, hier gibts es keine Händler zur Auswahl ...</acat.traderletter.error.ok>
<acat.traderletter.payed>Die Zahlung von {0} Silber wurde zur Zentrale der Fliegenden Hausierer teleportiert.</acat.traderletter.payed>

<!-- Mod options menu -->
<acat.costsrange>Kosten (Silber)</acat.costsrange>
<acat.costsrange.description>Spannweite der Kosten, die die Fliegenden Hausierer für ihren Service einfordern werden</acat.costsrange.description>
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
18 changes: 10 additions & 8 deletions Source/rimworld/ChoiceLetter_SelectTrader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
Expand Down Expand Up @@ -58,6 +59,15 @@ public override IEnumerable<DiaOption> Choices

IList<TraderKindDef> orbitalTraderDefs = DefDatabase<TraderKindDef>.AllDefsListForReading.FindAll(def => def.orbital);

// check game conditions still allow triggering the offer event now to determine if trader selection can continue
// if not a refusal notice will be send here as well
if (IncidentWorker_OrbitalTraderVisitingOffer.TryExecuteWorkerInternal(
this.map, orbitalTraderDefs, IncidentWorker_OrbitalTraderVisitingOffer.IncidentTrigger.LETTER_EVENT))
{
yield return CreateDiaOption((Constants.MOD_PREFIX + TRADER_LETTER + "error.ok").Translate());
yield break;
}

if (!this.canSelectTraderType)
{
orbitalTraderDefs = new TraderKindDef[] { orbitalTraderDefs.RandomElement() };
Expand All @@ -70,14 +80,6 @@ public override IEnumerable<DiaOption> Choices
{
Find.LetterStack.RemoveLetter(this);

// hardcoded limit of 5 in the basegame
if (this.map.passingShipManager.passingShips.Count >= 5)
{
// send info message so player knowns too many ships present already
Messages.Message((Constants.MOD_PREFIX + TRADER_LETTER + "toomanytraders").Translate(), null, MessageTypeDefOf.NeutralEvent, true);
return;
}

Find.Storyteller.incidentQueue.Add(new QueuedIncident(
new FiringIncident(IncidentDefOf.OrbitalTraderArrival, null,
new IncidentParms()
Expand Down
60 changes: 58 additions & 2 deletions Source/rimworld/IncidentWorker_OrbitalTraderVisitingOffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,71 @@ namespace Arakos.CallATrader
public class IncidentWorker_OrbitalTraderVisitingOffer : IncidentWorker
{

private static readonly String INCIDENT = ".incident.";

private static readonly int HARDCODED_SHIP_LIMIT = 5;

public enum IncidentTrigger
{
RANDOM_EVENT, PLAYER_EVENT, LETTER_EVENT
}

protected override bool CanFireNowSub(IncidentParms parms)
{
return parms.forced || CallATrader.settings.randomEventAllowed;
}

protected override bool TryExecuteWorker(IncidentParms parms)
{
Find.LetterStack.ReceiveLetter(new ChoiceLetter_SelectTrader((Map)parms.target));
return true;
return TryExecuteWorkerInternal((Map)parms.target,
DefDatabase<TraderKindDef>.AllDefsListForReading,
parms.forced ? IncidentTrigger.PLAYER_EVENT : IncidentTrigger.RANDOM_EVENT);
}

public static bool TryExecuteWorkerInternal(Map map, IList<TraderKindDef> orbitalTraderDefs, IncidentTrigger eventTrigger)
{
String displayableError = GetDisplayableError(map, orbitalTraderDefs);
Letter letter = null;

// if error but from non-interactive event trigger - ignore silently to not confuse player with random refusal messages
if (displayableError != null && eventTrigger != IncidentTrigger.RANDOM_EVENT)
{
letter = LetterMaker.MakeLetter(
(Constants.MOD_PREFIX + INCIDENT + "refusal.label").Translate(),
(Constants.MOD_PREFIX + INCIDENT + "refusal.base").Translate() + "\n\n" + displayableError,
LetterDefOf.NeutralEvent);
}

// if no error and not triggered by a letter event already send the choice letter
if (displayableError == null && eventTrigger != IncidentTrigger.LETTER_EVENT)
{
letter = new ChoiceLetter_SelectTrader(map);
}

if (letter != null)
{
Find.LetterStack.ReceiveLetter(letter);
return true;
}

return false;
}

public static String GetDisplayableError(Map map, IList<TraderKindDef> orbitalTraderDefs)
{
// colony situation causing no orbital traders to be available
if (!orbitalTraderDefs.Any(def => def.orbital))
{
return (Constants.MOD_PREFIX + INCIDENT + "refusal.noorbitaltradersavailable").Translate();
}

// check the limit of ships in the basegame
if (map.passingShipManager.passingShips.Count >= HARDCODED_SHIP_LIMIT)
{
return (Constants.MOD_PREFIX + INCIDENT + "refusal.toomanytraders").Translate(HARDCODED_SHIP_LIMIT);
}

return null;
}
}
}

0 comments on commit ac93118

Please sign in to comment.