ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/html5client/main.js
Revision: 1.10
Committed: Tue Nov 6 18:31:55 2012 UTC (11 years, 6 months ago) by root
Content type: application/javascript
Branch: MAIN
Changes since 1.9: +11 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 String.prototype.each = function (f,p){
2     for (var i=0;i<this.length;++i){
3     f.apply(this,[this[i],i,p]);
4     }
5     };
6    
7     Array.prototype.each = function (f,p){
8     for (var i=0;i<this.length;++i){
9     f.apply(this,[this[i],i,p]);
10     }
11     };
12    
13     Array.prototype.contains = function (e){
14     return this.indexOf(e) >= 0 && this.indexOf(e)<this.length;
15     }
16    
17     var canvas = null;
18     var canvasID = 'main';
19     var ctx = null;
20     var stage = null;
21     var Messages = [];
22     var output = null;
23     var commandline = null;
24    
25     var channels = {length: 0,list: []};
26    
27     var clickable = [];
28    
29     var extmap = true;
30     var Map = [];
31     var oldMapName = "";
32     var drawInventory = false;
33    
34     messageBox = window.alert;
35    
36     alert = function (s){
37     writeToScreen(s);
38     }
39    
40     var floorItems = [];
41     var myItems = [];
42     var mySpells = [];
43     var myStats = [];
44    
45    
46     var skillNames = [];
47    
48     var skipKeyTest = false;
49 sf-demisephi 1.4
50 root 1.1 var keys = {
51     shift: 0,
52     alt: 0,
53 sf-demisephi 1.3 ctrl: 0,
54     states : []
55 root 1.1 };
56    
57 sf-demisephi 1.4 var player = {
58     tag: 0,
59     weight: 0,
60     face: 0,
61     name: ""
62     }
63    
64    
65 root 1.1 var versionInfo = {
66     perlver: "5.014002",
67     clientver: "3.0Af0000000",
68     client: "deliantra",
69     gl_vendor: "NVIDIA Corporation",
70     gl_version: "4.2.0 NVIDIA 302.11",
71     modulever: "1.31",
72     osver: "linux",
73     protver: 1
74     };
75     var expTableFacenum = -1;
76    
77 sf-demisephi 1.3 var isRunning = false;
78     var isFiring = false;
79     mapsize = {width: 0,height:0};
80    
81 root 1.1 function appendToBody(e){
82     document.getElementsByTagName("body")[0].appendChild(e);
83     }
84    
85     function getPassword (){
86     return document.getElementById("password").value.trim();
87     }
88    
89     function getLogin (){
90     return document.getElementById("login").value.trim();
91     }
92    
93     function createCommandWindow (){
94     var div = createWindow("command",250,250,stage.stageWidth/2-250/2,stage.stageHeight-250/2);
95     var login = document.createElement("input");
96     login.type = "text";
97     login.placeholder = login.id = "command";
98     login.style.width = "100%";
99    
100 sf-demisephi 1.4 div.contents.appendChild(login);
101 root 1.1
102     var button = document.createElement("input");
103     button.type = "button";
104     button.value = "execute command";
105     button.style.width = "100%";
106 sf-demisephi 1.4 div.contents.appendChild(button);
107 root 1.1 button.addEventListener("click",function (e){
108 sf-demisephi 1.4 doSend("command " + login.value);
109     xCommmandWindow.show(false);
110 root 1.1 skipKeyTest = false;
111     })
112     var button = document.createElement("input");
113     button.type = "button";
114     button.value = "cancel";
115     button.style.width = "100%";
116 sf-demisephi 1.4 div.contents.appendChild(button);
117 root 1.1 button.addEventListener("click",function (e){
118 sf-demisephi 1.4 xCommmandWindow.show(false);
119 root 1.1 skipKeyTest = false;
120     })
121     return div;
122    
123     }
124    
125     var xMapWindow = null;
126     var xFloorWindow = null;
127     var xPlayerWindow = null;
128     var pattern = null;
129     var patternImage = null;
130     var isMainCalled = false;
131     var xInfoWindow = null;
132 sf-demisephi 1.3 var xBarsWindow = null;
133 sf-demisephi 1.4 var xCommmandWindow = null;
134     var xChatBoxWindow = null;
135 root 1.1
136 root 1.8 var wsUri = "ws://testserver.deliantra.net:13327/ws";
137     //var wsUri = "ws://localhost:13327/ws";
138 root 1.1
139     function createWebSocket(){
140     var websocket = new WebSocket(wsUri);
141     websocket.onopen = function(evt) { onOpen(evt) };
142     websocket.onclose = function(evt) { onClose(evt) };
143     websocket.onmessage = function(evt) { onMessage(evt) };
144     websocket.onerror = function(evt) { onError(evt) };
145     return websocket;
146     }
147    
148    
149    
150     function createLoginWindow(){
151     var div = createWindow("login",260,180,stage.stageWidth/2-250/2,stage.stageHeight/2-250/2).contents;;
152     var login = document.createElement("input");
153     login.type = "text";
154     login.placeholder = login.id = "login";
155     login.style.width = "100%";
156     login.value = "deliantra login";
157     div.appendChild(login);
158     var password = document.createElement("input");
159     password.type = "password";
160     password.value = "";
161     password.style.width = "100%";
162     password.placeholder = password.id = "password";
163     div.appendChild(password);
164    
165     var button = document.createElement("input");
166     button.type = "button";
167     button.value = "logmein";
168     button.style.width = "100%";
169     div.appendChild(button);
170    
171    
172     button.addEventListener("click",function (e){
173     div.parent.style.display="none";
174     xMapWindow.contents.appendChild(canvas);
175     xMapWindow.show(true);
176     xFloorWindow.show(true);
177 sf-demisephi 1.3 xBarsWindow.show(true);
178 root 1.1 ctx.fillStyle = "#000";
179    
180 sf-demisephi 1.4
181 root 1.1 setInterval(draw,1000/5);
182    
183     websocket = new WebSocket(wsUri);
184     websocket.onopen = function(evt) { onOpen(evt) };
185     websocket.onclose = function(evt) { onClose(evt) };
186     websocket.onmessage = function(evt) { onMessage(evt) };
187     websocket.onerror = function(evt) { onError(evt) };
188     })
189     button = document.createElement("input");
190     button.type = "button";
191     button.value = "logmeinasnull";
192     button.style.width = "100%";
193     div.appendChild(button);
194     button.addEventListener("click",function (e){
195     login.value = password.value = "null";
196     div.parent.style.display="none";
197     xMapWindow.contents.appendChild(canvas);
198     xMapWindow.show(true);
199     xFloorWindow.show(true);
200 sf-demisephi 1.3 xBarsWindow.show(true);
201 root 1.1 ctx.fillStyle = "#000";
202     ctx.font = "10px Courier New,MonoSpace";
203     setInterval(draw,1000/5);
204    
205     websocket = new WebSocket(wsUri);
206     websocket.onopen = function(evt) { onOpen(evt) };
207     websocket.onclose = function(evt) { onClose(evt) };
208     websocket.onmessage = function(evt) { onMessage(evt) };
209     websocket.onerror = function(evt) { onError(evt) };
210     })
211     button = document.createElement("input");
212     button.type = "button";
213     button.value = "logmeinasNULL";
214     button.style.width = "100%";
215     div.appendChild(button);
216     button.addEventListener("click",function (e){
217     login.value = password.value = "NULL";
218     div.parent.style.display="none";
219     xMapWindow.contents.appendChild(canvas);
220     xMapWindow.show(true);
221     xFloorWindow.show(true);
222 sf-demisephi 1.3 xBarsWindow.show(true);
223 root 1.1 ctx.fillStyle = "#000";
224     ctx.font = "10px Courier New,MonoSpace";
225     setInterval(draw,1000/5);
226     websocket = new WebSocket(wsUri);
227     websocket.onopen = function(evt) { onOpen(evt) };
228     websocket.onclose = function(evt) { onClose(evt) };
229     websocket.onmessage = function(evt) { onMessage(evt) };
230     websocket.onerror = function(evt) { onError(evt) };
231     })
232     button = document.createElement("input");
233     button.type = "button";
234     button.value = "logmeinasVOID";
235     button.style.width = "100%";
236     div.appendChild(button);
237     button.addEventListener("click",function (e){
238     login.value = password.value = "VOID";
239     div.parent.style.display="none";
240     xMapWindow.contents.appendChild(canvas);
241     xMapWindow.show(true);
242     xFloorWindow.show(true);
243 sf-demisephi 1.3 xBarsWindow.show(true);
244 root 1.1 ctx.fillStyle = "#000";
245     ctx.font = "10px Courier New,MonoSpace";
246     setInterval(draw,1000/5);
247     websocket = new WebSocket(wsUri);
248     websocket.onopen = function(evt) { onOpen(evt) };
249     websocket.onclose = function(evt) { onClose(evt) };
250     websocket.onmessage = function(evt) { onMessage(evt) };
251     websocket.onerror = function(evt) { onError(evt) };
252     })
253     return div.parent;
254    
255    
256     }
257    
258 sf-demisephi 1.3 function draw(){
259     xBarsWindow.ctx.fillStyle = "#000";
260     xBarsWindow.ctx.fillRect(0,0,xBarsWindow.sw,xBarsWindow.sh);
261    
262    
263     if ( typeof (myStats[CS_STAT_MAXHP]) == typeof(1)){
264     xBarsWindow.ctx.save();
265    
266     xBarsWindow.ctx.fillStyle = "#F00";
267     xBarsWindow.ctx.globalAlpha = 0.5;
268     xBarsWindow.ctx.fillRect(10,10,20,xBarsWindow.sh);
269     xBarsWindow.ctx.fillRect(10,10+xBarsWindow.sh-(myStats[CS_STAT_HP]/myStats[CS_STAT_MAXHP])*xBarsWindow.sh,20,(myStats[CS_STAT_HP]/myStats[CS_STAT_MAXHP])*xBarsWindow.sh);
270     xBarsWindow.ctx.restore();
271     }
272    
273     if ( typeof (myStats[CS_STAT_MAXSP]) == typeof(1)){
274     xBarsWindow.ctx.save();
275    
276     xBarsWindow.ctx.fillStyle = "#00F";
277     xBarsWindow.ctx.globalAlpha = 0.5;
278     xBarsWindow.ctx.fillRect(50,10,20,xBarsWindow.sh);
279     xBarsWindow.ctx.fillRect(50,10+xBarsWindow.sh-(myStats[CS_STAT_SP]/myStats[CS_STAT_MAXSP])*xBarsWindow.sh,20,(myStats[CS_STAT_SP]/myStats[CS_STAT_MAXSP])*xBarsWindow.sh);
280     xBarsWindow.ctx.restore();
281     }
282     if ( typeof (myStats[CS_STAT_MAXGRACE]) == typeof(1)){
283     xBarsWindow.ctx.save();
284     xBarsWindow.ctx.fillStyle = "#0FF";
285     xBarsWindow.ctx.globalAlpha = 0.5;
286     xBarsWindow.ctx.fillRect(90,10,20,xBarsWindow.sh);
287     xBarsWindow.ctx.fillRect(90,10+xBarsWindow.sh-(myStats[CS_STAT_GRACE]/myStats[CS_STAT_MAXGRACE])*xBarsWindow.sh,20,(myStats[CS_STAT_GRACE]/myStats[CS_STAT_MAXGRACE])*xBarsWindow.sh);
288     xBarsWindow.ctx.restore();
289     }
290    
291     if ( typeof (myStats[CS_STAT_FOOD]) == typeof(1)){
292     xBarsWindow.ctx.save();
293     xBarsWindow.ctx.fillStyle = "#ff0";
294     xBarsWindow.ctx.globalAlpha = 0.5;
295     xBarsWindow.ctx.fillRect(130,10,20,xBarsWindow.sh);
296     xBarsWindow.ctx.fillRect(130,10+xBarsWindow.sh-(myStats[CS_STAT_FOOD]/999)*xBarsWindow.sh,20,(myStats[CS_STAT_FOOD]/999)*xBarsWindow.sh);
297     xBarsWindow.ctx.restore();
298     }
299     }
300    
301 root 1.1 function main (){
302 sf-demisephi 1.3
303     for (var i = 0;i<255;++i){
304     keys.states[i]=0;
305     };
306    
307 root 1.1 if (isMainCalled==true){
308     isMainCalled = true;
309     return;
310     }
311    
312     window.WebSocket = window.WebSocket || window.MozWebSocket;
313    
314     if (window.WebSocket){
315    
316    
317     canvas = document.createElement("canvas");
318     var sw = canvas.width = window.innerWidth-10;
319     var sh = canvas.height =window.innerHeight-10;
320     var dx = Math.floor(sw/64);
321     var dy = Math.floor((sh-120)/64);
322    
323     dx = dy = Math.min(dx,dy);
324     stage = {stageWidth:sw,stageHeight:sh};
325     var logWindow = createWindow("log",stage.stageWidth,120,0,0);
326     xMapWindow = createWindow("map",dx*64+30,dy*64+30,0,120);
327     xMapWindow.style.top = (sh-xMapWindow.height()-20)+"px";
328     xMapWindow.show(false);
329     canvas.width = xMapWindow.width()-10;
330     canvas.height = xMapWindow.height()-25;
331    
332    
333    
334    
335     xFloorWindow = createWindow("floor",Math.floor((sw-xMapWindow.width()-30)/2),350,xMapWindow.width()+30,stage.stageHeight-20-350);
336     xFloorWindow.show(false);
337    
338     xPlayerWindow = createWindow("player",sw - 30,sh-30,10,10);
339     //xPlayerWindow.show(false);
340    
341     xPlayerWindow.contents.innerHTML = "";
342     var buttons = ["Statistics","Skills","SpellBook","Inventory"];
343     var div = document.createElement("div");
344     div.className = "buttons_widnow_content";
345     xPlayerWindow.contents.appendChild(div);
346    
347     for (var i = 0;i<buttons.length;++i){
348     var button = document.createElement("input");
349     button.type="button";
350     button.value = buttons[i] + " (F"+(i+2)+")";
351     button.addEventListener("click",showPlayerTab);
352     div.appendChild(button);
353     }
354     div = document.createElement("div");
355     div.className = "player_widnow_content";
356     xPlayerWindow.contents.appendChild(div);
357    
358     div = document.createElement("div");
359     div.className = "floor_widnow_content";
360     xPlayerWindow.contents.appendChild(div);
361    
362     div = document.createElement("div");
363     div.className = "spellbook_widnow_content";
364     xPlayerWindow.contents.appendChild(div);
365    
366     div = document.createElement("div");
367     div.className = "skills_widnow_content";
368     xPlayerWindow.contents.appendChild(div);
369 sf-demisephi 1.3
370     div = document.createElement("div");
371     div.className = "statistics_widnow_content";
372     xPlayerWindow.contents.appendChild(div);
373    
374 root 1.1 hideAllPlayerTabs();
375    
376     xPlayerWindow.show(false);
377     ctx = canvas.getContext('2d');
378    
379     appendToBody(createLoginWindow());
380     window.addEventListener("click",onClick);
381     window.addEventListener("contextmenu",onClick);
382     window.addEventListener("mousemove",onMouseMove);
383     window.addEventListener("mouseup",onMouseUp);
384    
385     //document.getElementsByTagName("body")[0].addEventListener("contextmenu",onClick);
386     //document.addEventListener("contextmenu",onClick);
387    
388 sf-demisephi 1.3 output = $_("textarea");
389 root 1.1
390     output.style.opacity ="0.3";
391     output.style.filter ="filter:alpha(opacity=30);";
392    
393     output.style.width = "99%"
394     output.style.height = "70%";
395     logWindow.contents.appendChild(output);
396    
397 sf-demisephi 1.3 xBarsWindow = createWindow("bars",250,300,sw - 280,sh-320);
398     var barsCanvas = $_("canvas");
399     barsCanvas.width = xBarsWindow.sw = xBarsWindow.width() - 20;
400     barsCanvas.height =xBarsWindow.sh = xBarsWindow.height() - 20;
401     xBarsWindow.contents.appendChild(barsCanvas);
402     xBarsWindow.ctx = barsCanvas.getContext("2d");
403     xBarsWindow.ctx.fillStyle = "#000";
404     xBarsWindow.ctx.fillRect(0,0,xBarsWindow.sw,xBarsWindow.sh);
405     xBarsWindow.show(false);
406 root 1.1 xInfoWindow = createWindow("info",300,200,-400,-300);
407     xInfoWindow.show(false);
408 sf-demisephi 1.4 xCommmandWindow = createCommandWindow();
409     xCommmandWindow.show(false);
410     xChatBoxWindow = createWindow("chatbox",sw-xMapWindow.width()-20,300,sw-(sw-xMapWindow.width()-20),logWindow.height()+10);
411     xChatBoxWindow.buttonsContainer = $_("div");
412     xChatBoxWindow.contents.appendChild(xChatBoxWindow.buttonsContainer);
413     xChatBoxWindow.channelContainer = $_("div");
414     xChatBoxWindow.channelContainer.style.height = "100%";
415     xChatBoxWindow.contents.appendChild(xChatBoxWindow.channelContainer);
416    
417 root 1.1
418     }
419     };
420    
421     var currentWindow=null;
422     var currentWindowOffset = {x:0,y:0};
423     var currentWindowResize = false;
424    
425 sf-demisephi 1.3 function showPlayerTab (e,tn){
426    
427     xPlayerWindow.show(true);
428     var tabName = tn ? tn : (this.value).split(" ")[0].toLowerCase();
429 root 1.1
430     var div;
431    
432     switch (tabName){
433     case "inventory":
434     hideAllPlayerTabs();
435     var content = xPlayerWindow.getElementsByClassName("player_widnow_content")[0];
436     content.style.display = "block";
437     content = xPlayerWindow.getElementsByClassName("floor_widnow_content")[0];
438     content.style.display = "block";
439     updateItemsList();
440     break;
441     case "spellbook":
442    
443     hideAllPlayerTabs();
444     var content = xPlayerWindow.getElementsByClassName("spellbook_widnow_content")[0];
445     content.style.display = "block";
446     updateSpellList();
447     break;
448     case "skills":
449     hideAllPlayerTabs();
450     var content = xPlayerWindow.getElementsByClassName("skills_widnow_content")[0];
451     content.style.display = "block";
452     updateSkillList();
453 sf-demisephi 1.3 break;;
454     case "statistics":
455     hideAllPlayerTabs();
456     var content = xPlayerWindow.getElementsByClassName("statistics_widnow_content")[0];
457     content.style.display = "block";
458     updateStatsList();
459     break;;
460 root 1.1 default:
461 sf-demisephi 1.3
462 root 1.1 break;
463     }
464     }
465 sf-demisephi 1.3 var playerTabs = ["player_widnow_content","floor_widnow_content","spellbook_widnow_content","skills_widnow_content","statistics_widnow_content"];
466 root 1.1
467     function hideAllPlayerTabs (){
468     for (var i = 0;i<playerTabs.length;++i){
469     xPlayerWindow.getElementsByClassName(playerTabs[i])[0].style.display="none";
470     }
471     }
472    
473 sf-demisephi 1.3 function updateStatsList(){
474     var content = xPlayerWindow.getElementsByClassName("statistics_widnow_content")[0];
475     var div;
476     content.innerHTML = "";
477     var tableLeft;
478     var tableRight;
479     var tr;
480     var td;
481    
482     content.appendChild(div=$_("div"));
483     div.innerHTML = "Primary/Secondary statistics.";
484     content.appendChild($_("hr"));
485     content.appendChild(tableLeft = $_("table"));
486     tableLeft.style.width="45%";
487     tableLeft.style.float = "left";
488     content.appendChild(tableRight = $_("table"));
489     tableRight.style.width="45%";
490     tableRight.style.float = "right";
491     content.appendChild(div=$_("br"));
492     content.appendChild(div=$_("br"));
493     content.appendChild(div=$_("div"));
494     div.innerHTML = "Resistances.";
495     div.style.clear = "both";
496     content.appendChild($_("hr"));
497    
498     var j=0;
499    
500     var basicStats = [CS_STAT_STR,CS_STAT_INT,CS_STAT_WIS,CS_STAT_DEX,CS_STAT_CON,CS_STAT_CHA,CS_STAT_WC,CS_STAT_AC,CS_STAT_DAM,/*CS_STAT_ARMOUR,*/CS_STAT_SPEED,CS_STAT_WEAP_SP];
501     var basicStatsNames = ['CS_STAT_STR','CS_STAT_INT','CS_STAT_WIS','CS_STAT_DEX','CS_STAT_CON','CS_STAT_CHA','CS_STAT_WC','CS_STAT_AC','CS_STAT_DAM',/*'CS_STAT_ARMOUR',*/'CS_STAT_SPEED','CS_STAT_WEAP_SP'];
502    
503    
504     for (i=0;i<basicStats.length;++i){
505    
506     var table = i<6 ? tableLeft : tableRight;
507    
508     table.appendChild(tr = $_("tr"));
509     tr.index = i;
510    
511    
512     tr.appendChild(td=$_("td"));
513     td.innerHTML = basicStatsNames[i];
514    
515    
516     tr.appendChild(td=$_("td"));
517     td.innerHTML = myStats[basicStats[i]];
518    
519     };
520     var resNames = ['CS_STAT_RES_PHYS','CS_STAT_RES_MAG','CS_STAT_RES_FIRE','CS_STAT_RES_ELEC','CS_STAT_RES_COLD','CS_STAT_RES_CONF','CS_STAT_RES_ACID',
521     'CS_STAT_RES_DRAIN','CS_STAT_RES_GHOSTHIT','CS_STAT_RES_POISON','CS_STAT_RES_SLOW','CS_STAT_RES_PARA','CS_STAT_TURN_UNDEAD','CS_STAT_RES_FEAR',
522     'CS_STAT_RES_DEPLETE', 'CS_STAT_RES_DEATH', 'CS_STAT_RES_HOLYWORD','CS_STAT_RES_BLIND'];
523    
524     content.appendChild(tableLeft = $_("table"));
525     tableLeft.style.width="45%";
526     tableLeft.style.float = "left";
527     content.appendChild(tableRight = $_("table"));
528     tableRight.style.width="45%";
529     tableRight.style.float = "right";
530    
531     for (i=CS_STAT_RESIST_START;i<CS_STAT_RESIST_END;++i){
532     var table = i%2==0 ? tableLeft : tableRight;
533    
534     table.appendChild(tr = $_("tr"));
535     tr.index = i;
536    
537    
538     tr.appendChild(td=$_("td"));
539     td.innerHTML = resNames[i-CS_STAT_RESIST_START];
540    
541    
542     tr.appendChild(td=$_("td"));
543     td.innerHTML = myStats[i];
544    
545     }
546    
547    
548    
549    
550     }
551    
552     /*
553    
554    
555     CS_STAT_SKILLINFO = 140,
556     CS_NUM_SKILLS = 50,
557     SF_FIREON = 0x01,
558     SF_RUNON = 0x02,
559     NDI_BLACK = 0,
560     NDI_WHITE = 1,
561     NDI_NAVY = 2,
562     NDI_RED = 3,
563     NDI_ORANGE = 4,
564     NDI_BLUE = 5,
565     NDI_DK_ORANGE = 6,
566     NDI_GREEN = 7,
567     NDI_LT_GREEN = 8,
568     NDI_GREY = 9,
569     NDI_BROWN = 10,
570     NDI_GOLD = 11,
571     NDI_TAN = 12,
572     NDI_MAX_COLOR = 12,
573     NDI_COLOR_MASK = 0x1f,
574     NDI_REPLY = 0x20,
575     NDI_NOCRATE = 0x40,
576     NDI_CLEAR = 0x80,
577     a_none = 0,
578     a_readied = 1,
579     a_wielded = 2,
580     a_worn = 3,
581     a_active = 4,
582     a_applied = 5,
583     F_APPLIED = 0x000F,
584     F_LOCATION = 0x00F0,
585     F_UNPAID = 0x0200,
586     F_MAGIC = 0x0400,
587     F_CURSED = 0x0800,
588     F_DAMNED = 0x1000,
589     F_OPEN = 0x2000,
590     F_NOPICK = 0x4000,
591     F_LOCKED = 0x8000,
592     CF_FACE_NONE = 0,
593     CF_FACE_BITMAP = 1,
594     CF_FACE_XPM = 2,
595     CF_FACE_PNG = 3,
596     CF_FACE_CACHE = 0x10,
597     FACE_FLOOR = 0x80,
598     FACE_COLOR_MASK = 0xf,
599     UPD_LOCATION = 0x01,
600     UPD_FLAGS = 0x02,
601     UPD_WEIGHT = 0x04,
602     UPD_FACE = 0x08,
603     UPD_NAME = 0x10,
604     UPD_ANIM = 0x20,
605     UPD_ANIMSPEED = 0x40,
606     UPD_NROF = 0x80,
607     UPD_SP_MANA = 0x01,
608     UPD_SP_GRACE = 0x02,
609     UPD_SP_LEVEL = 0x04,
610     SOUND_NORMAL = 0,
611     SOUND_SPELL = 1,
612    
613     PICKUP_NOTHING = 0x00000000,
614    
615     PICKUP_DEBUG = 0x10000000,
616     PICKUP_INHIBIT = 0x20000000,
617     PICKUP_STOP = 0x40000000,
618     PICKUP_NEWMODE = 0x80000000,
619    
620     PICKUP_RATIO = 0x0000000F,
621    
622     PICKUP_FOOD = 0x00000010,
623     PICKUP_DRINK = 0x00000020,
624     PICKUP_VALUABLES = 0x00000040,
625     PICKUP_BOW = 0x00000080,
626    
627     PICKUP_ARROW = 0x00000100,
628     PICKUP_HELMET = 0x00000200,
629     PICKUP_SHIELD = 0x00000400,
630     PICKUP_ARMOUR = 0x00000800,
631    
632     PICKUP_BOOTS = 0x00001000,
633     PICKUP_GLOVES = 0x00002000,
634     PICKUP_CLOAK = 0x00004000,
635     PICKUP_KEY = 0x00008000,
636    
637     PICKUP_MISSILEWEAPON = 0x00010000,
638     PICKUP_ALLWEAPON = 0x00020000,
639     PICKUP_MAGICAL = 0x00040000,
640     PICKUP_POTION = 0x00080000,
641    
642     PICKUP_SPELLBOOK = 0x00100000,
643     PICKUP_SKILLSCROLL = 0x00200000,
644     PICKUP_READABLES = 0x00400000,
645     PICKUP_MAGIC_DEVICE = 0x00800000,
646    
647     PICKUP_NOT_CURSED = 0x01000000,
648    
649     PICKUP_JEWELS = 0x02000000,
650     PICKUP_FLESH = 0x04000000;
651     */
652 root 1.1
653     function updateItemsList(){
654     var content = xPlayerWindow.getElementsByClassName("player_widnow_content")[0];
655    
656    
657     content.innerHTML = "";
658     myItems.each(function (item,i,p){
659     if (isNaN(item.nr_of))
660     return;
661 sf-demisephi 1.3 content.appendChild(div = $_("div"));
662 root 1.1 var img = tilesInfo.getImgByFaceNum(item.face);
663     if (img){
664     div.innerHTML="<div><input type='hidden' value='"+item.itemId+"'/> <img src='"+img.src+"' alt='' style='width:32px;'/>"+(item.nr_of>1?item.namepl:item.name)+(item.nr_of>1?item.nr_of:"")+"</div>"
665     }else{
666     div.innerHTML="<div><input type='hidden' value='"+item.itemId+"'/>"+(item.nr_of>1?item.namepl:item.name)+"</div>"
667     }
668    
669     div.addEventListener("click",myInventoryItemClick);
670     div.addEventListener("mouseover",inventoryItemMouseOver);
671     div.addEventListener("mouseout",inventoryItemMouseOut);
672     div.addEventListener("mousemove",inventoryItemMouseMove);
673     },{})
674    
675     content = xPlayerWindow.getElementsByClassName("floor_widnow_content")[0];
676    
677    
678     content.innerHTML = "";
679 sf-demisephi 1.4 var container = secondaryContainer != 0 ? containers["container_" + secondaryContainer] : floorItems;
680     container.each(function (item,i,p){
681 root 1.1 if (isNaN(item.nr_of))
682     return;
683 sf-demisephi 1.3 content.appendChild(div = $_("div"));
684 root 1.1 var img = tilesInfo.getImgByFaceNum(item.face);
685     if (img){
686     div.innerHTML="<div><input type='hidden' value='"+item.itemId+"'/> <img src='"+img.src+"' alt='' style='width:32px;'/>"+(item.nr_of>1?item.namepl:item.name)+(item.nr_of>1?item.nr_of:"")+"</div>"
687     }else{
688     div.innerHTML="<div><input type='hidden' value='"+item.itemId+"'/>"+(item.nr_of>1?item.namepl:item.name)+"</div>"
689     }
690     div.addEventListener("mouseover",inventoryItemMouseOver);
691     div.addEventListener("mouseout",inventoryItemMouseOut);
692     div.addEventListener("mousemove",inventoryItemMouseMove);
693     div.addEventListener("click",floorInventoryItemClick);
694     },{})
695    
696     }
697    
698     function floorInventoryItemClick(e){
699     var itemId = parseInt(this.getElementsByTagName("input")[0].value);
700    
701     if (!keys.shift){
702     return;
703     }
704    
705     for (var i = 0;i<floorItems.length;++i){
706     if (parseInt(floorItems[i].itemId) == itemId){
707     doSend("command get "+ (floorItems[i].nr_of>1 ? floorItems[i].namepl:floorItems[i].name));
708     }else{
709    
710     }
711     }
712     }
713    
714     function myInventoryItemClick(e){
715     var itemId = parseInt(this.getElementsByTagName("input")[0].value);
716    
717     if (!keys.shift){
718     return;
719     }
720     for (var i = 0;i<myItems.length;++i){
721    
722    
723     if (parseInt(myItems[i].itemId) == itemId){
724     doSend("command drop "+ (myItems[i].nr_of>1 ? myItems[i].namepl:myItems[i].name));
725     }else{
726    
727     }
728     }
729    
730     }
731    
732     function inventoryItemMouseOver(e){
733     this.style.background = "solid";
734     this.style.backgroundColor="white";
735     var itemId = this.getElementsByTagName("input")[0].value;
736     doSend("ex " + itemId);
737    
738     xInfoWindow.show(true);
739     xInfoWindow.style.left = (e.clientX+5)+"px";
740     xInfoWindow.style.top = (e.clientY+5)+"px";
741     }
742    
743     function inventoryItemMouseMove(e){
744    
745     xInfoWindow.style.left = (e.clientX+5)+"px";
746     xInfoWindow.style.top = (e.clientY+5)+"px";
747    
748     }
749    
750     function inventoryItemMouseOut(e){
751     this.style.background = "transparent";
752     xInfoWindow.show(false);
753     }
754    
755     function createWindow(title,width,height,x,y){
756     var windowTemplate = document.getElementById("window_template_container").innerHTML;
757 sf-demisephi 1.3 var div = $_("div");
758 root 1.1 div.innerHTML = windowTemplate;
759    
760     var xwindow = div.getElementsByClassName("window")[0];
761     xwindow.style.left = x+"px";
762     xwindow.style.top = y+"px";
763     xwindow.style.width = width + "px";
764     xwindow.width = function (){
765     return parseInt(xwindow.style.width);
766     };
767    
768     xwindow.height = function (){
769     return parseInt(xwindow.style.height);
770     };
771     xwindow.show = function (b){
772     xwindow.style.display = b?"block":"none";
773     return true;
774     };
775     xwindow.visible = function (b){
776     return xwindow.style.display =="block";
777     };
778     xwindow.style.height = height + "px";
779     xwindow.getElementsByClassName("window_top_title")[0].innerHTML = title;
780     xwindow.getElementsByClassName("window_close")[0].onclick = function (){(xwindow.close());};
781     xwindow.onmousedown = function (e) { if (e.clientY-parseInt(xwindow.style.top)<25){
782     currentWindow = xwindow;
783     currentWindowOffset={x:e.clientX-parseInt(xwindow.style.left),y:e.clientY-parseInt(xwindow.style.top)}
784     }else if (e.clientY-parseInt(xwindow.style.top)>parseInt(xwindow.style.height)-5){
785     if (e.clientX-parseInt(xwindow.style.left)>parseInt(xwindow.style.width)-5){
786     currentWindowResize = true;
787     currentWindow = xwindow;
788     }
789     }
790     };
791     xwindow.contents = xwindow.getElementsByClassName("content")[0];
792     xwindow.contents.parent = xwindow;
793     xwindow.close = function (){document.getElementsByTagName("body")[0].removeChild(xwindow);};
794     appendToBody(xwindow);
795    
796    
797     return xwindow;
798     }
799     function onMouseUp (e){
800    
801     if (currentWindow!=null){
802     currentWindow = null;
803     currentWindowResize = false;
804     }
805     }
806    
807     function onMouseMove (e){
808     stage.mouseX = e.clientX;
809     stage.mouseY = e.clientY;
810     if (currentWindow!=null){
811     if (currentWindowResize == false){
812     currentWindow.style.left = (stage.mouseX-currentWindowOffset.x)+"px";
813     currentWindow.style.top = (stage.mouseY-currentWindowOffset.y)+"px";
814     }else{
815     currentWindow.style.width = (stage.mouseX-parseInt(currentWindow.style.left))+"px";
816     currentWindow.style.height = (stage.mouseY-parseInt(currentWindow.style.top))+"px";
817     }
818     }
819     }
820    
821     function ptInRect(pt,rect){
822     if (pt.x<rect.x) return false;
823     if (pt.y<rect.y) return false;
824     if (pt.x>rect.x+rect.width) return false;
825     if (pt.y>rect.y+rect.height) return false;
826     return true;
827     }
828    
829     function onClick (e){
830     x = e.clientX;
831     y = e.clientY;
832    
833     try{
834     e.preventDefault();
835     }catch (ex){
836    
837     }
838     return false;
839     }
840    
841     function channels_setActive(channel_info){
842     for (var i=0;i<channels.length;++i){
843     if (channels.list[i]==channel_info){
844     channels.list[i].isActive = true;
845     }else{
846     channels.list[i].isActive = false;
847     }
848     }
849     }
850    
851     function channels_addMessage(channelId,o){
852 sf-demisephi 1.4 var ta = channels_get_chat_box("channel_" + channelId);
853     ta.value = ta.value + JSON.stringify(o);;
854 root 1.1 channels[channelId].newMessages = true;
855     }
856    
857    
858     function channels_add(channel_info){
859 sf-demisephi 1.4 var button,textarea;
860     if (channels[channel_info['id']]){
861     return;
862     }
863 root 1.1 channel_info.messages = [];
864     channel_info.index = channels.list.length;
865     channels[channel_info['id']] = channel_info;
866     channels.list.push (channel_info);
867     channels.length+=1;
868     channels_setActive(channel_info);
869 sf-demisephi 1.4 xChatBoxWindow.buttonsContainer.appendChild(button=$_("input"));
870     button.value = channel_info['id'];
871     button.type = "button";
872     xChatBoxWindow.channelContainer.appendChild(textarea=$_("textarea"));
873     textarea.id = "channel_" + button.value;
874     textarea.style.width = "90%";
875     textarea.style.height = "85%";
876     channels_hide_other ("channel_" + button.value);
877     button.onclick = function (){
878     channels_hide_other ("channel_" + button.value);
879     };
880     }
881     function channels_get_chat_box (pid){
882     var list = xChatBoxWindow.channelContainer.getElementsByTagName("textarea");
883     for (var i=0;i<list.length;++i){
884     var e = list[i];
885     if (e.id == pid)
886     return e;
887     };
888     return null;
889 root 1.1 }
890 sf-demisephi 1.4 function channels_hide_other(pid){
891     var list = xChatBoxWindow.channelContainer.getElementsByTagName("textarea");
892     for (var i=0;i<list.length;++i){
893     var e = list[i];
894     if (e.id != pid)e.style.display = "none";else e.style.display = "block";
895     };
896 root 1.1 }
897    
898     function onOpen(evt)
899     {
900     writeToScreen("CONNECTED");
901     doSend('version {"clientver":"0.001","client":"deliantra html5 client","osver":"linux","protver":1}');
902     }
903    
904     function onClose(evt)
905     {
906     writeToScreen("DISCONNECTED");
907     }
908    
909     var exti = {
910     nextId : 100,
911     getNextId : function (){
912     return this.nextId++;
913     }
914     };
915    
916 sf-demisephi 1.4 function getItemById(itmid){
917     var itm = findItem(myItems,itmid);
918     if (itm){
919     return itm;
920     }
921     itm = findItem(floorItems,itmid);
922     if (itm){
923     return itm;
924     }
925     for (var s in containers){
926     if (typeof(containers[s]) == typeof({}) ){
927     itm = findItem(containers[s],itmid);
928     if (itm){
929     return itm;
930     }
931    
932     }
933     }
934     }
935    
936     function feed_upditem (data,dataAsArray){
937     var buff=new Buffer(dataAsArray);
938     buff.position = "upditem ".length;
939     var flags = buff.readUint8();
940     var tag = buff.readUint32();
941    
942     var itm = getItemById(tag);
943     if (!itm){
944     return;
945     }
946    
947     if (flags & UPD_LOCATION) {
948     removeItemEx(tag);
949    
950     var container = buff.readUint32();
951     if (container==player.tag){
952     myItems.push(itm);
953     }else if (container==0){
954     floorItems.push(itm);
955     }else{
956     if (!typof(containers["container_" + container])==typeof([])){
957     containers["container_" + container] = [];
958     }
959     containers["container_" + container].push (itm);
960     }
961     }
962     if (flags & UPD_FLAGS)
963     itm.flags = buff.readUint32();
964     if (flags & UPD_WEIGHT)
965     itm.weight = buff.readUint32();//$item->{weight} = unpack "l", pack "L", unpack "N", substr $data, 0, 4, "" ;
966     if (flags & UPD_FACE)
967     itm.face = buff.readUint32();
968    
969    
970     if((itm.flags&F_OPEN)){
971     secondaryContainer = tag;
972     updateItemsList();
973     }
974    
975     //TODO: finish it!
976     /*
977     if ($flags & UPD_NAME) {
978     my $len = unpack "C", substr $data, 0, 1, "";
979    
980     my $names = substr $data, 0, $len, "";
981     utf8::decode $names;
982     @$item{qw(name name_pl)} = split /\x00/, $names;
983     }
984    
985     $item->{anim} = unpack "n", substr $data, 0, 2, "" if $flags & UPD_ANIM;
986     $item->{animspeed} = TICK * unpack "C", substr $data, 0, 1, "" if $flags & UPD_ANIMSPEED;
987     $item->{nrof} = unpack "N", substr $data, 0, 4, "" if $flags & UPD_NROF;
988    
989     $item->{mtime} = time;
990    
991     if ($item->{tag} == $self->{player}{tag}) {
992     $self->player_update ($self->{player} = $item);
993     } else {
994     $self->item_update ($item);
995     }
996     */
997     }
998     function removeItemEx(itmid){
999     removeItem(myItems,itmid);
1000     removeItem(floorItems,itmid);
1001     for (var s in containers){
1002     if (typeof(containers[s]) == typeof({}) ){
1003     removeItem(containers[s],itmid);
1004     }
1005     }
1006     }
1007 root 1.1 function feed_delitem (data,dataAsArray){
1008    
1009     var buff=new Buffer(dataAsArray);
1010     buff.position = 8;
1011    
1012     while (buff.position<dataAsArray.length){
1013     var itmid = buff.readUint32();
1014 sf-demisephi 1.4 removeItemEx(itmid);
1015     if (typeof(containers["container_" + itmid]) == typeof({}) ){
1016     containers["container_" + itmid] = [];
1017     }
1018    
1019 root 1.1 }
1020    
1021 sf-demisephi 1.4
1022     updateItemsList();
1023    
1024     }
1025     function findItem (items,itmid){
1026     for (var i=items.length-1;i>=0;--i){
1027     if (items[i].itemId == itmid){
1028     return items[i];
1029     }
1030     }
1031     return null;
1032 root 1.1 }
1033    
1034     function removeItem (items,itmid){
1035     for (var i=items.length-1;i>=0;--i){
1036     if (items[i].itemId == itmid){
1037     items.splice(i,1);
1038     }
1039     }
1040    
1041     updateItemsList();
1042     }
1043    
1044     function feed_ex (data,dataAsArray){
1045     var buff=new Buffer(dataAsArray);
1046     buff.position = 3;
1047     var len = buff.unpack_w();
1048     var str = buff.readString(len);
1049     xInfoWindow.contents.innerHTML = str.split("\n").join("<br/>")+"<small>shift+click - drop,move or pickup item</small>";
1050    
1051     }
1052    
1053     function feed_query (data,dataAsArray){
1054     switch (String.fromCharCode(dataAsArray[6])){
1055     case "0":
1056     //var login = prompt("What is your name? (login names are case-sensitive):");
1057     doSend("reply " + getLogin())
1058     return true;
1059     break;
1060    
1061     case "4":
1062     //var password = prompt("What is your password?");
1063     doSend("reply " + getPassword());
1064    
1065     return true
1066     break;
1067    
1068     }
1069     return false;
1070     }
1071    
1072    
1073 sf-demisephi 1.3 function onKeyDown (keyCode){
1074     switch(keyCode){
1075     case 38:
1076     if (keys.ctrl&&!isRunning){
1077     isRunning = true;
1078     doSend("command run 1");
1079     //doSend("command north")
1080     }
1081     else
1082     if (!isFiring&&keys.shift){
1083 sf-demisephi 1.4 doSend("command fire 1");
1084 sf-demisephi 1.3 isFiring = true;
1085     }else
1086     doSend("command north");
1087     break;
1088     case 40:
1089     if (keys.ctrl&&!isRunning){
1090     isRunning = true;
1091     doSend("command run 5" );
1092     //doSend("command souh")
1093     }
1094     else
1095     if (!isFiring&&keys.shift){
1096 sf-demisephi 1.4 doSend("command fire 5" );
1097 sf-demisephi 1.3 isFiring = true;
1098     }else
1099     doSend("command south");
1100     break;
1101     case 37:
1102     if (keys.ctrl&&!isRunning){
1103     isRunning = true;
1104     doSend("command run 7" );
1105     // doSend("command west")
1106     }
1107     else
1108     if (!isFiring&&keys.shift){
1109 sf-demisephi 1.4 doSend("command fire 7");
1110 sf-demisephi 1.3 isFiring = true;
1111     }else
1112     doSend("command west");
1113     break;
1114     case 39:
1115     if (keys.ctrl&&!isRunning){
1116     isRunning = true;
1117     doSend("command run 3" );
1118     //doSend("command west")
1119     }else
1120     if (!isFiring&&keys.shift){
1121 sf-demisephi 1.4 doSend("command fire 3");
1122 sf-demisephi 1.3 isFiring = true;
1123     }else
1124     doSend("command east");
1125     break;
1126     case 49:
1127     case 9:
1128     xPlayerWindow.show(!xPlayerWindow.visible() );
1129     break;
1130 sf-demisephi 1.4 case 67:
1131     skipKeyTest = true;
1132     xCommmandWindow.show(true);
1133    
1134     break;
1135 sf-demisephi 1.3
1136     case 32:
1137     doSend("command apply");
1138     break;
1139     case 188:
1140     doSend("command get");
1141     break;
1142     case 16:
1143     keys.shift = 1;
1144     break;
1145     case 18:
1146     keys.alt = 1;
1147     break;
1148     case 17:
1149     keys.ctrl = 1;
1150     break;
1151     case 113:
1152     showPlayerTab({},"statistics");
1153     break;
1154     case 114:
1155     showPlayerTab({},"skills");
1156     break;
1157    
1158     case 115:
1159     showPlayerTab({},"spellbook");
1160     break;
1161    
1162     case 116:
1163     showPlayerTab({},"inventory");
1164     break;
1165     default:
1166 sf-demisephi 1.4 //messageBox(keyCode);
1167 sf-demisephi 1.3 break;
1168     }
1169     }
1170    
1171     function onKeyUp(keyCode){
1172     switch(keyCode){
1173     case 38:
1174     if (isRunning&&!keys.ctrl){
1175     doSend("command run_stop");
1176     isRunning = false;
1177     }
1178     if (isFiring&&!keys.shift){
1179     doSend("command fire_stop");
1180     isFiring = false;
1181     }
1182     break;
1183     case 40:
1184     if (isFiring&&!keys.shift){
1185     doSend("command fire_stop");
1186     isFiring = false;
1187     }
1188     if (isRunning&&!keys.ctrl){
1189     doSend("command run_stop");
1190     isRunning = false;
1191     }
1192     break;
1193     case 37:
1194     if (isFiring&&!keys.shift){
1195     doSend("command fire_stop");
1196     isFiring = false;
1197     }
1198     if (isRunning&&!keys.ctrl){
1199     doSend("command run_stop");
1200     isRunning = false;
1201     }
1202     break;
1203     case 39:
1204     if (isFiring&&!keys.shift){
1205     doSend("command fire_stop");
1206     isFiring = false;
1207     }
1208     if (isRunning&&!keys.ctrl){
1209     doSend("command run_stop");
1210     isRunning = false;
1211     }
1212     break;
1213     case 49:
1214     break;
1215     case 16:
1216     keys.shift = 0;
1217 sf-demisephi 1.4 if (isFiring&&!keys.shift){
1218     doSend("command fire_stop");
1219     isFiring= false;
1220     }
1221 sf-demisephi 1.3 break;
1222     case 18:
1223     keys.alt = 0;
1224     break;
1225     case 17:
1226     keys.ctrl = 0;
1227     if (isRunning&&!keys.ctrl){
1228     doSend("command run_stop");
1229     isRunning = false;
1230     }
1231     break;
1232     default:
1233     //messageBox(e.keyCode);
1234     break;
1235     }
1236 root 1.1
1237 sf-demisephi 1.3 }
1238 root 1.1 function feed_version (data,dataAsArray){
1239     var smapsize = Math.floor(xMapWindow.width()/64);
1240     mapsize.width = mapsize.height = parseInt(smapsize);
1241     smapsize = smapsize +"x" + smapsize;
1242 sf-demisephi 1.2 map_clear();
1243 root 1.1 doSend('setup tileset 1 excmd 1 smoothing 1 mapinfocmd 1 facecache 1 newmapcmd 1 extmap 1 fxix 3 darkness 1 extcmd 2 msg 2 frag 0 map1acmd 1 spellmon 1 itemcmd 2 exp64 1 widget 1 lzf 0 mapsize ' + smapsize);
1244    
1245     window.addEventListener("keydown",function (e){
1246     if (skipKeyTest){
1247     return;
1248     }
1249    
1250 sf-demisephi 1.3 if (keys.states [e.keyCode]==0){
1251     onKeyDown(e.keyCode);
1252 root 1.1 }
1253 sf-demisephi 1.3
1254     keys.states [e.keyCode] = 1;
1255    
1256 root 1.1 try {
1257     e.preventDefault();
1258     }catch (e){
1259 sf-demisephi 1.3
1260 root 1.1 }
1261     return false;
1262     });
1263     window.addEventListener("keyup",function (e){
1264     if (skipKeyTest){
1265     return;
1266     }
1267 sf-demisephi 1.3 if (keys.states [e.keyCode]==1){
1268     onKeyUp(e.keyCode);
1269 root 1.1 }
1270 sf-demisephi 1.3 keys.states [e.keyCode] = 0;
1271 root 1.1 try {
1272     e.preventDefault();
1273     }catch (e){
1274    
1275     }
1276     //isRunning = false;
1277     return false;
1278     });
1279     channels_add({id:"log"});
1280     channels_add({id:"map"});
1281     return false;
1282     }
1283    
1284     function feed_setup (data,dataAsArray){
1285     doSend('exti ["http_faceurl", ' + exti.getNextId() +']');
1286     }
1287    
1288     //'',
1289     //'requestinfo spell_paths',
1290    
1291    
1292     function face2tile (){
1293    
1294     }
1295    
1296     function clear_cell (cell){
1297     cell.darkness = 256;
1298     cell.flags = 0;
1299     cell.player =0;
1300     cell.tiles = [];
1301    
1302    
1303     return cell;
1304     }
1305    
1306 sf-demisephi 1.2 function MapCell(){
1307     this.previousCell = null;
1308     this.nextCell = null;
1309     this.data = {};
1310     clear_cell(this.data);
1311     }
1312    
1313     function MapRow(){
1314     this.previousRow = null;
1315     this.nextRow = null;
1316     this.firstCell = null;
1317     this.lastCell = null;
1318     this.length = 0;
1319     while (this.length<mapsize.width){
1320     this.addCell(new MapCell());
1321     }
1322     }
1323     MapRow.prototype.addCell = function (cell){
1324     if (this.firstCell == null){
1325     this.firstCell = this.lastCell = cell;
1326    
1327     this.lastCell.nextCell = this.firstCell;
1328     this.lastCell.previousCell = this.firstCell;
1329    
1330     this.firstCell.nextCell = this.lastCell;
1331     this.firstCell.previousCell = this.lastCell;
1332    
1333     this.length = 1;
1334     return;
1335     }
1336     this.lastCell.nextCell = cell;
1337     cell.previousCell = this.lastCell;
1338     this.lastCell = cell;
1339     this.firstCell.previousCell = cell;
1340     cell.nextCell = this.firstCell;
1341     this.length+=1;
1342     }
1343    
1344     MapRow.prototype.shift = function (){
1345     var ret = this.firstCell;
1346     this.firstCell = ret.nextCell;
1347     this.lastCell.nextCell = this.firstCell;
1348     this.firstCell.previousCell = this.lastCell;
1349     return ret;
1350 root 1.1 }
1351    
1352 sf-demisephi 1.2 MapRow.prototype.pop = function (){
1353     var ret = this.lastCell;
1354     this.lastCell = ret.previousCell;
1355     this.lastCell.nextCell = this.firstCell;
1356     this.firstCell.previousCell = this.lastCell;
1357     return ret;
1358     }
1359 root 1.1
1360 sf-demisephi 1.2 MapRow.prototype.push = function (cell){
1361     this.addCell(cell);
1362     }
1363 root 1.1
1364 sf-demisephi 1.2 MapRow.prototype.unshift = function (cell){
1365     var tmp = this.firstCell;
1366     this.firstCell = cell;
1367     this.firstCell.nextCell = tmp;
1368     tmp.previousCell = this.firstCell;
1369     this.firstCell.previousCell = this.lastCell;
1370     this.lastCell.nextCell = this.firstCell;
1371 root 1.1 }
1372    
1373 sf-demisephi 1.2 function map_clear (){
1374     Map = {length:0,firstRow:null,lastRow : null,addRow:function (row){
1375     if (this.firstRow==null){
1376     this.firstRow = this.lastRow = row;
1377     this.length = 1;
1378     return;
1379 root 1.1 }
1380 sf-demisephi 1.2 this.lastRow.nextRow = row;
1381     row.previousRow = this.lastRow;
1382     this.lastRow = row;
1383     row.nextRow = this.firstRow;
1384     this.firstRow.previousRow = row;
1385     this.length++;
1386     }};
1387    
1388     while (Map.length<mapsize.height){
1389     Map.addRow(new MapRow());
1390 root 1.1 }
1391    
1392 sf-demisephi 1.2 if (stage&&stage.stageWidth)
1393     ctx.clearRect(0,0,stage.stageWidth,stage.stageHeight);
1394     }
1395 root 1.1
1396 sf-demisephi 1.2 function map_get_cell (x,y){
1397     var i = 0;
1398     var mapRow = Map.firstRow;
1399     while (i<y){
1400     mapRow = mapRow.nextRow;
1401     ++i;
1402     }
1403     i = 0;
1404     var mapCell = mapRow.firstCell;
1405     while (i<x){
1406     mapCell=mapCell.nextCell;
1407     ++i;
1408     }
1409     return mapCell.data;
1410 root 1.1 }
1411    
1412 sf-demisephi 1.3 function map_get_cell_ex (x,y){
1413     var i = 0;
1414     var mapRow = Map.firstRow;
1415     while (i<y){
1416     mapRow = mapRow.nextRow;
1417     ++i;
1418     }
1419     i = 0;
1420     var mapCell = mapRow.firstCell;
1421     while (i<x){
1422     mapCell=mapCell.nextCell;
1423     ++i;
1424     }
1425     return mapCell;
1426    
1427     }
1428    
1429 root 1.1 function scroll_map (dx,dy){
1430     var x,y;
1431     var tmpDx = dx;
1432     var tmpDy = dy;
1433 sf-demisephi 1.2 var i=0;
1434     while (i<tmpDy){
1435 root 1.1
1436 sf-demisephi 1.2 Map.firstRow = Map.firstRow.nextRow;
1437     Map.addRow(new MapRow());
1438     Map.length -=1;
1439     ++i;
1440     }
1441     i=0;
1442     while (tmpDy<i){
1443     var mapRow = new MapRow();
1444     mapRow.nextRow = Map.firstRow;
1445     Map.firstRow.previousRow = mapRow;
1446     mapRow.previousRow = Map.lastRow;
1447     Map.lastRow.nextRow = mapRow;
1448     Map.firstRow = mapRow;
1449     --i;
1450     }
1451     i = 0;
1452     while (i<tmpDx){
1453     var row = Map.firstRow;
1454     do {
1455     row.shift();
1456     row.push(new MapCell());
1457     row = row.nextRow;
1458     }while (row!=Map.firstRow);
1459     i++;
1460     }
1461     i = 0;
1462     while (tmpDx<i){
1463     var row = Map.firstRow;
1464     do {
1465     row.pop();
1466     row.unshift(new MapCell());
1467     row = row.nextRow;
1468     }while (row!=Map.firstRow);
1469     i--;
1470 root 1.1 }
1471     }
1472    
1473     function feed_map1a (stringData,data){
1474 sf-demisephi 1.2
1475 root 1.1 scroll_map(dx,dy);
1476     dx = dy = 0;
1477    
1478     var x,y;
1479    
1480     var index = 6;
1481 sf-demisephi 1.2
1482     while (index<data.length-2){
1483 root 1.1 var flags = (data[index++]<<8) + data[index++];
1484     x = ((flags >> 10) & 63);
1485     y = ((flags >> 4) & 63);
1486    
1487     cell = map_get_cell (x, y);
1488     if (!(flags&15)){
1489     clear_cell(cell);
1490     //ctx.clearRect(x<<6,(y<<6),64,64);
1491     continue;
1492     }
1493    
1494     if (cell.darkness==0){
1495     cell.darkness = 256;
1496     }
1497    
1498     if ((flags & 8)){
1499     do {
1500     var cmd = 0;
1501     var ext = 0;
1502    
1503     ext = data[index++];
1504     cmd = ext & 0x7f;
1505     if (cmd<4){
1506     cell.darkness = 255 - ext * 64 + 1;
1507     }else if (cmd == 5){
1508     cell.stat_width = 1;
1509     cell.stat_hp = data[index++];
1510     }else if (cmd == 6) {// monster width{
1511     cell.stat_width = data[index++] + 1;
1512     }else if (cmd == 0x47){
1513     if (data[index] == 1) cell.player = data [index + 1];
1514     else if (data[index] == 2) cell.player = data [index + 2] + (data [index + 1] << 8);
1515     else if (data[index] == 3) cell.player = data [index + 3] + (data [index + 2] << 8) + (data [index + 1] << 16);
1516     else if (data[index] == 4) cell.player = data [index + 4] + (data [index + 3] << 8) + (data [index + 2] << 16) + (data [index + 1] << 24);
1517    
1518 sf-demisephi 1.2 index += data[index] +1;
1519 root 1.1 }
1520     else if (cmd == 8) // cell flags
1521     cell.flags = data[index++];
1522     else if (ext & 0x40) // unknown, multibyte => skip
1523     index+= data[index]+1;
1524     else
1525     index++;
1526     }while (ext&0x80);
1527     }
1528    
1529    
1530    
1531     for (var z = 0; z <= 2; ++z)
1532     if ((flags & (4 >> z)))
1533     {
1534     var face = (data [index++] << 8) + data [index++];
1535 sf-demisephi 1.2 //need_facenum (face);
1536 root 1.1 cell.tiles [z] = face;
1537     }
1538 sf-demisephi 1.2 //Map[y][x]=cell;
1539 root 1.1
1540    
1541     }
1542     drawMap();
1543     return true;
1544    
1545     }
1546    
1547     function drawMap(){
1548    
1549 sf-demisephi 1.2
1550 root 1.1 ctx.clearRect(0,0,stage.stageWidth,stage.stageHeight);
1551     ctx.fillStyle = "#000";
1552     ctx.fillRect(0,0,canvas.width,canvas.height);
1553    
1554     for (var i = 0;i<mapsize.height;++i){
1555 sf-demisephi 1.3 var cell = map_get_cell_ex(0,i);
1556 root 1.1 for (var j=0;j<mapsize.width;++j){
1557     var x = j<<6;
1558     var y = i<<6;
1559 sf-demisephi 1.3 var cellx = cell.data;
1560 root 1.1 for (var z=0;z<=2;++z){
1561     if (!cellx.tiles[z])
1562     continue;
1563     var img = tilesInfo.getImgByFaceNum(cellx.tiles[z]);
1564     if (img){
1565     ctx.drawImage(img,x,y);
1566     }else{
1567    
1568     }
1569     }
1570 sf-demisephi 1.3 if ((typeof(cellx.stat_hp) == typeof(1))&&cellx.stat_hp>0){
1571     ctx.fillStyle = "#f00";
1572     ctx.fillRect(x,y,((255-cellx.stat_hp)/255)*64,8);
1573    
1574     //ctx.fillText(cellx.stat_hp,x,y);
1575     }
1576     cell = cell.nextCell;
1577    
1578 root 1.1 }
1579     }
1580     }
1581    
1582     function feed_ext (data,dataAsArray){
1583    
1584    
1585    
1586    
1587    
1588     if (data.indexOf ("channel_info")>0){
1589     var channel_info = JSON.parse(data.substr(4))[1];
1590     channels_add(channel_info);
1591     return true;
1592     }else{
1593    
1594     var o = JSON.parse(data.substr(4));
1595     var replyID = parseInt(o[0].split("-")[1]);
1596    
1597     if (replyID == 100){
1598     baseURL = o[1];
1599     baseURL = "http://testserver.deliantra.net:13327" + baseURL + "";
1600 sf-demisephi 1.3 doSend('exti ["resource",'+exti.getNextId()+',"exp_table"]');
1601    
1602 root 1.1
1603     }else if (replyID==101){
1604     expTableFacenum = parseInt(o[1]);
1605 sf-demisephi 1.3 doSend ('exti ["resource",'+exti.getNextId() + ',"exp_table", "skill_info", "spell_paths"]');
1606     }else if (replyID==102){
1607 root 1.1 doSend("addme");
1608     }
1609     else{
1610    
1611     }
1612    
1613    
1614     writeToScreen(data);
1615     }
1616     return false;
1617     }
1618     var Constants = {
1619     a_none : 0,
1620     a_readied : 1,
1621     a_wielded : 2,
1622     a_worn : 3,
1623     a_active : 4,
1624     a_applied : 5,
1625     F_APPLIED : 0x000F,
1626     F_LOCATION : 0x00F0,
1627     F_UNPAID : 0x0200,
1628     F_MAGIC : 0x0400,
1629     F_CURSED : 0x0800,
1630     F_DAMNED : 0x1000,
1631     F_OPEN : 0x2000,
1632     F_NOPICK : 0x4000,
1633     F_LOCKED : 0x8000
1634     };
1635     function Buffer (dataArray){
1636     this.buffer = dataArray;
1637     this.position = 0;
1638     this.length = dataArray.length;
1639     return this;
1640     }
1641    
1642     Buffer.prototype.unpack_w = function (){
1643     var num = 0;
1644     var byte = 0;
1645     do {
1646     num*=128;
1647     byte = parseInt(this.buffer[this.position++]);
1648     num+=byte&0x7f;
1649     }while (byte&0x80);
1650     return num;
1651     };
1652    
1653     Buffer.prototype.readUint32 = function (){
1654     var ret = 0;
1655     for (var i=0;i<4;++i){
1656     ret*=256;
1657     ret+=this.buffer[this.position++];
1658     }
1659     return ret;
1660     };
1661    
1662     Buffer.prototype.readUint8 = function (){
1663     var ret = 0;
1664     for (var i=0;i<1;++i){
1665     ret*=256;
1666     ret+=parseInt(this.buffer[this.position++]);
1667     }
1668     return ret;
1669     };
1670    
1671     Buffer.prototype.readUint16 = function (){
1672     var ret = 0;
1673     for (var i=0;i<2;++i){
1674     ret*=256;
1675     ret+=this.buffer[this.position++];
1676     }
1677     return ret;
1678     };
1679    
1680     Buffer.prototype.readString = function (len){
1681     var ret = "";
1682    
1683     if ( typeof (len) != "undefined"){
1684     for (var i=0;i<len;++i){
1685     ret+=String.fromCharCode(this.buffer[this.position++]);
1686     }
1687     }else{
1688    
1689     while (this.buffer[this.position]!=0){
1690     ret+=String.fromCharCode(this.buffer[this.position++]);
1691     }
1692     }
1693    
1694     return ret;
1695     };
1696    
1697    
1698    
1699     function unselectable (target){
1700     target.setAttribute('unselectable','on');
1701     if (typeof target.onselectstart != "undefined") //IE route
1702     target.onselectstart = function() { return false }
1703     else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
1704     target.style.MozUserSelect = "none"
1705     else //All other route (ie: Opera)
1706     target.onmousedown = function() { return false }
1707     }
1708    
1709     function Item (){
1710     this.itemId = 0;
1711     this.flags = 0;
1712     this.weight = 0;
1713     this.face = 0;
1714     this.name = "";
1715     this.namepl = "";
1716     this.animation_id=0;
1717     this.anim_speed=0;
1718     this.nr_of=0;
1719     this.clientType=0;
1720     }
1721    
1722    
1723     function feed_replyinfo (data){
1724 sf-demisephi 1.3 return false;
1725 root 1.1 }
1726    
1727 sf-demisephi 1.4 var containers = {};
1728     var secondaryContainer = 0;
1729    
1730 root 1.1 function feed_item2 (data,dataAsArray){
1731     var buff = new Buffer(dataAsArray);
1732     buff.position = 6;
1733     var container = buff.readUint32();
1734    
1735     while (buff.position<buff.length){
1736     var item = new Item();
1737    
1738     item.itemId = buff.readUint32();
1739    
1740     item.flags = buff.readUint32();
1741     item.weight = buff.readUint32();
1742     item.face = buff.readUint32();
1743     var len = (buff.readUint8());
1744    
1745     var names = (buff.readString(len)).split(String.fromCharCode(0));
1746     item.name = names[0];
1747     item.namepl = "";
1748    
1749     if (names.length>1)
1750     item.namepl = names[1];
1751    
1752     item.animation_id = buff.readUint16();
1753     item.anim_speed = buff.readUint8();
1754     item.nr_of = buff.readUint32();
1755     item.clientType = buff.readUint16();
1756 sf-demisephi 1.4 item.container = container;
1757    
1758     if (container==player.tag){
1759 root 1.1 myItems.push (item);
1760 sf-demisephi 1.4 }else if (container==0){
1761 root 1.1 floorItems.push(item);
1762 sf-demisephi 1.4 }else {
1763     if ( typeof(containers['container_' + container]) != typeof([])){
1764     containers['container_' + container] = [];
1765     }
1766     containers['container_' + container].push(item);
1767 root 1.1 }
1768     }
1769     if (container==0){
1770     xFloorWindow.contents.innerHTML="";
1771     for (var i=0;i<floorItems.length;++i){
1772     var item = floorItems[i];
1773     if (item.itemId==null||isNaN(item.itemId))
1774     continue;
1775     var img = tilesInfo.getImgByFaceNum(item.face);
1776 sf-demisephi 1.3 var div = $_("div");
1777 root 1.1 xFloorWindow.contents.appendChild(div);
1778     if (img){
1779     div.innerHTML+="<div><input type='hidden' value='"+item.itemId+"'/><img src='"+img.src+"' alt='' style='width:32px;'/>"+(item.nr_of>1?item.namepl:item.name)+(item.nr_of>1?item.nr_of:"")+"</div>"
1780     }else{
1781     div.innerHTML+="<div><input type='hidden' value='"+item.itemId+"'/>"+(item.nr_of>1?item.namepl:item.name)+"</div>"
1782     }
1783    
1784     div.addEventListener("click",floorInventoryItemClick);
1785     div.addEventListener("mouseover",inventoryItemMouseOver);
1786     div.addEventListener("mouseout",inventoryItemMouseOut);
1787     div.addEventListener("mousemove",inventoryItemMouseMove);
1788    
1789     }
1790    
1791    
1792     }
1793     updateItemsList();
1794     return false;
1795     }
1796    
1797     function Spell (){
1798    
1799     }
1800    
1801     function updateSpellList (){
1802     var content = xPlayerWindow.getElementsByClassName("spellbook_widnow_content")[0];
1803     content.style.display = "block";
1804    
1805     content.innerHTML = "";
1806     var table;
1807     var tr;
1808     var td;
1809    
1810 sf-demisephi 1.3 content.appendChild(table = $_("table"));
1811 root 1.1 table.style.width="100%";
1812     if (mySpells.length<=0){
1813     return;
1814     }
1815 sf-demisephi 1.3 table.appendChild(tr = $_("tr"));
1816 root 1.1 item = mySpells[0];
1817     for (s in item){
1818    
1819     if ((typeof(item[s])==typeof(1))||(typeof(item[s])==typeof(""))){
1820     if (s=="tag"){
1821    
1822     }else if (s=="message"){
1823    
1824     }else if (s=="face"){
1825 sf-demisephi 1.3 tr.appendChild(td=$_("td"));
1826 root 1.1 td.innerHTML = s;
1827     }else{
1828 sf-demisephi 1.3 tr.appendChild(td=$_("td"));
1829 root 1.1 td.innerHTML = s;
1830     }
1831     }
1832    
1833     }
1834    
1835    
1836     mySpells.each(function (item,i,p){
1837    
1838 sf-demisephi 1.3 table.appendChild(tr = $_("tr"));
1839 root 1.1 tr.index = i;
1840     var img = tilesInfo.getImgByFaceNum(item.face);
1841    
1842     var s;
1843     for (s in item){
1844     if (isNaN(item['face'])){
1845     continue;
1846     }
1847    
1848     if ((typeof(item[s])==typeof(1))||(typeof(item[s])==typeof(""))){
1849     if (s=="tag"){
1850     tr.tag = item[s];
1851     }else if (s=="message"){
1852     tr.message = item[s];
1853     }else if (s=="face"){
1854 sf-demisephi 1.3 tr.appendChild(td=$_("td"));
1855 root 1.1 td.innerHTML = "<img src='"+img.src+"' alt='' style='width:32px;'/>";
1856     }else{
1857 sf-demisephi 1.3 tr.appendChild(td=$_("td"));
1858 root 1.1 td.innerHTML = item[s];
1859     }
1860     }
1861    
1862     }
1863     tr.addEventListener("click",mySpellItemClick);
1864     tr.addEventListener("mouseover",SpellItemMouseOver);
1865     tr.addEventListener("mouseout",SpellItemMouseOut);
1866     tr.addEventListener("mousemove",SpellItemMouseMove);
1867    
1868     /*if (img){
1869     div.innerHTML="<div><input type='hidden' value='"+item.itemId+"'/> <img src='"+img.src+"' alt='' style='width:32px;'/>"+(item.nr_of>1?item.namepl:item.name)+(item.nr_of>1?item.nr_of:"")+"</div>"
1870     }else{
1871     div.innerHTML="<div><input type='hidden' value='"+item.itemId+"'/>"+(item.nr_of>1?item.namepl:item.name)+"</div>"
1872     }*/
1873    
1874    
1875     },{})
1876    
1877    
1878     }
1879     function updateSkillList (){
1880     var content = xPlayerWindow.getElementsByClassName("skills_widnow_content")[0];
1881    
1882    
1883     content.innerHTML = "";
1884     var tableLeft;
1885     var tableRight;
1886     var tr;
1887     var td;
1888    
1889 sf-demisephi 1.3 content.appendChild(tableLeft = $_("table"));
1890 root 1.1 tableLeft.style.width="45%";
1891     tableLeft.style.float = "left";
1892 sf-demisephi 1.3 content.appendChild(tableRight = $_("table"));
1893 root 1.1 tableRight.style.width="45%";
1894     tableRight.style.float = "right";
1895    
1896     var j=0;
1897    
1898     for (i=CS_STAT_SKILLINFO;i<CS_STAT_SKILLINFO+CS_NUM_SKILLS;++i){
1899    
1900     if (!myStats[i]){
1901     continue;
1902     }
1903     var table = j%2==0 ? tableLeft : tableRight;
1904    
1905 sf-demisephi 1.3 table.appendChild(tr = $_("tr"));
1906 root 1.1 tr.index = i;
1907    
1908    
1909 sf-demisephi 1.3 tr.appendChild(td=$_("td"));
1910     td.innerHTML = skillNames[i-CS_STAT_SKILLINFO][0];
1911 root 1.1
1912     for (var k =0 ;k<myStats[i].length;++k){
1913    
1914 sf-demisephi 1.3 tr.appendChild(td=$_("td"));
1915 root 1.1 td.innerHTML = myStats[i][k];
1916    
1917     }
1918 sf-demisephi 1.3 tr.appendChild(td=$_("td"));
1919     td.innerHTML = Math.floor(myStats[i][1]/expTable[parseInt(myStats[i][0])]*100) + "%";
1920 root 1.1 /*tr.addEventListener("click",mySpellItemClick);
1921     tr.addEventListener("mouseover",SpellItemMouseOver);
1922     tr.addEventListener("mouseout",SpellItemMouseOut);
1923     tr.addEventListener("mousemove",SpellItemMouseMove);
1924     */
1925     ++j;
1926     };
1927    
1928    
1929     }
1930    
1931     function mySpellItemClick(e){
1932     if (keys.ctrl){
1933     doSend("command invoke " + mySpells[this.index].name);
1934     }else if (keys.shift){
1935     doSend("command cast " + mySpells[this.index].name);
1936     }
1937     }
1938    
1939    
1940     function SpellItemMouseOver(e){
1941     this.style.background = "solid";
1942     this.style.backgroundColor="white";
1943    
1944     xInfoWindow.contents.innerHTML = this.message + "<small><br/>shift-click to cast<br/>ctrl-click to invoke</small>";
1945     xInfoWindow.show(true);
1946     xInfoWindow.style.left = (e.clientX+5)+"px";
1947     xInfoWindow.style.top = (e.clientY+5)+"px";
1948     }
1949    
1950     function SpellItemMouseMove(e){
1951    
1952     xInfoWindow.style.left = (e.clientX+5)+"px";
1953     xInfoWindow.style.top = (e.clientY+5)+"px";
1954    
1955     }
1956    
1957     function SpellItemMouseOut(e){
1958     this.style.background = "transparent";
1959     xInfoWindow.show(false);
1960     }
1961    
1962    
1963     function feed_addspell (data,dataAsArray){
1964    
1965     var buff = new Buffer(dataAsArray);
1966     buff.position = data.indexOf(" ")+1;
1967     while (buff.position<buff.length){
1968     spell=new Spell();
1969    
1970     spell.tag = buff.readUint32();
1971    
1972     spell.minLevel = buff.readUint16();
1973    
1974     spell.castingTime = buff.readUint16();
1975    
1976     spell.mana = buff.readUint16();
1977    
1978     spell.grace = buff.readUint16();
1979    
1980     spell.level = buff.readUint16();
1981    
1982     spell.skill = buff.readUint8();
1983    
1984     spell.path = buff.readUint32();
1985    
1986     spell.face = buff.readUint32();
1987     var len = buff.readUint8();
1988     spell.name = buff.readString(len);
1989     len = buff.readUint16();
1990     spell.message = buff.readString(len);
1991     mySpells.push(spell);
1992     }
1993    
1994    
1995     }
1996    
1997     function feed_delinv (data,dataAsArray){
1998     var container = parseInt(data.split(" ")[1]);
1999 sf-demisephi 1.4 if (container==player.tag){
2000 root 1.1 myItems = [];
2001 sf-demisephi 1.4 }else if (container!=0){
2002     containers["container_" +container]=[];
2003 root 1.1 }else{
2004     floorItems = [];
2005     }
2006 sf-demisephi 1.4 updateItemsList();
2007 root 1.1 return false;
2008     }
2009    
2010     var expTable = [0,1000,3000,7000,15000,31000,63000,98500,145000,210000,290000,400000,530000,695000,895000,1100000,1400000,1750000,2150000,2650000,3200000,3850000,4650000,5500000,6500000,7650000,8800000,10000000,11500000,13500000,15500000,18000000,20500000,23500000,26500000,30000000,34000000,38500000,43000000,48500000,54000000,60500000,67500000,75000000,83000000,91500000,100000000,110000000,120000000,130000000,145000000,160000000,175000000,190000000,210000000,230000000,250000000,275000000,300000000,325000000,350000000,380000000,410000000,445000000,480000000,520000000,560000000,605000000,655000000,705000000,755000000,810000000,870000000,930000000,990000000,1050000000,1100000000,1200000000,1250000000,1350000000,1450000000,1550000000,1650000000,1800000000,1900000000,2000000000,2150000000,2300000000,2450000000,2600000000,2750000000,2900000000,3100000000,3300000000,3500000000,3750000000,4050000000,4350000000,4750000000,5250000000,5850000000,6650000000,7650000000,9000000000,10500000000,13500000000,17000000000,23000000000,32000000000,47000000000,73000000000,120000000000,215000000000,430000000000,935000000000];
2011 sf-demisephi 1.3 var spellPaths = [];
2012 root 1.1
2013     function feed_fx (data,dataAsArray){
2014    
2015     var buff = new Buffer(dataAsArray);
2016     buff.position = 3;
2017     var ignore = true;
2018     while (buff.position<buff.length){
2019     var id = buff.unpack_w();
2020     var len = buff.readUint8();
2021     var nameX = "";
2022     for (var i = 0;i<len;++i){
2023     var c = parseInt(buff.readUint8());
2024     var out="";
2025     out+="0123456789abcdef"[c&0xf];
2026     out= "0123456789abcdef"[c>>4]+out;
2027     nameX+=out;
2028     }
2029 sf-demisephi 1.3 var img = $_("img");
2030 root 1.1
2031     var e;
2032     if (tilesInfo.getImgByFaceNum(id)){
2033    
2034     }else{
2035     if (nameX.length>3){
2036 sf-demisephi 1.3 if (nameX == "5d7a9b7f65deb9e99ce0dd74560eb0"){
2037 root 1.1 var req = new XMLHttpRequest();
2038     req.open('GET', baseURL+""+nameX, false);
2039     req.send(null);
2040     if(req.status == 200)
2041 sf-demisephi 1.3 skillNames = JSON.parse(req.responseText);
2042     }else if (nameX =="6c65c81502952fd958a6f794a0d34c"){
2043     var req = new XMLHttpRequest();
2044     req.open('GET', baseURL+""+nameX, false);
2045     req.send(null);
2046     if(req.status == 200)
2047     spellPaths = JSON.parse(req.responseText);
2048     }else if (nameX=="f66e1bc0a5662e59be0253a84ee06c"){
2049     var req = new XMLHttpRequest();
2050     req.open('GET', baseURL+""+nameX, false);
2051     req.send(null);
2052     if(req.status == 200)
2053     expTable = JSON.parse(req.responseText);
2054 root 1.1 }else{
2055     tilesInfo.listLoading.push (e={name:nameX,id:id,img:img,src:baseURL+""+nameX});
2056     e.img.parent = e;
2057     e.img.onload = function (){tilesInfo.markAsLoaded(this.parent);}
2058     if (!tilesInfo.isLoading){
2059    
2060     tilesInfo.isLoading = true;
2061     e.img.src = e.src;
2062     //alert("loading: " + e.src);
2063     }
2064     }
2065     }else{
2066     //alert ("face num " + id + " has name len :" + len + " !!!!");
2067     //prompt("",dataAsArray);
2068     }
2069     }
2070     }
2071    
2072     return false;
2073     }
2074    
2075    
2076     function feed_newmap (data,dataAsArray){
2077     //messageBox("newmap");
2078     map_clear();
2079 sf-demisephi 1.2
2080 root 1.1 }
2081    
2082     function feed_mapinfo (data,dataAsArray){
2083     var parts = data.split(/ /);
2084     //map_clear();
2085     return false;
2086     }
2087    
2088    
2089     function feed_msg (data,dataAsArray){
2090     var o = null;
2091     if (data.indexOf("[")>0){
2092     o = JSON.parse(data.substr(4));
2093    
2094     channels_addMessage(o[1],o)
2095     return true;
2096     }
2097     return false;
2098     }
2099    
2100    
2101     function feed_anim (data,dataAsArray){
2102     return false;
2103     }
2104    
2105     /*
2106     CONSTANTS
2107     */
2108    
2109     var TICK = 0.120,
2110     CS_QUERY_YESNO = 0x1,
2111     CS_QUERY_SINGLECHAR = 0x2,
2112     CS_QUERY_HIDEINPUT = 0x4,
2113     CS_SAY_NORMAL = 0x1,
2114     CS_SAY_SHOUT = 0x2,
2115     CS_SAY_GSAY = 0x4,
2116     FLOAT_MULTI = 100000,
2117     FLOAT_MULTF = 100000.0,
2118     CS_STAT_HP = 1,
2119     CS_STAT_MAXHP = 2,
2120     CS_STAT_SP = 3,
2121     CS_STAT_MAXSP = 4,
2122     CS_STAT_STR = 5,
2123     CS_STAT_INT = 6,
2124     CS_STAT_WIS = 7,
2125     CS_STAT_DEX = 8,
2126     CS_STAT_CON = 9,
2127     CS_STAT_CHA = 10,
2128     CS_STAT_EXP = 11,
2129     CS_STAT_LEVEL = 12,
2130     CS_STAT_WC = 13,
2131     CS_STAT_AC = 14,
2132     CS_STAT_DAM = 15,
2133     CS_STAT_ARMOUR = 16,
2134     CS_STAT_SPEED = 17,
2135     CS_STAT_FOOD = 18,
2136     CS_STAT_WEAP_SP = 19,
2137     CS_STAT_RANGE = 20,
2138     CS_STAT_TITLE = 21,
2139     CS_STAT_POW = 22,
2140     CS_STAT_GRACE = 23,
2141     CS_STAT_MAXGRACE = 24,
2142     CS_STAT_FLAGS = 25,
2143     CS_STAT_WEIGHT_LIM = 26,
2144     CS_STAT_EXP64 = 28,
2145     CS_STAT_SPELL_ATTUNE = 29,
2146     CS_STAT_SPELL_REPEL = 30,
2147     CS_STAT_SPELL_DENY = 31,
2148     CS_STAT_RESIST_START = 100,
2149     CS_STAT_RESIST_END = 117,
2150     CS_STAT_RES_PHYS = 100,
2151     CS_STAT_RES_MAG = 101,
2152     CS_STAT_RES_FIRE = 102,
2153     CS_STAT_RES_ELEC = 103,
2154     CS_STAT_RES_COLD = 104,
2155     CS_STAT_RES_CONF = 105,
2156     CS_STAT_RES_ACID = 106,
2157     CS_STAT_RES_DRAIN = 107,
2158     CS_STAT_RES_GHOSTHIT = 108,
2159     CS_STAT_RES_POISON = 109,
2160     CS_STAT_RES_SLOW = 110,
2161     CS_STAT_RES_PARA = 111,
2162     CS_STAT_TURN_UNDEAD = 112,
2163     CS_STAT_RES_FEAR = 113,
2164     CS_STAT_RES_DEPLETE = 114,
2165     CS_STAT_RES_DEATH = 115,
2166     CS_STAT_RES_HOLYWORD = 116,
2167     CS_STAT_RES_BLIND = 117,
2168     CS_STAT_SKILLINFO = 140,
2169     CS_NUM_SKILLS = 50,
2170     SF_FIREON = 0x01,
2171     SF_RUNON = 0x02,
2172     NDI_BLACK = 0,
2173     NDI_WHITE = 1,
2174     NDI_NAVY = 2,
2175     NDI_RED = 3,
2176     NDI_ORANGE = 4,
2177     NDI_BLUE = 5,
2178     NDI_DK_ORANGE = 6,
2179     NDI_GREEN = 7,
2180     NDI_LT_GREEN = 8,
2181     NDI_GREY = 9,
2182     NDI_BROWN = 10,
2183     NDI_GOLD = 11,
2184     NDI_TAN = 12,
2185     NDI_MAX_COLOR = 12,
2186     NDI_COLOR_MASK = 0x1f,
2187     NDI_REPLY = 0x20,
2188     NDI_NOCRATE = 0x40,
2189     NDI_CLEAR = 0x80,
2190     a_none = 0,
2191     a_readied = 1,
2192     a_wielded = 2,
2193     a_worn = 3,
2194     a_active = 4,
2195     a_applied = 5,
2196     F_APPLIED = 0x000F,
2197     F_LOCATION = 0x00F0,
2198     F_UNPAID = 0x0200,
2199     F_MAGIC = 0x0400,
2200     F_CURSED = 0x0800,
2201     F_DAMNED = 0x1000,
2202     F_OPEN = 0x2000,
2203     F_NOPICK = 0x4000,
2204     F_LOCKED = 0x8000,
2205     CF_FACE_NONE = 0,
2206     CF_FACE_BITMAP = 1,
2207     CF_FACE_XPM = 2,
2208     CF_FACE_PNG = 3,
2209     CF_FACE_CACHE = 0x10,
2210     FACE_FLOOR = 0x80,
2211     FACE_COLOR_MASK = 0xf,
2212     UPD_LOCATION = 0x01,
2213     UPD_FLAGS = 0x02,
2214     UPD_WEIGHT = 0x04,
2215     UPD_FACE = 0x08,
2216     UPD_NAME = 0x10,
2217     UPD_ANIM = 0x20,
2218     UPD_ANIMSPEED = 0x40,
2219     UPD_NROF = 0x80,
2220     UPD_SP_MANA = 0x01,
2221     UPD_SP_GRACE = 0x02,
2222     UPD_SP_LEVEL = 0x04,
2223     SOUND_NORMAL = 0,
2224     SOUND_SPELL = 1,
2225    
2226     PICKUP_NOTHING = 0x00000000,
2227    
2228     PICKUP_DEBUG = 0x10000000,
2229     PICKUP_INHIBIT = 0x20000000,
2230     PICKUP_STOP = 0x40000000,
2231     PICKUP_NEWMODE = 0x80000000,
2232    
2233     PICKUP_RATIO = 0x0000000F,
2234    
2235     PICKUP_FOOD = 0x00000010,
2236     PICKUP_DRINK = 0x00000020,
2237     PICKUP_VALUABLES = 0x00000040,
2238     PICKUP_BOW = 0x00000080,
2239    
2240     PICKUP_ARROW = 0x00000100,
2241     PICKUP_HELMET = 0x00000200,
2242     PICKUP_SHIELD = 0x00000400,
2243     PICKUP_ARMOUR = 0x00000800,
2244    
2245     PICKUP_BOOTS = 0x00001000,
2246     PICKUP_GLOVES = 0x00002000,
2247     PICKUP_CLOAK = 0x00004000,
2248     PICKUP_KEY = 0x00008000,
2249    
2250     PICKUP_MISSILEWEAPON = 0x00010000,
2251     PICKUP_ALLWEAPON = 0x00020000,
2252     PICKUP_MAGICAL = 0x00040000,
2253     PICKUP_POTION = 0x00080000,
2254    
2255     PICKUP_SPELLBOOK = 0x00100000,
2256     PICKUP_SKILLSCROLL = 0x00200000,
2257     PICKUP_READABLES = 0x00400000,
2258     PICKUP_MAGIC_DEVICE = 0x00800000,
2259    
2260     PICKUP_NOT_CURSED = 0x01000000,
2261    
2262     PICKUP_JEWELS = 0x02000000,
2263     PICKUP_FLESH = 0x04000000;
2264    
2265     var stat_32bit = [CS_STAT_WEIGHT_LIM,CS_STAT_SPELL_ATTUNE,CS_STAT_SPELL_REPEL,CS_STAT_SPELL_DENY,CS_STAT_EXP];
2266    
2267    
2268     function feed_stats (data,dataAsArray){
2269     var buff = new Buffer(dataAsArray);
2270     buff.position = "stats".length + 1;
2271     while (buff.position < buff.length){
2272     var stat = buff.readUint8();
2273     var value;
2274     if (stat_32bit.contains(stat)){
2275     value = buff.readUint32();
2276     }else if (stat == CS_STAT_SPEED||stat==CS_STAT_WEAP_SP){
2277     value = (1/FLOAT_MULTF) * buff.readUint32();
2278     }else if (stat==CS_STAT_RANGE||stat==CS_STAT_TITLE){
2279     var len = buff.readUint8();
2280     value = buff.readString(len);
2281     }else if (stat == CS_STAT_EXP64){
2282     var hi = buff.readUint32();
2283     var lo = buff.readUint32();
2284     value = hi * Math.pow(2,32) + lo;
2285     }else if (stat>=CS_STAT_SKILLINFO && stat < CS_STAT_SKILLINFO + CS_NUM_SKILLS){
2286     var lvl = buff.readUint8();
2287     var hi = buff.readUint32();
2288     var lo = buff.readUint32();
2289     value = [lvl,hi * Math.pow(2,32) + lo];
2290     }else{
2291     value = buff.readUint16();
2292 sf-demisephi 1.3 if (value > 60000){
2293     value -= 65536;
2294     }
2295 root 1.1 }
2296     myStats [stat] = value;
2297     //stats_update (stat);
2298     }
2299    
2300     return true;
2301     }
2302    
2303     function feed_player (data,dataAsArray){
2304 sf-demisephi 1.4 var buff = new Buffer(dataAsArray);
2305     buff.position ="player ".length;
2306     //my ($tag, $weight, $face, $name) = unpack "NNN C/a", $data;
2307     player.tag = buff.readUint32();
2308     player.weight = buff.readUint32();
2309     player.face = buff.readUint32();
2310     var len = buff.readUint8();
2311     player.name = buff.readString(len);
2312 root 1.1 return false;
2313     }
2314    
2315     function feed_drawinfo (data,dataAsArray){
2316     return false;
2317     }
2318    
2319    
2320    
2321     var tilesInfo = {
2322     listLoading:[],
2323     listLoaded:[],
2324    
2325     isLoading: false,
2326     getImgByFaceNum:function (id){
2327     for (var i=0;i<this.listLoaded.length;++i){
2328     if (this.listLoaded[i].id==id){
2329     return this.listLoaded[i].img;
2330     }
2331     }
2332     return null;
2333     },
2334     isImgLoading : function (id){
2335     for (var i=0;i<this.listLoading.length;++i){
2336     if (this.listLoading[i].id==id){
2337     return true;
2338     }
2339     }
2340     return false;
2341     },
2342     markAsLoaded : function (e){
2343     var i;
2344     for (i=0;i<this.listLoading.length;++i){
2345     if (this.listLoading[i].id == e.id){
2346     this.listLoading.splice(i,1);
2347     break;
2348     }
2349     }
2350    
2351     this.listLoaded.push (e);
2352     this.isLoading = false;
2353     while ((this.listLoading.length>0)&&(this.isLoading==false)){
2354    
2355     var e2 = this.listLoading.pop();
2356     if (e2.src.length > baseURL.length + 1){
2357     this.isLoading = true;
2358     e2.img.src = e2.src;
2359     //alert("loading " + e2.src);
2360     e2.onload = e.onload;
2361     }
2362     }
2363     }
2364     }
2365    
2366     var baseURL = "";
2367     DrawLater = {
2368     list : []
2369     };
2370    
2371    
2372     function imgFromString (s){
2373     var img = $_('img');
2374     img.src = s;
2375     return img;
2376     }
2377    
2378     function need_facenum (num){
2379     var img;
2380    
2381     if (tilesInfo.getImgByFaceNum(num)!=null){
2382     return;
2383     }
2384    
2385     /*if ( img = localStorage.getItem("face_" + num)){
2386    
2387     tilesInfo.listLoaded.push({num:num,data: {img:imgFromString(img)}});
2388     return;
2389     }*/
2390     }
2391     var dx = 0;
2392     var dy = 0;
2393    
2394     function feed_map_scroll (data,dataAsArray,base64data){
2395    
2396     data = data.split(/ /);
2397     data.shift();
2398     dx += parseInt(data.shift());
2399     dy += parseInt(data.shift());
2400    
2401    
2402     }
2403    
2404    
2405     function feed_ix (data,dataAsArray,base64data){
2406    
2407     }
2408    
2409     function arr2bytes(arr){
2410     var s = "";
2411     for (var i=0;i<arr.length;++i){
2412     s+=String.fromCharCode(arr[i]);
2413     }
2414     return s;
2415     }
2416     function bytes2arr(s){
2417     var arr = [];
2418     for (var i=0;i<s.length;++i){
2419     arr.push(s.charCodeAt(i));
2420     }
2421     return arr;
2422     }
2423     function $_(p){
2424     if (document.getElementById(p)!=null){
2425     return document.getElementById(p);
2426     }else{
2427 sf-demisephi 1.3 var ret = document.createElement(p);
2428     unselectable(ret);
2429     return ret;
2430 root 1.1 }
2431     }
2432     var tiles = [];
2433    
2434     function onMessage(evt)
2435     {
2436     var data = evt.data;
2437 root 1.10
2438     if (evt.data instanceof Blob){
2439     var r = new FileReader ();
2440     r.readAsText (data, "iso-8859-1");
2441     data = r.result;
2442     console.debug(r);
2443     }
2444    
2445     console.debug(typeof (data));
2446     console.debug(data);
2447 root 1.1
2448     var patt=/[0-9a-z_]*[^0-9a-z_]/i;
2449 root 1.5 var feed = "" + data.match(patt);
2450     feed = feed.substr (0,feed.length -1);
2451 root 1.1 if (feed=="nul"){
2452     if (data=="newmap"){
2453     feed="newmap";
2454     }else{
2455     return;
2456     }
2457     }
2458     if ((window['feed_' + feed])&&(typeof(window['feed_' + feed])=="function")){
2459 root 1.10 var retVal = window['feed_' + feed](data,bytes2arr(evt.data),evt.data);
2460 root 1.1 if (!retVal){
2461     //writeToScreen("[" + feed + "] " + data );
2462     //writeToScreen(dataAsArray);
2463     }
2464     }else{
2465     //alert('unhandled "feed_' + feed + '"');
2466    
2467     }
2468     }
2469    
2470     function decode_base64toArray(s) {
2471     var e={},i,k,v=[],r=[],w=String.fromCharCode;
2472     var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];
2473    
2474     for(z in n){for(i=n[z][0];i<n[z][1];i++){v.push(w(i));}}
2475     for(i=0;i<64;i++){e[v[i]]=i;}
2476    
2477     for(i=0;i<s.length;i+=72){
2478     var b=0,c,x,l=0,o=s.substring(i,i+72);
2479     for(x=0;x<o.length;x++){
2480     c=e[o.charAt(x)];b=(b<<6)+c;l+=6;
2481     while(l>=8){r.push((b>>>(l-=8))%256);}
2482     }
2483     }
2484     return r;
2485     }
2486    
2487    
2488    
2489     function processExtObj (o){
2490     switch (o[0]){
2491     case "channel_info":
2492     channels[o[1].id] = o[1];
2493     channels.list.push (channels[o[1].id]);
2494     channels[o[1].id].index =channels.length;
2495     channels.length+=1;
2496     return true;
2497     default:
2498     return false;
2499     break;
2500     }
2501     }
2502    
2503     function onError(evt)
2504     {
2505     writeToScreen("ERROR!");
2506     }
2507    
2508     function doSend(message)
2509     {
2510     writeToScreen("SENT: " + message);
2511 root 1.5 websocket.send(
2512     String.fromCharCode (message.length >> 8)
2513     + String.fromCharCode (message.length & 255)
2514     + message
2515     );
2516 root 1.1 }
2517    
2518     function writeToScreen(message)
2519     {
2520     var d = new Date();
2521     //Messages.push(new Message(200,(d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() ) + ":" + message));
2522     output.value = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ":" + message + "\n" + output.value;
2523     }
2524    
2525     function fillFromTemplate(e){
2526     document.getElementById("text").value = e.value;
2527     }
2528    
2529     isMainScriptLoaded = true;
2530    
2531    
2532     //+ Jonas Raoni Soares Silva
2533     //@ http://jsfromhell.com/geral/utf-8 [rev. #1]
2534    
2535     UTF8 = {
2536     encode: function(s){
2537     for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
2538     s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
2539     );
2540     return s.join("");
2541     },
2542     decode: function(s){
2543     for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
2544     ((a = s[i][c](0)) & 0x80) &&
2545     (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
2546     o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
2547     );
2548     return s.join("");
2549     }
2550 root 1.5 };