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::RequestSiteInfo(_)
|
||||||
| ClientGeneral::UnlockSkillGroup(_)
|
| ClientGeneral::UnlockSkillGroup(_)
|
||||||
| ClientGeneral::RequestPlayerPhysics { .. }
|
| ClientGeneral::RequestPlayerPhysics { .. }
|
||||||
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
| ClientGeneral::RequestLossyTerrainCompression { .. }
|
||||||
|
| ClientGeneral::ChangeAbility { .. } => {
|
||||||
#[cfg(feature = "tracy")]
|
#[cfg(feature = "tracy")]
|
||||||
{
|
{
|
||||||
ingame = 1.0;
|
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
|
/// Execute a single client tick, handle input and update the game state by
|
||||||
/// the given duration.
|
/// the given duration.
|
||||||
pub fn tick(
|
pub fn tick(
|
||||||
|
@ -75,6 +75,10 @@ pub enum ClientGeneral {
|
|||||||
RefundSkill(Skill),
|
RefundSkill(Skill),
|
||||||
UnlockSkillGroup(SkillGroupKind),
|
UnlockSkillGroup(SkillGroupKind),
|
||||||
RequestSiteInfo(SiteId),
|
RequestSiteInfo(SiteId),
|
||||||
|
ChangeAbility {
|
||||||
|
slot: usize,
|
||||||
|
new_ability: comp::Ability,
|
||||||
|
},
|
||||||
//Only in Game, via terrain stream
|
//Only in Game, via terrain stream
|
||||||
TerrainChunkRequest {
|
TerrainChunkRequest {
|
||||||
key: Vec2<i32>,
|
key: Vec2<i32>,
|
||||||
@ -127,7 +131,8 @@ impl ClientMsg {
|
|||||||
| ClientGeneral::RequestSiteInfo(_)
|
| ClientGeneral::RequestSiteInfo(_)
|
||||||
| ClientGeneral::UnlockSkillGroup(_)
|
| ClientGeneral::UnlockSkillGroup(_)
|
||||||
| ClientGeneral::RequestPlayerPhysics { .. }
|
| ClientGeneral::RequestPlayerPhysics { .. }
|
||||||
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
| ClientGeneral::RequestLossyTerrainCompression { .. }
|
||||||
|
| ClientGeneral::ChangeAbility { .. } => {
|
||||||
c_type == ClientType::Game && presence.is_some()
|
c_type == ClientType::Game && presence.is_some()
|
||||||
},
|
},
|
||||||
//Always possible
|
//Always possible
|
||||||
|
@ -65,8 +65,10 @@ impl AbilityPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_ability(&mut self, slot: usize, new_ability: Ability) {
|
pub fn change_ability(&mut self, slot: usize, new_ability: Ability) {
|
||||||
if let Some(ability) = self.abilities.get_mut(slot) {
|
if new_ability.is_valid_abilities_ability() {
|
||||||
*ability = new_ability;
|
if let Some(ability) = self.abilities.get_mut(slot) {
|
||||||
|
*ability = new_ability;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +208,19 @@ impl Ability {
|
|||||||
Ability::Empty => None,
|
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)]
|
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||||
|
@ -3,8 +3,8 @@ use crate::TerrainPersistence;
|
|||||||
use crate::{client::Client, presence::Presence, Settings};
|
use crate::{client::Client, presence::Presence, Settings};
|
||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{
|
||||||
Admin, CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Player, Pos, SkillSet,
|
AbilityPool, Admin, CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Player,
|
||||||
Vel,
|
Pos, SkillSet, Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
resources::PlayerPhysicsSettings,
|
resources::PlayerPhysicsSettings,
|
||||||
@ -40,6 +40,7 @@ impl Sys {
|
|||||||
velocities: &mut WriteStorage<'_, Vel>,
|
velocities: &mut WriteStorage<'_, Vel>,
|
||||||
orientations: &mut WriteStorage<'_, Ori>,
|
orientations: &mut WriteStorage<'_, Ori>,
|
||||||
controllers: &mut WriteStorage<'_, Controller>,
|
controllers: &mut WriteStorage<'_, Controller>,
|
||||||
|
ability_pools: &mut WriteStorage<'_, AbilityPool>,
|
||||||
settings: &Read<'_, Settings>,
|
settings: &Read<'_, Settings>,
|
||||||
build_areas: &Read<'_, BuildAreas>,
|
build_areas: &Read<'_, BuildAreas>,
|
||||||
player_physics_settings: &mut Write<'_, PlayerPhysicsSettings>,
|
player_physics_settings: &mut Write<'_, PlayerPhysicsSettings>,
|
||||||
@ -281,7 +282,20 @@ impl Sys {
|
|||||||
} => {
|
} => {
|
||||||
presence.lossy_terrain_compression = lossy_terrain_compression;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -307,6 +321,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
WriteStorage<'a, Presence>,
|
WriteStorage<'a, Presence>,
|
||||||
WriteStorage<'a, Client>,
|
WriteStorage<'a, Client>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
|
WriteStorage<'a, AbilityPool>,
|
||||||
Read<'a, Settings>,
|
Read<'a, Settings>,
|
||||||
Read<'a, BuildAreas>,
|
Read<'a, BuildAreas>,
|
||||||
Write<'a, PlayerPhysicsSettings>,
|
Write<'a, PlayerPhysicsSettings>,
|
||||||
@ -336,6 +351,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut presences,
|
mut presences,
|
||||||
mut clients,
|
mut clients,
|
||||||
mut controllers,
|
mut controllers,
|
||||||
|
mut ability_pools,
|
||||||
settings,
|
settings,
|
||||||
build_areas,
|
build_areas,
|
||||||
mut player_physics_settings,
|
mut player_physics_settings,
|
||||||
@ -371,6 +387,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
&mut velocities,
|
&mut velocities,
|
||||||
&mut orientations,
|
&mut orientations,
|
||||||
&mut controllers,
|
&mut controllers,
|
||||||
|
&mut ability_pools,
|
||||||
&settings,
|
&settings,
|
||||||
&build_areas,
|
&build_areas,
|
||||||
&mut player_physics_settings,
|
&mut player_physics_settings,
|
||||||
|
@ -533,6 +533,8 @@ pub enum Event {
|
|||||||
RemoveBuff(BuffKind),
|
RemoveBuff(BuffKind),
|
||||||
UnlockSkill(Skill),
|
UnlockSkill(Skill),
|
||||||
RequestSiteInfo(SiteId),
|
RequestSiteInfo(SiteId),
|
||||||
|
// TODO: This variant currently unused. UI is needed for it to be properly used.
|
||||||
|
ChangeAbility(usize, comp::Ability),
|
||||||
|
|
||||||
SettingsChange(SettingsChange),
|
SettingsChange(SettingsChange),
|
||||||
}
|
}
|
||||||
|
@ -1425,6 +1425,9 @@ impl PlayState for SessionState {
|
|||||||
HudEvent::AssignLeader(uid) => {
|
HudEvent::AssignLeader(uid) => {
|
||||||
self.client.borrow_mut().assign_group_leader(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) => {
|
HudEvent::SettingsChange(settings_change) => {
|
||||||
settings_change.process(global_state, self);
|
settings_change.process(global_state, self);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user