framework mapdata

This commit is contained in:
Moritz Roßbacher 2023-10-23 20:53:44 +02:00
parent b0a712bd6e
commit 05814dd0e7
9 changed files with 215 additions and 34 deletions

2
.idea/ZMP-bot.iml generated
View file

@ -3,6 +3,8 @@
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/commands/T/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/src/commands/T/target" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />

View file

@ -3,15 +3,13 @@ use crate::commands::lfg::Difficulty::Normal;
use crate::commands::lfg::Map::*; use crate::commands::lfg::Map::*;
use crate::commands::lfg::Mode::*; use crate::commands::lfg::Mode::*;
//from main.rs //from main.rs
use crate::Context; use crate::{Context, Error};
use crate::Error;
// //
use serenity::model::id::RoleId; use serenity::model::id::{RoleId};
use serenity::model::mention::Mention; use serenity::model::mention::Mention;
use serenity::model::mention::Mention::Role; use serenity::model::mention::Mention::{Role};
use serenity::prelude::Mentionable;
#[derive(Debug, poise::ChoiceParameter)] #[derive(Debug, poise::ChoiceParameter, PartialEq)]
pub enum Map { pub enum Map {
#[name = "Dead End"] #[name = "Dead End"]
DeadEnd, DeadEnd,
@ -41,7 +39,9 @@ pub enum Difficulty {
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn lfg( pub(crate) async fn lfg(
ctx: Context<'_>, ctx: Context<'_>,
#[rename = "map"] map: Map,
#[rename = "map"]
map: Map,
#[description = "Normal"] #[description = "Normal"]
#[rename = "difficulty"] #[rename = "difficulty"]

View file

@ -1 +1,3 @@
pub(crate) mod lfg; pub(crate) mod lfg;
pub(crate) mod round;
pub(crate) mod zombies;

10
src/commands/round.rs Normal file
View file

@ -0,0 +1,10 @@
use std::convert::Into;
use crate::{Context, Error};
use crate::commands::zombies::zombies::*;
#[poise::command(slash_command)]
pub(crate) async fn round(
ctx: Context<'_>
) -> Result<(), Error> {
Ok(())
}

View file

@ -0,0 +1,46 @@
use crate::commands::zombies::gear::ArmorMaterial::Leather;
use crate::commands::zombies::gear::ArmorPiece::Leggings;
use crate::commands::zombies::gear::Weapon::{Axe, Sword};
use crate::commands::zombies::gear::WeaponMaterial::{Diamond, Gold, Wood};
#[derive(Debug)]
pub enum ArmorPiece {
None,
Helmet(ArmorMaterial),
Chestplate(ArmorMaterial),
Leggings(ArmorMaterial),
Boots(ArmorMaterial)
}
#[derive(Debug)]
pub enum WeaponMaterial {
Wood,
Stone,
Gold,
Iron,
Diamond
}
#[derive(Debug)]
pub enum ArmorMaterial {
Leather,
Gold,
Chainmail,
Iron,
Diamond
}
#[derive(Debug)]
pub enum Weapon {
None,
Axe(WeaponMaterial),
Sword(WeaponMaterial)
}
pub const NO_WEAPON:Weapon = Weapon::None;
pub const WOODEN_AXE:Weapon = Axe(Wood);
pub const DIAMOND_AXE:Weapon = Axe(Diamond);
pub const GOLD_SWORD:Weapon = Sword(Gold);
pub const DIAMOND_SWORD:Weapon = Sword(Diamond);
pub const NO_HELMET:ArmorPiece = ArmorPiece::None;
pub const NO_CHESTPLATE:ArmorPiece = ArmorPiece::None;
pub const NO_LEGGINGS:ArmorPiece = ArmorPiece::None;
pub const NO_BOOTS:ArmorPiece = ArmorPiece::None;
pub const LEATHER_LEGGINGS:ArmorPiece = Leggings(Leather);

View file

@ -0,0 +1,3 @@
pub mod zombies;
pub mod gear;
pub(crate) mod rounds;

View file

@ -0,0 +1,53 @@
use crate::commands::zombies::rounds::Round::*;
use crate::commands::zombies::rounds::Wave::*;
use crate::commands::zombies::zombies::*;
/*type Wave = Vec<Horde>;
type Round = Vec<Wave>;
fn bad_blood_round1() -> Round {
let mut round:Round = Vec::with_capacity(2);
let mut wave1:Wave = Vec::with_capacity(2);
let mut wave2:Wave = Vec::with_capacity(1);
wave1.push(Horde {
zombie: BB_Z_1,
count: 4
});
wave2.push(Horde {
zombie: BB_Z_1,
count: 5
});
round.push(wave1);
round.push(wave2);
round
}*/
pub enum Wave {
Wave1horde([Horde;1]),
Wave2hordes([Horde;2]),
Wave3hordes([Horde;3]),
Wave4hordes([Horde;4]),
Wave5hordes([Horde;5]),
Wave6hordes([Horde;6]),
Wave7hordes([Horde;7])
}
pub enum Round {
Round2Waves([Wave;2]),
Round3Waves([Wave;3]),
Round4Waves([Wave;4]),
Round5Waves([Wave;5]),
Round6Waves([Wave;6]),
Round7Waves([Wave;7])
}
const DE:[Round;30] = [
Round2Waves([
Wave1horde([
Horde { zombie: BB_Z_1, count: 4 }
]),
Wave1horde([
Horde { zombie: BB_Z_1, count: 5 }
])
]);30
];
/*fn t() {
DE.get(2)
}*/

View file

@ -0,0 +1,27 @@
use crate::commands::zombies::gear::*;
use crate::{Context, Error};
#[derive(Debug)]
pub struct Zombie {
id: u16,
damage: u8,
health: u16,
speed: f32,
armor: [ArmorPiece;4],
weapon: Weapon,
follow_range: u8
}
#[derive(Debug)]
pub struct Horde {
pub zombie: Zombie,
pub count: u8
}
pub const BB_Z_1: Zombie = Zombie {
id: 1,
damage: 3,
health: 20,
speed: 0.25,
armor: [NO_HELMET,NO_CHESTPLATE,LEATHER_LEGGINGS,NO_BOOTS],
weapon: WOODEN_AXE,
follow_range: 35
};

View file

@ -1,22 +1,31 @@
mod commands; mod commands;
use poise::serenity_prelude as serenity; use poise::{async_trait, Event, serenity_prelude as serenity};
use serenity::model::id::UserId; use serenity::model::id::UserId;
use std::collections::HashSet; use std::collections::HashSet;
use std::convert::Into; use std::convert::Into;
use serenity::client::EventHandler;
use crate::commands::round::round;
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>; type Context<'a> = poise::Context<'a, Data, Error>;
// User data, which is stored and accessible in all command invocations
pub struct Data {} pub struct Data {}
struct ReadyHandler;
#[async_trait]
impl EventHandler for ReadyHandler {
async fn ready(&self, _: poise::serenity_prelude::Context, ready: poise::serenity_prelude::Ready) {
println!("{} is connected!", ready.user.id);
}
}
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let mut owners = HashSet::new(); let options = poise::FrameworkOptions {
owners.insert(UserId(449579075531440128_u64)); commands: vec![
let framework = poise::Framework::builder() commands::lfg::lfg(),
.options(poise::FrameworkOptions { ],
commands: vec![commands::lfg::lfg()],
prefix_options: poise::PrefixFrameworkOptions { prefix_options: poise::PrefixFrameworkOptions {
prefix: Some("~".into()), prefix: Some("~".into()),
..Default::default() ..Default::default()
@ -35,13 +44,28 @@ async fn main() {
} }
}) })
}, },
owners, owners: {
HashSet::from([UserId(449579075531440128_u64)])
},
event_handler: |_ctx, event, _framework, _data| {
Box::pin(event_handler(_ctx, event, _framework, _data))
},
..Default::default() ..Default::default()
}) };
let framework = poise::Framework::builder()
.options(options)
.token(std::env::var("DISCORD_TOKEN").unwrap()) .token(std::env::var("DISCORD_TOKEN").unwrap())
.intents( .intents(
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT, serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT,
) )
.setup(move |ctx, _ready, framework| { .setup(move |ctx, _ready, framework| {
Box::pin(async move { Box::pin(async move {
poise::builtins::register_globally(ctx, &framework.options().commands).await?; poise::builtins::register_globally(ctx, &framework.options().commands).await?;
@ -51,3 +75,17 @@ async fn main() {
framework.run().await.unwrap(); framework.run().await.unwrap();
} }
async fn event_handler(
_ctx: &serenity::Context,
event: &Event<'_>,
_framework: poise::FrameworkContext<'_, Data, Error>,
_data: &Data,
) -> Result<(), Error> {
match event {
Event::Ready { data_about_bot } => {
println!("Logged in as {}", data_about_bot.user.name);
}
_ => {}
}
Ok(())
}