aboutsummaryrefslogtreecommitdiff
path: root/server/src/entity
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-25 15:30:09 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-25 15:55:00 +0200
commit9587d6b4d4389f6108e2be0ff5c0f4a495ff842d (patch)
tree3cc2ea9a93de6dd39acd5396fddfbadafef471cf /server/src/entity
parent64564a25db65d7a578fee537a0cf91db1a7dbc60 (diff)
downloadhurrycurry-9587d6b4d4389f6108e2be0ff5c0f4a495ff842d.tar
hurrycurry-9587d6b4d4389f6108e2be0ff5c0f4a495ff842d.tar.bz2
hurrycurry-9587d6b4d4389f6108e2be0ff5c0f4a495ff842d.tar.zst
player class decoupled from character id
Diffstat (limited to 'server/src/entity')
-rw-r--r--server/src/entity/bot.rs11
-rw-r--r--server/src/entity/customers.rs4
2 files changed, 9 insertions, 6 deletions
diff --git a/server/src/entity/bot.rs b/server/src/entity/bot.rs
index cd505c4f..fe4d711f 100644
--- a/server/src/entity/bot.rs
+++ b/server/src/entity/bot.rs
@@ -18,7 +18,7 @@
use super::{Entity, EntityContext};
use anyhow::Result;
use hurrycurry_bot::{BotAlgo, DynBotAlgo};
-use hurrycurry_protocol::{PacketS, PlayerID};
+use hurrycurry_protocol::{PacketS, PlayerClass, PlayerID};
use log::info;
use rand::random;
use std::any::Any;
@@ -27,19 +27,19 @@ pub type DynBotDriver = BotDriver<DynBotAlgo>;
pub struct BotDriver<T> {
algo: T,
- join_data: Option<(String, i32)>,
+ join_data: Option<(String, i32, PlayerClass)>,
id: PlayerID,
interacting: bool,
left: bool,
}
impl<T: BotAlgo> BotDriver<T> {
- pub fn new(name: String, character: i32, algo: T) -> Self {
+ pub fn new(name: String, character: i32, class: PlayerClass, algo: T) -> Self {
Self {
algo,
id: PlayerID(0),
interacting: false,
- join_data: Some((name, character)),
+ join_data: Some((name, character, class)),
left: false,
}
}
@@ -49,13 +49,14 @@ impl<T: BotAlgo + Any> Entity for BotDriver<T> {
self.left
}
fn tick(&mut self, c: EntityContext<'_>) -> Result<()> {
- if let Some((name, character)) = self.join_data.take() {
+ if let Some((name, character, class)) = self.join_data.take() {
self.id = PlayerID(random()); // TODO bad code, can collide
info!("spawn {:?} ({name:?}, {character})", self.id);
c.packet_in.push_back(PacketS::Join {
name,
character,
id: Some(self.id),
+ class,
})
}
diff --git a/server/src/entity/customers.rs b/server/src/entity/customers.rs
index aaf6995f..388f7b26 100644
--- a/server/src/entity/customers.rs
+++ b/server/src/entity/customers.rs
@@ -18,6 +18,7 @@
use super::{bot::BotDriver, Entity, EntityContext};
use anyhow::Result;
use hurrycurry_bot::algos::Customer;
+use hurrycurry_protocol::PlayerClass;
use rand::random;
pub struct Customers {
@@ -53,7 +54,8 @@ impl Entity for Customers {
self.spawn_cooldown = 10. + random::<f32>() * 10.;
let bot = BotDriver::new(
"".to_string(),
- -1 - (random::<u16>() as i32),
+ random::<u16>() as i32,
+ PlayerClass::Customer,
Customer::default(),
);
self.customers.push(bot)