Skip to content

Commit

Permalink
add ScrambledLengthCoefficient
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirus59 committed Mar 4, 2025
1 parent a1c629c commit 458d39f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public sealed partial class SyllablesScrambleMethod : ScrambleMethod
[DataField]
public float SpecialCharacterChance = 0.5f;

/// <summary>
/// Coefficient of how much the length of the scrambled message will differ from the original.
/// The shorter the syllables length, the higher the accuracy.
/// </summary>
[DataField]
public float ScrambledLengthCoefficient = 1f;

/// <summary>
/// Special characters that can be inserted after a scrambled syllable
/// </summary>
Expand Down Expand Up @@ -73,8 +80,9 @@ public override string ScrambleMessage(string message, int? seed = null)
private string ScrambleWord(string word, int seed)
{
var random = new System.Random(seed);
var encryptedMessage = new StringBuilder();
while (encryptedMessage.Length < word.Length)
var scrambledMessage = new StringBuilder();
var scrambledLength = word.Length * ScrambledLengthCoefficient;
while (scrambledMessage.Length < scrambledLength)
{
var curSyllable = random.Pick(Syllables);

Expand All @@ -83,20 +91,20 @@ private string ScrambleWord(string word, int seed)
curSyllable = string.Concat(curSyllable.Substring(0, 1).ToUpper(), curSyllable.AsSpan(1));
_capitalize = false;
}
encryptedMessage.Append(curSyllable);
scrambledMessage.Append(curSyllable);

if (random.Prob(SpecialCharacterChance))
{
var character = GetSpecialCharacter(random);
if (character != null)
{
encryptedMessage.Append(character.Character);
scrambledMessage.Append(character.Character);
_capitalize = character.Capitalize;
}
}
}

var result = encryptedMessage.ToString();
var result = scrambledMessage.ToString();
return result;
}

Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/SS220/Language/language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
description: "language-binary-desc"
color: "#2cc2e8"
scrambleMethod: !type:SyllablesScrambleMethod
scrambledLengthCoefficient: 0.5
specialCharacterChance: 0.8
specialCharacters:
- character: " "
Expand Down

0 comments on commit 458d39f

Please sign in to comment.