[pre lang="ruby"]#==============================================================================
# ■ EFS
#------------------------------------------------------------------------------
# 群战系统的游戏主操控类
# 全新版本
# 作者 Raider Soap 肥皂君~
#
#==============================================================================
class EFS
#--------------------------------------------------------------------------
# ● 初始化数据
#--------------------------------------------------------------------------
def initialize(party1,party2)
$Team_Fighter = []
$Enermy_Fighter = []
$Num_Team = 1 # player
$Team_Fighter.push $game_player
$Num_Enermy = 0
#死亡计数
$Team_Death_counter = 0
$Enermy_Death_counter = 0
$game_player.self_battler = $game_player # 正太君改
$game_player.hp = $game_party.actors[0].hp # 正太君改
$game_player.maxhp = $game_party.actors[0].maxhp # 正太君改
$game_player.mp = $game_party.actors[0].sp # 正太君改
$game_player.maxmp = $game_party.actors[0].maxsp # 正太君改
$game_player.skilled_level = 3
$game_player.action_mode = 0
$game_player.armor = 30
$game_player.ap = 60
$game_player.ap_range = 5
$game_player.atk_se = "swordbasic_"
$game_player.atk_se_num = 11
$game_player.heavy = false
$game_player.name = "theplayer"
$game_player.atk_fr = 30
$game_player.is_cav = false
$game_player.shd = false
#双方队伍
@team_party = party1
@enermy_party = party2
#团队
$team_group = []
$enermy_group = []
$team_group[0] = []
for i in 1..10
$team_group[i] = []
$enermy_group[i] = []
end
$lisenter = 0
#坚守的行数量
@guarding_line_num = 1
#出生点
@group_spawn = []
for i in 1..10# 5改为10个
@group_spawn[i] = []
end
@group_spawn_e = []
for i in 1..10 # 5改为10个
@group_spawn_e[i] = []
end
@counter = 0
@counter_for_wait = 0
@counter_for_push = 0
@c = false
@spell_used = []
#一定要把所有技能在这里过一遍
#一定要把所有技能在这里过一遍
#一定要把所有技能在这里过一遍
# for i in 1..X
@spell_used[1] = Skill_data::TIME[1] # i
#end
end
#--------------------------------------------------------------------------
# ● 显示图标
#--------------------------------------------------------------------------
def show_icon
if $selected_item == 0
item_id = 33
else
item_id = Item_data::ID[$selected_item]
end
if $selected_spell == 0
spell_id = 0
else
spell_id = $selected_spell
end
item = $data_items[item_id]
spell_icon = Skill_data::ICON[spell_id]
# 设置变量
$game_variables[2] = $game_party.item_number(item_id) #物品数量
$game_variables[3] = @spell_used[$selected_spell]
# 显示图
$game_screen.pictures[5].show(item.icon_name,1,494,444, 100, 100, 255, 0)
$game_screen.pictures[2].show(spell_icon,1,532,444, 100, 100, 255, 0) if not $selected_spell == 0
$game_screen.pictures[8].show("shd01",1,609,444, 100, 100, 255, 0)
weapons = $data_weapons[$game_party.actors[0].weapon_id]
$game_screen.pictures[9].show(weapons.icon_name,1,571,444, 100, 100, 255, 0)
end
#--------------------------------------------------------------------------
# ● 寻找小队坐标点
#--------------------------------------------------------------------------
def group_spawn_points
#循环全部事件
for event in $game_map.events.values
Graphics.update
if event.name[0,3] == "##T"
group = event.name[3,1].to_i
@group_spawn[group].push event.x
@group_spawn[group].push event.y
@group_spawn[group].push event.name[4,1].to_i
#[event.x,event.y,event.name[4,1].to_i]
elsif event.name[0,3] == "##E"
group = event.name[3,1].to_i
@group_spawn_e[group].push event.x
@group_spawn_e[group].push event.y
# name[4,1]的值为 1 代表横着 2 代表竖着
@group_spawn_e[group].push event.name[4,1].to_i
end
end
end
#--------------------------------------------------------------------------
# ● 创建士兵
#--------------------------------------------------------------------------
def spawn_fighters
Drop_Item.pre_load
for group_id in 1..10
num_people = @team_party.number(group_id)
next if @team_party.number(group_id) == 0
num = even?(num_people) ? num_people/2 : (num_people-1)/2
for i in [email]0..@team_party.number[/email](group_id) - 1
x = @group_spawn[group_id][0]
y = @group_spawn[group_id][1]
new_x = @group_spawn[group_id][2] == 1 ? x - num + i : x
new_y = @group_spawn[group_id][2] == 2 ? y - num + i : y
Drop_Item.make_events_EFS(new_x,new_y)
Graphics.update
for event in $game_map.events.values
if event.x == new_x and event.y == new_y and not event.name[0,2] == "##"
team_fighter = @team_party.group[group_id][i]
@team_party.group[group_id][i].set_event(event)
$Team_Fighter.push(team_fighter)
$team_group[0].push team_fighter
$team_group[team_fighter.group_id].push team_fighter
event.self_battler = team_fighter
end
end
end
end
Drop_Item.refresh_map
end
def spawn_fighters_e
Drop_Item.pre_load
for group_id in 1..10
num_people = @enermy_party.number(group_id)
num = even?(num_people) ? num_people/2 : (num_people-1)/2
for i in [email]0..@enermy_party.number[/email](group_id)-1
x = @group_spawn_e[group_id][0]
y = @group_spawn_e[group_id][1]
new_x = @group_spawn_e[group_id][2] == 1 ? x - num + i : x
new_y = @group_spawn_e[group_id][2] == 2 ? y - num + i : y
Drop_Item.make_events_EFS(new_x,new_y)
Graphics.update
for event in $game_map.events.values
if event.x == new_x and event.y == new_y and not event.name[0,2] == "##"
team_fighter = @enermy_party.group[group_id][i]
@enermy_party.group[group_id][i].set_event(event)
$Enermy_Fighter.push(team_fighter)
$enermy_group[team_fighter.group_id].push team_fighter
event.self_battler = team_fighter
end
end
end
end
Drop_Item.refresh_map
end
def even?(value)
value & 1 == 0
end
#--------------------------------------------------------------------------
# ● 分组设定
#--------------------------------------------------------------------------
def groups_setting
for fighters in $Team_Fighter
$team_group[fighters.group_id].push fighters if fighters != $game_player
$team_group[0].push fighters if fighters != $game_player
end
for fighters in $Enermy_Fighter
$enermy_group[fighters.group_id].push fighters
end
end
#--------------------------------------------------------------------------
# ● 下达初始指令
#--------------------------------------------------------------------------
def command(team,group,command_id)
#TEAM = 1 代表 玩家的队伍 2 代表 敌人的队伍
if team = 1
for f in $team_group[group]
f.command_action = command_id
end
else
for e in $enermy_group[group]
e.command_action = command_id
end
end
end
#--------------------------------------------------------------------------
# ● 士兵基础设置 # 正太君改
#--------------------------------------------------------------------------
def set_fighters
#循环全部事件
for event in $game_map.events.values
if event.name[0,2] == "#T"
team_fighter = EFS_Team.new(event,event.name[3,3].to_i)
$Team_Fighter.push(team_fighter)
event.self_battler = team_fighter
elsif event.name[0,2] == "#E"
enermy_fighter = EFS_Enermy.new(event,event.name[3,3].to_i)
$Enermy_Fighter.push(enermy_fighter)
event.self_battler = enermy_fighter
end
end
end
def update_player_data
$game_player.hp = $game_party.actors[0].hp # 正太君改
$game_player.mp = $game_party.actors[0].sp # 正太君改
$game_party.actors[0].hp = $game_party.actors[0].hp.round
$game_party.actors[0].sp = $game_party.actors[0].sp.round
$game_player.update_die if $game_player.dead?
# 冷却
$item_cd -= 1 if $item_cd > 0
$spell_cd -= 1 if $spell_cd > 0
$item_opacity = 255 if $item_cd <= 0 else $item_opacity = 140
if $selected_item == 0
item_id = 33
else
item_id = Item_data::ID[$selected_item]
end
if $selected_spell == 0
spell_id = 0
else
spell_id = $selected_spell
end
item = $data_items[item_id]
# 设置变量
$game_variables[2] = $game_party.item_number(item_id)
$game_variables[3] = @spell_used[$selected_spell]
# 显示图
$game_screen.pictures[2].move(0,0,532,444, 100, 100, 255, 0) if not $selected_spell == 0
$game_screen.pictures[8].move(0,0,609,444, 100, 100, 255, 0)
$game_screen.pictures[5].move(0,0,450,432, 100, 100,$item_opacity, 0)
weapons = $data_weapons[$game_party.actors[0].weapon_id]
$game_screen.pictures[9].move(0,0,573,433, 100, 100,255, 0)
show_icon
# 是否是加速状态的更新
$game_player.accelarting = $game_player.move_speed == 4 ? true : false
end
#--------------------------------------------------------------------------
# ● 主处理 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
#--------------------------------------------------------------------------
def main
return if $BattleOn == false
#判断是否胜利
if check_winning
after_battle
return
end
$game_player.update_die if $game_player.dead?
#######UPDATE#########
update_player_data
######################
$game_player.attack if $game_player.attack? and not $game_player.dead?
#如果敌人是推进策略
for i in 1..10
group_check_cor(i)
end
if @enermy_party.strategy == 2
e_push if push_wait
end
#判断输入
if (Kboard.keyboard($R_Key_SPACE)) and not $game_player.dead?
$game_player.attack if use_sp(90)
elsif Kboard.keyboard($R_Key_1) and not $game_player.dead?
Notification.post("第1队!听我的命令!")
$lisenter = 1 #group 1
elsif Kboard.keyboard($R_Key_2) and not $game_player.dead?
$lisenter = 2 #group 2
Notification.post("第2队!听我的命令!")
elsif Kboard.keyboard($R_Key_3) and not $game_player.dead?
$lisenter = 3 #group 3
Notification.post("第3队!听我的命令!")
elsif Kboard.keyboard($R_Key_4) and not $game_player.dead?
$lisenter = 4 #group 4
Notification.post("第4队!听我的命令!")
elsif Kboard.keyboard($R_Key_5) and not $game_player.dead?
$lisenter = 5 #group 5
Notification.post("第5队!听我的命令!")
elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
$lisenter = 6 #group 5
Notification.post("第6队!听我的命令!")
elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
$lisenter = 7 #group 5
Notification.post("第7队!听我的命令!")
elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
$lisenter = 8 #group 5
Notification.post("第8队!听我的命令!")
elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
$lisenter = 9 #group 5
Notification.post("第9队!听我的命令!")
elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
$lisenter = 10 #group 5
Notification.post("第10队!听我的命令!")
elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
$lisenter = 0 #group All
Notification.post("所有人!听我的命令!")
elsif Kboard.keyboard($R_Key_Q) and not $game_player.dead?
Notification.post("坚守这里!")
blocked = false
for f in $Team_Fighter
next if f.is_a?(Game_Player)
blocked = true if f.check_guard_position($game_player.x,$game_player.y,$game_player.direction)
end
unless blocked
for e in $team_group[$lisenter]
e.command_action = 1 #def
e.set_guard_cor($game_player.x,$game_player.y,$game_player.direction,@guarding_line_num) if not @set
end
@set = true
else
$game_system.se_play($data_system.buzzer_se)
end
elsif Kboard.keyboard($R_Key_W) and not $game_player.dead?
Notification.post("跟我来!")
for e in $team_group[$lisenter]
e.command_action = 2 #onme
end
elsif Kboard.keyboard($R_Key_E) and not $game_player.dead?
Notification.post("冲锋")
for e in $team_group[$lisenter]
e.command_action = 3 #atk
end
elsif Kboard.keyboard($R_Key_A) and not $game_player.dead?
$game_player.character_name = "theplayer-jump"
if $game_player.accelarting
$game_player.animation_id = 117
$game_player.jump_forward(2) if use_sp(75)
else
$game_player.animation_id = 117
$game_player.jump_forward(1) if use_sp(50)
end
elsif Kboard.keyboard($R_Key_S) and not $game_player.dead?
use_item
elsif Kboard.keyboard($R_Key_D) and not $game_player.dead?
use_spell
end
#是否按键加速
if Kboard.keyb($R_Key_LSHIFT) and not $game_player.dead? and not $game_player.attack?
$game_player.character_name = "theplayer-swd-run" if not $game_player.jumping?
$game_player.move_speed = use_sp(4) ? 4 : 3
elsif Kboard.keyb($R_Key_Z) and not $game_player.dead? and not $game_player.attack?
$game_player.character_name = "theplayer-shd" if not $game_player.jumping?
$game_player.heavy = true
$game_player.move_speed = 2
$game_player.shd = true
else
if not $game_player.attack?
$game_player.shd = false
$game_player.heavy = false
$game_player.character_name = "theplayer" if not $game_player.jumping?
$game_party.actors[0].sp += 4
$game_party.actors[0].sp = $game_party.actors[0].maxsp if $game_party.actors[0].sp >= $game_party.actors[0].maxsp
end
$game_player.move_speed = 3
end
if Kboard.keyboard($R_Key_SEP)
if @guarding_line_num != 1
@guarding_line_num -= 1
else
@guarding_line_num = 3
end
Notification.post("排成"+@guarding_line_num.to_s+"行!")
elsif Kboard.keyboard($R_Key_DOTT)
if @guarding_line_num != 3
@guarding_line_num += 1
else
@guarding_line_num = 1
end
Notification.post("排成"+@guarding_line_num.to_s+"行!")
end
if Kboard.keyboard($R_Key_ALT)
@c = @c ? false : true
$game_switches[5] = @c
$game_switches[6] = @c
end
#所有士兵的main
for i in 1..$Team_Fighter.size-1
$Team_Fighter[i].main
end
for e in $Enermy_Fighter
e.main
end
@set = false
end
#--------------------------------------------------------------------------
# ● 判断玩家的体力是否足够维持&&可以的话就扣掉相应的
#--------------------------------------------------------------------------
def use_sp(sp)
if $game_party.actors[0].sp < sp
$game_system.se_play($data_system.buzzer_se)
return false
else
$game_party.actors[0].sp -= sp if ! $game_player.attack?
return true
end
end
#--------------------------------------------------------------------------
# ● 敌人策略分析器
#--------------------------------------------------------------------------
def enermy_strategy
case @enermy_party.strategy
when 1
for e in $Enermy_Fighter
e.get_group_spawn(@group_spawn_e,@group_spawn)
e.command_action = 1
end
when 2
for e in $Enermy_Fighter
e.get_group_spawn(@group_spawn_e,@group_spawn)
e.command_action = 1
end
when 3
for e in $Enermy_Fighter
e.command_action = 3
end
end
end
#--------------------------------------------------------------------------
# ● 设置初始坚守坐标
#--------------------------------------------------------------------------
def set_defualt_guard_cor
for e in $Team_Fighter
next if e.is_a?(Game_Player)
e.get_group_spawn(@group_spawn_e,@group_spawn)
e.command_action = 1
end
end
#--------------------------------------------------------------------------
# ● 是否进入警戒距离
#--------------------------------------------------------------------------
def group_check_cor(group_id)
d_list = []
e_x,e_y = enermy_avg_cor(group_id)
for i in 1..10
t_x,t_y = team_avg_cor(i)
d = (t_x - e_x).abs + (t_y - e_y).abs
d_list.push d
end
if d_list.min < 10
for e in $enermy_group[group_id]
e.command_action = 3
end
end
end
#--------------------------------------------------------------------------
# ● 小队的平均坐标
#--------------------------------------------------------------------------
def team_avg_cor(group_id)
return 0,0 if $team_group[group_id] == nil or $team_group[group_id].size == 0
sum_x,sum_y = 0,0
for f in $team_group[group_id]
sum_x += f.event.x
sum_y += f.event.y
end
sum_x /= $team_group[group_id].size
sum_y /= $team_group[group_id].size
return sum_x,sum_y
end
def enermy_avg_cor(group_id)
return 0,0 if $enermy_group[group_id] == nil or $enermy_group[group_id].size == 0
sum_x,sum_y = 0,0
for f in $enermy_group[group_id]
sum_x += f.event.x
sum_y += f.event.y
end
sum_x /= $enermy_group[group_id].size
sum_y /= $enermy_group[group_id].size
return sum_x,sum_y
end
def team_avg_cor_all
sum_x,sum_y = 0,0
for f in $Team_Fighter
sum_x += f.event.x
sum_y += f.event.y
end
sum_x /= $Team_Fighter.size
sum_y /= $Team_Fighter.size
return sum_x,sum_y
end
def enermy_avg_cor_all
sum_x,sum_y = 0,0
for f in $Enermy_Fighter
sum_x += f.event.x
sum_y += f.event.y
end
sum_x /= $Enermy_Fighter.size
sum_y /= $Enermy_Fighter.size
return sum_x,sum_y
end
#--------------------------------------------------------------------------
# ● 使用物品
#--------------------------------------------------------------------------
def use_item
if $selected_item == 0
item_id = 33
else
item_id = Item_data::ID[$selected_item]
end
item = $data_items[item_id]
# 如果物品用完的情况下
if $game_party.item_number(item_id) == 0
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 如果交战中
if $game_player.attack?
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
#冷却时间
if $item_cd > 0
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
target = $game_party.actors[0]
used = target.item_effect(item)
# 使用物品的情况下
if used
# 演奏物品使用时的 SE
$game_system.se_play(item.menu_se)
# 设定冷却时间
$item_cd = Item_data::COLD_DOWN[$selected_item]
###设置变灰###
$item_opacity = 140
# 动画
$game_player.animation_id = item.animation2_id
# 消耗品的情况下
if item.consumable
# 使用的物品数减 1
$game_party.lose_item(item.id, 1)
end
# 全灭的情况下
if $game_party.all_dead?
$scene = Scene_Gameover.new
return
end
# 公共事件 ID 有效的情况下
if item.common_event_id > 0
# 预约调用公共事件
$game_temp.common_event_id = item.common_event_id
return
end
end
# 无法使用物品的情况下
unless used
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
end
return
end
#--------------------------------------------------------------------------
# ● 使用技能
#--------------------------------------------------------------------------
def use_spell
return if $selected_spell == 0
# 如果技能使用次数用完
if @spell_used[$selected_spell] <= 0
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 如果交战中
if $game_player.attack?
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
#冷却时间
if $spell_cd > 0
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
@spell_used[$selected_spell] -= 1
$spell_cd = Skill_data::CD[$selected_spell]
name = Skill_data::NAME[$selected_spell]
code = Skill_data::CODE[$selected_spell]
Notification.post("发动了技能"+name+"!")
EFS_Spell.use_spell(code)
end
#--------------------------------------------------------------------------
# ● 判断胜利
#--------------------------------------------------------------------------
def check_winning
counter = 0
for enermy in $Enermy_Fighter
if enermy.dead?
counter+=1
end
end
return counter >= $Enermy_Fighter.size
end
#--------------------------------------------------------------------------
# ● 战后处理
#--------------------------------------------------------------------------
def after_battle
if Kboard.keyboard($R_Key_TAB)
reset
$scene.spriteset.clear_point_arrow
$scene.spriteset.clear_arrow
$game_temp.common_event_id = 2
$game_player.move_speed = 4
$BattleOn = false
$game_switches[20] = false
$game_temp.common_event_id = 21
Notification.clear
$game = nil
back_to_map
$game_party.actors[0].sp = $game_party.actors[0].maxsp
$player_party.full_ammo
return
end
$game_party.actors[0].sp += 5
$game_party.actors[0].sp = $game_party.actors[0].maxsp if $game_party.actors[0].sp >= $game_party.actors[0].maxsp
for e in $Enermy_Fighter
e.event.update_die
end
for i in 1..$Team_Fighter.size-1
$Team_Fighter[i].event.update_die if $Team_Fighter[i].dead?
next if $Team_Fighter[i].dead?
$Team_Fighter[i].event.attack_action = false
$Team_Fighter[i].action_mode = 1
$Team_Fighter[i].event.character_name = $Team_Fighter[i].name
end
$game_player.attack_action = false
$game_player.action_mode = 1
$game_player.attack_over
$game_player.move_speed =3
$game_party.actors[0].hp = $game_party.actors[0].hp.round
$game_party.actors[0].sp = $game_party.actors[0].sp.round
for e in $Team_Fighter
next if e.is_a?(Game_Player)
e.remove_all_state
end
end
#--------------------------------------------------------------------------
# ● 战斗结束的士兵处理
#--------------------------------------------------------------------------
def reset
for f in $Team_Fighter
next if f.is_a?(Game_Player)
$player_party.delete(f) if f.dead? and not f.wounded
end
end
#--------------------------------------------------------------------------
# ● 战斗结束返回地图
#--------------------------------------------------------------------------
def back_to_map
# 场所移动中、信息显示中、过渡处理中的情况下
if $game_temp.player_transferring or
$game_temp.message_window_showing or
$game_temp.transition_processing
# 结束
return false
end
$game_temp.player_transferring = true
# 设置主角的移动目标
$game_temp.player_new_map_id = @or_map_id
$game_temp.player_new_x = @or_x
$game_temp.player_new_y = @or_y
$game_temp.player_new_direction = @or_d
# 准备过渡
Graphics.freeze
# 设置过渡处理中标志
$game_temp.transition_processing = true
$game_temp.transition_name = ""
return false
end
def load_or_map_data
@or_map_id = $game_map.map_id
@or_x = $game_player.x
@or_y = $game_player.y
@or_d = $game_player.direction
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# ● 接近目标的方向 (面向目标)
#--------------------------------------------------------------------------
def get_guard_direction
sx = @group_spawn_e[1][0] - @group_spawn[1][0]
sy = @group_spawn_e[1][1] - @group_spawn[1][1]
abs_sx= (sx).abs
abs_sy = (sy).abs
if abs_sx == 0 and abs_sy == 0
return
end
if sx.abs > sy.abs
return sx > 0 ? 4 : 6
else
return sy > 0 ? 8 : 2
end
end
def e_push
case get_guard_direction
when 2
for i in 1..5
@group_spawn_e[i][1] += 4
end
when 4
for i in 1..5
@group_spawn_e[i][0] -= 4
end
when 6
for i in 1..5
@group_spawn_e[i][0] += 4
end
when 8
for i in 1..5
@group_spawn_e[i][1] -= 4
end
end
for e in $Enermy_Fighter
e.get_group_spawn(@group_spawn_e,@group_spawn)
end
end
#--------------------------------------------------------------------------
# ● Code等待
#--------------------------------------------------------------------------
def push_wait
if @counter_for_push < 135
@counter_for_push += 1
return false
else
@counter_for_push = 0
return true
end
end
#--------------------------------------------------------------------------
# ● Code等待
#--------------------------------------------------------------------------
def code_wait(s)
#不需要解释,自己写的太渣了
if @counter_for_wait < s
@counter_for_wait += 1
return false
else
@counter_for_wait = 0
return true
end
end
end