Skip to content

Commit

Permalink
Shaman event
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehni committed Jul 27, 2018
1 parent b7f67f8 commit 056299d
Show file tree
Hide file tree
Showing 23 changed files with 604 additions and 111 deletions.
1 change: 1 addition & 0 deletions About/PublishedFileId.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1454024362
Binary file modified Assemblies/MoreFactionInteraction.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions Defs/CustomChoiceLetters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
<letterClass>MoreFactionInteraction.ChoiceLetter_DiplomaticMarriage</letterClass>
</LetterDef>

<LetterDef ParentName="CustomChoiceLetterBase">
<defName>MysticalShaman</defName>
<letterClass>MoreFactionInteraction.ChoiceLetter_MysticalShaman</letterClass>
</LetterDef>

</Defs>
15 changes: 15 additions & 0 deletions Defs/Incidents/Incidents_World_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
</chanceFactorByPopulationCurve>
</IncidentDef>

<IncidentDef>
<defName>MFI_MysticalShaman</defName>
<label>mystical shaman</label>
<category>Misc</category>
<targetTags>
<li>World</li>
</targetTags>
<workerClass>MoreFactionInteraction.IncidentWorker_MysticalShaman</workerClass>
<letterLabel>Mystical shaman</letterLabel>
<letterDef>MysticalShaman</letterDef>
<baseChance>0.8</baseChance>
<earliestDay>1</earliestDay>
<minRefireDays>20</minRefireDays>
</IncidentDef>

<IncidentDef>
<defName>MFI_HuntersLodge</defName>
<label>hunters lodge</label>
Expand Down
2 changes: 1 addition & 1 deletion Defs/Incidents/Incidents_World_Quests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<letterText>You've received a message from [PAWN_nameDef], {0} of {1}. Their faction recently had diplomatic troubles with another faction and call upon you to negotiate between them and {2}. They've picked a neutral nearby location and invite you to come negotiate.\n\nIt could be a great opportunity to improve relations with their faction, but beware - a poor negotiator can cause more harm than good and even anger them.\n\nThe offer will expire after {3} days, after which [PAWN_nameDef] fears the worst.</letterText>
<letterDef>NeutralEvent</letterDef>
<baseChance>0.51</baseChance>
<minRefireDays>12</minRefireDays>
<minRefireDays>50</minRefireDays>
</IncidentDef>

</Defs>
14 changes: 14 additions & 0 deletions Defs/WorldObjects/WorldObjects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,18 @@
</comps>
</WorldObjectDef>

<WorldObjectDef>
<defName>MFI_MysticalShaman</defName>
<label>mystical shaman</label>
<description>The tent where a mystical shaman recides.</description>
<worldObjectClass>MoreFactionInteraction.More_Flavour.MysticalShaman</worldObjectClass>
<texture>FactionPeaceTalks</texture>
<expandingIcon>true</expandingIcon>
<expandingIconTexture>Expanding/HealerHand</expandingIconTexture>
<expandingIconPriority>70</expandingIconPriority>
<comps>
<li Class="WorldObjectCompProperties_Timeout" />
</comps>
</WorldObjectDef>

</Defs>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Mehni

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 7 additions & 1 deletion Languages/English/Keyed/Incidents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
<MFI_LetterLabelHarvest_Triumph>Bumper crop harvested</MFI_LetterLabelHarvest_Triumph>
<MFI_BumperCropXPGain>Your grower {0} has gained {1} growing experience.</MFI_BumperCropXPGain>

<MFI_DiplomaticMarriage>Word of {1}'s charm has reached {0} and they've asked you for {1}'s hand in marriage. Accepting this marriage proposal will cement relations and strengthen faction ties, but {1} will leave your faction to join theirs.</MFI_DiplomaticMarriage>
<MFI_DiplomaticMarriage>Word of {1}'s charm has reached {0} and they've asked you for {1}'s hand in marriage. Accepting this marriage proposal will cement relations and strengthen faction ties, but {1} will leave your faction to join {2}.</MFI_DiplomaticMarriage>
<MFI_DiplomaticMarriageLabel>Diplomatic marriage</MFI_DiplomaticMarriageLabel>
<MFI_AcceptedProposal>[PAWN_nameDef] sounds overjoyed. [PAWN_pronoun] is convinced they'll live happily ever after with {0}.\n\nRelations with {1} improved.</MFI_AcceptedProposal>
<MFI_DejectedProposal>[PAWN_nameDef] tries [PAWN_possessive] best not to sound rejected.\n\nRelations with {1} have deteriorated somewhat.</MFI_DejectedProposal>

<MFI_MysticalShamanLetter>Someone who claims to be a representative of {0} contacts us with a tall tale of a mystical shaman who has mastered the &quot;healer's hand&quot; to cure any injury or missing part. They'll tell us the location of this mysterious and normally reclusive person for a small fee of {1} silver.</MFI_MysticalShamanLetter>
<MFI_MysticalShamanTitle>Mystical Shaman</MFI_MysticalShamanTitle>

<MFI_MysticalShamanFoundNoSickPawn>The Shaman emerges from his polyester teepee just before your caravan announces their presence. He judges you silently with one crossed eye that penetrates through each of your caravan members deepest vitae and one eye that quivers more and more as he assesses your groups health. He orders you to wait a respectable distance while he retreats back in his teepee. Moments later you hear the rustling of fabric and the sound of a muffalo being spurred on.\n\nIt seems the mystical shaman packed up and left.</MFI_MysticalShamanFoundNoSickPawn>
<MFI_MysticalShamanDoesHisMagic>The Shaman seems to have been expecting you, and with great practice regales you the tale of his &quot;healer's hands&quot;. When he's down he invites {0} in to his teepee. There is a brief shake of the screen before {0} re-emerges, feeling much better.</MFI_MysticalShamanDoesHisMagic>

</LanguageData>
2 changes: 2 additions & 0 deletions MoreFactionInteraction/General/MFI_DefOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public static class MFI_DefOf

public static SiteCoreDef MFI_HuntersLodgeCore;
public static SitePartDef MFI_HuntersLodgePart;

public static WorldObjectDef MFI_FactionWarPeaceTalks;
public static WorldObjectDef MFI_MysticalShaman;
//public static IncidentDef MFI_WeddingGuestsArrival;
}
}
8 changes: 4 additions & 4 deletions MoreFactionInteraction/General/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace MoreFactionInteraction
public class MoreFactionInteraction_Settings : ModSettings
{
public static int ticksToUpgrade = 3 * GenDate.DaysPerQuadrum * GenDate.TicksPerDay;
public static float timeModifierBetweenFactionInteraction = 1f;
public static float traderWealthOffsetFromTimesTraded = 1f;
public static float timeModifierBetweenFactionInteraction = 2f;
public static float traderWealthOffsetFromTimesTraded = 0.7f;

public void DoWindowContents(Rect rect)
{
Expand All @@ -30,8 +30,8 @@ public void DoWindowContents(Rect rect)
public override void ExposeData()
{
Scribe_Values.Look(value: ref ticksToUpgrade, label: "ticksToUpgrade", defaultValue: 2700000);
Scribe_Values.Look(value: ref timeModifierBetweenFactionInteraction, label: "timeModifierBetweenFactionInteraction", defaultValue: 1f);
Scribe_Values.Look(value: ref traderWealthOffsetFromTimesTraded, label: "traderWealthOffsetFromTimesTraded", defaultValue: 1f);
Scribe_Values.Look(value: ref timeModifierBetweenFactionInteraction, label: "timeModifierBetweenFactionInteraction", defaultValue: 2f);
Scribe_Values.Look(value: ref traderWealthOffsetFromTimesTraded, label: "traderWealthOffsetFromTimesTraded", defaultValue: 0.8f);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using RimWorld.Planet;
using Verse;

namespace MoreFactionInteraction.More_Flavour
{
class CaravanArrivalAction_VisitMysticalShaman : CaravanArrivalAction
{
private MysticalShaman mysticalShaman;

public override string Label => "VisitPeaceTalks".Translate(mysticalShaman.Label);
public override string ReportString => "CaravanVisiting".Translate(this.mysticalShaman.Label);

public override void Arrived(Caravan caravan)
{
this.mysticalShaman.Notify_CaravanArrived(caravan: caravan);
}

public CaravanArrivalAction_VisitMysticalShaman()
{
}

public CaravanArrivalAction_VisitMysticalShaman(MysticalShaman mysticalShaman)
{
this.mysticalShaman = mysticalShaman;
}

public static IEnumerable<FloatMenuOption> GetFloatMenuOptions(Caravan caravan, MysticalShaman mysticalShaman)
{
return CaravanArrivalActionUtility.GetFloatMenuOptions(acceptanceReportGetter:
() => CanVisit(caravan: caravan, mysticalShaman: mysticalShaman), arrivalActionGetter:
() => new CaravanArrivalAction_VisitMysticalShaman(mysticalShaman: mysticalShaman),
label: "VisitPeaceTalks".Translate(mysticalShaman.Label),
caravan: caravan, pathDestination: mysticalShaman.Tile,
revalidateWorldClickTarget: mysticalShaman);
}

public static FloatMenuAcceptanceReport CanVisit(Caravan caravan, MysticalShaman mysticalShaman)
{
return mysticalShaman != null && mysticalShaman.Spawned;
}

public override void ExposeData()
{
base.ExposeData();
Scribe_References.Look(refee: ref this.mysticalShaman, label: "mysticalShaman");
}
}
}
77 changes: 77 additions & 0 deletions MoreFactionInteraction/More Flavour/ChoiceLetter_MysticalShaman.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using RimWorld;
using RimWorld.Planet;
using MoreFactionInteraction.More_Flavour;

namespace MoreFactionInteraction
{
public class ChoiceLetter_MysticalShaman : ChoiceLetter
{
public int tile;
public Faction faction;
public Map map;
public int fee;
private static readonly IntRange TimeoutDaysRange = new IntRange(min: 5, max: 15);

public override IEnumerable<DiaOption> Choices
{
get
{
if (this.ArchivedOnly)
{
yield return this.Option_Close;
}
else
{
DiaOption accept = new DiaOption(text: "RansomDemand_Accept".Translate())
{
action = () =>
{
MysticalShaman mysticalShaman = (MysticalShaman)WorldObjectMaker.MakeWorldObject(def: MFI_DefOf.MFI_MysticalShaman);
mysticalShaman.Tile = tile;
mysticalShaman.SetFaction(newFaction: faction);
int randomInRange = TimeoutDaysRange.RandomInRange;
mysticalShaman.GetComponent<TimeoutComp>().StartTimeout(ticks: randomInRange * GenDate.TicksPerDay);
Find.WorldObjects.Add(o: mysticalShaman);

TradeUtility.LaunchSilver(map: this.map, fee: this.fee);
Find.LetterStack.RemoveLetter(let: this);
},
resolveTree = true
};
if (!TradeUtility.ColonyHasEnoughSilver(map: this.map, fee: this.fee))
{
accept.Disable(newDisabledReason: "NeedSilverLaunchable".Translate(this.fee.ToString()));
}
yield return accept;

DiaOption reject = new DiaOption(text: "RansomDemand_Reject".Translate())
{
action = () =>
{
Find.LetterStack.RemoveLetter(let: this);
},
resolveTree = true
};
yield return reject;
yield return this.Option_Postpone;
}
}
}

public override bool CanShowInLetterStack => base.CanShowInLetterStack && Find.Maps.Contains(item: this.map);

public override void ExposeData()
{
base.ExposeData();
Scribe_References.Look<Map>(refee: ref this.map, label: "MFI_Shaman_Map");
Scribe_References.Look<Faction>(refee: ref this.faction, label: "MFI_Shaman_Faction");
Scribe_Values.Look(ref this.tile, "MFI_ShamanTile");
Scribe_Values.Look<int>(value: ref this.fee, label: "MFI_ShamanFee");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ protected override bool TryExecuteWorker(IncidentParms parms)
return false;
}

ChoiceLetter_DiplomaticMarriage choiceLetter_DiplomaticMarriage = (ChoiceLetter_DiplomaticMarriage)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_DiplomaticMarriage".Translate(args: new object[]
ChoiceLetter_DiplomaticMarriage choiceLetterDiplomaticMarriage = (ChoiceLetter_DiplomaticMarriage)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_DiplomaticMarriage".Translate(args: new object[]
{
this.marriageSeeker.LabelShort, this.betrothed.LabelShort
this.marriageSeeker.LabelShort, this.betrothed.LabelShort, this.marriageSeeker.Faction.Name
}).AdjustedFor(p: this.marriageSeeker), def: this.def.letterDef);

choiceLetter_DiplomaticMarriage.title = "MFI_DiplomaticMarriageLabel".Translate(args: new object[]
choiceLetterDiplomaticMarriage.title = "MFI_DiplomaticMarriageLabel".Translate(args: new object[]
{
this.betrothed.LabelShort
}).CapitalizeFirst();
choiceLetter_DiplomaticMarriage.radioMode = true;
choiceLetter_DiplomaticMarriage.marriageSeeker = this.marriageSeeker;
choiceLetter_DiplomaticMarriage.betrothed = this.betrothed;
choiceLetter_DiplomaticMarriage.StartTimeout(duration: TimeoutTicks);
Find.LetterStack.ReceiveLetter(@let: choiceLetter_DiplomaticMarriage);
choiceLetterDiplomaticMarriage.radioMode = true;
choiceLetterDiplomaticMarriage.marriageSeeker = this.marriageSeeker;
choiceLetterDiplomaticMarriage.betrothed = this.betrothed;
choiceLetterDiplomaticMarriage.StartTimeout(duration: TimeoutTicks);
Find.LetterStack.ReceiveLetter(@let: choiceLetterDiplomaticMarriage);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using RimWorld.Planet;

namespace MoreFactionInteraction
{
class IncidentWorker_MysticalShaman : IncidentWorker
{
private static List<Map> tmpAvailableMaps = new List<Map>();

public override float AdjustedChance => base.AdjustedChance;

private const int MinDistance = 8;
private const int MaxDistance = 22;
private const int TimeoutTicks = GenDate.TicksPerDay;

protected override bool CanFireNowSub(IncidentParms parms)
{
return base.CanFireNowSub(parms: parms) && Find.AnyPlayerHomeMap != null
&& !Find.WorldObjects.AllWorldObjects.Any(predicate: o => o.def == MFI_DefOf.MFI_MysticalShaman)
&& Find.FactionManager.AllFactionsVisible.Where(predicate: f => f.def.techLevel <= TechLevel.Neolithic
&& !f.HostileTo(other: Faction.OfPlayer)).TryRandomElement(result: out Faction result)
&& TryFindTile(tile: out int num)
&& TryGetRandomAvailableTargetMap (map: out Map map);
}

protected override bool TryExecuteWorker(IncidentParms parms)
{
if (!Find.FactionManager.AllFactionsVisible.Where(predicate: f => f.def.techLevel <= TechLevel.Neolithic
&& !f.HostileTo(other: Faction.OfPlayer)).TryRandomElement(result: out Faction faction))
return false;

if (!TryGetRandomAvailableTargetMap(map: out Map map))
return false;

if (faction == null)
return false;

if (map == null)
return false;

if (!TryFindTile(tile: out int tile))
return false;

int fee = Rand.RangeInclusive(min: 400, max: 1000);

ChoiceLetter_MysticalShaman choiceLetterMysticalShaman = (ChoiceLetter_MysticalShaman)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_MysticalShamanLetter".Translate(faction.Name, fee.ToString()), def: this.def.letterDef);
choiceLetterMysticalShaman.title = "MFI_MysticalShamanTitle".Translate().CapitalizeFirst();
choiceLetterMysticalShaman.faction = faction;
choiceLetterMysticalShaman.tile = tile;
choiceLetterMysticalShaman.map = map;
choiceLetterMysticalShaman.fee = fee;
choiceLetterMysticalShaman.StartTimeout(duration: TimeoutTicks);
Find.LetterStack.ReceiveLetter(let: choiceLetterMysticalShaman);
return true;
}

private static bool TryFindTile(out int tile)
{
return TileFinder.TryFindNewSiteTile(tile: out tile, minDist: MinDistance, maxDist: MaxDistance, allowCaravans: true, preferCloserTiles: false);
}

private static bool TryGetRandomAvailableTargetMap(out Map map)
{
tmpAvailableMaps.Clear();
List<Map> maps = Find.Maps;
foreach (Map potentialTargetMap in maps)
{
if (potentialTargetMap.IsPlayerHome && IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(originTile: potentialTargetMap.Tile) != null)
{
tmpAvailableMaps.Add(item: potentialTargetMap);
}
}
bool result = tmpAvailableMaps.TryRandomElement(result: out map);
tmpAvailableMaps.Clear();
return result;
}
}
}
Loading

0 comments on commit 056299d

Please sign in to comment.