ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/html5client/main.js
Revision: 1.14
Committed: Tue Nov 6 20:46:53 2012 UTC (13 years, 11 months ago) by root
Content type: application/javascript
Branch: MAIN
Changes since 1.13: +22 -0 lines
Log Message:
*** empty log message ***

File Contents

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