Added comments, added (what i think is TSDoc) to functions and classes. Removed empty lines i introduced

This commit is contained in:
Jannik Tappert 2024-05-12 09:59:48 +02:00
parent 6d55533493
commit d9a154220d
2 changed files with 31 additions and 7 deletions

View File

@ -747,16 +747,26 @@ export class SacrificialAttr extends MoveEffectAttr {
super(true, MoveEffectTrigger.PRE_APPLY); super(true, MoveEffectTrigger.PRE_APPLY);
} }
/**
* Applies the sacrificial effect to the user
* @param user Pokemon that used the move
* @param target The target of the move
* @param move Move with this attribute
* @param args N/A
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
user.damageAndUpdate(user.hp, HitResult.OTHER, false, true, true); user.damageAndUpdate(user.hp, HitResult.OTHER, false, true, true);
user.turnData.damageTaken += user.hp; user.turnData.damageTaken += user.hp;
return true; return true;
} }
/**
*
* @param user Pokemon that used the move
* @param target The target of the move
* @param move Move with this attribute
*/
getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
if (user.isBoss()) if (user.isBoss())
return -20; return -20;
@ -766,15 +776,23 @@ export class SacrificialAttr extends MoveEffectAttr {
/** /**
* Attribute used for moves which self KO the user but only if the move hits a target * * Attribute used for moves which self KO the user but only if the move hits a target
*/ */
export class SacrificialAttrOnHit extends MoveEffectAttr { export class SacrificialAttrOnHit extends MoveEffectAttr {
constructor() { constructor() {
super(true, MoveEffectTrigger.PRE_APPLY); super(true, MoveEffectTrigger.PRE_APPLY);
} }
/**
* Applies the sacrificial effect to the user
* @param user Pokemon that used the move
* @param target The target of the move
* @param move Move with this attribute
* @param args N/A
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
// If the move hits a target, the user will self KO
if (!super.apply(user, target, move, args)) if (!super.apply(user, target, move, args))
return false; return false;
@ -784,6 +802,12 @@ export class SacrificialAttrOnHit extends MoveEffectAttr {
return true; return true;
} }
/**
*
* @param user Pokemon that used the move
* @param target The target of the move
* @param move Move with this attribute
*/
getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
if (user.isBoss()) if (user.isBoss())
return -20; return -20;

View File

@ -2295,13 +2295,12 @@ export class MovePhase extends BattlePhase {
return this.end(); return this.end();
} }
// Check if the move has no valid targets (because they are flying, etc.) - if the used move is sacrificial it does not need a target so we add the user as a target so the move does not fail
if (targets.length === 0 && this.move.getMove().getAttrs(SacrificialAttr).length) { if (targets.length === 0 && this.move.getMove().getAttrs(SacrificialAttr).length) {
// Add the user as a target if the move is sacrificial // Add the user as a target if the move is sacrificial
targets.push(this.pokemon); targets.push(this.pokemon);
} }
if (!moveQueue.length || !moveQueue.shift().ignorePP) // using .shift here clears out two turn moves once they've been used if (!moveQueue.length || !moveQueue.shift().ignorePP) // using .shift here clears out two turn moves once they've been used
this.move.usePp(ppUsed); this.move.usePp(ppUsed);
@ -2465,13 +2464,14 @@ export class MoveEffectPhase extends PokemonPhase {
// Move animation only needs one target // Move animation only needs one target
new MoveAnim(this.move.getMove().id as Moves, user, this.getTarget()?.getBattlerIndex()).play(this.scene, () => { new MoveAnim(this.move.getMove().id as Moves, user, this.getTarget()?.getBattlerIndex()).play(this.scene, () => {
// Check if the user is in the targets list for sacrificial moves // Check if the user is in the targets list for sacrificial moves, if not add them
if (this.move.getMove().getAttrs(SacrificialAttr).length && !targets.includes(user)) { if (this.move.getMove().getAttrs(SacrificialAttr).length && !targets.includes(user)) {
targets.push(user); targets.push(user);
targetHitChecks[user.getBattlerIndex()] = true; targetHitChecks[user.getBattlerIndex()] = true;
} }
for (let target of targets) { for (let target of targets) {
if (!targetHitChecks[target.getBattlerIndex()]) { if (!targetHitChecks[target.getBattlerIndex()]) {
// If we have a sacrifical move, and the target isnt the user - it should not "miss". So we skip the miss check
if (this.move.getMove().getAttrs(SacrificialAttr).length && target !== user) { if (this.move.getMove().getAttrs(SacrificialAttr).length && target !== user) {
continue; continue;
} }