200 lines
6.7 KiB
Plaintext
200 lines
6.7 KiB
Plaintext
--#include "data\config\item\NormalItem.txt" once
|
||
--#include "data\functions\ItemEvent\ItemUseCount.txt" once
|
||
|
||
--回城券,随机传送卷
|
||
function BackToCityFunc(sysarg,count,itemidx,itemPtr,ItemTable) --count 无效,一次只能用一个
|
||
|
||
if not Actor.canUseItem(sysarg,itemidx) then
|
||
Actor.sendTipmsg( sysarg, Lang.Script.UserItem001,ttTipmsgWindow )
|
||
return false
|
||
end
|
||
--红名
|
||
if Actor.GetNameColorData(sysarg) == 3 then
|
||
Actor.sendTipmsg(sysarg,Lang.Script.UserItem002,ttFlyTip)
|
||
return false
|
||
end
|
||
--其他限制尚未添加...
|
||
if ItemTable.usedura == false then
|
||
Actor.removeItemByPtr(sysarg, itemPtr, 1, true, Lang.Log.UserItem001, 166)
|
||
else
|
||
local duaMax = Item.getItemProperty( sysarg, itemPtr, Item.ipItemDuaMax, 0)
|
||
local dua = Item.getItemProperty( sysarg, itemPtr, Item.ipItemDua, 0 )
|
||
local duaRemain = duaMax - dua
|
||
if duaRemain < 1000 then
|
||
return false
|
||
end
|
||
dua = dua + 1000
|
||
Item.setItemProperty( sysarg, itemPtr, Item.ipItemDua, dua)
|
||
if dua == duaMax then
|
||
Actor.removeItemByPtr(sysarg, itemPtr, 1, true, Lang.Log.UserItem001, 166)
|
||
end
|
||
end
|
||
local sendType = ItemTable.type or 2
|
||
if sendType == 1 then
|
||
System.telportScene(sysarg, ItemTable.SceneId, ItemTable.x, ItemTable.y)
|
||
elseif sendType == 2 then
|
||
System.telportRandPos(sysarg)
|
||
elseif sendType == 3 then
|
||
Actor.returnCity(sysarg)
|
||
end
|
||
return true
|
||
end
|
||
|
||
|
||
--经验丹
|
||
function UseExpItemFunc(sysarg,count,itemidx,itemPtr,ItemTable) --不能堆叠,一次只能吃一个
|
||
local idx1 = 0
|
||
local idx2 = 0
|
||
local level = Actor.getIntProperty(sysarg, PROP_CREATURE_LEVEL)
|
||
for k, v in ipairs(ExpItem) do
|
||
if v.item_id == itemidx then
|
||
idx1 = k
|
||
for x,y in ipairs(v.level) do
|
||
if level >= y.min and level <= y.max then
|
||
idx2 = x
|
||
break
|
||
end
|
||
end
|
||
break
|
||
end
|
||
end
|
||
if idx1 == 0 or idx2 == 0 then
|
||
return false
|
||
end
|
||
local upLevel = ExpItem[idx1].level[idx2].level
|
||
local upExp = ExpItem[idx1].level[idx2].exp
|
||
--转数判断
|
||
local ReachLevel = Actor.AddExpReachLevel(sysarg,upExp)
|
||
local circle = Actor.getIntProperty(sysarg, PROP_ACTOR_CIRCLE)
|
||
local circleMaxLevel = System.getPlayerMaxLevel(circle)
|
||
if upExp > 0 and ReachLevel > circleMaxLevel then
|
||
local str = string.format(Lang.Script.ExpItem001,circleMaxLevel)
|
||
Actor.sendTipmsg(sysarg,str,ttFlyTip)
|
||
return
|
||
elseif upExp > 0 and level == circleMaxLevel then
|
||
local levelupExp = Actor.GetLevelExp(sysarg,level+1)
|
||
local actorExp = Actor.getUInt64Property(sysarg, PROP_ACTOR_EXP)
|
||
if actorExp + upExp > levelupExp then
|
||
local str = string.format(Lang.Script.ExpItem001,circleMaxLevel)
|
||
Actor.sendTipmsg(sysarg,str,ttFlyTip)
|
||
return
|
||
end
|
||
end
|
||
--判断是否到本转最高级
|
||
if level == circleMaxLevel and upLevel > 0 then
|
||
local str = string.format(Lang.Script.ExpItem001,circleMaxLevel)
|
||
Actor.sendTipmsg(sysarg,str,ttFlyTip)
|
||
return
|
||
end
|
||
local delCount = Actor.removeItemByPtr(sysarg, itemPtr, 1, true, Lang.Log.UserItem002, 183)
|
||
if delCount < 1 then
|
||
return false
|
||
end
|
||
if upLevel > 0 then
|
||
Actor.giveAward(sysarg, qatUpgrade,0,upLevel,0,0,0,0,183, Lang.Log.UserItem002)
|
||
end
|
||
if upExp > 0 then
|
||
Actor.giveAward(sysarg, qatExp,0,upExp,0,0,0,0,183, Lang.Log.UserItem002)
|
||
end
|
||
return true
|
||
end
|
||
|
||
--战神油
|
||
function repairAllEquipItemFunc(sysarg,count,itemidx,itemPtr,ItemTable) -- count 无效,不能批量使用
|
||
local repairTabEquip = {}
|
||
local repairTabMaxDua = {}
|
||
local equipCount = Item.getEquipCount( sysarg ) --玩家穿着装备数
|
||
for i = 1, equipCount do
|
||
local equipPtr = Item.getEquipBySortID( sysarg, i )
|
||
if equipPtr then
|
||
local curDua = Item.getItemProperty( sysarg, equipPtr, Item.ipItemDua, 0 )
|
||
local maxDua = Item.getItemProperty( sysarg, equipPtr, Item.ipItemDuaMax, 0 )
|
||
if curDua < maxDua then
|
||
table.insert(repairTabEquip, equipPtr)
|
||
table.insert(repairTabMaxDua, maxDua)
|
||
end
|
||
end
|
||
end
|
||
local msgId = Lang.Script.zf045
|
||
if #repairTabEquip > 0 then
|
||
if ItemTable.needDelete then
|
||
if Actor.removeItemByPtr(sysarg, itemPtr, 1, true, Lang.Log.l00111, 190) <= 0 then
|
||
return false
|
||
end
|
||
end
|
||
for idx, equipPtr in ipairs(repairTabEquip) do
|
||
Item.setItemProperty( sysarg, equipPtr, Item.ipItemDua, repairTabMaxDua[idx] )
|
||
end
|
||
msgId = Lang.Script.zf044
|
||
end
|
||
Actor.sendTipmsg(sysarg, msgId, ttChatWindow)
|
||
return true
|
||
end
|
||
|
||
--祝福油
|
||
function useBlessOilFunc(sysarg,count,itemidx,itemPtr,ItemTable) -- count无效,不能批量使用祝福油
|
||
local weaponPtr = Item.getEquipByType(sysarg, Item.itWeapon)
|
||
if not weaponPtr then
|
||
Actor.sendTipmsg(sysarg, Lang.Script.itemFunctionTips000001, ttFlyTip)
|
||
return false
|
||
end
|
||
local luckVal = Item.getItemProperty(sysarg, weaponPtr, Item.ipItemLuck, 0)
|
||
local msgId = string.format(Lang.Script.itemFunctionTips000002,luckVal)
|
||
if luckVal < 0 then
|
||
luckVal = luckVal + ItemTable.blessVal
|
||
if luckVal >= 0 then
|
||
msgId = string.format(Lang.Script.itemFunctionTips000003,luckVal)
|
||
else
|
||
msgId = string.format(Lang.Script.itemFunctionTips000004,-luckVal)
|
||
end
|
||
else
|
||
|
||
if ItemTable.maxLv > 0 and luckVal >= ItemTable.maxLv then
|
||
Actor.sendTipmsg(sysarg, string.format(Lang.Script.itemFunctionTips000007,ItemTable.maxLv), ttChatWindow + ttFlyTip)
|
||
return
|
||
end
|
||
|
||
local succRates = ItemTable.succRate[luckVal + ItemTable.blessVal] or ItemTable.succRate[#ItemTable.succRate]
|
||
local noChgRates = ItemTable.noChgRate[luckVal + ItemTable.blessVal] or ItemTable.noChgRate[#ItemTable.failRate]
|
||
local randVal = math.random(10000)
|
||
if randVal <= succRates then --成功
|
||
luckVal = luckVal + ItemTable.blessVal
|
||
msgId = string.format(Lang.Script.itemFunctionTips000003,luckVal)
|
||
elseif randVal > (succRates + noChgRates) then--失败
|
||
luckVal = luckVal - ItemTable.blessVal
|
||
if luckVal >= 0 then
|
||
msgId = string.format(Lang.Script.itemFunctionTips000005,luckVal)
|
||
else
|
||
msgId = string.format(Lang.Script.itemFunctionTips000006,-luckVal)
|
||
end
|
||
end
|
||
end
|
||
if Actor.removeItemByPtr(sysarg, itemPtr, 1, true, "use Blessing oil", 3) > 0 then
|
||
Item.setItemProperty(sysarg, weaponPtr, Item.ipItemLuck, luckVal )
|
||
Actor.sendTipmsg(sysarg, msgId, ttChatWindow + ttFlyTip)
|
||
end
|
||
return true
|
||
end
|
||
|
||
--初始化物品使用时回调
|
||
function UseNormalItemFunc_Init(sysarg)
|
||
--回城卷
|
||
for k, v in ipairs(BackToCity) do
|
||
GlobalItemFn[v.item_id] = {func = BackToCityFunc,params = v}
|
||
end
|
||
--经验丹
|
||
for k, v in ipairs(ExpItem) do
|
||
GlobalItemFn[v.item_id] = {func = UseExpItemFunc,params = v}
|
||
end
|
||
--战神油
|
||
for i = 1,table.getn(RepairItems) do
|
||
local x = RepairItems[i]
|
||
GlobalItemFn[x.item_id] = { func = repairAllEquipItemFunc, params = x }
|
||
end
|
||
--祝福油
|
||
for idx, x in ipairs(BlessOil) do
|
||
GlobalItemFn[x.item_id] = {func = useBlessOilFunc,params = x}
|
||
end
|
||
end
|
||
|
||
table.insert(InitFnTable, UseNormalItemFunc_Init) |