R3EXS 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/R3EXS/RGSS3.rb CHANGED
@@ -1,1457 +1,1457 @@
1
- # frozen_string_literal: true
2
-
3
- # RPG Maker VX Ace Color 类
4
- class Color
5
-
6
- # 初始化时接受以下几种参数情况:
7
- # - 无参数时,默认 (0, 0, 0, 0)
8
- # - 3 个参数时,默认为 (red, green, blue, 255)
9
- # - 4 个参数时,指定 (red, green, blue, alpha)
10
- #
11
- # @param args [Array<Integer>] red, green, blue, alpha
12
- # - red: 红色通道的值 (0-255)
13
- # - green: 绿色通道的值 (0-255)
14
- # - blue: 蓝色通道的值 (0-255)
15
- # - alpha: 可选,透明度通道的值 (0-255),默认为 255
16
- # @return [Color]
17
- def initialize(*args)
18
- case args.length
19
- when 0 # 无参数
20
- set(0, 0, 0, 0)
21
- when 3 # 3 个参数, alpha 默认为 255
22
- set(*args)
23
- when 4 # 4 个参数, 分别为 red, green, blue, alpha
24
- set(*args)
25
- else
26
- raise ArgumentError, "Invalid arguments for initialize method"
27
- end
28
- end
29
-
30
- # 设置 Color 对象的值
31
- # - 无参数时,默认 (0, 0, 0, 0)
32
- # - 3 个参数时,默认为 (red, green, blue, 255)
33
- # - 4 个参数时,指定 (red, green, blue, alpha)
34
- #
35
- # @param args [Array<Integer>] red, green, blue, alpha
36
- # - red: 红色通道的值 (0-255)
37
- # - green: 绿色通道的值 (0-255)
38
- # - blue: 蓝色通道的值 (0-255)
39
- # - alpha: 可选,透明度通道的值 (0-255),默认为 255
40
- # @return [void]
41
- def set(*args)
42
- case args.length
43
- when 1 # 一个参数, 为 Color 对象
44
- if args[0].is_a?(Color)
45
- other_color = args[0]
46
- self.red = other_color.red
47
- self.green = other_color.green
48
- self.blue = other_color.blue
49
- self.alpha = other_color.alpha
50
- else
51
- raise ArgumentError, "Invalid arguments for set method"
52
- end
53
- when 3 # 三个参数, 分别为 red, green, blue (alpha 默认为 255)
54
- self.red = args[0]
55
- self.green = args[1]
56
- self.blue = args[2]
57
- self.alpha = 255.0
58
- when 4 # 四个参数, 分别为 red, green, blue, alpha
59
- self.red = args[0]
60
- self.green = args[1]
61
- self.blue = args[2]
62
- self.alpha = args[3]
63
- else
64
- raise ArgumentError, "Invalid arguments for set method"
65
- end
66
- end
67
-
68
- # 序列化 Color 对象
69
- #
70
- # @param level [Integer] 序列化的级别
71
- # @return [String]
72
- def _dump(level)
73
- [@red, @green, @blue, @alpha].pack('D4')
74
- end
75
-
76
- # 反序列化 Color 对象
77
- #
78
- # @param obj [String] 序列化后的字符串
79
- # @return [Color]
80
- def Color._load(obj)
81
- new(*obj.unpack('D4'))
82
- end
83
-
84
- # 设置 red 通道的值,限制在 0 到 255 之间
85
- #
86
- # @param value [Float] 新的 red 通道值
87
- # @return [void]
88
- def red=(value)
89
- @red = [[value, 0.0].max, 255.0].min.to_i
90
- end
91
-
92
- # 设置 green 通道的值,限制在 0 到 255 之间
93
- #
94
- # @param value [Float] 新的 green 通道值
95
- # @return [void]
96
- def green=(value)
97
- @green = [[value, 0.0].max, 255.0].min.to_i
98
- end
99
-
100
- # 设置 blue 通道的值,限制在 0 到 255 之间
101
- #
102
- # @param value [Float] 新的 blue 通道值
103
- # @return [void]
104
- def blue=(value)
105
- @blue = [[value, 0.0].max, 255.0].min.to_i
106
- end
107
-
108
- # 设置 alpha 通道的值,限制在 0 到 255 之间
109
- #
110
- # @param value [Float] 新的 alpha 通道值
111
- # @return [void]
112
- def alpha=(value)
113
- @alpha = [[value, 0.0].max, 255.0].min
114
- end
115
-
116
- # red 通道的值
117
- #
118
- # @return [Integer]
119
- attr_reader :red
120
-
121
- # green 通道的值
122
- #
123
- # @return [Integer]
124
- attr_reader :green
125
-
126
- # blue 通道的值
127
- #
128
- # @return [Integer]
129
- attr_reader :blue
130
-
131
- # alpha 通道的值
132
- #
133
- # @return [Integer]
134
- attr_reader :alpha
135
- end
136
-
137
- # RPG Maker VX Ace Tone 类
138
- class Tone
139
-
140
- # 初始化时接受以下几种参数情况:
141
- # - 无参数时,默认 (0, 0, 0, 0)
142
- # - 3 个参数时,默认为 (red, green, blue, 0)
143
- # - 4 个参数时,指定 (red, green, blue, gray)
144
- #
145
- # @param args [Array<Integer>] red, green, blue, gray
146
- # - red: 红色通道的值 (-255-255)
147
- # - green: 绿色通道的值 (-255-255)
148
- # - blue: 蓝色通道的值 (-255-255)
149
- # - gray: 可选,灰度通道的值 (0-255),默认为 0
150
- # @return [Tone]
151
- def initialize(*args)
152
- case args.length
153
- when 0 # 无参数
154
- set(0, 0, 0, 0)
155
- when 3 # 3 个参数, gray 默认为 0
156
- set(*args)
157
- when 4 # 4 个参数, 分别为 red, green, blue, gray
158
- set(*args)
159
- else
160
- raise ArgumentError, "Invalid arguments for initialize method"
161
- end
162
- end
163
-
164
- # 设置 Tone 对象的值
165
- # - 无参数时,默认 (0, 0, 0, 0)
166
- # - 3 个参数时,默认为 (red, green, blue, 0)
167
- # - 4 个参数时,指定 (red, green, blue, gray)
168
- #
169
- # @param args [Array<Integer>] red, green, blue, gray
170
- # - red: 红色通道的值 (-255-255)
171
- # - green: 绿色通道的值 (-255-255)
172
- # - blue: 蓝色通道的值 (-255-255)
173
- # - gray: 可选,透明度通道的值 (0-255),默认为 0
174
- # @return [void]
175
- def set(*args)
176
- case args.length
177
- when 1 # 一个参数, 为 Tone 对象
178
- if args[0].is_a?(Tone)
179
- self.red = args[0].red
180
- self.green = args[0].green
181
- self.blue = args[0].blue
182
- self.gray = args[0].gray
183
- else
184
- raise ArgumentError, "Invalid arguments for set method"
185
- end
186
- when 3 # 三个参数, 分别为 red, green, blue (gray 默认为 0)
187
- self.red = args[0]
188
- self.green = args[1]
189
- self.blue = args[2]
190
- self.gray = 0.0
191
- when 4 # 四个参数, 分别为 red, green, blue, gray
192
- self.red = args[0]
193
- self.green = args[1]
194
- self.blue = args[2]
195
- self.gray = args[3]
196
- else
197
- raise ArgumentError, "Invalid arguments for set method"
198
- end
199
- end
200
-
201
- # 序列化 Tone 对象
202
- #
203
- # @param level [Integer] 序列化的级别
204
- # @return [String]
205
- def _dump(level)
206
- [@red, @green, @blue, @gray].pack('D4')
207
- end
208
-
209
- # 反序列化 Tone 对象
210
- #
211
- # @param obj [String] 序列化后的字符串
212
- # @return [Tone]
213
- def Tone._load(obj)
214
- new(*obj.unpack('D4'))
215
- end
216
-
217
- # 设置 red 通道的值,限制在 -255 到 255 之间
218
- #
219
- # @param value [Float] 新的 red 通道值
220
- # @return [void]
221
- def red=(value)
222
- @red = [[value, -255.0].max, 255.0].min.to_i
223
- end
224
-
225
- # 设置 green 通道的值,限制在 -255 到 255 之间
226
- #
227
- # @param value [Float] 新的 green 通道值
228
- # @return [void]
229
- def green=(value)
230
- @green = [[value, -255.0].max, 255.0].min.to_i
231
- end
232
-
233
- # 设置 blue 通道的值,限制在 -255 到 255 之间
234
- #
235
- # @param value [Float] 新的 blue 通道值
236
- # @return [void]
237
- def blue=(value)
238
- @blue = [[value, -255.0].max, 255.0].min.to_i
239
- end
240
-
241
- # 设置 alpha 通道的值,限制在 0 到 255 之间
242
- #
243
- # @param value [Float] 新的 alpha 通道值
244
- # @return [void]
245
- def gray=(value)
246
- @gray = [[value, 0.0].max, 255.0].min.to_i
247
- end
248
-
249
- # red 通道的值
250
- #
251
- # @return [Integer]
252
- attr_reader :red
253
-
254
- # green 通道的值
255
- #
256
- # @return [Integer]
257
- attr_reader :green
258
-
259
- # blue 通道的值
260
- #
261
- # @return [Integer]
262
- attr_reader :blue
263
-
264
- # gray 通道的值
265
- #
266
- # @return [Integer]
267
- attr_reader :gray
268
-
269
- end
270
-
271
- # RPG Maker VX Ace Table 类
272
- #
273
- # Table 是一个多维数组,每个元素都是带符号的两字节整数(int16_t), 也就是 -32,768~32,767 之间的整数
274
- #
275
- # Ruby Array 类在处理大量信息时效率很差,因此使用了此类。
276
- class Table
277
-
278
- # 初始化 Table 对象,指定多维数组各维的长度。生成的数组可以是 1~3 维,甚至是没有元素的数组。
279
- #
280
- # 初始化时传入的参数个数决定了生成的数组维度:
281
- # - 最少 1 维,最多 3 维。
282
- # - `ysize` 和 `zsize` 参数可以省略,默认值为 1。
283
- #
284
- # 注意:该类没有参数检查,请确保 `ysize` 和 `zsize` 的值在 `[-32768, 32767]` 范围内。
285
- #
286
- # @param xsize [Integer] 第一维的长度(必需)
287
- # @param ysize [Integer, nil] 第二维的长度(可选,默认值为 nil)
288
- # @param zsize [Integer, nil] 第三维的长度(可选,默认值为 nil)
289
- # @return [Table]
290
- def initialize(xsize, ysize = nil, zsize = nil)
291
- init_attr(xsize, ysize, zsize)
292
- end
293
-
294
- # 设置各维的长度
295
- #
296
- # @param xsize [Integer] 第一维的长度
297
- # @param ysize [Integer, nil] 第二维的长度(如果为 nil,则默认为 1)
298
- # @param zsize [Integer, nil] 第三维的长度(如果为 nil,则默认为 1)
299
- # @return [void]
300
- def init_attr(xsize, ysize, zsize)
301
- @dim = 1 + (ysize.nil? ? 0 : 1) + (zsize.nil? ? 0 : 1)
302
- @xsize = xsize
303
- @ysize = ysize.nil? ? 1 : ysize
304
- @zsize = zsize.nil? ? 1 : zsize
305
- @data = Array.new(@xsize * @ysize * @zsize, 0)
306
- end
307
-
308
- # 获取指定位置的元素值
309
- #
310
- # @param x [Integer] 第一维的长度(必需)
311
- # @param y [Integer] 第二维的长度(可选,默认值为 0)
312
- # @param z [Integer] 第三维的长度(可选,默认值为 0)
313
- # @return [Integer]
314
- def [](x, y = 0, z = 0)
315
- @data[x + y * @xsize + z * @xsize * @ysize]
316
- end
317
-
318
- # 设置指定位置的元素值
319
- #
320
- # @param args [Array<Integer>] x, y, z, v
321
- # - x: 第一维的长度(必需)
322
- # - y: 第二维的长度(可选,默认值为 nil)
323
- # - z: 第三维的长度(可选,默认值为 nil)
324
- # - v: 新的元素值
325
- # @return [void]
326
- def []=(*args)
327
- v = args.pop
328
- x, y, z = args
329
- y ||= 0
330
- z ||= 0
331
- @data[x + y * @xsize + z * @xsize * @ysize] = v
332
- end
333
-
334
- # 扩容 Table 对象,保留原有数据
335
- #
336
- # @param xsize [Integer] 第一维的长度(必需)
337
- # @param ysize [Integer, nil] 第二维的长度(可选,默认值为 nil)
338
- # @param zsize [Integer, nil] 第三维的长度(可选,默认值为 nil)
339
- # @return [void]
340
- def resize(xsize, ysize = nil, zsize = nil)
341
- old_data = @data.dup
342
- old_xsize, old_ysize, old_zsize = @xsize, @ysize, @zsize
343
- init_attr(xsize, ysize, zsize)
344
- (0...[old_xsize, @xsize].min).each { |x|
345
- (0...[old_ysize, @ysize].min).each { |y|
346
- (0...[old_zsize, @zsize].min).each { |z|
347
- @data[x + y * @xsize + z * @xsize * @ysize] = old_data[x + y * old_xsize + z * old_xsize * old_ysize]
348
- }
349
- }
350
- }
351
- end
352
-
353
- # 序列化 Table 对象
354
- #
355
- # @param level [Integer] 序列化的级别
356
- # @return [String]
357
- def _dump(level)
358
- s = [@dim, @xsize, @ysize, @zsize, @xsize * @ysize * @zsize].pack('LLLLL')
359
- @data.each do |d|
360
- s << [d].pack('s')
361
- end
362
- s
363
- end
364
-
365
- # 反序列化 Table 对象
366
- #
367
- # @param obj [String] 序列化后的字符串
368
- # @return [Table]
369
- def Table._load(obj)
370
- # 从序列化字符串中解包维度信息
371
- dim, xsize, ysize, zsize, total_size = *obj[0, 20].unpack('LLLLL')
372
- # 初始化 Table 对象
373
- table = Table.new(*[xsize, ysize, zsize].first(dim))
374
- table.data = obj[20, total_size * 2].unpack("s#{total_size}")
375
- # 现在 @data 已经从序列化字符串中完整提取
376
- table
377
- end
378
-
379
- # 数据数组
380
- #
381
- # @return [Array<Integer>]
382
- attr_accessor :data
383
-
384
- # 维度
385
- #
386
- # @return [Integer]
387
- attr_accessor :dim
388
-
389
- # 第一维的长度
390
- #
391
- # @return [Integer]
392
- attr_accessor :xsize
393
-
394
- # 第二维的长度
395
- #
396
- # @return [Integer]
397
- attr_accessor :ysize
398
-
399
- # 第三维的长度
400
- #
401
- # @return [Integer]
402
- attr_accessor :zsize
403
- end
404
-
405
- # RPG Maker VX Ace 的RPG 模块
406
- module RPG
407
- class Map
408
- def initialize(width, height)
409
- @display_name = ''
410
- @tileset_id = 1
411
- @width = width
412
- @height = height
413
- @scroll_type = 0
414
- @specify_battleback = false
415
- @battleback_floor_name = ''
416
- @battleback_wall_name = ''
417
- @autoplay_bgm = false
418
- @bgm = RPG::BGM.new
419
- @autoplay_bgs = false
420
- @bgs = RPG::BGS.new('', 80)
421
- @disable_dashing = false
422
- @encounter_list = []
423
- @encounter_step = 30
424
- @parallax_name = ''
425
- @parallax_loop_x = false
426
- @parallax_loop_y = false
427
- @parallax_sx = 0
428
- @parallax_sy = 0
429
- @parallax_show = false
430
- @note = ''
431
- @data = Table.new(width, height, 4)
432
- @events = {}
433
- end
434
-
435
- attr_accessor :display_name
436
- attr_accessor :tileset_id
437
- attr_accessor :width
438
- attr_accessor :height
439
- attr_accessor :scroll_type
440
- attr_accessor :specify_battleback
441
- attr_accessor :battleback1_name
442
- attr_accessor :battleback2_name
443
- attr_accessor :autoplay_bgm
444
- attr_accessor :bgm
445
- attr_accessor :autoplay_bgs
446
- attr_accessor :bgs
447
- attr_accessor :disable_dashing
448
- attr_accessor :encounter_list
449
- attr_accessor :encounter_step
450
- attr_accessor :parallax_name
451
- attr_accessor :parallax_loop_x
452
- attr_accessor :parallax_loop_y
453
- attr_accessor :parallax_sx
454
- attr_accessor :parallax_sy
455
- attr_accessor :parallax_show
456
- attr_accessor :note
457
- attr_accessor :data
458
- attr_accessor :events
459
- end
460
-
461
- class Map::Encounter
462
- def initialize
463
- @troop_id = 1
464
- @weight = 10
465
- @region_set = []
466
- end
467
-
468
- attr_accessor :troop_id
469
- attr_accessor :weight
470
- attr_accessor :region_set
471
- end
472
-
473
- class MapInfo
474
- def initialize
475
- @name = ''
476
- @parent_id = 0
477
- @order = 0
478
- @expanded = false
479
- @scroll_x = 0
480
- @scroll_y = 0
481
- end
482
-
483
- attr_accessor :name
484
- attr_accessor :parent_id
485
- attr_accessor :order
486
- attr_accessor :expanded
487
- attr_accessor :scroll_x
488
- attr_accessor :scroll_y
489
- end
490
-
491
- class Event
492
- def initialize(x, y)
493
- @id = 0
494
- @name = ''
495
- @x = x
496
- @y = y
497
- @pages = [RPG::Event::Page.new]
498
- end
499
-
500
- attr_accessor :id
501
- attr_accessor :name
502
- attr_accessor :x
503
- attr_accessor :y
504
- attr_accessor :pages
505
- end
506
-
507
- class Event::Page
508
- def initialize
509
- @condition = RPG::Event::Page::Condition.new
510
- @graphic = RPG::Event::Page::Graphic.new
511
- @move_type = 0
512
- @move_speed = 3
513
- @move_frequency = 3
514
- @move_route = RPG::MoveRoute.new
515
- @walk_anime = true
516
- @step_anime = false
517
- @direction_fix = false
518
- @through = false
519
- @priority_type = 0
520
- @trigger = 0
521
- @list = [RPG::EventCommand.new]
522
- end
523
-
524
- attr_accessor :condition
525
- attr_accessor :graphic
526
- attr_accessor :move_type
527
- attr_accessor :move_speed
528
- attr_accessor :move_frequency
529
- attr_accessor :move_route
530
- attr_accessor :walk_anime
531
- attr_accessor :step_anime
532
- attr_accessor :direction_fix
533
- attr_accessor :through
534
- attr_accessor :priority_type
535
- attr_accessor :trigger
536
- attr_accessor :list
537
- end
538
-
539
- class Event::Page::Condition
540
- def initialize
541
- @switch1_valid = false
542
- @switch2_valid = false
543
- @variable_valid = false
544
- @self_switch_valid = false
545
- @item_valid = false
546
- @actor_valid = false
547
- @switch1_id = 1
548
- @switch2_id = 1
549
- @variable_id = 1
550
- @variable_value = 0
551
- @self_switch_ch = 'A'
552
- @item_id = 1
553
- @actor_id = 1
554
- end
555
-
556
- attr_accessor :switch1_valid
557
- attr_accessor :switch2_valid
558
- attr_accessor :variable_valid
559
- attr_accessor :self_switch_valid
560
- attr_accessor :item_valid
561
- attr_accessor :actor_valid
562
- attr_accessor :switch1_id
563
- attr_accessor :switch2_id
564
- attr_accessor :variable_id
565
- attr_accessor :variable_value
566
- attr_accessor :self_switch_ch
567
- attr_accessor :item_id
568
- attr_accessor :actor_id
569
- end
570
-
571
- class Event::Page::Graphic
572
- def initialize
573
- @tile_id = 0
574
- @character_name = ''
575
- @character_index = 0
576
- @direction = 2
577
- @pattern = 0
578
- end
579
-
580
- attr_accessor :tile_id
581
- attr_accessor :character_name
582
- attr_accessor :character_index
583
- attr_accessor :direction
584
- attr_accessor :pattern
585
- end
586
-
587
- class EventCommand
588
- def initialize(code = 0, indent = 0, parameters = [])
589
- @code = code
590
- @indent = indent
591
- @parameters = parameters
592
- end
593
-
594
- attr_accessor :code
595
- attr_accessor :indent
596
- attr_accessor :parameters
597
- end
598
-
599
- class MoveRoute
600
- def initialize
601
- @repeat = true
602
- @skippable = false
603
- @wait = false
604
- @list = [RPG::MoveCommand.new]
605
- end
606
-
607
- attr_accessor :repeat
608
- attr_accessor :skippable
609
- attr_accessor :wait
610
- attr_accessor :list
611
- end
612
-
613
- class MoveCommand
614
- def initialize(code = 0, parameters = [])
615
- @code = code
616
- @parameters = parameters
617
- end
618
-
619
- attr_accessor :code
620
- attr_accessor :parameters
621
- end
622
-
623
- class BaseItem
624
- def initialize
625
- @id = 0
626
- @name = ''
627
- @icon_index = 0
628
- @description = ''
629
- @features = []
630
- @note = ''
631
- end
632
-
633
- attr_accessor :id
634
- attr_accessor :name
635
- attr_accessor :icon_index
636
- attr_accessor :description
637
- attr_accessor :features
638
- attr_accessor :note
639
- end
640
-
641
- class Actor < BaseItem
642
-
643
- def initialize
644
- super
645
- @nickname = ''
646
- @class_id = 1
647
- @initial_level = 1
648
- @max_level = 99
649
- @character_name = ''
650
- @character_index = 0
651
- @face_name = ''
652
- @face_index = 0
653
- @equips = [0, 0, 0, 0, 0]
654
- end
655
-
656
- attr_accessor :nickname
657
- attr_accessor :class_id
658
- attr_accessor :initial_level
659
- attr_accessor :max_level
660
- attr_accessor :character_name
661
- attr_accessor :character_index
662
- attr_accessor :face_name
663
- attr_accessor :face_index
664
- attr_accessor :equips
665
- end
666
-
667
- class Class < BaseItem
668
- def initialize
669
- super
670
- @exp_params = [30, 20, 30, 30]
671
- @params = Table.new(8, 100)
672
- (1..99).each do |i|
673
- @params[0, i] = 400 + i * 50
674
- @params[1, i] = 80 + i * 10
675
- (2..5).each { |j| @params[j, i] = 15 + i * 5 / 4 }
676
- (6..7).each { |j| @params[j, i] = 30 + i * 5 / 2 }
677
- end
678
- @learnings = []
679
- @features.push(RPG::BaseItem::Feature.new(23, 0, 1))
680
- @features.push(RPG::BaseItem::Feature.new(22, 0, 0.95))
681
- @features.push(RPG::BaseItem::Feature.new(22, 1, 0.05))
682
- @features.push(RPG::BaseItem::Feature.new(22, 2, 0.04))
683
- @features.push(RPG::BaseItem::Feature.new(41, 1))
684
- @features.push(RPG::BaseItem::Feature.new(51, 1))
685
- @features.push(RPG::BaseItem::Feature.new(52, 1))
686
- end
687
-
688
- def exp_for_level(level)
689
- lv = level.to_f
690
- basis = @exp_params[0].to_f
691
- extra = @exp_params[1].to_f
692
- acc_a = @exp_params[2].to_f
693
- acc_b = @exp_params[3].to_f
694
- return (basis * ((lv - 1) ** (0.9 + acc_a / 250)) * lv * (lv + 1) /
695
- (6 + lv ** 2 / 50 / acc_b) + (lv - 1) * extra).round.to_i
696
- end
697
-
698
- attr_accessor :exp_params
699
- attr_accessor :params
700
- attr_accessor :learnings
701
- end
702
-
703
- class UsableItem < BaseItem
704
- def initialize
705
- super
706
- @scope = 0
707
- @occasion = 0
708
- @speed = 0
709
- @success_rate = 100
710
- @repeats = 1
711
- @tp_gain = 0
712
- @hit_type = 0
713
- @animation_id = 0
714
- @damage = RPG::UsableItem::Damage.new
715
- @effects = []
716
- end
717
-
718
- def for_opponent?
719
- [1, 2, 3, 4, 5, 6].include?(@scope)
720
- end
721
-
722
- def for_friend?
723
- [7, 8, 9, 10, 11].include?(@scope)
724
- end
725
-
726
- def for_dead_friend?
727
- [9, 10].include?(@scope)
728
- end
729
-
730
- def for_user?
731
- @scope == 11
732
- end
733
-
734
- def for_one?
735
- [1, 3, 7, 9, 11].include?(@scope)
736
- end
737
-
738
- def for_random?
739
- [3, 4, 5, 6].include?(@scope)
740
- end
741
-
742
- def number_of_targets
743
- for_random? ? @scope - 2 : 0
744
- end
745
-
746
- def for_all?
747
- [2, 8, 10].include?(@scope)
748
- end
749
-
750
- def need_selection?
751
- [1, 7, 9].include?(@scope)
752
- end
753
-
754
- def battle_ok?
755
- [0, 1].include?(@occasion)
756
- end
757
-
758
- def menu_ok?
759
- [0, 2].include?(@occasion)
760
- end
761
-
762
- def certain?
763
- @hit_type == 0
764
- end
765
-
766
- def physical?
767
- @hit_type == 1
768
- end
769
-
770
- def magical?
771
- @hit_type == 2
772
- end
773
-
774
- attr_accessor :scope
775
- attr_accessor :occasion
776
- attr_accessor :speed
777
- attr_accessor :animation_id
778
- attr_accessor :success_rate
779
- attr_accessor :repeats
780
- attr_accessor :tp_gain
781
- attr_accessor :hit_type
782
- attr_accessor :damage
783
- attr_accessor :effects
784
- end
785
-
786
- class Skill < UsableItem
787
- def initialize
788
- super
789
- @scope = 1
790
- @stype_id = 1
791
- @mp_cost = 0
792
- @tp_cost = 0
793
- @message1 = ''
794
- @message2 = ''
795
- @required_wtype_id1 = 0
796
- @required_wtype_id2 = 0
797
- end
798
-
799
- attr_accessor :stype_id
800
- attr_accessor :mp_cost
801
- attr_accessor :tp_cost
802
- attr_accessor :message1
803
- attr_accessor :message2
804
- attr_accessor :required_wtype_id1
805
- attr_accessor :required_wtype_id2
806
- end
807
-
808
- class Item < UsableItem
809
- def initialize
810
- super
811
- @scope = 7
812
- @itype_id = 1
813
- @price = 0
814
- @consumable = true
815
- end
816
-
817
- def key_item?
818
- @itype_id == 2
819
- end
820
-
821
- attr_accessor :itype_id
822
- attr_accessor :price
823
- attr_accessor :consumable
824
- end
825
-
826
- class EquipItem < BaseItem
827
- def initialize
828
- super
829
- @price = 0
830
- @etype_id = 0
831
- @params = [0] * 8
832
- end
833
-
834
- attr_accessor :price
835
- attr_accessor :etype_id
836
- attr_accessor :params
837
- end
838
-
839
- class Weapon < EquipItem
840
- def initialize
841
- super
842
- @wtype_id = 0
843
- @animation_id = 0
844
- @features.push(RPG::BaseItem::Feature.new(31, 1, 0))
845
- @features.push(RPG::BaseItem::Feature.new(22, 0, 0))
846
- end
847
-
848
- def performance
849
- params[2] + params[4] + params.inject(0) { |r, v| r += v }
850
- end
851
-
852
- attr_accessor :wtype_id
853
- attr_accessor :animation_id
854
- end
855
-
856
- class Armor < EquipItem
857
- def initialize
858
- super
859
- @atype_id = 0
860
- @etype_id = 1
861
- @features.push(RPG::BaseItem::Feature.new(22, 1, 0))
862
- end
863
-
864
- def performance
865
- params[3] + params[5] + params.inject(0) { |r, v| r += v }
866
- end
867
-
868
- attr_accessor :atype_id
869
- end
870
-
871
- class Enemy < BaseItem
872
- def initialize
873
- super
874
- @battler_name = ''
875
- @battler_hue = 0
876
- @params = [100, 0, 10, 10, 10, 10, 10, 10]
877
- @exp = 0
878
- @gold = 0
879
- @drop_items = Array.new(3) { RPG::Enemy::DropItem.new }
880
- @actions = [RPG::Enemy::Action.new]
881
- @features.push(RPG::BaseItem::Feature.new(22, 0, 0.95))
882
- @features.push(RPG::BaseItem::Feature.new(22, 1, 0.05))
883
- @features.push(RPG::BaseItem::Feature.new(31, 1, 0))
884
- end
885
-
886
- attr_accessor :battler_name
887
- attr_accessor :battler_hue
888
- attr_accessor :params
889
- attr_accessor :exp
890
- attr_accessor :gold
891
- attr_accessor :drop_items
892
- attr_accessor :actions
893
- end
894
-
895
- class State < BaseItem
896
- def initialize
897
- super
898
- @restriction = 0
899
- @priority = 50
900
- @remove_at_battle_end = false
901
- @remove_by_restriction = false
902
- @auto_removal_timing = 0
903
- @min_turns = 1
904
- @max_turns = 1
905
- @remove_by_damage = false
906
- @chance_by_damage = 100
907
- @remove_by_walking = false
908
- @steps_to_remove = 100
909
- @message1 = ''
910
- @message2 = ''
911
- @message3 = ''
912
- @message4 = ''
913
- end
914
-
915
- attr_accessor :restriction
916
- attr_accessor :priority
917
- attr_accessor :remove_at_battle_end
918
- attr_accessor :remove_by_restriction
919
- attr_accessor :auto_removal_timing
920
- attr_accessor :min_turns
921
- attr_accessor :max_turns
922
- attr_accessor :remove_by_damage
923
- attr_accessor :chance_by_damage
924
- attr_accessor :remove_by_walking
925
- attr_accessor :steps_to_remove
926
- attr_accessor :message1
927
- attr_accessor :message2
928
- attr_accessor :message3
929
- attr_accessor :message4
930
- end
931
-
932
- class BaseItem::Feature
933
- def initialize(code = 0, data_id = 0, value = 0)
934
- @code = code
935
- @data_id = data_id
936
- @value = value
937
- end
938
-
939
- attr_accessor :code
940
- attr_accessor :data_id
941
- attr_accessor :value
942
- end
943
-
944
- class UsableItem::Damage
945
- def initialize
946
- @type = 0
947
- @element_id = 0
948
- @formula = '0'
949
- @variance = 20
950
- @critical = false
951
- end
952
-
953
- def none?
954
- @type == 0
955
- end
956
-
957
- def to_hp?
958
- [1, 3, 5].include?(@type)
959
- end
960
-
961
- def to_mp?
962
- [2, 4, 6].include?(@type)
963
- end
964
-
965
- def recover?
966
- [3, 4].include?(@type)
967
- end
968
-
969
- def drain?
970
- [5, 6].include?(@type)
971
- end
972
-
973
- def sign
974
- recover? ? -1 : 1
975
- end
976
-
977
- def eval(a, b, v)
978
- [Kernel.eval(@formula), 0].max * sign rescue 0
979
- end
980
-
981
- attr_accessor :type
982
- attr_accessor :element_id
983
- attr_accessor :formula
984
- attr_accessor :variance
985
- attr_accessor :critical
986
- end
987
-
988
- class UsableItem::Effect
989
- def initialize(code = 0, data_id = 0, value1 = 0, value2 = 0)
990
- @code = code
991
- @data_id = data_id
992
- @value1 = value1
993
- @value2 = value2
994
- end
995
-
996
- attr_accessor :code
997
- attr_accessor :data_id
998
- attr_accessor :value1
999
- attr_accessor :value2
1000
- end
1001
-
1002
- class Class::Learning
1003
- def initialize
1004
- @level = 1
1005
- @skill_id = 1
1006
- @note = ''
1007
- end
1008
-
1009
- attr_accessor :level
1010
- attr_accessor :skill_id
1011
- attr_accessor :note
1012
- end
1013
-
1014
- class Enemy::DropItem
1015
- def initialize
1016
- @kind = 0
1017
- @data_id = 1
1018
- @denominator = 1
1019
- end
1020
-
1021
- attr_accessor :kind
1022
- attr_accessor :data_id
1023
- attr_accessor :denominator
1024
- end
1025
-
1026
- class Enemy::Action
1027
- def initialize
1028
- @skill_id = 1
1029
- @condition_type = 0
1030
- @condition_param1 = 0
1031
- @condition_param2 = 0
1032
- @rating = 5
1033
- end
1034
-
1035
- attr_accessor :skill_id
1036
- attr_accessor :condition_type
1037
- attr_accessor :condition_param1
1038
- attr_accessor :condition_param2
1039
- attr_accessor :rating
1040
- end
1041
-
1042
- class Troop
1043
- def initialize
1044
- @id = 0
1045
- @name = ''
1046
- @members = []
1047
- @pages = [RPG::Troop::Page.new]
1048
- end
1049
-
1050
- attr_accessor :id
1051
- attr_accessor :name
1052
- attr_accessor :members
1053
- attr_accessor :pages
1054
- end
1055
-
1056
- class Troop::Member
1057
- def initialize
1058
- @enemy_id = 1
1059
- @x = 0
1060
- @y = 0
1061
- @hidden = false
1062
- end
1063
-
1064
- attr_accessor :enemy_id
1065
- attr_accessor :x
1066
- attr_accessor :y
1067
- attr_accessor :hidden
1068
- end
1069
-
1070
- class Troop::Page
1071
- def initialize
1072
- @condition = RPG::Troop::Page::Condition.new
1073
- @span = 0
1074
- @list = [RPG::EventCommand.new]
1075
- end
1076
-
1077
- attr_accessor :condition
1078
- attr_accessor :span
1079
- attr_accessor :list
1080
- end
1081
-
1082
- class Troop::Page::Condition
1083
- def initialize
1084
- @turn_ending = false
1085
- @turn_valid = false
1086
- @enemy_valid = false
1087
- @actor_valid = false
1088
- @switch_valid = false
1089
- @turn_a = 0
1090
- @turn_b = 0
1091
- @enemy_index = 0
1092
- @enemy_hp = 50
1093
- @actor_id = 1
1094
- @actor_hp = 50
1095
- @switch_id = 1
1096
- end
1097
-
1098
- attr_accessor :turn_ending
1099
- attr_accessor :turn_valid
1100
- attr_accessor :enemy_valid
1101
- attr_accessor :actor_valid
1102
- attr_accessor :switch_valid
1103
- attr_accessor :turn_a
1104
- attr_accessor :turn_b
1105
- attr_accessor :enemy_index
1106
- attr_accessor :enemy_hp
1107
- attr_accessor :actor_id
1108
- attr_accessor :actor_hp
1109
- attr_accessor :switch_id
1110
- end
1111
-
1112
- class Animation
1113
- def initialize
1114
- @id = 0
1115
- @name = ''
1116
- @animation1_name = ''
1117
- @animation1_hue = 0
1118
- @animation2_name = ''
1119
- @animation2_hue = 0
1120
- @position = 1
1121
- @frame_max = 1
1122
- @frames = [RPG::Animation::Frame.new]
1123
- @timings = []
1124
- end
1125
-
1126
- def to_screen?
1127
- @position == 3
1128
- end
1129
-
1130
- attr_accessor :id
1131
- attr_accessor :name
1132
- attr_accessor :animation1_name
1133
- attr_accessor :animation1_hue
1134
- attr_accessor :animation2_name
1135
- attr_accessor :animation2_hue
1136
- attr_accessor :position
1137
- attr_accessor :frame_max
1138
- attr_accessor :frames
1139
- attr_accessor :timings
1140
- end
1141
-
1142
- class Animation::Frame
1143
- def initialize
1144
- @cell_max = 0
1145
- @cell_data = Table.new(0, 0)
1146
- end
1147
-
1148
- attr_accessor :cell_max
1149
- attr_accessor :cell_data
1150
- end
1151
-
1152
- class Animation::Timing
1153
- def initialize
1154
- @frame = 0
1155
- @se = RPG::SE.new('', 80)
1156
- @flash_scope = 0
1157
- @flash_color = Color.new(255, 255, 255, 255)
1158
- @flash_duration = 5
1159
- end
1160
-
1161
- attr_accessor :frame
1162
- attr_accessor :se
1163
- attr_accessor :flash_scope
1164
- attr_accessor :flash_color
1165
- attr_accessor :flash_duration
1166
- end
1167
-
1168
- class Tileset
1169
- def initialize
1170
- @id = 0
1171
- @mode = 1
1172
- @name = ''
1173
- @tileset_names = Array.new(9).collect { '' }
1174
- @flags = Table.new(8192)
1175
- @flags[0] = 0x0010
1176
- (2048..2815).each { |i| @flags[i] = 0x000F }
1177
- (4352..8191).each { |i| @flags[i] = 0x000F }
1178
- @note = ''
1179
- end
1180
-
1181
- attr_accessor :id
1182
- attr_accessor :mode
1183
- attr_accessor :name
1184
- attr_accessor :tileset_names
1185
- attr_accessor :flags
1186
- attr_accessor :note
1187
- end
1188
-
1189
- class CommonEvent
1190
- def initialize
1191
- @id = 0
1192
- @name = ''
1193
- @trigger = 0
1194
- @switch_id = 1
1195
- @list = [RPG::EventCommand.new]
1196
- end
1197
-
1198
- def autorun?
1199
- @trigger == 1
1200
- end
1201
-
1202
- def parallel?
1203
- @trigger == 2
1204
- end
1205
-
1206
- attr_accessor :id
1207
- attr_accessor :name
1208
- attr_accessor :trigger
1209
- attr_accessor :switch_id
1210
- attr_accessor :list
1211
- end
1212
-
1213
- class System
1214
- def initialize
1215
- @game_title = ''
1216
- @version_id = 0
1217
- @japanese = true
1218
- @party_members = [1]
1219
- @currency_unit = ''
1220
- @elements = [nil, '']
1221
- @skill_types = [nil, '']
1222
- @weapon_types = [nil, '']
1223
- @armor_types = [nil, '']
1224
- @switches = [nil, '']
1225
- @variables = [nil, '']
1226
- @boat = RPG::System::Vehicle.new
1227
- @ship = RPG::System::Vehicle.new
1228
- @airship = RPG::System::Vehicle.new
1229
- @title1_name = ''
1230
- @title2_name = ''
1231
- @opt_draw_title = true
1232
- @opt_use_midi = false
1233
- @opt_transparent = false
1234
- @opt_followers = true
1235
- @opt_slip_death = false
1236
- @opt_floor_death = false
1237
- @opt_display_tp = true
1238
- @opt_extra_exp = false
1239
- @window_tone = Tone.new(0, 0, 0)
1240
- @title_bgm = RPG::BGM.new
1241
- @battle_bgm = RPG::BGM.new
1242
- @battle_end_me = RPG::ME.new
1243
- @gameover_me = RPG::ME.new
1244
- @sounds = Array.new(24) { RPG::SE.new }
1245
- @test_battlers = []
1246
- @test_troop_id = 1
1247
- @start_map_id = 1
1248
- @start_x = 0
1249
- @start_y = 0
1250
- @terms = RPG::System::Terms.new
1251
- @battleback1_name = ''
1252
- @battleback2_name = ''
1253
- @battler_name = ''
1254
- @battler_hue = 0
1255
- @edit_map_id = 1
1256
- end
1257
-
1258
- attr_accessor :game_title
1259
- attr_accessor :version_id
1260
- attr_accessor :japanese
1261
- attr_accessor :party_members
1262
- attr_accessor :currency_unit
1263
- attr_accessor :skill_types
1264
- attr_accessor :weapon_types
1265
- attr_accessor :armor_types
1266
- attr_accessor :elements
1267
- attr_accessor :switches
1268
- attr_accessor :variables
1269
- attr_accessor :boat
1270
- attr_accessor :ship
1271
- attr_accessor :airship
1272
- attr_accessor :title1_name
1273
- attr_accessor :title2_name
1274
- attr_accessor :opt_draw_title
1275
- attr_accessor :opt_use_midi
1276
- attr_accessor :opt_transparent
1277
- attr_accessor :opt_followers
1278
- attr_accessor :opt_slip_death
1279
- attr_accessor :opt_floor_death
1280
- attr_accessor :opt_display_tp
1281
- attr_accessor :opt_extra_exp
1282
- attr_accessor :window_tone
1283
- attr_accessor :title_bgm
1284
- attr_accessor :battle_bgm
1285
- attr_accessor :battle_end_me
1286
- attr_accessor :gameover_me
1287
- attr_accessor :sounds
1288
- attr_accessor :test_battlers
1289
- attr_accessor :test_troop_id
1290
- attr_accessor :start_map_id
1291
- attr_accessor :start_x
1292
- attr_accessor :start_y
1293
- attr_accessor :terms
1294
- attr_accessor :battleback1_name
1295
- attr_accessor :battleback2_name
1296
- attr_accessor :battler_name
1297
- attr_accessor :battler_hue
1298
- attr_accessor :edit_map_id
1299
- end
1300
-
1301
- class System::Vehicle
1302
- def initialize
1303
- @character_name = ''
1304
- @character_index = 0
1305
- @bgm = RPG::BGM.new
1306
- @start_map_id = 0
1307
- @start_x = 0
1308
- @start_y = 0
1309
- end
1310
-
1311
- attr_accessor :character_name
1312
- attr_accessor :character_index
1313
- attr_accessor :bgm
1314
- attr_accessor :start_map_id
1315
- attr_accessor :start_x
1316
- attr_accessor :start_y
1317
- end
1318
-
1319
- class System::Terms
1320
- def initialize
1321
- @basic = Array.new(8) { '' }
1322
- @params = Array.new(8) { '' }
1323
- @etypes = Array.new(5) { '' }
1324
- @commands = Array.new(23) { '' }
1325
- end
1326
-
1327
- attr_accessor :basic
1328
- attr_accessor :params
1329
- attr_accessor :etypes
1330
- attr_accessor :commands
1331
- end
1332
-
1333
- class System::TestBattler
1334
- def initialize
1335
- @actor_id = 1
1336
- @level = 1
1337
- @equips = [0, 0, 0, 0, 0]
1338
- end
1339
-
1340
- attr_accessor :actor_id
1341
- attr_accessor :level
1342
- attr_accessor :equips
1343
- end
1344
-
1345
- class AudioFile
1346
- def initialize(name = '', volume = 100, pitch = 100)
1347
- @name = name
1348
- @volume = volume
1349
- @pitch = pitch
1350
- end
1351
-
1352
- attr_accessor :name
1353
- attr_accessor :volume
1354
- attr_accessor :pitch
1355
- end
1356
-
1357
- class BGM < AudioFile
1358
- @@last = RPG::BGM.new
1359
-
1360
- def play(pos = 0)
1361
- if @name.empty?
1362
- Audio.bgm_stop
1363
- @@last = RPG::BGM.new
1364
- else
1365
- Audio.bgm_play('Audio/BGM/' + @name, @volume, @pitch, pos)
1366
- @@last = self.clone
1367
- end
1368
- end
1369
-
1370
- def replay
1371
- play(@pos)
1372
- end
1373
-
1374
- def self.stop
1375
- Audio.bgm_stop
1376
- @@last = RPG::BGM.new
1377
- end
1378
-
1379
- def self.fade(time)
1380
- Audio.bgm_fade(time)
1381
- @@last = RPG::BGM.new
1382
- end
1383
-
1384
- def self.last
1385
- @@last.pos = Audio.bgm_pos
1386
- @@last
1387
- end
1388
-
1389
- attr_accessor :pos
1390
- end
1391
-
1392
- class BGS < AudioFile
1393
- @@last = RPG::BGS.new
1394
-
1395
- def play(pos = 0)
1396
- if @name.empty?
1397
- Audio.bgs_stop
1398
- @@last = RPG::BGS.new
1399
- else
1400
- Audio.bgs_play('Audio/BGS/' + @name, @volume, @pitch, pos)
1401
- @@last = self.clone
1402
- end
1403
- end
1404
-
1405
- def replay
1406
- play(@pos)
1407
- end
1408
-
1409
- def self.stop
1410
- Audio.bgs_stop
1411
- @@last = RPG::BGS.new
1412
- end
1413
-
1414
- def self.fade(time)
1415
- Audio.bgs_fade(time)
1416
- @@last = RPG::BGS.new
1417
- end
1418
-
1419
- def self.last
1420
- @@last.pos = Audio.bgs_pos
1421
- @@last
1422
- end
1423
-
1424
- attr_accessor :pos
1425
- end
1426
-
1427
- class ME < AudioFile
1428
- def play
1429
- if @name.empty?
1430
- Audio.me_stop
1431
- else
1432
- Audio.me_play('Audio/ME/' + @name, @volume, @pitch)
1433
- end
1434
- end
1435
-
1436
- def self.stop
1437
- Audio.me_stop
1438
- end
1439
-
1440
- def self.fade(time)
1441
- Audio.me_fade(time)
1442
- end
1443
- end
1444
-
1445
- class SE < AudioFile
1446
- def play
1447
- unless @name.empty?
1448
- Audio.se_play('Audio/SE/' + @name, @volume, @pitch)
1449
- end
1450
- end
1451
-
1452
- def self.stop
1453
- Audio.se_stop
1454
- end
1455
- end
1456
-
1
+ # frozen_string_literal: true
2
+
3
+ # RPG Maker VX Ace Color 类
4
+ class Color
5
+
6
+ # 初始化时接受以下几种参数情况:
7
+ # - 无参数时,默认 (0, 0, 0, 0)
8
+ # - 3 个参数时,默认为 (red, green, blue, 255)
9
+ # - 4 个参数时,指定 (red, green, blue, alpha)
10
+ #
11
+ # @param args [Array<Integer>] red, green, blue, alpha
12
+ # - red: 红色通道的值 (0-255)
13
+ # - green: 绿色通道的值 (0-255)
14
+ # - blue: 蓝色通道的值 (0-255)
15
+ # - alpha: 可选,透明度通道的值 (0-255),默认为 255
16
+ # @return [Color]
17
+ def initialize(*args)
18
+ case args.length
19
+ when 0 # 无参数
20
+ set(0, 0, 0, 0)
21
+ when 3 # 3 个参数, alpha 默认为 255
22
+ set(*args)
23
+ when 4 # 4 个参数, 分别为 red, green, blue, alpha
24
+ set(*args)
25
+ else
26
+ raise ArgumentError, "Invalid arguments for initialize method"
27
+ end
28
+ end
29
+
30
+ # 设置 Color 对象的值
31
+ # - 无参数时,默认 (0, 0, 0, 0)
32
+ # - 3 个参数时,默认为 (red, green, blue, 255)
33
+ # - 4 个参数时,指定 (red, green, blue, alpha)
34
+ #
35
+ # @param args [Array<Integer>] red, green, blue, alpha
36
+ # - red: 红色通道的值 (0-255)
37
+ # - green: 绿色通道的值 (0-255)
38
+ # - blue: 蓝色通道的值 (0-255)
39
+ # - alpha: 可选,透明度通道的值 (0-255),默认为 255
40
+ # @return [void]
41
+ def set(*args)
42
+ case args.length
43
+ when 1 # 一个参数, 为 Color 对象
44
+ if args[0].is_a?(Color)
45
+ other_color = args[0]
46
+ self.red = other_color.red
47
+ self.green = other_color.green
48
+ self.blue = other_color.blue
49
+ self.alpha = other_color.alpha
50
+ else
51
+ raise ArgumentError, "Invalid arguments for set method"
52
+ end
53
+ when 3 # 三个参数, 分别为 red, green, blue (alpha 默认为 255)
54
+ self.red = args[0]
55
+ self.green = args[1]
56
+ self.blue = args[2]
57
+ self.alpha = 255.0
58
+ when 4 # 四个参数, 分别为 red, green, blue, alpha
59
+ self.red = args[0]
60
+ self.green = args[1]
61
+ self.blue = args[2]
62
+ self.alpha = args[3]
63
+ else
64
+ raise ArgumentError, "Invalid arguments for set method"
65
+ end
66
+ end
67
+
68
+ # 序列化 Color 对象
69
+ #
70
+ # @param level [Integer] 序列化的级别
71
+ # @return [String]
72
+ def _dump(level)
73
+ [@red, @green, @blue, @alpha].pack('D4')
74
+ end
75
+
76
+ # 反序列化 Color 对象
77
+ #
78
+ # @param obj [String] 序列化后的字符串
79
+ # @return [Color]
80
+ def Color._load(obj)
81
+ new(*obj.unpack('D4'))
82
+ end
83
+
84
+ # 设置 red 通道的值,限制在 0 到 255 之间
85
+ #
86
+ # @param value [Float] 新的 red 通道值
87
+ # @return [void]
88
+ def red=(value)
89
+ @red = [[value, 0.0].max, 255.0].min.to_i
90
+ end
91
+
92
+ # 设置 green 通道的值,限制在 0 到 255 之间
93
+ #
94
+ # @param value [Float] 新的 green 通道值
95
+ # @return [void]
96
+ def green=(value)
97
+ @green = [[value, 0.0].max, 255.0].min.to_i
98
+ end
99
+
100
+ # 设置 blue 通道的值,限制在 0 到 255 之间
101
+ #
102
+ # @param value [Float] 新的 blue 通道值
103
+ # @return [void]
104
+ def blue=(value)
105
+ @blue = [[value, 0.0].max, 255.0].min.to_i
106
+ end
107
+
108
+ # 设置 alpha 通道的值,限制在 0 到 255 之间
109
+ #
110
+ # @param value [Float] 新的 alpha 通道值
111
+ # @return [void]
112
+ def alpha=(value)
113
+ @alpha = [[value, 0.0].max, 255.0].min
114
+ end
115
+
116
+ # red 通道的值
117
+ #
118
+ # @return [Integer]
119
+ attr_reader :red
120
+
121
+ # green 通道的值
122
+ #
123
+ # @return [Integer]
124
+ attr_reader :green
125
+
126
+ # blue 通道的值
127
+ #
128
+ # @return [Integer]
129
+ attr_reader :blue
130
+
131
+ # alpha 通道的值
132
+ #
133
+ # @return [Integer]
134
+ attr_reader :alpha
135
+ end
136
+
137
+ # RPG Maker VX Ace Tone 类
138
+ class Tone
139
+
140
+ # 初始化时接受以下几种参数情况:
141
+ # - 无参数时,默认 (0, 0, 0, 0)
142
+ # - 3 个参数时,默认为 (red, green, blue, 0)
143
+ # - 4 个参数时,指定 (red, green, blue, gray)
144
+ #
145
+ # @param args [Array<Integer>] red, green, blue, gray
146
+ # - red: 红色通道的值 (-255-255)
147
+ # - green: 绿色通道的值 (-255-255)
148
+ # - blue: 蓝色通道的值 (-255-255)
149
+ # - gray: 可选,灰度通道的值 (0-255),默认为 0
150
+ # @return [Tone]
151
+ def initialize(*args)
152
+ case args.length
153
+ when 0 # 无参数
154
+ set(0, 0, 0, 0)
155
+ when 3 # 3 个参数, gray 默认为 0
156
+ set(*args)
157
+ when 4 # 4 个参数, 分别为 red, green, blue, gray
158
+ set(*args)
159
+ else
160
+ raise ArgumentError, "Invalid arguments for initialize method"
161
+ end
162
+ end
163
+
164
+ # 设置 Tone 对象的值
165
+ # - 无参数时,默认 (0, 0, 0, 0)
166
+ # - 3 个参数时,默认为 (red, green, blue, 0)
167
+ # - 4 个参数时,指定 (red, green, blue, gray)
168
+ #
169
+ # @param args [Array<Integer>] red, green, blue, gray
170
+ # - red: 红色通道的值 (-255-255)
171
+ # - green: 绿色通道的值 (-255-255)
172
+ # - blue: 蓝色通道的值 (-255-255)
173
+ # - gray: 可选,透明度通道的值 (0-255),默认为 0
174
+ # @return [void]
175
+ def set(*args)
176
+ case args.length
177
+ when 1 # 一个参数, 为 Tone 对象
178
+ if args[0].is_a?(Tone)
179
+ self.red = args[0].red
180
+ self.green = args[0].green
181
+ self.blue = args[0].blue
182
+ self.gray = args[0].gray
183
+ else
184
+ raise ArgumentError, "Invalid arguments for set method"
185
+ end
186
+ when 3 # 三个参数, 分别为 red, green, blue (gray 默认为 0)
187
+ self.red = args[0]
188
+ self.green = args[1]
189
+ self.blue = args[2]
190
+ self.gray = 0.0
191
+ when 4 # 四个参数, 分别为 red, green, blue, gray
192
+ self.red = args[0]
193
+ self.green = args[1]
194
+ self.blue = args[2]
195
+ self.gray = args[3]
196
+ else
197
+ raise ArgumentError, "Invalid arguments for set method"
198
+ end
199
+ end
200
+
201
+ # 序列化 Tone 对象
202
+ #
203
+ # @param level [Integer] 序列化的级别
204
+ # @return [String]
205
+ def _dump(level)
206
+ [@red, @green, @blue, @gray].pack('D4')
207
+ end
208
+
209
+ # 反序列化 Tone 对象
210
+ #
211
+ # @param obj [String] 序列化后的字符串
212
+ # @return [Tone]
213
+ def Tone._load(obj)
214
+ new(*obj.unpack('D4'))
215
+ end
216
+
217
+ # 设置 red 通道的值,限制在 -255 到 255 之间
218
+ #
219
+ # @param value [Float] 新的 red 通道值
220
+ # @return [void]
221
+ def red=(value)
222
+ @red = [[value, -255.0].max, 255.0].min.to_i
223
+ end
224
+
225
+ # 设置 green 通道的值,限制在 -255 到 255 之间
226
+ #
227
+ # @param value [Float] 新的 green 通道值
228
+ # @return [void]
229
+ def green=(value)
230
+ @green = [[value, -255.0].max, 255.0].min.to_i
231
+ end
232
+
233
+ # 设置 blue 通道的值,限制在 -255 到 255 之间
234
+ #
235
+ # @param value [Float] 新的 blue 通道值
236
+ # @return [void]
237
+ def blue=(value)
238
+ @blue = [[value, -255.0].max, 255.0].min.to_i
239
+ end
240
+
241
+ # 设置 alpha 通道的值,限制在 0 到 255 之间
242
+ #
243
+ # @param value [Float] 新的 alpha 通道值
244
+ # @return [void]
245
+ def gray=(value)
246
+ @gray = [[value, 0.0].max, 255.0].min.to_i
247
+ end
248
+
249
+ # red 通道的值
250
+ #
251
+ # @return [Integer]
252
+ attr_reader :red
253
+
254
+ # green 通道的值
255
+ #
256
+ # @return [Integer]
257
+ attr_reader :green
258
+
259
+ # blue 通道的值
260
+ #
261
+ # @return [Integer]
262
+ attr_reader :blue
263
+
264
+ # gray 通道的值
265
+ #
266
+ # @return [Integer]
267
+ attr_reader :gray
268
+
269
+ end
270
+
271
+ # RPG Maker VX Ace Table 类
272
+ #
273
+ # Table 是一个多维数组,每个元素都是带符号的两字节整数(int16_t), 也就是 -32,768~32,767 之间的整数
274
+ #
275
+ # Ruby Array 类在处理大量信息时效率很差,因此使用了此类。
276
+ class Table
277
+
278
+ # 初始化 Table 对象,指定多维数组各维的长度。生成的数组可以是 1~3 维,甚至是没有元素的数组。
279
+ #
280
+ # 初始化时传入的参数个数决定了生成的数组维度:
281
+ # - 最少 1 维,最多 3 维。
282
+ # - `ysize` 和 `zsize` 参数可以省略,默认值为 1。
283
+ #
284
+ # 注意:该类没有参数检查,请确保 `ysize` 和 `zsize` 的值在 `[-32768, 32767]` 范围内。
285
+ #
286
+ # @param xsize [Integer] 第一维的长度(必需)
287
+ # @param ysize [Integer, nil] 第二维的长度(可选,默认值为 nil)
288
+ # @param zsize [Integer, nil] 第三维的长度(可选,默认值为 nil)
289
+ # @return [Table]
290
+ def initialize(xsize, ysize = nil, zsize = nil)
291
+ init_attr(xsize, ysize, zsize)
292
+ end
293
+
294
+ # 设置各维的长度
295
+ #
296
+ # @param xsize [Integer] 第一维的长度
297
+ # @param ysize [Integer, nil] 第二维的长度(如果为 nil,则默认为 1)
298
+ # @param zsize [Integer, nil] 第三维的长度(如果为 nil,则默认为 1)
299
+ # @return [void]
300
+ def init_attr(xsize, ysize, zsize)
301
+ @dim = 1 + (ysize.nil? ? 0 : 1) + (zsize.nil? ? 0 : 1)
302
+ @xsize = xsize
303
+ @ysize = ysize.nil? ? 1 : ysize
304
+ @zsize = zsize.nil? ? 1 : zsize
305
+ @data = Array.new(@xsize * @ysize * @zsize, 0)
306
+ end
307
+
308
+ # 获取指定位置的元素值
309
+ #
310
+ # @param x [Integer] 第一维的长度(必需)
311
+ # @param y [Integer] 第二维的长度(可选,默认值为 0)
312
+ # @param z [Integer] 第三维的长度(可选,默认值为 0)
313
+ # @return [Integer]
314
+ def [](x, y = 0, z = 0)
315
+ @data[x + y * @xsize + z * @xsize * @ysize]
316
+ end
317
+
318
+ # 设置指定位置的元素值
319
+ #
320
+ # @param args [Array<Integer>] x, y, z, v
321
+ # - x: 第一维的长度(必需)
322
+ # - y: 第二维的长度(可选,默认值为 nil)
323
+ # - z: 第三维的长度(可选,默认值为 nil)
324
+ # - v: 新的元素值
325
+ # @return [void]
326
+ def []=(*args)
327
+ v = args.pop
328
+ x, y, z = args
329
+ y ||= 0
330
+ z ||= 0
331
+ @data[x + y * @xsize + z * @xsize * @ysize] = v
332
+ end
333
+
334
+ # 扩容 Table 对象,保留原有数据
335
+ #
336
+ # @param xsize [Integer] 第一维的长度(必需)
337
+ # @param ysize [Integer, nil] 第二维的长度(可选,默认值为 nil)
338
+ # @param zsize [Integer, nil] 第三维的长度(可选,默认值为 nil)
339
+ # @return [void]
340
+ def resize(xsize, ysize = nil, zsize = nil)
341
+ old_data = @data.dup
342
+ old_xsize, old_ysize, old_zsize = @xsize, @ysize, @zsize
343
+ init_attr(xsize, ysize, zsize)
344
+ (0...[old_xsize, @xsize].min).each { |x|
345
+ (0...[old_ysize, @ysize].min).each { |y|
346
+ (0...[old_zsize, @zsize].min).each { |z|
347
+ @data[x + y * @xsize + z * @xsize * @ysize] = old_data[x + y * old_xsize + z * old_xsize * old_ysize]
348
+ }
349
+ }
350
+ }
351
+ end
352
+
353
+ # 序列化 Table 对象
354
+ #
355
+ # @param level [Integer] 序列化的级别
356
+ # @return [String]
357
+ def _dump(level)
358
+ s = [@dim, @xsize, @ysize, @zsize, @xsize * @ysize * @zsize].pack('LLLLL')
359
+ @data.each do |d|
360
+ s << [d].pack('s')
361
+ end
362
+ s
363
+ end
364
+
365
+ # 反序列化 Table 对象
366
+ #
367
+ # @param obj [String] 序列化后的字符串
368
+ # @return [Table]
369
+ def Table._load(obj)
370
+ # 从序列化字符串中解包维度信息
371
+ dim, xsize, ysize, zsize, total_size = *obj[0, 20].unpack('LLLLL')
372
+ # 初始化 Table 对象
373
+ table = Table.new(*[xsize, ysize, zsize].first(dim))
374
+ table.data = obj[20, total_size * 2].unpack("s#{total_size}")
375
+ # 现在 @data 已经从序列化字符串中完整提取
376
+ table
377
+ end
378
+
379
+ # 数据数组
380
+ #
381
+ # @return [Array<Integer>]
382
+ attr_accessor :data
383
+
384
+ # 维度
385
+ #
386
+ # @return [Integer]
387
+ attr_accessor :dim
388
+
389
+ # 第一维的长度
390
+ #
391
+ # @return [Integer]
392
+ attr_accessor :xsize
393
+
394
+ # 第二维的长度
395
+ #
396
+ # @return [Integer]
397
+ attr_accessor :ysize
398
+
399
+ # 第三维的长度
400
+ #
401
+ # @return [Integer]
402
+ attr_accessor :zsize
403
+ end
404
+
405
+ # RPG Maker VX Ace 的RPG 模块
406
+ module RPG
407
+ class Map
408
+ def initialize(width, height)
409
+ @display_name = ''
410
+ @tileset_id = 1
411
+ @width = width
412
+ @height = height
413
+ @scroll_type = 0
414
+ @specify_battleback = false
415
+ @battleback_floor_name = ''
416
+ @battleback_wall_name = ''
417
+ @autoplay_bgm = false
418
+ @bgm = RPG::BGM.new
419
+ @autoplay_bgs = false
420
+ @bgs = RPG::BGS.new('', 80)
421
+ @disable_dashing = false
422
+ @encounter_list = []
423
+ @encounter_step = 30
424
+ @parallax_name = ''
425
+ @parallax_loop_x = false
426
+ @parallax_loop_y = false
427
+ @parallax_sx = 0
428
+ @parallax_sy = 0
429
+ @parallax_show = false
430
+ @note = ''
431
+ @data = Table.new(width, height, 4)
432
+ @events = {}
433
+ end
434
+
435
+ attr_accessor :display_name
436
+ attr_accessor :tileset_id
437
+ attr_accessor :width
438
+ attr_accessor :height
439
+ attr_accessor :scroll_type
440
+ attr_accessor :specify_battleback
441
+ attr_accessor :battleback1_name
442
+ attr_accessor :battleback2_name
443
+ attr_accessor :autoplay_bgm
444
+ attr_accessor :bgm
445
+ attr_accessor :autoplay_bgs
446
+ attr_accessor :bgs
447
+ attr_accessor :disable_dashing
448
+ attr_accessor :encounter_list
449
+ attr_accessor :encounter_step
450
+ attr_accessor :parallax_name
451
+ attr_accessor :parallax_loop_x
452
+ attr_accessor :parallax_loop_y
453
+ attr_accessor :parallax_sx
454
+ attr_accessor :parallax_sy
455
+ attr_accessor :parallax_show
456
+ attr_accessor :note
457
+ attr_accessor :data
458
+ attr_accessor :events
459
+ end
460
+
461
+ class Map::Encounter
462
+ def initialize
463
+ @troop_id = 1
464
+ @weight = 10
465
+ @region_set = []
466
+ end
467
+
468
+ attr_accessor :troop_id
469
+ attr_accessor :weight
470
+ attr_accessor :region_set
471
+ end
472
+
473
+ class MapInfo
474
+ def initialize
475
+ @name = ''
476
+ @parent_id = 0
477
+ @order = 0
478
+ @expanded = false
479
+ @scroll_x = 0
480
+ @scroll_y = 0
481
+ end
482
+
483
+ attr_accessor :name
484
+ attr_accessor :parent_id
485
+ attr_accessor :order
486
+ attr_accessor :expanded
487
+ attr_accessor :scroll_x
488
+ attr_accessor :scroll_y
489
+ end
490
+
491
+ class Event
492
+ def initialize(x, y)
493
+ @id = 0
494
+ @name = ''
495
+ @x = x
496
+ @y = y
497
+ @pages = [RPG::Event::Page.new]
498
+ end
499
+
500
+ attr_accessor :id
501
+ attr_accessor :name
502
+ attr_accessor :x
503
+ attr_accessor :y
504
+ attr_accessor :pages
505
+ end
506
+
507
+ class Event::Page
508
+ def initialize
509
+ @condition = RPG::Event::Page::Condition.new
510
+ @graphic = RPG::Event::Page::Graphic.new
511
+ @move_type = 0
512
+ @move_speed = 3
513
+ @move_frequency = 3
514
+ @move_route = RPG::MoveRoute.new
515
+ @walk_anime = true
516
+ @step_anime = false
517
+ @direction_fix = false
518
+ @through = false
519
+ @priority_type = 0
520
+ @trigger = 0
521
+ @list = [RPG::EventCommand.new]
522
+ end
523
+
524
+ attr_accessor :condition
525
+ attr_accessor :graphic
526
+ attr_accessor :move_type
527
+ attr_accessor :move_speed
528
+ attr_accessor :move_frequency
529
+ attr_accessor :move_route
530
+ attr_accessor :walk_anime
531
+ attr_accessor :step_anime
532
+ attr_accessor :direction_fix
533
+ attr_accessor :through
534
+ attr_accessor :priority_type
535
+ attr_accessor :trigger
536
+ attr_accessor :list
537
+ end
538
+
539
+ class Event::Page::Condition
540
+ def initialize
541
+ @switch1_valid = false
542
+ @switch2_valid = false
543
+ @variable_valid = false
544
+ @self_switch_valid = false
545
+ @item_valid = false
546
+ @actor_valid = false
547
+ @switch1_id = 1
548
+ @switch2_id = 1
549
+ @variable_id = 1
550
+ @variable_value = 0
551
+ @self_switch_ch = 'A'
552
+ @item_id = 1
553
+ @actor_id = 1
554
+ end
555
+
556
+ attr_accessor :switch1_valid
557
+ attr_accessor :switch2_valid
558
+ attr_accessor :variable_valid
559
+ attr_accessor :self_switch_valid
560
+ attr_accessor :item_valid
561
+ attr_accessor :actor_valid
562
+ attr_accessor :switch1_id
563
+ attr_accessor :switch2_id
564
+ attr_accessor :variable_id
565
+ attr_accessor :variable_value
566
+ attr_accessor :self_switch_ch
567
+ attr_accessor :item_id
568
+ attr_accessor :actor_id
569
+ end
570
+
571
+ class Event::Page::Graphic
572
+ def initialize
573
+ @tile_id = 0
574
+ @character_name = ''
575
+ @character_index = 0
576
+ @direction = 2
577
+ @pattern = 0
578
+ end
579
+
580
+ attr_accessor :tile_id
581
+ attr_accessor :character_name
582
+ attr_accessor :character_index
583
+ attr_accessor :direction
584
+ attr_accessor :pattern
585
+ end
586
+
587
+ class EventCommand
588
+ def initialize(code = 0, indent = 0, parameters = [])
589
+ @code = code
590
+ @indent = indent
591
+ @parameters = parameters
592
+ end
593
+
594
+ attr_accessor :code
595
+ attr_accessor :indent
596
+ attr_accessor :parameters
597
+ end
598
+
599
+ class MoveRoute
600
+ def initialize
601
+ @repeat = true
602
+ @skippable = false
603
+ @wait = false
604
+ @list = [RPG::MoveCommand.new]
605
+ end
606
+
607
+ attr_accessor :repeat
608
+ attr_accessor :skippable
609
+ attr_accessor :wait
610
+ attr_accessor :list
611
+ end
612
+
613
+ class MoveCommand
614
+ def initialize(code = 0, parameters = [])
615
+ @code = code
616
+ @parameters = parameters
617
+ end
618
+
619
+ attr_accessor :code
620
+ attr_accessor :parameters
621
+ end
622
+
623
+ class BaseItem
624
+ def initialize
625
+ @id = 0
626
+ @name = ''
627
+ @icon_index = 0
628
+ @description = ''
629
+ @features = []
630
+ @note = ''
631
+ end
632
+
633
+ attr_accessor :id
634
+ attr_accessor :name
635
+ attr_accessor :icon_index
636
+ attr_accessor :description
637
+ attr_accessor :features
638
+ attr_accessor :note
639
+ end
640
+
641
+ class Actor < BaseItem
642
+
643
+ def initialize
644
+ super
645
+ @nickname = ''
646
+ @class_id = 1
647
+ @initial_level = 1
648
+ @max_level = 99
649
+ @character_name = ''
650
+ @character_index = 0
651
+ @face_name = ''
652
+ @face_index = 0
653
+ @equips = [0, 0, 0, 0, 0]
654
+ end
655
+
656
+ attr_accessor :nickname
657
+ attr_accessor :class_id
658
+ attr_accessor :initial_level
659
+ attr_accessor :max_level
660
+ attr_accessor :character_name
661
+ attr_accessor :character_index
662
+ attr_accessor :face_name
663
+ attr_accessor :face_index
664
+ attr_accessor :equips
665
+ end
666
+
667
+ class Class < BaseItem
668
+ def initialize
669
+ super
670
+ @exp_params = [30, 20, 30, 30]
671
+ @params = Table.new(8, 100)
672
+ (1..99).each do |i|
673
+ @params[0, i] = 400 + i * 50
674
+ @params[1, i] = 80 + i * 10
675
+ (2..5).each { |j| @params[j, i] = 15 + i * 5 / 4 }
676
+ (6..7).each { |j| @params[j, i] = 30 + i * 5 / 2 }
677
+ end
678
+ @learnings = []
679
+ @features.push(RPG::BaseItem::Feature.new(23, 0, 1))
680
+ @features.push(RPG::BaseItem::Feature.new(22, 0, 0.95))
681
+ @features.push(RPG::BaseItem::Feature.new(22, 1, 0.05))
682
+ @features.push(RPG::BaseItem::Feature.new(22, 2, 0.04))
683
+ @features.push(RPG::BaseItem::Feature.new(41, 1))
684
+ @features.push(RPG::BaseItem::Feature.new(51, 1))
685
+ @features.push(RPG::BaseItem::Feature.new(52, 1))
686
+ end
687
+
688
+ def exp_for_level(level)
689
+ lv = level.to_f
690
+ basis = @exp_params[0].to_f
691
+ extra = @exp_params[1].to_f
692
+ acc_a = @exp_params[2].to_f
693
+ acc_b = @exp_params[3].to_f
694
+ return (basis * ((lv - 1) ** (0.9 + acc_a / 250)) * lv * (lv + 1) /
695
+ (6 + lv ** 2 / 50 / acc_b) + (lv - 1) * extra).round.to_i
696
+ end
697
+
698
+ attr_accessor :exp_params
699
+ attr_accessor :params
700
+ attr_accessor :learnings
701
+ end
702
+
703
+ class UsableItem < BaseItem
704
+ def initialize
705
+ super
706
+ @scope = 0
707
+ @occasion = 0
708
+ @speed = 0
709
+ @success_rate = 100
710
+ @repeats = 1
711
+ @tp_gain = 0
712
+ @hit_type = 0
713
+ @animation_id = 0
714
+ @damage = RPG::UsableItem::Damage.new
715
+ @effects = []
716
+ end
717
+
718
+ def for_opponent?
719
+ [1, 2, 3, 4, 5, 6].include?(@scope)
720
+ end
721
+
722
+ def for_friend?
723
+ [7, 8, 9, 10, 11].include?(@scope)
724
+ end
725
+
726
+ def for_dead_friend?
727
+ [9, 10].include?(@scope)
728
+ end
729
+
730
+ def for_user?
731
+ @scope == 11
732
+ end
733
+
734
+ def for_one?
735
+ [1, 3, 7, 9, 11].include?(@scope)
736
+ end
737
+
738
+ def for_random?
739
+ [3, 4, 5, 6].include?(@scope)
740
+ end
741
+
742
+ def number_of_targets
743
+ for_random? ? @scope - 2 : 0
744
+ end
745
+
746
+ def for_all?
747
+ [2, 8, 10].include?(@scope)
748
+ end
749
+
750
+ def need_selection?
751
+ [1, 7, 9].include?(@scope)
752
+ end
753
+
754
+ def battle_ok?
755
+ [0, 1].include?(@occasion)
756
+ end
757
+
758
+ def menu_ok?
759
+ [0, 2].include?(@occasion)
760
+ end
761
+
762
+ def certain?
763
+ @hit_type == 0
764
+ end
765
+
766
+ def physical?
767
+ @hit_type == 1
768
+ end
769
+
770
+ def magical?
771
+ @hit_type == 2
772
+ end
773
+
774
+ attr_accessor :scope
775
+ attr_accessor :occasion
776
+ attr_accessor :speed
777
+ attr_accessor :animation_id
778
+ attr_accessor :success_rate
779
+ attr_accessor :repeats
780
+ attr_accessor :tp_gain
781
+ attr_accessor :hit_type
782
+ attr_accessor :damage
783
+ attr_accessor :effects
784
+ end
785
+
786
+ class Skill < UsableItem
787
+ def initialize
788
+ super
789
+ @scope = 1
790
+ @stype_id = 1
791
+ @mp_cost = 0
792
+ @tp_cost = 0
793
+ @message1 = ''
794
+ @message2 = ''
795
+ @required_wtype_id1 = 0
796
+ @required_wtype_id2 = 0
797
+ end
798
+
799
+ attr_accessor :stype_id
800
+ attr_accessor :mp_cost
801
+ attr_accessor :tp_cost
802
+ attr_accessor :message1
803
+ attr_accessor :message2
804
+ attr_accessor :required_wtype_id1
805
+ attr_accessor :required_wtype_id2
806
+ end
807
+
808
+ class Item < UsableItem
809
+ def initialize
810
+ super
811
+ @scope = 7
812
+ @itype_id = 1
813
+ @price = 0
814
+ @consumable = true
815
+ end
816
+
817
+ def key_item?
818
+ @itype_id == 2
819
+ end
820
+
821
+ attr_accessor :itype_id
822
+ attr_accessor :price
823
+ attr_accessor :consumable
824
+ end
825
+
826
+ class EquipItem < BaseItem
827
+ def initialize
828
+ super
829
+ @price = 0
830
+ @etype_id = 0
831
+ @params = [0] * 8
832
+ end
833
+
834
+ attr_accessor :price
835
+ attr_accessor :etype_id
836
+ attr_accessor :params
837
+ end
838
+
839
+ class Weapon < EquipItem
840
+ def initialize
841
+ super
842
+ @wtype_id = 0
843
+ @animation_id = 0
844
+ @features.push(RPG::BaseItem::Feature.new(31, 1, 0))
845
+ @features.push(RPG::BaseItem::Feature.new(22, 0, 0))
846
+ end
847
+
848
+ def performance
849
+ params[2] + params[4] + params.inject(0) { |r, v| r += v }
850
+ end
851
+
852
+ attr_accessor :wtype_id
853
+ attr_accessor :animation_id
854
+ end
855
+
856
+ class Armor < EquipItem
857
+ def initialize
858
+ super
859
+ @atype_id = 0
860
+ @etype_id = 1
861
+ @features.push(RPG::BaseItem::Feature.new(22, 1, 0))
862
+ end
863
+
864
+ def performance
865
+ params[3] + params[5] + params.inject(0) { |r, v| r += v }
866
+ end
867
+
868
+ attr_accessor :atype_id
869
+ end
870
+
871
+ class Enemy < BaseItem
872
+ def initialize
873
+ super
874
+ @battler_name = ''
875
+ @battler_hue = 0
876
+ @params = [100, 0, 10, 10, 10, 10, 10, 10]
877
+ @exp = 0
878
+ @gold = 0
879
+ @drop_items = Array.new(3) { RPG::Enemy::DropItem.new }
880
+ @actions = [RPG::Enemy::Action.new]
881
+ @features.push(RPG::BaseItem::Feature.new(22, 0, 0.95))
882
+ @features.push(RPG::BaseItem::Feature.new(22, 1, 0.05))
883
+ @features.push(RPG::BaseItem::Feature.new(31, 1, 0))
884
+ end
885
+
886
+ attr_accessor :battler_name
887
+ attr_accessor :battler_hue
888
+ attr_accessor :params
889
+ attr_accessor :exp
890
+ attr_accessor :gold
891
+ attr_accessor :drop_items
892
+ attr_accessor :actions
893
+ end
894
+
895
+ class State < BaseItem
896
+ def initialize
897
+ super
898
+ @restriction = 0
899
+ @priority = 50
900
+ @remove_at_battle_end = false
901
+ @remove_by_restriction = false
902
+ @auto_removal_timing = 0
903
+ @min_turns = 1
904
+ @max_turns = 1
905
+ @remove_by_damage = false
906
+ @chance_by_damage = 100
907
+ @remove_by_walking = false
908
+ @steps_to_remove = 100
909
+ @message1 = ''
910
+ @message2 = ''
911
+ @message3 = ''
912
+ @message4 = ''
913
+ end
914
+
915
+ attr_accessor :restriction
916
+ attr_accessor :priority
917
+ attr_accessor :remove_at_battle_end
918
+ attr_accessor :remove_by_restriction
919
+ attr_accessor :auto_removal_timing
920
+ attr_accessor :min_turns
921
+ attr_accessor :max_turns
922
+ attr_accessor :remove_by_damage
923
+ attr_accessor :chance_by_damage
924
+ attr_accessor :remove_by_walking
925
+ attr_accessor :steps_to_remove
926
+ attr_accessor :message1
927
+ attr_accessor :message2
928
+ attr_accessor :message3
929
+ attr_accessor :message4
930
+ end
931
+
932
+ class BaseItem::Feature
933
+ def initialize(code = 0, data_id = 0, value = 0)
934
+ @code = code
935
+ @data_id = data_id
936
+ @value = value
937
+ end
938
+
939
+ attr_accessor :code
940
+ attr_accessor :data_id
941
+ attr_accessor :value
942
+ end
943
+
944
+ class UsableItem::Damage
945
+ def initialize
946
+ @type = 0
947
+ @element_id = 0
948
+ @formula = '0'
949
+ @variance = 20
950
+ @critical = false
951
+ end
952
+
953
+ def none?
954
+ @type == 0
955
+ end
956
+
957
+ def to_hp?
958
+ [1, 3, 5].include?(@type)
959
+ end
960
+
961
+ def to_mp?
962
+ [2, 4, 6].include?(@type)
963
+ end
964
+
965
+ def recover?
966
+ [3, 4].include?(@type)
967
+ end
968
+
969
+ def drain?
970
+ [5, 6].include?(@type)
971
+ end
972
+
973
+ def sign
974
+ recover? ? -1 : 1
975
+ end
976
+
977
+ def eval(a, b, v)
978
+ [Kernel.eval(@formula), 0].max * sign rescue 0
979
+ end
980
+
981
+ attr_accessor :type
982
+ attr_accessor :element_id
983
+ attr_accessor :formula
984
+ attr_accessor :variance
985
+ attr_accessor :critical
986
+ end
987
+
988
+ class UsableItem::Effect
989
+ def initialize(code = 0, data_id = 0, value1 = 0, value2 = 0)
990
+ @code = code
991
+ @data_id = data_id
992
+ @value1 = value1
993
+ @value2 = value2
994
+ end
995
+
996
+ attr_accessor :code
997
+ attr_accessor :data_id
998
+ attr_accessor :value1
999
+ attr_accessor :value2
1000
+ end
1001
+
1002
+ class Class::Learning
1003
+ def initialize
1004
+ @level = 1
1005
+ @skill_id = 1
1006
+ @note = ''
1007
+ end
1008
+
1009
+ attr_accessor :level
1010
+ attr_accessor :skill_id
1011
+ attr_accessor :note
1012
+ end
1013
+
1014
+ class Enemy::DropItem
1015
+ def initialize
1016
+ @kind = 0
1017
+ @data_id = 1
1018
+ @denominator = 1
1019
+ end
1020
+
1021
+ attr_accessor :kind
1022
+ attr_accessor :data_id
1023
+ attr_accessor :denominator
1024
+ end
1025
+
1026
+ class Enemy::Action
1027
+ def initialize
1028
+ @skill_id = 1
1029
+ @condition_type = 0
1030
+ @condition_param1 = 0
1031
+ @condition_param2 = 0
1032
+ @rating = 5
1033
+ end
1034
+
1035
+ attr_accessor :skill_id
1036
+ attr_accessor :condition_type
1037
+ attr_accessor :condition_param1
1038
+ attr_accessor :condition_param2
1039
+ attr_accessor :rating
1040
+ end
1041
+
1042
+ class Troop
1043
+ def initialize
1044
+ @id = 0
1045
+ @name = ''
1046
+ @members = []
1047
+ @pages = [RPG::Troop::Page.new]
1048
+ end
1049
+
1050
+ attr_accessor :id
1051
+ attr_accessor :name
1052
+ attr_accessor :members
1053
+ attr_accessor :pages
1054
+ end
1055
+
1056
+ class Troop::Member
1057
+ def initialize
1058
+ @enemy_id = 1
1059
+ @x = 0
1060
+ @y = 0
1061
+ @hidden = false
1062
+ end
1063
+
1064
+ attr_accessor :enemy_id
1065
+ attr_accessor :x
1066
+ attr_accessor :y
1067
+ attr_accessor :hidden
1068
+ end
1069
+
1070
+ class Troop::Page
1071
+ def initialize
1072
+ @condition = RPG::Troop::Page::Condition.new
1073
+ @span = 0
1074
+ @list = [RPG::EventCommand.new]
1075
+ end
1076
+
1077
+ attr_accessor :condition
1078
+ attr_accessor :span
1079
+ attr_accessor :list
1080
+ end
1081
+
1082
+ class Troop::Page::Condition
1083
+ def initialize
1084
+ @turn_ending = false
1085
+ @turn_valid = false
1086
+ @enemy_valid = false
1087
+ @actor_valid = false
1088
+ @switch_valid = false
1089
+ @turn_a = 0
1090
+ @turn_b = 0
1091
+ @enemy_index = 0
1092
+ @enemy_hp = 50
1093
+ @actor_id = 1
1094
+ @actor_hp = 50
1095
+ @switch_id = 1
1096
+ end
1097
+
1098
+ attr_accessor :turn_ending
1099
+ attr_accessor :turn_valid
1100
+ attr_accessor :enemy_valid
1101
+ attr_accessor :actor_valid
1102
+ attr_accessor :switch_valid
1103
+ attr_accessor :turn_a
1104
+ attr_accessor :turn_b
1105
+ attr_accessor :enemy_index
1106
+ attr_accessor :enemy_hp
1107
+ attr_accessor :actor_id
1108
+ attr_accessor :actor_hp
1109
+ attr_accessor :switch_id
1110
+ end
1111
+
1112
+ class Animation
1113
+ def initialize
1114
+ @id = 0
1115
+ @name = ''
1116
+ @animation1_name = ''
1117
+ @animation1_hue = 0
1118
+ @animation2_name = ''
1119
+ @animation2_hue = 0
1120
+ @position = 1
1121
+ @frame_max = 1
1122
+ @frames = [RPG::Animation::Frame.new]
1123
+ @timings = []
1124
+ end
1125
+
1126
+ def to_screen?
1127
+ @position == 3
1128
+ end
1129
+
1130
+ attr_accessor :id
1131
+ attr_accessor :name
1132
+ attr_accessor :animation1_name
1133
+ attr_accessor :animation1_hue
1134
+ attr_accessor :animation2_name
1135
+ attr_accessor :animation2_hue
1136
+ attr_accessor :position
1137
+ attr_accessor :frame_max
1138
+ attr_accessor :frames
1139
+ attr_accessor :timings
1140
+ end
1141
+
1142
+ class Animation::Frame
1143
+ def initialize
1144
+ @cell_max = 0
1145
+ @cell_data = Table.new(0, 0)
1146
+ end
1147
+
1148
+ attr_accessor :cell_max
1149
+ attr_accessor :cell_data
1150
+ end
1151
+
1152
+ class Animation::Timing
1153
+ def initialize
1154
+ @frame = 0
1155
+ @se = RPG::SE.new('', 80)
1156
+ @flash_scope = 0
1157
+ @flash_color = Color.new(255, 255, 255, 255)
1158
+ @flash_duration = 5
1159
+ end
1160
+
1161
+ attr_accessor :frame
1162
+ attr_accessor :se
1163
+ attr_accessor :flash_scope
1164
+ attr_accessor :flash_color
1165
+ attr_accessor :flash_duration
1166
+ end
1167
+
1168
+ class Tileset
1169
+ def initialize
1170
+ @id = 0
1171
+ @mode = 1
1172
+ @name = ''
1173
+ @tileset_names = Array.new(9).collect { '' }
1174
+ @flags = Table.new(8192)
1175
+ @flags[0] = 0x0010
1176
+ (2048..2815).each { |i| @flags[i] = 0x000F }
1177
+ (4352..8191).each { |i| @flags[i] = 0x000F }
1178
+ @note = ''
1179
+ end
1180
+
1181
+ attr_accessor :id
1182
+ attr_accessor :mode
1183
+ attr_accessor :name
1184
+ attr_accessor :tileset_names
1185
+ attr_accessor :flags
1186
+ attr_accessor :note
1187
+ end
1188
+
1189
+ class CommonEvent
1190
+ def initialize
1191
+ @id = 0
1192
+ @name = ''
1193
+ @trigger = 0
1194
+ @switch_id = 1
1195
+ @list = [RPG::EventCommand.new]
1196
+ end
1197
+
1198
+ def autorun?
1199
+ @trigger == 1
1200
+ end
1201
+
1202
+ def parallel?
1203
+ @trigger == 2
1204
+ end
1205
+
1206
+ attr_accessor :id
1207
+ attr_accessor :name
1208
+ attr_accessor :trigger
1209
+ attr_accessor :switch_id
1210
+ attr_accessor :list
1211
+ end
1212
+
1213
+ class System
1214
+ def initialize
1215
+ @game_title = ''
1216
+ @version_id = 0
1217
+ @japanese = true
1218
+ @party_members = [1]
1219
+ @currency_unit = ''
1220
+ @elements = [nil, '']
1221
+ @skill_types = [nil, '']
1222
+ @weapon_types = [nil, '']
1223
+ @armor_types = [nil, '']
1224
+ @switches = [nil, '']
1225
+ @variables = [nil, '']
1226
+ @boat = RPG::System::Vehicle.new
1227
+ @ship = RPG::System::Vehicle.new
1228
+ @airship = RPG::System::Vehicle.new
1229
+ @title1_name = ''
1230
+ @title2_name = ''
1231
+ @opt_draw_title = true
1232
+ @opt_use_midi = false
1233
+ @opt_transparent = false
1234
+ @opt_followers = true
1235
+ @opt_slip_death = false
1236
+ @opt_floor_death = false
1237
+ @opt_display_tp = true
1238
+ @opt_extra_exp = false
1239
+ @window_tone = Tone.new(0, 0, 0)
1240
+ @title_bgm = RPG::BGM.new
1241
+ @battle_bgm = RPG::BGM.new
1242
+ @battle_end_me = RPG::ME.new
1243
+ @gameover_me = RPG::ME.new
1244
+ @sounds = Array.new(24) { RPG::SE.new }
1245
+ @test_battlers = []
1246
+ @test_troop_id = 1
1247
+ @start_map_id = 1
1248
+ @start_x = 0
1249
+ @start_y = 0
1250
+ @terms = RPG::System::Terms.new
1251
+ @battleback1_name = ''
1252
+ @battleback2_name = ''
1253
+ @battler_name = ''
1254
+ @battler_hue = 0
1255
+ @edit_map_id = 1
1256
+ end
1257
+
1258
+ attr_accessor :game_title
1259
+ attr_accessor :version_id
1260
+ attr_accessor :japanese
1261
+ attr_accessor :party_members
1262
+ attr_accessor :currency_unit
1263
+ attr_accessor :skill_types
1264
+ attr_accessor :weapon_types
1265
+ attr_accessor :armor_types
1266
+ attr_accessor :elements
1267
+ attr_accessor :switches
1268
+ attr_accessor :variables
1269
+ attr_accessor :boat
1270
+ attr_accessor :ship
1271
+ attr_accessor :airship
1272
+ attr_accessor :title1_name
1273
+ attr_accessor :title2_name
1274
+ attr_accessor :opt_draw_title
1275
+ attr_accessor :opt_use_midi
1276
+ attr_accessor :opt_transparent
1277
+ attr_accessor :opt_followers
1278
+ attr_accessor :opt_slip_death
1279
+ attr_accessor :opt_floor_death
1280
+ attr_accessor :opt_display_tp
1281
+ attr_accessor :opt_extra_exp
1282
+ attr_accessor :window_tone
1283
+ attr_accessor :title_bgm
1284
+ attr_accessor :battle_bgm
1285
+ attr_accessor :battle_end_me
1286
+ attr_accessor :gameover_me
1287
+ attr_accessor :sounds
1288
+ attr_accessor :test_battlers
1289
+ attr_accessor :test_troop_id
1290
+ attr_accessor :start_map_id
1291
+ attr_accessor :start_x
1292
+ attr_accessor :start_y
1293
+ attr_accessor :terms
1294
+ attr_accessor :battleback1_name
1295
+ attr_accessor :battleback2_name
1296
+ attr_accessor :battler_name
1297
+ attr_accessor :battler_hue
1298
+ attr_accessor :edit_map_id
1299
+ end
1300
+
1301
+ class System::Vehicle
1302
+ def initialize
1303
+ @character_name = ''
1304
+ @character_index = 0
1305
+ @bgm = RPG::BGM.new
1306
+ @start_map_id = 0
1307
+ @start_x = 0
1308
+ @start_y = 0
1309
+ end
1310
+
1311
+ attr_accessor :character_name
1312
+ attr_accessor :character_index
1313
+ attr_accessor :bgm
1314
+ attr_accessor :start_map_id
1315
+ attr_accessor :start_x
1316
+ attr_accessor :start_y
1317
+ end
1318
+
1319
+ class System::Terms
1320
+ def initialize
1321
+ @basic = Array.new(8) { '' }
1322
+ @params = Array.new(8) { '' }
1323
+ @etypes = Array.new(5) { '' }
1324
+ @commands = Array.new(23) { '' }
1325
+ end
1326
+
1327
+ attr_accessor :basic
1328
+ attr_accessor :params
1329
+ attr_accessor :etypes
1330
+ attr_accessor :commands
1331
+ end
1332
+
1333
+ class System::TestBattler
1334
+ def initialize
1335
+ @actor_id = 1
1336
+ @level = 1
1337
+ @equips = [0, 0, 0, 0, 0]
1338
+ end
1339
+
1340
+ attr_accessor :actor_id
1341
+ attr_accessor :level
1342
+ attr_accessor :equips
1343
+ end
1344
+
1345
+ class AudioFile
1346
+ def initialize(name = '', volume = 100, pitch = 100)
1347
+ @name = name
1348
+ @volume = volume
1349
+ @pitch = pitch
1350
+ end
1351
+
1352
+ attr_accessor :name
1353
+ attr_accessor :volume
1354
+ attr_accessor :pitch
1355
+ end
1356
+
1357
+ class BGM < AudioFile
1358
+ @@last = RPG::BGM.new
1359
+
1360
+ def play(pos = 0)
1361
+ if @name.empty?
1362
+ Audio.bgm_stop
1363
+ @@last = RPG::BGM.new
1364
+ else
1365
+ Audio.bgm_play('Audio/BGM/' + @name, @volume, @pitch, pos)
1366
+ @@last = self.clone
1367
+ end
1368
+ end
1369
+
1370
+ def replay
1371
+ play(@pos)
1372
+ end
1373
+
1374
+ def self.stop
1375
+ Audio.bgm_stop
1376
+ @@last = RPG::BGM.new
1377
+ end
1378
+
1379
+ def self.fade(time)
1380
+ Audio.bgm_fade(time)
1381
+ @@last = RPG::BGM.new
1382
+ end
1383
+
1384
+ def self.last
1385
+ @@last.pos = Audio.bgm_pos
1386
+ @@last
1387
+ end
1388
+
1389
+ attr_accessor :pos
1390
+ end
1391
+
1392
+ class BGS < AudioFile
1393
+ @@last = RPG::BGS.new
1394
+
1395
+ def play(pos = 0)
1396
+ if @name.empty?
1397
+ Audio.bgs_stop
1398
+ @@last = RPG::BGS.new
1399
+ else
1400
+ Audio.bgs_play('Audio/BGS/' + @name, @volume, @pitch, pos)
1401
+ @@last = self.clone
1402
+ end
1403
+ end
1404
+
1405
+ def replay
1406
+ play(@pos)
1407
+ end
1408
+
1409
+ def self.stop
1410
+ Audio.bgs_stop
1411
+ @@last = RPG::BGS.new
1412
+ end
1413
+
1414
+ def self.fade(time)
1415
+ Audio.bgs_fade(time)
1416
+ @@last = RPG::BGS.new
1417
+ end
1418
+
1419
+ def self.last
1420
+ @@last.pos = Audio.bgs_pos
1421
+ @@last
1422
+ end
1423
+
1424
+ attr_accessor :pos
1425
+ end
1426
+
1427
+ class ME < AudioFile
1428
+ def play
1429
+ if @name.empty?
1430
+ Audio.me_stop
1431
+ else
1432
+ Audio.me_play('Audio/ME/' + @name, @volume, @pitch)
1433
+ end
1434
+ end
1435
+
1436
+ def self.stop
1437
+ Audio.me_stop
1438
+ end
1439
+
1440
+ def self.fade(time)
1441
+ Audio.me_fade(time)
1442
+ end
1443
+ end
1444
+
1445
+ class SE < AudioFile
1446
+ def play
1447
+ unless @name.empty?
1448
+ Audio.se_play('Audio/SE/' + @name, @volume, @pitch)
1449
+ end
1450
+ end
1451
+
1452
+ def self.stop
1453
+ Audio.se_stop
1454
+ end
1455
+ end
1456
+
1457
1457
  end