mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-21 15:07:45 +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::{
|
use super::{
|
||||||
Actor, Event, Inventory, Item, LuaPlayer, Zone,
|
Actor, Event, Inventory, Item, LuaPlayer, StatusEffects, Zone,
|
||||||
ipc::{
|
ipc::{
|
||||||
ActorControl, ActorControlSelf, ActorSetPos, ClientZoneIpcSegment, ContainerInfo,
|
ActorControlSelf, ActorSetPos, ClientZoneIpcSegment, ContainerInfo, ContainerType,
|
||||||
ContainerType, InitZone, ItemInfo, ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect,
|
InitZone, ItemInfo, ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect,
|
||||||
StatusEffectList, UpdateClassInfo, WeatherChange,
|
StatusEffectList, UpdateClassInfo, WeatherChange,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -39,37 +39,6 @@ pub struct PlayerData {
|
||||||
pub zone_id: u16,
|
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
|
/// Represents a single connection between an instance of the client and the world server
|
||||||
pub struct ZoneConnection {
|
pub struct ZoneConnection {
|
||||||
pub socket: TcpStream,
|
pub socket: TcpStream,
|
||||||
|
|
|
@ -7,7 +7,7 @@ mod chat_handler;
|
||||||
pub use chat_handler::ChatHandler;
|
pub use chat_handler::ChatHandler;
|
||||||
|
|
||||||
mod connection;
|
mod connection;
|
||||||
pub use connection::{PlayerData, StatusEffects, ZoneConnection};
|
pub use connection::{PlayerData, ZoneConnection};
|
||||||
|
|
||||||
mod database;
|
mod database;
|
||||||
pub use database::{CharacterData, WorldDatabase};
|
pub use database::{CharacterData, WorldDatabase};
|
||||||
|
@ -23,3 +23,6 @@ pub use event::Event;
|
||||||
|
|
||||||
mod actor;
|
mod actor;
|
||||||
pub use actor::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