Low level inventory question

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Hirumakai
Thalore
Posts: 192
Joined: Wed Aug 11, 2010 2:39 pm

Low level inventory question

#1 Post by Hirumakai »

I've been having a few issues with the Weapon Bond talent, whose general gist is to improve the weapon your wielding "on the fly" so to speak.

It works, kinda, but I need to unequip and equip the weapon to get it note the wielder effects. Also, I've seen some cases where when it removes, certain stats are lowered to below starting (i.e. 4% physical penetration, levels up to 8%, remove it, now I have a base -4% physical penetration).

What I'd like to do is when it does the upgrade bit is:
1) remove the weapon in question from its inventory (whether MAINHAND, OFFHAND, or PSIONIC FOCUS), decreasing stats as approriate
2) Changes it properties
3) Re-equip, ignoring any requirements (and hopefully increasing stats and traits appropriately)

Code: Select all

do_trigger = function(self,t,target)
		if target and not target.weapon_bond_done then
			target.weapon_bond_done = true
			if self:getInven(self.INVEN_MAINHAND) then
				for i, o in ipairs(self:getInven(self.INVEN_MAINHAND)) do
					if (o.combat and (o.combat.talented == "axe" or o.combat.talented == "sword" or o.combat.talented == "mace" or o.combat.talented == "whip" or o.combat.talented == "trident" or o.combat.talented == "knife")) or (o.special_combat and o.special_combat.talented == "shield") then
						t.do_upgrade(self,t,i,o,target)
					end
				end
			end
			if self:getInven(self.INVEN_OFFHAND) then
				for i, o in ipairs(self:getInven(self.INVEN_OFFHAND)) do
					if (o.combat and (o.combat.talented == "axe" or o.combat.talented == "sword" or o.combat.talented == "mace" or o.combat.talented == "whip" or o.combat.talented == "trident" or o.combat.talented == "knife")) or (o.special_combat and o.special_combat.talented == "shield") then
						t.do_upgrade(self,t,i,o,target)
					end
				end
			end
			if self:getInven("PSIONIC_FOCUS") then
				for i,o in ipairs(self:getInven("PSIONIC_FOCUS")) do
					if type(o) == "boolean" then o = nil end
				    if o and ((o.combat and (o.combat.talented == "axe" or o.combat.talented == "sword" or o.combat.talented == "mace" or o.combat.talented == "whip" or o.combat.talented == "trident" or o.combat.talented == "knife")) or (o.special_combat and o.special_combat.talented == "shield")) then
						t.do_upgrade(self,t,i,o,target)
					end
				end
			end
		end
The above code seems to pass along the object no problem. And I'm able to change the stats of that o object no problem. But recently, when I added the following to the do_upgrade function call, I ran into some problems:

Code: Select all

do_upgrade = function(self,t,inven,o,target)
... some stuff ...
local object = self:removeObject(inven, 1)
When I try to access the properties of "object", it doesn't seem to have them. If however, I don't removeObject, but reference o directly, it works fine.

At the end, I'm guessing I'll need to do a

Code: Select all

self:addObject(inven, object)
Any help would be appreciated.

aardvark
Wyrmic
Posts: 200
Joined: Wed Aug 22, 2012 12:16 am

Re: Low level inventory question

#2 Post by aardvark »

It's because you're passing the item's inventory position (always 1 for these slots) as do_upgrade()'s inven parameter rather than the inventory that holds the item. Try something like this:

Code: Select all

	do_trigger = function(self,t,target)
		if target and not target.weapon_bond_done then
			target.weapon_bond_done = true
			local weapons = {self:getInven(self.INVEN_MAINHAND), self:getInven(self.INVEN_OFFHAND), self:getInven("PSIONIC_FOCUS")}
			if type(weapons[3]) == "boolean" then weapons[3] = nil end
			for _, inven in pairs(weapons) do
				local o = inven[1]
				if o and ((o.combat and (o.combat.talented == "axe" or o.combat.talented == "sword" or o.combat.talented == "mace" or o.combat.talented == "whip" or o.combat.talented == "trident" or o.combat.talented == "knife")) or (o.special_combat and o.special_combat.talented == "shield")) then
					t.do_upgrade(self, t, inven, o, target)
				end
			end
		end
	end
Sorry if the logic flow changes bother you, but the copypasta was bothering me.

Hirumakai
Thalore
Posts: 192
Joined: Wed Aug 11, 2010 2:39 pm

Re: Low level inventory question

#3 Post by Hirumakai »

Your explanation clarifies it alot. Its now been implemented, tested, and pushed in the latest Spellsword version.

Thanks very much for the help.

P.S. I don't mind the copy and paste merge. It is a bit cleaner that way. :)

Post Reply