From 1978b590aae9b1ff8f435284c0e8f79f92d21525 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Jun 2021 23:26:09 -0500 Subject: [PATCH 1/7] Destringified consumables --- assets/common/items/boss_drops/potions.ron | 2 +- assets/common/items/consumable/potion_big.ron | 2 +- assets/common/items/consumable/potion_med.ron | 2 +- .../common/items/consumable/potion_minor.ron | 2 +- assets/common/items/food/apple.ron | 2 +- .../items/food/apple_mushroom_curry.ron | 2 +- assets/common/items/food/apple_stick.ron | 2 +- assets/common/items/food/cactus_colada.ron | 2 +- assets/common/items/food/carrot.ron | 2 +- assets/common/items/food/cheese.ron | 2 +- assets/common/items/food/coconut.ron | 2 +- assets/common/items/food/coltsfoot.ron | 2 +- assets/common/items/food/dandelion.ron | 2 +- assets/common/items/food/garlic.ron | 2 +- assets/common/items/food/lettuce.ron | 2 +- assets/common/items/food/meat.ron | 2 +- .../items/food/meat/beast_large_cooked.ron | 2 +- .../items/food/meat/beast_large_raw.ron | 2 +- .../items/food/meat/beast_small_cooked.ron | 2 +- .../items/food/meat/beast_small_raw.ron | 2 +- assets/common/items/food/meat/bird_cooked.ron | 2 +- .../items/food/meat/bird_large_cooked.ron | 2 +- .../common/items/food/meat/bird_large_raw.ron | 2 +- assets/common/items/food/meat/bird_raw.ron | 2 +- assets/common/items/food/meat/fish_cooked.ron | 2 +- assets/common/items/food/meat/fish_raw.ron | 2 +- .../common/items/food/meat/tough_cooked.ron | 2 +- assets/common/items/food/meat/tough_raw.ron | 2 +- assets/common/items/food/mushroom.ron | 2 +- assets/common/items/food/mushroom_stick.ron | 2 +- assets/common/items/food/onion.ron | 2 +- assets/common/items/food/plainsalad.ron | 2 +- assets/common/items/food/sage.ron | 2 +- assets/common/items/food/sunflower_icetea.ron | 2 +- assets/common/items/food/tomato.ron | 2 +- assets/common/items/food/tomatosalad.ron | 2 +- assets/voxygen/item_image_manifest.ron | 68 +++++++++---------- common/src/comp/inventory/item/mod.rs | 8 ++- common/src/comp/inventory/mod.rs | 7 +- server/src/events/inventory_manip.rs | 2 +- voxygen/src/audio/sfx/mod.rs | 6 +- voxygen/src/hud/item_imgs.rs | 2 +- 42 files changed, 85 insertions(+), 80 deletions(-) diff --git a/assets/common/items/boss_drops/potions.ron b/assets/common/items/boss_drops/potions.ron index 2fbd66e4eb..bccc411161 100644 --- a/assets/common/items/boss_drops/potions.ron +++ b/assets/common/items/boss_drops/potions.ron @@ -2,7 +2,7 @@ ItemDef( name: "Potent Potion", description: "A potent healing potion.", kind: Consumable( - kind: "Potion", + kind: Potion, effect: [ Buff(( kind: Potion, diff --git a/assets/common/items/consumable/potion_big.ron b/assets/common/items/consumable/potion_big.ron index cb0eeb87f5..71cd4243a7 100644 --- a/assets/common/items/consumable/potion_big.ron +++ b/assets/common/items/consumable/potion_big.ron @@ -2,7 +2,7 @@ ItemDef( name: "Large Potion", description: "", kind: Consumable( - kind: "PotionLarge", + kind: Potion, effect: [ Buff(( kind: Potion, diff --git a/assets/common/items/consumable/potion_med.ron b/assets/common/items/consumable/potion_med.ron index fb3ebc8227..87c127cfce 100644 --- a/assets/common/items/consumable/potion_med.ron +++ b/assets/common/items/consumable/potion_med.ron @@ -2,7 +2,7 @@ ItemDef( name: "Medium Potion", description: "", kind: Consumable( - kind: "PotionMed", + kind: Potion, effect: [ Buff(( kind: Potion, diff --git a/assets/common/items/consumable/potion_minor.ron b/assets/common/items/consumable/potion_minor.ron index 219c2e595c..a7b5706847 100644 --- a/assets/common/items/consumable/potion_minor.ron +++ b/assets/common/items/consumable/potion_minor.ron @@ -2,7 +2,7 @@ ItemDef( name: "Minor Potion", description: "", kind: Consumable( - kind: "PotionMinor", + kind: Potion, effect: [ Buff(( kind: Potion, diff --git a/assets/common/items/food/apple.ron b/assets/common/items/food/apple.ron index 4648ace03b..d6a0316865 100644 --- a/assets/common/items/food/apple.ron +++ b/assets/common/items/food/apple.ron @@ -2,7 +2,7 @@ ItemDef( name: "Apple", description: "Red and juicy", kind: Consumable( - kind: "Apple", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/apple_mushroom_curry.ron b/assets/common/items/food/apple_mushroom_curry.ron index 62d591d08b..16fd5924b6 100644 --- a/assets/common/items/food/apple_mushroom_curry.ron +++ b/assets/common/items/food/apple_mushroom_curry.ron @@ -2,7 +2,7 @@ ItemDef( name: "Mushroom Curry", description: "Who could say no to that?", kind: Consumable( - kind: "AppleShroomCurry", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/apple_stick.ron b/assets/common/items/food/apple_stick.ron index 185f75a2bb..6ed79bafbd 100644 --- a/assets/common/items/food/apple_stick.ron +++ b/assets/common/items/food/apple_stick.ron @@ -2,7 +2,7 @@ ItemDef( name: "Apple Stick", description: "The stick makes it easier to carry!", kind: Consumable( - kind: "AppleStick", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/cactus_colada.ron b/assets/common/items/food/cactus_colada.ron index 421c140c23..7b8711e806 100644 --- a/assets/common/items/food/cactus_colada.ron +++ b/assets/common/items/food/cactus_colada.ron @@ -2,7 +2,7 @@ ItemDef( name: "Cactus Colada", description: "Giving you that special prickle.", kind: Consumable( - kind: "CactusColada", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/carrot.ron b/assets/common/items/food/carrot.ron index 4e7c888245..f0e5886d8b 100644 --- a/assets/common/items/food/carrot.ron +++ b/assets/common/items/food/carrot.ron @@ -2,7 +2,7 @@ ItemDef( name: "Carrot", description: "An orange root vegetable. They say it'll improve your vision!", kind: Consumable( - kind: "Carrot", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/cheese.ron b/assets/common/items/food/cheese.ron index 22141cfe96..0b4c501ca5 100644 --- a/assets/common/items/food/cheese.ron +++ b/assets/common/items/food/cheese.ron @@ -2,7 +2,7 @@ ItemDef( name: "Dwarven Cheese", description: "Aromatic and nutritious", kind: Consumable( - kind: "Cheese", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/coconut.ron b/assets/common/items/food/coconut.ron index d9ee0f05a1..265127256f 100644 --- a/assets/common/items/food/coconut.ron +++ b/assets/common/items/food/coconut.ron @@ -2,7 +2,7 @@ ItemDef( name: "Coconut", description: "Reliable source of water and fat.\n\nNaturally growing at the top of palm trees.", kind: Consumable( - kind: "Coconut", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/coltsfoot.ron b/assets/common/items/food/coltsfoot.ron index 958e4b702e..e802299a9e 100644 --- a/assets/common/items/food/coltsfoot.ron +++ b/assets/common/items/food/coltsfoot.ron @@ -2,7 +2,7 @@ ItemDef( name: "Coltsfoot", description: "A daisy-like flower often used in herbal teas.", kind: Consumable( - kind: "Coltsfoot", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/dandelion.ron b/assets/common/items/food/dandelion.ron index 44c46fc993..339abfafdc 100644 --- a/assets/common/items/food/dandelion.ron +++ b/assets/common/items/food/dandelion.ron @@ -2,7 +2,7 @@ ItemDef( name: "Dandelion", description: "A small, yellow flower. Uses the wind to spread its seeds.", kind: Consumable( - kind: "Dandelion", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/garlic.ron b/assets/common/items/food/garlic.ron index 16db0b22e5..478c954146 100644 --- a/assets/common/items/food/garlic.ron +++ b/assets/common/items/food/garlic.ron @@ -2,7 +2,7 @@ ItemDef( name: "Garlic", description: "Make sure to brush your teeth after eating.", kind: Consumable( - kind: "Garlic", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/lettuce.ron b/assets/common/items/food/lettuce.ron index 3afb3fc253..45bab6a156 100644 --- a/assets/common/items/food/lettuce.ron +++ b/assets/common/items/food/lettuce.ron @@ -2,7 +2,7 @@ ItemDef( name: "Lettuce", description: "A vibrant green leafy vegetable. Lettuce make some salads!", kind: Consumable( - kind: "Lettuce", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat.ron b/assets/common/items/food/meat.ron index 9ae711fcb3..221fb5182f 100644 --- a/assets/common/items/food/meat.ron +++ b/assets/common/items/food/meat.ron @@ -2,7 +2,7 @@ ItemDef( name: "Meat", description: "Meat. The lifeblood of mankind.", kind: Consumable( - kind: "Meat", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/beast_large_cooked.ron b/assets/common/items/food/meat/beast_large_cooked.ron index 862ab6a9c2..e464c3fa79 100644 --- a/assets/common/items/food/meat/beast_large_cooked.ron +++ b/assets/common/items/food/meat/beast_large_cooked.ron @@ -2,7 +2,7 @@ ItemDef( name: "Cooked Meat Slab", description: "Medium Rare.", kind: Consumable( - kind: "BeastLargeCooked", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/beast_large_raw.ron b/assets/common/items/food/meat/beast_large_raw.ron index ab6ef40fcf..19f6dfc974 100644 --- a/assets/common/items/food/meat/beast_large_raw.ron +++ b/assets/common/items/food/meat/beast_large_raw.ron @@ -2,7 +2,7 @@ ItemDef( name: "Raw Meat Slab", description: "Chunk of beastly animal meat, best after cooking.", kind: Consumable( - kind: "BeastLargeRaw", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/beast_small_cooked.ron b/assets/common/items/food/meat/beast_small_cooked.ron index e7c5a70809..13833e6c5c 100644 --- a/assets/common/items/food/meat/beast_small_cooked.ron +++ b/assets/common/items/food/meat/beast_small_cooked.ron @@ -2,7 +2,7 @@ ItemDef( name: "Cooked Meat Sliver", description: "Medium Rare.", kind: Consumable( - kind: "BeastSmallCooked", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/beast_small_raw.ron b/assets/common/items/food/meat/beast_small_raw.ron index c4c53f7399..377cc90e6d 100644 --- a/assets/common/items/food/meat/beast_small_raw.ron +++ b/assets/common/items/food/meat/beast_small_raw.ron @@ -2,7 +2,7 @@ ItemDef( name: "Raw Meat Sliver", description: "Small hunk of beastly animal meat, best after cooking.", kind: Consumable( - kind: "BeastSmallRaw", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/bird_cooked.ron b/assets/common/items/food/meat/bird_cooked.ron index d6ebe34157..bee712ce23 100644 --- a/assets/common/items/food/meat/bird_cooked.ron +++ b/assets/common/items/food/meat/bird_cooked.ron @@ -2,7 +2,7 @@ ItemDef( name: "Cooked Bird Meat", description: "Best enjoyed with one in each hand.", kind: Consumable( - kind: "BirdCooked", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/bird_large_cooked.ron b/assets/common/items/food/meat/bird_large_cooked.ron index 5664416901..d63ca774d7 100644 --- a/assets/common/items/food/meat/bird_large_cooked.ron +++ b/assets/common/items/food/meat/bird_large_cooked.ron @@ -2,7 +2,7 @@ ItemDef( name: "Huge Cooked Drumstick", description: "Makes for a legendary meal.", kind: Consumable( - kind: "BirdLargeCooked", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/bird_large_raw.ron b/assets/common/items/food/meat/bird_large_raw.ron index 2bd8afc6d1..b55479245b 100644 --- a/assets/common/items/food/meat/bird_large_raw.ron +++ b/assets/common/items/food/meat/bird_large_raw.ron @@ -2,7 +2,7 @@ ItemDef( name: "Huge Raw Drumstick", description: "It's magificent.", kind: Consumable( - kind: "BirdLargeRaw", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/bird_raw.ron b/assets/common/items/food/meat/bird_raw.ron index 252cb1fd63..234a0c58f6 100644 --- a/assets/common/items/food/meat/bird_raw.ron +++ b/assets/common/items/food/meat/bird_raw.ron @@ -2,7 +2,7 @@ ItemDef( name: "Raw Bird Meat", description: "A hefty drumstick.", kind: Consumable( - kind: "BirdRaw", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/fish_cooked.ron b/assets/common/items/food/meat/fish_cooked.ron index 9ed8777a41..de01e9305c 100644 --- a/assets/common/items/food/meat/fish_cooked.ron +++ b/assets/common/items/food/meat/fish_cooked.ron @@ -2,7 +2,7 @@ ItemDef( name: "Cooked Fish", description: "A fresh cooked seafood steak.", kind: Consumable( - kind: "FishCooked", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/fish_raw.ron b/assets/common/items/food/meat/fish_raw.ron index ef5515e91c..a454192290 100644 --- a/assets/common/items/food/meat/fish_raw.ron +++ b/assets/common/items/food/meat/fish_raw.ron @@ -2,7 +2,7 @@ ItemDef( name: "Raw Fish", description: "A steak chopped from a fish, best after cooking.", kind: Consumable( - kind: "FishRaw", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/tough_cooked.ron b/assets/common/items/food/meat/tough_cooked.ron index 0d437ebef1..34563112fe 100644 --- a/assets/common/items/food/meat/tough_cooked.ron +++ b/assets/common/items/food/meat/tough_cooked.ron @@ -2,7 +2,7 @@ ItemDef( name: "Cooked Tough Meat", description: "Tastes exotic.", kind: Consumable( - kind: "ToughCooked", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/meat/tough_raw.ron b/assets/common/items/food/meat/tough_raw.ron index a158d36faa..548160e875 100644 --- a/assets/common/items/food/meat/tough_raw.ron +++ b/assets/common/items/food/meat/tough_raw.ron @@ -2,7 +2,7 @@ ItemDef( name: "Raw Tough Meat", description: "Peculiar bit of meat, best after cooking.", kind: Consumable( - kind: "ToughRaw", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/mushroom.ron b/assets/common/items/food/mushroom.ron index e3ce58f273..e5b4f1c23f 100644 --- a/assets/common/items/food/mushroom.ron +++ b/assets/common/items/food/mushroom.ron @@ -2,7 +2,7 @@ ItemDef( name: "Mushroom", description: "Hopefully this one is not poisonous", kind: Consumable( - kind: "Mushroom", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/mushroom_stick.ron b/assets/common/items/food/mushroom_stick.ron index 326eec6540..ab42bf6059 100644 --- a/assets/common/items/food/mushroom_stick.ron +++ b/assets/common/items/food/mushroom_stick.ron @@ -2,7 +2,7 @@ ItemDef( name: "Mushroom Stick", description: "Roasted mushrooms on a stick for easy carrying", kind: Consumable( - kind: "MushroomStick", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/onion.ron b/assets/common/items/food/onion.ron index 9733cf05f2..e37c5c23b1 100644 --- a/assets/common/items/food/onion.ron +++ b/assets/common/items/food/onion.ron @@ -2,7 +2,7 @@ ItemDef( name: "Onion", description: "A vegetable that's made the toughest men cry.", kind: Consumable( - kind: "Onion", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/plainsalad.ron b/assets/common/items/food/plainsalad.ron index 276648092e..514ed65d10 100644 --- a/assets/common/items/food/plainsalad.ron +++ b/assets/common/items/food/plainsalad.ron @@ -2,7 +2,7 @@ ItemDef( name: "Plain Salad", description: "Literally just chopped lettuce. Does this even count as a salad?", kind: Consumable( - kind: "PlainSalad", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/sage.ron b/assets/common/items/food/sage.ron index 360ddb90ac..76535df51a 100644 --- a/assets/common/items/food/sage.ron +++ b/assets/common/items/food/sage.ron @@ -2,7 +2,7 @@ ItemDef( name: "Sage", description: "A herb commonly used in tea.", kind: Consumable( - kind: "Sage", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/sunflower_icetea.ron b/assets/common/items/food/sunflower_icetea.ron index aed7842885..9e30bbf2ad 100644 --- a/assets/common/items/food/sunflower_icetea.ron +++ b/assets/common/items/food/sunflower_icetea.ron @@ -2,7 +2,7 @@ ItemDef( name: "Sunflower Ice Tea", description: "Brewed from freshly shelled sunflower seeds", kind: Consumable( - kind: "SunflowerTea", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/tomato.ron b/assets/common/items/food/tomato.ron index a174bf652d..80da6495ef 100644 --- a/assets/common/items/food/tomato.ron +++ b/assets/common/items/food/tomato.ron @@ -2,7 +2,7 @@ ItemDef( name: "Tomato", description: "A red fruit. Not actually a vegetable.", kind: Consumable( - kind: "Tomato", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/common/items/food/tomatosalad.ron b/assets/common/items/food/tomatosalad.ron index eb550f9bb3..0842a003de 100644 --- a/assets/common/items/food/tomatosalad.ron +++ b/assets/common/items/food/tomatosalad.ron @@ -2,7 +2,7 @@ ItemDef( name: "Tomato Salad", description: "Leafy salad with some chopped, juicy tomatoes mixed in.", kind: Consumable( - kind: "TomatoSalad", + kind: Food, effect: [ Buff(( kind: Saturation, diff --git a/assets/voxygen/item_image_manifest.ron b/assets/voxygen/item_image_manifest.ron index 7f6526111d..9ec38b32f3 100644 --- a/assets/voxygen/item_image_manifest.ron +++ b/assets/voxygen/item_image_manifest.ron @@ -2235,40 +2235,36 @@ "element.items.item_bag_blue", ), // Consumables - Consumable("Apple"): Png( + Consumable("common.items.food.apple"): Png( "element.items.item_apple", ), - Consumable("Coconut"): Png( + Consumable("common.items.food.coconut"): Png( "element.items.item_coconut", ), - Consumable("CactusColada"): VoxTrans( + Consumable("common.items.food.cactus_colada"): VoxTrans( "voxel.object.cactus_drink", (-1.0, 1.0, 0.0), (-50.0, 30.0, 20.0), 0.8, ), - Consumable("PotionMed"): VoxTrans( + Consumable("common.items.consumable.potion_med"): VoxTrans( "voxel.object.potion_red", (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.7, ), - Consumable("PotionMinor"): VoxTrans( + Consumable("common.items.consumable.potion_minor"): VoxTrans( "voxel.object.potion_red", (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.5, ), - Consumable("PotionLarge"): VoxTrans( + Consumable("common.items.consumable.potion_big"): VoxTrans( "voxel.object.potion_red", (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.9, ), - Ingredient("PotionExp"): VoxTrans( - "voxel.object.potion_turq", - (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.8, + Consumable("common.items.boss_drops.potions"): VoxTrans( + "voxel.object.potion_red", + (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.9, ), - Consumable("Cheese"): Png( + Consumable("common.items.food.cheese"): Png( "element.items.item_cheese", ), - Consumable("Potion"): VoxTrans( - "voxel.object.potion_red", - (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 1.0, - ), - Consumable("Mushroom"): VoxTrans( + Consumable("common.items.food.mushroom"): VoxTrans( "voxel.sprite.mushrooms.mushroom-10", (0.0, 0.0, 0.0), (-50.0, 70.0, 40.0), 1.0, ), @@ -2280,83 +2276,83 @@ "voxel.sprite.velorite.velorite_1", (0.0, 0.0, 0.0), (-50.0, 40.0, 20.0), 0.8, ), - Consumable("AppleShroomCurry"): Png( + Consumable("common.items.food.apple_mushroom_curry"): Png( "element.items.item_apple_curry", ), - Consumable("AppleStick"): Png( + Consumable("common.items.food.apple_stick"): Png( "element.items.item_apple_stick", ), - Consumable("MushroomStick"): Png( + Consumable("common.items.food.mushroom_stick"): Png( "element.items.item_shroom_stick", ), - Consumable("SunflowerTea"): Png( + Consumable("common.items.food.sunflower_icetea"): Png( "element.items.item_sunflower_tea", ), - Consumable("Carrot"): VoxTrans( + Consumable("common.items.food.carrot"): VoxTrans( "voxel.sprite.carrot.carrot", (0.0, 0.0, 0.0), (-20.0, 10.0, 20.0), 0.9, ), - Consumable("Tomato"): VoxTrans( + Consumable("common.items.food.tomato"): VoxTrans( "voxel.sprite.tomato.tomato", (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.8, ), - Consumable("Lettuce"): VoxTrans( + Consumable("common.items.food.lettuce"): VoxTrans( "voxel.sprite.cabbage.cabbage", (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.8, ), - Consumable("FishRaw"): VoxTrans( + Consumable("common.items.food.meat.fish_raw"): VoxTrans( "voxel.sprite.food.meat.fish_raw", (0.0, 0.0, 0.0), (-20.0, 10.0, 20.0), 0.9, ), - Consumable("FishCooked"): VoxTrans( + Consumable("common.items.food.meat.fish_cooked"): VoxTrans( "voxel.sprite.food.meat.fish_cooked", (0.0, 0.0, 0.0), (-20.0, 10.0, 20.0), 0.9, ), - Consumable("BirdRaw"): VoxTrans( + Consumable("common.items.food.meat.bird_raw"): VoxTrans( "voxel.sprite.food.meat.bird_raw", (0.0, 0.0, 0.0), (-20.0, 10.0, 20.0), 0.9, ), - Consumable("BirdCooked"): VoxTrans( + Consumable("common.items.food.meat.bird_cooked"): VoxTrans( "voxel.sprite.food.meat.bird_cooked", (0.0, 0.0, 0.0), (-20.0, 10.0, 20.0), 0.9, ), - Consumable("BirdLargeRaw"): VoxTrans( + Consumable("common.items.food.meat.bird_large_raw"): VoxTrans( "voxel.sprite.food.meat.bird_large_raw", (0.0, 0.0, 0.0), (-20.0, 10.0, 20.0), 0.9, ), - Consumable("BirdLargeCooked"): VoxTrans( + Consumable("common.items.food.meat.bird_large_cooked"): VoxTrans( "voxel.sprite.food.meat.bird_large_cooked", (0.0, 0.0, 0.0), (-20.0, 10.0, 20.0), 0.9, ), - Consumable("BeastSmallRaw"): VoxTrans( + Consumable("common.items.food.meat.beast_small_raw"): VoxTrans( "voxel.sprite.food.meat.beast_small_raw", (0.0, 0.0, 0.0), (-50.0, 10.0, 0.0), 1.0, ), - Consumable("BeastSmallCooked"): VoxTrans( + Consumable("common.items.food.meat.beast_small_cooked"): VoxTrans( "voxel.sprite.food.meat.beast_small_cooked", (0.0, 0.0, 0.0), (-50.0, 20.0, 0.0), 1.0, ), - Consumable("ToughRaw"): VoxTrans( + Consumable("common.items.food.meat.tough_raw"): VoxTrans( "voxel.sprite.food.meat.tough_raw", (0.0, 0.0, 0.0), (-50.0, 10.0, 0.0), 1.0, ), - Consumable("ToughCooked"): VoxTrans( + Consumable("common.items.food.meat.tough_cooked"): VoxTrans( "voxel.sprite.food.meat.tough_cooked", (0.0, 0.0, 0.0), (-50.0, 20.0, 0.0), 1.0, ), - Consumable("BeastLargeRaw"): VoxTrans( + Consumable("common.items.food.meat.beast_large_raw"): VoxTrans( "voxel.sprite.food.meat.beast_large_raw", (-1.0, 0.0, 0.0), (-80.0, 40.0, 0.0), 0.8, ), - Consumable("BeastLargeCooked"): VoxTrans( + Consumable("common.items.food.meat.beast_large_cooked"): VoxTrans( "voxel.sprite.food.meat.beast_large_cooked", (-1.0, 0.0, 0.0), (-80.0, 40.0, 0.0), 0.8, ), - Consumable("PlainSalad"): VoxTrans( + Consumable("common.items.food.plainsalad"): VoxTrans( "voxel.sprite.food.salad_plain", (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.8, ), - Consumable("TomatoSalad"): VoxTrans( + Consumable("common.items.food.tomatosalad"): VoxTrans( "voxel.sprite.food.salad_tomato", (0.0, 0.0, 0.0), (-50.0, 30.0, 20.0), 0.8, ), diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 9130d1c90b..f8660a8918 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -251,7 +251,7 @@ pub enum ItemKind { Armor(armor::Armor), Glider(Glider), Consumable { - kind: String, + kind: ConsumableKind, effect: Vec, }, Throwable { @@ -270,6 +270,12 @@ pub enum ItemKind { }, } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum ConsumableKind { + Potion, + Food, +} + impl ItemKind { pub fn is_equippable(&self) -> bool { matches!( diff --git a/common/src/comp/inventory/mod.rs b/common/src/comp/inventory/mod.rs index 7152f130a2..772b3cd9ce 100644 --- a/common/src/comp/inventory/mod.rs +++ b/common/src/comp/inventory/mod.rs @@ -9,7 +9,10 @@ use vek::Vec3; use crate::{ comp::{ inventory::{ - item::{tool::AbilityMap, ItemDef, ItemKind, MaterialStatManifest, TagExampleInfo}, + item::{ + tool::AbilityMap, ConsumableKind, ItemDef, ItemKind, MaterialStatManifest, + TagExampleInfo, + }, loadout::Loadout, slot::{EquipSlot, Slot, SlotError}, }, @@ -803,7 +806,7 @@ impl Component for Inventory { pub enum InventoryUpdateEvent { Init, Used, - Consumed(String), + Consumed(ConsumableKind), Gave, Given, Swapped, diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 2e91ab1aaa..ffb5e484f5 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -287,7 +287,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv match item.kind() { ItemKind::Consumable { kind, effect, .. } => { maybe_effect = Some(effect.clone()); - Some(comp::InventoryUpdateEvent::Consumed(kind.clone())) + Some(comp::InventoryUpdateEvent::Consumed(*kind)) }, ItemKind::Throwable { kind, .. } => { if let Some(pos) = diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index 4c3c295f17..6518da74fc 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -92,7 +92,7 @@ use common::{ assets::{self, AssetExt, AssetHandle}, comp::{ beam, biped_large, biped_small, humanoid, - item::{ItemKind, ToolKind}, + item::{ConsumableKind, ItemKind, ToolKind}, object, poise::PoiseState, quadruped_low, quadruped_medium, quadruped_small, Body, CharacterAbilityType, @@ -276,7 +276,7 @@ pub enum SfxInventoryEvent { CollectedTool(ToolKind), CollectedItem(String), CollectFailed, - Consumed(String), + Consumed(ConsumableKind), Debug, Dropped, Given, @@ -308,7 +308,7 @@ impl From<&InventoryUpdateEvent> for SfxEvent { SfxEvent::Inventory(SfxInventoryEvent::CollectFailed) }, InventoryUpdateEvent::Consumed(consumable) => { - SfxEvent::Inventory(SfxInventoryEvent::Consumed(consumable.clone())) + SfxEvent::Inventory(SfxInventoryEvent::Consumed(*consumable)) }, InventoryUpdateEvent::Debug => SfxEvent::Inventory(SfxInventoryEvent::Debug), InventoryUpdateEvent::Dropped => SfxEvent::Inventory(SfxInventoryEvent::Dropped), diff --git a/voxygen/src/hud/item_imgs.rs b/voxygen/src/hud/item_imgs.rs index 185d9b0998..01d60ac658 100644 --- a/voxygen/src/hud/item_imgs.rs +++ b/voxygen/src/hud/item_imgs.rs @@ -49,7 +49,7 @@ impl From<&T> for ItemKey { ItemKind::Glider(Glider { kind, .. }) => ItemKey::Glider(kind.clone()), ItemKind::Armor(Armor { kind, .. }) => ItemKey::Armor(kind.clone()), ItemKind::Utility { kind, .. } => ItemKey::Utility(*kind), - ItemKind::Consumable { kind, .. } => ItemKey::Consumable(kind.clone()), + ItemKind::Consumable { .. } => ItemKey::Consumable(item_definition_id.to_owned()), ItemKind::Throwable { kind, .. } => ItemKey::Throwable(*kind), ItemKind::Ingredient { kind, .. } => ItemKey::Ingredient(kind.clone()), ItemKind::TagExamples { item_ids } => ItemKey::TagExamples( From 3559ce580372635f7d8fa67cb664f226e7392bb8 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 24 Jun 2021 20:38:11 -0500 Subject: [PATCH 2/7] Added UseItem character state. --- common/src/comp/character_state.rs | 2 + common/src/states/mod.rs | 1 + common/src/states/use_item.rs | 123 +++++++++++++++++++++++ common/src/states/utils.rs | 9 +- common/systems/src/character_behavior.rs | 2 + common/systems/src/stats.rs | 3 +- 6 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 common/src/states/use_item.rs diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 87102015bb..1b8c1fd2d7 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -105,6 +105,8 @@ pub enum CharacterState { SelfBuff(self_buff::Data), /// Creates sprites around the caster SpriteSummon(sprite_summon::Data), + /// Handles logic for using an item so it is not simply instant + UseItem(use_item::Data), } impl CharacterState { diff --git a/common/src/states/mod.rs b/common/src/states/mod.rs index 0e63dd48d4..bc1777bfe8 100644 --- a/common/src/states/mod.rs +++ b/common/src/states/mod.rs @@ -29,5 +29,6 @@ pub mod spin_melee; pub mod sprite_summon; pub mod stunned; pub mod talk; +pub mod use_item; pub mod utils; pub mod wielding; diff --git a/common/src/states/use_item.rs b/common/src/states/use_item.rs new file mode 100644 index 0000000000..951f69a5d2 --- /dev/null +++ b/common/src/states/use_item.rs @@ -0,0 +1,123 @@ +use super::utils::*; +use crate::{ + comp::{ + inventory::{ + item::{ConsumableKind, ItemKind}, + slot::Slot, + }, + CharacterState, StateUpdate, + }, + states::behavior::{CharacterBehavior, JoinData}, +}; +use serde::{Deserialize, Serialize}; +use std::time::Duration; + +/// Separated out to condense update portions of character state +#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct StaticData { + /// Buildup to item use + pub buildup_duration: Duration, + /// Duration of item use + pub use_duration: Duration, + /// Recovery after item use + pub recover_duration: Duration, + /// Inventory slot to use item from + pub inv_slot: Slot, + /// Kind of item used + pub item_kind: ItemUseKind, +} + +#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct Data { + /// Struct containing data that does not change over the course of the + /// character state + pub static_data: StaticData, + /// Timer for each stage + pub timer: Duration, + /// What section the character stage is in + pub stage_section: StageSection, + /// Had weapon + pub was_wielded: bool, + /// Was sneaking + pub was_sneak: bool, +} + +impl CharacterBehavior for Data { + fn behavior(&self, data: &JoinData) -> StateUpdate { + let mut update = StateUpdate::from(data); + + match self.stage_section { + StageSection::Buildup => { + if self.timer < self.static_data.buildup_duration { + // Build up + update.character = CharacterState::UseItem(Data { + timer: tick_attack_or_default(data, self.timer, None), + ..*self + }); + } else { + // Transitions to use section of stage + update.character = CharacterState::UseItem(Data { + timer: Duration::default(), + stage_section: StageSection::Use, + ..*self + }); + } + }, + StageSection::Use => { + if self.timer < self.static_data.use_duration { + // Item use + update.character = CharacterState::UseItem(Data { + timer: tick_attack_or_default(data, self.timer, None), + ..*self + }); + } else { + // Transitions to recover section of stage + update.character = CharacterState::UseItem(Data { + timer: Duration::default(), + stage_section: StageSection::Recover, + ..*self + }); + } + }, + StageSection::Recover => { + if self.timer < self.static_data.recover_duration { + // Recovery + update.character = CharacterState::UseItem(Data { + timer: tick_attack_or_default(data, self.timer, None), + ..*self + }); + } else { + // Done + if self.was_wielded { + update.character = CharacterState::Wielding; + } else if self.was_sneak { + update.character = CharacterState::Sneak; + } else { + update.character = CharacterState::Idle; + } + } + }, + _ => { + // If it somehow ends up in an incorrect stage section + update.character = CharacterState::Idle; + }, + } + + update + } +} + +/// Used to control effects based off of the type of item used +#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] +pub enum ItemUseKind { + Consumable(ConsumableKind), +} + +impl From<&ItemKind> for Option { + fn from(item_kind: &ItemKind) -> Self { + match item_kind { + ItemKind::Consumable { kind, .. } => Some(ItemUseKind::Consumable(*kind)), + _ => None, + } + } +} diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index d18830cf56..dadb6b4c8d 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -836,12 +836,15 @@ pub fn tick_attack_or_default( #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub enum StageSection { Buildup, - Swing, Recover, Charge, - Cast, - Shoot, Movement, + // TODO: Consolidate these to `Action` + // Code reviewers: comment here to remind me to open beginner issue + Swing, + Shoot, + Cast, + Use, } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/systems/src/character_behavior.rs b/common/systems/src/character_behavior.rs index 1782ef693f..b54bf021e7 100644 --- a/common/systems/src/character_behavior.rs +++ b/common/systems/src/character_behavior.rs @@ -332,6 +332,7 @@ impl<'a> System<'a> for Sys { CharacterState::BasicSummon(data) => data.handle_event(&j, action), CharacterState::SelfBuff(data) => data.handle_event(&j, action), CharacterState::SpriteSummon(data) => data.handle_event(&j, action), + CharacterState::UseItem(data) => data.handle_event(&j, action), }; local_emitter.append(&mut state_update.local_events); server_emitter.append(&mut state_update.server_events); @@ -388,6 +389,7 @@ impl<'a> System<'a> for Sys { CharacterState::BasicSummon(data) => data.behavior(&j), CharacterState::SelfBuff(data) => data.behavior(&j), CharacterState::SpriteSummon(data) => data.behavior(&j), + CharacterState::UseItem(data) => data.behavior(&j), }; local_emitter.append(&mut state_update.local_events); diff --git a/common/systems/src/stats.rs b/common/systems/src/stats.rs index 50a7578e8c..f047902707 100644 --- a/common/systems/src/stats.rs +++ b/common/systems/src/stats.rs @@ -289,7 +289,8 @@ impl<'a> System<'a> for Sys { CharacterState::Roll { .. } | CharacterState::Climb { .. } | CharacterState::Stunned { .. } - | CharacterState::BasicBlock { .. } => {}, + | CharacterState::BasicBlock { .. } + | CharacterState::UseItem { .. } => {}, } } From 9ff7ecea81b664182302b97c74e1a6ba5c1eece0 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 25 Jun 2021 17:58:22 -0500 Subject: [PATCH 3/7] Item use now goes through use item character state if it is a consumable. --- common/src/states/use_item.rs | 31 ++++++++++++++----- common/src/states/utils.rs | 57 ++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/common/src/states/use_item.rs b/common/src/states/use_item.rs index 951f69a5d2..342369307d 100644 --- a/common/src/states/use_item.rs +++ b/common/src/states/use_item.rs @@ -5,8 +5,9 @@ use crate::{ item::{ConsumableKind, ItemKind}, slot::Slot, }, - CharacterState, StateUpdate, + CharacterState, InventoryManip, StateUpdate, }, + event::ServerEvent, states::behavior::{CharacterBehavior, JoinData}, }; use serde::{Deserialize, Serialize}; @@ -25,6 +26,10 @@ pub struct StaticData { pub inv_slot: Slot, /// Kind of item used pub item_kind: ItemUseKind, + /// Had weapon wielded + pub was_wielded: bool, + /// Was sneaking + pub was_sneak: bool, } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -36,16 +41,23 @@ pub struct Data { pub timer: Duration, /// What section the character stage is in pub stage_section: StageSection, - /// Had weapon - pub was_wielded: bool, - /// Was sneaking - pub was_sneak: bool, } impl CharacterBehavior for Data { fn behavior(&self, data: &JoinData) -> StateUpdate { let mut update = StateUpdate::from(data); + match self.static_data.item_kind { + ItemUseKind::Consumable(ConsumableKind::Potion) => { + handle_orientation(data, &mut update, 1.0); + handle_move(data, &mut update, 1.0); + }, + ItemUseKind::Consumable(ConsumableKind::Food) => { + handle_orientation(data, &mut update, 0.0); + handle_move(data, &mut update, 0.0); + }, + } + match self.stage_section { StageSection::Buildup => { if self.timer < self.static_data.buildup_duration { @@ -61,6 +73,11 @@ impl CharacterBehavior for Data { stage_section: StageSection::Use, ..*self }); + // Create inventory manipulation event + let inv_manip = InventoryManip::Use(self.static_data.inv_slot); + update + .server_events + .push_front(ServerEvent::InventoryManip(data.entity, inv_manip)); } }, StageSection::Use => { @@ -88,9 +105,9 @@ impl CharacterBehavior for Data { }); } else { // Done - if self.was_wielded { + if self.static_data.was_wielded { update.character = CharacterState::Wielding; - } else if self.was_sneak { + } else if self.static_data.was_sneak { update.character = CharacterState::Sneak; } else { update.character = CharacterState::Idle; diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index dadb6b4c8d..2032cc8080 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -2,8 +2,8 @@ use crate::{ combat, comp::{ biped_large, biped_small, - inventory::slot::EquipSlot, - item::{Hands, ItemKind, Tool, ToolKind}, + inventory::slot::{EquipSlot, Slot}, + item::{ConsumableKind, Hands, ItemKind, Tool, ToolKind}, quadruped_low, quadruped_medium, quadruped_small, skills::{Skill, SwimSkill}, theropod, Body, CharacterAbility, CharacterState, Density, InputAttr, InputKind, @@ -575,9 +575,56 @@ pub fn handle_manipulate_loadout( update: &mut StateUpdate, inv_action: InventoryAction, ) { - update - .server_events - .push_front(ServerEvent::InventoryManip(data.entity, inv_action.into())); + use use_item::ItemUseKind; + if let InventoryAction::Use(Slot::Inventory(slot)) = inv_action { + // If inventory action is using a slot, and slot is in the inventory + // TODO: Do some non lazy way of handling the possibility that items equipped in + // the loadout will have effects that are desired to be non-instantaneous + if let Some(item_kind) = data + .inventory + .get(slot) + .and_then(|item| Option::::from(item.kind())) + { + // (buildup, use, recover) + let durations = match item_kind { + ItemUseKind::Consumable(ConsumableKind::Potion) => ( + Duration::from_secs_f32(0.25), + Duration::from_secs_f32(1.0), + Duration::from_secs_f32(0.25), + ), + ItemUseKind::Consumable(ConsumableKind::Food) => ( + Duration::from_secs_f32(1.0), + Duration::from_secs_f32(5.0), + Duration::from_secs_f32(1.0), + ), + }; + // If item returns a valid kind for item use, do into use item character state + update.character = CharacterState::UseItem(use_item::Data { + static_data: use_item::StaticData { + buildup_duration: durations.0, + use_duration: durations.1, + recover_duration: durations.2, + inv_slot: Slot::Inventory(slot), + item_kind, + was_wielded: matches!(data.character, CharacterState::Wielding), + was_sneak: matches!(data.character, CharacterState::Sneak), + }, + timer: Duration::default(), + stage_section: StageSection::Buildup, + }); + } else { + // Else emit inventory action instantnaneously + update + .server_events + .push_front(ServerEvent::InventoryManip(data.entity, inv_action.into())); + } + } else { + // Else if inventory action is not item use, or if slot is in loadout, just do + // event instantaneously + update + .server_events + .push_front(ServerEvent::InventoryManip(data.entity, inv_action.into())); + } } /// Checks that player can wield the glider and updates `CharacterState` if so From 37c6fe9ee80b923fb63b0d779757f42e9f15c88c Mon Sep 17 00:00:00 2001 From: jshipsey Date: Fri, 25 Jun 2021 22:48:48 -0400 Subject: [PATCH 4/7] anims --- common/src/comp/character_state.rs | 1 + common/src/states/utils.rs | 8 +- frame-trace_1624490729496.json | 29 ++++++ frame-trace_1624496547100.json | 19 ++++ frame-trace_1624499190101.json | 29 ++++++ voxygen/anim/src/character/consume.rs | 128 ++++++++++++++++++++++++++ voxygen/anim/src/character/mod.rs | 17 ++-- voxygen/src/scene/figure/mod.rs | 21 +++++ 8 files changed, 240 insertions(+), 12 deletions(-) create mode 100644 frame-trace_1624490729496.json create mode 100644 frame-trace_1624496547100.json create mode 100644 frame-trace_1624499190101.json create mode 100644 voxygen/anim/src/character/consume.rs diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 1b8c1fd2d7..1b917e7178 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -177,6 +177,7 @@ impl CharacterState { | CharacterState::Shockwave(_) | CharacterState::BasicBeam(_) | CharacterState::Stunned(_) + | CharacterState::UseItem(_) | CharacterState::Wielding | CharacterState::Talk | CharacterState::HealingBeam(_) diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 2032cc8080..fd45293eb4 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -588,14 +588,14 @@ pub fn handle_manipulate_loadout( // (buildup, use, recover) let durations = match item_kind { ItemUseKind::Consumable(ConsumableKind::Potion) => ( - Duration::from_secs_f32(0.25), - Duration::from_secs_f32(1.0), - Duration::from_secs_f32(0.25), + Duration::from_secs_f32(0.1), + Duration::from_secs_f32(1.1), + Duration::from_secs_f32(0.1), ), ItemUseKind::Consumable(ConsumableKind::Food) => ( Duration::from_secs_f32(1.0), Duration::from_secs_f32(5.0), - Duration::from_secs_f32(1.0), + Duration::from_secs_f32(0.5), ), }; // If item returns a valid kind for item use, do into use item character state diff --git a/frame-trace_1624490729496.json b/frame-trace_1624490729496.json new file mode 100644 index 0000000000..d89a3bdcdb --- /dev/null +++ b/frame-trace_1624490729496.json @@ -0,0 +1,29 @@ +{ +"traceEvents": [ +{ "pid":1, "tid":1, "ts":1624490729402630.3, "dur":4148.4832763671875, "ph":"X", "name":"frame" }, +{ "pid":1, "tid":1, "ts":1624490729402665, "dur":160.45570373535156, "ph":"X", "name":"shadow_pass" }, +{ "pid":1, "tid":1, "ts":1624490729402665.8, "dur":149.25003051757813, "ph":"X", "name":"direcred_terrain_shadows" }, +{ "pid":1, "tid":1, "ts":1624490729402815.5, "dur":9.5367431640625, "ph":"X", "name":"direcred_figure_shadows" }, +{ "pid":1, "tid":1, "ts":1624490729402828, "dur":200.74844360351563, "ph":"X", "name":"point shadows" }, +{ "pid":1, "tid":1, "ts":1624490729402845.8, "dur":18.835067749023438, "ph":"X", "name":"point shadow face-0 pass" }, +{ "pid":1, "tid":1, "ts":1624490729402876.8, "dur":20.02716064453125, "ph":"X", "name":"point shadow face-1 pass" }, +{ "pid":1, "tid":1, "ts":1624490729402908.8, "dur":21.219253540039063, "ph":"X", "name":"point shadow face-2 pass" }, +{ "pid":1, "tid":1, "ts":1624490729402942.3, "dur":20.503997802734375, "ph":"X", "name":"point shadow face-3 pass" }, +{ "pid":1, "tid":1, "ts":1624490729402975, "dur":18.358230590820313, "ph":"X", "name":"point shadow face-4 pass" }, +{ "pid":1, "tid":1, "ts":1624490729403005.5, "dur":20.503997802734375, "ph":"X", "name":"point shadow face-5 pass" }, +{ "pid":1, "tid":1, "ts":1624490729403062.5, "dur":2062.7975463867188, "ph":"X", "name":"first_pass" }, +{ "pid":1, "tid":1, "ts":1624490729403063, "dur":51.021575927734375, "ph":"X", "name":"figures" }, +{ "pid":1, "tid":1, "ts":1624490729403114.3, "dur":1763.3438110351563, "ph":"X", "name":"terrain" }, +{ "pid":1, "tid":1, "ts":1624490729404879, "dur":56.02836608886719, "ph":"X", "name":"figures" }, +{ "pid":1, "tid":1, "ts":1624490729404936, "dur":116.58668518066406, "ph":"X", "name":"lod_terrain" }, +{ "pid":1, "tid":1, "ts":1624490729405053.5, "dur":0.2384185791015625, "ph":"X", "name":"skybox" }, +{ "pid":1, "tid":1, "ts":1624490729405055, "dur":31.232833862304688, "ph":"X", "name":"sprites" }, +{ "pid":1, "tid":1, "ts":1624490729405086.5, "dur":1.1920928955078125, "ph":"X", "name":"fluid" }, +{ "pid":1, "tid":1, "ts":1624490729405088.5, "dur":34.809112548828125, "ph":"X", "name":"particles" }, +{ "pid":1, "tid":1, "ts":1624490729405124.8, "dur":0.7152557373046875, "ph":"X", "name":"debug" }, +{ "pid":1, "tid":1, "ts":1624490729405145.3, "dur":1360.6548309326172, "ph":"X", "name":"second_pass" }, +{ "pid":1, "tid":1, "ts":1624490729406520, "dur":255.34629821777344, "ph":"X", "name":"third_pass" }, +{ "pid":1, "tid":1, "ts":1624490729406520, "dur":229.12025451660156, "ph":"X", "name":"postprocess" }, +{ "pid":1, "tid":1, "ts":1624490729406749.5, "dur":24.557113647460938, "ph":"X", "name":"ui" } +] +} diff --git a/frame-trace_1624496547100.json b/frame-trace_1624496547100.json new file mode 100644 index 0000000000..bed1a8574b --- /dev/null +++ b/frame-trace_1624496547100.json @@ -0,0 +1,19 @@ +{ +"traceEvents": [ +{ "pid":1, "tid":1, "ts":1624496546983163, "dur":5097.150802612305, "ph":"X", "name":"frame" }, +{ "pid":1, "tid":1, "ts":1624496546983189.5, "dur":2680.7785034179688, "ph":"X", "name":"first_pass" }, +{ "pid":1, "tid":1, "ts":1624496546983190.8, "dur":49.591064453125, "ph":"X", "name":"figures" }, +{ "pid":1, "tid":1, "ts":1624496546983241.5, "dur":371.69456481933594, "ph":"X", "name":"terrain" }, +{ "pid":1, "tid":1, "ts":1624496546983614.3, "dur":0.7152557373046875, "ph":"X", "name":"figures" }, +{ "pid":1, "tid":1, "ts":1624496546983615.3, "dur":335.45494079589844, "ph":"X", "name":"lod_terrain" }, +{ "pid":1, "tid":1, "ts":1624496546983951.3, "dur":22.649765014648438, "ph":"X", "name":"skybox" }, +{ "pid":1, "tid":1, "ts":1624496546983973.8, "dur":22.172927856445313, "ph":"X", "name":"sprites" }, +{ "pid":1, "tid":1, "ts":1624496546983996, "dur":1871.347427368164, "ph":"X", "name":"fluid" }, +{ "pid":1, "tid":1, "ts":1624496546985868, "dur":0, "ph":"X", "name":"particles" }, +{ "pid":1, "tid":1, "ts":1624496546985869.5, "dur":0.7152557373046875, "ph":"X", "name":"debug" }, +{ "pid":1, "tid":1, "ts":1624496546985886.3, "dur":2170.562744140625, "ph":"X", "name":"second_pass" }, +{ "pid":1, "tid":1, "ts":1624496546988067.5, "dur":190.73486328125, "ph":"X", "name":"third_pass" }, +{ "pid":1, "tid":1, "ts":1624496546988067.8, "dur":188.35067749023438, "ph":"X", "name":"postprocess" }, +{ "pid":1, "tid":1, "ts":1624496546988255.8, "dur":1.6689300537109375, "ph":"X", "name":"ui" } +] +} diff --git a/frame-trace_1624499190101.json b/frame-trace_1624499190101.json new file mode 100644 index 0000000000..79b526c239 --- /dev/null +++ b/frame-trace_1624499190101.json @@ -0,0 +1,29 @@ +{ +"traceEvents": [ +{ "pid":1, "tid":1, "ts":1624499189977124.5, "dur":5191.564559936523, "ph":"X", "name":"frame" }, +{ "pid":1, "tid":1, "ts":1624499189977170.8, "dur":362.396240234375, "ph":"X", "name":"shadow_pass" }, +{ "pid":1, "tid":1, "ts":1624499189977171.8, "dur":352.3826599121094, "ph":"X", "name":"direcred_terrain_shadows" }, +{ "pid":1, "tid":1, "ts":1624499189977524.8, "dur":7.8678131103515625, "ph":"X", "name":"direcred_figure_shadows" }, +{ "pid":1, "tid":1, "ts":1624499189977535.5, "dur":323.29559326171875, "ph":"X", "name":"point shadows" }, +{ "pid":1, "tid":1, "ts":1624499189977546.8, "dur":39.81590270996094, "ph":"X", "name":"point shadow face-0 pass" }, +{ "pid":1, "tid":1, "ts":1624499189977605, "dur":44.58427429199219, "ph":"X", "name":"point shadow face-1 pass" }, +{ "pid":1, "tid":1, "ts":1624499189977656, "dur":46.96846008300781, "ph":"X", "name":"point shadow face-2 pass" }, +{ "pid":1, "tid":1, "ts":1624499189977711.3, "dur":43.15376281738281, "ph":"X", "name":"point shadow face-3 pass" }, +{ "pid":1, "tid":1, "ts":1624499189977762.8, "dur":40.29273986816406, "ph":"X", "name":"point shadow face-4 pass" }, +{ "pid":1, "tid":1, "ts":1624499189977809.5, "dur":46.96846008300781, "ph":"X", "name":"point shadow face-5 pass" }, +{ "pid":1, "tid":1, "ts":1624499189977879.5, "dur":2310.2760314941406, "ph":"X", "name":"first_pass" }, +{ "pid":1, "tid":1, "ts":1624499189977881.3, "dur":10.251998901367188, "ph":"X", "name":"figures" }, +{ "pid":1, "tid":1, "ts":1624499189977892.5, "dur":1368.2842254638672, "ph":"X", "name":"terrain" }, +{ "pid":1, "tid":1, "ts":1624499189979261.5, "dur":159.5020294189453, "ph":"X", "name":"figures" }, +{ "pid":1, "tid":1, "ts":1624499189979421.5, "dur":728.607177734375, "ph":"X", "name":"lod_terrain" }, +{ "pid":1, "tid":1, "ts":1624499189980150.5, "dur":18.596649169921875, "ph":"X", "name":"skybox" }, +{ "pid":1, "tid":1, "ts":1624499189980170.5, "dur":0.476837158203125, "ph":"X", "name":"sprites" }, +{ "pid":1, "tid":1, "ts":1624499189980171, "dur":1.1920928955078125, "ph":"X", "name":"fluid" }, +{ "pid":1, "tid":1, "ts":1624499189980172.8, "dur":14.543533325195313, "ph":"X", "name":"particles" }, +{ "pid":1, "tid":1, "ts":1624499189980188.5, "dur":0.476837158203125, "ph":"X", "name":"debug" }, +{ "pid":1, "tid":1, "ts":1624499189980201.8, "dur":1928.3294677734375, "ph":"X", "name":"second_pass" }, +{ "pid":1, "tid":1, "ts":1624499189982139.3, "dur":174.04556274414063, "ph":"X", "name":"third_pass" }, +{ "pid":1, "tid":1, "ts":1624499189982140.3, "dur":171.18453979492188, "ph":"X", "name":"postprocess" }, +{ "pid":1, "tid":1, "ts":1624499189982312.8, "dur":0.476837158203125, "ph":"X", "name":"ui" } +] +} diff --git a/voxygen/anim/src/character/consume.rs b/voxygen/anim/src/character/consume.rs new file mode 100644 index 0000000000..b76f8d5468 --- /dev/null +++ b/voxygen/anim/src/character/consume.rs @@ -0,0 +1,128 @@ +use super::{ + super::{vek::*, Animation}, + CharacterSkeleton, SkeletonAttr, +}; +use common::{ + comp::item::ConsumableKind, + states::{use_item::ItemUseKind, utils::StageSection}, +}; + +pub struct ConsumeAnimation; + +impl Animation for ConsumeAnimation { + type Dependency<'a> = (f32, Option, Option); + type Skeleton = CharacterSkeleton; + + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_consume\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_consume")] + fn update_skeleton_inner<'a>( + skeleton: &Self::Skeleton, + (_global_time, stage_section, item_kind): Self::Dependency<'a>, + anim_time: f32, + _rate: &mut f32, + s_a: &SkeletonAttr, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); + + match item_kind { + Some(ItemUseKind::Consumable(ConsumableKind::Potion)) => { + let (move1, move2, move3) = match stage_section { + Some(StageSection::Buildup) => (anim_time, 0.0, 0.0), + Some(StageSection::Use) => (1.0, (anim_time * 8.0).sin(), 0.0), + Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(0.25)), + _ => (0.0, 0.0, 0.0), + }; + let pullback = 1.0 - move3; + let move2 = move2 * pullback; + let move1 = move1 * pullback; + next.head.orientation = Quaternion::rotation_x(move1 * 0.5 + move2 * -0.05); + + next.hand_r.position = Vec3::new( + s_a.hand.0 + move1 * -4.0, + s_a.hand.1 + move1 * 6.0, + s_a.hand.2 + move1 * 10.0 + move2 * -1.0, + ); + next.hand_r.orientation = Quaternion::rotation_x(move1 * 2.3 + move2 * -0.2) + * Quaternion::rotation_y(move1 * 1.2); + next.chest.orientation = Quaternion::rotation_x(move1 * 0.25); + next.hand_l.position = Vec3::new( + -s_a.hand.0 + move1 * 3.0, + s_a.hand.1 + move1 * 2.0, + s_a.hand.2, + ); + + next.hand_l.orientation = + Quaternion::rotation_x(move1 * 0.8) * Quaternion::rotation_y(move1 * -0.5); + }, + Some(ItemUseKind::Consumable(ConsumableKind::Food)) => { + let (move1, move2, move3) = match stage_section { + Some(StageSection::Buildup) => (anim_time, 0.0, 0.0), + Some(StageSection::Use) => (1.0, (anim_time * 12.0).sin(), 0.0), + Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(0.25)), + _ => (0.0, 0.0, 0.0), + }; + let pullback = 1.0 - move3; + let move2 = move2 * pullback; + let move1 = move1 * pullback; + next.head.position = + Vec3::new(0.0, s_a.head.0 + move1 * 2.0, s_a.head.1 + move1 * 1.0); + next.head.orientation = + Quaternion::rotation_x(move1 * -0.3) * Quaternion::rotation_z(move2 * -0.15); + + next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + move1 * -3.0); + next.chest.orientation = + Quaternion::rotation_x(move1 * 0.3) * Quaternion::rotation_z(move2 * 0.05); + + next.belt.position = Vec3::new(0.0, s_a.belt.0 + move1 * 1.0, s_a.belt.1); + next.belt.orientation = Quaternion::rotation_x(move1 * 0.2); + + next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1); + + next.shorts.position = Vec3::new(0.0, s_a.shorts.0 + move1 * 3.0, s_a.shorts.1); + next.shorts.orientation = Quaternion::rotation_x(move1 * 0.7); + + next.hand_l.position = Vec3::new( + -s_a.hand.0 + move1 * 3.0 + move2 * -1.0, + s_a.hand.1 + move1 * 5.0, + s_a.hand.2 + move1 * 3.0 + move2 * -2.0, + ); + + next.hand_l.orientation = Quaternion::rotation_x(move1 * 1.2) + * Quaternion::rotation_y(move1 * -0.5 + move2 * 0.3); + + next.hand_r.position = Vec3::new( + s_a.hand.0 + move1 * -3.0 + move2 * -1.0, + s_a.hand.1 + move1 * 5.0, + s_a.hand.2 + move1 * 3.0 + move2 * 2.0, + ); + next.hand_r.orientation = Quaternion::rotation_x(move1 * 1.2) + * Quaternion::rotation_y(move1 * 0.5 + move2 * 0.3); + + next.foot_l.position = Vec3::new( + -s_a.foot.0, + s_a.foot.1 + move1 * 5.0, + s_a.foot.2 + move1 * 2.0, + ); + next.foot_l.orientation = Quaternion::rotation_x(move1 * 1.2); + + next.foot_r.position = Vec3::new( + s_a.foot.0, + s_a.foot.1 + move1 * 5.0, + s_a.foot.2 + move1 * 2.0, + ); + next.foot_r.orientation = Quaternion::rotation_x(move1 * 1.2); + + next.shoulder_l.position = + Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2); + + next.shoulder_r.position = + Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2); + }, + _ => {}, + } + + next + } +} diff --git a/voxygen/anim/src/character/mod.rs b/voxygen/anim/src/character/mod.rs index ad446fcff1..bacee0fc74 100644 --- a/voxygen/anim/src/character/mod.rs +++ b/voxygen/anim/src/character/mod.rs @@ -4,6 +4,7 @@ pub mod beta; pub mod block; pub mod chargeswing; pub mod climb; +pub mod consume; pub mod dance; pub mod dash; pub mod equip; @@ -32,14 +33,14 @@ pub mod wield; // Reexports pub use self::{ alpha::AlphaAnimation, beam::BeamAnimation, beta::BetaAnimation, block::BlockAnimation, - chargeswing::ChargeswingAnimation, climb::ClimbAnimation, dance::DanceAnimation, - dash::DashAnimation, equip::EquipAnimation, glidewield::GlideWieldAnimation, - gliding::GlidingAnimation, idle::IdleAnimation, jump::JumpAnimation, leapmelee::LeapAnimation, - repeater::RepeaterAnimation, roll::RollAnimation, run::RunAnimation, - shockwave::ShockwaveAnimation, shoot::ShootAnimation, sit::SitAnimation, sneak::SneakAnimation, - spin::SpinAnimation, spinmelee::SpinMeleeAnimation, staggered::StaggeredAnimation, - stand::StandAnimation, stunned::StunnedAnimation, swim::SwimAnimation, - swimwield::SwimWieldAnimation, talk::TalkAnimation, wield::WieldAnimation, + chargeswing::ChargeswingAnimation, climb::ClimbAnimation, consume::ConsumeAnimation, + dance::DanceAnimation, dash::DashAnimation, equip::EquipAnimation, + glidewield::GlideWieldAnimation, gliding::GlidingAnimation, idle::IdleAnimation, + jump::JumpAnimation, leapmelee::LeapAnimation, repeater::RepeaterAnimation, + roll::RollAnimation, run::RunAnimation, shockwave::ShockwaveAnimation, shoot::ShootAnimation, + sit::SitAnimation, sneak::SneakAnimation, spin::SpinAnimation, spinmelee::SpinMeleeAnimation, + staggered::StaggeredAnimation, stand::StandAnimation, stunned::StunnedAnimation, + swim::SwimAnimation, swimwield::SwimWieldAnimation, talk::TalkAnimation, wield::WieldAnimation, }; use super::{make_bone, vek::*, FigureBoneData, Skeleton}; use common::comp; diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 8a2699c75c..bd563961be 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -1426,6 +1426,27 @@ impl FigureMgr { skeleton_attr, ) }, + CharacterState::UseItem(s) => { + let stage_time = s.timer.as_secs_f32(); + let item_kind = s.static_data.item_kind; + let stage_progress = match s.stage_section { + StageSection::Buildup => { + stage_time / s.static_data.buildup_duration.as_secs_f32() + }, + StageSection::Use => stage_time, + StageSection::Recover => { + stage_time / s.static_data.recover_duration.as_secs_f32() + }, + _ => 0.0, + }; + anim::character::ConsumeAnimation::update_skeleton( + &target_base, + (time, Some(s.stage_section), Some(item_kind)), + stage_progress, + &mut state_animation_rate, + skeleton_attr, + ) + }, CharacterState::Equipping { .. } => { anim::character::EquipAnimation::update_skeleton( &target_base, From 8a9de26132c69a6a773f958d7a6dbffed996146e Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 26 Jun 2021 22:42:44 -0500 Subject: [PATCH 5/7] Food now applies buff at end of state. Rolling and poise states now cancel the potion buff. UseItem character state now checks that the item in the slot has the same item_definition_id as when the entity enters the state. Rolling can no cancel item use. Rolling now checks for move_dir instead of velocity. --- common/src/comp/ability.rs | 2 +- common/src/states/use_item.rs | 72 ++++++++++++++++++++---- common/src/states/utils.rs | 11 ++-- common/systems/src/character_behavior.rs | 8 +++ 4 files changed, 76 insertions(+), 17 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index d8b1413fa7..65e82a8c66 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -339,7 +339,7 @@ impl CharacterAbility { match self { CharacterAbility::Roll { energy_cost, .. } => { data.physics.on_ground.is_some() - && data.vel.0.xy().magnitude_squared() > 0.5 + && data.inputs.move_dir.magnitude_squared() > 0.25 && update .energy .try_change_by(-(*energy_cost as i32), EnergySource::Ability) diff --git a/common/src/states/use_item.rs b/common/src/states/use_item.rs index 342369307d..c36d30c5aa 100644 --- a/common/src/states/use_item.rs +++ b/common/src/states/use_item.rs @@ -1,9 +1,10 @@ use super::utils::*; use crate::{ comp::{ + buff::{BuffChange, BuffKind}, inventory::{ item::{ConsumableKind, ItemKind}, - slot::Slot, + slot::{InvSlotId, Slot}, }, CharacterState, InventoryManip, StateUpdate, }, @@ -14,7 +15,7 @@ use serde::{Deserialize, Serialize}; use std::time::Duration; /// Separated out to condense update portions of character state -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct StaticData { /// Buildup to item use pub buildup_duration: Duration, @@ -23,7 +24,9 @@ pub struct StaticData { /// Recovery after item use pub recover_duration: Duration, /// Inventory slot to use item from - pub inv_slot: Slot, + pub inv_slot: InvSlotId, + /// Item definition id, used to verify that slot still has the correct item + pub item_definition_id: String, /// Kind of item used pub item_kind: ItemUseKind, /// Had weapon wielded @@ -32,7 +35,7 @@ pub struct StaticData { pub was_sneak: bool, } -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Data { /// Struct containing data that does not change over the course of the /// character state @@ -58,48 +61,59 @@ impl CharacterBehavior for Data { }, } + let use_point = match self.static_data.item_kind { + ItemUseKind::Consumable(ConsumableKind::Potion) => UsePoint::BuildupUse, + ItemUseKind::Consumable(ConsumableKind::Food) => UsePoint::UseRecover, + }; + match self.stage_section { StageSection::Buildup => { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::UseItem(Data { + static_data: self.static_data.clone(), timer: tick_attack_or_default(data, self.timer, None), ..*self }); } else { // Transitions to use section of stage update.character = CharacterState::UseItem(Data { + static_data: self.static_data.clone(), timer: Duration::default(), stage_section: StageSection::Use, - ..*self }); - // Create inventory manipulation event - let inv_manip = InventoryManip::Use(self.static_data.inv_slot); - update - .server_events - .push_front(ServerEvent::InventoryManip(data.entity, inv_manip)); + if let UsePoint::BuildupUse = use_point { + // Create inventory manipulation event + use_item(data, &mut update, self); + } } }, StageSection::Use => { if self.timer < self.static_data.use_duration { // Item use update.character = CharacterState::UseItem(Data { + static_data: self.static_data.clone(), timer: tick_attack_or_default(data, self.timer, None), ..*self }); } else { // Transitions to recover section of stage update.character = CharacterState::UseItem(Data { + static_data: self.static_data.clone(), timer: Duration::default(), stage_section: StageSection::Recover, - ..*self }); + if let UsePoint::UseRecover = use_point { + // Create inventory manipulation event + use_item(data, &mut update, self); + } } }, StageSection::Recover => { if self.timer < self.static_data.recover_duration { // Recovery update.character = CharacterState::UseItem(Data { + static_data: self.static_data.clone(), timer: tick_attack_or_default(data, self.timer, None), ..*self }); @@ -120,6 +134,17 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + handle_state_interrupt(data, &mut update, false); + + if matches!(update.character, CharacterState::Roll(_)) { + // Remove potion effect if left the use item state early by rolling + update.server_events.push_front(ServerEvent::Buff { + entity: data.entity, + buff_change: BuffChange::RemoveByKind(BuffKind::Potion), + }); + } + update } } @@ -138,3 +163,28 @@ impl From<&ItemKind> for Option { } } } + +/// Used to control when the item is used in the state +enum UsePoint { + /// Between buildup and use + BuildupUse, + /// Between use and recover + UseRecover, +} + +fn use_item(data: &JoinData, update: &mut StateUpdate, state: &Data) { + // Check if the same item is in the slot + let item_is_same = data + .inventory + .get(state.static_data.inv_slot) + .map_or(false, |item| { + item.item_definition_id() == state.static_data.item_definition_id + }); + if item_is_same { + // Create inventory manipulation event + let inv_manip = InventoryManip::Use(Slot::Inventory(state.static_data.inv_slot)); + update + .server_events + .push_front(ServerEvent::InventoryManip(data.entity, inv_manip)); + } +} diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index fd45293eb4..bc0120627e 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -576,14 +576,14 @@ pub fn handle_manipulate_loadout( inv_action: InventoryAction, ) { use use_item::ItemUseKind; - if let InventoryAction::Use(Slot::Inventory(slot)) = inv_action { + if let InventoryAction::Use(Slot::Inventory(inv_slot)) = inv_action { // If inventory action is using a slot, and slot is in the inventory // TODO: Do some non lazy way of handling the possibility that items equipped in // the loadout will have effects that are desired to be non-instantaneous - if let Some(item_kind) = data + if let Some((item_kind, item)) = data .inventory - .get(slot) - .and_then(|item| Option::::from(item.kind())) + .get(inv_slot) + .and_then(|item| Option::::from(item.kind()).zip(Some(item))) { // (buildup, use, recover) let durations = match item_kind { @@ -604,8 +604,9 @@ pub fn handle_manipulate_loadout( buildup_duration: durations.0, use_duration: durations.1, recover_duration: durations.2, - inv_slot: Slot::Inventory(slot), + inv_slot, item_kind, + item_definition_id: item.item_definition_id().to_string(), was_wielded: matches!(data.character, CharacterState::Wielding), was_sneak: matches!(data.character, CharacterState::Sneak), }, diff --git a/common/systems/src/character_behavior.rs b/common/systems/src/character_behavior.rs index b54bf021e7..b6915984e7 100644 --- a/common/systems/src/character_behavior.rs +++ b/common/systems/src/character_behavior.rs @@ -165,6 +165,14 @@ impl<'a> System<'a> for Sys { let was_wielded = char_state.get_unchecked().is_wield(); let poise_state = poise.poise_state(); let pos = pos.0; + // Remove potion buff if knocked into poise state + if !matches!(poise_state, PoiseState::Normal) { + use comp::buff::{BuffChange, BuffKind}; + server_emitter.emit(ServerEvent::Buff { + entity, + buff_change: BuffChange::RemoveByKind(BuffKind::Potion), + }); + } match poise_state { PoiseState::Normal => {}, PoiseState::Interrupted => { From 381c7121c6752cc34b4e241c62480b6a424efd0d Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 26 Jun 2021 22:48:43 -0500 Subject: [PATCH 6/7] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b4690b7f3..1e2e9f7459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Players can press H to greet others - Ability to toggle chat visibility - Added gem rings with various stat improvements. +- Animations for using consumables. ### Changed From f5533cdb924644b296bcf069442d4ce0971c51c8 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 29 Jun 2021 05:58:50 -0500 Subject: [PATCH 7/7] Moved match on ItemUseKind to create durations to a function under ItemUseKind. --- common/src/states/use_item.rs | 18 ++++++++++++++++++ common/src/states/utils.rs | 22 +++++----------------- frame-trace_1624490729496.json | 29 ----------------------------- frame-trace_1624496547100.json | 19 ------------------- frame-trace_1624499190101.json | 29 ----------------------------- 5 files changed, 23 insertions(+), 94 deletions(-) delete mode 100644 frame-trace_1624490729496.json delete mode 100644 frame-trace_1624496547100.json delete mode 100644 frame-trace_1624499190101.json diff --git a/common/src/states/use_item.rs b/common/src/states/use_item.rs index c36d30c5aa..1df7960fa5 100644 --- a/common/src/states/use_item.rs +++ b/common/src/states/use_item.rs @@ -164,6 +164,24 @@ impl From<&ItemKind> for Option { } } +impl ItemUseKind { + /// Returns (buildup, use, recover) + pub fn durations(&self) -> (Duration, Duration, Duration) { + match self { + Self::Consumable(ConsumableKind::Potion) => ( + Duration::from_secs_f32(0.1), + Duration::from_secs_f32(1.1), + Duration::from_secs_f32(0.1), + ), + Self::Consumable(ConsumableKind::Food) => ( + Duration::from_secs_f32(1.0), + Duration::from_secs_f32(5.0), + Duration::from_secs_f32(0.5), + ), + } + } +} + /// Used to control when the item is used in the state enum UsePoint { /// Between buildup and use diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index bc0120627e..c9550723a2 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -3,7 +3,7 @@ use crate::{ comp::{ biped_large, biped_small, inventory::slot::{EquipSlot, Slot}, - item::{ConsumableKind, Hands, ItemKind, Tool, ToolKind}, + item::{Hands, ItemKind, Tool, ToolKind}, quadruped_low, quadruped_medium, quadruped_small, skills::{Skill, SwimSkill}, theropod, Body, CharacterAbility, CharacterState, Density, InputAttr, InputKind, @@ -585,25 +585,13 @@ pub fn handle_manipulate_loadout( .get(inv_slot) .and_then(|item| Option::::from(item.kind()).zip(Some(item))) { - // (buildup, use, recover) - let durations = match item_kind { - ItemUseKind::Consumable(ConsumableKind::Potion) => ( - Duration::from_secs_f32(0.1), - Duration::from_secs_f32(1.1), - Duration::from_secs_f32(0.1), - ), - ItemUseKind::Consumable(ConsumableKind::Food) => ( - Duration::from_secs_f32(1.0), - Duration::from_secs_f32(5.0), - Duration::from_secs_f32(0.5), - ), - }; + let (buildup_duration, use_duration, recover_duration) = item_kind.durations(); // If item returns a valid kind for item use, do into use item character state update.character = CharacterState::UseItem(use_item::Data { static_data: use_item::StaticData { - buildup_duration: durations.0, - use_duration: durations.1, - recover_duration: durations.2, + buildup_duration, + use_duration, + recover_duration, inv_slot, item_kind, item_definition_id: item.item_definition_id().to_string(), diff --git a/frame-trace_1624490729496.json b/frame-trace_1624490729496.json deleted file mode 100644 index d89a3bdcdb..0000000000 --- a/frame-trace_1624490729496.json +++ /dev/null @@ -1,29 +0,0 @@ -{ -"traceEvents": [ -{ "pid":1, "tid":1, "ts":1624490729402630.3, "dur":4148.4832763671875, "ph":"X", "name":"frame" }, -{ "pid":1, "tid":1, "ts":1624490729402665, "dur":160.45570373535156, "ph":"X", "name":"shadow_pass" }, -{ "pid":1, "tid":1, "ts":1624490729402665.8, "dur":149.25003051757813, "ph":"X", "name":"direcred_terrain_shadows" }, -{ "pid":1, "tid":1, "ts":1624490729402815.5, "dur":9.5367431640625, "ph":"X", "name":"direcred_figure_shadows" }, -{ "pid":1, "tid":1, "ts":1624490729402828, "dur":200.74844360351563, "ph":"X", "name":"point shadows" }, -{ "pid":1, "tid":1, "ts":1624490729402845.8, "dur":18.835067749023438, "ph":"X", "name":"point shadow face-0 pass" }, -{ "pid":1, "tid":1, "ts":1624490729402876.8, "dur":20.02716064453125, "ph":"X", "name":"point shadow face-1 pass" }, -{ "pid":1, "tid":1, "ts":1624490729402908.8, "dur":21.219253540039063, "ph":"X", "name":"point shadow face-2 pass" }, -{ "pid":1, "tid":1, "ts":1624490729402942.3, "dur":20.503997802734375, "ph":"X", "name":"point shadow face-3 pass" }, -{ "pid":1, "tid":1, "ts":1624490729402975, "dur":18.358230590820313, "ph":"X", "name":"point shadow face-4 pass" }, -{ "pid":1, "tid":1, "ts":1624490729403005.5, "dur":20.503997802734375, "ph":"X", "name":"point shadow face-5 pass" }, -{ "pid":1, "tid":1, "ts":1624490729403062.5, "dur":2062.7975463867188, "ph":"X", "name":"first_pass" }, -{ "pid":1, "tid":1, "ts":1624490729403063, "dur":51.021575927734375, "ph":"X", "name":"figures" }, -{ "pid":1, "tid":1, "ts":1624490729403114.3, "dur":1763.3438110351563, "ph":"X", "name":"terrain" }, -{ "pid":1, "tid":1, "ts":1624490729404879, "dur":56.02836608886719, "ph":"X", "name":"figures" }, -{ "pid":1, "tid":1, "ts":1624490729404936, "dur":116.58668518066406, "ph":"X", "name":"lod_terrain" }, -{ "pid":1, "tid":1, "ts":1624490729405053.5, "dur":0.2384185791015625, "ph":"X", "name":"skybox" }, -{ "pid":1, "tid":1, "ts":1624490729405055, "dur":31.232833862304688, "ph":"X", "name":"sprites" }, -{ "pid":1, "tid":1, "ts":1624490729405086.5, "dur":1.1920928955078125, "ph":"X", "name":"fluid" }, -{ "pid":1, "tid":1, "ts":1624490729405088.5, "dur":34.809112548828125, "ph":"X", "name":"particles" }, -{ "pid":1, "tid":1, "ts":1624490729405124.8, "dur":0.7152557373046875, "ph":"X", "name":"debug" }, -{ "pid":1, "tid":1, "ts":1624490729405145.3, "dur":1360.6548309326172, "ph":"X", "name":"second_pass" }, -{ "pid":1, "tid":1, "ts":1624490729406520, "dur":255.34629821777344, "ph":"X", "name":"third_pass" }, -{ "pid":1, "tid":1, "ts":1624490729406520, "dur":229.12025451660156, "ph":"X", "name":"postprocess" }, -{ "pid":1, "tid":1, "ts":1624490729406749.5, "dur":24.557113647460938, "ph":"X", "name":"ui" } -] -} diff --git a/frame-trace_1624496547100.json b/frame-trace_1624496547100.json deleted file mode 100644 index bed1a8574b..0000000000 --- a/frame-trace_1624496547100.json +++ /dev/null @@ -1,19 +0,0 @@ -{ -"traceEvents": [ -{ "pid":1, "tid":1, "ts":1624496546983163, "dur":5097.150802612305, "ph":"X", "name":"frame" }, -{ "pid":1, "tid":1, "ts":1624496546983189.5, "dur":2680.7785034179688, "ph":"X", "name":"first_pass" }, -{ "pid":1, "tid":1, "ts":1624496546983190.8, "dur":49.591064453125, "ph":"X", "name":"figures" }, -{ "pid":1, "tid":1, "ts":1624496546983241.5, "dur":371.69456481933594, "ph":"X", "name":"terrain" }, -{ "pid":1, "tid":1, "ts":1624496546983614.3, "dur":0.7152557373046875, "ph":"X", "name":"figures" }, -{ "pid":1, "tid":1, "ts":1624496546983615.3, "dur":335.45494079589844, "ph":"X", "name":"lod_terrain" }, -{ "pid":1, "tid":1, "ts":1624496546983951.3, "dur":22.649765014648438, "ph":"X", "name":"skybox" }, -{ "pid":1, "tid":1, "ts":1624496546983973.8, "dur":22.172927856445313, "ph":"X", "name":"sprites" }, -{ "pid":1, "tid":1, "ts":1624496546983996, "dur":1871.347427368164, "ph":"X", "name":"fluid" }, -{ "pid":1, "tid":1, "ts":1624496546985868, "dur":0, "ph":"X", "name":"particles" }, -{ "pid":1, "tid":1, "ts":1624496546985869.5, "dur":0.7152557373046875, "ph":"X", "name":"debug" }, -{ "pid":1, "tid":1, "ts":1624496546985886.3, "dur":2170.562744140625, "ph":"X", "name":"second_pass" }, -{ "pid":1, "tid":1, "ts":1624496546988067.5, "dur":190.73486328125, "ph":"X", "name":"third_pass" }, -{ "pid":1, "tid":1, "ts":1624496546988067.8, "dur":188.35067749023438, "ph":"X", "name":"postprocess" }, -{ "pid":1, "tid":1, "ts":1624496546988255.8, "dur":1.6689300537109375, "ph":"X", "name":"ui" } -] -} diff --git a/frame-trace_1624499190101.json b/frame-trace_1624499190101.json deleted file mode 100644 index 79b526c239..0000000000 --- a/frame-trace_1624499190101.json +++ /dev/null @@ -1,29 +0,0 @@ -{ -"traceEvents": [ -{ "pid":1, "tid":1, "ts":1624499189977124.5, "dur":5191.564559936523, "ph":"X", "name":"frame" }, -{ "pid":1, "tid":1, "ts":1624499189977170.8, "dur":362.396240234375, "ph":"X", "name":"shadow_pass" }, -{ "pid":1, "tid":1, "ts":1624499189977171.8, "dur":352.3826599121094, "ph":"X", "name":"direcred_terrain_shadows" }, -{ "pid":1, "tid":1, "ts":1624499189977524.8, "dur":7.8678131103515625, "ph":"X", "name":"direcred_figure_shadows" }, -{ "pid":1, "tid":1, "ts":1624499189977535.5, "dur":323.29559326171875, "ph":"X", "name":"point shadows" }, -{ "pid":1, "tid":1, "ts":1624499189977546.8, "dur":39.81590270996094, "ph":"X", "name":"point shadow face-0 pass" }, -{ "pid":1, "tid":1, "ts":1624499189977605, "dur":44.58427429199219, "ph":"X", "name":"point shadow face-1 pass" }, -{ "pid":1, "tid":1, "ts":1624499189977656, "dur":46.96846008300781, "ph":"X", "name":"point shadow face-2 pass" }, -{ "pid":1, "tid":1, "ts":1624499189977711.3, "dur":43.15376281738281, "ph":"X", "name":"point shadow face-3 pass" }, -{ "pid":1, "tid":1, "ts":1624499189977762.8, "dur":40.29273986816406, "ph":"X", "name":"point shadow face-4 pass" }, -{ "pid":1, "tid":1, "ts":1624499189977809.5, "dur":46.96846008300781, "ph":"X", "name":"point shadow face-5 pass" }, -{ "pid":1, "tid":1, "ts":1624499189977879.5, "dur":2310.2760314941406, "ph":"X", "name":"first_pass" }, -{ "pid":1, "tid":1, "ts":1624499189977881.3, "dur":10.251998901367188, "ph":"X", "name":"figures" }, -{ "pid":1, "tid":1, "ts":1624499189977892.5, "dur":1368.2842254638672, "ph":"X", "name":"terrain" }, -{ "pid":1, "tid":1, "ts":1624499189979261.5, "dur":159.5020294189453, "ph":"X", "name":"figures" }, -{ "pid":1, "tid":1, "ts":1624499189979421.5, "dur":728.607177734375, "ph":"X", "name":"lod_terrain" }, -{ "pid":1, "tid":1, "ts":1624499189980150.5, "dur":18.596649169921875, "ph":"X", "name":"skybox" }, -{ "pid":1, "tid":1, "ts":1624499189980170.5, "dur":0.476837158203125, "ph":"X", "name":"sprites" }, -{ "pid":1, "tid":1, "ts":1624499189980171, "dur":1.1920928955078125, "ph":"X", "name":"fluid" }, -{ "pid":1, "tid":1, "ts":1624499189980172.8, "dur":14.543533325195313, "ph":"X", "name":"particles" }, -{ "pid":1, "tid":1, "ts":1624499189980188.5, "dur":0.476837158203125, "ph":"X", "name":"debug" }, -{ "pid":1, "tid":1, "ts":1624499189980201.8, "dur":1928.3294677734375, "ph":"X", "name":"second_pass" }, -{ "pid":1, "tid":1, "ts":1624499189982139.3, "dur":174.04556274414063, "ph":"X", "name":"third_pass" }, -{ "pid":1, "tid":1, "ts":1624499189982140.3, "dur":171.18453979492188, "ph":"X", "name":"postprocess" }, -{ "pid":1, "tid":1, "ts":1624499189982312.8, "dur":0.476837158203125, "ph":"X", "name":"ui" } -] -}