Skip to content

Commit 7e3c5ce

Browse files
committed
Exponential levelling config option
Hardcoded constants for now
1 parent 3e230c8 commit 7e3c5ce

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ async fn deserialize_mars_options() -> Result<MarsConfigOptions, ConfigDeseriali
9898
"webhooks.reports" => { config.reports_webhook_url = v.to_string(); },
9999
"webhooks.notes" => { config.notes_webhook_url = v.to_string(); },
100100
"webhooks.debug" => { config.debug_log_webhook_url = v.to_string(); },
101+
"enable-exponential-exp" => { if let Ok(b) = v.to_string().parse::<bool>() { config.use_exponential_exp = b; } }
101102
_ => {}
102103
}
103104
});
@@ -173,7 +174,8 @@ pub struct MarsConfigOptions {
173174
pub punishments_webhook_url: String,
174175
pub reports_webhook_url: String,
175176
pub notes_webhook_url: String,
176-
pub debug_log_webhook_url: String
177+
pub debug_log_webhook_url: String,
178+
pub use_exponential_exp: bool
177179
}
178180

179181
impl Default for MarsConfigOptions {
@@ -188,6 +190,7 @@ impl Default for MarsConfigOptions {
188190
reports_webhook_url: String::new(),
189191
notes_webhook_url: String::new(),
190192
debug_log_webhook_url: String::new(),
193+
use_exponential_exp: false
191194
}
192195
}
193196
}

src/database/models/player.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use mongodb::Collection;
66
use serde::{Serialize, Deserialize};
77
use std::collections::HashMap;
88

9-
use crate::{database::CollectionOwner, socket::{leaderboard::ScoreType, player::{player_xp_listener::{PlayerXPListener, XP_PER_LEVEL}, player_events::PlayerXPGainData}, server::server_context::{ServerContext}, event_type::EventType}};
9+
use crate::{database::CollectionOwner, socket::{leaderboard::ScoreType, player::{player_xp_listener::PlayerXPListener, player_events::PlayerXPGainData}, server::server_context::ServerContext, event_type::EventType}};
1010

1111
use super::{punishment::StaffNote, level::LevelGamemode, r#match::Match};
1212

@@ -61,7 +61,8 @@ impl Player {
6161

6262
// TODO: Multipliers
6363
pub async fn add_xp(&mut self, server_context: &mut ServerContext, raw_xp: u32, reason: &String, notify: bool, raw_only: bool) {
64-
let original_level = self.stats.get_level();
64+
let use_exponential = server_context.api_state.config.options.use_exponential_exp;
65+
let original_level = self.stats.get_level(use_exponential);
6566
let target_xp_increment = if raw_only { raw_xp } else { u32::max(PlayerXPListener::gain(raw_xp, original_level), raw_xp) };
6667
self.stats.xp += target_xp_increment;
6768

@@ -146,8 +147,12 @@ pub struct PlayerStats {
146147
}
147148

148149
impl PlayerStats {
149-
pub fn get_level(&self) -> u32 {
150-
(self.xp + XP_PER_LEVEL) / XP_PER_LEVEL
150+
pub fn get_level(&self, use_exponential: bool) -> u32 {
151+
if use_exponential {
152+
((0.0056f32 * (self.xp as f32).powf(0.715f32)) as u32) + 1
153+
} else {
154+
(self.xp + 5000) / 5000
155+
}
151156
}
152157

153158
pub fn get_score(&self, score_type: &ScoreType) -> u32 {

src/socket/player/player_xp_listener.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::{player_listener::PlayerListener, player_events::PlayerDeathData};
44

55
pub struct PlayerXPListener {}
66

7-
pub static XP_PER_LEVEL : u32 = 5000;
87
pub static XP_BEGINNER_ASSIST_MAX : u32 = 10;
98

109
pub static XP_WIN : u32 = 200;

0 commit comments

Comments
 (0)