Browse Source

lint src/common/*

pull/42/head
jake 3 years ago
parent
commit
4ce7fb2a26
  1. 13
      src/common/leveltable.rs
  2. 2
      src/common/mainloop/client.rs
  3. 2
      src/common/mainloop/interserver.rs
  4. 2
      src/common/mainloop/mod.rs
  5. 2
      src/login/character.rs
  6. 2
      src/ship/ship.rs
  7. 2
      tests/test_exp_gain.rs

13
src/common/leveltable.rs

@ -30,9 +30,8 @@ pub struct CharacterLevelTable {
table: HashMap<CharacterClass, [CharacterLevelEntry; 200]>,
}
impl CharacterLevelTable {
pub fn new() -> CharacterLevelTable {
impl Default for CharacterLevelTable {
fn default() -> CharacterLevelTable {
let file = File::open("data/char_stats.json").unwrap();
let json: Value = serde_json::from_reader(file).unwrap();
let mut table = HashMap::new();
@ -55,7 +54,7 @@ impl CharacterLevelTable {
};
let mut statlist = [CharacterLevelEntry::default(); 200];
for (i, stat) in it.1.as_array().unwrap().into_iter().enumerate() {
for (i, stat) in it.1.as_array().unwrap().iter().enumerate() {
statlist[i] = CharacterLevelEntry {
hp: stat["hp"].as_i64().unwrap() as u32,
atp: stat["atp"].as_i64().unwrap() as u32,
@ -75,7 +74,9 @@ impl CharacterLevelTable {
table: table,
}
}
}
impl CharacterLevelTable {
pub fn get_level_from_exp(&self, ch_class: CharacterClass, exp: u32) -> u32 {
if let Some(statlist) = self.table.get(&ch_class) {
statlist
@ -120,14 +121,14 @@ mod test {
use super::*;
#[test]
fn test_stat_levels() {
let table = CharacterLevelTable::new();
let table = CharacterLevelTable::default();
assert!(table.get_stats_from_exp(CharacterClass::FOmarl, 0) == (1, CharacterStats { hp: 20, atp: 13, mst: 53, evp: 35, dfp: 10, ata: 15, lck: 10 }));
assert!(table.get_stats_from_exp(CharacterClass::FOmarl, 1 << 17) == (36, CharacterStats { hp: 125, atp: 114, mst: 219, evp: 182, dfp: 42, ata: 213, lck: 10 }));
}
#[test]
fn test_levels() {
let table = CharacterLevelTable::new();
let table = CharacterLevelTable::default();
assert!(table.get_level_from_exp(CharacterClass::FOmarl, 0) == 1);
assert!(table.get_level_from_exp(CharacterClass::FOmarl, 3000) == 8);
assert!(table.get_level_from_exp(CharacterClass::FOmarl, 3200) == 9);

2
src/common/mainloop/client.rs

@ -65,7 +65,7 @@ impl PacketReceiver {
return Err(NetworkError::ClientDisconnected);
}
self.recv_buffer.extend_from_slice(&mut data[..len]);
self.recv_buffer.extend_from_slice(&data[..len]);
let mut dec_buf = {
let mut cipher = self.cipher.lock().await;

2
src/common/mainloop/interserver.rs

@ -163,7 +163,7 @@ where
warn!("interserver send failed: {:?}", err);
break;
}
if let Err(err) = socket.write_all(&payload.as_bytes()).await {
if let Err(err) = socket.write_all(payload.as_bytes()).await {
warn!("intserserver send failed: {:?}", err);
break;
}

2
src/common/mainloop/mod.rs

@ -25,7 +25,7 @@ pub fn patch_mainloop(patch_state: PatchServerState, patch_port: u16) -> Pin<Box
pub fn login_mainloop<EG: EntityGateway + 'static>(login_state: LoginServerState<EG>, login_port: u16) -> Pin<Box<dyn Future<Output = ()>>> {
let login_state = Arc::new(Mutex::new(login_state));
let client_mainloop = client_accept_mainloop(login_state.clone(), login_port);
let client_mainloop = client_accept_mainloop(login_state, login_port);
Box::pin(client_mainloop)
}

2
src/login/character.rs

@ -306,7 +306,7 @@ impl<EG: EntityGateway> CharacterServerState<EG> {
param_data: param_data,
clients: HashMap::new(),
ships: BTreeMap::new(),
level_table: CharacterLevelTable::new(),
level_table: CharacterLevelTable::default(),
auth_token: auth_token,
authenticated_ships: BTreeSet::new(),
ship_sender: BTreeMap::new(),

2
src/ship/ship.rs

@ -367,7 +367,7 @@ impl<EG: EntityGateway> ShipServerStateBuilder<EG> {
ShipServerState {
entity_gateway: self.entity_gateway.unwrap(),
clients: HashMap::new(),
level_table: CharacterLevelTable::new(),
level_table: CharacterLevelTable::default(),
name: self.name.unwrap_or_else(|| "NAMENOTSET".into()),
item_manager: items::ItemManager::default(),
quests: quests::load_quests("data/quests.toml".into()).unwrap(),

2
tests/test_exp_gain.rs

@ -83,7 +83,7 @@ async fn test_character_levels_up() {
assert!(matches!(levelup_pkt[1].1, SendShipPacket::Message(Message {msg: GameMessage::PlayerLevelUp(PlayerLevelUp {lvl: 2, ..})})));
let leveltable = CharacterLevelTable::new();
let leveltable = CharacterLevelTable::default();
let c1 = ship.clients.get(&ClientId(1)).unwrap();
assert!(leveltable.get_level_from_exp(c1.character.char_class, c1.character.exp) == 2);
}

Loading…
Cancel
Save