mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added some client methods for changing abilities to hook into.
This commit is contained in:
parent
da677e8ea6
commit
b678f7f46e
@ -755,7 +755,8 @@ impl Client {
|
||||
| ClientGeneral::RequestSiteInfo(_)
|
||||
| ClientGeneral::UnlockSkillGroup(_)
|
||||
| ClientGeneral::RequestPlayerPhysics { .. }
|
||||
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
||||
| ClientGeneral::RequestLossyTerrainCompression { .. }
|
||||
| ClientGeneral::ChangeAbility { .. } => {
|
||||
#[cfg(feature = "tracy")]
|
||||
{
|
||||
ingame = 1.0;
|
||||
@ -1396,6 +1397,10 @@ impl Client {
|
||||
)));
|
||||
}
|
||||
|
||||
pub fn change_ability(&mut self, slot: usize, new_ability: comp::Ability) {
|
||||
self.send_msg(ClientGeneral::ChangeAbility { slot, new_ability })
|
||||
}
|
||||
|
||||
/// Execute a single client tick, handle input and update the game state by
|
||||
/// the given duration.
|
||||
pub fn tick(
|
||||
|
@ -75,6 +75,10 @@ pub enum ClientGeneral {
|
||||
RefundSkill(Skill),
|
||||
UnlockSkillGroup(SkillGroupKind),
|
||||
RequestSiteInfo(SiteId),
|
||||
ChangeAbility {
|
||||
slot: usize,
|
||||
new_ability: comp::Ability,
|
||||
},
|
||||
//Only in Game, via terrain stream
|
||||
TerrainChunkRequest {
|
||||
key: Vec2<i32>,
|
||||
@ -127,7 +131,8 @@ impl ClientMsg {
|
||||
| ClientGeneral::RequestSiteInfo(_)
|
||||
| ClientGeneral::UnlockSkillGroup(_)
|
||||
| ClientGeneral::RequestPlayerPhysics { .. }
|
||||
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
||||
| ClientGeneral::RequestLossyTerrainCompression { .. }
|
||||
| ClientGeneral::ChangeAbility { .. } => {
|
||||
c_type == ClientType::Game && presence.is_some()
|
||||
},
|
||||
//Always possible
|
||||
|
@ -65,8 +65,10 @@ impl AbilityPool {
|
||||
}
|
||||
|
||||
pub fn change_ability(&mut self, slot: usize, new_ability: Ability) {
|
||||
if let Some(ability) = self.abilities.get_mut(slot) {
|
||||
*ability = new_ability;
|
||||
if new_ability.is_valid_abilities_ability() {
|
||||
if let Some(ability) = self.abilities.get_mut(slot) {
|
||||
*ability = new_ability;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +208,19 @@ impl Ability {
|
||||
Ability::Empty => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Determines whether an ability is a valid entry for the abilities array
|
||||
/// on the ability pool
|
||||
pub fn is_valid_abilities_ability(self) -> bool {
|
||||
match self {
|
||||
Ability::ToolPrimary => false,
|
||||
Ability::ToolSecondary => false,
|
||||
Ability::SpeciesMovement => false,
|
||||
Ability::MainWeaponAbility(_) => true,
|
||||
Ability::OffWeaponAbility(_) => true,
|
||||
Ability::Empty => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
|
@ -3,8 +3,8 @@ use crate::TerrainPersistence;
|
||||
use crate::{client::Client, presence::Presence, Settings};
|
||||
use common::{
|
||||
comp::{
|
||||
Admin, CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Player, Pos, SkillSet,
|
||||
Vel,
|
||||
AbilityPool, Admin, CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Player,
|
||||
Pos, SkillSet, Vel,
|
||||
},
|
||||
event::{EventBus, ServerEvent},
|
||||
resources::PlayerPhysicsSettings,
|
||||
@ -40,6 +40,7 @@ impl Sys {
|
||||
velocities: &mut WriteStorage<'_, Vel>,
|
||||
orientations: &mut WriteStorage<'_, Ori>,
|
||||
controllers: &mut WriteStorage<'_, Controller>,
|
||||
ability_pools: &mut WriteStorage<'_, AbilityPool>,
|
||||
settings: &Read<'_, Settings>,
|
||||
build_areas: &Read<'_, BuildAreas>,
|
||||
player_physics_settings: &mut Write<'_, PlayerPhysicsSettings>,
|
||||
@ -281,7 +282,20 @@ impl Sys {
|
||||
} => {
|
||||
presence.lossy_terrain_compression = lossy_terrain_compression;
|
||||
},
|
||||
_ => tracing::error!("not a client_in_game msg"),
|
||||
ClientGeneral::ChangeAbility { slot, new_ability } => {
|
||||
if let Some(mut ability_pool) = ability_pools.get_mut(entity) {
|
||||
ability_pool.change_ability(slot, new_ability);
|
||||
}
|
||||
},
|
||||
ClientGeneral::RequestCharacterList
|
||||
| ClientGeneral::CreateCharacter { .. }
|
||||
| ClientGeneral::DeleteCharacter(_)
|
||||
| ClientGeneral::Character(_)
|
||||
| ClientGeneral::Spectate
|
||||
| ClientGeneral::TerrainChunkRequest { .. }
|
||||
| ClientGeneral::ChatMsg(_)
|
||||
| ClientGeneral::Command(..)
|
||||
| ClientGeneral::Terminate => tracing::error!("not a client_in_game msg"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -307,6 +321,7 @@ impl<'a> System<'a> for Sys {
|
||||
WriteStorage<'a, Presence>,
|
||||
WriteStorage<'a, Client>,
|
||||
WriteStorage<'a, Controller>,
|
||||
WriteStorage<'a, AbilityPool>,
|
||||
Read<'a, Settings>,
|
||||
Read<'a, BuildAreas>,
|
||||
Write<'a, PlayerPhysicsSettings>,
|
||||
@ -336,6 +351,7 @@ impl<'a> System<'a> for Sys {
|
||||
mut presences,
|
||||
mut clients,
|
||||
mut controllers,
|
||||
mut ability_pools,
|
||||
settings,
|
||||
build_areas,
|
||||
mut player_physics_settings,
|
||||
@ -371,6 +387,7 @@ impl<'a> System<'a> for Sys {
|
||||
&mut velocities,
|
||||
&mut orientations,
|
||||
&mut controllers,
|
||||
&mut ability_pools,
|
||||
&settings,
|
||||
&build_areas,
|
||||
&mut player_physics_settings,
|
||||
|
@ -533,6 +533,8 @@ pub enum Event {
|
||||
RemoveBuff(BuffKind),
|
||||
UnlockSkill(Skill),
|
||||
RequestSiteInfo(SiteId),
|
||||
// TODO: This variant currently unused. UI is needed for it to be properly used.
|
||||
ChangeAbility(usize, comp::Ability),
|
||||
|
||||
SettingsChange(SettingsChange),
|
||||
}
|
||||
|
@ -1425,6 +1425,9 @@ impl PlayState for SessionState {
|
||||
HudEvent::AssignLeader(uid) => {
|
||||
self.client.borrow_mut().assign_group_leader(uid);
|
||||
},
|
||||
HudEvent::ChangeAbility(slot, new_ability) => {
|
||||
self.client.borrow_mut().change_ability(slot, new_ability);
|
||||
},
|
||||
HudEvent::SettingsChange(settings_change) => {
|
||||
settings_change.process(global_state, self);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user