Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Gen 6 Symbiosis Eject Button glitch #10156

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ export const Items: {[itemid: string]: ItemData} = {
}
target.switchFlag = true;
if (target.useItem()) {
if (this.gen === 6) target.lastTurnEjected = this.turn;
source.switchFlag = false;
} else {
target.switchFlag = false;
Expand Down
93 changes: 93 additions & 0 deletions data/mods/gen6/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,33 @@ export const Items: {[k: string]: ModdedItemData} = {
}
},
},
airballoon: {
inherit: true,
onStart(target) {
if (!target.ignoringItem() && !this.field.getPseudoWeather('gravity')) {
this.add('-item', target, 'Air Balloon');
if (target.lastTurnEjected) this.add('-item', target, 'Air Balloon');
}
},
},
belueberry: {
inherit: true,
isNonstandard: null,
},
berryjuice: {
inherit: true,
onUpdate(pokemon) {
if (pokemon.hp <= pokemon.maxhp / 2) {
if (this.runEvent('TryHeal', pokemon, null, this.effect, 20) && pokemon.useItem()) {
this.heal(20);
if (pokemon.lastTurnEjected && !pokemon.newlySwitched) {
this.heal(20);
pokemon.lastTurnEjected = null;
}
}
}
},
},
cornnberry: {
inherit: true,
isNonstandard: null,
Expand Down Expand Up @@ -71,6 +94,13 @@ export const Items: {[k: string]: ModdedItemData} = {
}
},
},
leftovers: {
inherit: true,
onResidual(pokemon) {
this.heal(pokemon.baseMaxhp / 16);
if (pokemon.lastTurnEjected) this.heal(pokemon.baseMaxhp / 16);
},
},
levelball: {
inherit: true,
isNonstandard: "Unobtainable",
Expand All @@ -80,6 +110,7 @@ export const Items: {[k: string]: ModdedItemData} = {
onAfterMoveSecondarySelf(source, target, move) {
if (source && source !== target && move && move.category !== 'Status' && !move.ohko) {
this.damage(source.baseMaxhp / 10, source, source, this.dex.items.get('lifeorb'));
if (source.lastTurnEjected) this.damage(source.baseMaxhp / 10, source, source, this.dex.items.get('lifeorb'));
}
},
},
Expand Down Expand Up @@ -113,6 +144,33 @@ export const Items: {[k: string]: ModdedItemData} = {
inherit: true,
isNonstandard: null,
},
mentalherb: {
inherit: true,
onUpdate(pokemon) {
const conditions = ['attract', 'taunt', 'encore', 'torment', 'disable', 'healblock'];
for (const firstCondition of conditions) {
if (pokemon.volatiles[firstCondition]) {
if (!pokemon.useItem()) return;
let foundSource;
for (const secondCondition of conditions) {
let secondSource;
if (pokemon.volatiles[secondCondition] && pokemon.volatiles[secondCondition].source) {
secondSource = pokemon.volatiles[secondCondition].source;
}
pokemon.removeVolatile(secondCondition);
if (firstCondition === 'attract' && secondCondition === 'attract') {
this.add('-end', pokemon, 'move: Attract', '[from] item: Mental Herb');
if (secondSource.item && secondSource.item === 'destinyknot' && secondSource.lastTurnEjected) {
foundSource = secondSource;
}
}
}
this.add('-start', pokemon, 'Attract', '[from] item: Destiny Knot', '[of] ' + foundSource);
return;
}
}
},
},
moonball: {
inherit: true,
isNonstandard: "Unobtainable",
Expand All @@ -133,10 +191,28 @@ export const Items: {[k: string]: ModdedItemData} = {
inherit: true,
isNonstandard: null,
},
quickclaw: {
inherit: true,
onFractionalPriority(priority, pokemon, target, move) {
if (move.category === "Status" && pokemon.hasAbility("myceliummight")) return;
if (priority <= 0 && this.randomChance(1, 5)) {
this.add('-activate', pokemon, 'item: Quick Claw');
if (pokemon.lastTurnEjected) this.add('-activate', pokemon, 'item: Quick Claw');
return 0.1;
}
},
},
rabutaberry: {
inherit: true,
isNonstandard: null,
},
razorclaw: {
inherit: true,
onModifyCritRatio(critRatio) {
if (this.event.target.lastTurnEjected) return critRatio + 2;
return critRatio + 1;
},
},
razzberry: {
inherit: true,
isNonstandard: null,
Expand All @@ -146,6 +222,7 @@ export const Items: {[k: string]: ModdedItemData} = {
onDamagingHit(damage, target, source, move) {
if (move.flags['contact']) {
this.damage(source.baseMaxhp / 6, source, target, null, true);
if (target.lastTurnEjected) this.damage(source.baseMaxhp / 6, source, target, null, true);
}
},
},
Expand All @@ -159,6 +236,22 @@ export const Items: {[k: string]: ModdedItemData} = {
}
},
},
scopelens: {
inherit: true,
onModifyCritRatio(critRatio) {
if (this.event.target.lastTurnEjected) return critRatio + 2;
return critRatio + 1;
},
},
shellbell: {
inherit: true,
onAfterMoveSecondarySelf(pokemon, target, move) {
if (move.totalDamage && !pokemon.forceSwitchFlag) {
this.heal(move.totalDamage / 8, pokemon);
if (pokemon.lastTurnEjected) this.heal(move.totalDamage / 8, pokemon);
}
},
},
spelonberry: {
inherit: true,
isNonstandard: null,
Expand Down
3 changes: 2 additions & 1 deletion sim/battle-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ export class BattleQueue {
if (typeof action.pokemon.switchFlag === 'string') {
action.sourceEffect = this.battle.dex.moves.get(action.pokemon.switchFlag as ID) as any;
}
action.pokemon.switchFlag = false;
if (this.battle.turn !== action.pokemon.lastTurnEjected || !action.pokemon.item) action.pokemon.lastTurnEjected = null;
action.pokemon.switchFlag = null;
}
}

Expand Down
14 changes: 11 additions & 3 deletions sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {Dex, toID} from './dex';
import {Teams} from './teams';
import {Field} from './field';
import {Pokemon, EffectState, RESTORATIVE_BERRIES} from './pokemon';
import {Pokemon, EffectState, RESTORATIVE_BERRIES, DMG_REDUCING_BERRIES} from './pokemon';
import {PRNG, PRNGSeed} from './prng';
import {Side} from './side';
import {State} from './state';
Expand Down Expand Up @@ -509,8 +509,10 @@ export class Battle {
if ((handler.effectHolder as Field).pseudoWeather) handlerEventid = `Field${eventid}`;
if (handler.callback) {
this.singleEvent(handlerEventid, effect, handler.state, handler.effectHolder, null, null, relayVar, handler.callback);
if (handler.effectHolder instanceof Pokemon && handler.effectHolder.lastTurnEjected && effect.effectType === 'Item') {
this.singleEvent(handlerEventid, effect, handler.state, handler.effectHolder, null, null, relayVar, handler.callback);
}
}

this.faintMessages();
if (this.ended) return;
}
Expand Down Expand Up @@ -2138,13 +2140,19 @@ export class Battle {

chainModify(numerator: number | number[], denominator?: number) {
const previousMod = this.trunc(this.event.modifier * 4096);

if (Array.isArray(numerator)) {
denominator = numerator[1];
numerator = numerator[0];
}
const nextMod = this.trunc(numerator * 4096 / (denominator || 1));
this.event.modifier = ((previousMod * nextMod + 2048) >> 12) / 4096;
if (this.event.target.lastTurnEjected && (this.effect.effectType === 'Item' || this.effect.id === 'metronome' ||
DMG_REDUCING_BERRIES.has(this.effect.id))) {
this.event.modifier *= ((previousMod * nextMod + 2048) >> 12) / 4096;
}
if (DMG_REDUCING_BERRIES.has(this.effect.id)) {
this.event.target.lastTurnEjected = null;
}
}

modify(value: number, numerator: number | number[], denominator?: number) {
Expand Down
34 changes: 32 additions & 2 deletions sim/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const RESTORATIVE_BERRIES = new Set([
'leppaberry', 'aguavberry', 'enigmaberry', 'figyberry', 'iapapaberry', 'magoberry', 'sitrusberry', 'wikiberry', 'oranberry',
] as ID[]);

export const DMG_REDUCING_BERRIES = new Set([
'babiriberry', 'chartiberry', 'chilanberry', 'chopleberry', 'cobaberry', 'colburberry', 'habanberry', 'kasibberry', 'kebiaberry',
'occaberry', 'passhoberry', 'payapaberry', 'rindoberry', 'roseliberry', 'shucaberry', 'tangaberry', 'wacanberry', 'yacheberry',
] as ID[]);

export class Pokemon {
readonly side: Side;
readonly battle: Battle;
Expand Down Expand Up @@ -149,6 +154,9 @@ export class Pokemon {
newlySwitched: boolean;
beingCalledBack: boolean;

// Gen 6 only
lastTurnEjected: number | null;

lastMove: ActiveMove | null;
// Gen 2 only
lastMoveEncore?: ActiveMove | null;
Expand Down Expand Up @@ -433,10 +441,17 @@ export class Pokemon {
this.newlySwitched = false;
this.beingCalledBack = false;

/**
* Tracks the last turn the pokemon was ejected
* as a result of the eject button. Relevant in
* gen 6 to detect the validity of the symbiosis
* eject button glitch.
*/
this.lastTurnEjected = null;

this.lastMove = null;
// This is used in gen 2 only, here to avoid code repetition.
// Only declared if gen 2 to avoid declaring an object we aren't going to need.
if (this.battle.gen === 2) this.lastMoveEncore = null;
this.lastMoveUsed = null;
this.moveThisTurn = '';
this.statsRaisedThisTurn = false;
Expand Down Expand Up @@ -646,7 +661,10 @@ export class Pokemon {
*/

getWeight() {
const weighthg = this.battle.runEvent('ModifyWeight', this, null, null, this.weighthg);
let weighthg = this.battle.runEvent('ModifyWeight', this, null, null, this.weighthg);
if ((this.item === 'floatstone' || this.item === 'ironball') && this.lastTurnEjected) {
weighthg = this.battle.runEvent('ModifyWeight', this, null, null, weighthg);
}
return Math.max(1, weighthg);
}

Expand Down Expand Up @@ -1695,6 +1713,13 @@ export class Pokemon {

this.battle.singleEvent('Eat', item, this.itemState, this, source, sourceEffect);
this.battle.runEvent('EatItem', this, null, null, item);
if (this.lastTurnEjected && this.battle.turn !== this.lastTurnEjected && !this.newlySwitched) {
this.battle.singleEvent('Eat', item, this.itemState, this, source, sourceEffect);
this.battle.runEvent('EatItem', this, null, null, item);
if (!DMG_REDUCING_BERRIES.has(item.id)) {
this.lastTurnEjected = null;
}
}

if (RESTORATIVE_BERRIES.has(item.id)) {
switch (this.pendingStaleness) {
Expand Down Expand Up @@ -1741,6 +1766,10 @@ export class Pokemon {
}
if (item.boosts) {
this.battle.boost(item.boosts, this, source, item);
if (this.lastTurnEjected) {
this.battle.boost(item.boosts, this, source, item);
this.lastTurnEjected = null;
}
}

this.battle.singleEvent('Use', item, this.itemState, this, source, sourceEffect);
Expand Down Expand Up @@ -1769,6 +1798,7 @@ export class Pokemon {
const oldItemState = this.itemState;
this.itemState = {id: '', target: this};
this.pendingStaleness = undefined;
source.lastTurnEjected = null;
this.battle.singleEvent('End', item, oldItemState, this);
this.battle.runEvent('AfterTakeItem', this, null, null, item);
return item;
Expand Down
2 changes: 1 addition & 1 deletion test/sim/abilities/symbiosis.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Symbiosis', function () {
});

// See Marty's research for many more examples: https://www.smogon.com/forums/threads/battle-mechanics-research.3489239/post-6401506
describe.skip('Symbiosis Eject Button Glitch (Gen 6 only)', function () {
describe('Symbiosis Eject Button Glitch (Gen 6 only)', function () {
it('should cause Leftovers to restore HP 4 times', function () {
battle = common.gen(6).createBattle({gameType: 'doubles'}, [[
{species: 'florges', ability: 'symbiosis', item: 'leftovers', moves: ['sleeptalk']},
Expand Down
Loading