Skip to content

Commit

Permalink
Show error for wrong ID in DBCharacterClass.EligibleRace (#450)
Browse files Browse the repository at this point in the history
Load default CharacterClass if loading from DB fails
Remove CharacterClass.player member
  • Loading branch information
NetDwarf authored Feb 20, 2023
2 parents 5f18587 + 3104c8e commit 8a21b5c
Show file tree
Hide file tree
Showing 88 changed files with 158 additions and 165 deletions.
2 changes: 1 addition & 1 deletion GameServer/behaviour/BehaviourUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static string GetPersonalizedMessage(string message, GamePlayer player)
}

message = message.Replace(RACE, player.RaceName);
message = message.Replace(CLASS, player.CharacterClass.Name);
message = message.Replace(CLASS, player.Salutation);
message = message.Replace("<RealmTitle>", player.RealmTitle);

if (message.Contains("<Guild>"))
Expand Down
2 changes: 1 addition & 1 deletion GameServer/commands/gmcommands/GMinfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public void OnCommand(GameClient client, string[] args)
info.Add(" - Lastname : " + target.LastName);
info.Add(" - Realm : " + GlobalConstants.RealmToName(target.Realm));
info.Add(" - Level : " + target.Level);
info.Add(" - Class : " + target.CharacterClass.Name);
info.Add(" - Class : " + target.Salutation);
info.Add(" - Guild : " + target.GuildName);
info.Add(" ");
info.Add(" - Account Name : " + target.AccountName);
Expand Down
6 changes: 3 additions & 3 deletions GameServer/commands/gmcommands/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ public void OnCommand(GameClient client, string[] args)

foreach (GamePlayer p in player.Group.GetPlayersInTheGroup())
{
text.Add(p.Name + " " + p.Level + " " + p.CharacterClass.Name);
text.Add(p.Name + " " + p.Level + " " + p.Salutation);
}

client.Out.SendCustomTextWindow("Group Members", text);
Expand Down Expand Up @@ -2263,7 +2263,7 @@ private void Show_Inventory(GamePlayer player, GameClient client, string limitTy
var text = new List<string>();
text.Add(" - Name Lastname : " + player.Name + " " + player.LastName);
text.Add(" - Realm Level Class : " + GlobalConstants.RealmToName(player.Realm) + " " + player.Level + " " +
player.CharacterClass.Name);
player.Salutation);
text.Add(" ");
text.Add(Money.GetShortString(player.CopperBalance));
text.Add(" ");
Expand Down Expand Up @@ -2353,7 +2353,7 @@ private void Show_Info(GamePlayer player, GameClient client)
text.Add(" ");
text.Add("PLAYER INFORMATION (Client # " + player.Client.SessionID + ", " + player.GetType().FullName + ")");
text.Add(" - Name Lastname : " + player.Name + " " + player.LastName);
text.Add(" - Realm Level Gender Class : " + GlobalConstants.RealmToName(player.Realm) + " " + player.Level + " " + player.Gender + " " + player.CharacterClass.Name + " (" + player.CharacterClass.ID + ")");
text.Add(" - Realm Level Gender Class : " + GlobalConstants.RealmToName(player.Realm) + " " + player.Level + " " + player.Gender + " " + player.Salutation + " (" + player.CharacterClass.ID + ")");
text.Add(" - Guild : " + player.GuildName + " " + (player.GuildRank != null ? "Rank: " + player.GuildRank.RankLevel.ToString() : ""));
text.Add(" - XPs/RPs/BPs : " + player.Experience + " xp, " + player.RealmPoints + " rp, " + player.BountyPointBalance + " bp");

Expand Down
2 changes: 1 addition & 1 deletion GameServer/commands/playercommands/battlegroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void OnCommand(GameClient client, string[] args)
{
text.Append(" <Leader>");
}
text.Append("(" + nongrouped.CharacterClass.Name + ")");
text.Append("(" + nongrouped.Salutation + ")");
text.Append(nongrouped.Name + '\n');
client.Out.SendMessage(text.ToString(), eChatType.CT_BattleGroup, eChatLoc.CL_SystemWindow);
}
Expand Down
2 changes: 1 addition & 1 deletion GameServer/commands/playercommands/chatgroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void OnCommand(GameClient client, string[] args)
text.Append(">");
}
text.Append(" (");
text.Append(player.CharacterClass.Name);
text.Append(player.Salutation);
text.Append(")");
client.Out.SendMessage(text.ToString(), eChatType.CT_System, eChatLoc.CL_SystemWindow);
//TODO: make function formatstring
Expand Down
6 changes: 3 additions & 3 deletions GameServer/commands/playercommands/guild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ public void OnCommand(GameClient client, string[] args)
{
ind++;
string zoneName = (ply.CurrentZone == null ? "(null)" : ply.CurrentZone.Description);
string mesg = ind + ") " + ply.Name + " <guild=" + guild.Name + "> the Level " + ply.Level + " " + ply.CharacterClass.Name + " in " + zoneName;
string mesg = ind + ") " + ply.Name + " <guild=" + guild.Name + "> the Level " + ply.Level + " " + ply.Salutation + " in " + zoneName;
client.Out.SendMessage(mesg, eChatType.CT_Guild, eChatLoc.CL_SystemWindow);
}
}
Expand Down Expand Up @@ -1568,9 +1568,9 @@ public void OnCommand(GameClient client, string[] args)
string zoneName = (ply.CurrentZone == null ? "(null)" : ply.CurrentZone.Description);
string mesg;
if (ply.GuildRank.Title != null)
mesg = ind.ToString() + ") " + ply.Name + " <" + ply.GuildRank.Title + "> the Level " + ply.Level.ToString() + " " + ply.CharacterClass.Name + " in " + zoneName;
mesg = ind.ToString() + ") " + ply.Name + " <" + ply.GuildRank.Title + "> the Level " + ply.Level.ToString() + " " + ply.Salutation + " in " + zoneName;
else
mesg = ind.ToString() + ") " + ply.Name + " <" + ply.GuildRank.RankLevel.ToString() + "> the Level " + ply.Level.ToString() + " " + ply.CharacterClass.Name + " in " + zoneName;
mesg = ind.ToString() + ") " + ply.Name + " <" + ply.GuildRank.RankLevel.ToString() + "> the Level " + ply.Level.ToString() + " " + ply.Salutation + " in " + zoneName;
if (ServerProperties.Properties.ALLOW_CHANGE_LANGUAGE)
mesg += " <" + ply.Client.Account.Language + ">";
if (ind >= startInd)
Expand Down
4 changes: 2 additions & 2 deletions GameServer/commands/playercommands/who.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private string FormatLine(GamePlayer player, uint PrivLevel, GameClient source)
if (player.ClassNameFlag)
{
result.Append(" ");
result.Append(LanguageMgr.GetTranslation(source, "PlayerClass.Name." + player.CharacterClass.Name));
result.Append(LanguageMgr.GetTranslation(source, "PlayerClass.Name." + player.Salutation));
}
else if (player.CharacterClass != null)
{
Expand Down Expand Up @@ -388,7 +388,7 @@ public bool ApplyFilter(GamePlayer player)
return true;
if (GameServer.Instance.Configuration.ServerType == eGameServerType.GST_PvP)
return false;
if (player.CharacterClass.Name.ToLower().StartsWith(m_filterString))
if (player.Salutation.ToLower().StartsWith(m_filterString))
return true;
if (player.CurrentZone != null && player.CurrentZone.Description.ToLower().Contains(m_filterString))
return true;
Expand Down
14 changes: 7 additions & 7 deletions GameServer/gameobjects/Atlantis/Arbiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override bool Interact(GamePlayer player)
String realm = GlobalConstants.RealmToName((eRealm)Realm);

SayTo(player, eChatLoc.CL_PopupWindow, LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.Interact.Welcome", realm), player.CharacterClass.Name));
String.Format("{0}.Arbiter.Interact.Welcome", realm), player.Salutation));

// TODO: This appears to be level-dependent. Get the proper message
// for all the other cases (high enough level when starting the trials
Expand Down Expand Up @@ -75,7 +75,7 @@ public override bool WhisperReceive(GameLiving source, string text)
{
SayTo(player, eChatLoc.CL_PopupWindow,
LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Text1", realm), player.CharacterClass.Name));
String.Format("{0}.Arbiter.WhisperReceive.Text1", realm), player.Salutation));
return false;
}
else if (lowerCase == LanguageMgr.GetTranslation(player.Client.Account.Language,
Expand All @@ -99,7 +99,7 @@ public override bool WhisperReceive(GameLiving source, string text)
{
SayTo(player, eChatLoc.CL_PopupWindow,
LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Text4", realm), player.CharacterClass.Name));
String.Format("{0}.Arbiter.WhisperReceive.Text4", realm), player.Salutation));
return false;
}
else if (lowerCase == LanguageMgr.GetTranslation(player.Client.Account.Language,
Expand All @@ -115,31 +115,31 @@ public override bool WhisperReceive(GameLiving source, string text)
{
SayTo(player, eChatLoc.CL_PopupWindow,
LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Text6", realm), player.CharacterClass.Name));
String.Format("{0}.Arbiter.WhisperReceive.Text6", realm), player.Salutation));
return false;
}
else if (lowerCase == LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Case7", realm)))
{
SayTo(player, eChatLoc.CL_PopupWindow,
LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Text7", realm), player.CharacterClass.Name));
String.Format("{0}.Arbiter.WhisperReceive.Text7", realm), player.Salutation));
return false;
}
else if (lowerCase == LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Case8", realm)))
{
SayTo(player, eChatLoc.CL_PopupWindow,
LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Text8", realm), player.CharacterClass.Name));
String.Format("{0}.Arbiter.WhisperReceive.Text8", realm), player.Salutation));
return false;
}
else if (lowerCase == LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Case9", realm)))
{
SayTo(player, eChatLoc.CL_PopupWindow,
LanguageMgr.GetTranslation(player.Client.Account.Language,
String.Format("{0}.Arbiter.WhisperReceive.Text9", realm), player.CharacterClass.Name));
String.Format("{0}.Arbiter.WhisperReceive.Text9", realm), player.Salutation));
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion GameServer/gameobjects/Atlantis/ArtifactScholar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public override bool Interact(GamePlayer player)
(eCharacterClass)player.CharacterClass.ID, (eRealm)player.Realm);
if (versions.Count > 1)
{
this.SayTo(player, string.Format("{0}, I see that you carry {1}. If you are interested, I will exchange yours for you but there is a price to pay for the change. Any experience or levels your artifact has gained will be lost when the change occurs. Are you still [interested]?", player.CharacterClass.Name, art));
this.SayTo(player, string.Format("{0}, I see that you carry {1}. If you are interested, I will exchange yours for you but there is a price to pay for the change. Any experience or levels your artifact has gained will be lost when the change occurs. Are you still [interested]?", player.Salutation, art));
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion GameServer/gameobjects/Atlantis/Scholar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override bool Interact(GamePlayer player)
else
{
intro = String.Format("Which artifact may I assist you with, {0}? {1} {2}",
player.CharacterClass.Name,
player.Salutation,
"I study the lore and magic of the following artifacts:",
artifacts);

Expand Down
35 changes: 17 additions & 18 deletions GameServer/gameobjects/CharacterClasses/CharacterClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace DOL.GS
{
public class CharacterClass
{
private static Dictionary<int, CharacterClass> allClasses = new Dictionary<int, CharacterClass>();
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

private GamePlayer player;
private static Dictionary<int, CharacterClass> allClasses = new Dictionary<int, CharacterClass>();

private string name;
private string femaleName;
Expand All @@ -32,10 +32,7 @@ public class CharacterClass
public string ProfessionTranslationID { get; private set; } = "";
public ushort MaxPulsingSpells { get; private set; }

public string Name => GetSalutation(player.Gender);
public string BaseName => GetClass(baseClassID).name;
public string Profession
=> LanguageMgr.TryTranslateOrDefault(player, ProfessionTranslationID, ProfessionTranslationID);
public List<PlayerRace> EligibleRaces => eligibleRaces.ToList();
public int AdjustedSpecPointsMultiplier => SpecPointsMultiplier;

Expand Down Expand Up @@ -66,13 +63,19 @@ public static CharacterClass Create(DBCharacterClass dbCharClass)
charClass.ProfessionTranslationID = dbCharClass.ProfessionTranslationID;

charClass.AutoTrainSkills = dbCharClass.AutoTrainSkills
.Split(';', ',').Where(s => !string.IsNullOrEmpty(s));
.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);

var newElibibleRaces = dbCharClass.EligibleRaces
.Split(';', ',').Where(s => !string.IsNullOrEmpty(s))
.Select(s => Convert.ToInt32(s))
.Select(i => PlayerRace.GetRace(i));
charClass.eligibleRaces = newElibibleRaces;
var eligibleRaces = new List<PlayerRace>();
var raceIDs = dbCharClass.EligibleRaces
.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => Convert.ToInt32(s));
foreach (var raceID in raceIDs)
{
var race = PlayerRace.GetRace(raceID);
if (race.Equals(PlayerRace.Unknown)) log.Error($"CharacterClass with ID {charClass.ID} contains invalid EligibleRace {raceID}.");
else eligibleRaces.Add(race);
}
charClass.eligibleRaces = eligibleRaces;

charClass.MaxPulsingSpells = dbCharClass.MaxPulsingSpells == 0 ? (byte)2 : dbCharClass.MaxPulsingSpells;

Expand All @@ -87,6 +90,9 @@ public string GetSalutation(eGender gender)
else return name;
}

public string GetProfessionTitle(GamePlayer player)
=> LanguageMgr.TryTranslateOrDefault(player, ProfessionTranslationID, ProfessionTranslationID);

public string GetTitle(GamePlayer player, int level)
{
if (!HasAdvancedFromBaseClass()) level = 0;
Expand All @@ -109,13 +115,6 @@ public static CharacterClass GetClass(int classID)
return characterClass;
}

public static CharacterClass GetClass(GamePlayer player, int classID)
{
var charClass = GetClass(classID);
charClass.player = player;
return charClass;
}

public CharacterClass GetBaseClass()
=> GetClass(baseClassID);

Expand Down
25 changes: 13 additions & 12 deletions GameServer/gameobjects/CharacterClasses/CharacterClassDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,28 @@ public static void Load()
var dbClasses = DOLDB<DBCharacterClass>.SelectAllObjects().ToDictionary(c => c.ID, c => c);
foreach (var classID in defaultClasses.Keys.ToList().Union(dbClasses.Keys))
{
DBCharacterClass dbClass;
CharacterClass charClass;
if (dbClasses.TryGetValue(classID, out var databaseEntry))
{
dbClass = databaseEntry;
try
{
charClass = CharacterClass.Create(databaseEntry);
}
catch (Exception e)
{
log.Error($"CharacterClass with ID {classID} could not be loaded from database. Load default instead.:\n{e}");
charClass = CharacterClass.Create(defaultClasses[classID]);
}
}
else
{
dbClass = defaultClasses[classID];
var dbClass = defaultClasses[classID];
dbClass.AllowAdd = true;
GameServer.Database.AddObject(dbClass);
charClass = CharacterClass.Create(dbClass);
}

try
{
var charClass = CharacterClass.Create(dbClass);
CharacterClass.AddOrReplace(charClass);
}
catch (Exception e)
{
log.Error($"CharacterClass with ID {classID} could not be loaded:\n{e}");
}
CharacterClass.AddOrReplace(charClass);
}
}

Expand Down
2 changes: 1 addition & 1 deletion GameServer/gameobjects/CustomNPC/FaceCustomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override bool Interact(GamePlayer player)

if(player.CustomisationStep == 2)
{
SayTo(player, eChatLoc.CL_PopupWindow, player.CharacterClass.Name +", I have discovered a secret spell that will allow you to change your appearance. I can cast this spell upon you if you wish. All you must do is say the word and I will [change your appearance].");
SayTo(player, eChatLoc.CL_PopupWindow, player.Salutation +", I have discovered a secret spell that will allow you to change your appearance. I can cast this spell upon you if you wish. All you must do is say the word and I will [change your appearance].");
}
else if(player.CustomisationStep == 3)
{
Expand Down
4 changes: 2 additions & 2 deletions GameServer/gameobjects/CustomNPC/GameTrainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public bool PromotePlayer(GamePlayer player, int classid, string messageToPlayer

if (messageToPlayer != "")
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.PromotePlayer.Says", this.Name, messageToPlayer), eChatType.CT_System, eChatLoc.CL_PopupWindow);
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.PromotePlayer.Upgraded", player.CharacterClass.Name), eChatType.CT_Important, eChatLoc.CL_SystemWindow);
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.PromotePlayer.Upgraded", player.Salutation), eChatType.CT_Important, eChatLoc.CL_SystemWindow);

player.RefreshSpecDependantSkills(true);
player.StartPowerRegeneration();
Expand All @@ -405,7 +405,7 @@ public bool PromotePlayer(GamePlayer player, int classid, string messageToPlayer
}

// after gifts
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.PromotePlayer.Accepted", player.CharacterClass.Profession), eChatType.CT_Important, eChatLoc.CL_SystemWindow);
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.PromotePlayer.Accepted", player.CharacterClass.GetProfessionTitle(player)), eChatType.CT_Important, eChatLoc.CL_SystemWindow);

Notify(GameTrainerEvent.PlayerPromoted, this, new PlayerPromotedEventArgs(player, oldClass));

Expand Down
2 changes: 1 addition & 1 deletion GameServer/gameobjects/CustomNPC/GuildRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override bool Interact(GamePlayer player)
if (!base.Interact(player))
return false;

SayTo(player, "Hail, " + player.CharacterClass.Name + ". Have you come to [" + FORM_A_GUILD + "]?");
SayTo(player, "Hail, " + player.Salutation + ". Have you come to [" + FORM_A_GUILD + "]?");

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions GameServer/gameobjects/CustomNPC/Hastener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ public override bool Interact(GamePlayer player)
if (player.CurrentRegion.IsCapitalCity)
SayTo(player, string.Format("{0} {1}. {2} {3} {4}",
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.Greeting"),
player.CharacterClass.Name,
player.Salutation,
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.CityMovementOffer"),
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.StrengthOffer"),
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.BorderKeepPortOffer")));
else if (IsShroudedIslesStartZone(player.CurrentZone.ID))
SayTo(player, string.Format("{0} {1}. {2} {3}",
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.Greeting"),
player.CharacterClass.Name,
player.Salutation,
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.CityMovementOffer"),
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.BorderKeepPortOffer")));
else if(!player.CurrentRegion.IsRvR)//default message outside of RvR
SayTo(player, string.Format("{0} {1}. {2}",
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.Greeting"),
player.CharacterClass.Name,
player.Salutation,
LanguageMgr.GetTranslation(player.Client.Account.Language, "GameHastener.DefaultMovementOffer")));
return true;
}
Expand Down
Loading

0 comments on commit 8a21b5c

Please sign in to comment.