function s4() {
  return Math.floor((1 + Math.random()) * 0x10000)
    .toString(16)
    .substring(1);
}

function guid() {
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}

var Inventory = {
    create: function(name, coin, items, id) {
        var self = Object.create(this);
        self.name = name;
        self.coin = coin || { gp: 0, sp: 0, cp: 0};
        self.items = items || {};
        self.id = id || guid();

        return self;
    },

    newItem: function(name, val, desc, id) {
        var value = Object.assign({}, { gp: 0, sp: 0, cp: 0 }, val);
        var item = { name, value, desc };
        item.id = id || guid();

        this.items[item.id] = item;
        return item;
    },

    removeItem: function(id) {
        var item = this.items[id];
        delete this.items[id];
        return item;
    },

    getItem: function(id) {
        return this.items[id];
    },

    update: function(invUpdate) {
        this.name = invUpdate.name || this.name;
        if(invUpdate.coin !== undefined) {
            if(invUpdate.coin.gp !== undefined) this.coin.gp = invUpdate.coin.gp;
            if(invUpdate.coin.sp !== undefined) this.coin.sp = invUpdate.coin.sp;
            if(invUpdate.coin.cp !== undefined) this.coin.cp = invUpdate.coin.cp;
        }
        if(invUpdate.items !== undefined) this.items = invUpdate.items;
    },

    updateItem: function(id, itemUpdate) {
        var item = this.items[id];

        item.name = itemUpdate.name || item.name;
        if(itemUpdate.value !== undefined) item.value = itemUpdate.value;
        item.desc = itemUpdate.desc || item.desc;
        if(itemUpdate.weight !== undefined) item.weight = itemUpdate.weight;
        return item;
    },

    sellItem: function(id, coin) {
        var item = this.removeItem(id);

        if(!isNaN(coin.gp)) this.coin.gp += coin.gp;
        if(!isNaN(coin.sp)) this.coin.sp += coin.sp;
        if(!isNaN(coin.cp)) this.coin.cp += coin.cp;

        return item;
    },

    buyItem: function(item, coin) {
        this.items[item.id] = item;

        if(!isNaN(coin.gp)) this.coin.gp -= coin.gp;
        if(!isNaN(coin.sp)) this.coin.sp -= coin.sp;
        if(!isNaN(coin.cp)) this.coin.cp -= coin.cp;
    }
};

@@ -1830,25 +1830,24 @@
 em(id);%0A
-%0A
         
 if(!isNa
@@ -1838,35 +1838,92 @@
         
-if(!isNaN(coin.gp))
+var transaction = Object.assign(%7B%7D, %7B gp: 0, sp: 0, cp: 0 %7D, coin);%0A%0A       
  this.co
@@ -1931,19 +1931,26 @@
 n.gp += 
-coi
+transactio
 n.gp;%0A  
@@ -1954,36 +1954,16 @@
 %0A       
- if(!isNaN(coin.sp))
  this.co
@@ -1971,19 +1971,26 @@
 n.sp += 
-coi
+transactio
 n.sp;%0A  
@@ -1994,36 +1994,16 @@
 %0A       
- if(!isNaN(coin.cp))
  this.co
@@ -2011,19 +2011,26 @@
 n.cp += 
-coi
+transactio
 n.cp;%0A%0A 
@@ -2129,25 +2129,24 @@
 = item;%0A
-%0A
         
 if(!isNa
@@ -2141,27 +2141,84 @@
     
-if(!isNaN(coin.gp))
+var transaction = Object.assign(%7B%7D, %7B gp: 0, sp: 0, cp: 0 %7D, coin);%0A%0A       
  thi
@@ -2230,19 +2230,26 @@
 n.gp -= 
-coi
+transactio
 n.gp;%0A  
@@ -2257,28 +2257,8 @@
     
- if(!isNaN(coin.sp))
  thi
@@ -2270,19 +2270,26 @@
 n.sp -= 
-coi
+transactio
 n.sp;%0A  
@@ -2297,28 +2297,8 @@
     
- if(!isNaN(coin.cp))
  thi
@@ -2310,19 +2310,26 @@
 n.cp -= 
-coi
+transactio
 n.cp;%0A  

Update item transactions