Skip to content

Commit

Permalink
Merge branch 'smogon-master'
Browse files Browse the repository at this point in the history
* smogon-master:
  Update copyright year
  Update dependencies
  Gen 7/8: Fix -ate abilities, Reckless, and Iron Fist (smogon#446)
  Convert modifiers from hex to decimal (smogon#444)
  Fix broken link in README.md (smogon#431)
  Function modularization tweaks (gens 7, 8) and iron ball calculations (smogon#439)
  Fix Reversal and Flail power calculation for Gen 4 (smogon#433)
  Actually fix build
  Fix build
  Gen 3: Double Facade base power when poisoned, paralyzed or burned (smogon#412)
  Added Power Spot, Fixed Dauntless Shield, Made Competitive activate from Intimidate, Cleaned up EV and IV exporting (smogon#435)
  Fix Rivalry boost (smogon#440)
  Change BP limit from 999 to 65535 (smogon#442)
  Update packages and fix build
  Search for imported sets (smogon#428)
  Docker addition api (smogon#422)
  Modularize the Gen 7 & 8 mechanics page (smogon#429)
  New TextField for naming the imported sets (smogon#423)
  Export import bugfix (smogon#426)
  Support field-wide Fairy Aura, Dark Aura and Aura Break when neither Pokemon uses the ability (smogon#430)
  • Loading branch information
GriffinLedingham committed Jun 7, 2021
2 parents dd79550 + 4c665fb commit 6ecef23
Show file tree
Hide file tree
Showing 35 changed files with 970 additions and 575 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:12
# Create app directory
WORKDIR /usr/src/app/calc

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY calc/package*.json ./
RUN npm install

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source

COPY . .
RUN node build

EXPOSE 3000
CMD [ "node", "server.js" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2020 Honko and other contributors
Copyright (c) 2013-2021 Honko and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Alternatively, as [detailed below](#browser), if you are using `@smogon/calc` in
a convenient way to get started, simply depend on a transpiled and minified version via [unpkg][5]:

```html
<script src="https://unpkg.com/@smogon/calc/data/production.min.js"></script>
<script src="https://unpkg.com/@smogon/calc/dist/data/production.min.js"></script>
<script src="https://unpkg.com/@smogon/calc"></script>
```

Expand Down Expand Up @@ -135,7 +135,7 @@ $ cd calc && npm install
```

Next, run `node build` from the root directory of your clone of this repository. This should
run `npm run compile` in the `calc/` subdirectory to compile the `@smoogon/calc` package from
run `npm run compile` in the `calc/` subdirectory to compile the `@smogon/calc` package from
TypeScript to JavaScript that can be run in the browser, and then compile the 'templated' HTML
and copy everything into the top-level `dist/` folder. To then view the UI, open `dist/index.html` -
simply double-clicking on the file from your operating system's file manager UI should open it in
Expand Down
16 changes: 8 additions & 8 deletions calc/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ bundled += natures.slice(47, -2).join('\n');
bundled += bundler.read('data/abilities.js', 43, 1);
bundled += bundler.read('data/moves.js', 43, 1);
const items = bundler.read('data/items.js').split('\n');
bundled += items.slice(44, 48).join('\n'); // spreadArray polyfill
bundled += items.slice(63, -2).join('\n');
bundled += items.slice(44, 49).join('\n'); // spreadArray polyfill
bundled += items.slice(64, -2).join('\n');
bundled += `
var abilities_1 = exports;
var items_1 = exports;
Expand Down Expand Up @@ -70,18 +70,18 @@ bundled += field.slice(19, -2).join('\n');
bundled += bundler.read('move.js', 4, 1);
bundled += bundler.read('items.js', 4, 1);
const utils = bundler.read('mechanics/util.js').split('\n');
bundled += utils.slice(28, 32).join('\n'); // spreadArray polyfill
bundled += utils.slice(36, -2).join('\n');
bundled += bundler.read('result.js', 24, 1);
bundled += utils.slice(28, 33).join('\n'); // spreadArray polyfill
bundled += utils.slice(37, -2).join('\n');
bundled += bundler.read('result.js', 25, 1);
bundled += '\nvar result_1 = exports;\nvar util_2 = exports;\n';
bundled += bundler.read('desc.js', 22, 1);
bundled += '\nvar desc_1 = exports;\nvar items_1 = exports;\n';
bundled += bundler.read('mechanics/gen78.js', 7, 1);
bundled += bundler.read('mechanics/gen56.js', 7, 1);
bundled += bundler.read('mechanics/gen4.js', 26, 1);
bundled += bundler.read('mechanics/gen4.js', 27, 1);
// These don't require 'util', so 'mechanics/util' gets the util_1 name.
bundled += bundler.read('mechanics/gen3.js', 26, 1).replace(/util_1/g, 'util_2');
bundled += bundler.read('mechanics/gen12.js', 26, 1).replace(/util_1/g, 'util_2');
bundled += bundler.read('mechanics/gen3.js', 27, 1).replace(/util_1/g, 'util_2');
bundled += bundler.read('mechanics/gen12.js', 27, 1).replace(/util_1/g, 'util_2');
bundled += `
var field_1 = exports;
var gen12_1 = exports;
Expand Down
16 changes: 8 additions & 8 deletions calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
"repository": "github:GriffinLedingham/damage-calc",
"license": "MIT",
"dependencies": {
"@types/node": "^14.14.25"
"@types/node": "^15.0.3"
},
"devDependencies": {
"@pkmn/dex": "^0.3.15",
"@pkmn/dex": "0.4.4",
"@pkmn/eslint-config": "^1.1.0",
"@types/jest": "^26.0.20",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"eslint": "^7.19.0",
"@types/jest": "^26.0.23",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"eslint": "^7.26.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jest": "^24.3.6",
"jest": "^26.6.3",
"ts-jest": "^26.5.0",
"typescript": "^4.1.3"
"ts-jest": "^26.5.6",
"typescript": "^4.2.0"
},
"scripts": {
"lint": "eslint --cache src --ext ts",
Expand Down
2 changes: 0 additions & 2 deletions calc/src/data/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3145,15 +3145,13 @@ const SS_PATCH: {[name: string]: DeepPartial<MoveData>} = {
bp: 10,
type: 'Dark',
category: 'Physical',
breaksProtect: true,
isMax: true,
maxPower: 1,
},
'G-Max Rapid Flow': {
bp: 10,
type: 'Water',
category: 'Physical',
breaksProtect: true,
isMax: true,
maxPower: 1,
},
Expand Down
7 changes: 7 additions & 0 deletions calc/src/data/species.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7668,6 +7668,13 @@ const SS_PATCH: {[name: string]: DeepPartial<SpeciesData>} = {
abilities: {0: 'Strong Jaw'},
nfe: true,
},
Chromera: {
types: ['Dark', 'Poison'],
bs: {hp: 85, at: 85, df: 115, sa: 115, sd: 100, sp: 100},
weightkg: 215,
abilities: {0: 'Color Change'},
gender: 'N',
},
Cinderace: {
types: ['Fire'],
bs: {hp: 80, at: 116, df: 75, sa: 65, sd: 75, sp: 119},
Expand Down
4 changes: 4 additions & 0 deletions calc/src/desc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface RawDesc {
isProtected?: boolean;
isReflect?: boolean;
isBattery?: boolean;
isPowerSpot?: boolean;
isSwitching?: 'out' | 'in';
moveBP?: number;
moveName: string;
Expand Down Expand Up @@ -825,6 +826,9 @@ function buildDescription(description: RawDesc, attacker: Pokemon, defender: Pok
if (description.isBattery) {
output += ' Battery boosted ';
}
if (description.isPowerSpot) {
output += ' Power Spot boosted ';
}
if (description.isSwitching) {
output += ' switching boosted ';
}
Expand Down
2 changes: 2 additions & 0 deletions calc/src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class Side implements State.Side {
isFriendGuard: boolean;
isAuroraVeil: boolean;
isBattery: boolean;
isPowerSpot: boolean;
isSwitching?: 'out' | 'in';

constructor(side: State.Side = {}) {
Expand All @@ -91,6 +92,7 @@ export class Side implements State.Side {
this.isFriendGuard = !!side.isFriendGuard;
this.isAuroraVeil = !!side.isAuroraVeil;
this.isBattery = !!side.isBattery;
this.isPowerSpot = !!side.isPowerSpot;
this.isSwitching = side.isSwitching;
}

Expand Down
8 changes: 7 additions & 1 deletion calc/src/mechanics/gen3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function calculateADV(
desc.hits = move.hits;
}

let bp;
let bp = move.bp;
switch (move.name) {
case 'Flail':
case 'Reversal':
Expand All @@ -118,6 +118,12 @@ export function calculateADV(
bp = w >= 200 ? 120 : w >= 100 ? 100 : w >= 50 ? 80 : w >= 25 ? 60 : w >= 10 ? 40 : 20;
desc.moveBP = bp;
break;
case 'Facade':
if (attacker.hasStatus('par', 'psn', 'tox', 'brn')) {
bp = move.bp * 2;
desc.moveBP = bp;
}
break;
default:
bp = move.bp;
}
Expand Down
24 changes: 18 additions & 6 deletions calc/src/mechanics/gen4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,23 @@ export function calculateDPP(
}

const isGhostRevealed = attacker.hasAbility('Scrappy') || field.defenderSide.isForesight;
const type1Effectiveness =
let type1Effectiveness =
getMoveEffectiveness(gen, move, defender.types[0], isGhostRevealed, field.isGravity);
const type2Effectiveness = defender.types[1]
let type2Effectiveness = defender.types[1]
? getMoveEffectiveness(gen, move, defender.types[1], isGhostRevealed, field.isGravity)
: 1;
const typeEffectiveness = type1Effectiveness * type2Effectiveness;

let typeEffectiveness = type1Effectiveness * type2Effectiveness;

// Iron Ball ignores Klutz in generation 4
if (typeEffectiveness === 0 && move.hasType('Ground') && defender.hasItem('Iron Ball')) {
if (type1Effectiveness === 0) {
type1Effectiveness = 1;
} else if (defender.types[1] && type2Effectiveness === 0) {
type2Effectiveness = 1;
}
typeEffectiveness = type1Effectiveness * type2Effectiveness;
}

if (typeEffectiveness === 0) {
return result;
Expand All @@ -119,7 +130,8 @@ export function calculateDPP(
(move.hasType('Fire') && defender.hasAbility('Flash Fire')) ||
(move.hasType('Water') && defender.hasAbility('Dry Skin', 'Water Absorb')) ||
(move.hasType('Electric') && defender.hasAbility('Motor Drive', 'Volt Absorb')) ||
(move.hasType('Ground') && !field.isGravity && defender.hasAbility('Levitate')) ||
(move.hasType('Ground') && !field.isGravity &&
!defender.hasItem('Iron Ball') && defender.hasAbility('Levitate')) ||
(move.flags.sound && defender.hasAbility('Soundproof'))
) {
desc.defenderAbility = defender.ability;
Expand Down Expand Up @@ -162,8 +174,8 @@ export function calculateDPP(
break;
case 'Flail':
case 'Reversal':
const p = Math.floor((48 * attacker.curHP()) / attacker.maxHP());
basePower = p <= 1 ? 200 : p <= 4 ? 150 : p <= 9 ? 100 : p <= 16 ? 80 : p <= 32 ? 40 : 20;
const p = Math.floor((64 * attacker.curHP()) / attacker.maxHP());
basePower = p <= 1 ? 200 : p <= 5 ? 150 : p <= 12 ? 100 : p <= 21 ? 80 : p <= 42 ? 40 : 20;
desc.moveBP = basePower;
break;
case 'Fling':
Expand Down
Loading

0 comments on commit 6ecef23

Please sign in to comment.