-
Notifications
You must be signed in to change notification settings - Fork 1
/
DM_ConvertToArmorType.pas
176 lines (153 loc) · 4.17 KB
/
DM_ConvertToArmorType.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
unit DM_ConvertToArmorType;
{
Hotkey: Ctrl+Shift+A
Converts selected armors to Clothing/Light/Heavy.
}
uses xEditApi;
var
arType: integer;
const
arTypeCloth = 0;
arTypeLight = 1;
arTypeHeavy = 2;
ArmorClothing = 'ArmorClothing';
ArmorLight = 'ArmorLight';
ArmorHeavy = 'ArmorHeavy';
function KeywordIndex(e: IInterface; edid: string): Integer;
var
kwda: IInterface;
n: integer;
begin
Result := -1;
kwda := ElementByPath(e, 'KWDA');
for n := 0 to ElementCount(kwda) - 1 do
if GetElementEditValues(LinksTo(ElementByIndex(kwda, n)), 'EDID') = edid then begin
Result := n;
Exit;
end;
end;
procedure SwapKeyword(e: IInterface; fromKey, toKey: string);
var
idx: Integer;
key: IInterface;
begin
idx := KeywordIndex(e, fromKey);
if idx <> -1 then begin
key := ElementByIndex(ElementByPath(e, 'KWDA'), idx);
SetEditValue(key, toKey);
end;
end;
procedure ConvertToArmorType(e: IInterface; aType: string);
begin
SetElementEditValues(e, 'BOD2\Armor Type', aType);
end;
procedure ConvertToArmorClothes(e: IInterface);
const
ArmorClothingL = 'ArmorClothing [KYWD:0006BBE8]';
begin
SwapKeyword(e, ArmorHeavy, ArmorClothingL);
SwapKeyword(e, ArmorLight, ArmorClothingL);
SwapKeyword(e, 'ArmorCuirass', 'ClothingBody [KYWD:000A8657]');
SwapKeyword(e, 'ArmorGauntlets', 'ClothingHands [KYWD:0010CD13]');
SwapKeyword(e, 'ArmorHelmet ', 'ClothingHead [KYWD:0010CD11]');
SwapKeyword(e, 'ArmorBoots', 'ClothingFeet [KYWD:0010CD12]');
ConvertToArmorType(e, 'Clothing');
end;
procedure SwapToArmored(e: IInterface);
begin
SwapKeyword(e, 'ClothingBody', 'ArmorCuirass [KYWD:0006C0EC]');
SwapKeyword(e, 'ClothingHands', 'ArmorGauntlets [KYWD:0006C0EF]');
SwapKeyword(e, 'ClothingHead', 'ArmorHelmet [KYWD:0006C0EE]');
SwapKeyword(e, 'ClothingFeet', 'ArmorBoots [KYWD:0006C0ED]');
end;
procedure ConvertToArmorHeavy(e: IInterface);
const
ArmorHeavyL = 'ArmorHeavy [KYWD:0006BBD2]';
begin
SwapKeyword(e, ArmorClothing, ArmorHeavyL);
SwapKeyword(e, ArmorLight, ArmorHeavyL);
SwapToArmored(e);
ConvertToArmorType(e, 'Heavy Armor');
end;
procedure ConvertToArmorLight(e: IInterface);
const
ArmorLightL = 'ArmorLight [KYWD:0006BBD3]';
begin
SwapKeyword(e, ArmorClothing, ArmorLightL);
SwapKeyword(e, ArmorHeavy, ArmorLightL);
SwapToArmored(e);
ConvertToArmorType(e, 'Light Armor');
end;
function Process(e: IInterface): Integer;
begin
if not (Signature(e) = 'ARMO') then Exit;
case arType of
arTypeCloth: ConvertToArmorClothes(e);
arTypeLight: ConvertToArmorLight(e);
arTypeHeavy: ConvertToArmorHeavy(e);
end;
end;
function CreateButton(AParent: TControl): TButton;
begin
Result := TButton.Create(AParent);
Result.Parent := AParent;
Result.Left := 0;
Result.Top := 0;
Result.Width := 180;
Result.Height := 32;
end;
function ShowForm: Integer;
var
frm: TForm;
btnExit, btnOk: TButton;
rgpOptions: TRadioGroup;
const
x = 120;
y = 30;
dy = 40;
begin
frm := TForm.Create(nil);
Result := 0;
try
frm.Caption := 'Convert to armor type';
frm.Position := poScreenCenter;
frm.BorderStyle := bsDialog;
frm.Height := 290;
frm.Width := 440;
rgpOptions := TRadioGroup.Create(frm);
rgpOptions.Parent := frm;
rgpOptions.Left := x;
rgpOptions.Top := y;
rgpOptions.Caption := 'New type';
rgpOptions.Items.Add('&Clothing');
rgpOptions.Items.Add('&Light');
rgpOptions.Items.Add('&Heavy');
rgpOptions.ItemIndex := 0;
btnExit := CreateButton(frm);
btnExit.Caption := '&Cancel';
btnExit.Cancel := true;
btnExit.ModalResult := mrCancel;
btnExit.Left := x - 85;
btnExit.Top := y + (4 * dy);
btnOk := CreateButton(frm);
btnOk.Caption := '&Ok';
btnOk.Default := true;
btnOk.ModalResult := mrOk;
btnOk.Left := btnExit.Left + btnExit.Width + 10;
btnOk.Top := btnExit.Top;
if frm.ShowModal <> mrOk then begin
Result := 1;
end
else begin
arType := rgpOptions.ItemIndex;
end;
finally
frm.Release;
end;
end;
function Initialize: Integer;
begin
Result := ShowForm;
if Result <> 0 then Exit;
end;
end.