2019-09-25 15:52:58 +00:00
|
|
|
use crate::{
|
2019-10-22 18:18:40 +00:00
|
|
|
assets::{self, Asset},
|
2019-09-25 15:52:58 +00:00
|
|
|
effect::Effect,
|
|
|
|
terrain::{Block, BlockKind},
|
|
|
|
};
|
2020-01-26 22:57:06 +00:00
|
|
|
//use rand::prelude::*;
|
|
|
|
use rand::seq::SliceRandom;
|
2019-07-26 21:01:41 +00:00
|
|
|
use specs::{Component, FlaggedStorage};
|
2019-07-29 19:54:48 +00:00
|
|
|
use specs_idvs::IDVStorage;
|
2020-02-01 20:39:39 +00:00
|
|
|
use std::{fs::File, io::BufReader, time::Duration};
|
2019-05-18 16:46:14 +00:00
|
|
|
|
2019-08-27 19:56:46 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-12-29 23:47:42 +00:00
|
|
|
pub enum SwordKind {
|
|
|
|
Scimitar,
|
|
|
|
Rapier,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum ToolKind {
|
|
|
|
Sword(SwordKind),
|
2019-06-28 23:42:51 +00:00
|
|
|
Axe,
|
|
|
|
Hammer,
|
|
|
|
Bow,
|
2019-12-03 06:30:08 +00:00
|
|
|
Dagger,
|
2019-06-28 23:42:51 +00:00
|
|
|
Staff,
|
2019-12-03 06:30:08 +00:00
|
|
|
Shield,
|
2019-10-22 20:58:27 +00:00
|
|
|
Debug(Debug),
|
|
|
|
}
|
|
|
|
|
2020-01-05 23:17:22 +00:00
|
|
|
impl Default for ToolKind {
|
2020-02-03 21:02:32 +00:00
|
|
|
fn default() -> Self { Self::Axe }
|
2020-01-05 23:17:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 23:47:42 +00:00
|
|
|
impl ToolData {
|
2020-02-03 21:02:32 +00:00
|
|
|
pub fn equip_time(&self) -> Duration { Duration::from_millis(self.equip_time_millis) }
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-12-03 06:30:08 +00:00
|
|
|
pub fn attack_buildup_duration(&self) -> Duration {
|
2019-12-29 23:47:42 +00:00
|
|
|
Duration::from_millis(self.attack_buildup_millis)
|
2019-12-03 06:30:08 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-12-03 06:30:08 +00:00
|
|
|
pub fn attack_recover_duration(&self) -> Duration {
|
2019-12-29 23:47:42 +00:00
|
|
|
Duration::from_millis(self.attack_recover_millis)
|
2019-12-03 06:30:08 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-12-03 06:30:08 +00:00
|
|
|
pub fn attack_duration(&self) -> Duration {
|
|
|
|
self.attack_buildup_duration() + self.attack_recover_duration()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 20:58:27 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Debug {
|
|
|
|
Boost,
|
|
|
|
Possess,
|
2019-06-28 23:42:51 +00:00
|
|
|
}
|
2019-07-29 13:44:16 +00:00
|
|
|
|
2020-01-05 23:21:37 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-05-18 16:46:14 +00:00
|
|
|
pub enum Armor {
|
2020-02-01 20:39:39 +00:00
|
|
|
// TODO: Don't make armor be a body part. Wearing enemy's head is funny but also a creepy
|
|
|
|
// thing to do.
|
2019-06-28 08:24:13 +00:00
|
|
|
Helmet,
|
2019-06-28 23:42:51 +00:00
|
|
|
Shoulders,
|
|
|
|
Chestplate,
|
|
|
|
Belt,
|
|
|
|
Gloves,
|
|
|
|
Pants,
|
|
|
|
Boots,
|
2019-05-18 16:46:14 +00:00
|
|
|
Back,
|
|
|
|
Tabard,
|
|
|
|
Gem,
|
|
|
|
Necklace,
|
|
|
|
}
|
|
|
|
|
2020-03-04 10:09:48 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-09-25 14:56:57 +00:00
|
|
|
pub enum Consumable {
|
|
|
|
Apple,
|
2019-11-09 13:42:42 +00:00
|
|
|
Cheese,
|
2019-09-25 14:56:57 +00:00
|
|
|
Potion,
|
|
|
|
Mushroom,
|
2019-09-25 20:22:39 +00:00
|
|
|
Velorite,
|
2019-10-17 20:59:36 +00:00
|
|
|
VeloriteFrag,
|
2019-11-09 13:42:42 +00:00
|
|
|
PotionMinor,
|
2019-09-25 14:56:57 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 21:02:32 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2020-01-29 12:01:28 +00:00
|
|
|
pub enum Utility {
|
|
|
|
Collar,
|
|
|
|
}
|
|
|
|
|
2020-01-05 23:21:37 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-09-25 22:04:18 +00:00
|
|
|
pub enum Ingredient {
|
|
|
|
Flower,
|
|
|
|
Grass,
|
|
|
|
}
|
|
|
|
|
2020-01-05 23:21:37 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-12-29 23:47:42 +00:00
|
|
|
pub struct ToolData {
|
|
|
|
pub kind: ToolKind,
|
|
|
|
equip_time_millis: u64,
|
|
|
|
attack_buildup_millis: u64,
|
|
|
|
attack_recover_millis: u64,
|
|
|
|
range: u64,
|
2020-02-03 21:02:32 +00:00
|
|
|
pub base_damage: u64,
|
2019-12-29 23:47:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 23:21:37 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-10-22 18:18:40 +00:00
|
|
|
pub enum ItemKind {
|
2019-12-29 23:47:42 +00:00
|
|
|
Tool(ToolData),
|
2019-10-22 18:18:40 +00:00
|
|
|
Armor { kind: Armor, power: u32 },
|
|
|
|
Consumable { kind: Consumable, effect: Effect },
|
2020-01-29 12:01:28 +00:00
|
|
|
Utility { kind: Utility },
|
2019-10-22 18:18:40 +00:00
|
|
|
Ingredient(Ingredient),
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 18:18:40 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub struct Item {
|
|
|
|
name: String,
|
|
|
|
description: String,
|
|
|
|
pub kind: ItemKind,
|
|
|
|
}
|
2019-10-09 19:28:05 +00:00
|
|
|
|
2019-10-22 18:18:40 +00:00
|
|
|
impl Asset for Item {
|
|
|
|
const ENDINGS: &'static [&'static str] = &["ron"];
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-10-22 18:18:40 +00:00
|
|
|
fn parse(buf_reader: BufReader<File>) -> Result<Self, assets::Error> {
|
|
|
|
Ok(ron::de::from_reader(buf_reader).unwrap())
|
2019-10-09 19:28:05 +00:00
|
|
|
}
|
2019-10-22 18:18:40 +00:00
|
|
|
}
|
2019-10-09 19:28:05 +00:00
|
|
|
|
2019-10-22 18:18:40 +00:00
|
|
|
impl Item {
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn name(&self) -> &str { &self.name }
|
|
|
|
|
|
|
|
pub fn description(&self) -> &str { &self.description }
|
|
|
|
|
2019-09-25 14:56:57 +00:00
|
|
|
pub fn try_reclaim_from_block(block: Block) -> Option<Self> {
|
|
|
|
match block.kind() {
|
2019-10-22 18:18:40 +00:00
|
|
|
BlockKind::Apple => Some(assets::load_expect_cloned("common.items.apple")),
|
|
|
|
BlockKind::Mushroom => Some(assets::load_expect_cloned("common.items.mushroom")),
|
|
|
|
BlockKind::Velorite => Some(assets::load_expect_cloned("common.items.velorite")),
|
|
|
|
BlockKind::BlueFlower => Some(assets::load_expect_cloned("common.items.flowers.blue")),
|
|
|
|
BlockKind::PinkFlower => Some(assets::load_expect_cloned("common.items.flowers.pink")),
|
|
|
|
BlockKind::PurpleFlower => {
|
|
|
|
Some(assets::load_expect_cloned("common.items.flowers.purple"))
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-22 18:18:40 +00:00
|
|
|
BlockKind::RedFlower => Some(assets::load_expect_cloned("common.items.flowers.red")),
|
|
|
|
BlockKind::WhiteFlower => {
|
|
|
|
Some(assets::load_expect_cloned("common.items.flowers.white"))
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-22 18:18:40 +00:00
|
|
|
BlockKind::YellowFlower => {
|
|
|
|
Some(assets::load_expect_cloned("common.items.flowers.yellow"))
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-22 18:18:40 +00:00
|
|
|
BlockKind::Sunflower => Some(assets::load_expect_cloned("common.items.flowers.sun")),
|
|
|
|
BlockKind::LongGrass => Some(assets::load_expect_cloned("common.items.grasses.long")),
|
|
|
|
BlockKind::MediumGrass => {
|
|
|
|
Some(assets::load_expect_cloned("common.items.grasses.medium"))
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-22 18:18:40 +00:00
|
|
|
BlockKind::ShortGrass => Some(assets::load_expect_cloned("common.items.grasses.short")),
|
2020-01-26 22:57:06 +00:00
|
|
|
BlockKind::Chest => Some(assets::load_expect_cloned(
|
|
|
|
[
|
|
|
|
"common.items.apple",
|
|
|
|
"common.items.velorite",
|
|
|
|
"common.items.veloritefrag",
|
|
|
|
"common.items.cheese",
|
|
|
|
"common.items.potion_minor",
|
2020-01-29 12:01:28 +00:00
|
|
|
"common.items.collar",
|
2020-01-26 22:57:06 +00:00
|
|
|
"common.items.weapons.starter_sword",
|
|
|
|
"common.items.weapons.starter_axe",
|
|
|
|
"common.items.weapons.starter_hammer",
|
|
|
|
"common.items.weapons.starter_bow",
|
|
|
|
"common.items.weapons.starter_staff",
|
|
|
|
]
|
|
|
|
.choose(&mut rand::thread_rng())
|
|
|
|
.unwrap(), // Can't fail
|
|
|
|
)),
|
2019-09-25 14:56:57 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2019-07-25 22:52:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-18 16:46:14 +00:00
|
|
|
impl Component for Item {
|
2019-07-26 21:01:41 +00:00
|
|
|
type Storage = FlaggedStorage<Self, IDVStorage<Self>>;
|
2019-05-18 16:46:14 +00:00
|
|
|
}
|