|
@ -17,10 +17,11 @@ use crate::common::leveltable::CharacterLevelTable; |
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
|
|
|
use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
|
|
|
use crate::entity::character::Character;
|
|
|
use crate::entity::character::Character;
|
|
|
use crate::entity::item::ItemLocation;
|
|
|
|
|
|
|
|
|
use crate::entity::item::{ItemLocation, Item};
|
|
|
use crate::login::login::get_login_status;
|
|
|
use crate::login::login::get_login_status;
|
|
|
use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType, MAX_ROOMS};
|
|
|
use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType, MAX_ROOMS};
|
|
|
use crate::ship::character::{CharacterBuilder, FullCharacterBuilder};
|
|
|
use crate::ship::character::{CharacterBuilder, FullCharacterBuilder};
|
|
|
|
|
|
use crate::ship::items;
|
|
|
use crate::ship::room;
|
|
|
use crate::ship::room;
|
|
|
|
|
|
|
|
|
pub const SHIP_PORT: u16 = 23423;
|
|
|
pub const SHIP_PORT: u16 = 23423;
|
|
@ -109,24 +110,31 @@ struct ClientState { |
|
|
settings: UserSettings,
|
|
|
settings: UserSettings,
|
|
|
character: Character,
|
|
|
character: Character,
|
|
|
session: Session,
|
|
|
session: Session,
|
|
|
|
|
|
inventory: items::Inventory,
|
|
|
|
|
|
//bank: Bank,
|
|
|
block: u32,
|
|
|
block: u32,
|
|
|
room_client_id: u32,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl ClientState {
|
|
|
impl ClientState {
|
|
|
fn new(user: UserAccount, settings: UserSettings, character: Character, session: Session) -> ClientState {
|
|
|
|
|
|
|
|
|
fn new(user: UserAccount, settings: UserSettings, character: Character, inventory: items::Inventory, /*bank: Bank,*/ session: Session) -> ClientState {
|
|
|
ClientState {
|
|
|
ClientState {
|
|
|
user: user,
|
|
|
user: user,
|
|
|
settings: settings,
|
|
|
settings: settings,
|
|
|
character: character,
|
|
|
character: character,
|
|
|
session: session,
|
|
|
session: session,
|
|
|
|
|
|
inventory: inventory,
|
|
|
|
|
|
//bank: bank,
|
|
|
block: 1,
|
|
|
block: 1,
|
|
|
room_client_id: 0,
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct ShipServerState<EG: EntityGateway> {
|
|
|
pub struct ShipServerState<EG: EntityGateway> {
|
|
|
entity_gateway: EG,
|
|
|
entity_gateway: EG,
|
|
|
clients: HashMap<ClientId, ClientState>,
|
|
|
clients: HashMap<ClientId, ClientState>,
|
|
@ -134,6 +142,7 @@ pub struct ShipServerState<EG: EntityGateway> { |
|
|
level_table: CharacterLevelTable,
|
|
|
level_table: CharacterLevelTable,
|
|
|
name: String,
|
|
|
name: String,
|
|
|
rooms: [Option<room::RoomState>; MAX_ROOMS],
|
|
|
rooms: [Option<room::RoomState>; MAX_ROOMS],
|
|
|
|
|
|
item_activator: items::ItemActivator,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> ShipServerState<EG> {
|
|
|
impl<EG: EntityGateway> ShipServerState<EG> {
|
|
@ -145,6 +154,7 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
level_table: CharacterLevelTable::new(),
|
|
|
level_table: CharacterLevelTable::new(),
|
|
|
name: "Sona-Nyl".into(),
|
|
|
name: "Sona-Nyl".into(),
|
|
|
rooms: [None; MAX_ROOMS],
|
|
|
rooms: [None; MAX_ROOMS],
|
|
|
|
|
|
item_activator: items::ItemActivator::new(),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -162,7 +172,13 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
let settings = self.entity_gateway.get_user_settings_by_user(&user)
|
|
|
let settings = self.entity_gateway.get_user_settings_by_user(&user)
|
|
|
.ok_or(ShipError::ClientNotFound(id))?;
|
|
|
.ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
|
|
|
|
|
self.clients.insert(id, ClientState::new(user, settings, character, pkt.session));
|
|
|
|
|
|
|
|
|
let items = self.entity_gateway.get_items_by_character(&character);
|
|
|
|
|
|
let (inventory, bank) = items::split_items_into_inventory_and_bank(items);
|
|
|
|
|
|
let stacked_items = items::stack_items(inventory);
|
|
|
|
|
|
let activated_items = stacked_items.into_iter().map(|item| self.item_activator.activate_item(item)).collect();
|
|
|
|
|
|
let inventory = items::Inventory::new(activated_items);
|
|
|
|
|
|
|
|
|
|
|
|
self.clients.insert(id, ClientState::new(user, settings, character, inventory, pkt.session));
|
|
|
vec![SendShipPacket::LoginResponse(response), SendShipPacket::ShipBlockList(ShipBlockList::new(&self.name, 3))]
|
|
|
vec![SendShipPacket::LoginResponse(response), SendShipPacket::ShipBlockList(ShipBlockList::new(&self.name, 3))]
|
|
|
},
|
|
|
},
|
|
|
Err(err) => {
|
|
|
Err(err) => {
|
|
@ -177,34 +193,15 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
|
|
|
|
|
let (level, stats) = self.level_table.get_stats_from_exp(character::Class::from(client.character.character.ch_class), client.character.character.exp);
|
|
|
let (level, stats) = self.level_table.get_stats_from_exp(character::Class::from(client.character.character.ch_class), client.character.character.exp);
|
|
|
|
|
|
|
|
|
let items = self.entity_gateway.get_items_by_character(&client.character);
|
|
|
|
|
|
let (inventory, inv_len) = items
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.take(30)
|
|
|
|
|
|
.fold(([character::InventoryItem::default(); 30], 0), |(mut inv, len), item| {
|
|
|
|
|
|
let index = {
|
|
|
|
|
|
if let ItemLocation::Inventory{index, .. } = item.location {
|
|
|
|
|
|
index
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
panic!("inventory item that isnt in inventory???");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
let bytes = item.item.as_bytes();
|
|
|
|
|
|
inv[index].data1.copy_from_slice(&bytes[0..12]);
|
|
|
|
|
|
inv[index].item_id = item.id;
|
|
|
|
|
|
(inv, len+1)
|
|
|
|
|
|
});
|
|
|
|
|
|
let fc = FullCharacterBuilder::new()
|
|
|
let fc = FullCharacterBuilder::new()
|
|
|
.character(&CharacterBuilder::new()
|
|
|
.character(&CharacterBuilder::new()
|
|
|
.character(&client.character.character)
|
|
|
.character(&client.character.character)
|
|
|
.stats(&stats)
|
|
|
.stats(&stats)
|
|
|
.level(level - 1)
|
|
|
.level(level - 1)
|
|
|
.build())
|
|
|
.build())
|
|
|
.inventory(&inventory, inv_len)
|
|
|
|
|
|
|
|
|
.inventory(&client.inventory)
|
|
|
.key_config(&client.settings.settings.key_config)
|
|
|
.key_config(&client.settings.settings.key_config)
|
|
|
.joystick_config(&client.settings.settings.joystick_config)
|
|
|
.joystick_config(&client.settings.settings.joystick_config)
|
|
|
//.team_config(&joystick_config)
|
|
|
|
|
|
.build();
|
|
|
.build();
|
|
|
|
|
|
|
|
|
Ok(vec![
|
|
|
Ok(vec![
|
|
|