@@ -58,6 +58,22 @@ pub enum GearType {
5858 Drone // 0x800001
5959}
6060
61+ #[derive(Drop , Copy , Serde )]
62+ pub struct GearDetails {
63+ // Type of gear (e.g., Weapon, Helmet, Vehicle)
64+ pub gear_type : GearType ,
65+ // Minimum XP required to use the gear
66+ pub min_xp_needed : u256 ,
67+ // Base damage value for the gear (0 for non-damaging items)
68+ pub base_damage : u64 ,
69+ // Maximum upgrade level for the gear
70+ pub max_upgrade_level : u64 ,
71+ // Initial total count for fungible items (default 1 for non-fungible)
72+ pub total_count : u64 ,
73+ // Reference to variation (e.g., specific model like "Iron Sword")
74+ pub variation_ref : u256 ,
75+ }
76+
6177#[derive(Drop , Copy , Serde , Default )]
6278pub struct GearProperties {
6379 asset_id : u256 ,
@@ -166,6 +182,52 @@ pub impl GearImpl of GearTrait {
166182 }
167183}
168184
185+ // Implementation of GearDetails with validation and default behavior
186+ #[generate_trait]
187+ pub impl GearDetailsImpl of GearDetailsTrait {
188+ // Creates a new GearDetails instance with validation
189+ fn new (
190+ gear_type : GearType ,
191+ min_xp_needed : u256 ,
192+ base_damage : u64 ,
193+ max_upgrade_level : u64 ,
194+ total_count : u64 ,
195+ variation_ref : u256 ,
196+ ) -> GearDetails {
197+ // Validate inputs
198+ assert (gear_type != GearType :: None , ' Gear type cannot be None' );
199+ assert (min_xp_needed >= 0 , ' Min XP cannot be negative' );
200+ assert (base_damage <= 1000 , ' Base damage exceeds max (1000)' );
201+ assert (max_upgrade_level > 0 , ' Max upgrade level must be > 0' );
202+ assert (total_count > 0 , ' Total count must be > 0' );
203+
204+ GearDetails {
205+ gear_type , min_xp_needed , base_damage , max_upgrade_level , total_count , variation_ref ,
206+ }
207+ }
208+
209+ // Validates the GearDetails instance
210+ fn validate (self : @ GearDetails ) -> bool {
211+ * self . gear_type != GearType :: None
212+ && * self . min_xp_needed >= 0
213+ && * self . base_damage <= 1000
214+ && * self . max_upgrade_level > 0
215+ && * self . total_count > 0
216+ }
217+
218+ // Creates a default GearDetails for testing or fallback
219+ fn default () -> GearDetails {
220+ GearDetails {
221+ gear_type : GearType :: Weapon ,
222+ min_xp_needed : 5 ,
223+ base_damage : 10 ,
224+ max_upgrade_level : 1 ,
225+ total_count : 1 ,
226+ variation_ref : 0 ,
227+ }
228+ }
229+ }
230+
169231// Implementation of conversion from GearType to felt252
170232impl GearTypeIntoFelt252 of Into <GearType , felt252 > {
171233 fn into (self : GearType ) -> felt252 {
@@ -425,3 +487,57 @@ impl OptionArrayTupleImpl of Clone<Option<Array<(u256, u256)>>> {
425487 }
426488 }
427489}
490+
491+ // Tests for GearDetails struct
492+ #[cfg(test)]
493+ mod tests {
494+ use super :: {GearDetails , GearDetailsImpl , GearType };
495+
496+ #[test]
497+ fn test_valid_gear_details () {
498+ let gear = GearDetailsImpl :: new (GearType :: Sword , 30 , 50 , 10 , 1 , 1 );
499+ assert! (gear . validate (), " Valid gear should pass validation" );
500+ assert (gear . gear_type == GearType :: Sword , ' Gear type mismatch' );
501+ assert (gear . min_xp_needed == 30 , ' Min XP mismatch' );
502+ assert (gear . base_damage == 50 , ' Base damage mismatch' );
503+ assert (gear . max_upgrade_level == 10 , ' Max upgrade level mismatch' );
504+ assert (gear . total_count == 1 , ' Total count mismatch' );
505+ assert (gear . variation_ref == 1 , ' Variation ref mismatch' );
506+ }
507+
508+ #[test]
509+ #[should_panic(expected: (' Gear type cannot be None' ,))]
510+ fn test_invalid_gear_type () {
511+ GearDetailsImpl :: new (GearType :: None , 5 , 10 , 1 , 1 , 0 );
512+ }
513+
514+ #[test]
515+ #[should_panic(expected: (' Base damage exceeds max (1000)' ,))]
516+ fn test_invalid_base_damage () {
517+ GearDetailsImpl :: new (GearType :: Weapon , 5 , 1001 , 1 , 1 , 0 );
518+ }
519+
520+ #[test]
521+ #[should_panic(expected: (' Max upgrade level must be > 0' ,))]
522+ fn test_invalid_max_upgrade_level () {
523+ GearDetailsImpl :: new (GearType :: Weapon , 5 , 10 , 0 , 1 , 0 );
524+ }
525+
526+ #[test]
527+ #[should_panic(expected: (' Total count must be > 0' ,))]
528+ fn test_invalid_total_count () {
529+ GearDetailsImpl :: new (GearType :: Weapon , 5 , 10 , 1 , 0 , 0 );
530+ }
531+
532+ #[test]
533+ fn test_default_gear_details () {
534+ let gear = GearDetailsImpl :: default ();
535+ assert (gear . validate (), ' Default gear should be valid' );
536+ assert (gear . gear_type == GearType :: Weapon , ' Default gear type mismatch' );
537+ assert (gear . min_xp_needed == 5 , ' Default min XP mismatch' );
538+ assert (gear . base_damage == 10 , ' Default base damage mismatch' );
539+ assert! (gear . max_upgrade_level == 1 , " Default max upgrade level mismatch" );
540+ assert (gear . total_count == 1 , ' Default total count mismatch' );
541+ assert (gear . variation_ref == 0 , ' Default variation ref mismatch' );
542+ }
543+ }
0 commit comments