Close
Showing results 1501 to 1510 of 2112

Threaded View

  1. #11

    Cool

    Jafula,

    Not sure if anyone will find this useful - I think they might - I wrote this to support a new quest reward selection method. This code will attempt to choose an item upgrades for each character from quest rewards, if it doesn't believe there is an upgrade, it will simply choose the most valuable item for vendoring. This is my first time writing anything in LUA, but I think dropping this code in AJMoChooseQuestReward will get you most of the way there (I've been testing in a separate addon):

    At the very top of AJMoChooseQuestReward add:
    Code:
    local numberOfQuestRewards = GetNumQuestChoices()
    Replace any explicit call to GetNumQuestChoices() with numberOfQuestRewards, for cleanliness.

    Then, in the conditional for "more than one quest reward", a new option like "AJM.db.hasChoiceAquireBestQuestRewardForCharacter " would contain the logic below:
    Code:
                            -- Choose the best item for this character, otherwise choose the most valuable to vendor:
                            local mostValuableQuestItemIndex, mostValuableQuestItemValue, bestQuestItemIndex, bestQuestItemArmorWeight = 1, 0, -1, -1
                            local armorWeights = { Plate = 4, Mail = 2, Leather = 1, Cloth = 0 }
                    
                            -- Yanked this from LibItemUtils; sucks that we need this lookup table, but GetItemInfo only 
                            -- returns an equipment location, which must first be converted to a slot value that GetInventoryItemLink understands:
                            local equipmentSlotLookup = {
                                INVTYPE_HEAD = {"HeadSlot", nil},
                                INVTYPE_NECK = {"NeckSlot", nil},
                                INVTYPE_SHOULDER = {"ShoulderSlot", nil},
                                INVTYPE_CLOAK = {"BackSlot", nil},
                                INVTYPE_CHEST = {"ChestSlot", nil},
                                INVTYPE_WRIST = {"WristSlot", nil},
                                INVTYPE_HAND = {"HandsSlot", nil},
                                INVTYPE_WAIST = {"WaistSlot", nil},
                                INVTYPE_LEGS = {"LegsSlot", nil},
                                INVTYPE_FEET = {"FeetSlot", nil},
                                INVTYPE_SHIELD = {"SecondaryHandSlot", nil},
                                INVTYPE_ROBE = {"ChestSlot", nil},
                                INVTYPE_2HWEAPON = {"MainHandSlot", "SecondaryHandSlot"},
                                INVTYPE_WEAPONMAINHAND = {"MainHandSlot", nil},
                                INVTYPE_WEAPONOFFHAND = {"SecondaryHandSlot", "MainHandSlot"},
                                INVTYPE_WEAPON = {"MainHandSlot","SecondaryHandSlot"},
                                INVTYPE_THROWN = {"RangedSlot", nil},
                                INVTYPE_RANGED = {"RangedSlot", nil},
                                INVTYPE_RANGEDRIGHT = {"RangedSlot", nil},
                                INVTYPE_FINGER = {"Finger0Slot", "Finger1Slot"},
                                INVTYPE_HOLDABLE = {"SecondaryHandSlot", "MainHandSlot"},
                                INVTYPE_TRINKET = {"Trinket0Slot", "Trinket1Slot"}
                            } 
                            
                            for questItemIndex = 1, numberOfQuestRewards do
                                local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount,
                        itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(GetQuestItemLink("choice", questItemIndex))
                                local itemId = itemLink:match("|Hitem:(%d+)")
                                local isItemEquippable = IsEquippableItem(itemId)
                                local _, _, _, _, isItemUsable = GetQuestItemInfo("choice", questItemIndex)
                    
                                if itemSellPrice > mostValuableQuestItemValue then
                                    -- Keep track of which item is most valuable:
                                    mostValuableQuestItemIndex = questItemIndex
                                    mostValuableQuestItemValue = itemSellPrice
                                end
                                
                                if isItemEquippable == 1 and isItemUsable ~= nil then
                                    -- NPC is offering us an item we can actually wear:
                                    local currentEquippedItemLinksInSlots = {}
                                    local currentWorstEquippedItemInSlot = nil
                                    
                                    -- Figure out what we already have equipped:
                                    for _, itemSlot in ipairs(equipmentSlotLookup[itemEquipLoc]) do
                                        if itemSlot ~= nil then
                                            local currentEquippedItemLinkInSlot = GetInventoryItemLink("player", GetInventorySlotInfo(itemSlot))
                                            
                                            if currentEquippedItemLinkInSlot == nil then
                                                -- Of the n item slots available, at least one of them has nothing equipped. Ergo, it is the worst:
                                                currentWorstEquippedItemInSlot = nil
                                                break
                                            else
                                                -- There's an item in this slot, get some details on it:
                                                local _, _, _, currentEquippedItemLevelInSlot, _, _, currentEquippedItemSubTypeInSlot = GetItemInfo(currentEquippedItemLinkInSlot)
                                                
                                                -- We haven't yet determined the worst item, or the item we see in this slot happens to be worse than the other item
                                                -- we saw in this partner slot (ie. a ring in one slot is worse than a ring in another slot):
                                                if currentWorstEquippedItemInSlot == nil or currentWorstEquippedItemInSlot.itemLevel > currentEquippedItemLevelInSlot then
                                                    currentWorstEquippedItemInSlot = { 
                                                        itemLink = currentEquippedItemLinkInSlot,
                                                        itemLevel = currentEquippedItemLevelInSlot,
                                                        itemSubType = currentEquippedItemSubTypeInSlot
                                                    }
                                                end
                                            end
                                        end
                                    end
                    
                                    if currentWorstEquippedItemInSlot == nil then
                                        -- We're not even wearing an item in this slot, and the vendor has something we can use, take it:
                                        bestQuestItemIndex = questItemIndex
                                    else
                                        if itemLevel > currentWorstEquippedItemInSlot.itemLevel then
                                            -- NPC is providing us with an better item than what we currently have in this slot:
                                            if armorWeights[itemSubType] ~= nil then
                                                -- Armor subtype is one which we care to select based on some priority order:
                                                if armorWeights[itemSubType] > bestQuestItemArmorWeight then
                                                    -- If this piece of armor is a better subtype (ie. Plate is better than Cloth if we can wear it):
                                                    bestQuestItemIndex = questItemIndex
                                                    bestQuestItemArmorWeight = armorWeights[itemSubType]
                                                end
                                            elseif currentWorstEquippedItemInSlot.itemSubType == itemSubType then
                                                -- This isn't a piece of armor (ie. might be a weapon) - only take it if it's the same 
                                                -- subtype as the item we are already wearing (if we're wearing a staff, and NPC offers
                                                --  a staff and a dagger, we'll take the staff):
                                                bestQuestItemIndex = questItemIndex
                                                bestQuestItemArmorWeight = -1
                                            end
                                        end
                                    end
                                end
                            end
                            
                            if bestQuestItemIndex < 0 then
                                -- If we haven't determined an item upgrade by now, just choose the one that we can vendor for the most gold:
                                bestQuestItemIndex = mostValuableQuestItemIndex
                            end
                            
                            GetQuestReward(bestQuestItemIndex)
    All yours if you want to make use of it. Only part of that code that isn't mine is the lookup table for equipment locations -> item slots, which I pulled in from LibItemUtils.

    EDIT: Here's the code on PasteBin - easier to read w/ syntax highlighting: http://pastebin.com/m5ee57c2d
    Last edited by loop : 01-09-2010 at 11:38 AM

Similar Threads

  1. Replies: 29
    Last Post: 06-27-2009, 03:09 AM
  2. Replies: 1
    Last Post: 04-23-2009, 05:57 PM
  3. Any idea when we'll see an update for Jamba?
    By Clovis in forum Macros and Addons
    Replies: 2
    Last Post: 04-20-2009, 09:21 AM
  4. Jamba Addon new features suggetion
    By Ivanhalf in forum Macros and Addons
    Replies: 3
    Last Post: 04-01-2009, 04:26 AM
  5. SickOfClickingDailies AddOn - great for multiboxers
    By puppychow in forum Macros and Addons
    Replies: 1
    Last Post: 10-16-2008, 04:14 PM

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •