2023-04-15 12:34:42 +00:00
|
|
|
use anyhow::Result;
|
2022-06-30 15:34:57 +00:00
|
|
|
use std::fmt::Debug;
|
|
|
|
use std::sync::Arc;
|
2022-06-06 11:54:59 +00:00
|
|
|
|
2022-09-07 16:01:26 +00:00
|
|
|
use crate::dynamic_data::{ItemScript, Script, ScriptOwnerData};
|
2022-06-30 15:34:57 +00:00
|
|
|
use crate::static_data::Item;
|
2023-04-15 12:34:42 +00:00
|
|
|
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
2022-06-30 15:34:57 +00:00
|
|
|
|
|
|
|
/// A script resolver deals with the resolving of scripts. These scripts are non-hardcoded
|
|
|
|
/// implementations of different effects in Pokemon. This allows for things such as generational
|
|
|
|
/// differences, and custom implementations.
|
2022-10-14 08:33:19 +00:00
|
|
|
pub trait ScriptResolver: Debug + ValueIdentifiable {
|
2022-06-30 15:34:57 +00:00
|
|
|
/// Loads a standard script with a given unique combination of category and key. If no script
|
|
|
|
/// can be created with this combination, returns None.
|
|
|
|
fn load_script(
|
|
|
|
&self,
|
2022-09-07 16:01:26 +00:00
|
|
|
owner: ScriptOwnerData,
|
2022-06-30 15:34:57 +00:00
|
|
|
category: ScriptCategory,
|
|
|
|
script_key: &StringKey,
|
2023-04-15 12:34:42 +00:00
|
|
|
) -> Result<Option<Arc<dyn Script>>>;
|
2022-06-30 15:34:57 +00:00
|
|
|
|
|
|
|
/// Loads an item script with the given unique key. If no script can be created with this
|
|
|
|
/// combinations, returns None. Note that ItemScripts are immutable, as their script should be
|
|
|
|
/// shared between all different usages.
|
2023-04-15 12:34:42 +00:00
|
|
|
fn load_item_script(&self, _key: &dyn Item) -> Result<Option<Arc<dyn ItemScript>>>;
|
2022-06-30 15:34:57 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 15:21:24 +00:00
|
|
|
use std::fmt::Display;
|
2022-06-30 15:34:57 +00:00
|
|
|
/// A script category defines a sub-group of scripts. This can be used to have multiple scripts with
|
|
|
|
/// the same name, but a different script. It should be completely valid for a move to have the same
|
|
|
|
/// name as an ability, or more commonly: for a script attached to a Pokemon to have the same name as
|
|
|
|
/// a move that placed it there.
|
2022-10-15 15:21:24 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Display)]
|
2022-07-18 08:16:47 +00:00
|
|
|
#[repr(u8)]
|
2022-06-06 11:54:59 +00:00
|
|
|
pub enum ScriptCategory {
|
2022-06-30 15:34:57 +00:00
|
|
|
/// A script that belongs to a move. This generally is only the script that is attached to a
|
|
|
|
/// [`MoveChoice`](crate::dynamic_data::MoveChoice) and [`ExecutingMove`](crate::dynamic_data::ExecutingMove)
|
|
|
|
Move = 0,
|
|
|
|
/// An ability script. Scripts in this category are always abilities, and therefore always
|
|
|
|
/// attached to a Pokemon.
|
|
|
|
Ability = 1,
|
|
|
|
/// A non volatile status script. Scripts in this category are always non volatile statuses, and
|
|
|
|
/// therefore always attached to a Pokemon.
|
|
|
|
Status = 2,
|
|
|
|
/// A volatile status script. Scripts in this category are always volatile status effects, and
|
|
|
|
/// therefore always attached to a Pokemon.
|
|
|
|
Pokemon = 3,
|
|
|
|
/// A script that can be attached to an entire side.
|
|
|
|
Side = 4,
|
|
|
|
/// A script that can be attached to the entire battle.
|
|
|
|
Battle = 5,
|
2022-09-16 09:01:37 +00:00
|
|
|
/// A special script for weather, for use on battles.
|
|
|
|
Weather = 6,
|
2022-06-30 15:34:57 +00:00
|
|
|
/// A special script for held items. As they're part of a held item, they're attached to a Pokemon.
|
2022-09-16 09:01:37 +00:00
|
|
|
ItemBattleTrigger = 7,
|
2022-06-30 15:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A basic empty script resolver, that always returns None.
|
2023-01-03 11:58:23 +00:00
|
|
|
#[derive(Debug, Default)]
|
2022-10-14 08:33:19 +00:00
|
|
|
pub struct EmptyScriptResolver {
|
|
|
|
/// A unique identifier so we know what value this is.
|
|
|
|
pub identifier: ValueIdentifier,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ValueIdentifiable for EmptyScriptResolver {
|
|
|
|
fn value_identifier(&self) -> ValueIdentifier {
|
|
|
|
self.identifier
|
|
|
|
}
|
|
|
|
}
|
2022-06-30 15:34:57 +00:00
|
|
|
|
|
|
|
impl ScriptResolver for EmptyScriptResolver {
|
|
|
|
fn load_script(
|
|
|
|
&self,
|
2022-09-07 16:01:26 +00:00
|
|
|
_owner: ScriptOwnerData,
|
2022-06-30 15:34:57 +00:00
|
|
|
_category: ScriptCategory,
|
|
|
|
_script_key: &StringKey,
|
2023-04-15 12:34:42 +00:00
|
|
|
) -> Result<Option<Arc<dyn Script>>> {
|
2022-06-30 15:34:57 +00:00
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
|
2023-04-15 12:34:42 +00:00
|
|
|
fn load_item_script(&self, _key: &dyn Item) -> Result<Option<Arc<dyn ItemScript>>> {
|
2022-06-30 15:34:57 +00:00
|
|
|
Ok(None)
|
|
|
|
}
|
2022-06-06 11:54:59 +00:00
|
|
|
}
|