Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/ZoneServer/Commands/ChatCommands.Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,9 +1498,28 @@ private CommandResult HandleAddJob(Character sender, Character target, string me

if (job == null)
{
// Store current levels of all existing jobs before adding the new one,
// because adding a job changes the rank which affects how TotalExp
// translates to Level (Level is calculated from TotalExp + rank)
var existingJobLevels = new Dictionary<JobId, int>();
foreach (var existingJob in target.Jobs.GetList())
existingJobLevels[existingJob.Id] = existingJob.Level;

Send.ZC_PC(target, PcUpdateType.Job, (int)jobId, (int)circle);
target.JobId = jobId;
target.Jobs.Add(new Job(target, jobId, circle));

// After adding the job, the rank has increased. Recalculate TotalExp
// for all existing jobs to maintain their levels at the new rank.
var newRank = target.Jobs.GetCurrentRank();
foreach (var existingJob in target.Jobs.GetList())
{
if (existingJob.Id == jobId)
continue; // Skip the newly added job

var targetLevel = existingJobLevels[existingJob.Id];
existingJob.TotalExp = ZoneServer.Instance.Data.ExpDb.GetNextTotalJobExp(newRank, targetLevel);
}
}
else
target.Jobs.ChangeCircle(jobId, circle);
Expand Down