| Ancien membre du staff |
 |
 |
Inscrit le: 24 Juin 2008, 00:00 Messages: 476 Logiciel(s) préféré(s): Scintilla based Point(s) Fort(s): Rubyismes Points d'aide: 60/60
Créations :
- [Rmxp] Vocab
- [Rmxp] Visible Equipment
- [Rmxp] Animated Title
- [XP/VX] Cache Extension
Voir ses créations
|
Script :- Code: Tout sélectionner
#=============================================================================== # *** Visible Equipment # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Auteur : Wawower # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Version : 3.0 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Dependances : # - Database Management v2 par Åvygeil # - Cache Extension # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Description : # Ce script permet d'afficher les equipements d'un personnage sur son character. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Utilisation : # - Il faut remplir la base de données pour assigner à chaque equipement son character. # - Pour assigner un character par defaut il suffit de laisser le champs "for_actor" vide. # - Les équipements peuvent être placés plus ou moins haut avec le champs "z", le # character du héros est placé à une hauteur de 0, pour qu'un équipement soit en dessous # de ce dernier il suffit donc qu'il ait un valeur de "z" négative. # - Pour donner à un event l'apparence d'un héros, avec ses équipements, il faut ajouter # dans cet event un commentaire sous la forme "Actor: [Id]" où Id est l'id dans la base de # données du-dit acteur. #===============================================================================
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Création des tables de la database. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Database.create_table "VisibleWeapon" do |t| t.column :weapon, Database::Weapons t.column :character, Database::File["Graphics/Equipments"] t.column :character_hue, Database::Integer t.column :z, Database::Integer, :default => 100 t.column :for_actor, Database::Actors end Database.create_table "VisibleArmor" do |t| t.column :armor, Database::Armors t.column :character, Database::File["Graphics/Equipments"] t.column :character_hue, Database::Integer t.column :z, Database::Integer, :default => 100 t.column :for_actor, Database::Actors end
#============================================================================== # ** Game Actor # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Modifications de la classe Game_Actor qui gére maintenant les characters des # équipements à ajouter au character du perso. #============================================================================== class Game_Actor # Accesseur ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ attr_reader :visible_equipment # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Aliases des méthodes essentielles dans la gestion des équipements et du # character avec ajout de l'appel de la methode update_visible_equipment. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alias visible_equip_initialize initialize def initialize(*args) visible_equip_initialize(*args) update_visible_equipment end # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alias visible_equip_equip equip def equip(*args) visible_equip_equip(*args) update_visible_equipment end # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alias visible_equip_set_graphic set_graphic def set_graphic(*args) visible_equip_set_graphic(*args) update_visible_equipment end # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Récuperation dans la base de données des characters à associer # aux differents équipements du héros. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def update_visible_equipment @visible_equipment = [] # Récuperation de la ligne database associée à l'arme pour cet acteur. row = Database::VisibleWeapon.find { |r| r.weapon == @weapon_id and r.for_actor == self.id } # Si aucune ligne n'est spécifique à cet acteur, on prend la ligne par défaut. row ||= Database::VisibleWeapon.find { |r| r.weapon == @weapon_id and r.for_actor == 0 } @visible_equipment << row unless row.nil? [@armor1_id,@armor2_id,@armor3_id,@armor4_id].each { |armor_id| # Récuperation de la ligne database associée à l'équipement pour cet acteur. row = Database::VisibleArmor.find { |r| r.armor == armor_id and r.for_actor == self.id } # Si aucune ligne n'est spécifique à cet acteur, on prend la ligne par défaut. row ||= Database::VisibleArmor.find { |r| r.armor == armor_id and r.for_actor == 0 } @visible_equipment << row unless row.nil? } @visible_equipment.compact! @visible_equipment.delete_if { |e| e.character.nil? } @sprite_outdated = true end
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Prédicat indiquant si le Sprite_Character associé à cet acteur # doit être mis à jour. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def sprite_outdated? @sprite_outdated end
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Le sprite à été mis à jour. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def sprite_uptodate @sprite_outdated = false end
end
#============================================================================== # ** Game Event #============================================================================== class Game_Event # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Pseudo-prédicat permettant d'identifier si le character est associé # à un acteur et de récuperer cet acteur le cas échéant. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ attr :associated_actor def check_associated_actor comment = @list.find { |command| [108, 408].include?(command.code) and command.parameters[0] =~ /^Actor:\s?([0-9]+)/ } return false if comment.nil? comment = comment.parameters[0] actor = $game_actors[$1.to_i] return (!actor.nil? and actor) end # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Initialize le pseudo-prédicat et donne une valeur à @character_name si # besoin est pour gerer la passabilité de l'event. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alias ve_refresh refresh def refresh ve_refresh @associated_actor = check_associated_actor if @associated_actor @character_name = @associated_actor.character_name end end
end
#============================================================================== # ** Game Player #============================================================================== class Game_Player # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Pseudo-prédicat permettant d'identifier si le character est associé # à un acteur. Doit être redefini si l'utilisateur utilise un script de # gestion de leader plus complexe. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def associated_actor $game_party.actors[0] end end
#============================================================================== # ** RPG::Cache #============================================================================== module RPG::Cache # Ajout du dossier Equipments et de la méthode associé #equipments. add "Equipments" # Nouvelle table de hashage reservée aux characters des héros. @actor_cache = {} class << self
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Récuperation du bitmap associé à l'acteur avec les équipements blittés. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def actor_character(actor) key = [actor.character_name, actor.character_hue] key += actor.visible_equipment.map { |e| e.id } cached_picture = @actor_cache[key] # Si l'image n'existe pas déjà ou est disposée. if cached_picture.nil? or cached_picture.disposed? bmps = actor.visible_equipment.map { |e| [e.z, equipment(e.character, e.character_hue)] } bmps << [0, character(actor.character_name, actor.character_hue)] bmps.sort! { |bmp1, bmp2| bmp1[0] <=> bmp2[0] } bmps.map! { |bmp| bmp[1] } chara = bmps.shift.clone rect = Rect.new(0, 0, chara.width, chara.height) bmps.each { |bmp| chara.blt(0, 0, bmp, rect) } # Mise en cache. return (@actor_cache[key] = chara) end return cached_picture end # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * clear # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alias ve_clear clear unless method_defined? :ve_clear def clear @actor_cache = {} ve_clear end
end
end #============================================================================== # ** Sprite_Character #============================================================================== class Sprite_Character # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Redéfinition de la méthode update qui rafraichit maintenant le # character du sprite si c'est un character d'acteur et si au # moins un des équipement de celui-ci a changé. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def update super # If sprite has to be updated or if tile ID, file name, # or hue are different from current ones associated_actor = @character.associated_actor if (associated_actor and associated_actor.sprite_outdated?) or @tile_id != @character.tile_id or @character_name != @character.character_name or @character_hue != @character.character_hue # Remember associated_actor, tile ID, file name, and hue @tile_id = @character.tile_id @character_name = @character.character_name @character_hue = @character.character_hue if associated_actor self.bitmap = RPG::Cache.actor_character(associated_actor) @cw = bitmap.width / 4 @ch = bitmap.height / 4 self.ox = @cw / 2 self.oy = @ch associated_actor.sprite_uptodate else # 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) @cw = bitmap.width / 4 @ch = bitmap.height / 4 self.ox = @cw / 2 self.oy = @ch end 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 #============================================================================== # ** Window_Base #============================================================================== class Window_Base # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Redéfinition de la méthode de dessin des characters des # acteurs pour y inclure leurs équipements. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def draw_actor_graphic(actor, x, y) bitmap = RPG::Cache.actor_character(actor) cw = bitmap.width / 4 ch = bitmap.height / 4 src_rect = Rect.new(0, 0, cw, ch) self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect) end end #============================================================================== # ** Window_SaveFile # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Modification du fonctionnement de Window_Save_File afin d'afficher les # characters avec les équipements #============================================================================== class Window_SaveFile < Window_Base # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * initialize # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def initialize(file_index, filename) super(0, 64 + file_index % 4 * 104, 640, 104) self.contents = Bitmap.new(width - 32, height - 32) @file_index = file_index @filename = "Save#{@file_index + 1}.rxdata" @time_stamp = Time.at(0) @file_exist = FileTest.exist?(@filename) if @file_exist file = File.open(@filename, "r") @time_stamp = file.mtime Marshal.load(file) @frame_count = Marshal.load(file) @game_system = Marshal.load(file) @game_switches = Marshal.load(file) @game_variables = Marshal.load(file) 3.times { Marshal.load(file) } @actors = Marshal.load(file).actors[0..4] @total_sec = @frame_count / Graphics.frame_rate file.close end refresh @selected = false end # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * refresh # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def refresh self.contents.clear # Draw file number self.contents.font.color = normal_color name = "File #{@file_index + 1}" self.contents.draw_text(4, 0, 600, 32, name) @name_width = contents.text_size(name).width # If save file exists if @file_exist # Draw character @actors.each_with_index { |actor, i| bitmap = RPG::Cache.actor_character(actor) cw = bitmap.rect.width / 4 ch = bitmap.rect.height / 4 src_rect = Rect.new(0, 0, cw, ch) x = 300 - 4 * 32 + i * 64 - cw / 2 self.contents.blt(x, 68 - ch, bitmap, src_rect) } # Draw play time hour = @total_sec / 60 / 60 min = @total_sec / 60 % 60 sec = @total_sec % 60 time_string = sprintf("%02d:%02d:%02d", hour, min, sec) self.contents.font.color = normal_color self.contents.draw_text(4, 8, 600, 32, time_string, 2) # Draw timestamp self.contents.font.color = normal_color time_string = @time_stamp.strftime("%Y/%m/%d %H:%M") self.contents.draw_text(4, 40, 600, 32, time_string, 2) end end end
|
|