2024-01-13 12:24:24 -05:00
|
|
|
import { Biome } from "./enums/biome";
|
2024-05-17 05:25:21 -05:00
|
|
|
import { getPokemonMessage, getPokemonPrefix } from "../messages";
|
2024-02-29 20:08:50 -05:00
|
|
|
import Pokemon from "../field/pokemon";
|
2023-04-17 00:46:50 -04:00
|
|
|
import { Type } from "./type";
|
|
|
|
import Move, { AttackMove } from "./move";
|
2023-04-20 15:46:05 -04:00
|
|
|
import * as Utils from "../utils";
|
2023-04-27 14:30:03 -04:00
|
|
|
import BattleScene from "../battle-scene";
|
2024-03-18 21:22:27 -04:00
|
|
|
import { SuppressWeatherEffectAbAttr } from "./ability";
|
2024-03-09 21:57:33 -05:00
|
|
|
import { TerrainType } from "./terrain";
|
2024-05-15 19:31:18 +02:00
|
|
|
import i18next from "i18next";
|
2023-04-16 20:41:52 -04:00
|
|
|
|
|
|
|
export enum WeatherType {
|
|
|
|
NONE,
|
|
|
|
SUNNY,
|
|
|
|
RAIN,
|
|
|
|
SANDSTORM,
|
|
|
|
HAIL,
|
2024-04-15 22:35:35 +02:00
|
|
|
SNOW,
|
2023-04-16 20:41:52 -04:00
|
|
|
FOG,
|
|
|
|
HEAVY_RAIN,
|
|
|
|
HARSH_SUN,
|
|
|
|
STRONG_WINDS
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Weather {
|
|
|
|
public weatherType: WeatherType;
|
|
|
|
public turnsLeft: integer;
|
|
|
|
|
|
|
|
constructor(weatherType: WeatherType, turnsLeft?: integer) {
|
|
|
|
this.weatherType = weatherType;
|
2024-04-05 23:45:31 -04:00
|
|
|
this.turnsLeft = !this.isImmutable() ? turnsLeft || 0 : 0;
|
2023-04-16 20:41:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
lapse(): boolean {
|
2024-04-05 23:45:31 -04:00
|
|
|
if (this.isImmutable())
|
|
|
|
return true;
|
2023-04-16 20:41:52 -04:00
|
|
|
if (this.turnsLeft)
|
|
|
|
return !!--this.turnsLeft;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-04-17 00:46:50 -04:00
|
|
|
|
|
|
|
isImmutable(): boolean {
|
|
|
|
switch (this.weatherType) {
|
|
|
|
case WeatherType.HEAVY_RAIN:
|
|
|
|
case WeatherType.HARSH_SUN:
|
|
|
|
case WeatherType.STRONG_WINDS:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isDamaging(): boolean {
|
|
|
|
switch (this.weatherType) {
|
|
|
|
case WeatherType.SANDSTORM:
|
|
|
|
case WeatherType.HAIL:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isTypeDamageImmune(type: Type): boolean {
|
|
|
|
switch (this.weatherType) {
|
|
|
|
case WeatherType.SANDSTORM:
|
|
|
|
return type === Type.GROUND || type === Type.ROCK || type === Type.STEEL;
|
|
|
|
case WeatherType.HAIL:
|
|
|
|
return type === Type.ICE;
|
|
|
|
}
|
2023-04-19 14:07:38 -04:00
|
|
|
|
|
|
|
return false;
|
2023-04-17 00:46:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
getAttackTypeMultiplier(attackType: Type): number {
|
|
|
|
switch (this.weatherType) {
|
|
|
|
case WeatherType.SUNNY:
|
|
|
|
case WeatherType.HARSH_SUN:
|
|
|
|
if (attackType === Type.FIRE)
|
|
|
|
return 1.5;
|
|
|
|
if (attackType === Type.WATER)
|
|
|
|
return 0.5;
|
|
|
|
break;
|
|
|
|
case WeatherType.RAIN:
|
|
|
|
case WeatherType.HEAVY_RAIN:
|
|
|
|
if (attackType === Type.FIRE)
|
|
|
|
return 0.5;
|
|
|
|
if (attackType === Type.WATER)
|
|
|
|
return 1.5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
isMoveWeatherCancelled(move: Move): boolean {
|
|
|
|
switch (this.weatherType) {
|
|
|
|
case WeatherType.HARSH_SUN:
|
|
|
|
return move instanceof AttackMove && move.type === Type.WATER;
|
|
|
|
case WeatherType.HEAVY_RAIN:
|
|
|
|
return move instanceof AttackMove && move.type === Type.FIRE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-04-27 14:30:03 -04:00
|
|
|
|
|
|
|
isEffectSuppressed(scene: BattleScene): boolean {
|
2024-03-11 20:55:41 -04:00
|
|
|
const field = scene.getField(true);
|
2023-04-27 14:30:03 -04:00
|
|
|
|
2023-05-18 11:11:06 -04:00
|
|
|
for (let pokemon of field) {
|
2024-04-11 09:39:15 -04:00
|
|
|
let suppressWeatherEffectAbAttr = pokemon.getAbility().getAttrs(SuppressWeatherEffectAbAttr).find(() => true) as SuppressWeatherEffectAbAttr;
|
2024-04-11 09:24:03 -04:00
|
|
|
if (!suppressWeatherEffectAbAttr)
|
2024-04-15 15:03:50 +10:00
|
|
|
suppressWeatherEffectAbAttr = pokemon.hasPassive() ? pokemon.getPassiveAbility().getAttrs(SuppressWeatherEffectAbAttr).find(() => true) as SuppressWeatherEffectAbAttr : null;
|
2023-05-02 22:27:04 -04:00
|
|
|
if (suppressWeatherEffectAbAttr && (!this.isImmutable() || suppressWeatherEffectAbAttr.affectsImmutable))
|
|
|
|
return true;
|
|
|
|
}
|
2023-04-27 14:30:03 -04:00
|
|
|
|
2023-05-02 22:27:04 -04:00
|
|
|
return false;
|
2023-04-27 14:30:03 -04:00
|
|
|
}
|
2023-04-17 00:46:50 -04:00
|
|
|
}
|
|
|
|
|
2024-03-09 21:57:33 -05:00
|
|
|
export function getWeatherStartMessage(weatherType: WeatherType): string {
|
2023-04-17 00:46:50 -04:00
|
|
|
switch (weatherType) {
|
|
|
|
case WeatherType.SUNNY:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:sunnyStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.RAIN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:rainStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.SANDSTORM:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:sandstormStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HAIL:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:hailStartMessage');
|
2024-04-15 22:35:35 +02:00
|
|
|
case WeatherType.SNOW:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:snowStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.FOG:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:fogStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HEAVY_RAIN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:heavyRainStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HARSH_SUN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:harshSunStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.STRONG_WINDS:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:strongWindsStartMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-03-09 21:57:33 -05:00
|
|
|
export function getWeatherLapseMessage(weatherType: WeatherType): string {
|
2023-04-17 00:46:50 -04:00
|
|
|
switch (weatherType) {
|
|
|
|
case WeatherType.SUNNY:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:sunnyLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.RAIN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:rainLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.SANDSTORM:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:sandstormLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HAIL:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:hailLapseMessage');
|
2024-04-15 22:35:35 +02:00
|
|
|
case WeatherType.SNOW:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:snowLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.FOG:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:fogLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HEAVY_RAIN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:heavyRainLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HARSH_SUN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:harshSunLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.STRONG_WINDS:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:strongWindsLapseMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-03-09 21:57:33 -05:00
|
|
|
export function getWeatherDamageMessage(weatherType: WeatherType, pokemon: Pokemon): string {
|
2023-04-17 00:46:50 -04:00
|
|
|
switch (weatherType) {
|
|
|
|
case WeatherType.SANDSTORM:
|
2024-05-17 05:25:21 -05:00
|
|
|
return i18next.t('weather:sandstormDamageMessage', {pokemonPrefix: getPokemonPrefix(pokemon), pokemonName: pokemon.name});
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HAIL:
|
2024-05-17 05:25:21 -05:00
|
|
|
return i18next.t('weather:hailDamageMessage', {pokemonPrefix: getPokemonPrefix(pokemon), pokemonName: pokemon.name});
|
2023-04-17 00:46:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-03-09 21:57:33 -05:00
|
|
|
export function getWeatherClearMessage(weatherType: WeatherType): string {
|
2023-04-17 00:46:50 -04:00
|
|
|
switch (weatherType) {
|
|
|
|
case WeatherType.SUNNY:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:sunnyClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.RAIN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:rainClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.SANDSTORM:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:sandstormClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HAIL:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:hailClearMessage');
|
2024-04-15 22:35:35 +02:00
|
|
|
case WeatherType.SNOW:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:snowClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.FOG:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:fogClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HEAVY_RAIN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:heavyRainClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.HARSH_SUN:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:harshSunClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
case WeatherType.STRONG_WINDS:
|
2024-05-15 19:31:18 +02:00
|
|
|
return i18next.t('weather:strongWindsClearMessage');
|
2023-04-17 00:46:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-04-16 20:41:52 -04:00
|
|
|
}
|
|
|
|
|
2024-03-09 21:57:33 -05:00
|
|
|
export function getTerrainStartMessage(terrainType: TerrainType): string {
|
2024-03-18 18:03:13 -04:00
|
|
|
switch (terrainType) {
|
|
|
|
case TerrainType.MISTY:
|
|
|
|
return 'Mist swirled around the battlefield!';
|
|
|
|
case TerrainType.ELECTRIC:
|
|
|
|
return 'An electric current ran across the battlefield!';
|
|
|
|
case TerrainType.GRASSY:
|
|
|
|
return 'Grass grew to cover the battlefield!';
|
|
|
|
case TerrainType.PSYCHIC:
|
|
|
|
return 'The battlefield got weird!';
|
|
|
|
}
|
2024-03-09 21:57:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getTerrainClearMessage(terrainType: TerrainType): string {
|
2024-03-18 18:03:13 -04:00
|
|
|
switch (terrainType) {
|
|
|
|
case TerrainType.MISTY:
|
|
|
|
return 'The mist disappeared from the battlefield.';
|
|
|
|
case TerrainType.ELECTRIC:
|
|
|
|
return 'The electricity disappeared from the battlefield.';
|
|
|
|
case TerrainType.GRASSY:
|
|
|
|
return 'The grass disappeared from the battlefield.';
|
|
|
|
case TerrainType.PSYCHIC:
|
|
|
|
return 'The weirdness disappeared from the battlefield!';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTerrainBlockMessage(pokemon: Pokemon, terrainType: TerrainType): string {
|
|
|
|
if (terrainType === TerrainType.MISTY)
|
|
|
|
return getPokemonMessage(pokemon, ` surrounds itself with a protective mist!`);
|
|
|
|
return getPokemonMessage(pokemon, ` is protected by the ${Utils.toReadableString(TerrainType[terrainType])} Terrain!`);
|
2024-03-09 21:57:33 -05:00
|
|
|
}
|
|
|
|
|
2023-04-16 20:41:52 -04:00
|
|
|
interface WeatherPoolEntry {
|
|
|
|
weatherType: WeatherType;
|
|
|
|
weight: integer;
|
|
|
|
}
|
|
|
|
|
2023-12-29 21:04:40 -05:00
|
|
|
export function getRandomWeatherType(arena: any /* Importing from arena causes a circular dependency */): WeatherType {
|
2023-04-16 20:41:52 -04:00
|
|
|
let weatherPool: WeatherPoolEntry[] = [];
|
2023-12-29 21:04:40 -05:00
|
|
|
const hasSun = arena.getTimeOfDay() < 2;
|
|
|
|
switch (arena.biomeType) {
|
2023-04-16 20:41:52 -04:00
|
|
|
case Biome.GRASS:
|
|
|
|
weatherPool = [
|
2023-12-29 21:04:40 -05:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 7 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
2023-12-29 21:04:40 -05:00
|
|
|
if (hasSun)
|
|
|
|
weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 3 });
|
2023-04-16 20:41:52 -04:00
|
|
|
break;
|
|
|
|
case Biome.TALL_GRASS:
|
|
|
|
weatherPool = [
|
2024-03-27 22:40:10 -04:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 8 },
|
2023-04-17 00:46:50 -04:00
|
|
|
{ weatherType: WeatherType.RAIN, weight: 5 },
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
2023-12-29 21:04:40 -05:00
|
|
|
if (hasSun)
|
|
|
|
weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 8 });
|
2023-04-16 20:41:52 -04:00
|
|
|
break;
|
|
|
|
case Biome.FOREST:
|
|
|
|
weatherPool = [
|
|
|
|
{ weatherType: WeatherType.NONE, weight: 8 },
|
2023-10-28 17:59:49 -04:00
|
|
|
{ weatherType: WeatherType.RAIN, weight: 5 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
case Biome.SEA:
|
|
|
|
weatherPool = [
|
|
|
|
{ weatherType: WeatherType.NONE, weight: 3 },
|
2023-10-28 17:59:49 -04:00
|
|
|
{ weatherType: WeatherType.RAIN, weight: 12 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
case Biome.SWAMP:
|
|
|
|
weatherPool = [
|
2024-04-10 12:56:31 -04:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 3 },
|
|
|
|
{ weatherType: WeatherType.RAIN, weight: 4 },
|
|
|
|
{ weatherType: WeatherType.FOG, weight: 1 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
case Biome.BEACH:
|
|
|
|
weatherPool = [
|
2023-12-13 19:24:10 -05:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 8 },
|
|
|
|
{ weatherType: WeatherType.RAIN, weight: 3 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
2023-12-29 21:04:40 -05:00
|
|
|
if (hasSun)
|
|
|
|
weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 5 });
|
2023-04-16 20:41:52 -04:00
|
|
|
break;
|
|
|
|
case Biome.LAKE:
|
|
|
|
weatherPool = [
|
|
|
|
{ weatherType: WeatherType.NONE, weight: 10 },
|
|
|
|
{ weatherType: WeatherType.RAIN, weight: 5 },
|
2024-04-10 12:56:31 -04:00
|
|
|
{ weatherType: WeatherType.FOG, weight: 1 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
case Biome.SEABED:
|
|
|
|
weatherPool = [
|
2023-10-28 17:59:49 -04:00
|
|
|
{ weatherType: WeatherType.RAIN, weight: 1 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
2023-05-11 10:31:39 -04:00
|
|
|
case Biome.BADLANDS:
|
2023-04-16 20:41:52 -04:00
|
|
|
weatherPool = [
|
|
|
|
{ weatherType: WeatherType.NONE, weight: 8 },
|
2023-10-28 17:59:49 -04:00
|
|
|
{ weatherType: WeatherType.SANDSTORM, weight: 2 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
2023-12-29 21:04:40 -05:00
|
|
|
if (hasSun)
|
|
|
|
weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 5 });
|
2023-04-16 20:41:52 -04:00
|
|
|
break;
|
|
|
|
case Biome.DESERT:
|
|
|
|
weatherPool = [
|
2023-12-29 21:04:40 -05:00
|
|
|
{ weatherType: WeatherType.SANDSTORM, weight: 2 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
2023-12-29 21:04:40 -05:00
|
|
|
if (hasSun)
|
|
|
|
weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 2 });
|
2023-04-16 20:41:52 -04:00
|
|
|
break;
|
|
|
|
case Biome.ICE_CAVE:
|
|
|
|
weatherPool = [
|
2024-04-15 17:45:18 -04:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 3 },
|
|
|
|
{ weatherType: WeatherType.SNOW, weight: 4 },
|
2023-04-16 20:41:52 -04:00
|
|
|
{ weatherType: WeatherType.HAIL, weight: 1 }
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
case Biome.MEADOW:
|
|
|
|
weatherPool = [
|
2023-12-29 21:04:40 -05:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 2 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
2023-12-29 21:04:40 -05:00
|
|
|
if (hasSun)
|
|
|
|
weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 2 });
|
2023-04-16 20:41:52 -04:00
|
|
|
case Biome.VOLCANO:
|
|
|
|
weatherPool = [
|
2023-12-29 21:04:40 -05:00
|
|
|
{ weatherType: hasSun ? WeatherType.SUNNY : WeatherType.NONE, weight: 1 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
case Biome.GRAVEYARD:
|
|
|
|
weatherPool = [
|
2024-04-10 12:56:31 -04:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 3 },
|
2023-04-16 20:41:52 -04:00
|
|
|
{ weatherType: WeatherType.FOG, weight: 1 }
|
|
|
|
];
|
|
|
|
break;
|
2024-04-15 17:45:18 -04:00
|
|
|
case Biome.JUNGLE:
|
2023-04-16 20:41:52 -04:00
|
|
|
weatherPool = [
|
2024-04-15 17:45:18 -04:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 8 },
|
|
|
|
{ weatherType: WeatherType.RAIN, weight: 2 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
2024-04-15 17:45:18 -04:00
|
|
|
case Biome.SNOWY_FOREST:
|
2023-04-16 20:41:52 -04:00
|
|
|
weatherPool = [
|
2024-04-15 17:45:18 -04:00
|
|
|
{ weatherType: WeatherType.SNOW, weight: 7 },
|
|
|
|
{ weatherType: WeatherType.HAIL, weight: 1 }
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
|
|
|
break;
|
2024-04-15 17:45:18 -04:00
|
|
|
case Biome.ISLAND:
|
2023-04-16 20:41:52 -04:00
|
|
|
weatherPool = [
|
2024-04-15 17:45:18 -04:00
|
|
|
{ weatherType: WeatherType.NONE, weight: 5 },
|
|
|
|
{ weatherType: WeatherType.RAIN, weight: 1 },
|
2023-04-16 20:41:52 -04:00
|
|
|
];
|
2024-04-15 17:45:18 -04:00
|
|
|
if (hasSun)
|
|
|
|
weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 2 });
|
2023-04-16 20:41:52 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (weatherPool.length > 1) {
|
|
|
|
let totalWeight = 0;
|
|
|
|
weatherPool.forEach(w => totalWeight += w.weight);
|
|
|
|
|
2023-10-18 18:01:15 -04:00
|
|
|
const rand = Utils.randSeedInt(totalWeight);
|
2023-04-16 20:41:52 -04:00
|
|
|
let w = 0;
|
|
|
|
for (let weather of weatherPool) {
|
|
|
|
w += weather.weight;
|
|
|
|
if (rand < w)
|
2023-04-17 00:46:50 -04:00
|
|
|
return weather.weatherType;
|
2023-04-16 20:41:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return weatherPool.length
|
2023-04-17 00:46:50 -04:00
|
|
|
? weatherPool[0].weatherType
|
|
|
|
: WeatherType.NONE;
|
2023-04-16 20:41:52 -04:00
|
|
|
}
|