Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion game/src/packets/from_client/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Message<RequestRestart> for PlayerClient {
let p = CharSelectionInfo::new(&user_name.clone(), session_id, &self.controller, chars)?;
let player = self.try_get_selected_char()?.clone(); // we clone it to avoid borrow checker issues with reference to self
self.controller.broadcast_packet_with_filter(
DeleteObject::new(player.get_id())?,
DeleteObject::new(player.get_object_id())?,
Some(Box::new(move |acc, _| !acc.eq(&user_name))),
);
self.send_packet(RestartResponse::ok()?).await?;
Expand Down
2 changes: 1 addition & 1 deletion game/src/packets/to_client/char_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl CharInfo {
inst.buffer.write_i32(p.get_z())?; // Confirmed
inst.buffer
.write_i32(p.get_vehicle_object_id().unwrap_or(0))?; // Confirmed
inst.buffer.write_i32(p.char_model.id)?; // Confirmed
inst.buffer.write_i32(p.get_object_id())?; // Confirmed
inst.buffer
.write_c_utf16le_string(Some(p.get_visible_name()))?; // Confirmed
inst.buffer.write_i16(p.char_model.race_id)?; // Confirmed
Expand Down
2 changes: 1 addition & 1 deletion game/src/packets/to_client/char_move_to_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl CharMoveToLocation {
buffer: SendablePacketBuffer::new(),
};
inst.buffer.write(Self::PACKET_ID)?;
inst.buffer.write_i32(p.get_id())?; // 1-7 increase force, level
inst.buffer.write_i32(p.get_object_id())?; // 1-7 increase force, level

// Target position
inst.buffer.write_i32(target_x)?;
Expand Down
9 changes: 5 additions & 4 deletions game/src/packets/to_client/char_selected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl CharSelected {
inst.buffer.write(Self::PACKET_ID)?;
inst.buffer
.write_c_utf16le_string(Some(&player.char_model.name))?;
inst.buffer.write_i32(player.char_model.id)?;
inst.buffer.write_i32(player.get_object_id())?;
inst.buffer
.write_c_utf16le_string(player.char_model.title.as_deref())?;
inst.buffer.write_i32(session_id)?;
Expand Down Expand Up @@ -61,6 +61,7 @@ mod tests {
use entities::entities::character;
use l2_core::config::traits::ConfigDirLoader;
use l2_core::data::char_template::ClassTemplates;
use l2_core::id_factory::ObjectId;

#[test]
fn test_char_selected() {
Expand All @@ -81,16 +82,16 @@ mod tests {
x: -90939,
y: 248_138,
z: -3563,
id: 268_476_204,
..Default::default()
};
let templates = ClassTemplates::load();
let temp = templates.try_get_template(inst.class_id).unwrap().clone();
let char = Player::new(inst, vec![], temp);
let mut char = Player::new(inst, vec![], temp);
char.object_id = ObjectId::new(268_476_207);
let mut packet = CharSelected::new(&char, 9998, 286).unwrap();
assert_eq!(
[
11, 65, 0, 100, 0, 101, 0, 108, 0, 97, 0, 110, 0, 116, 0, 101, 0, 0, 0, 44,
11, 65, 0, 100, 0, 101, 0, 108, 0, 97, 0, 110, 0, 116, 0, 101, 0, 0, 0, 47,
159, 0, 16, 0, 0, 14, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10,
0, 0, 0, 1, 0, 0, 0, 197, 156, 254, 255, 74, 201, 3, 0, 21, 242, 255, 255, 0, 0, 0,
0, 0, 128, 88, 64, 0, 0, 0, 0, 0, 128, 77, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
11 changes: 6 additions & 5 deletions game/src/packets/to_client/extended/equipped_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl EquippedItems {
};
inst.buffer.write(Self::PACKET_ID)?;
inst.buffer.write_u16(Self::EX_PACKET_ID)?;
inst.buffer.write_i32(p.char_model.id)?;
inst.buffer.write_i32(p.get_object_id())?;
let mut bitmask = BitMask::new(40); //5 bytes, 50 bits
let slots = InventorySlot::iter();
let num_slots = slots.len();
Expand Down Expand Up @@ -62,18 +62,18 @@ mod tests {
use l2_core::shared_packets::common::SendablePacket;
use l2_core::traits::ServerConfig;
use std::sync::Arc;
use l2_core::id_factory::ObjectId;
use test_utils::utils::get_test_db;
#[tokio::test]
async fn test_equipped_items() {
let db_pool = get_test_db().await;
let user = user_factory(&db_pool, |u| u).await;
let mut char = char_factory(&db_pool, |mut m| {
let char = char_factory(&db_pool, |mut m| {
m.name = "Adelante".to_string();
m.user_id = user.id;
m
})
.await;
char.id = 268_476_204;
let cfg = Arc::new(GSServerConfig::from_string(include_str!(
"../../../../config/game.yaml"
)));
Expand All @@ -82,11 +82,12 @@ mod tests {
.class_templates
.try_get_template(Class::try_from(char.class_id).unwrap())
.unwrap();
let player = Player::new(char, vec![], template.clone());
let mut player = Player::new(char, vec![], template.clone());
player.object_id = ObjectId::new(268_476_206);
let p = EquippedItems::new(&player, true).unwrap();
assert_eq!(
[
254, 86, 1, 44, 159, 0, 16, 33, 0, 255, 255, 255, 255, 128, 22, 0, 0, 0, 0, 0, 0,
254, 86, 1, 46, 159, 0, 16, 33, 0, 255, 255, 255, 255, 128, 22, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
11 changes: 6 additions & 5 deletions game/src/packets/to_client/extended/inventory_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl InventoryWeight {
};
inst.buffer.write(Self::PACKET_ID)?;
inst.buffer.write_u16(Self::EX_PACKET_ID)?;
inst.buffer.write_i32(p.char_model.id)?;
inst.buffer.write_i32(p.get_object_id())?;
inst.buffer.write_i32(p.inventory.get_current_load())?;
inst.buffer.write_i32(p.inventory.get_max_load())?;
Ok(inst)
Expand All @@ -33,18 +33,18 @@ mod tests {
use l2_core::shared_packets::common::SendablePacket;
use l2_core::traits::ServerConfig;
use std::sync::Arc;
use l2_core::id_factory::ObjectId;
use test_utils::utils::get_test_db;
#[tokio::test]
async fn test_inventory_weight() {
let db_pool = get_test_db().await;
let user = user_factory(&db_pool, |u| u).await;
let mut char = char_factory(&db_pool, |mut m| {
let char = char_factory(&db_pool, |mut m| {
m.name = "Adelante".to_string();
m.user_id = user.id;
m
})
.await;
char.id = 268_476_204;
let cfg = Arc::new(GSServerConfig::from_string(include_str!(
"../../../../config/game.yaml"
)));
Expand All @@ -53,10 +53,11 @@ mod tests {
.class_templates
.try_get_template(Class::try_from(char.class_id).unwrap())
.unwrap();
let player = Player::new(char, vec![], template.clone());
let mut player = Player::new(char, vec![], template.clone());
player.object_id = ObjectId::new(268_476_205);
let p = InventoryWeight::new(&player).unwrap();
assert_eq!(
[254, 102, 1, 44, 159, 0, 16, 0, 0, 0, 0, 108, 24, 3, 0],
[254, 102, 1, 45, 159, 0, 16, 0, 0, 0, 0, 108, 24, 3, 0],
p.get_buffer().get_data_mut(false)[2..]
);
}
Expand Down
9 changes: 5 additions & 4 deletions game/src/packets/to_client/extended/premium_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl PremiumState {
let mut buffer = SendablePacketBuffer::new();
buffer.write(Self::PACKET_ID)?;
buffer.write_u16(Self::EX_PACKET_ID)?;
buffer.write_i32(p.char_model.id)?;
buffer.write_i32(p.get_object_id())?;
buffer.write(p.has_premium())?;
Ok(Self { buffer })
}
Expand All @@ -30,6 +30,7 @@ mod test {
use l2_core::shared_packets::common::SendablePacket;
use l2_core::traits::ServerConfig;
use std::sync::Arc;
use l2_core::id_factory::ObjectId;
use test_utils::utils::get_test_db;
use super::*;

Expand All @@ -43,7 +44,6 @@ mod test {
m
})
.await;
char.id = 268_476_204;
let cfg = Arc::new(GSServerConfig::from_string(include_str!(
"../../../../config/game.yaml"
)));
Expand All @@ -52,10 +52,11 @@ mod test {
.class_templates
.try_get_template(Class::try_from(char.class_id).unwrap())
.unwrap();
let player = Player::new(char, vec![], template.clone());
let mut player = Player::new(char, vec![], template.clone());
player.object_id = ObjectId::new(268_476_209);
let p = PremiumState::new(&player).unwrap();
assert_eq!(
[254, 218, 0, 44, 159, 0, 16, 0],
[254, 218, 0, 49, 159, 0, 16, 0],
p.get_buffer().get_data_mut(false)[2..]
);
}
Expand Down
7 changes: 4 additions & 3 deletions game/src/packets/to_client/extended/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Rotation {
};
inst.buffer.write(Self::PACKET_ID)?;
inst.buffer.write_u16(Self::EX_PACKET_ID)?;
inst.buffer.write_i32(player.char_model.id)?;
inst.buffer.write_i32(player.get_object_id())?;
inst.buffer.write_i32(player.get_location().heading)?;
Ok(inst)
}
Expand All @@ -35,6 +35,7 @@ mod tests {
use l2_core::shared_packets::common::SendablePacket;
use l2_core::traits::ServerConfig;
use std::sync::Arc;
use l2_core::id_factory::ObjectId;
use test_utils::utils::get_test_db;
#[tokio::test]
async fn test_rotation_packet() {
Expand All @@ -46,7 +47,6 @@ mod tests {
m
})
.await;
char.id = 268_476_204;
let cfg = Arc::new(GSServerConfig::from_string(include_str!(
"../../../../config/game.yaml"
)));
Expand All @@ -56,10 +56,11 @@ mod tests {
.try_get_template(Class::try_from(char.class_id).unwrap())
.unwrap();
let mut player = Player::new(char, vec![], template.clone());
player.object_id = ObjectId::new(268_476_210);
player.set_location_heading(33897);
let p = Rotation::new(&player).unwrap();
assert_eq!(
[0, 254, 194, 0, 44, 159, 0, 16, 105, 132, 0, 0],
[0, 254, 194, 0, 50, 159, 0, 16, 105, 132, 0, 0],
p.get_buffer().get_data_mut(false)[1..]
);
}
Expand Down
2 changes: 1 addition & 1 deletion game/src/packets/to_client/move_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl MoveTo {
pub fn new(p: &Player, loc: &Location) -> anyhow::Result<Self> {
let mut buffer = SendablePacketBuffer::new();
buffer.write(Self::PACKET_ID)?;
buffer.write_i32(p.char_model.id)?;
buffer.write_i32(p.get_object_id())?;
let p_loc = p.get_location();
buffer.write_i32(p_loc.x)?;
buffer.write_i32(p_loc.y)?;
Expand Down
3 changes: 2 additions & 1 deletion game/src/packets/to_client/quest_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod tests {
use l2_core::traits::ServerConfig;
use std::sync::Arc;
use sea_orm::JsonValue;
use l2_core::id_factory::ObjectId;
use test_utils::utils::get_test_db;
#[tokio::test]
async fn test_quest_list_packet() {
Expand All @@ -59,7 +60,6 @@ mod tests {
m
})
.await;
char.id = 268_476_204;
let cfg = Arc::new(GSServerConfig::from_string(include_str!(
"../../../../config/game.yaml"
)));
Expand All @@ -69,6 +69,7 @@ mod tests {
.try_get_template(Class::try_from(char.class_id).unwrap())
.unwrap();
let mut player = Player::new(char, vec![], template.clone());
player.object_id = ObjectId::new(268_476_208);
player.quests.push(Quest {
model: quest::Model {
char_id: player.char_model.id,
Expand Down
2 changes: 1 addition & 1 deletion game/src/packets/to_client/relation_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl RelationChangedBuilder {
pub fn add_relation(mut self, player: &Player, relation: u32, auto_attackable: bool) -> Self {
if !player.is_invisible() {
let relation = Relation {
obj_id: player.char_model.id,
obj_id: player.get_object_id(),
rel: relation,
auto_attackable,
reputation: player.char_model.reputation,
Expand Down
1 change: 0 additions & 1 deletion game/src/packets/to_client/skill_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ mod test {
is_female: true,
delete_at: None,
user_id: 1,
id: 268_476_204,
..Default::default()
};
let templates = ClassTemplates::load();
Expand Down
11 changes: 6 additions & 5 deletions game/src/packets/to_client/user_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl UserInfo {
title: String::new(),
};
inst.buffer.write(Self::PACKET_ID)?;
inst.buffer.write_i32(player.char_model.id)?;
inst.buffer.write_i32(player.get_object_id())?;
inst.buffer.write_u32(inst.block_size)?;
inst.buffer.write_u16(23u16)?;
inst.buffer.write_bytes(inst.mask.flags())?;
Expand Down Expand Up @@ -425,7 +425,7 @@ impl UserInfo {
let mut relation = 0;
if let Some(pt) = p.party.as_ref() {
relation |= 0x08;
if pt.get_leader_id() == p.char_model.id {
if pt.get_leader_id() == p.get_object_id() {
relation |= 0x10;
}
}
Expand All @@ -451,6 +451,7 @@ mod tests {
use sea_orm::JsonValue;
use std::str::FromStr;
use std::sync::Arc;
use l2_core::id_factory::ObjectId;
use test_utils::utils::get_test_db;

#[tokio::test]
Expand Down Expand Up @@ -483,7 +484,6 @@ mod tests {
})
.await;

char.id = 268_476_204;
let cfg = Arc::new(GSServerConfig::from_string(include_str!(
"../../../../config/game.yaml"
)));
Expand All @@ -492,7 +492,8 @@ mod tests {
.class_templates
.try_get_template(Class::try_from(char.class_id).unwrap())
.unwrap();
let player = Player::new(char, vec![], template.clone());
let mut player = Player::new(char, vec![], template.clone());
player.object_id = ObjectId::new(268_476_204);
let p = UserInfo::new(&player, UserInfoType::all(), &controller)
.await
.unwrap();
Expand All @@ -516,7 +517,7 @@ mod tests {
assert_eq!(
[
50, //packet id
44, 159, 0, 16, //cjar model id
44, 159, 0, 16, //char model id
137, 1, 0, 0, //block size
23, 0, //23
255, 255, 254, //flags
Expand Down
3 changes: 1 addition & 2 deletions l2-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ serde_json.workspace = true
kameo.workspace = true

[dev-dependencies]
test-utils = { path = "../test-utils" }
ntest.workspace = true
test-utils = { path = "../test-utils" }
9 changes: 3 additions & 6 deletions l2-core/src/data/char_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,9 @@ impl CharTemplate {
target.base_class_id = self.class_id as i8;
target.access_level = 0;
target.race_id = self.class_id.get_class().race as i8;
let base_max_hp =
self.get_base_max_parameter(target.level, &CreatureParameter::HP)?;
let base_max_mp =
self.get_base_max_parameter(target.level, &CreatureParameter::MP)?;
let base_max_cp =
self.get_base_max_parameter(target.level, &CreatureParameter::CP)?;
let base_max_hp = self.get_base_max_parameter(target.level, &CreatureParameter::HP)?;
let base_max_mp = self.get_base_max_parameter(target.level, &CreatureParameter::MP)?;
let base_max_cp = self.get_base_max_parameter(target.level, &CreatureParameter::CP)?;
let base_con = base_stats.con_bonus(self.static_data.base_con)?;
let base_men = base_stats.con_bonus(self.static_data.base_men)?;
target.max_hp = f64::from(base_max_hp) * base_con;
Expand Down
Loading
Loading