rpg_stat/
material.rs

1/*!
2# 
3
4
5*/
6use std::fmt;
7use std::fmt::Debug;
8//use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign};
9extern crate num;
10use serde::{Deserialize, Serialize};
11
12#[cfg(feature = "fltkform")]
13use fltk::{prelude::*, *};
14#[cfg(feature = "fltkform")]
15use fltk_form_derive::*;
16#[cfg(feature = "fltkform")]
17use fltk_form::FltkForm;
18
19use crate::random::Random;
20
21/*
22# Armor 
23
24Basic Armor materials
25
26*/
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
28pub enum Armor {
29    /// Interlocking rings of metal forming a cloth-like armor
30    Mail,
31    /// Often metal, small rounded overlapping plates.
32    Scale,
33    /// Large metal pieces forming entire parts
34    Plate,
35    /// 
36    Splint,
37    /// Nothing
38    None,
39}
40impl Default for Armor {
41    fn default() -> Self {
42        Self::None
43    }
44}
45impl fmt::Display for Armor {
46    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47        let v:String;
48        match *self {
49            //Armor:: => v = String::from(""),
50            _=> v = String::from("None"),
51        }
52        write!(f, "{}", v.as_str())
53    }
54}
55
56/*
57# Advanced 
58
59*/
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
61pub enum Advanced {
62    /// 
63    Diamond,
64    /// 
65    Gold,
66    /// 
67    Gem,
68    /// 
69    Meteorite,
70    /// Nothing
71    None,
72}
73impl Default for Advanced {
74    fn default() -> Self {
75        Self::None
76    }
77}
78impl fmt::Display for Advanced {
79    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
80        let v:String;
81        match *self {
82            //Advanced:: => v = String::from(""),
83            _=> v = String::from("None"),
84        }
85        write!(f, "{}", v.as_str())
86    }
87}
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
89#[cfg_attr(feature = "fltkform", derive(FltkForm))]
90/*  
91# Drops
92
93*/
94pub enum Drops {
95    /// 
96    Feed,
97    /// 
98    Hide,
99    /// 
100    Scale,
101    /// 
102    Tooth,
103    /// 
104    Horn,
105    /// 
106    Talon,
107    /// 
108    Feather,
109    /// 
110    Claw,
111    /// 
112    Fang,
113    /// 
114    Bone,
115    /// 
116    Hair,
117    /// 
118    Jerky,
119    /// 
120    Oil,
121    /// 
122    Wool,
123    /// 
124    Pelt,
125    /// 
126    Leather,
127    /// 
128    Fur,
129    /// 
130    Tusk,
131    /// Nothing
132    None,
133}
134impl Default for Drops {
135    fn default() -> Self {
136        Self::None
137    }
138}
139impl fmt::Display for Drops {
140    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
141        let v:String;
142        match *self {
143            Drops::Feed => v = String::from("Feed"),
144            Drops::Hide => v = String::from("Hide"),
145            Drops::Scale => v = String::from("Scale"),
146            Drops::Tooth => v = String::from("Tooth"),
147            Drops::Horn => v = String::from("Horn"),
148            Drops::Talon => v = String::from("Talon"),
149            Drops::Feather => v = String::from("Feather"),
150            Drops::Claw => v = String::from("Claw"),
151            Drops::Fang => v = String::from("Fang"),
152            Drops::Bone => v = String::from("Bone"),
153            Drops::Hair => v = String::from("Hair"),
154            Drops::Jerky => v = String::from("Jerky"),
155            Drops::Oil => v = String::from("Oil"),
156            Drops::Wool => v = String::from("Wool"),
157            Drops::Pelt => v = String::from("Pelt"),
158            Drops::Leather => v = String::from("Leather"),
159            Drops::Fur => v = String::from("Fur"),
160            Drops::Tusk => v = String::from("Tusk"),
161            _=> v = String::from("None"),
162        }
163        write!(f, "{}", v.as_str())
164    }
165}
166impl Random for Drops {
167    type Type = Drops;
168    fn random_type(&self) -> Self::Type {
169        let max = 18;
170        let val = self.random_rate(max);
171        match val {
172            0 => Drops::Feed,
173            1 => Drops::Hide,
174            2 => Drops::Scale,
175            3 => Drops::Tooth,
176            4 => Drops::Horn,
177            5 => Drops::Talon,
178            6 => Drops::Feather,
179            7 => Drops::Claw,
180            8 => Drops::Fang,
181            9 => Drops::Bone,
182            10 => Drops::Hair,
183            11 => Drops::Jerky,
184            12 => Drops::Oil,
185            13 => Drops::Wool,
186            14 => Drops::Pelt,
187            15 => Drops::Leather,
188            16 => Drops::Fur,
189            17 => Drops::Tusk,
190            _=> Drops::None,
191        }
192    }
193    
194}
195impl Drops {
196    ///
197    pub fn list() -> Vec<Drops> {
198        vec![Drops::Feed, Drops::Hide, Drops::Scale, Drops::Tooth, Drops::Horn, Drops::Talon, Drops::Feather, Drops::Claw, Drops::Fang, Drops::Bone, Drops::Hair, Drops::Jerky, Drops::Oil, Drops::Wool, Drops::Pelt, Drops::Leather, Drops::Fur, Drops::Tusk]
199    }
200    /// 
201    pub fn get_price(drop:Drops) -> f64 {
202        drop.price()
203    }
204    pub fn price(&self) -> f64 {
205        match *self {
206           Drops::Feed =>  1.0,
207           Drops::Hide =>  2.0,
208           Drops::Scale =>  3.0,
209           Drops::Tooth =>  4.0,
210           Drops::Horn =>  5.0,
211           Drops::Talon =>  6.0,
212           Drops::Feather =>  7.0,
213           Drops::Claw =>  8.0,
214           Drops::Fang =>  9.0,
215           Drops::Bone =>  10.0,
216           Drops::Hair =>  11.0,
217           Drops::Jerky =>  12.0,
218           Drops::Oil =>  13.0,
219           Drops::Wool =>  14.0,
220           Drops::Pelt =>  15.0,
221           Drops::Leather =>  16.0,
222           Drops::Fur =>  17.0,
223           Drops::Tusk =>  18.0,
224           _=> 0.0,
225        }
226    }
227}
228#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
229#[cfg_attr(feature = "fltkform", derive(FltkForm))]
230/*
231
232*/
233pub struct DropBag {
234    pub feed:f64,
235    pub hide:f64,
236    pub scale:f64,
237    pub tooth:f64,
238    pub horn:f64,
239    pub talon:f64,
240    pub feather:f64,
241    pub claw:f64,
242    pub fang:f64,
243    pub bone:f64,
244    pub hair:f64,
245    pub jerky:f64,
246    pub oil:f64,
247    pub wool:f64,
248    pub pelt:f64,
249    pub leather:f64,
250    pub fur:f64,
251    pub tusk:f64,
252}
253impl DropBag {
254    pub fn new() -> Self {
255            DropBag {
256            feed:0.0,
257            hide:0.0,
258            scale:0.0,
259            tooth:0.0,
260            horn:0.0,
261            talon:0.0,
262            feather:0.0,
263            claw:0.0,
264            fang:0.0,
265            bone:0.0,
266            hair:0.0,
267            jerky:0.0,
268            oil:0.0,
269            wool:0.0,
270            pelt:0.0,
271            leather:0.0,
272            fur:0.0,
273            tusk:0.0,
274        }
275    }
276/*
277# Sell
278
279Sell an item from your bag
280*/
281    pub fn sell(&mut self, drop:Drops) -> f64 {
282        let mut price:f64 = 0.0;
283        match drop {
284            Drops::Feed =>  {
285                if self.feed >= 1.0 {
286                    self.feed -= 1.0;
287                    price = drop.price();
288                }
289            },
290            Drops::Hide =>  {
291                if self.hide >= 1.0 {
292                    self.hide -= 1.0;
293                    price = drop.price();
294                }
295            },
296            Drops::Scale =>  {
297                if self.scale >= 1.0 {
298                    self.scale -= 1.0;
299                    price = drop.price();
300                }
301            },
302            Drops::Tooth =>  {
303                if self.tooth >= 1.0 {
304                    self.tooth -= 1.0;
305                    price = drop.price();
306                }
307            },
308            Drops::Horn =>  {
309                if self.horn >= 1.0 {
310                    self.horn -= 1.0;
311                    price = drop.price();
312                }
313            },
314            Drops::Talon =>  {
315                if self.talon >= 1.0 {
316                    self.talon -= 1.0;
317                    price = drop.price();
318                }
319            },
320            Drops::Feather =>  {
321                if self.feather >= 1.0 {
322                    self.feather -= 1.0;
323                    price = drop.price();
324                }
325            },
326            Drops::Claw =>  {
327                if self.claw >= 1.0 {
328                    self.claw -= 1.0;
329                    price = drop.price();
330                }
331            },
332            Drops::Fang =>  {
333                if self.fang >= 1.0 {
334                    self.fang -= 1.0;
335                    price = drop.price();
336                }
337            },
338            Drops::Bone =>  {
339                if self.bone >= 1.0 {
340                    self.bone -= 1.0;
341                    price = drop.price();
342                }
343            },
344            Drops::Hair =>  {
345                if self.hair >= 1.0 {
346                    self.hair -= 1.0;
347                    price = drop.price();
348                }
349            },
350            Drops::Jerky =>  {
351                if self.jerky >= 1.0 {
352                    self.jerky -= 1.0;
353                    price = drop.price();
354                }
355            },
356            Drops::Oil =>  {
357                if self.oil >= 1.0 {
358                    self.oil -= 1.0;
359                    price = drop.price();
360                }
361            },
362            Drops::Wool =>  {
363                if self.wool >= 1.0 {
364                    self.wool -= 1.0;
365                    price = drop.price();
366                }
367            },
368            Drops::Pelt =>  {
369                if self.pelt >= 1.0 {
370                    self.pelt -= 1.0;
371                    price = drop.price();
372                }
373            },
374            Drops::Leather =>  {
375                if self.leather >= 1.0 {
376                    self.leather -= 1.0;
377                    price = drop.price();
378                }
379            },
380            Drops::Fur =>  {
381                if self.fur >= 1.0 {
382                    self.fur -= 1.0;
383                    price = drop.price();
384                }
385            },
386            Drops::Tusk =>  {
387                if self.tusk >= 1.0 {
388                    self.tusk -= 1.0;
389                    price = drop.price();
390                }
391            },
392            _=> (),
393        }
394        price
395    }
396/*
397# Get
398
399Get an item into your bag
400*/
401    pub fn get(&mut self, drop:Drops) {
402        match drop {
403            Drops::Feed =>  self.feed += 1.0,
404            Drops::Hide =>  self.hide += 1.0,
405            Drops::Scale =>  self.scale += 1.0,
406            Drops::Tooth =>  self.tooth += 1.0,
407            Drops::Horn =>  self.horn += 1.0,
408            Drops::Talon =>  self.talon += 1.0,
409            Drops::Feather =>  self.feather += 1.0,
410            Drops::Claw =>  self.claw += 1.0,
411            Drops::Fang =>  self.fang += 1.0,
412            Drops::Bone =>  self.bone += 1.0,
413            Drops::Hair =>  self.hair += 1.0,
414            Drops::Jerky =>  self.jerky += 1.0,
415            Drops::Oil =>  self.oil += 1.0,
416            Drops::Wool =>  self.wool += 1.0,
417            Drops::Pelt =>  self.pelt += 1.0,
418            Drops::Leather =>  self.leather += 1.0,
419            Drops::Fur =>  self.fur += 1.0,
420            Drops::Tusk =>  self.tusk += 1.0,
421            _=> (),
422        }
423    }
424}
425impl Default for DropBag {
426    fn default() -> Self {
427        Self::new()
428    }
429}