4
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

152 lines
5.7 KiB (Stored with Git LFS)

{
Generates conditions for dismantling recipes in Enderal SE
Author: Eddoursul, condition generation borrowed from fireundubh's work
Version: 1.0
One-handed weapon conditions:
>= 1
&&
> 2 || temp < 2
&&
> 1 || temp == 0
&&
arcane perk check
All other weapons and armor:
>= 1
&&
> 1 || ! equipped
&&
arcane perk check
}
unit UserScript;
function Process(e: IInterface): integer;
var
rec, item, conditions, condition, ctda, lastcondition, lastctda, checkcondition, checkctda, baseItem: IInterface;
i, iLastIndex, iResults: integer;
equipType: string;
begin
item := ElementByPath(e, 'Items\Item\CNTO\Item');
baseItem := LinksTo(item);
// Recreate conditions
Remove(ElementByName(e, 'Conditions'));
conditions := Add(e, 'Conditions', true);
// GetItemCount >= 1
ctda := ElementByPath(e, 'Conditions\Condition\CTDA');
SetEditValue(ElementByIndex(ctda, 0), '11000000');
SetNativeValue(ElementByIndex(ctda, 2), GetNativeValue(ElementByPath(e, 'Items\Item\CNTO\Count')));
SetEditValue(ElementByIndex(ctda, 3), 'GetItemCount');
SetEditValue(ElementByName(ctda, 'Inventory Object'), GetEditValue(item));
equipType := ShortName(LinksTo(ElementByPath(baseItem, 'ETYP')));
// One-handed weapons
if (Signature(baseItem) = 'WEAP') and ((Pos('[EQUP:00013F42]', equipType) > 0) or (Pos('[EQUP:00013F43]', equipType) > 0) or (Pos('[EQUP:00013F44]', equipType) > 0)) then begin
// GetItemCount > 2 OR
condition := ElementAssign(conditions, HighInteger, nil, true);
conditions := ElementByName(e, 'Conditions');
iLastIndex := ElementCount(conditions) - 1;
lastcondition := ElementByIndex(conditions, iLastIndex);
lastctda := ElementBySignature(ElementByIndex(conditions, iLastIndex), 'CTDA');
SetEditValue(ElementByIndex(lastctda, 0), '01010000');
SetNativeValue(ElementByIndex(lastctda, 2), 2.0);
SetEditValue(ElementByIndex(lastctda, 3), 'GetItemCount');
SetEditValue(ElementByName(lastctda, 'Inventory Object'), GetEditValue(item));
// Temp < 2
condition := ElementAssign(conditions, HighInteger, nil, true);
iLastIndex := ElementCount(conditions) - 1;
lastcondition := ElementByIndex(conditions, iLastIndex);
lastctda := ElementBySignature(ElementByIndex(conditions, iLastIndex), 'CTDA');
SetEditValue(ElementByIndex(lastctda, 0), '00100000');
SetNativeValue(ElementByIndex(lastctda, 2), 2.0);
SetEditValue(ElementByIndex(lastctda, 3), 'GetItemCount');
SetEditValue(ElementByName(lastctda, 'Inventory Object'), GetEditValue(item));
SetEditValue(ElementByName(lastctda, 'Run On'), 'Reference');
SetEditValue(ElementByName(lastctda, 'Reference'), '[REFR:000469E7]');
// GetItemCount > 1 OR
condition := ElementAssign(conditions, HighInteger, nil, true);
conditions := ElementByName(e, 'Conditions');
iLastIndex := ElementCount(conditions) - 1;
lastcondition := ElementByIndex(conditions, iLastIndex);
lastctda := ElementBySignature(ElementByIndex(conditions, iLastIndex), 'CTDA');
SetEditValue(ElementByIndex(lastctda, 0), '01010000');
SetNativeValue(ElementByIndex(lastctda, 2), 1.0);
SetEditValue(ElementByIndex(lastctda, 3), 'GetItemCount');
SetEditValue(ElementByName(lastctda, 'Inventory Object'), GetEditValue(item));
// Temp == 0
condition := ElementAssign(conditions, HighInteger, nil, true);
conditions := ElementByName(e, 'Conditions');
iLastIndex := ElementCount(conditions) - 1;
lastcondition := ElementByIndex(conditions, iLastIndex);
lastctda := ElementBySignature(ElementByIndex(conditions, iLastIndex), 'CTDA');
SetEditValue(ElementByIndex(lastctda, 0), '10000000');
SetNativeValue(ElementByIndex(lastctda, 2), 0);
SetEditValue(ElementByIndex(lastctda, 3), 'GetItemCount');
SetEditValue(ElementByName(lastctda, 'Inventory Object'), GetEditValue(item));
SetEditValue(ElementByName(lastctda, 'Run On'), 'Reference');
SetEditValue(ElementByName(lastctda, 'Reference'), '[REFR:000469E7]');
end
else if (Signature(baseItem) = 'WEAP') or (Signature(baseItem) = 'ARMO') then begin
// GetEquipped == 0 OR
condition := ElementAssign(conditions, HighInteger, nil, true);
iLastIndex := ElementCount(conditions) - 1;
lastcondition := ElementByIndex(conditions, iLastIndex);
lastctda := ElementBySignature(ElementByIndex(conditions, iLastIndex), 'CTDA');
SetEditValue(ElementByIndex(lastctda, 0), '10010000');
SetNativeValue(ElementByIndex(lastctda, 2), 0);
SetEditValue(ElementByIndex(lastctda, 3), 'GetEquipped');
SetEditValue(ElementByName(lastctda, 'Inventory Object'), GetEditValue(item));
// GetItemCount > 1
condition := ElementAssign(conditions, HighInteger, nil, true);
iLastIndex := ElementCount(conditions) - 1;
lastcondition := ElementByIndex(conditions, iLastIndex);
lastctda := ElementBySignature(ElementByIndex(conditions, iLastIndex), 'CTDA');
SetEditValue(ElementByIndex(lastctda, 0), '01000000');
SetNativeValue(ElementByIndex(lastctda, 2), 1.0);
SetEditValue(ElementByIndex(lastctda, 3), 'GetItemCount');
SetEditValue(ElementByName(lastctda, 'Inventory Object'), GetEditValue(item));
end;
// Check the arcane perk if the dismantled item is enchanted
if Assigned(ElementByPath(baseItem, 'EITM')) then begin
condition := ElementAssign(conditions, HighInteger, nil, true);
iLastIndex := ElementCount(conditions) - 1;
lastcondition := ElementByIndex(conditions, iLastIndex);
lastctda := ElementBySignature(ElementByIndex(conditions, iLastIndex), 'CTDA');
SetEditValue(ElementByIndex(lastctda, 0), '10000000');
SetNativeValue(ElementByIndex(lastctda, 2), 1);
SetEditValue(ElementByIndex(lastctda, 3), 'HasPerk');
SetEditValue(ElementByName(lastctda, 'Perk'), '[PERK:0005218E]');
end;
end;
function Finalize: integer;
begin
AddMessage('Done');
Result := 1;
end;
end.