| 赞 | 402 |
| VIP | |
| 好人卡 | |
| 积分 | 251 |
| 经验 | |
| 最后登录 | 2024-7-2 |
| 在线时间 | 3339 小时 |
- 梦石
- 1
- 星屑
- 24088
- 在线时间
- 3339 小时
- 注册时间
- 2011-7-8
- 回帖
- 3862

|
发表于 2023-4-5 03:47:54
|
显示全部楼层
如6楼所说,可以在make_action里做文章。关于智能的方式可以参考我写的这段set_auto_action:
- class Scene_Battle
- # 选项:0=随机攻击,1=仅恢复魔法,2=节省魔法,3=最大输出,
- # 1:随机/固定目标,2:节省/不节省魔法,4:输出/治疗优先
- #
- def plan
- {
- 'save_mana' => $game_setting['auto_battle_save_mana'] == 0,
- }
- end
-
- def set_auto_action(actor)
- skills = actor.skills.select{|id| actor.skill_can_use?(id)}
- skills.push 0
- scores = {}
- for index in 0..2 do
- for skill_id in skills do
- scores[[skill_id, index]] = score(actor, skill_id ,index)
- end
- end
-
- max_score = scores.values.sort{|v1, v2| v2.abs <=> v1.abs}[0]
- skill_id, index = scores.index(max_score)
- $last_auto_action = [index, max_score]
-
- if skill_id == 0
- actor.current_action.kind = 0
- actor.current_action.basic = 0
- actor.current_action.target_index = index
- else
- actor.current_action.kind = 1
- actor.current_action.skill_id = skill_id
- actor.current_action.target_index = index
- end
- end
-
- def score(actor, skill_id, index)
- # 1. 获取目标
- if skill_id == 0 || $data_skills[skill_id].scope <= 2
- target = $game_troop.enemies[index]
- else
- target = $game_party.actors[index]
- end
- # 如果此目标不存在,返回 -1
- return -1 if !target || !target.exist?
- # 2. 计算基本伤害
- if skill_id == 0
- dps = actor.atk * (1 + actor.crt * 0.01 * (actor.crtd - 100) * 0.01)
- else
- skill = $data_skills[skill_id]
- dps = get_skill_power(actor, skill)
- if dps < 0
- dps = [target.hp - target.maxhp, dps].max * 0.6
- end
- end
- # 3. 计算护甲、闪避、命中
- if skill_id == 0 || skill.atk_f > 0
- dps = dps * def2rate(target.pdef)
- eva_f = (skill_id == 0) ? 1 : skill.eva_f * 0.01
- dps = dps * (1 - eva_f * target.eva * 0.01)
- dps = dps * actor.hit * 0.01
- else
- x = 50 + (target.mdef - 50) * skill.mdef_f / 100
- dps = dps * def2rate(x)
- dps = dps * skill.hit * 0.01
- dps = dps * target.elements_correct(skill.element_set) * 0.01
- end
- # 4. 治疗/伤害 与目标生命值的关系
- if dps < 0
- if target.hp < target.maxhp * 0.5
- dps = dps * target.maxhp / (target.hp + 1)
- end
- dps *= 1.5 if target == actor # 优先治疗自身
- else
- dps = dps * (1 + [(dps / (target.hp + 1)) ** 2, 1].min)
- end
- # 5. 节省魔法
- if skill_id != 0 && plan['save_mana']
- r = skill.sp_cost.to_f / [actor.sp, 10].max
- dps = dps * [1 - r * 1.5, 0.5].max
- end
- # 6. spread
- if skill_id != 0
- enemy_size = $game_troop.enemies.select{|e| e.exist?}.size
- dps = dps * (1 + actor.spread * enemy_size * 0.01)
- end
- # 7. 分散度
- dps = dps * (rand(0.3) + 0.85)
- # 8. 上个角色的行动
- if $last_auto_action
- last_index, last_dps = $last_auto_action
- if last_index == index
- if last_dps < 0 && dps < 0
- dps = dps * 0.7
- elsif last_dps > 0 && dps > 0
- dps = dps * 1.3
- end
- end
- end
- # 输出信息
- # p [dps.abs, skill_id == 0 ? '攻击' : skill.name, target.name]
- return dps
- end
-
- def get_skill_power(user, skill)
- if skill.power >= 0
- if skill.atk_f > 0
- power = skill.power + user.atk * skill.atk_f / 100
- else
- power = skill.power + user.int * skill.eva_f / 100
- end
- else
- if skill.atk_f > 0
- power = skill.power - user.atk * skill.atk_f / 100
- else
- power = skill.power - user.int * skill.eva_f / 100
- end
- end
- # 主属性
- rate = 100.0
- case user.main
- when 0
- rate += user.str * skill.str_f * 0.05
- when 1
- rate += user.dex * skill.dex_f * 0.05
- when 2
- rate += user.agi * skill.agi_f * 0.05
- when 3
- rate += user.int * skill.int_f * 0.05
- end
- # 计算基本伤害
- power = (power * rate).round / 100
- return power
- end
-
- #------------------------------------------------------------------------
- # ● 防御减伤公式
- # x = 0, +25% | x = 20, 0% | x = 40, -20% |
- #------------------------------------------------------------------------
- def def2rate(x)
- 1.5 ** (1 - 0.02 * x)
- end
- end
复制代码 |
|