// ==UserScript==
// @name Bullet Despawn Marker
// @namespace https://tanktrouble.com/
// @version 1.0
// @description Marks the position where the most recent normal bullet despawned.
// @author Gentleman (#878689)
// @license GPL-3.0
// @match https://tanktrouble.com/*
// @match https://beta.tanktrouble.com/*
// @match https://cdn.tanktrouble.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
!function(){"use strict";console.log("[Bullet Despawn Marker] Bullet despawn marker loaded"),function(e,t){const l=e.split("."),s=l.pop();let o=window;for(const e of l)"object"==typeof o[e]&&null!==o[e]||(o[e]={}),o=o[e];Object.defineProperty(o,s,{configurable:!0,enumerable:!0,set(l){if(!l?.method)return console.log(`[Bullet Despawn Marker] ${e} has no methods to patch`),void Object.defineProperty(o,s,{value:l,writable:!0,configurable:!0});l.method=new Proxy(l.method,{apply(e,l,[s,o]){const r=t(s,o);return Reflect.apply(e,l,[s,r])}}),Object.defineProperty(o,s,{value:l,writable:!0,configurable:!0}),console.log(`[Bullet Despawn Marker] ${e} successfully patched`)},get(){}})}("Game.UIGameState",((e,t)=>{switch(e){case"create":return function(){t.call(this),this.golfGroup=this.game.add.group(this.gameGroup),this.golfMarkers=[],this.golfLabels=[],this.golfProjectiles={};for(let e=0;e<UIConstants.PROJECTILE_POOL_SIZE/5;++e){const e=new UIProjectileImage(this.game,this.gameController);e.exists=!1,e.alpha=.6,this.golfGroup.add(e),this.golfMarkers.push(e);const t=32,l=8,s=1/this.golfGroup.worldScale.x,o=this.game.add.text(0,0,"",{font:t*s+"px TankTrouble",fill:"#ffffff",stroke:"#000000",strokeThickness:l*s});o.anchor.set(0,.5),o.exists=!1,o.alpha=.6,this.golfGroup.add(o),this.golfLabels.push(o)}};case"_cleanUp":return function(){t.call(this),this.golfMarkers.forEach((e=>e.retire())),this.golfLabels.forEach((e=>{e.kill(),e.setText("")})),this.golfProjectiles={}};case"_roundEventHandler":return function(e,l,s,o){switch(s){case RoundModel._EVENTS.PROJECTILE_TIMEOUT:{const t=e.gameController.getProjectile(o);if(t.getType()===Constants.WEAPON_TYPES.BULLET){const l=t.getPlayerId(),s=e.golfProjectiles[l];s&&(s.marker.retire(),s.label.kill(),delete e.golfProjectiles[l]);const o=e.golfMarkers.find((e=>!e.exists)),r=e.golfLabels.find((e=>!e.exists));if(o&&r){const s=UIUtils.mpx(t.getX()),a=UIUtils.mpx(t.getY());o.spawn(s,a,t.getId(),"bullet"),r.reset(s+10,a),r.setText(l),r.exists=!0,r.visible=!0,e.golfProjectiles[l]={marker:o,label:r},Backend.getInstance().getPlayerDetails((e=>{"object"==typeof e&&r.setText(e.getUsername())}),null,null,l,Caches.getPlayerDetailsCache())}}e._removeProjectile(o),e._spawnProjectilePuffs(o);break}default:return t.call(this,e,l,s,o)}};default:return t}}))}();