lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

[/] [trunk/] [JackdawPlugins/] [SortPack/] [Sort.lua] - Blame information for rev 143

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 112 MrJackdaw-1942
function Sort()
2 MrJackdaw-1942
        --If the bag function is enabled then close the sortbag before sorting and open it again when finished. Stops lots of errors.
3 MrJackdaw-1942
        if SortBag~=nil then
4 MrJackdaw-1942
                if SortBag:IsVisible() then Turbine.Shell.WriteLine("Sortbag window closed on sorting. Open again after sort.") SortBag:Close() closedsortbag=true end
5 MrJackdaw-1942
        end
6 MrJackdaw-1942
 
7 MrJackdaw-1942
        --An attempt to make as many variables local to this proc as possible. May avoid the crash? Either way it "feels" right to have as much data disappear as possible.
8 MrJackdaw-1942
        local VirtPack
9 MrJackdaw-1942
        local item
10 MrJackdaw-1942
        local Category
11 MrJackdaw-1942
        local CategoryText
12 MrJackdaw-1942
        local CatWeight
13 MrJackdaw-1942
        local FirstStart
14 MrJackdaw-1942
        local Name
15 MrJackdaw-1942
        local Quality
16 MrJackdaw-1942
        local QualWeight
17 MrJackdaw-1942
        local Slot
18 MrJackdaw-1942
        local Start
19 MrJackdaw-1942
 
20 MrJackdaw-1942
        Timer=Turbine.UI.Control()
21 MrJackdaw-1942
 
22 MrJackdaw-1942
        function Timer:Start()
23 MrJackdaw-1942
                Turbine.Shell.WriteLine("<rgb=#888888>Sort Started")
24 MrJackdaw-1942
                FirstStart= Turbine.Engine.GetGameTime()
25 MrJackdaw-1942
                VirtPack=analysepack()
26 MrJackdaw-1942
 
27 MrJackdaw-1942
                Slot=1
28 MrJackdaw-1942
                Start= Turbine.Engine.GetGameTime()
29 MrJackdaw-1942
                Timer:SetWantsUpdates(true)
30 MrJackdaw-1942
        end
31 MrJackdaw-1942
 
32 MrJackdaw-1942
        function Timer:Update()
33 MrJackdaw-1942
                local Time = Turbine.Engine.GetGameTime()
34 MrJackdaw-1942
                local elapsed = Time - Start
35 MrJackdaw-1942
 
36 MrJackdaw-1942
                if Slot>size then
37 MrJackdaw-1942
                        Timer:SetWantsUpdates(false)
38 MrJackdaw-1942
                        --If sortbag is loaded and the window was open before sorting, then open it again.
39 MrJackdaw-1942
                        if SortBag~=nil then
40 MrJackdaw-1942
                                if closedsortbag then closedsortbag=nil openbag() end
41 MrJackdaw-1942
                        end
42 MrJackdaw-1942
                        Timer=nil
43 MrJackdaw-1942
                        Turbine.Shell.WriteLine("<rgb=#888888>Sort finished after "..Time-FirstStart.." seconds.")
44 MrJackdaw-1942
                        return
45 MrJackdaw-1942
                end
46 MrJackdaw-1942
 
47 MrJackdaw-1942
                        --Get the name of the target item
48 MrJackdaw-1942
                        target=VirtPack[Slot].Name
49 MrJackdaw-1942
 
50 MrJackdaw-1942
                        --Get item in current slot
51 MrJackdaw-1942
                        item=backpack:GetItem(Slot)
52 MrJackdaw-1942
 
53 MrJackdaw-1942
                        --Get the name of the item in the current slot. If empty return that name as "zEmpty"
54 MrJackdaw-1942
                        if item~=nil then Name=item:GetName() else Name="zEmpty" end
55 MrJackdaw-1942
 
56 MrJackdaw-1942
                        --Turbine.Shell.WriteLine("<rgb=#888888>Slot "..Slot.." should contain "..target.." but contains ".. Name)
57 MrJackdaw-1942
 
58 MrJackdaw-1942
                        --If the Name of the current item is equal to the target name, move on.
59 MrJackdaw-1942
                        if Name==target then Slot=Slot+1 return end
60 MrJackdaw-1942
 
61 MrJackdaw-1942
                if elapsed>0.2 then
62 MrJackdaw-1942
                        --Search for the item in the rest of the pack.
63 MrJackdaw-1942
                        for i=Slot+1,size do
64 MrJackdaw-1942
                                item=backpack:GetItem(i)
65 MrJackdaw-1942
                                if item~=nil then item=item:GetName() else item="zEmpty" end
66 MrJackdaw-1942
                                if item==target then
67 MrJackdaw-1942
                                        swop(i,Slot)
68 MrJackdaw-1942
                                        Start= Turbine.Engine.GetGameTime()
69 MrJackdaw-1942
                                        return
70 MrJackdaw-1942
                                end
71 MrJackdaw-1942
                        end
72 MrJackdaw-1942
                        Turbine.Shell.WriteLine("<rgb=#888888>Should never get here! Error in Update function. Did your inventory change during the sort? Restarting!")
73 MrJackdaw-1942
                        Timer:SetWantsUpdates(false)
74 MrJackdaw-1942
                        Timer:Start()
75 MrJackdaw-1942
                end
76 MrJackdaw-1942
        end
77 MrJackdaw-1942
 
78 MrJackdaw-1942
        function swop(i,j)
79 MrJackdaw-1942
 
80 MrJackdaw-1942
                if backpack:GetItem(j)==backpack:GetItem(i) then return end
81 MrJackdaw-1942
 
82 MrJackdaw-1942
                item=backpack:GetItem(j)
83 MrJackdaw-1942
 
84 MrJackdaw-1942
                if item~=nil then
85 MrJackdaw-1942
                        backpack:PerformItemDrop(item,i, false)
86 MrJackdaw-1942
                        return
87 MrJackdaw-1942
                end
88 MrJackdaw-1942
 
89 MrJackdaw-1942
                item=backpack:GetItem(i)
90 MrJackdaw-1942
 
91 MrJackdaw-1942
                if item~=nil then
92 MrJackdaw-1942
                        backpack:PerformItemDrop(item,j, false)
93 MrJackdaw-1942
                        return
94 MrJackdaw-1942
                end
95 MrJackdaw-1942
 
96 MrJackdaw-1942
                Turbine.Shell.WriteLine("<rgb=#888888>Should never be seen. Error in Swop function.")
97 MrJackdaw-1942
                Timer:SetWantsUpdates(false)
98 MrJackdaw-1942
                Timer:Start()
99 MrJackdaw-1942
        end
100 MrJackdaw-1942
 
101 MrJackdaw-1942
        Timer:Start()
102 MrJackdaw-1942
end

All times are GMT -5. The time now is 06:39 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui