From 918eeda9db40e1b6468e62d01cc3fa8b402ebd76 Mon Sep 17 00:00:00 2001 From: zhouzihao <1042181618@qq.com> Date: Sat, 9 Sep 2023 16:05:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?dev-=E6=8E=89=E8=90=BD=E7=89=A9=E5=93=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=92=8C=E9=9A=8F=E6=9C=BA=E6=8E=89=E8=90=BD?= =?UTF-8?q?=E6=94=AF=E6=92=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../textures/\350\213\271\346\236\234.png" | Bin 0 -> 1298 bytes src/server/async_chunk.rs | 20 +++--- src/staff/mod.rs | 60 ++++++++++++++++++ staff.ron | 10 ++- 4 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 "assets/textures/\350\213\271\346\236\234.png" diff --git "a/assets/textures/\350\213\271\346\236\234.png" "b/assets/textures/\350\213\271\346\236\234.png" new file mode 100644 index 0000000000000000000000000000000000000000..20752d4545e29f81850209c8e5eb84f85bb14d90 GIT binary patch literal 1298 zcmV+t1?~EYP)2YfF)F??Rnb zb)^VSQf?aXHonY2m7+c9wri6woAOkKCe<6)MwP#v_dZeF!|E}Rsg(eA=BiiQ5g2U z!fo{;f_0Q-D>WwnD}c8eY#M#pemCHXFvR4?ec|j zp08aM?98J0Y#R}r1Yq*S?o$(a-x!7AS_?Hoe8RCgiO^;sbh3&3{qKJqT!iv(0H<7i zi7SA!f2jJM$H3(4pjE;m$0)7>*FNA#$5_2V6XB>!8zKQX`}=uFx&f2SzE=7=ws5SX zDsZWQk6OeyDTrfr5#ZhGjUjq{7ih1+rdUm|3c%&Rw_!d%vCgjna~!jEolRN+OTHrY zh_@xKr2@QBy)kX&UxQ6C*Fh@4YaRpj1Q&bL zPl=IKfQy~O86KjTrKc|n-m5dt2Zo*&n?8X&MSiH#WKP1*IVKwBU9N&1Xc z0Bx;(xyeq?{17X{7Bt4HLs|iWN)y`Yz13t?Eq@;(SW2I8OQp%O^!0Wf34Uoa7(xUK zj=30%1mM?zs^A2GRhzvp5d@{bs?y|mnSIHAqg8+xuU)O~uN|~{^&mnMd9D1vaP?~y zpgg=pY8FL7RY1(nNt}}i)y}aE1eqtCS84KtOZEv)J3}M}i9p9*vnaj-V29+nE@J~5 zdCvY7l_noMjBD0m6~Lfmz>B3f0c@=XX;`mchjh>+B!5$-$qt>o%UJ`buK+pL&hwE7 zTkASSVaXcD3x*xw4Pf%C978Me1m^`2YCvm*L|7b!;pM7bNurL3Df1HIcuby-$Sigt zzed1jAUuCVufrJtp9y z9|lWzAHO1w$*Dze0vH-w-0N$j73^d5pmab_5^EQ7`{s8ccN|W!(XRE|r z;u=%{Q=^yWLoD6RUH?NsZEUXb^mU|mh8bp, pub voxel_staff: HashMap, + // 灵活的 体素和物品掉落的关系 + pub filled_map: HashMap, } impl StaffInfoStroge { + fn register_filled(&mut self, fill_mate: FilledMeta) { + self.filled_map + .insert(fill_mate.voxel_id, fill_mate.clone()); + } fn register(&mut self, staff: Staff) { if self.data.contains_key(&staff.id) { warn!("{} is already registered", staff.id); @@ -57,6 +64,38 @@ impl StaffInfoStroge { pub fn voxel_to_staff(&self, voxel: Voxel) -> Option<&Staff> { self.voxel_staff.get(&voxel.id) } + + // 通过体素获取掉落物 + pub fn voxel_to_staff_list(&self, voxel: Voxel) -> Option> { + let mut ret: Vec = Vec::new(); + let voxle_id = voxel.id; + if let Some(mate) = self.filled_map.get(&(voxle_id as usize)) { + for FilledPair { + possible, + staff_id, + times, + } in mate.filled_config.iter() + { + if let Some(staff) = self.get(*staff_id) { + for _ in 0..*times { + let mut rng = rand::thread_rng(); + if rng.gen_bool(*possible as f64) { + ret.push(staff.clone()); + } + } + } + } + } else { + if let Some(staff) = self.voxel_staff.get(&voxel.id) { + ret.push(staff.clone()); + } + } + if ret.len() > 0 { + return Some(ret); + } + None + } + // 通过 物品点 获取物品id pub fn get(&self, staff_id: usize) -> Option { self.data.get(&staff_id).map(|a| a.clone()) @@ -76,6 +115,7 @@ impl Plugin for StaffInfoPlugin { app.insert_resource(StaffInfoStroge { data: HashMap::default(), voxel_staff: HashMap::default(), + filled_map: HashMap::default(), }); app.add_systems(Startup, setup.in_set(StaffSet::Init)); } @@ -93,6 +133,7 @@ impl Plugin for ServerStaffInfoPlugin { app.insert_resource(StaffInfoStroge { data: HashMap::default(), voxel_staff: HashMap::default(), + filled_map: HashMap::default(), }); app.add_systems(Startup, server_setup.in_set(StaffSet::Init)); } @@ -110,9 +151,25 @@ pub struct StaffMeta { staff_type: StaffType, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FilledMeta { + // 体素类型的id + voxel_id: usize, + filled_config: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FilledPair { + possible: f32, + staff_id: usize, + times: usize, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct StaffConfigs { pub configs: Vec, + // 掉落物的特性 + pub filled_configs: Vec, } fn load_staff_configs( @@ -141,6 +198,9 @@ fn load_staff_configs( }); } } + for mate in res.filled_configs { + staff_info_stroge.register_filled(mate); + } } Err(_) => { error!("读取Staff配置数据失败"); diff --git a/staff.ron b/staff.ron index 70c7384..cfd60bc 100644 --- a/staff.ron +++ b/staff.ron @@ -10,5 +10,13 @@ (id:7,name:"BlueGrass",icon_string:"textures/苍翠地.png",staff_type:Voxel((id:9))), (id:8,name:"AppleWood",icon_string:"textures/苹果树A面.png",staff_type:Voxel((id:10))), (id:9,name:"AppleLeaf",icon_string:"textures/苹果叶子.png",staff_type:Voxel((id:11))), - ] + (id:10,name:"Apple",icon_string:"textures/苹果.png",staff_type:Consumable(0)), + ], + // 掉落配置 + filled_configs:[ + // 叶子有 20% 概率掉 一个苹果 + (voxel_id:11,filled_config:[ + (possible: 0.2,staff_id: 10,times: 1), + ]), + ], ) \ No newline at end of file From b317a73f7ce6051a02054c2a5a376a194ffa340f Mon Sep 17 00:00:00 2001 From: zhouzihao <1042181618@qq.com> Date: Sat, 9 Sep 2023 16:34:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?dev-=E6=B7=BB=E5=8A=A0=E6=9C=A8=E6=A3=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../textures/\346\243\215\345\255\220.png" | Bin 0 -> 588 bytes .../textures/\350\213\271\346\236\234.png" | Bin 1298 -> 1295 bytes ...1\346\236\234\345\217\266\345\255\220.png" | Bin 807 -> 265 bytes staff.ron | 2 ++ 4 files changed, 2 insertions(+) create mode 100644 "assets/textures/\346\243\215\345\255\220.png" diff --git "a/assets/textures/\346\243\215\345\255\220.png" "b/assets/textures/\346\243\215\345\255\220.png" new file mode 100644 index 0000000000000000000000000000000000000000..e9eaed00cd5010dd352819d6557f7b9d24ecd506 GIT binary patch literal 588 zcmV-S0<-;zP)nlxIegit+-nj;DfI_nl7D?tKF#~xop=NTu<0)J^JD+T z&&xNuYS8A5Qo{lalWz%OGxY}P2o~UU{(bOqiTAo>1lIzpRRo`jnFFUY{4jjj#gh#0 z4hU|c9K+uQOcJI7QY(RN=0Ws^U=9NJcJKhMlv_jSRX~dfSL=Y*5TXmAmJmi)f~_F@ zyA*B#Ve-3xbc9KOFeD<(0&rE3yJDn_FuMYzA|$ndOF|Mt5Tk6(dHB7%^hRh!G?HrwDAci=yaVnNlDKY)*r|+6{tcijVfv ziYySFQC(DpcE8}jgYv$QL=XlOz*22R<#*G+d&eU_oi~9p%30k)-dCng7_0&$#7dhX zMVMIyR55hsOIR!5&I>Phk?j|MMF6ky^$LJz0fZ_|7PBb+55PYFasYn-_!+=udRC=L z>B^fJUIfsH9|l0zT>uLP^T+riks<&G036Gr_&$J309Jj9(W?L&@nZmv0{F6nI}+?5 zU0D?W3E&ifvn)n$BJ|b?QeasWAIhTmcMf)^#U3USTDD6(!#=N58`Nii)Y!B_F9I<6 zvjElrJZB-(_Pxe!^&*0Glw~V5CjTRVeGN8^zHGl6a8;$rUR$4F6RDE`OnwSr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rt6KHx~l zSiM0L;iyX+A^|x2`*}#Z0h7$WR{A=&aIB&#aH)WgTEsXhh+}mT;N9wtA$olmXs^Mh zSWU1Bz~#TUVLm^x&aVM;9J6(uOQ&bLPl=IKfQy~O86KjTrKc|n-m5dt2Zo*& zn}0rmJVkz}(qvA;&*d|CL1Hw?zCc?a_(}SVRRC?ReYwd_&-@T8!xl8gszX`AlrtR4soWB3MeFa7(4hvh?+K9SMGEGZ;by3y!%Miv-};fU4jGfK{8lFA)T#zpB#Y zc$t04exp@@7q4Bd?ynuRdi5Ye6M3!tzkhJ`YZah8yhLgiML|_S%+5)ilL*z$u?+;7 zC!AMl@`FqE2~ImhBnF8<$6m82z5-x}kH{uPxbA3Ka|)?pREpk%;{r8fa= ztp;gWuV06B&?F>(Q>DocoxICg1E;S5Io8hekqBGsIz?g08pjKU9pDXM@~a#}D}V9? z=LHdJKx>3VSR94n<*HptqK=3u^Ah5COrDO&EOsHkM!;quJby#4!x;dd343cJgwKDa z(&Tdqd9P=LuvrAE=ab_+-?W3=2S#B?NAM1+G+B{m-n#&mM)ZS{N5*-+r6=Mv1V6@u z9JrMIAOh4hq#u<%FwXNmA}1TmoOh<*KLhxN=OMT>9|lWzAHO1w$*Dze0vH-w-0N$j73^d5pmab_5^EQ7`{s8ccN|W!(XRE|r;u=%{Q=^yWLoD6RUH?NsZEUXb o^mU|mh8bpPx# diff --git "a/assets/textures/\350\213\271\346\236\234\345\217\266\345\255\220.png" "b/assets/textures/\350\213\271\346\236\234\345\217\266\345\255\220.png" index 51d0c999102432c23cb9154dffd353aa22f58371..eac33990bb07480a061b8f89cf13434482046817 100644 GIT binary patch delta 238 zcmZ3^*2y$Mxt`&Ir;B4q#hkadH*zvLim+S=%sCj+b4KUD5h0x;pL7l$5j*0+x5jzr zRA%Pn@E`d`i*L_;{LJ;-w&PEYTQ^Ir-)H~E%dEgI_8x1`&iifqmj5igHaoQX!JbP? z_q#II7qqR*WDWWK?{ndEv!=seFaEZ<+jQ_HJ6p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index cfd60bc..5b02c00 100644 --- a/staff.ron +++ b/staff.ron @@ -11,12 +11,14 @@ (id:8,name:"AppleWood",icon_string:"textures/苹果树A面.png",staff_type:Voxel((id:10))), (id:9,name:"AppleLeaf",icon_string:"textures/苹果叶子.png",staff_type:Voxel((id:11))), (id:10,name:"Apple",icon_string:"textures/苹果.png",staff_type:Consumable(0)), + (id:11,name:"AppleLog",icon_string:"textures/棍子.png",staff_type:Consumable(0)), ], // 掉落配置 filled_configs:[ // 叶子有 20% 概率掉 一个苹果 (voxel_id:11,filled_config:[ (possible: 0.2,staff_id: 10,times: 1), + (possible: 0.6,staff_id: 11,times: 2), ]), ], ) \ No newline at end of file