forked from RSamaium/RPG-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpg-alpha-2.min.js
730 lines (730 loc) · 109 KB
/
rpg-alpha-2.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/*!
* RPG JavaScript Library Alpha 2.0
* http://rpgjs.com
*
* Copyright 2011, Samuel Ronce
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Includes Easel.js (modified)
* http://easeljs.com
* Copyright 2011, Grant Skinner
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Date: May 08, 2011
*/
(function(window){SpriteSheetUtils=function(){throw"SpriteSheetUtils cannot be instantiated";}
SpriteSheetUtils._workingCanvas=document.createElement("canvas");SpriteSheetUtils._workingContext=SpriteSheetUtils._workingCanvas.getContext("2d");SpriteSheetUtils.flip=function(spriteSheet,flipData){var image=spriteSheet.image;var frameData=spriteSheet.frameData;var frameWidth=spriteSheet.frameWidth;var frameHeight=spriteSheet.frameHeight;var cols=image.width/frameWidth|0;var rows=image.height/frameHeight|0;var ttlFrames=cols*rows;var frData={};var data;for(var n in frameData){data=frameData[n];if(data instanceof Array){data=data.slice(0);}
frData[n]=data;}
var map=[];var frCount=0;var i=0;for(n in flipData){var fd=flipData[n];data=frameData[fd[0]];if(data==null){continue;}
if(data instanceof Array){var start=data[0];var end=data[1];if(end==null){end=start;}}else{start=end=data;}
map[i]=n;map[i+1]=start;map[i+2]=end;frCount+=end-start+1;i+=4;}
var canvas=SpriteSheetUtils._workingCanvas;canvas.width=image.width;canvas.height=Math.ceil(rows+frCount/cols)*frameHeight;var ctx=SpriteSheetUtils._workingContext;ctx.drawImage(image,0,0,cols*frameWidth,rows*frameHeight,0,0,cols*frameWidth,rows*frameHeight);var frame=ttlFrames-1;for(i=0;i<map.length;i+=4){n=map[i];start=map[i+1];end=map[i+2];fd=flipData[n];var flipH=fd[1]?-1:1;var flipV=fd[2]?-1:1;var offH=flipH==-1?frameWidth:0;var offV=flipV==-1?frameHeight:0;for(var j=start;j<=end;j++){frame++;ctx.save();ctx.translate((frame%cols)*frameWidth+offH,(frame/cols|0)*frameHeight+offV);ctx.scale(flipH,flipV);ctx.drawImage(image,(j%cols)*frameWidth,(j/cols|0)*frameHeight,frameWidth,frameHeight,0,0,frameWidth,frameHeight);ctx.restore();}
frData[n]=[frame-(end-start),frame,fd[3]];}
var img=new Image();img.src=canvas.toDataURL("image/png");return new SpriteSheet((img.width>0)?img:canvas,frameWidth,frameHeight,frData);}
SpriteSheetUtils.frameDataToString=function(frameData){var str="";var max=0;var min=0;var count=0;var data,next;for(var n in frameData){count++;data=frameData[n];if(data instanceof Array){var start=data[0];var end=data[1];if(end==null){end=start;}
next=data[2];if(next==null){next=n;}}else{start=end=data;next=n;}
str+="\n\t"+n+", start="+start+", end="+end+", next="+next;if(next==false){str+=" (stop)";}
else if(next==n){str+=" (loop)";}
if(end>max){max=end;}
if(start<min){min=start;}}
str=count+" sequences, min="+min+", max="+max+str;return str;}
SpriteSheetUtils.extractFrame=function(spriteSheet,frame){var image=spriteSheet.image;var frameWidth=spriteSheet.frameWidth;var frameHeight=spriteSheet.frameHeight;var cols=image.width/frameWidth|0;if(isNaN(frame)){var data=spriteSheet.frameData[frame];if(data instanceof Array){frame=data[0];}
else{frame=data;}}
var canvas=SpriteSheetUtils._workingCanvas;canvas.width=frameWidth;canvas.height=frameHeight;SpriteSheetUtils._workingContext.drawImage(image,(frame%cols)*frameWidth,(frame/cols|0)*frameHeight,frameWidth,frameHeight,0,0,frameWidth,frameHeight);var img=new Image();img.src=canvas.toDataURL("image/png");return img;}
window.SpriteSheetUtils=SpriteSheetUtils;}(window));(function(window){Ticker=function(){throw"Ticker cannot be instantiated.";}
Ticker._listeners=[];Ticker._pauseable=[];Ticker._paused=false;Ticker._inited=false;Ticker._startTime=0;Ticker._pausedTime=0;Ticker._ticks=0;Ticker._pausedTickers=0;Ticker._interval=50;Ticker._intervalID=null;Ticker._lastTime=0;Ticker._times=[];Ticker.addListener=function(o,pauseable){if(!Ticker._inited){Ticker._inited=true;Ticker.setInterval(Ticker._interval);}
this.removeListener(o);Ticker._pauseable[Ticker._listeners.length]=(pauseable==null)?true:pauseable;Ticker._listeners.push(o);}
Ticker.removeListener=function(o){if(Ticker._listeners==null){return;}
var index=Ticker._listeners.indexOf(o);if(index!=-1){Ticker._listeners.splice(index,1);Ticker._pauseable.splice(index,1);}}
Ticker.removeAllListeners=function(){Ticker._listeners=[];Ticker._pauseable=[];}
Ticker.setInterval=function(interval){if(Ticker._intervalID!=null){clearInterval(Ticker._intervalID);}
Ticker._lastTime=Ticker._getTime();Ticker._interval=interval;Ticker._intervalID=setInterval(Ticker._tick,interval);}
Ticker.getInterval=function(){return Ticker._interval;}
Ticker.getFPS=function(){return 1000/Ticker._interval;}
Ticker.setFPS=function(value){Ticker.setInterval(1000/value);}
Ticker.getMeasuredFPS=function(ticks){if(Ticker._times.length<2){return-1;}
if(ticks==null){ticks=Ticker.getFPS()>>1;}
ticks=Math.min(Ticker._times.length-1,ticks);return 1000/((Ticker._times[0]-Ticker._times[ticks])/ticks);}
Ticker.setPaused=function(value){Ticker._paused=value;}
Ticker.getPaused=function(){return Ticker._paused;}
Ticker.getTime=function(pauseable){return Ticker._getTime()-Ticker._startTime-(pauseable?Ticker._pausedTime:0);}
Ticker.getTicks=function(pauseable){return Ticker._ticks-(pauseable?Ticker._pausedTickers:0);}
Ticker._tick=function(){Ticker._ticks++;var time=Ticker.getTime(false);var elapsedTime=time-Ticker._lastTime;var paused=Ticker._paused;if(paused){Ticker._pausedTickers++;Ticker._pausedTime+=elapsedTime;}
Ticker._lastTime=time;var pauseable=Ticker._pauseable;var listeners=Ticker._listeners;var l=listeners?listeners.length:0;for(var i=0;i<l;i++){var p=pauseable[i];var listener=listeners[i];if(listener==null||(paused&&p)||listener.tick==null){continue;}
listener.tick(elapsedTime);}
Ticker._times.unshift(time);if(Ticker._times.length>100){Ticker._times.pop();}}
Ticker._getTime=function(){return new Date().getTime();}
Ticker._startTime=Ticker._getTime();window.Ticker=Ticker;}(window));(function(window){UID=function(){throw"UID cannot be instantiated";}
UID._nextID=0;UID.get=function(){return UID._nextID++;}
window.UID=UID;}(window));(function(window){MouseEvent=function(type,stageX,stageY){this.initialize(type,stageX,stageY);}
var p=MouseEvent.prototype;p.stageX=0;p.stageY=0;p.type=null;p.onMouseMove=null;p.onMouseUp=null;p.initialize=function(type,stageX,stageY){this.type=type;this.stageX=stageX;this.stageY=stageY;}
p.clone=function(){return new MouseEvent(this.type,this.stageX,this.stageY);}
p.toString=function(){return"[MouseEvent (type="+this.type+" stageX="+this.stageX+" stageY="+this.stageY+")]";}
window.MouseEvent=MouseEvent;}(window));(function(window){Matrix2D=function(a,b,c,d,tx,ty){this.initialize(a,b,c,d,tx,ty);}
var p=Matrix2D.prototype;Matrix2D.identity=null;Matrix2D.DEG_TO_RAD=Math.PI/180;p.a=1;p.b=0;p.c=0;p.d=1;p.tx=0;p.ty=0;p.alpha=1;p.shadow=null;p.compositeOperation=null;p.initialize=function(a,b,c,d,tx,ty){if(a!=null){this.a=a;}
if(b!=null){this.b=b;}
if(c!=null){this.c=c;}
if(d!=null){this.d=d;}
if(tx!=null){this.tx=tx;}
if(ty!=null){this.ty=ty;}}
p.prepend=function(a,b,c,d,tx,ty){var tx1=this.tx;if(a!=1||b!=0||c!=0||d!=1){var a1=this.a;var c1=this.c;this.a=a1*a+this.b*c;this.b=a1*b+this.b*d;this.c=c1*a+this.d*c;this.d=c1*b+this.d*d;}
this.tx=tx1*a+this.ty*c+tx;this.ty=tx1*b+this.ty*d+ty;}
p.append=function(a,b,c,d,tx,ty){var a1=this.a;var b1=this.b;var c1=this.c;var d1=this.d;this.a=a*a1+b*c1;this.b=a*b1+b*d1;this.c=c*a1+d*c1;this.d=c*b1+d*d1;this.tx=tx*a1+ty*c1+this.tx;this.ty=tx*b1+ty*d1+this.ty;}
p.prependMatrix=function(matrix){this.prepend(matrix.a,matrix.b,matrix.c,matrix.d,matrix.tx,matrix.ty);this.prependProperties(matrix.alpha,matrix.shadow,matrix.compositeOperation);}
p.appendMatrix=function(matrix){this.append(matrix.a,matrix.b,matrix.c,matrix.d,matrix.tx,matrix.ty);this.appendProperties(matrix.alpha,matrix.shadow,matrix.compositeOperation);}
p.prependTransform=function(x,y,scaleX,scaleY,rotation,skewX,skewY,regX,regY){if(rotation%360){var r=rotation*Matrix2D.DEG_TO_RAD;var cos=Math.cos(r);var sin=Math.sin(r);}else{cos=1;sin=0;}
if(regX||regY){this.tx-=regX;this.ty-=regY;}
if(skewX||skewY){skewX*=Matrix2D.DEG_TO_RAD;skewY*=Matrix2D.DEG_TO_RAD;this.prepend(cos*scaleX,sin*scaleX,-sin*scaleY,cos*scaleY,0,0);this.prepend(Math.cos(skewY),Math.sin(skewY),-Math.sin(skewX),Math.cos(skewX),x,y);}else{this.prepend(cos*scaleX,sin*scaleX,-sin*scaleY,cos*scaleY,x,y);}}
p.appendTransform=function(x,y,scaleX,scaleY,rotation,skewX,skewY,regX,regY){if(rotation%360){var r=rotation*Matrix2D.DEG_TO_RAD;var cos=Math.cos(r);var sin=Math.sin(r);}else{cos=1;sin=0;}
if(skewX||skewY){skewX*=Matrix2D.DEG_TO_RAD;skewY*=Matrix2D.DEG_TO_RAD;this.append(Math.cos(skewY),Math.sin(skewY),-Math.sin(skewX),Math.cos(skewX),x,y);this.append(cos*scaleX,sin*scaleX,-sin*scaleY,cos*scaleY,0,0);}else{this.append(cos*scaleX,sin*scaleX,-sin*scaleY,cos*scaleY,x,y);}
if(regX||regY){this.tx-=regX*this.a+regY*this.c;this.ty-=regX*this.b+regY*this.d;}}
p.rotate=function(angle){var cos=Math.cos(angle);var sin=Math.sin(angle);var a1=this.a;var c1=this.c;var tx1=this.tx;this.a=a1*cos-this.b*sin;this.b=a1*sin+this.b*cos;this.c=c1*cos-this.d*sin;this.d=c1*sin+this.d*cos;this.tx=tx1*cos-this.ty*sin;this.ty=tx1*sin+this.ty*cos;}
p.skew=function(skewX,skewY){skewX=skewX*Matrix2D.DEG_TO_RAD;skewY=skewY*Matrix2D.DEG_TO_RAD;this.append(Math.cos(skewY),Math.sin(skewY),-Math.sin(skewX),Math.cos(skewX),0,0);}
p.scale=function(x,y){this.a*=x;this.d*=y;this.tx*=x;this.ty*=y;}
p.translate=function(x,y){this.tx+=x;this.ty+=y;}
p.identity=function(){this.alpha=this.a=this.d=1;this.b=this.c=this.tx=this.ty=0;this.shadow=this.compositeOperation=null;}
p.invert=function(){var a1=this.a;var b1=this.b;var c1=this.c;var d1=this.d;var tx1=this.tx;var n=a1*d1-b1*c1;this.a=d1/n;this.b=-b1/n;this.c=-c1/n;this.d=a1/n;this.tx=(c1*this.ty-d1*tx1)/n;this.ty=-(a1*this.ty-b1*tx1)/n;}
p.decompose=function(target){if(target==null){target={};}
target.x=this.tx;target.y=this.ty;target.scaleX=Math.sqrt(this.a*this.a+this.b*this.b);target.scaleY=Math.sqrt(this.c*this.c+this.d*this.d);var skewX=Math.atan2(-this.c,this.d);var skewY=Math.atan2(this.b,this.a);if(skewX==skewY){target.rotation=skewY/Matrix2D.DEG_TO_RAD;if(this.a<0&&this.d>=0){target.rotation+=(target.rotation<=0)?180:-180;}
target.skewX=target.skewY=0;}else{target.skewX=skewX/Matrix2D.DEG_TO_RAD;target.skewY=skewY/Matrix2D.DEG_TO_RAD;}
return target;}
p.appendProperties=function(alpha,shadow,compositeOperation){this.alpha*=alpha;this.shadow=shadow||this.shadow;this.compositeOperation=compositeOperation||this.compositeOperation;}
p.prependProperties=function(alpha,shadow,compositeOperation){this.alpha*=alpha;this.shadow=this.shadow||shadow;this.compositeOperation=this.compositeOperation||compositeOperation;}
p.clone=function(){var mtx=new Matrix2D(this.a,this.b,this.c,this.d,this.tx,this.ty);mtx.shadow=this.shadow;mtx.alpha=this.alpha;mtx.compositeOperation=this.compositeOperation;return mtx;}
p.toString=function(){return"[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]";}
Matrix2D.identity=new Matrix2D(1,0,0,1,0,0);window.Matrix2D=Matrix2D;}(window));(function(window){Point=function(x,y){this.initialize(x,y);}
var p=Point.prototype;p.x=0;p.y=0;p.initialize=function(x,y){this.x=(x==null?0:x);this.y=(y==null?0:y);}
p.clone=function(){return new Point(this.x,this.y);}
p.toString=function(){return"[Point (x="+this.x+" y="+this.y+")]";}
window.Point=Point;}(window));(function(window){Rectangle=function(x,y,width,height){this.initialize(x,y,width,height);}
var p=Rectangle.prototype;p.x=0;p.y=0;p.width=0;p.height=0;p.initialize=function(x,y,width,height){this.x=(x==null?0:x);this.y=(y==null?0:y);this.width=(width==null?0:width);this.height=(height==null?0:height);}
p.clone=function(){return new Rectangle(this.x,this.y,this.width,this.height);}
p.toString=function(){return"[Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+")]";}
window.Rectangle=Rectangle;}(window));(function(window){DisplayObject=function(){this.initialize();}
var p=DisplayObject.prototype;DisplayObject.suppressCrossDomainErrors=false;DisplayObject._hitTestCanvas=document.createElement("canvas");DisplayObject._hitTestCanvas.width=DisplayObject._hitTestCanvas.height=1;DisplayObject._hitTestContext=DisplayObject._hitTestCanvas.getContext("2d");DisplayObject._workingMatrix=new Matrix2D();p.alpha=1;p.cacheCanvas=null;p.id=-1;p.mouseEnabled=true;p.name=null;p.parent=null;p.regX=0;p.regY=0;p.rotation=0;p.scaleX=1;p.scaleY=1;p.skewX=0;p.skewY=0;p.shadow=null;p.visible=true;p.x=0;p.y=0;p.compositeOperation=null;p.snapToPixel=false;p.onPress=null;p.onClick=null;p.onMouseOver=null;p.onMouseOut=null;p._cacheOffsetX=0;p._cacheOffsetY=0;p._cacheDraw=false;p._activeContext=null;p._restoreContext=false;p._revertShadow=false;p._revertX=0;p._revertY=0;p._revertAlpha=1;p.initialize=function(){this.id=UID.get();this.children=[];}
p.isVisible=function(){return this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0;}
p.draw=function(ctx,ignoreCache){if(ignoreCache||!this.cacheCanvas){return false;}
ctx.translate(this._cacheOffsetX,this._cacheOffsetY);ctx.drawImage(this.cacheCanvas,0,0);ctx.translate(-this._cacheOffsetX,-this._cacheOffsetY);return true;}
p.cache=function(x,y,width,height){var ctx;if(this.cacheCanvas==null){this.cacheCanvas=document.createElement("canvas");}
ctx=this.cacheCanvas.getContext("2d");this.cacheCanvas.width=width;this.cacheCanvas.height=height;ctx.setTransform(1,0,0,1,-x,-y);ctx.clearRect(0,0,width+1,height+1);this.draw(ctx,true);this._cacheOffsetX=x;this._cacheOffsetY=y;}
p.updateCache=function(compositeOperation){if(this.cacheCanvas==null){throw"cache() must be called before updateCache()";}
var ctx=this.cacheCanvas.getContext("2d");ctx.setTransform(1,0,0,1,-this._cacheOffsetX,-this._cacheOffsetY);if(!compositeOperation){ctx.clearRect(0,0,this.cacheCanvas.width+1,this.cacheCanvas.height+1);}
else{ctx.globalCompositeOperation=compositeOperation;}
this.draw(ctx,true);if(compositeOperation){ctx.globalCompositeOperation="source-over";}}
p.uncache=function(){this.cacheCanvas=null;this.cacheOffsetX=this.cacheOffsetY=0;}
p.getStage=function(){var o=this;while(o.parent){o=o.parent;}
if(o instanceof Stage){return o;}
return null;}
p.localToGlobal=function(x,y){var mtx=this.getConcatenatedMatrix();if(mtx==null){return null;}
mtx.append(1,0,0,1,x,y);return new Point(mtx.tx,mtx.ty);}
p.globalToLocal=function(x,y){var mtx=this.getConcatenatedMatrix();if(mtx==null){return null;}
mtx.invert();mtx.append(1,0,0,1,x,y);return new Point(mtx.tx,mtx.ty);}
p.localToLocal=function(x,y,target){var pt=this.localToGlobal(x,y);return target.globalToLocal(pt.x,pt.y);}
p.getConcatenatedMatrix=function(mtx){if(mtx){mtx.identity();}
else{mtx=new Matrix2D();}
var target=this;while(target!=null){mtx.prependTransform(target.x,target.y,target.scaleX,target.scaleY,target.rotation,target.skewX,target.skewY,target.regX,target.regY);mtx.prependProperties(target.alpha,target.shadow,target.compositeOperation);target=target.parent;}
return mtx;}
p.hitTest=function(x,y){var ctx=DisplayObject._hitTestContext;var canvas=DisplayObject._hitTestCanvas;ctx.setTransform(1,0,0,1,-x,-y);this.draw(ctx);var hit=this._testHit(ctx);canvas.width=0;canvas.width=1;return hit;}
p.clone=function(){var o=new DisplayObject();this.cloneProps(o);return o;}
p.toString=function(){return"[DisplayObject (name="+this.name+")]";}
p.cloneProps=function(o){o.alpha=this.alpha;o.name=this.name;o.regX=this.regX;o.regY=this.regY;o.rotation=this.rotation;o.scaleX=this.scaleX;o.scaleY=this.scaleY;o.shadow=this.shadow;o.skewX=this.skewX;o.skewY=this.skewY;o.visible=this.visible;o.x=this.x;o.y=this.y;o.mouseEnabled=this.mouseEnabled;o.compositeOperation=this.compositeOperation;}
p.applyShadow=function(ctx,shadow){shadow=shadow||Shadow.identity;ctx.shadowColor=shadow.color;ctx.shadowOffsetX=shadow.offsetX;ctx.shadowOffsetY=shadow.offsetY;ctx.shadowBlur=shadow.blur;}
p._testHit=function(ctx){try{var hit=ctx.getImageData(0,0,1,1).data[3]>1;}catch(e){if(!DisplayObject.suppressCrossDomainErrors){throw"An error has occured. This is most likely due to security restrictions on reading canvas pixel "+"data with local or cross-domain images.";}}
return hit;}
window.DisplayObject=DisplayObject;}(window));(function(window){Bitmap=function(image){this.initialize(image);}
var p=Bitmap.prototype=new DisplayObject();p.image=null;p.snapToPixel=true;p.DisplayObject_initialize=p.initialize;p.initialize=function(image){this.DisplayObject_initialize();this.image=image;}
p.isVisible=function(){return this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0&&this.image&&(this.image.complete||this.image.getContext);}
p.DisplayObject_draw=p.draw;p.draw=function(ctx,ignoreCache){if(this.DisplayObject_draw(ctx,ignoreCache)){return true;}
ctx.drawImage(this.image,0,0);return true;}
p.clone=function(){var o=new Bitmap(this.image);this.cloneProps(o);return o;}
p.toString=function(){return"[Bitmap (name="+this.name+")]";}
window.Bitmap=Bitmap;}(window));(function(window){BitmapSequence=function(spriteSheet){this.initialize(spriteSheet);}
var p=BitmapSequence.prototype=new DisplayObject();p.callback=null;p.currentFrame=-1;p.waitFrame=0;p.currentWaitFrame=0;p.arrayFrames;p.arrayFramesPosition=0;p.nbSequenceToPlay=-1;p.nbSequencePlayed=0;p.currentSequence=null;p.currentEndFrame=null;p.currentStartFrame=null;p.nextSequence=null;p.paused=false;p.spriteSheet=null;p.snapToPixel=true;p.DisplayObject_initialize=p.initialize;p.initialize=function(spriteSheet){this.DisplayObject_initialize();this.spriteSheet=spriteSheet;}
p.isVisible=function(){var image=this.spriteSheet?this.spriteSheet.image:null;return this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0&&image&&this.currentFrame>=0&&(image.complete||image.getContext);}
p.DisplayObject_draw=p.draw;p.draw=function(ctx,ignoreCache){if(this.DisplayObject_draw(ctx,ignoreCache)){return true;}
var image=this.spriteSheet.image;var frameWidth=this.spriteSheet.frameWidth;var frameHeight=this.spriteSheet.frameHeight;var cols=image.width/frameWidth|0;var rows=image.height/frameHeight|0;if(this.currentEndFrame!=null){if(this.currentFrame>this.currentEndFrame){this.nbSequencePlayed++;if(this.nextSequence&&(this.nbSequenceToPlay==-1||this.nbSequenceToPlay>this.nbSequencePlayed)){this._goto(this.nextSequence);}else{this.paused=true;this.currentFrame=this.currentEndFrame;this.nbSequencePlayed=0;}
if(this.callback){this.callback(this);}}}else{var ttlFrames=this.spriteSheet.totalFrames||cols*rows;if(this.currentFrame>=ttlFrames){if(this.spriteSheet.loop){this.currentFrame=0;}
else{this.currentFrame=ttlFrames-1;this.paused=true;}
if(this.callback){this.callback(this);}}}
if(this.currentFrame>=0){var col=this.currentFrame%cols;var row=this.currentFrame/cols|0;ctx.drawImage(image,frameWidth*col,frameHeight*row,frameWidth,frameHeight,0,0,frameWidth,frameHeight);}
return true;}
p.tick=function(){if(this.currentFrame==-1&&this.spriteSheet.frameData){this.paused=true;}
if(this.paused){return;}
if(this.currentWaitFrame==this.waitFrame){if(this.arrayFrames){if(this.arrayFramesPosition>=this.arrayFrames.length){this.arrayFramesPosition=0;}
this.currentFrame=this.arrayFrames[this.arrayFramesPosition];this.arrayFramesPosition++;}
else{this.currentFrame++;}
this.currentWaitFrame=0;}
this.currentWaitFrame++;}
p.gotoAndPlay=function(frameOrSequence){this.paused=false;this._goto(frameOrSequence);}
p.gotoAndStop=function(frameOrSequence){this.paused=true;this._goto(frameOrSequence);}
p.clone=function(){var o=new BitmapSequence(this.spriteSheet);this.cloneProps(o);return o;}
p.toString=function(){return"[BitmapSequence (name="+this.name+")]";}
p.DisplayObject_cloneProps=p.cloneProps;p.cloneProps=function(o){this.DisplayObject_cloneProps(o);o.waitFrame=this.waitFrame;o.arrayFrames=this.arrayFrames;o.callback=this.callback;o.currentFrame=this.currentFrame;o.currentStartFrame=this.currentStartFrame;o.currentEndFrame=this.currentEndFrame;o.currentSequence=this.currentSequence;o.nextSequence=this.nextSequence;o.paused=this.paused;o.frameData=this.frameData;}
p._goto=function(frameOrSequence){if(isNaN(frameOrSequence)){if(frameOrSequence==this.currentSequence){this.currentFrame=this.currentStartFrame;return;}
var data=this.spriteSheet.frameData[frameOrSequence];if(data instanceof Array){this.currentFrame=this.currentStartFrame=data[0];this.currentSequence=frameOrSequence;this.currentEndFrame=data[1];if(this.currentEndFrame==null){this.currentEndFrame=this.currentStartFrame;}
if(this.currentEndFrame==null){this.currentEndFrame=this.currentFrame;}
this.nextSequence=data[2];if(this.nextSequence==null){this.nextSequence=this.currentSequence;}
else if(this.nextSequence==false){this.nextSequence=null;}}else{this.currentSequence=this.nextSequence=null;this.currentEndFrame=this.currentFrame=this.currentStartFrame=data;}}else{this.currentSequence=this.nextSequence=this.currentEndFrame=null;this.currentStartFrame=0;this.currentFrame=frameOrSequence;}}
window.BitmapSequence=BitmapSequence;}(window));(function(window){Container=function(){this.initialize();}
var p=Container.prototype=new DisplayObject();p.children=null;p.DisplayObject_initialize=p.initialize;p.initialize=function(){this.DisplayObject_initialize();this.children=[];}
p.isVisible=function(){return this.visible&&this.alpha>0&&this.children.length&&this.scaleX!=0&&this.scaleY!=0;}
p.DisplayObject_draw=p.draw;p.draw=function(ctx,ignoreCache,_mtx){var snap=Stage._snapToPixelEnabled;if(!_mtx){_mtx=new Matrix2D();_mtx.appendProperties(this.alpha,this.shadow,this.compositeOperation);}
if(this.DisplayObject_draw(ctx,ignoreCache)){return true;}
var l=this.children.length;var list=this.children.slice(0);for(var i=0;i<l;i++){var child=list[i];if(child.tick){child.tick();}
if(!child.isVisible()){continue;}
var shadow=false;var mtx=_mtx.clone();mtx.appendTransform(child.x,child.y,child.scaleX,child.scaleY,child.rotation,child.skewX,child.skewY,child.regX,child.regY);mtx.appendProperties(child.alpha,child.shadow,child.compositeOperation);if(!(child instanceof Container)){if(snap&&child.snapToPixel&&mtx.a==1&&mtx.b==0&&mtx.c==0&&mtx.d==1){ctx.setTransform(mtx.a,mtx.b,mtx.c,mtx.d,mtx.tx+0.5|0,mtx.ty+0.5|0);}else{ctx.setTransform(mtx.a,mtx.b,mtx.c,mtx.d,mtx.tx,mtx.ty);}
ctx.globalAlpha=mtx.alpha;ctx.globalCompositeOperation=mtx.compositeOperation||"source-over";if(shadow=mtx.shadow){this.applyShadow(ctx,shadow);}}
child.draw(ctx,false,mtx);if(shadow){this.applyShadow(ctx);}}
return true;}
p.addChild=function(child){var l=arguments.length;if(l>1){for(var i=0;i<l;i++){this.addChild(arguments[i]);}
return arguments[l-1];}
if(child.parent){child.parent.removeChild(child);}
child.parent=this;this.children.push(child);return child;}
p.addChildAt=function(child,index){var l=arguments.length;if(l>2){index=arguments[i-1];for(var i=0;i<l-1;i++){this.addChildAt(arguments[i],index+i);}
return arguments[l-2];}
if(child.parent){child.parent.removeChild(child);}
child.parent=this;this.children.splice(index,0,child);return child;}
p.removeChild=function(child){var l=arguments.length;if(l>1){var good=true;for(var i=0;i<l;i++){good=good&&this.removeChild(arguments[i]);}
return good;}
return this.removeChildAt(this.children.indexOf(child));}
p.removeChildAt=function(index){var l=arguments.length;if(l>1){var a=[];for(var i=0;i<l;i++){a[i]=arguments[i];}
a.sort(function(a,b){return b-a;})
var good=true;for(var i=0;i<l;i++){good=good&&this.removeChildAt(a[i]);}
return good;}
if(index<0||index>this.children.length-1){return false;}
var child=this.children[index];if(child!=null){child.parent=null;}
this.children.splice(index,1);return true;}
p.removeAllChildren=function(){while(this.children.length){this.removeChildAt(0);}}
p.getChildAt=function(index){return this.children[index];}
p.sortChildren=function(sortFunction){this.children.sort(sortFunction);}
p.getChildIndex=function(child){return this.children.indexOf(child);}
p.getNumChildren=function(){return this.children.length;}
p.contains=function(child){while(child){if(child==this){return true;}
child=child.parent;}
return false;}
p.hitTest=function(x,y){return(this.getObjectUnderPoint(x,y)!=null);}
p.getObjectsUnderPoint=function(x,y){var arr=[];var pt=this.localToGlobal(x,y);this._getObjectsUnderPoint(pt.x,pt.y,arr);return arr;}
p.getObjectUnderPoint=function(x,y){var pt=this.localToGlobal(x,y);return this._getObjectsUnderPoint(pt.x,pt.y);}
p.clone=function(recursive){var o=new Container();this.cloneProps(o);if(recursive){var arr=o.children=[];for(var i=0,l=this.children.length;i<l;i++){arr.push(this.children[i].clone(recursive));}}
return o;}
p.toString=function(){return"[Container (name="+this.name+")]";}
p._getObjectsUnderPoint=function(x,y,arr,mouseEvents){var ctx=DisplayObject._hitTestContext;var canvas=DisplayObject._hitTestCanvas;var mtx=DisplayObject._workingMatrix;var hasHandler=(mouseEvents&1&&(this.onPress||this.onClick))||(mouseEvents&2&&(this.onMouseOver||this.onMouseOut));if(this.cacheCanvas){this.getConcatenatedMatrix(mtx);ctx.setTransform(mtx.a,mtx.b,mtx.c,mtx.d,mtx.tx-x,mtx.ty-y);ctx.globalAlpha=mtx.alpha;this.draw(ctx);if(this._testHit(ctx)){canvas.width=0;canvas.width=1;if(hasHandler){return this;}}else{return null;}}
var l=this.children.length;for(var i=l-1;i>=0;i--){var child=this.children[i];if(!child.isVisible()||!child.mouseEnabled){continue;}
if(child instanceof Container){var result;if(hasHandler){result=child._getObjectsUnderPoint(x,y);if(result){return this;}}else{result=child._getObjectsUnderPoint(x,y,arr,mouseEvents);if(!arr&&result){return result;}}}else if(!mouseEvents||hasHandler||(mouseEvents&1&&(child.onPress||child.onClick))||(mouseEvents&2&&(child.onMouseOver||child.onMouseOut))){child.getConcatenatedMatrix(mtx);ctx.setTransform(mtx.a,mtx.b,mtx.c,mtx.d,mtx.tx-x,mtx.ty-y);ctx.globalAlpha=mtx.alpha;child.draw(ctx);if(!this._testHit(ctx)){continue;}
canvas.width=0;canvas.width=1;if(hasHandler){return this;}
else if(arr){arr.push(child);}
else{return child;}}}
return null;}
window.Container=Container;}(window));(function(window){function Command(f,params){this.f=f;this.params=params;}
Command.prototype.exec=function(scope){this.f.apply(scope,this.params);}
Graphics=function(instructions){this.initialize(instructions);}
var p=Graphics.prototype;Graphics.getRGB=function(r,g,b,alpha){if(r!=null&&b==null){alpha=g;b=r&0xFF;g=r>>8&0xFF;r=r>>16&0xFF;}
if(alpha==null){return"rgb("+r+","+g+","+b+")";}else{return"rgba("+r+","+g+","+b+","+alpha+")";}}
Graphics.getHSL=function(hue,saturation,lightness,alpha){if(alpha==null){return"hsl("+(hue%360)+","+saturation+"%,"+lightness+"%)";}else{return"hsla("+(hue%360)+","+saturation+"%,"+lightness+"%,"+alpha+")";}}
Graphics.STROKE_CAPS_MAP=["butt","round","square"];Graphics.STROKE_JOINTS_MAP=["miter","round","bevel"];Graphics._ctx=document.createElement("canvas").getContext("2d");Graphics.beginCmd=new Command(Graphics._ctx.beginPath,[]);Graphics.fillCmd=new Command(Graphics._ctx.fill,[]);Graphics.strokeCmd=new Command(Graphics._ctx.stroke,[]);p._strokeInstructions=null;p._strokeStyleInstructions=null;p._fillInstructions=null;p._instructions=null;p._oldInstructions=null;p._activeInstructions=null;p._active=false;p._dirty=false;p.initialize=function(instructions){this.clear();this._ctx=Graphics._ctx;with(this){eval(instructions);}}
p.draw=function(ctx){if(this._dirty){this._updateInstructions();}
var instr=this._instructions;for(var i=0,l=instr.length;i<l;i++){instr[i].exec(ctx);}}
p.moveTo=function(x,y){this._activeInstructions.push(new Command(this._ctx.moveTo,[x,y]));return this;}
p.lineTo=function(x,y){this._dirty=this._active=true;this._activeInstructions.push(new Command(this._ctx.lineTo,[x,y]));return this;}
p.arcTo=function(x1,y1,x2,y2,radius){this._dirty=this._active=true;this._activeInstructions.push(new Command(this._ctx.arcTo,[x1,y1,x2,y2,radius]));return this;}
p.arc=function(x,y,radius,startAngle,endAngle,anticlockwise){this._dirty=this._active=true;if(anticlockwise==null){anticlockwise=false;}
this._activeInstructions.push(new Command(this._ctx.arc,[x,y,radius,startAngle,endAngle,anticlockwise]));return this;}
p.quadraticCurveTo=function(cpx,cpy,x,y){this._dirty=this._active=true;this._activeInstructions.push(new Command(this._ctx.quadraticCurveTo,[cpx,cpy,x,y]));return this;}
p.bezierCurveTo=function(cp1x,cp1y,cp2x,cp2y,x,y){this._dirty=this._active=true;this._activeInstructions.push(new Command(this._ctx.bezierCurveTo,[cp1x,cp1y,cp2x,cp2y,x,y]));return this;}
p.rect=function(x,y,w,h){this._dirty=this._active=true;this._activeInstructions.push(new Command(this._ctx.rect,[x,y,w-1,h]));return this;}
p.closePath=function(){if(this._active){this._dirty=true;this._activeInstructions.push(new Command(this._ctx.closePath,[]));}
return this;}
p.clear=function(){this._instructions=[];this._oldInstructions=[];this._activeInstructions=[];this._strokeStyleInstructions=this._strokeInstructions=this._fillInstructions=null;this._active=this._dirty=false;return this;}
p.beginFill=function(color){if(this._active){this._newPath();}
this._fillInstructions=color?[new Command(this._setProp,["fillStyle",color])]:null;return this;}
p.beginLinearGradientFill=function(colors,ratios,x0,y0,x1,y1){if(this._active){this._newPath();}
var o=this._ctx.createLinearGradient(x0,y0,x1,y1);for(var i=0,l=colors.length;i<l;i++){o.addColorStop(ratios[i],colors[i]);}
this._fillInstructions=[new Command(this._setProp,["fillStyle",o])];return this;}
p.beginRadialGradientFill=function(colors,ratios,x0,y0,r0,x1,y1,r1){if(this._active){this._newPath();}
var o=this._ctx.createRadialGradient(x0,y0,r0,x1,y1,r1);for(var i=0,l=colors.length;i<l;i++){o.addColorStop(ratios[i],colors[i]);}
this._fillInstructions=[new Command(this._setProp,["fillStyle",o])];return this;}
p.beginBitmapFill=function(image,repetition){if(this._active){this._newPath();}
repetition=repetition||"";var o=this._ctx.createPattern(image,repetition);this._fillInstructions=[new Command(this._setProp,["fillStyle",o])];return this;}
p.endFill=function(){this.beginFill(null);return this;}
p.setStrokeStyle=function(thickness,caps,joints,miterLimit){if(this._active){this._newPath();}
this._strokeStyleInstructions=[new Command(this._setProp,["lineWidth",(thickness==null?"1":thickness)]),new Command(this._setProp,["lineCap",(caps==null?"butt":(isNaN(caps)?caps:Graphics.STROKE_CAPS_MAP[caps]))]),new Command(this._setProp,["lineJoin",(joints==null?"miter":(isNaN(joints)?joints:Graphics.STROKE_JOINTS_MAP[joints]))]),new Command(this._setProp,["miterLimit",(miterLimit==null?"10":miterLimit)])];return this;}
p.beginStroke=function(color){if(this._active){this._newPath();}
this._strokeInstructions=color?[new Command(this._setProp,["strokeStyle",color])]:null;return this;}
p.beginLinearGradientStroke=function(colors,ratios,x0,y0,x1,y1){if(this._active){this._newPath();}
var o=this._ctx.createLinearGradient(x0,y0,x1,y1);for(var i=0,l=colors.length;i<l;i++){o.addColorStop(ratios[i],colors[i]);}
this._strokeInstructions=[new Command(this._setProp,["strokeStyle",o])];return this;}
p.beginRadialGradientStroke=function(colors,ratios,x0,y0,r0,x1,y1,r1){if(this._active){this._newPath();}
var o=this._ctx.createRadialGradient(x0,y0,r0,x1,y1,r1);for(var i=0,l=colors.length;i<l;i++){o.addColorStop(ratios[i],colors[i]);}
this._strokeInstructions=[new Command(this._setProp,["strokeStyle",o])];return this;}
p.beginBitmapStroke=function(image,repetition){if(this._active){this._newPath();}
repetition=repetition||"";var o=this._ctx.createPattern(image,repetition);this._strokeInstructions=[new Command(this._setProp,["strokeStyle",o])];return this;}
p.endStroke=function(){this.beginStroke(null);return this;}
p.curveTo=p.quadraticCurveTo;p.drawRect=p.rect;p.drawRoundRect=function(x,y,w,h,radius){this.drawRoundRectComplex(x,y,w,h,radius,radius,radius,radius);return this;}
p.drawRoundRectComplex=function(x,y,w,h,radiusTL,radiusTR,radiusBR,radiusBL){this._dirty=this._active=true;this._activeInstructions.push(new Command(this._ctx.moveTo,[x+radiusTL,y]),new Command(this._ctx.lineTo,[x+w-radiusTR,y]),new Command(this._ctx.arc,[x+w-radiusTR,y+radiusTR,radiusTR,(-Math.PI/2),0,false]),new Command(this._ctx.lineTo,[x+w,y+h-radiusBR]),new Command(this._ctx.arc,[x+w-radiusBR,y+h-radiusBR,radiusBR,0,Math.PI/2,false]),new Command(this._ctx.lineTo,[x+radiusBL,y+h]),new Command(this._ctx.arc,[x+radiusBL,y+h-radiusBL,radiusBL,Math.PI/2,Math.PI,false]),new Command(this._ctx.lineTo,[x,y+radiusTL]),new Command(this._ctx.arc,[x+radiusTL,y+radiusTL,radiusTL,Math.PI,Math.PI*3/2,false]));return this;}
p.drawCircle=function(x,y,radius){this.arc(x,y,radius,0,Math.PI*2);return this;}
p.drawEllipse=function(x,y,w,h){this._dirty=this._active=true;var k=0.5522848;var ox=(w/2)*k;var oy=(h/2)*k;var xe=x+w;var ye=y+h;var xm=x+w/2;var ym=y+h/2;this._activeInstructions.push(new Command(this._ctx.moveTo,[x,ym]),new Command(this._ctx.bezierCurveTo,[x,ym-oy,xm-ox,y,xm,y]),new Command(this._ctx.bezierCurveTo,[xm+ox,y,xe,ym-oy,xe,ym]),new Command(this._ctx.bezierCurveTo,[xe,ym+oy,xm+ox,ye,xm,ye]),new Command(this._ctx.bezierCurveTo,[xm-ox,ye,x,ym+oy,x,ym]));return this;}
p.drawPolyStar=function(x,y,radius,sides,pointSize,angle){this._dirty=this._active=true;if(pointSize==null){pointSize=0;}
pointSize=1-pointSize;if(angle==null){angle=0;}
else{angle/=180/Math.PI;}
var a=Math.PI/sides;this._activeInstructions.push(new Command(this._ctx.moveTo,[x+Math.cos(angle)*radius,y+Math.sin(angle)*radius]));for(var i=0;i<sides;i++){angle+=a;if(pointSize!=1){this._activeInstructions.push(new Command(this._ctx.lineTo,[x+Math.cos(angle)*radius*pointSize,y+Math.sin(angle)*radius*pointSize]));}
angle+=a;this._activeInstructions.push(new Command(this._ctx.lineTo,[x+Math.cos(angle)*radius,y+Math.sin(angle)*radius]));}
return this;}
p.clone=function(){var o=new Graphics();o._instructions=this._instructions.slice();o._activeInstructions=this._activeInstructions.slice();o._oldInstructions=this._oldInstructions.slice();if(this._fillInstructions){o._fillInstructions=this._fillInstructions.slice();}
if(this._strokeInstructions){o._strokeInstructions=this._strokeInstructions.slice();}
if(this._strokeStyleInstructions){o._strokeStyleInstructions=this._strokeStyleInstructions.slice();}
o._active=this._active;o._dirty=this._dirty;return o;}
p.toString=function(){return"[Graphics]";}
p.mt=p.moveTo;p.lt=p.lineTo;p.at=p.arcTo;p.bt=p.bezierCurveTo;p.qt=p.quadraticCurveTo;p.a=p.arc;p.r=p.rect;p.cp=p.closePath;p.c=p.clear;p.f=p.beginFill;p.lf=p.beginLinearGradientFill;p.rf=p.beginRadialGradientFill;p.bf=p.beginBitmapFill;p.ef=p.endFill;p.ss=p.setStrokeStyle;p.s=p.beginStroke;p.ls=p.beginLinearGradientStroke;p.rs=p.beginRadialGradientStroke;p.bs=p.beginBitmapStroke;p.es=p.endStroke;p.dr=p.drawRect;p.rr=p.drawRoundRect;p.rc=p.drawRoundRectComplex;p.dc=p.drawCircle;p.de=p.drawEllipse;p.dp=p.drawPolyStar;p._updateInstructions=function(){this._instructions=this._oldInstructions.slice()
this._instructions.push(Graphics.beginCmd);if(this._fillInstructions){this._instructions.push.apply(this._instructions,this._fillInstructions);}
if(this._strokeInstructions){this._instructions.push.apply(this._instructions,this._strokeInstructions);if(this._strokeStyleInstructions){this._instructions.push.apply(this._instructions,this._strokeStyleInstructions);}}
this._instructions.push.apply(this._instructions,this._activeInstructions);if(this._fillInstructions){this._instructions.push(Graphics.fillCmd);}
if(this._strokeInstructions){this._instructions.push(Graphics.strokeCmd);}}
p._newPath=function(){if(this._dirty){this._updateInstructions();}
this._oldInstructions=this._instructions;this._activeInstructions=[];this._active=this._dirty=false;}
p._setProp=function(name,value){this[name]=value;}
window.Graphics=Graphics;}(window));(function(window){Shadow=function(color,offsetX,offsetY,blur){this.initialize(color,offsetX,offsetY,blur);}
var p=Shadow.prototype;Shadow.identity=null;p.color=null;p.offsetX=0;p.offsetY=0;p.blur=0;p.initialize=function(color,offsetX,offsetY,blur){this.color=color;this.offsetX=offsetX;this.offsetY=offsetY;this.blur=blur;}
p.toString=function(){return"[Shadow]";}
p.clone=function(){return new Shadow(this.color,this.offsetX,this.offsetY,this.blur);}
Shadow.identity=new Shadow(null,0,0,0);window.Shadow=Shadow;}(window));(function(window){Shape=function(graphics){this.initialize(graphics);}
var p=Shape.prototype=new DisplayObject();p.graphics=null;p.DisplayObject_initialize=p.initialize;p.initialize=function(graphics){this.DisplayObject_initialize();this.graphics=graphics?graphics:new Graphics();}
p.isVisible=function(){return this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0&&this.graphics;}
p.DisplayObject_draw=p.draw;p.draw=function(ctx,ignoreCache){if(this.DisplayObject_draw(ctx,ignoreCache)){return true;}
this.graphics.draw(ctx);return true;}
p.clone=function(recursive){var o=new Shape((recursive&&this.graphics)?this.graphics.clone():this.graphics);this.cloneProps(o);return o;}
p.toString=function(){return"[Shape (name="+this.name+")]";}
window.Shape=Shape;}(window));(function(window){SpriteSheet=function(image,frameWidth,frameHeight,frameData){this.initialize(image,frameWidth,frameHeight,frameData);}
var p=SpriteSheet.prototype;p.image=null;p.frameWidth=0;p.frameHeight=0;p.frameData=null;p.loop=true;p.totalFrames=0;p.initialize=function(image,frameWidth,frameHeight,frameData){this.image=image;this.frameWidth=frameWidth;this.frameHeight=frameHeight;this.frameData=frameData;}
p.toString=function(){return"[SpriteSheet]";}
p.clone=function(){var o=new SpriteSheet(this.image,this.frameWidth,this.frameHeight,this.frameData);o.loop=this.loop;o.totalFrames=this.totalFrames;return o;}
window.SpriteSheet=SpriteSheet;}(window));(function(window){Stage=function(canvas){this.initialize(canvas);}
var p=Stage.prototype=new Container();Stage._snapToPixelEnabled=false;p.autoClear=true;p.canvas=null;p.mouseX=null;p.mouseY=null;p.onMouseMove=null;p.onMouseUp=null;p.onMouseDown=null;p.snapToPixelEnabled=false;p.mouseInBounds=false;p._tmpCanvas=null;p._activeMouseEvent=null;p._activeMouseTarget=null;p._mouseOverIntervalID=null;p._mouseOverX=0;p._mouseOverY=0;p._mouseOverTarget=null;p.Container_initialize=p.initialize;p.initialize=function(canvas){this.Container_initialize();this.canvas=canvas;this.mouseChildren=true;var o=this;if(window.addEventListener){window.addEventListener("mouseup",function(e){o._handleMouseUp(e);},false);window.addEventListener("mousemove",function(e){o._handleMouseMove(e);},false);}else if(document.addEventListener){document.addEventListener("mouseup",function(e){o._handleMouseUp(e);},false);document.addEventListener("mousemove",function(e){o._handleMouseMove(e);},false);}
canvas.addEventListener("mousedown",function(e){o._handleMouseDown(e);},false);}
p.update=function(){if(!this.canvas){return;}
if(this.autoClear){this.clear();}
Stage._snapToPixelEnabled=this.snapToPixelEnabled;this.draw(this.canvas.getContext("2d"),false,this.getConcatenatedMatrix(DisplayObject._workingMatrix));}
p.tick=p.update;p.clear=function(){if(!this.canvas){return;}
var ctx=this.canvas.getContext("2d");ctx.setTransform(1,0,0,1,0,0);ctx.clearRect(0,0,this.canvas.width,this.canvas.height);}
p.toDataURL=function(backgroundColor,mimeType){if(!mimeType){mimeType="image/png";}
var ctx=this.canvas.getContext('2d');var w=this.canvas.width;var h=this.canvas.height;var data;if(backgroundColor){data=ctx.getImageData(0,0,w,h);var compositeOperation=ctx.globalCompositeOperation;ctx.globalCompositeOperation="destination-over";ctx.fillStyle=backgroundColor;ctx.fillRect(0,0,w,h);}
var dataURL=this.canvas.toDataURL(mimeType);if(backgroundColor){ctx.clearRect(0,0,w,h);ctx.putImageData(data,0,0);ctx.globalCompositeOperation=compositeOperation;}
return dataURL;}
p.enableMouseOver=function(frequency){if(this._mouseOverIntervalID){clearInterval(this._mouseOverIntervalID);this._mouseOverIntervalID=null;}
if(frequency<=0){return;}
var o=this;this._mouseOverIntervalID=setInterval(function(){o._testMouseOver();},1000/Math.min(50,frequency));this._mouseOverX=NaN;this._mouseOverTarget=null;}
p.clone=function(){var o=new Stage(null);this.cloneProps(o);return o;}
p.toString=function(){return"[Stage (name="+this.name+")]";}
p._handleMouseMove=function(e){if(!this.canvas){this.mouseX=this.mouseY=null;return;}
if(!e){e=window.event;}
var inBounds=this.mouseInBounds;this._updateMousePosition(e.pageX,e.pageY);if(!inBounds&&!this.mouseInBounds){return;}
var evt=new MouseEvent("onMouseMove",this.mouseX,this.mouseY);if(this.onMouseMove){this.onMouseMove(evt);}
if(this._activeMouseEvent&&this._activeMouseEvent.onMouseMove){this._activeMouseEvent.onMouseMove(evt);}}
p._updateMousePosition=function(pageX,pageY){var o=this.canvas;do{pageX-=o.offsetLeft;pageY-=o.offsetTop;}while(o=o.offsetParent);this.mouseInBounds=(pageX>=0&&pageY>=0&&pageX<this.canvas.width&&pageY<this.canvas.height);if(this.mouseInBounds){this.mouseX=pageX;this.mouseY=pageY;}}
p._handleMouseUp=function(e){var evt=new MouseEvent("onMouseUp",this.mouseX,this.mouseY);if(this.onMouseUp){this.onMouseUp(evt);}
if(this._activeMouseEvent&&this._activeMouseEvent.onMouseUp){this._activeMouseEvent.onMouseUp(evt);}
if(this._activeMouseTarget&&this._activeMouseTarget.onClick&&this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,true,(this._mouseOverIntervalID?3:1))==this._activeMouseTarget){this._activeMouseTarget.onClick(new MouseEvent("onClick",this.mouseX,this.mouseY));}
this._activeMouseEvent=this.activeMouseTarget=null;}
p._handleMouseDown=function(e){if(this.onMouseDown){this.onMouseDown(new MouseEvent("onMouseDown",this.mouseX,this.mouseY));}
var target=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,(this._mouseOverIntervalID?3:1));if(target){if(target.onPress instanceof Function){var evt=new MouseEvent("onPress",this.mouseX,this.mouseY);target.onPress(evt);if(evt.onMouseMove||evt.onMouseUp){this._activeMouseEvent=evt;}}
this._activeMouseTarget=target;}}
p._testMouseOver=function(){if(this.mouseX==this._mouseOverX&&this.mouseY==this._mouseOverY&&this.mouseInBounds){return;}
var target=null;if(this.mouseInBounds){var target=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,3);this._mouseOverX=this.mouseX;this._mouseOverY=this.mouseY;}
if(this._mouseOverTarget!=target){if(this._mouseOverTarget&&this._mouseOverTarget.onMouseOut){this._mouseOverTarget.onMouseOut(new MouseEvent("onMouseOver",this.mouseX,this.mouseY));}
if(target&&target.onMouseOver){target.onMouseOver(new MouseEvent("onMouseOut",this.mouseX,this.mouseY));}
this._mouseOverTarget=target;}}
window.Stage=Stage;}(window));(function(window){Text=function(text,font,color){this.initialize(text,font,color);}
var p=Text.prototype=new DisplayObject();Text._workingContext=document.createElement("canvas").getContext("2d");p.text="";p.font=null;p.color=null;p.textAlign=null;p.textBaseline=null;p.maxWidth=null;p.outline=false;p.lineHeight=null;p.lineWidth=null;p.DisplayObject_initialize=p.initialize;p.initialize=function(text,font,color){this.DisplayObject_initialize();this.text=text;this.font=font;this.color=color?color:"#000";}
p.isVisible=function(){return Boolean(this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0&&this.text!=null&&this.text!="");}
p.DisplayObject_draw=p.draw;p.draw=function(ctx,ignoreCache){if(this.DisplayObject_draw(ctx,ignoreCache)){return true;}
if(this.outline){ctx.strokeStyle=this.color;}
else{ctx.fillStyle=this.color;}
ctx.font=this.font;ctx.textAlign=this.textAlign?this.textAlign:"start";ctx.textBaseline=this.textBaseline?this.textBaseline:"alphabetic";var lines=String(this.text).split(/(?:\r\n|\r|\n)/);var lineHeight=(this.lineHeight==null)?this.getMeasuredLineHeight():this.lineHeight;var y=0;for(var i=0,l=lines.length;i<l;i++){var w=ctx.measureText(lines[i]).width;if(this.lineWidth==null||w<this.lineWidth){this._drawTextLine(ctx,lines[i],y);y+=lineHeight;continue;}
var words=lines[i].split(/(\s)/);var str=words[0];for(var j=1,jl=words.length;j<jl;j+=2){if(ctx.measureText(str+words[j]+words[j+1]).width>this.lineWidth){this._drawTextLine(ctx,str,y);y+=lineHeight;str=words[j+1];}else{str+=words[j]+words[j+1];}}
this._drawTextLine(ctx,str,y);y+=lineHeight;}
return true;}
p.getMeasuredWidth=function(){return this._getWorkingContext().measureText(this.text).width;}
p.getMeasuredLineHeight=function(){return this._getWorkingContext().measureText("M").width*1.2;}
p.clone=function(){var o=new Text(this.text,this.font,this.color);this.cloneProps(o);return o;}
p.toString=function(){return"[Text (text="+(this.text.length>20?this.text.substr(0,17)+"...":this.text)+")]";}
p.DisplayObject_cloneProps=p.cloneProps;p.cloneProps=function(o){this.DisplayObject_cloneProps(o);o.textAlign=this.textAlign;o.textBaseline=this.textBaseline;o.maxWidth=this.maxWidth;o.outline=this.outline;o.lineHeight=this.lineHeight;o.lineWidth=this.lineWidth;}
p._getWorkingContext=function(){var ctx=Text._workingContext;ctx.font=this.font;ctx.textAlign=this.textAlign?this.textAlign:"start";ctx.textBaseline=this.textBaseline?this.textBaseline:"alphabetic";return ctx;}
p._drawTextLine=function(ctx,text,y){if(this.outline){ctx.strokeText(text,0,y,this.maxWidth);}
else{ctx.fillText(text,0,y,this.maxWidth);}}
window.Text=Text;}(window));
// --
Cache={nb_files:0,events_data:{},files:{},propretiesEvent:{},propretiesMap:{},loadFinish:function(){}}
Database={}
Cache.loadGraphics=function(filename,type,load,data){var path;switch(type){case"tilesets":path="Graphics/Tilesets";break;case"autotiles":path="Graphics/Autotiles";break;case"characters":path="Graphics/Characters";break;case"windowskins":path="Graphics/Windowskins";break;case"animations":path="Graphics/Animations";break;case"pictures":path="Graphics/Pictures";break;}
var file=Cache.get(filename,type);if(file){callback();return file;}
var img=new Image();Cache.nb_files++;img.src=path+"/"+filename;img.filename=filename;img.onload=function(){Cache.nb_files--;if(!Cache.files[type])Cache.files[type]=[];Cache.files[type].push(img);callback();}
img.onerror=function(){alert('[en] No such file or directory :\n[fr] Impossible de trouver le fichier ou dossier :\n\n'+this.src);}
function callback(){if(Cache.loadFinish&&Cache.nb_files==0){var onfinish=Cache.loadFinish;Cache.loadFinish=undefined;onfinish();}
if(load){if(file){load(file,data);}
else{load(img,data);}}}
return img;}
Cache.get=function(filename,type){if(Cache.files[type]){for(var i=0;i<Cache.files[type].length;i++){if(filename==Cache.files[type][i].filename){return Cache.files[type][i];}}}
return false;}
Cache.tilesets=function(filename,load,data){return Cache.loadGraphics(filename,"tilesets",load,data);}
Cache.autotiles=function(filename,load,data){return Cache.loadGraphics(filename,"autotiles",load,data);}
Cache.characters=function(filename,load,data){return Cache.loadGraphics(filename,"characters",load,data);}
Cache.windowskins=function(filename,load,data){return Cache.loadGraphics(filename,"windowskins",load,data);}
Cache.animations=function(filename,load,data){return Cache.loadGraphics(filename,"animations",load,data);}
Cache.pictures=function(filename,load,data){return Cache.loadGraphics(filename,"pictures",load,data);}
Cache.event=function(name,callback_event){if(Cache.propretiesEvent[name]){callback_event(Cache.propretiesEvent[name]);}
else{Cache.ajax('Data/Events/'+name+'.js',function(ret){eval('var event='+ret+';');Cache.propretiesEvent[name]=event;callback_event(event);});}}
Cache.loadAudio=function(filename,type,load){if(!filename)return false;var path;switch(type){case"bgm":path="Audio/BGM";break;case"bgs":path="Audio/BGS";break;case"me":path="Audio/ME";break;case"se":path="Audio/SE";break;}
var snd=new Audio();if(typeof filename!="string"){if(snd.canPlayType){if(!!(snd.canPlayType('audio/mpeg;').replace(/no/,''))){filename=filename.mp3+'.mp3';}
else if(!!(snd.canPlayType('audio/ogg;codecs="vorbis"').replace(/no/,''))){filename=filename.ogg+'.ogg';}
snd.src=path+"/"+filename;}}
else{snd.src=path+"/"+filename;}
var file=Cache.get(filename,type);if(file){load(file);return file;}
if(!Cache.files[type])Cache.files[type]=[];Cache.files[type].push(snd);if(load)load(snd);}
Cache.audioStop=function(type){if(Cache.files[type]){for(var i=0;i<Cache.files[type].length;i++){Cache.files[type][i].pause();}}}
Cache.SE=function(filename,load){return Cache.loadAudio(filename,"se",load);}
Cache.BGM=function(filename,load){return Cache.loadAudio(filename,"bgm",load);}
Cache.ME=function(filename,load){return Cache.loadAudio(filename,"me",load);}
Cache.BGS=function(filename,load){return Cache.loadAudio(filename,"bgs",load);}
Cache.map=function(name,callback){if(Cache.propretiesMap[name]){callback(Cache.propretiesMap[name]);}
else{Cache.ajax('Data/Maps/'+name+'.js',function(ret){eval('var map_data='+ret);Cache.propretiesMap[name]=map_data;callback(map_data);});}}
Cache.ajax=function(filename,callback){var xhr;try{xhr=new ActiveXObject('Msxml2.XMLHTTP');}
catch(e)
{try{xhr=new ActiveXObject('Microsoft.XMLHTTP');}
catch(e2)
{try{xhr=new XMLHttpRequest();}
catch(e3){xhr=false;}}}
xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status==200){callback(xhr.responseText);}}};xhr.open("GET",filename,true);xhr.send(null);},Cache.onload=function(load){Cache.loadFinish=load;}
Rpg.debug=false;function Rpg(canvas_tag){this.canvas=document.getElementById(canvas_tag);this.ctx=this.canvas.getContext("2d");this.stage=new Stage(this.canvas);this.func_trigger={};this.maps=[];this.currentMapInfo={};this.currentMap=[[]];this.containerMap={x:0,y:0};this.layer=[];this.tile_w=32;this.tile_h=32;this.speedScrolling=4;this.screen_x=0;this.screen_y=0;this.screen_refresh={};this.events=[];this.eventsCache=[];this.switches={};this.items={};this.gold=0;this.propAnimations={};this.animations={};this.currentSound={bgm:'',bgs:'',me:'',se:''};this.soundVolume={bgm:1,bgs:1,me:1,se:1};this.windowskinDefault='001-Blue01.png';this.currentWindows=[];this.actions={};this.tacticalMap=[];this.initialize();}
Rpg.prototype={initialize:function(){if(Rpg.debug){this.fpsLabel=new Text("-- fps","bold 18px Arial","#FFF");this.stage.addChild(this.fpsLabel);this.fpsLabel.x=10;this.fpsLabel.y=20;}
this.setFPS(25);Ticker.addListener(this);},setScrolling:function(speed){this.speedScrolling=speed;},setFPS:function(fps){this.fps=fps;Ticker.setFPS(fps);},eventsRefresh:function(){var i;for(i=0;i<this.events.length;i++){this.events[i].refresh();}},setGraphicAnimation:function(width,height){this.propAnimations.pattern_w=width;this.propAnimations.pattern_h=height;},addAnimation:function(anim){this.animations[anim.name]=new Animation(anim,this);},setSwitches:function(switches,bool){var i;if(this.isArray(switches)){for(i=0;i<switches.length;i++){this.switches[switches[i]]=bool;}}
else{this.switches[switches]=bool;}
this.eventsRefresh();},isArray:function(a){return(typeof(a)==='object')?a.constructor.toString().match(/array/i)!==null||a.length!==undefined:false;},keyExist:function(a,value){if(this.isArray(value)){return a[value[0]]&&a[value[0]][value[1]];}
else{return a[value];}},valueExist:function(a,value){var array_find,i,j;for(i=0;i<a.length;i++){if(this.isArray(value)){array_find=true;for(j=0;j<a[i].length;j++){if(a[i][j]!=value[j]){array_find=false;}}
if(array_find){return true;}}
else{if(a[i]==value){return true;}}}
return false;},switchesIsOn:function(switches){var i;if(this.isArray(switches)){for(i=0;i<switches.length;i++){if(!this.switches[switches[i]]){return false;}}}
else{if(!this.switches[switches])return false;}
return true;},setActionBattle:function(prop){var i;this.actionBattle=prop;this.actionBattle.ennemy=[];for(i=0;i<this.events.length;i++){if(this.events[i].actionBattle){this.actionBattle.ennemy.push(this.events[i]);}}
if(prop.displayHpBar){var ennemy;for(i=0;i<this.actionBattle.ennemy.length;i++){ennemy=this.actionBattle.ennemy[i];ennemy.displayBar(ennemy.actionBattle.hp_max,ennemy.actionBattle.hp_max,70,5);}}
for(i=0;i<prop.eventsCache.length;i++){this.prepareEventAjax(prop.eventsCache[i]);}},setTactical:function(prop){var i,j;this.tactical=prop;this.tactical.event_selected=null;var self=this;this.stage.enableMouseOver();var sound_area_hover=new Audio("Audio/SE/"+prop.sound_hover_area);this.tactical.players=[];this.tactical.ai=[];for(i=0;i<this.events.length;i++){if(this.events[i].tactical!=undefined){var type=this.events[i].tactical.play;if(type=='player'){this.tactical.players.push(this.events[i]);}
else if(type=="ai"){this.tactical.ai.push(this.events[i]);}}}
var area=new Image();area.src='Graphics/Pictures/'+prop.actor_area;area.onload=function(){var bitmap=new Bitmap(area);var k=0;for(i=0;i<self.currentMap.length;i++){self.tacticalMap[i]=[];for(j=0;j<self.currentMap[0].length;j++){bitmap.name='area_actor';bitmap.x=i*self.tile_w;bitmap.y=j*self.tile_h;bitmap.visible=false;bitmap.onMouseOver=function(){sound_area_hover.play();}
self.tacticalMap[i][j]=bitmap;self.layer[7].addChild(bitmap);if(k<self.currentMap.length*self.currentMap[0].length){bitmap=bitmap.clone();}
k++;}}
if(self.tactical.displayHpBar){var players;for(i=0;i<self.tactical.players.length;i++){players=self.tactical.players[i];players.displayBar(players.tactical.hp_max,players.tactical.hp_max,70,5);}}}},tacticalAreaClear:function(){var i,j;for(i=0;i<this.tacticalMap.length;i++){for(j=0;j<this.tacticalMap[0].length;j++){this.tacticalMap[i][j].visible=false;}}},isTactical:function(){return this.tactical!=undefined;},changeGold:function(gold){this.gold+=gold;this.call('changeGold',gold);},getMapWidth:function(real){return this.currentMap.length*(real?this.tile_w:1);},getMapHeight:function(real){return this.currentMap[0].length*(real?this.tile_h:1);},scroll:function(x,y){this.screen_x=x*this.tile_w;this.screen_y=y*this.tile_h;},setScreen:function(x,y){this.setCamera(x,y);},setCamera:function(x,y){var width;var height;var real_x=x*this.tile_w;var real_y=y*this.tile_h;if(real_x<=this.canvas.width/2){width=0;}
else if(real_x+this.canvas.width/2>=this.getMapWidth(true)){width=-(this.getMapWidth(true)-this.canvas.width);}
else{width=-(real_x-this.canvas.width/2+(this.canvas.width/2%this.tile_w))}
if(real_y<=this.canvas.height/2){height=0;}
else if(real_y+this.canvas.height/2>=this.getMapHeight(true)){height=-(this.getMapHeight(true)-this.canvas.height);}
else{height=-(real_y-this.canvas.height/2+(this.canvas.height/2%this.tile_h));}
this.containerMap.x=width;this.containerMap.y=height;var multiple_w=this.tile_w/this.speedScrolling;var multiple_h=this.tile_h/this.speedScrolling;this.containerMap.x=Math.floor(this.containerMap.x/multiple_w)*multiple_w;this.containerMap.y=Math.floor(this.containerMap.y/multiple_h)*multiple_h;this.screen_x=Math.abs(this.containerMap.x);this.screen_y=Math.abs(this.containerMap.y);this.screen_refresh.x=this.screen_x;this.screen_refresh.y=this.screen_y;this.screen_refresh.scroll_y=false;this.screen_refresh.scroll_x=false;this._multipleScreen();this.refreshMap(true);},_multipleScreen:function(){var multiple_w=this.tile_w/this.speedScrolling;var multiple_h=this.tile_h/this.speedScrolling;this.screen_x=Math.floor(this.screen_x/multiple_w)*multiple_w;this.screen_y=Math.floor(this.screen_y/multiple_h)*multiple_h;},tick:function(){var self=this;var containerMap={x:this.containerMap.x,y:this.containerMap.y};if(this.targetScreen=="Mouse"){this.screen_x=this.stage.mouseX;this.screen_y=this.stage.mouseY;}
else if(this.targetScreen=="Player"){}
if(this.targetScreen!=undefined){this._multipleScreen();containerMap.x-=Math.abs(containerMap.x)==this.screen_x?0:Math.floor((this.screen_x<Math.abs(containerMap.x)?-this.tile_w:this.tile_w)/this.speedScrolling);containerMap.y-=Math.abs(containerMap.y)==this.screen_y?0:Math.floor((this.screen_y<Math.abs(containerMap.y)?-this.tile_h:this.tile_h)/this.speedScrolling);if(containerMap.x>0){this.screen_x=containerMap.x=0;}
else if(containerMap.x+this.getMapWidth(true)<this.canvas.width){containerMap.x=this.canvas.width-this.getMapWidth(true);this.screen_x=Math.abs(containerMap.x);}
if(containerMap.y>0){this.screen_y=containerMap.y=0;}
else if(containerMap.y+this.getMapHeight(true)<this.canvas.height){containerMap.y=this.canvas.height-this.getMapHeight(true);this.screen_y=Math.abs(containerMap.y);}
function refreshScreen(screen_xORy){var screen,tile,coor,coor_start,scroll;if(screen_xORy){screen=self.screen_x;tile=self.tile_w;coor=self.screen_refresh.x;coor_start=self.screen_refresh.start_x;scroll=self.screen_refresh.scroll_x;}
else{screen=self.screen_y;tile=self.tile_h;coor=self.screen_refresh.y;coor_start=self.screen_refresh.start_y;scroll=self.screen_refresh.scroll_y;}
if(Math.abs(coor-coor_start)>=tile/2&&scroll){if(screen_xORy){coor=self.screen_refresh.x=screen;}
else{coor=self.screen_refresh.y=screen;}}
if(!isNaN(coor)){if(coor!=screen&&!scroll){var params={};if(screen_xORy){self.screen_refresh.start_x=screen;self.screen_refresh.scroll_x=true;}
else{self.screen_refresh.start_y=screen;self.screen_refresh.scroll_y=true;}
if(coor>screen){if(screen_xORy){params.direction='left';}
else{params.direction='up';}}
else{if(screen_xORy){params.direction='right';}
else{params.direction='bottom';}}
self.screen_refresh.dir=params.direction;self.call('_scrollStart',params);}
else if(coor==screen&&scroll){if(screen_xORy){self.screen_refresh.scroll_x=false;}
else{self.screen_refresh.scroll_y=false;}
self.call('_scrollFinish',{direction:self.screen_refresh.dir});}}}
refreshScreen(true);refreshScreen(false);}
if(this.currentMap){this.screen_refresh.x=this.screen_x;this.screen_refresh.y=this.screen_y;if(this.canvas.width<=this.getMapWidth(true)){this.containerMap.x=containerMap.x;}
if(this.canvas.height<=this.getMapHeight(true)){this.containerMap.y=containerMap.y;}}
if(Rpg.debug){this.fpsLabel.text=Math.round(Ticker.getMeasuredFPS())+" fps";}
this.call('update');this.stage.update();},menu:function(){},clone:function(srcInstance){var i;if(typeof(srcInstance)!='object'||srcInstance==null){return srcInstance;}
var newInstance=srcInstance.constructor();for(i in srcInstance){newInstance[i]=this.clone(srcInstance[i]);}
return newInstance;},tilePriority:function(tile_id){return this.mapData.propreties[tile_id][0];},tilePassage:function(tile_id){return this.mapData.propreties[tile_id][1];},isPassable:function(x,y,dir){var i;if(!dir)dir=16;if(x<0||y<0||x>=this.currentMap.length||y>=this.currentMap[0].length)return false;for(i=0;i<this.events.length;i++){if(this.events[i].character_hue!=undefined&&this.events[i].x==x&&this.events[i].y==y){if(this.events[i].through){return true;}
else{return false;}}}
var tiles=this.currentMap[x][y];var passage,priority;for(i=2;i>=0;i--){if(tiles[i]!=null){priority=this.tilePriority(tiles[i]);if(priority==0){passage=this.tilePassage(tiles[i]);if(passage==0||passage==16){return true;}
else{return false;}}}}
return false;},prepareMap:function(filename,propreties,isLoad){this.maps.push({name:filename,propreties:propreties,callback:isLoad});},getPreparedMap:function(name){var i;for(i=0;i<this.maps.length;i++){if(this.maps[i].name==name){return this.maps[i];}}
return false;},setPreparedMap:function(name,propreties,callback){var map=this.getPreparedMap(name);if(map){map.propreties=propreties;if(callback)map.callback=callback;return true;}
return false;},callMap:function(name){var map=this.getPreparedMap(name);if(map){this.loadMap(name,map.propreties,map.callback);return true;}
return false;},loadMap:function(filename,propreties,isLoad){var self=this;var autotiles_array=[];var i,j,k,l;for(i=0;i<9;i++){this.layer[i]=new Container();}
for(i=0;i<this.events.length;i++){Ticker.removeListener(this.events[i]);}
this.events=[];this.bind('update',function(){});if(this.containerMap.name!==undefined){this.stage.clear();this.containerMap.removeAllChildren();if(this.player){this.player.refreshBitmap();}}
this.maps.push({name:filename,propreties:propreties,callback:isLoad});this.currentMapInfo={name:filename,propreties:propreties};Cache.map(filename,callback);function bitmapAutoTiles(bmp,position,animated){var i=0;var cont=new Container();var nb_seq=animated/16;autotiles_array.push(cont);for(i=0;i<4;i++){bmp.currentFrame=nb_seq*position[i][1]+position[i][0];if(animated){bmp.waitFrame=5;bmp.arrayFrames=[];for(k=0;k<nb_seq/6;k++){bmp.arrayFrames.push(bmp.currentFrame+(k*6));}}
switch(i){case 1:bmp.x=16;break;case 2:bmp.y=16;break;case 3:bmp.x=0;break;}
cont.addChild(bmp);bmp=bmp.clone();}}
function dataAutotile(x,y){var i=0;x=(x-1)*2;y=(y-1)*2;var tab=[];for(i=0;i<4;i++){switch(i){case 1:x++;break;case 2:y++;break;case 3:x--;break;}
tab.push([x,y]);}
return tab;}
function constructAutoTiles(seq,bmp,autotile,animated){var i,j,k;switch(seq){case 0:bitmapAutoTiles(bmp,autotile.center,animated);break;case 1:var array_corner=[];var corner_close=[];var split;for(i=1;i<=4;i++){for(j=0;j<=array_corner.length;j++){corner_close.push((j!=0?array_corner[j-1]:'')+i+";");}
for(j=0;j<corner_close.length;j++){array_corner.push(corner_close[j]);split=corner_close[j].split(';');split.pop();var tile_corner=[];for(k=1;k<=4;k++){if(self.valueExist(split,k)){tile_corner.push(autotile.corner[k-1]);}
else{tile_corner.push(autotile.center[k-1]);}}
bitmapAutoTiles(bmp,tile_corner,animated);bmp=bmp.clone();}
corner_close=[];}
break;case 2:var dir=[autotile.left,autotile.top,autotile.right,autotile.bottom];var new_tile;var corner_id=[2,3];var pos;for(i=0;i<4;i++){for(j=0;j<4;j++){new_tile=self.clone(dir[i]);if(j==1||j==3){pos=corner_id[0]-1;new_tile[pos]=autotile.corner[pos];}
if(j==2||j==3){pos=corner_id[1]-1;new_tile[pos]=autotile.corner[pos];}
bitmapAutoTiles(bmp,new_tile,animated);bmp=bmp.clone();}
corner_id[0]++;corner_id[1]++;if(corner_id[0]>4)corner_id[0]=1;if(corner_id[1]>4)corner_id[1]=1;}
break;case 3:bitmapAutoTiles(bmp,[autotile.left[0],autotile.right[1],autotile.right[2],autotile.left[3]],animated);bmp=bmp.clone();bitmapAutoTiles(bmp,[autotile.top[0],autotile.top[1],autotile.bottom[2],autotile.bottom[3]],animated);break;case 4:var dir=[autotile.top_left,autotile.top_right,autotile.bottom_right,autotile.bottom_left];var new_tile;var pos=3;for(i=0;i<dir.length;i++){for(j=0;j<2;j++){new_tile=self.clone(dir[i]);if(j==1){new_tile[pos-1]=autotile.corner[pos-1];}
bitmapAutoTiles(bmp,new_tile,animated);bmp=bmp.clone();}
pos++;if(pos>4)pos=1;}
break;case 5:var dir=[[autotile.top_left[0],autotile.top_right[1],autotile.right[2],autotile.left[3]],[autotile.top_left[0],autotile.top[1],autotile.bottom[2],autotile.bottom_left[3]],[autotile.left[0],autotile.right[1],autotile.bottom_right[2],autotile.bottom_left[3]],[autotile.top[0],autotile.top_right[1],autotile.bottom_right[2],autotile.bottom[3]]];for(i=0;i<dir.length;i++){bitmapAutoTiles(bmp,dir[i],animated);bmp=bmp.clone();}
break;case 6:bitmapAutoTiles(bmp,autotile.full,animated);bmp=bmp.clone();bitmapAutoTiles(bmp,autotile.full,animated);break;}}
function callback(map_data){self.mapData=map_data;var map=map_data.map;var container_map=new Container();Cache.onload(function(){if(propreties.autotiles){var autotile={center:dataAutotile(2,3),full:dataAutotile(1,1),corner:dataAutotile(3,1),left:dataAutotile(1,3),right:dataAutotile(3,3),top:dataAutotile(2,2),bottom:dataAutotile(2,4),top_left:dataAutotile(1,2),top_right:dataAutotile(3,2),bottom_left:dataAutotile(1,4),bottom_right:dataAutotile(3,4)};var img_autotiles,cont,bitmap_autotiles,sprite;for(i=0;i<propreties.autotiles.length;i++){img_autotiles=Cache.get(propreties.autotiles[i],"autotiles");sprite=new SpriteSheet(img_autotiles,self.tile_w/2,self.tile_h/2);bitmap_autotiles=new BitmapSequence(sprite);for(j=0;j<7;j++){constructAutoTiles(j,bitmap_autotiles,autotile,img_autotiles.width);bitmap_autotiles=bitmap_autotiles.clone();}}}
var img_tileset=Cache.get(propreties.tileset,"tilesets");var spriteSheet=new SpriteSheet(img_tileset,self.tile_w,self.tile_h);var bmpSeq=new BitmapSequence(spriteSheet);var k=0;for(l=0;l<3;l++){for(i=0;i<map.length;i++){for(j=0;j<map[0].length;j++){var id=map[i][j][l];if(id!=null){var priority=self.tilePriority(id);priority=l+(priority==0?0:4);if(!map[i][j][3]){map[i][j][3]={};}
if((id-48)-autotiles_array.length>=0){bmpSeq.name="tile"+k+"_"+i+"_"+j;bmpSeq.x=i*self.tile_w;bmpSeq.y=j*self.tile_h;bmpSeq.currentFrame=id-385;map[i][j][3][priority]=bmpSeq;bmpSeq=bmpSeq.clone();}
else{var cont=autotiles_array[id-48];if(cont){cont=cont.clone(true);cont.x=i*self.tile_w;cont.y=j*self.tile_h;map[i][j][3][priority]=cont;}}
k++;}}}}
for(i=0;i<self.layer.length;i++){container_map.addChild(self.layer[i]);}
self.stage.addChildAt(container_map,0);container_map.onClick=function(){var real_x=self.stage.mouseX-self.containerMap.x;var real_y=self.stage.mouseY-self.containerMap.y;var x=Math.floor(real_x/self.tile_w);var y=Math.floor(real_y/self.tile_h);var obj=this.getObjectUnderPoint(real_x,real_y);if(obj.name=="event"){var event=self.getEventById(obj.id);event.click();}
else if(obj.name=="area_actor"){if(self.tactical.event_selected!=null){var dir=self.tactical.event_selected.pathfinding(x,y);self.tactical.event_selected.move(dir,function(){self.tactical.event_selected.animation('stop');});self.tacticalAreaClear();}}
else if(self.mapClick!=undefined){self.mapClick({mouse_x:real_x,mouse_y:real_y,x:x,y:y,data:self.currentMap[x][y],obj:obj});}};self.currentMap=map;self.containerMap=container_map;if(propreties.player){if(!self.player){self.player=new Player(propreties.player,self);}
else{self.player.setPosition(propreties.player.x,propreties.player.y);}
self.setCamera(self.player.x,self.player.y);self.player.fixCamera(true);self.player.setTransfert([]);if(propreties.transfert){self.player.setTransfert(propreties.transfert);}
self.player.inTransfert=false;}
if(propreties.events){var event;for(i=0;i<propreties.events.length;i++){event=propreties.events[i];Cache.event(event,function(prop){self.events.push(new Event(prop,self));if(self.events.length==propreties.events.length){if(isLoad)isLoad();}});}}
else{if(isLoad)isLoad();}});Cache.tilesets(propreties.tileset);if(propreties.autotiles){for(i=0;i<propreties.autotiles.length;i++){Cache.autotiles(propreties.autotiles[i]);}}
if(propreties.bgm){var regex=/\/([^\/]+)$/;var array=regex.exec(self.currentSound.bgm.src);var bgm=true;if(array){if(typeof propreties.bgm=='string'){bgm=array[1]!=propreties.bgm;}
else{bgm=array[1]!=propreties.bgm.mp3+'.mp3'&&array[1]!=propreties.bgm.ogg+'.ogg';}
if(bgm){self.playBGM(propreties.bgm);}}
else{self.playBGM(propreties.bgm);}}}
this.bind('_scrollStart',function(e){self.refreshMap(false,{direction:e.direction,add:true});});this.bind('_scrollFinish',function(e){self.refreshMap(false,{direction:e.direction,add:false});});},refreshMap:function(allclear,clear_prop){var i,j,k,map;var width=Math.ceil(this.canvas.width/this.tile_w);var height=Math.ceil(this.canvas.height/this.tile_h);var x=Math.floor(Math.abs(this.containerMap.x)/this.tile_w);var y=Math.floor(Math.abs(this.containerMap.y)/this.tile_h);if(allclear){for(k=0;k<8;k++){if(k!=3){this.layer[k].removeAllChildren();for(i=0;i<width;i++){for(j=0;j<height;j++){map=this.currentMap[x+i][y+j][3][k];if(map){this.layer[k].addChild(map);}}}}}}
if(clear_prop){var dir=clear_prop.direction;var type=clear_prop.add?'add':'del';var a;var x=Math.floor(this.screen_x/this.tile_w);var y=Math.floor(this.screen_y/this.tile_h);var clear_x=clear_prop.direction=='up'||clear_prop.direction=='bottom'?false:true;var size=clear_x?height:width;for(k=0;k<8;k++){for(i=0;i<size;i++){if(dir=='left'||dir=='up'){a=type=='add'?0:(clear_x?width:height);}
else{a=type=='add'?(clear_x?width:height):-1;}
if(clear_x){map=this.currentMap[x+a][y+i][3][k];}
else{map=this.currentMap[x+i][y+a][3][k];}
if(map){if(type=='add'){this.layer[k].addChild(map);}
else{this.layer[k].removeChild(map);}}}}}},getEventById:function(id){return this._getEvent('id',{id:id});},getEventByName:function(name){return this._getEvent('name',{name:name});},getEventByPosition:function(x,y,multi){return this._getEvent('position',{x:x,y:y,multi:multi});},_getEvent:function(by,params){var i,array_event=[];for(i=0;i<this.events.length;i++){switch(by){case'name':if(this.events[i].name&&this.events[i].name==params.name){return this.events[i];}
break;case'id':if(this.events[i].id&&this.events[i].id==params.id){return{seek:i,event:this.events[i]};}
break;case'position':if(this.events[i].x==params.x&&this.events[i].y==params.y){if(params.multi){array_event.push(this.events[i]);}
else{return this.events[i];}}
break;}}
if(by=="position"){return array_event;}
return null;},removeEvent:function(id){var obj=this.getEventById(id);if(obj!=null){Ticker.removeListener(obj.event);obj.event.bitmap=undefined;this.layer[3].removeChild(obj.event.sprite);this.events.splice(obj.seek,1);return true;}
return false;},setScreenIn:function(obj){this.targetScreen=obj;},bind:function(name,func){this.func_trigger[name]=func;},call:function(name,params){if(this.func_trigger[name]!=undefined){return this.func_trigger[name](params);}},addAction:function(name,prop){this.actions[name]=prop;},addEvent:function(prop){var event=new Event(prop,this);this.events.push(event);return event;},addEventAjax:function(name,callback){var self=this;Cache.event(name,function(event){self.addEvent(event);if(callback)callback(event);});},addEventPrepared:function(name){var event=this.getEventPreparedByName(name);if(event!=null){return this.addEvent(event);}
return false;},getEventPreparedByName:function(name){for(var i=0;i<this.eventsCache.length;i++){if(this.eventsCache[i][0].name==name){return this.eventsCache[i];}}
return null;},setEventPrepared:function(name,propreties,page){var event=this.getEventPreparedByName(name);if(event!=null){for(var key in event[0]){if(propreties[key]){event[0][key]=propreties[key];}}
if(page){for(var key in event[1][page]){if(propreties[key]){event[1][page][key]=propreties[key];}}}}},prepareEvent:function(event){this.eventsCache.push(event);},prepareEventAjax:function(name,callback){var self=this;Cache.event(name,function(event){self.prepareEvent(event);if(callback)callback(event);});},setEventMode:function(event,mode){var change_mode=this.actionBattle.onChangeMode;event.actionBattle.mode=mode;if(mode=="passive"&&this.actionBattle.eventPassive&&this.actionBattle.eventPassive[event.actionBattle.passive]){this.actionBattle.eventPassive[event.actionBattle.passive](event);}
if(change_mode)change_mode(event,mode);},setVolumeAudio:function(volume,type){var self=this;if(type){setVolume(type);}
for(var key in this.soundVolume){setVolume(key);}
function setVolume(key){self.soundVolume[key]=volume;self.currentSound[key].volume=volume;}},playBGM:function(filename,load){var self=this;Cache.audioStop('bgm');Cache.BGM(filename,function(snd){self.currentSound.bgm=snd;snd.volume=self.soundVolume.bgm;snd.loop=true;snd.play();if(load)load(snd);});},playSE:function(filename,load){var self=this;Cache.SE(filename,function(snd){snd.volume=self.soundVolume.se;snd.play();if(load)load(snd);});},callCommandsEvent:function(event,onFinishCommand,freeze){var self=this;var can_freeze=freeze&&this.player;if(can_freeze)this.player.freeze=true;event.bind('onFinishCommand',function(){if(can_freeze)self.player.freeze=false;if(onFinishCommand)onFinishCommand();});event.onCommands();}}
function Window(prop,rpg){this.windowskin=prop.skin?prop.skin:rpg.windowskinDefault;this.opacity=prop.opacity;this.onLoad=prop.onLoad;this.propfadeIn=prop.fadeIn;this.propfadeOut=prop.fadeOut;this.blockMovement=prop.blockMovement;this.fadeMaxOpacity=this.opacity;this.dialog={};this.rpg=rpg;this.content;this.onClose;this.onOpen;this.id=Math.floor(Math.random()*100000);this.isOpen=false;this.keyopen=null;this.keyclose=null;this.initialize();}
Window.prototype={initialize:function(){Ticker.addListener(this);this.setWindowskin();},setWindowskin:function(){var self=this;this.dialog.skin=new Container();Cache.windowskins(this.windowskin,function(img){var spriteSheet=new SpriteSheet(img,128,128);var bmpSeq=new BitmapSequence(spriteSheet);bmpSeq.x=2;bmpSeq.y=2;bmpSeq.scaleX=1;bmpSeq.scaleY=1;bmpSeq.alpha=self.opacity;self.dialog.border={};var bmp_border=new BitmapSequence(new SpriteSheet(img,16,16));function borderConstruct(frame,x,y,position){bmp_border.currentFrame=frame;bmp_border.x=x;bmp_border.y=y;self.dialog.border[position]=bmp_border;self.dialog.skin.addChild(bmp_border);bmp_border=bmp_border.clone();}
self.dialog.content=bmpSeq;self.dialog.skin.addChild(bmpSeq);borderConstruct(8,16,0,'top');borderConstruct(19,0,16,'left');borderConstruct(22,32,16,'right');borderConstruct(44,16,32,'bottom');borderConstruct(7,0,0,'top_left');borderConstruct(10,32,0,'top_right');borderConstruct(43,0,32,'bottom_left');borderConstruct(46,32,32,'bottom_right');self.onLoad();});},setKeyClose:function(key){this.keyclose=key;},setKeyOpen:function(key){this.keyopen=key;},setText:function(text,css,color){this.content=new Text(text,css,color);},open:function(width,height,position,next){var self=this;if(!width)width=480;if(!height)height=160;if(!next)next=false;if(!position)position='bottom';var border_w=16;var border_h=16;var content_w=128;var content_h=128;this.dialog.border.top.scaleX=this.dialog.border.bottom.scaleX=(width-border_w)/border_w;this.dialog.border.right.scaleY=this.dialog.border.left.scaleY=(height-border_h)/border_h;this.dialog.border.top_right.x=this.dialog.border.right.x=this.dialog.border.bottom_right.x=width-border_w+5;this.dialog.border.bottom_right.y=this.dialog.border.bottom_left.y=this.dialog.border.bottom.y=height-border_h+5;this.dialog.content.scaleX=width/content_w;this.dialog.content.scaleY=height/content_h;var obj_text=this.content;obj_text.x=30;obj_text.y=40;obj_text.lineHeight=30;if(position=='bottom'){this.dialog.skin.x=this.rpg.canvas.width/2-width/2;this.dialog.skin.y=this.rpg.canvas.height-height-20;}
this.dialog.open=true;this.dialog.text=obj_text;this.dialog.skin.addChild(obj_text);this.dialog.skin.alpha=0;this.rpg.stage.addChild(this.dialog.skin);this.rpg.currentWindows.push(this);this.isOpen=true;if(this.propfadeIn){this.opacity=0;this.fadeIn(this.propfadeIn,function(){if(self.onOpen)self.onOpen();});}
else{this.dialog.skin.alpha=1;if(self.onOpen)self.onOpen();}},close:function(){var self=this;function _close(){self.isOpen=false;for(var i=0;i<self.rpg.currentWindows.length;i++){if(self.rpg.currentWindows[i].id==self.id){self.rpg.currentWindows.splice(i,1);break;}}
self.dialog.skin.removeChild(self.dialog.text);self.rpg.stage.removeChild(self.dialog.skin);if(self.onClose)self.onClose();}
if(this.propfadeOut){this.fadeOut(this.propfadeOut,_close);}
else{_close();}},tick:function(){if(this.fade&&this.fade.value!=this.opacity){var opacity=this.opacity;var speed=Math.round((this.fade.speed/255)*100)/100;if(this.fade.value<opacity){opacity-=speed;}
else{opacity+=speed;}
if(opacity<0){opacity=0;if(this.fade.callback)this.fade.callback();}
else if(opacity>this.fadeMaxOpacity){opacity=this.fadeMaxOpacity;if(this.fade.callback)this.fade.callback();}
this.opacity=opacity;this.dialog.skin.alpha=this.opacity;}},fadeOut:function(speed,callback){this.fading(0,speed,callback);},fadeIn:function(speed,callback){this.fading(1,speed,callback);},fading:function(value,speed,callback){this.fade={};this.fade.value=value;this.fade.speed=speed;this.fade.callback=callback;},}
function Animation(prop,rpg){this.frames=prop.frames;this.graphic=prop.graphic;this.name=prop.name;this.file_sound=prop.sound;this.framesDefault={};this.sound;this.bitmap;this.sprite;this.playing=false;this.currentSequence=0;this.rpg=rpg;this.onFinish;this.pattern_w=this.rpg.propAnimations.pattern_w;this.pattern_h=this.rpg.propAnimations.pattern_h;this.initialize(prop);}
Animation.prototype={initialize:function(prop){var self=this;var default_prop={y:0,x:0,zoom:100,opacity:255,rotation:0,opacity:255};for(var key in default_prop){if(prop.framesDefault&&prop.framesDefault[key]!==undefined){this.framesDefault[key]=prop.framesDefault[key];}
else{this.framesDefault[key]=default_prop[key];}}
Ticker.addListener(this);this.sprite=new Container();Cache.SE(this.file_sound,function(sdn){self.sound=sdn;});Cache.animations(this.graphic,function(anim){var spriteSheet=new SpriteSheet(anim,self.pattern_w,self.pattern_h);self.bitmap=new BitmapSequence(spriteSheet);});},tick:function(){var currentSeq;var i;var bitmap=this.bitmap;if(this.playing){if(this.frames[this.currentSequence]!=undefined){this.sprite.removeAllChildren();for(i=0;i<this.frames[this.currentSequence].length;i++){currentSeq=this.frames[this.currentSequence][i];if(currentSeq){bitmap.currentFrame=currentSeq.pattern-1;bitmap.x=currentSeq.x!=undefined?currentSeq.x:this.framesDefault.x;bitmap.y=currentSeq.y!=undefined?currentSeq.y:this.framesDefault.y;bitmap.scaleX=currentSeq.zoom!=undefined?currentSeq.zoom/100:this.framesDefault.zoom/100;bitmap.scaleY=currentSeq.zoom!=undefined?currentSeq.zoom/100:this.framesDefault.zoom/100;bitmap.alpha=currentSeq.opacity!=undefined?currentSeq.opacity/255:this.framesDefault.opacity/255;bitmap.rotation=currentSeq.rotation!=undefined?currentSeq.rotation:this.framesDefault.rotation;bitmap.regX=this.pattern_w/2;bitmap.regY=this.pattern_h/2;this.sprite.addChild(bitmap);bitmap=bitmap.clone();}}
this.currentSequence++;}
else{this.currentSequence=0;this.playing=false;this.rpg.layer[7].removeChild(this.sprite);if(this.onFinish!=undefined){this.onFinish();}}
if(this.fix){this.setPosition(this.fix.sprite.x,this.fix.sprite.y,true);}}},play:function(onFinish){this.playing=true;if(this.sound!=undefined){this.sound.volume=this.rpg.soundVolume.se;this.sound.play();}
this.onFinish=onFinish;this.rpg.layer[7].addChild(this.sprite);},setPosition:function(x,y,real){this.sprite.x=x*(real?1:this.rpg.tile_w);this.sprite.y=y*(real?1:this.rpg.tile_h);},setPositionEvent:function(event){this.setPosition(event.sprite.x,event.sprite.y,true);this.fix=event;},setZoom:function(zoom){this.sprite.scaleX=zoom;this.sprite.scaleY=zoom;}}
function Event(prop,rpg){if(prop==undefined)return;this.rpg=rpg;this.self_switch={};this.func_trigger={};this.actions=[];this.action_motions={};this.action_prop={};this.inAction=false;this.blockMovement=false;this.name=prop[0].name;this.commands=prop.commands;this.id=!prop[0].id?Math.floor(Math.random()*100000):prop[0].id;this.pages=prop[1];this.x=prop[0].x;this.y=prop[0].y;this.regX=prop[0].regX;this.regY=prop[0].regY;this.opacity=1;this.moving=false;this.stopMove=false;this.detection=false;this._wait={frame:0};this.currentFreq=1;this.fixcamera=false;this.targetPos={x:this.x,y:this.y};this.bitmap;this.bar;this.sprite=new Container();this.changePage=true;this.currentPage=0;this.currentCmd=0;this.tab_move_passable=[];this.tab_move=[];this.tickPlayer;this.initialize();}
Event.prototype={initialize:function(){Ticker.addListener(this);this.refresh();},init_tab_move:function(){for(var i=0;i<this.tactical.move*2+1;i++){this.tab_move_passable[i]=[];for(var j=0;j<this.tactical.move*2+1;j++){this.tab_move_passable[i][j]=-1;}}
var middle=Math.floor(this.tab_move_passable.length/2);this.tab_move_passable[middle][middle]=0;},refresh:function(){var self=this;function load(){if(prop.character_hue&&self.direction)self.bitmap.gotoAndStop(self.direction);self._trigger();}
var page=this.setPage();if(!page){if(this.bitmap!=undefined){this.rpg.layer[3].removeChild(this.sprite);this.character_hue=undefined;}
return;}
var prop=this.pages[this.currentPage];this.commands=prop.commands;this.tactical=prop.tactical;if(!this.actionBattle&&prop.action_battle){this.actionBattle=prop.action_battle;this.actionBattle.hp=this.actionBattle.hp_max;this.actions=this.actionBattle.actions;}
this.trigger=prop.trigger;this.direction_fix=prop.direction_fix;this.no_animation=prop.no_animation;this.stop_animation=prop.stop_animation;this.speed=prop.speed===undefined?4:prop.speed;this.type=prop.type?prop.type:'fixed';this.frequence=(prop.frequence?prop.frequence:0)*5;this.nbSequenceX=(prop.nbSequenceX?prop.nbSequenceX:4);this.nbSequenceY=(prop.nbSequenceY?prop.nbSequenceY:4);this.graphic_pattern=prop.pattern===undefined?0:prop.pattern;this.through=prop.character_hue?prop.through:true;this.direction=prop.direction;if(this.character_hue!==undefined){if(this.character_hue!==prop.character_hue){this.rpg.layer[3].removeChild(this.sprite);this.character_hue=prop.character_hue;if(this.character_hue)this.setCharacterHue(load);}
else{load();}}
else{this.character_hue=prop.character_hue;if(prop.character_hue!==undefined){this.setCharacterHue(load);}
else{load();}}
if(this.tactical!=undefined){this.tactical.status='wait';}},displayBar:function(min,max,width,height){if(this.bar){width=width?width:this.bar.width;height=height?height:this.bar.height;max=max?max:this.bar.max;this.sprite.removeChild(this.bar);}
if(max==undefined)return;if(!min)min=max;if(min>max){min=max}
var bar=new Shape();var y=-5;var x=-(width/2-this.rpg.tile_w/2);var pourcent=(100*min/max)/100;bar.width=width;bar.height=height;bar.max=max;bar.graphics.beginStroke("#000").drawRect(x,y,width,height);bar.graphics.beginFill("#8FFF8C").drawRect(x,y,width*pourcent,height);this.bar=bar;this.sprite.addChild(bar);},setSelfSwitch:function(id,bool){var _id=this.rpg.currentMapInfo.name+"_"+this.id;this.self_switch[id]=bool;if(!Cache.events_data[_id]){Cache.events_data[_id]={};}
if(!Cache.events_data[_id].self_switch){Cache.events_data[_id].self_switch={};}
Cache.events_data[_id].self_switch[id]=bool;this.refresh();},selfSwitchesIsOn:function(id){var _id=this.rpg.currentMapInfo.name+"_"+this.id;var e=Cache.events_data[_id];if(e&&e.self_switch&&e.self_switch[id]){return true;}
else{return false;}},refreshBitmap:function(){if(this.bitmap){this.rpg.layer[3].addChild(this.sprite);}},setCharacterHue:function(onload){var self=this;var i;Cache.characters(this.character_hue,function(chara){if(self.regY===undefined){self.regY=chara.height/self.nbSequenceY-self.rpg.tile_h;}
if(self.regX===undefined){self.regX=chara.width/self.nbSequenceX-self.rpg.tile_w;}
var up=self.nbSequenceY*3+self.graphic_pattern;var right=self.nbSequenceX*2+self.graphic_pattern;var left=self.nbSequenceX+self.graphic_pattern;var bottom=0+self.graphic_pattern;var nb=self.nbSequenceX-1;var anim={walkUp:[up,up+nb],walkRight:[right,right+nb],walkBottom:[bottom,bottom+nb],walkLeft:[left,left+nb],up:up,right:right,bottom:bottom,left:left}
var spriteSheet=new SpriteSheet(chara,chara.width/self.nbSequenceX,chara.height/self.nbSequenceY,anim);var bmpSeq=new BitmapSequence(spriteSheet);bmpSeq.gotoAndStop(self.direction);bmpSeq.waitFrame=self.rpg.fps/5;self.sprite.x=self.x*self.rpg.tile_w;self.sprite.y=self.y*self.rpg.tile_h;self.sprite.regY=self.regY;self.sprite.regX=self.regX;bmpSeq.name="event";bmpSeq.id=self.id;self.bitmap=bmpSeq;self.sprite.addChild(bmpSeq);self.rpg.layer[3].addChild(self.sprite);var act,name,spritesheet;var regex=new RegExp("(.*?)\\.(.*?)$","gi");var match=regex.exec(self.character_hue);for(i=0;i<self.actions.length;i++){name=self.actions[i];act=self.rpg.actions[name];if(match!=null){Cache.characters(match[1]+act.suffix_motion[0]+'.'+match[2],function(img,name){spritesheet=new SpriteSheet(img,img.width/4,img.height/4,anim);bmpSeq=bmpSeq.clone();bmpSeq.spriteSheet=spritesheet;self.action_motions[name]=bmpSeq;},name);}}
if(Rpg.debug){var size=new Shape();size.graphics.beginStroke("#00FF00").drawRect(0,0,chara.width/4,chara.height/4);self.sprite.addChild(size);var point_reg=new Shape();point_reg.graphics.beginStroke("#FF0000").drawRect(self.sprite.regX,self.sprite.regY,self.rpg.tile_w,self.rpg.tile_h);self.sprite.addChild(point_reg);}
if(onload)onload();});},_trigger:function(){if(this.trigger=='parallel_process'||this.trigger=='auto'||this.trigger=='auto_one_time'){this.onCommands();}
this.moveType();if(this.stop_animation){this.animation('stop');}},moveType:function(){if(this.type=='random'){this.moveRandom();}
else if(this.type=='approach'){this.approachPlayer();}},click:function(){if(this.trigger=='click'){this.onCommands();}
if(this.rpg.isTactical()){this.rpg.tacticalAreaClear();this.rpg.tactical.event_selected=this;if(this.tactical.status=='wait'){this.pathMove();for(var i=0;i<this.tab_move.length;i++){var x=this.tab_move[i][0];var y=this.tab_move[i][1];this.rpg.tacticalMap[x][y].visible=true;this.tactical.status='readyMove';}}
else if(this.tactical.status=='readyMove'){this.rpg.tacticalAreaClear();this.tactical.status='wait';}}},fixCamera:function(bool){for(var i=0;i<this.rpg.events.length;i++){this.rpg.events[i].fixcamera=false;}
if(this.rpg.player){this.rpg.player.fixcamera=false;}
this.fixcamera=bool;},tick:function(){if(this.bitmap==undefined)return;if(this._wait.frame>0){this._wait.frame--;if(this._wait.frame==0&&this._wait.callback)this._wait.callback();if(this._wait.block)return;}
var bmp_x=this.sprite.x;var bmp_y=this.sprite.y;var real_x=this.x*this.rpg.tile_w;var real_y=this.y*this.rpg.tile_h;var finish_step='';if(!this._moveReal){if(bmp_x!=real_x){if(real_x>bmp_x){bmp_x+=this.rpg.tile_w/this.speed;if(bmp_x>=real_x){bmp_x=real_x;finish_step='right';}}
else if(real_x<bmp_x){bmp_x-=this.rpg.tile_w/this.speed;if(bmp_x<=real_x){bmp_x=real_x;finish_step='left';}}
if(this.fixcamera){this.rpg.screen_x=bmp_x-this.rpg.canvas.width/2+(this.rpg.canvas.width/2%this.rpg.tile_w);}
this.sprite.x=bmp_x;}
if(bmp_y!=real_y){if(real_y>bmp_y){bmp_y+=this.rpg.tile_h/this.speed;if(bmp_y>=real_y){bmp_y=real_y;finish_step='bottom';}}
else if(real_y<bmp_y){bmp_y-=this.rpg.tile_h/this.speed;if(bmp_y<=real_y){bmp_y=real_y;finish_step='up';}}
if(this.fixcamera){this.rpg.screen_y=bmp_y-this.rpg.canvas.height/2+(this.rpg.canvas.height/2%this.rpg.tile_h);}
this.sprite.y=bmp_y;}
if(finish_step!=''||this.currentFreq>1){if(this.currentFreq==this.frequence||this.frequence==0){this.call('onFinishStep',finish_step);this.currentFreq=1;}
else{this.animation('stop');this.currentFreq++;}}}
else{var bmp_x=this.sprite.x;var bmp_y=this.sprite.y;var real_x=this._moveReal.xfinal;var real_y=this._moveReal.yfinal;if(bmp_x!=real_x){this._moveReal.vx=Math.abs(bmp_x-real_x)/this._moveReal.speed;if(this._moveReal.vx<0.01){this._moveReal.vx=0;}
if(real_x>bmp_x){bmp_x+=this._moveReal.vx;if(bmp_x>=real_x-0.2)bmp_x=real_x;}
else if(real_x<bmp_x){bmp_x-=this._moveReal.vx;if(bmp_x<=real_x-0.2)bmp_x=real_x;}
this.x=Math.floor(bmp_x/this.rpg.tile_w);this.sprite.x=bmp_x;}
if(bmp_y!=real_y){this._moveReal.vy=Math.abs(bmp_y-real_y)/this._moveReal.speed;if(this._moveReal.vy<0.01){this._moveReal.vy=0;}
if(real_y>bmp_y){bmp_y+=this._moveReal.vy;if(bmp_y>=real_x-0.2)bmp_y=real_y;}
else if(real_y<bmp_y){bmp_y-=this._moveReal.vy;if(bmp_y<=real_x-0.2)bmp_y=real_y;}
this.y=Math.floor(bmp_y/this.rpg.tile_h);this.sprite.y=bmp_y;}}
if(this.fade&&this.fade.value!=this.opacity){var opacity=this.opacity;var speed=Math.round((this.fade.speed/255)*100)/100;if(this.fade.value<opacity){opacity-=speed;}
else{opacity+=speed;}
if(opacity<0){opacity=0;if(this.fade.callback)this.fade.callback();}
else if(opacity>1){opacity=1;if(this.fade.callback)this.fade.callback();}
this.opacity=opacity;this.sprite.alpha=this.opacity;}
if(this.tickPlayer){this.tickPlayer();}
if(this.actionBattle){var detect=this.detectionPlayer(this.actionBattle.area);if(detect&&!this.detection){this.detection=true;var detection=this.rpg.actionBattle.detection?this.rpg.actionBattle.detection[this.actionBattle.detection]:false;this.rpg.setEventMode(this,'detection');if(detection){detection(this);}}
else if(!detect&&this.detection){this.detection=false;var nodetection=this.rpg.actionBattle.nodetection?this.rpg.actionBattle.nodetection[this.actionBattle.nodetection]:false;this.rpg.setEventMode(this,'nodetection');if(nodetection){nodetection(this);}}
if(this.actionBattle.mode=='offensive'){if(this.rpg.actionBattle.eventOffensive&&this.actionBattle.offensive){this.rpg.actionBattle.eventOffensive[this.actionBattle.offensive](this);}
var player=this.getEventAround(true);if(player.up.length>0||player.left.length>0||player.right.length>0||player.bottom.length>0){this.rpg.setEventMode(this,'attack');if(this.rpg.actionBattle.eventAttack&&this.actionBattle.attack){this.rpg.actionBattle.eventAttack[this.actionBattle.attack](this);}}}}
for(var key in this.action_prop){if(!isNaN(this.action_prop[key].wait)){this.action_prop[key].wait++;}}
if(this._blink&&this._blink.current){if(this._blink.currentDuration!=this._blink.duration){if(this._blink.currentFrequence>=this._blink.frequence){this._blink.currentFrequence=0;this._blink.visible=this._blink.visible?false:true;this.visible(this._blink.visible);}
this._blink.currentDuration++
this._blink.currentFrequence++}
else{this._blink.current=false;this.visible(true);if(this._blink.callback)this._blink.callback();}}},fadeOut:function(speed,callback){this.fading(0,speed,callback);},fadeIn:function(speed,callback){this.fading(1,speed,callback);},blink:function(duration,frequence,callback){this._blink={}
this._blink.duration=duration;this._blink.currentDuration=0;this._blink.frequence=frequence;this._blink.currentFrequence=0;this._blink.visible=true;this._blink.current=true;this._blink.callback=callback;},visible:function(visible){this.sprite.visible=visible;},wait:function(frame,block,callback){this._wait.frame=frame;this._wait.block=block;this._wait.callback=callback;},fading:function(value,speed,callback){this.fade={};this.fade.value=value;this.fade.speed=speed;this.fade.callback=callback;},detectionPlayer:function(area){var player=this.rpg.player;if(!player)return false;if(player.x<=this.x+area&&player.x>=this.x-area&&player.y<=this.y+area&&player.y>=this.y-area)return true;return false;},distance:function(xfinal,yfinal,x,y){var dis_final=Math.abs(xfinal-x)+Math.abs(yfinal-y);var dis_ini=Math.abs(this.x-x)+Math.abs(this.y-y);var somme_dis=dis_final+dis_ini;return{'_final':dis_final,'ini':dis_ini,'somme':somme_dis};},animation:function(sequence,speed,onFinish,nbSequence){if(!this.bitmap)return false;if(sequence=='stop'){if(this.stop_animation){sequence='walk';}
else if(!this.direction_fix){this.bitmap.gotoAndStop(this.direction);return;}
else if(this.direction_fix){return;}}
if(sequence=='walk'){switch(this.direction){case'left':sequence='walkLeft';break;case'right':sequence='walkRight';break;case'up':sequence='walkUp';break;case'bottom':sequence='walkBottom';break;}}
if(this.bitmap.currentSequence!=sequence){this.bitmap.nbSequenceToPlay=nbSequence?nbSequence:-1;this.bitmap.gotoAndPlay(sequence);this.bitmap.waitFrame=speed?Math.ceil(this.rpg.fps/speed):this.bitmap.waitFrame;this.bitmap.callback=onFinish;}},setStopDirection:function(dir){this.direction=dir;this.animation('stop');},turnTowardPlayer:function(){var player=this.rpg.player;if(player){var dir=this.directionRelativeToPlayer();if(dir==2){this.setStopDirection('up');}
else if(dir==8){this.setStopDirection('bottom');}
else if(dir==6){this.setStopDirection('right');}
else if(dir==4){this.setStopDirection('left');}}},moveAwayFromPlayer:function(onFinish,passable){var dir;var player=this.rpg.player;if(player){if(player.y<this.y){dir=8}
else if(player.y>this.y){dir=2;}
else if(player.x>this.x){dir=4;}
else if(player.x<this.x){dir=6;}
this.move([dir],onFinish,passable);}},directionRelativeToPlayer:function(){var player=this.rpg.player;if(player){if(player.y<this.y){return 2;}
if(player.y>this.y){return 8;}
if(player.x>this.x){return 6;}
if(player.x<this.x){return 4;}}
return false;},approachPlayer:function(){var self=this;approach();function approach(){if(self.stopMove)return;var dir=self.directionRelativeToPlayer();if(dir){if(self.canMove(dir)){self.move([dir],function(){approach();});}
else{var dir=self.pathfinding(self.rpg.player.x,self.rpg.player.y);dir.pop();self.move(dir);}}}},moveStop:function(animation_stop){if(animation_stop)this.animation('stop');this.stopMove=true;},moveStart:function(){this.stopMove=false;},moveRandom:function(){var self=this;rand();function rand(){if(self.stopMove)return;var dir=(Math.floor(Math.random()*4)+1)*2;if(self.canMove(dir)){self.move([dir],function(){rand();});}
else{rand();}}},canMove:function(dir){var x=this.x;var y=this.y;var passable=true;switch(dir){case 2:y--;break;case 4:x--;break;case 6:x++;break;case 8:y++;break;}
if(this.rpg.player.x==x&&this.rpg.player.y==y){this.moving=false;return false;}
passable=this.rpg.isPassable(x,y);if(!passable){this.moving=false;}
return passable;},move:function(dir,onFinishMove,passable){var self=this;var pos=0;var is_passable=true;if(dir.length==0||this.blockMovement){this.moving=false;return;}
moving();function moving(){switch(dir[pos]){case'up':case 2:if(!passable||(passable&&this.rpg.isPassable(self.x,self.y-1))){self.y-=1;}
else{is_passable=false;}
self.direction='up';if(!self.no_animation)self.animation('walkUp');break;case'left':case 4:if(!passable||(passable&&this.rpg.isPassable(self.x-1,self.y))){self.x-=1;}
else{is_passable=false;}
self.direction='left';if(!self.no_animation)self.animation('walkLeft');break;case'right':case 6:if(!passable||(passable&&this.rpg.isPassable(self.x+1,self.y))){self.x+=1;}
else{is_passable=false;}
self.direction='right';if(!self.no_animation)self.animation('walkRight');break;case'bottom':case 8:if(!passable||(passable&&this.rpg.isPassable(self.x,self.y+1))){self.y+=1;}
else{is_passable=false;}
self.direction='bottom';if(!self.no_animation)self.animation('walkBottom');break;}
self.moving=true;var event=self.getEventAround(self.name!="Player");if(event.left[0]!=null&&event.left[0].through){event.left[0].setIndexBefore(0);}
if(event.right[0]!=null&&event.right[0].through){event.right[0].setIndexBefore(0);}
if(event.up[0]!=null){var index=event.up[0].getIndex();if(self.getIndex()<index){self.setIndexAfter(index);}}
else if(event.bottom[0]!=null&&!event.bottom[0].through){var index=event.bottom[0].getIndex();if(self.getIndex()>index){self.setIndexBefore(index);}}
if(!is_passable){self.call('onFinishStep');}}
this.bind('onFinishStep',function(){pos++;if(pos>=dir.length){if(onFinishMove)onFinishMove();self.moving=false;}
else{moving();}});},moveReal:function(xfinal,yfinal,speed,easing){this._moveReal={xfinal:xfinal,yfinal:yfinal,speed:speed,acceleration:easing.acceleration}},jump:function(x_plus,y_plus){if(x_plus!=0||y_plus!=0){if(Math.abs(x_plus)>Math.abs(y_plus)){x_plus<0?this.setStopDirection('left'):this.setStopDirection('right');}
else{y_plus<0?this.setStopDirection('up'):this.setStopDirection('down')}}
var new_x=this.x+x_plus
var new_y=this.y+y_plus},getEventBeside:function(player){var x=this.x;var y=this.y;var event;switch(this.direction){case'up':y--;break;case'right':x++;break;case'left':x--;break;case'bottom':y++;break;}
if(player){if(this.rpg.player&&this.rpg.player.x==x&&this.rpg.player.y==y){event=this.rpg.player;}}
else{event=this.rpg.getEventByPosition(x,y);}
return event;},getEventAround:function(player){var i,x,y,find_player;var event_dir={};var dir=['up','right','left','bottom'];for(i=0;i<4;i++){find_player=false;x=this.x;y=this.y;switch(dir[i]){case'up':y--;break;case'right':x++;break;case'left':x--;break;case'bottom':y++;break;}
if(player){if(this.rpg.player&&this.rpg.player.x==x&&this.rpg.player.y==y){event_dir[dir[i]]=[this.rpg.player];find_player=true;}}
if(!find_player){event_dir[dir[i]]=this.rpg.getEventByPosition(x,y,true);}}
return event_dir;},actionType:function(type){var event;var self=this;switch(type){case'attack':event=this.getEventBeside();if(event&&event.actionBattle){if(event.actionBattle.mode=='invinsible'){if(this.rpg.actionBattle.eventInvinsible&&event.actionBattle.invinsible){this.rpg.actionBattle.eventInvinsible[event.actionBattle.invinsible](event);}
return;}
if(this.rpg.actionBattle.eventAffected&&event.actionBattle.affected){this.rpg.setEventMode(event,'affected');this.rpg.actionBattle.eventAffected[event.actionBattle.affected](event);}
if(event.actionBattle.hp<=0){this.rpg.setEventMode(event,'death');var anim=event.actionBattle.animation_death;if(anim){this.rpg.animations[anim].setPosition(event.x,event.y);this.rpg.animations[anim].play();}
event.fadeOut(50,function(){var item_drop=event.actionBattle.ennemyDead;var random=Math.floor(Math.random()*100);var min=0,max=0,drop_id=null;for(var i=0;i<item_drop.length;i++){max+=item_drop[i].probability;if(random>=min&&random<=max-1){drop_id=i;break;}
min+=max;}
self.rpg.removeEvent(event.id);if(drop_id!=null){var drop_name=item_drop[drop_id].name;var drop=self.rpg.actionBattle.ennemyDead?self.rpg.actionBattle.ennemyDead[item_drop[drop_id].call]:false;if(drop)drop(event,drop_name);}});}
else{event.displayBar(event.actionBattle.hp);}}
break;}},action:function(name,onFinish){var action=this.rpg.actions[name];var i=0;var self=this;var bmp_ini=this.bitmap;var anim,duration;if(this.action_prop[name]&&!isNaN(this.action_prop[name].wait)&&this.action_prop[name].wait<action.wait_finish){return false;}
if(this.inAction)return false;if(action.condition&&!action.condition())return false;if(action.onStart)action.onStart(this);this.changeBitmap(this.action_motions[name]);this.direction_fix=true;this.no_animation=true;this.inAction=true;this.blockMovement=action.block_movement;function playAnimation(animation_type){if(action[animation_type]){if(typeof action[animation_type]==="string"){anim=action[animation_type];}
else{anim=action[animation_type][self.direction];}
if(anim){self.rpg.animations[anim].setPosition(self.x,self.y);self.rpg.animations[anim].play();}}}
this.actionType(action.action);duration=action.duration_motion?action.duration_motion:1;playAnimation('animations');this.animation('walk',action.speed!==undefined?action.speed:10,function(bmp){if(i>0){playAnimation('animations');}
if(duration-1==i){bmp.paused=true;actionFinish();}
i++;},duration);function actionFinish(){self.blockMovement=false;self.direction_fix=false;self.no_animation=false;self.changeBitmap(bmp_ini);self.animation('stop');self.inAction=false;self.action_prop[name]={}
self.action_prop[name].wait=0;playAnimation('animation_finish');if(action.onFinish)action.onFinish(self);if(onFinish)onFinish(self);}},turn:function(){},changeBitmap:function(bitmap){this.sprite.removeChild(this.bitmap);this.bitmap=bitmap.clone();this.sprite.addChild(this.bitmap);},pathfinding:function(xfinal,yfinal){var x=this.x;var y=this.y;var array_dir=[];var list_ouvert={};list_ouvert[x]={};list_ouvert[x][y]=[null,null,null];var dis=this.distance(xfinal,yfinal,x,y);var list_ferme={};list_ferme[x]={};list_ferme[x][y]=[0,dis._final,dis.somme,0];var id=0;while(!(x==xfinal&&y==yfinal)){if(y==null||x==null)return[];id++;for(var i=0;i<4;i++){x=parseInt(x);y=parseInt(y);switch(i){case 0:var new_y=y-1;var new_x=x;break;case 1:var new_y=y;var new_x=x+1;break;case 2:var new_y=y+1;var new_x=x;break;case 3:var new_y=y;var new_x=x-1;break;}
if(!this.rpg.keyExist(list_ouvert,[new_x,new_y])){if(this.rpg.isPassable(new_x,new_y)||this.rpg.valueExist(this.tab_move,[new_x,new_y])){var dis=this.distance(xfinal,yfinal,new_x,new_y);if(list_ouvert[new_x]==undefined){list_ouvert[new_x]={};}
list_ouvert[new_x][new_y]=[dis.ini,dis._final,dis.somme,id];}}}
list_ouvert[x][y]=[null,null,null];var min_dis_final=min_somme_dis=200;var new_value=new_pos=[];for(var key_x in list_ouvert){for(var key_y in list_ouvert[key_x]){var value=list_ouvert[key_x][key_y];if(value[2]!=null){if(value[2]<=min_somme_dis&&value[1]<=min_dis_final){min_dis_final=value[1];min_somme_dis=value[2];new_value=value;new_pos=[key_x,key_y];}}}}
if(list_ferme[new_pos[0]]==undefined){list_ferme[new_pos[0]]={};}
list_ferme[new_pos[0]][new_pos[1]]=new_value;x=new_pos[0];y=new_pos[1];}
var min_dis_ini=200;while(min_dis_ini!=0){var min_dis_ini=min_somme_dis=min_dis_id=200;x=parseInt(x);y=parseInt(y);if(y==null||x==null)return[];for(var i=0;i<4;i++){switch(i){case 0:var new_y=y-1;var new_x=x;var dir=8;break;case 1:var new_y=y;var new_x=x+1;var dir=4;break;case 2:var new_y=y+1;var new_x=x;var dir=2;break;case 3:var new_y=y;var new_x=x-1;var dir=6;break;}
if(list_ferme[new_x]==undefined){list_ferme[new_x]={};}
var value=list_ferme[new_x][new_y];list_ferme[x][y]=null;if(value!=null){if(value[3]<min_dis_id){min_dis_id=value[3];min_dis_ini=value[0];var n_dir=dir;var n_new_x=new_x;var n_new_y=new_y;}}}
x=n_new_x;y=n_new_y;array_dir.push(n_dir);}
return array_dir.reverse();},pathMove:function(){var x=this.x;var y=this.y;var pos_temporaire=[];var pos_semi_tempor=[[x,y]];var path=0;var diff_x=pos_semi_tempor[0][0]-this.tactical.move;var diff_y=pos_semi_tempor[0][1]-this.tactical.move;this.tab_move=[];this.init_tab_move();while(path!=this.tactical.move&&!pos_semi_tempor.length==0){pos_temporaire=[];for(var i=0;i<pos_semi_tempor.length;i++){var new_pos_x=pos_semi_tempor[i][0];var new_pos_y=pos_semi_tempor[i][1];var tab_x=new_pos_x-diff_x;var tab_y=new_pos_y-diff_y;for(var j=0;j<4;j++){switch(j){case 0:if(this.rpg.isPassable(new_pos_x,new_pos_y+1)&&this.tab_move_passable[tab_x][tab_y+1]==-1){pos_temporaire.push([new_pos_x,new_pos_y+1]);this.tab_move.push([new_pos_x,new_pos_y+1]);this.tab_move_passable[tab_x][tab_y+1]=0;}
break;case 1:if(this.rpg.isPassable(new_pos_x+1,new_pos_y)&&this.tab_move_passable[tab_x+1][tab_y]==-1){pos_temporaire.push([new_pos_x+1,new_pos_y]);this.tab_move.push([new_pos_x+1,new_pos_y]);this.tab_move_passable[tab_x+1][tab_y]=0;}
break;case 2:if(this.rpg.isPassable(new_pos_x,new_pos_y-1)&&this.tab_move_passable[tab_x][tab_y-1]==-1){pos_temporaire.push([new_pos_x,new_pos_y-1]);this.tab_move.push([new_pos_x,new_pos_y-1]);this.tab_move_passable[tab_x][tab_y-1]=0;}
break;case 3:if(this.rpg.isPassable(new_pos_x-1,new_pos_y)&&this.tab_move_passable[tab_x-1][tab_y]==-1){pos_temporaire.push([new_pos_x-1,new_pos_y]);this.tab_move.push([new_pos_x-1,new_pos_y]);this.tab_move_passable[tab_x-1][tab_y]=0;}
break;}}}
pos_semi_tempor=this.rpg.clone(pos_temporaire);path+=1;}},setPosition:function(x,y){this.sprite.x=x*this.rpg.tile_w;this.sprite.y=y*this.rpg.tile_h;this.x=x;this.y=y;this.moving=false;this.animation('stop');},setIndexBefore:function(index){var i=index-1;if(i<0){i=0;}
this.setIndexAfter(i);},setIndexAfter:function(index){var layer=this.rpg.layer[3];layer.removeChild(this.sprite);layer.addChildAt(this.sprite,index);},getIndex:function(){return this.rpg.layer[3].getChildIndex(this.sprite);},createEventRelativeThis:function(name,prop){if(prop.x===undefined)prop.x=0;if(prop.y===undefined)prop.y=0;var x=this.x+prop.x;var y=this.y+prop.y;if(prop.dir!==undefined){var dir=prop.dir;switch(this.direction){case'up':y-=dir;break;case'left':x-=dir;break;case'right':x+=dir;break;case'bottom':y+=dir;break;}}
this.rpg.setEventPrepared(name,{x:x,y:y});var event=this.rpg.addEventPrepared(name);if(!event)return false;if(prop.move){event.moveReal(this.x*this.rpg.tile_w+this.rpg.tile_w*prop.x,this.y*this.rpg.tile_h+this.rpg.tile_h*prop.y,prop.speed,{acceleration:prop.acceleration,angleBound:prop.angleBound});}
var index=event.getIndex();if(event.y<this.y){this.setIndexAfter(index);}},commandsExit:function(){this.currentCmd=-2;},setPage:function(){var page_find=false;for(var i=this.pages.length-1;i>=0;i--){if(!page_find){if(this.pages[i].conditions==undefined){this.currentPage=i;page_find=true;}
else{var valid=true;var condition=this.pages[i].conditions;if(this.pages[i].conditions.switches!=undefined){valid&=this.rpg.switchesIsOn(condition.switches);}
if(this.pages[i].conditions.self_switch!=undefined){valid&=this.selfSwitchesIsOn(condition.self_switch);}
if(valid){this.currentPage=i;page_find=true;}}}}
return page_find;},onCommands:function(){var cmd=this.commands[this.currentCmd];if(cmd!=undefined){if(cmd.show_text){this.cmdShowText(cmd.show_text);}
else if(cmd.erase_event&&cmd.erase_event){this.cmdErase();}
else if(cmd.switches_on){this.cmdSwitches(cmd.switches_on,true);}
else if(cmd.switches_off){this.cmdSwitches(cmd.switches_off,false);}
else if(cmd.self_switch_on){this.cmdSelfSwitches(cmd.self_switch_on,true);}
else if(cmd.self_switch_off){this.cmdSelfSwitches(cmd.self_switch_off,false);}
else if(cmd.change_gold){this.cmdChangeGold(cmd.change_gold);}
else if(cmd.move_route){this.cmdMoveRoute(cmd.move_route);}
else if(cmd.show_animation){this.cmdShowAnimation(cmd.show_animation);}
else if(cmd.transfer_player){this.cmdTransferPlayer(cmd.transfer_player);}
else if(cmd.playSE){this.cmdPlaySE(cmd.playSE);}
else if(cmd.blink){this.cmdBlink(cmd.blink);}
else if(cmd.call){this.cmdCall(cmd.call);}}
else{this.currentCmd=0;this.call('onFinishCommand');if(this.trigger=='parallel_process'||this.trigger=='auto'){this.onCommands();}}},bind:function(name,func){this.func_trigger[name]=func;},call:function(name,params){if(this.func_trigger[name]!=undefined){this.func_trigger[name](params);}},nextCommand:function(){this.currentCmd++;this.onCommands();},cmdShowText:function(text){var self=this;var prevCmd=this.commands[this.currentCmd-1];var nextCmd=this.commands[this.currentCmd+1];var prop={skin:this.rpg.windowskinDefault,opacity:0.9,blockMovement:true,onLoad:function(){this.setText(text,"18px Arial","#FFF");this.setKeyClose('Space');this.open();}};if(!prevCmd||(prevCmd&&!prevCmd.show_text)){prop.fadeIn=40;}
if(!nextCmd||(nextCmd&&!nextCmd.show_text)){prop.fadeOut=40;}
var dialog=new Window(prop,this.rpg);dialog.onClose=function(){self.nextCommand();}},cmdErase:function(){this.rpg.removeEvent(this.id);this.nextCommand();},cmdSwitches:function(switches,bool){this.rpg.setSwitches(switches,bool);this.nextCommand();},cmdSelfSwitches:function(self_switches,bool){this.setSelfSwitch(self_switches,bool);this.nextCommand();},cmdChangeGold:function(gold){this.rpg.changeGold(gold);this.nextCommand();},cmdMoveRoute:function(dir){var self=this;var current_move=-1;nextRoute();function nextRoute(){current_move++;if(dir[current_move]!==undefined){switch(dir[current_move]){case 2:case 4:case 6:case 8:case'up':case'left':case'right':case'bottom':self.move(dir,function(){nextRoute();},true);break;case'step_backward':self.moveAwayFromPlayer(function(){nextRoute();},true);break;}}
else{self.animation('stop');self.nextCommand();}}},cmdShowAnimation:function(anim){var self=this;anim.target
if(this.rpg.animations[anim.name]){var target=this._target(anim.target);if(anim.zoom){this.rpg.animations[anim.name].setZoom(anim.zoom);}
this.rpg.animations[anim.name].setPositionEvent(target);if(anim.wait){this.rpg.animations[anim.name].play(onAnimationFinish);}
else{this.rpg.animations[anim.name].play();}}
if(!anim.wait){onAnimationFinish();}
function onAnimationFinish(){self.nextCommand();}},cmdTransferPlayer:function(map){var m=this.rpg.getPreparedMap(map.name);if(m){if(!m.propreties.player)m.propreties.player={};m.propreties.player.x=map.x;m.propreties.player.y=map.y;this.rpg.callMap(map.name);}
this.nextCommand();},cmdPlaySE:function(prop){var self=this;this.rpg.playSE(prop.filename,function(){self.nextCommand();});},cmdBlink:function(prop){var target=this._target(prop.target);if(prop.wait){target.blink(prop.duration,prop.frequence,this.nextCommand);}
else{target.blink(prop.duration,prop.frequence);this.nextCommand();}},cmdCall:function(call){this.rpg.call("eventCall_"+call,this);this.nextCommand();},_target:function(target){var _target=this;if(target){if(target=='Player'){_target=this.rpg.player;}
else{_target=this.rpg.getEventByName(target);}}
return _target;}}
function Player(prop,rpg){var speed=prop.speed?prop.speed:4;var prop_event=[{name:'Player',x:prop.x,y:prop.y,regX:prop.regX,regY:prop.regY},[{character_hue:prop.filename,direction:prop.direction?prop.direction:'bottom',trigger:'player',no_animation:prop.no_animation,speed:speed,commands:[],action_battle:prop.actionBattle}]];rpg.speedScrolling=speed;this.keyBuffer=0;this.moving=false;this.keypress=false;this.freeze=false;this.transfert=[];this.inTransfert=false;this.parent=Event;this.parent(prop_event,rpg);this.actions=prop.actions;this.handleKeyPress();this.tickPlayer=this._tick;this.old_direction=this.direction;}
var p=Player.prototype=new Event();p.handleKeyPress=function(){var self=this;function keytype(code){switch(code){case 97:case 65:return'A';break;case 122:return'Z';break;case 101:return'E';break;case 113:return'Q';break;case 13:return'Enter';break;case 16:return'Shift';break;case 17:return'Ctrl';break;case 18:return'Alt';break;case 19:return'Pause';break;case 32:return'Space';break;}}
function keyaction(type,e){var i,act;for(i=0;i<self.actions.length;i++){act=self.rpg.actions[self.actions[i]];if(act[type]){if(self.rpg.valueExist(act[type],keytype(e.which))){self.action(self.actions[i]);}}}}
document.onkeydown=function(e){var blockMovement=self.movementIsBlocked();if(!self.freeze&&!blockMovement){if(!blockMovement){if(e.keyCode>=37&&e.keyCode<=40){self.keyBuffer=e.keyCode;}}
keyaction('keydown',e);}},document.onkeyup=function(e){if(self.freeze)return false;if(self.keyBuffer==e.keyCode){self.keyBuffer=0;}
keyaction('keyup',e);}
document.onkeypress=function(e){var blockMovement=self.movementIsBlocked();var keyCode=e.which;var dialog_open=false;var dialog;for(var i=0;i<self.rpg.currentWindows.length;i++){dialog=self.rpg.currentWindows[i];if(dialog.isOpen){dialog_open=true;if(dialog.keyclose!=null&&dialog.keyclose==keytype(keyCode)){dialog.close();}}}
if(self.freeze&&!blockMovement)return false;if(keyCode==32||keyCode==13){if(!dialog_open){self.interactionEventBeside('action_button');}}
keyaction('keypress',e);}}
p.movementIsBlocked=function(){var blockMovement=false;if(this.rpg.inAction)return false;for(var i=0;i<this.rpg.currentWindows.length;i++){if(this.rpg.currentWindows[i].blockMovement){blockMovement=true;break;}}
return blockMovement;}
p._tick=function(){var self=this;if(this.keyBuffer&&!this.moving){var key=this.keyBuffer;var direction=0;switch(key){case 37:if(this.rpg.isPassable(this.x-1,this.y)){direction=4;}
this.direction='left';break;case 38:if(this.rpg.isPassable(this.x,this.y-1)){direction=2;}
this.direction='up';break;case 39:if(this.rpg.isPassable(this.x+1,this.y)){direction=6;}
this.direction='right';break;case 40:if(this.rpg.isPassable(this.x,this.y+1)){direction=8;}
this.direction='bottom';break;}
if(direction==0&&!this.moving&&!this.inAction){this.animation('stop');}
this.interactionEventBeside('contact');if(!self.moving&&direction!=0){self.moving=true;self.move([direction],function(){self.moving=false;if(self.keyBuffer==0&&!self.inAction){self.animation('stop');}});}
for(var i=0;i<this.transfert.length;i++){var dy=this.transfert[i].dy===undefined?0:this.transfert[i].dy;var dx=this.transfert[i].dx===undefined?0:this.transfert[i].dx;var direction=this.transfert[i].direction?this.direction==this.transfert[i].direction:true;var transfert_y,transfert_x;if(dy<0){transfert_y=this.y>=this.transfert[i].y+dy&&this.y<=this.transfert[i].y;}
else{transfert_y=this.y>=this.transfert[i].y&&this.y<=this.transfert[i].y+dy;}
if(dx<0){transfert_x=this.x>=this.transfert[i].x+dx&&this.x<=this.transfert[i].x;}
else{transfert_x=this.x>=this.transfert[i].x&&this.x<=this.transfert[i].x+dx;}
if(transfert_y&&transfert_x&&!this.inTransfert&&direction){var map=this.rpg.getPreparedMap(this.transfert[i].map);if(map){if(!map.propreties.player)map.propreties.player={};map.propreties.player.x=this.transfert[i].x_final+(this.transfert[i].parallele?Math.abs(this.x-this.transfert[i].x):0);map.propreties.player.y=this.transfert[i].y_final+(this.transfert[i].parallele?Math.abs(this.y-this.transfert[i].y):0);var call=true;this.moving=false;this.keyBuffer=0;if(this.transfert[i].callback){call=this.transfert[i].callback();}
if(call){this.inTransfert=true;this.rpg.callMap(map.name);}
break;}}}}}
p.interactionEventBeside=function(trigger){var i,event,self=this;var e=this.getEventAround()[this.direction];for(i=0;i<e.length;i++){event=e[i];if(event!=null){if(event.trigger==trigger){if(!event.through){this.keyBuffer=0;}
this.freeze=true;var ini_dir=event.direction;if(!event.direction_fix){event.turnTowardPlayer();}
var currentPage=event.currentPage;event.moveStop();event.bind('onFinishCommand',function(){if(event.currentPage==currentPage){event.setStopDirection(ini_dir);event.moveStart();event.moveType();}
self.freeze=false;});event.onCommands();}}}}
p.setTransfert=function(prop){this.transfert=prop;}