Commits

Johan Euphrosine committed 533547e

fix attack in web client

  • Participants
  • Parent commits 9c50c79

Comments (0)

Files changed (3)

File websocket/public/lib/client.js

                   break;
                 }
                 else {
-                  var obj = inventory_map[t][0];
-                  sendUse(map_action_map[o.oc][t][p].action, obj.id, o.id);
-                  break;
+                  if (inventory_map[t]) {
+                    var obj = inventory_map[t][0];
+                    sendUse(map_action_map[o.oc][t][p].action, obj.id, o.id);
+                    break;
+                  }
                 }
               }
             }

File websocket/public/test/mockup.js

     classes : [ { id: 1, icon: 'a.png' }, 
                 { id: 2, icon: 'b.png' },
                 { id: 3, icon: 'c.png' },
-                { id: 4, icon: 'd.png' } ],
+                { id: 4, icon: 'd.png' },
+                { id: 5, icon: 'e.png' }],
     actions : [ { id: 1, name: "PickUp" , range : 100 , target: []},
-                { id: 2, name: "Drop" , range : 0} ],
+                { id: 2, name: "Drop" , range : 0},
+                { id: 3, name: "Attack" , range : 0}],
     interactions : [ {context:"map",object:3,action:1,range:100},
                      {context:"inventory",object:3,action:2,range:0},
-                     {context:"inventory",object:3,action:3,range:100,points:10,target:2} ]
+                     {context:"inventory",object:3,action:3,range:100,points:10,target:2},
+                     {context:"map",object:5,action:1,range:100},
+                     {context:"inventory",object:5,action:2,range:0},
+                     {context:"inventory",object:5,action:3,range:100,points:10,target:2}]
   }
 };

File websocket/public/test/test.js

   });
 
   conn.onmessage({data: JSON.stringify({t: 'logon', player: {player: {"id" : 1 , "device_id" : "42424242"}}})});
-  conn.onmessage({data: JSON.stringify({t: 'P', lon: 1, lat: 2, id: 1, oc: 1, inventory: {1: {oc: 3, id: 1}, 2: {oc: 3, id: 2 }}})});
+  conn.onmessage({data: JSON.stringify({t: 'P', lon: 1, lat: 2, id: 1, oc: 1, inventory: {1: {oc: 3, id: 2}}})});
   conn.onmessage({data: JSON.stringify({t: 'C', lon: 1, lat: 2, id: 3, oc: 2 })});
 
   capture.markerTap(undefined, undefined, undefined, [{objectId: 3}]);
   equal(capture.packets.length, 1);
   equal(JSON.parse(capture.packets[0]).t, 'use');
   equal(JSON.parse(capture.packets[0]).action, 3);
-  equal(JSON.parse(capture.packets[0]).object, 1);
+  equal(JSON.parse(capture.packets[0]).object, 2);
+  equal(JSON.parse(capture.packets[0]).target, 3);
+});
+
+test('handle use attack 2', function() {
+  expect(5);
+
+  var capture = {}, conn = mockup.conn(capture), c = client({
+    conn: conn,
+    T5: mockup.T5(capture),
+    resources: mockup.resources,
+    navigator: navigator
+  });
+
+  conn.onmessage({data: JSON.stringify({t: 'logon', player: {player: {"id" : 1 , "device_id" : "42424242"}}})});
+  conn.onmessage({data: JSON.stringify({t: 'P', lon: 1, lat: 2, id: 1, oc: 1, inventory: {2: {oc: 5, id: 2}}})});
+  conn.onmessage({data: JSON.stringify({t: 'C', lon: 1, lat: 2, id: 3, oc: 2 })});
+
+  capture.markerTap(undefined, undefined, undefined, [{objectId: 3}]);
+  equal(capture.packets.length, 1);
+  equal(JSON.parse(capture.packets[0]).t, 'use');
+  equal(JSON.parse(capture.packets[0]).action, 3);
+  equal(JSON.parse(capture.packets[0]).object, 2);
   equal(JSON.parse(capture.packets[0]).target, 3);
 });