From 0e2808a8fda9e6223d9c744f6fe0d757cfc5505d Mon Sep 17 00:00:00 2001 From: ubruntu Date: Tue, 5 Oct 2021 00:55:29 +0000 Subject: [PATCH] Interactable campfires --- CHANGELOG.md | 1 + common/src/comp/body.rs | 2 ++ common/src/comp/buff.rs | 2 +- common/src/comp/character_state.rs | 22 +++++++++++++++++++++- common/systems/src/aura.rs | 13 +++++++------ voxygen/src/session/interactable.rs | 2 +- voxygen/src/session/mod.rs | 9 +++++++++ 7 files changed, 42 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d511fdf01e..e34a0debb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Put date at the begining of the log file instead of the end to allow MIME type recognition - Tweaked CR and exp calculation formula - Sprite spawn rates +- The Interact button can be used on campfires to sit ### Removed diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index 45982c3557..b5a288399b 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -150,6 +150,8 @@ impl< impl Body { pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) } + pub fn is_campfire(&self) -> bool { matches!(self, Body::Object(object::Body::CampfireLit)) } + /// Average density of the body // Units are based on kg/m³ pub fn density(&self) -> Density { diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index 63a7e2e1f7..b224710692 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -27,7 +27,7 @@ pub enum BuffKind { /// Strength should be the healing per second Potion, /// Applied when sitting at a campfire - /// Strength is fraction of health resotred per second + /// Strength is fraction of health restored per second CampfireHeal, /// Raises maximum energy /// Strength should be 10x the effect to max energy diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 9038594052..1feb6ed264 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -1,6 +1,9 @@ use crate::{ combat::Attack, - comp::{tool::ToolKind, ControlAction, Density, Energy, InputAttr, InputKind, Ori, Pos, Vel}, + comp::{ + item::ConsumableKind, tool::ToolKind, ControlAction, Density, Energy, InputAttr, InputKind, + Ori, Pos, Vel, + }, event::{LocalEvent, ServerEvent}, states::{ self, @@ -219,6 +222,23 @@ impl CharacterState { || matches!(self, CharacterState::Roll(s) if s.stage_section == StageSection::Movement) } + pub fn is_sitting(&self) -> bool { + use use_item::{Data, ItemUseKind, StaticData}; + matches!( + self, + CharacterState::Sit + | CharacterState::UseItem(Data { + static_data: StaticData { + item_kind: ItemUseKind::Consumable( + ConsumableKind::ComplexFood | ConsumableKind::Food + ), + .. + }, + .. + }) + ) + } + /// Compares for shallow equality (does not check internal struct equality) pub fn same_variant(&self, other: &Self) -> bool { // Check if state is the same without looking at the inner data diff --git a/common/systems/src/aura.rs b/common/systems/src/aura.rs index f316e6fde7..dccd642e30 100644 --- a/common/systems/src/aura.rs +++ b/common/systems/src/aura.rs @@ -163,11 +163,12 @@ fn activate_aura( let should_activate = match aura.aura_kind { AuraKind::Buff { kind, source, .. } => { let conditions_held = match kind { - BuffKind::CampfireHeal => { - let target_state = read_data.char_states.get(target); - matches!(target_state, Some(CharacterState::Sit)) - && health.current() < health.maximum() - }, + BuffKind::CampfireHeal => read_data + .char_states + .get(target) + .map_or(false, |target_state| { + target_state.is_sitting() && health.current() < health.maximum() + }), // Add other specific buff conditions here _ => true, }; @@ -175,7 +176,7 @@ fn activate_aura( // TODO: this check will disable friendly fire with PvE switch. // // Which means that you can't apply debuffs on you and your group - // even if it's intented mechanic. + // even if it's intended mechanic. // // We don't have this for now, but think about this // when we will add this. diff --git a/voxygen/src/session/interactable.rs b/voxygen/src/session/interactable.rs index 9e04ca55fc..39a8d5b926 100644 --- a/voxygen/src/session/interactable.rs +++ b/voxygen/src/session/interactable.rs @@ -35,7 +35,7 @@ impl Interactable { } } -/// Select interactable to hightlight, display interaction text for, and to +/// Select interactable to highlight, display interaction text for, and to /// interact with if the interact key is pressed /// Selected in the following order: /// 1) Targeted items, in order of nearest under cursor: diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 3907d616c9..58ff24ac25 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -732,6 +732,15 @@ impl PlayState for SessionState { .is_some() { client.pick_up(entity); + } else if client + .state() + .ecs() + .read_storage::() + .get(entity) + .map_or(false, |b| b.is_campfire()) + { + // TODO: maybe start crafting instead? + client.toggle_sit(); } else { client.npc_interact(entity); }