Code: Select all
local slotToUse = 2;
local mainPet = CEggPet(1);
local tmp = settings.profile.options.EGGPET_ENABLE_ASSIST;
settings.profile.options.EGGPET_ENABLE_ASSIST = false;
mainPet:Return();
for i=1, inventory.MaxSlots, 1 do
local item = inventory.BagSlot[i];
local itemName = string.lower(item.Name);
if (string.find(itemName, ".*pet egg")) then
printf("Found a pet egg at slot "..i.." called "..item.Name.."\n");
local egg = CPetEgg(item);
if (egg) then
if (egg.Level <= mainPet.Level) then
local reagentPet = egg:extract(slotToUse);
if (mainPet and reagentPet) then
mainPet:merge(reagentPet);
end;
else
printf("Egg level was too high\n");
end;
end;
end;
end;
settings.profile.options.EGGPET_ENABLE_ASSIST = tmp;
Code: Select all
local PM = {}
PM.doMerge = function(_target, _source)
--merges the _source egg into the _target egg
if ((_source == nil) or (not PM.petExists(_source))) then
printf("Source egg is not valid\n");
end;
if ((_target == nil) or (not PM.petExists(_target))) then
printf("Target egg is not valid\n");
end;
if (_target.eggSlot == _source.eggSlot) then
printf("Source and Target are the same Egg!!!\n");
end;
if (_target.Level < _source.Level) then
printf("Target level is less than Source level!!!\n");
end;
local oldAssist = settings.profile.options.EGGPET_ASSIST_SLOT;
settings.profile.options.EGGPET_ASSIST_SLOT = false;
_source:Return();
_target:Return();
_target:merge(_source);
settings.profile.options.EGGPET_ASSIST_SLOT = oldAssist;
end;
PM.getEggsInInventory = function()
local result = {};
inventory:update();
for i=1, inventory.MaxSlots, 1 do
local item = inventory.BagSlot[i];
local itemName = string.lower(item.Name);
if (string.find(itemName, ".*pet egg")) then
printf("Found a pet egg at slot "..i.." called "..item.Name.."\n");
local egg = CPetEgg(item);
if (egg) then
table.insert(result, egg);
end;
end;
end;
table.sort(result, function(a,b) return a.Level < b.Level end);
end;
PM.petExists = function(_pet)
return (_pet.eggSlot ~= nil) and (_pet.eggSlot ~= 0);
end;
PM.runCrossMerging = function(_slot1, _slot2)
local slot1 = _slot1;
local slot2 = _slot2;
local Pet1 = CEggPet(slot1);
local Pet2 = CEggPet(slot2);
local eggs = PM.getEggsInInventory();
if (#eggs < 2) then
printf("Not enough eggs found\n");
end;
local q = CQueue(fase);
for k,v in pairs(eggs) do
q:push(v);
end;
local currentPet = Pet1;
local egg = {};
if (not PM.petExists(Pet1)) then
egg = eggs:pop();
Pet1 = egg:extract(slot1);
currentPet = Pet1;
end;
if (not PM.petExists(Pet2)) then
egg = eggs:pop();
Pet2 = egg:extract(slot2);
currentPet = Pet2;
end;
repeat
local otherPet = Pet1;
if (currentPet == Pet1) then otherPet = Pet2; end;
currentPet:merge(otherPet);
currentPet = Pet1;
egg = eggs:pop();
if (not PM.petExists(Pet1)) then
Pet1 = egg:extract(slot1);
currentPet = Pet1;
end;
if (not PM.petExists(Pet2)) then
Pet2 = egg:extract(slot2);
currentPet = Pet2;
end;
Pet1:update();
Pet2:update();
until ((q:isEmpty()) or (not PM.petExists(Pet1)) or (not PM.petExists(Pet2)));
end;
Code: Select all
CQueue = class(
function(self, _debug)
self.Debug = _debug or false;
self.List = {first = 0, last = -1};
end
)
function CQueue:isEmpty()
if (self.Debug) then printf("q: first="..tostring(self.List.first)..", last="..tostring(self.List.last).."\n"); end;
return (self.List.first > self.List.last);
end;
function CQueue:count()
return (self.List.last - self.List.first)+1;
end;
function CQueue:push(item)
if (item) then
if (self.Debug) then printf("q: pushing "..tostring(item).."\n"); end;
local last = self.List.last + 1
if (self.Debug) then printf("q: old last "..tostring(last-1).."->"..tostring(last).."\n"); end;
self.List.last = last
self.List[last] = item
if (self.Debug) then printf("q: self.List["..tostring(last).."] = "..tostring(self.List[last]).."\n"); end;
end;
end;
function CQueue:pop()
local first = self.List.first
if (self.Debug) then printf("q: popping "..tostring(first).."\n"); end;
if first > self.List.last then error("list is empty") end
local value = self.List[first]
if (self.Debug) then printf("popping: value "..tostring(value).."\n"); end;
self.List[first] = nil -- to allow garbage collection
self.List.first = first + 1
if (self.Debug) then printf("q: new first "..tostring(first+1).."\n"); end;
return value
end;
function CQueue:peek()
local first = self.List.first
if first > self.List.last then error("list is empty") end
local value = self.List[first]
return value
end