ModernUO/Projects/UOContent/Misc/Titles.cs
Jack 597c81345e
feat: Adjusts fame and karma system with era gates for OSI accuracy (#2389)
## Summary

Overhauls the fame and karma system to be more era-accurate, based on original design documents and publish notes.

### Karma on player kill → karma on murder report
- Removes karma gain/loss on player kill (was immediate on death)
- Karma is now set to `Kills * -1000` on murder **report** instead
- Fame on player kill now uses the same formula as monster kills (`Fame / 100`)

This karma loss on murder report behaviour was tested on both the demo and live servers, behaviour was matching in terms of karma loss on report. Official UO servers karma loss AMOUNT match with my memory of T2A/UOR with one caveat - it's doubled on live servers (-2000 * kill count). I'm not sure when this changed and this behaviour has always had very poor and incorrect documentation, even 10-20 years ago.  I was obsessed with the dread lord title on OSI and the only way I knew how to get it was reach 10 kills then macro them off. Even in publish 16 (when "The Murderer" title was removed) it still required 10 kills. Maybe it changed to -2000*Kills in AOS - that's where I've put the era gating diff.

### Era gates
- **Karma lock** (ankh toggle + auto-lock on negative karma) gated to `Core.UOTD && !Core.AOS` — [didn't exist before Jan 28, 2001](https://web.archive.org/web/20010128092700/http://update.uo.com/design_300.html)
- **Felucca fame/karma +30% bonus** gated to `Core.LBR` — [added in Publish 16, July 2002](https://uo.com/wiki/ultima-online-wiki/technical/previous-publishes/2002-2/publish-16-part-2-5-23rd-july/)
- **Fame/karma splitting** among damage dealers gated to `Core.UOR` — pre-UOR awards go to last hit only

### Skill karma penalties
- **Provocation** on innocent NPC: NPC says cliloc 501591, karma loss (floor -7500)
- **Stealing** attempt: karma loss on every attempt (floor -5000). Stealing did not cause karma loss at all before!
- **Summon Daemon**: karma loss on successful cast (floor -7000)
- **Corpse carving** (human): -70 for innocent corpses (floor -7000), -20 for freely-aggressable (floor -2000)
- **Bounty head turn-in**: karma gain capped at 2000 (was awarding flat +2000)

### Beneficial action karma
- **Beneficial spells** (heal, cure, etc.): `AwardKarma(caster, target.Karma / 5)` — healing good targets raises karma, healing evil targets lowers it - source is UO98 demo scripts
- **Bandages**: same formula but gain only (skipped if target karma ≤ 0) - see stratics link ("only ever gain karma, not lose it")

Sources: UO98 Demo scripts and playing, [Fame and Karma wiki](https://uo.com/wiki/ultima-online-wiki/player/fame-and-karma/), [UO design doc (Jan 2001)](https://web.archive.org/web/20010128092700/http://update.uo.com/design_300.html), [Publish 16](https://uo.com/wiki/ultima-online-wiki/technical/previous-publishes/2002-2/publish-16-part-2-5-23rd-july/), [Stratics healing reference](https://web.archive.org/web/20001209014200fw_/http://uo.stratics.com/heal.shtml)

### Refactoring
- Extracted `Titles.ComputeKillAwards(killed, map)` shared by player kill and creature kill paths
- Extracted `Titles.SetKarma(m, value, message)` for direct karma assignment (used by murder report)
- Extracted `SendKarmaMessage` and `CheckKarmaLock` helpers from `AwardKarma`
2026-04-25 11:19:57 -07:00

467 lines
15 KiB
C#

using System;
using Server.Engines.CannedEvil;
using Server.Mobiles;
using Server.Text;
namespace Server.Misc
{
public static class Titles
{
public const int MinFame = 0;
public const int MaxFame = 15000;
public const int MinKarma = -15000;
public const int MaxKarma = 15000;
private static readonly string[,] m_Levels =
{
{ "Neophyte", "Neophyte", "Neophyte" },
{ "Novice", "Novice", "Novice" },
{ "Apprentice", "Apprentice", "Apprentice" },
{ "Journeyman", "Journeyman", "Journeyman" },
{ "Expert", "Expert", "Expert" },
{ "Adept", "Adept", "Adept" },
{ "Master", "Master", "Master" },
{ "Grandmaster", "Grandmaster", "Grandmaster" },
{ "Elder", "Tatsujin", "Shinobi" },
{ "Legendary", "Kengo", "Ka-ge" }
};
private static readonly FameEntry[] m_FameEntries =
{
new(
1249,
new[]
{
new KarmaEntry(-10000, "The Outcast "),
new KarmaEntry(-5000, "The Despicable "),
new KarmaEntry(-2500, "The Scoundrel "),
new KarmaEntry(-1250, "The Unsavory "),
new KarmaEntry(-625, "The Rude "),
new KarmaEntry(624, ""),
new KarmaEntry(1249, "The Fair "),
new KarmaEntry(2499, "The Kind "),
new KarmaEntry(4999, "The Good "),
new KarmaEntry(9999, "The Honest "),
new KarmaEntry(10000, "The Trustworthy ")
}
),
new(
2499,
new[]
{
new KarmaEntry(-10000, "The Wretched "),
new KarmaEntry(-5000, "The Dastardly "),
new KarmaEntry(-2500, "The Malicious "),
new KarmaEntry(-1250, "The Dishonorable "),
new KarmaEntry(-625, "The Disreputable "),
new KarmaEntry(624, "The Notable "),
new KarmaEntry(1249, "The Upstanding "),
new KarmaEntry(2499, "The Respectable "),
new KarmaEntry(4999, "The Honorable "),
new KarmaEntry(9999, "The Commendable "),
new KarmaEntry(10000, "The Estimable ")
}
),
new(
4999,
new[]
{
new KarmaEntry(-10000, "The Nefarious "),
new KarmaEntry(-5000, "The Wicked "),
new KarmaEntry(-2500, "The Vile "),
new KarmaEntry(-1250, "The Ignoble "),
new KarmaEntry(-625, "The Notorious "),
new KarmaEntry(624, "The Prominent "),
new KarmaEntry(1249, "The Reputable "),
new KarmaEntry(2499, "The Proper "),
new KarmaEntry(4999, "The Admirable "),
new KarmaEntry(9999, "The Famed "),
new KarmaEntry(10000, "The Great ")
}
),
new(
9999,
new[]
{
new KarmaEntry(-10000, "The Dread "),
new KarmaEntry(-5000, "The Evil "),
new KarmaEntry(-2500, "The Villainous "),
new KarmaEntry(-1250, "The Sinister "),
new KarmaEntry(-625, "The Infamous "),
new KarmaEntry(624, "The Renowned "),
new KarmaEntry(1249, "The Distinguished "),
new KarmaEntry(2499, "The Eminent "),
new KarmaEntry(4999, "The Noble "),
new KarmaEntry(9999, "The Illustrious "),
new KarmaEntry(10000, "The Glorious ")
}
),
new(
10000,
new[]
{
new KarmaEntry(-10000, "The Dread "),
new KarmaEntry(-5000, "The Evil "),
new KarmaEntry(-2500, "The Dark "),
new KarmaEntry(-1250, "The Sinister "),
new KarmaEntry(-625, "The Dishonored "),
new KarmaEntry(624, ""),
new KarmaEntry(1249, "The Distinguished "),
new KarmaEntry(2499, "The Eminent "),
new KarmaEntry(4999, "The Noble "),
new KarmaEntry(9999, "The Illustrious "),
new KarmaEntry(10000, "The Glorious ")
}
)
};
public static (int Fame, int Karma) ComputeKillAwards(Mobile killed, Map map)
{
var totalFame = killed.Fame / 100;
var totalKarma = -killed.Karma / 100;
if (Core.LBR && map == Map.Felucca)
{
totalFame += totalFame / 10 * 3;
totalKarma += totalKarma / 10 * 3;
}
return (totalFame, totalKarma);
}
public static void AwardFame(Mobile m, int offset, bool message)
{
if (offset > 0)
{
if (m.Fame >= MaxFame)
{
return;
}
offset = Math.Max(offset - m.Fame / 100, 0);
}
else if (offset < 0)
{
if (m.Fame <= MinFame)
{
return;
}
offset = Math.Min(offset - m.Fame / 100, 0);
}
offset = (m.Fame + offset) switch
{
> MaxFame => MaxFame - m.Fame,
< MinFame => MinFame - m.Fame,
_ => offset
};
m.Fame += offset;
if (message)
{
if (offset > 40)
{
m.SendLocalizedMessage(1019054); // You have gained a lot of fame.
}
else if (offset > 20)
{
m.SendLocalizedMessage(1019053); // You have gained a good amount of fame.
}
else if (offset > 10)
{
m.SendLocalizedMessage(1019052); // You have gained some fame.
}
else if (offset > 0)
{
m.SendLocalizedMessage(1019051); // You have gained a little fame.
}
else if (offset < -40)
{
m.SendLocalizedMessage(1019058); // You have lost a lot of fame.
}
else if (offset < -20)
{
m.SendLocalizedMessage(1019057); // You have lost a good amount of fame.
}
else if (offset < -10)
{
m.SendLocalizedMessage(1019056); // You have lost some fame.
}
else if (offset < 0)
{
m.SendLocalizedMessage(1019055); // You have lost a little fame.
}
}
}
public static void SetKarma(Mobile m, int newKarma, bool message)
{
newKarma = Math.Clamp(newKarma, MinKarma, MaxKarma);
var offset = newKarma - m.Karma;
var wasPositiveKarma = m.Karma >= 0;
m.Karma = newKarma;
if (message)
{
SendKarmaMessage(m, offset);
}
CheckKarmaLock(m, wasPositiveKarma);
}
public static void AwardKarma(Mobile m, int offset, bool message)
{
var pm = m as PlayerMobile;
if (offset > 0)
{
if (Core.UOTD && !Core.AOS && pm?.KarmaLocked == true)
{
return;
}
if (m.Karma >= MaxKarma)
{
return;
}
offset = Math.Max(offset - m.Karma / 100, 0);
}
else if (offset < 0)
{
if (m.Karma <= MinKarma)
{
return;
}
offset = Math.Min(offset - m.Karma / 100, 0);
}
offset = (m.Karma + offset) switch
{
> MaxKarma => MaxKarma - m.Karma,
< MinKarma => MinKarma - m.Karma,
_ => offset
};
var wasPositiveKarma = m.Karma >= 0;
m.Karma += offset;
if (message)
{
SendKarmaMessage(m, offset);
}
CheckKarmaLock(m, wasPositiveKarma);
}
private static void SendKarmaMessage(Mobile m, int offset)
{
var message = offset switch
{
> 40 => 1019062, // You have gained a lot of karma.
> 20 => 1019061, // You have gained a good amount of karma.
> 10 => 1019060, // You have gained some karma.
> 0 => 1019059, // You have gained a little karma.
< -40 => 1019066, // You have lost a lot of karma.
< -20 => 1019065, // You have lost a good amount of karma.
< -10 => 1019064, // You have lost some karma.
_ => 1019063, // You have lost a little karma.
};
m.SendLocalizedMessage(message);
}
private static void CheckKarmaLock(Mobile m, bool wasPositiveKarma)
{
if (Core.UOTD && !Core.AOS && wasPositiveKarma && m.Karma < 0 && m is PlayerMobile { KarmaLocked: false } pm)
{
pm.KarmaLocked = true;
// Karma is locked. A mantra spoken at a shrine will unlock it again.
m.SendLocalizedMessage(1042511, "", 0x22);
}
}
public static string ComputeTitle(Mobile beholder, Mobile beheld)
{
using var title = ValueStringBuilder.Create();
var fame = beheld.Fame;
var karma = beheld.Karma;
var showSkillTitle = beheld.ShowFameTitle && (beholder == beheld || fame >= 5000);
if (beheld.ShowFameTitle || beholder == beheld)
{
for (var i = 0; i < m_FameEntries.Length; ++i)
{
var fe = m_FameEntries[i];
if (fame <= fe.m_Fame || i == m_FameEntries.Length - 1)
{
var karmaEntries = fe.m_Karma;
for (var j = 0; j < karmaEntries.Length; ++j)
{
var ke = karmaEntries[j];
if (karma <= ke.m_Karma || j == karmaEntries.Length - 1)
{
if (fame >= 10000)
{
if (beheld.Female)
{
title.Append($"{ke.m_Title}Lady {beheld.Name}");
}
else
{
title.Append($"{ke.m_Title}Lord {beheld.Name}");
}
}
else
{
title.Append($"{ke.m_Title}{beheld.Name}");
}
break;
}
}
break;
}
}
}
else
{
title.Append(beheld.Name);
}
if (beheld is PlayerMobile mobile && mobile.DisplayChampionTitle)
{
var titleLabel = ChampionTitleSystem.GetChampionTitleLabel(mobile);
if (titleLabel > 0)
{
// Should this be translated to the receivers language? Prefix titles aren't?
title.Append($": {Localization.GetText(titleLabel)}");
// Do not display the skills title
return title.ToString();
}
}
var customTitle = beheld.Title?.Trim();
if (customTitle?.Length > 0)
{
title.Append($" {customTitle}");
}
else if (showSkillTitle && beheld.Player)
{
var skillTitle = GetSkillTitle(beheld);
if (skillTitle != null)
{
title.Append($", {skillTitle}");
}
}
return title.ToString();
}
public static string GetSkillTitle(Mobile mob)
{
var highest = GetHighestSkill(mob); // beheld.Skills.Highest;
if (highest?.BaseFixedPoint >= 300)
{
var skillLevel = GetSkillLevel(highest);
var skillTitle = highest.Info.Title;
if (mob.Female && skillTitle.EndsWithOrdinal("man"))
{
return $"{skillLevel} {skillTitle.AsSpan(0, skillTitle.Length - 3)}woman";
}
return $"{skillLevel} {skillTitle}";
}
return null;
}
private static Skill GetHighestSkill(Mobile m)
{
var skills = m.Skills;
if (!Core.AOS)
{
return skills.Highest;
}
Skill highest = null;
for (var i = 0; i < m.Skills.Length; ++i)
{
var check = m.Skills[i];
if (highest == null || check.BaseFixedPoint > highest.BaseFixedPoint)
{
highest = check;
}
else if (highest.Lock != SkillLock.Up && check.Lock == SkillLock.Up &&
check.BaseFixedPoint == highest.BaseFixedPoint)
{
highest = check;
}
}
return highest;
}
private static string GetSkillLevel(Skill skill) => m_Levels[GetTableIndex(skill), GetTableType(skill)];
private static int GetTableType(Skill skill)
{
return skill.SkillName switch
{
SkillName.Bushido => 1,
SkillName.Ninjitsu => 2,
_ => 0
};
}
private static int GetTableIndex(Skill skill)
{
var fp = Math.Min(skill.BaseFixedPoint, 1200);
return (fp - 300) / 100;
}
}
public class FameEntry
{
public int m_Fame;
public KarmaEntry[] m_Karma;
public FameEntry(int fame, KarmaEntry[] karma)
{
m_Fame = fame;
m_Karma = karma;
}
}
public class KarmaEntry
{
public int m_Karma;
public string m_Title;
public KarmaEntry(int karma, string title)
{
m_Karma = karma;
m_Title = title;
}
}
}