• Anmelden

Anemone

Rekrut

  • »Anemone« ist der Autor dieses Themas

Motto: Was zählt ist nicht das eigene Leben, sondern es aufs Spiel zusetzen.

  • Nachricht senden

1

Donnerstag, 15. Oktober 2009, 23:21

Meine KI muss mal gepimpt werden >>

Infos:
das kampfsystem is ein sideview system indem man herum laufen kann, halt n Hybrid Kampfsystem im style von Tales of Phantasia und co.
Die aktionen in event.action werden ausgeführt, das wichtige sind hia bloss 'Move' oder 'Run' (bewegt sich automatisch wenn dieser befehl eingesetzt wird)
die variable event.action_count wird ausserhalb -1 genommen bis sie 0 erreicht
Die variable even.brain_action is nur zum zwischenspeichern, sie wird ned ausgeführt, nur event.action hat auswirkungen
@ran_coor ist 160.0 und bestimmt einen bestimten reactionsbereich um den event
attack?(event, event.frames['Attack0'].space) checkt ob sich im angriffs breich von event mit einer reichweite von event.frames['Attack0'].space ein ziel befindet (boolean)
@troop= array mit den gegner daten
@actors= array mit den team daten
event.face_toward_target= zum ziel drehen
event.face_away_target= vom ziel wegdrehen
event.target_index= index of target
event.actor?= gibt true falls event ein team mitglied ist
event.auto_target= sucht das nächst beste ziel zum angreifen

Problem:
Sobald ich einen Kämpfer über diese KI laufen lasse läuft dieser vor seien ziel immer stückchenweise weg bis gegen ne wand wo er dann immer gegenläuft.
Er soll aber kämpfen und ned weglaufen :/
damn kann mia wer helfen?

Braucht ihr mehr informationen? dann fragt bitte einfach nach ^^ ty
Hier der code:
Spoiler

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  #===============================
  # KI 
  #   for Actors and Enemies
  #===============================
  def ki(event)
    #Check aviability of events target
    tindex=event.target_index
    atc_cache=attack?(event, event.frames['Attack0'].space)
    if event.actor?
      tchar=@troop[tindex]
    else
      tchar=@actors[tindex]
    end
    if tchar.nil? or tchar.dead?
      return event.auto_index
    end
    if event.dead?
      event.action='Dead'
      event.combo=0
      return
    end
    if event.combo >= event.max_combo
      event.action='Break'
      event.combo=0
      event.need_refresh=true
      return
    end
    if event.action == 'Defend'
      event.combo=0
      if event.action_count <= 0
        event.action='Stand'
        event.need_refresh=true
      else
        event.action='Defend'
      end
      return
    end
    if event.action == 'Break'
      event.combo=0
      if event.action_count <= 0
        event.action_count=0
        event.action='Stand'
        event.brain_action='none'
      end
      return
    end
    action_type=0
    if event.brain_action != 'none'
      case event.brain_action
      when 'walk toward', 'walk away'
        unless atc_cache.empty?
          event.brain_action='attack'
          return
        end
        if (tchar.x-event.x).abs >= @run_coor
          event.action='Move'
        else
          event.action='Run'
        end
        if event.action_count <= 0
          if event.attack_rate >= rand(100)
            if rand(2)==0
              event.action_count = 0
            else
              event.action_count=10*(rand(2)+1)
            end
          else
            event.action_count=20*(rand(2)+1)
          end
          event.brain_action='wait'
          return
        end
      when 'attack'
        if event.attack_rate >= rand(100)
          if atc_cache.empty?
            # No targets in Space
            event.action_count = RUN_TIME*2
            event.face_toward_target
            # Running or Moving?
            if (tchar.x-event.x).abs >= @run_coor
              event.action='Move'
            else
              event.action='Run'
            end
            event.brain_action = 'walk toward'
            return
          else
            # Prepare for attack
            action_type=1
          end
        else
            event.action_count = RUN_TIME
            event.face_away_target
            # Running or Moving?
            if (tchar.x-event.x).abs >= @run_coor
              event.action='Move'
            else
              event.action='Run'
            end
          event.brain_action = 'walk away'
          return
        end
      when 'skill'
        if event.attack_rate >= rand(100)
          if atc_cache.empty?
            # No targets in Space
            event.action_count = RUN_TIME*2
            event.face_toward_target
            # Running or Moving?
            if (tchar.x-event.x).abs >= @run_coor
              event.action='Move'
            else
              event.action='Run'
            end
            event.brain_action = 'walk toward'
            return
          else
            # Prepare for skill
            action_type=2
          end
        else
            event.action_count = RUN_TIME
            event.face_away_target
            # Running or Moving?
            if (tchar.x-event.x).abs >= @run_coor
              event.action='Move'
            else
              event.action='Run'
            end
          event.brain_action = 'walk away'
          return
        end
      when 'wait'
        event.face_toward_target
        event.action='Stand'
        if event.action_count <= 0
          event.brain_action='none'
        end
        return
      else
        return event.brain_action='none'
      end
    else 
      #if event.brain_action == 'none'
      if (tchar.x-event.x).abs >= @run_coor
        case rand(10)
        when 0
          method=0
        when 1,2,3
          method=1
        else
          method=2
        end
      else
        case rand(10)
        when 0,7
          method=0
        when 1,2,3,4,5,6
          method=2
        else
          method=3
        end
      end
      case method
      when 0
        event.brain_action = 'skill'
      when 1
        event.brain_action = 'walk away'
        event.action_count = RUN_TIME*3
        event.face_away_target
      when 2
        event.brain_action = 'walk toward'
        event.action_count = RUN_TIME*3
        event.face_toward_target
      end
    end
    #End KI-Explorer
    #KI-Execute
    case action_type
    when 1 #Attack
      event.face_toward_target
      if rand(5) >= 3
        #Switch to skill
        return event.brain_action='skill'
      end
      # Use normal attack with equipped weapon
      actions=['Attack','AttackUp','AttackDown','AttackSide']
      event.action=actions[rand(actions.size)]+event.combo.to_s
      space=event.frames[event.action].space
      event.combo+=1
      event.brain_action='attack'
      if event.combo.between? event.max_combo/2, event.max_combo and
        event.attack_rate < rand(100)
        event.brain_action='walk away'
      end
    when 2 #Skill
      # Use skill
      event.brain_action='none' #Not now aviable, build is in progress
    end
    #End KI-Execute
    #KI-Result
    #End KI-Result
  end
zum Lesen den Text mit der Maus markieren

2

Samstag, 17. Oktober 2009, 00:18

Meine Vorgehensweise

Ich bin zwar auch nur Anfänger und kann daher erstmal nur vermuten, wo das Problem liegt. Mich würden einige Variablen interessieren, die du verwendest

Auf welchem Wert steht

event.brain_action

und

Welchen Wert hat

event.attack_rate

standardmäßig bzw. woher kommt er.

Vielleicht sind dort irgendwelche Werte eingestellt, die automatisch zu einer Flucht führen müssen.

Eine andere Ursache könnten die
event.action 'Move' und 'Run' sein. Wie sehen die denn aus.

Anemone

Rekrut

  • »Anemone« ist der Autor dieses Themas

Motto: Was zählt ist nicht das eigene Leben, sondern es aufs Spiel zusetzen.

  • Nachricht senden

3

Samstag, 17. Oktober 2009, 15:23

Quellcode

1
2
event.attack_rate=85
event.brain_action='none'

event.brain_action wird nur in der einen methode umgeändert

event = Battlerinformations
$my_battle.troop = Gegnerisches Team
$my_battle.actors = Verbündete
event.action 'Move' und 'Run':

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Battlerinformations
  def initialize id=0
    [...]
    @direction=(actor? ? 4 : 6)
    @action="Stand"
    @action_counter=0
  end
  def update
   [...]
   @action_counter-=1 if @action_counter > 0
   excute
   [...]
  end
  def execute
   case @action
     when "Move", "Run"
      move_forward
    end
  end
  def face_toward_target
    if actor?
      return auto_index if $my_battle.troop[@target_index].nil?
      wx=@x-$my_battle.troop[@target_index].x
    else
      return auto_index if $my_battle.actors[@target_index].nil?
      wx=@x-$my_battle.actors[@target_index].x
    end
    if wx > 0
      @direction=4
    elsif wx < 0
      @direction=6
    end
  end
  def face_away_target
    if actor?
      return auto_index if $my_battle.troop[@target_index].nil?
      wx=@x-$my_battle.troop[@target_index].x
    else
      return auto_index if $my_battle.actors[@target_index].nil?
      wx=@x-$my_battle.actors[@target_index].x
    end
    if wx < 0
      @direction=4
    elsif wx > 0
      @direction=6
    end
  end
end


Der originale code:

[HBS] Battler
Spoiler

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
class Battler_Informations < Gravitation
  #================================
  # Initialize
  #---------------------------------------------------------------
  # battler = Battler
  # id = Party/Troop ID
  #================================  
  def initialize battler, id, player=false
    @battler=battler
    @id=id
    @character_id=id
    @player=player
    initialize_char
    setup
  end
  #================================
  # Setup
  #================================  
  def setup
    @need_refresh=false
    @magic_start=false
    @use_skill=false
    @attacked=false
    @critical=false
    @damaged=false
    @droped=false
    @magic_id=0
    @skill_frames=0
    @damage=0
    @combo=0
    @target_index=1
    @direction=6
    @action='Stand'
    @object_damage=3
    @bore_count=0
    if actor?
      @job=$data_classes[@battler.class_id].name
      @hp=@battler.hp
      @sp=@battler.sp
      @maxhp=@battler.maxhp
      @maxsp=@battler.maxsp
      @weapon_id=@battler.weapon_id #Equipped weapon ID
      @animation2_id=$data_weapons[@weapon_id].animation2_id
      @max_combo=$my_actors[battler.id].max_combo
      @aggresive=$my_actors[battler.id].aggresive
      @attack_rate=$my_actors[battler.id].attack_rate
      @defend_rate=$my_actors[battler.id].defend_rate
      @backeyes_faktor=$my_actors[battler.id].backeyes_faktor
      @defend_break_base=$my_actors[battler.id].defend_break
      @exp=0
      @money=0
      @drop_id=0
      @drop_typ="None"
    else
      @job='ENEMY'
      @hp=@battler.maxhp
      @sp=@battler.maxsp
      @maxhp=@hp
      @maxsp=@sp
      @weapon_id=@battler.animation1_id #NO id of Weapon, ID OF ANIMATION
      @animation2_id=@battler.animation2_id
      @max_combo=$my_enemies[battler.id].max_combo
      @aggresive=$my_enemies[battler.id].aggresive
      @attack_rate=$my_enemies[battler.id].attack_rate
      @defend_rate=$my_enemies[battler.id].defend_rate
      @backeyes_faktor=$my_enemies[battler.id].backeyes_faktor
      @defend_break_base=$my_enemies[battler.id].defend_break
      @exp=@battler.exp
      @money=@battler.gold
      @treasure_prob=@battler.treasure_prob
      lucky=(rand(100) < @treasure_prob)
      if @battler.weapon_id > 0 and lucky
        @drop_id=@battler.weapon_id
        @drop_typ="Weapon"
      elsif @battler.item_id > 0 and lucky
        @drop_id=@battler.weapon_id
        @drop_typ="Item"
      elsif @battler.armor_id > 0 and lucky
        @drop_id=@battler.weapon_id
        @drop_typ="Armor"
      else
        @drop_id=0
        @drop_typ="None"        
      end
      if ((@drop_typ == "Weapon" or @drop_typ == "Armor") and rand(100) <= 15) or  #15% auf Falle bei Waffen und Rüstungen
        ((@drop_typ == "Item" or @drop_typ == "None") and rand(100) <= 8) #8%  auf Falle bei Item und Nichts
        @drop_id=$my_game.local_trap
        @drop_typ="Trap"
      end
    end
    @name=@battler.name
    @atk=battler.atk
    @pdef=battler.pdef
    @mdef=battler.mdef
    @agi=battler.agi
    @str=battler.str
    @dex=battler.dex
    @int=battler.int
    @eva=battler.eva
    @frames=Battler_Action_Informations.new @battler
    @brain_action='none'
    @action_count=0
    @defend_break_counter=0
    @attacked_frame=[]
    @animation_id=0
  end
  #================================
  # Battler is Game_Actor?
  #================================  
  def actor?
    return @battler.is_a? Game_Actor
  end
  #================================
  # Battler is Human?
  #================================  
  def is_player?
    return (actor? and @player)
  end
  #================================
  # Dead?
  #================================  
  def dead?
    return @hp <= 0
  end
  #================================
  # Cast Skill is able?
  #================================
  def cast? sp_min=0
    return @sp >= sp_min
  end
  #================================
  # Magic (Addon for Skill)
  #================================
  def cast_magic
    user=$my_battle.get_character(@character_id)
    user.loop_animation_id=-1
    @magic_counter=0
    @magic_start=false
    return if dead?
    s=$data_skills[@magic_id]
    unless cast? s.sp_cost
      @action='Break'
      return
    end
    @use_skill=true
    @action="Use Magic"
    @sp-=s.sp_cost
    animation1=$data_animations[s.animation1_id]
    animation2=$data_animations[s.animation2_id]
    if actor?
      return if $my_battle.troop[@target_index-1].dead?
      target=$my_battle.get_character(@target_index)
    else
      return if $my_battle.actors[@target_index-1].dead?
      target=$my_battle.get_character(@target_index+4)
    end
    if target.nil?
      #Das Momentane Ziel ist nicht erreichbar (nicht exestensiel) also suche ein neues aus.
      auto_index
      #Neustart der Ziel wahl
      if actor?
        target=$my_battle.get_character(@target_index)
      else
        target=$my_battle.get_character(@target_index+4)
      end
    end
    return if target.nil? #Kein Ziel kann erreicht werden also breche den angriff ab. (= Map ist leer)
    if actor?
      $my_battle.troop[@target_index-1].action='Hurt'
    else
      $my_battle.actors[@target_index-1].action='Hurt'
    end
    case animation1.position
    when 3
      $my_battle.screen.animation animation1, true
    else
      user.animation_id=animation1.id
    end
    case animation2.position
    when 3
      if animation1.position != 3
        $my_battle.screen.animation animation2, true
      else
        target.animation_id=animation2.id
      end
    else
      target.animation_id=animation2.id
    end
    @used_skill=s
    $my_battle.help_window.set_text s.name, 1
    $my_battle.help_window.countdown 100
    $my_battle.refresh
  end
  #================================
  # Skill
  #================================
  def skill(tech_pos_id=0)
    skill_id=@battler.equiped_skills[tech_pos_id]
    return if skill_id <= 0
    s=$data_skills[skill_id]
    return unless cast? s.sp_cost
    @skill_frames=$my_skills.skill[s.name].frames
    if $my_skills.skill[s.name].misc
      $game_switches[$my_skills.skill[s.name].switch_id+@id]=false
      a=[5,5,6,7,8]
      m=[80,81,82,83]
      char=$my_battle.get_character(a[@id])
      d= @direction == 4 ? -1 : 1
      $my_battle.get_character(m[@id]).moveto(char.x+d, char.y)
      $game_variables[$my_skills.skill[s.name].variable_id+@id]=@direction
      $game_switches[$my_skills.skill[s.name].switch_id+@id]=true
    end
    if $my_skills.skill[s.name].magic
      @action="Cast Magic"
      @magic_id=s.id
      @magic_start=true
      @magic_counter=cast_time(s)
      $my_battle.get_character(@character_id).loop_animation_id=$my_battle.magic_animation[element(s)]
      return
    else
      @action="Skill#{s.name}"
    end
    @sp-=s.sp_cost
    ani=s.animation1_id
    if ani != nil and ani > 0
      $my_battle.get_character(@character_id).animation_id=ani+(@direction == 4 ? 1:0)
    end
    @use_skill=true
    @used_skill=s
    $my_battle.help_window.set_text s.name, 1
    $my_battle.help_window.countdown 100
    $my_battle.refresh
  end
  #================================
  # Time for Casting
  #================================
  def cast_time(s)
    return ((s.agi_f**2)*2/@int)
  end
  #================================
  # Element of Skill
  #================================
  def element(s)
    return s.element_set[0]
  end
  #================================
  # Update
  #================================
  def update
    if @action_count >= 0
      @action_count -= 1
    end
    update_gravitation
    if moving?
      update_move
    end
    pattern_update
    execute
    if @magic_start
      @magic_counter-=1
      if @magic_counter <= 0
        cast_magic
      end
    end
  end
  #================================
  # Auto Index
  #================================
  def auto_index
    #Wer nimmt alles NOCH AKTIV am Kampf teil? (GEGNERISCHES TEAM)
    combat_character=[]
    eok=[]
    way=[]
    if actor?
      for i in 0..$my_battle.troop.size-1
        if not $my_battle.troop[i].nil? and not $my_battle.troop[i].dead?
          eok.push i
          combat_character.push $my_battle.troop[i]
          way.push ($my_battle.troop[i].x-@x).abs
        end
      end
    else
      for i in 0..$my_battle.actors.size-1
        if not $my_battle.actors[i].nil? and not $my_battle.actors[i].dead?
          eok.push i
          combat_character.push $my_battle.actors[i]
          way.push ($my_battle.actors[i].x-@x).abs
        end
      end
    end
    return if combat_character.empty?
    #Sortiere
    sort=way.clone
    sort.sort!
    #Nächstes Event herausfinden
    for i in 0..way.size-1
      if way[i]==sort[0]
        id= i
        break
      end
    end
    #Rückschlüsse auf Character nehmen und dann als Ziel festlegen
    @target_index=eok[id]
    if @id == 0
      $my_battle.camera_select 2, @target_index
    end
  end
  #================================
  # After battle transfering the status.
  #================================
  def transfer_status
    return unless actor?
    @battler.hp=@hp
    @battler.sp=@sp
  end
  #================================
  # Turn Face toward Target Position
  #================================
  def face_toward_target
    if actor?
      return auto_index if $my_battle.troop[@target_index].nil?
      wx=@x-$my_battle.troop[@target_index].x
    else
      return auto_index if $my_battle.actors[@target_index].nil?
      wx=@x-$my_battle.actors[@target_index].x
    end
    if wx > 0
      @direction=4
    elsif wx < 0
      @direction=6
    end
  end
  #================================
  # Turn Face away Target Position
  #================================
  def face_away_target
    if actor?
      return auto_index if $my_battle.troop[@target_index].nil?
      wx=@x-$my_battle.troop[@target_index].x
    else
      return auto_index if $my_battle.actors[@target_index].nil?
      wx=@x-$my_battle.actors[@target_index].x
    end
    if wx < 0
      @direction=4
    elsif wx > 0
      @direction=6
    end
  end
  #================================
  # Public Instance Variables
  #================================  
  attr_writer :player
  attr_writer :jump_mode
  attr_reader :job
  attr_reader :maxhp
  attr_reader :maxsp
  attr_reader :battler
  attr_reader :atk
  attr_reader :pdef
  attr_reader :mdef
  attr_reader :agi
  attr_reader :str
  attr_reader :dex
  attr_reader :int
  attr_reader :eva
  attr_reader :attack_rate
  attr_reader :defend_rate
  attr_reader :backeyes_faktor
  attr_reader :defend_break_base
  attr_reader :id
  attr_reader :exp
  attr_reader :money
  attr_reader :drop_typ
  attr_reader :drop_id
  attr_reader :treasure_prob
  attr_reader :name
  attr_reader :action
  attr_reader :x
  attr_reader :y
  attr_reader :real_x
  attr_reader :real_y
  attr_accessor :pattern
  attr_reader :width
  attr_reader :height
  attr_reader :object_damage
  attr_accessor :loop_animation_id
  attr_accessor :attacked_frame
  attr_accessor :droped
  attr_accessor :frozen
  attr_accessor :animation2_id
  attr_accessor :weapon_id
  attr_accessor :frames
  attr_accessor :combo
  attr_accessor :max_combo
  attr_accessor :direction
  attr_accessor :hp
  attr_accessor :sp
  attr_accessor :damage
  attr_accessor :damaged
  attr_accessor :critical
  attr_accessor :attacked
  attr_accessor :use_skill
  attr_accessor :skill_frames
  attr_accessor :target_index
  attr_accessor :aggresive
  attr_accessor :character_id
  attr_accessor :used_skill
  attr_accessor :magic_start
  attr_accessor :magic_id
  attr_accessor :need_refresh
  attr_accessor :brain_action
  attr_accessor :action_count
  attr_accessor :defend_break_counter
  attr_accessor :animation_id
  attr_accessor :bore_count
end
zum Lesen den Text mit der Maus markieren


[HBS] Battler Input/KI
Spoiler

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
class My_Battle
  #Konstanten
  RUN_TIME=20
  BREAK_TIME=35
  #Keys
  UP='Up'
  DOWN='Down'
  LEFT='Left'
  RIGHT='Right'
  ACTION='Attack'
  RUN='Run'
  SKILL='Skill'
  #===============================
  # Input/KI splitter
  #===============================
  def events_update
    return unless start?
    unless actor_freeze?
      for actor in @actors
        actor.update
        if actor.is_player?
          actor_input(actor)
        else
          ki(actor)
        end
      end
    end
    unless enemy_freeze?
      for enemy in @troop
        enemy.update
        ki(enemy)
      end
    end
  end
  #===============================
  # Input Module
  #   for active Actors (/Players)
  #===============================
  def none_action event
    return (event.action=='Stand' or event.action=='Weak' or event.action=='Boring')
  end
  def actor_input(actor)
    return if actor.action=='Hurt' or
               actor.damaged
    keys=$key_player[actor.id]
    if actor.dead?
      actor.action='Dead'
      actor.combo=0
      return
    end
    if actor.gravitation != 0
      if Input.press?(keys[RIGHT])
        actor.jump_mode=2
        actor.direction=6
      elsif Input.press?(keys[LEFT])
        actor.jump_mode=1
        actor.direction=4
      else
        actor.jump_mode=0
      end
      return
    end
    if actor.combo >= actor.max_combo
      actor.action='Break'
      actor.action_count=BREAK_TIME
      actor.combo=0
      return
    end
    if Input.trigger?(keys[SKILL])
      #If Skill key was pressed
      if Input.press?(keys[DOWN])
        actor.skill 0
      elsif Input.press?(keys[RIGHT]) or Input.press?(keys[LEFT])
        actor.skill 1
      elsif Input.press?(keys[UP])
        actor.skill 2
      else
        actor.skill 3
      end
    elsif !actor.action.include? 'Attack' and
     actor.action != 'Break' and
     !actor.action.include? 'Skill'
      #If Skill key was not pressed and no other blocking action is in progress
      if Input.trigger?(keys[ACTION])
        #If Action key was pressed
        c=actor.combo
        if Input.press?(keys[DOWN])
          actor.action="AttackDown#{c}"
        elsif Input.press?(keys[RIGHT]) or Input.press?(keys[LEFT])
          actor.action="AttackSide#{c}"
        elsif Input.press?(keys[UP])
          actor.action="AttackUp#{c}"
        else
          actor.action="Attack#{c}"
        end
        actor.combo+=1
      else
        move_press=false
        if Input.press?(keys[RUN])
          #If RunKey is pressing, speed up Movements
          if Input.press?(keys[LEFT])
            actor.direction=4
            actor.action='Run'
            actor.combo=0
            move_press=true
          elsif Input.press?(keys[RIGHT])
            actor.direction=6
            actor.action='Run'
            actor.combo=0
            move_press=true
          end
        else
          #If RunKey is not pressing, normal Movements
          if Input.press?(keys[LEFT])
            actor.direction=4
            actor.action='Move'
            actor.combo=0
            move_press=true
          elsif Input.press?(keys[RIGHT])
            actor.direction=6
            actor.action='Move'
            actor.combo=0
            move_press=true
          end
        end
        if Input.press?(keys[DOWN])
          #Defend
          actor.action='Defend'
          actor.magic_start=false
          actor.magic_id=0
          actor.loop_animation_id=-1
        elsif Input.press?(keys[UP])
          #Jump
          if none_action actor
            actor.init_jump(0)
          elsif actor.action=='Move' or
            actor.action=='Run'
            case actor.direction
            when 4
              actor.init_jump(1)
            when 6
              actor.init_jump(2)
            end
          end
        else
          if move_press
            actor.bore_count=0
            return
          end
          #Default position
          if actor.hp <= actor.maxhp*30/100
            actor.action='Weak'
          else
            if actor.bore_count >= 24
              actor.action='Boring'
            else
              actor.bore_count+=1
              actor.action='Stand'
            end
          end
        end
      end
    elsif actor.action == 'Break' and actor.action_count <= 0
      if actor.hp <= actor.maxhp*30/100
        actor.action='Weak'
      else
        actor.action='Stand'
      end
    end
  end
  #===============================
  # KI 
  #   for Actors and Enemys
  #===============================
  def ki(event)
    event.action_count-=1 if event.action_count > 0
    #Check aviability of events target
    tindex=event.target_index
    #KI Header
    atc_cache=attack?(event, event.frames['Attack0'].space)
    if event.actor?
      tchar=@troop[tindex]
    else
      tchar=@actors[tindex]
    end
    if tchar.nil? or tchar.dead?
      return event.auto_index
    end
    if event.dead?
      event.action='Dead'
      event.combo=0
      return
    end
    if event.combo >= event.max_combo
      event.action='Break'
      event.combo=0
      event.need_refresh=true
      return
    end
    if event.action == 'Defend'
      event.combo=0
      if event.action_count <= 0
        event.action='Stand'
        event.need_refresh=true
      else
        event.action='Defend'
      end
      return
    end
    if event.action == 'Break'
      event.combo=0
      if event.action_count <= 0
        event.action_count=0
        event.action='Stand'
        event.brain_action='none'
      end
      return
    end
    #End KI Header
    #KI-Explorer
    action_type=0
    if event.brain_action != 'none'
      #BGActions in Progress
      case event.brain_action
      when 'walk toward', 'walk away'
        if (tchar.x-event.x).abs >= @run_coor
          event.action='Move'
        else
          event.action='Run'
        end
        if event.action_count <= 0
          if event.attack_rate >= rand(100)
            if rand(2)==0
              event.action_count = 0
            else
              event.action_count=10*(rand(2)+1)
            end
          else
            event.action_count=20*(rand(2)+1)
          end
          event.brain_action='wait'
          return
        end
      when 'attack'
        p 'error'
        exit
      when 'skill'
        return event.brain_action='none'
      when 'wait'
        event.face_toward_target
        event.action='Stand'
        if event.action_count <= 0
          event.brain_action='none'
        end
        return
      else
        return event.brain_action='none'
      end
    else 
      #if event.brain_action == 'none'
      if (tchar.x-event.x).abs >= @run_coor
        case rand(10)
        when 0
          method=0
        when 1,2,3
          method=1
        else
          method=2
        end
      else
        case rand(10)
        when 0,7
          method=0
        when 1,2,3,4,5,6
          method=2
        else
          method=3
        end
      end
      case method
      when 0
        event.brain_action = 'skill'
      when 1
        event.brain_action = 'walk away'
        event.action_count = RUN_TIME
        event.face_away_target
      when 2
        event.brain_action = 'walk toward'
        event.action_count = RUN_TIME
        event.face_toward_target
      end
    end
    #End KI-Explorer
    #KI-Execute
    case action_type
    when 1 #Attack
      event.face_toward_target
      if rand(5) >= 3
        #Switch to skill
        return event.brain_action='skill'
      end
      # Use normal attack with equipped weapon
      actions=['Attack','AttackUp','AttackDown','AttackSide']
      event.action=actions[rand(actions.size)]+event.combo.to_s
      space=event.frames[event.action].space
      event.combo+=1
      event.brain_action='attack'
      if event.combo.between? event.max_combo/2, event.max_combo and
        event.attack_rate < rand(100)
        event.brain_action='walk away'
      end
    when 2 #Skill
      # Use skill
      event.brain_action='none' #Not now aviable, build is in progress
    end
    #End KI-Execute
    #KI-Result
    #End KI-Result
  end
end
zum Lesen den Text mit der Maus markieren


[HBS] Battler Character
Spoiler

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
class Battler_Informations < Gravitation
  SPACE_FACTOR=1
  #===============================
  # Initialize
  #===============================
  def initialize_char
    @x=0.0 # X poistion on screen (absolute)
    @y=0.0 # Y poistion on screen (absolute)
    @repeat_key=[0,0,0,0,0,0,0,0,0]
    @base_x=0
    @base_y=0
    @max_direction=10
    @max_pattern=8
    @angle=0 # Angle of objects sprite
    @mirror=false # Mirror objects sprite
    @disallow_move=false # Block all input for Movements if true
    @gravitation=0.1 # Gravitation in Y Durection, auto amp. @ gravitation != 0
    @x_gravitation=0.0  # Gravitation in X Direction, amp. @ movement
    @fall_way=0.0  # After the Objects Gravity adding positive values this variable 
                            # will incrase (@weight-63.0)/100.0 each frame 
                            # (eg.: @weight = 64.0;@fall_way+=0.01)
    @weight=64.0  # Body weight, 64.0 is standart and can be compared to 64kg (not lower then 63.0!)
    @body_strenght=0.0  # Aditional Power of Body for Jump and Knocking out Enemies
    @start_pattern=0
    @pose=0
    @width=32 # Source Rect Width of Sprite
    @height=32 # Source Rect Height of Sprite
    @critical=false # Popup effect (true = big, false = normal)
    @damage=0 # Popup value (Int. or Str.)
    @damaged=false # if true, the value of the variable damaga will popup on sprite
    @acting=0
    @acting_time=0
    @once=false
    @default_pose=''
    @offset_x=0
    @offset_y=0
    @offset_width=0
    @offset_height=0
    @loop_animation_id=0
    @character_name='' # Filename (not folders, only file)
    @old_character_name=''
    @character_hue=0
    @pattern=0
    @move_speed=0
    @anime_count=0
    @step_anime=0
    @stop_count=0
    @real_x=0.0
    @real_y=0.0
    @folder_name="Graphics/Battlecharsets/" # Path to folder of sprite source
    @fix_action=false # Dissalow Animation if true
  end
  #===============================
  # Pattern Update
  #===============================
  def pattern_update
    if @anime_count > 18 - @move_speed * 2
      if @once
        if @pattern == @max_pattern-1
          @acting+=1
        end
        if @acting >= @acting_time
          @acting=0
          @acting_time=0
          @once=false
          $my_battle.action_force self, @default_pose
          return
        end
      end
      if @pattern >= @max_pattern-1
        @pattern=@start_pattern
      else
        @pattern+=1
      end
      @anime_count = 0
    end
    @anime_count+=1
  end
  #===============================
  # Battle Progress Manager
  #===============================
  def time_manager time=4, default='Stand'
    @acting=0
    @acting_time=time
    @once=true
    @default_pose=default
  end
  #===============================
  # Get Screen X-Coordinates
  #===============================
  def screen_x
    return (@real_x - $my_battle.display_x.to_f + 3.0) / 4.0 + My_Battle::MAP_TILE_SIZE[0]/2.0
  end
  #===============================
  # Get Screen Y-Coordinates
  #===============================
  def screen_y
    return (@real_y - $my_battle.display_y.to_f + 3.0) / 4.0 + My_Battle::MAP_TILE_SIZE[1]
  end
  #===============================
  # Get Screen Z-Coordinates
  #===============================
  def screen_z(h = 0)
    return (@real_y - $my_battle.display_y.to_f + 3.0) / 4.0 + My_Battle::MAP_TILE_SIZE[1] + ((h > My_Battle::MAP_TILE_SIZE[1]) ? My_Battle::MAP_TILE_SIZE[1]-1.0 : 0.0)
  end
  #===============================
  # Get X&Y Screen Coor
  #===============================
  def get_screen
    return [screen_x,screen_y]
  end
  #===============================
  # Get O x/y
  #===============================
  def get_o
    return [@width/2,@height]
  end
  #===============================
  # Get SRC Rect
  #===============================
  def get_src_rect
    return Rect.new(@pattern*@width+@offset_x,
                            @pose*@height+@offset_y,
                            @width+@offset_width,
                            @height+@offset_height
                           )
  end
  #===============================
  # Get Bitmap Path
  #===============================
  def get_path
    return @folder_name+@character_name
  end
  #===============================
  # Get Weapon Sprite
  #===============================
  def get_weapon_sprite(sprite)
    return Sprite.new(sprite.viewport) unless actor?
    return Weapon_Sprite.new(sprite.viewport,$data_weapons[@weapon_id].name,self)
  end
  #===============================
  # Sprite- Auto initialize
  #===============================
  def spr_auto_initialize(sprite)
    action='Initialize'
    sprite.ox = get_o[0]
    sprite.oy = get_o[1]
    sprite.weapon = get_weapon_sprite(sprite)
  end
  #===============================
  # Sprite- Auto update
  #===============================
  def spr_auto_update(sprite)
    # Set Coor
    sprite.x = screen_x
    sprite.y = screen_y
    sprite.z = screen_z
    sprite.zoom_x=$xcam
    sprite.zoom_y=$xcam
    # Refresh Bitmap
    if @old_character_name != @character_name
      sprite.bitmap = RPG::Cache.load_bitmap(@folder_name,@character_name,@character_hue)
      @old_character_name=@character_name
    end
    # Set Source Rectangle
    sprite.src_rect=get_src_rect
    # Set Misc. Sprite Attributes
#    sprite.blend_type = @blend_type
#    sprite.bush_depth = @bush_depth
#    sprite.visible = !@transparent
    sprite.mirror = (@direction==4 ? false : true)
    sprite.angle = @angle
#    sprite.opacity = @opacity
    #Updating
    sprite.weapon.update
    # Show Damage
    if @damaged
      sprite.damage(@damage, @critical)
      @damaged=false
    end
    # Event Animation (eg. Status)
    if @animation_id > 0
      sprite.animation($data_animations[@animation_id],true)
      @animation_id=0
    end
    if @loop_animation_id > 0
      sprite.loop_animation($data_animations[@loop_animation_id])
      @loop_animation_id=0
    end
    if @loop_animation_id == -1
      sprite.dispose_loop_animation
      @loop_animation_id=0
    end
  end
end
zum Lesen den Text mit der Maus markieren


[HBS] Battler Movement
Spoiler

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class Battler_Informations < Gravitation
  MOVE_WIDTH=1.0#128.0
  #1.0 for the Line following movement system
  X_MOVE_SPEED=16.0
  JUMP_FACTOR=1.0
  #---------------------------------------------------------------
  # Update Move
  #---------------------------------------------------------------
  def update_move
    distance = (2 ** @move_speed).to_f
    if @y * MOVE_WIDTH > @real_y #Down
      @real_y = [@real_y + distance, @y * MOVE_WIDTH].min
    end
    if @x * MOVE_WIDTH < @real_x #Left
      @real_x = [@real_x - distance, @x * MOVE_WIDTH].max
    end
    if @x * MOVE_WIDTH > @real_x #Right
      @real_x = [@real_x + distance, @x * MOVE_WIDTH].min
    end
    if @y * MOVE_WIDTH < @real_y #Up
      @real_y = [@real_y - distance, @y * MOVE_WIDTH].max
    end
  end
  #---------------------------------------------------------------
  # Determine if Moving
  #---------------------------------------------------------------
  def moving?
    return (@real_x.to_i != (@x * MOVE_WIDTH).to_i or @real_y.to_i != (@y * MOVE_WIDTH).to_i)
  end
  def moveable?
    return true
  end
  #---------------------------------------------------------------
  # Determine if Jumping
  #---------------------------------------------------------------
  def jumping?
    return (@gravitation != 0)
  end
  def jumpable?
    return @gravitation.between?(-1.0,0)
  end
  #---------------------------------------------------------------
  # Move to Designated Position
  #---------------------------------------------------------------
  def moveto(x, y)
    @x = x % My_Battle::MAP_WIDTH
    @y = y % My_Battle::MAP_HEIGHT
    @real_x = @x * MOVE_WIDTH
    @real_y = @y * MOVE_WIDTH
    @prelock_direction = 0
  end
  #===============================
  # Move Right
  #===============================
  def move_right direction_switch=true
    @direction=6 if direction_switch
    @x_gravitation=X_MOVE_SPEED * (@action == 'Run' ? 1.5 : 1.0)
  end
  #===============================
  # Move Left
  #===============================
  def move_left direction_switch=true
    @direction=4 if direction_switch
    @x_gravitation=-X_MOVE_SPEED * (@action == 'Run' ? 1.5 : 1.0)
  end
  #===============================
  # After Up/Down Action Set
  #===============================
  def move_up_action_set
    case @action
    when 'InitJump'
      action='MainJump'
    when 'InitJumpRight'
      action='MainJumpRight'
    when 'InitJumpLeft'
      action='MainJumpLeft'
    end
  end
  def move_down_action_set
    case @action
    when 'MainJump'
      action='EndJump'
    when 'MainJumpRight'
      action='EndJumpRight'
    when 'MainJumpLeft'
      action='EndJumpLeft'
    end
  end
  #===============================
  # Check that char using a action for X-Movements
  #===============================
  def x_action?
    return (@action == "Move" or @action == "Run" or @action == "InitJumpRight" or
               @action == "InitJumpLeft" or @action == "MainJumpRight" or @action == "MainJumpLeft" or 
               @action == "EndJumpRight" or @action == "EndJumpLeft")
  end
  #===============================
  # BackPower of the Crash with Gravitation Power
  #===============================
  def crash_value
    cv=-(@gravitation.abs-@weight)*TERRAIN_ABSORB
    return (cv > 0 ? 0 : cv)
  end
  #===============================
  # Move Forward
  #===============================
  def move_forward
    if @direction == 4
      move_left
    else
      move_right
    end
  end
  #===============================
  # Move Backward
  #===============================
  def move_backward
    if @direction == 4
      move_right false
    else
      move_left false
    end
  end
  #===============================
  # Intialize Jump-Progress
  #===============================
  def init_jump id
    return unless jumpable?
    @jump_mode=id
    @gravitation=-95.5-@body_strenght+@weight
  end
end
zum Lesen den Text mit der Maus markieren


[HBS] Battler Execute
Spoiler

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Battler_Informations < Gravitation
  def execute
    case @action
    when 'Move', 'Run', 
          'InitJumpRight', 'MainJumpRight', 'EndJumpRight',
          'InitJumpLeft', 'MainJumpLeft', 'EndJumpLeft'
      move_forward
    end
    # Setup Action Performe
    $my_battle.frame_action @frames[@action].operation, self
  end
  def action=(na)
    return if na == @action or @fix_action
    set_new_action na
  end
  def set_new_action na
    @action=na
    se=@frames[@action].se.se
    if !se.nil? and se != ''
     Audio.se_play("Audio/SE/#{se}",My_Se::VOLUME,100)
    end
    @need_refresh=false
    frame=@frames[@action]
    @start_pattern=frame.start_pattern
    @offset_x=frame.offset_x
    @offset_y=frame.offset_y
    @offset_width=frame.offset_width
    @offset_height=frame.offset_height
    @folder_name=frame.folder
    @pose=frame.pose
    @width=frame.width
    @height=frame.height
    @max_pattern=frame.max_pattern
    @move_speed=frame.move_speed
    @frequency=frame.frequency
    @step_anime=frame.animate
    @character_name=frame.name
    @gravitation+=frame.gravitation
    @pattern=0
    time_manager(frame.act,frame.default) if frame.once
  end
end
zum Lesen den Text mit der Maus markieren

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Anemone« (17. Oktober 2009, 15:43)


Anemone

Rekrut

  • »Anemone« ist der Autor dieses Themas

Motto: Was zählt ist nicht das eigene Leben, sondern es aufs Spiel zusetzen.

  • Nachricht senden

4

Montag, 2. November 2009, 16:11

Ich habs jz selber heraus bekommen und eine lösung gefunden warum meine KI so scheiße ist XD
ich habs innen shema zusammen gestellt:
Bild
Bild

dank an dich Charriu für dein interrese ^^

5

Montag, 2. November 2009, 21:22

deswegen hatte ich die idee man könnte ja events als Automaten programieren


http://de.wikipedia.org/wiki/Endlicher_Automat << hier infos
Realität ist nur eine subjektive Wahrnehmungsstörung.

Alles ist wahr, wenn man für wahr einen bestimmten Wert annimmt.

Anemone

Rekrut

  • »Anemone« ist der Autor dieses Themas

Motto: Was zählt ist nicht das eigene Leben, sondern es aufs Spiel zusetzen.

  • Nachricht senden

6

Dienstag, 30. März 2010, 14:06

so hab ich mir das auch vorgestellt, aber das zeuch will ned so wie ich will XD naja ich schreib meine KI einfach von grund auf neu XD ty für die hilfen :)

Ähnliche Themen

Social Bookmarks