Guest User

AMW [code.lua]

a guest
Apr 17th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.40 KB | None | 0 0
  1. -- стыдно //look_at_you_
  2. local addon = {}
  3. addon.mainPanel = mainForm:GetChildChecked("MainPanel", false)
  4. local mode = "look_at_you_"
  5. local cooldown = {party = 60, raid = 180}
  6. local buff = {}
  7. local illuminate, illuminated, update_backlight_radius = common.GetAddonRelatedVisObject( "BacklightMobQuest" ), false, 70
  8. local isInit = false
  9. -----------------------------------------------------------------------------------
  10. local function place(widget,posX,posY,sizeX,sizeY,alignX,alignY,highPosX,highPosY)
  11.    
  12.     local tmp_place = widget:GetPlacementPlain()
  13.     if posX then tmp_place.posX = posX end
  14.     if posY then tmp_place.posY = posY end
  15.     if sizeX then tmp_place.sizeX = sizeX end
  16.     if sizeY then tmp_place.sizeY = sizeY end
  17.     if alignX then tmp_place.alignX = alignX end
  18.     if alignY then tmp_place.alignY = alignY end
  19.     if highPosX then tmp_place.highPosX = highPosX end
  20.     if highPosY then tmp_place.highPosY = highPosY end
  21.     widget:SetPlacementPlain(tmp_place)
  22.  
  23. end
  24. -----------------------------------------------------------------------------------
  25. local tmp_p = 0
  26.  
  27. function update_distance(p)
  28.        
  29.     tmp_p = avatar.GetPos()
  30.                
  31.     buff[p].distance_number = math.floor( math.sqrt( math.pow( (buff[p].pos.posX - tmp_p.posX), 2 ) + math.pow( (buff[p].pos.posY - tmp_p.posY), 2 ) + math.pow( (buff[p].pos.posZ - tmp_p.posZ), 2 ) ) )
  32.     buff[p].distance:SetVal( "value", common.FormatInt(buff[p].distance_number, "%d") )
  33.    
  34.     if buff[p].distance_number < update_backlight_radius then
  35.  
  36.         if not illuminated then
  37.  
  38.             mission.SetMarkerObject( illuminate, buff[p].pos )
  39.            
  40.             illuminated = true
  41.        
  42.         end
  43.  
  44.     else
  45.    
  46.         if illuminated then illuminated = false end
  47.  
  48.     end
  49.    
  50. end
  51.  
  52. function avatar_pos_changed(p)
  53.  
  54.     update_distance('l')
  55.    
  56.     if mode == 'raid' then update_distance('r') end
  57.    
  58. end
  59.  
  60. local function from_second_timer(p)
  61.  
  62.     if buff[p].cooldown > 0 then
  63.        
  64.         buff[p].time:SetVal( "value", common.FormatInt( buff[p].cooldown, "%d" ) )
  65.         buff[p].pointer:Rotate( math.rad( (360/cooldown[mode]) * buff[p].cooldown ) )
  66.         buff[p].cooldown = buff[p].cooldown - 1
  67.    
  68.     elseif buff[p].cooldown == 0 and buff[p].fix_timer == 0 then
  69.    
  70.         buff[p].time:SetVal( "value", userMods.ToWString( 'Баф' ) )
  71.         buff[p].pointer:Rotate( math.rad( 0 ) )
  72.        
  73.         if not buff[p].id then
  74.        
  75.             buff[p].fix_timer = 10
  76.        
  77.         end
  78.  
  79.     elseif buff[p].fix_timer > 0 then
  80.    
  81.         buff[p].fix_timer = buff[p].fix_timer - 1
  82.        
  83.         if buff[p].fix_timer == 0 then
  84.        
  85.             buff[p].cooldown = cooldown[mode] - 10
  86.            
  87.         end
  88.        
  89.     end
  90.    
  91. end
  92.  
  93. function second_timer(p)
  94.  
  95.     from_second_timer('l')
  96.    
  97.     if mode == 'raid' then from_second_timer('r') end      
  98.  
  99. end
  100.  
  101. local function from_track_added(p, id)
  102.  
  103.     buff[p].cooldown = 0
  104.     buff[p].id = id
  105.     buff[p].fix_timer = 0
  106.    
  107. end
  108.  
  109. function track_added(p)
  110.  
  111.     local trackInfo
  112.    
  113.     trackInfo = objects.GetTrackInfo(p.id)
  114.                
  115.     if not trackInfo then return end
  116.            
  117.     if not trackInfo.position then return end
  118.        
  119.     if userMods.FromWString( trackInfo.playerName ) ~= 'Возможности призыва' then return end
  120.        
  121.     if mode == 'party' then
  122.    
  123.         from_track_added('l', p.id)
  124.    
  125.         if math.ceil(buff.l.pos.posX) == 0 and math.ceil(buff.l.pos.posY) == 0 then
  126.        
  127.             buff.l.pos = trackInfo.position
  128.        
  129.         end
  130.    
  131.     end
  132.    
  133.     if mode == 'raid' then
  134.    
  135.         if math.ceil(trackInfo.position.posX) == math.ceil(buff.l.pos.posX) then
  136.        
  137.             from_track_added('l', p.id)
  138.        
  139.         else   
  140.        
  141.             from_track_added('r', p.id)
  142.        
  143.         end
  144.    
  145.     end
  146.  
  147. end
  148.  
  149. function track_removed(p)
  150.  
  151.     if p.id == buff.l.id then
  152.    
  153.         buff.l.cooldown = cooldown[mode]
  154.         buff.l.id = nil
  155.        
  156.     elseif p.id == buff.r.id then
  157.    
  158.         buff.r.cooldown = cooldown[mode]
  159.         buff.r.id = nil
  160.        
  161.                
  162.     end
  163.  
  164. end
  165.  
  166. function client_zone_changed(p)
  167.  
  168.     local tmp
  169.    
  170.     tmp = cartographer.GetCurrentZone().sysZoneName
  171.    
  172.     if string.sub( tmp, 1, 3 ) == 'MW_' then
  173.        
  174.         if tmp == 'MW_RaidIsle01' then
  175.        
  176.             if avatar.GetItemInfo then -- После обновления 5.0.01.19 AMW не появляется на рейдовом доминионе //look_at_you_
  177.        
  178.                 mode = 'raid'
  179.                
  180.                 initialization(true)
  181.                
  182.             else
  183.            
  184.                 mode = 'look_at_you_'
  185.            
  186.                 initialization(false)
  187.            
  188.             end
  189.                                    
  190.         else
  191.        
  192.             mode = 'party'
  193.            
  194.             initialization(true)
  195.                        
  196.         end
  197.                
  198.     elseif addon.mainPanel:IsVisible() then
  199.    
  200.         mode = 'look_at_you_'
  201.  
  202.         initialization(false)  
  203.    
  204.     end    
  205.    
  206. end
  207.  
  208. function initialization(flag)
  209.     -----
  210.     buff.l.cooldown, buff.r.cooldown, buff.l.fix_timer, buff.r.fix_timer, buff.l.distance_number, buff.r.distance_number = -1, -1, 0, 0, 0, 0  
  211.     buff.l.pos, buff.r.pos = {posX = 0, posY = 0, posZ = 0}, {posX = 0, posY = 0, posZ = 0}
  212.     buff.l.id, buff.r.id = nil, nil
  213.     -----
  214.     buff.l.time:SetVal( "value", userMods.ToWString( '*O*' ) )
  215.     buff.l.distance:SetVal( "value", userMods.ToWString( 'P_rn' ) )
  216.     -----
  217.     buff.r.time:SetVal( "value", userMods.ToWString( '*O*' ) )
  218.     buff.r.distance:SetVal( "value", userMods.ToWString( 'P_rn' ) )
  219.     -----
  220.     place(addon.mainPanel,nil,nil,60)
  221.     -----
  222.     if flag then
  223.         -----
  224.         if not isInit then
  225.             -----
  226.             if mode == 'raid' then
  227.                            
  228.                 buff.l.pos, buff.r.pos = {posX = 993.82, posY = 1282.44, posZ = 37.84}, {posX = 1574.70, posY = 1277.65, posZ = 38.62}
  229.                            
  230.                 place(addon.mainPanel,nil,nil,120)         
  231.            
  232.             end
  233.             -----
  234.             addon.mainPanel:Show(true)
  235.             -----
  236.             common.RegisterEventHandler( track_added, "EVENT_TRACK_ADDED")
  237.             common.RegisterEventHandler( track_removed, "EVENT_TRACK_REMOVED")
  238.             common.RegisterEventHandler( avatar_pos_changed, "EVENT_AVATAR_POS_CHANGED")
  239.             common.RegisterEventHandler( second_timer, "EVENT_SECOND_TIMER")
  240.             -----
  241.             collectgarbage()
  242.             -----
  243.             if debug and debug.state then
  244.  
  245.                 update_backlight_radius = debug.update_backlight_radius
  246.                
  247.             else
  248.  
  249.                 update_backlight_radius = 75
  250.  
  251.             end
  252.             -----
  253.         end
  254.         -----
  255.     else
  256.         -----
  257.         if isInit then
  258.         -----
  259.         addon.mainPanel:Show(false)
  260.         -----
  261.         common.UnRegisterEventHandler( track_added, "EVENT_TRACK_ADDED")
  262.         common.UnRegisterEventHandler( track_removed, "EVENT_TRACK_REMOVED")
  263.         common.UnRegisterEventHandler( avatar_pos_changed, "EVENT_AVATAR_POS_CHANGED")
  264.         common.UnRegisterEventHandler( second_timer, "EVENT_SECOND_TIMER")
  265.         -----
  266.         mission.SetMarkerObject(nil, nil)
  267.         -----
  268.         end
  269.         -----
  270.     end
  271.  
  272. end
  273.  
  274. function avatar_created(p)
  275.     -----
  276.     common.RegisterEventHandler( client_zone_changed, "EVENT_AVATAR_CLIENT_ZONE_CHANGED")  
  277.     -----
  278.     local panel = addon.mainPanel:GetChildChecked("panel", false)
  279.     -----
  280.     buff.l, buff.r = {}, {}
  281.     -----
  282.     buff.l.panel = mainForm:CreateWidgetByDesc(panel:GetWidgetDesc())
  283.         addon.mainPanel:AddChild(buff.l.panel)
  284.         buff.l.panel:SetName("panel.l")
  285.         buff.l.panel:SetPriority(3)
  286.     -----
  287.     buff.l.time = buff.l.panel:GetChildChecked("time", false)
  288.         buff.l.time:SetFormat( userMods.ToWString( '<header fontname="AllodsConsole" fontsize="18" shadow="1" alignx="right" color="0xFF000000"><r name="value"/></header>' ) )
  289.     -----
  290.     buff.l.timer = buff.l.panel:GetChildChecked("timer", false)
  291.     -----
  292.     buff.l.pointer = buff.l.timer:GetChildChecked("pointer", false)
  293.         buff.l.pointer:Rotate( math.rad(0) )
  294.     -----
  295.     buff.l.distance = mainForm:CreateWidgetByDesc(buff.l.time:GetWidgetDesc())
  296.         buff.l.panel:AddChild(buff.l.distance)
  297.         buff.l.distance:SetName("distance")
  298.         buff.l.distance:SetFormat( userMods.ToWString( '<header fontname="AllodsConsole" fontsize="15" shadow="1" alignx="right" color="0xFF000000"><r name="value"/></header>' ) )
  299.     -----
  300.     place(buff.l.panel,0,0,60,30,WIDGET_ALIGN_LOW,WIDGET_ALIGN_CENTER)
  301.     place(buff.l.time,0,-3,34,22,WIDGET_ALIGN_HIGH,WIDGET_ALIGN_LOW,-2)
  302.     place(buff.l.distance,0,0,60,18,WIDGET_ALIGN_HIGH,WIDGET_ALIGN_HIGH,-2,0)
  303.     place(buff.l.timer,3,0,20,24,WIDGET_ALIGN_LOW,WIDGET_ALIGN_CENTER)
  304.     place(buff.l.pointer,0,1,15,15,WIDGET_ALIGN_CENTER,WIDGET_ALIGN_CENTER)
  305.     -----
  306.     buff.r.panel = mainForm:CreateWidgetByDesc(panel:GetWidgetDesc())
  307.         addon.mainPanel:AddChild(buff.r.panel)
  308.         buff.r.panel:SetName("panel.r")
  309.     -----
  310.     buff.r.time = buff.r.panel:GetChildChecked("time", false)
  311.         buff.r.time:SetFormat( userMods.ToWString( '<header fontname="AllodsConsole" fontsize="18" shadow="1" alignx="right" color="0xFF000000"><r name="value"/></header>' ) )
  312.     -----
  313.     buff.r.timer = buff.r.panel:GetChildChecked("timer", false)
  314.     -----
  315.     buff.r.pointer = buff.r.timer:GetChildChecked("pointer", false)
  316.         buff.r.pointer:Rotate( math.rad(0) )
  317.     -----
  318.     buff.r.distance = mainForm:CreateWidgetByDesc(buff.r.time:GetWidgetDesc())
  319.         buff.r.panel:AddChild(buff.r.distance)
  320.         buff.r.distance:SetName("distance")
  321.         buff.r.distance:SetFormat( userMods.ToWString( '<header fontname="AllodsConsole" fontsize="15" shadow="1" alignx="left" color="0xFF000000"><r name="value"/></header>' ) )
  322.     -----
  323.     place(buff.r.panel,0,0,60,30,WIDGET_ALIGN_HIGH,WIDGET_ALIGN_CENTER)
  324.     place(buff.r.time,2,-3,34,22,WIDGET_ALIGN_LOW,WIDGET_ALIGN_LOW)
  325.     place(buff.r.distance,2,0,58,18,WIDGET_ALIGN_LOW,WIDGET_ALIGN_HIGH)
  326.     place(buff.r.timer,0,0,20,24,WIDGET_ALIGN_HIGH,WIDGET_ALIGN_CENTER,2)
  327.     place(buff.r.pointer,0,1,15,15,WIDGET_ALIGN_CENTER,WIDGET_ALIGN_CENTER)
  328.     -----
  329.     panel:DestroyWidget()
  330.     place(addon.mainPanel,0,0,120,30,WIDGET_ALIGN_LOW,WIDGET_ALIGN_LOW)
  331.     DnD:Init(buff.l.panel, addon.mainPanel, true, true, {1,1,1,1})
  332.     addon.mainPanel:Show(false)
  333.     -----
  334.     client_zone_changed()
  335.     -----
  336. end
  337.  
  338. function Init()
  339.  
  340.     common.RegisterEventHandler( avatar_created, "EVENT_AVATAR_CREATED")
  341.  
  342.     if avatar.IsExist() then avatar_created( {id = avatar.GetId()} ) end
  343.    
  344. end
  345.  
  346. Init()
Advertisement
Add Comment
Please, Sign In to add comment