|
@ -3,26 +3,58 @@ use libpso::packet::ship::*; |
|
|
use libpso::packet::messages::*;
|
|
|
use libpso::packet::messages::*;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::common::serverstate::ClientId;
|
|
|
use crate::common::serverstate::ClientId;
|
|
|
|
|
|
use crate::common::leveltable::CharacterLevelTable;
|
|
|
use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation};
|
|
|
use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation};
|
|
|
use crate::ship::location::{ClientLocation, ClientLocationError, RoomLobby};
|
|
|
use crate::ship::location::{ClientLocation, ClientLocationError, RoomLobby};
|
|
|
use crate::ship::map::{MapArea};
|
|
|
use crate::ship::map::{MapArea};
|
|
|
use crate::ship::items::{ItemManager, ClientItemId};
|
|
|
use crate::ship::items::{ItemManager, ClientItemId};
|
|
|
use crate::ship::packet::builder;
|
|
|
use crate::ship::packet::builder;
|
|
|
|
|
|
|
|
|
pub fn request_exp(id: ClientId,
|
|
|
|
|
|
request_exp: &RequestExp,
|
|
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
|
|
rooms: &Rooms)
|
|
|
|
|
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
|
|
|
|
|
|
|
|
|
|
|
match client_location.get_area(id).unwrap() {
|
|
|
|
|
|
RoomLobby::Room(room) => {
|
|
|
|
|
|
let r = rooms[room.0].as_ref().unwrap();
|
|
|
|
|
|
warn!("killed a {:?}", r.maps.enemy_by_id(request_exp.enemy_id as usize).unwrap().monster);
|
|
|
|
|
|
},
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
};
|
|
|
|
|
|
Box::new(None.into_iter())
|
|
|
|
|
|
|
|
|
pub async fn request_exp<EG: EntityGateway>(id: ClientId,
|
|
|
|
|
|
request_exp: &RequestExp,
|
|
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
|
|
clients: &mut Clients,
|
|
|
|
|
|
rooms: &mut Rooms,
|
|
|
|
|
|
level_table: &CharacterLevelTable)
|
|
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
|
|
let area_client = client_location.get_local_client(id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
|
|
let room_id = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
|
|
let room = rooms.get_mut(room_id.0)
|
|
|
|
|
|
.ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?
|
|
|
|
|
|
.as_mut()
|
|
|
|
|
|
.ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?;
|
|
|
|
|
|
|
|
|
|
|
|
let monster = room.maps.enemy_by_id(request_exp.enemy_id as usize)?;
|
|
|
|
|
|
let monster_stats = room.monster_stats.get(&monster.monster).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let clients_in_area = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
|
|
let gain_exp_pkt = builder::message::character_gained_exp(area_client, monster_stats.exp);
|
|
|
|
|
|
let mut exp_pkts: Box<dyn Iterator<Item = _> + Send> = Box::new(clients_in_area.clone().into_iter()
|
|
|
|
|
|
.map(move |c| {
|
|
|
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::GiveCharacterExp(gain_exp_pkt.clone()))))
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
let before_level = level_table.get_level_from_exp(client.character.char_class, client.character.exp);
|
|
|
|
|
|
let after_level = level_table.get_level_from_exp(client.character.char_class, client.character.exp + monster_stats.exp);
|
|
|
|
|
|
let level_up = before_level != after_level;
|
|
|
|
|
|
|
|
|
|
|
|
if level_up {
|
|
|
|
|
|
let (_, before_stats) = level_table.get_stats_from_exp(client.character.char_class, client.character.exp);
|
|
|
|
|
|
let (after_level, after_stats) = level_table.get_stats_from_exp(client.character.char_class, client.character.exp + monster_stats.exp);
|
|
|
|
|
|
|
|
|
|
|
|
let level_up_pkt = builder::message::character_leveled_up(area_client, after_level, before_stats, after_stats);
|
|
|
|
|
|
exp_pkts = Box::new(exp_pkts.chain(clients_in_area.into_iter()
|
|
|
|
|
|
.map(move |c| {
|
|
|
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::PlayerLevelUp(level_up_pkt.clone()))))
|
|
|
|
|
|
})))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
client.character.exp += monster_stats.exp;
|
|
|
|
|
|
entity_gateway.save_character(&client.character).await;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(exp_pkts)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub async fn player_drop_item<EG>(id: ClientId,
|
|
|
pub async fn player_drop_item<EG>(id: ClientId,
|
|
|