From 620230556b946c657ab1b82a0a3a40c9e9bf25ce Mon Sep 17 00:00:00 2001 From: zhouzihao <1042181618@qq.com> Date: Fri, 8 Sep 2023 17:07:34 +0800 Subject: [PATCH] =?UTF-8?q?dev-=E6=94=AF=E6=8C=81=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E5=85=AC=E5=BC=8F=E4=B8=AD=E5=8F=AF=E4=BB=A5=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E5=90=88=E6=88=90=E5=A4=9A=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/ui/staff_rules.rs | 23 +++++++++++----- src/server/staff_rule_sync.rs | 51 +++++++++++++++++++++-------------- src/staff/rule.rs | 2 +- staff_rules.ron | 12 +++++---- 4 files changed, 56 insertions(+), 32 deletions(-) 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