mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added equip slots for other weapons.
This commit is contained in:
parent
16b952e01e
commit
9173dca03f
@ -805,8 +805,8 @@ fn equipped_item_and_tool(inv: &Inventory, slot: EquipSlot) -> Option<(&Item, &T
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn get_weapons(inv: &Inventory) -> (Option<ToolKind>, Option<ToolKind>) {
|
||||
(
|
||||
equipped_item_and_tool(inv, EquipSlot::Mainhand).map(|(_, tool)| tool.kind),
|
||||
equipped_item_and_tool(inv, EquipSlot::Offhand).map(|(_, tool)| tool.kind),
|
||||
equipped_item_and_tool(inv, EquipSlot::ActiveMainhand).map(|(_, tool)| tool.kind),
|
||||
equipped_item_and_tool(inv, EquipSlot::ActiveOffhand).map(|(_, tool)| tool.kind),
|
||||
)
|
||||
}
|
||||
|
||||
@ -845,14 +845,14 @@ fn weapon_skills(inventory: &Inventory, skill_set: &SkillSet) -> f32 {
|
||||
|
||||
fn get_weapon_rating(inventory: &Inventory, msm: &MaterialStatManifest) -> f32 {
|
||||
let mainhand_rating =
|
||||
if let Some((item, _)) = equipped_item_and_tool(inventory, EquipSlot::Mainhand) {
|
||||
if let Some((item, _)) = equipped_item_and_tool(inventory, EquipSlot::ActiveMainhand) {
|
||||
weapon_rating(item, msm)
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
let offhand_rating =
|
||||
if let Some((item, _)) = equipped_item_and_tool(inventory, EquipSlot::Offhand) {
|
||||
if let Some((item, _)) = equipped_item_and_tool(inventory, EquipSlot::ActiveOffhand) {
|
||||
weapon_rating(item, msm)
|
||||
} else {
|
||||
0.0
|
||||
|
@ -75,8 +75,10 @@ impl Loadout {
|
||||
(EquipSlot::Armor(ArmorSlot::Bag2), "bag2".to_string()),
|
||||
(EquipSlot::Armor(ArmorSlot::Bag3), "bag3".to_string()),
|
||||
(EquipSlot::Armor(ArmorSlot::Bag4), "bag4".to_string()),
|
||||
(EquipSlot::Mainhand, "active_item".to_string()),
|
||||
(EquipSlot::Offhand, "second_item".to_string()),
|
||||
(EquipSlot::ActiveMainhand, "active_mainhand".to_string()),
|
||||
(EquipSlot::ActiveOffhand, "active_offhand".to_string()),
|
||||
(EquipSlot::InactiveMainhand, "inactive_mainhand".to_string()),
|
||||
(EquipSlot::InactiveOffhand, "inactive_offhand".to_string()),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(equip_slot, persistence_key)| LoadoutSlot::new(equip_slot, persistence_key))
|
||||
|
@ -30,7 +30,7 @@ use tracing::warn;
|
||||
/// // Build a loadout with character starter defaults and a specific sword with default sword abilities
|
||||
/// let loadout = LoadoutBuilder::new()
|
||||
/// .defaults()
|
||||
/// .active_item(Some(Item::new_from_asset_expect("common.items.weapons.sword.steel-8")))
|
||||
/// .active_mainhand(Some(Item::new_from_asset_expect("common.items.weapons.sword.steel-8")))
|
||||
/// .build();
|
||||
/// ```
|
||||
#[derive(Clone)]
|
||||
@ -376,7 +376,7 @@ impl LoadoutBuilder {
|
||||
match config {
|
||||
Adlet => match active_tool_kind {
|
||||
Some(ToolKind::Bow) => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.adlet.head.adlet_bow",
|
||||
)))
|
||||
@ -397,7 +397,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Some(ToolKind::Spear) | Some(ToolKind::Staff) => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.adlet.head.adlet_spear",
|
||||
)))
|
||||
@ -417,11 +417,11 @@ impl LoadoutBuilder {
|
||||
"common.items.npc_armor.biped_small.adlet.tail.adlet",
|
||||
)))
|
||||
.build(),
|
||||
_ => LoadoutBuilder::new().active_item(active_item).build(),
|
||||
_ => LoadoutBuilder::new().active_mainhand(active_item).build(),
|
||||
},
|
||||
Gnarling => match active_tool_kind {
|
||||
Some(ToolKind::Bow) => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.gnarling.head.gnarling",
|
||||
)))
|
||||
@ -442,7 +442,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Some(ToolKind::Staff) => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.gnarling.head.gnarling",
|
||||
)))
|
||||
@ -463,7 +463,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Some(ToolKind::Spear) => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.gnarling.head.gnarling",
|
||||
)))
|
||||
@ -480,10 +480,10 @@ impl LoadoutBuilder {
|
||||
"common.items.npc_armor.biped_small.gnarling.pants.gnarling",
|
||||
)))
|
||||
.build(),
|
||||
_ => LoadoutBuilder::new().active_item(active_item).build(),
|
||||
_ => LoadoutBuilder::new().active_mainhand(active_item).build(),
|
||||
},
|
||||
Sahagin => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.sahagin.head.sahagin",
|
||||
)))
|
||||
@ -504,7 +504,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Haniwa => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.haniwa.head.haniwa",
|
||||
)))
|
||||
@ -522,7 +522,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Myrmidon => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.myrmidon.head.myrmidon",
|
||||
)))
|
||||
@ -543,7 +543,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Husk => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.head(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_small.husk.head.husk",
|
||||
)))
|
||||
@ -561,7 +561,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Guard => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.leather_plate.shoulder",
|
||||
)))
|
||||
@ -703,7 +703,7 @@ impl LoadoutBuilder {
|
||||
}
|
||||
}
|
||||
LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.twigsflowers.shoulder",
|
||||
)))
|
||||
@ -742,7 +742,7 @@ impl LoadoutBuilder {
|
||||
.build()
|
||||
},
|
||||
Outcast => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.cloth_purple.shoulder",
|
||||
)))
|
||||
@ -767,7 +767,7 @@ impl LoadoutBuilder {
|
||||
})
|
||||
.build(),
|
||||
Highwayman => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.swift.shoulder",
|
||||
)))
|
||||
@ -795,7 +795,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Bandit => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.assassin.shoulder",
|
||||
)))
|
||||
@ -823,7 +823,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
CultistNovice => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.steel.shoulder",
|
||||
)))
|
||||
@ -854,7 +854,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
CultistAcolyte => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.cultist.shoulder",
|
||||
)))
|
||||
@ -885,7 +885,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Warlord => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.warlord.shoulder",
|
||||
)))
|
||||
@ -916,7 +916,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Warlock => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.shoulder(Some(Item::new_from_asset_expect(
|
||||
"common.items.armor.warlock.shoulder",
|
||||
)))
|
||||
@ -947,7 +947,7 @@ impl LoadoutBuilder {
|
||||
)))
|
||||
.build(),
|
||||
Villager => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.chest(Some(Item::new_from_asset_expect(
|
||||
match rand::thread_rng().gen_range(0..10) {
|
||||
0 => "common.items.armor.misc.chest.worker_green_0",
|
||||
@ -981,36 +981,46 @@ impl LoadoutBuilder {
|
||||
match body {
|
||||
Body::BipedLarge(b) => match b.species {
|
||||
biped_large::Species::Mindflayer => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.chest(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.biped_large.mindflayer",
|
||||
)))
|
||||
.build(),
|
||||
_ => LoadoutBuilder::new().active_item(active_item).build(),
|
||||
_ => LoadoutBuilder::new().active_mainhand(active_item).build(),
|
||||
},
|
||||
Body::Golem(g) => match g.species {
|
||||
golem::Species::ClayGolem => LoadoutBuilder::new()
|
||||
.active_item(active_item)
|
||||
.active_mainhand(active_item)
|
||||
.chest(Some(Item::new_from_asset_expect(
|
||||
"common.items.npc_armor.golem.claygolem",
|
||||
)))
|
||||
.build(),
|
||||
_ => LoadoutBuilder::new().active_item(active_item).build(),
|
||||
_ => LoadoutBuilder::new().active_mainhand(active_item).build(),
|
||||
},
|
||||
_ => LoadoutBuilder::new().active_item(active_item).build(),
|
||||
_ => LoadoutBuilder::new().active_mainhand(active_item).build(),
|
||||
}
|
||||
};
|
||||
|
||||
Self(loadout)
|
||||
}
|
||||
|
||||
pub fn active_item(mut self, item: Option<Item>) -> Self {
|
||||
self.0.swap(EquipSlot::Mainhand, item);
|
||||
pub fn active_mainhand(mut self, item: Option<Item>) -> Self {
|
||||
self.0.swap(EquipSlot::ActiveMainhand, item);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn second_item(mut self, item: Option<Item>) -> Self {
|
||||
self.0.swap(EquipSlot::Offhand, item);
|
||||
pub fn active_offhand(mut self, item: Option<Item>) -> Self {
|
||||
self.0.swap(EquipSlot::ActiveOffhand, item);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn inactive_mainhand(mut self, item: Option<Item>) -> Self {
|
||||
self.0.swap(EquipSlot::InactiveMainhand, item);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn inactive_offhand(mut self, item: Option<Item>) -> Self {
|
||||
self.0.swap(EquipSlot::InactiveOffhand, item);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -553,10 +553,11 @@ impl Inventory {
|
||||
self.get(inv_slot)
|
||||
.and_then(|item| self.loadout.get_slot_to_equip_into(item.kind()))
|
||||
.map(|equip_slot| {
|
||||
// Special case when equipping into main hand - swap with offhand first
|
||||
if equip_slot == EquipSlot::Mainhand {
|
||||
// Special case when equipping into active main hand - swap with active offhand
|
||||
// first
|
||||
if equip_slot == EquipSlot::ActiveMainhand {
|
||||
self.loadout
|
||||
.swap_slots(EquipSlot::Mainhand, EquipSlot::Offhand);
|
||||
.swap_slots(EquipSlot::ActiveMainhand, EquipSlot::InactiveMainhand);
|
||||
}
|
||||
|
||||
self.swap_inventory_loadout(inv_slot, equip_slot)
|
||||
|
@ -81,8 +81,10 @@ impl From<InvSlotId> for SlotId {
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize, Deserialize)]
|
||||
pub enum EquipSlot {
|
||||
Armor(ArmorSlot),
|
||||
Mainhand,
|
||||
Offhand,
|
||||
ActiveMainhand,
|
||||
ActiveOffhand,
|
||||
InactiveMainhand,
|
||||
InactiveOffhand,
|
||||
Lantern,
|
||||
Glider,
|
||||
}
|
||||
@ -120,8 +122,10 @@ impl EquipSlot {
|
||||
pub fn can_hold(self, item_kind: &item::ItemKind) -> bool {
|
||||
match (self, item_kind) {
|
||||
(Self::Armor(slot), ItemKind::Armor(armor::Armor { kind, .. })) => slot.can_hold(kind),
|
||||
(Self::Mainhand, ItemKind::Tool(_)) => true,
|
||||
(Self::Offhand, ItemKind::Tool(_)) => true,
|
||||
(Self::ActiveMainhand, ItemKind::Tool(_)) => true,
|
||||
(Self::ActiveOffhand, ItemKind::Tool(_)) => true,
|
||||
(Self::InactiveMainhand, ItemKind::Tool(_)) => true,
|
||||
(Self::InactiveOffhand, ItemKind::Tool(_)) => true,
|
||||
(Self::Lantern, ItemKind::Lantern(_)) => true,
|
||||
(Self::Glider, ItemKind::Glider(_)) => true,
|
||||
_ => false,
|
||||
|
@ -14,6 +14,7 @@
|
||||
option_expect_none,
|
||||
option_unwrap_none,
|
||||
option_zip,
|
||||
or_patterns,
|
||||
trait_alias,
|
||||
type_alias_impl_trait
|
||||
)]
|
||||
|
@ -440,14 +440,34 @@ pub fn handle_wield(data: &JoinData, update: &mut StateUpdate) {
|
||||
|
||||
/// If a tool is equipped, goes into Equipping state, otherwise goes to Idle
|
||||
pub fn attempt_wield(data: &JoinData, update: &mut StateUpdate) {
|
||||
if let Some((item, ItemKind::Tool(tool))) = data
|
||||
.inventory
|
||||
.equipped(EquipSlot::Mainhand)
|
||||
.map(|i| (i, i.kind()))
|
||||
{
|
||||
// Closure to get equip time provided an equip slot if a tool is equipped in
|
||||
// equip slot
|
||||
let equip_time = |equip_slot| {
|
||||
data.inventory
|
||||
.equipped(equip_slot)
|
||||
.and_then(|item| match item.kind() {
|
||||
ItemKind::Tool(tool) => Some((item, tool)),
|
||||
_ => None,
|
||||
})
|
||||
.map(|(item, tool)| tool.equip_time(data.msm, item.components()))
|
||||
};
|
||||
|
||||
// Calcualtes time required to equip weapons, if weapon in mainhand and offhand,
|
||||
// uses maximum duration
|
||||
let mainhand_equip_time = equip_time(EquipSlot::ActiveMainhand);
|
||||
let offhand_equip_time = equip_time(EquipSlot::ActiveOffhand);
|
||||
let equip_time = match (mainhand_equip_time, offhand_equip_time) {
|
||||
(Some(a), Some(b)) => Some(a.max(b)),
|
||||
(Some(a), None) | (None, Some(a)) => Some(a),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
// Moves entity into equipping state if there is some equip time, else moves
|
||||
// intantly into wield
|
||||
if let Some(equip_time) = equip_time {
|
||||
update.character = CharacterState::Equipping(equipping::Data {
|
||||
static_data: equipping::StaticData {
|
||||
buildup_duration: tool.equip_time(data.msm, item.components()),
|
||||
buildup_duration: equip_time,
|
||||
},
|
||||
timer: Duration::default(),
|
||||
});
|
||||
@ -504,7 +524,15 @@ pub fn handle_climb(data: &JoinData, update: &mut StateUpdate) -> bool {
|
||||
|
||||
/// Checks that player can Swap Weapons and updates `Loadout` if so
|
||||
pub fn attempt_swap_equipped_weapons(data: &JoinData, update: &mut StateUpdate) {
|
||||
if data.inventory.equipped(EquipSlot::Offhand).is_some() {
|
||||
if data
|
||||
.inventory
|
||||
.equipped(EquipSlot::InactiveMainhand)
|
||||
.is_some()
|
||||
|| data
|
||||
.inventory
|
||||
.equipped(EquipSlot::InactiveOffhand)
|
||||
.is_some()
|
||||
{
|
||||
update.swap_equipped_weapons = true;
|
||||
}
|
||||
}
|
||||
@ -556,14 +584,14 @@ fn handle_ability(data: &JoinData, update: &mut StateUpdate, input: InputKind) {
|
||||
let no_main_hand = hands.0.is_none();
|
||||
// skill_index used to select ability for the AbilityKey::Skill2 input
|
||||
let (equip_slot, skill_index) = if no_main_hand {
|
||||
(Some(EquipSlot::Offhand), 1)
|
||||
(Some(EquipSlot::ActiveOffhand), 1)
|
||||
} else if always_main_hand {
|
||||
(Some(EquipSlot::Mainhand), 0)
|
||||
(Some(EquipSlot::ActiveMainhand), 0)
|
||||
} else {
|
||||
match hands {
|
||||
(Some(Hands::Two), _) => (Some(EquipSlot::Mainhand), 1),
|
||||
(_, Some(Hands::One)) => (Some(EquipSlot::Offhand), 0),
|
||||
(Some(Hands::One), _) => (Some(EquipSlot::Mainhand), 1),
|
||||
(Some(Hands::Two), _) => (Some(EquipSlot::ActiveMainhand), 1),
|
||||
(_, Some(Hands::One)) => (Some(EquipSlot::ActiveOffhand), 0),
|
||||
(Some(Hands::One), _) => (Some(EquipSlot::ActiveMainhand), 1),
|
||||
(_, _) => (None, 0),
|
||||
}
|
||||
};
|
||||
@ -596,7 +624,11 @@ fn handle_ability(data: &JoinData, update: &mut StateUpdate, input: InputKind) {
|
||||
{
|
||||
update.character = CharacterState::from((
|
||||
&ability,
|
||||
AbilityInfo::from_input(data, matches!(equip_slot, EquipSlot::Offhand), input),
|
||||
AbilityInfo::from_input(
|
||||
data,
|
||||
matches!(equip_slot, EquipSlot::ActiveOffhand),
|
||||
input,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -640,7 +672,8 @@ pub fn handle_block_input(data: &JoinData, update: &mut StateUpdate) {
|
||||
|equip_slot| matches!(unwrap_tool_data(data, equip_slot), Some(tool) if tool.can_block());
|
||||
let hands = get_hands(data);
|
||||
if input_is_pressed(data, InputKind::Block)
|
||||
&& (can_block(EquipSlot::Mainhand) || (hands.0.is_none() && can_block(EquipSlot::Offhand)))
|
||||
&& (can_block(EquipSlot::ActiveMainhand)
|
||||
|| (hands.0.is_none() && can_block(EquipSlot::ActiveOffhand)))
|
||||
{
|
||||
let ability = CharacterAbility::default_block();
|
||||
if ability.requirements_paid(data, update) {
|
||||
@ -696,15 +729,18 @@ pub fn get_hands(data: &JoinData) -> (Option<Hands>, Option<Hands>) {
|
||||
None
|
||||
}
|
||||
};
|
||||
(hand(EquipSlot::Mainhand), hand(EquipSlot::Offhand))
|
||||
(
|
||||
hand(EquipSlot::ActiveMainhand),
|
||||
hand(EquipSlot::ActiveOffhand),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_crit_data(data: &JoinData, ai: AbilityInfo) -> (f32, f32) {
|
||||
const DEFAULT_CRIT_DATA: (f32, f32) = (0.5, 1.3);
|
||||
use HandInfo::*;
|
||||
let slot = match ai.hand {
|
||||
Some(TwoHanded) | Some(MainHand) => EquipSlot::Mainhand,
|
||||
Some(OffHand) => EquipSlot::Offhand,
|
||||
Some(TwoHanded) | Some(MainHand) => EquipSlot::ActiveMainhand,
|
||||
Some(OffHand) => EquipSlot::ActiveOffhand,
|
||||
None => return DEFAULT_CRIT_DATA,
|
||||
};
|
||||
if let Some(item) = data.inventory.equipped(slot) {
|
||||
@ -792,9 +828,9 @@ pub struct AbilityInfo {
|
||||
impl AbilityInfo {
|
||||
pub fn from_input(data: &JoinData, from_offhand: bool, input: InputKind) -> Self {
|
||||
let tool_data = if from_offhand {
|
||||
unwrap_tool_data(data, EquipSlot::Offhand)
|
||||
unwrap_tool_data(data, EquipSlot::ActiveOffhand)
|
||||
} else {
|
||||
unwrap_tool_data(data, EquipSlot::Mainhand)
|
||||
unwrap_tool_data(data, EquipSlot::ActiveMainhand)
|
||||
};
|
||||
let (tool, hand) = (
|
||||
tool_data.map(|t| t.kind),
|
||||
|
@ -60,9 +60,12 @@ impl CharacterBehavior for Data {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
match inv_action {
|
||||
InventoryAction::Drop(EquipSlot::Mainhand)
|
||||
| InventoryAction::Swap(EquipSlot::Mainhand, _)
|
||||
| InventoryAction::Swap(_, Slot::Equip(EquipSlot::Mainhand)) => {
|
||||
InventoryAction::Drop(EquipSlot::ActiveMainhand | EquipSlot::ActiveOffhand)
|
||||
| InventoryAction::Swap(EquipSlot::ActiveMainhand | EquipSlot::ActiveOffhand, _)
|
||||
| InventoryAction::Swap(
|
||||
_,
|
||||
Slot::Equip(EquipSlot::ActiveMainhand | EquipSlot::ActiveOffhand),
|
||||
) => {
|
||||
update.character = CharacterState::Idle;
|
||||
},
|
||||
_ => (),
|
||||
|
@ -51,12 +51,22 @@ fn incorporate_update(join: &mut JoinStruct, mut state_update: StateUpdate) {
|
||||
assert!(
|
||||
inventory
|
||||
.swap(
|
||||
Slot::Equip(EquipSlot::Mainhand),
|
||||
Slot::Equip(EquipSlot::Offhand),
|
||||
Slot::Equip(EquipSlot::ActiveMainhand),
|
||||
Slot::Equip(EquipSlot::InactiveMainhand),
|
||||
)
|
||||
.first()
|
||||
.is_none(),
|
||||
"Swapping main and offhand never results in leftover items",
|
||||
"Swapping active and inactive mainhand never results in leftover items",
|
||||
);
|
||||
assert!(
|
||||
inventory
|
||||
.swap(
|
||||
Slot::Equip(EquipSlot::ActiveOffhand),
|
||||
Slot::Equip(EquipSlot::InactiveOffhand),
|
||||
)
|
||||
.first()
|
||||
.is_none(),
|
||||
"Swapping active and inactive offhand never results in leftover items",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ pub fn create_character(
|
||||
|
||||
let loadout = LoadoutBuilder::new()
|
||||
.defaults()
|
||||
.active_item(Some(Item::new_from_asset_expect(&tool_id)))
|
||||
.active_mainhand(Some(Item::new_from_asset_expect(&tool_id)))
|
||||
.build();
|
||||
|
||||
let mut inventory = Inventory::new_with_loadout(loadout);
|
||||
|
@ -254,15 +254,15 @@ pub fn handle_possess(server: &mut Server, possessor_uid: Uid, possesse_uid: Uid
|
||||
assert!(
|
||||
inventory
|
||||
.swap(
|
||||
Slot::Equip(EquipSlot::Mainhand),
|
||||
Slot::Equip(EquipSlot::Offhand),
|
||||
Slot::Equip(EquipSlot::ActiveMainhand),
|
||||
Slot::Equip(EquipSlot::InactiveMainhand),
|
||||
)
|
||||
.first()
|
||||
.is_none(),
|
||||
"Swapping main and offhand never results in leftover items",
|
||||
"Swapping active and inactive mainhands never results in leftover items",
|
||||
);
|
||||
|
||||
inventory.replace_loadout_item(EquipSlot::Mainhand, Some(debug_item));
|
||||
inventory.replace_loadout_item(EquipSlot::ActiveMainhand, Some(debug_item));
|
||||
}
|
||||
|
||||
// Remove will of the entity
|
||||
|
8
server/src/migrations/V37__equip_slots.sql
Normal file
8
server/src/migrations/V37__equip_slots.sql
Normal file
@ -0,0 +1,8 @@
|
||||
-- Sets active_item to active_mainhand and second_item to inactive_mainhand.
|
||||
--
|
||||
-- second_item becomes inactive_mainhand because active_offhand is enforced to be 1h
|
||||
-- and second_item was not necessarily guaranteed to be 1h.
|
||||
UPDATE item
|
||||
SET position = 'active_mainhand' WHERE position = 'active_item';
|
||||
UPDATE item
|
||||
SET position = 'inactive_mainhand' WHERE position = 'second_item';
|
@ -1568,7 +1568,7 @@ impl<'a> AgentData<'a> {
|
||||
|
||||
let tactic = self
|
||||
.inventory
|
||||
.equipped(EquipSlot::Mainhand)
|
||||
.equipped(EquipSlot::ActiveMainhand)
|
||||
.as_ref()
|
||||
.map(|item| {
|
||||
if let Some(ability_spec) = item.ability_spec() {
|
||||
|
@ -145,7 +145,7 @@ impl CombatEventMapper {
|
||||
previous_state: &PreviousEntityState,
|
||||
inventory: &Inventory,
|
||||
) -> SfxEvent {
|
||||
if let Some(item) = inventory.equipped(EquipSlot::Mainhand) {
|
||||
if let Some(item) = inventory.equipped(EquipSlot::ActiveMainhand) {
|
||||
if let ItemKind::Tool(data) = item.kind() {
|
||||
if character_state.is_attack() {
|
||||
return SfxEvent::Attack(
|
||||
|
@ -1154,11 +1154,11 @@ impl<'a> Widget for Bag<'a> {
|
||||
}
|
||||
// Mainhand/Left-Slot
|
||||
let mainhand_item = inventory
|
||||
.equipped(EquipSlot::Mainhand)
|
||||
.equipped(EquipSlot::ActiveMainhand)
|
||||
.map(|item| item.to_owned());
|
||||
|
||||
let slot = slot_maker
|
||||
.fabricate(EquipSlot::Mainhand, [85.0; 2])
|
||||
.fabricate(EquipSlot::ActiveMainhand, [85.0; 2])
|
||||
.bottom_right_with_margins_on(state.ids.back_slot, -95.0, 0.0)
|
||||
.with_icon(self.imgs.mainhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
|
||||
.filled_slot(filled_slot);
|
||||
@ -1177,10 +1177,10 @@ impl<'a> Widget for Bag<'a> {
|
||||
}
|
||||
// Offhand/Right-Slot
|
||||
let offhand_item = inventory
|
||||
.equipped(EquipSlot::Offhand)
|
||||
.equipped(EquipSlot::ActiveOffhand)
|
||||
.map(|item| item.to_owned());
|
||||
let slot = slot_maker
|
||||
.fabricate(EquipSlot::Offhand, [85.0; 2])
|
||||
.fabricate(EquipSlot::ActiveOffhand, [85.0; 2])
|
||||
.bottom_left_with_margins_on(state.ids.feet_slot, -95.0, 0.0)
|
||||
.with_icon(self.imgs.offhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
|
||||
.filled_slot(filled_slot);
|
||||
|
@ -88,9 +88,12 @@ impl State {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let equip_slot = match (hands(EquipSlot::Mainhand), hands(EquipSlot::Offhand)) {
|
||||
(Some(_), _) => Some(EquipSlot::Mainhand),
|
||||
(_, Some(_)) => Some(EquipSlot::Offhand),
|
||||
let equip_slot = match (
|
||||
hands(EquipSlot::ActiveMainhand),
|
||||
hands(EquipSlot::ActiveOffhand),
|
||||
) {
|
||||
(Some(_), _) => Some(EquipSlot::ActiveMainhand),
|
||||
(_, Some(_)) => Some(EquipSlot::ActiveOffhand),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@ -140,14 +143,14 @@ impl State {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let active_tool_hands = hands(EquipSlot::Mainhand);
|
||||
let second_tool_hands = hands(EquipSlot::Offhand);
|
||||
let active_tool_hands = hands(EquipSlot::ActiveMainhand);
|
||||
let second_tool_hands = hands(EquipSlot::ActiveOffhand);
|
||||
|
||||
let (equip_slot, skill_index) = match (active_tool_hands, second_tool_hands) {
|
||||
(Some(Hands::Two), _) => (Some(EquipSlot::Mainhand), 1),
|
||||
(Some(_), Some(Hands::One)) => (Some(EquipSlot::Offhand), 0),
|
||||
(Some(Hands::One), _) => (Some(EquipSlot::Mainhand), 1),
|
||||
(None, Some(_)) => (Some(EquipSlot::Offhand), 1),
|
||||
(Some(Hands::Two), _) => (Some(EquipSlot::ActiveMainhand), 1),
|
||||
(Some(_), Some(Hands::One)) => (Some(EquipSlot::ActiveOffhand), 0),
|
||||
(Some(Hands::One), _) => (Some(EquipSlot::ActiveMainhand), 1),
|
||||
(None, Some(_)) => (Some(EquipSlot::ActiveOffhand), 1),
|
||||
(_, _) => (None, 0),
|
||||
};
|
||||
|
||||
|
@ -536,7 +536,7 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
.map(|item| (item.name(), item.description())),
|
||||
hotbar::SlotContents::Ability3 => content_source
|
||||
.1
|
||||
.equipped(EquipSlot::Mainhand)
|
||||
.equipped(EquipSlot::ActiveMainhand)
|
||||
.map(|i| i.kind())
|
||||
.and_then(|kind| match kind {
|
||||
ItemKind::Tool(Tool { kind, .. }) => ability_description(kind),
|
||||
@ -552,14 +552,14 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let active_tool_hands = hands(EquipSlot::Mainhand);
|
||||
let second_tool_hands = hands(EquipSlot::Offhand);
|
||||
let active_tool_hands = hands(EquipSlot::ActiveMainhand);
|
||||
let second_tool_hands = hands(EquipSlot::ActiveOffhand);
|
||||
|
||||
let equip_slot = match (active_tool_hands, second_tool_hands) {
|
||||
(Some(Hands::Two), _) => Some(EquipSlot::Mainhand),
|
||||
(Some(_), Some(Hands::One)) => Some(EquipSlot::Offhand),
|
||||
(Some(Hands::One), _) => Some(EquipSlot::Mainhand),
|
||||
(None, Some(_)) => Some(EquipSlot::Offhand),
|
||||
(Some(Hands::Two), _) => Some(EquipSlot::ActiveMainhand),
|
||||
(Some(_), Some(Hands::One)) => Some(EquipSlot::ActiveOffhand),
|
||||
(Some(Hands::One), _) => Some(EquipSlot::ActiveMainhand),
|
||||
(None, Some(_)) => Some(EquipSlot::ActiveOffhand),
|
||||
(_, _) => None,
|
||||
};
|
||||
|
||||
@ -657,8 +657,8 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
.right_from(state.ids.slot5, slot_offset)
|
||||
.set(state.ids.m1_slot_bg, ui);
|
||||
|
||||
let active_tool = get_item_and_tool(self.inventory, EquipSlot::Mainhand);
|
||||
let second_tool = get_item_and_tool(self.inventory, EquipSlot::Offhand);
|
||||
let active_tool = get_item_and_tool(self.inventory, EquipSlot::ActiveMainhand);
|
||||
let second_tool = get_item_and_tool(self.inventory, EquipSlot::ActiveOffhand);
|
||||
|
||||
let tool = match (
|
||||
active_tool.map(|(_, x)| x.hands),
|
||||
@ -700,8 +700,8 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
let active_tool = get_item_and_tool(self.inventory, EquipSlot::Mainhand);
|
||||
let second_tool = get_item_and_tool(self.inventory, EquipSlot::Offhand);
|
||||
let active_tool = get_item_and_tool(self.inventory, EquipSlot::ActiveMainhand);
|
||||
let second_tool = get_item_and_tool(self.inventory, EquipSlot::ActiveOffhand);
|
||||
|
||||
let tool = match (
|
||||
active_tool.map(|(_, x)| x.hands),
|
||||
|
@ -143,12 +143,12 @@ impl<'a> SlotKey<HotbarSource<'a>, HotbarImageSource<'a>> for HotbarSlot {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let active_tool_hands = hands(EquipSlot::Mainhand);
|
||||
let second_tool_hands = hands(EquipSlot::Offhand);
|
||||
let active_tool_hands = hands(EquipSlot::ActiveMainhand);
|
||||
let second_tool_hands = hands(EquipSlot::ActiveOffhand);
|
||||
|
||||
let equip_slot = match (active_tool_hands, second_tool_hands) {
|
||||
(Some(_), _) => Some(EquipSlot::Mainhand),
|
||||
(None, Some(_)) => Some(EquipSlot::Offhand),
|
||||
(Some(_), _) => Some(EquipSlot::ActiveMainhand),
|
||||
(None, Some(_)) => Some(EquipSlot::ActiveOffhand),
|
||||
(_, _) => None,
|
||||
};
|
||||
|
||||
@ -189,14 +189,14 @@ impl<'a> SlotKey<HotbarSource<'a>, HotbarImageSource<'a>> for HotbarSlot {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let active_tool_hands = hands(EquipSlot::Mainhand);
|
||||
let second_tool_hands = hands(EquipSlot::Offhand);
|
||||
let active_tool_hands = hands(EquipSlot::ActiveMainhand);
|
||||
let second_tool_hands = hands(EquipSlot::ActiveOffhand);
|
||||
|
||||
let (equip_slot, skill_index) = match (active_tool_hands, second_tool_hands) {
|
||||
(Some(Hands::Two), _) => (Some(EquipSlot::Mainhand), 1),
|
||||
(Some(_), Some(Hands::One)) => (Some(EquipSlot::Offhand), 0),
|
||||
(Some(Hands::One), _) => (Some(EquipSlot::Mainhand), 1),
|
||||
(None, Some(_)) => (Some(EquipSlot::Offhand), 1),
|
||||
(Some(Hands::Two), _) => (Some(EquipSlot::ActiveMainhand), 1),
|
||||
(Some(_), Some(Hands::One)) => (Some(EquipSlot::ActiveOffhand), 0),
|
||||
(Some(Hands::One), _) => (Some(EquipSlot::ActiveMainhand), 1),
|
||||
(None, Some(_)) => (Some(EquipSlot::ActiveOffhand), 1),
|
||||
(_, _) => (None, 0),
|
||||
};
|
||||
|
||||
|
@ -182,7 +182,7 @@ impl Mode {
|
||||
|
||||
let loadout = LoadoutBuilder::new()
|
||||
.defaults()
|
||||
.active_item(Some(Item::new_from_asset_expect(tool)))
|
||||
.active_mainhand(Some(Item::new_from_asset_expect(tool)))
|
||||
.build();
|
||||
|
||||
let inventory = Box::new(Inventory::new_with_loadout(loadout));
|
||||
@ -1328,7 +1328,7 @@ impl Controls {
|
||||
{
|
||||
*tool = value;
|
||||
inventory.replace_loadout_item(
|
||||
EquipSlot::Mainhand,
|
||||
EquipSlot::ActiveMainhand,
|
||||
Some(Item::new_from_asset_expect(*tool)),
|
||||
);
|
||||
}
|
||||
|
@ -221,10 +221,10 @@ impl CharacterCacheKey {
|
||||
};
|
||||
Some(CharacterToolKey {
|
||||
active: inventory
|
||||
.equipped(EquipSlot::Mainhand)
|
||||
.equipped(EquipSlot::ActiveMainhand)
|
||||
.map(tool_key_from_item),
|
||||
second: inventory
|
||||
.equipped(EquipSlot::Offhand)
|
||||
.equipped(EquipSlot::ActiveOffhand)
|
||||
.map(tool_key_from_item),
|
||||
})
|
||||
} else {
|
||||
|
@ -740,9 +740,9 @@ impl FigureMgr {
|
||||
};
|
||||
|
||||
let (active_tool_kind, active_tool_hand, active_tool_spec) =
|
||||
tool_info(EquipSlot::Mainhand);
|
||||
tool_info(EquipSlot::ActiveMainhand);
|
||||
let (second_tool_kind, second_tool_hand, second_tool_spec) =
|
||||
tool_info(EquipSlot::Offhand);
|
||||
tool_info(EquipSlot::ActiveOffhand);
|
||||
|
||||
let hands = (active_tool_hand, second_tool_hand);
|
||||
|
||||
|
@ -307,7 +307,7 @@ impl Scene {
|
||||
.clean(&mut self.col_lights, scene_data.tick);
|
||||
|
||||
let active_item_kind = inventory
|
||||
.and_then(|inv| inv.equipped(EquipSlot::Mainhand))
|
||||
.and_then(|inv| inv.equipped(EquipSlot::ActiveMainhand))
|
||||
.map(|i| i.kind());
|
||||
|
||||
let (active_tool_kind, active_tool_hand) =
|
||||
@ -318,7 +318,7 @@ impl Scene {
|
||||
};
|
||||
|
||||
let second_item_kind = inventory
|
||||
.and_then(|inv| inv.equipped(EquipSlot::Offhand))
|
||||
.and_then(|inv| inv.equipped(EquipSlot::ActiveOffhand))
|
||||
.map(|i| i.kind());
|
||||
|
||||
let (second_tool_kind, second_tool_hand) =
|
||||
|
@ -329,7 +329,7 @@ impl PlayState for SessionState {
|
||||
.borrow()
|
||||
.inventories()
|
||||
.get(player_entity)
|
||||
.and_then(|inv| inv.equipped(EquipSlot::Mainhand))
|
||||
.and_then(|inv| inv.equipped(EquipSlot::ActiveMainhand))
|
||||
.and_then(|item| item.tool())
|
||||
.map_or(false, |tool| tool.kind == ToolKind::Pick)
|
||||
&& self.client.borrow().is_wielding() == Some(true);
|
||||
|
Loading…
Reference in New Issue
Block a user