Advertisement
Guest User

testsuite.lua

a guest
Oct 23rd, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.87 KB | None | 0 0
  1. require 'actions'
  2. require 'socket'
  3. --inspect = require 'inspect'
  4. autoshot = 0
  5.  
  6. ranged_hit_struct = {
  7.     hit = true,
  8.     crit = false,
  9.     start_time = 0,
  10.     end_time = 0,
  11.     diff_time = 0,
  12.     ammo_delay = 240,
  13.     weapon_delay = 582,
  14.     rapidshot = 0,
  15.     snapshot = 15,
  16.     weapon_type = 'Annihilator',
  17.     job = 'rng/war',
  18.     damage = 0,
  19.     charname = '',
  20.     mob = '',
  21.     flurry = true,
  22.     flurry2 = false,
  23. }
  24. ranged_rows = {}
  25. counter = 1
  26.  
  27. function log_hit(ranged)
  28.     local ouf = assert(io.open("D:/Program Files (x86)/Windower4/testsuite_data.sql", "a"))
  29.     str = "insert into ranged_log(id,hit,crit,start_time,end_time,diff_time,ammo_delay,weapon_delay,rapidshot,snapshot,weapon_type,job,damage,charname,mob,flurry,flurry2) values (null,"..
  30.     tostring(ranged.hit)..","..tostring(ranged.crit)..","..ranged.start_time..","..ranged.end_time..","..ranged.diff_time..","..ranged.ammo_delay..","..ranged.weapon_delay..","..ranged.rapidshot..","..
  31.     ranged.snapshot..",'"..ranged.weapon_type.."','"..ranged.job.."',"..ranged.damage..",'"..ranged.charname.."','"..ranged.mob.."',"..tostring(ranged.flurry)..","..tostring(ranged.flurry2)..
  32.     ");"
  33.     print(ranged.diff_time)
  34.     if ouf then
  35.         ouf:write(tostring(str))
  36.         ouf:write("\n")
  37.         io.close(ouf)
  38.         --print('wrote to file')
  39.     else
  40.         --print('could not open file to write')
  41.     end
  42. end
  43.  
  44.  
  45. function table.shallow_copy(t)
  46.     local t2 = {}
  47.     for k,v in pairs(t) do
  48.         t2[k] = v
  49.     end
  50.     return t2
  51. end
  52.  
  53. ranged_hit = table.shallow_copy(ranged_hit_struct)
  54.  
  55. function log_data_structure(data_object)
  56.     str = inspect(data_object)
  57.     local ouf = assert(io.open("D:/Program Files (x86)/Windower4/file_log.txt", "a"))
  58.     if ouf then
  59.         ouf:write(tostring(str))
  60.         ouf:write("\n")
  61.         io.close(ouf)
  62.         --print('wrote to file')
  63.     else
  64.         --print('could not open file to write')
  65.     end
  66. end
  67.  
  68. function find_pet_owner_name(actionpacket)
  69.     local pet = windower.ffxi.get_mob_by_id(actionpacket:get_id())
  70.     local party = windower.ffxi.get_party()
  71.    
  72.     local name = nil
  73.    
  74.     for _, member in pairs(party) do
  75.         if type(member) == 'table' and member.mob then
  76.             if member.mob.pet_index and member.mob.pet_index> 0 and pet.index == member.mob.pet_index then
  77.                 name = member.mob.name
  78.                 break
  79.             end
  80.         end
  81.     end
  82.     return name
  83. end
  84.  
  85. r_start = 0
  86. function event_action(raw_actionpacket)
  87.     local actionpacket = ActionPacket.new(raw_actionpacket)
  88.    
  89.     actionstr = actionpacket:get_category_string()
  90.  
  91.     if actionstr == 'ranged_begin' then
  92.         for target in actionpacket:get_targets() do
  93.             for subactionpacket in target:get_actions() do
  94.                 --log_data_structure(subactionpacket)
  95.                 r_start = socket.gettime()*1000
  96.             end
  97.         end
  98.     end
  99.     if actionstr == 'ranged_finish' then
  100.         for target in actionpacket:get_targets() do
  101.             for subactionpacket in target:get_actions() do
  102.                 if (mob_is_ally(actionpacket.raw.actor_id) and not mob_is_ally(target.raw.id)) then
  103.                     --log_data_structure(subactionpacket)
  104.                     ranged_hit = table.shallow_copy(ranged_hit_struct)
  105.                     ranged_hit.start_time = r_start
  106.                     ranged_hit.end_time = socket.gettime()*1000
  107.                     ranged_hit.diff_time = ranged_hit.end_time - ranged_hit.start_time
  108.                     ranged_hit.charname = actionpacket:get_actor_name()
  109.                     ranged_hit.mob = target:get_name()
  110.                     if subactionpacket.message_id == 353 then
  111.                         ranged_hit.crit = true
  112.                         ranged_hit.damage = subactionpacket.param
  113.                     elseif T{157, 352, 576, 577}:contains(subactionpacket.message_id) then
  114.                         ranged_hit.damage = subactionpacket.param
  115.                     elseif subactionpacket.message_id == 354 then
  116.                         ranged_hit.hit = false
  117.                     end
  118.                     --log_data_structure(ranged_hit)
  119.                     log_hit(ranged_hit)
  120.                 end
  121.             end
  122.         end
  123.     end
  124.    
  125.  
  126.     -- print out all melee hits to the console
  127. --  if actionstr == 'ranged_begin' then
  128. --      for target in actionpacket:get_targets() do -- target iterator
  129. --          for action in target:get_actions() do -- subaction iterator
  130. --              if action.message == 1 then -- 1 is the code for messages
  131. --                  print(string.format("%s hit %s for %d damage",
  132. --                  actionpacket:get_actor_name(), target:get_name(), action.param))
  133. --              end
  134. --          end
  135. --      end
  136. --  end
  137. --  if actionstr == 'ranged_finish' then
  138. --      for target in actionpacket:get_targets() do -- target iterator
  139. --          for action in target:get_actions() do -- subaction iterator
  140. --              log_data_structure(action)
  141. --              if action.message == 1 then -- 1 is the code for messages
  142. --                  print(string.format("%s hit %s for %d damage",
  143. --                  actionpacket:get_actor_name(), target:get_name(), action.param))
  144. --              end
  145. --          end
  146. --      end
  147. --  end
  148. end
  149.  
  150.  
  151. function recorder(raw_actionpacket)
  152.     local actionpacket = ActionPacket.new(raw_actionpacket)
  153.  
  154.     local category = actionpacket:get_category_string()
  155.  
  156.     local player = windower.ffxi.get_player()
  157.     if player ~= nil then
  158.         local player_mob = windower.ffxi.get_mob_by_id(player.id)
  159.     end
  160.     if not player or not (windower.ffxi.get_player().in_combat) then
  161.         print('no player found, exiting')
  162.         return
  163.     end
  164.     for target in actionpacket:get_targets() do
  165.         for subactionpacket in target:get_actions() do
  166.             if (mob_is_ally(actionpacket.raw.actor_id) and not mob_is_ally(target.raw.id)) then
  167.                 local main  = subactionpacket:get_basic_info()
  168.                 ranged_hit.end_time = os.time()
  169.  
  170.                 if T{157, 352, 576, 577}:contains(main.message_id) then
  171.                     dps_db:add_r_hit(target:get_name(), create_mob_name(actionpacket), main.param)
  172.                 elseif main.message_id == 353 then
  173.                     dps_db:add_r_crit(target:get_name(), create_mob_name(actionpacket), main.param)
  174.                 elseif main.message_id == 354 then
  175.                     dps_db:incr_r_misses(target:get_name(), create_mob_name(actionpacket))
  176.                 end
  177.  
  178.                 counter = counter + 1
  179.             end
  180.         end
  181.     end
  182.    
  183.    
  184. end
  185. --ActionPacket.open_listener(recorder)
  186.  
  187. ActionPacket.open_listener(event_action)
  188.  
  189. function record_shot()
  190.     start_time = os.time()
  191.     ranged_hit = table.shallow_copy(ranged_hit_struct)
  192.     ranged_hit.start_time = start_time
  193.     windower.send_command('input /ra <t>')
  194. end
  195.  
  196.  
  197. -- Returns all mob IDs for anyone in your alliance, including their pets.
  198. function get_ally_mob_ids()
  199.     local allies = T{}
  200.     local party = windower.ffxi.get_party()
  201.  
  202.     for _, member in pairs(party) do
  203.         if type(member) == 'table' and member.mob then
  204.             allies:append(member.mob.id)
  205.             if member.mob.pet_index and member.mob.pet_index> 0 and windower.ffxi.get_mob_by_index(member.mob.pet_index) then
  206.                 allies:append(windower.ffxi.get_mob_by_index(member.mob.pet_index).id)
  207.             end
  208.         end
  209.     end
  210.  
  211.     if settings.showfellow then
  212.         local fellow = windower.ffxi.get_mob_by_target("ft")
  213.         if fellow ~= nil then
  214.             allies:append(fellow.id)
  215.         end
  216.     end
  217.  
  218.     return allies
  219. end
  220.  
  221. -- Returns all mob IDs for anyone in your alliance, including their pets.
  222. function get_ally_mob_ids()
  223.     local allies = T{}
  224.     local party = windower.ffxi.get_party()
  225.  
  226.     for _, member in pairs(party) do
  227.         if type(member) == 'table' and member.mob then
  228.             allies:append(member.mob.id)
  229.             if member.mob.pet_index and member.mob.pet_index> 0 and windower.ffxi.get_mob_by_index(member.mob.pet_index) then
  230.                 allies:append(windower.ffxi.get_mob_by_index(member.mob.pet_index).id)
  231.             end
  232.         end
  233.     end
  234.  
  235.     return allies
  236. end
  237.  
  238.  
  239.  
  240. -- Returns true if is someone (or a pet of someone) in your alliance.
  241. function mob_is_ally(mob_id)
  242.     -- get zone-local ids of all allies and their pets
  243.     return get_ally_mob_ids():contains(mob_id)
  244. end
  245.  
  246.  
  247.  
  248. --function Player:add_r_hit(damage)
  249. --    -- increment hits
  250. --    self.r_hits = self.r_hits + 1
  251. --
  252. --    -- update min/max/avg melee values
  253. --    self.r_min = math.min(self.r_min, damage)
  254. --    self.r_max = math.max(self.r_max, damage)
  255. --    self.r_avg = self.r_avg * (self.r_hits - 1)/self.r_hits + damage/self.r_hits
  256. --        
  257. --    -- accumulate damage
  258. --    self.damage = self.damage + damage
  259. --end
  260. --
  261. --
  262. --function Player:add_r_crit(damage)
  263. --    -- increment crits
  264. --    self.r_crits = self.r_crits + 1
  265. --
  266. --    -- update min/max/avg melee values
  267. --    self.r_crit_min = math.min(self.r_crit_min, damage)
  268. --    self.r_crit_max = math.max(self.r_crit_max, damage)
  269. --    self.r_crit_avg = self.r_crit_avg * (self.r_crits - 1)/self.r_crits + damage/self.r_crits
  270. --        
  271. --    -- accumulate damage
  272. --    self.damage = self.damage + damage
  273. --end
  274. --
  275. --
  276. --function Player:incr_r_misses() self.r_misses = self.r_misses + 1 end
  277.  
  278. reg = {}
  279.  
  280. --windower.register_event('incoming chunk',function(id,original,modified,is_injected,is_blocked)
  281. --    if id == 0x01A then
  282. --        local packet = packets.parse('incoming', data)
  283. --      log_data_structure(packet)
  284. --    end
  285. --end)
  286.  
  287. packets = require('packets')
  288. windower.register_event('outgoing chunk',function(id,data)
  289.     if id == 0x01A then
  290.     --if id ~= 0x015 then
  291.         local packet = packets.parse('outgoing', data)
  292.         --log_data_structure(packet)
  293.     end
  294. --  if id == 0x0B6 then
  295. --      local packet = packets.parse('outgoing', data)
  296. --      print(packet['Target Name'], packet['Message'])
  297. --  end
  298. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement