1+ /*:
2+ * @plugindesc Fail to load images, audio, movies and map data.
3+ * @author RM CoreScript team
4+ *
5+ * @param failImage
6+ * @desc Probability of image loading failure (0-1)
7+ * @default 0.5
8+ *
9+ * @param failAudio
10+ * @desc Probability of audio loading failure (0-1)
11+ * @default 0.5
12+ *
13+ * @param failMovie
14+ * @desc Probability of movie loading failure (0-1)
15+ * @default 0.5
16+ *
17+ * @param failMapData
18+ * @desc Probability of map data loading failure (0-1)
19+ * @default 0.5
20+ */
21+
22+ /*:ja
23+ * @plugindesc 画像や音声、動画やマップデータの読み込みに失敗します。
24+ * @author RM CoreScript team
25+ *
26+ * @param failImage
27+ * @desc 画像の読み込みに失敗する確率 (0-1)
28+ * @default 0.5
29+ *
30+ * @param failAudio
31+ * @desc 音声の読み込みに失敗する確率 (0-1)
32+ * @default 0.5
33+ *
34+ * @param failMovie
35+ * @desc 動画の読み込みに失敗する確率 (0-1)
36+ * @default 0.5
37+ *
38+ * @param failMapData
39+ * @desc マップデータ読み込みに失敗する確率 (0-1)
40+ * @default 0.5
41+ */
42+
43+ ( function ( ) {
44+ function toNumber ( str , def ) {
45+ return isNaN ( str ) ? def : + ( str || def ) ;
46+ }
47+
48+ var parameters = PluginManager . parameters ( 'Debug_FailLoading' ) ;
49+ var failImage = toNumber ( parameters [ 'failImage' ] , 0.5 ) ;
50+ var failAudio = toNumber ( parameters [ 'failAudio' ] , 0.5 ) ;
51+ var failMovie = toNumber ( parameters [ 'failMovie' ] , 0.5 ) ;
52+ var failMapData = toNumber ( parameters [ 'failMapData' ] , 0.5 ) ;
53+
54+ var _Bitmap_onLoad = Bitmap . prototype . _onLoad ;
55+ Bitmap . prototype . _onLoad = function ( ) {
56+ if ( Math . random ( ) < failImage ) {
57+ this . _image . onerror ( ) ;
58+ } else {
59+ _Bitmap_onLoad . apply ( this , arguments ) ;
60+ }
61+ } ;
62+
63+ WebAudio . prototype . _load = function ( url ) {
64+ if ( WebAudio . _context ) {
65+ var xhr = new XMLHttpRequest ( ) ;
66+ if ( Decrypter . hasEncryptedAudio ) url = Decrypter . extToEncryptExt ( url ) ;
67+ xhr . open ( 'GET' , url ) ;
68+ xhr . responseType = 'arraybuffer' ;
69+ xhr . onload = function ( ) {
70+ if ( Math . random ( ) < failAudio ) {
71+ xhr . onerror ( ) ;
72+ } else if ( xhr . status < 400 ) {
73+ this . _onXhrLoad ( xhr ) ;
74+ }
75+ } . bind ( this ) ;
76+ xhr . onerror = this . _loader ;
77+ xhr . send ( ) ;
78+ }
79+ } ;
80+
81+ var _Graphics_onVideoLoad = Graphics . _onVideoLoad ;
82+ Graphics . _onVideoLoad = function ( ) {
83+ if ( Math . random ( ) < failMovie ) {
84+ this . _video . onerror ( ) ;
85+ } else {
86+ _Graphics_onVideoLoad . apply ( this , arguments ) ;
87+ }
88+ } ;
89+
90+ DataManager . loadDataFile = function ( name , src ) {
91+ var xhr = new XMLHttpRequest ( ) ;
92+ var url = 'data/' + src ;
93+ xhr . open ( 'GET' , url ) ;
94+ xhr . overrideMimeType ( 'application/json' ) ;
95+ xhr . onload = function ( ) {
96+ if ( name === '$dataMap' && Math . random ( ) < failMapData ) {
97+ xhr . onerror ( ) ;
98+ } else if ( xhr . status < 400 ) {
99+ window [ name ] = JSON . parse ( xhr . responseText ) ;
100+ DataManager . onLoad ( window [ name ] ) ;
101+ }
102+ } ;
103+ xhr . onerror = this . _mapLoader || function ( ) {
104+ DataManager . _errorUrl = DataManager . _errorUrl || url ;
105+ } ;
106+ window [ name ] = null ;
107+ xhr . send ( ) ;
108+ } ;
109+ } ) ( ) ;
0 commit comments