Advertisement
FalownPSA

statics.lua

Oct 13th, 2014
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.74 KB | None | 0 0
  1. --Copyright (c) 2013, Byrthnoth
  2. --All rights reserved.
  3.  
  4. --Redistribution and use in source and binary forms, with or without
  5. --modification, are permitted provided that the following conditions are met:
  6.  
  7. --    * Redistributions of source code must retain the above copyright
  8. --      notice, this list of conditions and the following disclaimer.
  9. --    * Redistributions in binary form must reproduce the above copyright
  10. --      notice, this list of conditions and the following disclaimer in the
  11. --      documentation and/or other materials provided with the distribution.
  12. --    * Neither the name of <addon name> nor the
  13. --      names of its contributors may be used to endorse or promote products
  14. --      derived from this software without specific prior written permission.
  15.  
  16. --THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. --ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. --WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. --DISCLAIMED. IN NO EVENT SHALL <your name> BE LIABLE FOR ANY
  20. --DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. --(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. --LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. --ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. --(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. --SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26.  
  27. -- Convert the spells and job abilities into a referenceable list of aliases --
  28.  
  29. unify_prefix = {['/ma'] = '/ma', ['/magic']='/ma',['/jobability'] = '/ja',['/ja']='/ja',['/item']='/item',['/song']='/ma',
  30.     ['/so']='/ma',['/ninjutsu']='/ma',['/weaponskill']='/ws',['/ws']='/ws',['/ra']='/ra',['/rangedattack']='/ra',['/nin']='/ma',
  31.     ['/throw']='/ra',['/range']='/ra',['/shoot']='/ra',['/monsterskill']='/ms',['/ms']='/ms',['/pet']='/ja',['Mon']='Monster '}
  32.  
  33. action_type_map = {['/ja']='Ability',['/jobability']='Ability',['/so']='Magic',['/song']='Magic',['/ma']='Magic',['/magic']='Magic',['/nin']='Magic',['/ninjutsu']='Magic',
  34.     ['/ra']='Ranged Attack',['/range']='Ranged Attack',['/throw']='Ranged Attack',['/shoot']='Ranged Attack',['/ms']='Ability',['/monsterskill']='Ability',
  35.     ['/ws']='Ability',['/weaponskill']='Ability',['/item']='Item',['/pet']='Ability',['Monster']='Monster Move'}
  36.    
  37. delay_map_to_action_type = {['Ability']=2,['Magic']=20,['Ranged Attack']=10,['Item']=10,['Monster Move']=10}
  38.    
  39. validabils = {}
  40. validabils['english'] = {['/ma'] = {}, ['/ja'] = {}, ['/ws'] = {}, ['/item'] = {}, ['/ra'] = {}, ['/ms'] = {}, ['/pet'] = {}, ['/trig'] = {}, ['/echo'] = {}}
  41. validabils['french'] = {['/ma'] = {}, ['/ja'] = {}, ['/ws'] = {}, ['/item'] = {}, ['/ra'] = {}, ['/ms'] = {}, ['/pet'] = {}, ['/trig'] = {}, ['/echo'] = {}}
  42. validabils['german'] = {['/ma'] = {}, ['/ja'] = {}, ['/ws'] = {}, ['/item'] = {}, ['/ra'] = {}, ['/ms'] = {}, ['/pet'] = {}, ['/trig'] = {}, ['/echo'] = {}}
  43. validabils['japanese'] = {['/ma'] = {}, ['/ja'] = {}, ['/ws'] = {}, ['/item'] = {}, ['/ra'] = {}, ['/ms'] = {}, ['/pet'] = {}, ['/trig'] = {}, ['/echo'] = {}}
  44.  
  45. function make_abil(abil,lang,i)
  46.     if not abil[lang] or not abil.prefix then return end
  47.     local sp,pref = abil[lang]:lower(), unify_prefix[abil.prefix:lower()]
  48.     validabils[lang][pref][sp] = i
  49. end
  50.  
  51. function make_entry(v,i)
  52.     make_abil(v,'english',i)
  53.     make_abil(v,'german',i)
  54.     make_abil(v,'french',i)
  55.     make_abil(v,'japanese',i)
  56. end
  57.  
  58. for i,v in pairs(res.spells) do
  59.     if not T{363,364}:contains(i) then
  60.         make_entry(v,i)
  61.     end
  62. end
  63.  
  64. for i,v in pairs(res.job_abilities) do
  65.     make_entry(v,i)
  66. end
  67.  
  68. for i,v in pairs(res.weapon_skills) do
  69.     v.type = 'WeaponSkill'
  70.     v.recast_id = 900
  71.     make_entry(v,i)
  72. end
  73.  
  74. for i,v in pairs(res.monster_abilities) do
  75.     v.type = 'MonsterSkill'
  76.     v.recast_id = 900
  77.     make_entry(v,i)
  78. end
  79.  
  80. for i,v in pairs(res.items) do
  81.     v.prefix = '/item'
  82.     make_entry(v,i)
  83. end
  84.    
  85. default_slot_map = T{'sub','range','ammo','head','body','hands','legs','feet','neck','waist',
  86.     'left_ear', 'right_ear', 'left_ring', 'right_ring','back'}
  87. default_slot_map[0]= 'main'
  88.  
  89. jas = {false,false,false,false,false,true,false,false,false,false,false,false,false,true,true,false}--6,14,15}
  90. readies = {false,false,false,false,false,false,true,true,true,false,false,true,false,false,false,false}--{7,8,9,12}
  91. uses = {false,true,true,true,true,false,false,false,false,false,true,false,true,false,false,false}--{2,3,4,5,11,13}
  92. unable_to_use = T{17,18,55,56,87,88,89,90,104,191,308,313,325,410,428,561,574,579,580,581,661,665,
  93.     12,16,34,35,40,47,48,49,71,72,76,78,84,91,92,95,96,106,111,128,154,155,190,192,193,198,
  94.     199,215,216,217,218,219,220,233,246,247,307,315,316,328,337,338,346,347,348,349,356,411,443,444,
  95.     445,446,514,516,517,518,523,524,525,547,568,569,575,649,660,662,666,700,701,62} -- Probably don't need some of these (event action)
  96.     -- 94 removed - "You must wait longer to perform that action." -- I think this is only sent in response to engage packets.
  97.  
  98. -- 192 : param_1 = Ability ID
  99. -- 17 : no information
  100. -- 34 : param_1 = Spell index
  101. pass_through_targs = {['<t>']=true,['<me>']=true,['<ft>']=true,['<scan>']=true,['<bt>']=true,['<lastst>']=true,
  102.     ['<r>']=true,['<pet>']=true,['<p0>']=true,['<p1>']=true,['<p2>']=true,['<p3>']=true,['<p4>']=true,
  103.     ['<p5>']=true,['<a10>']=true,['<a11>']=true,['<a12>']=true,['<a13>']=true,['<a14>']=true,['<a15>']=true,
  104.     ['<a20>']=true,['<a21>']=true,['<a22>']=true,['<a23>']=true,['<a24>']=true,['<a25>']=true,['<st>']=true,
  105.     ['<stnpc>']=true,['<stal>']=true,['<stpc>']=true,['<stpt>']=true}
  106.  
  107. avatar_element = {Ifrit=0,Titan=3,Leviathan=5,Garuda=2,Shiva=1,Ramuh=4,Carbuncle=6,
  108.     Diabolos=7,Fenrir=7,['Cait Sith']=6,['Fire Elemental']=0,['Earth Elemental']=3,['Water Elemental']=5,
  109.     ['Wind Elemental']=2,['Ice Elemental']=1,['Lightning Elemental']=4,['Light Elemental']=6,
  110.     ['Dark Elemental']=7}
  111.  
  112. encumbrance_map = {0x79,0x7F,0x7F,0x7A,0x7B,0x7C,0x7D,0x7D,0x7A,0x7E,0x80,0x80,0x80,0x80,0x7E}
  113. encumbrance_map[0] = 0x79 -- Slots mapped onto encumbrance byte values.
  114.  
  115. addendum_white = {[14]="Poisona",[15]="Paralyna",[16]="Blindna",[17]="Silena",[18]="Stona",[19]="Viruna",[20]="Cursna",
  116.     [143]="Erase",[13]="Raise II",[140]="Raise III",[141]="Reraise II",[142]="Reraise III",[135]="Reraise"}
  117.    
  118. addendum_black = {[253]="Sleep",[259]="Sleep II",[260]="Dispel",[162]="Stone IV",[163]="Stone V",[167]="Thunder IV",
  119.     [168]="Thunder V",[157]="Aero IV",[158]="Aero V",[152]="Blizzard IV",[153]="Blizzard V",[147]="Fire IV",[148]="Fire V",
  120.     [172]="Water IV",[173]="Water V",[255]="Break"}
  121.  
  122. resources_ranged_attack = {id="0",index="0",prefix="/range",english="Ranged",german="Fernwaffe",french="Attaque à dist.",japanese="飛び道具",type="Misc",element="None",targets=S{"Enemy"}}
  123.  
  124.    
  125. -- _globals --
  126. user_data_table = {
  127.     __newindex = function(tab, key, val)
  128.             rawset(tab, user_key_filter(key), val)
  129.         end,
  130.  
  131.     __index = function(tab, key)
  132.         return rawget(tab, user_key_filter(key))
  133.     end
  134.     }
  135.  
  136. --[[eq_data_table = {
  137.     __newindex = function(tab, key, val)
  138.             rawset(tab, slot_map[user_key_filter(key)], newtab)
  139.         end,
  140.  
  141.     __index = function(tab, key)
  142.         return rawget(tab, slot_map[user_key_filter(key)])
  143.     end
  144.     }]]
  145.    
  146. slot_map = make_user_table()
  147.  
  148. slot_map.main = 0
  149. slot_map.sub = 1
  150. slot_map.range = 2
  151. slot_map.ranged = 2
  152. slot_map.ammo = 3
  153. slot_map.head = 4
  154. slot_map.body = 5
  155. slot_map.hands = 6
  156. slot_map.legs = 7
  157. slot_map.feet = 8
  158. slot_map.neck = 9
  159. slot_map.waist = 10
  160. slot_map.ear1 = 11
  161. slot_map.ear2 = 12
  162. slot_map.left_ear = 11
  163. slot_map.right_ear = 12
  164. slot_map.learring = 11
  165. slot_map.rearring = 12
  166. slot_map.lear = 11
  167. slot_map.rear = 12
  168. slot_map.left_ring = 13
  169. slot_map.right_ring = 14
  170. slot_map.lring = 13
  171. slot_map.rring = 14
  172. slot_map.ring1 = 13
  173. slot_map.ring2 = 14
  174. slot_map.back = 15
  175.  
  176.  
  177.  
  178. gearswap_disabled = false
  179. not_sent_out_equip = {}
  180. command_registry = {}
  181. equip_list = {}
  182. world = make_user_table()
  183. buffactive = make_user_table()
  184. alliance = make_user_table()
  185. st_targs = {['<st>']=true,['<stpc>']=true,['<stal>']=true,['<stnpc>']=true,['<stpt>']=true}
  186. current_job_file = nil
  187. disable_table = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false}
  188. disable_table[0] = false
  189. outgoing_action_category_table = {['/ma']=3,['/ws']=7,['/ja']=9,['/ra']=16,['/ms']=25}
  190. encumbrance_table = table.reassign({},disable_table)
  191. registered_user_events = {}
  192. empty = {name="empty"}
  193. --outgoing_packet_table = {}
  194. last_refresh = 0
  195.  
  196.  
  197.  
  198. _global = make_user_table()
  199. _global.cast_delay = 0
  200. _global.cancel_spell = false
  201. _global.current_event = 'None'
  202.  
  203. _settings = {debug_mode = false, demo_mode = false, show_swaps = false}
  204.  
  205. _ExtraData = {
  206.         player = {},
  207.         spell = {},
  208.         alliance = {},
  209.         pet = {},
  210.         fellow = {},
  211.         world = {in_mog_house = false,conquest=false},
  212.     }
  213.  
  214. unbridled_learning_set = {['Thunderbolt']=true,['Harden Shell']=true,['Absolute Terror']=true,
  215.     ['Gates of Hades']=true,['Tourbillion']=true,['Pyric Bulwark']=true,['Bilgestorm']=true,
  216.     ['Bloodrake']=true,['Droning Whirlwind']=true,['Carcharian Verve']=true,['Blistering Roar']=true,
  217.     ['Uproot']=true,['Crashing Thunder']=true,['Polar Roar']=true}
  218.  
  219. tool_map = {
  220.         ['Katon: Ichi'] = res.items[1161],
  221.         ['Katon: Ni'] = res.items[1161],
  222.         ['Katon: San'] = res.items[1161],
  223.         ['Hyoton: Ichi'] = res.items[1164],
  224.         ['Hyoton: Ni'] = res.items[1164],
  225.         ['Hyoton: San'] = res.items[1164],
  226.         ['Huton: Ichi'] = res.items[1167],
  227.         ['Huton: Ni'] = res.items[1167],
  228.         ['Huton: San'] = res.items[1167],
  229.         ['Doton: Ichi'] = res.items[1170],
  230.         ['Doton: Ni'] = res.items[1170],
  231.         ['Doton: San'] = res.items[1170],
  232.         ['Raiton: Ichi'] = res.items[1173],
  233.         ['Raiton: Ni'] = res.items[1173],
  234.         ['Raiton: San'] = res.items[1173],
  235.         ['Suiton: Ichi'] = res.items[1176],
  236.         ['Suiton: Ni'] = res.items[1176],
  237.         ['Suiton: San'] = res.items[1176],
  238.         ['Utsusemi: Ichi'] = res.items[1179],
  239.         ['Utsusemi: Ni'] = res.items[1179],
  240.         ['Utsusemi: San'] = res.items[1179],
  241.         ['Jubaku: Ichi'] = res.items[1182],
  242.         ['Jubaku: Ni'] = res.items[1182],
  243.         ['Jubaku: San'] = res.items[1182],
  244.         ['Hojo: Ichi'] = res.items[1185],
  245.         ['Hojo: Ni'] = res.items[1185],
  246.         ['Hojo: San'] = res.items[1185],
  247.         ['Kurayami: Ichi'] = res.items[1188],
  248.         ['Kurayami: Ni'] = res.items[1188],
  249.         ['Kurayami: San'] = res.items[1188],
  250.         ['Dokumori: Ichi'] = res.items[1191],
  251.         ['Dokumori: Ni'] = res.items[1191],
  252.         ['Dokumori: San'] = res.items[1191],
  253.         ['Tonko: Ichi'] = res.items[1194],
  254.         ['Tonko: Ni'] = res.items[1194],
  255.         ['Tonko: San'] = res.items[1194],
  256.         ['Monomi: Ichi'] = res.items[2553],
  257.         ['Monomi: Ni'] = res.items[2553],
  258.         ['Aisha: Ichi'] = res.items[2555],
  259.         ['Myoshu: Ichi'] = res.items[2642],
  260.         ['Yurin: Ichi'] = res.items[2643],
  261.         ['Migawari: Ichi'] = res.items[2970],
  262.         ['Kakka: Ichi'] = res.items[2644],
  263.         ['Gekka: Ichi'] = res.items[8803],
  264.         ['Yain: Ichi'] = res.items[8804],
  265.     }
  266.  
  267. universal_tool_map = {
  268.         ['Katon: Ichi'] = res.items[2971],
  269.         ['Katon: Ni'] = res.items[2971],
  270.         ['Katon: San'] = res.items[2971],
  271.         ['Hyoton: Ichi'] = res.items[2971],
  272.         ['Hyoton: Ni'] = res.items[2971],
  273.         ['Hyoton: San'] = res.items[2971],
  274.         ['Huton: Ichi'] = res.items[2971],
  275.         ['Huton: Ni'] = res.items[2971],
  276.         ['Huton: San'] = res.items[2971],
  277.         ['Doton: Ichi'] = res.items[2971],
  278.         ['Doton: Ni'] = res.items[2971],
  279.         ['Doton: San'] = res.items[2971],
  280.         ['Raiton: Ichi'] = res.items[2971],
  281.         ['Raiton: Ni'] = res.items[2971],
  282.         ['Raiton: San'] = res.items[2971],
  283.         ['Suiton: Ichi'] = res.items[2971],
  284.         ['Suiton: Ni'] = res.items[2971],
  285.         ['Suiton: San'] = res.items[2971],
  286.         ['Utsusemi: Ichi'] = res.items[2972],
  287.         ['Utsusemi: Ni'] = res.items[2972],
  288.         ['Utsusemi: San'] = res.items[2972],
  289.         ['Jubaku: Ichi'] = res.items[2973],
  290.         ['Jubaku: Ni'] = res.items[2973],
  291.         ['Jubaku: San'] = res.items[2973],
  292.         ['Hojo: Ichi'] = res.items[2973],
  293.         ['Hojo: Ni'] = res.items[2973],
  294.         ['Hojo: San'] = res.items[2973],
  295.         ['Kurayami: Ichi'] = res.items[2973],
  296.         ['Kurayami: Ni'] = res.items[2973],
  297.         ['Kurayami: San'] = res.items[2973],
  298.         ['Dokumori: Ichi'] = res.items[2973],
  299.         ['Dokumori: Ni'] = res.items[2973],
  300.         ['Dokumori: San'] = res.items[2973],
  301.         ['Tonko: Ichi'] = res.items[2972],
  302.         ['Tonko: Ni'] = res.items[2972],
  303.         ['Tonko: San'] = res.items[2972],
  304.         ['Monomi: Ichi'] = res.items[2972],
  305.         ['Aisha: Ichi'] = res.items[2973],
  306.         ['Myoshu: Ichi'] = res.items[2972],
  307.         ['Yurin: Ichi'] = res.items[2973],
  308.         ['Migawari: Ichi'] = res.items[2972],
  309.         ['Kakka: Ichi'] = res.items[2972],
  310.         ['Gekka: Ichi'] = res.items[2972],
  311.         ['Yain: Ichi'] = res.items[2972],
  312.     }
  313.  
  314. region_to_zone_map = {
  315.     [4] = S{100,101,139,140,141,142,167,190},
  316.     [5] = S{102,103,108,193,196,248},
  317.     [6] = S{1,2,104,105,149,150,195},
  318.     [7] = S{106,107,143,144,172,173,191},
  319.     [8] = S{109,110,147,148,197},
  320.     [9] = S{115,116,145,146,169,170,192,194},
  321.     [10] = S{3,4,117,118,198,213,249},
  322.     [11] = S{7,8,119,120,151,152,200},
  323.     [12] = S{9,10,111,166,203,204,206},
  324.     [13] = S{5,6,112,161,162,165},
  325.     [14] = S{126,127,157,158,179,184},
  326.     [15] = S{121,122,153,154,202,251},
  327.     [16] = S{114,125,168,208,209,247},
  328.     [17] = S{113,128.174,201,212},
  329.     [18] = S{123,176,250,252},
  330.     [19] = S{124,159,160,163,205,207,211},
  331.     [20] = S{130,177,178,180,181},
  332.     [22] = S{11,12,13},
  333.     [24] = S{24,25,26,27,28,29,30,31,32},
  334.     }
  335.  
  336.  
  337. function initialize_globals()
  338.     local pl = windower.ffxi.get_player()
  339.     if not pl then
  340.         player = make_user_table()
  341.         player.vitals = {}
  342.         player.buffs = {}
  343.         player.skills = {}
  344.         player.jobs = {}
  345.         player.merits = {}
  346.     else
  347.         player = make_user_table()
  348.         table.reassign(player,pl)
  349.         if not player.vitals then player.vitals = {} end
  350.         if not player.buffs then player.buffs = {} end
  351.         if not player.skills then player.skills = {} end
  352.         if not player.jobs then player.jobs = {} end
  353.         if not player.merits then player.merits = {} end
  354.     end
  355.    
  356.     player.equipment = make_user_table()
  357.     pet = make_user_table()
  358.     pet.isvalid = false
  359.     fellow = make_user_table()
  360.     fellow.isvalid = false
  361.  
  362.     items = windower.ffxi.get_items()
  363.     if not items then
  364.         items = {
  365.                 inventory = make_inventory_table(),
  366.                 safe = make_inventory_table(),
  367.                 storage = make_inventory_table(),
  368.                 temporary = make_inventory_table(),
  369.                 satchel = make_inventory_table(),
  370.                 sack = make_inventory_table(),
  371.                 locker = make_inventory_table(),
  372.                 case = make_inventory_table(),
  373.                 wardrobe = make_inventory_table(),
  374.                 equipment = {},
  375.             }
  376.         for id,name in pairs(default_slot_map) do
  377.             items.equipment[name] = {slot = empty,bag_id=0}
  378.         end
  379.     else
  380.         if not items.inventory then items.inventory = make_inventory_table() else
  381.             items.inventory[0] = make_empty_item_table(0) end
  382.         if not items.safe then items.safe = make_inventory_table()  else
  383.             items.safe[0] = make_empty_item_table(0) end
  384.         if not items.storage then items.storage = make_inventory_table()  else
  385.             items.storage[0] = make_empty_item_table(0) end
  386.         if not items.temporary then items.temporary = make_inventory_table()  else
  387.             items.temporary[0] = make_empty_item_table(0) end
  388.         if not items.satchel then items.satchel = make_inventory_table()  else
  389.             items.satchel[0] = make_empty_item_table(0) end
  390.         if not items.sack then items.sack = make_inventory_table()  else
  391.             items.sack[0] = make_empty_item_table(0) end
  392.         if not items.locker then items.locker = make_inventory_table()  else
  393.             items.locker[0] = make_empty_item_table(0) end
  394.         if not items.case then items.case = make_inventory_table()  else
  395.             items.case[0] = make_empty_item_table(0) end
  396.         if not items.wardrobe then items.wardrobe = make_inventory_table()  else
  397.             items.wardrobe[0] = make_empty_item_table(0) end
  398.         if not items.equipment then
  399.             items.equipment = {}
  400.             for id,name in pairs(default_slot_map) do
  401.                 items.equipment[name] = {slot = empty,bag_id=0}
  402.             end
  403.         else
  404.             for id,name in pairs(default_slot_map) do
  405.                 items.equipment[name] = {
  406.                     slot   = items.equipment[name],
  407.                     bag_id = items.equipment[name..'_bag']
  408.                     }
  409.                     items.equipment[name..'_bag'] = nil
  410.                 if items.equipment[name].slot == 0 then items.equipment[name].slot = empty end
  411.             end
  412.         end
  413.     end
  414.  
  415.     local wo = windower.ffxi.get_info()
  416.     if wo then
  417.         for i,v in pairs(region_to_zone_map) do
  418.             if v:contains(wo.zone) then
  419.                _ExtraData.world.conquest = {
  420.                     region_id = i,
  421.                     region_name = res.regions[i][language],
  422.                     }
  423.                 break
  424.             end
  425.         end
  426.     end
  427. end
  428.  
  429. initialize_globals()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement