diff --git a/src/client/ui/staff_rules.rs b/src/client/ui/staff_rules.rs index c2c4f4c..1f38b73 100644 --- a/src/client/ui/staff_rules.rs +++ b/src/client/ui/staff_rules.rs @@ -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 + )); + } + } } } }); diff --git a/src/server/staff_rule_sync.rs b/src/server/staff_rule_sync.rs index c2bcfb3..685c7b5 100644 --- a/src/server/staff_rule_sync.rs +++ b/src/server/staff_rule_sync.rs @@ -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, }; @@ -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()); } } } diff --git a/src/staff/rule.rs b/src/staff/rule.rs index 42e6400..8d922ca 100644 --- a/src/staff/rule.rs +++ b/src/staff/rule.rs @@ -18,7 +18,7 @@ pub struct StaffRule { // 输入要求 pub input: Vec, // 输出类型 - pub output_id: usize, + pub output: Vec, // 需要的依赖 pub base_on: Option, // 描述 diff --git a/staff_rules.ron b/staff_rules.ron index 0849f5d..7397063 100644 --- a/staff_rules.ron +++ b/staff_rules.ron @@ -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:"测试使用的合成烟花的公式(测试一个合成多个)", ), ] \ No newline at end of file