Skip to content

Commit

Permalink
dev-支持输出公式中可以一次合成多个
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhgithub committed Sep 8, 2023
1 parent 5b70f86 commit 6202305
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
23 changes: 17 additions & 6 deletions src/client/ui/staff_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,24 @@ pub fn staff_rules_ui(
}
});
row.col(|ui| {
if let Some(staff) =
staff_info_stroge.get(staff_rule.output_id)
{
if let Some(txt_id) =
user_textures.image_id(&staff.icon)
for pair in staff_rule.output {
if let Some(staff) =
staff_info_stroge.get(pair.staff_id)
{
ui.image(txt_id, Vec2::new(64., 64.));
if let Some(txt_id) =
user_textures.image_id(&staff.icon)
{
ui.image(
txt_id,
Vec2::new(64., 64.),
);
if pair.num_needed > 1 {
ui.label(format!(
"x {}",
pair.num_needed
));
}
}
}
}
});
Expand Down
51 changes: 31 additions & 20 deletions src/server/staff_rule_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use bevy_renet::renet::RenetServer;

use crate::{
client::message_def::{staff_rule_message::StaffRuleMessage, ClientChannel},
staff::{rule::StaffRules, StaffInfoStroge},
staff::{
rule::{StaffNumPair, StaffRules},
StaffInfoStroge,
},
tools::vec3_to_chunk_key_any_xyz,
voxel_world::player_state::PlayerOntimeState,
};
Expand Down Expand Up @@ -35,28 +38,36 @@ pub fn deal_with_staff_rule(
need,
} = bincode::deserialize(&message).unwrap();
if let Some(rule) = staff_rules.rules.get(&staff_rule_id) {
if let Some(out_staff) = staff_info_stroge.get(rule.output_id) {
if let Some(entity) = lobby.players.get(&client_id) {
if let Ok((_, trf, mut player_state)) = query.get_mut(*entity) {
// 找到用户的Ontime 减少物品
for (index, staff_id, use_num) in need {
if player_state.0.use_staff(index, staff_id, use_num) == None {
println!("物体生成时消耗错误!");
println!("{}|{}|{}", index, staff_id, use_num);
if let Some(entity) = lobby.players.get(&client_id) {
if let Ok((_, trf, mut player_state)) = query.get_mut(*entity) {
// 找到用户的Ontime 减少物品
for (index, staff_id, use_num) in need {
if player_state.0.use_staff(index, staff_id, use_num) == None {
println!("物体生成时消耗错误!");
println!("{}|{}|{}", index, staff_id, use_num);
}
}
for StaffNumPair {
staff_id,
num_needed,
} in rule.output.clone()
{
if let Some(out_staff) = staff_info_stroge.get(staff_id) {
for _ in 0..num_needed {
let center = trf.translation;
let (chunk_key, xyz) = vec3_to_chunk_key_any_xyz(center);
// 生成新的掉落物
fill_event.send(ObjectFillEvent {
chunk_key: chunk_key,
xyz: xyz,
center: center,
staff: out_staff.clone(),
});
}
}
let center = trf.translation;
let (chunk_key, xyz) = vec3_to_chunk_key_any_xyz(center);
// 生成新的掉落物
fill_event.send(ObjectFillEvent {
chunk_key: chunk_key,
xyz: xyz,
center: center,
staff: out_staff,
});
// 同步 toolbar变化
send_all_tool_bar(client_id, &mut server, player_state.0.clone());
}
// 数据都处理完了 再一起同步
send_all_tool_bar(client_id, &mut server, player_state.0.clone());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/staff/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct StaffRule<T> {
// 输入要求
pub input: Vec<StaffNumPair>,
// 输出类型
pub output_id: usize,
pub output: Vec<StaffNumPair>,
// 需要的依赖
pub base_on: Option<T>,
// 描述
Expand Down
12 changes: 7 additions & 5 deletions staff_rules.ron
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
id:0,
input:[
(staff_id:0,num_needed:1),
(staff_id:2,num_needed:2),
(staff_id:4,num_needed:3),
(staff_id:3,num_needed:4),
// (staff_id:2,num_needed:2),
// (staff_id:4,num_needed:3),
// (staff_id:3,num_needed:4),
],
// 合成烟花
output_id: 5,
output: [
(staff_id:5,num_needed:4),
],
base_on:None,
desc:"测试使用的合成烟花的公式",
desc:"测试使用的合成烟花的公式(测试一个合成多个)",
),
]

0 comments on commit 6202305

Please sign in to comment.