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

Refactor lastAttackedBy to hurtBy #4894

Merged
merged 6 commits into from
Oct 11, 2018
Merged

Conversation

bgsamm
Copy link
Contributor

@bgsamm bgsamm commented Oct 8, 2018

Messed up pretty bad with my last pull request and had to open a new one. I apologize, still getting used to git. That said, I added the lastHurtBy getter as requested by Marty-D.

Original description:
Replaced the 'lastAttackedBy' attribute of a Pokemon with an array of attacks that the Pokemon has recently received. This corrects a bug in double battles arising from lastAttackedBy always getting replaced by the most recent attack, which caused Avalanche and Revenge to not double in power when they otherwise should have (e.g. see https://replay.pokemonshowdown.com/gen7doublescustomgame-796785834). This also addresses the corresponding task in #2444.

sim/pokemon.js Outdated
this.hurtBy.push(lastHurtBy);
}

get lastHurtBy() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like getters for various reasons, the main one being readability – it's not obvious from a glance that this property is automatically updated rather than something you need to write to.

data/moves.js Outdated
this.debug('Boosted for getting hit by ' + pokemon.lastAttackedBy.move);
let hurtByTarget = pokemon.hurtBy.find(function (x) {
return x.source === target && x.damage > 0 && x.thisTurn;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't seem to use the found value. Did you mean some rather than find?

Also, your code style prefers new-style lambdas here:

let hurtByTarget = pokemon.hurtBy.some(h =>
  p.source === target && p.damage > 0 && p.thisTurn;
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the found value in the debug output to get the move that triggered the boost. If that's not too important I can use some and a more generic debug statement.

@Zarel
Copy link
Member

Zarel commented Oct 11, 2018

@Marty-D thoughts?

@Marty-D
Copy link
Collaborator

Marty-D commented Oct 11, 2018

Looks good to me @Zarel. We can deal with splitting "thisTurn"-specific stuff from past turn stuff at a later date.

@Zarel Zarel merged commit a68f627 into smogon:master Oct 11, 2018
@Zarel
Copy link
Member

Zarel commented Oct 11, 2018

Cool, thank you!

@bgsamm bgsamm deleted the refactor-lastattackedby branch October 11, 2018 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants