=begin
------------
HOW TO USE:
------------
In an event, use a script call and by putting one of the following:
$game_party.cut_wood(id)
$game_party.mine_rock(id)
Where 'id' is the type of wood/rock you want to cut/mine depending on the
values configured in the Configuration below.
The script processes the animation and adds the EXP upon successful harvest.
=end
#---------------------------------------------------------------------------
# Configuration for different types of trees and rocks to cut and mine.
# Defines how long it takes to cut/mine, EXP gained, and level requirement.
#---------------------------------------------------------------------------
module Config
Hatchet_spr = 'hatchet'
Pickaxe_spr = 'pickaxe'
def self.tree_setup(tree)
return case tree
#when TREE_ID then [WAIT_TIME, EXP_GAINED, ITEM_GAINED, LEVEL_REQUIRED]
when 1 then [60, 100, 5, 1, 1]
when 2 then [40, 100, 10, 2, 5]
else ''
end
end
def self.rock_setup(rock)
return case rock
#when ROCK_ID then [WAIT_TIME, EXP_GAINED, ITEM_GAINED, LEVEL_REQUIRED]
when 1 then [60, 100, 5, 1, 1]
when 2 then [40, 100, 10, 2, 5]
else ''
end
end
end
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
#
# E N D C O N F I G U R A T I O N
#
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
#---------------------------------------------------------------------------
# * Game Actor
# Creates woodcutting and mining attributes to the actor. Sets up the EXP chart
# as well as set/get methods for their levels and EXP.
#---------------------------------------------------------------------------
class Game_Actor
attr_reader :minelevel # mining level
attr_accessor :mineexp # mining exp
attr_reader :wclevel # woodcutting level
attr_accessor :wcexp # woodcutting exp
#--------------------------------------------------------------------------
alias setup_mod setup
def setup(actor_id)
setup_mod(actor_id)
@minelevel = 1
@mineexp_list = Array.new(101)
make_mineexp_list
@mineexp = @mineexp_list[@minelevel]
#-------------------------------------
@wclevel = 1
@wcexp_list = Array.new(101)
make_wcexp_list
@wcexp = @wcexp_list[@wclevel]
end
#--------------------------------------------------------------------------
# * CALCULATE mine XP
#--------------------------------------------------------------------------
def make_mineexp_list
actor = $data_actors[@actor_id]
@mineexp_list[1] = 0
@mineexp_list[2] = 35 # Level 2 requires 35 exp
for i in 3..100 # Now let's use an equation to do the rest of the exp values
if i > actor.final_level
@mineexp_list[i] = 0
else
@mineexp_list[i] = (35*(i-1) + @mineexp_list[i-1]) * 2
end
end
end
#--------------------------------------------------------------------------
# * Change mine EXP
# mineexp : new mine xp
#--------------------------------------------------------------------------
def mineexp=(mineexp)
@mineexp = [[mineexp, 9999999].min, 0].max
# Level up
while @mineexp >= @mineexp_list[@minelevel+1] and @mineexp_list[@minelevel+1] > 0
@minelevel += 1
end
# Level down
while @mineexp < @mineexp_list[@minelevel]
@minelevel -= 1
end
end
#--------------------------------------------------------------------------
# * Get mine EXP String
#--------------------------------------------------------------------------
def mineexp_s
return @mineexp_list[@minelevel+1] > 0 ? @mineexp.to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Next Level mine EXP String
#--------------------------------------------------------------------------
def next_mineexp_s
return @mineexp_list[@minelevel+1] > 0 ? @mineexp_list[@minelevel+1].to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Until Next Level mine EXP String
#--------------------------------------------------------------------------
def next_rest_mineexp_s
return @mineexp_list[@minelevel+1] > 0 ?
(@mineexp_list[@minelevel+1] - @mineexp).to_s : "-------"
end
#--------------------------------------------------------------------------
# * CALCULATE WC XP
#--------------------------------------------------------------------------
def make_wcexp_list
actor = $data_actors[@actor_id]
@wcexp_list[1] = 0
@wcexp_list[2] = 35 # Level 2 requires 35 exp
for i in 3..100 # Now let's use an equation to do the rest of the exp values
if i > actor.final_level
@wcexp_list[i] = 0
else
@wcexp_list[i] = (35*(i-1) + @wcexp_list[i-1]) * 2
end
end
end
#--------------------------------------------------------------------------
# * Change WC EXP
# wcexp : new WC EXP
#--------------------------------------------------------------------------
def wcexp=(wcexp)
@wcexp = [[wcexp, 9999999].min, 0].max
# Level up
while @wcexp >= @wcexp_list[@wclevel+1] and @wcexp_list[@wclevel+1] > 0
@wclevel += 1
end
# Level down
while @wcexp < @wcexp_list[@wclevel]
@wclevel -= 1
end
end
#--------------------------------------------------------------------------
# * Get WC EXP String
#--------------------------------------------------------------------------
def wcexp_s
return @wcexp_list[@wclevel+1] > 0 ? @wcexp.to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Next Level WC EXP String
#--------------------------------------------------------------------------
def next_wcexp_s
return @wcexp_list[@wclevel+1] > 0 ? @wcexp_list[@wclevel+1].to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Until Next Level WC EXP String
#--------------------------------------------------------------------------
def next_rest_wcexp_s
return @wcexp_list[@wclevel+1] > 0 ?
(@wcexp_list[@wclevel+1] - @wcexp).to_s : "-------"
end
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
# *Game_Player (activate/deactivate step_anime)
# Also processes the action of cutting and mining
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
class Game_Player < Game_Character
attr_accessor :step_anime, :wc_count, :mine_count, :character_name
def initialize
super
@wc_count, @mine_count = 0, 0
end
alias call_update_after_counting_down_timers update
def update
if @wc_count > 0 or @mine_count > 0
super
# A direction was pressed or canceled
if Input.dir4 != 0 or Input.trigger?(Input::B)
@wc_count, @mine_count = 0, 0
$game_party.finalize(false) # Failed to complete task
return
end
@wc_count -= 1 if @wc_count > 0
@mine_count -= 1 if @mine_count > 0
# Call the last steps when cutting/mining completes
$game_party.finalize(true) if (@wc_count == 0 and @mine_count == 0)
else
call_update_after_counting_down_timers
end
end
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
# *Game_Party
# Controls the majority of cutting/mining functions
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
class Game_Party
attr_accessor :cutting, :mining
alias init_before_cutting_mining initialize
def initialize
init_before_cutting_mining
@cutting = false
@mining = false
@object = nil
end
def cut_tree(id)
@object = Config.tree_setup(id)
@actors.each{|actor| $game_player.wc_count = (@object[0] * 2 - 1) if actor.wclevel >= @object[4] }
return if $game_player.wc_count == 0
@cutting = true
player = @actors[0]
mine_graphic = player.character_name + "_mine"
$game_player.character_name = mine_graphic
player.set_graphic(mine_graphic, player.character_hue, player.battler_name, player.battler_hue)
$game_player.step_anime = true
end
def mine_rock(id)
@object = Config.rock_setup(id)
@actors.each{|actor| $game_player.mine_count = (@object[0] * 2 - 1) if actor.minelevel >= @object[4] }
return if $game_player.mine_count == 0
@mining = true
player = @actors[0]
mine_graphic = player.character_name + "_mine"
$game_player.character_name = mine_graphic
player.set_graphic(mine_graphic, player.character_hue, player.battler_name, player.battler_hue)
$game_player.step_anime = true
end
def finalize(task_completed)
type = 1 if @cutting
type = 2 if @mining
player = @actors[0]
orig_name = player.character_name.split('_mine')
$game_player.character_name = orig_name[0]
player.set_graphic(orig_name[0], player.character_hue, player.battler_name, player.battler_hue)
$game_player.step_anime = false
@cutting, @mining = false, false
return unless task_completed
# Reward EXP to the actors with high enough levels
if type == 1
@actors.each{|a| a.wcexp += @object[2] if a.wclevel >= @object[4] }
else #type == 2
@actors.each{|a| a.mineexp += @object[2] if a.minelevel >= @object[4] }
end
end
end
#==============================================================================
# ** Sprite_Character
# Editted to include the hatchet and pickaxe sprites
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
if @character_name == $game_player.character_name and
($game_party.cutting or $game_party.mining)
RPG::Cache.clear
type = ($game_party.cutting ? Config::Hatchet_spr : Config::Pickaxe_spr)
src_bitmap = RPG::Cache.character(type, 0)
self.bitmap.blt(0, 0, src_bitmap, Rect.new(0,0,src_bitmap.width,src_bitmap.height))
end
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end