Advertisement
zSatan

Amplifier Handler

Feb 19th, 2018
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.99 KB | None | 0 0
  1. --[[
  2. *******************************************************************************************************************************
  3. ###############################################################################################################################
  4. *******************************************************************************************************************************
  5.     Installation:
  6.         1) Change 'path' on ampData.Conf to you desired save path.
  7.         2) Setup ampData.Fruit to have the amp, bonuses, time in minutes that the amp will provide upon use as the value
  8.             eg:
  9.                 [1128] = { Bonus = {'EXP'} , Rate = 4 , MinLv = 00, MaxLv = 40 , Min = 05},
  10.                 Means the item 1128 will provide EXP, 2x bonus (4/2), no minimum lv req, can be used until lv40 and 5min duration
  11.                
  12.                 As well you can provide either just EXP or EXP and DROP in a amplifier, here a eg:
  13.                 [0898] = { Bonus = {'EXP','DROP'} , Rate = 4 , MinLv = 30, MaxLv = lm , Min = 15}, 
  14.         3) Paste the codes inside function AmplifierADS(ignore, role) at cha_timer and remove Hook:AddPostHook if you don't have custom_timer
  15.         4) Open exp_and_level.lua
  16.             Find at GetExp_PKM(dead, atk):
  17.                 if ChaIsBoat (k[item_host] ) == 1 then
  18.                     local ship_lv = GetChaAttr ( k[item_host] , ATTR_LV )
  19.                     local shipowner_lv  = GetChaAttr ( TurnToCha ( k[item_host] ) , ATTR_LV )  
  20.                     local ship_exp = GetChaAttr ( k[item_host] , ATTR_CEXP )
  21.                     local ship_expadd = math.floor ( math.min ( 7 , ( dead_lv / 10 + 2 ) ) )
  22.                     local lv_limit = math.min ( ship_lv , shipowner_lv ) - 10
  23.                     if dead_lv >= lv_limit then
  24.                         ship_exp = ship_exp + ship_expadd
  25.                         SetCharaAttr (  ship_exp , k[item_host] ,ATTR_CEXP )
  26.                     end
  27.                 end
  28.             Replace with:
  29.                 if ChaIsBoat(k[item_host]) == 1 then
  30.                     local SHIP_RAID                             = 1    
  31.                     local StateLv                               = ampData.GetChaStateLv(TurnToCha(k[item_host]), 'EXP')
  32.                     if StateLv > 0 and StateLv <= 20 then
  33.                         SHIP_RAID                               = SHIP_RAID * StateLv/2
  34.                     end    
  35.                    
  36.                     local ship_lv                               = GetChaAttr(k[item_host], ATTR_LV)
  37.                     local shipowner_lv                          = GetChaAttr(TurnToCha(k[item_host]), ATTR_LV)  
  38.                     local ship_exp                              = GetChaAttr(k[item_host], ATTR_CEXP)
  39.                     local ship_expadd                           = math.floor(math.min(7, (dead_lv/10 + 2)))
  40.                     local lv_limit                              = math.min(ship_lv, shipowner_lv) - 10
  41.                     if dead_lv >= lv_limit then
  42.                         ship_exp                                = ship_exp + ship_expadd
  43.                         SetCharaAttr(ship_exp * SHIP_EXP * SHIP_RAID, k[item_host] ,ATTR_CEXP)
  44.                     end
  45.                 end        
  46.        
  47.             Find at ShareTeamEXP(dead, team_atker, dead_exp, The_Killer, expsource):
  48.                 local EXP_RAID_STATE = 1
  49.                 local StateLv = GetChaStateLv ( t[i] , STATE_SBJYGZ )
  50.                 if StateLv > 0 and StateLv <= 10 then
  51.                     if StateLv == 1 then
  52.                         EXP_RAID_STATE = StateLv + 1
  53.                     end
  54.                     if StateLv == 2 then
  55.                         EXP_RAID_STATE = 2
  56.                     end
  57.                     if StateLv == 3 then
  58.                         EXP_RAID_STATE = 2.5
  59.                     end
  60.                     if StateLv == 4 then
  61.                         EXP_RAID_STATE = 5
  62.                     end
  63.                     if StateLv == 5 then
  64.                         EXP_RAID_STATE = 3
  65.                     end
  66.                 end
  67.             Replace with:
  68.                 local EXP_RAID_STATE                            = 1
  69.                 local StateLv                                   = ampData.GetChaStateLv(t[i], 'EXP')
  70.                 if StateLv > 0 and StateLv <= 20 then
  71.                     EXP_RAID_STATE                              = StateLv/2
  72.                 end
  73.  
  74.             Find GetExp_MKP(dead , atk) and paste the following inside:
  75.                 AmpDeathPunish(dead, atk)  
  76.             Do the same above with GetExp_PKP(dead, atk)
  77.         5) Open skilleffect.lua
  78.             Find at Check_Baoliao(ATKER, DEFER, ...):
  79.                 local StateLv = GetChaStateLv(ATKER, STATE_SBJYGZ)
  80.                 if StateLv >= 0 and StateLv <= 10 then
  81.                     if StateLv == 1 then
  82.                         MF_RAID_STATE = StateLv + 1
  83.                     end
  84.                     if StateLv == 2 then
  85.                         MF_RAID_STATE = 2.5
  86.                     end
  87.                     if StateLv == 3 then
  88.                         MF_RAID_STATE = 3
  89.                     end
  90.                 end    
  91.             Replace with:
  92.                 local StateLv = ampData.GetChaStateLv(ATKER, 'DROP')
  93.                 if StateLv > 0 and StateLv <= 20 then
  94.                     MF_RAID_STATE = StateLv/2
  95.                 end    
  96.         6) Load this file with DoFile()
  97.        
  98.     Information:
  99.         1) Database file named with every single PlayerID
  100.         2) No longer use STATES to provide EXP or DROP bonus to players
  101.         3) Upon getting killed (by monsters and players), players will lose their bonus
  102.         4) EXP and DROP rate will persist throughout diconnection and/or server restart
  103.         5) Every couple minutes, players will receive a message on the remaining time
  104.         6) Players will not be allowed to use same or lower tier amps if another tier activated
  105.         7) Players will be notified when an amp has come to an end
  106.         8) Bonuses will work while player sailing
  107.         9) Global function to all amplifiers PKO_AMP_SYS. Must replace original function on amps at ItemInfo.txt to this new one!
  108.         10) Fixed amps bonuses based on their description
  109. --]]
  110. --*-----------------------------------------*--
  111. --* dir parent  : addon                     *--
  112. --* File name   : AmpHandler.lua            *--
  113. --* Last Mod    : 02/17/2018 - 02:20PM      *--
  114. --* Created by  : Eviles                    *--
  115. --* Discord     : #2759                     *--
  116. --* Credits     : Billy, KONG               *--
  117. --*-----------------------------------------*--
  118. print('* Loading <AmpHandler> init.lua')
  119.  
  120. local lm                                            = LV_LIMIT
  121.  
  122. ampData                                             = {}
  123.     ampData.Temp                                    = {}
  124.     ampData.Conf                                    = {
  125.         path                                        = GetResPath('script/addon/AmpHandler/data/')
  126.     }
  127.    
  128. function ampData.CreateDB(file)
  129.     t = io.open(file, 'r')
  130.     if t ~= nil then
  131.         io.close(t)
  132.     else
  133.         table.save({},file, 'w')
  134.     end
  135. end
  136.  
  137. function ampData.GetChaStateLv(role, type)
  138.     local chaId                                     = GetCharID(role)
  139.     if file_exists(ampData.Conf['path']..chaId..'.txt') == true then
  140.         local data                                  = table.load(ampData.Conf['path']..chaId..'.txt', 'r')
  141.         local chaId                                 = GetCharID(role)
  142.         if data ~= nil then
  143.             if data[type] ~= nil then
  144.                 return data[type].Rate
  145.             end
  146.         end
  147.     end
  148.     return 0
  149. end
  150.  
  151. function ampData.GetChaStateTime(role, type)
  152.     local chaId                                     = GetCharID(role)
  153.     if file_exists(ampData.Conf['path']..chaId..'.txt') == true then
  154.         local data                                  = table.load(ampData.Conf['path']..chaId..'.txt', 'r')
  155.         if data ~= nil then
  156.             if data[type] ~= nil then
  157.                 return data[type].Time
  158.             end
  159.         end
  160.     end
  161.     return 0
  162. end
  163.  
  164. function AmplifierADS(ignore, role)
  165.     local chaId                                         = GetCharID(role)
  166.     if file_exists(ampData.Conf['path']..chaId..'.txt') == true then   
  167.         local data                                      = table.load(ampData.Conf['path']..chaId..'.txt', 'r')
  168.         if data ~= nil then
  169.             if data['EXP'] ~= nil then
  170.                 if os.time() < data['EXP'].Time then
  171.                     local expTime                       = data['EXP'].Time - os.time()
  172.                     local expState                      = data['EXP'].Rate
  173.                     if ampData.Temp['EXP'] == nil then
  174.                         ampData.Temp['EXP']             = {}
  175.                     end
  176.                    
  177.                     if ampData.Temp['EXP'][chaId] == nil then
  178.                         local xpcycle                   = math.random(120, 240)
  179.                         ampData.Temp['EXP'][chaId]      = xpcycle
  180.                     end
  181.                    
  182.                     if math.mod(now_tick, ampData.Temp['EXP'][chaId]) == 0 and now_tick > 0 then
  183.                         BickerNotice(role, 'Remaining '..(expState/2)..'x EXP: '..ToClockFormat(expTime)..'!')
  184.                         ampData.Temp['EXP'][chaId]      = nil
  185.                     end
  186.                 end
  187.                
  188.                 local expState                          = data['EXP'].Rate
  189.                 if os.time() >= data['EXP'].Time then
  190.                     if expState ~= 0 then
  191.                         BickerNotice(role, (expState/2)..'x EXP bonus has vanished...')
  192.                         data['EXP']                 = nil
  193.                         table.save(data, ampData.Conf['path']..chaId..'.txt', 'w')
  194.                     end
  195.                 end
  196.             end
  197.                
  198.             if data['DROP'] ~= nil then
  199.                 if os.time() < data['DROP'].Time then
  200.                     local dropTime                      = data['DROP'].Time - os.time()
  201.                     local dropState                     = data['DROP'].Rate
  202.                     if ampData.Temp['DROP'] == nil then
  203.                         ampData.Temp['DROP']            = {}
  204.                     end
  205.                    
  206.                     if ampData.Temp['DROP'][chaId] == nil then
  207.                         local mfcycle                   = math.random(120, 240)
  208.                         ampData.Temp['DROP'][chaId]     = mfcycle
  209.                     end
  210.                    
  211.                     if math.mod(now_tick, ampData.Temp['DROP'][chaId]) == 0 and now_tick > 0 then
  212.                         BickerNotice(role, 'Remaining '..(dropState/2)..'x DROP: '..ToClockFormat(dropTime)..'!')
  213.                         ampData.Temp['DROP'][chaId]     = nil
  214.                     end
  215.                 end
  216.                
  217.                 local dropState                         = data['DROP'].Rate        
  218.                 if os.time() >= data['DROP'].Time then
  219.                     if dropState ~= 0 then
  220.                         BickerNotice(role, (dropState/2)..'x DROP bonus has vanished...')
  221.                         data['DROP']                    = nil
  222.                         table.save(data, ampData.Conf['path']..chaId..'.txt', 'w')
  223.                     end
  224.                 end
  225.             end
  226.         end
  227.     end
  228. end
  229.  
  230. function AmpDeathPunish(dead, atk)
  231.     local chaId                                         = GetCharID(atk)
  232.     if file_exists(ampData.Conf['path']..chaId..'.txt') == true then
  233.         local data                                      = table.load(ampData.Conf['path']..chaId..'.txt', 'r')
  234.         if data ~= nil then
  235.             if data['EXP'] ~= nil then
  236.                 local expBonus                          = ampData.GetChaStateLv(dead, 'EXP')
  237.                 SystemNotice(dead, (expBonus/2)..'x EXP bonus has vanished...')
  238.                 data['EXP']                             = nil
  239.             end
  240.            
  241.             if data['DROP'] ~= nil then
  242.                 local dropBonus                         = ampData.GetChaStateLv(dead, 'DROP')
  243.                 SystemNotice(dead, (dropBonus/2)..'x DROP bonus has vanished...')
  244.                 data['DROP']                            = nil
  245.             end
  246.             table.save(data, ampData.Conf['path']..chaId..'.txt', 'w')
  247.         end
  248.     end
  249. end
  250.  
  251. function PKO_AMP_SYS(role, Item)
  252.     local chaId                                     = GetCharID(role)
  253.     local chaLv                                     = GetChaAttr(role, ATTR_LV)
  254.     local ampId                                     = GetItemID(Item)
  255.     local ampName                                   = GetItemName(ampId)
  256.     ampData.CreateDB(ampData.Conf['path']..chaId..'.txt')
  257.     local ampFruit                                  = {
  258.         -- EXP
  259.         [0048]                                      = { Bonus = {'EXP'} , Rate = 10 , MinLv = 00, MaxLv = 85 , Min = 02 },                      --Hairy Crab
  260.         [0056]                                      = { Bonus = {'EXP'} , Rate = 40 , MinLv = 00, MaxLv = 85 , Min = 02 },                      --Steamed Crab
  261.         [0898]                                      = { Bonus = {'EXP','DROP'} , Rate = 4 , MinLv = 30, MaxLv = lm , Min = 15 },                --Mystical Fruit
  262.         [0993]                                      = { Bonus = {'EXP'} , Rate = 20 , MinLv = 00, MaxLv = 48 , Min = 15 },                      --Super Booster
  263.         [0998]                                      = { Bonus = {'EXP'} , Rate = 20 , MinLv = 65, MaxLv = 75 , Min = 30 },                      --Thruster of Mystic
  264.         [1128]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 00, MaxLv = 40 , Min = 05 },                      --Mini Amp
  265.         [2586]                                      = { Bonus = {'EXP'} , Rate = 07 , MinLv = 76, MaxLv = lm , Min = 30 },                      --3.5X Amplifier of Strive
  266.         [2587]                                      = { Bonus = {'EXP'} , Rate = 08 , MinLv = 81, MaxLv = lm , Min = 30 },                      --4X Amplifier of Strive
  267.         [3039]                                      = { Bonus = {'EXP'} , Rate = 10 , MinLv = 00, MaxLv = 70 , Min = 30 },                      --Level pushing Machine
  268.         [3094]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 00, MaxLv = lm , Min = 30 },                      --Amp of Strive
  269.         [3095]                                      = { Bonus = {'EXP'} , Rate = 05 , MinLv = 60, MaxLv = lm , Min = 30 },                      --Hi-Amp of Strive
  270.         [3844]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 00, MaxLv = lm , Min = 15 },                      --Heaven's Berry
  271.         [3879]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 40, MaxLv = lm , Min = 15 },                      --Special Mystic Fruit
  272.         [3880]                                      = { Bonus = {'EXP'} , Rate = 05 , MinLv = 60, MaxLv = lm , Min = 15 },                      --Super Mystic Fruit
  273.         [5616]                                      = { Bonus = {'EXP'} , Rate = 20 , MinLv = 00, MaxLv = 49 , Min = 15 },                      --Novice 10X Exp Fruit
  274.         [5617]                                      = { Bonus = {'EXP'} , Rate = 10 , MinLv = 00, MaxLv = 70 , Min = 30 },                      --5X Exp Fruit
  275.         [5638]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 00, MaxLv = 40 , Min = 60+5*(chaLv-1) },          --Novice 2X Exp Fruit
  276.         [5639]                                      = { Bonus = {'EXP'} , Rate = 06 , MinLv = 50, MaxLv = lm , Min = 30 },                      --3x Exp Fruit
  277.         [5694]                                      = { Bonus = {'EXP'} , Rate = 07 , MinLv = 75, MaxLv = lm , Min = 30 },                      --3.5x EXP Amp
  278.         [5695]                                      = { Bonus = {'EXP'} , Rate = 08 , MinLv = 80, MaxLv = lm , Min = 30 },                      --4X EXP Amp
  279.         [5767]                                      = { Bonus = {'EXP'} , Rate = 06 , MinLv = 70, MaxLv = lm , Min = 30 },                      --3X EXP Amp
  280.         [5894]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 00, MaxLv = 45 , Min = 30 },                      --Enhanced Newbie Leveling Fruit
  281.         [6017]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 00, MaxLv = lm , Min = 30 },                      --Fine 2x Exp Fruit
  282.         [6405]                                      = { Bonus = {'EXP'} , Rate = 04 , MinLv = 00, MaxLv = 40 , Min = 60+5*(chaLv-1) },          --Magic Lucky Fruit    
  283.         [6406]                                      = { Bonus = {'EXP'} , Rate = 10 , MinLv = 50, MaxLv = 75 , Min = 30 },                      --Magic Blessing Fruit
  284.         [7451]                                      = { Bonus = {'EXP'} , Rate = 06 , MinLv = 50, MaxLv = lm , Min = 30 },                      --3X EXP Fruit
  285.         [8330]                                      = { Bonus = {'EXP'} , Rate = 06 , MinLv = 50, MaxLv = lm , Min = 30 },                      --3x Exp Fruit     
  286.         -- DROP
  287.         [1006]                                      = { Bonus = {'DROP'} , Rate = 04 , MinLv = 00, MaxLv = lm , Min = 15 },                     --Loveless Tear
  288.         [3096]                                      = { Bonus = {'DROP'} , Rate = 04 , MinLv = 00, MaxLv = lm , Min = 30 },                     --Amp of Luck
  289.         [3097]                                      = { Bonus = {'DROP'} , Rate = 06 , MinLv = 60, MaxLv = lm , Min = 30 },                     --Hi-Amp of Luck
  290.         [3845]                                      = { Bonus = {'DROP'} , Rate = 04 , MinLv = 00, MaxLv = lm , Min = 15 },                     --Charmed Berry
  291.         [3881]                                      = { Bonus = {'DROP'} , Rate = 05 , MinLv = 40, MaxLv = lm , Min = 15 },                     --Special Luck Fruit
  292.         [3882]                                      = { Bonus = {'DROP'} , Rate = 06 , MinLv = 60, MaxLv = lm , Min = 15 },                     --Super Luck Fruit
  293.         [5640]                                      = { Bonus = {'DROP'} , Rate = 06 , MinLv = 60, MaxLv = lm , Min = 30 },                     --3x Drop Fruit
  294.         [6018]                                      = { Bonus = {'DROP'} , Rate = 04 , MinLv = 00, MaxLv = lm , Min = 30 },                     --Fine 2x Drop Fruit
  295.         [8331]                                      = { Bonus = {'DROP'} , Rate = 06 , MinLv = 60, MaxLv = lm , Min = 30 }                      --3x Drop Fruit
  296.     }  
  297.     local data                                      = table.load(ampData.Conf['path']..chaId..'.txt', 'r')
  298.     if ampFruit[ampId] == nil then
  299.         SystemNotice(role, ampName..': is not registered!')
  300.         UseItemFailed(role)
  301.         return
  302.     end
  303.    
  304.     if chaLv < ampFruit[ampId].MinLv then
  305.         SystemNotice(role, ampName.. ': for Lv'..ampFruit[ampId].MinLv..' and above!')
  306.         UseItemFailed(role)
  307.         return
  308.     end
  309.    
  310.     if chaLv > ampFruit[ampId].MaxLv then
  311.         SystemNotice(role, ampName.. ': for Lv'..ampFruit[ampId].MaxLv..' and below!')
  312.         UseItemFailed(role)
  313.         return
  314.     end
  315.    
  316.     local duration                                  = ampFruit[ampId].Min * 60
  317.     local stateSec                                  = os.time() + duration
  318.     if data == nil then
  319.         data                                        = {}
  320.         table.save(data, ampData.Conf['path']..chaId..'.txt', 'w')
  321.     end
  322.    
  323.     local Boat                                      = 0
  324.     Boat                                            = GetCtrlBoat(role)
  325.     for k,v in pairs(ampFruit[ampId].Bonus) do
  326.         if Boat == nil then
  327.             local ampBonus                          = ampFruit[ampId].Bonus[k] 
  328.             local ampState                          = ampFruit[ampId].Rate
  329.             local chastateLv                        = ampData.GetChaStateLv(role, ampBonus)
  330.             if chastateLv > ampState then
  331.                 SystemNotice(role, 'Better or same fruit in effect. Please use again later...')
  332.                 UseItemFailed(role)
  333.                 return
  334.             end    
  335.            
  336.             if chastateLv == ampState then
  337.                 local stateTime                     = data[ampBonus].Time - os.time()      
  338.                 BickerNotice(role, 'Better fruit still in effect for '..ToClockFormat(stateTime)..'!')
  339.                 UseItemFailed(role)
  340.                 return
  341.             end    
  342.        
  343.             data[v]                                 = {Time = stateSec , Rate = ampState}
  344.             SystemNotice(role, 'Feels the effect of '..ampName..'. Granted '..(ampState/2)..'x times of '..ampBonus..' for duration '..ToClockFormat(duration)..'!')
  345.         else   
  346.             local ampBonus                          = ampFruit[ampId].Bonus[k]         
  347.             local ampState                          = ampFruit[ampId].Rate     
  348.             local chastateLv                        = ampData.GetChaStateLv(role, ampBonus)
  349.             if chastateLv > ampState then
  350.                 SystemNotice(Boat, 'Better or same fruit in effect. Please use again later...')
  351.                 UseItemFailed(Boat)
  352.                 return
  353.             end    
  354.            
  355.             if chastateLv == ampState then
  356.                 local stateTime                     = data[ampBonus].Time - os.time()      
  357.                 BickerNotice(Boat, 'Better fruit still in effect for '..ToClockFormat(stateTime)..'!')
  358.                 UseItemFailed(Boat)
  359.                 return
  360.             end    
  361.        
  362.             data[v]                             = {Time = stateSec , Rate = ampState}
  363.             SystemNotice(Boat, 'Feels the effect of '..ampName..'. Granted '..(ampState/2)..'x times of '..ampBonus..' for duration '..ToClockFormat(duration)..'!')   
  364.         end
  365.     end
  366.     table.save(data, ampData.Conf['path']..chaId..'.txt', 'w')
  367. end
  368.  
  369. Hook:AddPostHook('player_timer', AmplifierADS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement