Skip to content

Commit

Permalink
Merge pull request #1 from Mehni/unstable-1.0
Browse files Browse the repository at this point in the history
Unstable 1.0
  • Loading branch information
Mehni authored Aug 29, 2018
2 parents d93b668 + dac79f5 commit ce3f684
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 52 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModMetaData>
<name>Dismiss Trader</name>
<author>Mehni</author>
<targetVersion>0.18.0</targetVersion>
<targetVersion>0.19.0</targetVersion>
<description>Dismiss traders with the click of a button.</description>
<url>https://ludeon.com/forums/index.php?topic=35832.0</url>
</ModMetaData>
Binary file modified Assemblies/0Harmony.dll
Binary file not shown.
Binary file modified Assemblies/Dismiss_Trader.dll
Binary file not shown.
46 changes: 16 additions & 30 deletions Source/Dismiss_Trader.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using RimWorld;
using RimWorld;
using Verse;
using Harmony;
using System.Collections;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Linq;
using System.Reflection;
using UnityEngine;
using Verse.AI;

Expand All @@ -29,35 +24,26 @@ private static void FloatMenuMakerMap_AddHumanlikeOrdersToDismissTraders_PostFix
{
Pawn localpawn = pawn;
LocalTargetInfo dest = target;
if (!pawn.CanReach(dest, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)) return;
else if (pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled) return;
else
if (!pawn.CanReach(dest, PathEndMode.OnCell, Danger.Deadly)) return;
if (pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled) return;

Pawn pTarg = (Pawn)dest.Thing;
void Action()
{
Pawn pTarg = (Pawn)dest.Thing;
Action action = delegate
{
Job job = new Job(TraderDismissalJobDefs.DismissTrader, pTarg)
{
playerForced = true
};
localpawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
};
Job job = new Job(TraderDismissalJobDefs.DismissTrader, pTarg) { playerForced = true };
localpawn.jobs.TryTakeOrderedJob(job);
}

string str = string.Empty;
if (pTarg.Faction != null)
{
str = " (" + pTarg.Faction.Name + ")";
}
string str = string.Empty;
if (pTarg.Faction != null)
{
str = " (" + pTarg.Faction.Name + ")";
}

string label = "GETOUT".Translate(new object[]
{
pTarg.LabelShort + ", " + pTarg.TraderKind.label
}) + str;
string label = "GETOUT".Translate(pTarg.LabelShort + ", " + pTarg.TraderKind.label) + str;

opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(label, action, MenuOptionPriority.InitiateSocial, null, dest.Thing, 0f, null, null), pawn, pTarg, "ReservedBy"));
}
opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(label, Action, MenuOptionPriority.InitiateSocial, null, dest.Thing), pawn, pTarg));
}
return;
}
}

Expand Down
28 changes: 9 additions & 19 deletions Source/JobDriver_DismissTrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@ namespace Dismiss_Trader
{
class JobDriver_DismissTrader : JobDriver
{
private Pawn Trader
{
get
{
return (Pawn)base.TargetThingA;
}
}
private Pawn Trader => (Pawn)base.TargetThingA;

public override bool TryMakePreToilReservations()
{
return this.pawn.Reserve(this.Trader, this.job, 1, -1, null);
}
public override bool TryMakePreToilReservations(bool errorOnFailed) => this.pawn.Reserve(this.Trader, this.job);

//approach: find Lord transition that is the regular time-out and add another (very short) Trigger_TicksPassed. That'll then fire, and the traders will leave.

//other (failed) approaches:
//other (failed) approaches:
//- inheriting from LordJob_TradeWithColony and overriding the stategraph. Set a bool in the job, which works as a trigger. Still seems like the "correct" and OOP approach, but I suck at C#
//- adding new LordToil_ExitMapAndEscortCarriers() & telling the lord to jump to it. (lord null, somehow not registered in graph?)
//- Outright removing the lord. Works, but also removes the traderflag, defending at exit and the group behaviour. Bad.
Expand All @@ -37,20 +28,19 @@ protected override IEnumerable<Toil> MakeNewToils()
this.FailOnDespawnedOrNull(TargetIndex.A);
yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOn(() => !this.Trader.CanTradeNow);
Toil trade = new Toil();
trade.initAction = delegate
trade.initAction = () =>
{
Pawn actor = trade.actor;
if (this.Trader.CanTradeNow)
{
{
Lord lord = Trader.GetLord();
List<Transition> transitions = lord.Graph.transitions.ToList();
for (int i = 0; i < transitions.Count; i++)
foreach (Transition transition in transitions)
{
foreach(Trigger trigger in transitions[i].triggers)
foreach (Trigger trigger in transition.triggers)
{
if (trigger.GetType() == typeof(Trigger_TicksPassed))
if (trigger is Trigger_TicksPassed)
{
transitions[i].triggers.Add(new Trigger_TicksPassed(20));
transition.triggers.Add(new Trigger_TicksPassed(20));
break;
}
}
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("0.18.0.1")]
[assembly: AssemblyFileVersion("0.18.0.1")]
[assembly: AssemblyVersion("0.1.0.1")]
[assembly: AssemblyFileVersion("0.1.0.1")]

0 comments on commit ce3f684

Please sign in to comment.