Move XP generation constant values to database and increase apparent level comparison value
Badgey Deployment / build (push) Successful in 6m11s
Details
Badgey Deployment / build (push) Successful in 6m11s
Details
This commit is contained in:
parent
cd391d7475
commit
a9feba9845
|
|
@ -27,6 +27,9 @@ jobs:
|
||||||
POSTGRES_USER: ${{ vars.POSTGRES_USER }}
|
POSTGRES_USER: ${{ vars.POSTGRES_USER }}
|
||||||
POSTGRES_DATABASE_NAME: ${{ vars.POSTGRES_DATABASE_NAME }}
|
POSTGRES_DATABASE_NAME: ${{ vars.POSTGRES_DATABASE_NAME }}
|
||||||
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
|
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
|
||||||
|
WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }}
|
||||||
|
DOGPICS_API_KEY: ${{ secrets.DOGPICS_API_KEY }}
|
||||||
|
CATPICS_API_KEY: ${{ secrets.CATPICS_API_KEY }}
|
||||||
- name: Seed SSH key for deploy
|
- name: Seed SSH key for deploy
|
||||||
run: echo "${{ secrets.DEPLOY_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa && chmod 0600 ~/.ssh/id_rsa
|
run: echo "${{ secrets.DEPLOY_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa && chmod 0600 ~/.ssh/id_rsa
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
<component name="SqlDialectMappings">
|
<component name="SqlDialectMappings">
|
||||||
<file url="file://$PROJECT_DIR$/migrations/2023-09-20-230922_extend userinfo to include XP/up.sql" dialect="PostgreSQL" />
|
<file url="file://$PROJECT_DIR$/migrations/2023-09-20-230922_extend userinfo to include XP/up.sql" dialect="PostgreSQL" />
|
||||||
<file url="file://$PROJECT_DIR$/migrations/2023-09-26-215927_add custom responses table/up.sql" dialect="PostgreSQL" />
|
<file url="file://$PROJECT_DIR$/migrations/2023-09-26-215927_add custom responses table/up.sql" dialect="PostgreSQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/migrations/2023-11-20-091909_add constant values to each rank track for XP generation control/down.sql" dialect="PostgreSQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/migrations/2023-11-20-091909_add constant values to each rank track for XP generation control/up.sql" dialect="PostgreSQL" />
|
||||||
<file url="PROJECT" dialect="SQLite" />
|
<file url="PROJECT" dialect="SQLite" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
"weather": {
|
"weather": {
|
||||||
"source_uri": "https://api.weatherapi.com/v1",
|
"source_uri": "https://api.weatherapi.com/v1",
|
||||||
"cache_mode": "NoCache",
|
"cache_mode": "NoCache",
|
||||||
"api_key": "70aacb9af931438a957215406211210"
|
"api_key": "#{WEATHER_API_KEY}#"
|
||||||
},
|
},
|
||||||
"frog_tips": {
|
"frog_tips": {
|
||||||
"source_uri": "https://frog.tips/api/1/tips/",
|
"source_uri": "https://frog.tips/api/1/tips/",
|
||||||
|
|
@ -27,13 +27,13 @@
|
||||||
"source_uri": "https://api.thedogapi.com/v1/images/search?limit=100&order=RAND",
|
"source_uri": "https://api.thedogapi.com/v1/images/search?limit=100&order=RAND",
|
||||||
"cache_name": "dog_pics",
|
"cache_name": "dog_pics",
|
||||||
"cache_mode": "Cache",
|
"cache_mode": "Cache",
|
||||||
"api_key": "live_RRrRUsdmRIpKUefuwOwuAV1nab7Gt8GqyvIqPGCgLAbpLHGdyStbGj9Xc67inYMt"
|
"api_key": "#{DOGPICS_API_KEY}#"
|
||||||
},
|
},
|
||||||
"cat_pics": {
|
"cat_pics": {
|
||||||
"source_uri": "https://api.thecatapi.com/v1/images/search?limit=100&order=RAND",
|
"source_uri": "https://api.thecatapi.com/v1/images/search?limit=100&order=RAND",
|
||||||
"cache_name": "cat_pics",
|
"cache_name": "cat_pics",
|
||||||
"cache_mode": "Cache",
|
"cache_mode": "Cache",
|
||||||
"api_key": "live_nvupPQbrXjHy8jsZJ1stp72fzsRLR8jQby8IR3l9yMngqAU9gcTEV8RA0OOiK8zP"
|
"api_key": "#{CATPICS_API_KEY}#"
|
||||||
},
|
},
|
||||||
"dad_jokes": {
|
"dad_jokes": {
|
||||||
"source_uri": "https://icanhazdadjoke.com/search?limit=30",
|
"source_uri": "https://icanhazdadjoke.com/search?limit=30",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE tracks
|
||||||
|
DROP COLUMN IF EXISTS xp_level_constant,
|
||||||
|
DROP COLUMN IF EXISTS xp_award_range_min,
|
||||||
|
DROP COLUMN IF EXISTS xp_award_range_max;
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE tracks
|
||||||
|
ADD COLUMN xp_level_constant FLOAT NOT NULL DEFAULT 0.25,
|
||||||
|
ADD COLUMN xp_award_range_min INT NOT NULL DEFAULT 1,
|
||||||
|
ADD COLUMN xp_award_range_max INT NOT NULL DEFAULT 30;
|
||||||
|
|
@ -102,7 +102,7 @@ async fn rank(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
|
||||||
|
|
||||||
let current_rank = Rank::get_rank_for_level(db, &xp.user_current_level, &xp.rank_track).unwrap_or(Rank::new());
|
let current_rank = Rank::get_rank_for_level(db, &xp.user_current_level, &xp.rank_track).unwrap_or(Rank::new());
|
||||||
|
|
||||||
let next_level_xp = xp.get_xp_to_next_level();
|
let next_level_xp = xp.get_xp_to_next_level(&db);
|
||||||
let next_rank_xp = xp.get_xp_to_next_rank(&db).unwrap_or(0);
|
let next_rank_xp = xp.get_xp_to_next_rank(&db).unwrap_or(0);
|
||||||
|
|
||||||
let mut response = format!("You're currently {}. You need {} more XP to get to the next level", RoleId::from(current_rank.role_id as u64).mention(), next_level_xp);
|
let mut response = format!("You're currently {}. You need {} more XP to get to the next level", RoleId::from(current_rank.role_id as u64).mention(), next_level_xp);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ impl BadgeyHandler {
|
||||||
if valid {
|
if valid {
|
||||||
xp.last_given_xp = Some(chrono::Utc::now().timestamp());
|
xp.last_given_xp = Some(chrono::Utc::now().timestamp());
|
||||||
xp.xp_value += &xp_reward;
|
xp.xp_value += &xp_reward;
|
||||||
let calculated_level = xp.get_level_from_xp();
|
let calculated_level = xp.get_level_from_xp(&db, None);
|
||||||
|
|
||||||
if xp.freeze_rank.is_some() {
|
if xp.freeze_rank.is_some() {
|
||||||
xp.user_current_level = calculated_level.clone();
|
xp.user_current_level = calculated_level.clone();
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,14 @@ pub struct Rank {
|
||||||
pub rank_name: String,
|
pub rank_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Selectable, Identifiable, Debug, Clone)]
|
#[derive(Queryable, Selectable, Identifiable, Debug, Clone, Default)]
|
||||||
#[diesel(primary_key(track_id))]
|
#[diesel(primary_key(track_id))]
|
||||||
pub struct Track {
|
pub struct Track {
|
||||||
pub track_id: i64,
|
pub track_id: i64,
|
||||||
pub track_name: String,
|
pub track_name: String,
|
||||||
|
pub xp_level_constant: f64,
|
||||||
|
pub xp_award_range_min: i32,
|
||||||
|
pub xp_award_range_max: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Xp {
|
impl Xp {
|
||||||
|
|
@ -76,22 +79,28 @@ impl Xp {
|
||||||
.map_err(|e| ManifoldError::from(e))
|
.map_err(|e| ManifoldError::from(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_level_from_xp(&self) -> i64 {
|
pub fn get_level_from_xp(&self, conn: &Db, constant: Option<&f64>) -> i64 {
|
||||||
(0.125 * f64::sqrt(self.xp_value.clone() as f64)) as i64
|
let c = match constant {
|
||||||
|
Some(c) => *c,
|
||||||
|
None => Track::get_track_by_id(conn, &self.rank_track).unwrap_or_default().xp_level_constant
|
||||||
|
};
|
||||||
|
(c * f64::sqrt(self.xp_value.clone() as f64)) as i64
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_xp_to_next_level(&self) -> i64 {
|
pub fn get_xp_to_next_level(&self, conn: &Db) -> i64 {
|
||||||
let current_level = self.get_level_from_xp();
|
let constant = Track::get_track_by_id(conn, &self.rank_track).unwrap_or_default().xp_level_constant;
|
||||||
|
let current_level = self.get_level_from_xp(conn, Some(&constant));
|
||||||
let target_level = current_level + 1;
|
let target_level = current_level + 1;
|
||||||
|
|
||||||
(target_level as f32 / 0.125).powi(2) as i64 - &self.xp_value
|
(target_level as f64 / constant).powi(2) as i64 - &self.xp_value
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_xp_to_next_rank(&self, conn: &Db) -> ManifoldResult<i64> {
|
pub fn get_xp_to_next_rank(&self, conn: &Db) -> ManifoldResult<i64> {
|
||||||
let current_level = self.get_level_from_xp();
|
let constant = Track::get_track_by_id(conn, &self.rank_track)?.xp_level_constant;
|
||||||
|
let current_level = self.get_level_from_xp(conn, Some(&constant));
|
||||||
let target_level = Rank::get_next_rank_for_level(conn, ¤t_level, &self.rank_track)?.required_level;
|
let target_level = Rank::get_next_rank_for_level(conn, ¤t_level, &self.rank_track)?.required_level;
|
||||||
|
|
||||||
Ok((target_level as f32 / 0.125).powi(2) as i64 - &self.xp_value)
|
Ok((target_level as f64 / constant).powi(2) as i64 - &self.xp_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_timeout(value: &Option<i64>, timeout: &i64) -> ManifoldResult<()> {
|
pub fn check_timeout(value: &Option<i64>, timeout: &i64) -> ManifoldResult<()> {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ diesel::table! {
|
||||||
track_id -> Int8,
|
track_id -> Int8,
|
||||||
#[max_length = 128]
|
#[max_length = 128]
|
||||||
track_name -> Varchar,
|
track_name -> Varchar,
|
||||||
|
xp_level_constant -> Float8,
|
||||||
|
xp_award_range_min -> Int4,
|
||||||
|
xp_award_range_max -> Int4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue