-
Notifications
You must be signed in to change notification settings - Fork 2
/
Robot Mod - Import Stats.pas
141 lines (110 loc) · 4.48 KB
/
Robot Mod - Import Stats.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
{
Script to import modifications for robot from a spreadsheet. run on something within targetfile.
columns must be separated by , only. Lines can be commented out using // or ; in the first cell.
}
unit ImportRobotMods;
uses praUtil, robotModLib;
var
targetFile: IInterface;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
begin
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
begin
Result := 0;
// comment this out if you don't want those messages
// AddMessage('Processing: ' + FullPath(e));
if(not assigned(targetFile)) then begin
targetFile := GetFile(e);
doInit(targetFile);
end;
end;
function getNumFromLine(line: TStringList; index: integer): integer;
var
resStr: string;
resTest: integer;
begin
Result := 0;
if(line.count >= index) then begin
resStr := line[index];
if(resStr <> '') then begin
resTest := 0;
try
resTest := StrToInt(resStr);
Result := resTest;
except
// meh
end;
end;
end;
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
var
sourceFile, curLine, edid, desc: string;
csvLines, csvCols: TStringList;
i, strength, perception, endurance, intelligence, charisma, agility, luck: integer;
elem: IInterface;
begin
Result := 0;
sourceFile := ShowOpenFileDialog('Select Models file', 'CSV Files|*.csv|All Files|*.*');
if(sourceFile = '') then begin
AddMessage('No source file');
Result := 1;
exit;
end;
csvLines := TStringList.create;
csvLines.LoadFromFile(sourceFile);
for i:=1 to csvLines.count-1 do begin
curLine := trim(csvLines.Strings[i]);
if(curLine = '') then begin
continue;
end;
// legacy
if(strStartsWith(curLine, ';') or strStartsWith(curLine, '";')) then continue;
// new
if(strStartsWith(curLine, '//') or strStartsWith(curLine, '"//')) then continue;
csvCols := TStringList.create;
csvCols.Delimiter := ',';
csvCols.StrictDelimiter := TRUE;
csvCols.DelimitedText := curLine;
if(csvCols.count < 9) then begin
csvCols.free();
continue;
end;
edid := trim(csvCols[0]);
if(edid = '') then begin
csvCols.free();
continue;
end;
elem := FindObjectByEdid(edid);
if(not assigned(elem)) then begin
AddMessage('WARN: Failed to find object '+edid+', skipping');
csvCols.free();
continue;
end;
// elem := getWinningOverrideBefore(elem, targetFile);
strength := getNumFromLine(csvCols, 2);
perception := getNumFromLine(csvCols, 3);
endurance := getNumFromLine(csvCols, 4);
charisma := getNumFromLine(csvCols, 5);
intelligence := getNumFromLine(csvCols, 6);
agility := getNumFromLine(csvCols, 7);
luck := getNumFromLine(csvCols, 8);
desc := '';
if(csvCols.count > 9) then begin
desc := trim(csvCols[9]);
end;
AddMessage(curLine);
AddMessage('S+'+IntToStr(strength)+' P+'+IntToStr(perception)+' E+'+IntToStr(endurance)+' C+'+IntToStr(charisma)+' I+'+IntToStr(intelligence)+' A+'+IntToStr(agility)+' L+'+IntToStr(luck)+' desc: '+desc);
setStatsDesc(elem, strength, perception, endurance, charisma, intelligence, agility, luck, desc);
csvCols.free();
end;
csvLines.free();
Result := 0;
end;
end.