-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFishing Mini Game.rb
2347 lines (2018 loc) · 58.3 KB
/
Fishing Mini Game.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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#------------------------------------------------------------------------------#
# Galv's Fishing Mini Game
#------------------------------------------------------------------------------#
# For: RPGMAKER VX ACE
# Version 1.5
#------------------------------------------------------------------------------#
# NOTICE: This script is NOT free for commercial use.
# Contact Galv via PM at one of the following forums:
# http://www.rpgmakervxace.net/
# http://forums.rpgmakerweb.com/
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# 2015-02-07 - Version 1.5 - rare crash hopefully fixed
# 2013-04-22 - Version 1.4 - added fish statistics scene
# - added scripts to use in control variables to use
# data in eventing.
# 2013-04-22 - Version 1.3 - fixed a bug with crashing when equipping rod
# 2013-04-22 - Version 1.2 - stopped the fish caught message from ending too
# soon. Added controls to HUD image to look nicer.
# 2013-04-21 - Version 1.1 - added ability to run common event when fish caught
# - fixed a big image disposing bug (oops!)
# - upgraded the fish caught message with custom text
# options and image.
# - added storing fish data and script calls to use it
# 2013-04-20 - Version 1.0 - release
#------------------------------------------------------------------------------#
# This script allows the player to play a fishing mini game.
#
# HOW TO PLAY
# The player needs a rod item and bait items in order to fish. They choose
# which rod and bait to equip, each having a different use. Once equipped, the
# player casts his line into the water and must try to reel the line in to get
# the bait close enough to a fish to take it. The action key or right arrow
# will reel the line in.
# Once a fish as the bait, the player must reel it in, but be careful to not
# reel in while the fish is pulling to the left, else the line strength will
# weaken and eventually break.
#
# RODS
# The rod strength of an item detemines how much strain the line can take
# before it breaks. Also, the higher the rod strength is above a fish's 'pull'
# will increase the speed the fish is reeled in. If a fish has more pull than
# a rod's strength, it will break the line much quicker than normal.
#
# BAIT
# Baits have 2 attributes - type and weight. Fish can be set up to only eat
# cetain types of bait. Weight determines how fast the bait sinks in the water.
#
# FISH
# Fish can be set up with a bunch of options (see futher down). Note that these
# options allow you to create "fish" that aren't fish. For example, you could
# make a crab that can only move on the bottom of the water.
#
# CONTROLS
# Press Z at the right time in the power bar to detemine casting distance.
# Hold the right arrow to reel in.
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# SCRIPT CALLS
#------------------------------------------------------------------------------#
#
# fish_back(w,x,y,z) # Change background images used in fishing scene.
# # w = over, x = under, y = flow, z = flow opacity
#
# fish_opt("Music") # Change fishing options
#
#
#
# add_fish(x,x,x,x) # Add these fish_id's into the pond.
#
# rand_fish(x,min,max) # Add a random amount between min and max of fish with
# # fish_id x into the pond. Make min a negative number to
# # increase the chance the fish will not appear at all.
#
# fishing # Starts the fishing scene (make sure you add fish using
# # any amount of the script calls above before you call
# # the fishing scene).
#
# fishing_stats # Starts the fishing statistics scene.
#
#------------------------------------------------------------------------------#
# EXAMPLE OF USE
# fish_back(3,0,2,150) # fishing will use images from /Graphics/GFish/ folder
# # over3, under0 and flow2. flow2 will be at 150 opacity
# # Default is fish_back(0,0,0,120)
# fish_opt("Town1") # Changes music to Town1
# add_fish(1,1,2) # Adds 2 x fish with id1 and 1 x fish with id2 to pond
# rand_fish(0,2,10) # Adds 2-10 fish with id0 to pond.
#
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# Notetag for ITEMS
#------------------------------------------------------------------------------#
#
# <bait: type,weight> # Items with this tag can be used as bait.
# # type = a number to determine what fish like it
# # weight = speed bait sinks in the water (Default 10)
#
# <bait_img: image> # The image name of to use a different bait spritesheet
# # /Graphics/GFish/ folder. (use same layout as bait.png)
#
# <rod: x> # Items with this tag can be used as fishing rods.
# # x = strength of the rod (Minimum 1). The rod strength
# # determines how long it takes for the line to snap and
# # also decreases the amount of pull a fish has.
#
# <rod_img: image> # The image name of a new rod spritesheet to use from
# # /Graphics/GFish/ folder. (use same layout as rod.png)
#
#------------------------------------------------------------------------------#
# EXAMPLES OF USE:
# <bait: 7,10> # Fish with bait_type 7 will eat it. 10 weight is default.
# <bait_img: bait2> # Uses /Graphics/GFish/Bait2.png for the bait image.
# <rod_img: rod2> # Uses /Graphics/GFish/Bait2.png for the held pole image.
# <rod: 1> # A rod with strength 1 (weakest)
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# SCRIPT for CONTROL VARIABLES
#------------------------------------------------------------------------------#
# $game_system.fish[id].caught # get number of that type of fish caught
# $game_system.fish[id].length # get the record length of that fish caught
# $game_system.fish[id].width # get the record width of that fish caught
# count_all_fish # get the total of all fish caught
# record_fish(data,id?) # data can be :weight or :length
# # this will return data of your largest fish.
# # id? is optional. It will return fish id if true
# # if you haven't caught a fish, this will be -1
#------------------------------------------------------------------------------#
# EXAMPLE
# record_fish(:length,true) # gets the id of your longest fish
# record_fish(:length) # gets the length of your longest fish
# record_fish(:weight,true) # gets the id of your heaviest fish
# record_fish(:weight) # gets the weight of your heaviest fish
#------------------------------------------------------------------------------#
($imported ||= {})["Galv_Fishing"] = true
module GFISH
#-------------------------------------------------------------------------------
#
# * SETTINGS
#
#-------------------------------------------------------------------------------
# Gameplay
FISH_VAR = 1 # The variable used to store the fish_id of the last fish you
# have caught. This can be used, for example, in conjunction
# with the common event fish setting for conditional branches.
# Audio
DEFAULT_BGM = "Angevin" # Default fishing music
DEFAULT_SE = "Up4" # SE that plays when you successfully catch a fish
CAST_SE = "Wind4" # SE when casting line
SPLASH_SE = "Dive" # SE when bait lands in water
BROKE_SE = "Blow5" # SE when line breaks
# Vocab
POWER = " MEDIDOR " # Text used for power meter
CTEXT_BEFORE = " Você pescou um " # Text that appears before caught fish item
CTEXT_AFTER = " ! " # Text that appears after caught fish item
CATCH_ITEM_0 = " Pegou " # Text appears when you catch a fish that has
# item 0 in it's setup and no custom text.
CONTROLS = "" # Text that appears top right of screen.
CONTROL_FONT_SIZE = 20 # I added the controls into the HUD instead of using
# this text.
STAT_HEADING = " ESTATÍSTICAS " # Heading of the fish statistics scene
TOTAL_FISH = " Total de peixes pegos " # Text before the total number of fish caught
FISH_TYPES = " Tipos de peixes " # Text displayed before how many type of fish
# player has caught.
RECORD_FISH = " Tamanho " # Text for biggest length fish player has caught
FISH_CAUGHT = " Apanhados "
FISH_LENGTH = " Comprimento "
FISH_WEIGHT = " Peso "
# Other
ROD_X = 0 # Offset the rod's x position
ROD_Y = 0 # Offset the rod's y position
DECIMALS = true # Use decimal places for weight and height of fish stats.
#-------------------------------------------------------------------------------
# * FISH SETUP
#-------------------------------------------------------------------------------
FISH = [] # don't touch
#-------------------------------------------------------------------------------
# Here is where you set up all the possible fish you can catch and certain
# attributes about each fish. The number in each FISH[x] below must be unique.
# This is the 'fish_id' used to add fish manually to a pond
#-------------------------------------------------------------------------------
FISH[0] = [ # Purple Fish
"fish2", # graphic
5, # speed
0, # pull
1, # move type
[2,8], # level
-1, # x pos
23, # item
[1,2,3], # bait type
"", # custom se
[20,2], # range
0, # common event
[150,310], # length
[23,52], # weight
true, # stats
"", # custom txt
]
#-------------------------------------------------------------------------------
FISH[1] = [ # Green Fish
"fish1", # graphic
8, # speed
0, # pull
1, # move type
[1,9], # level
-1, # x pos
24, # item
[2,4], # bait type
"", # custom se
[20,2], # range
0, # common event
[100,210], # length
[20,45], # weight
true, # stats
"", # custom txt
]
#-------------------------------------------------------------------------------
FISH[2] = [ # Rock
"rock", # graphic
0, # speed
99, # pull
-1, # move type
[0,0], # level
200, # x pos
0, # item
[1,2,3,4], # bait type
"", # custom se
[20,20], # range
0, # common event
[400,400], # length
[999,999], # weight
false, # stats
"", # custom txt
]
#-------------------------------------------------------------------------------
FISH[3] = [ # A chest!
"chest", # graphic
5, # speed
2, # pull
0, # move type
[0,0], # level
400, # x pos
26, # item
[6], # bait type
"Item3", # custom se
[20,20], # range
0, # common event
[350,350], # length
[200,200], # weight
false, # stats
"", # custom txt
]
#-------------------------------------------------------------------------------
FISH[4] = [ # A Monster!
"jellyfish", # graphic
5, # speed
1, # pull
2, # move type
[0,5], # level
-1, # x pos
0, # item
[1,2,3,4], # bait type
"Item3", # custom se
[40,3], # range
1, # common event
[30,60], # length
[200,200], # weight
false, # stats
"Você pegou um MONSTRO!", # custom txt
]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# EXPLANATION
# graphic = the image used from /Graphics/GFish/ folder.
# speed = the swim speed of the fish. 10 is default.
# pull = the higher their pull, the more difficult it is to reel in and
# quicker the line will break.
# move type = the type of movement.
# -1 = unmovable - use for things like rocks to snag the line
# - will constantly stress the line when reeling in
# 0 = inanimate - use for things like chests or quest items
# - will constantly stress the line when reeling in
# 1 = passive - normal fish movement
# - will stress the line only when fish is pulling
# 2 = erratic - fish changes direction more often
# - will stress the line only when fish is pulling
# level = [lowest,highest] fish swims. 0 = ground, 10 = water surface
# x pos = the fish will start in this x position. -1 is random.
# item = the item that will be gained if fish is caught (item id)
# bait type = list of bait types that the fish will eat.
# custom se = play a different SE instead of DEFAULT_SE when fish caught
# range = [detect,take] distance from bait a fish will detect and take it
# default is detect 20, take 2.
# common event = When this fish is caught, it will exit and run common event
# length = no gameplay effect. For fish stats only. rand between [min,max]
# weight = no gameplay effect. For fish stats only. rand between [min,max]
# stats = include in the fish-caught stats page? true or false
# custom txt = text displayed instead of the item name when catching a fish and
# in the fish stat scene.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# * END SETTINGS
#
#-------------------------------------------------------------------------------
end
#----------------------#
#---| GAME_INTERPRETER |----------------------------------------------------
#----------------------#
class Game_Interpreter
def fishing
$game_system.save_bgm
command_221
SceneManager.call(Scene_GFish)
wait(1)
$game_system.fish_list = []
command_222
end
def fishing_stats
SceneManager.call(Scene_FishStats)
end
def count_all_fish
fish_caught = 0
$game_system.fish.each { |fish|
next if !fish.stats
fish_caught += fish.caught
}
return fish_caught
end
def record_fish(data,get_id = false)
check = 0
fish_id = -1
$game_system.fish.each { |fish|
next if !fish.stats
if data == :length && check < fish.length
check = fish.length
fish_id = fish.id
elsif data == :weight && check < fish.weight
check = fish.weight
fish_id = fish.id
end
}
if get_id
return fish_id
else
return check
end
end
def calculate_data
@fish_caught = 0
length_check = 0
@c = 0
@t = 0
@longest_fish = nil
$game_system.fish.each { |fish|
next if !fish.stats
@fish_caught += fish.caught
if length_check < fish.length
length_check = fish.length
@longest_fish = fish.id
end
@c += 1 if fish.caught > 0
@t += 1
}
end
def fish_back(over,under,flow,flowopacity)
$game_system.fishb = [over,under,flow,flowopacity]
end
def fish_opt(music)
$game_system.fishs[0] = music
end
def add_fish(*args)
$game_system.fish_list += [*args]
end
def rand_fish(fish_id,min,max)
amount = (rand(min - max) + min).to_i
amount.times { |i| $game_system.fish_list << fish_id } if amount > 0
end
end
#-----------#
#---| CACHE |---------------------------------------------------------------
#-----------#
module Cache
def self.gfish(filename)
load_bitmap("Graphics/GFish/", filename)
end
end # Cache
#-----------------#
#---| GAME_SYSTEM |---------------------------------------------------------
#-----------------#
class Game_System
attr_accessor :fish # Data of all fish caught
attr_accessor :fishb # Fishing scene background images
attr_accessor :fishs # Fishing scene settings
attr_accessor :fish_list # List of fish that will appear in next scene
alias galv_fish_gs_initialize initialize
def initialize
@fishb = [0,0,0,120] # over, under, flow, opacity
@fishs = Array.new([GFISH::DEFAULT_BGM])
@fish_list = []
@fish = []
GFISH::FISH.each_with_index { |fish,i|
if fish.nil?
@fish << nil
else
@fish << Fish_Stats.new(i)
end
}
galv_fish_gs_initialize
end
end # Game_System
#-----------------#
#---| GAME_PLAYER |---------------------------------------------------------
#-----------------#
class Game_Player < Game_Character
attr_accessor :equipped_bait
attr_accessor :equipped_rod
end # Game_Player < Game_Character
#----------------#
#---| RPG::ITEMS |----------------------------------------------------------
#----------------#
class RPG::Item
def bait
if @bait.nil?
if @note =~ /<bait:[ ](.*)>/i
@bait = $1.to_s.split(",").map {|i| i.to_i}
else
@bait = nil
end
end
@bait
end
def rod
if @rod.nil?
if @note =~ /<rod:[ ](.*)>/i
@rod = $1.to_i
else
@rod = nil
end
end
@rod
end
def rod_img
if @rod_img.nil?
if @note =~ /<rod_img:[ ](.*)>/i
@rod_img = $1
else
@rod_img = "rod"
end
end
@rod_img
end
def bait_img
if @bait_img.nil?
if @note =~ /<bait_img:[ ](.*)>/i
@bait_img = $1
else
@bait_img = "bait"
end
end
@bait_img
end
end # RPG::Item
#------------------#
#---| GAME_FISHING |--------------------------------------------------------
#------------------#
class Game_Fishing
attr_accessor :reeling
attr_accessor :fishing_pattern
attr_accessor :fish_phase
attr_accessor :phase_timer
attr_accessor :bait_x
attr_accessor :bait_y
attr_accessor :fish_hooked
attr_reader :surface_y
attr_reader :floor_y
attr_reader :end_x
attr_accessor :fish
def initialize
@fishing_pattern = 1
@fish_phase = 0
@bait_x = 0
@bait_y = 0
@phase_timer = 0
@end_x = player_x - 25
@surface_y = player_y + 20
@floor_y = Graphics.height - 20
@reelx = 0
@reely = 0
end
def refresh_fish
@fish = []
$game_system.fish_list.each_with_index { |id,i|
next if GFISH::FISH[id].nil?
@fish.push(Game_Fish.new(i,id))
}
end
def player_x
Graphics.width - 40
end
def player_y
160
end
#---| UPDATE STUFF |
def update
update_phase
end
def update_phase
case @fish_phase
when 0
update_phase_0
when 1
update_phase_1
when 2
update_phase_2
when 3
update_phase_3
when 4
update_phase_4
when 5
update_phase_5
end
@phase_timer += 1
end
def update_phase_0
@fishing_pattern = 1
@bait_y = 0
@bait_x = 0
@fish.each { |fish| fish.update_normal }
end
def update_phase_1
# Determine cast distance
update_cancel_button
if Input.trigger?(:C)
@phase_timer = 0
@fish_phase = 2
@bait_y = @surface_y
@line_strength = 90 + 10 * $game_player.equipped_rod.rod
SceneManager.scene.casting_set
end
@fish.each { |fish| fish.update_normal }
end
def update_phase_2
# Casting rod animation
RPG::SE.new(GFISH::CAST_SE,70,70).play if @phase_timer == 18
if @phase_timer >= 30
RPG::SE.new(GFISH::SPLASH_SE,70,80).play
SceneManager.scene.spriteset.splash.reset
@fish_phase = 3
SceneManager.scene.spriteset.rod.line_in_water
@phase_timer = 0
end
@fish.each { |fish| fish.update_normal }
end
def update_phase_3
# Fishing phase
update_cancel_button
if Input.press?(:RIGHT) || Input.press?(:C)
reeling_in
else
sinking
end
@fish.each { |fish| fish.update_action }
end
def update_phase_4
# Fish is on the line!
update_fish_struggle
@fish.each { |fish| fish.update_action }
end
def update_phase_5
# Victory stuff
@fish.each { |fish| fish.update_normal }
cancel_fishing if Input.trigger?(:C)
update_cancel_button
end
def update_cancel_button
cancel_fishing if Input.press?(:B)
end
#---| FUNCTIONALITY |
def sinking
if @bait_y < @floor_y
@bait_y += $game_player.equipped_bait.bait[1].to_f / 10.to_f
end
@reeling = false
@fishing_pattern = 0
end
def reeling_in
@reeling = true
@fishing_pattern = 2
@bait_x += 1.5 if @bait_x <= @end_x
@bait_y -= 1.5 if @bait_y >= @surface_y
cancel_fishing if @bait_x >= @end_x && @bait_y <= @surface_y
end
def cancel_fishing
@fish_phase = 0
@fish_hooked = false
@phase_timer = 0
@reeling = false
SceneManager.scene.cancel_fishing
end
def casting
@phase_timer = 0
@fish_phase = 1
end
def update_fish_struggle
reeling_in_struggle
if @fish_hooked.move_type < 0
fish_x = 0; fish_y = 0
elsif @fish_hooked.move_type == 0
fish_x = 0; fish_y = 0
fish_x = @reelx
fish_y = @reely + 1
else
fish_x = @reelx.to_f + (@fish_hooked.dir * 2)
fish_y = @reely.to_f + (@fish_hooked.vdir * 2)
end
if fish_x > 0
@bait_x += fish_x if @bait_x < @end_x
elsif fish_x < 0
@bait_x += fish_x if @bait_x > @fish_hooked.left
end
if fish_y > 0
@bait_y += fish_y if @bait_y < @floor_y
elsif fish_y < 0
@bait_y += fish_y if @bait_y > @surface_y
end
test_line
lost_fish if Input.trigger?(:B)
end
def test_line
if @reeling && @fish_hooked.dir < 0 || @reeling && @fish_hooked.move_type <= 0
@line_strength -= [@fish_hooked.pull - $game_player.equipped_rod.rod,1].max
end
lost_fish if @line_strength <= 0
end
def lose_bait
item = $game_player.equipped_bait
$game_party.lose_item(item, 1)
SceneManager.scene.refresh_menus if SceneManager.scene_is?(Scene_GFish)
end
def reeling_in_struggle
if Input.press?(:RIGHT) || Input.press?(:C)
@reeling = true
@fishing_pattern = 2
if @fish_hooked.pull < 0
@reelx = 0
@reely = 0
else
@reelx = 1 * [$game_player.equipped_rod.rod - @fish_hooked.pull,1].max
@reely = -1 * [$game_player.equipped_rod.rod - @fish_hooked.pull,1].max
end
caught_fish if @bait_x >= @end_x && @bait_y <= @surface_y &&
@fish_hooked.move_type >= 0
else
@reelx = 0
@reely = 0
@reeling = false
@fishing_pattern = 0
end
end
def lost_fish
@fish_hooked.lost
@fish_hooked.check_dir
RPG::SE.new(GFISH::BROKE_SE,100,100).play
cancel_fishing
lose_bait
end
def caught_fish
@fish_phase = 5
@fish_hooked.caught
add_fish_data
if @fish_hooked.se == ""
RPG::SE.new(GFISH::DEFAULT_SE,70,70).play
else
RPG::SE.new(@fish_hooked.se,70,70).play
end
lose_bait
if @fish_hooked.item > 0
item = $data_items[@fish_hooked.item]
$game_party.gain_item(item,1)
end
SceneManager.scene.show_victory
end
def add_fish_data
$game_variables[GFISH::FISH_VAR] = @fish_hooked.fish_id
f = $game_system.fish[@fish_hooked.fish_id]
f.caught += 1
f.length = @fish_hooked.length if f.length < @fish_hooked.length
f.weight = @fish_hooked.weight if f.weight < @fish_hooked.weight
$game_temp.reserve_common_event(@fish_hooked.cevent)
end
end # Game_Fishing
#---------------#
#---| GAME_FISH |-----------------------------------------------------------
#---------------#
class Game_Fish
attr_accessor :x
attr_accessor :y
attr_accessor :living
attr_accessor :fish_id # the fish id to get fish stats
attr_reader :id # the id of the fish in the pond
attr_reader :graphic
attr_reader :speed
attr_reader :move_type
attr_reader :item
attr_reader :bait_type
attr_reader :dir
attr_reader :vdir
attr_reader :se
attr_reader :pull
attr_reader :cevent
attr_reader :length
attr_reader :weight
attr_reader :stats
attr_reader :ctxt
def initialize(id,fish_id)
@id = id
@fish_id = fish_id
initialize_variables
end
def surface; $game_fishing.surface_y; end
def floor; $game_fishing.floor_y; end
def left; 10; end
def right; $game_fishing.end_x; end
def moving?; @movetimer > 0; end
def get_fish_minmax
if @level[0] <= 0
@fish_floor = floor
else
@fish_floor = floor - (floor - surface) * (@level[0] * 0.1)
end
if @level[1] <= 0
@fish_surface = floor
else
@fish_surface = floor - (floor - surface) * (@level[1] * 0.1)
end
end
def initialize_variables
@living = true
@movetimer = 0
@graphic,@speed,@pull,@move_type,@level,@x,@item,@bait_type,@se,@range,
@cevent,@lengtha,@weighta,@stats,@ctxt = Array.new(GFISH::FISH[@fish_id])
random_stats
@speed *= 0.1
get_fish_minmax
set_fish_starting
end
def random_stats
rand_ratio = ((rand(100) + 1) * 0.01).round(2)
min = @lengtha[0].to_f
max = @lengtha[1].to_f
@length = ((max - min).to_f * rand_ratio + min.to_f).round(1)
@length = @length.to_i if !GFISH::DECIMALS
min = @weighta[0].to_f
max = @weighta[1].to_f
@weight = ((max - min) * rand_ratio + min).round(1)
@weight = @weight.to_i if !GFISH::DECIMALS
end
def set_fish_starting
if @move_type > 0
@dir = rand(3) - 1 # -1 = left, 0 = none, 1 = right
@vdir = rand(3) - 1 # -1 = up, 0 = none, 1 = down
else
@dir = 0
@vdir = 0
end
@x = (rand(left - right) + left).to_i if @x < 0
level = (rand(@level[0] - @level[1]) + @level[0]).to_i
if level == 0
@y = floor
else
@y = floor - (floor - surface) * (level * 0.1)
end
end
def alive?
@living
end
def near_bait?
if @x.between?($game_fishing.bait_x - @range[0],$game_fishing.bait_x + @range[0]) &&
@y.between?($game_fishing.bait_y - @range[0],$game_fishing.bait_y + @range[0]) &&
$game_player.equipped_bait &&
@bait_type.include?($game_player.equipped_bait.bait[0])
return true
end
return false
end
def update_action
if @hooked
update_hooked
elsif $game_fishing.fish_phase == 4
update_normal
elsif $game_fishing.fish_phase == 3 && near_bait?
update_near_bait
update_nibble
else
update_normal
end
end
def update_near_bait
return if @move_type < 0
if @x < $game_fishing.bait_x
@x += @speed * 1.5
@dir = 1 if @x < $game_fishing.bait_x - 5
elsif @x > $game_fishing.bait_x
@x -= @speed * 1.5
@dir = -1 if @x > $game_fishing.bait_x + 5
end
if @y < $game_fishing.bait_y
@y += @speed * 1.5 if @y < @fish_floor
@vdir = 1
elsif @y > $game_fishing.bait_y
@y -= @speed * 1.5 if @y > @fish_surface
@vdir = -1
end
end
def update_nibble
if @x.between?($game_fishing.bait_x - @range[1],$game_fishing.bait_x + @range[1]) &&
@y.between?($game_fishing.bait_y - @range[1],$game_fishing.bait_y + @range[1])
@hooked = true
$game_fishing.fish_hooked = self
RPG::SE.new("Blow5",70,80).play
SceneManager.scene.spriteset.fish_sprites[@id].flash(Color.new(255,255,255,180), 6)
$game_fishing.fish_phase = 4
@dir = -1 if @move_type > 0
end
end
def check_dir
if @move_type <= 0
@dir = 0
@vdir = 0
end
end
def update_hooked
return if @move_type < 0
@x = $game_fishing.bait_x
@y = $game_fishing.bait_y
determine_struggle if !moving?
@movetimer -= 1
end
def determine_struggle
if @move_type <= 0
@dir = 0
@vdir = 0
else
@dir = (rand(3) - 1).to_f * @speed.to_f
@vdir = (rand(3) - 1).to_f * @speed.to_f
@movetimer = rand(70)
end
end
def caught
@hooked = false
@living = false
@x = -1000
@y = -1000
end
def lost
@hooked = false
end
def update_normal
return if !@living
if moving?
if out_of_position?
do_move_to_level
else
do_move
end
else
determine_action
end
@movetimer -= 1
end
def determine_action
case @move_type
when 0
# Idle
@movetimer = 10
when 1
# Passive
@dir = (rand(3) - 1) * @speed
@vdir = ((rand(3) - 1).to_f * 0.5) * @speed.to_f