bayuMIR/Mirserver/Mir200/Envir/QuestDiary/游戏功能/A2_二大陆/紫金葫芦.lua
2026-06-23 01:08:46 +08:00

198 lines
5.8 KiB
Lua

ZhiJinHuLuOBJ = Up_BaseClass:new()
ZhiJinHuLuOBJ._name = "ZhiJinHuLuOBJ"
-- NPCID
ZhiJinHuLuOBJ.id = { 189 }
for i, v in ipairs(ZhiJinHuLuOBJ.id or {}) do
Npc.clicknpcCfg[v] = ZhiJinHuLuOBJ
end
-- 配置文件
ZhiJinHuLuOBJ.cfg = Func.require("cfg_紫金葫芦")
---* 加入上线同步数据
-- Player.sycCfg[ZhiJinHuLuOBJ._name] = ZhiJinHuLuOBJ.cfg
ZhiJinHuLuOBJ.CaChe = {}
---* 允许前端调用的函数
ZhiJinHuLuOBJ.allowFunc = { "up" }
function ZhiJinHuLuOBJ:up(actor, p1, p2, p3, data)
if not Npc.CheckNPCRange(actor, 189) then
return
end
local itemOjb = GetItemByPos(actor, 16)
local itemName = getiteminfo(actor, itemOjb, ConstCfg.iteminfo.name)
if itemOjb == "0" or itemName ~= "紫金葫芦" then
Func.sendmsg9(actor, "[紫金葫芦]:#70|请先穿戴好[紫金葫芦].")
return
end
local attstr = getitemattr(actor, itemOjb, 5)
local attr = Func.splitString(attstr, "|")
if #attr >= 5 then
Func.sendmsg9(actor, "[紫金葫芦]:#70|您的葫芦已全部解锁.")
return
end
local cfg = self.cfg[#attr + 1]
if Func.takeitmes(actor, cfg.xh, true, true) then
additemattr(actor, itemOjb, 5, 3, cfg.attid, self:getattValue(actor, cfg.attid, cfg.attvalue))
refreshitem(actor, itemOjb)
end
end
----* 葫芦穿戴触发
local function ZhiJinHuLuOBJ_takeon(actor, makeIndex, where, itemName)
if itemName == "紫金葫芦" then
local open_var = Item.getint(makeIndex, VarCfg.item.int["葫芦刀魂_开启"])
if open_var == 0 then
Item.setint(actor, makeIndex, VarCfg.item.int["葫芦刀魂_开启"], 1)
Item.setint(actor, makeIndex, VarCfg.item.int["葫芦刀魂_当前进度"], 0)
Item.setint(actor, makeIndex, VarCfg.item.int["葫芦刀魂_最大进度"], 10000)
SendItemVarToc(actor, makeindex)
end
ZhiJinHuLuOBJ.changaCache(actor)
end
end
GameEvent.add(EventCfg.onTakeOnEx, ZhiJinHuLuOBJ_takeon, ZhiJinHuLuOBJ)
---* 增加酒气
function ZhiJinHuLuOBJ:addjiuqi(actor, num)
local itemOjb = GetItemByPos(actor, 16)
local itemName = getiteminfo(actor, itemOjb, ConstCfg.iteminfo.name)
if itemOjb == "0" or itemName ~= "紫金葫芦" then
return
end
local Cur_value = Item.getint(itemOjb, VarCfg.item.int["葫芦刀魂_当前进度"])
local Max_value = Item.getint(itemOjb, VarCfg.item.int["葫芦刀魂_最大进度"])
local open = Item.getint(itemOjb, VarCfg.item.int["葫芦刀魂_开启"])
if open == 0 then
return
end
if Cur_value >= Max_value then
Func.sendmsg9(actor, "[酒气护体]:#70|当前酒气已满.")
return false
end
if Func.takeitmes(actor, { { "竹叶青", num, 0 } }, true, true) then
local _value = num * 2000
local add_value = Cur_value + _value >= Max_value and Max_value or Cur_value + _value
Item.setint(actor, itemOjb, VarCfg.item.int["葫芦刀魂_当前进度"], add_value)
SendItemVarToc(actor, itemOjb)
local self_id = getbaseinfo(actor, ConstCfg.gbase.id)
self.CaChe[self_id] = add_value
self:changeBuff(actor)
end
end
---* 登陆和重载QF 缓存Cache
function ZhiJinHuLuOBJ.changaCache(actor)
local itemOjb = GetItemByPos(actor, 16)
local itemName = getiteminfo(actor, itemOjb, ConstCfg.iteminfo.name)
local self_id = getbaseinfo(actor, ConstCfg.gbase.id)
if itemOjb == "0" or itemName ~= "紫金葫芦" then
ZhiJinHuLuOBJ.CaChe[self_id] = 0
return
end
ZhiJinHuLuOBJ.CaChe[self_id] = Item.getint(itemOjb, VarCfg.item.int["葫芦刀魂_当前进度"])
ZhiJinHuLuOBJ:changeBuff(actor)
end
GameEvent.add(EventCfg.onLogin, ZhiJinHuLuOBJ.changaCache, ZhiJinHuLuOBJ)
GameEvent.add(EventCfg.onqfloadend, ZhiJinHuLuOBJ.changaCache, ZhiJinHuLuOBJ)
---* 酒气变动计算
function ZhiJinHuLuOBJ:changeBuff(actor)
local self_id = getbaseinfo(actor, ConstCfg.gbase.id)
if self.CaChe[self_id] then
if self.CaChe[self_id] >= 6000 then
if not hasbuff(actor, 10031) then
addbuff(actor, 10031)
end
if not hasbuff(actor, 10032) then
addbuff(actor, 10032)
end
else
if hasbuff(actor, 10031) then
delbuff(actor, 10031)
end
end
if self.CaChe[self_id] > 0 then
if not hasbuff(actor, 10032) then
addbuff(actor, 10032)
end
else
if hasbuff(actor, 10032) then
delbuff(actor, 10032)
end
end
else
if hasbuff(actor, 10031) then
delbuff(actor, 10031)
end
if hasbuff(actor, 10032) then
delbuff(actor, 10032)
end
end
end
---* 攻击计算
function ZhiJinHuLuOBJ.OnAttack(actor)
local itemOjb = GetItemByPos(actor, 16)
local itemName = getiteminfo(actor, itemOjb, ConstCfg.iteminfo.name)
local self_id = getbaseinfo(actor, ConstCfg.gbase.id)
if itemOjb == "0" or itemName ~= "紫金葫芦" then
ZhiJinHuLuOBJ.CaChe[self_id] = 0
return
end
local cur_value = Item.getint(itemOjb, VarCfg.item.int["葫芦刀魂_当前进度"])
if cur_value > 0 then
Item.setint(actor, itemOjb, VarCfg.item.int["葫芦刀魂_当前进度"], cur_value - 1)
local self_id = getbaseinfo(actor, ConstCfg.gbase.id)
if ZhiJinHuLuOBJ.CaChe[self_id] and ZhiJinHuLuOBJ.CaChe[self_id] > 0 then
ZhiJinHuLuOBJ.CaChe[self_id] = ZhiJinHuLuOBJ.CaChe[self_id] - 1
ZhiJinHuLuOBJ:changeBuff(actor)
end
end
end
GameEvent.add(EventCfg.onAttack, ZhiJinHuLuOBJ.OnAttack, ZhiJinHuLuOBJ)
---* 穿戴葫芦
local function ZhiJinHuLuOBJ_onTakeOffEx(actor, makeIndex, where, itemName)
if itemName == "紫金葫芦" then
local self_id = getbaseinfo(actor, ConstCfg.gbase.id)
ZhiJinHuLuOBJ.CaChe[self_id] = 0
ZhiJinHuLuOBJ:changeBuff(actor)
end
end
GameEvent.add(EventCfg.onTakeOffEx, ZhiJinHuLuOBJ_onTakeOffEx, ZhiJinHuLuOBJ)
return ZhiJinHuLuOBJ