PHPXRef 0.7 : NEABExplorer : /locations_modules/2dmap/map_script.js source
[ Index ]
PHP Cross Reference of NEABExplorer
if (gwGetCookie('xrefnav')=='off')
document.write('[ Show Explorer ]');
else
document.write('[ Hide Explorer ]');
[ Show Explorer ]
[ Hide Navbar ]
titleBody[close]
/locations_modules/2dmap/ -> map_script.js (source)
[Summary view]
[Print]
[Text view]
1 /************************************************************
2 (c) Alain Bertrand - 2005
3 Please contact the author before using it for you own needs:
4 bertrand@nodalideas.com
5 ************************************************************/
6
7 var kb = {LEFT:37, RIGHT:39, UP:38, DOWN:40, BACKSPACE:8, CAPSLOCK:20, CONTROL:17, DELETEKEY:46, END:35, ENTER:13, ESCAPE:27, HOME:36, INSERT:45, TAB:9, PGDN:34, PGUP:33, SPACE:32, SHIFT:16};
8
9 var comedir=-1;
10 var isherbs=new Array();
11 var isinit=false;
12 var map_dialogs=new Array();
13 var inmapdialog=false;
14
15 // Structure which stores the map dialogs
16 function map_dialog(x,y,dialog)
17 {
18 this.x=x;
19 this.y=y;
20 this.dialog=dialog;
21 }
22
23 function add_map_dialog(x,y,dialog)
24 {
25 map_dialogs[map_dialogs.length]=new map_dialog(x,y,dialog)
26 }
27
28 function draw_dialogs(rx,ry,x,y)
29 {
30 var div=document.getElementById("DIALOG_DIV");
31 for(var i=0;i < map_dialogs.length;i++)
32 {
33 var a=x-map_dialogs[i].x;
34 var b=y-map_dialogs[i].y;
35
36 var d=Math.round(Math.sqrt(a*a+b*b));
37 if(d < 2)
38 {
39 var dx;
40 var dy;
41 if(zoom)
42 {
43 dx=(map_dialogs[i].x-rx)*128-10;
44 dy=(map_dialogs[i].y-ry)*128-10;
45 }
46 else
47 {
48 dx=(map_dialogs[i].x-rx)*64+185-40;
49 dy=(map_dialogs[i].y-ry)*64+80-10;
50 }
51 div.style.top=dy;
52 div.style.left=dx;
53 div.style.visibility="visible";
54 div.innerHTML=map_dialogs[i].dialog;
55 return;
56 }
57 }
58 div.style.visibility="hidden";
59 }
60
61 function getCookie(name)
62 {
63 var dc = document.cookie;
64 var prefix = name + "=";
65 var begin = dc.indexOf("; " + prefix);
66 if (begin == -1)
67 {
68 begin = dc.indexOf(prefix);
69 if (begin != 0) return null;
70 }
71 else
72 {
73 begin += 2;
74 }
75 var end = document.cookie.indexOf(";", begin);
76 if (end == -1)
77 {
78 end = dc.length;
79 }
80 return unescape(dc.substring(begin + prefix.length, end));
81 }
82
83 function change_hp()
84 {
85 document.images['HP'].width=Math.ceil(hp/maxhp*99)+1;
86 text=String(hp)+"/"+String(maxhp);
87 try
88 {
89 document.getElementById("HPVIEW").innerHTML=text;
90 }
91 catch(e)
92 {
93 }
94 }
95
96 function disable_move()
97 {
98 disablemove=true;
99 if(timeID != 0)
100 clearTimeout(timeID);
101 divtiles=document.getElementById("BG_TILES");
102 divwait=document.getElementById("WAIT_LOADING");
103 if(divtiles == null)
104 return;
105 divtiles.style.visibility="hidden";
106 divwait.style.visibility="visible";
107 if(document.getElementById("TIME") != null)
108 document.getElementById("TIME").style.visibility="hidden";
109
110 // Hidde objects
111 for(var i=0;i < 7;i++)
112 {
113 for(var j=0;j < 7;j++)
114 {
115 divobj=document.getElementById("OVER_OBJ_"+i+"_"+j);
116 divobj.style.visibility="hidden";
117 }
118 }
119 divwait.innerHTML="<BR><BR><BR><FONT SIZE=+2>Loading new map... Please wait.</FONT>";
120 }
121
122 function init_map()
123 {
124 // Init the keyboard
125 init();
126
127 // Check if the startup position is not walkable... In which case try to find a better position.
128 for(var i=0;i < 600;i++)
129 isherbs[i]=false;
130 for(var i=0;i < herbs.length;i++)
131 isherbs[herbs[i]]=true;
132
133 divtiles=document.getElementById("BG_TILES");
134 if(divtiles.style.visibility == "visible")
135 return;
136 divtiles.style.visibility="visible";
137 if(document.getElementById("TIME") != null)
138 document.getElementById("TIME").style.visibility="visible";
139 if(y == 0)
140 comedir=0;
141 else if(x == 0)
142 comedir=1;
143 else if(x == 98)
144 comedir=2;
145 else if(y == 98)
146 comedir=3;
147
148 if(check_walkable_map(map[x][y],boat) == false)
149 {
150 for(var i=1;i < 99;i++)
151 {
152 for(var j=1;j < 99;j++)
153 {
154 if(check_walkable_map(map[i][j],boat) == true)
155 {
156 x=i;
157 y=j;
158 break;
159 }
160 }
161 if(check_walkable_map(map[i][j],boat) == true)
162 break;
163 }
164 }
165
166 // Show the two layers now that we are loaded...
167 divwait=document.getElementById("WAIT_LOADING");
168 document.getElementById("MESSAGES").style.backgroundColor="#E0E0E0";
169 document.getElementById("MESSAGES").innerHTML="<B>Message window:</B>\n";
170
171 if(showminimap == true && ismappable == false)
172 document.getElementById("MESSAGES").innerHTML="<B>Message window:</B><BR>It seems the minimap doesn't work here.\n";
173 else if(document.getElementById("TIME") != null)
174 document.getElementById("MESSAGES").innerHTML="<B>Message window:</B>\n<BR>It's now "+hour+" in the realm.\n";
175
176 divwait.style.visibility="hidden";
177
178 if(nbmonsters == 0 && isplayerdongeon == false)
179 {
180 Display();
181 return;
182 }
183
184 if(restore_monsters() == true)
185 {
186 paint_monsters();
187 if(isplayerdongeon == true && owner == userid)
188 {
189 for(var i=0;i < 100;i++)
190 for(var j=0;j < 100;j++)
191 if(mapobj[i][j] == 143) // Switch on the dongeon manager.
192 {
193 mapobj[i][j]=142;
194 Display();
195 return;
196 }
197 }
198 Display();
199 return;
200 }
201
202 placed=0;
203
204 for(var i=0;i < 100;i++)
205 {
206 for(var j=0;j < 100;j++)
207 {
208 if(mapobj[i][j] == 143 && isplayerdongeon == true && owner == userid) // Switch on the dongeon manager.
209 mapobj[i][j]=142;
210 // No objects Not on the walls of the cave :-) And with some random
211 else if(nbmonsters > 0 && density > 0 && mapobj[i][j] == 0 && check_walkable_map(map[i][j],false) == true && Math.round(Math.random()*density) == 0)
212 {
213 placed++;
214 mapobj[i][j]=-monsterid[Math.floor(Math.random()*nbmonsters)];
215 }
216 }
217 }
218 paint_monsters();
219 Display();
220 }
221
222 function paint_monsters()
223 {
224 if(showminimonsters == false)
225 return;
226 html="";
227 for(var i=0;i < 99;i++)
228 for(var j=0;j < 99;j++)
229 if(mapobj[i][j] < 0)
230 {
231 if(zoom)
232 html+="<DIV STYLE='position: absolute; visibility: visible; top: "+(j*2)+"; left: "+(i*2)+"; height: 2; width: 2; background-color: #A00000;'><IMAGE SRC=images/spacer.gif WIDTH=2 HEIGHT=2></DIV>\n";
233 else
234 html+="<DIV STYLE='position: absolute; visibility: visible; top: "+(j*2+4)+"; left: "+(i*2+4)+"; height: 2; width: 2; background-color: #A00000;'><IMAGE SRC=images/spacer.gif WIDTH=2 HEIGHT=2></DIV>\n";
235 }
236 document.getElementById("MINIMONSTERS").innerHTML=html;
237 }
238
239 function move_monsters()
240 {
241 if(repulse == true)
242 {
243 paint_monsters();
244 return;
245 }
246 a=x-5;b=y-5;
247 c=x+5;d=y+5;
248
249 donepos=new Array(27);
250 for(var i=0;i < 27;i++)
251 donepos[i]=new Array(11);
252 for(var i=0;i < 27;i++)
253 for(var j=0;j < 27;j++)
254 donepos[i][j]=0;
255
256 timeID=setTimeout("move_monsters()",700);
257
258 if(a < 0) a=0;
259 if(b < 0) b=0;
260 if(c > 99) c=99;
261 if(d > 99) d=99;
262
263 // Display pos
264 rx=x-3;
265 ry=y-3;
266 if(rx < 0)
267 rx=0;
268 if(ry < 0)
269 ry=0;
270 if(rx > 99-7)
271 rx=99-7;
272 if(ry > 99-7)
273 ry=99-7;
274
275 changed=false;
276
277 for(var i=a;i <= c;i++)
278 {
279 for(var j=b;j <= d;j++)
280 {
281 if(mapobj[i][j] < 0 && donepos[i+8-rx][j+8-ry] == 0) // it's a monster... we didn't touched it so far, so let move it
282 {
283 changed=true;
284 e=i;f=j;
285 if(invisible != 0)
286 {
287 switch(Math.round(Math.random()*4))
288 {
289 case 0:
290 if(mapobj[e+1][f] == 0 && check_walkable_map(map[e+1][f],false) == true)
291 e++;
292 break;
293 case 1:
294 if(mapobj[e-1][f] == 0 && check_walkable_map(map[e-1][f],false) == true)
295 e--;
296 break;
297 case 2:
298 if(mapobj[e][f+1] == 0 && check_walkable_map(map[e][f+1],false) == true)
299 f++;
300 break;
301 case 3:
302 if(mapobj[e][f-1] == 0 && check_walkable_map(map[e][f-1],false) == true)
303 f--;
304 break;
305 }
306 }
307 else if(e < x && mapobj[e+1][f] == 0 && check_walkable_map(map[e+1][f],false) == true)
308 e++;
309 else if(e > x && mapobj[e-1][f] == 0 && check_walkable_map(map[e-1][f],false) == true)
310 e--;
311 else if(f < y && mapobj[e][f+1] == 0 && check_walkable_map(map[e][f+1],false) == true)
312 f++;
313 else if(f > y && mapobj[e][f-1] == 0 && check_walkable_map(map[e][f-1],false) == true)
314 f--;
315 if(e == x && f == y) // The monster attacked us
316 {
317 //newloc="game.php?COMBAT="+(-mapobj[i][j])+"&X="+x+"&Y="+y
318 document.forms["COMM"].COMBAT.value=(-mapobj[i][j]);
319 document.forms["COMM"].X.value=x;
320 document.forms["COMM"].Y.value=y;
321 if(invisible != -100)
322 document.forms["COMM"].INVISIBILITY.value=invisible;
323 else
324 document.forms["COMM"].INVISIBILITY.value=0;
325 mapobj[i][j]=0;
326 disable_move();
327 needtostore=false;
328 //document.location=newloc;
329 document.forms["COMM"].submit();
330 return;
331 }
332 if(e != i || f != j)
333 {
334 mapobj[e][f]=mapobj[i][j];
335 mapobj[i][j]=0;
336 if((i-rx) >= 0 && (i-rx) < 7 && (j-ry) >= 0 && (j-ry) < 7)
337 {
338 document.images["OBJ_"+(i-rx)+"_"+(j-ry)].src=loader+tileset+"objects/0.gif";
339 divobj=document.getElementById("OVER_OBJ_"+(i-rx)+"_"+(j-ry));
340 if(divobj.style != null)
341 divobj.style.visibility="hidden";
342 else
343 divobj.visibility="hidden";
344 }
345 if((e-rx) >= 0 && (e-rx) < 7 && (f-ry) >= 0 && (f-ry) < 7)
346 {
347 if((-mapobj[e][f]) >= 10000)
348 document.images["OBJ_"+(e-rx)+"_"+(f-ry)].src=cacheloader+"monsters/monster_"+(-mapobj[e][f])+"_s.png";
349 else
350 document.images["OBJ_"+(e-rx)+"_"+(f-ry)].src=loader+"monsters/monster_"+(-mapobj[e][f])+"_s.gif";
351 divobj=document.getElementById("OVER_OBJ_"+(e-rx)+"_"+(f-ry));
352 if(divobj.style != null)
353 divobj.style.visibility="visible";
354 else
355 divobj.visibility="visible";
356 }
357 //Display();
358 //return;
359 donepos[e+8-rx][f+8-ry]=1;
360 }
361 }
362 }
363 }
364 if(changed == true)
365 paint_monsters();
366 }
367
368 function check_map(a,b,px,py)
369 {
370 if(map[a][b] == 102)
371 {
372 document.forms["COMM"].ACTION.value='DOOR';
373 document.forms["COMM"].X.value=px;
374 document.forms["COMM"].Y.value=py;
375 document.forms["COMM"].DX.value=a;
376 document.forms["COMM"].DY.value=b;
377 if(invisible != -100)
378 document.forms["COMM"].INVISIBILITY.value=invisible;
379 else
380 document.forms["COMM"].INVISIBILITY.value=0;
381 disable_move();
382 needtostore=false;
383 document.forms["COMM"].submit();
384 return false;
385 }
386 return true;
387 }
388
389 function check_walkable_map(type,flagboat)
390 {
391 if(flagboat == true && type >= 52 && type <= 64) // Water
392 return true;
393 if(flagboat == false && type >= 121 && type <= 132) // Ice & Water
394 return true;
395 if(flagboat == false && type >= 165 && type <= 172) // Ice & Water & Sand
396 return true;
397
398 if(bgwalk.charAt(type) == "N")
399 return false;
400 return true;
401 }
402
403 function check_walkable_obj(a,b)
404 {
405 type=mapobj[a][b];
406
407 if(type < 0) // Moved over a monster
408 {
409 document.forms["COMM"].COMBAT.value=(-type);
410 document.forms["COMM"].X.value=a;
411 document.forms["COMM"].Y.value=b;
412 if(invisible != -100)
413 document.forms["COMM"].INVISIBILITY.value=invisible;
414 else
415 document.forms["COMM"].INVISIBILITY.value=0;
416 mapobj[a][b]=0;
417 disable_move();
418 needtostore=false;
419 document.forms["COMM"].submit();
420 return false;
421 }
422
423 switch(type)
424 {
425 case 115: // Down
426 case 117:
427 if(randommap == true)
428 {
429 disable_move();
430 needtostore=false;
431 document.location=downlink+"&PREVLOC="+loc;
432 }
433 return true;
434 break;
435 case 114: // Up
436 case 118:
437 if(randommap == true)
438 {
439 disable_move();
440 needtostore=false;
441 document.location=uplink+"&PREVLOC="+loc;
442 }
443 return true;
444 break;
445 case 149: // Crystal ball
446 if(isplayerdongeon == true)
447 {
448 document.forms["COMM"].ACTION.value='CRYSTALBALL';
449 document.forms["COMM"].X.value=a;
450 document.forms["COMM"].Y.value=b;
451 if(invisible != -100)
452 document.forms["COMM"].INVISIBILITY.value=invisible;
453 else
454 document.forms["COMM"].INVISIBILITY.value=0;
455 disable_move();
456 needtostore=false;
457 document.forms["COMM"].submit();
458 }
459 return false;
460 case 155: // Piano
461 case 170: // Organ
462 document.forms["COMM"].ACTION.value='PLAYORGAN';
463 document.forms["COMM"].X.value=a;
464 document.forms["COMM"].Y.value=b;
465 if(invisible != -100)
466 document.forms["COMM"].INVISIBILITY.value=invisible;
467 else
468 document.forms["COMM"].INVISIBILITY.value=0;
469 disable_move();
470 needtostore=false;
471 document.forms["COMM"].submit();
472 return false;
473 case 116: // Tresore box
474 if(isplayerdongeon == true)
475 {
476 document.forms["COMM"].ACTION.value='MANAGECHEST';
477 document.forms["COMM"].OWNER.value=owner;
478 document.forms["COMM"].LEVEL.value=1;
479 document.forms["COMM"].X.value=a;
480 document.forms["COMM"].Y.value=b;
481 if(invisible != -100)
482 document.forms["COMM"].INVISIBILITY.value=invisible;
483 else
484 document.forms["COMM"].INVISIBILITY.value=0;
485 disable_move();
486 needtostore=false;
487 document.forms["COMM"].submit();
488 return false;
489 }
490 else if(randommap == true)
491 {
492 if(owner == 0)
493 {
494 mapobj[a][b]=0;
495 harverst("CHEST",a,b);
496 }
497 else
498 {
499 document.forms["COMM"].ACTION.value='CHEST';
500 document.forms["COMM"].OWNER.value=owner;
501 document.forms["COMM"].LEVEL.value=1;
502 document.forms["COMM"].X.value=a;
503 document.forms["COMM"].Y.value=b;
504 if(invisible != -100)
505 document.forms["COMM"].INVISIBILITY.value=invisible;
506 else
507 document.forms["COMM"].INVISIBILITY.value=0;
508 disable_move();
509 needtostore=false;
510 document.forms["COMM"].submit();
511 }
512 return true;
513 }
514 return true;
515 case 132: // Firefern (if in underground)
516 if(randommap == true)
517 {
518 mapobj[a][b]=0;
519 harverst("GETFIREFERN",a,b);
520 return true;
521 }
522 return false;
523 case 134: // Big stone
524 if(injail == true)
525 {
526 harverst("JAILMETAL",a,b);
527 return false;
528 }
529 else if(randommap == true && weapon == 24)
530 {
531 if(hp >= 3)
532 {
533 mapobj[a][b]=0;
534 harverst("GETMETAL",a,b);
535 hp-=1;
536 change_hp();
537 }
538 else
539 {
540 display_message("You are too weak to continue to harvest metals.");
541 }
542 return true;
543 }
544 else if(randommap == true && weapon != 24)
545 {
546 display_message("You must have equiped a pick in order to harverst metals.");
547 return false;
548 }
549 return false;
550 case 220: // Mytril stone
551 if(randommap == true && weapon == 24)
552 {
553 if(hp >= 3)
554 {
555 mapobj[a][b]=0;
556 harverst("GETMYTRIL",a,b);
557 hp-=1;
558 change_hp();
559 }
560 else
561 {
562 display_message("You are too weak to continue to harvest metals.");
563 }
564 return true;
565 }
566 else if(randommap == true && weapon != 24)
567 {
568 display_message("You must have equiped a pick in order to harverst metals.");
569 return false;
570 }
571 return false;
572 case 61: // Thumbstone
573 if(injail == true)
574 alert("Here lies Tom, He died trying to work off what he stole.\nHis lesson has been learned.\n-The Guard");
575 return true;
576 case 5: // Trees
577 case 57:
578 case 58:
579 case 62:
580 case 63:
581 if(weapon == 1)
582 {
583 if(hp >= 3)
584 hp-=1;
585 change_hp();
586 harverst("GETWOOD",a,b);
587 }
588 else
589 display_message("You must have equiped an hand axe in order to harverst wood.");
590 return false;
591 case 138: // Green Egg
592 if(randommap == true)
593 {
594 harverst("GETEGG",a,b);
595 mapobj[a][b]=0;
596 return true;
597 }
598 return false;
599 case 139: // Red mushroom
600 if(randommap == true)
601 {
602 harverst("GETREDMUSHROOM",a,b);
603 mapobj[a][b]=0;
604 return true;
605 }
606 return false;
607 case 140: // Red mushroom
608 if(randommap == true)
609 {
610 harverst("GETBLUEMUSHROOM",a,b);
611 mapobj[a][b]=0;
612 return true;
613 }
614 return false;
615 case 141: // Augmentatium
616 if(randommap == true)
617 {
618 harverst("GETAUGMENT",a,b);
619 mapobj[a][b]=0;
620 return true;
621 }
622 return false;
623 case 142:
624 if(isplayerdongeon == true)
625 {
626 document.forms["COMM"].ACTION.value='MANAGEDONGEON';
627 document.forms["COMM"].X.value=a;
628 document.forms["COMM"].Y.value=b;
629 if(invisible != -100)
630 document.forms["COMM"].INVISIBILITY.value=invisible;
631 else
632 document.forms["COMM"].INVISIBILITY.value=0;
633 disable_move();
634 needtostore=false;
635 document.forms["COMM"].submit();
636 return false;
637 }
638 return false;
639 case 124: // Beds
640 case 125:
641 case 126:
642 case 168:
643 if(isplayerdongeon == true)
644 {
645 document.forms["COMM"].ACTION.value='SLEEP';
646 document.forms["COMM"].X.value=a;
647 document.forms["COMM"].Y.value=b;
648 if(invisible != -100)
649 document.forms["COMM"].INVISIBILITY.value=invisible;
650 else
651 document.forms["COMM"].INVISIBILITY.value=0;
652 disable_move();
653 needtostore=false;
654 document.forms["COMM"].submit();
655 return false;
656 }
657 return false;
658 case 187: // Junkyard
659 harverst("JUNKYARD",a,b);
660 return false;
661 case 250: // Trap
662 document.forms["COMM"].ACTION.value='TRAP';
663 document.forms["COMM"].X.value=a;
664 document.forms["COMM"].Y.value=b;
665 if(invisible != -100)
666 document.forms["COMM"].INVISIBILITY.value=invisible;
667 else
668 document.forms["COMM"].INVISIBILITY.value=0;
669 disable_move();
670 needtostore=false;
671 document.forms["COMM"].submit();
672 return true;
673 default:
674 if(isherbs[type] == true)
675 {
676 harverst("HERBS&TYPE="+type,a,b);
677 mapobj[a][b]=0;
678 }
679
680 if(objwalk.charAt(type) == 'Y')
681 return true;
682 return false;
683 }
684 }
685
686 function GoUp()
687 {
688 if(disablemove == true)
689 return;
690 if(!monsterstarted)
691 {
692 monsterstarted=true;
693 timeID=setTimeout("move_monsters()",500);
694 }
695 var nx=x;
696 var ny=y;
697
698 ny--;
699 playerdir='n';
700 if(ny < 0)
701 ny=0;
702 ok=true;
703 if(check_map(nx,ny,x,y) == false)
704 ok=false;
705 if(ok == true && (check_walkable_map(map[nx][ny],boat) == false || (mapobj[nx][ny] != 0 && check_walkable_obj(nx,ny) == false)))
706 ok=false;
707 else
708 y=ny;
709
710
711 if(ok == true)
712 handle_sickness();
713 }
714
715 function GoDown()
716 {
717 if(disablemove == true)
718 return;
719 if(!monsterstarted)
720 {
721 monsterstarted=true;
722 timeID=setTimeout("move_monsters()",500);
723 }
724 var nx=x;
725 var ny=y;
726 ny++;
727 playerdir='s';
728 if(ny > 98)
729 ny=98;
730 ok=true;
731 if(check_map(nx,ny,x,y) == false)
732 ok=false;
733 if(ok == true && (check_walkable_map(map[nx][ny],boat) == false || (mapobj[nx][ny] != 0 && check_walkable_obj(nx,ny) == false)))
734 ok=false;
735 else
736 y=ny;
737
738 if(ok == true)
739 handle_sickness();
740 }
741
742 function GoLeft()
743 {
744 if(disablemove == true)
745 return;
746 if(!monsterstarted)
747 {
748 monsterstarted=true;
749 timeID=setTimeout("move_monsters()",500);
750 }
751
752 var nx=x;
753 var ny=y;
754 nx--;
755 playerdir='w';
756 if(nx < 0)
757 nx=0;
758 ok=true;
759 if(check_map(nx,ny,x,y) == false)
760 ok=false;
761 if(ok == true && (check_walkable_map(map[nx][ny],boat) == false || (mapobj[nx][ny] != 0 && check_walkable_obj(nx,ny) == false)))
762 ok=false;
763 else
764 x=nx;
765
766 if(ok == true)
767 handle_sickness();
768 }
769
770 function GoRight()
771 {
772 if(disablemove == true)
773 return;
774 if(!monsterstarted)
775 {
776 monsterstarted=true;
777 timeID=setTimeout("move_monsters()",500);
778 }
779 var nx=x;
780 var ny=y;
781 nx++;
782 playerdir='e';
783 if(nx > 98)
784 nx=98;
785 ok=true;
786 if(check_map(nx,ny,x,y) == false)
787 ok=false;
788 if(ok == true && (check_walkable_map(map[nx][ny],boat) == false || (mapobj[nx][ny] != 0 && check_walkable_obj(nx,ny) == false)))
789 ok=false;
790 else
791 x=nx;
792
793 if(ok == true)
794 handle_sickness();
795 }
796
797 function CheckLinks(checkborder)
798 {
799 // Check if there is a link at the current pos
800 for(var i=0;i < linkx.length;i++)
801 {
802 if(linkx[i] == x && linky[i] == y)
803 {
804 newloc=maplinks[i];
805 needtostore=false;
806 needtostoremonsters=false;
807
808 //if(inmap[i] == true)
809 if(maplinks[i].indexOf("&INMAP=TRUE") != -1)
810 {
811 document.getElementById("NPCDIALOG").src=newloc+"&PREVLOC="+loc+"&X="+x+"&Y="+y;
812 if(zoom == true)
813 {
814 document.getElementById("NPCDIALOG").style.top=document.body.clientHeight/2+64;
815 var l=(document.body.clientWidth-185)/2-document.getElementById("NPCDIALOG").clientWidth/2;
816 document.getElementById("NPCDIALOG").style.left=l+121;
817 }
818 else
819 {
820 document.getElementById("NPCDIALOG").style.top=339;
821 document.getElementById("NPCDIALOG").style.left=211;
822 }
823 document.getElementById("NPCDIALOG").style.visibility="visible";
824 inmapdialog=true;
825 }
826 else
827 {
828 disable_move();
829 document.location=newloc+"&PREVLOC="+loc;
830 }
831 return true;
832 }
833 }
834 // Over a water monster ? Totaly random :-)
835 if(map[x][y] == 52 && Math.floor(Math.random()*50) == 0)
836 {
837 document.forms["COMM"].ACTION.value="WATERCOMBAT";
838 document.forms["COMM"].X.value=x;
839 document.forms["COMM"].Y.value=y;
840 if(invisible != -100)
841 document.forms["COMM"].INVISIBILITY.value=invisible;
842 else
843 document.forms["COMM"].INVISIBILITY.value=0;
844 disable_move();
845 needtostore=false;
846 document.forms["COMM"].submit();
847 }
848 if(mapobj[x][y] == 116 && randommap == false) // Tresor chest !
849 {
850 document.forms["COMM"].ACTION.value='CHEST';
851 document.forms["COMM"].X.value=x;
852 document.forms["COMM"].Y.value=y;
853 if(invisible != -100)
854 document.forms["COMM"].INVISIBILITY.value=invisible;
855 else
856 document.forms["COMM"].INVISIBILITY.value=0;
857 disable_move();
858 needtostore=false;
859 document.forms["COMM"].submit();
860 return true;
861 }
862 if(checkborder == true && x == 0 && leftlink != null)
863 {
864 disable_move();
865 needtostore=false;
866 needtostoremonsters=false;
867 document.location=leftlink+"&X=98&Y="+y+"&PREVLOC="+loc;
868 return true;
869 }
870 else if(checkborder == true && x == 98 && rightlink != null)
871 {
872 disable_move();
873 needtostore=false;
874 needtostoremonsters=false;
875 document.location=rightlink+"&X=0&Y="+y+"&PREVLOC="+loc;
876 return true;
877 }
878 else if(checkborder == true && y == 0 && toplink != null)
879 {
880 disable_move();
881 needtostore=false;
882 needtostoremonsters=false;
883 document.location=toplink+"&X="+x+"&Y=98&PREVLOC="+loc;
884 return true;
885 }
886 else if(checkborder == true && y == 98 && bottomlink != null)
887 {
888 disable_move();
889 needtostore=false;
890 needtostoremonsters=false;
891 document.location=bottomlink+"&X="+x+"&Y=0&PREVLOC="+loc;
892 return true;
893 }
894 return false;
895 }
896
897 function Display()
898 {
899 if(disablemove == true || isinit == false)
900 return;
901
902 var rx=x-3;
903 var ry=y-3;
904 if(rx < 0)
905 rx=0;
906 if(ry < 0)
907 ry=0;
908 if(rx > 99-7)
909 rx=99-7;
910 if(ry > 99-7)
911 ry=99-7;
912 var ux=x-rx;
913 var uy=y-ry;
914
915 draw_dialogs(rx,ry,x,y);
916
917 if(showminimap == true) // Should update the minimap
918 {
919 cell=document.getElementById("MINIMAPPOS");
920 var a=0;
921 var b=0;
922 if(zoom)
923 {
924 a=x*2;
925 b=y*2+1;
926
927 var w=document.body.clientWidth-200;
928 if(w > 882) w=882;
929 a+=w;
930 }
931 else
932 {
933 a=x*2+644;
934 b=y*2+324;
935 }
936 if(cell.style != null)
937 {
938 cell.style.top=b;
939 cell.style.left=a;
940 }
941 else
942 {
943 cell.top=b;
944 cell.left=a;
945 }
946 }
947
948 for(var i=0;i < 7;i++)
949 {
950 for(var j=0;j < 7;j++)
951 {
952 document.images["IMG_"+i+"_"+j].src=loader+tileset+"tiles/"+map[i+rx][j+ry]+".gif";
953
954 if(mapobj[i+rx][j+ry] == 0 && (i+rx) != x && (j+ry) != y)
955 document.getElementById("OVER_OBJ_"+i+"_"+j).style.visibility="hidden";
956 else
957 document.getElementById("OVER_OBJ_"+i+"_"+j).style.visibility="visible";
958
959 if(mapobj[i+rx][j+ry] <= -10000)
960 document.images["OBJ_"+i+"_"+j].src=cacheloader+"monsters/monster_"+(-mapobj[i+rx][j+ry])+"_s.png";
961 else if(mapobj[i+rx][j+ry] < 0)
962 document.images["OBJ_"+i+"_"+j].src=loader+"monsters/monster_"+(-mapobj[i+rx][j+ry])+"_s.gif";
963 else
964 document.images["OBJ_"+i+"_"+j].src=loader+tileset+"objects/"+mapobj[i+rx][j+ry]+".gif";
965 }
966 }
967
968
969 document.getElementById("OVER_OBJ_"+ux+"_"+uy).style.visibility="visible";
970 if((invisible > 0 || invisible == -100) && map[x][y] >= 52 && map[x][y] <= 64) // Water
971 document.images["OBJ_"+ux+"_"+uy].src=cacheloader+"players/"+boattype+"boat_0_"+playerdir+".gif";
972 else if(invisible > 0 || invisible == -100)
973 document.images["OBJ_"+ux+"_"+uy].src=cacheloader+"players/player_0_"+playerdir+".gif";
974 else if(map[x][y] >= 52 && map[x][y] <= 64) // Water
975 document.images["OBJ_"+ux+"_"+uy].src=cacheloader+"players/"+boattype+"boat_"+iconid+"_"+playerdir+".gif";
976 else
977 document.images["OBJ_"+ux+"_"+uy].src=cacheloader+"players/player_"+iconid+"_"+playerdir+".gif";
978 }
979 function RPGKeyPress(e)
980 {
981 key=e.keyCode;
982 if(e.keyCode == 0 && e.which != null)
983 key=String.fromCharCode(e.which);
984 else if(e.keyCode > 60)
985 key=String.fromCharCode(e.keyCode);
986 execKey(key);
987 }
988
989 function execKey(key)
990 {
991 if(disablemove == true || inmapdialog == true)
992 return;
993
994 prevx=x;
995 prevy=y;
996
997 switch(key)
998 {
999 case 56:
1000 case 38:
1001 case '8':
1002 case 'w':
1003 case 'W':
1004 case 'z':
1005 case 'Z':
1006 GoUp();
1007 break;
1008 case 'a':
1009 case 'A':
1010 case 'q':
1011 case 'Q':
1012 case '4':
1013 case 52:
1014 case 37:
1015 GoLeft();
1016 break;
1017 case 'd':
1018 case 'D':
1019 case '6':
1020 case 54:
1021 case 39:
1022 GoRight();
1023 break;
1024 case 'x':
1025 case 'X':
1026 case '2':
1027 case 40:
1028 case 50:
1029 GoDown();
1030 break;
1031 }
1032 Display();
1033 if((comedir == 0 && y == 0 && y == prevy) || (comedir == 1 && x == 0 && x == prevx) || (comedir == 2 && x == 98 && x == prevx) || (comedir == 3 && y == 98 && y == prevy))
1034 CheckLinks(false);
1035 else if(prevx != x || prevy != y)
1036 CheckLinks(true);
1037 }
1038
1039 function str2nb(str,pos)
1040 {
1041 return (str.charCodeAt(pos)-97)*26+(str.charCodeAt(pos+1)-97);
1042 }
1043
1044 function nb2str(nb)
1045 {
1046 return String.fromCharCode(Math.floor(nb/26)+97,(nb%26)+97);
1047 }
1048
1049 function store_monsters()
1050 {
1051 str="";
1052 for(var i=0;i < 100;i++)
1053 for(var j=0;j < 100;j++)
1054 if(mapobj[i][j] < 0)
1055 str=str+nb2str(i)+nb2str(j)+nb2str(Math.floor(-mapobj[i][j]/600))+nb2str((-mapobj[i][j])%600);
1056 document.cookie="monsters="+nb2str(Math.floor(Math.abs(loc)/600))+nb2str(Math.abs(loc)%600)+str;
1057 }
1058
1059 function known_monster(c)
1060 {
1061 for(var i=0;i < monsters.length;i++)
1062 if(monsterid[i] == c)
1063 return true;
1064 return false;
1065 }
1066
1067 function restore_monsters()
1068 {
1069 str=getCookie("monsters");
1070 if(str == null)
1071 return false;
1072 oldloc=str2nb(str,0)*600+str2nb(str,2);
1073 if(oldloc != Math.abs(loc))
1074 return false;
1075 for(var i=4;i < str.length;i+=8)
1076 {
1077 a=str2nb(str,i);
1078 b=str2nb(str,i+2);
1079 c=str2nb(str,i+4)*600+str2nb(str,i+6);
1080
1081 if(mapobj[a][b] != 0 || check_walkable_map(map[a][b],false) == false || !known_monster(c))// This location is not valid... cleanup the mess and say no :-)
1082 {
1083 for(var j=0;j != 100;j++)
1084 for(var k=0;k != 100;k++)
1085 if(mapobj[j][k] < 0)
1086 mapobj[j][k] == 0;
1087 return false;
1088 }
1089 mapobj[a][b]=-c;
1090 }
1091 return true;
1092 }
1093
1094 function store_pos()
1095 {
1096 var http;
1097 var url;
1098
1099 if(needtostoremonsters == true)
1100 store_monsters();
1101 else
1102 document.cookie="monsters=";
1103
1104 if(needtostore == false)
1105 return;
1106
1107 try
1108 {
1109 http = new XMLHttpRequest();
1110 }
1111 catch (e)
1112 {
1113 try
1114 {
1115 http = new ActiveXObject("Microsoft.XMLHTTP");
1116 }
1117 catch (e2)
1118 {
1119 http=false;
1120 }
1121 }
1122 if(!http)
1123 {
1124 return;
1125 }
1126 if(invisible != -100)
1127 url = 'game.php?ACTION=STORE&LOC='+loc+'&X='+x+'&Y='+y+"&INVISIBILITY="+invisible;
1128 else
1129 url = 'game.php?ACTION=STORE&LOC='+loc+'&X='+x+'&Y='+y+"&INVISIBILITY=0";
1130 http.open("GET", url);
1131 http.onreadystatechange = function ()
1132 {
1133 if (http.readyState==4)
1134 {
1135 ok=true;
1136 }
1137 }
1138
1139 http.send(null);
1140 }
1141
1142 function handle_sickness()
1143 {
1144 if(invisible > 0)
1145 {
1146 invisible--;
1147 if(invisible == 0)
1148 {
1149 harverst("LOSTINVISIBLE",x,y);
1150 }
1151 }
1152
1153 if(sickness == 0)
1154 return;
1155 nbsteps++;
1156 if(nbsteps > sickness)
1157 {
1158 hp--;
1159 change_hp();
1160 if(hp <= 0)
1161 {
1162 needtostore=false;
1163 //document.location="game.php?ACTION=DIE";
1164 document.forms["COMM"].ACTION.value='DIE';
1165 disable_move();
1166 needtostore=false;
1167 document.forms["COMM"].submit();
1168 }
1169 else
1170 harverst("SICKNESS",x,y);
1171 nbsteps=0;
1172 }
1173 }
1174
1175 function harverst(what,a,b)
1176 {
1177 var http;
1178 var url;
1179
1180 disablemove=true;
1181 msgwin=document.getElementById("MESSAGES");
1182 msgwin.style.backgroundColor="#FFA0A0";
1183 msgwin.innerHTML="<B>Message window:</B><BR><BR>\nWaiting for an answer...";
1184
1185 try
1186 {
1187 http = new XMLHttpRequest();
1188 }
1189 catch (e)
1190 {
1191 try
1192 {
1193 http = new ActiveXObject("Microsoft.XMLHTTP");
1194 }
1195 catch (e2)
1196 {
1197 http=false;
1198 }
1199 }
1200 if(!http)
1201 {
1202 return;
1203 }
1204 if(timeID != 0)
1205 clearTimeout(timeID);
1206 url = 'game.php?ACTION='+what+'&LOC='+loc+'&X='+a+'&Y='+b;
1207 http.open("GET", url);
1208 http.onreadystatechange = function ()
1209 {
1210 if (http.readyState==4)
1211 {
1212 if(http.responseText.substring(0,13) == "##RELOAD PAGE")
1213 {
1214 alert(http.responseText.substring(14));
1215 document.location='game.php';
1216 }
1217 else
1218 {
1219 disablemove=false;
1220 Display();
1221 msgwin=document.getElementById("MESSAGES");
1222 msgwin.innerHTML="<B>Message window:</B><BR><BR>\n"+http.responseText;
1223 msgwin.style.backgroundColor="#E0E0E0";
1224 timeID=setTimeout("move_monsters()",700);
1225 }
1226 }
1227 }
1228
1229 http.send(null);
1230 }
1231
1232 function normal_message_color()
1233 {
1234 msgwin=document.getElementById("MESSAGES");
1235 msgwin.style.backgroundColor="#E0E0E0";
1236 }
1237
1238 function display_message(msg)
1239 {
1240 msgwin=document.getElementById("MESSAGES");
1241 msgwin.innerHTML="<B>Message window:</B><BR><BR>\n"+msg;
1242 msgwin.style.backgroundColor="#FFA0A0";
1243 setTimeout("normal_message_color()",250);
1244 }
1245
1246 function link_to(q)
1247 {
1248 document.forms["COMM"].ACTION.value=q;
1249 document.forms["COMM"].X.value=x;
1250 document.forms["COMM"].Y.value=y;
1251 if(invisible != -100)
1252 document.forms["COMM"].INVISIBILITY.value=invisible;
1253 else
1254 document.forms["COMM"].INVISIBILITY.value=0;
1255 disable_move();
1256 needtostore=false;
1257 document.forms["COMM"].submit();
1258 return false;
1259 }
1260
1261 function kDown(e)
1262 {
1263 e = e?e:event;
1264 if(disablemove)
1265 return;
1266 RPGKeyPress(e);
1267
1268 // IE
1269 try
1270 {
1271 e.cancelBubble = true;
1272 e.returnValue = false;
1273 }
1274 catch(er)
1275 {
1276 }
1277 // Firefox
1278 try
1279 {
1280 e.preventDefault();
1281 e.stopPropagation();
1282 }
1283 catch(er)
1284 {
1285 }
1286 return false;
1287 }
1288
1289 function kUp(e)
1290 {
1291 e = e?e:event;
1292
1293 // IE
1294 try
1295 {
1296 e.cancelBubble = true;
1297 e.returnValue = false;
1298 }
1299 catch(er)
1300 {
1301 }
1302 // Firefox
1303 try
1304 {
1305 e.preventDefault();
1306 e.stopPropagation();
1307 }
1308 catch(er)
1309 {
1310 }
1311 return false;
1312 }
1313
1314 function kPress(e)
1315 {
1316 // IE
1317 try
1318 {
1319 e.cancelBubble = true;
1320 e.returnValue = false;
1321 }
1322 catch(er)
1323 {
1324 }
1325 // Firefox
1326 try
1327 {
1328 e.preventDefault();
1329 e.stopPropagation();
1330 }
1331 catch(er)
1332 {
1333 }
1334 }
1335
1336 function init()
1337 {
1338 if(isinit == true)
1339 return;
1340
1341 isinit=true;
1342
1343 if (!document.addEventListener && document.attachEvent) {
1344 document.addEventListener = function (t, f) {
1345 document.attachEvent("on"+ t, f);
1346 };
1347 document.removeEventListener = function (t, f) {
1348 document.detachEvent("on"+ t, f);
1349 };
1350 }
1351 if (typeof kDown == "function") document.addEventListener("keydown", kDown, false);
1352 if (typeof kUp == "function") document.addEventListener("keyup", kUp, false);
1353 document.onkeypress=kPress;
1354 document.onclick=null;
1355 }
FUNC_DATA={
'execkey': ['execkey', '', [['locations_modules/2dmap','map_script.js',989]], 5],
'check_walkable_obj': ['check_walkable_obj', '', [['locations_modules/2dmap','map_script.js',403]], 4],
'goright': ['goright', '', [['locations_modules/2dmap','map_script.js',770],['admin_tools/map_editor','map_editor.php',664]], 1],
'store_monsters': ['store_monsters', '', [['locations_modules/2dmap','map_script.js',1049]], 1],
'display_message': ['display_message', '', [['locations_modules/2dmap','map_script.js',1238]], 5],
'add_map_dialog': ['add_map_dialog', '', [['locations_modules/2dmap','map_script.js',23]], 1],
'checklinks': ['checklinks', '', [['locations_modules/2dmap','map_script.js',797]], 2],
'kdown': ['kdown', '', [['locations_modules/2dmap','map_script.js',1261],['admin_tools/object_editor','object_editor.php',465]], 0],
'display': ['display', '', [['locations_modules/2dmap','map_script.js',897],['admin_tools/map_editor','map_editor.php',830]], 20],
'init': ['init', '', [['locations_modules/2dmap','map_script.js',1336],['admin_tools/object_editor','object_editor.php',958]], 2],
'goleft': ['goleft', '', [['locations_modules/2dmap','map_script.js',742],['admin_tools/map_editor','map_editor.php',656]], 1],
'harverst': ['harverst', '', [['locations_modules/2dmap','map_script.js',1175]], 14],
'godown': ['godown', '', [['locations_modules/2dmap','map_script.js',715],['admin_tools/map_editor','map_editor.php',648]], 1],
'restore_monsters': ['restore_monsters', '', [['locations_modules/2dmap','map_script.js',1067]], 1],
'move_monsters': ['move_monsters', '', [['locations_modules/2dmap','map_script.js',239]], 6],
'map_dialog': ['map_dialog', '', [['locations_modules/2dmap','map_script.js',16]], 2],
'store_pos': ['store_pos', '', [['locations_modules/2dmap','map_script.js',1094]], 1],
'handle_sickness': ['handle_sickness', '', [['locations_modules/2dmap','map_script.js',1142]], 4],
'getcookie': ['getcookie', '', [['locations_modules/2dmap','map_script.js',61],['player_tools/inventory','inventory.js',559]], 2],
'init_map': ['init_map', '', [['locations_modules/2dmap','map_script.js',122]], 1],
'paint_monsters': ['paint_monsters', '', [['locations_modules/2dmap','map_script.js',222]], 4],
'check_walkable_map': ['check_walkable_map', '', [['locations_modules/2dmap','map_script.js',389],['libs','map_util.php',156]], 21],
'nb2str': ['nb2str', '', [['locations_modules/2dmap','map_script.js',1044]], 6],
'draw_dialogs': ['draw_dialogs', '', [['locations_modules/2dmap','map_script.js',28]], 1],
'goup': ['goup', '', [['locations_modules/2dmap','map_script.js',686],['admin_tools/map_editor','map_editor.php',640]], 1],
'str2nb': ['str2nb', '', [['locations_modules/2dmap','map_script.js',1039]], 6],
'check_map': ['check_map', '', [['locations_modules/2dmap','map_script.js',368]], 4],
'change_hp': ['change_hp', '', [['locations_modules/2dmap','map_script.js',83],['player_tools/quick_inventory','quick_inventory.php',42]], 5],
'rpgkeypress': ['rpgkeypress', '', [['locations_modules/2dmap','map_script.js',979],['admin_tools/map_editor','object_list.php',67],['admin_tools/map_editor','tile_list.php',61],['admin_tools/map_editor','map_editor.php',857]], 6],
'disable_move': ['disable_move', '', [['locations_modules/2dmap','map_script.js',96]], 21],
'kup': ['kup', '', [['locations_modules/2dmap','map_script.js',1289],['admin_tools/object_editor','object_editor.php',497]], 0],
'known_monster': ['known_monster', '', [['locations_modules/2dmap','map_script.js',1059]], 1],
'kpress': ['kpress', '', [['locations_modules/2dmap','map_script.js',1314],['admin_tools/object_editor','object_editor.php',400]], 0],
'link_to': ['link_to', '', [['locations_modules/2dmap','map_script.js',1246]], 4],
'normal_message_color': ['normal_message_color', '', [['locations_modules/2dmap','map_script.js',1232]], 1],
'sqrt': ['sqrt', '', [], 1],
'floor': ['floor', '', [], 45],
'abs': ['abs', '', [], 17],
'ceil': ['ceil', '', [], 66],
'round': ['round', '', [], 19]};
CLASS_DATA={
};
CONST_DATA={
};
titleDescriptionBody
titleDescriptionBody
titleDescriptionBody
titleBody
Generated: Sun Jul 8 18:11:25 2007
Cross-referenced by PHPXref 0.7
Wyszukiwarka
Podobne podstrony:
map script js sourcemap script jshelp?llon js sourcehelp?llon js sourceMap jsMap jssource30Util jsTD 53x INPA ScriptMatrix3?pp sourceThread?pp sourcearm biquad ?scade ?1 ?st q31? sourcearm conv ?2? sourcearm mat mult q15? sourcebrowse mapResource 8inl sourcewięcej podobnych podstron