Advertisement
madmenyo

Item example for database storage

Sep 18th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public class WeaponExample {
  2.     Weapon weapon = new Weapon();
  3.  
  4.     public WeaponExample()
  5.     {
  6.         weapon.name = "sword";
  7.         weapon.damage = 10;
  8.         weapon.levelRequirement = 4;
  9.  
  10.         //create a modifier that adds extra strength to the character
  11.         Modifier modifier1 = new Modifier();
  12.         modifier1.type = "strength";
  13.         modifier1.amount = 5;
  14.  
  15.         //create a modifier for 10% extra damage against undead
  16.         Modifier modifier2 = new Modifier();
  17.         modifier2.type = "undead";
  18.         modifier2.percentage = 10;
  19.  
  20.         //add them to the weapon
  21.         weapon.modifiers.add(modifier1);
  22.         weapon.modifiers.add(modifier2);
  23.  
  24.         //serialize weapon.modifiers to store in database.
  25.         //..
  26.     }
  27.  
  28. }
  29.  
  30. class Weapon {
  31.     //Basic weapon data
  32.     public String name;
  33.     public int damage;
  34.     public int levelRequirement;
  35.     //... etc
  36.  
  37.     //Data to be serialized to binary and stored
  38.     List<Modifier> modifiers;
  39. }
  40.  
  41. class Modifier {
  42.     public String type;
  43.     public int percentage;
  44.     public int amount;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement