// 角色详细数据合区处理过程
procedure TFrmMain.MirAllone;
var
FMirInfo: THumDataInfo; // 角色详细信息结构
FDBRecord, FNewDBRecord: TMirRecord; // 数据库文件操作对象
ALLcount, nIndex, I, nRecordCount: Integer; // 总数、索引、循环计数、记录数
DBHeader: TDBHeader; // 数据库文件头
begin
// 检查主区Mir.DB是否存在
if FileExists(EdtMainMir.Text) then
FDBRecord := TMirRecord.Create(EdtMainMir.Text, fmShareDenyNone)
else begin
Application.MessageBox('主区Mir数据库不存在!', '提示信息', MB_ICONQUESTION);
Exit;
end;
nItemidx := 0; // 重置物品ID计数器
// 如果目标目录存在Mir.DB则删除
if FileExists(EdtSavePath.Text + '\DBServer\FDB\Mir.DB') then
DeleteFile(EdtSavePath.Text + '\DBServer\FDB\Mir.DB');
// 创建新的Mir.DB文件
FNewDBRecord := TMirRecord.Create(EdtSavePath.Text + '\DBServer\FDB\Mir.DB', fmCreate);
try
// 设置记录大小
FNewDBRecord.RecSize := SizeOf(FMirInfo);
try
// 处理主区数据
FDBRecord.RecSize := SizeOf(FMirInfo);
// 读取并写入文件头
FDBRecord.Seek(0, 0);
FDBRecord.Read(DBHeader, SizeOf(DBHeader));
FNewDBRecord.Seek(0, 0);
FNewDBRecord.Write(DBHeader, SizeOf(DBHeader));
nRecordCount := FDBRecord.NumRecs;
FDBRecord.First;
StatusBar1.Panels[0].Text := '正在把主区Mir写入新库';
StatusBar1.Panels[1].Text := '';
Application.ProcessMessages;
// 复制主区所有角色详细数据
for i := 1 to nRecordCount do begin
FDBRecord.ReadRec(FMirInfo);
// 如果勾选了重置物品ID选项
if CheckBox1.Checked then
RefItemId(FMirInfo); // 重新生成物品ID
FNewDBRecord.AppendRec(FMirInfo);
// 更新进度条
StatusBar1.Panels[1].Text := '完成:' + inttostr(round((i / nRecordCount) * 100)) + '%';
Application.ProcessMessages;
FDBRecord.NextRec;
end;
finally
FDBRecord.Free;
end;
// 处理从区数据
if FileExists(EdtSlaveMir.Text) then
FDBRecord := TMirRecord.Create(EdtSlaveMir.Text, fmShareDenyNone)
else begin
Application.MessageBox('从库Mir数据库不存在!', '提示信息', MB_ICONQUESTION);
Exit;
end;
try
FDBRecord.RecSize := SizeOf(FMirInfo);
nRecordCount := FDBRecord.NumRecs;
FDBRecord.First;
StatusBar1.Panels[0].Text := '正在把从库Mir写入新库';
StatusBar1.Panels[1].Text := '';
Application.ProcessMessages;
// 处理从区所有角色详细数据
for i := 1 to nRecordCount do begin
FDBRecord.ReadRec(FMirInfo);
// 更新角色名称(如果在变更列表中)
nIndex := HumChangeList.GetIndex(FMirInfo.Data.sChrName);
if nIndex <> -1 then begin
FMirInfo.Header.sName := pTQuickName(HumChangeList.Objects[nIndex])^.sNewName;
FMirInfo.Data.sChrName := pTQuickName(HumChangeList.Objects[nIndex])^.sNewName;
end;
// 更新英雄名称(如果有)
if FMirInfo.Data.sHeroName <> '' then begin
nIndex := HumChangeList.GetIndex(FMirInfo.Data.sHeroName);
if nIndex <> -1 then
FMirInfo.Data.sHeroName := pTQuickName(HumChangeList.Objects[nIndex])^.sNewName;
end else begin
// 更新英雄主人名称
nIndex := HumChangeList.GetIndex(FMirInfo.Data.sHeroMasterName);
if nIndex <> -1 then
FMirInfo.Data.sHeroMasterName := pTQuickName(HumChangeList.Objects[nIndex])^.sNewName;
end;
// 更新配偶名称(如果有)
if FMirInfo.Data.sDearName <> '' then begin
nIndex := HumChangeList.GetIndex(FMirInfo.Data.sDearName);
if nIndex <> -1 then
FMirInfo.Data.sDearName := pTQuickName(HumChangeList.Objects[nIndex])^.sNewName;
end;
// 更新师傅名称(如果有)
if FMirInfo.Data.sMasterName <> '' then begin
nIndex := HumChangeList.GetIndex(FMirInfo.Data.sMasterName);
if nIndex <> -1 then
FMirInfo.Data.sMasterName := pTQuickName(HumChangeList.Objects[nIndex])^.sNewName;
end;
// 更新账号(如果在变更列表中)
nIndex := AccountChangeList.GetIndex(FMirInfo.Data.sAccount);
if nIndex <> -1 then
FMirInfo.Data.sAccount := pTQuickName(AccountChangeList.Objects[nIndex])^.sNewName;
// 注释掉的功能:清除经验值和奖励点数
{
if CheckBox2.Checked then
FMirInfo.Data.Abil.Exp := 0;
if CheckBox3.Checked then begin
FillChar(FMirInfo.Data.BonusAbil, SizeOf(TNakedAbility), #0);
FMirInfo.Data.nBonusPoint := 0;
end;
}
// 重新生成物品ID(如果勾选)
if CheckBox1.Checked then
RefItemId(FMirInfo);
FNewDBRecord.AppendRec(FMirInfo);
// 更新进度条
StatusBar1.Panels[1].Text := '完成:' + inttostr(round((i / nRecordCount) * 100)) + '%';
Application.ProcessMessages;
FDBRecord.NextRec;
end;
// 更新文件头中的记录总数
FDBRecord.Seek(0, 0);
FDBRecord.Read(DBHeader, SizeOf(DBHeader));
ALLcount := FNewDBRecord.NumRecs;
FNewDBRecord.Seek(0, 0);
DBHeader.nHumCount := ALLcount;
FNewDBRecord.Write(DBHeader, SizeOf(DBHeader));
finally
FDBRecord.Free;
end;
finally
FNewDBRecord.Free;
end;
end;