R3EXS 1.0.5 → 1.1.1

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