Made buff commands exhaustive

This commit is contained in:
Sam 2021-05-04 09:22:10 -04:00
parent d99623b298
commit 062c290e49
7 changed files with 60 additions and 57 deletions

2
Cargo.lock generated
View File

@ -5542,6 +5542,8 @@ dependencies = [
"specs-idvs", "specs-idvs",
"spin_sleep", "spin_sleep",
"structopt", "structopt",
"strum",
"strum_macros",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
"uuid", "uuid",

View File

@ -7,6 +7,7 @@
"hud.outcome.burning": "died of: burning", "hud.outcome.burning": "died of: burning",
"hud.outcome.curse": "died of: curse", "hud.outcome.curse": "died of: curse",
"hud.outcome.bleeding": "died of: bleeding", "hud.outcome.bleeding": "died of: bleeding",
"hud.outcome.crippled": "died of: crippled",
// Chat outputs // Chat outputs
"hud.chat.online_msg": "[{name}] is online now", "hud.chat.online_msg": "[{name}] is online now",

View File

@ -49,7 +49,7 @@ ron = { version = "0.6", default-features = false }
serde_json = "1.0.50" serde_json = "1.0.50"
serde_repr = "0.1.6" serde_repr = "0.1.6"
# esv export # csv export
csv = { version = "1.1.3", optional = true } csv = { version = "1.1.3", optional = true }
structopt = { version = "0.3.13", optional = true } structopt = { version = "0.3.13", optional = true }
@ -59,6 +59,10 @@ slotmap = { version = "1.0", features = ["serde"] }
indexmap = "1.3.0" indexmap = "1.3.0"
slab = "0.4.2" slab = "0.4.2"
# Strum
strum = "0.20"
strum_macros = "0.20"
# ECS # ECS
specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control", "nightly"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" } specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control", "nightly"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" }
specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "b65fb220e94f5d3c9bc30074a076149763795556" } specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "b65fb220e94f5d3c9bc30074a076149763795556" }

View File

@ -1,4 +1,8 @@
use crate::{assets, comp, npc, terrain}; use crate::{
assets,
comp::{self, buff::BuffKind},
npc, terrain,
};
use assets::AssetExt; use assets::AssetExt;
use hashbrown::HashMap; use hashbrown::HashMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -8,6 +12,7 @@ use std::{
path::Path, path::Path,
str::FromStr, str::FromStr,
}; };
use strum::IntoEnumIterator;
use tracing::warn; use tracing::warn;
/// Struct representing a command that a user can run from server chat. /// Struct representing a command that a user can run from server chat.
@ -210,21 +215,40 @@ lazy_static! {
.map(|s| s.to_string()) .map(|s| s.to_string())
.collect(); .collect();
static ref BUFFS: Vec<String> = vec![ pub static ref BUFF_PARSER: HashMap<String, BuffKind> = {
// Debuffs let string_from_buff = |kind| match kind {
"burning", "bleeding", "curse", BuffKind::Burning => "burning",
// Heal BuffKind::Regeneration => "regeration",
"regeneration", "saturation", "potion", "campfire_heal", BuffKind::Saturation => "saturation",
// Outmaxing stats BuffKind::Bleeding => "bleeding",
"increase_max_energy", "increase_max_health", BuffKind::Cursed => "cursed",
// Defensive buffs BuffKind::Potion => "potion",
"invulnerability", "protecting_ward", BuffKind::CampfireHeal => "campfire_heal",
// One command to rule them all BuffKind::IncreaseMaxEnergy => "increase_max_energy",
"all", BuffKind::IncreaseMaxHealth => "increase_max_health",
] BuffKind::Invulnerability => "invulnerability",
.iter() BuffKind::ProtectingWard => "protecting_ward",
.map(|b| b.to_string()) BuffKind::Frenzied => "frenzied",
.collect(); BuffKind::Crippled => "crippled",
};
let mut buff_parser = HashMap::new();
BuffKind::iter().for_each(|kind| {buff_parser.insert(string_from_buff(kind).to_string(), kind);});
buff_parser
};
pub static ref BUFF_PACK: Vec<String> = {
let mut buff_pack: Vec<_> = BUFF_PARSER.keys().cloned().collect();
// Remove invulnerability as it removes debuffs
buff_pack.retain(|kind| kind != "invulnerability");
buff_pack
};
static ref BUFFS: Vec<String> = {
let mut buff_pack: Vec<_> = BUFF_PARSER.keys().cloned().collect();
// Add all as valid command
buff_pack.push("all".to_string());
buff_pack
};
static ref BLOCK_KINDS: Vec<String> = terrain::block::BLOCK_KINDS static ref BLOCK_KINDS: Vec<String> = terrain::block::BLOCK_KINDS
.keys() .keys()

View File

@ -9,10 +9,13 @@ use specs::{Component, DerefFlaggedStorage};
use specs_idvs::IdvStorage; use specs_idvs::IdvStorage;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use std::{cmp::Ordering, time::Duration}; use std::{cmp::Ordering, time::Duration};
use strum_macros::EnumIter;
/// De/buff Kind. /// De/buff Kind.
/// This is used to determine what effects a buff will have /// This is used to determine what effects a buff will have
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Serialize, Deserialize, PartialOrd, Ord)] #[derive(
Clone, Copy, PartialEq, Eq, Hash, Debug, Serialize, Deserialize, PartialOrd, Ord, EnumIter,
)]
pub enum BuffKind { pub enum BuffKind {
// Buffs // Buffs
/// Restores health/time for some period /// Restores health/time for some period

View File

@ -11,7 +11,7 @@ use authc::Uuid;
use chrono::{NaiveTime, Timelike}; use chrono::{NaiveTime, Timelike};
use common::{ use common::{
assets, assets,
cmd::{ChatCommand, CHAT_COMMANDS, CHAT_SHORTCUTS}, cmd::{ChatCommand, BUFF_PACK, BUFF_PARSER, CHAT_COMMANDS, CHAT_SHORTCUTS},
comp::{ comp::{
self, self,
aura::{Aura, AuraKind, AuraTarget}, aura::{Aura, AuraKind, AuraTarget},
@ -36,13 +36,11 @@ use common_net::{
}; };
use common_state::{BuildAreaError, BuildAreas}; use common_state::{BuildAreaError, BuildAreas};
use core::{convert::TryFrom, ops::Not, time::Duration}; use core::{convert::TryFrom, ops::Not, time::Duration};
use hashbrown::HashSet; use hashbrown::{HashMap, HashSet};
use rand::Rng; use rand::Rng;
use specs::{Builder, Entity as EcsEntity, Join, WorldExt}; use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement};
use hashbrown::HashMap;
use vek::*; use vek::*;
use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement};
use world::util::Sampler; use world::util::Sampler;
use crate::{client::Client, login_provider::LoginProvider, wiring}; use crate::{client::Client, login_provider::LoginProvider, wiring};
@ -2615,22 +2613,6 @@ fn handle_apply_buff(
args: String, args: String,
action: &ChatCommand, action: &ChatCommand,
) -> CmdResult<()> { ) -> CmdResult<()> {
const BUFF_PACK: &[&str] = &[
// Debuffs
"burning",
"bleeding",
"curse",
// Healing
"regeneration",
"saturation",
"potion",
"campfire_heal",
// Outmaxing stats
"increase_max_energy",
"increase_max_health",
// Defensive buffs (invulnerability is skipped because it ruins all debuffs)
"protecting_ward",
];
if let (Some(buff), strength, duration) = if let (Some(buff), strength, duration) =
scan_fmt_some!(&args, &action.arg_fmt(), String, f32, f64) scan_fmt_some!(&args, &action.arg_fmt(), String, f32, f64)
{ {
@ -2640,7 +2622,7 @@ fn handle_apply_buff(
if buff != "all" { if buff != "all" {
cast_buff(&buff, buffdata, server, target) cast_buff(&buff, buffdata, server, target)
} else { } else {
for kind in BUFF_PACK { for kind in BUFF_PACK.iter() {
cast_buff(kind, buffdata, server, target)?; cast_buff(kind, buffdata, server, target)?;
} }
Ok(()) Ok(())
@ -2663,19 +2645,4 @@ fn cast_buff(kind: &str, data: BuffData, server: &mut Server, target: EcsEntity)
} }
} }
fn parse_buffkind(buff: &str) -> Option<BuffKind> { fn parse_buffkind(buff: &str) -> Option<BuffKind> { BUFF_PARSER.get(buff).copied() }
match buff {
"burning" => Some(BuffKind::Burning),
"regeneration" => Some(BuffKind::Regeneration),
"saturation" => Some(BuffKind::Saturation),
"bleeding" => Some(BuffKind::Bleeding),
"curse" => Some(BuffKind::Cursed),
"potion" => Some(BuffKind::Potion),
"campfire_heal" => Some(BuffKind::CampfireHeal),
"increase_max_energy" => Some(BuffKind::IncreaseMaxEnergy),
"increase_max_health" => Some(BuffKind::IncreaseMaxHealth),
"invulnerability" => Some(BuffKind::Invulnerability),
"protecting_ward" => Some(BuffKind::ProtectingWard),
_ => None,
}
}

View File

@ -628,6 +628,7 @@ fn insert_killing_buff(buff: BuffKind, localized_strings: &Localization, templat
BuffKind::Burning => localized_strings.get("hud.outcome.burning"), BuffKind::Burning => localized_strings.get("hud.outcome.burning"),
BuffKind::Bleeding => localized_strings.get("hud.outcome.bleeding"), BuffKind::Bleeding => localized_strings.get("hud.outcome.bleeding"),
BuffKind::Cursed => localized_strings.get("hud.outcome.curse"), BuffKind::Cursed => localized_strings.get("hud.outcome.curse"),
BuffKind::Crippled => localized_strings.get("hud.outcome.crippled"),
BuffKind::Regeneration BuffKind::Regeneration
| BuffKind::Saturation | BuffKind::Saturation
| BuffKind::Potion | BuffKind::Potion
@ -635,7 +636,8 @@ fn insert_killing_buff(buff: BuffKind, localized_strings: &Localization, templat
| BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxEnergy
| BuffKind::IncreaseMaxHealth | BuffKind::IncreaseMaxHealth
| BuffKind::Invulnerability | BuffKind::Invulnerability
| BuffKind::ProtectingWard => { | BuffKind::ProtectingWard
| BuffKind::Frenzied => {
tracing::error!("Player was killed by a positive buff!"); tracing::error!("Player was killed by a positive buff!");
localized_strings.get("hud.outcome.mysterious") localized_strings.get("hud.outcome.mysterious")
}, },