Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ■ Emoji Engine Ace - Origin "AI Core"
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Dev Script who permit to have interactive basic AI for your scene.
- # Created by Nio Kasgami.
- # Data : 2015/05/31
- # Version : 1.0.0
- # Require : NA
- #==============================================================================
- #==============================================================================
- # History
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # 2015/05/24 - Begin of the modular scripts {beta phase}.
- # 2015/???/??? - Implementations of the AI_Personality switch to Class.
- # 2015/???/??? - Begin of the AI Manual.
- # 2015/07/19 - Finish the Scripts {stable phase}.
- # 2015/07/25 - Begin of the new documentations since the old ones is now
- # obsolete.
- # 2015/08/02 - Adding new methods
- #==============================================================================
- #==============================================================================
- # Introduction
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- #==============================================================================
- module Emoji
- module AI
- #==============================================================================
- # System
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # It's the main Configuration of AI it's permit to setup some Core Options.
- # it's not needed to copy paste this part
- #==============================================================================
- System = {
- # define the pathfolder where you put your Graphics
- :ai_graphics_folder => "Graphics/AI/",
- # Define the Voice folder for your AI have to be in Audio/SE/:voice_folder
- :voice_folder => "voice",
- # set to true if you want to have entering and quitting animation effects
- # set to false for desactivate the effects
- :effects_enable => true,
- # define wich message system you use for show the dialogues
- # :default = the rtp message system
- # :nio_ai_dialogues = Emoji message_system
- :message_system => :default
- }
- AI_Personality ||= { } # do not touch!
- #AI_Personality Explaination
- # for add a new personality just set a new id like that AI_Personality[id] ={}
- # id = id is the id you want to set your game
- #
- # AI_Personality Mandatory option {Important}
- # it's important to include these option or the system will crash
- #AI_Personality[id] ={
- #:ai_graphics => filename,
- #:ai_posx => value_x,
- #:ai_posy => value_y,
- #:ai_posz => value_z,
- # }
- # AI_Personality Optional element {Effects}
- # C'est element ne sont obligatoire que si :effect_enable, bubble_emo_enable est sur
- # true. Sinon il n'est pas necessaire de les ajouter a AI_Personality
- # E.G :
- #AI_Personality[id] ={
- # :entering_effect_type => effect_type,
- # :quitting_effect_type => effect_type,
- # :invert_effect => false,
- # }
- # AI_Personality Optional element {dialogue && voice}
- # c'est element peuvent être modifier ou enlever du system sans affecter son fonctionnement
- # Vous pouvez aussi en rajouter des nouvelle en modifiant la methode "retrieve_dialogues_and_voices"
- # de Game_AI. Le fait que certaine de ces variable ne soit pas presente dans les differente
- # AI_Personality n'affecteras pas son fonctionnement
- # E.G :
- # AI_Personality[1] ={
- #:greeting => "blabla",
- #:good_bye => "blibli",
- #:voice_greeting_filename => "hi!"
- #}
- # AI_Personality[2] ={
- #:good_bye => "bubhu",
- #:sell => "money!"
- #}
- AI_Personality[1] ={
- :ai_sprite => "dummy_",
- :ai_posx => 0,
- :ai_posy => 0,
- # :ai_z => 0,
- :ai_posz => 200,
- # effects :
- # :hori_slide = le buste glissera horizontalement de l'exterieur de l'écran jusqu'a l'interieur
- # :verti_slide = le buste gli
- # :fadein =
- #
- :entering_effect_type => :hori_slide,
- :quitting_effect_type => :execute_outhori_slide,
- :invert_effect => false,
- :greeting => "yeah",
- :good_bye => "",
- :buy_goods_dialogues => "text",
- :sell_goods_dialogues => "",
- :not_buying_dialogues => "",
- :not_selling_dialogues => "",
- #not yet
- :haggle_goods_dialogues => "",
- :suceed_haggles_dialogues => "",
- :fail_haggles_dialogues => "",
- #not yet implemented
- :good_reputation_greeting => "",
- :bad_reputation_greeting => "",
- :kick_out_shop_dialogues => "",
- :patience => 100
- }
- end
- end
- #==============================================================================
- # ◎ Global_Variable : Version
- #------------------------------------------------------------------------------
- # Cette variable sert tout bonnement pour pouvoir ajouter des mise a jours
- # supplementaire a mon scripts sans forcer les gens a recopier mon script
- # constament effaçant ainsi leurs propre modifications au script.
- # si vous voulez ajoutez une "patch" supplementaire changer le numeros de la
- # version.
- #(le script original sera toujours mit a jours dans le lien principal)
- $version = 1.00
- #=============================================================================
- #==============================================================================
- # ■ Game_AI
- #------------------------------------------------------------------------------
- # This class handles ai actions. It used within the Game_Personalities class
- # ($game_personalities).
- #==============================================================================
- class Game_AI
- include Emoji::AI
- #==============================================================================
- # ■ Game_AI {Public Instance Variables}
- #------------------------------------------------------------------------------
- # this the section where I handdle all the variables who can be change in games
- # or in script in simple this permit to handle variable who change a lots
- #==============================================================================
- #----------------------------------------------------------------------------
- # ♦ Public Instance Variables {System}
- #----------------------------------------------------------------------------
- attr_accessor :ai_enable # AI Activation flag
- #----------------------------------------------------------------------------
- # ♦ Public Instance Variables {Interactive AI::Dialogues}
- #----------------------------------------------------------------------------
- attr_accessor :dialogues # Get text (in row)
- attr_accessor :greeting # Greeting dialogues
- attr_accessor :goodbye # Good bye dialogues
- attr_accessor :buy_goods_dialogues # Buying dialogues
- attr_accessor :sell_goods_dialogues # Selling dialogues
- attr_accessor :not_buying_dialogues # not buying dialogues
- attr_accessor :not_selling_dialogues # not selling dialogues
- #----------------------------------------------------------------------------
- # ♦ Public Instance Variables {Interactive AI::Interaction}
- #----------------------------------------------------------------------------
- attr_accessor :interaction # make interactions accessible
- attr_accessor :interaction_type # define the type of interaction
- # attr_accessor :interaction_emotion_type # define the type of emotion
- attr_accessor :ai_id # For ai personality
- #----------------------------------------------------------------------------
- # ♦ Public Instance Variables {Interactive AI::Graphics}
- #----------------------------------------------------------------------------
- attr_accessor :ai_sprite # For the shopkeeper bust graphics
- attr_accessor :index # for define the file index
- #===============================================================================
- # => END : Game_AI {Public Instance Variables}
- #===============================================================================
- #==============================================================================
- # ■ Game_AI {Core}
- #------------------------------------------------------------------------------
- # This section is the place where I initialize everything's and permit to
- # retrieve the whole AI_Personality[id] informations. It's also inits the
- # firts actions made by the system.
- # {exclude sprite configurations}
- #==============================================================================
- #----------------------------------------------------------------------------
- # ○ new method: initialize
- #----------------------------------------------------------------------------
- def initialize(ai_id)
- # core data
- @ai_id = ai_id
- @ai_personality = AI_Personality[@ai_id]
- @voice = @ai_personality[@ai_id]
- @interaction_type = :normal
- # @interaction_emotion_type = :neutral {obsolete}
- #------------------------------------------------
- check_message_types
- retrieve_dialogues_and_voices
- init_sprite
- # init_flags {desactivate because not ready reactivate it if you are sure
- # to know how to play with effects}
- end
- #----------------------------------------------------------------------------
- # ○ new method: retrieve_dialogues_and_voices
- #----------------------------------------------------------------------------
- def retrieve_dialogues_and_voices
- @greeting = @ai_personality[:greeting]
- @goodbye = @ai_personality[:goodbye]
- @buy_goods_dialogues = @ai_personality[:buy_goods_dialogues]
- @sell_goods_dialogues = @ai_personality[:sell_goods_dialogues]
- @not_buying_dialogues = @ai_personality[:not_buying_dialogues]
- @not_selling_dialogues = @ai_personality[:not_selling_dialogues]
- end
- #----------------------------------------------------------------------------
- # ○ new method: check_message_types
- #----------------------------------------------------------------------------
- def check_message_types
- case System[:message_system]
- when :default
- @dialogue_system = $game_message
- when :nio_ai_dialogues
- @dialogue_system = $game_dialogues
- end
- end
- #----------------------------------------------------------------------------
- # ○ new method: init_flags
- #----------------------------------------------------------------------------
- def init_flags
- if System[:effects_enable]
- @flag_type = :entering
- @effect_flag = true
- end
- @interaction_type = :greeting_action
- interaction
- end
- #===============================================================================
- # => END : Game_AI {Core}
- #===============================================================================
- #==============================================================================
- # ■ Game_AI {Core::interactions}
- #------------------------------------------------------------------------------
- # Cette section sert pour la configuration qui dicte comment votre IA reagit
- # a vos actions. Il est generalement dicter par
- # $game_personalities[ai_id].interaction_type = :key
- # et activer par
- # $game_personalities[ai_id].interaction
- #==============================================================================
- #----------------------------------------------------------------------------
- # ○ new method: interaction
- #----------------------------------------------------------------------------
- def interaction
- case @interaction_type
- when :greeting_action
- greeting_reactions
- when :try2
- @index = 1
- $game_message.add(@buy_goods_dialogues) #@dialogue.call_dialogues("stuff")
- when :try3
- @index = 2
- when :over
- @index = 2
- $game_message.add(@greeting )
- $game_message.new_page
- $game_message.add("stuff")
- call_voice("rawr",100,100)
- end
- end
- #----------------------------------------------------------------------------
- # ★ preset methods : interaction_actions {for organisation purpose}
- #----------------------------------------------------------------------------
- def greeting_reactions
- @index = 2
- @dialogue_system.add(@greeting)
- # call_voice(@voice[:greeting_voice],100,100)
- end
- #===============================================================================
- # => END : Game_AI {Core::Interactions}
- #===============================================================================
- #==============================================================================
- # ■ Game_AI {Sprite}
- #------------------------------------------------------------------------------
- # This section serve for Sprite initialization and configuration purpose
- #==============================================================================
- #----------------------------------------------------------------------------
- # ○ new method: init_sprite
- #----------------------------------------------------------------------------
- def init_sprite
- # retrieve sprite data from AI_Personality
- @ai_sprite = @ai_personality[:ai_sprite]
- @index = 0
- # Initialize Sprite
- @sprite = Sprite.new
- @sprite.bitmap = Cache.system(@ai_sprite + @index.to_s)
- @sprite.x = @ai_personality[:ai_posx]
- @sprite.y = @ai_personality[:ai_posy]
- @sprite.z = @ai_personality[:ai_posz]
- @sprite.opacity = 250
- # @sprite.ox = Graphics.width / 2
- # @sprite.oy = Graphics.height / 2
- # create effects flags
- @effect_flag = false
- @effect_type = :nil
- @flag_type = :nil
- @invert_effect = @ai_personality[:invert_effect]
- # create_effects datas
- @hori_left = (@sprite.ox - @sprite.x - 100)
- @hori_right = (@sprite.ox + @sprite.x + 100)
- @verti_up = (@sprite.oy - @sprite.y - 100)
- # @verti_down = (@sprite.oy + 100)
- @time_value = 0
- @fadein_value = 2
- @fadeout_value = 2
- end
- #----------------------------------------------------------------------------
- # ○ new method: refresh
- #----------------------------------------------------------------------------
- def refresh
- @index = 0
- end
- #----------------------------------------------------------------------------
- # ○ new method: terminate_sprite
- #----------------------------------------------------------------------------
- def terminate_sprite
- @sprite.dispose
- @sprite.bitmap.dispose
- end
- #----------------------------------------------------------------------------
- # ○ new method: update_sprite
- #----------------------------------------------------------------------------
- def update_sprite
- @sprite.bitmap = Cache.system(@ai_sprite + @index.to_s )
- update_effect if @effect_flag
- refresh if !@dialogue_system.busy?
- end
- #===============================================================================
- # => END : Game_AI {Sprite}
- #===============================================================================
- #==============================================================================
- # ■ Game_AI {Sprite::Effects}
- #------------------------------------------------------------------------------
- #==============================================================================
- #~ #----------------------------------------------------------------------------
- #~ # ○ new method: update_effect
- #----------------------------------------------------------------------------
- def update_effect
- case @flag_type
- when :entering
- @effect_type = @ai_personality[:entering_effect_type]
- init_entering_effects
- when :quitting
- @effect_type = @ai_personality[:quitting_effect_type]
- init_quitting_effects
- end
- end
- def execute_dummy
- @final_pos = @ai_personality[:ai_posx]
- while @time_value <= 200
- #if @time_value < 10
- @sprite.x += 2
- @time_value += 2
- break if @sprite.x >= @final_pos + 70
- end
- #elsif @time_value > 10
- # @effect_flag = false
- # @sprite.x = @final_pos
- # @effect_flag = false
- end
- #----------------------------------------------------------------------------
- # ○ new method: init_entering_effects
- #----------------------------------------------------------------------------
- def init_entering_effects
- execute_inhori_slide if @effect_type == :hori_slide
- execute_inverti_slide if @effect_type == :verti_slide
- execute_fadein if @effect_type == :fadein
- end
- #----------------------------------------------------------------------------
- # ○ new method: init_quitting_effects
- #----------------------------------------------------------------------------
- def init_quitting_effects
- execute_outverti_slide if @effect_type == :hori_slide
- execute_ouverti_slide if @effect_type == :verti_slide
- execute_fadeout if @effect_type == :fadeout
- end
- #----------------------------------------------------------------------------
- # ○ new method: execute_inhori_slide {in horizontal slide effect}
- #----------------------------------------------------------------------------
- def execute_inhori_slide(time_value,hori_left,hori_right)
- @time_value = 0
- @final_pos = @ai_personality[:ai_posx]
- if @time_value > 250
- @sprite.x += 2
- else
- @sprite.x = @final_pos
- end
- @effect_flag = false
- end
- #----------------------------------------------------------------------------
- # ○ new method: execute_inverti_slide {in vertical slide effect}
- #----------------------------------------------------------------------------
- def execute_inverti_slide#(time_value,verti_down,verti_up)
- @final_pos = @ai_personality[:ai_posy]
- # @sprite.y = @verti_down
- while @time_value <= 200
- #if @time_value < 10
- @sprite.y -= 2
- @time_value += 2
- break if @sprite.y <= @final_pos + 70
- end
- @effect_flag = false if @sprite.y == @final_pos
- end
- #----------------------------------------------------------------------------
- # ○ new method: execute_fadein {fadein effect}
- #----------------------------------------------------------------------------
- def execute_fadein(time_value, fadein_value)
- @time_value = 0
- while @time_value < 250
- @time_value += 2
- @sprite.opacity += @fadein_value
- break if @sprite.opacity >= 250 || @time_value >= 250
- end
- @effect_flag = false
- end
- #----------------------------------------------------------------------------
- # ○ new method: execute_outhori_slide {out horizontal slide effect}
- #----------------------------------------------------------------------------
- def execute_outhori_slide(time_value,hori_left,hori_right)
- @time_value = 0
- if !invert_effect
- while @time_value < 250
- @time_value += 2
- @sprite.ox -= 2
- break if @sprite.x >= @hori_left || @time_value >= 250
- end
- else
- while @time_value < 250
- @time_value += 2
- @sprite.ox += 2
- break if @sprite.x >= @hori_right || @time_value >= 250
- end
- end
- @effect_flag = false
- end
- #----------------------------------------------------------------------------
- # ○ new method: execute_outverti_slide {out vertical slide effect}
- #----------------------------------------------------------------------------
- def execute_outverti_slide(time_value,verti_down,verti_up)
- @time_value = 0
- if !invert_effect
- while @time_value < 250
- @time_value += 2
- @sprite.oy -= 2
- break if @sprite.y >= @verti_down || @time_value >= 250
- end
- else
- while @time_value < 250
- @time_value += 2
- @sprite.oy += 2
- break if @sprite.y >= @verti_up || @time_value >= 250
- end
- end
- @effect_flag = false
- end
- #----------------------------------------------------------------------------
- # ○ new method: execute_fadeout {fadeout effect}
- #----------------------------------------------------------------------------
- def execute_fadeout(time_value, fadeout_value)
- @time_value = 0
- while @time_value < 250
- @time_value += 2
- @sprite.opacity -= @fadeout_value
- break if @sprite.opacity <= 0 || @time_value >= 250
- end
- @effect_flag = false
- end
- #===============================================================================
- # => END : Game_AI {Sprite::Effects}
- #===============================================================================
- #==============================================================================
- # ■ Game_AI {Voice}
- #------------------------------------------------------------------------------
- # This section serve for AI Voice SE purpose
- # use call_voice("filename",volume,pitch)
- #==============================================================================
- #----------------------------------------------------------------------------
- # ○ new method: pathfile
- #----------------------------------------------------------------------------
- def pathfile
- @voice_folder = System[:voice_folder]
- pathfile = @voice_folder + "/"
- end
- #----------------------------------------------------------------------------
- # ○ new method: call_voice
- #----------------------------------------------------------------------------
- def call_voice(voice_index,volume,pitch)
- RPG::SE.new(pathfile + voice_index ,volume,pitch).play
- end
- #===============================================================================
- # => END : Game_AI {Voice}
- #===============================================================================
- end
- #===============================================================================
- # => END : Game_AI
- #===============================================================================
- #==============================================================================
- # ■ Module : Cache
- #------------------------------------------------------------------------------
- # This module loads graphics, creates bitmap objects, and retains them.
- # To speed up load times and conserve memory, this module holds the
- # created bitmap object in the internal hash, allowing the program to
- # return preexisting objects when the same bitmap is requested again.
- #==============================================================================
- module Cache
- #----------------------------------------------------------------------------
- # ○ new method: pathfolder
- #----------------------------------------------------------------------------
- def self.pathfolder
- return Emoji::AI::System[:ai_graphics_folder]
- end
- #----------------------------------------------------------------------------
- # ○ new method: ai_graphics
- #----------------------------------------------------------------------------
- def self.ai_graphics(filename)
- load_bitmap(pathfolder,filename)
- end
- end
- #===============================================================================
- # => END : Module Cache
- #===============================================================================
- #==============================================================================
- # ■ DataManager
- #------------------------------------------------------------------------------
- # This module manages the database and game objects. Almost all of the
- # global variables used by the game are initialized by this module.
- #==============================================================================
- module DataManager
- #----------------------------------------------------------------------------
- # ★ FalseClass : alias
- #----------------------------------------------------------------------------
- class << self
- alias nio_ai_object create_game_objects
- alias nio_ai_save make_save_contents
- alias nio_ai_extracts extract_save_contents
- end
- #----------------------------------------------------------------------------
- # ● alias method: create_game_objects
- #----------------------------------------------------------------------------
- def self.create_game_objects
- nio_ai_object
- $game_personalities = Game_Personalities.new
- $game_dialogues = Game_Dialogues.new
- end
- #----------------------------------------------------------------------------
- # ● alias method: make_save_contents
- #----------------------------------------------------------------------------
- def self.make_save_contents
- contents = nio_ai_save
- contents[:personalities] = $game_personalities
- contents[:dialogues] = $game_dialogues
- contents
- end
- #----------------------------------------------------------------------------
- # ● alias method: extract_save_contents
- #----------------------------------------------------------------------------
- def self.extract_save_contents(contents)
- nio_ai_extracts(contents)
- $game_personalities = contents[:personalities]
- $game_dialogues = contents[:dialogues]
- end
- end
- #===============================================================================
- # => END : Module DataManager
- #===============================================================================
- #==============================================================================
- # ■ Game_Personalities
- #------------------------------------------------------------------------------
- # This class handles Personality_id. It's a wrapper for the built-in class
- # "Array." The instance of this class is referenced by $game_Personalities.
- #==============================================================================
- class Game_Personalities
- #----------------------------------------------------------------------------
- # ○ new method: initialize
- #----------------------------------------------------------------------------
- def initialize
- @personality =[]
- end
- #----------------------------------------------------------------------------
- # ○ new method: []
- #----------------------------------------------------------------------------
- def [](ai_id)
- if !Emoji::AI::AI_Personality[ai_id]
- msgbox("ERROR : please assign a valid ID")
- exit
- else
- @personality[ai_id] ||= Game_AI.new(ai_id)
- end
- end
- end
- #===============================================================================
- # => END : Game_Personalities
- #===============================================================================
- #==============================================================================
- # ■ Game_Interpreter
- #------------------------------------------------------------------------------
- # An interpreter for executing event commands. This class is used within the
- # Game_Map, Game_Troop, and Game_Event classes. This snipset add executing
- # for Game_Personalities and Game_AI classes event processing.
- #==============================================================================
- class Game_Interpreter
- #----------------------------------------------------------------------------
- # ♦ Public Instance Variables {System}
- #----------------------------------------------------------------------------
- attr_accessor :ai_shop_id
- #----------------------------------------------------------------------------
- # ● alias method: initialize
- #----------------------------------------------------------------------------
- alias nio_interp initialize
- def initialize(depth = 0)
- nio_interp
- @ai_shop_id = 0
- end
- #----------------------------------------------------------------------------
- # ○ new method: ai_scene
- #----------------------------------------------------------------------------
- def ai_scene(scenes,personality_type)
- SceneManager.call(scenes)
- SceneManager.scene.prepare(personality_type)
- end
- #----------------------------------------------------------------------------
- # ● overwrite method: command_302 { desactivate }
- #----------------------------------------------------------------------------
- # def command_302
- # return if $game_party.in_battle
- # goods = [@params]
- # while next_event_code == 605
- # @index += 1
- # goods.push(@list[@index].parameters)
- # end
- # SceneManager.call(Scene_Shop)
- # SceneManager.scene.prepare(goods, @params[4], @ai_shop_id)
- # Fiber.yield
- # end
- end
- #===============================================================================
- # => END : Game_interpreter
- #===============================================================================
- #==============================================================================
- # ■ Scene_Foo {structural exemple}
- #------------------------------------------------------------------------------
- # This a exemple of How structure the script for the
- # Prepare, update, terminate method
- #==============================================================================
- class Scene_Foo < Scene_Base
- def prepare(ai_id)
- @ai_id = ai_id
- end
- def start
- #you_stuff
- create_message_system
- @var_name = $game_personalities[@ai_id]
- a_calling_method
- end
- def a_calling_method
- @var_name.personality_type = :greeting # will set wich kind of reactions
- @var_name.interaction # will call interactions
- def create_message_system
- @message = Window_Message.new
- end
- def update
- super
- @var_name.update_sprite
- end
- def terminate
- super
- @var_name.terminate_sprite
- end
- end
- #===============================================================================
- # => END : Scene_Foo
- #===============================================================================
- #==============================================================================
- # END OF SCRIPT
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement