From 551f2ed0d872fee52e11ef40e3f3b14b2889653d Mon Sep 17 00:00:00 2001 From: JianMiau Date: Sun, 29 May 2022 22:05:59 +0800 Subject: [PATCH] [add] Slot1201 --- src/main.ts | 1 + src/script/Common/Game/Base/SlotBase.ts | 8 +- src/script/Common/Game/Slot1201.ts | 10 + .../Utils/CCExtensions/NumberExtension.ts | 198 +++++++++--------- 4 files changed, 116 insertions(+), 101 deletions(-) create mode 100644 src/script/Common/Game/Slot1201.ts diff --git a/src/main.ts b/src/main.ts index 625b274..f8483ee 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,7 @@ import locale from "element-plus/lib/locale/lang/zh-tw"; import { createApp } from "vue"; import App from "./App.vue"; import "./script/Engine/CatanEngine/CSharp/String"; +import "./script/Engine/Utils/CCExtensions/NumberExtension"; createApp(App).use(ElementPlus, { locale }).mount("#app"); diff --git a/src/script/Common/Game/Base/SlotBase.ts b/src/script/Common/Game/Base/SlotBase.ts index be327a0..38f00b1 100644 --- a/src/script/Common/Game/Base/SlotBase.ts +++ b/src/script/Common/Game/Base/SlotBase.ts @@ -2,12 +2,15 @@ import CSMessage from "../../../Base/CSMessage"; import { BJ_Casino_Bot } from "../../../BJ_Casino_Bot"; import { BJ_Casino_Bot_Slot } from "../../../BJ_Casino_Bot_Slot"; import { INetResponse } from "../../../Engine/CatanEngine/NetManagerV2/Core/INetResponse"; +import { NumberEx } from "../../../Engine/Utils/Number/NumberEx"; import { CommonSlotFgSpinRequest, CommonSlotSpinRequest } from "../Request/CommonSlotRequest"; export default class SlotBase { //#region public public get ID(): number { return this._bj_Casino_Bot.LobbyScript.Slot; } + public get FreeCount(): number { return this.GameRunData["free"][1]; } + public GameRunData: JSON = null; //#endregion @@ -44,7 +47,7 @@ export default class SlotBase { await req.SendAsync(); let resp: INetResponse = req.Result; if (resp.IsValid) { - gameRunData = resp.Data; + gameRunData = this.GameRunData = resp.Data; } else { CSMessage.NetError(resp.Method, resp.Status); } @@ -65,12 +68,13 @@ export default class SlotBase { } } if (free) { - let freeCount: number = free[1]; + let freeCount: number = this.FreeCount; await this.FreeSpin(freeCount); freeLog = `, hasFree: True, free: ${freeCount}`; } this._bj_Casino_Bot.UserData.Money = money; this._bj_Casino_Bot.SetUI(); + let scale: number = winMoney > 0 ? NumberEx.divide(winMoney, this._bj_Slot.NowBet) : 0; this._bj_Casino_Bot.AddLog(`Slot${this.ID} Spin Bet: ${this._bj_Slot.NowBet}, Money: ${money}${winMoneyLog}${freeLog}`); } diff --git a/src/script/Common/Game/Slot1201.ts b/src/script/Common/Game/Slot1201.ts new file mode 100644 index 0000000..6614476 --- /dev/null +++ b/src/script/Common/Game/Slot1201.ts @@ -0,0 +1,10 @@ +import SlotBase from "./Base/SlotBase"; + + +export default class Slot1 extends SlotBase { + //#region public + + public get FreeCount(): number { return +this.GameRunData["free"]; } + + //#endregion +} diff --git a/src/script/Engine/Utils/CCExtensions/NumberExtension.ts b/src/script/Engine/Utils/CCExtensions/NumberExtension.ts index a745286..1a67dee 100644 --- a/src/script/Engine/Utils/CCExtensions/NumberExtension.ts +++ b/src/script/Engine/Utils/CCExtensions/NumberExtension.ts @@ -1,76 +1,79 @@ -declare interface Number { - - /** - * 金額每三位數(千)加逗號, 並且補到小數點第2位 - * 輸出 41,038,560.00 - * @param precision 補到小數點第幾位 - * @param isPadZero 是否要補零 - * */ - ExFormatNumberWithComma(precision?: number, isPadZero?: boolean): string; - /** - * 基本4位數(9,999-999B-T) - * */ - ExTransferToBMK(precision?: number,offset?: number): string; - /** - * 數字轉字串, 頭補0 - * @param size - */ - Pad(size: number): string; - /** - * 四捨五入到小數點第X位 (同server計算規則) - * @param precision - */ - ExToNumRoundDecimal(precision: number): number; - /** - * 無條件捨去到小數點第X位 - * @param precision - */ - ExToNumFloorDecimal(precision: number): number; - /** - * 無條件捨去強制保留X位小數,如:2,會在2後面補上00.即2.00 - * @param precision 補到小數點第幾位 - * @param isPadZero 是否要補零 - */ - ExToStringFloorDecimal(precision: number, isPadZero?: boolean): string; - /** - * 取整數) - */ - ExToInt():number; - /** - * 小數轉整數(支援科學符號) - */ - Float2Fixed():number; - /** - * 數字長度(支援科學符號) - */ - DigitLength():number; +// declare interface Number { +declare global { + interface Number { - target: number; + /** + * 金額每三位數(千)加逗號, 並且補到小數點第2位 + * 輸出 41,038,560.00 + * @param precision 補到小數點第幾位 + * @param isPadZero 是否要補零 + */ + ExFormatNumberWithComma(precision?: number, isPadZero?: boolean): string; + /** + * 基本4位數(9,999-999B-T) + */ + ExTransferToBMK(precision?: number, offset?: number): string; + /** + * 數字轉字串, 頭補0 + * @param size + */ + Pad(size: number): string; + /** + * 四捨五入到小數點第X位 (同server計算規則) + * @param precision + */ + ExToNumRoundDecimal(precision: number): number; + /** + * 無條件捨去到小數點第X位 + * @param precision + */ + ExToNumFloorDecimal(precision: number): number; + /** + * 無條件捨去強制保留X位小數,如:2,會在2後面補上00.即2.00 + * @param precision 補到小數點第幾位 + * @param isPadZero 是否要補零 + */ + ExToStringFloorDecimal(precision: number, isPadZero?: boolean): string; + /** + * 取整數) + */ + ExToInt(): number; + /** + * 小數轉整數(支援科學符號) + */ + Float2Fixed(): number; + /** + * 數字長度(支援科學符號) + */ + DigitLength(): number; - + target: number; + + + } } -Number.prototype.ExFormatNumberWithComma || Object.defineProperty(Number.prototype, 'ExFormatNumberWithComma', { +Number.prototype.ExFormatNumberWithComma || Object.defineProperty(Number.prototype, "ExFormatNumberWithComma", { enumerable: false, value: function (precision: number = 2, isPadZero: boolean = true) { - + // let arr = String(this).split('.'); - let arr = this.ExToStringFloorDecimal(precision, isPadZero).split('.'); - let num = arr[0], result = ''; + let arr = this.ExToStringFloorDecimal(precision, isPadZero).split("."); + let num = arr[0], result = ""; while (num.length > 3) { - result = ',' + num.slice(-3) + result; + result = "," + num.slice(-3) + result; num = num.slice(0, num.length - 3); } - if (num.length > 0) result = num + result; - return arr[1] ? result + '.' + arr[1] : result; + if (num.length > 0) { result = num + result; } + return arr[1] ? result + "." + arr[1] : result; } -}) +}); -Number.prototype.ExTransferToBMK || Object.defineProperty(Number.prototype, 'ExTransferToBMK', { +Number.prototype.ExTransferToBMK || Object.defineProperty(Number.prototype, "ExTransferToBMK", { enumerable: false, - value: function (precision: number=2,offset: number = 0) { + value: function (precision: number = 2, offset: number = 0) { /**千 */ let MONEY_1K: number = 1000; /**萬 */ @@ -98,56 +101,53 @@ Number.prototype.ExTransferToBMK || Object.defineProperty(Number.prototype, 'ExT // return (~~(this / MONEY_1T)).ExFormatNumberWithComma(0) + "T"; // } if (this >= MONEY_1B * offset) { - //1,000B~900,000B - //1B~900B + // 1,000B~900,000B + // 1B~900B return (this / MONEY_1B).ExFormatNumberWithComma(3, false) + "B"; - } - else if (this >= MONEY_1M * offset) { - //1,000M~900,000M - //1M~900M + } else if (this >= MONEY_1M * offset) { + // 1,000M~900,000M + // 1M~900M return (this / MONEY_1M).ExFormatNumberWithComma(3, false) + "M"; - } - else if (this >= MONEY_1K * offset) { - //1,000K~900,000K - //1K~90K + } else if (this >= MONEY_1K * offset) { + // 1,000K~900,000K + // 1K~90K return (this / MONEY_1K).ExFormatNumberWithComma(3, false) + "K"; - } - else { - //0~9,000,000 - //0~9,000 + } else { + // 0~9,000,000 + // 0~9,000 return this.ExFormatNumberWithComma(precision); } } -}) -Number.prototype.Pad || Object.defineProperty(Number.prototype, 'Pad', { +}); +Number.prototype.Pad || Object.defineProperty(Number.prototype, "Pad", { enumerable: false, value: function (size: number) { let s = this + ""; - while (s.length < size) s = "0" + s; + while (s.length < size) { s = "0" + s; } return s; } -}) -Number.prototype.ExToNumRoundDecimal || Object.defineProperty(Number.prototype, 'ExToNumRoundDecimal', { +}); +Number.prototype.ExToNumRoundDecimal || Object.defineProperty(Number.prototype, "ExToNumRoundDecimal", { enumerable: false, value: function (precision: number) { return Math.round(Math.round(this * Math.pow(10, (precision || 0) + 1)) / 10) / Math.pow(10, (precision || 0)); } -}) -Number.prototype.ExToInt || Object.defineProperty(Number.prototype, 'ExToInt',{ +}); +Number.prototype.ExToInt || Object.defineProperty(Number.prototype, "ExToInt", { enumerable: false, - value: function (){ + value: function () { return ~~this; } -}) -Number.prototype.ExToNumFloorDecimal || Object.defineProperty(Number.prototype, 'ExToNumFloorDecimal', { +}); +Number.prototype.ExToNumFloorDecimal || Object.defineProperty(Number.prototype, "ExToNumFloorDecimal", { enumerable: false, - value: function (precision: number) { + value: function (precision: number) { let str = this.toPrecision(12); - let dotPos = str.indexOf('.'); - return dotPos == -1 ? this : +`${str.substr(0, dotPos + 1 + precision)}`; + let dotPos = str.indexOf("."); + return dotPos === -1 ? this : +`${str.substr(0, dotPos + 1 + precision)}`; } -}) -Number.prototype.ExToStringFloorDecimal || Object.defineProperty(Number.prototype, 'ExToStringFloorDecimal', { +}); +Number.prototype.ExToStringFloorDecimal || Object.defineProperty(Number.prototype, "ExToStringFloorDecimal", { enumerable: false, value: function (precision: number, isPadZero: boolean = true) { // 取小數點第X位 @@ -155,35 +155,35 @@ Number.prototype.ExToStringFloorDecimal || Object.defineProperty(Number.prototyp let s = f.toString(); // 補0 if (isPadZero) { - let rs = s.indexOf('.'); + let rs = s.indexOf("."); if (rs < 0) { rs = s.length; - s += '.'; + s += "."; } while (s.length <= rs + precision) { - s += '0'; + s += "0"; } } return s; } -}) -Number.prototype.Float2Fixed || Object.defineProperty(Number.prototype, 'Float2Fixed', { +}); +Number.prototype.Float2Fixed || Object.defineProperty(Number.prototype, "Float2Fixed", { enumerable: false, value: function () { - if (this.toString().indexOf('e') === -1) { - return Number(this.toString().replace('.', '')); + if (this.toString().indexOf("e") === -1) { + return Number(this.toString().replace(".", "")); } const dLen = this.DigitLength(); return dLen > 0 ? +parseFloat((this * Math.pow(10, dLen)).toPrecision(12)) : this; } -}) -Number.prototype.DigitLength || Object.defineProperty(Number.prototype, 'DigitLength', { +}); +Number.prototype.DigitLength || Object.defineProperty(Number.prototype, "DigitLength", { enumerable: false, value: function () { const eSplit = this.toString().split(/[eE]/); - const len = (eSplit[0].split('.')[1] || '').length - (+(eSplit[1] || 0)); + const len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); return len > 0 ? len : 0; } -}) +}); - \ No newline at end of file +export { };