@betorigami/games 2.8.5 → 2.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -16573,7 +16573,7 @@ var j6=Object.create;var{getPrototypeOf:M6,defineProperty:B3,getOwnPropertyNames
16573
16573
  :host {
16574
16574
  height: 100%;
16575
16575
  }
16576
- `;class D3{edge=0;currentBalance;activeBet=null;previousPlayResults=[];randomSequence=[];useCustomSequence=!1;amount="0";constructor(a){this.currentBalance=K(a)}setRandomSequence(a){let e=Array.from({length:this.maxRandomValues-a.length},()=>Math.floor(Math.random()*(this.maxRandomValue-this.minRandomValue+1))+this.minRandomValue);this.randomSequence=[...a,...e],this.useCustomSequence=!0}async startGame(a){let e=K(a.amount);if(e.gt(this.currentBalance))return{success:!1,error:"Insufficient balance"};let i=this.currentBalance.minus(e);if(!this.useCustomSequence)this.randomSequence=Array.from({length:this.maxRandomValues},()=>Math.floor(Math.random()*(this.maxRandomValue-this.minRandomValue+1))+this.minRandomValue);this.useCustomSequence=!1,this.amount=a.amount;let r=J3(this.randomSequence),t=this.createGameEngine(this.edge).play(r,a.gameInputs,[]);this.previousPlayResults=[t];let o=crypto.randomUUID(),l=this.toActionData(t);if(t.state.isFinished){let d=e.mul(t.state.multiplier),c=i.plus(d);this.currentBalance=c;let m={id:o,tenantId:"origami-casino",userId:"mock-user",tenantUserId:"mock-user",gameId:this.gameId,amount:e.toString(),payout:d.toString(),afterBalance:c.toString(),multiplier:t.state.multiplier.toString(),clientSeed:"mock-seed",randomValue:t.proof.proofHash,proof:t.proof.proofString,nonce:1,betActions:[{type:"START_BET",betAmount:a.amount,payoutAmount:null,actionIndex:0,data:l},{type:"END_BET",betAmount:null,payoutAmount:d.toString(),actionIndex:1,data:l}]};return this.clearState(),{success:!0,data:m}}let s={id:o,tenantId:"origami-casino",userId:"mock-user",tenantUserId:"mock-user",gameId:this.gameId,amount:e.toString(),payout:null,afterBalance:i.toString(),multiplier:null,clientSeed:"mock-seed",randomValue:null,proof:null,nonce:1,betActions:[{type:"START_BET",betAmount:a.amount,payoutAmount:null,actionIndex:0,data:l}]};return this.currentBalance=i,this.activeBet=s,{success:!0,data:s}}async performNextAction(a){if(!this.activeBet)return{success:!1,error:"No active bet"};let e=J3(this.randomSequence),r=this.createGameEngine(this.edge).play(e,a,this.previousPlayResults);this.previousPlayResults=[...this.previousPlayResults,r];let n=this.activeBet,t=[...n.betActions],o=t.length,l=this.toActionData(r),s=r.additionalBetAmount!==void 0,d=s?r.additionalBetAmount:null,c=d!==null?K(this.amount).plus(d):K(this.amount),m=c.mul(r.state.multiplier),u=this.currentBalance;if(s&&d!==null){u=u.minus(d),this.amount=c.toString();let H={type:"INTERMEDIATE_BET_ACTION",betAmount:d.toString(),payoutAmount:null,actionIndex:o,data:l},z=[...t,H];if(!r.state.isFinished){this.currentBalance=u;let b={...n,amount:c.toString(),afterBalance:u.toString(),betActions:z};return this.activeBet=b,{success:!0,data:b}}let v=u.plus(m);this.currentBalance=v,z.push({type:"END_BET",betAmount:null,payoutAmount:m.toString(),actionIndex:o+1,data:l});let g={...n,amount:c.toString(),payout:m.toString(),afterBalance:v.toString(),multiplier:r.state.multiplier.toString(),randomValue:r.proof.proofHash,proof:r.proof.proofString,betActions:z};return this.clearState(),{success:!0,data:g}}if(!r.state.isFinished){let H={type:"INTERMEDIATE_NON_BET_ACTION",betAmount:null,payoutAmount:null,actionIndex:o,data:l},z={...n,afterBalance:u.toString(),betActions:[...t,H]};return this.currentBalance=u,this.activeBet=z,{success:!0,data:z}}let f=u.plus(m);this.currentBalance=f;let k={type:"END_BET",betAmount:null,payoutAmount:m.toString(),actionIndex:o,data:l},p={...n,payout:m.toString(),afterBalance:f.toString(),multiplier:r.state.multiplier.toString(),randomValue:r.proof.proofHash,proof:r.proof.proofString,betActions:[...t,k]};return this.clearState(),{success:!0,data:p}}async fetchActiveBet(){if(!this.activeBet)return{success:!1,error:"No active bet"};return{success:!0,data:this.activeBet}}clearState(){this.activeBet=null,this.previousPlayResults=[],this.randomSequence=[],this.amount="0"}}var bu=0,zu=51,yu=63;class ri extends D3{static pendingCardSequence=null;gameId="blackjack";maxRandomValues=yu;minRandomValue=bu;maxRandomValue=zu;static setCardSequence(a){ri.pendingCardSequence=[...a]}constructor(a){super(a)}createGameEngine(a){return new _i(a)}toActionData(a){return{BLACKJACK:a}}async startBet(a){if(ri.pendingCardSequence!==null)this.setRandomSequence(ri.pendingCardSequence),ri.pendingCardSequence=null;let e=a.mainBetAmount,i=a.pairBonusAmount??"0",r=a.threeCardBonusAmount??"0",n=K(e).plus(i).plus(r),t=await this.startGame({amount:n.toString(),gameInputs:{type:ja.START,mainBetAmount:e,pairBonusAmount:i,threeCardBonusAmount:r}});if(t.success)return t;return{success:!1,errorCode:t.error==="Insufficient balance"?"INSUFFICIENT_BALANCE":"UNKNOWN"}}async next(a){let e=await this.performNextAction({type:a.type});if(e.success)return e;return{success:!1,errorCode:"UNKNOWN"}}async getActiveBet(){let a=await this.fetchActiveBet();if(a.success)return a;if(a.error==="No active bet")return{success:!0,data:null};return{success:!1,errorCode:"UNKNOWN"}}}var xu=(a)=>{if(typeof a!=="object"||a===null||!("cardId"in a))return!1;return a.cardId===void 0||typeof a.cardId==="string"};class kr{host;constructor(a){this.host=a,a.addController(this)}hostConnected(){}get instantMode(){return this.host.gameData.instantBetEnabled}static BETWEEN_CARD_ACTIONS_PAUSE=120;static DEALER_REVEAL_PAUSE=300;async waitBeforeDealerReveal(){if(this.instantMode)return;if(this.host.visibleState.stage!=="player")return;await qa(kr.DEALER_REVEAL_PAUSE)}async waitBetweenCardActions(){if(this.instantMode)return;await qa(kr.BETWEEN_CARD_ACTIONS_PAUSE)}async dealPlayerCard(a,e){let i=this.host.addPlayerCardToHand(a,e);await this.waitForCardDealComplete(i)}async dealDealerCard(a){let e=this.host.addDealerCard(a);await this.waitForCardDealComplete(e)}async revealDealerHoleCard(a){this.host.updateDealerCard(1,a,!1),await this.waitForCardDealComplete("d-1")}async runCardActions(a){for(let e=0;e<a.length;e++){let i=a[e];if(await i(),e<a.length-1)await this.waitBetweenCardActions()}}async playInitialDeal(a,e){if(this.instantMode){this.host.updateVisibleState({playerHands:[a],dealerCards:e});return}let i={...e[1],faceDown:!0};await this.runCardActions([()=>this.dealPlayerCard(0,a[0]),()=>this.dealDealerCard(e[0]),()=>this.dealPlayerCard(0,a[1]),()=>this.dealDealerCard(i)])}async playDealerReveal(a){await this.waitBeforeDealerReveal(),this.host.updateVisibleState({stage:"dealer"}),await this.host.triggerForceUIUpdate();let e=[];if(a[1])e.push(()=>this.revealDealerHoleCard(a[1]));for(let i=2;i<a.length;i++){let r=a[i];e.push(()=>this.dealDealerCard(r))}await this.runCardActions(e)}async playSplitDeal(a,e){await this.dealPlayerCard(0,a),await this.waitBetweenCardActions(),await this.dealPlayerCard(1,e)}async waitForAllCardsToBeIdle(){if(this.instantMode)return;await this.host.triggerForceUIUpdate(),await qa(50)}waitForCardDealComplete(a){if(this.instantMode)return Promise.resolve();return new Promise((e)=>{let i=!1,r=(n)=>{if(!(n instanceof CustomEvent)||!xu(n.detail)||n.detail.cardId!==a)return;this.host.removeEventListener("blackjack-card-dealt",r),i=!0,e()};this.host.addEventListener("blackjack-card-dealt",r),qa(2000).then(()=>{if(i)return;this.host.removeEventListener("blackjack-card-dealt",r),e()})})}}var Hu=5,O6="origami-blackjack-sidebet-onboarded";class P2 extends Ha{static styles=[...Ha.styles,K6];currentBetId=null;currentMainBetAmount="0";animationController;actionHandlers;betController;hasTrackedSessionConfig=!1;previousAuthToken="";previousBaseUrl="";get activeHand(){return this.visibleState.playerHands[this.visibleState.activeHandIndex]??[]}get playerHandsForContent(){return this.visibleState.playerHands}get activeHandIndexForContent(){return this.visibleState.activeHandIndex}get isGameActive(){return this.visibleState.stage!=="idle"&&this.visibleState.stage!=="settled"}get isToggleDisabled(){return this.visibleState.isActing||this.autobetInProgress||this.autobetStopping||this.isGameActive}get areInputsDisabled(){return this.visibleState.isActing||this.autobetInProgress||this.autobetStopping||this.controlsLocked}get totalBetExceedsBalance(){if(!this.gameData?.hasLoadedBalance)return!1;let a=this.gameData.betAmount??"0",e=this.sideBetMode?this.pairBonusAmount:"0",i=this.sideBetMode?this.threeCardBonusAmount:"0";if(![a,e,i].every(fa))return!1;return K(a).plus(e).plus(i).gt(K(this.gameData.balance??0))}get sidebarMode(){return this.sideBetMode||this.showSideBetOnboarding?"Auto":"Manual"}_getBlackjackApi=_1(()=>this.gameData,()=>this.isDemoMode,{createReal:(a,e)=>new Y3(a,e),createMock:()=>new ri(this.gameData.balance)});getBlackjackApi(){return this._getBlackjackApi()}constructor(){super();this.canonicalState=null;this.visibleState=ur();this.history=[];this.controlsLocked=!1;this._loadingAction=null;this.suppressNextContentAnimations=!1;this.sideBetMode=!1;this.pairBonusAmount="0";this.threeCardBonusAmount="0";this.sideBetResults=null;this.showSideBetOnboarding=!1;this.animationController=new kr(this),this.actionHandlers=new $3(this,this.animationController),this.betController=new P3(this,this.animationController),new Ta(this,[{key:" ",callback:this.handleSpacebar,options:{repeat:!0,repeatInterval:200,disabled:this.isSpacebarDisabled}},{key:"q",callback:this.handleHit,options:{disabled:this.isHitDisabled}},{key:"w",callback:this.handleStand,options:{disabled:this.isStandDisabled}},{key:"e",callback:this.handleSplit,options:{disabled:this.isSplitDisabled}},{key:"r",callback:this.handleDoubleDown,options:{disabled:this.isDoubleDisabled}},{key:"t",callback:this.handleAcceptInsurance,options:{disabled:this.isAcceptInsuranceDisabled}},{key:"y",callback:this.handleNoInsurance,options:{disabled:this.isNoInsuranceDisabled}}])}setCanonicalState(a){this.canonicalState=a}setVisibleState(a){this.visibleState=a}updateVisibleState(a){this.visibleState={...this.visibleState,...a}}addToHistory(a,e,i){this.history=[...this.history,{multiplier:a,won:e,id:i}].slice(-Hu)}async withOptimisticBalanceDeduction(a,e){let i=K(this.gameData.balance);this.gameData.updateBalance(i.minus(a));try{let r=await e();if(r===null)this.gameData.updateBalance(i);return r}catch(r){throw this.gameData.updateBalance(i),r}}async runWithLockedControls(a,e){this.controlsLocked=!0,this._loadingAction=e??null;try{await a()}finally{this.controlsLocked=!1,this._loadingAction=null}}async firstUpdated(a){super.firstUpdated(a),await this.getBlackjackActiveBet()}updated(a){super.updated(a);let e=this.gameData.authToken,i=this.gameData.baseUrl;if(!this.hasTrackedSessionConfig){this.previousAuthToken=e,this.previousBaseUrl=i,this.hasTrackedSessionConfig=!0;return}if(e===this.previousAuthToken&&i===this.previousBaseUrl)return;let r=Boolean(this.previousAuthToken)&&Boolean(this.previousBaseUrl),n=Boolean(e)&&Boolean(i);if(this.previousAuthToken=e,this.previousBaseUrl=i,!r&&!n)return;this.getBlackjackActiveBet()}async getBlackjackActiveBet(){let a=!1;try{let e=await this.getBlackjackApi().getActiveBet();if(!e.success)return;if(e.data===null){this.currentBetId=null,this.canonicalState=null,this.sideBetResults=null,this.setVisibleState(ur());return}this.currentBetId=e.data.id;let i=dr(e.data);if(!i)return;this.canonicalState=i,this.suppressNextContentAnimations=!0,a=!0,this.setVisibleState(hs(i)),this.sideBetResults=qi(i),await this.forceUIUpdate()}catch{this.showError(R("alerts.gameError",this.gameData.language||W))}finally{if(a)this.suppressNextContentAnimations=!1}}addPlayerCardToHand(a,e){let i=this.visibleState.playerHands.map((r,n)=>n===a?[...r,e]:r);return this.visibleState={...this.visibleState,playerHands:i},`p-${a}-${i[a].length-1}`}addDealerCard(a){return this.visibleState={...this.visibleState,dealerCards:[...this.visibleState.dealerCards,a]},`d-${this.visibleState.dealerCards.length-1}`}updateDealerCard(a,e,i){this.visibleState={...this.visibleState,dealerCards:this.visibleState.dealerCards.map((r,n)=>{if(n===a)return{...e,faceDown:i};return r})}}setSuppressAnimations(a){this.suppressNextContentAnimations=a}setSideBetResults(a){this.sideBetResults=a}revertToStandardModeIfNoSideBets(){if(!this.sideBetMode)return;if(![this.pairBonusAmount,this.threeCardBonusAmount].some((e)=>fa(e)&&K(e).gt(0)))this.sideBetMode=!1}async finishRound(a){if(!this.canonicalState)return;let e=this.canonicalState.multiplier.toNumber(),i=e>1;this.addToHistory(e,i,a.id),this.updateHistoryWithBet({id:a.id,amount:a.amount,payout:a.payout});let r=yt(this.canonicalState),n=cr(this.canonicalState);if(await this.animationController.waitForAllCardsToBeIdle(),this.updateVisibleState({resultMultiplier:e,mainHandOutcome:r.mainOutcome,splitHandOutcome:r.splitOutcome,insuranceOutcome:n}),await this.forceUIUpdate(),i)this.playWinFeedback();if(a.afterBalance)this.gameData.updateBalance(K(a.afterBalance));this.updateVisibleState({stage:"settled",isActing:!1}),this.hasPendingBet=!1,this.currentBetId=null,this.currentMainBetAmount="0"}async executeNextAction(a){if(!this.currentBetId)return null;let e=await this.getBlackjackApi().next({betId:this.currentBetId,type:a});if(!e.success)return this.showError(R(i1(e.errorCode),this.gameData.language||W)),null;let i=dr(e.data);return this.canonicalState=i,e.data}async blackjackPlay(){if(this.isGameActive)return;this.updateVisibleState({isActing:!0}),this.gameData.soundEffects?.play(ca.buttonPress(0.5));try{await this.betController.handleBetExecution(this.gameData.betAmount??"0")}catch{this.showError(R("alerts.gameError",this.gameData.language||W))}finally{this.updateVisibleState({isActing:!1})}}async executeAutobet(a,e){return{pnl:K(0),gameOutcome:"Draw",hasError:!0,errorMessage:R("alerts.gameError",this.gameData.language||W)}}triggerForceUIUpdate(){return this.forceUIUpdate()}triggerShowError(a){this.showError(a)}setHasPendingBet(a){this.hasPendingBet=a}canAffordAction(a){if(!this.gameData?.hasLoadedBalance)return!0;if(!fa(this.currentMainBetAmount))return!0;let e=K(this.gameData.balance??0),i=K(this.currentMainBetAmount);switch(a){case ja.SPLIT:case ja.DOUBLE_DOWN:return e.gte(i);case ja.BUY_INSURANCE:return e.gte(i.div(2));case ja.HIT:case ja.STAND:case ja.START:case ja.REJECT_INSURANCE:return!0;default:return!1}}canPerformAction(a){return this.visibleState.stage==="player"&&!this.controlsLocked&&this.currentBetId!==null&&ss(this.canonicalState).includes(a)&&this.canAffordAction(a)}onBuyInsurance=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleInsurance(ja.BUY_INSURANCE),"buy-insurance")};onDeclineInsurance=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleInsurance(ja.REJECT_INSURANCE),"no-insurance")};handleHit=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleHit(this.currentBetId),"hit")};handleStand=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleStand(this.currentBetId),"stand")};handleDoubleDown=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleDoubleDown(this.currentBetId),"double")};handleSplit=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleSplit(this.currentBetId),"split")};isSpacebarDisabled=()=>{if(!this.gameData.hotkeysOpenEnabled||this.isGameActive)return!0;return this._blackjackManualEl?.isPrimaryActionDisabled()??!0};isHitDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.HIT)};isStandDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.STAND)};isSplitDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.SPLIT)};isDoubleDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.DOUBLE_DOWN)};isAcceptInsuranceDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||this.controlsLocked||this.visibleState.stage!=="insurance"||!this.canAffordAction(ja.BUY_INSURANCE)};isNoInsuranceDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||this.controlsLocked||this.visibleState.stage!=="insurance"};handleAcceptInsurance=()=>{if(this.isAcceptInsuranceDisabled())return;this.onBuyInsurance()};handleNoInsurance=()=>{if(this.isNoInsuranceDisabled())return;this.onDeclineInsurance()};handleSpacebar=()=>{if(this.isSpacebarDisabled())return;this._blackjackManualEl?.triggerPrimaryAction()};onBetModeChange=(a)=>{if(!Y1(a.detail.tab))return;if(a.detail.tab==="Manual"&&this.showSideBetOnboarding){this.showSideBetOnboarding=!1;return}if(a.detail.tab==="Auto"&&!this.sideBetMode&&!this.sideBetOnboardingComplete){this.showSideBetOnboarding=!0;return}this.showSideBetOnboarding=!1,this.sideBetMode=a.detail.tab==="Auto"};get sideBetOnboardingComplete(){if(typeof localStorage==="undefined")return!1;return localStorage.getItem(O6)==="1"}handleSideBetOnboardingComplete=()=>{if(typeof localStorage!=="undefined")localStorage.setItem(O6,"1");this.showSideBetOnboarding=!1,this.sideBetMode=!0};onPairBonusAmountChange=(a)=>{this.pairBonusAmount=a.detail.value};onThreeCardBonusAmountChange=(a)=>{this.threeCardBonusAmount=a.detail.value};onDealSound=()=>{this.gameData.soundEffects?.play(ca.cardSlide())};onCardFlip=()=>{this.gameData.soundEffects?.play(ca.cardFlip())};render(){let a=this.gameData.mainWidth>=768,e=this.areInputsDisabled||this.isGameActive||this.totalBetExceedsBalance,i=Va(this.gameData);return x`
16576
+ `;class D3{edge=0;currentBalance;activeBet=null;previousPlayResults=[];randomSequence=[];useCustomSequence=!1;amount="0";constructor(a){this.currentBalance=K(a)}setRandomSequence(a){let e=Array.from({length:this.maxRandomValues-a.length},()=>Math.floor(Math.random()*(this.maxRandomValue-this.minRandomValue+1))+this.minRandomValue);this.randomSequence=[...a,...e],this.useCustomSequence=!0}async startGame(a){let e=K(a.amount);if(e.gt(this.currentBalance))return{success:!1,error:"Insufficient balance"};let i=this.currentBalance.minus(e);if(!this.useCustomSequence)this.randomSequence=Array.from({length:this.maxRandomValues},()=>Math.floor(Math.random()*(this.maxRandomValue-this.minRandomValue+1))+this.minRandomValue);this.useCustomSequence=!1,this.amount=a.amount;let r=J3(this.randomSequence),t=this.createGameEngine(this.edge).play(r,a.gameInputs,[]);this.previousPlayResults=[t];let o=crypto.randomUUID(),l=this.toActionData(t);if(t.state.isFinished){let d=e.mul(t.state.multiplier),c=i.plus(d);this.currentBalance=c;let m={id:o,tenantId:"origami-casino",userId:"mock-user",tenantUserId:"mock-user",gameId:this.gameId,amount:e.toString(),payout:d.toString(),afterBalance:c.toString(),multiplier:t.state.multiplier.toString(),clientSeed:"mock-seed",randomValue:t.proof.proofHash,proof:t.proof.proofString,nonce:1,betActions:[{type:"START_BET",betAmount:a.amount,payoutAmount:null,actionIndex:0,data:l},{type:"END_BET",betAmount:null,payoutAmount:d.toString(),actionIndex:1,data:l}]};return this.clearState(),{success:!0,data:m}}let s={id:o,tenantId:"origami-casino",userId:"mock-user",tenantUserId:"mock-user",gameId:this.gameId,amount:e.toString(),payout:null,afterBalance:i.toString(),multiplier:null,clientSeed:"mock-seed",randomValue:null,proof:null,nonce:1,betActions:[{type:"START_BET",betAmount:a.amount,payoutAmount:null,actionIndex:0,data:l}]};return this.currentBalance=i,this.activeBet=s,{success:!0,data:s}}async performNextAction(a){if(!this.activeBet)return{success:!1,error:"No active bet"};let e=J3(this.randomSequence),r=this.createGameEngine(this.edge).play(e,a,this.previousPlayResults);this.previousPlayResults=[...this.previousPlayResults,r];let n=this.activeBet,t=[...n.betActions],o=t.length,l=this.toActionData(r),s=r.additionalBetAmount!==void 0,d=s?r.additionalBetAmount:null,c=d!==null?K(this.amount).plus(d):K(this.amount),m=c.mul(r.state.multiplier),u=this.currentBalance;if(s&&d!==null){u=u.minus(d),this.amount=c.toString();let H={type:"INTERMEDIATE_BET_ACTION",betAmount:d.toString(),payoutAmount:null,actionIndex:o,data:l},z=[...t,H];if(!r.state.isFinished){this.currentBalance=u;let b={...n,amount:c.toString(),afterBalance:u.toString(),betActions:z};return this.activeBet=b,{success:!0,data:b}}let v=u.plus(m);this.currentBalance=v,z.push({type:"END_BET",betAmount:null,payoutAmount:m.toString(),actionIndex:o+1,data:l});let g={...n,amount:c.toString(),payout:m.toString(),afterBalance:v.toString(),multiplier:r.state.multiplier.toString(),randomValue:r.proof.proofHash,proof:r.proof.proofString,betActions:z};return this.clearState(),{success:!0,data:g}}if(!r.state.isFinished){let H={type:"INTERMEDIATE_NON_BET_ACTION",betAmount:null,payoutAmount:null,actionIndex:o,data:l},z={...n,afterBalance:u.toString(),betActions:[...t,H]};return this.currentBalance=u,this.activeBet=z,{success:!0,data:z}}let f=u.plus(m);this.currentBalance=f;let k={type:"END_BET",betAmount:null,payoutAmount:m.toString(),actionIndex:o,data:l},p={...n,payout:m.toString(),afterBalance:f.toString(),multiplier:r.state.multiplier.toString(),randomValue:r.proof.proofHash,proof:r.proof.proofString,betActions:[...t,k]};return this.clearState(),{success:!0,data:p}}async fetchActiveBet(){if(!this.activeBet)return{success:!1,error:"No active bet"};return{success:!0,data:this.activeBet}}clearState(){this.activeBet=null,this.previousPlayResults=[],this.randomSequence=[],this.amount="0"}}var bu=0,zu=51,yu=63;class ri extends D3{static pendingCardSequence=null;gameId="blackjack";maxRandomValues=yu;minRandomValue=bu;maxRandomValue=zu;edge=1;static setCardSequence(a){ri.pendingCardSequence=[...a]}constructor(a){super(a)}createGameEngine(a){return new _i(a)}toActionData(a){return{BLACKJACK:a}}async startBet(a){if(ri.pendingCardSequence!==null)this.setRandomSequence(ri.pendingCardSequence),ri.pendingCardSequence=null;let e=a.mainBetAmount,i=a.pairBonusAmount??"0",r=a.threeCardBonusAmount??"0",n=K(e).plus(i).plus(r),t=await this.startGame({amount:n.toString(),gameInputs:{type:ja.START,mainBetAmount:e,pairBonusAmount:i,threeCardBonusAmount:r}});if(t.success)return t;return{success:!1,errorCode:t.error==="Insufficient balance"?"INSUFFICIENT_BALANCE":"UNKNOWN"}}async next(a){let e=await this.performNextAction({type:a.type});if(e.success)return e;return{success:!1,errorCode:"UNKNOWN"}}async getActiveBet(){let a=await this.fetchActiveBet();if(a.success)return a;if(a.error==="No active bet")return{success:!0,data:null};return{success:!1,errorCode:"UNKNOWN"}}}var xu=(a)=>{if(typeof a!=="object"||a===null||!("cardId"in a))return!1;return a.cardId===void 0||typeof a.cardId==="string"};class kr{host;constructor(a){this.host=a,a.addController(this)}hostConnected(){}get instantMode(){return this.host.gameData.instantBetEnabled}static BETWEEN_CARD_ACTIONS_PAUSE=120;static DEALER_REVEAL_PAUSE=300;async waitBeforeDealerReveal(){if(this.instantMode)return;if(this.host.visibleState.stage!=="player")return;await qa(kr.DEALER_REVEAL_PAUSE)}async waitBetweenCardActions(){if(this.instantMode)return;await qa(kr.BETWEEN_CARD_ACTIONS_PAUSE)}async dealPlayerCard(a,e){let i=this.host.addPlayerCardToHand(a,e);await this.waitForCardDealComplete(i)}async dealDealerCard(a){let e=this.host.addDealerCard(a);await this.waitForCardDealComplete(e)}async revealDealerHoleCard(a){this.host.updateDealerCard(1,a,!1),await this.waitForCardDealComplete("d-1")}async runCardActions(a){for(let e=0;e<a.length;e++){let i=a[e];if(await i(),e<a.length-1)await this.waitBetweenCardActions()}}async playInitialDeal(a,e){if(this.instantMode){this.host.updateVisibleState({playerHands:[a],dealerCards:e});return}let i={...e[1],faceDown:!0};await this.runCardActions([()=>this.dealPlayerCard(0,a[0]),()=>this.dealDealerCard(e[0]),()=>this.dealPlayerCard(0,a[1]),()=>this.dealDealerCard(i)])}async playDealerReveal(a){await this.waitBeforeDealerReveal(),this.host.updateVisibleState({stage:"dealer"}),await this.host.triggerForceUIUpdate();let e=[];if(a[1])e.push(()=>this.revealDealerHoleCard(a[1]));for(let i=2;i<a.length;i++){let r=a[i];e.push(()=>this.dealDealerCard(r))}await this.runCardActions(e)}async playSplitDeal(a,e){await this.dealPlayerCard(0,a),await this.waitBetweenCardActions(),await this.dealPlayerCard(1,e)}async waitForAllCardsToBeIdle(){if(this.instantMode)return;await this.host.triggerForceUIUpdate(),await qa(50)}waitForCardDealComplete(a){if(this.instantMode)return Promise.resolve();return new Promise((e)=>{let i=!1,r=(n)=>{if(!(n instanceof CustomEvent)||!xu(n.detail)||n.detail.cardId!==a)return;this.host.removeEventListener("blackjack-card-dealt",r),i=!0,e()};this.host.addEventListener("blackjack-card-dealt",r),qa(2000).then(()=>{if(i)return;this.host.removeEventListener("blackjack-card-dealt",r),e()})})}}var Hu=5,O6="origami-blackjack-sidebet-onboarded";class P2 extends Ha{static styles=[...Ha.styles,K6];currentBetId=null;currentMainBetAmount="0";animationController;actionHandlers;betController;hasTrackedSessionConfig=!1;previousAuthToken="";previousBaseUrl="";get activeHand(){return this.visibleState.playerHands[this.visibleState.activeHandIndex]??[]}get playerHandsForContent(){return this.visibleState.playerHands}get activeHandIndexForContent(){return this.visibleState.activeHandIndex}get isGameActive(){return this.visibleState.stage!=="idle"&&this.visibleState.stage!=="settled"}get isToggleDisabled(){return this.visibleState.isActing||this.autobetInProgress||this.autobetStopping||this.isGameActive}get areInputsDisabled(){return this.visibleState.isActing||this.autobetInProgress||this.autobetStopping||this.controlsLocked}get totalBetExceedsBalance(){if(!this.gameData?.hasLoadedBalance)return!1;let a=this.gameData.betAmount??"0",e=this.sideBetMode?this.pairBonusAmount:"0",i=this.sideBetMode?this.threeCardBonusAmount:"0";if(![a,e,i].every(fa))return!1;return K(a).plus(e).plus(i).gt(K(this.gameData.balance??0))}get sidebarMode(){return this.sideBetMode||this.showSideBetOnboarding?"Auto":"Manual"}_getBlackjackApi=_1(()=>this.gameData,()=>this.isDemoMode,{createReal:(a,e)=>new Y3(a,e),createMock:()=>new ri(this.gameData.balance)});getBlackjackApi(){return this._getBlackjackApi()}constructor(){super();this.canonicalState=null;this.visibleState=ur();this.history=[];this.controlsLocked=!1;this._loadingAction=null;this.suppressNextContentAnimations=!1;this.sideBetMode=!1;this.pairBonusAmount="0";this.threeCardBonusAmount="0";this.sideBetResults=null;this.showSideBetOnboarding=!1;this.animationController=new kr(this),this.actionHandlers=new $3(this,this.animationController),this.betController=new P3(this,this.animationController),new Ta(this,[{key:" ",callback:this.handleSpacebar,options:{repeat:!0,repeatInterval:200,disabled:this.isSpacebarDisabled}},{key:"q",callback:this.handleHit,options:{disabled:this.isHitDisabled}},{key:"w",callback:this.handleStand,options:{disabled:this.isStandDisabled}},{key:"e",callback:this.handleSplit,options:{disabled:this.isSplitDisabled}},{key:"r",callback:this.handleDoubleDown,options:{disabled:this.isDoubleDisabled}},{key:"t",callback:this.handleAcceptInsurance,options:{disabled:this.isAcceptInsuranceDisabled}},{key:"y",callback:this.handleNoInsurance,options:{disabled:this.isNoInsuranceDisabled}}])}setCanonicalState(a){this.canonicalState=a}setVisibleState(a){this.visibleState=a}updateVisibleState(a){this.visibleState={...this.visibleState,...a}}addToHistory(a,e,i){this.history=[...this.history,{multiplier:a,won:e,id:i}].slice(-Hu)}async withOptimisticBalanceDeduction(a,e){let i=K(this.gameData.balance);this.gameData.updateBalance(i.minus(a));try{let r=await e();if(r===null)this.gameData.updateBalance(i);return r}catch(r){throw this.gameData.updateBalance(i),r}}async runWithLockedControls(a,e){this.controlsLocked=!0,this._loadingAction=e??null;try{await a()}finally{this.controlsLocked=!1,this._loadingAction=null}}async firstUpdated(a){super.firstUpdated(a),await this.getBlackjackActiveBet()}updated(a){super.updated(a);let e=this.gameData.authToken,i=this.gameData.baseUrl;if(!this.hasTrackedSessionConfig){this.previousAuthToken=e,this.previousBaseUrl=i,this.hasTrackedSessionConfig=!0;return}if(e===this.previousAuthToken&&i===this.previousBaseUrl)return;let r=Boolean(this.previousAuthToken)&&Boolean(this.previousBaseUrl),n=Boolean(e)&&Boolean(i);if(this.previousAuthToken=e,this.previousBaseUrl=i,!r&&!n)return;this.getBlackjackActiveBet()}async getBlackjackActiveBet(){let a=!1;try{let e=await this.getBlackjackApi().getActiveBet();if(!e.success)return;if(e.data===null){this.currentBetId=null,this.canonicalState=null,this.sideBetResults=null,this.setVisibleState(ur());return}this.currentBetId=e.data.id;let i=dr(e.data);if(!i)return;this.canonicalState=i,this.suppressNextContentAnimations=!0,a=!0,this.setVisibleState(hs(i)),this.sideBetResults=qi(i),await this.forceUIUpdate()}catch{this.showError(R("alerts.gameError",this.gameData.language||W))}finally{if(a)this.suppressNextContentAnimations=!1}}addPlayerCardToHand(a,e){let i=this.visibleState.playerHands.map((r,n)=>n===a?[...r,e]:r);return this.visibleState={...this.visibleState,playerHands:i},`p-${a}-${i[a].length-1}`}addDealerCard(a){return this.visibleState={...this.visibleState,dealerCards:[...this.visibleState.dealerCards,a]},`d-${this.visibleState.dealerCards.length-1}`}updateDealerCard(a,e,i){this.visibleState={...this.visibleState,dealerCards:this.visibleState.dealerCards.map((r,n)=>{if(n===a)return{...e,faceDown:i};return r})}}setSuppressAnimations(a){this.suppressNextContentAnimations=a}setSideBetResults(a){this.sideBetResults=a}revertToStandardModeIfNoSideBets(){if(!this.sideBetMode)return;if(![this.pairBonusAmount,this.threeCardBonusAmount].some((e)=>fa(e)&&K(e).gt(0)))this.sideBetMode=!1}async finishRound(a){if(!this.canonicalState)return;let e=this.canonicalState.multiplier.toNumber(),i=e>1;this.addToHistory(e,i,a.id),this.updateHistoryWithBet({id:a.id,amount:a.amount,payout:a.payout});let r=yt(this.canonicalState),n=cr(this.canonicalState);if(await this.animationController.waitForAllCardsToBeIdle(),this.updateVisibleState({resultMultiplier:e,mainHandOutcome:r.mainOutcome,splitHandOutcome:r.splitOutcome,insuranceOutcome:n}),await this.forceUIUpdate(),i)this.playWinFeedback();if(a.afterBalance)this.gameData.updateBalance(K(a.afterBalance));this.updateVisibleState({stage:"settled",isActing:!1}),this.hasPendingBet=!1,this.currentBetId=null,this.currentMainBetAmount="0"}async executeNextAction(a){if(!this.currentBetId)return null;let e=await this.getBlackjackApi().next({betId:this.currentBetId,type:a});if(!e.success)return this.showError(R(i1(e.errorCode),this.gameData.language||W)),null;let i=dr(e.data);return this.canonicalState=i,e.data}async blackjackPlay(){if(this.isGameActive)return;this.updateVisibleState({isActing:!0}),this.gameData.soundEffects?.play(ca.buttonPress(0.5));try{await this.betController.handleBetExecution(this.gameData.betAmount??"0")}catch{this.showError(R("alerts.gameError",this.gameData.language||W))}finally{this.updateVisibleState({isActing:!1})}}async executeAutobet(a,e){return{pnl:K(0),gameOutcome:"Draw",hasError:!0,errorMessage:R("alerts.gameError",this.gameData.language||W)}}triggerForceUIUpdate(){return this.forceUIUpdate()}triggerShowError(a){this.showError(a)}setHasPendingBet(a){this.hasPendingBet=a}canAffordAction(a){if(!this.gameData?.hasLoadedBalance)return!0;if(!fa(this.currentMainBetAmount))return!0;let e=K(this.gameData.balance??0),i=K(this.currentMainBetAmount);switch(a){case ja.SPLIT:case ja.DOUBLE_DOWN:return e.gte(i);case ja.BUY_INSURANCE:return e.gte(i.div(2));case ja.HIT:case ja.STAND:case ja.START:case ja.REJECT_INSURANCE:return!0;default:return!1}}canPerformAction(a){return this.visibleState.stage==="player"&&!this.controlsLocked&&this.currentBetId!==null&&ss(this.canonicalState).includes(a)&&this.canAffordAction(a)}onBuyInsurance=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleInsurance(ja.BUY_INSURANCE),"buy-insurance")};onDeclineInsurance=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleInsurance(ja.REJECT_INSURANCE),"no-insurance")};handleHit=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleHit(this.currentBetId),"hit")};handleStand=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleStand(this.currentBetId),"stand")};handleDoubleDown=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleDoubleDown(this.currentBetId),"double")};handleSplit=async()=>{await this.runWithLockedControls(()=>this.actionHandlers.handleSplit(this.currentBetId),"split")};isSpacebarDisabled=()=>{if(!this.gameData.hotkeysOpenEnabled||this.isGameActive)return!0;return this._blackjackManualEl?.isPrimaryActionDisabled()??!0};isHitDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.HIT)};isStandDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.STAND)};isSplitDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.SPLIT)};isDoubleDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||!this.canPerformAction(ja.DOUBLE_DOWN)};isAcceptInsuranceDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||this.controlsLocked||this.visibleState.stage!=="insurance"||!this.canAffordAction(ja.BUY_INSURANCE)};isNoInsuranceDisabled=()=>{return!this.gameData.hotkeysOpenEnabled||this.controlsLocked||this.visibleState.stage!=="insurance"};handleAcceptInsurance=()=>{if(this.isAcceptInsuranceDisabled())return;this.onBuyInsurance()};handleNoInsurance=()=>{if(this.isNoInsuranceDisabled())return;this.onDeclineInsurance()};handleSpacebar=()=>{if(this.isSpacebarDisabled())return;this._blackjackManualEl?.triggerPrimaryAction()};onBetModeChange=(a)=>{if(!Y1(a.detail.tab))return;if(a.detail.tab==="Manual"&&this.showSideBetOnboarding){this.showSideBetOnboarding=!1;return}if(a.detail.tab==="Auto"&&!this.sideBetMode&&!this.sideBetOnboardingComplete){this.showSideBetOnboarding=!0;return}this.showSideBetOnboarding=!1,this.sideBetMode=a.detail.tab==="Auto"};get sideBetOnboardingComplete(){if(typeof localStorage==="undefined")return!1;return localStorage.getItem(O6)==="1"}handleSideBetOnboardingComplete=()=>{if(typeof localStorage!=="undefined")localStorage.setItem(O6,"1");this.showSideBetOnboarding=!1,this.sideBetMode=!0};onPairBonusAmountChange=(a)=>{this.pairBonusAmount=a.detail.value};onThreeCardBonusAmountChange=(a)=>{this.threeCardBonusAmount=a.detail.value};onDealSound=()=>{this.gameData.soundEffects?.play(ca.cardSlide())};onCardFlip=()=>{this.gameData.soundEffects?.play(ca.cardFlip())};render(){let a=this.gameData.mainWidth>=768,e=this.areInputsDisabled||this.isGameActive||this.totalBetExceedsBalance,i=Va(this.gameData);return x`
16577
16577
  <origami-game-layout style=${i} .gameType=${"BLACKJACK"} data-is-desktop=${a}>
16578
16578
  <origami-game-sidebar
16579
16579
  slot="control-panel"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betorigami/games",
3
- "version": "2.8.5",
3
+ "version": "2.8.6",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",