From faa86226c7314f799ef223bbba4d4cb552ebdbbd Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 29 Jan 2020 12:01:28 +0000 Subject: [PATCH] Collars --- CHANGELOG.md | 1 + assets/common/items/collar.ron | 7 +++ assets/voxygen/element/icons/collar.vox | 3 + assets/voxygen/item_image_manifest.ron | 6 +- assets/voxygen/voxel/object/potion_turq.vox | 3 + common/src/comp/inventory/item.rs | 8 ++- server/src/lib.rs | 67 ++++++++++++++++++++- voxygen/src/hud/item_imgs.rs | 4 +- voxygen/src/hud/mod.rs | 2 +- 9 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 assets/common/items/collar.ron create mode 100644 assets/voxygen/element/icons/collar.vox create mode 100644 assets/voxygen/voxel/object/potion_turq.vox diff --git a/CHANGELOG.md b/CHANGELOG.md index 18baf2e358..7f36758442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added pathfinding to NPCs - Overhauled NPC AI - Pets now attack enemies and defend their owners +- Added collars to tame wild animals ### Changed diff --git a/assets/common/items/collar.ron b/assets/common/items/collar.ron new file mode 100644 index 0000000000..5226dd0c0a --- /dev/null +++ b/assets/common/items/collar.ron @@ -0,0 +1,7 @@ +Item( + name: "Collar", + description: "Tames wild animals within 5 blocks.", + kind: Utility( + kind: Collar, + ), +) diff --git a/assets/voxygen/element/icons/collar.vox b/assets/voxygen/element/icons/collar.vox new file mode 100644 index 0000000000..92b3346340 --- /dev/null +++ b/assets/voxygen/element/icons/collar.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8d5ce0e89923fa33ab1cb169ff7cab414c863956b6b7620bd4a6b82409af3e5 +size 58948 diff --git a/assets/voxygen/item_image_manifest.ron b/assets/voxygen/item_image_manifest.ron index 048ac495b4..a53c7a6c8b 100644 --- a/assets/voxygen/item_image_manifest.ron +++ b/assets/voxygen/item_image_manifest.ron @@ -31,6 +31,10 @@ "voxel.weapon.shield.wood-0", (0.0, 9.0, 0.0), (-90.0, 90.0, 0.0), 2.4, ), + Utility(Collar): VoxTrans( + "element.icons.collar", + (0.0, 0.0, 0.0), (-90.0, 180.0, 10.0), 1.3, + ), // Consumables Consumable(Apple): VoxTrans( "element.icons.item_apple", @@ -41,7 +45,7 @@ (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.8, ), Consumable(Cheese): Png( - "element.icons.item_cheese", + "element.icons.item_cheese", ), Consumable(Potion): VoxTrans( "voxel.object.potion_red", diff --git a/assets/voxygen/voxel/object/potion_turq.vox b/assets/voxygen/voxel/object/potion_turq.vox new file mode 100644 index 0000000000..8bdbc01c74 --- /dev/null +++ b/assets/voxygen/voxel/object/potion_turq.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c9c944dd7bc205288e0b28148d939252df5537f90ec8fa2b9cc18e8fe863921 +size 55889 diff --git a/common/src/comp/inventory/item.rs b/common/src/comp/inventory/item.rs index 1ec6f4508b..23365ceb76 100644 --- a/common/src/comp/inventory/item.rs +++ b/common/src/comp/inventory/item.rs @@ -88,7 +88,6 @@ pub enum Armor { Necklace, } -//TODO: Do we even need this? #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Consumable { Apple, @@ -100,6 +99,11 @@ pub enum Consumable { PotionMinor, } +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum Utility { + Collar, +} + #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Ingredient { Flower, @@ -111,6 +115,7 @@ pub enum ItemKind { Tool { kind: Tool, power: u32 }, Armor { kind: Armor, power: u32 }, Consumable { kind: Consumable, effect: Effect }, + Utility { kind: Utility }, Ingredient(Ingredient), } @@ -165,6 +170,7 @@ impl Item { "common.items.veloritefrag", "common.items.cheese", "common.items.potion_minor", + "common.items.collar", "common.items.weapons.starter_sword", "common.items.weapons.starter_axe", "common.items.weapons.starter_hammer", diff --git a/server/src/lib.rs b/server/src/lib.rs index 880e5b3b99..da009757bc 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -575,8 +575,73 @@ impl Server { comp::ItemKind::Consumable { effect, .. } => { state.apply_effect(entity, effect); } + comp::ItemKind::Utility { kind } => match kind { + comp::item::Utility::Collar => { + let reinsert = if let Some(pos) = + state.read_storage::().get(entity) + { + if ( + &state.read_storage::(), + &state.read_storage::(), + ) + .join() + .filter(|(alignment, _)| { + alignment + == &&comp::Alignment::Owned(entity) + }) + .count() + >= 3 + { + true + } else if let Some(tameable_entity) = { + let nearest_tameable = ( + &state.ecs().entities(), + &state.ecs().read_storage::(), + &state + .ecs() + .read_storage::(), + ) + .join() + .filter(|(_, wild_pos, _)| { + wild_pos.0.distance_squared(pos.0) + < 5.0f32.powf(2.0) + }) + .filter(|(_, _, alignment)| { + alignment == &&comp::Alignment::Wild + }) + .min_by_key(|(_, wild_pos, _)| { + (wild_pos.0.distance_squared(pos.0) + * 100.0) + as i32 + }) + .map(|(entity, _, _)| entity); + nearest_tameable + } { + let _ = state + .ecs() + .write_storage::() + .insert( + tameable_entity, + comp::Alignment::Owned(entity), + ); + false + } else { + true + } + } else { + true + }; + + if reinsert { + let _ = state + .ecs() + .write_storage::() + .get_mut(entity) + .map(|inv| inv.insert(slot, item)); + } + } + }, _ => { - // Re-insert it if unused let _ = state .ecs() .write_storage::() diff --git a/voxygen/src/hud/item_imgs.rs b/voxygen/src/hud/item_imgs.rs index 4d7ee2686f..9c3d7f5d7f 100644 --- a/voxygen/src/hud/item_imgs.rs +++ b/voxygen/src/hud/item_imgs.rs @@ -1,7 +1,7 @@ use crate::ui::{Graphic, SampleStrat, Transform, Ui}; use common::{ assets::{self, watch::ReloadIndicator, Asset}, - comp::item::{Armor, Consumable, Ingredient, Item, ItemKind, Tool}, + comp::item::{Armor, Consumable, Ingredient, Item, ItemKind, Tool, Utility}, }; use conrod_core::image::Id; use dot_vox::DotVoxData; @@ -16,6 +16,7 @@ use vek::*; pub enum ItemKey { Tool(Tool), Armor(Armor), + Utility(Utility), Consumable(Consumable), Ingredient(Ingredient), } @@ -24,6 +25,7 @@ impl From<&Item> for ItemKey { match &item.kind { ItemKind::Tool { kind, .. } => ItemKey::Tool(kind.clone()), ItemKind::Armor { kind, .. } => ItemKey::Armor(kind.clone()), + ItemKind::Utility { kind } => ItemKey::Utility(kind.clone()), ItemKind::Consumable { kind, .. } => ItemKey::Consumable(kind.clone()), ItemKind::Ingredient(kind) => ItemKey::Ingredient(kind.clone()), } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index cfdde8db7d..1853c5fa88 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -66,7 +66,7 @@ const TEXT_COLOR_3: Color = Color::Rgba(1.0, 1.0, 1.0, 0.1); const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0); const LOW_HP_COLOR: Color = Color::Rgba(0.93, 0.59, 0.03, 1.0); const CRITICAL_HP_COLOR: Color = Color::Rgba(0.79, 0.19, 0.17, 1.0); -const MANA_COLOR: Color = Color::Rgba(0.47, 0.55, 1.0, 0.9); +const MANA_COLOR: Color = Color::Rgba(0.29, 0.62, 0.75, 0.9); //const FOCUS_COLOR: Color = Color::Rgba(1.0, 0.56, 0.04, 1.0); //const RAGE_COLOR: Color = Color::Rgba(0.5, 0.04, 0.13, 1.0); const META_COLOR: Color = Color::Rgba(1.0, 1.0, 0.0, 1.0);