Re-balanced items

This commit is contained in:
Joey Hines 2024-05-28 20:53:05 -06:00
parent 04cb04bdd6
commit 2000d536ff
Signed by: joeyahines
GPG Key ID: 995E531F7A569DDB
4 changed files with 46 additions and 8 deletions

View File

@ -1,6 +1,6 @@
use crate::album_manager::AlbumManager; use crate::album_manager::AlbumManager;
use crate::error::Error; use crate::error::Error;
use crate::migrations::do_migration; use crate::migrations::{CURRENT_DB_VERSION, do_migration};
use crate::rass::RaaSHandler; use crate::rass::RaaSHandler;
use config::{Config, File}; use config::{Config, File};
use j_db::database::Database; use j_db::database::Database;
@ -12,6 +12,7 @@ use serenity::prelude::TypeMapKey;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
use j_db::metadata::DBMetadata;
use structopt::StructOpt; use structopt::StructOpt;
use tokio::sync::mpsc::{channel, Receiver, Sender}; use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -87,6 +88,15 @@ impl GlobalData {
pub async fn new(args: Args, cfg: BotConfig) -> Result<Self, Error> { pub async fn new(args: Args, cfg: BotConfig) -> Result<Self, Error> {
let db = Database::new(&cfg.db_path)?; let db = Database::new(&cfg.db_path)?;
let version = db.version()?;
if version == 0 {
db.insert::<j_db::metadata::DBMetadata>( DBMetadata {
id: None,
version: CURRENT_DB_VERSION,
}).unwrap();
}
do_migration(&db); do_migration(&db);
Ok(Self { Ok(Self {

View File

@ -341,6 +341,24 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
msg.reply(&ctx.http, "You're trusty helmet regards you helmetly") msg.reply(&ctx.http, "You're trusty helmet regards you helmetly")
.await?; .await?;
} }
ItemType::TacticalNuke => {
let mut users: Vec<User> = global_data.db.filter(|_, _user: &User| {
true
}
)?.collect();
for user in &mut users {
for item in &mut user.inventory.inventory {
if item.item_type == ItemType::KillGun || item.item_type == ItemType::CancelRay || item.item_type == ItemType::CancelInsurance || item.item_type == ItemType::Helmet {
item.quantity = 0;
}
}
global_data.db.insert(user.clone())?;
}
msg.reply(&ctx.http, "I have become cancel, the canceller of worlds. https://tenor.com/view/explosion-mushroom-cloud-atomic-bomb-bomb-boom-gif-4464831").await?;
}
} }
Ok(()) Ok(())
@ -456,6 +474,10 @@ pub async fn restock_shop(ctx: &Context, global_data: &GlobalData) -> Result<(),
.inventory .inventory
.give_item(ItemType::Helmet, thread_rng().gen_range(1..=3), None); .give_item(ItemType::Helmet, thread_rng().gen_range(1..=3), None);
bot_user
.inventory
.give_item(ItemType::TacticalNuke, thread_rng().gen_range(0..=1), None);
loop { loop {
let mut dir = tokio::fs::read_dir(&global_data.cfg.nft_path).await?; let mut dir = tokio::fs::read_dir(&global_data.cfg.nft_path).await?;

View File

@ -36,6 +36,7 @@ pub enum ItemType {
KillGun, KillGun,
CancelRay, CancelRay,
Helmet, Helmet,
TacticalNuke,
} }
impl ItemType { impl ItemType {
@ -51,6 +52,7 @@ impl ItemType {
ItemType::KillGun => "Used to kill people. `!use kill gun @Austin`".to_string(), ItemType::KillGun => "Used to kill people. `!use kill gun @Austin`".to_string(),
ItemType::CancelRay => "Used to cancel people. `!use cancel ray @Austin`".to_string(), ItemType::CancelRay => "Used to cancel people. `!use cancel ray @Austin`".to_string(),
ItemType::Helmet => "Automatically used to block being killed".to_string(), ItemType::Helmet => "Automatically used to block being killed".to_string(),
ItemType::TacticalNuke => "Reset everyone back to the stone age".to_string(),
} }
} }
} }
@ -85,6 +87,8 @@ impl FromStr for ItemType {
Ok(ItemType::Helmet) Ok(ItemType::Helmet)
} else if item.starts_with("cancelray") { } else if item.starts_with("cancelray") {
Ok(ItemType::CancelRay) Ok(ItemType::CancelRay)
} else if item.starts_with("tacticalnuke") {
Ok(ItemType::TacticalNuke)
} else { } else {
Err(InventoryError::UnkownItem) Err(InventoryError::UnkownItem)
} }
@ -102,6 +106,7 @@ impl Display for ItemType {
ItemType::KillGun => "Kill Gun".to_string(), ItemType::KillGun => "Kill Gun".to_string(),
ItemType::Helmet => "Helmet".to_string(), ItemType::Helmet => "Helmet".to_string(),
ItemType::CancelRay => "Cancel Ray".to_string(), ItemType::CancelRay => "Cancel Ray".to_string(),
ItemType::TacticalNuke => "Tactical Nuke".to_string()
}; };
write!(f, "{}", name) write!(f, "{}", name)
@ -128,14 +133,15 @@ pub struct InventorySlot {
impl InventorySlot { impl InventorySlot {
pub fn value(&self) -> i64 { pub fn value(&self) -> i64 {
match self.item_type { match self.item_type {
ItemType::CancelInsurance => 500, ItemType::CancelInsurance => 10_000,
ItemType::TheConceptOfLove => 300, ItemType::TheConceptOfLove => 300,
ItemType::GoodFortune => 75, ItemType::GoodFortune => 75,
ItemType::Nft => 100, ItemType::Nft => 250,
ItemType::LicenseToBeHorny => 100, ItemType::LicenseToBeHorny => 250,
ItemType::KillGun => 1000, ItemType::KillGun => 2_000,
ItemType::Helmet => 500, ItemType::Helmet => 10_000,
ItemType::CancelRay => 1000, ItemType::CancelRay => 2_000,
ItemType::TacticalNuke => 100_000,
} }
} }

View File

@ -11,7 +11,7 @@ mod migration3_remove_img;
mod migration_4_update_random; mod migration_4_update_random;
mod migration_5_update_motivation; mod migration_5_update_motivation;
const CURRENT_DB_VERSION: u64 = 5; pub const CURRENT_DB_VERSION: u64 = 5;
#[allow(clippy::single_match)] #[allow(clippy::single_match)]
pub fn do_migration(db: &Database) { pub fn do_migration(db: &Database) {