missing project/build files
[client-tools.git] / src / game / server / database / item_conversion / hotfix_1.sql
blob9677b9202c1ecd21070d2b7355e15628f9f4d33a
1 CREATE OR REPLACE PACKAGE  "HOTFIX_1" as
2         procedure StartItemConversion (rbs_to_use varchar2 default null, conversion_id number default 1);
3         procedure DoSingleObject (objectId number, conversion_id number default 1);
4 end;
7 CREATE OR REPLACE PACKAGE BODY  "HOTFIX_1" as
8         -- private type defs
9         type objVarType is record (
10                 object_id number := NULL,
11                 objvar_name varchar2(500) := NULL,
12                 objvar_type number := NULL,
13                 objvar_value varchar2(1000)  := NULL,
14                 objvar_name_id number := 0,
15                 old_objvar_name_id number := 0);
17         type objRowType is record (
18                 object_id number,
19                 object_template_id number,
20                 object_name varchar2(127), name_string_table varchar2(500), name_string_text varchar2(500),
21                 objvar_0_name varchar2(50), objvar_0_type number, objvar_0_value varchar2(50),
22                 objvar_1_name varchar2(50), objvar_1_type number, objvar_1_value varchar2(50),
23                 objvar_2_name varchar2(50), objvar_2_type number, objvar_2_value varchar2(50),
24                 objvar_3_name varchar2(50), objvar_3_type number, objvar_3_value varchar2(50),
25                 objvar_4_name varchar2(50), objvar_4_type number, objvar_4_value varchar2(50),
26                 objvar_5_name varchar2(50), objvar_5_type number, objvar_5_value varchar2(50),
27                 objvar_6_name varchar2(50), objvar_6_type number, objvar_6_value varchar2(50),
28                 objvar_7_name varchar2(50), objvar_7_type number, objvar_7_value varchar2(50),
29                 objvar_8_name varchar2(50), objvar_8_type number, objvar_8_value varchar2(50),
30                 objvar_9_name varchar2(50), objvar_9_type number, objvar_9_value varchar2(50),
31                 objvar_10_name varchar2(50), objvar_10_type number, objvar_10_value varchar2(50),
32                 objvar_11_name varchar2(50), objvar_11_type number, objvar_11_value varchar2(50),
33                 objvar_12_name varchar2(50), objvar_12_type number, objvar_12_value varchar2(50),
34                 objvar_13_name varchar2(50), objvar_13_type number, objvar_13_value varchar2(50),
35                 objvar_14_name varchar2(50), objvar_14_type number, objvar_14_value varchar2(50),
36                 objvar_15_name varchar2(50), objvar_15_type number, objvar_15_value varchar2(50),
37                 objvar_16_name varchar2(50), objvar_16_type number, objvar_16_value varchar2(50),
38                 objvar_17_name varchar2(50), objvar_17_type number, objvar_17_value varchar2(50),
39                 objvar_18_name varchar2(50), objvar_18_type number, objvar_18_value varchar2(50),
40                 objvar_19_name varchar2(50), objvar_19_type number, objvar_19_value varchar2(50),
41                 scriptlist  varchar2(2000));
43         type objVarRowType is record (
44                 object_id number,
45                 objvar_name_id number,
46                 objvar_name varchar2(500), 
47                 objvar_type number, 
48                 objvar_value varchar2(1000));
49                 
50         type weaponRowType is record (
51                 object_id number,
52                 min_damage number,
53                 max_damage number,
54                 attack_speed float,
55                 wound_chance float,
56                 accuracy number,
57                 attack_cost number,
58                 min_range float,
59                 max_range float,
60                 damage_type number,
61                 elemental_type number,
62                 elemental_value number);
63         
64         type manfSchematicRowType is record (
65                 object_id number,
66                 draft_schematic number);
67                 
68         type manfAttributeRowType is record (
69                 object_id number,
70                 attribute varchar2(500),
71                 value float);
73         type rangeType is varray(4) of number;
75         type rangeTableType is table of rangeType;
77         type numTable is table of number;
78         
79         type varcharTable is table of varchar2(500);
81         type numTableVarchar is table of number
82                 index by varchar2(500);
83                 
84         type varcharTableNum is table of varchar2(500)
85                 index by binary_integer;
87         type objectObjVarArray is varray(20) of objVarType;
89         type objVarTable is table of objVarType
90                 index by varchar2(500);
92         type dotObjVarTable is table of objVarType
93                 index by varchar2(10);
95         type dotArrayVarchar is table of dotObjVarTable
96                 index by varchar2(500);
98         type numTableNumber is table of number 
99                  index by binary_integer;
101         type dotsMatrixType is table of numTableNumber index by varchar2(50);
102         
103         type manfAttributesTable is table of manfAttributeRowType
104                 index by varchar2(500);
106         -- private global containers
107         use_rbs                 varchar2(50);
108         object_id       number;
109         free_slots      numTable;                               -- empty OBJECTS ObjVar columns
110         slot_map        numTableVarchar;                -- map from ObjVar name to OBJECTS slot
111         Obj_ObjVars     objectObjVarArray;              -- array of ObjVars in OBJECTS
112         OV_ObjVars      objVarTable;                    -- map by name of ObjVars in OBJECT_VARIABLES
113         dot_list        dotArrayVarchar;                -- map from extracted DoT name and class to ObjVar
114                                                                                         -- example: dot_list('actionShot1')('type')
115         isObjModified   boolean;                                -- tracks if any of the OBJECTS data has changed
116         updated_objvars varcharTable;                   -- list of updated ObjVar names in OBJECT_VARIABLES
117         deleted_objvars varcharTable;                   -- list of deleted ObjVar names in OBJECT_VARIABLES
118         added_objvars   varcharTable;                   -- list of added ObjVar names in OBJECT_VARIABLES
119         isSchematic     boolean;                                -- tracks if the object has MANF_SCHEMATIC_OBJECTS data
120         isFactory       boolean;
121         script_list     varchar2(2000);
122         object_name     varchar2(127);
123         name_table      varchar2(500);
124         name_text       varchar2(500);
125         template_id     number;
126         new_template_id number;
127         new_schematic_id number;
128         err_num                 number;
129         
130         -- private lookup tables
131         templateIdSet   numTableNumber;                 -- set of template ids to be converted
132         objvarNameIdMap numTableVarchar;                -- map from ObjVar name to OBJECT_VARIABLES_NAMES ID
133         schematic_map   numTableNumber;                 -- map of schematic to created template
134         templateNameTable varcharTableNum;              -- map of new template ids to string_name_table
135         templateNameText  varcharTableNum;              -- map of new template ids to string_name_text
136         
137         
138         -- private constants
139         blankObjVar     objVarType;                             -- can't use CONSTANT properly with records :(
140         
141         -- private function declaration
142         procedure DoItemConversionBatch(start_objectid number, end_objectid number, conversion_id number);
143         function InitializeData return boolean;
144         
145         procedure AddObjVar (objvar_name varchar2, objvar_type number, objvar_value varchar2);
146         procedure DeleteObjVar (objVarName in varchar2);
147         procedure ModifyObjVar (oldObjVarName varchar2, objvar_name varchar2, objvar_type number, objvar_value varchar2);
148         procedure ModifyObjVar (oldObjVarName varchar2, objvar_name varchar2, objvar_type number, rangeTable rangeTableType);
149         procedure RenameObjVar (oldObjVarName varchar2, objvar_name varchar2);
150         function GetObjVarValue (objvar_name varchar2) return varchar2;
151         procedure AddScript (newScript varchar2);
152         procedure RemoveScript (oldScript varchar2);
153         procedure SetNewTemplateId (newTemplateId number);
154         procedure SetTemplateText (newTemplateId number);
155         procedure InvalidateSchematic;
157         procedure SetGenProtection(rangeTable rangeTableType);
158         procedure SetArmorCondLevelCat(condition varchar2, lev varchar2, category varchar2);
159         procedure SetArmorLevel(lev varchar);
160         procedure SetArmorCategory(category varchar2);
161         procedure SetGpAndCond(gp_name varchar2, gp_val varchar2, cond_name varchar2, cond_val varchar2);
162         
163         procedure DeleteCraftingComponents;
164         
165         function ConvertValue (oldvalue number, rangeTable rangeTableType) return number;
167         function SchematicMap(schematic_id number)
168                 return number;
170         -- public function definitions
171         procedure StartItemConversion (rbs_to_use varchar2, conversion_id number)
172         is
173                 maxObjectId number;
174                 startObjectId number := 0;
175                 starttime date := sysdate;
176         begin
177                 use_rbs := rbs_to_use;
178                 if use_rbs is not null then
179                         execute immediate 'set transaction use rollback segment ' || use_rbs;
180                 end if;
181                 if (InitializeData) then
182                         -- loop through all objects in batches
183                         select max(object_id) into maxObjectId from objects;
184                         while startObjectId < maxObjectId loop
185                                 dbms_output.put_line('starting batch: ' || startObjectId || ' time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
186                                 DoItemConversionBatch(startObjectId, startObjectId + 19999999999, conversion_id);
187                                 commit;
188                                 if use_rbs is not null then
189                                         execute immediate 'set transaction use rollback segment ' || use_rbs;
190                                 end if;
191                                 startObjectId := startObjectId + 20000000000;
192                         end loop;
193                 end if;
194                 dbms_output.put_line('start time = ' || to_char(starttime, 'MM/DD/YY HH24:MI:SS'));
195                 dbms_output.put_line('final time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
196                 dbms_output.put_line('total time = ' || to_char(trunc((sysdate - starttime)*24*60)) || ' mins');
197         exception
198                 when others then
199                         err_num := SQLCODE;
200                         dbms_output.put_line('Error in StartItemConversion - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
201                         db_error_logger.dblogerror(err_num, 'Error in StartItemConversion');
202         end;
204         procedure DoSingleObject (objectId number, conversion_id number)
205         is
206         begin
207                 if (InitializeData) then
208                         DoItemConversionBatch(objectId, objectId, conversion_id);
209                 end if;
210         exception
211                 when others then
212                         err_num := SQLCODE;
213                         dbms_output.put_line('Error in DoSingleObject - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
214                         db_error_logger.dblogerror(err_num, 'Error in ObjVarUpdates');
215         end;
217         -- private function definitions
218         procedure DoItemConversionBatch(start_objectid number, end_objectid number, conversion_id number)
219         is
220                 -- cursors
221                 objRow objRowType;
222                 cursor objCursor (start_id number, end_id number) is
223                 select
224                         o.object_id,
225                         o.object_template_id,
226                         o.object_name, o.name_string_table, o.name_string_text,
227                         o.objvar_0_name, o.objvar_0_type, o.objvar_0_value,
228                         o.objvar_1_name, o.objvar_1_type, o.objvar_1_value,
229                         o.objvar_2_name, o.objvar_2_type, o.objvar_2_value,
230                         o.objvar_3_name, o.objvar_3_type, o.objvar_3_value,
231                         o.objvar_4_name, o.objvar_4_type, o.objvar_4_value,
232                         o.objvar_5_name, o.objvar_5_type, o.objvar_5_value,
233                         o.objvar_6_name, o.objvar_6_type, o.objvar_6_value,
234                         o.objvar_7_name, o.objvar_7_type, o.objvar_7_value,
235                         o.objvar_8_name, o.objvar_8_type, o.objvar_8_value,
236                         o.objvar_9_name, o.objvar_9_type, o.objvar_9_value,
237                         o.objvar_10_name, o.objvar_10_type, o.objvar_10_value,
238                         o.objvar_11_name, o.objvar_11_type, o.objvar_11_value,
239                         o.objvar_12_name, o.objvar_12_type, o.objvar_12_value,
240                         o.objvar_13_name, o.objvar_13_type, o.objvar_13_value,
241                         o.objvar_14_name, o.objvar_14_type, o.objvar_14_value,
242                         o.objvar_15_name, o.objvar_15_type, o.objvar_15_value,
243                         o.objvar_16_name, o.objvar_16_type, o.objvar_16_value,
244                         o.objvar_17_name, o.objvar_17_type, o.objvar_17_value,
245                         o.objvar_18_name, o.objvar_18_type, o.objvar_18_value,
246                         o.objvar_19_name, o.objvar_19_type, o.objvar_19_value,
247                         script_list
248                 from objects o
249                 where object_id between start_id and end_id
250                 and object_template_id in (-448030425, 1838042928, 2082588198, 1741906969, 1120303977, -1207917085)
251                 order by object_id;
253                 objVarRow objVarRowType;
254                 cursor objVarCursor (start_id number, end_id number) is
255                 select
256                         v.object_id,
257                         v.name_id,
258                         nvl(n.name, to_char(n.id)),
259                         v.type,
260                         v.value
261                 from object_variables v, object_variable_names n
262                 where v.object_id between start_id and end_id
263                         and nvl(v.detached,0) = 0
264                         and v.name_id = n.id
265                 order by v.object_id;
267                 -- local variables
268                 i          number;
269                 n          number;
270                 idx        number := 0;
271                 cnt        number := 0;
272                 cvt        number := 0;
273                 bool       boolean;
274                 tempObjVar objVarType;
275                 stmt       varchar2(4000);
276                 prefix     varchar2(100);
277         begin
278                 dbms_output.put_line('start time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
279                 open objCursor (start_objectid, end_objectid);
280                 fetch objCursor into objRow;
281                 dbms_output.put_line('object cursor time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
282                 open objVarCursor (start_objectid, end_objectid);
283                 fetch objVarCursor into objVarRow;
284                 dbms_output.put_line('objvar cursor time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
286                 while objCursor%found loop
287                         begin
288                                 -- Clear Data
289                                 free_slots.delete;
290                                 free_slots := numTable(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
291                                 slot_map.delete;
292                                 for i in 1..20 loop
293                                         Obj_ObjVars(i) := blankObjVar;
294                                 end loop;
295                                 OV_ObjVars.delete;
296                                 updated_objvars.trim(updated_objvars.count);
297                                 deleted_objvars.trim(deleted_objvars.count);
298                                 added_objvars.trim(added_objvars.count);
299                                 isObjModified := FALSE;
300                                 isSchematic := FALSE;
301                                 isFactory := FALSE;
302                                 prefix := 'crafting_components.';
303                                 new_schematic_id := 0;
304                                 
305                                 -- Load the data into variables
306                                 object_id := objRow.object_id;
307                                 script_list := objRow.scriptList;
308                                 object_name := objRow.object_name;
309                                 name_table := objRow.name_string_table;
310                                 name_text := objRow.name_string_text;
311                                 template_id := objRow.object_template_id;
312                                 new_template_id := template_id;
314                                 Obj_ObjVars(1).object_id := objRow.object_id;    -- might be able to eliminate
315                                 Obj_ObjVars(1).objvar_name := objRow.objvar_0_name;
316                                 Obj_ObjVars(1).objvar_type := objRow.objvar_0_type;
317                                 Obj_ObjVars(1).objvar_value := objRow.objvar_0_value;
318                                 if ((objRow.objvar_0_name is not null) and (objRow.objvar_0_type != -1))then
319                                         slot_map(objRow.objvar_0_name) := 1;
320                                         free_slots.delete(1);
321                                 end if;
323                                 Obj_ObjVars(2).object_id := objRow.object_id;
324                                 Obj_ObjVars(2).objvar_name := objRow.objvar_1_name;
325                                 Obj_ObjVars(2).objvar_type := objRow.objvar_1_type;
326                                 Obj_ObjVars(2).objvar_value := objRow.objvar_1_value;
327                                 if ((objRow.objvar_1_name is not null) and (objRow.objvar_1_type != -1))then
328                                         slot_map(objRow.objvar_1_name) := 2;
329                                         free_slots.delete(2);
330                                 end if;
332                                 Obj_ObjVars(3).object_id := objRow.object_id;
333                                 Obj_ObjVars(3).objvar_name := objRow.objvar_2_name;
334                                 Obj_ObjVars(3).objvar_type := objRow.objvar_2_type;
335                                 Obj_ObjVars(3).objvar_value := objRow.objvar_2_value;
336                                 if ((objRow.objvar_2_name is not null) and (objRow.objvar_2_type != -1))then
337                                         slot_map(objRow.objvar_2_name) := 3;
338                                         free_slots.delete(3);
339                                 end if;
341                                 Obj_ObjVars(4).object_id := objRow.object_id;
342                                 Obj_ObjVars(4).objvar_name := objRow.objvar_3_name;
343                                 Obj_ObjVars(4).objvar_type := objRow.objvar_3_type;
344                                 Obj_ObjVars(4).objvar_value := objRow.objvar_3_value;
345                                 if ((objRow.objvar_3_name is not null) and (objRow.objvar_3_type != -1))then
346                                         slot_map(objRow.objvar_3_name) := 4;
347                                         free_slots.delete(4);
348                                 end if;
350                                 Obj_ObjVars(5).object_id := objRow.object_id;
351                                 Obj_ObjVars(5).objvar_name := objRow.objvar_4_name;
352                                 Obj_ObjVars(5).objvar_type := objRow.objvar_4_type;
353                                 Obj_ObjVars(5).objvar_value := objRow.objvar_4_value;
354                                 if ((objRow.objvar_4_name is not null) and (objRow.objvar_4_type != -1))then
355                                         slot_map(objRow.objvar_4_name) := 5;
356                                         free_slots.delete(5);
357                                 end if;
359                                 Obj_ObjVars(6).object_id := objRow.object_id;
360                                 Obj_ObjVars(6).objvar_name := objRow.objvar_5_name;
361                                 Obj_ObjVars(6).objvar_type := objRow.objvar_5_type;
362                                 Obj_ObjVars(6).objvar_value := objRow.objvar_5_value;
363                                 if ((objRow.objvar_5_name is not null) and (objRow.objvar_5_type != -1))then
364                                         slot_map(objRow.objvar_5_name) := 6;
365                                         free_slots.delete(6);
366                                 end if;
368                                 Obj_ObjVars(7).object_id := objRow.object_id;
369                                 Obj_ObjVars(7).objvar_name := objRow.objvar_6_name;
370                                 Obj_ObjVars(7).objvar_type := objRow.objvar_6_type;
371                                 Obj_ObjVars(7).objvar_value := objRow.objvar_6_value;
372                                 if ((objRow.objvar_6_name is not null) and (objRow.objvar_6_type != -1))then
373                                         slot_map(objRow.objvar_6_name) := 7;
374                                         free_slots.delete(7);
375                                 end if;
377                                 Obj_ObjVars(8).object_id := objRow.object_id;
378                                 Obj_ObjVars(8).objvar_name := objRow.objvar_7_name;
379                                 Obj_ObjVars(8).objvar_type := objRow.objvar_7_type;
380                                 Obj_ObjVars(8).objvar_value := objRow.objvar_7_value;
381                                 if ((objRow.objvar_7_name is not null) and (objRow.objvar_7_type != -1))then
382                                         slot_map(objRow.objvar_7_name) := 8;
383                                         free_slots.delete(8);
384                                 end if;
386                                 Obj_ObjVars(9).object_id := objRow.object_id;
387                                 Obj_ObjVars(9).objvar_name := objRow.objvar_8_name;
388                                 Obj_ObjVars(9).objvar_type := objRow.objvar_8_type;
389                                 Obj_ObjVars(9).objvar_value := objRow.objvar_8_value;
390                                 if ((objRow.objvar_8_name is not null) and (objRow.objvar_8_type != -1))then
391                                         slot_map(objRow.objvar_8_name) := 9;
392                                         free_slots.delete(9);
393                                 end if;
395                                 Obj_ObjVars(10).object_id := objRow.object_id;
396                                 Obj_ObjVars(10).objvar_name := objRow.objvar_9_name;
397                                 Obj_ObjVars(10).objvar_type := objRow.objvar_9_type;
398                                 Obj_ObjVars(10).objvar_value := objRow.objvar_9_value;
399                                 if ((objRow.objvar_9_name is not null) and (objRow.objvar_9_type != -1))then
400                                         slot_map(objRow.objvar_9_name) := 10;
401                                         free_slots.delete(10);
402                                 end if;
404                                 Obj_ObjVars(11).object_id := objRow.object_id;
405                                 Obj_ObjVars(11).objvar_name := objRow.objvar_10_name;
406                                 Obj_ObjVars(11).objvar_type := objRow.objvar_10_type;
407                                 Obj_ObjVars(11).objvar_value := objRow.objvar_10_value;
408                                 if ((objRow.objvar_10_name is not null) and (objRow.objvar_10_type != -1))then
409                                         slot_map(objRow.objvar_10_name) := 11;
410                                         free_slots.delete(11);
411                                 end if;
413                                 Obj_ObjVars(12).object_id := objRow.object_id;
414                                 Obj_ObjVars(12).objvar_name := objRow.objvar_11_name;
415                                 Obj_ObjVars(12).objvar_type := objRow.objvar_11_type;
416                                 Obj_ObjVars(12).objvar_value := objRow.objvar_11_value;
417                                 if ((objRow.objvar_11_name is not null) and (objRow.objvar_11_type != -1))then
418                                         slot_map(objRow.objvar_11_name) := 12;
419                                         free_slots.delete(12);
420                                 end if;
422                                 Obj_ObjVars(13).object_id := objRow.object_id;
423                                 Obj_ObjVars(13).objvar_name := objRow.objvar_12_name;
424                                 Obj_ObjVars(13).objvar_type := objRow.objvar_12_type;
425                                 Obj_ObjVars(13).objvar_value := objRow.objvar_12_value;
426                                 if ((objRow.objvar_12_name is not null) and (objRow.objvar_12_type != -1))then
427                                         slot_map(objRow.objvar_12_name) := 13;
428                                         free_slots.delete(13);
429                                 end if;
431                                 Obj_ObjVars(14).object_id := objRow.object_id;
432                                 Obj_ObjVars(14).objvar_name := objRow.objvar_13_name;
433                                 Obj_ObjVars(14).objvar_type := objRow.objvar_13_type;
434                                 Obj_ObjVars(14).objvar_value := objRow.objvar_13_value;
435                                 if ((objRow.objvar_13_name is not null) and (objRow.objvar_13_type != -1))then
436                                         slot_map(objRow.objvar_13_name) := 14;
437                                         free_slots.delete(14);
438                                 end if;
440                                 Obj_ObjVars(15).object_id := objRow.object_id;
441                                 Obj_ObjVars(15).objvar_name := objRow.objvar_14_name;
442                                 Obj_ObjVars(15).objvar_type := objRow.objvar_14_type;
443                                 Obj_ObjVars(15).objvar_value := objRow.objvar_14_value;
444                                 if ((objRow.objvar_14_name is not null) and (objRow.objvar_14_type != -1))then
445                                         slot_map(objRow.objvar_14_name) := 15;
446                                         free_slots.delete(15);
447                                 end if;
449                                 Obj_ObjVars(16).object_id := objRow.object_id;
450                                 Obj_ObjVars(16).objvar_name := objRow.objvar_15_name;
451                                 Obj_ObjVars(16).objvar_type := objRow.objvar_15_type;
452                                 Obj_ObjVars(16).objvar_value := objRow.objvar_15_value;
453                                 if ((objRow.objvar_15_name is not null) and (objRow.objvar_15_type != -1))then
454                                         slot_map(objRow.objvar_15_name) := 16;
455                                         free_slots.delete(16);
456                                 end if;
458                                 Obj_ObjVars(17).object_id := objRow.object_id;
459                                 Obj_ObjVars(17).objvar_name := objRow.objvar_16_name;
460                                 Obj_ObjVars(17).objvar_type := objRow.objvar_16_type;
461                                 Obj_ObjVars(17).objvar_value := objRow.objvar_16_value;
462                                 if ((objRow.objvar_16_name is not null) and (objRow.objvar_16_type != -1))then
463                                         slot_map(objRow.objvar_16_name) := 17;
464                                         free_slots.delete(17);
465                                 end if;
467                                 Obj_ObjVars(18).object_id := objRow.object_id;
468                                 Obj_ObjVars(18).objvar_name := objRow.objvar_17_name;
469                                 Obj_ObjVars(18).objvar_type := objRow.objvar_17_type;
470                                 Obj_ObjVars(18).objvar_value := objRow.objvar_17_value;
471                                 if ((objRow.objvar_17_name is not null) and (objRow.objvar_17_type != -1))then
472                                         slot_map(objRow.objvar_17_name) := 18;
473                                         free_slots.delete(18);
474                                 end if;
476                                 Obj_ObjVars(19).object_id := objRow.object_id;
477                                 Obj_ObjVars(19).objvar_name := objRow.objvar_18_name;
478                                 Obj_ObjVars(19).objvar_type := objRow.objvar_18_type;
479                                 Obj_ObjVars(19).objvar_value := objRow.objvar_18_value;
480                                 if ((objRow.objvar_18_name is not null) and (objRow.objvar_18_type != -1))then
481                                         slot_map(objRow.objvar_18_name) := 19;
482                                         free_slots.delete(19);
483                                 end if;
485                                 Obj_ObjVars(20).object_id := objRow.object_id;
486                                 Obj_ObjVars(20).objvar_name := objRow.objvar_19_name;
487                                 Obj_ObjVars(20).objvar_type := objRow.objvar_19_type;
488                                 Obj_ObjVars(20).objvar_value := objRow.objvar_19_value;
489                                 if ((objRow.objvar_19_name is not null) and (objRow.objvar_19_type != -1))then
490                                         slot_map(objRow.objvar_19_name) := 20;
491                                         free_slots.delete(20);
492                                 end if;
495                                 while (objVarCursor%found and objVarRow.object_id <= objRow.object_id) loop
496                                         if objVarRow.object_id = objRow.object_id then
497                                                 tempObjVar := blankObjVar;
498                                                 tempObjVar.object_id := objVarRow.object_id;
499                                                 tempObjVar.objvar_name := objVarRow.objvar_name;
500                                                 tempObjVar.objvar_type := objVarRow.objvar_type;
501                                                 tempObjVar.objvar_value := objVarRow.objvar_value;
502                                                 tempObjVar.objvar_name_id := objVarRow.objvar_name_id;
503                                                 OV_ObjVars(objVarRow.objvar_name) := tempObjVar;
504                                                 slot_map(objVarRow.objvar_name) := 21;
505                                         end if;
506                                         fetch objVarCursor into objVarRow;
507                                 end loop;
509                                 -- check to see if it a weapon (162889564) or armor (1120303977) factory crate
510                                 -- or food (-200781577) or chemicals (-1966544754)
511                                 -- or electronics (-754298423) or clothing (-1207917085)
512                                 if template_id = 162889564 or template_id = 1120303977 
513                                                 or template_id = -200781577 or template_id = -1966544754 
514                                                 or template_id = -754298423 or template_id = -1207917085 then
515                                         if slot_map.exists('draftSchematic') then
516                                                 if slot_map('draftSchematic') < 21 then
517                                                         template_id := SchematicMap(to_number(Obj_ObjVars(slot_map('draftSchematic')).objvar_value));
518                                                 else
519                                                         template_id := SchematicMap(to_number(OV_ObjVars('draftSchematic').objvar_value));
520                                                 end if;
521                                                 isFactory := TRUE;
522                                                 prefix := 'crafting_attributes.crafting:';
523                                                 DeleteObjVar('ingr.*');
524                                         end if;
525                                 end if;
527                                 -- Do the conversions
528                                 if template_id = -448030425 then
529                                         SetGpAndCond(prefix || 'general_protection', '0.3', prefix || 'condition', '0.2');
530                                         if isFactory = TRUE then
531                                                 ModifyObjVar('draftSchematic','draftSchematic',0,1861772866);
532                                                 AddScript('systems.crafting.armor.component.crafting_new_armor_segment');
533                                         else
534                                                 SetNewTemplateId(1594162622);           --object/tangible/component/armor/armor_segment_recon.iff
535                                                 RemoveScript('systems.crafting.armor.component.crafting_armor_component_attribute');
536                                                 RemoveScript('item.armor.new_armor');  -- to prevent two copies of same script
537                                                 AddScript('item.armor.new_armor');
538                                         end if;
539                                 elsif template_id = 1838042928 then
540                                         RenameObjVar(prefix || 'armor_general_protection',prefix || 'general_protection');
541                                         RenameObjVar(prefix || 'armor_condition',prefix || 'condition');
542                                         if isFactory = FALSE then
543                                                 SetNewTemplateId(-1438161694);          --object/tangible/component/armor/armor_segment_battle.iff
544                                         end if;
545                                 elsif template_id = 2082588198 then
546                                         RenameObjVar(prefix || 'armor_general_protection',prefix || 'general_protection');
547                                         RenameObjVar(prefix || 'armor_condition',prefix || 'condition');
548                                         if isFactory = FALSE then
549                                                 SetNewTemplateId(2042493214);           --object/tangible/component/armor/armor_segment_assault.iff
550                                         end if;
551                                 elsif template_id = 1741906969 then
552                                         RenameObjVar(prefix || 'armor_general_protection',prefix || 'general_protection');
553                                         RenameObjVar(prefix || 'armor_condition',prefix || 'condition');
554                                         if isFactory = FALSE then
555                                                 SetNewTemplateId(1594162622);           --object/tangible/component/armor/armor_segment_recon.iff
556                                         end if;
557                                 end if;
558                                 -- Save the changes
559                                 if isObjModified = TRUE then
560                                         begin
561                                                 stmt := 'update objects set '
562                                                         || 'objvar_0_name = :o0n, objvar_0_type = :o0t, objvar_0_value = :o0v, '
563                                                         || 'objvar_1_name = :o1n, objvar_1_type = :o1t, objvar_1_value = :o1v, '
564                                                         || 'objvar_2_name = :o2n, objvar_2_type = :o2t, objvar_2_value = :o2v, '
565                                                         || 'objvar_3_name = :o3n, objvar_3_type = :o3t, objvar_3_value = :o3v, '
566                                                         || 'objvar_4_name = :o4n, objvar_4_type = :o4t, objvar_4_value = :o4v, '
567                                                         || 'objvar_5_name = :o5n, objvar_5_type = :o5t, objvar_5_value = :o5v, '
568                                                         || 'objvar_6_name = :o6n, objvar_6_type = :o6t, objvar_6_value = :o6v, '
569                                                         || 'objvar_7_name = :o7n, objvar_7_type = :o7t, objvar_7_value = :o7v, '
570                                                         || 'objvar_8_name = :o8n, objvar_8_type = :o8t, objvar_8_value = :o8v, '
571                                                         || 'objvar_9_name = :o9n, objvar_9_type = :o9t, objvar_9_value = :o9v, '
572                                                         || 'objvar_10_name = :o10n, objvar_10_type = :o10t, objvar_10_value = :o10v, '
573                                                         || 'objvar_11_name = :o11n, objvar_11_type = :o11t, objvar_11_value = :o11v, '
574                                                         || 'objvar_12_name = :o12n, objvar_12_type = :o12t, objvar_12_value = :o12v, '
575                                                         || 'objvar_13_name = :o13n, objvar_13_type = :o13t, objvar_13_value = :o13v, '
576                                                         || 'objvar_14_name = :o14n, objvar_14_type = :o14t, objvar_14_value = :o14v, '
577                                                         || 'objvar_15_name = :o15n, objvar_15_type = :o15t, objvar_15_value = :o15v, '
578                                                         || 'objvar_16_name = :o16n, objvar_16_type = :o16t, objvar_16_value = :o16v, '
579                                                         || 'objvar_17_name = :o17n, objvar_17_type = :o17t, objvar_17_value = :o17v, '
580                                                         || 'objvar_18_name = :o18n, objvar_18_type = :o18t, objvar_18_value = :o18v, '
581                                                         || 'objvar_19_name = :o19n, objvar_19_type = :o19t, objvar_19_value = :o19v, '
582                                                         || 'script_list = :sl, object_template_id = :otid, '
583                                                         || 'object_name = :obn, name_string_table = :nstb, name_string_text = :nstx, '
584                                                         || 'conversion_id = :version '
585                                                         || 'where object_id = :id';
587                                                 execute immediate stmt using
588                                                         Obj_ObjVars(1).objvar_name, Obj_ObjVars(1).objvar_type, Obj_ObjVars(1).objvar_value,
589                                                         Obj_ObjVars(2).objvar_name, Obj_ObjVars(2).objvar_type, Obj_ObjVars(2).objvar_value,
590                                                         Obj_ObjVars(3).objvar_name, Obj_ObjVars(3).objvar_type, Obj_ObjVars(3).objvar_value,
591                                                         Obj_ObjVars(4).objvar_name, Obj_ObjVars(4).objvar_type, Obj_ObjVars(4).objvar_value,
592                                                         Obj_ObjVars(5).objvar_name, Obj_ObjVars(5).objvar_type, Obj_ObjVars(5).objvar_value,
593                                                         Obj_ObjVars(6).objvar_name, Obj_ObjVars(6).objvar_type, Obj_ObjVars(6).objvar_value,
594                                                         Obj_ObjVars(7).objvar_name, Obj_ObjVars(7).objvar_type, Obj_ObjVars(7).objvar_value,
595                                                         Obj_ObjVars(8).objvar_name, Obj_ObjVars(8).objvar_type, Obj_ObjVars(8).objvar_value,
596                                                         Obj_ObjVars(9).objvar_name, Obj_ObjVars(9).objvar_type, Obj_ObjVars(9).objvar_value,
597                                                         Obj_ObjVars(10).objvar_name, Obj_ObjVars(10).objvar_type, Obj_ObjVars(10).objvar_value,
598                                                         Obj_ObjVars(11).objvar_name, Obj_ObjVars(11).objvar_type, Obj_ObjVars(11).objvar_value,
599                                                         Obj_ObjVars(12).objvar_name, Obj_ObjVars(12).objvar_type, Obj_ObjVars(12).objvar_value,
600                                                         Obj_ObjVars(13).objvar_name, Obj_ObjVars(13).objvar_type, Obj_ObjVars(13).objvar_value,
601                                                         Obj_ObjVars(14).objvar_name, Obj_ObjVars(14).objvar_type, Obj_ObjVars(14).objvar_value,
602                                                         Obj_ObjVars(15).objvar_name, Obj_ObjVars(15).objvar_type, Obj_ObjVars(15).objvar_value,
603                                                         Obj_ObjVars(16).objvar_name, Obj_ObjVars(16).objvar_type, Obj_ObjVars(16).objvar_value,
604                                                         Obj_ObjVars(17).objvar_name, Obj_ObjVars(17).objvar_type, Obj_ObjVars(17).objvar_value,
605                                                         Obj_ObjVars(18).objvar_name, Obj_ObjVars(18).objvar_type, Obj_ObjVars(18).objvar_value,
606                                                         Obj_ObjVars(19).objvar_name, Obj_ObjVars(19).objvar_type, Obj_ObjVars(19).objvar_value,
607                                                         Obj_ObjVars(20).objvar_name, Obj_ObjVars(20).objvar_type, Obj_ObjVars(20).objvar_value,
608                                                         script_list, new_template_id,
609                                                         object_name, name_table, name_text,
610                                                         conversion_id,
611                                                         object_id;
612                                         exception
613                                                 when others then
614                                                         err_num := SQLCODE;
615                                                         dbms_output.put_line('Error in object update(' || object_id || ') - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
616                                                         db_error_logger.dblogerror(err_num, 'Error in object update');
617                                         end;
618                                 end if;
620                                 i := deleted_objvars.first;
621                                 while i is not null loop
622                                         begin
623                                                 stmt := 'delete from object_variables '
624                                                         || 'where object_id = :id and name_id = :oldname';
626                                                 execute immediate stmt using
627                                                         object_id,
628                                                         OV_ObjVars(deleted_objvars(i)).old_objvar_name_id;
630                                                 i := deleted_objvars.next(i);
631                                         exception
632                                                 when others then
633                                                         err_num := SQLCODE;
634                                                         dbms_output.put_line('Error (' || SQLERRM(err_num) || ') with deleted_objvars(' || object_id || ') - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
635                                                         db_error_logger.dblogerror(err_num, 'Error with deleted_objvars');
636                                                         i := deleted_objvars.next(i);
637                                         end;
638                                 end loop;
640                                 i := added_objvars.first;
641                                 while i is not null loop
642                                         begin
643                                                 stmt := 'insert into object_variables values '
644                                                         || '(:id, :name, :type, :value, 0)';
646                                                 execute immediate stmt using
647                                                         object_id,
648                                                         OV_ObjVars(added_objvars(i)).objvar_name_id,
649                                                         OV_ObjVars(added_objvars(i)).objvar_type,
650                                                         OV_ObjVars(added_objvars(i)).objvar_value;
652                                                 i := added_objvars.next(i);
653                                         exception
654                                                 when others then
655                                                         err_num := SQLCODE;
656                                                         dbms_output.put_line('Error (' || SQLERRM(err_num) || ') with added_objvars(' || object_id || ') - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
657                                                         db_error_logger.dblogerror(err_num, 'Error with added_objvars');
658                                                 i := added_objvars.next(i);
659                                         end;
660                                 end loop;
662                                 i := updated_objvars.first;
663                                 while i is not null loop
664                                         begin
665                                                 stmt := 'update object_variables set '
666                                                         || 'name_id = :name, type = :type, value = :value '
667                                                         || 'where object_id = :id and name_id = :oldname';
669                                                 execute immediate stmt using
670                                                         objvarNameIdMap(OV_ObjVars(updated_objvars(i)).objvar_name),
671                                                         OV_ObjVars(updated_objvars(i)).objvar_type,
672                                                         OV_ObjVars(updated_objvars(i)).objvar_value,
673                                                         object_id,
674                                                         OV_ObjVars(updated_objvars(i)).old_objvar_name_id;
676                                                 i := updated_objvars.next(i);
677                                         exception
678                                                 when others then
679                                                         err_num := SQLCODE;
680                                                         dbms_output.put_line('Error (' || SQLERRM(err_num) || ') with updated_objvars(' || object_id || ') - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
681                                                         db_error_logger.dblogerror(err_num, 'Error with updated_objvars');
682                                                         i := updated_objvars.next(i);
683                                         end;
684                                 end loop;
686                                 cvt := cvt + 1;
687                                 idx := idx + 1;
688                                 -- commit every 100,000 records
689                                 if idx > 99999 then
690                                         commit;
691                                         if use_rbs is not null then
692                                                 execute immediate 'set transaction use rollback segment ' || use_rbs;
693                                         end if;
694                                         dbms_output.put_line('100,000 rows = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
695                                         cnt := cnt + idx;
696                                         idx := 0;
697                                 end if;                                 
698                         end;
699                         fetch objCursor into objRow;
700                 end loop;
701                 --commit;
702                 close objVarCursor;
703                 close objCursor;
704                 cnt := cnt + idx;
705                 dbms_output.put_line('end time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
706                 dbms_output.put_line('converted = ' || to_char(cvt));
707                 dbms_output.put_line('total count = ' || to_char(cnt));
708         exception
709                 when others then
710                         err_num := SQLCODE;
711                         dbms_output.put_line('Error (' || SQLERRM(err_num) || ') in DoItemConversionBatch (' || object_id || ') - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
712                         db_error_logger.dblogerror(err_num, 'Error in DoItemConversionBatch');
713         end;
715         function InitializeData return boolean
716         is
717                 objvarNameIdRow object_variable_names%rowtype;
718                 -- ALL added/updated objvar names MUST be in this list
719                 cursor objvarNameIdCursor is
720                 select id, name from object_variable_names
721                 where name in (
722                         'armor.armorCategory',
723                         'armor.armorLevel',
724                         'armor.armorencumbrance',
725                         'armor.condition',
726                         'armor.effectiveness',
727                         'armor.encumbrance',
728                         'armor.encumbranceSplit',
729                         'armor.general_protection',
730                         'armor.layer0',
731                         'armor.layer13',
732                         'armor.layer14',
733                         'armor.layer15',
734                         'armor.mandDeconstruct',
735                         'armor.rating',
736                         'armor.recharge_rate',
737                         'armor.risDeconstruct',
738                         'armor.special.1',
739                         'armor.special.1024',
740                         'armor.special.128',
741                         'armor.special.16',
742                         'armor.special.2',
743                         'armor.special.2048',
744                         'armor.special.256',
745                         'armor.special.32',
746                         'armor.special.4',
747                         'armor.special.4096',
748                         'armor.special.512',
749                         'armor.special.64',
750                         'armor.special.8',
751                         'armor.vulnerability',
752                         'armorCategory',
753                         'armorLevel',
754                         'biolink.faction_points',
755                         'blindChance',
756                         'blindDuration',
757                         'buff_name',
758                         'burnDuration',
759                         'burnIntensity',
760                         'crafting_attributes.crafting:accuracy',
761                         'crafting_attributes.crafting:armor_condition',
762                         'crafting_attributes.crafting:armor_general_protection',
763                         'crafting_attributes.crafting:armor_layer0',
764                         'crafting_attributes.crafting:armor_layer1',
765                         'crafting_attributes.crafting:armor_layer2',
766                         'crafting_attributes.crafting:armor_layer4',
767                         'crafting_attributes.crafting:armor_layer5',
768                         'crafting_attributes.crafting:armor_layer6',
769                         'crafting_attributes.crafting:armor_layer7',
770                         'crafting_attributes.crafting:armor_layer12',
771                         'crafting_attributes.crafting:attackActionCost',
772                         'crafting_attributes.crafting:attackCost',
773                         'crafting_attributes.crafting:attackHealthCost',
774                         'crafting_attributes.crafting:attackMindCost',
775                         'crafting_attributes.crafting:attackSpeed',
776                         'crafting_attributes.crafting:condition',
777                         'crafting_attributes.crafting:damageType',
778                         'crafting_attributes.crafting:effect',
779                         'crafting_attributes.crafting:efficiency',
780                         'crafting_attributes.crafting:elementalType',
781                         'crafting_attributes.crafting:elementalValue',
782                         'crafting_attributes.crafting:flavor',
783                         'crafting_attributes.crafting:general_protection',
784                         'crafting_attributes.crafting:hitPoints',
785                         'crafting_attributes.crafting:maxDamage',
786                         'crafting_attributes.crafting:maxRange',
787                         'crafting_attributes.crafting:maxRangeMod',
788                         'crafting_attributes.crafting:midRange',
789                         'crafting_attributes.crafting:midRangeMod',
790                         'crafting_attributes.crafting:minDamage',
791                         'crafting_attributes.crafting:minRange',
792                         'crafting_attributes.crafting:minRangeMod',
793                         'crafting_attributes.crafting:nutrition',
794                         'crafting_attributes.crafting:power',
795                         'crafting_attributes.crafting:woundChance',
796                         'crafting_attributes.crafting:zeroRangeMod',
797                         'crafting_components.accuracy',
798                         'crafting_components.armor_armorencumbrance',
799                         'crafting_components.armor_condition',
800                         'crafting_components.armor_general_protection',
801                         'crafting_components.armor_layer0',
802                         'crafting_components.armor_layer1',
803                         'crafting_components.armor_layer2',
804                         'crafting_components.armor_layer4',
805                         'crafting_components.armor_layer5',
806                         'crafting_components.armor_layer6',
807                         'crafting_components.armor_layer7',
808                         'crafting_components.armor_layer12',
809                         'crafting_components.attackActionCost',
810                         'crafting_components.attackCost',
811                         'crafting_components.attackHealthCost',
812                         'crafting_components.attackMindCost',
813                         'crafting_components.attackSpeed',
814                         'crafting_components.attribute.bonus.0',
815                         'crafting_components.attribute.bonus.1',
816                         'crafting_components.attribute.bonus.2',
817                         'crafting_components.attribute.bonus.3',
818                         'crafting_components.attribute.bonus.4',
819                         'crafting_components.attribute.bonus.5',
820                         'crafting_components.attribute.bonus.6',
821                         'crafting_components.attribute.bonus.7',
822                         'crafting_components.attribute.bonus.8',
823                         'crafting_components.condition',
824                         'crafting_components.damageType',
825                         'crafting_components.elementalType',
826                         'crafting_components.elementalValue',
827                         'crafting_components.general_protection',
828                         'crafting_components.hitPoints',
829                         'crafting_components.layer13',
830                         'crafting_components.layer14',
831                         'crafting_components.layer15',
832                         'crafting_components.maxDamage',
833                         'crafting_components.maxRange',
834                         'crafting_components.maxRangeMod',
835                         'crafting_components.midRange',
836                         'crafting_components.midRangeMod',
837                         'crafting_components.minDamage',
838                         'crafting_components.minRange',
839                         'crafting_components.minRangeMod',
840                         'crafting_components.recharge_rate',
841                         'crafting_components.woundChance',
842                         'crafting_components.zeroRangeMod',
843                         'draftSchematic',
844                         'duration',
845                         'effect_class',
846                         'effectiveness',
847                         'filling',
848                         'ImAnInvalidSchematic',
849                         'intAOEDamagePercent',
850                         'intWeaponType',
851                         'jedi.crystal.stats.accuracy',
852                         'jedi.crystal.stats.attack_cost',
853                         'jedi.crystal.stats.damage_type',
854                         'jedi.crystal.stats.elemental_type',
855                         'jedi.crystal.stats.elemental_value',
856                         'jedi.crystal.stats.force',
857                         'jedi.crystal.stats.max_dmg',
858                         'jedi.crystal.stats.max_rng',
859                         'jedi.crystal.stats.min_dmg',
860                         'jedi.crystal.stats.min_rng',
861                         'jedi.crystal.stats.speed',
862                         'jedi.crystal.stats.wound',
863                         'jedi.saber.base_stats.accuracy',
864                         'jedi.saber.base_stats.attack_cost',
865                         'jedi.saber.base_stats.damage_type',
866                         'jedi.saber.base_stats.elemental_type',
867                         'jedi.saber.base_stats.elemental_value',
868                         'jedi.saber.base_stats.force',
869                         'jedi.saber.base_stats.max_dmg',
870                         'jedi.saber.base_stats.max_rng',
871                         'jedi.saber.base_stats.min_dmg',
872                         'jedi.saber.base_stats.min_rng',
873                         'jedi.saber.base_stats.speed',
874                         'jedi.saber.base_stats.wound',
875                         'jedi.saber.force',
876                         'healing.power',
877                         'powerup.accuracy',
878                         'powerup.actionCost',
879                         'powerup.damage',
880                         'powerup.effect',
881                         'powerup.efficiency',
882                         'powerup.speed',
883                         'powerup.usesLeft',
884                         'powerup.wound',
885                         'reuseTimer',
886                         'skillmod.bonus.pistol_speed',
887                         'slowDuration',
888                         'slowIntensity',
889                         'spice.name',
890                         'strWeaponType',
891                         'weapon.intNoCertRequired',
892                         'weaponType'
893                 );
894                 maxNameId number;
895                 
896                 schematicRow schematic_templates%rowtype;
897                 cursor schematicCursor is
898                 select schematic_id, object_template_id
899                 from schematic_templates;
900                 
901                 v varchar2(500);
902                 stmt varchar2(4000);
903         begin
904                 -- initialize
905                 free_slots  := numTable(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
906                 Obj_ObjVars := objectObjVarArray();
907                 Obj_Objvars.extend(20);
908                 updated_objvars  := varcharTable();
909                 deleted_objvars := varcharTable();
910                 added_objvars   := varcharTable();
912                 objvarNameIdMap('armor.armorCategory') := 0;
913                 objvarNameIdMap('armor.armorLevel') := 0;
914                 objvarNameIdMap('armor.armorencumbrance') := 0;
915                 objvarNameIdMap('armor.condition') := 0;
916                 objvarNameIdMap('armor.effectiveness') := 0;
917                 objvarNameIdMap('armor.encumbrance') := 0;
918                 objvarNameIdMap('armor.encumbranceSplit') := 0;
919                 objvarNameIdMap('armor.general_protection') := 0;
920                 objvarNameIdMap('armor.layer0') := 0;
921                 objvarNameIdMap('armor.layer14') := 0;
922                 objvarNameIdMap('armor.layer13') := 0;
923                 objvarNameIdMap('armor.layer15') := 0;
924                 objvarNameIdMap('armor.mandDeconstruct') := 0;
925                 objvarNameIdMap('armor.rating') := 0;
926                 objvarNameIdMap('armor.recharge_rate') := 0;
927                 objvarNameIdMap('armor.risDeconstruct') := 0;
928                 objvarNameIdMap('armor.special.1') := 0;
929                 objvarNameIdMap('armor.special.1024') := 0;
930                 objvarNameIdMap('armor.special.128') := 0;
931                 objvarNameIdMap('armor.special.16') := 0;
932                 objvarNameIdMap('armor.special.2') := 0;
933                 objvarNameIdMap('armor.special.2048') := 0;
934                 objvarNameIdMap('armor.special.256') := 0;
935                 objvarNameIdMap('armor.special.32') := 0;
936                 objvarNameIdMap('armor.special.4') := 0;
937                 objvarNameIdMap('armor.special.4096') := 0;
938                 objvarNameIdMap('armor.special.512') := 0;
939                 objvarNameIdMap('armor.special.64') := 0;
940                 objvarNameIdMap('armor.special.8') := 0;
941                 objvarNameIdMap('armor.vulnerability') := 0;
942                 objvarNameIdMap('armorCategory') := 0;
943                 objvarNameIdMap('armorLevel') := 0;
944                 objvarNameIdMap('biolink.faction_points') := 0;
945                 objvarNameIdMap('blindChance') := 0;
946                 objvarNameIdMap('blindDuration') := 0;
947                 objvarNameIdMap('buff_name') := 0;
948                 objvarNameIdMap('burnDuration') := 0;
949                 objvarNameIdMap('burnIntensity') := 0;
950                 objvarNameIdMap('crafting_attributes.crafting:accuracy') := 0;
951                 objvarNameIdMap('crafting_attributes.crafting:armor_general_protection') := 0;
952                 objvarNameIdMap('crafting_attributes.crafting:armor_condition') := 0;
953                 objvarNameIdMap('crafting_attributes.crafting:armor_layer0') := 0;
954                 objvarNameIdMap('crafting_attributes.crafting:armor_layer1') := 0;
955                 objvarNameIdMap('crafting_attributes.crafting:armor_layer2') := 0;
956                 objvarNameIdMap('crafting_attributes.crafting:armor_layer4') := 0;
957                 objvarNameIdMap('crafting_attributes.crafting:armor_layer5') := 0;
958                 objvarNameIdMap('crafting_attributes.crafting:armor_layer6') := 0;
959                 objvarNameIdMap('crafting_attributes.crafting:armor_layer7') := 0;
960                 objvarNameIdMap('crafting_attributes.crafting:armor_layer12') := 0;
961                 objvarNameIdMap('crafting_attributes.crafting:attackActionCost') := 0;
962                 objvarNameIdMap('crafting_attributes.crafting:attackCost') := 0;
963                 objvarNameIdMap('crafting_attributes.crafting:attackHealthCost') := 0;
964                 objvarNameIdMap('crafting_attributes.crafting:attackMindCost') := 0;
965                 objvarNameIdMap('crafting_attributes.crafting:attackSpeed') := 0;
966                 objvarNameIdMap('crafting_attributes.crafting:condition') := 0;
967                 objvarNameIdMap('crafting_attributes.crafting:damageType') := 0;
968                 objvarNameIdMap('crafting_attributes.crafting:effect') := 0;
969                 objvarNameIdMap('crafting_attributes.crafting:efficiency') := 0;
970                 objvarNameIdMap('crafting_attributes.crafting:elementalType') := 0;
971                 objvarNameIdMap('crafting_attributes.crafting:elementalValue') := 0;
972                 objvarNameIdMap('crafting_attributes.crafting:flavor') := 0;
973                 objvarNameIdMap('crafting_attributes.crafting:general_protection') := 0;
974                 objvarNameIdMap('crafting_attributes.crafting:hitPoints') := 0;
975                 objvarNameIdMap('crafting_attributes.crafting:maxDamage') := 0;
976                 objvarNameIdMap('crafting_attributes.crafting:maxRange') := 0;
977                 objvarNameIdMap('crafting_attributes.crafting:maxRangeMod') := 0;
978                 objvarNameIdMap('crafting_attributes.crafting:midRange') := 0;
979                 objvarNameIdMap('crafting_attributes.crafting:midRangeMod') := 0;
980                 objvarNameIdMap('crafting_attributes.crafting:minDamage') := 0;
981                 objvarNameIdMap('crafting_attributes.crafting:minRange') := 0;
982                 objvarNameIdMap('crafting_attributes.crafting:minRangeMod') := 0;
983                 objvarNameIdMap('crafting_attributes.crafting:nutrition') := 0;
984                 objvarNameIdMap('crafting_attributes.crafting:power') := 0;
985                 objvarNameIdMap('crafting_attributes.crafting:woundChance') := 0;
986                 objvarNameIdMap('crafting_attributes.crafting:zeroRangeMod') := 0;
987                 objvarNameIdMap('crafting_components.accuracy') := 0;
988                 objvarNameIdMap('crafting_components.armor_armorencumbrance') := 0;
989                 objvarNameIdMap('crafting_components.armor_condition') := 0;
990                 objvarNameIdMap('crafting_components.armor_general_protection') := 0;
991                 objvarNameIdMap('crafting_components.armor_layer0') := 0;
992                 objvarNameIdMap('crafting_components.armor_layer1') := 0;
993                 objvarNameIdMap('crafting_components.armor_layer2') := 0;
994                 objvarNameIdMap('crafting_components.armor_layer4') := 0;
995                 objvarNameIdMap('crafting_components.armor_layer5') := 0;
996                 objvarNameIdMap('crafting_components.armor_layer6') := 0;
997                 objvarNameIdMap('crafting_components.armor_layer7') := 0;
998                 objvarNameIdMap('crafting_components.armor_layer12') := 0;
999                 objvarNameIdMap('crafting_components.attackActionCost') := 0;
1000                 objvarNameIdMap('crafting_components.attackCost') := 0;
1001                 objvarNameIdMap('crafting_components.attackHealthCost') := 0;
1002                 objvarNameIdMap('crafting_components.attackMindCost') := 0;
1003                 objvarNameIdMap('crafting_components.attackSpeed') := 0;
1004                 objvarNameIdMap('crafting_components.attribute.bonus.0') := 0;
1005                 objvarNameIdMap('crafting_components.attribute.bonus.1') := 0;
1006                 objvarNameIdMap('crafting_components.attribute.bonus.2') := 0;
1007                 objvarNameIdMap('crafting_components.attribute.bonus.3') := 0;
1008                 objvarNameIdMap('crafting_components.attribute.bonus.4') := 0;
1009                 objvarNameIdMap('crafting_components.attribute.bonus.5') := 0;
1010                 objvarNameIdMap('crafting_components.attribute.bonus.6') := 0;
1011                 objvarNameIdMap('crafting_components.attribute.bonus.7') := 0;
1012                 objvarNameIdMap('crafting_components.attribute.bonus.8') := 0;
1013                 objvarNameIdMap('crafting_components.condition') := 0;
1014                 objvarNameIdMap('crafting_components.damageType') := 0;
1015                 objvarNameIdMap('crafting_components.elementalType') := 0;
1016                 objvarNameIdMap('crafting_components.elementalValue') := 0;
1017                 objvarNameIdMap('crafting_components.general_protection') := 0;
1018                 objvarNameIdMap('crafting_components.hitPoints') := 0;
1019                 objvarNameIdMap('crafting_components.layer13') := 0;
1020                 objvarNameIdMap('crafting_components.layer14') := 0;
1021                 objvarNameIdMap('crafting_components.layer15') := 0;
1022                 objvarNameIdMap('crafting_components.maxDamage') := 0;
1023                 objvarNameIdMap('crafting_components.maxRange') := 0;
1024                 objvarNameIdMap('crafting_components.maxRangeMod') := 0;
1025                 objvarNameIdMap('crafting_components.midRange') := 0;
1026                 objvarNameIdMap('crafting_components.midRangeMod') := 0;
1027                 objvarNameIdMap('crafting_components.minDamage') := 0;
1028                 objvarNameIdMap('crafting_components.minRange') := 0;
1029                 objvarNameIdMap('crafting_components.minRangeMod') := 0;
1030                 objvarNameIdMap('crafting_components.recharge_rate') := 0;
1031                 objvarNameIdMap('crafting_components.woundChance') := 0;
1032                 objvarNameIdMap('crafting_components.zeroRangeMod') := 0;
1033                 objvarNameIdMap('draftSchematic') := 0;
1034                 objvarNameIdMap('duration') := 0;
1035                 objvarNameIdMap('effect_class') := 0;
1036                 objvarNameIdMap('effectiveness') := 0;
1037                 objvarNameIdMap('filling') := 0;
1038                 objvarNameIdMap('ImAnInvalidSchematic') := 0;
1039                 objvarNameIdMap('intAOEDamagePercent') := 0;
1040                 objvarNameIdMap('intWeaponType') := 0;
1041                 objvarNameIdMap('jedi.crystal.stats.accuracy') := 0;
1042                 objvarNameIdMap('jedi.crystal.stats.attack_cost') := 0;
1043                 objvarNameIdMap('jedi.crystal.stats.damage_type') := 0;
1044                 objvarNameIdMap('jedi.crystal.stats.elemental_type') := 0;
1045                 objvarNameIdMap('jedi.crystal.stats.elemental_value') := 0;
1046                 objvarNameIdMap('jedi.crystal.stats.force') := 0;
1047                 objvarNameIdMap('jedi.crystal.stats.max_dmg') := 0;
1048                 objvarNameIdMap('jedi.crystal.stats.max_rng') := 0;
1049                 objvarNameIdMap('jedi.crystal.stats.min_dmg') := 0;
1050                 objvarNameIdMap('jedi.crystal.stats.min_rng') := 0;
1051                 objvarNameIdMap('jedi.crystal.stats.speed') := 0;
1052                 objvarNameIdMap('jedi.crystal.stats.wound') := 0;
1053                 objvarNameIdMap('jedi.saber.base_stats.accuracy') := 0;
1054                 objvarNameIdMap('jedi.saber.base_stats.attack_cost') := 0;
1055                 objvarNameIdMap('jedi.saber.base_stats.damage_type') := 0;
1056                 objvarNameIdMap('jedi.saber.base_stats.elemental_type') := 0;
1057                 objvarNameIdMap('jedi.saber.base_stats.elemental_value') := 0;
1058                 objvarNameIdMap('jedi.saber.base_stats.force') := 0;
1059                 objvarNameIdMap('jedi.saber.base_stats.max_dmg') := 0;
1060                 objvarNameIdMap('jedi.saber.base_stats.max_rng') := 0;
1061                 objvarNameIdMap('jedi.saber.base_stats.min_dmg') := 0;
1062                 objvarNameIdMap('jedi.saber.base_stats.min_rng') := 0;
1063                 objvarNameIdMap('jedi.saber.base_stats.speed') := 0;
1064                 objvarNameIdMap('jedi.saber.base_stats.wound') := 0;
1065                 objvarNameIdMap('jedi.saber.force') := 0;
1066                 objvarNameIdMap('healing.power') := 0;
1067                 objvarNameIdMap('powerup.accuracy') := 0;
1068                 objvarNameIdMap('powerup.actionCost') := 0;
1069                 objvarNameIdMap('powerup.damage') := 0;
1070                 objvarNameIdMap('powerup.effect') := 0;
1071                 objvarNameIdMap('powerup.efficiency') := 0;
1072                 objvarNameIdMap('powerup.speed') := 0;
1073                 objvarNameIdMap('powerup.usesLeft') := 0;
1074                 objvarNameIdMap('powerup.wound') := 0;
1075                 objvarNameIdMap('reuseTimer') := 0;
1076                 objvarNameIdMap('skillmod.bonus.pistol_speed') := 0;
1077                 objvarNameIdMap('slowDuration') := 0;
1078                 objvarNameIdMap('slowIntensity') := 0;
1079                 objvarNameIdMap('spice.name') := 0;
1080                 objvarNameIdMap('strWeaponType') := 0;
1081                 objvarNameIdMap('weapon.intNoCertRequired') := 0;
1082                 objvarNameIdMap('weaponType') := 0;
1084                 open objvarNameIdCursor;
1085                 fetch objvarNameIdCursor into objvarNameIdRow;
1086                 while objvarNameIdCursor%found loop
1087                           objvarNameIdMap(objvarNameIdRow.name) := objvarNameIdRow.id;
1088                           fetch objvarNameIdCursor into objvarNameIdRow;
1089                 end loop;
1090                 close objvarNameIdCursor;
1092                 select max(id) into maxNameId from object_variable_names;
1094                 v := objvarNameIdMap.first;
1095                 while v is not null loop
1096                         if objvarNameIdMap(v) = 0 then
1097                                 maxNameId := maxNameId + 1;
1098                                 stmt := 'insert into object_variable_names values (:id, :name)';
1099                                 execute immediate stmt using maxNameId, v;
1100                                 objvarNameIdMap(v) := maxNameId;
1101                         end if;
1102                         v := objvarNameIdMap.next(v);
1103                 end loop;
1104                 commit;
1105                 if use_rbs is not null then
1106                         execute immediate 'set transaction use rollback segment ' || use_rbs;
1107                 end if;
1109                 open schematicCursor;
1110                 fetch schematicCursor into schematicRow;
1111                 while schematicCursor%found loop
1112                           schematic_map(schematicRow.schematic_id) := schematicRow.object_template_id;
1113                           fetch schematicCursor into schematicRow;
1114                 end loop;
1115                 close schematicCursor;
1116         
1117                 
1118                 templateNameText(1594162622)  := 'armor_recon_segment';
1119                 templateNameTable(1594162622) := 'craft_armor_ingredients_n';
1120                 templateNameText(-1438161694) := 'armor_battle_segment';
1121                 templateNameTable(-1438161694):= 'craft_armor_ingredients_n';
1122                 templateNameText(2042493214)  := 'armor_assault_segment';
1123                 templateNameTable(2042493214) := 'craft_armor_ingredients_n';
1124                 
1125                 return TRUE;
1126         exception
1127                 when others then
1128                         err_num := SQLCODE;
1129                         dbms_output.put_line('Error in InitializeData - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1130                         db_error_logger.dblogerror(err_num, 'Error in InitializeData');
1131                         return FALSE;
1132         end;
1134         procedure AddObjVar (objvar_name varchar2, objvar_type number, objvar_value varchar2)
1135         is
1136                 n number;
1137                 tempObjVar objVarType;
1138                 oldName varchar2(500);
1139         begin
1140                 if slot_map.exists(objvar_name) then
1141                         ModifyObjVar(objvar_name, objvar_name, objvar_type, objvar_value);
1142                 else
1143                         if free_slots.count > 0 and length(objvar_name) <= 50 then
1144                                 n := free_slots(free_slots.first);
1145                                 Obj_ObjVars(n).objvar_name := objvar_name;
1146                                 Obj_ObjVars(n).objvar_type := objvar_type;
1147                                 Obj_ObjVars(n).objvar_value := objvar_value;
1148                                 free_slots.delete(n);
1149                                 isObjModified := TRUE;
1150                         else
1151                                 if deleted_objvars.count > 0 then
1152                                         oldName := deleted_objvars(deleted_objvars.last);
1153                                         deleted_objvars.trim(1);
1154                                         OV_ObjVars(oldName).objvar_name := objvar_name;
1155                                         OV_ObjVars(oldName).objvar_type := objvar_type;
1156                                         OV_ObjVars(oldName).objvar_value := objvar_value;
1157                                         updated_objvars.extend(1);
1158                                         updated_objvars(updated_objvars.last) := oldName;
1159                                 else
1160                                         tempObjVar.object_id := object_id;
1161                                         tempObjVar.objvar_name := objvar_name;
1162                                         tempObjVar.objvar_type := objvar_type;
1163                                         tempObjVar.objvar_value := objvar_value;
1164                                         tempObjVar.objvar_name_id := objvarNameIdMap(objvar_name);
1165                                         OV_ObjVars(objvar_name) := tempObjVar;
1166                                         added_objvars.extend(1);
1167                                         added_objvars(added_objvars.last) := objvar_name;
1168                                 end if;
1169                         end if;
1170                 end if;
1171         exception
1172                 when others then
1173                         err_num := SQLCODE;
1174                         dbms_output.put_line('Error in AddObjVar - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1175                         db_error_logger.dblogerror(err_num, 'Error in AddObjVar');
1176         end;
1178         procedure DeleteObjVar (objVarName in varchar2)
1179         is
1180                 n number;
1181                 v varchar2(500);
1182         begin
1183                 if slot_map.exists(objVarName) then
1184                         if slot_map(objVarName) < 21 then
1185                                 n := slot_map(objVarName);
1186                                 if Obj_ObjVars(n).objvar_name = objVarName then
1187                                         Obj_ObjVars(n).objvar_name := NULL;
1188                                         Obj_ObjVars(n).objvar_type := NULL;
1189                                         Obj_ObjVars(n).objvar_value := NULL;
1190                                         free_slots(n) := n;
1191                                         isObjModified := TRUE;
1192                                 end if;
1193                         else
1194                                 if OV_ObjVars(objVarName).objvar_name  = objVarName then
1195                                         OV_ObjVars(objVarName).old_objvar_name_id := OV_ObjVars(objVarName).objvar_name_id;
1196                                         OV_ObjVars(objVarName).objvar_name := NULL;
1197                                         OV_ObjVars(objVarName).objvar_type := NULL;
1198                                         OV_ObjVars(objVarName).objvar_value := NULL;
1199                                         deleted_objvars.extend(1);
1200                                         deleted_objvars(deleted_objvars.last) := objVarName;
1201                                 end if;
1202                         end if;
1203                 elsif instr(objVarName,'*') > 0 then
1204                         n := instr(objVarName,'*') -1;
1205                         v := slot_map.first;
1206                         while v is not null loop
1207                                 if substr(v,1,n) = substr(objVarName,1,n) then
1208                                         DeleteObjVar(v);
1209                                 end if;
1210                                 v := slot_map.next(v);
1211                         end loop;
1212                 end if;
1213         exception
1214                 when others then
1215                         err_num := SQLCODE;
1216                         dbms_output.put_line('Error in DeleteObjVar - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1217                         db_error_logger.dblogerror(err_num, 'Error in DeleteObjVar');
1218         end;
1220         procedure ModifyObjVar (oldObjVarName varchar2, objvar_name varchar2, objvar_type number, objvar_value varchar2)
1221         is
1222                 n number;
1223         begin
1224                 if slot_map.exists(oldObjVarName) then
1225                         if slot_map(oldObjVarName) < 21 then
1226                                 n := slot_map(oldObjVarName);
1227                                 Obj_ObjVars(n).objvar_name := objvar_name;
1228                                 Obj_ObjVars(n).objvar_type := objvar_type;
1229                                 Obj_ObjVars(n).objvar_value := objvar_value;
1230                                 isObjModified := TRUE;
1231                         else
1232                                 OV_ObjVars(oldObjVarName).old_objvar_name_id := OV_ObjVars(oldObjVarName).objvar_name_id;
1233                                 OV_ObjVars(oldObjVarName).objvar_name := objvar_name;
1234                                 OV_ObjVars(oldObjVarName).objvar_type := objvar_type;
1235                                 OV_ObjVars(oldObjVarName).objvar_value := objvar_value;
1236                                 updated_objvars.extend(1);
1237                                 updated_objvars(updated_objvars.last) := oldObjVarName;
1238                         end if;
1239                 end if;
1240         exception
1241                 when others then
1242                         err_num := SQLCODE;
1243                         dbms_output.put_line('Error in ModifyObjVar - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1244                         db_error_logger.dblogerror(err_num, 'Error in ModifyObjVar');
1245         end;
1247         procedure ModifyObjVar (oldObjVarName varchar2, objvar_name varchar2, objvar_type number, rangeTable rangeTableType)
1248         is
1249                 n number;
1250         begin
1251                 if slot_map.exists(oldObjVarName) then
1252                         if slot_map(oldObjVarName) < 21 then
1253                                 n := slot_map(oldObjVarName);
1254                                 Obj_ObjVars(n).objvar_name := objvar_name;
1255                                 Obj_ObjVars(n).objvar_type := objvar_type;
1256                                 Obj_ObjVars(n).objvar_value := ConvertValue (to_number(Obj_ObjVars(n).objvar_value), rangeTable);
1257                                 isObjModified := TRUE;
1258                         else
1259                                 if OV_ObjVars(oldObjVarName).old_objvar_name_id = 0 then
1260                                         OV_ObjVars(oldObjVarName).old_objvar_name_id := OV_ObjVars(oldObjVarName).objvar_name_id;
1261                                 end if;
1262                                 OV_ObjVars(oldObjVarName).objvar_name := objvar_name;
1263                                 OV_ObjVars(oldObjVarName).objvar_type := objvar_type;
1264                                 OV_ObjVars(oldObjVarName).objvar_value := ConvertValue (to_number(OV_ObjVars(oldObjVarName).objvar_value), rangeTable);
1265                                 updated_objvars.extend(1);
1266                                 updated_objvars(updated_objvars.last) := oldObjVarName;
1267                         end if;
1268                 end if;
1269         exception
1270                 when others then
1271                         err_num := SQLCODE;
1272                         dbms_output.put_line('Error in ModifyObjVar - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1273                         db_error_logger.dblogerror(err_num, 'Error in ModifyObjVar');
1274         end;
1276         procedure RenameObjVar (oldObjVarName varchar2, objvar_name varchar2)
1277         is
1278                 n number;
1279         begin
1280                 if slot_map.exists(oldObjVarName) then
1281                         if slot_map(oldObjVarName) < 21 then
1282                                 n := slot_map(oldObjVarName);
1283                                 Obj_ObjVars(n).objvar_name := objvar_name;
1284                                 isObjModified := TRUE;
1285                         else
1286                                 OV_ObjVars(oldObjVarName).old_objvar_name_id := OV_ObjVars(oldObjVarName).objvar_name_id;
1287                                 OV_ObjVars(oldObjVarName).objvar_name := objvar_name;
1288                                 updated_objvars.extend(1);
1289                                 updated_objvars(updated_objvars.last) := oldObjVarName;
1290                         end if;
1291                 end if;
1292         exception
1293                 when others then
1294                         err_num := SQLCODE;
1295                         dbms_output.put_line('Error in ModifyObjVar - time = ' || to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1296                         db_error_logger.dblogerror(err_num, 'Error in ModifyObjVar');
1297         end;
1299         function GetObjVarValue (objvar_name varchar2) return varchar2
1300         is
1301         begin
1302                 if slot_map.exists(objvar_name) then
1303                         if slot_map(objvar_name) < 21 then
1304                                 return Obj_ObjVars(slot_map(objvar_name)).objvar_value;
1305                         else
1306                                 return OV_ObjVars(objvar_name).objvar_value;
1307                         end if;
1308                 else
1309                         return null;
1310                 end if;
1311         end;
1313         procedure AddScript (newScript varchar2)
1314         is
1315         begin
1316                 script_list := trim(script_list) ||  newScript || ':';
1317                 isObjModified := TRUE;
1318         end;
1320         procedure RemoveScript (oldScript varchar2)
1321         is
1322         begin
1323                 script_list := replace(script_list, oldScript || ':');
1324                 isObjModified := TRUE;
1325         end;
1327         procedure SetNewTemplateId (newTemplateId number)
1328         is
1329         begin
1330                 new_template_id := newTemplateId;
1331                 SetTemplateText (newTemplateId);
1332         end;
1333         
1334         procedure SetTemplateText (newTemplateId number)
1335         is
1336         begin           
1337                 if templateNameText.exists(newTemplateId) then
1338                         object_name := null;
1339                         name_text  := templateNameText(newTemplateId);
1340                         if templateNameTable.exists(newTemplateId) then
1341                                 name_table := templateNameTable(newTemplateId);
1342                         end if;
1343                 end if;
1344         end;
1345         
1346         procedure InvalidateSchematic
1347         is
1348         begin
1349                 AddObjVar('ImAnInvalidSchematic',0,1);
1350                 isObjModified := TRUE;
1351         end;
1352         
1353         procedure SetGenProtection(rangeTable rangeTableType)
1354         is
1355         begin
1356                 if isFactory= TRUE then
1357                         ModifyObjVar('crafting_attributes.crafting:armor_effectiveness','crafting_attributes.crafting:general_protection',2,rangeTable);
1358                 else
1359                         ModifyObjVar('armor.effectiveness','armor.general_protection',2,rangeTable);
1360                 end if;
1361         end;
1362         
1363         procedure SetArmorCondLevelCat(condition varchar2, lev varchar2, category varchar2)
1364         is
1365         begin
1366                 if isFactory= TRUE then
1367                         AddObjVar('crafting_attributes.crafting:condition',2,condition);
1368                         AddObjVar('armorLevel',0,lev);
1369                         AddObjVar('armorCategory',0,category);
1370                 else
1371                         AddObjVar('armor.condition',2,condition);
1372                         AddObjVar('armor.armorLevel',0,lev);
1373                         AddObjVar('armor.armorCategory',0,category);
1374                 end if;
1375         end;
1376         
1377         procedure SetArmorLevel(lev varchar)
1378         is
1379         begin
1380                 if isFactory= TRUE then
1381                         AddObjVar('armorLevel',0,lev);
1382                 else
1383                         AddObjVar('armor.armorLevel',0,lev);
1384                 end if;
1385         end;
1386         
1387         procedure SetArmorCategory(category varchar2)
1388         is 
1389         begin
1390                 if isFactory= TRUE then
1391                         AddObjVar('armorCategory',0,category);
1392                 else
1393                         AddObjVar('armor.armorCategory',0,category);
1394                 end if;
1395         end;
1397         procedure SetGpAndCond(gp_name varchar2, gp_val varchar2, cond_name varchar2, cond_val varchar2)
1398         is 
1399         begin
1400                 AddObjVar(gp_name,2,gp_val);
1401                 AddObjVar(cond_name,2,cond_val);
1402         end;
1403         
1404         procedure DeleteCraftingComponents
1405         is
1406         begin
1407                 DeleteObjVar('crafting_components.*');
1408                 DeleteObjVar('item_attrib_keys');
1409                 DeleteObjVar('item_attrib_values');
1410         end;
1412         function ConvertValue (oldvalue number, rangeTable rangeTableType)
1413                 return number
1414         is
1415                 retval number;
1416                 i number;
1417         begin
1418                 retval := rangeTable(rangeTable.first)(3);  -- default to min value
1419                 if oldvalue >= rangeTable(rangeTable.last)(2) then
1420                         retval := rangeTable(rangeTable.last)(4);
1421                 else
1422                         i := rangeTable.first;
1423                         while i is not null loop
1424                                 if oldvalue >= rangeTable(i)(1) and oldvalue < rangeTable(i)(2) then
1425                                         retval := (( (oldvalue - rangeTable(i)(1)) * 
1426                                                                  ((rangeTable(i)(4)-rangeTable(i)(3))/(rangeTable(i)(2)-rangeTable(i)(1))) )
1427                                                                 + rangeTable(i)(3) );
1428                                         exit;
1429                                 end if;
1430                                 i := rangeTable.next(i);
1431                         end loop;
1432                 end if;
1434                 return retval;
1435         end;
1437         function SchematicMap(schematic_id number)
1438                 return number
1439         is
1440                 retval number := 0;
1441         begin
1442                 if schematic_map.exists(schematic_id) then
1443                         retval := schematic_map(schematic_id);
1444                 end if;
1445                 return retval;
1446         end;
1447 end;