Advertisement
nio_kasgami

Emoji Engine Ace - Origin "AI Core"

Aug 12th, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 29.43 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Emoji Engine Ace - Origin "AI Core"
  3. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  4. # Dev Script who permit to have interactive basic AI for your scene.
  5. # Created by Nio Kasgami.
  6. # Data : 2015/05/31
  7. # Version : 1.0.0
  8. # Require : NA
  9. #==============================================================================
  10.  
  11. #==============================================================================
  12. # History
  13. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  14. # 2015/05/24 - Begin of the modular scripts {beta phase}.
  15. # 2015/???/??? - Implementations of the AI_Personality switch to Class.
  16. # 2015/???/??? - Begin of the AI Manual.
  17. # 2015/07/19 - Finish the Scripts {stable phase}.
  18. # 2015/07/25 - Begin of the new documentations since the old ones is now
  19. # obsolete.
  20. # 2015/08/02 - Adding new methods
  21. #==============================================================================
  22.  
  23. #==============================================================================
  24. # Introduction
  25. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  26. #
  27. #==============================================================================
  28. module Emoji
  29. module AI
  30. #==============================================================================
  31. # System
  32. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  33. # It's the main Configuration of AI it's permit to setup some Core Options.
  34. # it's not needed to copy paste this part
  35. #==============================================================================
  36.   System = {
  37.   # define the pathfolder where you put your Graphics
  38.     :ai_graphics_folder => "Graphics/AI/",
  39.   # Define the Voice folder for your AI have to be in Audio/SE/:voice_folder
  40.     :voice_folder => "voice",
  41.   # set to true if you want to have entering and quitting animation effects
  42.   # set to false for desactivate the effects
  43.     :effects_enable => true,
  44.   # define wich message system you use for show the dialogues
  45.   # :default = the rtp message system
  46.   # :nio_ai_dialogues = Emoji message_system
  47.     :message_system => :default
  48.  
  49.   }
  50.       AI_Personality ||= { } # do not touch!
  51.  
  52.     #AI_Personality Explaination
  53.     # for add a new personality just set a new id like that AI_Personality[id] ={}
  54.     # id = id is the id you want to set your game
  55.     #
  56.     # AI_Personality Mandatory option {Important}
  57.     # it's important to include these option or the system will crash
  58.     #AI_Personality[id] ={
  59.     #:ai_graphics => filename,
  60.     #:ai_posx => value_x,
  61.     #:ai_posy => value_y,
  62.     #:ai_posz => value_z,
  63.  
  64.   #     }
  65.  
  66.    # AI_Personality Optional element {Effects}
  67.    # C'est element ne sont obligatoire que si :effect_enable, bubble_emo_enable est sur
  68.    # true. Sinon il n'est pas necessaire de les ajouter a AI_Personality
  69.    # E.G :
  70.    #AI_Personality[id] ={
  71.    #  :entering_effect_type => effect_type,
  72.    # :quitting_effect_type => effect_type,
  73.    # :invert_effect => false,
  74.    # }
  75.  
  76.    # AI_Personality Optional element {dialogue && voice}
  77.    # c'est element peuvent être modifier ou enlever du system sans affecter son fonctionnement
  78.    # Vous pouvez aussi en rajouter des nouvelle en modifiant la methode "retrieve_dialogues_and_voices"
  79.    # de Game_AI. Le fait que certaine de ces variable ne soit pas presente dans les differente
  80.    # AI_Personality n'affecteras pas son fonctionnement
  81.    # E.G :
  82.    # AI_Personality[1] ={
  83.    #:greeting => "blabla",
  84.    #:good_bye => "blibli",
  85.  
  86.    #:voice_greeting_filename => "hi!"
  87.    #}
  88.    # AI_Personality[2] ={
  89.    #:good_bye => "bubhu",
  90.    #:sell => "money!"
  91.    #}
  92.    
  93.     AI_Personality[1] ={
  94.  
  95.     :ai_sprite => "dummy_",
  96.     :ai_posx => 0,
  97.     :ai_posy => 0,
  98.    # :ai_z => 0,
  99.     :ai_posz => 200,
  100.     # effects :
  101.     # :hori_slide = le buste glissera horizontalement de l'exterieur de l'écran jusqu'a l'interieur
  102.     # :verti_slide = le buste gli
  103.     # :fadein =
  104.     #  
  105.     :entering_effect_type => :hori_slide,
  106.     :quitting_effect_type => :execute_outhori_slide,
  107.     :invert_effect => false,
  108.  
  109.     :greeting => "yeah",
  110.     :good_bye => "",
  111.     :buy_goods_dialogues => "text",
  112.     :sell_goods_dialogues => "",
  113.    
  114.     :not_buying_dialogues => "",
  115.     :not_selling_dialogues => "",
  116.    
  117.     #not yet
  118.     :haggle_goods_dialogues => "",
  119.     :suceed_haggles_dialogues => "",
  120.     :fail_haggles_dialogues => "",
  121.    
  122.    
  123.    
  124.    
  125.     #not yet implemented
  126.     :good_reputation_greeting => "",
  127.     :bad_reputation_greeting => "",
  128.     :kick_out_shop_dialogues => "",
  129.     :patience => 100
  130.     }
  131.   end
  132. end
  133.  
  134.  
  135. #==============================================================================
  136. # ◎ Global_Variable : Version
  137. #------------------------------------------------------------------------------
  138. # Cette variable sert tout bonnement pour pouvoir ajouter des mise a jours
  139. # supplementaire a mon scripts sans forcer les gens a recopier mon script
  140. # constament effaçant ainsi leurs propre modifications au script.
  141. # si vous voulez ajoutez une "patch" supplementaire changer le numeros de la
  142. # version.
  143. #(le script original sera toujours mit a jours dans le lien principal)
  144.   $version = 1.00
  145. #=============================================================================
  146.  
  147. #==============================================================================
  148. # ■ Game_AI
  149. #------------------------------------------------------------------------------
  150. # This class handles ai actions. It used within the Game_Personalities class
  151. # ($game_personalities).
  152. #==============================================================================
  153.  
  154. class Game_AI
  155.   include Emoji::AI
  156. #==============================================================================
  157. # ■ Game_AI {Public Instance Variables}
  158. #------------------------------------------------------------------------------
  159. # this the section where I handdle all the variables who can be change in games
  160. # or in script in simple this permit to handle variable who change a lots
  161. #==============================================================================
  162.  
  163.   #----------------------------------------------------------------------------
  164.   # ♦ Public Instance Variables {System}
  165.   #----------------------------------------------------------------------------
  166.     attr_accessor :ai_enable            # AI Activation flag
  167.   #----------------------------------------------------------------------------
  168.   # ♦ Public Instance Variables {Interactive AI::Dialogues}
  169.   #----------------------------------------------------------------------------
  170.     attr_accessor :dialogues             # Get text (in row)
  171.    
  172.     attr_accessor :greeting              # Greeting dialogues
  173.     attr_accessor :goodbye               # Good bye dialogues
  174.     attr_accessor :buy_goods_dialogues   # Buying dialogues
  175.     attr_accessor :sell_goods_dialogues  # Selling dialogues
  176.     attr_accessor :not_buying_dialogues  # not buying dialogues
  177.     attr_accessor :not_selling_dialogues # not selling dialogues
  178.   #----------------------------------------------------------------------------
  179.   # ♦ Public Instance Variables {Interactive AI::Interaction}
  180.   #----------------------------------------------------------------------------
  181.     attr_accessor :interaction              # make interactions accessible
  182.     attr_accessor :interaction_type         # define the type of interaction  
  183. #   attr_accessor :interaction_emotion_type # define the type of emotion
  184.     attr_accessor :ai_id                    # For ai personality
  185.   #----------------------------------------------------------------------------
  186.   # ♦ Public Instance Variables {Interactive AI::Graphics}
  187.   #----------------------------------------------------------------------------
  188.     attr_accessor :ai_sprite             # For the shopkeeper bust graphics
  189.     attr_accessor :index                 # for define the file index
  190.    
  191.  
  192.    
  193. #===============================================================================
  194. # => END : Game_AI {Public Instance Variables}
  195. #===============================================================================
  196.  
  197. #==============================================================================
  198. # ■ Game_AI {Core}
  199. #------------------------------------------------------------------------------
  200.  # This section is the place where I initialize everything's and permit to
  201.  # retrieve the whole AI_Personality[id] informations. It's also inits the
  202.  # firts actions made by the system.
  203.  # {exclude sprite configurations}
  204. #==============================================================================
  205.  
  206. #----------------------------------------------------------------------------
  207. # ○ new method: initialize
  208. #----------------------------------------------------------------------------
  209.   def initialize(ai_id)
  210.   # core data
  211.     @ai_id = ai_id
  212.     @ai_personality = AI_Personality[@ai_id]
  213.     @voice = @ai_personality[@ai_id]
  214.     @interaction_type = :normal
  215.   # @interaction_emotion_type = :neutral {obsolete}
  216.   #------------------------------------------------
  217.     check_message_types
  218.     retrieve_dialogues_and_voices
  219.     init_sprite
  220.    # init_flags {desactivate because not ready reactivate it if you are sure
  221.  # to know how to play with effects}
  222.   end
  223.  
  224. #----------------------------------------------------------------------------
  225. # ○ new method: retrieve_dialogues_and_voices
  226. #----------------------------------------------------------------------------
  227. def retrieve_dialogues_and_voices
  228.     @greeting = @ai_personality[:greeting]
  229.     @goodbye = @ai_personality[:goodbye]
  230.     @buy_goods_dialogues = @ai_personality[:buy_goods_dialogues]
  231.     @sell_goods_dialogues = @ai_personality[:sell_goods_dialogues]
  232.     @not_buying_dialogues = @ai_personality[:not_buying_dialogues]
  233.     @not_selling_dialogues = @ai_personality[:not_selling_dialogues]
  234. end
  235.  
  236. #----------------------------------------------------------------------------
  237. # ○ new method: check_message_types
  238. #----------------------------------------------------------------------------
  239. def check_message_types
  240.   case System[:message_system]
  241.   when :default
  242.     @dialogue_system = $game_message
  243.   when :nio_ai_dialogues
  244.     @dialogue_system = $game_dialogues
  245.   end
  246. end
  247.  
  248. #----------------------------------------------------------------------------
  249. # ○ new method: init_flags
  250. #----------------------------------------------------------------------------
  251.  def init_flags
  252.   if System[:effects_enable]
  253.   @flag_type = :entering
  254.   @effect_flag = true
  255. end
  256.   @interaction_type = :greeting_action
  257.   interaction
  258. end
  259. #===============================================================================
  260. # => END : Game_AI {Core}
  261. #===============================================================================
  262.  
  263. #==============================================================================
  264. # ■ Game_AI {Core::interactions}
  265. #------------------------------------------------------------------------------
  266.  # Cette section sert pour la configuration qui dicte comment votre IA reagit
  267.  # a vos actions. Il est generalement dicter par
  268.  # $game_personalities[ai_id].interaction_type = :key
  269.  # et activer par
  270.  # $game_personalities[ai_id].interaction
  271. #==============================================================================
  272.  
  273. #----------------------------------------------------------------------------
  274. # ○ new method: interaction
  275. #----------------------------------------------------------------------------
  276.   def interaction
  277.    case @interaction_type
  278.    when :greeting_action
  279.     greeting_reactions
  280.    when :try2
  281.       @index = 1
  282.       $game_message.add(@buy_goods_dialogues)  #@dialogue.call_dialogues("stuff")
  283.      
  284.    when :try3
  285.     @index = 2
  286.   when :over
  287.     @index = 2
  288.     $game_message.add(@greeting )
  289.     $game_message.new_page  
  290.     $game_message.add("stuff")  
  291.     call_voice("rawr",100,100)
  292.   end
  293. end
  294.  
  295. #----------------------------------------------------------------------------
  296. # ★ preset methods : interaction_actions {for organisation purpose}
  297. #----------------------------------------------------------------------------
  298. def greeting_reactions
  299.   @index =  2
  300.   @dialogue_system.add(@greeting)
  301.  # call_voice(@voice[:greeting_voice],100,100)
  302. end
  303. #===============================================================================
  304. # => END : Game_AI {Core::Interactions}
  305. #===============================================================================
  306.  
  307. #==============================================================================
  308. # ■ Game_AI {Sprite}
  309. #------------------------------------------------------------------------------
  310. # This section serve for Sprite initialization and configuration purpose
  311. #==============================================================================
  312.  
  313. #----------------------------------------------------------------------------
  314. # ○ new method: init_sprite
  315. #----------------------------------------------------------------------------
  316. def init_sprite
  317. # retrieve sprite data from AI_Personality
  318.   @ai_sprite = @ai_personality[:ai_sprite]
  319.   @index = 0
  320. # Initialize Sprite
  321.   @sprite = Sprite.new
  322.   @sprite.bitmap = Cache.system(@ai_sprite + @index.to_s)
  323.   @sprite.x =  @ai_personality[:ai_posx]
  324.   @sprite.y =  @ai_personality[:ai_posy]
  325.   @sprite.z =  @ai_personality[:ai_posz]
  326.   @sprite.opacity = 250
  327.  # @sprite.ox = Graphics.width / 2
  328.  # @sprite.oy = Graphics.height / 2
  329.  
  330. # create effects flags
  331.   @effect_flag = false
  332.   @effect_type = :nil
  333.   @flag_type = :nil
  334.   @invert_effect = @ai_personality[:invert_effect]
  335. # create_effects datas
  336.   @hori_left = (@sprite.ox - @sprite.x - 100)
  337.   @hori_right = (@sprite.ox + @sprite.x + 100)
  338.   @verti_up = (@sprite.oy - @sprite.y - 100)
  339. #  @verti_down = (@sprite.oy  + 100)
  340.   @time_value = 0
  341.   @fadein_value = 2
  342.   @fadeout_value = 2
  343. end
  344. #----------------------------------------------------------------------------
  345. # ○ new method: refresh
  346. #----------------------------------------------------------------------------
  347.  def refresh
  348.     @index = 0
  349.   end
  350. #----------------------------------------------------------------------------
  351. # ○ new method: terminate_sprite
  352. #----------------------------------------------------------------------------
  353.   def terminate_sprite
  354.     @sprite.dispose
  355.     @sprite.bitmap.dispose
  356.   end
  357. #----------------------------------------------------------------------------
  358. # ○ new method: update_sprite
  359. #----------------------------------------------------------------------------
  360. def update_sprite
  361.    @sprite.bitmap = Cache.system(@ai_sprite + @index.to_s )
  362.    update_effect if @effect_flag
  363.    refresh if !@dialogue_system.busy?
  364.   end
  365.  
  366. #===============================================================================
  367. # => END : Game_AI {Sprite}
  368. #===============================================================================
  369.  
  370. #==============================================================================
  371. # ■ Game_AI {Sprite::Effects}
  372. #------------------------------------------------------------------------------
  373.  
  374. #==============================================================================
  375.  
  376. #~ #----------------------------------------------------------------------------
  377. #~ # ○ new method: update_effect
  378. #----------------------------------------------------------------------------
  379.   def update_effect
  380.    case @flag_type
  381.     when :entering
  382.       @effect_type = @ai_personality[:entering_effect_type]
  383.       init_entering_effects
  384.     when :quitting
  385.       @effect_type = @ai_personality[:quitting_effect_type]
  386.       init_quitting_effects
  387.     end
  388.   end
  389.  
  390.   def execute_dummy
  391.     @final_pos = @ai_personality[:ai_posx]
  392.    
  393.    
  394.     while @time_value <= 200
  395.     #if @time_value < 10
  396.       @sprite.x += 2
  397.       @time_value += 2
  398.      break if  @sprite.x >= @final_pos + 70
  399.     end
  400.     #elsif @time_value > 10
  401.   # @effect_flag = false
  402.      # @sprite.x = @final_pos
  403.    #   @effect_flag = false
  404.   end
  405. #----------------------------------------------------------------------------
  406. # ○ new method: init_entering_effects
  407. #----------------------------------------------------------------------------
  408. def init_entering_effects
  409.    execute_inhori_slide  if @effect_type == :hori_slide
  410.    execute_inverti_slide if @effect_type == :verti_slide
  411.    execute_fadein        if @effect_type == :fadein
  412.  end
  413.  
  414. #----------------------------------------------------------------------------
  415. # ○ new method: init_quitting_effects
  416. #----------------------------------------------------------------------------
  417.  def init_quitting_effects
  418.   execute_outverti_slide if @effect_type == :hori_slide
  419.   execute_ouverti_slide  if @effect_type == :verti_slide
  420.   execute_fadeout        if @effect_type == :fadeout
  421. end
  422.  
  423. #----------------------------------------------------------------------------
  424. # ○ new method: execute_inhori_slide {in horizontal slide effect}
  425. #----------------------------------------------------------------------------
  426. def execute_inhori_slide(time_value,hori_left,hori_right)
  427.   @time_value = 0
  428.   @final_pos = @ai_personality[:ai_posx]
  429.   if @time_value > 250
  430.     @sprite.x += 2
  431.   else
  432.     @sprite.x = @final_pos
  433.   end
  434.   @effect_flag = false
  435. end
  436.  
  437. #----------------------------------------------------------------------------
  438. # ○ new method: execute_inverti_slide {in vertical slide effect}
  439. #----------------------------------------------------------------------------
  440. def  execute_inverti_slide#(time_value,verti_down,verti_up)
  441.    @final_pos = @ai_personality[:ai_posy]
  442. #   @sprite.y = @verti_down
  443.    
  444.     while @time_value <= 200
  445.     #if @time_value < 10
  446.       @sprite.y -= 2
  447.       @time_value += 2
  448.      break if  @sprite.y <= @final_pos + 70
  449.      
  450.     end
  451.   @effect_flag = false if  @sprite.y == @final_pos
  452. end
  453.  
  454. #----------------------------------------------------------------------------
  455. # ○ new method: execute_fadein {fadein effect}
  456. #----------------------------------------------------------------------------
  457. def execute_fadein(time_value, fadein_value)
  458.   @time_value = 0
  459.   while @time_value < 250
  460.     @time_value += 2
  461.     @sprite.opacity += @fadein_value
  462.     break if @sprite.opacity >= 250 || @time_value >= 250
  463.   end
  464.   @effect_flag = false
  465. end
  466.  
  467. #----------------------------------------------------------------------------
  468. # ○ new method: execute_outhori_slide {out horizontal slide effect}
  469. #----------------------------------------------------------------------------
  470. def execute_outhori_slide(time_value,hori_left,hori_right)
  471.   @time_value = 0
  472.   if !invert_effect
  473.     while @time_value < 250
  474.       @time_value += 2
  475.       @sprite.ox -= 2
  476.       break if @sprite.x >= @hori_left || @time_value >= 250
  477.     end
  478.   else
  479.     while @time_value < 250
  480.       @time_value += 2
  481.       @sprite.ox += 2
  482.       break if @sprite.x >= @hori_right || @time_value >= 250
  483.     end
  484.   end
  485.   @effect_flag = false
  486. end
  487.  
  488. #----------------------------------------------------------------------------
  489. # ○ new method: execute_outverti_slide {out vertical slide effect}
  490. #----------------------------------------------------------------------------
  491. def execute_outverti_slide(time_value,verti_down,verti_up)
  492.   @time_value = 0
  493.   if !invert_effect
  494.     while @time_value < 250
  495.       @time_value += 2
  496.       @sprite.oy -= 2
  497.       break if @sprite.y >= @verti_down || @time_value >= 250
  498.     end
  499.   else
  500.     while @time_value < 250
  501.       @time_value += 2
  502.       @sprite.oy += 2
  503.       break if @sprite.y >= @verti_up || @time_value >= 250
  504.     end
  505.   end
  506.   @effect_flag = false
  507. end
  508.  
  509. #----------------------------------------------------------------------------
  510. # ○ new method: execute_fadeout {fadeout effect}
  511. #----------------------------------------------------------------------------
  512. def execute_fadeout(time_value, fadeout_value)
  513.   @time_value = 0
  514.   while @time_value < 250
  515.     @time_value += 2
  516.     @sprite.opacity -= @fadeout_value
  517.     break if @sprite.opacity <= 0 || @time_value >= 250
  518.   end
  519.   @effect_flag = false
  520. end
  521. #===============================================================================
  522. # => END : Game_AI {Sprite::Effects}
  523. #===============================================================================
  524.  
  525. #==============================================================================
  526. # ■ Game_AI {Voice}
  527. #------------------------------------------------------------------------------
  528. # This section serve for AI Voice SE purpose
  529. # use call_voice("filename",volume,pitch)
  530. #==============================================================================
  531.  
  532. #----------------------------------------------------------------------------
  533. # ○ new method: pathfile
  534. #----------------------------------------------------------------------------
  535. def pathfile
  536.   @voice_folder = System[:voice_folder]
  537.   pathfile = @voice_folder + "/"
  538. end
  539.  
  540. #----------------------------------------------------------------------------
  541. # ○ new method: call_voice
  542. #----------------------------------------------------------------------------
  543. def call_voice(voice_index,volume,pitch)
  544. RPG::SE.new(pathfile + voice_index ,volume,pitch).play
  545. end
  546. #===============================================================================
  547. # => END : Game_AI {Voice}
  548. #===============================================================================
  549.  
  550. end
  551. #===============================================================================
  552. # => END : Game_AI
  553. #===============================================================================
  554.  
  555. #==============================================================================
  556. # ■ Module : Cache
  557. #------------------------------------------------------------------------------
  558. #  This module loads graphics, creates bitmap objects, and retains them.
  559. # To speed up load times and conserve memory, this module holds the
  560. # created bitmap object in the internal hash, allowing the program to
  561. # return preexisting objects when the same bitmap is requested again.
  562. #==============================================================================
  563.  module Cache
  564. #----------------------------------------------------------------------------
  565. # ○ new method: pathfolder
  566. #----------------------------------------------------------------------------
  567.   def self.pathfolder
  568.     return Emoji::AI::System[:ai_graphics_folder]
  569.   end
  570. #----------------------------------------------------------------------------
  571. # ○ new method: ai_graphics
  572. #----------------------------------------------------------------------------
  573.   def self.ai_graphics(filename)
  574.     load_bitmap(pathfolder,filename)
  575.   end
  576.  
  577.   end
  578. #===============================================================================
  579. # => END : Module Cache
  580. #===============================================================================
  581.  
  582. #==============================================================================
  583. # ■ DataManager
  584. #------------------------------------------------------------------------------
  585. #  This module manages the database and game objects. Almost all of the
  586. # global variables used by the game are initialized by this module.
  587. #==============================================================================
  588. module DataManager
  589.  
  590. #----------------------------------------------------------------------------
  591. # ★ FalseClass : alias
  592. #----------------------------------------------------------------------------
  593.   class << self
  594.      alias nio_ai_object create_game_objects
  595.      alias nio_ai_save make_save_contents
  596.      alias nio_ai_extracts extract_save_contents
  597.  
  598.   end
  599.  
  600. #----------------------------------------------------------------------------
  601. # ● alias method: create_game_objects
  602. #----------------------------------------------------------------------------  
  603.  def self.create_game_objects
  604.   nio_ai_object
  605.     $game_personalities = Game_Personalities.new
  606.     $game_dialogues     = Game_Dialogues.new
  607.   end
  608.  
  609. #----------------------------------------------------------------------------
  610. # ● alias method: make_save_contents
  611. #----------------------------------------------------------------------------
  612.   def self.make_save_contents
  613.     contents = nio_ai_save
  614.     contents[:personalities]        = $game_personalities
  615.     contents[:dialogues]            = $game_dialogues
  616.     contents
  617.   end
  618. #----------------------------------------------------------------------------
  619. # ● alias method: extract_save_contents
  620. #----------------------------------------------------------------------------
  621.   def self.extract_save_contents(contents)
  622.     nio_ai_extracts(contents)
  623.     $game_personalities       = contents[:personalities]
  624.     $game_dialogues           = contents[:dialogues]
  625.   end
  626. end
  627. #===============================================================================
  628. # => END : Module DataManager
  629. #===============================================================================
  630.  
  631. #==============================================================================
  632. # ■ Game_Personalities
  633. #------------------------------------------------------------------------------
  634. #  This class handles Personality_id. It's a wrapper for the built-in class
  635. #  "Array." The instance of this class is referenced by $game_Personalities.
  636. #==============================================================================
  637. class Game_Personalities
  638.  
  639.   #----------------------------------------------------------------------------
  640.   # ○ new method: initialize
  641.   #----------------------------------------------------------------------------
  642.   def initialize
  643.     @personality =[]
  644.   end
  645.  
  646.   #----------------------------------------------------------------------------
  647.   # ○ new method: []
  648.   #----------------------------------------------------------------------------
  649.   def [](ai_id)
  650.      if !Emoji::AI::AI_Personality[ai_id]
  651.        msgbox("ERROR : please assign a valid ID")
  652.        exit
  653.      else
  654.     @personality[ai_id] ||= Game_AI.new(ai_id)
  655.   end
  656. end
  657.  
  658. end
  659. #===============================================================================
  660. # => END : Game_Personalities
  661. #===============================================================================
  662.  
  663. #==============================================================================
  664. # ■ Game_Interpreter
  665. #------------------------------------------------------------------------------
  666. #  An interpreter for executing event commands. This class is used within the
  667. # Game_Map, Game_Troop, and Game_Event classes. This snipset add executing
  668. # for Game_Personalities and Game_AI classes event processing.
  669. #==============================================================================
  670. class Game_Interpreter
  671.  
  672.   #----------------------------------------------------------------------------
  673.   # ♦ Public Instance Variables {System}
  674.   #----------------------------------------------------------------------------
  675.    attr_accessor :ai_shop_id
  676.  
  677. #----------------------------------------------------------------------------
  678. # ● alias method: initialize
  679. #----------------------------------------------------------------------------
  680.   alias nio_interp initialize
  681.   def initialize(depth = 0)
  682.     nio_interp
  683.     @ai_shop_id = 0
  684.   end
  685.  
  686. #----------------------------------------------------------------------------
  687. # ○ new method: ai_scene
  688. #----------------------------------------------------------------------------
  689.   def ai_scene(scenes,personality_type)
  690.     SceneManager.call(scenes)
  691.     SceneManager.scene.prepare(personality_type)
  692.   end
  693.  
  694.  
  695. #----------------------------------------------------------------------------
  696. # ● overwrite method: command_302 { desactivate }
  697. #----------------------------------------------------------------------------  
  698. #  def command_302
  699. #    return if $game_party.in_battle
  700. #    goods = [@params]
  701. #    while next_event_code == 605
  702. #      @index += 1
  703. #      goods.push(@list[@index].parameters)
  704. #    end
  705.    
  706. #    SceneManager.call(Scene_Shop)
  707. #    SceneManager.scene.prepare(goods, @params[4], @ai_shop_id)
  708. #    Fiber.yield
  709. #  end
  710. end
  711. #===============================================================================
  712. # => END : Game_interpreter
  713. #===============================================================================
  714.  
  715. #==============================================================================
  716. # ■ Scene_Foo {structural exemple}
  717. #------------------------------------------------------------------------------
  718. #  This a exemple of How structure the script for the
  719. #  Prepare, update, terminate method
  720. #==============================================================================
  721. class Scene_Foo < Scene_Base
  722.  
  723.   def prepare(ai_id)
  724.     @ai_id = ai_id
  725.   end
  726.  
  727.   def start
  728.     #you_stuff
  729.     create_message_system
  730.     @var_name = $game_personalities[@ai_id]
  731.     a_calling_method
  732.   end
  733.  
  734.   def a_calling_method
  735.     @var_name.personality_type = :greeting # will set wich kind of reactions
  736.     @var_name.interaction # will call interactions
  737.  
  738.   def create_message_system
  739.     @message = Window_Message.new
  740.   end
  741.  
  742.   def update
  743.     super
  744.     @var_name.update_sprite
  745.   end
  746.  
  747.   def terminate
  748.     super
  749.     @var_name.terminate_sprite
  750.   end
  751. end
  752. #===============================================================================
  753. # => END : Scene_Foo
  754. #===============================================================================
  755.  
  756. #==============================================================================
  757. # END OF SCRIPT
  758. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement