Spaces:
Running
Running
{ | |
"version": 3, | |
"sources": ["../../sim/field.ts"], | |
"sourcesContent": ["/**\n * Simulator Field\n * Pokemon Showdown - http://pokemonshowdown.com/\n *\n * @license MIT\n */\n\nimport { State } from './state';\nimport { type EffectState } from './pokemon';\nimport { toID } from './dex';\n\nexport class Field {\n\treadonly battle: Battle;\n\treadonly id: ID;\n\n\tweather: ID;\n\tweatherState: EffectState;\n\tterrain: ID;\n\tterrainState: EffectState;\n\tpseudoWeather: { [id: string]: EffectState };\n\n\tconstructor(battle: Battle) {\n\t\tthis.battle = battle;\n\t\tconst fieldScripts = this.battle.format.field || this.battle.dex.data.Scripts.field;\n\t\tif (fieldScripts) Object.assign(this, fieldScripts);\n\t\tthis.id = '';\n\n\t\tthis.weather = '';\n\t\tthis.weatherState = this.battle.initEffectState({ id: '' });\n\t\tthis.terrain = '';\n\t\tthis.terrainState = this.battle.initEffectState({ id: '' });\n\t\tthis.pseudoWeather = {};\n\t}\n\n\ttoJSON(): AnyObject {\n\t\treturn State.serializeField(this);\n\t}\n\n\tsetWeather(status: string | Condition, source: Pokemon | 'debug' | null = null, sourceEffect: Effect | null = null) {\n\t\tstatus = this.battle.dex.conditions.get(status);\n\t\tif (!sourceEffect && this.battle.effect) sourceEffect = this.battle.effect;\n\t\tif (!source && this.battle.event?.target) source = this.battle.event.target;\n\t\tif (source === 'debug') source = this.battle.sides[0].active[0];\n\n\t\tif (this.weather === status.id) {\n\t\t\tif (sourceEffect && sourceEffect.effectType === 'Ability') {\n\t\t\t\tif (this.battle.gen > 5 || this.weatherState.duration === 0) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else if (this.battle.gen > 2 || status.id === 'sandstorm') {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\tif (source) {\n\t\t\tconst result = this.battle.runEvent('SetWeather', source, source, status);\n\t\t\tif (!result) {\n\t\t\t\tif (result === false) {\n\t\t\t\t\tif ((sourceEffect as Move)?.weather) {\n\t\t\t\t\t\tthis.battle.add('-fail', source, sourceEffect, '[from] ' + this.weather);\n\t\t\t\t\t} else if (sourceEffect && sourceEffect.effectType === 'Ability') {\n\t\t\t\t\t\tthis.battle.add('-ability', source, sourceEffect, '[from] ' + this.weather, '[fail]');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\tconst prevWeather = this.weather;\n\t\tconst prevWeatherState = this.weatherState;\n\t\tthis.weather = status.id;\n\t\tthis.weatherState = this.battle.initEffectState({ id: status.id });\n\t\tif (source) {\n\t\t\tthis.weatherState.source = source;\n\t\t\tthis.weatherState.sourceSlot = source.getSlot();\n\t\t}\n\t\tif (status.duration) {\n\t\t\tthis.weatherState.duration = status.duration;\n\t\t}\n\t\tif (status.durationCallback) {\n\t\t\tif (!source) throw new Error(`setting weather without a source`);\n\t\t\tthis.weatherState.duration = status.durationCallback.call(this.battle, source, source, sourceEffect);\n\t\t}\n\t\tif (!this.battle.singleEvent('FieldStart', status, this.weatherState, this, source, sourceEffect)) {\n\t\t\tthis.weather = prevWeather;\n\t\t\tthis.weatherState = prevWeatherState;\n\t\t\treturn false;\n\t\t}\n\t\tthis.battle.eachEvent('WeatherChange', sourceEffect);\n\t\treturn true;\n\t}\n\n\tclearWeather() {\n\t\tif (!this.weather) return false;\n\t\tconst prevWeather = this.getWeather();\n\t\tthis.battle.singleEvent('FieldEnd', prevWeather, this.weatherState, this);\n\t\tthis.weather = '';\n\t\tthis.battle.clearEffectState(this.weatherState);\n\t\tthis.battle.eachEvent('WeatherChange');\n\t\treturn true;\n\t}\n\n\teffectiveWeather() {\n\t\tif (this.suppressingWeather()) return '';\n\t\treturn this.weather;\n\t}\n\n\tsuppressingWeather() {\n\t\tfor (const side of this.battle.sides) {\n\t\t\tfor (const pokemon of side.active) {\n\t\t\t\tif (pokemon && !pokemon.fainted && !pokemon.ignoringAbility() &&\n\t\t\t\t\tpokemon.getAbility().suppressWeather && !pokemon.abilityState.ending) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tisWeather(weather: string | string[]) {\n\t\tconst ourWeather = this.effectiveWeather();\n\t\tif (!Array.isArray(weather)) {\n\t\t\treturn ourWeather === toID(weather);\n\t\t}\n\t\treturn weather.map(toID).includes(ourWeather);\n\t}\n\n\tgetWeather() {\n\t\treturn this.battle.dex.conditions.getByID(this.weather);\n\t}\n\n\tsetTerrain(status: string | Effect, source: Pokemon | 'debug' | null = null, sourceEffect: Effect | null = null) {\n\t\tstatus = this.battle.dex.conditions.get(status);\n\t\tif (!sourceEffect && this.battle.effect) sourceEffect = this.battle.effect;\n\t\tif (!source && this.battle.event?.target) source = this.battle.event.target;\n\t\tif (source === 'debug') source = this.battle.sides[0].active[0];\n\t\tif (!source) throw new Error(`setting terrain without a source`);\n\n\t\tif (this.terrain === status.id) return false;\n\t\tconst prevTerrain = this.terrain;\n\t\tconst prevTerrainState = this.terrainState;\n\t\tthis.terrain = status.id;\n\t\tthis.terrainState = this.battle.initEffectState({\n\t\t\tid: status.id,\n\t\t\tsource,\n\t\t\tsourceSlot: source.getSlot(),\n\t\t\tduration: status.duration,\n\t\t});\n\t\tif (status.durationCallback) {\n\t\t\tthis.terrainState.duration = status.durationCallback.call(this.battle, source, source, sourceEffect);\n\t\t}\n\t\tif (!this.battle.singleEvent('FieldStart', status, this.terrainState, this, source, sourceEffect)) {\n\t\t\tthis.terrain = prevTerrain;\n\t\t\tthis.terrainState = prevTerrainState;\n\t\t\treturn false;\n\t\t}\n\t\tthis.battle.eachEvent('TerrainChange', sourceEffect);\n\t\treturn true;\n\t}\n\n\tclearTerrain() {\n\t\tif (!this.terrain) return false;\n\t\tconst prevTerrain = this.getTerrain();\n\t\tthis.battle.singleEvent('FieldEnd', prevTerrain, this.terrainState, this);\n\t\tthis.terrain = '';\n\t\tthis.battle.clearEffectState(this.terrainState);\n\t\tthis.battle.eachEvent('TerrainChange');\n\t\treturn true;\n\t}\n\n\teffectiveTerrain(target?: Pokemon | Side | Battle) {\n\t\tif (this.battle.event && !target) target = this.battle.event.target;\n\t\treturn this.battle.runEvent('TryTerrain', target) ? this.terrain : '';\n\t}\n\n\tisTerrain(terrain: string | string[], target?: Pokemon | Side | Battle) {\n\t\tconst ourTerrain = this.effectiveTerrain(target);\n\t\tif (!Array.isArray(terrain)) {\n\t\t\treturn ourTerrain === toID(terrain);\n\t\t}\n\t\treturn terrain.map(toID).includes(ourTerrain);\n\t}\n\n\tgetTerrain() {\n\t\treturn this.battle.dex.conditions.getByID(this.terrain);\n\t}\n\n\taddPseudoWeather(\n\t\tstatus: string | Condition,\n\t\tsource: Pokemon | 'debug' | null = null,\n\t\tsourceEffect: Effect | null = null\n\t): boolean {\n\t\tif (!source && this.battle.event?.target) source = this.battle.event.target;\n\t\tif (source === 'debug') source = this.battle.sides[0].active[0];\n\t\tstatus = this.battle.dex.conditions.get(status);\n\n\t\tlet state = this.pseudoWeather[status.id];\n\t\tif (state) {\n\t\t\tif (!(status as any).onFieldRestart) return false;\n\t\t\treturn this.battle.singleEvent('FieldRestart', status, state, this, source, sourceEffect);\n\t\t}\n\t\tstate = this.pseudoWeather[status.id] = this.battle.initEffectState({\n\t\t\tid: status.id,\n\t\t\tsource,\n\t\t\tsourceSlot: source?.getSlot(),\n\t\t\tduration: status.duration,\n\t\t});\n\t\tif (status.durationCallback) {\n\t\t\tif (!source) throw new Error(`setting fieldcond without a source`);\n\t\t\tstate.duration = status.durationCallback.call(this.battle, source, source, sourceEffect);\n\t\t}\n\t\tif (!this.battle.singleEvent('FieldStart', status, state, this, source, sourceEffect)) {\n\t\t\tdelete this.pseudoWeather[status.id];\n\t\t\treturn false;\n\t\t}\n\t\tthis.battle.runEvent('PseudoWeatherChange', source, source, status);\n\t\treturn true;\n\t}\n\n\tgetPseudoWeather(status: string | Effect) {\n\t\tstatus = this.battle.dex.conditions.get(status);\n\t\treturn this.pseudoWeather[status.id] ? status : null;\n\t}\n\n\tremovePseudoWeather(status: string | Effect) {\n\t\tstatus = this.battle.dex.conditions.get(status);\n\t\tconst state = this.pseudoWeather[status.id];\n\t\tif (!state) return false;\n\t\tthis.battle.singleEvent('FieldEnd', status, state, this);\n\t\tdelete this.pseudoWeather[status.id];\n\t\treturn true;\n\t}\n\n\tdestroy() {\n\t\t// deallocate ourself\n\n\t\t// get rid of some possibly-circular references\n\t\t(this as any).battle = null!;\n\t}\n}\n"], | |
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAAsB;AAEtB,iBAAqB;AATrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,MAAM,MAAM;AAAA,EAUlB,YAAY,QAAgB;AAC3B,SAAK,SAAS;AACd,UAAM,eAAe,KAAK,OAAO,OAAO,SAAS,KAAK,OAAO,IAAI,KAAK,QAAQ;AAC9E,QAAI;AAAc,aAAO,OAAO,MAAM,YAAY;AAClD,SAAK,KAAK;AAEV,SAAK,UAAU;AACf,SAAK,eAAe,KAAK,OAAO,gBAAgB,EAAE,IAAI,GAAG,CAAC;AAC1D,SAAK,UAAU;AACf,SAAK,eAAe,KAAK,OAAO,gBAAgB,EAAE,IAAI,GAAG,CAAC;AAC1D,SAAK,gBAAgB,CAAC;AAAA,EACvB;AAAA,EAEA,SAAoB;AACnB,WAAO,mBAAM,eAAe,IAAI;AAAA,EACjC;AAAA,EAEA,WAAW,QAA4B,SAAmC,MAAM,eAA8B,MAAM;AACnH,aAAS,KAAK,OAAO,IAAI,WAAW,IAAI,MAAM;AAC9C,QAAI,CAAC,gBAAgB,KAAK,OAAO;AAAQ,qBAAe,KAAK,OAAO;AACpE,QAAI,CAAC,UAAU,KAAK,OAAO,OAAO;AAAQ,eAAS,KAAK,OAAO,MAAM;AACrE,QAAI,WAAW;AAAS,eAAS,KAAK,OAAO,MAAM,CAAC,EAAE,OAAO,CAAC;AAE9D,QAAI,KAAK,YAAY,OAAO,IAAI;AAC/B,UAAI,gBAAgB,aAAa,eAA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