-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_StealingSystem.rb
353 lines (342 loc) · 13.3 KB
/
RS_StealingSystem.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
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#==============================================================================
# ** Stealing System
#------------------------------------------------------------------------------
# Name : Stealing System
# Author : 러닝은빛(biud436)
# Date : 2014-08-19
# Version : 1.0
#==============================================================================
# ** Terms of Use
#==============================================================================
# Free for commercial and non-commercial use
#==============================================================================
$imported = {} if $imported.nil?
$imported["RS_StealingSystem"] = true
module Tile
# 탐색이 가능한 타일셋의 이름 (타일셋이 등록되지 않은 곳에선 물건을 훔칠 수 없습니다)
NAME = ["Interior"]
# 탐색이 가능한 조형물의 범위
RANGE = [(48..112),(48..112)]
# 찾아낼 수 있는 화폐의 최대값
GOLD = 1000
# 아이템을 찾을 수 있는 최소 확률
P_MIN = 0
# 아이템을 찾을 수 있는 확률 (램덤입니다만 이 값이 높을 수록 찾기가 어려워질 수 있습니다)
P_MAX = 20
end
#==============================================================================
# ** Message(HUD)
#------------------------------------------------------------------------------
# Author : 러닝은빛(biud436)
# Date : 2014-08-17
# Version : 1.0
#==============================================================================
module HUD_TEMP
#--------------------------------------------------------------------------
# * Font Size
#--------------------------------------------------------------------------
FONT_SIZE = 18
#--------------------------------------------------------------------------
# * Decrease Opacity
#--------------------------------------------------------------------------
OPACITY = 0.5
#--------------------------------------------------------------------------
# * Chat Update
#--------------------------------------------------------------------------
CHAT_UPDATE = true
#--------------------------------------------------------------------------
# * Color
#--------------------------------------------------------------------------
RED = Color.new(255,0,0,255)
WHITE = Color.new(255,255,255,255)
BLUE = Color.new(65,102,245,255)
BKG_COLOR = [Color.new(0,0,0,64),Color.new(0,0,0,0)]
#--------------------------------------------------------------------------
# * Class::Struct
#--------------------------------------------------------------------------
Coord = Struct.new(:x,:y)
CRect = Struct.new(:w,:h)
#--------------------------------------------------------------------------
# * Coordinate Struct
#--------------------------------------------------------------------------
BackGround = CRect.new(220,85)
BG_Center = Coord.new(Graphics.width/2 - BackGround.w/2, FONT_SIZE * 2)
end
#==============================================================================
# ** HUD
#------------------------------------------------------------------------------
#
#==============================================================================
class HUD
attr_accessor :text
attr_accessor :color
BKG = Rect.new(0,0,HUD_TEMP::BackGround.w,HUD_TEMP::BackGround.h)
#--------------------------------------------------------------------------
# * 초기화
#--------------------------------------------------------------------------
def initialize
@text = []
@color = :white
@f_size = HUD_TEMP::FONT_SIZE
@text_temp = []
create_background
end
#--------------------------------------------------------------------------
# * 배경
#--------------------------------------------------------------------------
def create_background
@background = Sprite.new
@background.bitmap = Bitmap.new( BKG.width , BKG.height )
@background.bitmap.fill_rect(BKG,HUD_TEMP::BKG_COLOR[1])
@background.x = HUD_TEMP::BG_Center.x
@background.y = HUD_TEMP::BG_Center.y
end
#--------------------------------------------------------------------------
# * 텍스트
#--------------------------------------------------------------------------
def create_text(str)
txt = Text.new
txt.bitmap = Bitmap.new(BKG.width,BKG.height)
txt.bitmap.font = Font.new
txt.bitmap.font.color = set_color
txt.bitmap.font.size = HUD_TEMP::FONT_SIZE
txt.bitmap.draw_text(BKG,str,1)
txt.x = HUD_TEMP::BG_Center.x
txt.y = @background.y + (HUD_TEMP::FONT_SIZE * text_size) - HUD_TEMP::FONT_SIZE
push_text(txt)
end
#--------------------------------------------------------------------------
# * 색상
#--------------------------------------------------------------------------
def set_color
case @color
when :red; return HUD_TEMP::RED;
when :white; return HUD_TEMP::WHITE;
when :blue; return HUD_TEMP::BLUE;
end
end
#--------------------------------------------------------------------------
# * 배열 사이즈
#--------------------------------------------------------------------------
def text_size
size = @text.size - 1
end
#--------------------------------------------------------------------------
# * 업데이트
#--------------------------------------------------------------------------
def update
@background.update
@text.each_with_index do |i,index|
return false if i.nil?
i.y = @background.y + (i.bitmap.font.size * index - 1) - HUD_TEMP::FONT_SIZE
i.update
end
end
#--------------------------------------------------------------------------
# * 배열에 텍스트 추가
#--------------------------------------------------------------------------
def push_text(str)
if @text.size >= 4
@text.shift
end
@text.push(str)
end
#--------------------------------------------------------------------------
# * 해방
#--------------------------------------------------------------------------
def dispose
@background.bitmap.dispose
@background.dispose
end
#--------------------------------------------------------------------------
# * 텍스트 해방
#--------------------------------------------------------------------------
def dispose_text
@text.each do |i|
i.bitmap.dispose
i.dispose
end
end
end
#==============================================================================
# ** Text
#------------------------------------------------------------------------------
# 텍스트의 투명도를 낮춰줍니다
#==============================================================================
class Text < Sprite
#--------------------------------------------------------------------------
# * 투명도
#--------------------------------------------------------------------------
def update
super
self.opacity -= HUD_TEMP::OPACITY if self.opacity > 0
$hud.text.shift if self.opacity <= 0
end
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# HUD 생성을 담당합니다
#==============================================================================
class Game_Map
alias chat_initialize initialize
alias chat_update update
#--------------------------------------------------------------------------
# * 전역 변수 선언
#--------------------------------------------------------------------------
def initialize
chat_initialize
$hud = HUD.new
end
#--------------------------------------------------------------------------
# * 업데이트
#--------------------------------------------------------------------------
def update(main=false)
chat_update(main)
$hud.update if HUD_TEMP::CHAT_UPDATE
end
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# 도둑질 시스템이 정의되어있는 클래스입니다
# Date : 2014-08-19
#==============================================================================
class Game_Map
alias cup_initialize initialize
alias cup_update update
attr_accessor :probability
#--------------------------------------------------------------------------
# * 초기화
#--------------------------------------------------------------------------
def initialize
cup_initialize
@hash = Hash.new
@steal = []
@size = {:item => item_size, :weapons => weapons_size, :armors => armors_size}
@probability = [4+Tile::P_MIN,rand(Tile::P_MAX)].max
end
#--------------------------------------------------------------------------
# * 결정키를 누르면 훔칠 아이템이 있는 지 확인합니다
#--------------------------------------------------------------------------
def update(main=false)
cup_update(main)
count_main if Input.trigger?(:C)
end
#--------------------------------------------------------------------------
# * 통행이 불가능한 장애물이 있는지 확인합니다
#--------------------------------------------------------------------------
def count_main
d = $game_player.direction
f = passable?(x_with_direction($game_player.x,d),
y_with_direction($game_player.y,d),d)
if f == false
id = layered_tiles(x_with_direction($game_player.x,d),y_with_direction($game_player.y,d))
steal_item(id,x_with_direction($game_player.x,d),y_with_direction($game_player.y,d))
end
end
#--------------------------------------------------------------------------
# * 특정 조형물만 탐색합니다
#--------------------------------------------------------------------------
def steal_item(id,x,y)
# 이미 탐색이 완료된 조형물인가?
if @hash[@map_id].is_a?(Array) && @hash[@map_id].include?([id[0],x*y])
$hud.create_text("더 이상 훔칠 물건이 없습니다")
return false
end
# 탐색이 가능한 지역인가?
if Tile::NAME.include?(tileset.name) == false
$hud.create_text("탐색이 불가능한 지역입니다")
return false
end
# 탐색이 가능한 오브젝트인가?
case id[0]
when range
@hash[@map_id] = @steal.push([id[0],x*y])
random_item;
end
end
#--------------------------------------------------------------------------
# * 타일의 범위를 검색합니다
#--------------------------------------------------------------------------
def range
begin
i = Tile::NAME.index(tileset.name)
return Tile::RANGE[i]
rescue
return Tile::RANGE[0]
end
end
#--------------------------------------------------------------------------
# * 물건을 램덤으로 획득합니다
#--------------------------------------------------------------------------
def random_item
case srand(Graphics.frame_count) % @probability.to_i
when 0 # 아이템 획득
$game_party.gain_item($data_items[[1,rand(@size[:item])].max], 1)
$hud.create_text(sprintf("%s 을/를 훔쳤습니다",
$data_items[[1,rand(@size[:item])].max].name))
when 1 # 무기구 획득
$game_party.gain_item($data_weapons[[1,rand(@size[:weapons])].max], 1)
$hud.create_text(sprintf("%s 을/를 훔쳤습니다",
$data_weapons[[1,rand(@size[:weapons])].max].name))
when 2 # 방어구 획득
$game_party.gain_item($data_armors[[1,rand(@size[:armors])].max], 1)
$hud.create_text(sprintf("%s 을/를 훔쳤습니다",
$data_armors[[1,rand(@size[:armors])].max].name))
when 3 # 골드 획득
$hud.create_text(sprintf("+%d %s 획득",
$game_party.gain_gold([1,rand(Tile::GOLD)].max),
$data_system.currency_unit))
else # 아무것도 찾지 못했을 때
$hud.color = :red
$hud.create_text("아무것도 찾지 못했습니다")
$hud.color = :white
end
end
#--------------------------------------------------------------------------
# * 아이템의 갯수
#--------------------------------------------------------------------------
def item_size
j = []
$data_items.each_with_index do |i,index|
next if i.is_a?(RPG::Item) == false
next if i.nil?
next if i.name.size <= 0
j.push(index)
end
return j.size
end
#--------------------------------------------------------------------------
# * 무기구의 갯수
#--------------------------------------------------------------------------
def weapons_size
j = []
$data_weapons.each_with_index do |i,index|
next if i.is_a?(RPG::Weapon) == false
next if i.nil?
next if i.name.size <= 0
j.push(index)
end
return j.size
end
#--------------------------------------------------------------------------
# * 방어구의 갯수
#--------------------------------------------------------------------------
def armors_size
j = []
$data_armors.each_with_index do |i,index|
next if i.is_a?(RPG::Armor) == false
next if i.nil?
next if i.name.size <= 0
j.push(index)
end
return j.size
end
end