Dancer_A

Item_Data.cs

Oct 10th, 2015 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System.IO;
  2.  
  3. namespace FEXNA_Library
  4. {
  5.     public enum Item_Data_Type { Weapon, Item }
  6.     public class Item_Data
  7.     {
  8.         public Item_Data_Type Type = Item_Data_Type.Weapon;
  9.         public int Id = 0;
  10.         public int Uses = 0;
  11.         public int Cost = 0;
  12.  
  13.         #region Serialization
  14.         public static Item_Data read(BinaryReader reader)
  15.         {
  16.             int count = reader.ReadInt32();
  17.             if (count == 4)
  18.                 return new Item_Data(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
  19.             else //Debug
  20.                 return new Item_Data(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
  21.         }
  22.        
  23.         public void write(BinaryWriter writer)
  24.         {
  25.             if (true) //Debug
  26.             {
  27.                 writer.Write(4);
  28.                 writer.Write((int)Type);
  29.                 writer.Write(Id);
  30.                 writer.Write(Uses);
  31.                 writer.Write(Cost);
  32.             }
  33.         }
  34.         #endregion
  35.  
  36.         public Item_Data() { }
  37.         public Item_Data(Item_Data_Type type, int id, int uses)
  38.         {
  39.             Type = type;
  40.             Id = id;
  41.             Uses = uses;
  42.         }
  43.         public Item_Data(Item_Data_Type type, int id, int uses, int cost)
  44.         {
  45.             Type = type;
  46.             Id = id;
  47.             Uses = uses;
  48.             Cost = cost;
  49.         }
  50.        
  51.         public Item_Data(int type, int id, int uses, int cost) : this((Item_Data_Type)type, id, uses, cost) { }
  52.         public Item_Data(Item_Data data) : this(data.Type, data.Id, data.Uses, data.Cost) { }
  53.  
  54.         public bool is_weapon
  55.         {
  56.             get { return Type == Item_Data_Type.Weapon; }
  57.         }
  58.  
  59.         public bool is_item
  60.         {
  61.             get { return Type == Item_Data_Type.Item; }
  62.         }
  63.  
  64.         public bool blank_item
  65.         {
  66.             get { return Type == Item_Data_Type.Weapon && Id == 0 && Uses == 0; }
  67.         }
  68.  
  69.         public bool same_item(Item_Data item)
  70.         {
  71.             return Type == item.Type && Id == item.Id;
  72.         }
  73.     }
  74. }
Add Comment
Please, Sign In to add comment