simlify player handling in handle_chat_scripts()
This commit is contained in:
parent
a29b7c8436
commit
03e96e6ecd
91
src/chat.rs
91
src/chat.rs
|
@ -91,7 +91,9 @@ impl Plugin for ChatPlugin {
|
||||||
handle_chat_events
|
handle_chat_events
|
||||||
.run_if(game_running)
|
.run_if(game_running)
|
||||||
.before(handle_chat_scripts),
|
.before(handle_chat_scripts),
|
||||||
handle_chat_scripts.run_if(game_running),
|
handle_chat_scripts
|
||||||
|
.run_if(game_running)
|
||||||
|
.run_if(on_event::<ChatScriptEvent>()),
|
||||||
update_chat_variables.run_if(game_running),
|
update_chat_variables.run_if(game_running),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -913,6 +915,14 @@ pub fn handle_chat_scripts(
|
||||||
id2pos: Res<game::Id2Pos>,
|
id2pos: Res<game::Id2Pos>,
|
||||||
id2v: Res<game::Id2V>,
|
id2v: Res<game::Id2V>,
|
||||||
) {
|
) {
|
||||||
|
let (player_entity, _, mut suit, mut gforce) =
|
||||||
|
if let Ok(player_data) = q_player.get_single_mut() {
|
||||||
|
player_data
|
||||||
|
} else {
|
||||||
|
error!("Can't access player in handle_chat_scripts");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
for script in er_chatscript.read() {
|
for script in er_chatscript.read() {
|
||||||
// Parse the script string
|
// Parse the script string
|
||||||
let mut parts = script.0.split_whitespace();
|
let mut parts = script.0.split_whitespace();
|
||||||
|
@ -929,32 +939,29 @@ pub fn handle_chat_scripts(
|
||||||
match name {
|
match name {
|
||||||
"refilloxygen" => {
|
"refilloxygen" => {
|
||||||
if let Ok(mut amount) = param1.to_string().parse::<f32>() {
|
if let Ok(mut amount) = param1.to_string().parse::<f32>() {
|
||||||
for (_, _, mut suit, _) in q_player.iter_mut() {
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Refill));
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Refill));
|
if param2.is_empty() {
|
||||||
if param2.is_empty() {
|
suit.oxygen = (suit.oxygen + amount).clamp(0.0, suit.oxygen_max);
|
||||||
suit.oxygen = (suit.oxygen + amount).clamp(0.0, suit.oxygen_max);
|
} else {
|
||||||
} else {
|
let mut found_other = false;
|
||||||
let mut found_other = false;
|
info!("param2={}", param2);
|
||||||
info!("param2={}", param2);
|
for (other_actor, mut other_suit) in q_actor.iter_mut() {
|
||||||
for (other_actor, mut other_suit) in q_actor.iter_mut() {
|
if !other_actor.id.is_empty() {
|
||||||
if !other_actor.id.is_empty() {
|
info!("ID={}", other_actor.id);
|
||||||
info!("ID={}", other_actor.id);
|
|
||||||
}
|
|
||||||
if other_actor.id == param2 {
|
|
||||||
found_other = true;
|
|
||||||
amount = amount
|
|
||||||
.clamp(0.0, other_suit.oxygen)
|
|
||||||
.clamp(0.0, suit.oxygen_max - suit.oxygen);
|
|
||||||
other_suit.oxygen = other_suit.oxygen - amount;
|
|
||||||
suit.oxygen =
|
|
||||||
(suit.oxygen + amount).clamp(0.0, suit.oxygen_max);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !found_other {
|
if other_actor.id == param2 {
|
||||||
error!("Script error: could not find actor with ID `{}`", param2);
|
found_other = true;
|
||||||
|
amount = amount
|
||||||
|
.clamp(0.0, other_suit.oxygen)
|
||||||
|
.clamp(0.0, suit.oxygen_max - suit.oxygen);
|
||||||
|
other_suit.oxygen = other_suit.oxygen - amount;
|
||||||
|
suit.oxygen = (suit.oxygen + amount).clamp(0.0, suit.oxygen_max);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !found_other {
|
||||||
|
error!("Script error: could not find actor with ID `{}`", param2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error!("Invalid parameter for command `{}`: `{}`", name, param1);
|
error!("Invalid parameter for command `{}`: `{}`", name, param1);
|
||||||
|
@ -962,9 +969,7 @@ pub fn handle_chat_scripts(
|
||||||
}
|
}
|
||||||
"repairsuit" => {
|
"repairsuit" => {
|
||||||
ew_achievement.send(game::AchievementEvent::RepairSuit);
|
ew_achievement.send(game::AchievementEvent::RepairSuit);
|
||||||
for (_, _, mut suit, _) in q_player.iter_mut() {
|
suit.integrity = 1.0;
|
||||||
suit.integrity = 1.0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"cryotrip" => {
|
"cryotrip" => {
|
||||||
if param1.is_empty() {
|
if param1.is_empty() {
|
||||||
|
@ -1011,10 +1016,8 @@ pub fn handle_chat_scripts(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok((_, _, mut suit, mut gforce)) = q_player.get_single_mut() {
|
suit.oxygen = suit.oxygen_max;
|
||||||
suit.oxygen = suit.oxygen_max;
|
gforce.ignore_gforce_seconds = 1.0;
|
||||||
gforce.ignore_gforce_seconds = 1.0;
|
|
||||||
}
|
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::WakeUp));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::WakeUp));
|
||||||
ew_effect.send(visual::SpawnEffectEvent {
|
ew_effect.send(visual::SpawnEffectEvent {
|
||||||
class: visual::Effects::FadeIn(css::AQUA.into()),
|
class: visual::Effects::FadeIn(css::AQUA.into()),
|
||||||
|
@ -1053,20 +1056,18 @@ pub fn handle_chat_scripts(
|
||||||
ew_playerdies.send(game::PlayerDiesEvent(actor::DamageType::Bullet));
|
ew_playerdies.send(game::PlayerDiesEvent(actor::DamageType::Bullet));
|
||||||
}
|
}
|
||||||
"addcatears" => {
|
"addcatears" => {
|
||||||
if let Ok((player_entity, _, _, _)) = q_player.get_single_mut() {
|
let mut entitycmd = commands.spawn((
|
||||||
let mut entitycmd = commands.spawn((
|
hud::AugmentedRealityOverlay {
|
||||||
hud::AugmentedRealityOverlay {
|
owner: player_entity,
|
||||||
owner: player_entity,
|
scale: 1.0,
|
||||||
scale: 1.0,
|
always_visible: true,
|
||||||
always_visible: true,
|
},
|
||||||
},
|
world::DespawnOnPlayerDeath,
|
||||||
world::DespawnOnPlayerDeath,
|
SpatialBundle::default(),
|
||||||
SpatialBundle::default(),
|
));
|
||||||
));
|
load_asset("suit_ar_nekomimi", &mut entitycmd, &*asset_server);
|
||||||
load_asset("suit_ar_nekomimi", &mut entitycmd, &*asset_server);
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Crash));
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Crash));
|
vars.set_in_scope("$", "catears", "1".to_string());
|
||||||
vars.set_in_scope("$", "catears", "1".to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Error, undefined chat script {name}");
|
error!("Error, undefined chat script {name}");
|
||||||
|
|
Loading…
Reference in a new issue