Advertisement
nio_kasgami

Nio Kasgami Engine Ace "Basic AI module"

May 28th, 2015
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.28 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Nio Kasgami Engine Ace "Basic AI Module"
  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. #
  9. #==============================================================================
  10.  
  11. #==============================================================================
  12. # Introduction
  13. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  14. # Ce script est un outil de develloppeur pour permettre le develloppement de IA
  15. # pour les scenes. Cependant, il ne s'agit pas pour les system de combats,
  16. # mais plutot pour l'aspect interaction du jeux. B.A.M a pour but de simuler
  17. # une interaction dynamique dans les scene ou le dialogue est de mise. Pour
  18. # faire plus simple, il permet d'implementer des émotions ainsi que des
  19. # personalitées a vos vendeur, forgerons, gérant de mission, ect...
  20. # Les possibilitées sont illimitées et vont selon votre imagination.
  21. # Cela require quelque petite connaissance en rgss3, mais le module est conçu
  22. # pour vous permetre de batir vos IA avec des personalitée diversifier sans
  23. # trop de difficulté.
  24. # Ce script est fait pour vous simplifier la vie!
  25. #==============================================================================
  26.  
  27. #==============================================================================
  28. # How to use
  29. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  30. # TO NORMAL USER :
  31. # "Veuillez prendre note si vous n'avez pas mes add-ons commme
  32. # NKEA-"Dynamic ShopKeeper" ce script ne vous sert strictement a rien sauf si
  33. # vous avez intentions d'utiliser le module pour batir votre IA."
  34. #------------------------------------------------------------------------------
  35. #------------------------------------------------------------------------------
  36. # TO SCRIPTER USER:
  37. # "Merci d'avoir décidé d'utiliser Basic AI Module ou B.A.M pour l'implementer
  38. # dans votre script!
  39. #
  40. # Les première chose qu'il faut s'avoir est que le script ne fonctionnera pas
  41. # tant que vous ne aurez pas implementer certaine methode dans votre propre
  42. # script.
  43.  
  44. # La methode primordial a implementer au commencement est:
  45. # -> AI_Base.pre_check_setup
  46.  
  47. # Apres avoir implementer cette methode le personnage apparaitra comme il se
  48. # doit et fera la premiere reaction qui est le "greeting". Cependant, l'IA
  49. # ne reagira pas tant que vous ne lui aurez pas dicter ou programmer ses actions
  50. # ne vous inquietez pas il déja la plupart des code implementer pour les
  51. # reactions il ne vous reste qu'a les activer en appellant cette method
  52. # -> AI_Base.interaction
  53.  
  54. # Cependant, il faut avant tout avant d'executer de la commande de s'assurer
  55. # que cette commande soit integrer :
  56. # -> AI_Base.interaction_type = :key
  57. # Sinon le personnage ne reagira pas
  58.  
  59. # Et voici quelque example de ":key" déja conçu dans le systeme:
  60. # -> AI_Base.interaction_type = :buying_good
  61. # -> AI_Base.interaction_type = :goodbye
  62.  
  63. # B.A.M est conçut pour faire une mise a jour tout de suite apres que vous
  64. # avez appuyer sur la touche "Entrer" ou attendue 10 frames pour revenir a
  65. # l'expression "neutral" SAUF! si vous avez l'ad-ons NKEA-"Mood AI" dans votre
  66. # éditeur de script.
  67. #------------------------------------------------------------------------------
  68. # Les "key" que vous voyez ne sont la que pour reference n'hésitez pas a
  69. # les modifier, les retirer ou en ajouter des supplementaires!Tout le script
  70. # est structurer pour vous aider a bien modifier le script pour vos besoins!
  71. #==============================================================================
  72.  
  73. #==============================================================================
  74. #
  75. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  76. #
  77. module Nio
  78.   module IA_Setup
  79. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  80. # SYSTEM
  81. # -----------------------------------------------------------------------------
  82. # This section serve for configure the basic option of the script
  83. #==============================================================================
  84.     SYSTEM ={
  85.     :ia_enable => true
  86.     }
  87.    
  88.    
  89.    
  90.     AIV_Default ={
  91.     :vendor_graphics => "",
  92.     :greeting => "",
  93.     :good_bye => "",
  94.     :buy_goods_dialogues => "what you want to buy?",
  95.     :sell_goods_dialogues => "",
  96.    
  97.     :not_buying_dialogues => "",
  98.     :not_selling_dialogues => "",
  99.    
  100.     #not yet
  101.     :haggle_goods_dialogues => "",
  102.     :suceed_haggles_dialogues => "",
  103.     :fail_haggles_dialogues => "",
  104.    
  105.    
  106.    
  107.    
  108.     #not yet implemented
  109.     :good_reputation_greeting => "",
  110.     :bad_reputation_greeting => "",
  111.     :kick_out_shop_dialogues => "",
  112.     :patience => 100
  113.    
  114.     }
  115.    
  116.    
  117.     AI_Personality ||= { } # do not touch!
  118.    
  119.     AI_Personality[1] ={
  120.     :buy_goods_dialogues => "text"
  121.     }
  122.    
  123.      NIV ={
  124.      :enter_shop_dialogues => "",
  125.      :buy_goods_dialogues => "",
  126.      :sell_goods_dialogues => "",
  127.      :quit_shops_dialogues => ""
  128.      }
  129.      
  130.   end
  131. end
  132.  
  133.  
  134. module AI_Base
  135.   include Nio::IA_Setup
  136.  
  137. #==============================================================================
  138. # ■ AI_Base {Public Instance Variables}
  139. #------------------------------------------------------------------------------
  140. # this the section where I handdle all the variables who can be change in games
  141. # or in script in simple this permit to handle variable who change a lots
  142. #==============================================================================
  143.  
  144.   class << self
  145.   #----------------------------------------------------------------------------
  146.   # ♦ Public Instance Variables {System}
  147.   #----------------------------------------------------------------------------
  148.     attr_accessor :AI_enable             # AI Activation flag
  149.   #----------------------------------------------------------------------------
  150.   # ♦ Public Instance Variables {Interactive AI::Dialogues}
  151.   #----------------------------------------------------------------------------
  152.     attr_accessor :dialogues             # Get text (in row)
  153.    
  154.     attr_accessor :greeting              # Greeting dialogues
  155.     attr_accessor :goodbye               # Good bye dialogues
  156.     attr_accessor :buy_goods_dialogues   # Buying dialogues
  157.     attr_accessor :sell_goods_dialogues  # Selling dialogues
  158.     attr_accessor :not_buying_dialogues  # not buying dialogues
  159.     attr_accessor :not_selling_dialogues # not selling dialogues
  160.   #----------------------------------------------------------------------------
  161.   # ♦ Public Instance Variables {Interactive AI::Interaction}
  162.   #----------------------------------------------------------------------------
  163.     attr_accessor :interaction_type         # define the type of interaction  
  164.     attr_accessor :interaction_emotion_type # define the type of emotion
  165.    
  166.   #----------------------------------------------------------------------------
  167.   # ♦ Public Instance Variables {Interactive AI::Graphics}
  168.   #----------------------------------------------------------------------------
  169.     attr_accessor :vendor_graphics       # For the shopkeeper bust graphics
  170.    
  171.     attr_accessor :index                 # for define the file index
  172.    
  173.     attr_accessor :ai_id
  174.    end
  175. #===============================================================================
  176. # => END : AI_Base {Public Instance Variables}
  177. #===============================================================================
  178.  
  179. #==============================================================================
  180. # ■ AI_Base {Interactive AI::Dialogues}
  181. #------------------------------------------------------------------------------
  182. # This Section handle all the Dialogues of the scripts I building them into
  183. # method for permit to be easily change in game when you not use AI_Personality
  184. # how to change in game via script call
  185. # Vendor_IA.method_name = "string"
  186. #===============================================================================
  187.  
  188. # def self.ai_id
  189.   #return @ai_id
  190. #end
  191.  
  192.  def self.as_personality?
  193.   ai_id > 0  #and ai_id <= @ai_personality.size
  194. end
  195. #----------------------------------------------------------------------------
  196. # ○ new method: default_AI
  197. #----------------------------------------------------------------------------
  198. def self.default_AI
  199.  return AIV_Default
  200. end
  201.  
  202. #----------------------------------------------------------------------------
  203. # ○ new method: vendor_graphics
  204. #----------------------------------------------------------------------------
  205.  def self.vendor_graphics
  206.     @vendor_graphics = default_AI[:vendor_graphics]
  207. end
  208.  
  209. #----------------------------------------------------------------------------
  210. # ○ new method: greeting
  211. #----------------------------------------------------------------------------  
  212.   def self.greeting
  213.     @greeting = default_AI[:greeting_dialogues]
  214.   end
  215. #----------------------------------------------------------------------------
  216. # ○ new method: goodbye
  217. #----------------------------------------------------------------------------    
  218.   def self.goodbye
  219.     @goodbye = default_AI[:goodbye_dialogues]
  220.   end
  221. #----------------------------------------------------------------------------
  222. # ○ new method: buy_goods_dialogues
  223. #----------------------------------------------------------------------------  
  224.   def self.buy_goods_dialogues
  225.    # if !as_personality?
  226.   #  @buy_goods_dialogues = default_AI[:buy_goods_dialogues]
  227.  # else
  228.     @buy_goods_dialogues = AI_Personality[:buy_goods_dialogues]
  229. #  end
  230. end
  231.  
  232. #----------------------------------------------------------------------------
  233. # ○ new method: sell_goods_dialogues
  234. #----------------------------------------------------------------------------      
  235.   def self.sell_goods_dialogues
  236.     @sell_goods_dialogues = default_AI[:sell_goods_dialogues]
  237.   end
  238. #----------------------------------------------------------------------------
  239. # ○ new method: not_buying_dialogues
  240. #----------------------------------------------------------------------------    
  241.   def self.not_buying_dialogues
  242.     @not_buying_dialogues = default_AI[:not_buying_dialogues]
  243.   end
  244. #----------------------------------------------------------------------------
  245. # ○ new method: not_selling_dialogues
  246. #----------------------------------------------------------------------------    
  247.   def self.not_selling_dialogues
  248.     @not_selling_dialogues = default_AI[:not_selling_dialogues]
  249.   end
  250.  
  251.  
  252. #===============================================================================
  253. # => END : AI_Base {Interactive AI::Dialogues}
  254. #===============================================================================
  255.  
  256. #==============================================================================
  257. # ■ AI_Base {AI::Initialization}
  258. #------------------------------------------------------------------------------
  259. # This section handle the initialization, the update and the dispose of the
  260. # script. it's mostly the important method you call in your own script for make
  261. # them enable in your system.
  262. #===============================================================================
  263.  
  264.    def self.pre_check_setup
  265.     setup
  266. #    ia_active
  267.     update_AI until scene_changing?
  268.     terminate_AI
  269.   end
  270.  
  271.   def self.scene_changing?
  272.     SceneManager.scene != self
  273.   end
  274.  
  275.    
  276.    
  277.   def self.setup
  278.    @ai_id = ai_id
  279.    @ai_personality = AI_Personality[@ai_id]
  280.   end
  281.  
  282.   def self.update_AI
  283.     interaction
  284.     interaction_emotion
  285.     refresh_dialogues
  286.     refresh_interaction
  287.   end
  288.  
  289.  
  290.   def self.terminate_AI
  291.   end
  292.  
  293.    def self.ia_is_active?
  294.      SYSTEM[:ia_enable] == true
  295.   end
  296.  
  297.  
  298.  
  299.  
  300. #===============================================================================
  301. # => END : AI_Base {AI::Initialization}
  302. #===============================================================================
  303.    
  304. #==============================================================================
  305. # ■ AI_Base {Interactive AI::Graphics}
  306. #------------------------------------------------------------------------------
  307. def self.create_vendor
  308.     @vendor = Sprite.new
  309.     @vendor.bitmap = Cache.system(@vendor_graphics + @index.to_s)
  310.   end
  311.    
  312.  
  313.    
  314.   def self.initialize_non_interactive_vendor
  315.     @text = []
  316.     @vendor_graphics = ""
  317.     @index = 0
  318.   end
  319.    def self.initialize_non_interactive_vendor
  320.    end
  321. ###############################################################################
  322. #temporary header
  323. ###############################################################################
  324. #==============================================================================
  325. # ■ AI_Base {Interactive AI::Interaction}
  326. #------------------------------------------------------------------------------
  327. #==============================================================================
  328.  
  329. #----------------------------------------------------------------------------
  330. # ○ new method: interaction_type
  331. #----------------------------------------------------------------------------    
  332.  def self.interaction_type
  333.    return @interaction_type
  334.  end
  335. #----------------------------------------------------------------------------
  336. # ○ new method: interaction_emotion_type
  337. #----------------------------------------------------------------------------    
  338.  def self.interaction_emotion_type
  339.    return @interaction_emotion_type
  340.  end
  341.  
  342. ###############################################################################
  343. # EDITABLE_SECTION
  344. #-----------------------------------------------------------------------------
  345.   def self.interaction
  346.     case interaction_type
  347.     when :buying_shop
  348.       call_buying_reaction
  349.       end
  350.   end
  351.  
  352.   def self.interaction_emotion
  353.     case interaction_emotion_type
  354.     when :neutral
  355.       @index = 0
  356.     when :irritated
  357.       @index = 1
  358.       when :happy
  359.        @index = 2
  360.      end
  361.    end
  362.    
  363.    def self.call_buying_reaction
  364.      interaction_emotion_type = :happy
  365.     # call_dialogues(buy_goods_dialogues)
  366.      msgbox_p(buy_goods_dialogues)
  367.     # refresh if Input.trigger?(:C)
  368.   end
  369. ################################################################################
  370.  
  371.      
  372.  
  373. #===============================================================================
  374. # => END : AI_Base {AI::Interaction}
  375. #===============================================================================
  376.  
  377. #==============================================================================
  378. # ■ AI_Base {Interactive AI::AI_Personality}
  379. #------------------------------------------------------------------------------
  380.  
  381.  
  382.  
  383. #===============================================================================
  384. # => END : AI_Base {Interactive AI::AI_Personality}
  385. #===============================================================================
  386.  
  387.  
  388.  
  389. end
  390.  
  391. #===============================================================================
  392. # => END : AI_Base {Interactive AI::Haggle}
  393. #===============================================================================
  394.  
  395. #==============================================================================
  396. # => END: Module Vendor_AI
  397. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement