Skip to content

Commit

Permalink
feat(ranks): Add Excavator rank and refine mining mechanics
Browse files Browse the repository at this point in the history
- Add new Excavator rank with custom skin and inventory loadout
- Refactor inventory slot management to use variables instead of constants
- Update ore distribution weights to include coal and rebalance percentages
- Enhance Miner rank with torch and upgraded pickaxe
- Add PartialEq, Eq traits to Rank enum
  • Loading branch information
andrewgazelka committed Nov 13, 2024
1 parent 50c1f10 commit b7193fc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 25 deletions.
59 changes: 43 additions & 16 deletions crates/hyperion-rank-tree/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ impl Team {

impl Rank {
pub fn apply_inventory(self, team: Team, inventory: &mut PlayerInventory) {
const PICKAXE_SLOT: u16 = 1;
const BUILD_SLOT: u16 = 2;
const ARROW_SLOT: u16 = 7;
const GUI_SLOT: u16 = 8;
let mut pickaxe_slot: u16 = 1;

if self == Rank::Miner {
pickaxe_slot = 1;
}

let main_slot: u16 = 0;
let build_slot: u16 = 2;
let arrow_slot: u16 = 7;
let gui_slot: u16 = 8;

let default_pickaxe = ItemBuilder::new(ItemKind::WoodenPickaxe).build();
inventory.set_hotbar(PICKAXE_SLOT, default_pickaxe);
inventory.set_hotbar(pickaxe_slot, default_pickaxe);

let default_build_item = team.build_item().count(16).build();
inventory.set_hotbar(BUILD_SLOT, default_build_item);
inventory.set_hotbar(build_slot, default_build_item);

match self {
Self::Stick => {
Expand All @@ -39,33 +45,41 @@ impl Rank {
.add_attribute(AttackDamage(3.0))
.build();

inventory.set_hotbar(0, stick);
inventory.set_hotbar(main_slot, stick);
}

Self::Archer => {
let bow = ItemBuilder::new(ItemKind::Bow).build();

inventory.set_hotbar(0, bow);
inventory.set_hotbar(main_slot, bow);

let arrow = ItemBuilder::new(ItemKind::Arrow).count(64).build();

inventory.set_hotbar(ARROW_SLOT, arrow);
inventory.set_hotbar(arrow_slot, arrow);
}
Self::Sword => {
let sword = ItemBuilder::new(ItemKind::StoneSword)
.name("§3VERTEX§f-§bSLICER")
.add_attribute(AttackDamage(3.0))
.build();

inventory.set_hotbar(0, sword);
inventory.set_hotbar(main_slot, sword);
}

Self::Miner => {
let pickaxe = ItemBuilder::new(ItemKind::WoodenPickaxe)
let torch = ItemBuilder::new(ItemKind::Torch)
.name("§3§lTORCH")
.glowing()
.add_attribute(AttackDamage(3.0))
.build();

inventory.set_hotbar(main_slot, torch);

let pickaxe = ItemBuilder::new(ItemKind::StonePickaxe)
.add_attribute(AttackDamage(2.0))
.build();

inventory.set_hotbar(0, pickaxe);
inventory.set_hotbar(pickaxe_slot, pickaxe);
}

Self::Mage => {
Expand All @@ -74,7 +88,7 @@ impl Rank {
.add_attribute(AttackDamage(2.0))
.build();

inventory.set_hotbar(0, wand);
inventory.set_hotbar(main_slot, wand);
}
Self::Knight => {
let knight_sword = ItemBuilder::new(ItemKind::IronSword)
Expand All @@ -83,21 +97,34 @@ impl Rank {
.add_attribute(AttackDamage(4.0))
.build();

inventory.set_hotbar(0, knight_sword);
inventory.set_hotbar(main_slot, knight_sword);
}
Self::Builder => {
let builder_tool = ItemBuilder::new(ItemKind::GoldenPickaxe)
.add_attribute(AttackDamage(5.0))
.build();

inventory.set_hotbar(0, builder_tool);
inventory.set_hotbar(main_slot, builder_tool);
}
Rank::Excavator => {
let pickaxe = ItemBuilder::new(ItemKind::IronPickaxe).build();

inventory.set_hotbar(pickaxe_slot, pickaxe);

let minecart = ItemBuilder::new(ItemKind::Minecart)
.name("§3§lMINECART")
.glowing()
.add_attribute(AttackDamage(3.0))
.build();

inventory.set_hotbar(main_slot, minecart);
}
}

let upgrade_item = ItemBuilder::new(ItemKind::FireworkStar)
.name("Upgrades")
.build();

inventory.set_hotbar(GUI_SLOT, upgrade_item);
inventory.set_hotbar(gui_slot, upgrade_item);
}
}
4 changes: 3 additions & 1 deletion crates/hyperion-rank-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod skin;

mod util;

#[derive(Copy, Clone, Debug, ValueEnum)]
#[derive(Copy, Clone, Debug, ValueEnum, PartialEq, Eq)]
#[repr(C)]
pub enum Rank {
/// ![Widget Example](https://i.imgur.com/pW7v0Xn.png)
Expand All @@ -17,6 +17,8 @@ pub enum Rank {
Sword,
Miner,

Excavator,

Mage,
Knight,
Builder,
Expand Down
2 changes: 2 additions & 0 deletions crates/hyperion-rank-tree/src/skin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define_skin!(ARCHER_SKIN, "skin/archer.toml");
define_skin!(MAGE_SKIN, "skin/mage.toml");
define_skin!(BUILDER_SKIN, "skin/builder.toml");
define_skin!(MINER_SKIN, "skin/miner.toml");
define_skin!(EXCAVATOR_SKIN, "skin/excavator.toml");

impl Rank {
#[must_use]
Expand All @@ -32,6 +33,7 @@ impl Rank {
Self::Mage => &MAGE_SKIN,
Self::Builder => &BUILDER_SKIN,
Self::Miner => &MINER_SKIN,
Rank::Excavator => &EXCAVATOR_SKIN,
}
}
}
5 changes: 5 additions & 0 deletions crates/hyperion-rank-tree/src/skin/excavator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://mineskin.org/
# https://namemc.com/skin/bef08f02f7e42ed9
textures = """ewogICJ0aW1lc3RhbXAiIDogMTcxNTE5Njk3MTg4MCwKICAicHJvZmlsZUlkIiA6ICJiMTJhNTI4M2U3NTM0ZmM0OGNkYzFiYTUyZGFiZTMzZCIsCiAgInByb2ZpbGVOYW1lIiA6ICJZdXVuYV9fX19fIiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzcwMWQ0YjhiMWNiNzUyOTI2YzQwZWFhZDAxNjE2MThiNWI2MzgxOWU3MzZmMWRiN2RhYmJkMmEwMGYwZTcxOGMiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ=="""

signature = """i0mOJIlO/6JCSVNrt5ZHTrbvTHj5A1Ne1RbeazsbGPXXGzSERogrRdZEXyuZKnkXyvuGVCmaZmJfCTQurrqFt8AEhO+8k85TmrhvzkN0lo2FJRtkuABNg/ZQq2gI7i+5FLMLUU/qKIbJcaVUOCPepmEbCMN+hXiSh5FO1Qh4UwGojTNhKZszd44wYHVq1sn7c6xF/yE4wCmSRIRLAGZBSngeMVufEuCCWmrDGbEJfG6webJyc5epeBo7sh36MP+7h6tHz0OAJm+rX+WVeyVTfy9+pJdONbTvY685HKS3RJ1ZLrZkeXSn6XjkqHVTTVqADw0Nag0k/Qh3Zugz5MmebtRvprEJPRD3Mgu6JQJ1qMmSWphezRmoTHReagvMsAYIKELxrtkM18cUUO2WO22ZLbTm3CEY2wN8i32HGKPyEYvllBJDrgnnvtk9OTgsV/V+JkkzVtqB8qYz9G4QV/1f6VaYL/ZwCEDwMTAqO/NQtt7ypucH5iDfqidZqm947Mx1ke3MEWvgRs9VLji4/y6mD6Omd4AYENrf77sevcvKmMznwHqX6m6FlT5mcZBJMfmYlfMH63BnsucITyLLvuWEMBxei0R73SCcgHRwsYNaj7wjgD2ItSqF5BgaM/9gTQbJRoMkwAk80bsjaE1EcZxyTkBMC1opQxwEQh/b19VbLTA="""
17 changes: 9 additions & 8 deletions events/proof-of-concept/src/command/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ pub struct ReplaceCommand;
/// Weights are roughly based on real Minecraft ore distribution
fn pick_ore() -> BlockState {
// Total weight is 100 for easy percentage calculation
const WEIGHTS: [(BlockState, u32); 5] = [
(BlockState::COBBLESTONE, 40), // 40%
(BlockState::COPPER_ORE, 35), // 35%
(BlockState::IRON_ORE, 15), // 15%
(BlockState::GOLD_ORE, 8), // 8%
(BlockState::EMERALD_ORE, 2), // 2%
const WEIGHTS: &[(BlockState, u32)] = &[
(BlockState::COBBLESTONE, 35),
(BlockState::COAL_ORE, 35),
(BlockState::COPPER_ORE, 25),
(BlockState::IRON_ORE, 15),
(BlockState::GOLD_ORE, 8),
(BlockState::EMERALD_ORE, 2),
];

let total_weight: u32 = WEIGHTS.iter().map(|(_, w)| w).sum();
let mut roll = fastrand::u32(0..total_weight);

for (block, weight) in WEIGHTS {
if roll < weight {
return block;
if roll < *weight {
return *block;
}
roll -= weight;
}
Expand Down

0 comments on commit b7193fc

Please sign in to comment.