overlord_event_system/behaviors/combat/
fight_start.rs1use essences::fighting::ActiveFight;
15
16use crate::behaviors::{BehaviorKind, BehaviorMeta, BehaviorRegistry};
17use crate::event::OverlordEvent;
18use crate::mechanics::content_lookups::ContentLookups;
19use crate::mechanics::fight::{self, NativeSink};
20use crate::state::OverlordState;
21
22pub struct FightStartCtx<'a> {
27 pub fight: &'a ActiveFight,
28 pub state: &'a OverlordState,
29 pub lookups: &'a ContentLookups,
30}
31
32pub type FightStartFn = fn(&FightStartCtx) -> anyhow::Result<Vec<OverlordEvent>>;
34
35pub fn init_fight_self(ctx: &FightStartCtx) -> anyhow::Result<Vec<OverlordEvent>> {
39 let mut sink = NativeSink::default();
40 fight::init_fight(
41 &mut sink,
42 ctx.lookups,
43 ctx.fight,
44 ctx.state,
45 ctx.fight.fight_id,
46 )
47 .map_err(|e| anyhow::anyhow!("init_fight: {e}"))?;
48 Ok(sink.events)
49}
50
51pub fn init_fight_self_static_buff(ctx: &FightStartCtx) -> anyhow::Result<Vec<OverlordEvent>> {
56 let mut events = init_fight_self(ctx)?;
57 events.push(OverlordEvent::EntityIncrAttribute {
58 entity_id: ctx.fight.player_id,
59 attribute: "static".to_string(),
60 delta: 1,
61 });
62 if let Some(party_player_id) = ctx.fight.party_player_id {
63 events.push(OverlordEvent::EntityIncrAttribute {
64 entity_id: party_player_id,
65 attribute: "static".to_string(),
66 delta: 1,
67 });
68 }
69 Ok(events)
70}
71
72pub fn noop(_ctx: &FightStartCtx) -> anyhow::Result<Vec<OverlordEvent>> {
76 Ok(vec![])
77}
78
79pub fn damage_first_entity_5(ctx: &FightStartCtx) -> anyhow::Result<Vec<OverlordEvent>> {
84 let Some(entity) = ctx.fight.entities.first() else {
85 return Ok(vec![]);
86 };
87 Ok(vec![OverlordEvent::Damage {
88 entity_id: entity.id,
89 damage: 5,
90 damage_data: crate::event::CustomEventData::default(),
91 }])
92}
93
94pub fn apply_spawn_on_death_to_player(ctx: &FightStartCtx) -> anyhow::Result<Vec<OverlordEvent>> {
99 Ok(vec![OverlordEvent::EntityApplyEffect {
100 entity_id: ctx.fight.player_id,
101 effect_id: uuid::Uuid::parse_str("39f135d2-b930-42a7-abfa-f1ec49f3cc00")?,
102 }])
103}
104
105pub fn register(registry: &mut BehaviorRegistry) {
107 registry.register_fight_start(
108 BehaviorMeta {
109 name: "noop".to_string(),
110 category: BehaviorKind::FightStart,
111 title: "Пустой start_behavior".to_string(),
112 description: "Эквивалент пустого start_behavior — не создаёт событий.".to_string(),
113 },
114 noop,
115 );
116 registry.register_fight_start(
117 BehaviorMeta {
118 name: "damage_first_entity_5".to_string(),
119 category: BehaviorKind::FightStart,
120 title: "Урон 5 по первой сущности (тест)".to_string(),
121 description: "Damage(Fight.entities[0], 5) — порт test fight start_behavior."
122 .to_string(),
123 },
124 damage_first_entity_5,
125 );
126 registry.register_fight_start(
127 BehaviorMeta {
128 name: "apply_spawn_on_death_to_player".to_string(),
129 category: BehaviorKind::FightStart,
130 title: "Эффект spawn-on-death на игрока (тест)".to_string(),
131 description: "ApplyEffect(Fight.player_id, 39f135d2) — порт test fight start_behavior."
132 .to_string(),
133 },
134 apply_spawn_on_death_to_player,
135 );
136 registry.register_fight_start(
137 BehaviorMeta {
138 name: "init_fight_self".to_string(),
139 category: BehaviorKind::FightStart,
140 title: "Инициализация боя".to_string(),
141 description: "Порт start_behavior `ctx.init_fight(State, <self id>)` — \
142 стартовые события боя через init_fight (без RNG)."
143 .to_string(),
144 },
145 init_fight_self,
146 );
147 registry.register_fight_start(
148 BehaviorMeta {
149 name: "init_fight_self_static_buff".to_string(),
150 category: BehaviorKind::FightStart,
151 title: "Инициализация боя + static-бафф".to_string(),
152 description: "Порт init_fight + push EntityIncrAttribute(player, \"static\", 1) \
153 и того же для party_player_id, если он есть."
154 .to_string(),
155 },
156 init_fight_self_static_buff,
157 );
158}