-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquasi.rb
787 lines (742 loc) · 28 KB
/
quasi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
#==============================================================================
# ** Quasi v0.4.9
#==============================================================================
# Adds new methods to VXA's default classes and modules which is found to
# be useful.
#
# These methods will be used in other scripts create by Quasi, so instead of
# making them over and over, they will be placed here.
#==============================================================================
# How to install:
# - Place this above Main but below Materials.
# - All my other scripts should go below this unless stated otherwise.
#==============================================================================
module Quasi
#--------------------------------------------------------------------------
# * Master volume control. VXA default sounds are too loud on my pc
# so I have it set at -70 when testing scripts.
#--------------------------------------------------------------------------
VOLUME = -50
#--------------------------------------------------------------------------
# * Allows for a quick test by skipping the title screen starting a
# new game. Only works when play testing.
#--------------------------------------------------------------------------
QUICKTEST = true
#--------------------------------------------------------------------------
# * Set to true to use quasis follower mod, or false to ignore quasis
# follower mod. With quasis mod, followers are only created when they
# are present. By default followers are created even when there's 1 character.
# *NOTE* Might be buggy, but its nice for games that do not use followers
#--------------------------------------------------------------------------
FOLLOWERS = false
#==============================================================================
# ** New Features / Addons
#==============================================================================
#------------------------------------------------------------------------------
# * State add fixed Parameter value
#------------------------------------------------------------------------------
# States can now add fixed values to parameters, instead of by a percent
# from the features list!
# To use:
# Inside the state database you create a note tag
# <param change>
# param => value
# </param change>
# Where param can be: MHP, MMP, ATK, DEF, MAT, MDF, AGI, LUK, HRT, MRT, TRT
#
# HRT, MRT, TRT are new params that work like HRG, MRG, TGR but instead of
# increasing/decreasing by a percentage, it ticks a fixed value.
#
# Value can be a formula that accepts a and v[id], similiar to skill formulas
# But does not take b!
#
# Example:
# <param change>
# MHP => 100
# ATK => 20
# </param change>
# Would result in that state adding 100 to max hp and 20 to attack.
#
# <param change>
# MHP => -100
# MRT => 5 + v[1]
# </param change>
# Would result in that state removes 100 hp but you will have an mp regen of
# 5 + value of variable 1
# * value can be negative
# * param is not case sensative
#
#------------------------------------------------------------------------------
# * Animation zoom range
#------------------------------------------------------------------------------
# Allows for animations to display at different sizes each time they are played.
# To use:
# In animation's name include a range inside <>'s
#
# Example:
# 02:Hit Fire <-50..50>
# Animation will play at a random size between -50% to 50%
#
#==============================================================================
# Change Log
#------------------------------------------------------------------------------
# v0.4.9 - 1/5/15
# - Move def linepoints to Math module
# --
# v0.4.8 - 12/30/14
# - Fixed bug with int? method
# --
# v0.4.7 - 12/28/14
# - Fixed bug in grab_comment method
# --
# v0.4.6 - 12/28/14
# - Fixed typo in the Hex color method
# --
# v0.4.5 - 12/23/14
# - Added Hex color code compatibility
#==============================================================================#
# By Quasi (http://quasixi.com/) || (https://github.com/quasixi/RGSS3)
# - 11/11/14
#==============================================================================#
# ** Stop! Do not edit anything below, unless you know what you **
# ** are doing! **
#==============================================================================#
#--------------------------------------------------------------------------
# * Simple regex grabber
# Used for my notetags
#--------------------------------------------------------------------------
def self.regex(string, regex, returnvalue=:na, default=false)
if string =~ regex
if $1
case returnvalue
when :string
result = $1.to_s
when :int
result = $1.to_i
when :array
result = $1.to_ary
when :intarray
result = regex(string, regex, :array, default)
when :linearray
result = []
for line in $1.split("\r\n")
result << line if line != ""
end
when :linehash
result = {}
for line in $1.split("\r\n")
next if line == ""
hash = line.split("=>")
key = hash[0] ? hash[0].strip : nil
value = hash[1] ? hash[1].strip : nil
key = key.int? ? key.to_i : (key.sym? ? key.delete(":").to_sym : key) if key
if value
if value.int?
value = value.to_i
elsif value.sym?
value = value.delete(":").to_sym
elsif value.ary?
value = value.gsub(/[\[\]]/,"").to_ary
end
end
result[key] = value
end
else
result = $1
end
else
result = true
end
else
result = default
end
return result
end
#--------------------------------------------------------------------------
# * Converts hex color to rgb
#--------------------------------------------------------------------------
def self.color(hex, alpha=255)
r = hex[0, 2].to_i(16)
g = hex[2, 2].to_i(16)
b = hex[4, 2].to_i(16)
return Color.new(r, g, b, alpha)
end
end
$imported = {} if $imported.nil?
$imported["Quasi"] = 0.49
#==============================================================================
# ** SceneManager
#------------------------------------------------------------------------------
# This module manages scene transitions. For example, it can handle
# hierarchical structures such as calling the item screen from the main menu
# or returning from the item screen to the main menu.
#==============================================================================
module SceneManager
#--------------------------------------------------------------------------
# * Alias self.run
#--------------------------------------------------------------------------
class << self
alias qsm_run run
end
#--------------------------------------------------------------------------
# * Execute
#--------------------------------------------------------------------------
def self.run
if Quasi::QUICKTEST && $TEST && !$BTEST
DataManager.init
Audio.setup_midi if use_midi?
DataManager.setup_new_game
$game_map.autoplay
@scene = Scene_Map.new
@scene.main while @scene
else
qsm_run
end
end
end
#==============================================================================
# ** Game_BattlerBase
#------------------------------------------------------------------------------
# This base class handles battlers. It mainly contains methods for calculating
# parameters. It is used as a super class of the Game_Battler class.
#==============================================================================
class Game_BattlerBase
def hrt; qparam(0); end # HRT Hp ReGeneration tick
def mrt; qparam(1); end # MRT Mp ReGeneration tick
def trt; qparam(2); end # TRT Tp ReGeneration tick
alias qgbb_param param
#--------------------------------------------------------------------------
# * Get Parameter
#--------------------------------------------------------------------------
def param(param_id)
value = qgbb_param(param_id)
value += state_param_plus(param_id)
[[value, param_max(param_id)].min, param_min(param_id)].max.to_i
end
def state_param_plus(param_id)
value = 0
states.each do |state|
next unless state.param_change
a = self
v = $game_variables
param_change = eval(state.param_change[param_id].to_s) rescue 0
value += param_change if param_change
end
return value
end
def qparam(qparam_id)
return state_param_plus(qparam_id + 8)
end
end
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * Regenerate HP
#--------------------------------------------------------------------------
def regenerate_hp
damage = -(mhp * hrg).to_i - hrt
perform_map_damage_effect if $game_party.in_battle && damage > 0
@result.hp_damage = [damage, max_slip_damage].min
self.hp -= @result.hp_damage
end
#--------------------------------------------------------------------------
# * Regenerate MP
#--------------------------------------------------------------------------
def regenerate_mp
@result.mp_damage = -(mmp * mrg).to_i - mrt
self.mp -= @result.mp_damage
end
#--------------------------------------------------------------------------
# * Regenerate TP
#--------------------------------------------------------------------------
def regenerate_tp
self.tp += 100 * trg + trt
end
end
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# This class handles parties. Information such as gold and items is included.
# Instances of this class are referenced by $game_party.
#==============================================================================
class Game_Party < Game_Unit
if Quasi::FOLLOWERS
#--------------------------------------------------------------------------
# * Add an Actor
#--------------------------------------------------------------------------
def add_actor(actor_id)
if [email protected]?(actor_id)
@actors.push(actor_id)
$game_player.followers.recreate
SceneManager.scene.spriteset_refresh if SceneManager.scene_is?(Scene_Map)
end
$game_player.refresh
$game_map.need_refresh = true
end
#--------------------------------------------------------------------------
# * Remove Actor
#--------------------------------------------------------------------------
def remove_actor(actor_id)
@actors.delete(actor_id)
$game_player.followers.recreate
SceneManager.scene.spriteset_refresh if SceneManager.scene_is?(Scene_Map)
$game_player.refresh
$game_map.need_refresh = true
end
end
#--------------------------------------------------------------------------
# * Get Average Level of Party Members
#--------------------------------------------------------------------------
def avg_level
avg = 0
members.each {|actor| avg += actor.level}
avg /= members.size
return avg
end
#--------------------------------------------------------------------------
# * Get Average Value of param of Party Members
#--------------------------------------------------------------------------
def avg_param(param_id)
avg = 0
members.each {|actor| avg += actor.param(param_id)}
avg /= members.size
return avg
end
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Clone event from any map to x,y pos
#--------------------------------------------------------------------------
def clone_event(x,y,mapid,eventid)
cmap = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
return if cmap.events[eventid].nil?
cmap.events[eventid].x = x
cmap.events[eventid].y = y
@events[@events.length+1] = Game_Event.new(mapid, cmap.events[eventid])
SceneManager.scene.spriteset_refresh
refresh
end
end
#==============================================================================
# ** Game_Follower
#------------------------------------------------------------------------------
# This class handles followers. A follower is an allied character, other than
# the front character, displayed in the party. It is referenced within the
# Game_Followers class.
#==============================================================================
class Game_Follower < Game_Character
if Quasi::FOLLOWERS
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(member_index, preceding_character)
super()
@member_index = member_index
@preceding_character = !preceding_character ? $game_player : preceding_character
@transparent = $data_system.opt_transparent
@through = true
end
end
end
#==============================================================================
# ** Game_Followers
#------------------------------------------------------------------------------
# This is a wrapper for a follower array. This class is used internally for
# the Game_Player class.
#==============================================================================
class Game_Followers
if Quasi::FOLLOWERS
#--------------------------------------------------------------------------
# * Object Initialization
# leader: Lead character
#--------------------------------------------------------------------------
def initialize(leader)
@visible = $data_system.opt_followers
@gathering = false # Gathering processing underway flag
@data = []
$data_system.party_members.each_index do |index|
next if index == 0
prec = index == 1 ? leader : @data[-1]
@data.push(Game_Follower.new(index, prec))
end
end
#--------------------------------------------------------------------------
# * Recreate
#--------------------------------------------------------------------------
def recreate
@data = []
$game_party.battle_members.each_index do |index|
next if index == 0
prec = index == 1 ? $game_player : @data[-1]
@data.push(Game_Follower.new(index, prec))
end
synchronize($game_player.x, $game_player.y, $game_player.direction)
end
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# This class handles events. Functions include event page switching via
# condition determinants and running parallel process events. Used within the
# Game_Map class.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Grabs comment from event
#--------------------------------------------------------------------------
def grab_comment(regex,default=nil)
unless @list
return default unless default.nil?
return false
end
reg = []
@list.each do |cmd|
next if cmd.code != 108 && cmd.code != 408
comment = cmd.parameters[0]
next unless comment =~ regex
if !default.nil?
reg << $1
else
reg = [true]
end
end
return default if reg.empty?
return reg if reg.length > 1
return reg[0]
end
#--------------------------------------------------------------------------
# * Grabs all comments from event page
#--------------------------------------------------------------------------
def comments
return unless @list
comments = ""
@list.each do |cmd|
next if cmd.code != 108 && cmd.code != 408
comments += cmd.parameters[0] + "\r\n"
end
return comments
end
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * Checks if any switch is equal to the value
#--------------------------------------------------------------------------
def any_switch?(switches, value=true)
return switches.any?{|i| $game_switches[i] == value}
end
#--------------------------------------------------------------------------
# * Checks if all switches are equal to the value
#--------------------------------------------------------------------------
def all_switch?(switches, value=true)
return switches.all?{|i| game_switches[i] == value}
end
end
#==============================================================================
# ** Sprite_Base
#------------------------------------------------------------------------------
# A sprite class with animation display processing added.
#==============================================================================
class Sprite_Base < Sprite
#--------------------------------------------------------------------------
# * Start Animation
#--------------------------------------------------------------------------
alias :quasi_start_animation :start_animation
def start_animation(animation, mirror = false)
quasi_start_animation(animation, mirror)
if @animation
@rand = qrand(@animation.zoom_range)
end
end
#--------------------------------------------------------------------------
# * Set Animation Sprite
# frame : Frame data (RPG::Animation::Frame)
#--------------------------------------------------------------------------
alias :quasi_animation_set :animation_set_sprites
def animation_set_sprites(frame)
quasi_animation_set(frame)
return if @rand == 0
cell_data = frame.cell_data
@ani_sprites.each_with_index do |sprite, i|
next unless sprite
pattern = cell_data[i, 0]
next if !pattern || pattern < 0
sprite.zoom_x += @rand/100.0
sprite.zoom_y += @rand/100.0
end
end
end
#==============================================================================
# ** Scene_Base
#------------------------------------------------------------------------------
# This is a super class of all scenes within the game.
#==============================================================================
class Scene_Base
#--------------------------------------------------------------------------
# * Wait
#--------------------------------------------------------------------------
def wait(duration)
duration.times { update_basic }
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs the map screen processing.
#==============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# * Refresh spriteset
#--------------------------------------------------------------------------
def spriteset_refresh
@spriteset.refresh_characters
end
end
#==============================================================================
# ** Kernel
#==============================================================================
module Kernel
#--------------------------------------------------------------------------
# * New random method that recordes the previous 3 randoms
# if current random is equal to any of the previous 3, it runs again
#--------------------------------------------------------------------------
def qrand(max)
max = 1 if max == 0
@prevRand = [] if @prevRand.nil?
value = Random.new.rand(max)
value = Random.new.rand(max) if @prevRand.include?(value)
@prevRand << value
@prevRand.shift if @prevRand.length > 3
return value
end
end
#==============================================================================
# ** Math
#==============================================================================
module Math
#--------------------------------------------------------------------------
# * Calculate angle between 2 points
#--------------------------------------------------------------------------
def self.angle(point1, point2, quad4 = false)
x = point2[0] - point1[0]
y = point2[1] - point1[1]
y *= -1 if quad4
radian = atan2(y, x)
angle = (radian * 180 / PI)
angle = 360 + angle if angle < 0
return angle
end
#--------------------------------------------------------------------------
# * Calculate pos on a circle
#--------------------------------------------------------------------------
def self.circle(cx, cy, radius, angle)
x = cx + Math.sin(angle)*radius
y = cy + Math.cos(angle)*radius
return [x, y]
end
#--------------------------------------------------------------------------
# * Returns the points on a line
# line = [x1, y1, x2, y2]
#--------------------------------------------------------------------------
def self.linepoints(line, precision=1)
sx, sy, ex, ey = line
points = []
x1 = sx < ex ? sx.floor : ex.floor
y1 = sy < ey ? sy.floor : ey.floor
x2 = x1 == sx ? ex.floor : sx.floor
y2 = y1 == sy ? ey.floor : sy.floor
distx = (sx - ex)
disty = (sy - ey)
slope = disty / distx if distx != 0
if distx.abs > disty.abs
if slope
for x in x1..x2
next unless x % precision == 0
y = slope == 0 ? sy : ((x-sx)*slope).round + sy
points << [x, y]
end
end
else
if slope
for y in y1..y2
next unless y % precision == 0
x = slope == 0 ? sx : ((y-sy)/slope).round + sx
points << [x, y]
end
else
for y in y1..y2
next unless y % precision == 0
points << [sx, y]
end
end
end
points.reverse! if points[0] != [sx, sy]
return points
end
end
#==============================================================================
# ** String
#==============================================================================
class String
#--------------------------------------------------------------------------
# * Converts the string to a range
#--------------------------------------------------------------------------
def to_range
return unless self.include? ".."
literal = (self.include?"...") ? literal = "..." : literal = ".."
range = self.split(literal).map {|x| x.to_i}
return range[0]..range[1] if literal == ".."
return range[0]...range[1]
end
#--------------------------------------------------------------------------
# * Converts the string to an array
#--------------------------------------------------------------------------
def to_ary
ary = self.split(",")
ary.map!{|s| s.int? ? s.to_i : s}
return ary
end
#--------------------------------------------------------------------------
# * Checks if string only contains letters
#--------------------------------------------------------------------------
def abc?
return self !~ /\d/
end
#--------------------------------------------------------------------------
# * Checks if string only contains numbers
#--------------------------------------------------------------------------
def int?
self.strip.to_i.to_s == self.strip
end
#--------------------------------------------------------------------------
# * Checks if string is in Symbol format
#--------------------------------------------------------------------------
def sym?
return self[0] == ":"
end
#--------------------------------------------------------------------------
# * Checks if string is in Symbol format
#--------------------------------------------------------------------------
def ary?
return self[0] == "[" && self[self.size-1] == "]"
end
end
#==============================================================================
# ** Array
#==============================================================================
class Array
def to_h
return Hash[self]
end
end
#==============================================================================
# ** Array
#==============================================================================
class Color
def to_hex
r = red.to_i.to_s(16).rjust(2,"0")
g = green.to_i.to_s(16).rjust(2,"0")
b = blue.to_i.to_s(16).rjust(2,"0")
return r + g + b
end
end
#==============================================================================
# ** RPG::State
#==============================================================================
class RPG::State
def param_change
if !@param_change
regex = /<(?:param_change|param change)>(.*)<\/(?:param_change|param change)>/im
temp = Quasi::regex(@note, regex, :linehash, false)
id = {"mhp" => 0, "mmp" => 1, "atk" => 2, "def" => 3, "mat" => 4,
"mdf" => 5, "agi" => 6, "luk" => 7,
"hrt" => 8, "mrt" => 9, "trt" => 10}
if temp
@param_change = temp.map {|key, v| [id[key.downcase] || key, v]}.to_h
else
@param_change = false
end
end
return @param_change
end
end
#==============================================================================
# ** RPG::Animation
#==============================================================================
class RPG::Animation
#--------------------------------------------------------------------------
# * Zoom Range name tag
#--------------------------------------------------------------------------
def zoom_range
if !@zoom_range
@zoom_range = @name =~ /<(.*)>/i ? $1.to_range : 0
end
return @zoom_range
end
end
#==============================================================================
# ** RPG::SE | RPG::BGM | RPG::ME | RPG::BGS
#==============================================================================
class RPG::SE < RPG::AudioFile
def play
unless @name.empty?
volume = @volume + Quasi::VOLUME
volume = 0 if volume < 0
Audio.se_play('Audio/SE/' + @name, volume, @pitch)
end
end
end
class RPG::BGM < RPG::AudioFile
def play(pos = 0)
if @name.empty?
Audio.bgm_stop
@@last = RPG::BGM.new
else
volume = @volume + Quasi::VOLUME
volume = 0 if volume < 0
Audio.bgm_play('Audio/BGM/' + @name, volume, @pitch, pos)
@@last = self.clone
end
end
end
class RPG::ME < RPG::AudioFile
def play
if @name.empty?
Audio.me_stop
else
volume = @volume + Quasi::VOLUME
volume = 0 if volume < 0
Audio.me_play('Audio/ME/' + @name, volume, @pitch)
end
end
end
class RPG::BGS < RPG::AudioFile
def play(pos = 0)
if @name.empty?
Audio.bgs_stop
@@last = RPG::BGS.new
else
volume = @volume + Quasi::VOLUME
volume = 0 if volume < 0
Audio.bgs_play('Audio/BGS/' + @name, volume, @pitch, pos)
@@last = self.clone
end
end
end