2024-01-05 22:24:05 -05:00
|
|
|
import { Stat, getStatName } from "./pokemon-stat";
|
|
|
|
import * as Utils from "../utils";
|
|
|
|
import { TextStyle, getBBCodeFrag } from "../ui/text";
|
2024-06-13 11:11:12 -04:00
|
|
|
import { UiTheme } from "#enums";
|
2024-05-23 17:03:10 +02:00
|
|
|
import i18next from "i18next";
|
2024-01-05 22:24:05 -05:00
|
|
|
|
|
|
|
export enum Nature {
|
|
|
|
HARDY,
|
|
|
|
LONELY,
|
|
|
|
BRAVE,
|
|
|
|
ADAMANT,
|
|
|
|
NAUGHTY,
|
|
|
|
BOLD,
|
|
|
|
DOCILE,
|
|
|
|
RELAXED,
|
|
|
|
IMPISH,
|
|
|
|
LAX,
|
|
|
|
TIMID,
|
|
|
|
HASTY,
|
|
|
|
SERIOUS,
|
|
|
|
JOLLY,
|
|
|
|
NAIVE,
|
|
|
|
MODEST,
|
|
|
|
MILD,
|
|
|
|
QUIET,
|
|
|
|
BASHFUL,
|
|
|
|
RASH,
|
|
|
|
CALM,
|
|
|
|
GENTLE,
|
|
|
|
SASSY,
|
|
|
|
CAREFUL,
|
|
|
|
QUIRKY
|
|
|
|
}
|
|
|
|
|
2024-04-04 20:33:08 -04:00
|
|
|
export function getNatureName(nature: Nature, includeStatEffects: boolean = false, forStarterSelect: boolean = false, ignoreBBCode: boolean = false, uiTheme: UiTheme = UiTheme.DEFAULT): string {
|
2024-01-05 22:24:05 -05:00
|
|
|
let ret = Utils.toReadableString(Nature[nature]);
|
2024-05-12 04:22:45 +02:00
|
|
|
//Translating nature
|
2024-05-24 02:19:20 +02:00
|
|
|
if (i18next.exists("nature:" + ret)) {
|
2024-05-23 17:03:10 +02:00
|
|
|
ret = i18next.t("nature:" + ret as any);
|
2024-05-12 04:22:45 +02:00
|
|
|
}
|
2024-01-05 22:24:05 -05:00
|
|
|
if (includeStatEffects) {
|
|
|
|
const stats = Utils.getEnumValues(Stat).slice(1);
|
|
|
|
let increasedStat: Stat = null;
|
|
|
|
let decreasedStat: Stat = null;
|
2024-05-23 17:03:10 +02:00
|
|
|
for (const stat of stats) {
|
2024-01-05 22:24:05 -05:00
|
|
|
const multiplier = getNatureStatMultiplier(nature, stat);
|
2024-05-23 17:03:10 +02:00
|
|
|
if (multiplier > 1) {
|
2024-01-05 22:24:05 -05:00
|
|
|
increasedStat = stat;
|
2024-05-23 17:03:10 +02:00
|
|
|
} else if (multiplier < 1) {
|
2024-01-05 22:24:05 -05:00
|
|
|
decreasedStat = stat;
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2024-01-05 22:24:05 -05:00
|
|
|
}
|
2024-03-31 21:14:35 -04:00
|
|
|
const textStyle = forStarterSelect ? TextStyle.SUMMARY_ALT : TextStyle.WINDOW;
|
2024-04-04 20:33:08 -04:00
|
|
|
const getTextFrag = !ignoreBBCode ? (text: string, style: TextStyle) => getBBCodeFrag(text, style, uiTheme) : (text: string, style: TextStyle) => text;
|
2024-05-23 17:03:10 +02:00
|
|
|
if (increasedStat && decreasedStat) {
|
|
|
|
ret = `${getTextFrag(`${ret}${!forStarterSelect ? "\n" : " "}(`, textStyle)}${getTextFrag(`+${getStatName(increasedStat, true)}`, TextStyle.SUMMARY_PINK)}${getTextFrag("/", textStyle)}${getTextFrag(`-${getStatName(decreasedStat, true)}`, TextStyle.SUMMARY_BLUE)}${getTextFrag(")", textStyle)}`;
|
|
|
|
} else {
|
|
|
|
ret = getTextFrag(`${ret}${!forStarterSelect ? "\n" : " "}(-)`, textStyle);
|
|
|
|
}
|
2024-01-05 22:24:05 -05:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNatureStatMultiplier(nature: Nature, stat: Stat): number {
|
|
|
|
switch (stat) {
|
2024-05-23 17:03:10 +02:00
|
|
|
case Stat.ATK:
|
|
|
|
switch (nature) {
|
|
|
|
case Nature.LONELY:
|
|
|
|
case Nature.BRAVE:
|
|
|
|
case Nature.ADAMANT:
|
|
|
|
case Nature.NAUGHTY:
|
|
|
|
return 1.1;
|
|
|
|
case Nature.BOLD:
|
|
|
|
case Nature.TIMID:
|
|
|
|
case Nature.MODEST:
|
|
|
|
case Nature.CALM:
|
|
|
|
return 0.9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Stat.DEF:
|
|
|
|
switch (nature) {
|
|
|
|
case Nature.BOLD:
|
|
|
|
case Nature.RELAXED:
|
|
|
|
case Nature.IMPISH:
|
|
|
|
case Nature.LAX:
|
|
|
|
return 1.1;
|
|
|
|
case Nature.LONELY:
|
|
|
|
case Nature.HASTY:
|
|
|
|
case Nature.MILD:
|
|
|
|
case Nature.GENTLE:
|
|
|
|
return 0.9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Stat.SPATK:
|
|
|
|
switch (nature) {
|
|
|
|
case Nature.MODEST:
|
|
|
|
case Nature.MILD:
|
|
|
|
case Nature.QUIET:
|
|
|
|
case Nature.RASH:
|
|
|
|
return 1.1;
|
|
|
|
case Nature.ADAMANT:
|
|
|
|
case Nature.IMPISH:
|
|
|
|
case Nature.JOLLY:
|
|
|
|
case Nature.CAREFUL:
|
|
|
|
return 0.9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Stat.SPDEF:
|
|
|
|
switch (nature) {
|
|
|
|
case Nature.CALM:
|
|
|
|
case Nature.GENTLE:
|
|
|
|
case Nature.SASSY:
|
|
|
|
case Nature.CAREFUL:
|
|
|
|
return 1.1;
|
|
|
|
case Nature.NAUGHTY:
|
|
|
|
case Nature.LAX:
|
|
|
|
case Nature.NAIVE:
|
|
|
|
case Nature.RASH:
|
|
|
|
return 0.9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Stat.SPD:
|
|
|
|
switch (nature) {
|
|
|
|
case Nature.TIMID:
|
|
|
|
case Nature.HASTY:
|
|
|
|
case Nature.JOLLY:
|
|
|
|
case Nature.NAIVE:
|
|
|
|
return 1.1;
|
|
|
|
case Nature.BRAVE:
|
|
|
|
case Nature.RELAXED:
|
|
|
|
case Nature.QUIET:
|
|
|
|
case Nature.SASSY:
|
|
|
|
return 0.9;
|
|
|
|
}
|
|
|
|
break;
|
2024-01-05 22:24:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|