yolkbot 0.1.4-alpha.2 → 0.1.4-alpha.4
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.
package/dist/bot.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
|
|
3
|
-
import{createAccount as B,loginAnonymously as D,loginWithCredentials as L,loginWithRefreshToken as H,queryServices as I}from"./api.js";import s from"./comm/CommIn.js";import P from"./comm/CommOut.js";import{CommCode as r}from"./constants/codes.js";import x from"./bot/GamePlayer.js";import W from"./matchmaker.js";import j from"./socket.js";import{ChiknWinnerDailyLimit as $,CollectTypes as _,CoopStates as w,findItemById as g,GameActions as C,GameModes as k,GameOptionFlags as v,GunList as q,IsBrowser as K,ItemTypes as Z,Movements as T,PlayTypes as Y,ProxiesEnabled as J,ShellStreaks as p}from"./constants/index.js";import O from"./dispatches/LookAtPosDispatch.js";import R from"./dispatches/MovementDispatch.js";import{NodeList as Q}from"./pathing/mapnode.js";import{Challenges as V}from"./constants/challenges.js";import{Maps as U}from"./constants/maps.js";const M=Object.fromEntries(Object.entries(w).map(([y,t])=>[t,y])),E=Object.fromEntries(Object.entries(k).map(([y,t])=>[t,y])),F={CHALLENGES:1,STATS:2,PATHFINDING:3,BUFFERS:4,PING:5,COSMETIC_DATA:6,PLAYER_HEALTH:7,PACKET_HOOK:8,MONITOR:9};class X{static Intents=F;Intents=F;constructor(t={}){if(t.proxy&&!J)throw new Error("proxies do not work and hence are not supported in the browser");this.intents=t.intents||[],this.instance=t.instance||"shellshock.io",this.proxy=t.proxy||"",this.autoUpdate=t.doUpdate||!0,this.updateInterval=t.updateInterval||16.5,this._hooks={},this._globalHooks=[],this._liveCallbacks=[],this.state={name:"",weaponIdx:0,reloading:!1,swappingGun:!1,usingMelee:!1,shotsFired:0,quit:!1},this.players={},this.me=new x(this.id,0,{}),this.game={raw:{},code:"",socket:null,gameModeId:0,gameMode:E[0],mapIdx:0,map:{filename:"",hash:"",name:"",modes:{FFA:!1,Teams:!1,Spatula:!1,King:!1},availability:"both",numPlayers:"18",raw:{},nodes:{},zones:[]},playerLimit:0,isGameOwner:!1,isPrivate:!0,options:{gravity:1,damage:1,healthRegen:1,locked:!1,noTeamChange:!1,noTeamShuffle:!1,weaponsDisabled:Array(7).fill(!1),mustUseSecondary:!1},collectables:[[],[]],teamScore:[0,0,0],spatula:{coords:{x:0,y:0,z:0},controlledBy:0,controlledByTeam:0},stage:w.capturing,zoneNumber:0,activeZone:[],capturing:0,captureProgress:0,numCapturing:0,stageName:"",capturePercent:0,eggOrg:{evil:0,good:0}},this.account={id:0,firebaseId:"",sessionId:"",session:"",email:"",password:"",cw:{atLimit:!1,limit:0,secondsUntilPlay:0,canPlayAgain:Date.now()},loadout:{hatId:null,meleeId:0,stampId:null,classIdx:0,colorIdx:0,grenadeId:0,primaryId:[3100,3600,3400,3800,4e3,4200,4500],secondaryId:new Array(7).fill(3e3),stampPositionX:0,stampPositionY:0},ownedItemIds:[],vip:!1,accountAge:0,emailVerified:!1,eggBalance:0,eggOrgSide:"none",rawLoginData:{}},this._dispatches=[],this._packetQueue=[],this.matchmaker=null,this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastChatTime=-1,this.lastUpdateTime=-1,this.controlKeys=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0},this.intents.includes(this.Intents.PLAYER_HEALTH)&&(this.healthIntervalId=setInterval(()=>{if(this.players){for(const e of Object.values(this.players))if(e.playing&&e.hp>0){const a=.1*(this.game.isPrivate?this.game.options.healthRegen:1);e.streakRewards.includes(p.OverHeal)?e.hp=Math.max(100,e.hp-a):e.hp=Math.min(100,e.hp+a)}}},33))}dispatch(t){this._dispatches.push(t)}async createAccount(t,e){this.account.email=t,this.account.password=e;const a=await B(t,e,this.proxy,this.instance);return await this.#e(a.playerOutput)}async login(t,e){this.account.email=t,this.account.password=e;const a=await L(t,e,this.proxy,this.instance);return await this.#e(a.playerOutput)}async loginWithRefreshToken(t){const e=await H(t,this.proxy,this.instance);return await this.#e(e.playerOutput)}async loginAnonymously(){delete this.account.email,delete this.account.password;const t=await D(this.proxy,this.instance);return await this.#e(t.playerOutput)}async#e(t){return typeof t!="object"?(this.emit("authFail",t),!1):t.banRemaining?(this.emit("banned",t.banRemaining),!1):(this.account.rawLoginData=t,this.account.accountAge=t.accountAge,this.account.eggBalance=t.currentBalance,this.account.eggOrgSide=t.eggOrgNeedsFaction==="rew_eggfu"?"good":"evil",this.account.emailVerified=t.emailVerified,this.account.firebaseId=t.firebaseId,this.account.id=t.id,this.account.loadout=t.loadout,this.account.ownedItemIds=t.ownedItemIds,this.account.session=t.session,this.account.sessionId=t.sessionId,this.account.vip=t.upgradeProductId&&!t.upgradeIsExpired,this.intents.includes(this.Intents.STATS)&&(this.account.stats={lifetime:t.statsLifetime,monthly:t.statsCurrent}),this.intents.includes(this.Intents.CHALLENGES)&&this.#t(t.challenges),this.account)}#t(t){this.account.challenges=[];for(const e of t){const a=V.find(n=>n.id==e.challengeId);a&&(delete e.playerId,this.account.challenges.push({raw:{challengeInfo:a,challengeData:e},id:e.challengeId,name:a.loc.title,desc:a.loc.desc,rewardEggs:a.reward,isRerolled:!!e.reset,isClaimed:!!e.claimed,isCompleted:!!e.completed,progressNum:e.progress,goalNum:a.goal}))}}async initMatchmaker(){return!this.account.sessionId&&!await this.loginAnonymously()?!1:(this.matchmaker||(this.matchmaker=new W({sessionId:this.account.sessionId,proxy:this.proxy,instance:this.instance}),this.matchmaker.on("authFail",t=>this.emit("authFail",t)),await this.matchmaker.getRegions()),!0)}async#n(t){return await this.initMatchmaker()?await new Promise(e=>{const a=n=>{if(n.command=="gameFound"&&(this.matchmaker.off("msg",a),this.game.raw=n,this.game.code=n.id,e()),n.error&&n.error=="gameNotFound")throw new Error(`Game ${t} not found (likely expired).`)};this.matchmaker.on("msg",a),this.matchmaker.send({command:"joinGame",id:t,observe:!1,sessionId:this.account.sessionId})}):!1}async createPrivateGame(t={}){if(!await this.initMatchmaker())return!1;if(!t.region)throw new Error('pass a region: createPrivateGame({ region: "useast", ... })');if(!this.matchmaker.regionList.find(n=>n.id==t.region))throw new Error('invalid region, see <bot>.matchmaker.regionList for a region list (pass an "id")');if(!t.mode)throw new Error('pass a mode: createPrivateGame({ mode: "ffa", ... })');if(k[t.mode]==null)throw new Error("invalid mode, see GameModes for a list");if(!t.map)throw new Error('pass a map: createPrivateGame({ map: "downfall", ... })');const e=U.find(n=>n.name.toLowerCase()==t.map.toLowerCase()),a=U.indexOf(e);if(a==-1)throw new Error("invalid map, see the Maps constant for a list");return await new Promise(n=>{const i=o=>{o.command=="gameFound"&&(this.matchmaker.off("msg",i),this.game.raw=o,this.game.code=this.game.raw.id,n())};this.matchmaker.on("msg",i),this.matchmaker.send({command:"findGame",region:t.region,playType:Y.createPrivate,gameType:k[t.mode],sessionId:this.account.sessionId,noobLobby:!1,map:a})}),this.game.raw}async join(t,e){if(this.state.name=t||"yolkbot",typeof e=="string"?(e.includes("#")&&(e=e.split("#")[1]),await this.#n(e)):typeof e=="object"&&(this.account.id==0&&await this.loginAnonymously(),this.game.raw=e,this.game.code=this.game.raw.id),!this.game.raw.id||!this.game.raw.subdomain)throw new Error("invalid game data passed to <bot>.join");const a=async()=>{try{this.game.socket=new j(`wss://${this.game.raw.subdomain}.${this.instance}/game/${this.game.raw.id}`,this.proxy),this.game.socket.onerror=async n=>(console.error(n),await new Promise(i=>setTimeout(i,100)),await a())}catch{await new Promise(n=>setTimeout(n,100)),await a()}};await a(),this.game.socket.binaryType="arraybuffer",this.game.socket.onopen=()=>{this.game.socket.onerror=null},this.game.socket.onmessage=n=>this.processPacket(n.data),this.game.socket.onclose=n=>{this.emit("close",n.code),this.quit(!0,!0)}}#i(){if(Object.entries(this.me.position).map(e=>Math.floor(e[1])).join(",")==this.pathing.activePath[this.pathing.activePath.length-1].positionStr())this.pathing.followingPath=!1,this.pathing.activePath=null,this.pathing.activeNode=null,this.pathing.activeNodeIdx=0,this.dispatch(new R(0));else{let e;this.pathing.activeNodeIdx<this.pathing.activePath.length-1?(e=this.pathing.activePath[this.pathing.activeNodeIdx+1].flatCenter(),this.dispatch(new O(e))):(e=this.pathing.activePath[this.pathing.activeNodeIdx].flatCenter(),this.dispatch(new O(e)));for(const a of this.pathing.activePath)if(a.flatRadialDistance(this.me.position)<.1&&a.position.y==Math.floor(this.me.position.y)&&this.pathing.activePath.indexOf(a)>=this.pathing.activeNodeIdx){this.pathing.activeNodeIdx=this.pathing.activePath.indexOf(a)+1,this.pathing.activeNode=this.pathing.activePath[this.pathing.activeNodeIdx];break}this.controlKeys&T.FORWARD||this.dispatch(new R(T.FORWARD))}}update(){if(!this.state.joinedGame)throw new Error("You cannot call update() if the bot is not in a game.");if(this.state.quit)return;for(this.pathing.followingPath&&this.intents.includes(this.Intents.PATHFINDING)&&this.#i();this._packetQueue.length>0;)this.processPacket(this._packetQueue.shift());if(this._dispatches.length>0)for(let e=0;e<this._dispatches.length;e++){const a=this._dispatches[e];if(a.check(this)){a.execute(this),this._dispatches.splice(e,1);break}}const t=Date.now();if(t-this.lastUpdateTime>=50){if(this.emit("tick"),!this.intents.includes(this.Intents.MONITOR)){const e=P.getBuffer();e.packInt8(r.syncMe),e.packInt8(Math.random()*128|0),e.packInt8(this.me.serverStateIdx);for(let a=0;a<3;a++)e.packInt8(this.controlKeys),e.packInt8(this.state.shotsFired),e.packRadU(this.me.view.yaw),e.packRad(this.me.view.pitch),e.packInt8(100);e.send(this.game.socket)}this.lastUpdateTime=t,this.state.shotsFired=0}for(;this._liveCallbacks.length>0;)this._liveCallbacks.shift()()}on(t,e){Object.keys(this._hooks).includes(t)?this._hooks[t].push(e):this._hooks[t]=[e]}onAny(t){this._globalHooks.push(t)}#a=["authFail","banned"];emit(t,...e){if(!this.state.quit){if(this._hooks[t])for(const a of this._hooks[t])this.#a.includes(t)?a(...e):this._liveCallbacks.push(()=>a(...e));for(const a of this._globalHooks)this.#a.includes(t)?a(t,...e):this._liveCallbacks.push(()=>a(t,...e))}}async#o(t,e){if(K)return await(await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${t}.json`)).json();{const{existsSync:a,mkdirSync:n,readFileSync:i,writeFileSync:o}=await import("node:fs"),{join:c}=await import("node:path"),{homedir:l}=await import("node:os"),m=c(l(),".yolkbot"),d=c(m,"maps");a(m)||n(m),a(d)||n(d);const h=c(d,`${t}-${e}.json`);if(a(h))return JSON.parse(i(h,"utf-8"));console.log("map not in cache, IMPORT!!",t,e);const f=await(await fetch(`https://${this.instance}/maps/${t}.json?${e}`)).json();return o(h,JSON.stringify(f,null,4),{flag:"w+"}),f}}#c(){const t=this.game.map.raw.data["DYNAMIC.capture-zone.none"];if(!t)return delete this.game.map.zones;let e=0;const a={},n=[];for(const c of t)a[c.x]||(a[c.x]={}),a[c.x][c.y]||(a[c.x][c.y]={}),a[c.x][c.y][c.z]={zone:null};const i=[{x:-1,z:0},{x:1,z:0},{x:0,z:-1},{x:0,z:1}];function o(c,l,m){return a[c]&&a[c][l]&&a[c][l][m]?a[c][l][m]:null}for(const c of t)if(!a[c.x][c.y][c.z].zone){c.zone=++e,a[c.x][c.y][c.z].zone=c.zone;const l=[c];let m;do{m=0;for(const d of t)if(!a[d.x][d.y][d.z].zone)for(const h of i){const f=o(d.x+h.x,d.y,d.z+h.z);if(f&&f.zone==c.zone){m++,d.zone=c.zone,a[d.x][d.y][d.z].zone=c.zone,l.push(d);break}}}while(m>0);n.push(l)}this.game.map.zones=n}#r(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackString().valueOf(),n=this.players[Object.keys(this.players).find(i=>this.players[i].id==t)];this.emit("chat",n,a,e)}#h(){const t=s.unPackInt8U(),e=this.intents.includes(this.Intents.COSMETIC_DATA),a={id_:t,uniqueId_:s.unPackString(),name_:s.unPackString(),safename_:s.unPackString(),charClass_:s.unPackInt8U(),team_:s.unPackInt8U(),primaryWeaponItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),secondaryWeaponItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),shellColor_:s.unPackInt8U(),hatItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),stampItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),_unused:s.unPackInt8(),_unused2:s.unPackInt8(),grenadeItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),meleeItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),x_:s.unPackFloat(),y_:s.unPackFloat(),z_:s.unPackFloat(),dx_:s.unPackFloat(),dy_:s.unPackFloat(),dz_:s.unPackFloat(),yaw_:s.unPackRadU(),pitch_:s.unPackRad(),score_:s.unPackInt32U(),kills_:s.unPackInt16U(),deaths_:s.unPackInt16U(),streak_:s.unPackInt16U(),totalKills_:s.unPackInt32U(),totalDeaths_:s.unPackInt32U(),bestGameStreak_:s.unPackInt16U(),bestOverallStreak_:s.unPackInt16U(),shield_:s.unPackInt8U(),hp_:s.unPackInt8U(),playing_:s.unPackInt8U(),weaponIdx_:s.unPackInt8U(),controlKeys_:s.unPackInt8U(),upgradeProductId_:s.unPackInt8U(),activeShellStreaks_:s.unPackInt8U(),social_:s.unPackLongString(),hideBadge_:s.unPackInt8U()};a.gameData_={},a.gameData_.mapIdx=s.unPackInt8U(),a.gameData_.private=s.unPackInt8U(),a.gameData_.gameType=s.unPackInt8U(),this.players[a.id_]||(this.players[a.id_]=new x(a.id_,a.team_,a)),this.me.id==a.id_&&(this.me=this.players[a.id_]),this.emit("playerJoin",this.players[a.id_])}#l(){const t=s.unPackInt8U(),e=s.unPackInt16U(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),c=s.unPackInt8U(),l=s.unPackInt8U(),m=s.unPackInt8U(),d=s.unPackInt8U(),h=this.players[t];h&&(h.playing=!0,h.randomSeed=e,h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.rounds=o),h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.store=c),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.rounds=l),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.store=m),h.grenades=d,h.position={x:a,y:n,z:i},this.emit("playerRespawn",h))}#m(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackInt8U(),o=this.players[t];if(!o||o.id==this.me.id){for(let c=0;c<3;c++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U();return}if(o.position.x!==e&&(o.position.x=e),o.position.z!==n&&(o.position.z=n),(!o.jumping||Math.abs(o.position.y-a)>.5&&o.position.y!==a)&&(o.position.y=a),o.climbing!==i&&(o.climbing=i),this.intents.includes(this.Intents.BUFFERS)){if(!o.buffer)return;for(let c=0;c<3;c++){o.buffer[c].controlKeys=s.unPackInt8U();const l=s.unPackRadU();isNaN(l)||(o.buffer[c].yaw_=l);const m=s.unPackRad();isNaN(m)||(o.buffer[c].pitch_=m),s.unPackInt8U()}o.buffer[0].x=e,o.buffer[0].y=a,o.buffer[0].z=n}else for(let c=0;c<3;c++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U()}#d(){const t=s.unPackInt8U(),e=this.players[t];e&&(e.playing=!1,this.emit("playerPause",e))}#u(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];a&&(a.activeGun=e,this.emit("playerSwapWeapon",a,e))}#p(){const t=s.unPackInt8U(),e=s.unPackInt8U();s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U();const a=this.players[t],n=this.players[e];a&&(a.playing=!1,a.streak=0,a.lastDeathTime=Date.now(),a.hp=100,a.hpShield=0),n&&n.streak++,this.emit("playerDeath",a,n)}#g(){const t=s.unPackInt8U();for(let n=0;n<6;n++)s.unPackFloat();const e=this.players[t],a=e.weapons[e.activeGun];a&&a.ammo&&(a.ammo.rounds--,this.emit("playerFire",e,a))}#k(){const t=s.unPackInt16U(),e=s.unPackInt8U(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat();this.game.collectables[e].push({id:t,x:a,y:n,z:i}),this.emit("spawnItem",e,t,{x:a,y:n,z:i})}#I(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt8U(),n=s.unPackInt16U(),i=this.players[t];if(this.game.collectables[e]=this.game.collectables[e].filter(o=>o.id!=n),e==_.AMMO){const o=i.weapons[a];o&&o.ammo&&(o.ammo.store=Math.min(o.ammo.storeMax,o.ammo.store+o.ammo.pickup),this.emit("collectAmmo",i,o))}e==_.GRENADE&&(i.grenades++,i.grenades>3&&(i.grenades=3),this.emit("collectGrenade",i))}#f(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const n=a.hp;a.hp=e,this.emit("playerDamaged",a,n,a.hp)}#P(){const t=s.unPackInt8U();s.unPackFloat(),s.unPackFloat();const e=this.me.hp;this.me.hp=t,this.emit("selfDamaged",e,this.me.hp)}#y(){const t=s.unPackInt8U(),e=this.players[t];if(!e)return;s.unPackInt8U();const a=s.unPackInt8U();e.serverStateIdx=a;const n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat();s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U();const c=e.position.x,l=e.position.y,m=e.position.z;e.position.x=n,e.position.y=i,e.position.z=o,(c!=n||l!=i||m!=o)&&this.emit("selfMoved",e,{x:c,y:l,z:m},{x:n,y:i,z:o})}#w(){if(!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.eventModifier),t.send(this.game.socket)}}#U(){const t=s.unPackInt8U(),e={...this.players[t]};delete this.players[t.toString()],this.emit("playerLeave",e)}#b(){if(this.game.gameModeId==k.spatula){this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U();const t={x:s.unPackFloat(),y:s.unPackFloat(),z:s.unPackFloat()},e=s.unPackInt8U(),a=s.unPackInt8U();this.game.spatula={coords:t,controlledBy:e,controlledByTeam:a},this.emit("gameStateChange",this.game)}else this.game.gameModeId==k.kotc?(this.game.stage=s.unPackInt8U(),this.game.zoneNumber=s.unPackInt8U(),this.game.capturing=s.unPackInt8U(),this.game.captureProgress=s.unPackInt16U(),this.game.numCapturing=s.unPackInt8U(),this.game.teamScore[1]=s.unPackInt8U(),this.game.teamScore[2]=s.unPackInt8U(),this.game.stageName=M[this.game.stage],this.game.capturePercent=this.game.captureProgress/1e3,this.game.activeZone=this.game.map.zones?this.game.map.zones[this.game.zoneNumber-1]:null,this.emit("gameStateChange",this.game)):this.game.gameModeId==k.team&&(this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U());this.game.gameModeId!==k.spatula&&delete this.game.spatula,this.game.gameModeId!==k.kotc&&(delete this.game.stage,delete this.game.zoneNumber,delete this.game.capturing,delete this.game.captureProgress,delete this.game.numCapturing,delete this.game.stageName,delete this.game.numCapturing,delete this.game.activeZone),this.game.gameModeId==k.ffa&&delete this.game.teamScore}#S(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];switch(e){case p.HardBoiled:a.hpShield=100,a.streakRewards.push(p.HardBoiled);break;case p.EggBreaker:a.streakRewards.push(p.EggBreaker);break;case p.Restock:{a.grenades=3,a.weapons[0]&&a.weapons[0].ammo&&(a.weapons[0].ammo.rounds=a.weapons[0].ammo.capacity,a.weapons[0].ammo.store=a.weapons[0].ammo.storeMax),a.weapons[1]&&a.weapons[1].ammo&&(a.weapons[1].ammo.rounds=a.weapons[1].ammo.capacity,a.weapons[1].ammo.store=a.weapons[1].ammo.storeMax);break}case p.OverHeal:a.hp=Math.min(200,a.hp+100),a.streakRewards.push(p.OverHeal);break;case p.DoubleEggs:a.streakRewards.push(p.DoubleEggs);break;case p.MiniEgg:a.streakRewards.push(p.MiniEgg);break}this.emit("playerBeginStreak",a,e)}#x(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];[p.EggBreaker,p.OverHeal,p.DoubleEggs,p.MiniEgg].includes(e)&&a.streakRewards.includes(e)&&(a.streakRewards=a.streakRewards.filter(i=>i!=e)),this.emit("playerEndStreak",e,a)}#_(){const t=s.unPackInt8U(),e=s.unPackInt8U();s.unPackFloat(),s.unPackFloat(),this.me.hpShield=t,this.me.hp=e,this.me.hpShield<=0?(this.me.streakRewards=this.me.streakRewards.filter(a=>a!=p.HardBoiled),this.emit("selfShieldLost")):this.emit("selfShieldHit",this.me.hpShield)}#C(){const t={...this.game.options};let e=s.unPackInt8U(),a=s.unPackInt8U(),n=s.unPackInt8U();(e<1||e>4)&&(e=4),(a<0||a>8)&&(a=4),n>16&&(n=4),this.game.options.gravity=e/4,this.game.options.damage=a/4,this.game.options.healthRegen=n/4;const i=s.unPackInt8U();return Object.keys(v).forEach(o=>{const c=i&v[o]?1:0;this.game.options[o]=c}),this.game.options.weaponsDisabled=Array.from({length:7},()=>s.unPackInt8U()===1),this.game.options.mustUseSecondary=this.game.options.weaponsDisabled.every(o=>o),this.emit("gameOptionsChange",t,this.game.options),!1}#v(){const t=s.unPackInt8U();t==C.pause&&(this.emit("gameForcePause"),setTimeout(()=>this.me.playing=!1,3e3)),t==C.reset&&(Object.values(this.players).forEach(e=>e.streak=0),this.game.gameModeId!==k.ffa&&(this.game.teamScore=[0,0,0]),this.game.gameModeId===k.spatula&&(this.game.spatula.controlledBy=0,this.game.spatula.controlledByTeam=0,this.game.spatula.coords={x:0,y:0,z:0}),this.game.gameModeId===k.kotc&&(this.game.stage=w.capturing,this.game.zoneNumber=0,this.game.activeZone=null,this.game.capturing=0,this.game.captureProgress=0,this.game.numCapturing=0,this.game.stageName=M[w.capturing],this.game.capturePercent=0),this.emit("gameReset"))}#T(){if(!this.intents.includes(this.Intents.PING))return;const t=this.ping;this.ping=Date.now()-this.lastPingTime,this.emit("pingUpdate",t,this.ping),this.intents.includes(this.Intents.MONITOR)||setTimeout(()=>{const e=P.getBuffer();e.packInt8(r.ping),e.send(this.game.socket),this.lastPingTime=Date.now()},this.pingInterval)}#O(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const n=a.team;a.team=e,a.streak=0,this.emit("playerSwitchTeam",a,n,e)}#R(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt16U(),n=s.unPackInt16U(),i=s.unPackInt8U(),o=s.unPackInt16U(),c=s.unPackInt16U(),l=s.unPackInt16U(),m=s.unPackInt16U();s.unPackInt8(),s.unPackInt8();const d=this.intents.includes(this.Intents.COSMETIC_DATA),h=d?g(a):a,f=d?g(n):n,G=d?g(o):o,z=d?g(c):c,A=d?g(l):l,N=d?g(m):m,u=this.players[t];if(u){const b={...u.character},S=u.selectedGun;u.character.eggColor=i,u.character.primaryGun=h,u.character.secondaryGun=f,u.character.stamp=z,u.character.hat=G,u.character.grenade=A,u.character.melee=N,u.selectedGun=e,u.weapons[0]=new q[e],S!==u.selectedGun&&this.emit("playerChangeGun",u,S,u.selectedGun),b!==u.character&&this.emit("playerChangeCharacter",u,b,u.character)}}#M(){const t=s.unPackInt32U(),e=this.account.eggBalance;this.account.eggBalance=t,this.emit("balanceUpdate",t-e,t)}#E(){this.me.playing=!1,this.emit("selfRespawnFail")}#F(){const t=s.unPackInt8U(),e=this.players[t];e&&this.emit("playerMelee",e)}#G(){const t=s.unPackInt8U(),e=this.players[t];if(!e)return;const a=e.weapons[e.activeGun];if(a.ammo){const n=Math.min(Math.min(a.ammo.capacity,a.ammo.reload)-a.ammo.rounds,a.ammo.store);a.ammo.rounds+=n,a.ammo.store-=n}this.emit("playerReload",e,a)}#z(){if(!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.gameOptions),t.packInt8(this.game.options.gravity*4),t.packInt8(this.game.options.damage*4),t.packInt8(this.game.options.healthRegen*4);const e=(this.game.options.locked?1:0)|(this.game.options.noTeamChange?2:0)|(this.game.options.noTeamShuffle?4:0);t.packInt8(e),this.game.options.weaponsDisabled.forEach(a=>{t.packInt8(a?1:0)}),t.send(this.game.socket)}}#A(){const t=s.unPackInt8U();let e=s.unPackInt16U();const a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),c=s.unPackFloat();this.intents.includes(this.Intents.COSMETIC_DATA)&&(e=g(e)),t==Z.Grenade?this.emit("grenadeExploded",e,{x:a,y:n,z:i},o,c):this.emit("rocketHit",{x:a,y:n,z:i},o,c)}#N(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),c=s.unPackFloat(),l=this.players[t];l&&(l.grenades--,this.emit("playerThrowGrenade",l,{x:e,y:a,z:n},{x:i,y:o,z:c}))}#B(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;if(!this.intents.includes(this.Intents.CHALLENGES))return this.emit("challengeComplete",a,e);const n=this.account.challenges.find(i=>i.id==e);this.emit("challengeComplete",a,n),a.id==this.me.id&&this.refreshChallenges()}#D(){this.#s()}#s(){const t=s.unPackString();try{const e=JSON.parse(t);this.game.eggOrg.evil=e[0],this.game.eggOrg.good=e[1],this.emit("eggOrgUpdate",this.game.eggOrg)}catch{}}#L(){if(!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.joinGame),t.packString(this.state.name),t.packString(this.game.raw.uuid),t.packInt8(0),t.packInt8(this.state.weaponIdx||0),t.packInt32(this.account.session),t.packString(this.account.firebaseId),t.packString(this.account.sessionId),t.send(this.game.socket)}}async#H(){if(this.me.id=s.unPackInt8U(),this.me.team=s.unPackInt8U(),this.game.gameModeId=s.unPackInt8U(),this.game.gameMode=E[this.game.gameModeId],this.game.mapIdx=s.unPackInt8U(),this.game.map=U[this.game.mapIdx],this.intents.includes(this.Intents.PATHFINDING)&&(this.game.map.raw=await this.#o(this.game.map.filename,this.game.map.hash),this.pathing.nodeList=new Q(this.game.map.raw),this.game.gameModeId===k.kotc&&this.#c()),this.game.playerLimit=s.unPackInt8U(),this.game.isGameOwner=s.unPackInt8U()==1,this.game.isPrivate=s.unPackInt8U()==1,this.state.joinedGame=!0,this.lastDeathTime=Date.now(),!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.clientReady),t.send(this.game.socket),this.game.socket.onmessage=e=>this._packetQueue.push(e.data)}if(this.autoUpdate&&(this.updateIntervalId=setInterval(()=>this.update(),this.updateInterval)),this.intents.includes(this.Intents.PING)&&(this.lastPingTime=Date.now(),!this.intents.includes(this.Intents.MONITOR))){const t=P.getBuffer();t.packInt8(r.ping),t.send(this.game.socket)}}processPacket(t){s.init(t),this.intents.includes(this.Intents.PACKET_HOOK)&&this.emit("packet",t);let e=0,a=0,n=!1;for(;s.isMoreDataAvailable()&&!n;){const i=s.unPackInt8U();switch(i){case r.syncThem:this.#m();break;case r.fire:this.#g();break;case r.hitThem:this.#f();break;case r.syncMe:this.#y();break;case r.hitMe:this.#P();break;case r.swapWeapon:this.#u();break;case r.collectItem:this.#I();break;case r.respawn:this.#l();break;case r.die:this.#p();break;case r.pause:this.#d();break;case r.chat:this.#r();break;case r.addPlayer:this.#h();break;case r.removePlayer:this.#U();break;case r.eventModifier:this.#w();break;case r.metaGameState:this.#b();break;case r.beginShellStreak:this.#S();break;case r.endShellStreak:this.#x();break;case r.hitMeHardBoiled:this.#_();break;case r.gameOptions:this.#C();break;case r.ping:this.#T();break;case r.switchTeam:this.#O();break;case r.changeCharacter:this.#R();break;case r.reload:this.#G();break;case r.explode:this.#A();break;case r.throwGrenade:this.#N();break;case r.eggOrgUpdate:this.#s();break;case r.spawnItem:this.#k();break;case r.melee:this.#F();break;case r.updateBalance:this.#M();break;case r.challengeCompleted:this.#B();break;case r.socketReady:this.#L();break;case r.gameJoined:this.#H();break;case r.gameAction:this.#v();break;case r.requestGameOptions:this.#z();break;case r.respawnDenied:this.#E();break;case r.clientReady:this.#D();break;case r.expireUpgrade:break;case r.musicInfo:s.unPackLongString();break;default:console.error(`handlePacket: I got but did not handle a: ${Object.keys(r).find(o=>r[o]===i)} ${i}`),e&&console.error(`handlePacket: It may be a result of the ${e} command (${a}).`),n=!0;break}e=Object.keys(r).find(o=>r[o]===i),a=i}}async checkChiknWinner(){const t=await I({cmd:"chicknWinnerReady",id:this.account.id,sessionId:this.account.sessionId});return typeof t=="string"?t:(this.account.cw.limit=t.limit,this.account.cw.atLimit=t.limit>=4,this.account.cw.secondsUntilPlay=(this.account.cw.atLimit?t.period:t.span)||0,this.account.cw.canPlayAgain=Date.now()+this.account.cw.secondsUntilPlay*1e3,this.account.cw)}async playChiknWinner(t=!0){if(this.account.cw.atLimit||this.account.cw.limit>$)return"hit_daily_limit";if(this.account.cw.canPlayAgain>Date.now()&&t)return"on_cooldown";const e=await I({cmd:"incentivizedVideoReward",firebaseId:this.account.firebaseId,id:this.account.id,sessionId:this.account.sessionId,token:null},this.proxy,this.instance);return typeof e=="string"?e:e.error?e.error=="RATELIMITED"||e.error=="RATELMITED"?(await this.checkChiknWinner(),"on_cooldown"):e.error=="SESSION_EXPIRED"?"session_expired":(console.error("Unknown Chikn Winner response",e),"unknown_error"):e.reward?(this.account.eggBalance+=e.reward.eggsGiven,e.reward.itemIds.forEach(a=>this.account.ownedItemIds.push(a)),await this.checkChiknWinner(),e.reward):(console.error("Unknown Chikn Winner response",e),"unknown_error")}async resetChiknWinner(){if(this.account.eggBalance<200)return"not_enough_eggs";if(!this.account.cw.atLimit)return"not_at_limit";const t=await I({cmd:"chwReset",sessionId:this.account.sessionId});return typeof t=="string"?t:t.result!=="SUCCESS"?(console.error("Unknown Chikn Winner reset response",t),"unknown_error"):(this.account.eggBalance-=200,await this.checkChiknWinner(),this.account.cw)}canSee(t){if(!this.intents.includes(this.Intents.PATHFINDING))throw new Error("You must have the PATHFINDING intent to use this method.");return this.pathing.nodeList.hasLineOfSight(this.me.position,t.position)}getBestTarget(t=()=>!0){const e=Object.values(this.players).filter(i=>i).filter(i=>i!==this.me).filter(i=>i.playing).filter(i=>i.hp>0).filter(i=>i.name!==this.me.name).filter(i=>this.me.team===0||i.team!==this.me.team).filter(i=>this.canSee(i)).filter(i=>!!t(i));let a=200,n=null;for(const i of e){const o=i.position.x-this.me.position.x,c=i.position.y-this.me.position.y,l=i.position.z-this.me.position.z,m=Math.sqrt(o*o+c*c+l*l);m<a&&(a=m,n=i)}return n}async refreshChallenges(){const t=await I({cmd:"challengeGetDaily",sessionId:this.account.sessionId,playerId:this.account.id},this.proxy,this.instance);return this.#t(t),this.account.challenges}async rerollChallenge(t){const e=await I({cmd:"challengeRerollSlot",sessionId:this.account.sessionId,slotId:t},this.proxy,this.instance);return this.#t(e),this.account.challenges}async claimChallenge(t){const e=await I({cmd:"challengeClaimReward",sessionId:this.account.sessionId,slotId:t},this.proxy,this.instance);return this.#t(e.challenges),{eggReward:e.reward,updatedChallenges:this.account.challenges}}async refreshBalance(){const t=await I({cmd:"checkBalance",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId},this.proxy,this.instance);return this.account.eggBalance=t.currentBalance,t.currentBalance}async redeemCode(t){const e=await I({cmd:"redeem",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,id:this.account.id,code:t},this.proxy,this.instance);return e.result==="SUCCESS"?(this.account.eggBalance=e.eggs_given,e.item_ids.forEach(a=>this.account.ownedItemIds.push(a)),{result:e,eggsGiven:e.eggs_given,itemIds:e.item_ids}):e}async claimURLReward(t){const e=await I({cmd:"urlRewardParams",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,reward:t},this.proxy,this.instance);return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async claimSocialReward(t){const e=await I({cmd:"reward",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,rewardTag:t},this.proxy,this.instance);return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async buyItem(t){const e=await I({cmd:"buy",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,itemId:t,save:!0},this.proxy,this.instance);return e.result==="SUCCESS"&&(this.account.eggBalance=e.currentBalance,this.account.ownedItemIds.push(e.itemId)),e}quit(t=!1,e=!1){this.state.quit||(this.intents.includes(this.Intents.PLAYER_HEALTH)&&clearInterval(this.healthIntervalId),clearInterval(this.updateIntervalId),this.game?.socket&&this.game.socket.close(),this.matchmaker&&this.matchmaker.close(),e||(this._dispatches=[]),this._packetQueue=[],t||(delete this.account,delete this.game,delete this.me,delete this.players),this.state.quit=!0)}killZastix(){const t=this.players.find(e=>e.name==="zastix");this.on("tick",()=>{t&&this.canSee(t)&&(this.state.shotsFired+=5)})}}var ue=X;export{X as Bot,ue as default};
|
|
3
|
+
import{createAccount as B,loginAnonymously as D,loginWithCredentials as L,loginWithRefreshToken as H,queryServices as I}from"./api.js";import s from"./comm/CommIn.js";import P from"./comm/CommOut.js";import{CommCode as r}from"./constants/codes.js";import x from"./bot/GamePlayer.js";import W from"./matchmaker.js";import j from"./socket.js";import{ChiknWinnerDailyLimit as $,CollectTypes as _,CoopStates as w,findItemById as g,GameActions as C,GameModes as k,GameOptionFlags as v,GunList as q,IsBrowser as K,ItemTypes as Z,Movements as T,PlayTypes as Y,ProxiesEnabled as J,ShellStreaks as p}from"./constants/index.js";import O from"./dispatches/LookAtPosDispatch.js";import R from"./dispatches/MovementDispatch.js";import{NodeList as Q}from"./pathing/mapnode.js";import{Challenges as V}from"./constants/challenges.js";import{Maps as U}from"./constants/maps.js";const M=Object.fromEntries(Object.entries(w).map(([y,t])=>[t,y])),E=Object.fromEntries(Object.entries(k).map(([y,t])=>[t,y])),F={CHALLENGES:1,STATS:2,PATHFINDING:3,BUFFERS:4,PING:5,COSMETIC_DATA:6,PLAYER_HEALTH:7,PACKET_HOOK:8,MONITOR:9};class X{static Intents=F;Intents=F;constructor(t={}){if(t.proxy&&!J)throw new Error("proxies do not work and hence are not supported in the browser");this.intents=t.intents||[],this.instance=t.instance||"shellshock.io",this.proxy=t.proxy||"",this.autoUpdate=t.doUpdate||!0,this.updateInterval=t.updateInterval||16.5,this._hooks={},this._globalHooks=[],this._liveCallbacks=[],this.state={name:"",weaponIdx:0,reloading:!1,swappingGun:!1,usingMelee:!1,shotsFired:0,quit:!1},this.players={},this.me=new x(this.id,0,{}),this.game={raw:{},code:"",socket:null,gameModeId:0,gameMode:E[0],mapIdx:0,map:{filename:"",hash:"",name:"",modes:{FFA:!1,Teams:!1,Spatula:!1,King:!1},availability:"both",numPlayers:"18",raw:{},nodes:{},zones:[]},playerLimit:0,isGameOwner:!1,isPrivate:!0,options:{gravity:1,damage:1,healthRegen:1,locked:!1,noTeamChange:!1,noTeamShuffle:!1,weaponsDisabled:Array(7).fill(!1),mustUseSecondary:!1},collectables:[[],[]],teamScore:[0,0,0],spatula:{coords:{x:0,y:0,z:0},controlledBy:0,controlledByTeam:0},stage:w.capturing,zoneNumber:0,activeZone:[],capturing:0,captureProgress:0,numCapturing:0,stageName:"",capturePercent:0,eggOrg:{evil:0,good:0}},this.account={id:0,firebaseId:"",sessionId:"",session:"",email:"",password:"",cw:{atLimit:!1,limit:0,secondsUntilPlay:0,canPlayAgain:Date.now()},loadout:{hatId:null,meleeId:0,stampId:null,classIdx:0,colorIdx:0,grenadeId:0,primaryId:[3100,3600,3400,3800,4e3,4200,4500],secondaryId:new Array(7).fill(3e3),stampPositionX:0,stampPositionY:0},ownedItemIds:[],vip:!1,accountAge:0,emailVerified:!1,eggBalance:0,eggOrgSide:"none",rawLoginData:{}},this._dispatches=[],this._packetQueue=[],this.matchmaker=null,this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastChatTime=-1,this.lastUpdateTime=-1,this.controlKeys=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0},this.intents.includes(this.Intents.PLAYER_HEALTH)&&(this.healthIntervalId=setInterval(()=>{if(this.players){for(const e of Object.values(this.players))if(e.playing&&e.hp>0){const a=.1*(this.game.isPrivate?this.game.options.healthRegen:1);e.streakRewards.includes(p.OverHeal)?e.hp=Math.max(100,e.hp-a):e.hp=Math.min(100,e.hp+a)}}},33))}dispatch(t){this._dispatches.push(t)}async createAccount(t,e){this.account.email=t,this.account.password=e;const a=await B(t,e,this.proxy,this.instance);return await this.#e(a.playerOutput)}async login(t,e){this.account.email=t,this.account.password=e;const a=await L(t,e,this.proxy,this.instance);return await this.#e(a.playerOutput)}async loginWithRefreshToken(t){const e=await H(t,this.proxy,this.instance);return await this.#e(e.playerOutput)}async loginAnonymously(){delete this.account.email,delete this.account.password;const t=await D(this.proxy,this.instance);return await this.#e(t.playerOutput)}async#e(t){return typeof t!="object"?(this.emit("authFail",t),!1):t.banRemaining?(this.emit("banned",t.banRemaining),!1):(this.account.rawLoginData=t,this.account.accountAge=t.accountAge,this.account.eggBalance=t.currentBalance,this.account.eggOrgSide=t.eggOrgNeedsFaction==="rew_eggfu"?"good":"evil",this.account.emailVerified=t.emailVerified,this.account.firebaseId=t.firebaseId,this.account.id=t.id,this.account.loadout=t.loadout,this.account.ownedItemIds=t.ownedItemIds,this.account.session=t.session,this.account.sessionId=t.sessionId,this.account.vip=t.upgradeProductId&&!t.upgradeIsExpired,this.intents.includes(this.Intents.STATS)&&(this.account.stats={lifetime:t.statsLifetime,monthly:t.statsCurrent}),this.intents.includes(this.Intents.CHALLENGES)&&this.#t(t.challenges),this.account)}#t(t){this.account.challenges=[];for(const e of t){const a=V.find(n=>n.id==e.challengeId);a&&(delete e.playerId,this.account.challenges.push({raw:{challengeInfo:a,challengeData:e},id:e.challengeId,name:a.loc.title,desc:a.loc.desc,rewardEggs:a.reward,isRerolled:!!e.reset,isClaimed:!!e.claimed,isCompleted:!!e.completed,progressNum:e.progress,goalNum:a.goal}))}}async initMatchmaker(){return!this.account.sessionId&&!await this.loginAnonymously()?!1:(this.matchmaker||(this.matchmaker=new W({sessionId:this.account.sessionId,proxy:this.proxy,instance:this.instance}),this.matchmaker.on("authFail",t=>this.emit("authFail",t)),await this.matchmaker.getRegions()),!0)}async#n(t){return await this.initMatchmaker()?await new Promise(e=>{const a=n=>{if(n.command=="gameFound"&&(this.matchmaker.off("msg",a),this.game.raw=n,this.game.code=n.id,e()),n.error&&n.error=="gameNotFound")throw new Error(`Game ${t} not found (likely expired).`)};this.matchmaker.on("msg",a),this.matchmaker.send({command:"joinGame",id:t,observe:!1,sessionId:this.account.sessionId})}):!1}async createPrivateGame(t={}){if(!await this.initMatchmaker())return!1;if(!t.region)throw new Error('pass a region: createPrivateGame({ region: "useast", ... })');if(!this.matchmaker.regionList.find(n=>n.id==t.region))throw new Error('invalid region, see <bot>.matchmaker.regionList for a region list (pass an "id")');if(!t.mode)throw new Error('pass a mode: createPrivateGame({ mode: "ffa", ... })');if(k[t.mode]==null)throw new Error("invalid mode, see GameModes for a list");if(!t.map)throw new Error('pass a map: createPrivateGame({ map: "downfall", ... })');const e=U.find(n=>n.name.toLowerCase()==t.map.toLowerCase()),a=U.indexOf(e);if(a==-1)throw new Error("invalid map, see the Maps constant for a list");return await new Promise(n=>{const i=o=>{o.command=="gameFound"&&(this.matchmaker.off("msg",i),this.game.raw=o,this.game.code=this.game.raw.id,n())};this.matchmaker.on("msg",i),this.matchmaker.send({command:"findGame",region:t.region,playType:Y.createPrivate,gameType:k[t.mode],sessionId:this.account.sessionId,noobLobby:!1,map:a})}),this.game.raw}async join(t,e){if(this.state.name=t||"yolkbot",typeof e=="string"?(e.includes("#")&&(e=e.split("#")[1]),await this.#n(e)):typeof e=="object"&&(this.account.id==0&&await this.loginAnonymously(),this.game.raw=e,this.game.code=this.game.raw.id),!this.game.raw.id||!this.game.raw.subdomain)throw new Error("invalid game data passed to <bot>.join");const a=async()=>{try{this.game.socket=new j(`wss://${this.game.raw.subdomain}.${this.instance}/game/${this.game.raw.id}`,this.proxy),this.game.socket.onerror=async n=>(console.error(n),await new Promise(i=>setTimeout(i,100)),await a())}catch{await new Promise(n=>setTimeout(n,100)),await a()}};await a(),this.game.socket.binaryType="arraybuffer",this.game.socket.onopen=()=>{this.game.socket.onerror=null},this.game.socket.onmessage=n=>this.processPacket(n.data),this.game.socket.onclose=n=>{this.emit("close",n.code),this.quit(!0,!0)}}#i(){if(Object.entries(this.me.position).map(e=>Math.floor(e[1])).join(",")==this.pathing.activePath[this.pathing.activePath.length-1].positionStr())this.pathing.followingPath=!1,this.pathing.activePath=null,this.pathing.activeNode=null,this.pathing.activeNodeIdx=0,this.dispatch(new R(0));else{let e;this.pathing.activeNodeIdx<this.pathing.activePath.length-1?(e=this.pathing.activePath[this.pathing.activeNodeIdx+1].flatCenter(),this.dispatch(new O(e))):(e=this.pathing.activePath[this.pathing.activeNodeIdx].flatCenter(),this.dispatch(new O(e)));for(const a of this.pathing.activePath)if(a.flatRadialDistance(this.me.position)<.1&&a.position.y==Math.floor(this.me.position.y)&&this.pathing.activePath.indexOf(a)>=this.pathing.activeNodeIdx){this.pathing.activeNodeIdx=this.pathing.activePath.indexOf(a)+1,this.pathing.activeNode=this.pathing.activePath[this.pathing.activeNodeIdx];break}this.controlKeys&T.FORWARD||this.dispatch(new R(T.FORWARD))}}update(){if(!this.state.joinedGame)throw new Error("You cannot call update() if the bot is not in a game.");if(this.state.quit)return;for(this.pathing.followingPath&&this.intents.includes(this.Intents.PATHFINDING)&&this.#i();this._packetQueue.length>0;)this.processPacket(this._packetQueue.shift());if(this._dispatches.length>0)for(let e=0;e<this._dispatches.length;e++){const a=this._dispatches[e];if(a.check(this)){a.execute(this),this._dispatches.splice(e,1);break}}const t=Date.now();if(t-this.lastUpdateTime>=50){if(this.emit("tick"),!this.intents.includes(this.Intents.MONITOR)){const e=P.getBuffer();e.packInt8(r.syncMe),e.packInt8(Math.random()*128|0),e.packInt8(this.me.serverStateIdx);for(let a=0;a<3;a++)e.packInt8(this.controlKeys),e.packInt8(this.state.shotsFired),e.packRadU(this.me.view.yaw),e.packRad(this.me.view.pitch),e.packInt8(100);e.send(this.game.socket)}this.lastUpdateTime=t,this.state.shotsFired=0}for(;this._liveCallbacks.length>0;)this._liveCallbacks.shift()()}on(t,e){Object.keys(this._hooks).includes(t)?this._hooks[t].push(e):this._hooks[t]=[e]}onAny(t){this._globalHooks.push(t)}#a=["authFail","banned"];emit(t,...e){if(!this.state.quit){if(this._hooks[t])for(const a of this._hooks[t])this.#a.includes(t)?a(...e):this._liveCallbacks.push(()=>a(...e));for(const a of this._globalHooks)this.#a.includes(t)?a(t,...e):this._liveCallbacks.push(()=>a(t,...e))}}async#o(t,e){if(K)return await(await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${t}.json`)).json();{const{existsSync:a,mkdirSync:n,readFileSync:i,writeFileSync:o}=await import("node:fs"),{join:c}=await import("node:path"),{homedir:l}=await import("node:os"),m=c(l(),".yolkbot"),d=c(m,"maps");a(m)||n(m),a(d)||n(d);const h=c(d,`${t}-${e}.json`);if(a(h))return JSON.parse(i(h,"utf-8"));console.log("map not in cache, IMPORT!!",t,e);const f=await(await fetch(`https://${this.instance}/maps/${t}.json?${e}`)).json();return o(h,JSON.stringify(f,null,4),{flag:"w+"}),f}}#c(){const t=this.game.map.raw.data["DYNAMIC.capture-zone.none"];if(!t)return delete this.game.map.zones;let e=0;const a={},n=[];for(const c of t)a[c.x]||(a[c.x]={}),a[c.x][c.y]||(a[c.x][c.y]={}),a[c.x][c.y][c.z]={zone:null};const i=[{x:-1,z:0},{x:1,z:0},{x:0,z:-1},{x:0,z:1}];function o(c,l,m){return a[c]&&a[c][l]&&a[c][l][m]?a[c][l][m]:null}for(const c of t)if(!a[c.x][c.y][c.z].zone){c.zone=++e,a[c.x][c.y][c.z].zone=c.zone;const l=[c];let m;do{m=0;for(const d of t)if(!a[d.x][d.y][d.z].zone)for(const h of i){const f=o(d.x+h.x,d.y,d.z+h.z);if(f&&f.zone==c.zone){m++,d.zone=c.zone,a[d.x][d.y][d.z].zone=c.zone,l.push(d);break}}}while(m>0);n.push(l)}this.game.map.zones=n}#r(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackString().valueOf(),n=this.players[Object.keys(this.players).find(i=>this.players[i].id==t)];this.emit("chat",n,a,e)}#h(){const t=s.unPackInt8U(),e=this.intents.includes(this.Intents.COSMETIC_DATA),a={id_:t,uniqueId_:s.unPackString(),name_:s.unPackString(),safename_:s.unPackString(),charClass_:s.unPackInt8U(),team_:s.unPackInt8U(),primaryWeaponItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),secondaryWeaponItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),shellColor_:s.unPackInt8U(),hatItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),stampItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),_unused:s.unPackInt8(),_unused2:s.unPackInt8(),grenadeItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),meleeItem_:e?g(s.unPackInt16U()):s.unPackInt16U(),x_:s.unPackFloat(),y_:s.unPackFloat(),z_:s.unPackFloat(),dx_:s.unPackFloat(),dy_:s.unPackFloat(),dz_:s.unPackFloat(),yaw_:s.unPackRadU(),pitch_:s.unPackRad(),score_:s.unPackInt32U(),kills_:s.unPackInt16U(),deaths_:s.unPackInt16U(),streak_:s.unPackInt16U(),totalKills_:s.unPackInt32U(),totalDeaths_:s.unPackInt32U(),bestGameStreak_:s.unPackInt16U(),bestOverallStreak_:s.unPackInt16U(),shield_:s.unPackInt8U(),hp_:s.unPackInt8U(),playing_:s.unPackInt8U(),weaponIdx_:s.unPackInt8U(),controlKeys_:s.unPackInt8U(),upgradeProductId_:s.unPackInt8U(),activeShellStreaks_:s.unPackInt8U(),social_:s.unPackLongString(),hideBadge_:s.unPackInt8U()};a.gameData_={},a.gameData_.mapIdx=s.unPackInt8U(),a.gameData_.private=s.unPackInt8U(),a.gameData_.gameType=s.unPackInt8U(),this.players[a.id_]||(this.players[a.id_]=new x(a.id_,a.team_,a)),this.me.id==a.id_&&(this.me=this.players[a.id_]),this.emit("playerJoin",this.players[a.id_])}#l(){const t=s.unPackInt8U(),e=s.unPackInt16U(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),c=s.unPackInt8U(),l=s.unPackInt8U(),m=s.unPackInt8U(),d=s.unPackInt8U(),h=this.players[t];h&&(h.playing=!0,h.randomSeed=e,h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.rounds=o),h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.store=c),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.rounds=l),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.store=m),h.grenades=d,h.position={x:a,y:n,z:i},this.emit("playerRespawn",h))}#m(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackInt8U(),o=this.players[t];if(!o||o.id==this.me.id){for(let c=0;c<3;c++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U();return}if(o.position.x!==e&&(o.position.x=e),o.position.z!==n&&(o.position.z=n),(!o.jumping||Math.abs(o.position.y-a)>.5&&o.position.y!==a)&&(o.position.y=a),o.climbing!==i&&(o.climbing=i),this.intents.includes(this.Intents.BUFFERS)){if(!o.buffer)return;for(let c=0;c<3;c++){o.buffer[c].controlKeys=s.unPackInt8U();const l=s.unPackRadU();isNaN(l)||(o.buffer[c].yaw_=l);const m=s.unPackRad();isNaN(m)||(o.buffer[c].pitch_=m),s.unPackInt8U()}o.buffer[0].x=e,o.buffer[0].y=a,o.buffer[0].z=n}else for(let c=0;c<3;c++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U()}#d(){const t=s.unPackInt8U(),e=this.players[t];e&&(e.playing=!1,this.emit("playerPause",e))}#u(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];a&&(a.activeGun=e,this.emit("playerSwapWeapon",a,e))}#p(){const t=s.unPackInt8U(),e=s.unPackInt8U();s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U();const a=this.players[t],n=this.players[e];a&&(a.playing=!1,a.streak=0,a.lastDeathTime=Date.now(),a.hp=100,a.hpShield=0),n&&n.streak++,this.emit("playerDeath",a,n)}#g(){const t=s.unPackInt8U();for(let n=0;n<6;n++)s.unPackFloat();const e=this.players[t],a=e.weapons[e.activeGun];a&&a.ammo&&(a.ammo.rounds--,this.emit("playerFire",e,a))}#k(){const t=s.unPackInt16U(),e=s.unPackInt8U(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat();this.game.collectables[e].push({id:t,x:a,y:n,z:i}),this.emit("spawnItem",e,t,{x:a,y:n,z:i})}#I(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt8U(),n=s.unPackInt16U(),i=this.players[t];if(this.game.collectables[e]=this.game.collectables[e].filter(o=>o.id!=n),e==_.AMMO){const o=i.weapons[a];o&&o.ammo&&(o.ammo.store=Math.min(o.ammo.storeMax,o.ammo.store+o.ammo.pickup),this.emit("collectAmmo",i,o))}e==_.GRENADE&&(i.grenades++,i.grenades>3&&(i.grenades=3),this.emit("collectGrenade",i))}#f(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const n=a.hp;a.hp=e,this.emit("playerDamaged",a,n,a.hp)}#P(){const t=s.unPackInt8U();s.unPackFloat(),s.unPackFloat();const e=this.me.hp;this.me.hp=t,this.emit("selfDamaged",e,this.me.hp)}#y(){const t=s.unPackInt8U(),e=this.players[t];s.unPackInt8U();const a=s.unPackInt8U(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat();if(s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U(),!e)return;e.serverStateIdx=a;const c=e.position.x,l=e.position.y,m=e.position.z;e.position.x=n,e.position.y=i,e.position.z=o,(c!=n||l!=i||m!=o)&&this.emit("selfMoved",e,{x:c,y:l,z:m},{x:n,y:i,z:o})}#w(){if(!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.eventModifier),t.send(this.game.socket)}}#U(){const t=s.unPackInt8U(),e={...this.players[t]};delete this.players[t.toString()],this.emit("playerLeave",e)}#b(){if(this.game.gameModeId==k.spatula){this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U();const t={x:s.unPackFloat(),y:s.unPackFloat(),z:s.unPackFloat()},e=s.unPackInt8U(),a=s.unPackInt8U();this.game.spatula={coords:t,controlledBy:e,controlledByTeam:a},this.emit("gameStateChange",this.game)}else this.game.gameModeId==k.kotc?(this.game.stage=s.unPackInt8U(),this.game.zoneNumber=s.unPackInt8U(),this.game.capturing=s.unPackInt8U(),this.game.captureProgress=s.unPackInt16U(),this.game.numCapturing=s.unPackInt8U(),this.game.teamScore[1]=s.unPackInt8U(),this.game.teamScore[2]=s.unPackInt8U(),this.game.stageName=M[this.game.stage],this.game.capturePercent=this.game.captureProgress/1e3,this.game.activeZone=this.game.map.zones?this.game.map.zones[this.game.zoneNumber-1]:null,this.emit("gameStateChange",this.game)):this.game.gameModeId==k.team&&(this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U());this.game.gameModeId!==k.spatula&&delete this.game.spatula,this.game.gameModeId!==k.kotc&&(delete this.game.stage,delete this.game.zoneNumber,delete this.game.capturing,delete this.game.captureProgress,delete this.game.numCapturing,delete this.game.stageName,delete this.game.numCapturing,delete this.game.activeZone),this.game.gameModeId==k.ffa&&delete this.game.teamScore}#S(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];switch(e){case p.HardBoiled:a.hpShield=100,a.streakRewards.push(p.HardBoiled);break;case p.EggBreaker:a.streakRewards.push(p.EggBreaker);break;case p.Restock:{a.grenades=3,a.weapons[0]&&a.weapons[0].ammo&&(a.weapons[0].ammo.rounds=a.weapons[0].ammo.capacity,a.weapons[0].ammo.store=a.weapons[0].ammo.storeMax),a.weapons[1]&&a.weapons[1].ammo&&(a.weapons[1].ammo.rounds=a.weapons[1].ammo.capacity,a.weapons[1].ammo.store=a.weapons[1].ammo.storeMax);break}case p.OverHeal:a.hp=Math.min(200,a.hp+100),a.streakRewards.push(p.OverHeal);break;case p.DoubleEggs:a.streakRewards.push(p.DoubleEggs);break;case p.MiniEgg:a.streakRewards.push(p.MiniEgg);break}this.emit("playerBeginStreak",a,e)}#x(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];[p.EggBreaker,p.OverHeal,p.DoubleEggs,p.MiniEgg].includes(e)&&a.streakRewards.includes(e)&&(a.streakRewards=a.streakRewards.filter(i=>i!=e)),this.emit("playerEndStreak",e,a)}#_(){const t=s.unPackInt8U(),e=s.unPackInt8U();s.unPackFloat(),s.unPackFloat(),this.me.hpShield=t,this.me.hp=e,this.me.hpShield<=0?(this.me.streakRewards=this.me.streakRewards.filter(a=>a!=p.HardBoiled),this.emit("selfShieldLost")):this.emit("selfShieldHit",this.me.hpShield)}#C(){const t={...this.game.options};let e=s.unPackInt8U(),a=s.unPackInt8U(),n=s.unPackInt8U();(e<1||e>4)&&(e=4),(a<0||a>8)&&(a=4),n>16&&(n=4),this.game.options.gravity=e/4,this.game.options.damage=a/4,this.game.options.healthRegen=n/4;const i=s.unPackInt8U();return Object.keys(v).forEach(o=>{const c=i&v[o]?1:0;this.game.options[o]=c}),this.game.options.weaponsDisabled=Array.from({length:7},()=>s.unPackInt8U()===1),this.game.options.mustUseSecondary=this.game.options.weaponsDisabled.every(o=>o),this.emit("gameOptionsChange",t,this.game.options),!1}#v(){const t=s.unPackInt8U();t==C.pause&&(this.emit("gameForcePause"),setTimeout(()=>this.me.playing=!1,3e3)),t==C.reset&&(Object.values(this.players).forEach(e=>e.streak=0),this.game.gameModeId!==k.ffa&&(this.game.teamScore=[0,0,0]),this.game.gameModeId===k.spatula&&(this.game.spatula.controlledBy=0,this.game.spatula.controlledByTeam=0,this.game.spatula.coords={x:0,y:0,z:0}),this.game.gameModeId===k.kotc&&(this.game.stage=w.capturing,this.game.zoneNumber=0,this.game.activeZone=null,this.game.capturing=0,this.game.captureProgress=0,this.game.numCapturing=0,this.game.stageName=M[w.capturing],this.game.capturePercent=0),this.emit("gameReset"))}#T(){if(!this.intents.includes(this.Intents.PING))return;const t=this.ping;this.ping=Date.now()-this.lastPingTime,this.emit("pingUpdate",t,this.ping),this.intents.includes(this.Intents.MONITOR)||setTimeout(()=>{const e=P.getBuffer();e.packInt8(r.ping),e.send(this.game.socket),this.lastPingTime=Date.now()},this.pingInterval)}#O(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const n=a.team;a.team=e,a.streak=0,this.emit("playerSwitchTeam",a,n,e)}#R(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt16U(),n=s.unPackInt16U(),i=s.unPackInt8U(),o=s.unPackInt16U(),c=s.unPackInt16U(),l=s.unPackInt16U(),m=s.unPackInt16U();s.unPackInt8(),s.unPackInt8();const d=this.intents.includes(this.Intents.COSMETIC_DATA),h=d?g(a):a,f=d?g(n):n,G=d?g(o):o,z=d?g(c):c,A=d?g(l):l,N=d?g(m):m,u=this.players[t];if(u){const b={...u.character},S=u.selectedGun;u.character.eggColor=i,u.character.primaryGun=h,u.character.secondaryGun=f,u.character.stamp=z,u.character.hat=G,u.character.grenade=A,u.character.melee=N,u.selectedGun=e,u.weapons[0]=new q[e],S!==u.selectedGun&&this.emit("playerChangeGun",u,S,u.selectedGun),b!==u.character&&this.emit("playerChangeCharacter",u,b,u.character)}}#M(){const t=s.unPackInt32U(),e=this.account.eggBalance;this.account.eggBalance=t,this.emit("balanceUpdate",t-e,t)}#E(){this.me.playing=!1,this.emit("selfRespawnFail")}#F(){const t=s.unPackInt8U(),e=this.players[t];e&&this.emit("playerMelee",e)}#G(){const t=s.unPackInt8U(),e=this.players[t];if(!e)return;const a=e.weapons[e.activeGun];if(a.ammo){const n=Math.min(Math.min(a.ammo.capacity,a.ammo.reload)-a.ammo.rounds,a.ammo.store);a.ammo.rounds+=n,a.ammo.store-=n}this.emit("playerReload",e,a)}#z(){if(!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.gameOptions),t.packInt8(this.game.options.gravity*4),t.packInt8(this.game.options.damage*4),t.packInt8(this.game.options.healthRegen*4);const e=(this.game.options.locked?1:0)|(this.game.options.noTeamChange?2:0)|(this.game.options.noTeamShuffle?4:0);t.packInt8(e),this.game.options.weaponsDisabled.forEach(a=>{t.packInt8(a?1:0)}),t.send(this.game.socket)}}#A(){const t=s.unPackInt8U();let e=s.unPackInt16U();const a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),c=s.unPackFloat();this.intents.includes(this.Intents.COSMETIC_DATA)&&(e=g(e)),t==Z.Grenade?this.emit("grenadeExploded",e,{x:a,y:n,z:i},o,c):this.emit("rocketHit",{x:a,y:n,z:i},o,c)}#N(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),c=s.unPackFloat(),l=this.players[t];l&&(l.grenades--,this.emit("playerThrowGrenade",l,{x:e,y:a,z:n},{x:i,y:o,z:c}))}#B(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;if(!this.intents.includes(this.Intents.CHALLENGES))return this.emit("challengeComplete",a,e);const n=this.account.challenges.find(i=>i.id==e);this.emit("challengeComplete",a,n),a.id==this.me.id&&this.refreshChallenges()}#D(){this.#s()}#s(){const t=s.unPackString();try{const e=JSON.parse(t);this.game.eggOrg.evil=e[0],this.game.eggOrg.good=e[1],this.emit("eggOrgUpdate",this.game.eggOrg)}catch{}}#L(){if(!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.joinGame),t.packString(this.state.name),t.packString(this.game.raw.uuid),t.packInt8(0),t.packInt8(this.state.weaponIdx||0),t.packInt32(this.account.session),t.packString(this.account.firebaseId),t.packString(this.account.sessionId),t.send(this.game.socket)}}async#H(){if(this.me.id=s.unPackInt8U(),this.me.team=s.unPackInt8U(),this.game.gameModeId=s.unPackInt8U(),this.game.gameMode=E[this.game.gameModeId],this.game.mapIdx=s.unPackInt8U(),this.game.map=U[this.game.mapIdx],this.intents.includes(this.Intents.PATHFINDING)&&(this.game.map.raw=await this.#o(this.game.map.filename,this.game.map.hash),this.pathing.nodeList=new Q(this.game.map.raw),this.game.gameModeId===k.kotc&&this.#c()),this.game.playerLimit=s.unPackInt8U(),this.game.isGameOwner=s.unPackInt8U()==1,this.game.isPrivate=s.unPackInt8U()==1,this.state.joinedGame=!0,this.lastDeathTime=Date.now(),!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.clientReady),t.send(this.game.socket),this.game.socket.onmessage=e=>this._packetQueue.push(e.data)}if(this.autoUpdate&&(this.updateIntervalId=setInterval(()=>this.update(),this.updateInterval)),this.intents.includes(this.Intents.PING)&&(this.lastPingTime=Date.now(),!this.intents.includes(this.Intents.MONITOR))){const t=P.getBuffer();t.packInt8(r.ping),t.send(this.game.socket)}}processPacket(t){s.init(t),this.intents.includes(this.Intents.PACKET_HOOK)&&this.emit("packet",t);let e=0,a=0,n=!1;for(;s.isMoreDataAvailable()&&!n;){const i=s.unPackInt8U();switch(i){case r.syncThem:this.#m();break;case r.fire:this.#g();break;case r.hitThem:this.#f();break;case r.syncMe:this.#y();break;case r.hitMe:this.#P();break;case r.swapWeapon:this.#u();break;case r.collectItem:this.#I();break;case r.respawn:this.#l();break;case r.die:this.#p();break;case r.pause:this.#d();break;case r.chat:this.#r();break;case r.addPlayer:this.#h();break;case r.removePlayer:this.#U();break;case r.eventModifier:this.#w();break;case r.metaGameState:this.#b();break;case r.beginShellStreak:this.#S();break;case r.endShellStreak:this.#x();break;case r.hitMeHardBoiled:this.#_();break;case r.gameOptions:this.#C();break;case r.ping:this.#T();break;case r.switchTeam:this.#O();break;case r.changeCharacter:this.#R();break;case r.reload:this.#G();break;case r.explode:this.#A();break;case r.throwGrenade:this.#N();break;case r.eggOrgUpdate:this.#s();break;case r.spawnItem:this.#k();break;case r.melee:this.#F();break;case r.updateBalance:this.#M();break;case r.challengeCompleted:this.#B();break;case r.socketReady:this.#L();break;case r.gameJoined:this.#H();break;case r.gameAction:this.#v();break;case r.requestGameOptions:this.#z();break;case r.respawnDenied:this.#E();break;case r.clientReady:this.#D();break;case r.expireUpgrade:break;case r.musicInfo:s.unPackLongString();break;default:console.error(`handlePacket: I got but did not handle a: ${Object.keys(r).find(o=>r[o]===i)} ${i}`),e&&console.error(`handlePacket: It may be a result of the ${e} command (${a}).`),n=!0;break}e=Object.keys(r).find(o=>r[o]===i),a=i}}async checkChiknWinner(){const t=await I({cmd:"chicknWinnerReady",id:this.account.id,sessionId:this.account.sessionId});return typeof t=="string"?t:(this.account.cw.limit=t.limit,this.account.cw.atLimit=t.limit>=4,this.account.cw.secondsUntilPlay=(this.account.cw.atLimit?t.period:t.span)||0,this.account.cw.canPlayAgain=Date.now()+this.account.cw.secondsUntilPlay*1e3,this.account.cw)}async playChiknWinner(t=!0){if(this.account.cw.atLimit||this.account.cw.limit>$)return"hit_daily_limit";if(this.account.cw.canPlayAgain>Date.now()&&t)return"on_cooldown";const e=await I({cmd:"incentivizedVideoReward",firebaseId:this.account.firebaseId,id:this.account.id,sessionId:this.account.sessionId,token:null},this.proxy,this.instance);return typeof e=="string"?e:e.error?e.error=="RATELIMITED"||e.error=="RATELMITED"?(await this.checkChiknWinner(),"on_cooldown"):e.error=="SESSION_EXPIRED"?"session_expired":(console.error("Unknown Chikn Winner response",e),"unknown_error"):e.reward?(this.account.eggBalance+=e.reward.eggsGiven,e.reward.itemIds.forEach(a=>this.account.ownedItemIds.push(a)),await this.checkChiknWinner(),e.reward):(console.error("Unknown Chikn Winner response",e),"unknown_error")}async resetChiknWinner(){if(this.account.eggBalance<200)return"not_enough_eggs";if(!this.account.cw.atLimit)return"not_at_limit";const t=await I({cmd:"chwReset",sessionId:this.account.sessionId});return typeof t=="string"?t:t.result!=="SUCCESS"?(console.error("Unknown Chikn Winner reset response",t),"unknown_error"):(this.account.eggBalance-=200,await this.checkChiknWinner(),this.account.cw)}canSee(t){if(!this.intents.includes(this.Intents.PATHFINDING))throw new Error("You must have the PATHFINDING intent to use this method.");return this.pathing.nodeList.hasLineOfSight(this.me.position,t.position)}getBestTarget(t=()=>!0){const e=Object.values(this.players).filter(i=>i).filter(i=>i!==this.me).filter(i=>i.playing).filter(i=>i.hp>0).filter(i=>i.name!==this.me.name).filter(i=>this.me.team===0||i.team!==this.me.team).filter(i=>this.canSee(i)).filter(i=>!!t(i));let a=200,n=null;for(const i of e){const o=i.position.x-this.me.position.x,c=i.position.y-this.me.position.y,l=i.position.z-this.me.position.z,m=Math.sqrt(o*o+c*c+l*l);m<a&&(a=m,n=i)}return n}async refreshChallenges(){const t=await I({cmd:"challengeGetDaily",sessionId:this.account.sessionId,playerId:this.account.id},this.proxy,this.instance);return this.#t(t),this.account.challenges}async rerollChallenge(t){const e=await I({cmd:"challengeRerollSlot",sessionId:this.account.sessionId,slotId:t},this.proxy,this.instance);return this.#t(e),this.account.challenges}async claimChallenge(t){const e=await I({cmd:"challengeClaimReward",sessionId:this.account.sessionId,slotId:t},this.proxy,this.instance);return this.#t(e.challenges),{eggReward:e.reward,updatedChallenges:this.account.challenges}}async refreshBalance(){const t=await I({cmd:"checkBalance",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId},this.proxy,this.instance);return this.account.eggBalance=t.currentBalance,t.currentBalance}async redeemCode(t){const e=await I({cmd:"redeem",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,id:this.account.id,code:t},this.proxy,this.instance);return e.result==="SUCCESS"?(this.account.eggBalance=e.eggs_given,e.item_ids.forEach(a=>this.account.ownedItemIds.push(a)),{result:e,eggsGiven:e.eggs_given,itemIds:e.item_ids}):e}async claimURLReward(t){const e=await I({cmd:"urlRewardParams",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,reward:t},this.proxy,this.instance);return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async claimSocialReward(t){const e=await I({cmd:"reward",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,rewardTag:t},this.proxy,this.instance);return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async buyItem(t){const e=await I({cmd:"buy",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,itemId:t,save:!0},this.proxy,this.instance);return e.result==="SUCCESS"&&(this.account.eggBalance=e.currentBalance,this.account.ownedItemIds.push(e.itemId)),e}quit(t=!1,e=!1){this.state.quit||(this.intents.includes(this.Intents.PLAYER_HEALTH)&&clearInterval(this.healthIntervalId),clearInterval(this.updateIntervalId),this.game?.socket&&this.game.socket.close(),this.matchmaker&&this.matchmaker.close(),e||(this._dispatches=[]),this._packetQueue=[],t||(delete this.account,delete this.game,delete this.me,delete this.players),this.state.quit=!0)}killZastix(){const t=this.players.find(e=>e.name==="zastix");this.on("tick",()=>{t&&this.canSee(t)&&(this.state.shotsFired+=5)})}}var ue=X;export{X as Bot,ue as default};
|