mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-22 07:27:44 +00:00
Move StatusEffects struct to it's own module
This commit is contained in:
parent
fe318cbc65
commit
7efbc5fd02
3 changed files with 39 additions and 35 deletions
|
@ -10,10 +10,10 @@ use crate::{
|
|||
};
|
||||
|
||||
use super::{
|
||||
Actor, Event, Inventory, Item, LuaPlayer, Zone,
|
||||
Actor, Event, Inventory, Item, LuaPlayer, StatusEffects, Zone,
|
||||
ipc::{
|
||||
ActorControl, ActorControlSelf, ActorSetPos, ClientZoneIpcSegment, ContainerInfo,
|
||||
ContainerType, InitZone, ItemInfo, ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect,
|
||||
ActorControlSelf, ActorSetPos, ClientZoneIpcSegment, ContainerInfo, ContainerType,
|
||||
InitZone, ItemInfo, ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect,
|
||||
StatusEffectList, UpdateClassInfo, WeatherChange,
|
||||
},
|
||||
};
|
||||
|
@ -39,37 +39,6 @@ pub struct PlayerData {
|
|||
pub zone_id: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct StatusEffects {
|
||||
pub status_effects: Vec<StatusEffect>,
|
||||
/// If the list is dirty and must be propagated to the client
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
impl StatusEffects {
|
||||
pub fn add(&mut self, effect_id: u16, duration: f32) {
|
||||
let status_effect = self.find_or_create_status_effect(effect_id);
|
||||
status_effect.duration = duration;
|
||||
self.dirty = true
|
||||
}
|
||||
|
||||
fn find_or_create_status_effect(&mut self, effect_id: u16) -> &mut StatusEffect {
|
||||
if let Some(i) = self
|
||||
.status_effects
|
||||
.iter()
|
||||
.position(|effect| effect.effect_id == effect_id)
|
||||
{
|
||||
&mut self.status_effects[i]
|
||||
} else {
|
||||
self.status_effects.push(StatusEffect {
|
||||
effect_id,
|
||||
..Default::default()
|
||||
});
|
||||
self.status_effects.last_mut().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a single connection between an instance of the client and the world server
|
||||
pub struct ZoneConnection {
|
||||
pub socket: TcpStream,
|
||||
|
|
|
@ -7,7 +7,7 @@ mod chat_handler;
|
|||
pub use chat_handler::ChatHandler;
|
||||
|
||||
mod connection;
|
||||
pub use connection::{PlayerData, StatusEffects, ZoneConnection};
|
||||
pub use connection::{PlayerData, ZoneConnection};
|
||||
|
||||
mod database;
|
||||
pub use database::{CharacterData, WorldDatabase};
|
||||
|
@ -23,3 +23,6 @@ pub use event::Event;
|
|||
|
||||
mod actor;
|
||||
pub use actor::Actor;
|
||||
|
||||
mod status_effects;
|
||||
pub use status_effects::StatusEffects;
|
||||
|
|
32
src/world/status_effects.rs
Normal file
32
src/world/status_effects.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use crate::world::ipc::StatusEffect;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct StatusEffects {
|
||||
pub status_effects: Vec<StatusEffect>,
|
||||
/// If the list is dirty and must be propagated to the client
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
impl StatusEffects {
|
||||
pub fn add(&mut self, effect_id: u16, duration: f32) {
|
||||
let status_effect = self.find_or_create_status_effect(effect_id);
|
||||
status_effect.duration = duration;
|
||||
self.dirty = true
|
||||
}
|
||||
|
||||
fn find_or_create_status_effect(&mut self, effect_id: u16) -> &mut StatusEffect {
|
||||
if let Some(i) = self
|
||||
.status_effects
|
||||
.iter()
|
||||
.position(|effect| effect.effect_id == effect_id)
|
||||
{
|
||||
&mut self.status_effects[i]
|
||||
} else {
|
||||
self.status_effects.push(StatusEffect {
|
||||
effect_id,
|
||||
..Default::default()
|
||||
});
|
||||
self.status_effects.last_mut().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue