"use strict"; var PayAmount = 0; var Price = 0.0; var PetPayAmount = 0; var PetPrice = 0; var IsInQuery = false; var SelectedPage = 1; var BackTimeOutCount = 60; var EndTimeOutCount = 300; function ShowMessage(text, time, iserror, marginTop) { var label = $.CreatePanel("Label", $.GetContextPanel(), ""); label.style["background-color"] = iserror ? "#A22C00" : "#000E"; label.style["color"] = iserror ? "#fff" : "#F37702"; label.style["padding"] = "20px"; label.style["font-size"] = "30px"; if (marginTop) label.style["margin-top"] = marginTop; label.style["horizontal-align"] = "center"; label.style["vertical-align"] = "center"; label.html = true; label.text = text; label.DeleteAsync(time > 0 ? time : 3); } function PageModeSelect(type) { if (type === "fairy") { SelectedPage = 1; $("#InputPage").visible = true; $("#PetInputPage").visible = false; $("#HtmlPage").visible = false; $("#AvalonCoin").text = ""; return; } if (type === "pet") { SelectedPage = 2; $("#InputPage").visible = false; $("#PetInputPage").visible = true; $("#HtmlPage").visible = false; $("#PetLevelText").text = ""; return; } } function ShowModeSelectTip(index) { $.DispatchEvent("DOTAShowTextTooltip", $("#PageModeToggle").GetChild(index), $.Localize("#pay_tip_mode" + index)); } function HideModeSelectTip() { $.DispatchEvent("DOTAHideTextTooltip") } function GoBack() { $("#InputPage").visible = SelectedPage === 1; $("#PetInputPage").visible = SelectedPage === 2; $("#HtmlPage").visible = false; $("#AvalonCoin").text = ""; $("#PetLevelText").text = ""; EndTimeOutCount = 0; BackTimeOutCount = 0; GameEvents.SendCustomGameEventToServer("custom_game_pay_auto_query", {}); } function Pay( method, type ) { if ((!Price || Price < 0) && (!PetPrice || PetPrice < 0)) return; $("#PayQrImg").SetImage(""); $("#InputPage").visible = false; $("#PetInputPage").visible = false; $("#HtmlPage").visible = true; $("#CompleteButton").visible = false; $("#GoBackButton").enabled = false; BackTimeOutCount = 30; GoBackTimeCount(); EndTimeOutCount = 300; EndBackTimeCount() var payType = 2; if (method === "alipay") { payType = 1; } else if (method === "wechatpay") { payType = 2; } if (type === "fairy") { GameEvents.SendCustomGameEventToServer("custom_game_pay_select", {"method":payType, "amount":PayAmount, "price":Price * 100, "type": type}); } else if (type === "pet") { GameEvents.SendCustomGameEventToServer("custom_game_pay_select", {"method":payType, "amount":PetPayAmount, "price":PetPrice * 100, "type": type}); } } function GoBackTimeCount() { if (BackTimeOutCount <= 0) { $("#GoBackButton").enabled = true; $("#GoBackButton").SetDialogVariableInt("timeout", 0) $("#CompleteButton").visible = true; return; } BackTimeOutCount--; $("#GoBackButton").SetDialogVariableInt("timeout", BackTimeOutCount) $.Schedule(1, GoBackTimeCount); } function EndBackTimeCount() { if (EndTimeOutCount <= 0) { return; } EndTimeOutCount--; var m = Math.floor(EndTimeOutCount/60); var s = EndTimeOutCount%60; var note = m > 0 ? (m + "分") : ""; note += s > 0 ? (s + "秒") : ""; if (note === "") note = "0秒(已过期,请返回)"; $("#HtmlPage").SetDialogVariable("LeftTime", note); $.Schedule(1, EndBackTimeCount); } function PayComplete() { if (IsInQuery) return; IsInQuery = true; GameEvents.SendCustomGameEventToServer("custom_game_pay_query", {}); } // 文本改变 var AvalonCoinLock = false; function OnAvalonCoinChange() { if (AvalonCoinLock) return; AvalonCoinLock=true; var AvalonCoin = $("#AvalonCoin"); var text = AvalonCoin.text; var m = text.replace(/\D+/g,""); var amount = parseInt(m); if (amount >= 10) { AvalonCoin.text = parseInt(m); } else { amount = 0; AvalonCoin.text = ""; } if (amount > 0) { // $("#PrePayButton").SetDialogVariable("Amount",((100 * amount / 2 - RandomInt(0, 100))/100).toFixed(2).toString()); if (PayAmount != amount) { PayAmount = amount; Price = (100 * amount * 0.5 - RandomInt(0, 100))/100; $("#PrePayButton").SetDialogVariable("Amount",Price.toString()); $("#HtmlPage").SetDialogVariable("Amount",Price.toString()); } } else { PayAmount = 0; Price = 0.0; $("#PrePayButton").SetDialogVariable("Amount", "0"); $("#HtmlPage").SetDialogVariable("Amount", "0"); } AvalonCoinLock = false; } // 文本改变 var PetlevelLock = false; function OnPetLevelChange() { if (PetlevelLock) return; PetlevelLock=true; var PetLevelText = $("#PetLevelText"); var text = PetLevelText.text; var m = text.replace(/\D+/g,""); var amount = parseInt(m); if (amount > 0) { PetLevelText.text = parseInt(m); } else { amount = 0; PetLevelText.text = ""; } if (amount > 0) { if (PetPayAmount != amount) { PetPayAmount = amount; PetPrice = (100 * amount * 30 - RandomInt(0, 100))/100; $("#PetPrePayButton").SetDialogVariable("Amount",PetPrice.toString()); $("#HtmlPage").SetDialogVariable("Amount",PetPrice.toString()); } } else { PetPayAmount = 0; PetPrice = 0.0; $("#PetPrePayButton").SetDialogVariable("Amount", "0"); $("#HtmlPage").SetDialogVariable("Amount", "0"); } PetlevelLock = false; } function RandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function AddAvalonCoin(num) { var AvalonCoin = $("#AvalonCoin"); var text = AvalonCoin.text; var amount = parseInt(text); if (!amount || amount < 0) amount = 0; if (num > 0) AvalonCoin.text = (amount + num); else AvalonCoin.text = ""; } function AddPetLevel(num) { var PetLevelText = $("#PetLevelText"); var text = PetLevelText.text; var amount = parseInt(text); if (!amount || amount < 0) amount = 0; if (num > 0) PetLevelText.text = (amount + num); else PetLevelText.text = ""; } var closeHandle = null; function Close() { if (closeHandle) { closeHandle(); } } function AvalonCoinInputFocus(){ // $("#PetTextPanel").SetFocus(); } function PetInputFocus() { $("#PetLevelText").SetFocus(); } ;(function(){ $("#PrePayButton").SetDialogVariable("Amount", "0"); $("#HtmlPage").SetDialogVariable("Amount", "0"); $("#HtmlPage").visible = false; $("#AvalonCoin").enabled = false; $("#InputPage").visible = SelectedPage === 1; $("#PetInputPage").visible = SelectedPage === 2; $.GetContextPanel().OnClose = function (f) { closeHandle = f }; GameEvents.Subscribe("thtd_pay_post", function (data){ if (data.code === 1) { // $("#Html").SetURL(data.url);占用性能 // $("#PayQrImg").SetImage(data.url); $("#PayQrImg").SetImage(data.method === 1 ? "s2r://panorama/images/custom_game/qr_alipay_png.vtex" : "s2r://panorama/images/custom_game/qr_wechat_png.vtex"); } else { // $("#Html").SetURL("https://qrcode/error.jpg"); $("#PayQrImg").SetImage(""); ShowMessage("获取支付码失败," + data.msg, 10, true); } }); GameEvents.Subscribe("thtd_pay_result", function (data){ IsInQuery = false; if (data.code === "0000") { ShowMessage(data.msg, 5); Game.EmitSound("Quest.Completed"); BackTimeOutCount = 0; } else { ShowMessage(data.msg, 5, true); } }); })();