Updated serenity version and added new commands
+ Added task.rs to handle periodic tasks
This commit is contained in:
20 files changed
+1978
-1038
No files matched your search
+46
-4
@@ -33,6 +33,26 @@ pub enum ItemType {
|
||||
GoodFortune,
|
||||
Nft,
|
||||
LicenseToBeHorny,
|
||||
KillGun,
|
||||
CancelRay,
|
||||
Helmet,
|
||||
}
|
||||
|
||||
impl ItemType {
|
||||
pub fn description(&self) -> String {
|
||||
match self {
|
||||
ItemType::CancelInsurance => "Automatically used to prevent being canceled".to_string(),
|
||||
ItemType::TheConceptOfLove => "Understand!".to_string(),
|
||||
ItemType::GoodFortune => {
|
||||
"Used to give a good fortune. `!use good fortune am I not cringe?`".to_string()
|
||||
}
|
||||
ItemType::Nft => "A Non Fungible Token on the REAL FREN blockchain network".to_string(),
|
||||
ItemType::LicenseToBeHorny => "Allows one horny time".to_string(),
|
||||
ItemType::KillGun => "Used to kill people. `!use kill gun @Austin`".to_string(),
|
||||
ItemType::CancelRay => "Used to cancel people. `!use cancel ray @Austin`".to_string(),
|
||||
ItemType::Helmet => "Automatically used to block being killed".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash, Eq, PartialEq, Copy)]
|
||||
@@ -59,6 +79,12 @@ impl FromStr for ItemType {
|
||||
Ok(ItemType::Nft)
|
||||
} else if item.starts_with("licensetobehorny") {
|
||||
Ok(ItemType::LicenseToBeHorny)
|
||||
} else if item.starts_with("killgun") {
|
||||
Ok(ItemType::KillGun)
|
||||
} else if item.starts_with("helmet") {
|
||||
Ok(ItemType::Helmet)
|
||||
} else if item.starts_with("cancelray") {
|
||||
Ok(ItemType::CancelRay)
|
||||
} else {
|
||||
Err(InventoryError::UnkownItem)
|
||||
}
|
||||
@@ -73,6 +99,9 @@ impl Display for ItemType {
|
||||
ItemType::GoodFortune => "Good Fortune".to_string(),
|
||||
ItemType::Nft => "NFT".to_string(),
|
||||
ItemType::LicenseToBeHorny => "License to be Horny".to_string(),
|
||||
ItemType::KillGun => "Kill Gun".to_string(),
|
||||
ItemType::Helmet => "Helmet".to_string(),
|
||||
ItemType::CancelRay => "Cancel Ray".to_string(),
|
||||
};
|
||||
|
||||
write!(f, "{}", name)
|
||||
@@ -88,11 +117,14 @@ pub struct InventorySlot {
|
||||
impl InventorySlot {
|
||||
pub fn value(&self) -> i64 {
|
||||
match self.item_type {
|
||||
ItemType::CancelInsurance => 50,
|
||||
ItemType::CancelInsurance => 500,
|
||||
ItemType::TheConceptOfLove => 300,
|
||||
ItemType::GoodFortune => 75,
|
||||
ItemType::Nft => 100,
|
||||
ItemType::LicenseToBeHorny => 100,
|
||||
ItemType::KillGun => 1000,
|
||||
ItemType::Helmet => 500,
|
||||
ItemType::CancelRay => 1000,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +151,8 @@ impl InventorySlot {
|
||||
pub fn use_cost(&self) -> i64 {
|
||||
match self.item_type {
|
||||
ItemType::Nft => 0,
|
||||
ItemType::Helmet => 0,
|
||||
ItemType::CancelInsurance => 0,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
@@ -205,16 +239,24 @@ impl InventoryManager {
|
||||
msg_builder.build()
|
||||
}
|
||||
|
||||
pub fn try_use_item(&mut self, item: ItemType) -> Result<Option<ItemData>, InventoryError> {
|
||||
pub fn try_use_item(
|
||||
&mut self,
|
||||
item: ItemType,
|
||||
force: bool,
|
||||
) -> Result<Option<ItemData>, InventoryError> {
|
||||
let item_slot = self
|
||||
.get_item_mut(item)
|
||||
.ok_or(InventoryError::NotEnoughItems)?;
|
||||
|
||||
if item_slot.quantity < item_slot.use_cost() {
|
||||
if item_slot.quantity < item_slot.use_cost() || item_slot.quantity == 0 {
|
||||
return Err(InventoryError::NotEnoughItems);
|
||||
}
|
||||
|
||||
item_slot.quantity -= item_slot.use_cost();
|
||||
if force {
|
||||
item_slot.quantity -= 1;
|
||||
} else {
|
||||
item_slot.quantity -= item_slot.use_cost();
|
||||
}
|
||||
|
||||
Ok(item_slot.item_data.clone())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user