[]aRPG en semi-event
Auteur : Darkleo
Hi creative !
Aujourd'hui est un grand jour, je partage la base de mon script d'aRPG.
Le plus grand problème des aRPG, c'est qu'en général, le systeme est soit en script, totalement non modifiable, soit en event, totalement borné pas les capacités du log.
Mon script permet de se servir pleinement d'un aRPG en event, avec les fonctions script indispensables !
Le script se décompose en fait en 4 scripts, pour une approche plus aisée pour les scripteurs. C'est une base sur laquelle viendra se raccrocher des petits AddOns (comme un hud par exemple, etc...) au grès des demandes.
Pour bien montrer le fonctionnement du script, je joindrai une démo contenant un aRPG en semi/event déjà réalisé.
Un tutoriel sera bien évidement aussi mis en ligne.
Je remercie Sunmat pour le script de copie d'event, et Roys pour l'affichage des dégats.
Enjoy !
Script : aRPG Game_Character- Code: Tout sélectionner
#====================================================================
# ■ Game_Character
# aRPG par Darkleo
#====================================================================
class Game_Character
# Animation d'attaque
P_ANIM_ID = 4 # animation d'attaque physique
M_ANIM_ID = 4 # animation d'attaque magique
#--------------------------------------------------------------------------
attr_accessor :var1
attr_accessor :var2
attr_accessor :var3
attr_accessor :delai_atk
attr_accessor :stopped
attr_reader :original_character_name
#--------------------------------------------------------------------------
alias arpg_character_initialize initialize
def initialize
arpg_character_initialize
@var1 = 0
@var2 = 0
@var3 = 0
@delai_atk = 0
@stopped = false
@original_character_name = @character_name
end
#--------------------------------------------------------------------------
alias character_arpg_update update
def update
if @delai_atk >= 1
@stopped = true
@delai_atk -= 1
@stopped = false if @delai_atk == 0
end
character_arpg_update
end
#--------------------------------------------------------------------------
def character_name=(character_name)
@original_character_name = character_name
@character_name = character_name
end
#--------------------------------------------------------------------------
def hit_p(*args)
tab = args.dup
tab.shift
tab.each { |i|
a = 0 ; b = 0
a += $1.to_i if i[/droite((d))/] != nil
a -= $1.to_i if i[/gauche((d))/] != nil
b += $1.to_i if i[/devant((d))/] != nil
b -= $1.to_i if i[/derriere((d))/] != nil
case @direction
when 2
x = @x - a ; y = @y + b
when 4
x = @x - b ; y = @y - a
when 6
x = @x + b ; y = @y + a
when 8
x = @x + a ; y = @y - b
end
for chara in $game_map.events.values
if chara.x == x and chara.y == y and chara.hp != 0
chara.animation_id = P_ANIM_ID
chara.damage_p(args[0])
end
end
if $game_player.x == x and $game_player.y == y
$game_player.animation_id = P_ANIM_ID
$game_player.damage_p(args[0])
end
}
end
#--------------------------------------------------------------------------
def hit_m(*args)
tab = args.dup
tab.shift
tab.each { |i|
a = 0 ; b = 0
a += $1.to_i if i[/droite((d))/] != nil
a -= $1.to_i if i[/gauche((d))/] != nil
b += $1.to_i if i[/devant((d))/] != nil
b -= $1.to_i if i[/derriere((d))/] != nil
case @direction
when 2
x = @x - a ; y = @y + b
when 4
x = @x - b ; y = @y - a
when 6
x = @x + b ; y = @y + a
when 8
x = @x + a ; y = @y - b
end
for chara in $game_map.events.values
if chara.x == x and chara.y == y and chara.hp != 0
chara.animation_id = M_ANIM_ID
chara.damage_m(args[0])
end
end
if $game_player.x == x and $game_player.y == y
$game_player.animation_id = M_ANIM_ID
$game_player.damage_m(args[0])
end
}
end
#--------------------------------------------------------------------------
def on_map?(v=0)
v *= 32
return (screen_x+v >= 0 and screen_x-v <= 640 and
screen_y+v >= 0 and screen_y-v <= 480 )
end
#--------------------------------------------------------------------------
def view_range(radius, chara_id=[0], type=2, opt=0)
d = 999999
type = 2 if opt >= radius
tab_chara = []
for i in chara_id
if i == 0
tab_chara << $game_player
else
tab_chara << $game_map.events[i]
end
end
for chara in tab_chara
next if chara == self
case type
when 1
d = ((@x.to_i - chara.x.to_i).abs + (@y.to_i - chara.y.to_i).abs)/2
when 2
d = Math.sqrt ( (@x.to_i - chara.x.to_i)**2 + (@y.to_i - chara.y.to_i)**2)
when 3
case @direction
when 2
next if (@y-opt) > chara.y
when 4
next if (@x+opt) < chara.x
when 6
next if (@x-opt) > chara.x
when 8
next if (@y+opt) < chara.y
end
d = Math.sqrt ( (@x.to_i - chara.x.to_i)**2 + (@y.to_i - chara.y.to_i)**2)
end
break if d <= radius
end
return d <= radius
end
#--------------------------------------------------------------------------
def touch?(id = 0)
if id == 0
return true if (@x-$game_player.x).abs + (@y-$game_player.y).abs == 1
else
for chara in $game_map.events.value
return true if (@x-chara.x).abs + (@y-chara.y).abs == 1
end
end
return false
end
#--------------------------------------------------------------------------
def look?(id = 0)
if id == 0
if @x-$game_player.x == 1 and @direction == 2 or
@x-$game_player.x == -1 and @direction == 8 or
@y-$game_player.y == 1 and @direction == 6 or
@y-$game_player.y == -1 and @direction == 4
return true
end
else
for chara in $game_map.events.value
if @x-chara.x == 1 and @direction == 2 or @x-chara.x == -1 and @direction == 8 or
@y-charar.y == 1 and @direction == 6 or @y-chara.y == -1 and @direction == 4
return true
end
end
end
return false
end
#--------------------------------------------------------------------------
end
#====================================================================
Script : aRPG Game_Event- Code: Tout sélectionner
#====================================================================
# ■ Game_Event
# aRPG par Darkleo
#====================================================================
class Game_Event < Game_Character
# Repartition de l'exp
# 1 : donne l'exp au heros principal uniquement
# 2 : donne l'exp à tout les membres du groupe
# 3 : partage l'exp entre les membres
# 4 : idem 3 en privilegiant le heros principal
TYPE_EXP = 1
# ID de la map d'où les events sont copies
MAP_ID = 1
#--------------------------------------------------------------------------
attr_reader :hp
attr_reader :type
attr_reader :database_id
#--------------------------------------------------------------------------
alias event_arpg_initialize initialize
def initialize(map_id, event)
event_arpg_initialize(map_id, event)
@hp = 0
@type = 'event'
end
#--------------------------------------------------------------------------
def id=(id)
@id = id
@event.id = id
end
#--------------------------------------------------------------------------
def erased?
@erased
end
#--------------------------------------------------------------------------
def load_database(id)
@database_id = id
@hp = $data_enemies[id].maxhp
@name = $data_enemies[id].name
@type = @name[/(ally)/] != nil ? 'ally' : 'enemy'
@event.same_as(id, MAP_ID)
$game_map.need_refresh = true
end
#--------------------------------------------------------------------------
def atk_player
atk = $data_enemies[@database_id].atk
atk_plus = rand(atk/10)
atk_plus *= rand(1) == 1 ? 1 : -1
atk += atk_plus
$game_player.damage_p(atk)
end
#--------------------------------------------------------------------------
def damage_p(v)
return if @hp <= 0
v = [v/2, v-$data_enemies[@database_id].pdef].max
@text = v.to_s
@hp -= v
end
#--------------------------------------------------------------------------
def damage_m(v)
return if @hp <= 0
v = [v/2, v-$data_enemies[@database_id].mdef].max
@text = v.to_s
@hp -= v
end
#--------------------------------------------------------------------------
def move_random
return if @stopped or moving?
safe = false
checked = []
if passable?(@x, @y, @direction) and rand(5) != 0
safe = true
move_forward
end
while safe == false
break if checked.include?(0) and checked.include?(1) and
checked.include?(2) and checked.include?(3)
case rand(4)
when 0
return if checked.include?(0)
checked << 0
if passable?(@x, @y, 2)
safe = true
move_down(true)
end
when 1
return if checked.include?(1)
checked << 1
if passable?(@x, @y, 4)
safe = true
move_left(true)
end
when 2
return if checked.include?(2)
checked << 2
if passable?(@x, @y, 6)
safe = true
move_right(true)
end
when 3
return if checked.include?(3)
checked << 3
if passable?(@x, @y, 8)
safe = true
move_up(true)
end
end
end
end
#--------------------------------------------------------------------------
def on_player?
return (@x == $game_player.x and @y == $game_player.y)
end
#--------------------------------------------------------------------------
def able_to_attack
return false unless touch?(0)
return false if moving?
return false if stopped
return true
end
#--------------------------------------------------------------------------
def drop?
return false if $data_enemies[@database_id].item_id == 0 and
$data_enemies[@database_id].weapon_id == 0 and
$data_enemies[@database_id].armor_id == 0 and
$data_enemies[@database_id].gold == 0
return rand(100) <= $data_enemies[@database_id].treasure_prob
end
#--------------------------------------------------------------------------
def drop
gold = $data_enemies[@database_id].gold
$game_party.gain_gold(gold)
item = $data_enemies[@database_id].item_id
$game_party.gain_item(item, 1)
weapon = $data_enemies[@database_id].weapon_id
$game_party.gain_weapon(weapon, 1)
armor = $data_enemies[@database_id].armor_id
$game_party.gain_armor(armor, 1)
$game_system.se_play(RPG::AudioFile.new("006-System06",100,100))
end
#--------------------------------------------------------------------------
def kill
@dead = true
# Donne l'experience
case TYPE_EXP
when 1
$game_party.actors[0].exp += $data_enemies[@database_id].exp
when 2
s = $game_party.actors.size
for i in 0...s
$game_party.actors[i].exp += $data_enemies[@database_id].exp
end
when 3
s = $game_party.actors.size
for i in 0...s
$game_party.actors[i].exp += $data_enemies[@database_id].exp / s
end
when 4
$game_party.actors[0].exp += $data_enemies[@database_id].exp / 2
s = $game_party.actors.size
for i in 1...s
$game_party.actors[i].exp += $data_enemies[@database_id].exp / (2*s)
end
end
end
#--------------------------------------------------------------------------
end
#====================================================================
_________________

Projets