use bevy::prelude::*;
use issun_core::mechanics::diplomacy::{
ArgumentType, DiplomacyConfig, DiplomacyEvent, DiplomacyState,
};
#[derive(Resource, Reflect, Default, Clone)]
#[reflect(Resource)]
pub struct DiplomacyConfigResource {
#[reflect(ignore)]
pub config: DiplomacyConfig,
}
impl DiplomacyConfigResource {
pub fn new(config: DiplomacyConfig) -> Self {
Self { config }
}
}
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
pub struct Negotiator {
pub persuasion: f32,
}
#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct DiplomaticStance {
pub resistance: f32,
pub relationship: f32,
pub patience: u32,
pub progress: f32,
}
impl Default for DiplomaticStance {
fn default() -> Self {
Self {
resistance: 10.0,
relationship: 0.0,
patience: 5,
progress: 0.0,
}
}
}
impl DiplomaticStance {
pub fn to_state(&self) -> DiplomacyState {
let mut state = DiplomacyState::new(self.relationship, self.patience);
state.agreement_progress = self.progress;
state
}
pub fn from_state(&mut self, state: &DiplomacyState) {
self.progress = state.agreement_progress;
self.patience = state.patience;
}
}
#[derive(bevy::ecs::message::Message, Debug, Clone)]
pub struct NegotiationRequested {
pub initiator: Entity,
pub target: Entity,
pub argument_type: ArgumentType,
}
#[derive(bevy::ecs::message::Message, Debug, Clone, PartialEq)]
pub struct NegotiationResult {
pub initiator: Entity,
pub target: Entity,
pub event: DiplomacyEvent,
}
pub struct BevyDiplomacyEmitter<'a, 'b> {
initiator: Entity,
target: Entity,
writer: &'a mut bevy::ecs::message::MessageWriter<'b, NegotiationResult>,
}
impl<'a, 'b> BevyDiplomacyEmitter<'a, 'b> {
pub fn new(
initiator: Entity,
target: Entity,
writer: &'a mut bevy::ecs::message::MessageWriter<'b, NegotiationResult>,
) -> Self {
Self {
initiator,
target,
writer,
}
}
}
impl<'a, 'b> issun_core::mechanics::EventEmitter<DiplomacyEvent> for BevyDiplomacyEmitter<'a, 'b> {
fn emit(&mut self, event: DiplomacyEvent) {
self.writer.write(NegotiationResult {
initiator: self.initiator,
target: self.target,
event,
});
}
}