Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # TheoAllen - Basic Modules
- # Version : 1.4
- # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # (Some of documentations was written in informal indonesian language)
- # =============================================================================
- $imported = {} if $imported.nil?
- # =============================================================================
- # This module contains :
- # =============================================================================
- $imported[:Theo_BasicFuntions] = true # Basic Funtions
- $imported[:Theo_BitmapAddons] = true # Bitmap Extra Addons
- $imported[:Theo_CoreDamage] = true # Core Damage Processing
- $imported[:Theo_CoreResult] = true # Core Damage Result
- $imported[:Theo_Movement] = true # Object Core Movement
- $imported[:Theo_CoreFade] = true # Object Core Fade
- $imported[:Theo_Circular] = true # Object Circular Movement
- $imported[:Theo_CloneImage] = true # Clone Image. For Afterimage Base
- $imported[:Theo_RotateImage] = true # To rotate sprite
- # =============================================================================
- # NOTE:
- # -----------------------------------------------------------------------------
- # Categorize this script as core script. It means that you have to put this
- # script above all custom script
- #
- # If u want to disable one of these, just replace "true" with "false"
- # =============================================================================
- # Known incompatibility :
- # >> Modern Algebra - Bitmap Addons (Disable the Bitmap Addon)
- # >> Tsukihime - Core Damage (Disable the Core Damage processing)
- # >> Enu - Tankentai
- # =============================================================================
- # ChangeLogs :
- # =============================================================================
- # Version 1.0 : - Initial Release
- # Version 1.2 : - Add Bitmap Entire Fill
- # - Add Bitmap Border Fill
- # - Add To Center window position
- # - Add more description
- # Version 1.3 : - Added Clone Sprite function and afterimagebase
- # Version 1.3b : - Added TSBS basic function
- # - Greatly reduced lag for afterimage effect
- # Version 1.4 : - Added rotate image basic module
- # - Fixed bug at Object Core Fade
- # =============================================================================
- # RGSS3 ~ Bug Fixes (Taken from RMWeb.com)
- # forums.rpgmakerweb.com/index.php?/topic/1131-rgss3-unofficial-bugfix-snippets
- # =============================================================================
- # Screen shake bugfix
- # -----------------------------------------------------------------------------
- class Game_Interpreter
- def command_225
- screen.start_shake(@params[0], @params[1], @params[2])
- wait(@params[2]) if @params[3]
- end
- end
- # -----------------------------------------------------------------------------
- # Enemy targeting bugfix
- # -----------------------------------------------------------------------------
- class Game_Action
- def targets_for_friends
- if item.for_user?
- [subject]
- elsif item.for_dead_friend?
- if item.for_one?
- [friends_unit.smooth_dead_target(@target_index)]
- else
- friends_unit.dead_members
- end
- elsif item.for_friend?
- if item.for_one?
- if @target_index < 0
- [friends_unit.random_target]
- else
- [friends_unit.smooth_target(@target_index)]
- end
- else
- friends_unit.alive_members
- end
- end
- end
- end
- # -----------------------------------------------------------------------------
- # process normal char bugfix
- # -----------------------------------------------------------------------------
- class Window_Base < Window
- alias :process_normal_character_vxa :process_normal_character
- def process_normal_character(c, pos)
- return unless c >= ' '
- process_normal_character_vxa(c, pos)
- end
- end
- # -----------------------------------------------------------------------------
- # Disable Japanese input name
- # -----------------------------------------------------------------------------
- class Game_System
- def japanese?
- false
- end
- end
- # =============================================================================
- # Basic Functions ~
- # -----------------------------------------------------------------------------
- if $imported[:Theo_BasicFuntions]
- # =============================================================================
- module Math
- # Konversi dari derajat ke radian
- def self.radian(degree)
- return (degree.to_f/180) * Math::PI
- end
- # Konversi dari radian ke derajat
- def self.degree(radian)
- return (radian.to_f/Math::PI) * 180
- end
- end
- class Object
- # Generate angka random dari jarak minimum - maksimum
- unless method_defined?(:rand_range)
- def rand_range(min,max,float = false)
- range = max - min
- return float ? (min + (rand*range)) : min + rand(range)
- end
- end
- # iterasi instance variable satu2
- def each_var
- instance_variables.each do |varsymb|
- yield instance_variable_get(varsymb)
- end
- end
- end
- # -----------------------------------------------------------------------------
- # Sprite yang gedenya selayar penuh (buat nggambar2)
- # -----------------------------------------------------------------------------
- class Sprite_Screen < Sprite
- def initialize(viewport = nil)
- super(viewport)
- self.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- end
- def dispose
- self.bitmap.dispose
- super
- end
- end
- class Window_Confirmation < Window_Command
- def window_width
- return 100
- end
- def make_command_list
- add_command(ok_vocab, :ok, ok_condition)
- add_command(cancel_vocab, :cancel, cancel_condition)
- end
- def ok_vocab
- return "Yes"
- end
- def cancel_vocab
- return "No"
- end
- def ok_condition
- return true
- end
- def cancel_condition
- return true
- end
- def alignment
- return 1
- end
- end
- # ----------------------------------------------------------------------------
- # Class Coordinate (nyimpen posisi x dan posisi y)
- # ----------------------------------------------------------------------------
- class Coordinate
- attr_accessor :x,:y
- def initialize(x,y)
- @x = x
- @y = y
- end
- def + (other)
- other = other.to_c unless other.is_a?(Coordinate)
- Coordinate.new(self.x + other.x, self.y + other.y)
- end
- def - (other)
- other = other.to_c unless other.is_a?(Coordinate)
- Coordinate.new(self.x + other.x, self.y + other.y)
- end
- def == (other)
- other = other.to_c unless other.is_a?(Coordinate)
- return self.x == other.x && self.y == other.y
- end
- def to_s
- return "(#{self.x},#{self.y})"
- end
- end
- # ----------------------------------------------------------------------------
- # Class vector (Handles vector object)
- # ----------------------------------------------------------------------------
- class Vector
- attr_accessor :pangkal
- attr_accessor :ujung
- def initialize(pangkal,ujung,radius = 0)
- @pangkal = pangkal.is_a?(Coordinate) ? pangkal : pangkal.to_c
- if ujung.is_a?(Numeric)
- x_pos = @pangkal.x + (Math.cos(Math.radian(ujung)) * radius)
- y_pos = @pangkal.y + (Math.sin(Math.radian(ujung)) * radius)
- @ujung = Coordinate.new(x_pos,y_pos)
- return
- end
- @ujung = ujung.is_a?(Coordinate) ? ujung : ujung.to_c
- end
- def skalar
- Math.sqrt(jarak_x**2 + jarak_y**2)
- end
- def + (other)
- if other.is_a?(Coordinate)
- return Vector.new(pangkal + other, ujung + other)
- end
- Vector.new(pangkal, ujung + other.satuan)
- end
- def - (other)
- if other.is_a?(Coordinate)
- return Vector.new(pangkal - other, ujung - other)
- end
- Vector.new(pangkal, ujung - other.satuan)
- end
- def degree
- Math.degree(Math.atan2(jarak_y,jarak_x)) rescue 0
- end
- def jarak_y
- ujung.y - pangkal.y
- end
- def jarak_x
- ujung.x - pangkal.x
- end
- def satuan
- Coordinate.new(jarak_x, jarak_y)
- end
- def to_s
- return @pangkal.to_s + " ---> " + @ujung.to_s
- end
- end
- # -----------------------------------------------------------------------------
- # Class Vector Object (untuk ngejadiin dua object jadi vector)
- # -----------------------------------------------------------------------------
- class VectorObject
- attr_accessor :pangkal
- attr_accessor :ujung
- attr_accessor :color
- attr_accessor :offset_x
- attr_accessor :offset_y
- def initialize(pangkal,ujung,color)
- @pangkal = pangkal
- @ujung = ujung
- @color = color
- @offset_x = 0
- @offset_y = 0
- end
- def to_v
- a = @pangkal.to_c
- b = @ujung.to_c
- a.x += @offset_x
- b.x += @offset_x
- a.y += @offset_y
- b.y += @offset_y
- Vector.new(a,b)
- end
- end
- # -----------------------------------------------------------------------------
- # Class Bitmap
- # -----------------------------------------------------------------------------
- class Bitmap
- def entire_fill(color = Color.new(0,0,0,150))
- fill_rect(self.rect,color)
- end
- def border_fill(color = Color.new(255,255,255))
- fill_rect(0,0,width,1,color)
- fill_rect(0,0,1,height,color)
- fill_rect(width-1,0,1,height,color)
- fill_rect(0,height-1,width,1,color)
- end
- end
- # -----------------------------------------------------------------------------
- # Class Window_Base
- # -----------------------------------------------------------------------------
- class Window_Base < Window
- def entire_fill(color = Color.new(0,0,0,150))
- contents.entire_fill(color)
- end
- def to_center
- self.x = Graphics.width/2 - self.width/2
- self.y = Graphics.height/2 - self.height/2
- end
- end
- # -----------------------------------------------------------------------------
- # Class Color
- # -----------------------------------------------------------------------------
- class Color
- def same?(*args)
- args = args.select {|color| color.is_a?(Color)}
- return false if args.empty?
- return args.any?{|color| self.red == color.red &&
- self.green == color.green && self.blue == color.blue &&
- self.alpha == color.alpha}
- end
- def empty?
- return self.alpha <= 0
- end
- end
- # -----------------------------------------------------------------------------
- # New Method : To Coordinate Object
- # -----------------------------------------------------------------------------
- class Object
- def to_c
- return Coordinate.new(0,0)
- end
- end
- class Numeric
- def to_c
- return Coordinate.new(self,self)
- end
- end
- class Sprite
- def to_c
- return Coordinate.new(self.x,self,y)
- end
- end
- class Window
- def to_c
- return Coordinate.new(self.x,self,y)
- end
- end
- class Game_Enemy < Game_Battler
- def to_c
- return Coordinate.new(self.screen_x,self,screen_y)
- end
- end
- class Game_CharacterBase
- def to_c(map = false)
- if map
- return Coordinate.new(self.real_x,self.real_y)
- end
- return Coordinate.new(self.screen_x,self.screen_y)
- end
- end
- # -----------------------------------------------------------------------------
- # Added TSBS basic function
- # -----------------------------------------------------------------------------
- module TSBS
- def self.cell(row, col)
- result = (MaxCol * (row - 1)) + (col - 1)
- return result
- end
- end
- end
- # =============================================================================
- # Bitmap Extra addons v2.1
- # -----------------------------------------------------------------------------
- if $imported[:Theo_BitmapAddons]
- # =============================================================================
- class Bitmap
- attr_accessor :start_degree
- # ------------------------------------------------------------------------
- # Static Members
- # ------------------------------------------------------------------------
- @@default_color = Color.new(255,255,255)
- @@arrow_degree = 30
- def self.default_color=(color)
- @@default_color = color
- end
- def self.arrow_degree=(degree)
- @@arrow_degree = degree
- end
- def self.default_color
- @@default_color
- end
- def self.arrow_degree
- @@arrow_degree
- end
- alias theo_bitmap_init initialize
- def initialize(*args)
- theo_bitmap_init(*args)
- @start_degree = 270
- end
- # ------------------------------------------------------------------------
- # Bitmap draw line
- # ------------------------------------------------------------------------
- def draw_line(x1, y1=0, x2=0, y2=0, color=@@default_color.dup,
- color_set_skip = false)
- # ----------------------------------------------------------------------
- # Jika yang dimasukkan adalah class Vector
- # ----------------------------------------------------------------------
- if x1.is_a?(Vector)
- new_color = (y1.is_a?(Color) ? y1 : color)
- draw_line(x1.pangkal,x1.ujung,new_color) # rekursif
- return
- # ----------------------------------------------------------------------
- # Jika yang dimasukkan adalah dua koordinat
- # ----------------------------------------------------------------------
- elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
- pangkal = x1
- ujung = y1
- new_color = (x2.is_a?(Color) ? x2 : color)
- draw_line(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color) # rekursif
- return # Exit
- end
- # ----------------------------------------------------------------------
- # Jika yang dimasukkan adalah koordinat yang sama
- # ----------------------------------------------------------------------
- if x1 == x2 && y1 == y2
- set_pixel(x1,y1,color)
- yield [x1,x2] if block_given?
- return # Exit
- end
- # ----------------------------------------------------------------------
- # kalkulasi jarak x dan jarak y
- # ----------------------------------------------------------------------
- jarak_x = (x2-x1)
- jarak_y = (y2-y1)
- # ----------------------------------------------------------------------
- # Jika garis merupakan garis horizontal / vertikal
- # ----------------------------------------------------------------------
- if jarak_y == 0 || jarak_x == 0
- # Horizontal
- if jarak_y == 0
- draw_horz(x1,y1,jarak_x,color)
- for j in 0..jarak_x
- yield [x1,y1]
- x1 += 1
- end if block_given?
- # Vertikal
- elsif jarak_x == 0
- draw_vert(x1,y1,jarak_y,color)
- for k in 0..jarak_y
- yield [x1,y1]
- y1 += 1
- end if block_given?
- end
- return # Exit
- end
- # ----------------------------------------------------------------------
- # Jika garis adalah diagonal
- # ----------------------------------------------------------------------
- maximum = [jarak_x.abs,jarak_y.abs].max
- rasio_x = jarak_x / maximum.to_f
- rasio_y = jarak_y / maximum.to_f
- real_x = x1.to_f
- real_y = y1.to_f
- for i in 0..maximum
- set_pixel(x1,y1,color) unless get_pixel(x1,y1).same?(color) ||
- color_set_skip ? !get_pixel(x1,y1).empty? : false
- real_x += rasio_x
- real_y += rasio_y
- yield [x1,y1] if block_given?
- x1 = real_x.round
- y1 = real_y.round
- end
- end
- # ------------------------------------------------------------------------
- # Garis Gradient ~
- # ------------------------------------------------------------------------
- def gradient_line(x1,y1=0,x2=0,y2=0,color1=@@default_color.dup,color2 = color1)
- if x1.is_a?(Vector)
- warna_pangkal = (y1.is_a?(Color) ? y1 : color1)
- warna_ujung = (x2.is_a?(Color) ? x2 : color2)
- gradient_line(x1.pangkal, x1.ujung, warna_pangkal, warna_ujung)
- return
- elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
- pangkal = x1
- ujung = y1
- warna_pangkal = (x2.is_a?(Color) ? x2 : color1)
- warna_ujung = (y2.is_a?(Color) ? y2 : color2)
- gradient_line(pangkal.x,pangkal.y,ujung.x,ujung.y,warna_pangkal,
- warna_ujung)
- return
- end
- jarak_x = (x2-x1)
- jarak_y = (y2-y1)
- radius = Math.sqrt((jarak_x**2) + (jarak_y**2))
- red_diff = (color2.red - color1.red) / radius
- green_diff = (color2.green - color1.green) / radius
- blue_diff = (color2.blue - color1.blue) / radius
- alpha_diff = (color2.alpha - color1.alpha) / radius
- red = color1.red
- green = color1.green
- blue = color1.blue
- alpha = color1.alpha
- if jarak_y.abs == 0 || jarak_x.abs == 0
- gradient_fill_rect(x1,y1,1,jarak_y,color1,color2,true) if jarak_y.abs == 0
- gradient_fill_rect(x1,y1,jarak_x,1,color1,color2) if jarak_x.abs == 0
- return
- end
- maximum = [jarak_x.abs,jarak_y.abs].max
- rasio_x = jarak_x / maximum.to_f
- rasio_y = jarak_y / maximum.to_f
- real_x = x1.to_f
- real_y = y1.to_f
- for i in 0..maximum
- new_color = Color.new(red,green,blue,alpha)
- set_pixel(x1,y1,new_color) unless get_pixel(x1,y1).same?(new_color)
- real_x += rasio_x
- real_y += rasio_y
- x1 = real_x.round
- y1 = real_y.round
- red += red_diff
- blue += blue_diff
- green += green_diff
- alpha += alpha_diff
- end
- end
- def draw_horz(x,y,width,color = Color.new(255,255,255))
- if width < 0
- fill_rect(x+width+1,y,width.abs,1,color)
- return
- end
- fill_rect(x,y,width,1,color)
- end
- def draw_vert(x,y,height,color = Color.new(255,255,255))
- if height < 0
- fill_rect(x,y+height+1,1,height.abs,color)
- return
- end
- fill_rect(x,y,1,height,color)
- end
- def draw_ellipse(x,y=0,horz=1,vert=1,color=Color.new(255,255,255),think=1,
- step=0.1)
- return if think < 1
- ori_x = x
- ori_y = y
- x += horz
- degree = 0.0
- while degree <= 360
- yield [x,y] if block_given?
- set_pixel(x,y,color) unless get_pixel(x,y).same?(color)
- x = Math.cos(Math.radian(degree)) * horz + ori_x
- y = Math.sin(Math.radian(degree)) * vert + ori_y
- degree = [degree+step,361].min
- end
- if think > 1
- draw_ellipse(ori_x+1,ori_y+1,horz,vert,think-1,color,step)
- draw_ellipse(ori_x-1,ori_y-1,horz,vert,think-1,color,step)
- draw_ellipse(ori_x+1,ori_y-1,horz,vert,think-1,color,step)
- draw_ellipse(ori_x-1,ori_y+1,horz,vert,think-1,color,step)
- end
- end
- def draw_circle(x,y,radius,color=Color.new(255,255,255),think=1)
- draw_ellipse(x,y,radius,radius,think,color) {|coordinate|
- yield coordinate if block_given?
- }
- end
- def fill_circle(x,y,radius,color1,color2=color1,step=0.1)
- fill_ellipse(x,y,radius,radius,color1,color2,step)
- end
- def fill_ellipse(x,y,horz,vert,color1,color2=color1,step=0.1)
- draw_ellipse(x,y,horz,vert,1,color1,0.5) {|cor|
- draw_line(x,y,cor[0],cor[1],color2,true)
- }
- for i in 0..1
- for baris in 0..horz*2
- for kolom in 0..vert*2
- pos_x = baris-horz+x
- pos_y = kolom-vert+y
- syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
- (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
- get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
- (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
- (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
- if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
- set_pixel(pos_x,pos_y,color2)
- end
- end
- end
- end
- end
- def draw_polygon(x,y,corner,length,color1,bone=true,color2=color1)
- return unless corner.is_a?(Numeric)
- draw_shape(x,y,Array.new(corner){1},length,color1,bone,false,color2)
- end
- def fill_polygon(x,y,corner,length,color1,color2=color1)
- return unless corner.is_a?(Numeric)
- draw_shape(x,y,Array.new(corner),length,color1,false,true,color2)
- end
- def draw_shape_params(x,y,params,length,color1,bone=true,color2=color1)
- draw_shape(x,y,params,length,color1,bone,false,color2)
- end
- def fill_shape_params(x,y,params,length,color1,color2=color1)
- draw_shape(x,y,params,length,color1,false,true,color2)
- end
- def draw_shape(x,y,params,length,color1 = Color.new(255,255,255),
- include_bone = true ,fill=false,color2 = color1)
- return unless params.is_a?(Array)
- return unless params.size >= 3
- degree_plus = 360 / params.size
- degree = @start_degree
- coordinate = []
- edge = []
- params.each do |i|
- x_des = x + Math.cos(Math.radian(degree)) * (length*(i.to_f/params.max))
- y_des = y + Math.sin(Math.radian(degree)) * (length*(i.to_f/params.max))
- draw_line(x,y,x_des,y_des,color2) if include_bone
- degree += degree_plus
- coordinate.push(Coordinate.new(x_des,y_des))
- end
- for i in -1..coordinate.size-2
- c = coordinate
- draw_line(c[i].x,c[i].y,c[i+1].x,c[i+1].y,color1) {|cor| edge.push(cor)}
- end
- return unless fill
- edge.each do |line|
- draw_line(x,y,line[0],line[1],color2,true)
- end
- for i in 0..1
- for baris in 0..length*2
- for kolom in 0..length*2
- pos_x = baris-length+x
- pos_y = kolom-length+y
- syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
- (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
- get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
- (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
- (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
- if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
- set_pixel(pos_x,pos_y,color2)
- end
- end
- end
- end
- end
- def draw_arrow(x1,y1=0,x2=0,y2=0,color=@@default_color.dup)
- if x1.is_a?(Vector)
- new_color = (y1.is_a?(Color) ? y1 : color)
- draw_arrow(x1.pangkal,x1.ujung,new_color)
- return
- elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
- pangkal = x1
- ujung = y1
- new_color = (x2.is_a?(Color) ? x2 : color)
- draw_arrow(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color)
- return
- end
- draw_line(x1,y1,x2,y2,color)
- degree = Vector.new(Coordinate.new(x1,y1),Coordinate.new(x2,y2)).degree-180
- draw_line(Vector.new(Coordinate.new(x2,y2),degree + @@arrow_degree,10))
- draw_line(Vector.new(Coordinate.new(x2,y2),degree - @@arrow_degree,10))
- end
- end
- # -----------------------------------------------------------------------------
- # Draw Polygon status
- # -----------------------------------------------------------------------------
- class Game_Battler < Game_BattlerBase
- def params_array
- return [self.atk,self.def,self.mat,self.mdf,self.agi,self.luk]
- end
- end
- class Window_Base < Window
- def draw_polygon_params(x,y,actor,inner,outer,color1,color2)
- contents.draw_shape_params(x,y,actor.params_array,inner,color1)
- contents.draw_polygon(x,y,actor.params_array.size,outer,color2)
- end
- end
- end
- # ============================================================================
- # Core Damage Processing ~
- # ----------------------------------------------------------------------------
- if $imported[:Theo_CoreDamage]
- # ============================================================================
- class Game_Battler < Game_BattlerBase
- def make_damage_value(user, item)
- value = base_damage(user, item)
- value = apply_element_rate(user, item, value)
- value = process_damage_rate(user, item, value)
- value = apply_damage_modifiers(user, item, value)
- @result.make_damage(value.to_i, item)
- end
- def base_damage(user, item)
- value = item.damage.eval(user, self, $game_variables)
- value
- end
- def apply_element_rate(user, item, value)
- value *= item_element_rate(user, item)
- value
- end
- def process_damage_rate(user, item, value)
- value *= pdr if item.physical?
- value *= mdr if item.magical?
- value *= rec if item.damage.recover?
- value
- end
- def apply_damage_modifiers(user, item, value)
- value = apply_critical(value, user) if @result.critical
- value = apply_variance(value, item.damage.variance)
- value = apply_guard(value)
- value
- end
- def apply_critical(damage, user)
- damage * 3
- end
- end
- end
- # ============================================================================
- # Core Damage Result ~
- # ----------------------------------------------------------------------------
- if $imported[:Theo_CoreResult]
- # ============================================================================
- class Game_Battler < Game_BattlerBase
- def item_apply(user, item)
- make_base_result(user, item)
- apply_hit(user, item) if @result.hit?
- end
- def make_base_result(user, item)
- @result.clear
- @result.used = item_test(user, item)
- @result.missed = (@result.used && rand >= item_hit(user, item))
- @result.evaded = (!@result.missed && rand < item_eva(user, item))
- end
- def apply_hit(user, item)
- unless item.damage.none?
- determine_critical(user, item)
- make_damage_value(user, item)
- execute_damage(user)
- end
- apply_item_effects(user, item)
- end
- def determine_critical(user, item)
- @result.critical = (rand < item_cri(user, item))
- end
- def apply_item_effects(user, item)
- item.effects.each {|effect| item_effect_apply(user, item, effect) }
- item_user_effect(user, item)
- end
- end
- end
- # ============================================================================
- # Object Core Movement
- # ----------------------------------------------------------------------------
- if $imported[:Theo_Movement]
- # ============================================================================
- module THEO
- module Movement
- class Move_Object
- attr_reader :obj
- def initialize(obj)
- @obj = obj
- clear_move_info
- end
- def clear_move_info
- @to_x = -1
- @to_y = -1
- @real_x = 0.0
- @real_y = 0.0
- @x_speed = 0.0
- @y_speed = 0.0
- @jump = 0.0
- @jump_interval = 0.0
- @offset = 0
- end
- def move_to(x,y=0,jump=0,duration=0)
- if x.is_a?(Coordinate)
- target = x
- move_to(target.x, target.y, y, jump)
- return
- end
- @to_x = x
- @to_y = y
- @real_x = @obj.x.to_f
- @real_y = @obj.y.to_f
- determine_speed(duration,jump)
- end
- def determine_speed(duration,jump)
- @x_speed = (@to_x - @obj.x) / duration.to_f
- @y_speed = (@to_y - @obj.y) / duration.to_f
- @jump = jump.to_f
- @jump_interval = @jump/(duration/2.0)
- end
- def moving?
- return false if @to_x == -1 && @to_y == -1
- result = @obj.x != @to_x || @obj.y != @to_y
- return result
- end
- def update_move
- @real_x += @x_speed
- @real_y += @y_speed
- @obj.x = @real_x.round
- @obj.y = @real_y.round + @offset.round
- @jump -= @jump_interval
- @offset -= @jump
- clear_move_info unless moving?
- end
- end
- def can_move?(obj)
- return obj.is_a?(Window) || obj.is_a?(Sprite)
- end
- def set_obj(obj)
- @move_obj = Move_Object.new(obj)
- end
- def goto(x,y,duration = Graphics.frame_rate,jump = 0.0)
- @move_obj.move_to(x,y,jump,duration)
- end
- def slide(x,y,duration = Graphics.frame_rate,jump = 0.0)
- slide_x = 0
- slide_y = 0
- if x.is_a?(Coordinate)
- target = x
- slide_x = @move_obj.obj.x + target.x
- slide_y = @move_obj.obj.y + target.y
- else
- slide_x = @move_obj.obj.x + x
- slide_y = @move_obj.obj.y + y
- end
- goto(slide_x,slide_y,duration,jump) unless moving?
- end
- def update_move
- @move_obj.update_move if moving?
- end
- def moving?
- @move_obj.moving?
- end
- def up(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(0,-range,duration,jump)
- end
- def down(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(0,range,duration,jump)
- end
- def right(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,0,duration,jump)
- end
- def left(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,0,duration,jump)
- end
- def upright(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,-range,duration,jump)
- end
- def upleft(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,-range,duration,jump)
- end
- def downright(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,-range,duration,jump)
- end
- def downleft(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,range,duration,jump)
- end
- end
- end
- class Sprite
- include THEO::Movement
- alias theolized_sprite_init initialize
- def initialize(*args)
- theolized_sprite_init(*args)
- set_obj(self)
- end
- alias theolized_move_update update
- def update
- theolized_move_update
- update_move
- end
- end
- class Window
- include THEO::Movement
- alias theolized_move_window_init initialize
- def initialize(x, y, width, height)
- theolized_move_window_init(x, y, width, height)
- set_obj(self)
- end
- alias theolized_move_update update
- def update
- theolized_move_update
- update_move
- end
- end
- end
- # =============================================================================
- # Object Core Fade
- # -----------------------------------------------------------------------------
- if $imported[:Theo_CoreFade]
- # =============================================================================
- module THEO
- module FADE
- DEFAULT_DURATION = 60
- # set default durationnya disini (dalam satuan frame)
- def init_fade_members
- @obj = nil
- @target_opacity = -1
- @target_contents_opacity = -1
- @fade_speed = 0.0
- @fade_speed2 = 0.0
- end
- def setfade_obj(obj)
- @obj = obj
- @target_opacity = (window? ? @obj.back_opacity : @obj.opacity)
- @target_contents_opacity = @obj.contents_opacity if window?
- end
- def fade(opacity, duration = DEFAULT_DURATION)
- @target_opacity = opacity
- @target_contents_opacity = opacity if @obj.is_a?(Window)
- make_fade_speed(duration)
- end
- def contents_fade(opacity, duration = DEFAULT_DURATION)
- return unless window?
- @target_contents_opacity = opacity
- make_fade_speed(duration)
- end
- def back_fade(opacity, duration = DEFAULT_DURATION)
- return unless window?
- @target_opacity = opacity
- make_fade_speed(duration)
- end
- def make_fade_speed(duration)
- @fade_speed = (@target_opacity - (window? ? @obj.back_opacity :
- @obj.opacity))/duration.to_f
- @fade_speed2 = (@target_contents_opacity - @obj.contents_opacity) /
- duration.to_f if window?
- end
- def window?
- @obj.is_a?(Window)
- end
- def fadeout(duration = DEFAULT_DURATION)
- fade(0, duration)
- end
- def fadein(duration = DEFAULT_DURATION)
- fade(255, duration)
- end
- def update_fade
- return unless fade?
- @obj.opacity += @fade_speed
- @obj.contents_opacity += @fade_speed2 if window?
- @target_opacity = -1 unless fade?
- end
- def fade?
- return false if @target_opacity == -1
- if window?
- (@target_opacity != @obj.opacity) &&
- (@target_contents_opacity != @obj.contents_opacity)
- else
- @target_opacity != @obj.opacity
- end
- end
- end
- end
- class Window
- include THEO::FADE
- alias pre_fade_init initialize
- def initialize(*args)
- pre_fade_init(*args)
- init_fade_members
- setfade_obj(self)
- end
- alias pre_fade_update update
- def update
- pre_fade_update
- update_fade
- end
- end
- class Sprite
- include THEO::FADE
- alias pre_fade_init initialize
- def initialize(*args)
- pre_fade_init(*args)
- init_fade_members
- setfade_obj(self)
- end
- alias pre_fade_update update
- def update
- pre_fade_update
- update_fade
- end
- end
- end
- # =============================================================================
- # Object Circular Movement
- # -----------------------------------------------------------------------------
- if $imported[:Theo_Circular]
- # =============================================================================
- module THEO
- module Circular
- class Circular_Obj
- attr_reader :ox
- attr_reader :oy
- attr_reader :center_obj
- attr_reader :obj
- def initialize(obj,ox,oy,center_obj)
- @obj = obj
- @center_obj = center_obj if can_move?(center_obj)
- @ox = ox
- @oy = oy
- @speed = 0
- @endless = false
- @freeze = false
- refresh_info
- end
- def refresh_info
- @radius = radius
- @degree_dest = @current_degree = get_degree
- end
- def center_obj=(center)
- return unless can_move?(center)
- @center_obj = center
- refresh_info
- end
- def ox=(ox)
- @ox = ox
- refresh_info
- end
- def oy=(oy)
- @oy = oy
- refresh_info
- end
- def can_move?(obj)
- obj.is_a?(Window) || obj.is_a?(Sprite)
- end
- def circle_move(degree,duration)
- return if endless?
- @degree_dest = (@current_degree + degree)
- @speed = (@degree_dest - @current_degree) / duration.to_f
- end
- def endless_circle(speed)
- @speed = speed
- @endless = true
- end
- def get_degree
- Math.degree(Math.atan2(range_y,range_x)) rescue 0
- end
- def range_x
- @obj.x - center_x
- end
- def range_y
- @obj.y - center_y
- end
- def center_x
- @center_obj.nil? ? @ox : @center_obj.x
- end
- def center_y
- @center_obj.nil? ? @oy : @center_obj.y
- end
- def radius
- Math.sqrt((range_x**2) + (range_y**2))
- end
- def update_circle
- return if circle_frozen?
- return unless rotate? || @endless
- @current_degree += @speed
- update_x
- update_y
- @degree_dest = @current_degree if @endless
- end
- def rotate?
- return @current_degree != @degree_dest
- end
- def update_x
- @obj.x = center_x + (@radius * Math.cos(Math.radian(@current_degree))).round
- end
- def update_y
- @obj.y = center_y + (@radius * Math.sin(Math.radian(@current_degree))).round
- end
- def circle_freeze
- @freeze = true
- end
- def circle_unfreeze
- @freeze = false
- end
- def circle_frozen?
- @freeze
- end
- def stop
- @endless = false
- end
- def continue
- @endless = true
- end
- def endless?
- @endless
- end
- end
- def set_circle(obj,ox = 0,oy = 0,center_obj = nil)
- @circle = Circular_Obj.new(obj,ox,oy,center_obj)
- end
- def stop
- @circle.stop
- end
- def continue
- @circle.continue
- end
- def endless?
- @circle.endless?
- end
- def circle_move(degree, dur = Graphics.frame_rate)
- @circle.circle_move(degree,dur)
- end
- def endless_circle(speed)
- @circle.endless_circle(speed)
- end
- def circle_freeze
- @circle.circle_freeze
- end
- def circle_unfreeze
- @circle.circle_unfreeze
- end
- def circle_frozed?
- @circle.circle_frozen?
- end
- def update_circle
- @circle.update_circle
- end
- def rotating?
- @circle.rotate?
- end
- def center_coordinate(ox,oy)
- @circle.ox = ox
- @circle.oy = oy
- end
- def center_distance(ox,oy)
- @circle.ox = @circle.obj.x + ox
- @circle.oy = @circle.obj.y + oy
- end
- def center_obj(obj)
- @circle.center_obj = obj
- end
- def refresh_info
- @circle.refresh_info
- end
- end
- end
- class Window
- include THEO::Circular
- alias theolized_circle_window_init initialize
- def initialize(*args)
- theolized_circle_window_init(*args)
- set_circle(self,x,y)
- end
- alias window_circle_update update
- def update
- window_circle_update
- update_circle
- end
- end
- class Sprite
- include THEO::Circular
- alias theolized_circle_init initialize
- def initialize(*args)
- theolized_circle_init(*args)
- set_circle(self,x,y)
- end
- alias sprite_circle_update update
- def update
- sprite_circle_update
- update_circle
- end
- end
- end
- # =============================================================================
- # Afterimage Base
- # -----------------------------------------------------------------------------
- if $imported[:Theo_CloneImage]
- # =============================================================================
- #~ class Bitmap
- #~ attr_reader :filename
- #~
- #~ alias theo_filename_init initialize
- #~ def initialize(*args)
- #~ @filename = ""
- #~ if args[0].is_a?(String)
- #~ @filename = args[0].dup.freeze
- #~ end
- #~ theo_filename_init(*args)
- #~ end
- #~
- #~ end
- class Sprite
- attr_reader :clone_bitmap
- alias theo_clonesprites_init initialize
- def initialize(*args)
- @cloned_sprites = []
- theo_clonesprites_init(*args)
- end
- # --------------------------------------------------------------------------
- # Base function to clone sprite
- # --------------------------------------------------------------------------
- def clone(z_pos = 0, clone_bitmap = false)
- @cloned_sprites.delete_if {|spr| spr.disposed? }
- cloned = clone_class.new(viewport)
- cloned.x = x
- cloned.y = y
- cloned.bitmap = bitmap
- cloned.bitmap = bitmap.clone if clone_bitmap
- if z_pos != 0
- cloned.z = z + z_pos
- else
- @cloned_sprites.each do |spr|
- spr.z -= 1
- end
- cloned.z = z - 1
- end
- cloned.src_rect.set(src_rect)
- cloned.zoom_x = zoom_x
- cloned.zoom_y = zoom_y
- cloned.angle = angle
- cloned.mirror = mirror
- cloned.opacity = opacity
- cloned.blend_type = blend_type
- cloned.color.set(color)
- cloned.tone.set(tone)
- cloned.visible = visible
- cloned.bush_depth = bush_depth
- cloned.bush_opacity = bush_opacity
- cloned.ox = ox
- cloned.oy = oy
- on_after_cloning(cloned)
- @cloned_sprites.push(cloned)
- cloned
- end
- def on_after_cloning(cloned)
- # Abstract method. Overwrite it as you want
- end
- # Sprite class for cloned sprite
- def clone_class
- Sprite
- end
- end
- # =============================================================================
- # Afterimages basic module for all sprite base instance object
- # =============================================================================
- class Sprite_Base < Sprite
- attr_accessor :afterimage
- attr_accessor :afterimage_opac
- attr_accessor :afterimage_rate
- alias theo_afterimagebase_init initialize
- def initialize(*args)
- init_afterimage_base
- theo_afterimagebase_init(*args)
- end
- def init_afterimage_base
- @afterimage = false
- @afterimage_count = 0
- @afterimage_rate = 3
- @afterimage_opac = 5
- @afterimages = []
- end
- alias theo_afterimagebase_update update
- def update
- theo_afterimagebase_update
- update_afterimage_effect
- end
- def update_afterimage_effect
- @afterimages.delete_if do |image|
- image.opacity -= afterimage_opac
- image.update if updating_afterimages?
- if image.opacity == 0
- image.dispose
- end
- image.disposed?
- end
- return unless afterimage
- @afterimage_count += 1
- if @afterimage_count % afterimage_rate == 0
- @afterimages.push(clone)
- end
- end
- def updating_afterimages?
- return false
- end
- end
- end
- # =============================================================================
- # Sprite Rotate Basic module
- # -----------------------------------------------------------------------------
- if $imported[:Theo_RotateImage]
- # =============================================================================
- module Theo
- module Rotation
- def init_rotate
- @degree = self.angle.to_f
- @target_degree = 0
- @rotating = false
- @rotate_speed = 0.0
- end
- def change_angle(target_degree, duration)
- @degree = self.angle.to_f
- @target_degree = target_degree.to_f
- if duration == 0
- @rotate_speed = target_degree
- else
- @rotate_speed = (target_degree - @degree) / duration
- end
- @rotating = true
- end
- def update_rotation
- return unless @rotating
- @degree += @rotate_speed
- new_angle = @degree.round
- self.angle = new_angle
- if new_angle == @target_degree
- init_rotate
- end
- end
- def start_rotate(degree_plus, duration)
- change_angle(@degree + degree_plus, duration)
- end
- end
- end
- class Sprite
- include Theo::Rotation
- alias theo_spr_rotate_init initialize
- def initialize(viewport = nil)
- theo_spr_rotate_init(viewport)
- init_rotate
- end
- alias theo_spr_rotate_update update
- def update
- theo_spr_rotate_update
- update_rotation
- end
- end
- end
- def debug
- puts "This line is executed"
- end
- def debugc
- puts Graphics.frame_count
- end
Advertisement
Add Comment
Please, Sign In to add comment