Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CustomSpawns/CampaignData/Config/CampaignDataConfigLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Xml.Serialization;
using CustomSpawns.ModIntegration;
using CustomSpawns.Utils;
using TaleWorlds.Localization;

namespace CustomSpawns.CampaignData.Config
{
Expand Down Expand Up @@ -50,7 +51,7 @@ private void ConstructConfigs(string xmlPath)

if (!processed)
{
_messageBoxService.ShowMessage("Could not find Campaign Data config file for type " + t.Name);
_messageBoxService.ShowMessage(new TextObject("{=SpawnAPIWarn003}Could not find Campaign Data config file for type {NAME}").SetTextVariable("NANE", t.Name).ToString());
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions CustomSpawns/CampaignData/Implementations/DevestationMetricData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.TwoDimension;
using TaleWorlds.Localization;

namespace CustomSpawns.CampaignData.Implementations
{
Expand Down Expand Up @@ -84,13 +85,13 @@ private void OnMapEventEnded(MapEvent e)

if (!_settlementToDevestation.ContainsKey(closestSettlement))
{
_messageBoxService.ShowCustomSpawnsErrorMessage(new System.Exception("Devestation value for settlement could not be found!"));
_messageBoxService.ShowCustomSpawnsErrorMessage(new System.Exception("Devastation value for settlement could not be found!"));
return;
}

ChangeDevestation(closestSettlement, increase);

_modDebug.ShowMessage("Fight at " + closestSettlement.Name + ". Increasing devestation by " + increase + ". New devestation is: " + _settlementToDevestation[closestSettlement], _config);
_modDebug.ShowMessage(new TextObject("{=SpawnAPIMsg003}Fight at {SETTLEMENT}. Increasing devastation by {VALUE1}. New devastation is: {VALUE2}", new Dictionary<string, object>() { { "SETTLEMENT", closestSettlement.Name}, { "VALUE1", increase}, { "VALUE2", _settlementToDevestation[closestSettlement] } }).ToString(), _config);
}

private void OnVillageLooted(Village v)
Expand All @@ -100,7 +101,7 @@ private void OnVillageLooted(Village v)

ChangeDevestation(v.Settlement, _config.DevestationPerTimeLooted);

_modDebug.ShowMessage("Successful Looting at " + v.Name + ". Increasing devestation by " + _config.DevestationPerTimeLooted, _config);
_modDebug.ShowMessage(new TextObject("{=SpawnAPIMsg004}Successful Looting at {NAME}. Increasing devastation by {VALUE}", new Dictionary<string, object>() { { "NAME", v.Name}, { "VALUE", _config.DevestationPerTimeLooted } }).ToString(), _config);
}

private void OnSettlementDaily(Settlement s)
Expand Down Expand Up @@ -136,29 +137,29 @@ private void OnSettlementDaily(Settlement s)
}
}

if(friendlyGain > 0)
if (friendlyGain > 0)
{
//ModDebug.ShowMessage("Calculating friendly presence devestation decay in " + s.Name + ". Decreasing devestation by " + friendlyGain, campaignConfig);

ChangeDevestation(s, -friendlyGain);
}


if(hostileDecay > 0)
if (hostileDecay > 0)
{
_modDebug.ShowMessage("Calculating hostile presence devestation gain in " + s.Name + ". Increasing devestation by " + hostileDecay, _config);
_modDebug.ShowMessage(new TextObject("{=SpawnAPIMsg005}Calculating hostile presence devastation gain in {NAME}. Increasing devastation gain in {VALUE}", new Dictionary<string, object>() { { "NAME", s.Name }, { "VALUE", hostileDecay } }).ToString(), _config);

ChangeDevestation(s, hostileDecay);
}

if(GetDevestation(s) > 0)
if (GetDevestation(s) > 0)
{
_modDebug.ShowMessage("Calculating daily Devestation Decay in " + s.Name + ". Decreasing devestation by " + _config.DailyDevestationDecay, _config);
_modDebug.ShowMessage(new TextObject("{=SpawnAPIMsg006}Calculating daily Devastation Decay in {NAME}. Decreasing devastation by {VALUE}", new Dictionary<string, object>() { { "NAME", s.Name }, { "VALUE", _config.DailyDevestationDecay } }).ToString(), _config);
ChangeDevestation(s, -_config.DailyDevestationDecay);
}

if(GetDevestation(s) != 0)
_modDebug.ShowMessage("Current Devestation at " + s.Name + " is now " + _settlementToDevestation[s], _config);
if (GetDevestation(s) != 0)
_modDebug.ShowMessage(new TextObject("{=SpawnAPIMsg007}Current Devastation at {NAME} is now {VALUE}", new Dictionary<string, object>() {{ "NAME", s.Name }, { "VALUE", _settlementToDevestation[s] }}).ToString(), _config);
}

#endregion
Expand All @@ -169,7 +170,7 @@ private void ChangeDevestation(Settlement s, float change)
{
if (!_settlementToDevestation.ContainsKey(s))
{
_messageBoxService.ShowCustomSpawnsErrorMessage(new System.Exception("Devastation value for settlement could not be found!"));
_messageBoxService.ShowCustomSpawnsErrorMessage(new System.Exception("Devestation value for settlement could not be found!"));
return;
}

Expand All @@ -187,7 +188,7 @@ public float GetDevestation(Settlement s)
if (_settlementToDevestation.ContainsKey(s))
return _settlementToDevestation[s];

_messageBoxService.ShowCustomSpawnsErrorMessage(new System.Exception("Devestation value for settlement could not be found!"));
_messageBoxService.ShowCustomSpawnsErrorMessage(new System.Exception("Devastation value for settlement could not be found!"));
return 0;
}

Expand Down
5 changes: 3 additions & 2 deletions CustomSpawns/Data/Dao/SpawnDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using CustomSpawns.Exception;
using CustomSpawns.Utils;
using TaleWorlds.Core;
using TaleWorlds.Localization;

namespace CustomSpawns.Data.Dao
{
Expand Down Expand Up @@ -42,11 +43,11 @@ private List<SpawnDto> Spawns()
}
catch (TechnicalException e)
{
_messageBoxService.ShowMessage("Warning: The Custom Spawns API detected that you are trying to load" +
_messageBoxService.ShowMessage(new TextObject("{=SpawnAPIWarn001}Warning: The Custom Spawns API detected that you are trying to load" +
" a Custom Spawns sub-mod into an existing saved game." +
" This mod requires a fresh start to work correctly.\n" +
"If you decide to continue, expect to have very unstable" +
" behaviours during your play-through.");
" behaviours during your play-through.").ToString());
return null;
}
})
Expand Down
10 changes: 5 additions & 5 deletions CustomSpawns/Data/Model/Dialogue/DefaultDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private Dialogue HostileAttackDialogue()
{
Dialogue dialogue = new();
dialogue.IsPlayerDialogue = false;
dialogue.Text = "That's a nice head on your shoulders!";
dialogue.Text = "{=EVkXWo6S}That's a nice head on your shoulders!";
dialogue.Consequence = "Battle";
dialogue.Condition = BaseDefaultCondition + " AND IsHostile AND IsAttacking";
dialogue.Options = new();
Expand All @@ -37,7 +37,7 @@ private Dialogue HostileDefendDialogue()
{
Dialogue dialogue = new();
dialogue.IsPlayerDialogue = false;
dialogue.Text = "I will drink from your skull!";
dialogue.Text = "{=C7PgdtDN}I will drink from your skull!";
dialogue.Consequence = "Battle";
dialogue.Condition = BaseDefaultCondition + " AND IsHostile AND IsDefending";
dialogue.Options = new();
Expand All @@ -48,7 +48,7 @@ private Dialogue FriendlyDialogue()
{
Dialogue dialogue = new();
dialogue.IsPlayerDialogue = false;
dialogue.Text = "It's almost harvesting season!";
dialogue.Text = "{=Z28hBxDM}It's almost harvesting season!";
dialogue.Condition = BaseDefaultCondition + " AND IsFriendly";
dialogue.Options = new();
dialogue.Options.Add(AttackFriendlyDialogue());
Expand All @@ -60,7 +60,7 @@ private Dialogue LeaveFriendlyDialogue()
{
Dialogue dialogue = new();
dialogue.IsPlayerDialogue = true;
dialogue.Text = "Away with you vile beggar!";
dialogue.Text = "{=J50mnkoo}Away with you vile beggar!";
dialogue.Consequence = "Leave";
dialogue.Options = new();
return dialogue;
Expand All @@ -70,7 +70,7 @@ private Dialogue AttackFriendlyDialogue()
{
Dialogue dialogue = new();
dialogue.IsPlayerDialogue = true;
dialogue.Text = "I will tear you limb from limb!";
dialogue.Text = "{=nJ3uAPZH}I will tear you limb from limb!";
dialogue.Consequence = "War";
dialogue.Options = new();
return dialogue;
Expand Down
43 changes: 40 additions & 3 deletions CustomSpawns/Data/Model/Spawn.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using System;
using CustomSpawns.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;
using TaleWorlds.Diamond;
using TaleWorlds.Library;
using TaleWorlds.Localization;

namespace CustomSpawns.Data.Model
{
Expand Down Expand Up @@ -39,13 +44,45 @@ public class Spawn
public int RepeatSpawnRolls { get; set; } = 1;

[XmlElement(ElementName="SpawnMessage")]
public string? SpawnMessage { get; set; }
public string? SpawnMessage {
get
{
return this._spawnMessage;
}
set
{
if (value == null)
{
this._spawnMessage = null;
}
else
{
this._spawnMessage = Regex.Replace(value.ToString(), @"\[" + UX.SpawnPlaceIdentifier + @"\]", $"{{{UX.SpawnPlaceIdentifier}}}", RegexOptions.IgnoreCase);
}
}
}
private string? _spawnMessage = null;

[XmlElement(ElementName="SpawnMessageColor")]
public string? SpawnMessageColor { get; set; }

[XmlElement(ElementName="DeathMessage")]
public string? DeathMessage { get; set; }
public string? DeathMessage {
get
{ return this._deathMessage; }
set
{
if (value == null)
{
this._deathMessage = value;
}
else
{
this._deathMessage = Regex.Replace(value.ToString(), @"\[" + UX.DeathPlaceIdentifier + @"\]", $"{{{UX.DeathPlaceIdentifier}}}", RegexOptions.IgnoreCase);
}
}
}
private string? _deathMessage = null;

[XmlElement(ElementName = "DeathMessageColor")]
public string? DeathMessageColor { get; set; }
Expand Down
7 changes: 4 additions & 3 deletions CustomSpawns/Dialogues/DialogueConsequenceInterpretor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Library;
using TaleWorlds.Localization;

namespace CustomSpawns.Dialogues
{
Expand Down Expand Up @@ -99,7 +100,7 @@ public DialogueConsequence ParseConsequence(string text)
}
catch (System.Exception e)
{
_messageBoxService.ShowMessage("Could not parse dialogue consequnce: \n" + text + "\n Error Message: \n" + e.Message);
_messageBoxService.ShowMessage(new TextObject("{SpawnAPIErr002}Could not parse dialogue consequnce:\n{TEXT}\nError Message:\n{ERROR}", new Dictionary<string, object>() { { "TEXT", text }, { "EROR", e.Message } }).ToString());
return null;
}

Expand Down Expand Up @@ -306,12 +307,12 @@ private static void declare_peace_consequence_delegate()
{ //Interestingly, PlayerEncounter.EnemySurrender = true; results in a null reference crash.
param.PlayerParty.Party.AddPrisoners(param.AdversaryParty.Party.MemberRoster);
param.AdversaryParty.RemoveParty();
UX.ShowMessage("You have taken your enemies prisoner.", TaleWorlds.Library.Colors.Green);
UX.ShowMessage(new TextObject("{=SpawnAPIMsg001}You have taken your enemies prisoner.").ToString(), TaleWorlds.Library.Colors.Green);
end_conversation_consequence_delegate(param);
}
else
{
_messageBoxService.ShowMessage("Can't interpret " + isPlayer.ToString() + " as a bool. Possible typo in the XML consequence 'Surrender'");
_messageBoxService.ShowMessage(new TextObject("{=SpawnAPIMsg002}Can't interpret {PLAYER} as a bool. Possible typo in the XML consequence 'Surrender'").SetTextVariable("PLAYER", isPlayer.ToString()).ToString());
}
PlayerEncounter.Update();
}
Expand Down
5 changes: 3 additions & 2 deletions CustomSpawns/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using TaleWorlds.MountAndBlade;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Library;
using TaleWorlds.Localization;

namespace CustomSpawns
{
Expand Down Expand Up @@ -123,11 +124,11 @@ private void InstantiateDependencies()

private void DisplayLoadedModules()
{
UX.ShowMessage("Custom Spawns API loaded", Color.ConvertStringToColor("#001FFFFF"));
UX.ShowMessage(new TextObject("{=SpawnAPIMsg000}Custom Spawns API loaded").ToString(), Color.ConvertStringToColor("#001FFFFF"));
AIManager.FlushRegisteredBehaviours(); //forget old behaviours to allocate space.
foreach (var subMod in _subModService.GetAllLoadedSubMods())
{
UX.ShowMessage(subMod.SubModuleName + " is now integrated into the Custom Spawns API.",
UX.ShowMessage(new TextObject("{=SpawnAPIMsg010}{NAME} is now integrated into the Custom Spawns API.").SetTextVariable("NAME", subMod.SubModuleName).ToString(),
Color.ConvertStringToColor("#001FFFFF"));
}
}
Expand Down
6 changes: 2 additions & 4 deletions CustomSpawns/Spawn/Spawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public MobileParty SpawnParty(Settlement spawnedSettlement, Clan clan, PartyTemp
{
//get name and show message.
TextObject name = partyName ?? clan.Name;
_modDebug.ShowMessage(
"CustomSpawns: Spawning " + name + " at " + spawnedSettlement.GatePosition + " in settlement " +
spawnedSettlement.Name, DebugMessageType.Spawn);
_modDebug.ShowMessage(new TextObject("{=SpawnAPIDebug001}CustomSpawns: Spawning {NAME} at {POSITION} in settlement {SETTLEMENT}", new System.Collections.Generic.Dictionary<string, object> { { "NAME", name}, { "POSITION", spawnedSettlement.GatePosition}, { "SETTLEMENT", spawnedSettlement.Name} }).ToString(), DebugMessageType.Spawn);

if (clan.IsBanditFaction)
{
Expand All @@ -42,7 +40,7 @@ public MobileParty SpawnParty(Settlement spawnedSettlement, Clan clan, PartyTemp
}
catch (System.Exception e)
{
_messageBoxService.ShowMessage("Possible invalid spawn data. Spawning of party terminated.");
_messageBoxService.ShowMessage(new TextObject("{=SpawnAPIWarn002}Possible invalid spawn data. Spawning of party terminated.").ToString());
_messageBoxService.ShowCustomSpawnsErrorMessage(e, "party spawning");
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion CustomSpawns/Utils/MessageBoxService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using BUTR.MessageBoxPInvoke.Helpers;
using TaleWorlds.Library;
using TaleWorlds.Localization;

namespace CustomSpawns.Utils
{
Expand All @@ -20,7 +21,7 @@ public void ShowCustomSpawnsErrorMessage(System.Exception? e, string during = ""
{
errorMessage = e.Message + " AT " + e.Source + " " + duringMessage + "TRACE: " + e.StackTrace;
}
string shown = "CustomSpawns error has occured, please report to mod developer: " + errorMessage;
string shown = new TextObject("{=SpawnAPIErr001}CustomSpawns error has occured, please report to mod developer: ").ToString() + errorMessage;
ShowMessage(shown);
}

Expand Down
25 changes: 4 additions & 21 deletions CustomSpawns/Utils/UX.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using TaleWorlds.Library;
using TaleWorlds.Localization;

namespace CustomSpawns.Utils
{
public static class UX
{
private static readonly string SpawnPlaceIdentifier = "spawnplace";
public static readonly string SpawnPlaceIdentifier = "spawnplace";

private static readonly string DeathPlaceIdentifier = "deathplace";
public static readonly string DeathPlaceIdentifier = "deathplace";

private static readonly Dictionary<string, string> FlagToMessageColour = new ()
{
Expand Down Expand Up @@ -39,24 +39,7 @@ public static string GetMessageColour(string flag)

private static string ResolveVariables(string message, string settlementName)
{
string[] codes = message.Split(new [] { "[", "]"}, StringSplitOptions.None);
if (codes.Length == 1) {
return message;
}
StringBuilder spawnMessageBuilder = new();
foreach(string code in codes)
{
string variable = code.ToLower();
if (variable.Equals(SpawnPlaceIdentifier) || variable.Equals(DeathPlaceIdentifier))
{
spawnMessageBuilder.Append(settlementName);
}
else
{
spawnMessageBuilder.Append(code);
}
}
return spawnMessageBuilder.ToString();
return new TextObject(message, new Dictionary<string, object>() { { SpawnPlaceIdentifier, settlementName }, { DeathPlaceIdentifier, settlementName} }).ToString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LanguageData id="日本語">
<LanguageFile xml_path="JP/strings-JP.xml">
</LanguageFile>
</LanguageData>
Loading