Skip to content

Instantly share code, notes, and snippets.

@yggdrasil75
Last active February 7, 2020 01:59
Show Gist options
  • Save yggdrasil75/956281ed289db9286ed00658faf72796 to your computer and use it in GitHub Desktop.
Save yggdrasil75/956281ed289db9286ed00658faf72796 to your computer and use it in GitHub Desktop.
function MaterialListPrinter(CurrentKYWDName: string): integer;
var
ValidSignatures, perks, Output, Input, TempList: TStringList;
EDID,TempSig, PEDID: String;
item, cc, perk, CurrentKYWD, CurrentItem, CurrentReference, ConPath: IInterface;
itemIndex, RecipeCount, k, a, i, l, p, LimitIndex: Integer;
y, amount, limit: double;
perkcheck: boolean;
begin
ValidSignatures := TStringList.Create;
ValidSignatures.DelimitedText := 'AMMO,ARMO,WEAP,SLGM';
input := TStringList.Create;
Output := TStringList.Create;
perks := TStringList.Create;
CurrentKYWD := TrueRecordByEDID(CurrentKYWDName);
if not Assigned(CurrentKYWD) then exit;
RecipeCount := 0;
for k := referencedByCount(CurrentKYWD) - 1 downto 0 do
begin
//if debug then AddMessage('Cycle ' + IntToStr(k));
CurrentItem := ReferencedByIndex(CurrentKYWD, k);
TempSig := Signature(CurrentItem);
if ValidSignatures.IndexOf(TempSig) < 0 then continue;
if IntToStr(GetElementNativeValues(itemRecord, 'DATA\Flags\Non-Playable')) < 0 then continue;
if IntToStr(GetElementNativeValues(itemRecord, 'Record Header\Record Flags\Non-Playable')) < 0 then exit;
if GetElementNativeValues(CurrentItem, 'EITM') > 0 then continue;
//if debug then AddMessage('Passed Signature');
for a := ReferencedByCount(CurrentItem) - 1 downto 0 do
begin
//if debug then AddMessage('Recipe Search ' + IntToStr(a));
CurrentReference := ReferencedByIndex(CurrentItem, a);
if not pos('COBJ', signature(CurrentReference)) > 0 then continue;
//if debug then AddMessage('it is a recipe');
if not equals(CurrentItem, LinksTo(ElementByPath(CurrentReference, 'CNAM'))) then continue;
//if debug then AddMessage('output is the same');
if GetLoadOrderFormID(LinksTo(ElementByPath(CurrentReference, 'BNAM'))) = $000ADB78 then continue;
if GetLoadOrderFormID(LinksTo(ElementByPath(CurrentReference, 'BNAM'))) = $00088108 then continue;
if not IsWinningOverride(CurrentReference) then continue;
if length(GetElementEditValues(CurrentReference, 'COCT')) = 0 then continue
else l := tryStrToInt(GetElementEditValues(CurrentReference, 'COCT'), 0) - 1;
//if debug then AddMessage('standard recipe limitations');
for i := l downto 0 do
begin
TempList := TStringList.Create;
item := LinksTo(ElementByIndex(ElementByIndex(ElementByIndex(ElementByPath(CurrentReference, 'Items'), i), 0), 0));
if ValidSignatures.IndexOf(signature(item)) >= 0 then continue;
EDID := EditorID(item);
ItemIndex := Input.IndexOf(EDID);
//if debug then AddMessage(IntToStr(TempList.Count));
if ItemIndex < 0 then
begin
TempList.Add(EDID);
TempList.Add(IntToStr(1));
TempList.Add(IntToStr(1));
TempList.Objects[0] := item;
ItemIndex := Input.AddObject(EDID, TempList);
end else TempList.Assign(Input.Objects[ItemIndex]);
TempList.strings[1] := IntToStr(tryStrToInt(TempList.strings[1], 0) + 1);
TempList.strings[2] := IntToStr(tryStrToInt(TempList.strings[2], 0) + GetEditValue(ElementByIndex(ElementByIndex(ElementByIndex(ElementByPath(CurrentReference, 'Items'), i), 0), 1)));
Input.Objects[ItemIndex] := TempList;
end;
ConPath := ElementByPath(CurrentReference, 'Conditions');
if not Assigned(ConPath) then continue;
for i := ElementCount(ConPath) downto 0 do
begin
cc := ElementByPath(ElementByIndex(ConPath, i), 'CTDA');
addmessage(EditorID(LinksTo(ElementByPath(ElementByPath(ElementByIndex(ElementByPath(CurrentReference, 'Conditions'), 1), 'CTDA'), 'Perk'))));
//if not pos('HasPerk', GetEditValue(ElementByPath(CC, 'Function'))) > 0 then continue;
Perk := LinksTo(ElementByPath(cc, 'Perk'));
if not assigned(Perk) then continue;
PEDID := EditorID(Perk);
ItemIndex := Perks.IndexOf(PEDID);
if ItemIndex > 0 then Perks.Values[ItemIndex] := IntToStr(tryStrToInt(Perks.Values[ItemIndex], 0) + 1)
else
begin
ItemIndex := Perks.AddObject(EditorID(LinksTo(ElementByPath(ElementByPath(ElementByIndex(ElementByPath(CurrentReference, 'Conditions'), i), 'CTDA'), 'Perk'))), Perk);
Perks.Values[ItemIndex] := IntToStr(1);
end;
end;
RecipeCount := RecipeCount + 1;
end;
end;
Limit := 0;
for a := Input.Count - 1 downto 0 do
begin
TempList := input.objects[a];
if length(TempList.strings[1]) = 0 then
begin
input.Delete[a];
continue;
end;
if length(TempList.Strings[2]) = 0 then
begin
input.Delete[a];
continue;
end;
if tryStrToInt(TempList.strings[1], 0) < (recipeCount / 2) then input.Delete(a);
if not tryStrToFloat(tryStrToInt(TempList.Strings[1], 0) / tryStrToInt(TempList.strings[2], 1), 1) > Limit then continue;
Limit := tryStrToInt(TempList.Strings[1], 0) / tryStrToInt(TempList.Strings[2], 1);
LimitIndex := a;
end;
if limit > 0 then y := 1 / limit
else y := 1;
if perks.count > 0 then begin
perkcheck := true;
while perkcheck = true do
begin
perks.sorted := true;
if length(perks.strings[0]) = 0 then perkcheck := false;
if not assigned(ObjectToElement(perks.Objects[0])) then perkcheck := false;
if length(perks.values[0]) = 0 then perkcheck := false;
if not tryStrToInt(perks.Values[0], 0) > (recipeCount * 0.25) then perkcheck := false;
output.Add('p:' + GetFileName(GetFile(ObjectToElement(perks.objects[0]))) + '|' + perks.strings[0]);
AddMessage(GetFileName(GetFile(ObjectToElement(perks.Objects[0]))));
end;
end;
for a := input.count - 1 downto 0 do
begin
TempList := input.objects[a];
item := ObjectToElement(TempList.Objects[0]);
Edid := TempList.strings[0];
if tryStrToInt(TempList.Strings[2], 0) > 0 then
amount := StrToFloat(TempList.Strings[1]) / StrToFloat(TempList.Strings[2])
else continue;
if amount = 0.0 then continue;
output.add('i' + signature(item) + ':' + GetFileName(GetFile(MasterOrSelf(item))) + '|' + EDID + '=' + FloatToStr(Amount * y));
end;
input.free;
perks.free;
ini.WriteString('Crafting', CurrentKYWDName, output.commatext);
ini.UpdateFile;
output.free;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment