New EggPet class.

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Message
Author
BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: New EggPet class.

#201 Post by BillDoorNZ » Thu Jun 07, 2012 6:58 pm

updated to make sure pet was returned :)

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;
and some untested code for cross merging!!!! Will get around to trying it out when I get a bit of time tho.

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;
oops, this requires the following class:

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	

User avatar
gloover
Posts: 304
Joined: Wed Jul 07, 2010 4:31 am

Re: New EggPet class.

#202 Post by gloover » Wed Jun 19, 2013 3:28 pm

Hey bill.

Thanx for the idea fo cross-merging. Have tried to create my own userfunction, but I'm out of practice with my lua knowledge, so have you or someone else the working userfunction. Ist really annoying to sort the eggs by level manually then to cross-merging


thx in advance!

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: New EggPet class.

#203 Post by BillDoorNZ » Thu Jun 20, 2013 4:50 am

sorry man,

been away from the game for a long time, but getting back into it now and will be starting a new character soonish so will need to dev a pet for it too and will test it then....not sure when that will happen tho as i have yet to get up to speed with the zodiac pets etc too yet.

User avatar
gloover
Posts: 304
Joined: Wed Jul 07, 2010 4:31 am

Re: New EggPet class.

#204 Post by gloover » Thu Jun 20, 2013 6:09 am

I also have started a new character - so I'd also appreciate it if you could share your developement of "zodiac projects".
thx in advance.

wps
Posts: 74
Joined: Tue Feb 05, 2013 11:11 am

Re: New EggPet class.

#205 Post by wps » Sat Aug 03, 2013 9:01 pm

gloover wrote:Hey bill.

Thanx for the idea fo cross-merging. Have tried to create my own userfunction, but I'm out of practice with my lua knowledge, so have you or someone else the working userfunction. Ist really annoying to sort the eggs by level manually then to cross-merging


thx in advance!
I tried to write a quicksort for pet eggs in bags,
however it doesn't work out.

I adopt BillDoorNZ's sorting method to sort pet eggs in memory only, and mail to another account
that would mail the eggs by the sorted order, and use mail addon to take the mail by seq.
They will be ordered in the receiver's bag.
It's very slow, but works.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests