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",
"spin_sleep",
"structopt",
"strum",
"strum_macros",
"tracing",
"tracing-subscriber",
"uuid",

View File

@ -7,6 +7,7 @@
"hud.outcome.burning": "died of: burning",
"hud.outcome.curse": "died of: curse",
"hud.outcome.bleeding": "died of: bleeding",
"hud.outcome.crippled": "died of: crippled",
// Chat outputs
"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_repr = "0.1.6"
# esv export
# csv export
csv = { version = "1.1.3", optional = true }
structopt = { version = "0.3.13", optional = true }
@ -59,6 +59,10 @@ slotmap = { version = "1.0", features = ["serde"] }
indexmap = "1.3.0"
slab = "0.4.2"
# Strum
strum = "0.20"
strum_macros = "0.20"
# ECS
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" }

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 hashbrown::HashMap;
use lazy_static::lazy_static;
@ -8,6 +12,7 @@ use std::{
path::Path,
str::FromStr,
};
use strum::IntoEnumIterator;
use tracing::warn;
/// Struct representing a command that a user can run from server chat.
@ -210,21 +215,40 @@ lazy_static! {
.map(|s| s.to_string())
.collect();
static ref BUFFS: Vec<String> = vec![
// Debuffs
"burning", "bleeding", "curse",
// Heal
"regeneration", "saturation", "potion", "campfire_heal",
// Outmaxing stats
"increase_max_energy", "increase_max_health",
// Defensive buffs
"invulnerability", "protecting_ward",
// One command to rule them all
"all",
]
.iter()
.map(|b| b.to_string())
.collect();
pub static ref BUFF_PARSER: HashMap<String, BuffKind> = {
let string_from_buff = |kind| match kind {
BuffKind::Burning => "burning",
BuffKind::Regeneration => "regeration",
BuffKind::Saturation => "saturation",
BuffKind::Bleeding => "bleeding",
BuffKind::Cursed => "cursed",
BuffKind::Potion => "potion",
BuffKind::CampfireHeal => "campfire_heal",
BuffKind::IncreaseMaxEnergy => "increase_max_energy",
BuffKind::IncreaseMaxHealth => "increase_max_health",
BuffKind::Invulnerability => "invulnerability",
BuffKind::ProtectingWard => "protecting_ward",
BuffKind::Frenzied => "frenzied",
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
.keys()

View File

@ -9,10 +9,13 @@ use specs::{Component, DerefFlaggedStorage};
use specs_idvs::IdvStorage;
#[cfg(not(target_arch = "wasm32"))]
use std::{cmp::Ordering, time::Duration};
use strum_macros::EnumIter;
/// De/buff Kind.
/// 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 {
// Buffs
/// Restores health/time for some period

View File

@ -11,7 +11,7 @@ use authc::Uuid;
use chrono::{NaiveTime, Timelike};
use common::{
assets,
cmd::{ChatCommand, CHAT_COMMANDS, CHAT_SHORTCUTS},
cmd::{ChatCommand, BUFF_PACK, BUFF_PARSER, CHAT_COMMANDS, CHAT_SHORTCUTS},
comp::{
self,
aura::{Aura, AuraKind, AuraTarget},
@ -36,13 +36,11 @@ use common_net::{
};
use common_state::{BuildAreaError, BuildAreas};
use core::{convert::TryFrom, ops::Not, time::Duration};
use hashbrown::HashSet;
use hashbrown::{HashMap, HashSet};
use rand::Rng;
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement};
use hashbrown::HashMap;
use vek::*;
use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement};
use world::util::Sampler;
use crate::{client::Client, login_provider::LoginProvider, wiring};
@ -2615,22 +2613,6 @@ fn handle_apply_buff(
args: String,
action: &ChatCommand,
) -> 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) =
scan_fmt_some!(&args, &action.arg_fmt(), String, f32, f64)
{
@ -2640,7 +2622,7 @@ fn handle_apply_buff(
if buff != "all" {
cast_buff(&buff, buffdata, server, target)
} else {
for kind in BUFF_PACK {
for kind in BUFF_PACK.iter() {
cast_buff(kind, buffdata, server, target)?;
}
Ok(())
@ -2663,19 +2645,4 @@ fn cast_buff(kind: &str, data: BuffData, server: &mut Server, target: EcsEntity)
}
}
fn parse_buffkind(buff: &str) -> Option<BuffKind> {
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,
}
}
fn parse_buffkind(buff: &str) -> Option<BuffKind> { BUFF_PARSER.get(buff).copied() }

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