unit viewrcd;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, TabNotBk, Grids, ExtCtrls, Buttons,
  ComCtrls, HumDB, Grobal2, DBShare, HUtil32;
type
  TFrmFDBViewer = class(TForm)
    TabbedNotebook1: TTabbedNotebook;
    HumanGrid: TStringGrid;
    UseMagicGrid: TStringGrid;
    BagItemGrid: TStringGrid;
    SaveItemGrid: TStringGrid;
    UserItemGrid: TStringGrid;
    procedure FormCreate(Sender: TObject);
  private
    procedure sub_49A0C0();
    procedure sub_49A9DC();
    procedure sub_49AA84();
    procedure sub_49AB10();
    procedure InitUserItemGrid;
    procedure ShowUserItem(nIndex: Integer; sName: string; Item: TUserItem);
    procedure ShowBagItem(nIndex: Integer; sName: string; Item: TUserItem);
    procedure ShowUserItems();
    procedure ShowBagItems();
    procedure ShowUseMagic();
    procedure ShowSaveItem();
    procedure ShowHumanInfo();
    { Private declarations }
  public
    n2F8: Integer;
    s2FC: string;
    ChrRecord: THumDataInfo;
    procedure ShowHumData();
    { Public declarations }
  end;

var
  FrmFDBViewer: TFrmFDBViewer;

implementation
{$R *.DFM}

procedure TFrmFDBViewer.FormCreate(Sender: TObject);
begin
  sub_49A0C0();
  sub_49A9DC();
  sub_49AA84();
  sub_49AB10();
  InitUserItemGrid;
end;

procedure TFrmFDBViewer.ShowHumData();
begin
  if HumanGrid.Visible then ShowHumanInfo();
  if UserItemGrid.Visible then ShowUserItems();
  if BagItemGrid.Visible then ShowBagItems();
  if UseMagicGrid.Visible then ShowUseMagic();
  if SaveItemGrid.Visible then ShowSaveItem();
  TabbedNotebook1.PageIndex := 0;
end;

procedure TFrmFDBViewer.sub_49A0C0();
begin
  HumanGrid.Cells[0,1]:='Index';
  HumanGrid.Cells[1,1]:='ChrName';
  HumanGrid.Cells[2,1]:='Current Map';
  HumanGrid.Cells[3,1]:='Current X';
  HumanGrid.Cells[4,1]:='Current Y';
  HumanGrid.Cells[5,1]:='Direction';
  HumanGrid.Cells[6,1]:='Job';
  HumanGrid.Cells[7,1]:='Sex';
  HumanGrid.Cells[8,1]:='Hair';
  HumanGrid.Cells[9,1]:='Gold';
  HumanGrid.Cells[10,1]:='Dear';
  HumanGrid.Cells[11,1]:='Home Map';

  HumanGrid.Cells[0, 3] := 'Home X';
  HumanGrid.Cells[1, 3] := 'Home Y';
  HumanGrid.Cells[2, 3] := 'Level';
  HumanGrid.Cells[3, 3] := 'AC';
  HumanGrid.Cells[4, 3] := 'MAC';
  HumanGrid.Cells[5, 3] := 'Reserved1';
  HumanGrid.Cells[6, 3] := 'Min DC';
  HumanGrid.Cells[7, 3] := 'Max DC';
  HumanGrid.Cells[8, 3] := 'Min MC';
  HumanGrid.Cells[9, 3] := 'Max MC';
  HumanGrid.Cells[10, 3] := 'Min SC';
  HumanGrid.Cells[11, 3] := 'Max SC';

  HumanGrid.Cells[0,5]:='Reserved2';
  HumanGrid.Cells[1,5]:='Current HP';
  HumanGrid.Cells[2,5]:='Max HP';
  HumanGrid.Cells[3,5]:='Current MP';
  HumanGrid.Cells[4,5]:='Max MP';
  HumanGrid.Cells[5,5]:='Reserved3';
  HumanGrid.Cells[6,5]:='Exp';
  HumanGrid.Cells[7,5]:='Max Exp';
  HumanGrid.Cells[8,5]:='PK-Point';
  HumanGrid.Cells[9,5]:='';
  HumanGrid.Cells[10, 5] := 'Login Account';
  HumanGrid.Cells[11, 5] := 'Last Login';

  HumanGrid.Cells[0, 7] := 'Spouse';
  HumanGrid.Cells[1, 7] := 'Master and apprentice';
  HumanGrid.Cells[2, 7] := 'Storage password';
  HumanGrid.Cells[3, 7] := 'Reputation points';
  HumanGrid.Cells[4, 7] := 'Is a hero';
  HumanGrid.Cells[5, 7] := '';
  HumanGrid.Cells[6, 7] := '';
  HumanGrid.Cells[7, 7] := '';
  HumanGrid.Cells[8, 7] := '';
  HumanGrid.Cells[9, 7] := '';
  HumanGrid.Cells[10, 7] := '';
  HumanGrid.Cells[11, 7] := '';
end;

procedure TFrmFDBViewer.InitUserItemGrid;
begin
 UserItemGrid.Cells[0, 0] := 'Item Slot';
 UserItemGrid.Cells[1, 0] := 'Item ID';
 UserItemGrid.Cells[2, 0] := 'Item Number';
 UserItemGrid.Cells[3, 0] := 'Durability';
 UserItemGrid.Cells[4, 0] := 'Item Name';


 UserItemGrid.Cells[0, 1] := 'Clothes';
 UserItemGrid.Cells[0, 2] := 'Weapons';
 UserItemGrid.Cells[0, 3] := 'Lighting';
 UserItemGrid.Cells[0, 4] := 'Necklace';
 UserItemGrid.Cells[0, 5] := 'Helmet';
 UserItemGrid.Cells[0, 6] := 'Left bracelet';
 UserItemGrid.Cells[0, 7] := 'Right bracelet';
 UserItemGrid.Cells[0, 8] := 'Left ring';
 UserItemGrid.Cells[0, 9] := 'Right Ring';
 UserItemGrid.Cells[0, 10] := 'Item';
 UserItemGrid.Cells[0, 11] := 'Belt';
 UserItemGrid.Cells[0, 12] := 'Shoes';
 UserItemGrid.Cells[0, 13] := 'Gem';
 UserItemGrid.Cells[0, 14] := 'Mount';
 UserItemGrid.Cells[0, 15] := 'Item1';
 UserItemGrid.Cells[0, 16] := 'Item2';
 UserItemGrid.Cells[0, 17] := 'Item3';
 UserItemGrid.Cells[0, 18] := 'Item4';
 UserItemGrid.Cells[0, 19] := 'Item5';
end;

procedure TFrmFDBViewer.sub_49A9DC();
begin
 BagItemGrid.Cells[0, 0] := 'Item number';
 BagItemGrid.Cells[1, 0] := 'Item ID';
 BagItemGrid.Cells[2, 0] := 'item number';
 BagItemGrid.Cells[3, 0] := 'Durability';
 BagItemGrid.Cells[4, 0] := 'Item Name';
end;

procedure TFrmFDBViewer.sub_49AA84();
begin
 SaveItemGrid.Cells[0, 0] := 'Number';
 SaveItemGrid.Cells[1, 0] := 'Item Serial Number';
 SaveItemGrid.Cells[2, 0] := 'Item number';
 SaveItemGrid.Cells[3, 0] := 'Durability';
 SaveItemGrid.Cells[4, 0] := 'Item Name';

end;

procedure TFrmFDBViewer.sub_49AB10();
begin
 UseMagicGrid.Cells[0, 0] := 'Skill ID';
 UseMagicGrid.Cells[1, 0] := 'Shortcut Key';
 UseMagicGrid.Cells[2, 0] := 'Discipline status';
 UseMagicGrid.Cells[3, 0] := 'Skill Name';

end;

procedure TFrmFDBViewer.ShowBagItem(nIndex: Integer; sName: string; Item: TUserItem);
begin
  if Item.wIndex > 0 then begin
    BagItemGrid.Cells[0, nIndex] := sName;
    BagItemGrid.Cells[1, nIndex] := IntToStr(Item.MakeIndex);
    BagItemGrid.Cells[2, nIndex] := IntToStr(Item.wIndex);
    BagItemGrid.Cells[3, nIndex] := IntToStr(Item.Dura) + '/' + IntToStr(Item.DuraMax);
    BagItemGrid.Cells[4, nIndex] := GetStdItemName(Item.wIndex);
  end else begin
    BagItemGrid.Cells[0, nIndex] := sName;
    BagItemGrid.Cells[1, nIndex] := '';
    BagItemGrid.Cells[2, nIndex] := '';
    BagItemGrid.Cells[3, nIndex] := '';
    BagItemGrid.Cells[4, nIndex] := '';
  end;
end;

procedure TFrmFDBViewer.ShowUserItem(nIndex: Integer; sName: string; Item: TUserItem);
begin
  if Item.wIndex > 0 then begin
    UserItemGrid.Cells[1, nIndex] := IntToStr(Item.MakeIndex);
    UserItemGrid.Cells[2, nIndex] := IntToStr(Item.wIndex);
    UserItemGrid.Cells[3, nIndex] := IntToStr(Item.Dura) + '/' + IntToStr(Item.DuraMax);
    UserItemGrid.Cells[4, nIndex] := GetStdItemName(Item.wIndex);
  end else begin
    UserItemGrid.Cells[1, nIndex] := '';
    UserItemGrid.Cells[2, nIndex] := '';
    UserItemGrid.Cells[3, nIndex] := '';
    UserItemGrid.Cells[4, nIndex] := '';
  end;
end;

procedure TFrmFDBViewer.ShowHumanInfo();
var
  HumData: pTHumData;
begin
  HumData := @ChrRecord.Data;
  HumanGrid.Cells[0, 2] := IntToStr(n2F8);
  HumanGrid.Cells[1, 2] := HumData.sChrName;
  HumanGrid.Cells[2, 2] := HumData.sCurMap;
  HumanGrid.Cells[3, 2] := IntToStr(HumData.wCurX);
  HumanGrid.Cells[4, 2] := IntToStr(HumData.wCurY);
  HumanGrid.Cells[5, 2] := IntToStr(HumData.btDir);
  HumanGrid.Cells[6, 2] := IntToStr(HumData.btJob);
  HumanGrid.Cells[7, 2] := IntToStr(HumData.btSex);
  HumanGrid.Cells[8, 2] := IntToStr(HumData.btHair);
  HumanGrid.Cells[9, 2] := IntToStr(HumData.nGold);
  HumanGrid.Cells[10, 2] := HumData.sDearName;
  HumanGrid.Cells[11, 2] := HumData.sHomeMap;

  HumanGrid.Cells[0, 4] := IntToStr(HumData.wHomeX);
  HumanGrid.Cells[1, 4] := IntToStr(HumData.wHomeY);
  HumanGrid.Cells[2, 4] := IntToStr(HumData.Abil.Level);
  HumanGrid.Cells[3, 4] := IntToStr(HumData.Abil.AC);
  HumanGrid.Cells[4, 4] := IntToStr(HumData.Abil.MAC);
  //  HumanGrid.Cells[5,4]:=IntToStr(HumData.Abil.bt49);
  HumanGrid.Cells[6, 4] := IntToStr(LoByte(HumData.Abil.DC));
  HumanGrid.Cells[7, 4] := IntToStr(HiByte(HumData.Abil.DC));
  HumanGrid.Cells[8, 4] := IntToStr(LoByte(HumData.Abil.MC));
  HumanGrid.Cells[9, 4] := IntToStr(HiByte(HumData.Abil.MC));
  HumanGrid.Cells[10, 4] := IntToStr(LoByte(HumData.Abil.SC));
  HumanGrid.Cells[11, 4] := IntToStr(HiByte(HumData.Abil.SC));
  //  HumanGrid.Cells[0,6]:=IntToStr(HumData.Abil.bt48);
  HumanGrid.Cells[1, 6] := IntToStr(HumData.Abil.HP);
  HumanGrid.Cells[2, 6] := IntToStr(HumData.Abil.HP);
  HumanGrid.Cells[3, 6] := IntToStr(HumData.Abil.MaxMP);
  HumanGrid.Cells[4, 6] := IntToStr(HumData.Abil.MaxMP);
  //  HumanGrid.Cells[5,6]:=IntToStr(HumData.Abil.bt48);
  HumanGrid.Cells[6, 6] := IntToStr(HumData.Abil.Exp);
  HumanGrid.Cells[7, 6] := IntToStr(HumData.Abil.MaxExp);
  HumanGrid.Cells[8, 6] := IntToStr(HumData.nPKPoint);
  HumanGrid.Cells[9, 6] := '';
  HumanGrid.Cells[10, 6] := HumData.sAccount;
  HumanGrid.Cells[11, 6] := DateTimeToStr(ChrRecord.Header.dCreateDate);
  HumanGrid.Cells[0, 8] := HumData.sDearName;
  HumanGrid.Cells[1, 8] := HumData.sMasterName;
  HumanGrid.Cells[2, 8] := HumData.sStoragePwd;
  HumanGrid.Cells[3, 8] := IntToStr(HumData.btCreditPoint);
  HumanGrid.Cells[4, 8] := BooleanToStr(HumData.boIsHero);
  if not HumData.boIsHero then begin
    HumanGrid.Cells[1, 7] := 'Apprenticeship';
    HumanGrid.Cells[5, 7] := 'Is there a hero';
    HumanGrid.Cells[6, 7] := 'Heroes name';
    HumanGrid.Cells[5, 8] := BooleanToStr(HumData.boHasHero);
    HumanGrid.Cells[6, 8] := HumData.sHeroChrName;
  end else begin
    HumanGrid.Cells[1, 7] := 'Host name';
    HumanGrid.Cells[5, 7] := '';
    HumanGrid.Cells[6, 7] := '';
    HumanGrid.Cells[5, 8] := '';
    HumanGrid.Cells[6, 8] := '';
  end;
end;

procedure TFrmFDBViewer.ShowBagItems();
var
  I, II: Integer;
begin
  for I := 1 to BagItemGrid.RowCount - 1 do begin
    for II := 0 to BagItemGrid.ColCount - 1 do begin
      BagItemGrid.Cells[II, I] := '';
    end;
  end;
  for I := Low(ChrRecord.Data.BagItems) to High(ChrRecord.Data.BagItems) do begin
    ShowBagItem(I + 1, IntToStr(I + 1), ChrRecord.Data.BagItems[I]);
  end;
end;

procedure TFrmFDBViewer.ShowUserItems();
var
  I, II: Integer;
begin
  for I := 1 to UserItemGrid.RowCount - 1 do begin
    for II := 1 to UserItemGrid.ColCount - 1 do begin
      UserItemGrid.Cells[II, I] := '';
    end;
  end;
   ShowUserItem(1, 'Clothing', ChrRecord.Data.HumItems [0]);
   ShowUserItem(2, 'Weapons', ChrRecord.Data.HumItems [1]);
   ShowUserItem(3, 'Lighting', ChrRecord.Data.HumItems [2]);
   ShowUserItem(4, 'Necklace', ChrRecord.Data.HumItems [3]);
   ShowUserItem(5, 'Helmets', ChrRecord.Data.HumItems [4]);
   ShowUserItem(6, 'Left Bracelets', ChrRecord.Data.HumItems [5]);
   ShowUserItem(7, 'Right Bracelets', ChrRecord.Data.HumItems [6]);
   ShowUserItem(8, 'Left Ring', ChrRecord.Data.HumItems [7]);
   ShowUserItem(9, 'Right Ring', ChrRecord.Data.HumItems [8]);
   ShowUserItem(10, 'Items', ChrRecord.Data.HumAddItems [9]);
   ShowUserItem(11, 'Belt', ChrRecord.Data.HumAddItems [10]);
   ShowUserItem(12, 'Shoes', ChrRecord.Data.HumAddItems [11]);
   ShowUserItem(13, 'Gems', ChrRecord.Data.HumAddItems [12]);
//   ShowUserItem(14, 'Mount', ChrRecord.Data.HumAddItems [13]);
end;

procedure TFrmFDBViewer.ShowUseMagic();
var
  I, ii: Integer;
begin
  for I := 1 to UseMagicGrid.RowCount - 1 do begin
    for ii := 0 to UseMagicGrid.ColCount - 1 do begin
      UseMagicGrid.Cells[ii, I] := '';
    end;
  end;
  for I := Low(ChrRecord.Data.HumMagics) to High(ChrRecord.Data.HumMagics) do begin
    if ChrRecord.Data.HumMagics[I].wMagIdx <= 0 then Break;
    UseMagicGrid.Cells[0, I + 1] := IntToStr(ChrRecord.Data.HumMagics[I].wMagIdx);
    UseMagicGrid.Cells[1, I + 1] := IntToStr(ChrRecord.Data.HumMagics[I].btKey);
    UseMagicGrid.Cells[2, I + 1] := IntToStr(ChrRecord.Data.HumMagics[I].nTranPoint);
    UseMagicGrid.Cells[3, I + 1] := GetMagicName(ChrRecord.Data.HumMagics[I].wMagIdx);
  end;
end;

procedure TFrmFDBViewer.ShowSaveItem();
var
  I, ii: Integer;
  nCount: Integer;
begin
  for I := 1 to SaveItemGrid.RowCount - 1 do begin
    for ii := 0 to SaveItemGrid.ColCount - 1 do begin
      SaveItemGrid.Cells[ii, I] := '';
    end;
  end;
  nCount := 0;
  for I := Low(ChrRecord.Data.StorageItems) to High(ChrRecord.Data.StorageItems) do begin
    if ChrRecord.Data.StorageItems[I].wIndex <= 0 then Continue;
    SaveItemGrid.Cells[0, I + 1] := IntToStr(nCount);
    SaveItemGrid.Cells[1, I + 1] := IntToStr(ChrRecord.Data.StorageItems[I].MakeIndex);
    SaveItemGrid.Cells[2, I + 1] := IntToStr(ChrRecord.Data.StorageItems[I].wIndex);
    SaveItemGrid.Cells[3, I + 1] := IntToStr(ChrRecord.Data.StorageItems[I].Dura) + '/' +
      IntToStr(ChrRecord.Data.StorageItems[I].DuraMax);
    SaveItemGrid.Cells[4, I + 1] := GetStdItemName(ChrRecord.Data.StorageItems[I].wIndex);
    Inc(nCount);
  end;
end;

end.
