兑换点数不正确-UI界面与脚本功能修改之兑换元宝赠点门贡

一、客户端

1、补丁修改 Interface 目录下 YuanbaoExchange\YuanbaoExchange.xml

·
·
·
<Window Type="TLBB_EditBoxNormal" Name="YuanbaoExchange_Moral_Value">
        <Property Name="UnifiedSize" Value="{{1.000000,-120.000000},{0.000000,20.000000}}"/>
        <Property Name="UnifiedPosition" Value="{{0.000000,38.000000},{1.000000,-93}}"/>
        //此条表示这个输入框最大长度只能输入 5 位数
        <Property Name="MaxTextLength" Value="5" />
        //下面表示此输入框表示只能输入0-9的数字。[0-9]* 是正则验证规则
        <Property Name="ValidationString" Value="[0-9]*" />
        //下面表示是此框的事件,调用了方法。对应的方法在 UI 对应的 Lua 脚本里面定义了逻辑
        <Event Name="TextChanged" Function="YuanbaoExchange_Count_Change();" />
</Window>
YuanbaoExchange_Count_Change() 此方法为记录输入框数据改变,可以在UI界面对应的 lua 脚本里面查询到具体代码的逻辑。
·
·
·
<Window Type="TLBB_ButtonCommon" Name="YuanbaoExchange_Max">
        <Property Name="UnifiedSize" Value="{{0.000000,40.000000},{0.000000,20.000000}}"/>
        <Property Name="UnifiedPosition" Value="{{1.000000,-78.000000},{1.000000,-93}}"/>
        <Property Name="Text" Value="#{INTERFACE_XML_903}" />
        <Event Name="Clicked" Function="YuanbaoExchange_Max_Clicked();" />
</Window>

## YuanbaoExchange_Max_Clicked() 此该当为最大兑换方法,可以在UI界面对应的 lua 脚本里面查询到具体代码的逻辑。
·
·
·
<Window Type="TLBB_ButtonCommon" Name="YuanbaoExchange_OK">
    <Property Name="UnifiedPosition" Value="{{1.000000,-82.000000},{1.000000,-20.000000}" />
    <Property Name="AbsoluteSize" Value="w:40.000000 h:20.000000" />
    <Property Name="Text" Value="#{INTERFACE_XML_258}" />
    <Event Name="Clicked" Function="YuanbaoExchange_OK_Clicked();" />
</Window>

## YuanbaoExchange_OK_Clicked() 此该当为兑换方法,可以在UI界面对应的 lua 脚本里面查询到兑换的主要逻辑
·
·
·

2、补丁修改 Interface 目录下 YuanBaoExchange\YuanbaoExchange.lua

-- 此方法为记录输入框数据改变,可以在UI界面对应的 lua 脚本里面查询到具体代码的逻辑。
function YuanbaoExchange_Count_Change()
    -- 获取输入的值,点数
    local str = YuanbaoExchange_Moral_Value : GetText();
    local strNumber = 0;
    if ( str == nil ) then
        return;
    elseif( str == "" ) then
        strNumber = 1;
    else
        strNumber = tonumber( str );
    end
    str = tostring( strNumber );
    YuanbaoExchange_Moral_Value:SetTextOriginal( str );
    YuanbaoExchange_Text3 : SetText("需要花费点数:"..tostring( Exchange_Rate * strNumber ) )
end

-- 点击界面最大值的方法
function YuanbaoExchange_Max_Clicked()
    -- 最大值限定在10万,
    local maxYuanBao = 100000;
    local point2YuanBao = g_Point/Exchange_Rate;
    if point2YuanBao < 0 then point2YuanBao = 0; end

    YuanbaoExchange_Moral_Value:SetProperty("ClearOffset", "True");
    if point2YuanBao > maxYuanBao then
        YuanbaoExchange_Moral_Value:SetText(tostring(maxYuanBao));
    else
        YuanbaoExchange_Moral_Value:SetText(tostring(point2YuanBao));
    end
    YuanbaoExchange_Moral_Value:SetProperty("CaratIndex", 1024);
end

-- 调用兑换元宝,赠点的逻辑
function YuanbaoExchange_OK_Clicked()
    local str = YuanbaoExchange_Moral_Value : GetText();

    if str == nil or str == "" then
        YuanbaoExchange_Text3 : SetText("需要花费点数:0")
        PushDebugMessage("请输入要兑换的元宝数额")
        return
    end

    if tonumber(str) > 100000 then
        PushDebugMessage("每次兑换的元宝数量最多为100000点,请输入小于等于100000点的数字。")
        return
    end
    if( tonumber(str) <= 0 ) then
        PushDebugMessage("每次兑换的元宝数量最少为1点,请输入大于等于1点的数字。")
        return
    end

    --AxTrace(0,0,"YuanbaoExchange_OK_Clicked 2");
    -- 调用服务端接口,进行兑换赠点,元宝
    Clear_XSCRIPT();
        Set_XSCRIPT_Function_Name("BuyYuanbao");
        Set_XSCRIPT_ScriptID(181000);
        Set_XSCRIPT_Parameter(0,tonumber(str));
        Set_XSCRIPT_Parameter(1,tonumber(g_Point));
        Set_XSCRIPT_ParamCount(2);
    Send_XSCRIPT();

    YuanbaoExchange_Close();
end

二、服务端

1、通过调用关系,找到对应脚本。一般的版本都是在 主脚本 tlbb\Public\Data\Script\obj\qianzhuang\oqianzhuang_yuanbao.lua

-- 通过客户端调用的关系 BuyYuanbao 在里面查找到对应的方法
function x181000_BuyYuanbao( sceneId, selfId, nYuanBao, leftPoint )
    if leftPoint==0 then
        x181000_NotifyTip( sceneId, selfId, "你没有任何可兑换的点数,请充值后重试。" )
        return
    end
    x181000_NotifyTip( sceneId, selfId,"身上剩余点数:"..leftPoint..",兑换的点数:"..nYuanBao)
    local zd=ZengDian(sceneId,selfId,targetId,3)
    if nYuanBao*100000+zd>2100000000 then
        x181000_NotifyTip( sceneId, selfId, "兑换赠点的值超过系统上限,请使用一部分后再兑换。" )
        return
    end
    -- 此项,进行核心功能的调用 PRIZE_SCRIPT_ID 此ID可以在 Script.dat 里面查找到是哪个脚本
    CallScriptFunction( PRIZE_SCRIPT_ID, "AskYuanBao", sceneId, selfId, nYuanBao,nYuanBao)
end
·
·
·
-- 通过上面查找,找到兑换的核心脚本 lua
-- tlbb\Public\Data\Script\event\prize\eprize.lua
--**********************************
-- 购买 元宝
--**********************************
function x888899_AskYuanBao( sceneId, selfId, nYuanBao, nPoint )
    -- 调用引擎方法。通过回调方法进行处理。nYuanBao 和 nPoint 是由客户端传递过来。
    -- 因为传输的类型不一样。nPoint*10才能与对应的版本对应上。
    GetCharPrize(sceneId,selfId,3,999,nYuanBao,nPoint*10);
end

--**********************************
-- 购买 元宝 的返回回调函数
-- ntype 请参考 enum PRIZE_TYPE_ENUM
-- 1 代表 OPT_YUANBAO_ADD 增加元宝
--**********************************
function x888899_BuyRet( sceneId, selfId, ntype, nYuanBao, nLeftPoint )
    if( 2 == ntype ) then
        zd=nYuanBao
        local mg=nYuanBao*100000
        local t_mg=mg
        local nMenpaiPoint=GetHumanMenpaiPoint(sceneId, selfId)
        mg=mg+nMenpaiPoint
        SetHumanMenpaiPoint(sceneId, selfId, mg)
        YuanBao(sceneId,selfId,targetId,1,mg)
        ZengDian(sceneId,selfId,targetId,1,zd)
        BuyYuanBaoCount(sceneId,selfId,-1,1,nYuanBao)
        local mecount = BuyYuanBaoCount(sceneId,selfId,-1,3,0)
        local curmost = LuaFnGetWorldGlobalData(1)
        if mecount > curmost then
            LuaFnSetWorldGlobalData(1,mecount)
            local nMonsterNum = GetMonsterCount(sceneId)
            for i=0, nMonsterNum-1 do
                local MonsterId = GetMonsterObjID(sceneId,i)
                local MosDataID = GetMonsterDataID(sceneId, MonsterId )
                if MosDataID == 15735 then
                    SetCharacterName(sceneId,MonsterId,GetName(sceneId,selfId))
                end
            end
        end
        BeginEvent(sceneId)
            strText = "您成功的兑换了"..tostring(zd).."点赠点!"
            AddText(sceneId,strText)
        EndEvent(sceneId)
        DispatchMissionTips(sceneId,selfId)
    end
end

三、视频教程详情讲解