public SpriteBattler(Viewport viewport, Game_Battler battler = null) { Global.AddUIElement(this); this.battler = battler; this.battler_visible = false; InitializeComponent(); }
//-------------------------------------------------------------------------- // ● 生成描绘用的状态字符串 // actor : 角色 // width : 描画目标的宽度 // need_normal : [正常] 是否为必须 (true / false) //-------------------------------------------------------------------------- public string make_battler_state_text(Game_Battler battler, int width, bool need_normal) { // 获取括号的宽 var brackets_width = (int)this.contents.text_size("[]").Width; // 生成状态名字符串 var text = ""; foreach (var i in battler.states) { if (Global.data_states[i].rating >= 1) { if (text == "") { text = Global.data_states[i].name; } else { var new_text = text + "/" + Global.data_states[i].name; var text_width = (int)this.contents.text_size(new_text).Width; if (text_width > width - brackets_width) { break; } text = new_text; } } } // 状态名空的字符串是 "[正常]" 的情况下 if (text == "") { if (need_normal) { text = "[正常]"; } } else { // 加上括号 text = "[" + text + "]"; } // 返回完成后的文字类 return(text); }
//-------------------------------------------------------------------------- // ● 初始化对像 // viewport : 显示端口 // battler : 战斗者 (Game_Battler) //-------------------------------------------------------------------------- public Sprite_Battler(Viewport viewport, Game_Battler battler = null) : base(viewport) { this.battler = battler; this.battler_visible = false; }
//-------------------------------------------------------------------------- // ● 生成基本行动结果 //-------------------------------------------------------------------------- public void make_basic_action_result() { Game_Battler target = null; int index = 0; // 攻击的情况下 if (this.active_battler.current_action.basic == 0) { // 设置攻击 ID this.animation1_id = this.active_battler.animation1_id; this.animation2_id = this.active_battler.animation2_id; // 行动方的战斗者是敌人的情况下 if (this.active_battler is Game_Enemy) { if (this.active_battler.restriction == 3) { target = Global.game_troop.random_target_enemy(); } else if (this.active_battler.restriction == 2) { target = Global.game_party.random_target_actor(); } else { index = this.active_battler.current_action.target_index; target = Global.game_party.smooth_target_actor(index); } } // 行动方的战斗者是角色的情况下 if (this.active_battler is Game_Actor) { if (this.active_battler.restriction == 3) { target = Global.game_party.random_target_actor(); } else if (this.active_battler.restriction == 2) { target = Global.game_troop.random_target_enemy(); } else { index = this.active_battler.current_action.target_index; target = Global.game_troop.smooth_target_enemy(index); } } // 设置对像方的战斗者序列 this.target_battlers = new List <Game_Battler>() { target }; // 应用通常攻击效果 foreach (var target1 in this.target_battlers) { target1.attack_effect(this.active_battler); } return; } // 防御的情况下 if (this.active_battler.current_action.basic == 1) { // 帮助窗口显示"防御" this.help_window.set_text(Global.data_system.words.guard, 1); return; } // 逃跑的情况下 if (this.active_battler is Game_Enemy && this.active_battler.current_action.basic == 2) { // 帮助窗口显示"逃跑" this.help_window.set_text("逃跑", 1); // 逃跑 ((Game_Enemy)this.active_battler).escape(); return; } // 什么也不做的情况下 if (this.active_battler.current_action.basic == 3) { // 清除强制行动对像的战斗者 Global.game_temp.forcing_battler = null; // 移至步骤 1 this.phase4_step = 1; return; } }
//-------------------------------------------------------------------------- // ● 应用通常攻击效果 // attacker : 攻击者 (battler) //-------------------------------------------------------------------------- public bool attack_effect(Game_Battler attacker) { double damage = 0.0; if (this.damage is double) { damage = Convert.ToDouble(this.damage); } // 清除会心一击标志 this.critical = false; // 第一命中判定 var hit_result = (Global.rand(100) < attacker.hit); // 命中的情况下 if (hit_result == true) { // 计算基本伤害 var atk = Math.Max(attacker.atk - this.pdef / 2, 0); damage = atk * (20 + attacker.str) / 20; // 属性修正 damage *= elements_correct(attacker.element_set); damage /= 100; // 伤害符号正确的情况下 if (damage > 0) { // 会心一击修正 if (Global.rand(100) < 4 * attacker.dex / this.agi) { damage *= 2; this.critical = true; } // 防御修正 if (this.is_guarding) { damage /= 2; } } // 分散 if (Math.Abs(damage) > 0) { var amp = Math.Max(Math.Abs(damage) * 15 / 100, 1); damage += Global.rand((int)amp + 1) + Global.rand((int)amp + 1) - amp; } // 第二命中判定 var eva = 8 * this.agi / attacker.dex + this.eva; var hit = damage < 0 ? 100 : 100 - eva; hit = this.is_cant_evade ? 100 : hit; hit_result = (Global.rand(100) < hit); } // 命中的情况下 if (hit_result == true) { // 状态冲击解除 remove_states_shock(); // HP 的伤害计算 this.hp -= damage; // 状态变化 this.state_changed = false; states_plus(attacker.plus_state_set); states_minus(attacker.minus_state_set); } // Miss 的情况下 else { // 伤害设置为 "Miss" this.damage = "Miss"; // 清除会心一击标志 this.critical = false; } this.damage = damage; // 过程结束 return(true); }
//-------------------------------------------------------------------------- // ● 应用特技效果 // user : 特技的使用者 (battler) // skill : 特技 //-------------------------------------------------------------------------- public bool skill_effect(Game_Battler user, RPG.Skill skill) { // 清除会心一击标志 this.critical = false; // 特技的效果范围是 HP 1 以上的己方、自己的 HP 为 0、 // 或者特技的效果范围是 HP 0 的己方、自己的 HP 为 1 以上的情况下 if (((skill.scope == 3 || skill.scope == 4) && this.hp == 0) || ((skill.scope == 5 || skill.scope == 6) && this.hp >= 1)) { // 过程结束 return(false); } double damage = 0.0; if (this.damage is double) { damage = Convert.ToDouble(this.damage); } // 清除有效标志 var effective = false; // 公共事件 ID 是有效的情况下,设置为有效标志 effective |= skill.common_event_id > 0; // 第一命中判定 var hit = skill.hit; if (skill.atk_f > 0) { hit *= (int)(user.hit / 100); } var hit_result = (Global.rand(100) < hit); // 不确定的特技的情况下设置为有效标志 effective |= hit < 100; // 命中的情况下 if (hit_result == true) { // 计算威力 var power = skill.power + user.atk * skill.atk_f / 100; if (power > 0) { power -= this.pdef * skill.pdef_f / 200; power -= this.mdef * skill.mdef_f / 200; power = Math.Max(power, 0); } // 计算倍率 double rate = 20; rate += (user.str * skill.str_f / 100); rate += (user.dex * skill.dex_f / 100); rate += (user.agi * skill.agi_f / 100); rate += (user.int1 * skill.int_f / 100); // 计算基本伤害 damage = power * rate / 20; // 属性修正 damage *= elements_correct(skill.element_set); damage /= 100; // 伤害符号正确的情况下 if (damage > 0) { // 防御修正 if (this.is_guarding) { damage /= 2; } } // 分散 if (skill.variance > 0 && Math.Abs(damage) > 0) { var amp = Math.Max(Math.Abs(damage) * skill.variance / 100, 1); damage += Global.rand((int)amp + 1) + Global.rand((int)amp + 1) - amp; } // 第二命中判定 var eva = 8 * this.agi / user.dex + this.eva; hit = damage < 0 ? 100 : (int)(100 - eva * skill.eva_f / 100); hit = this.is_cant_evade ? 100 : hit; hit_result = (Global.rand(100) < hit); // 不确定的特技的情况下设置为有效标志 effective |= hit < 100; } this.damage = damage; // 命中的情况下 if (hit_result == true) { // 威力 0 以外的物理攻击的情况下 if (skill.power != 0 && skill.atk_f > 0) { // 状态冲击解除 remove_states_shock(); // 设置有效标志 effective = true; } // HP 的伤害减法运算 var last_hp = this.hp; this.hp -= damage; effective |= this.hp != last_hp; // 状态变化 this.state_changed = false; effective |= states_plus(skill.plus_state_set); effective |= states_minus(skill.minus_state_set); // 威力为 0 的场合 if (skill.power == 0) { // 伤害设置为空的字串 this.damage = ""; // 状态没有变化的情况下 if (!this.state_changed) { // 伤害设置为 "Miss" this.damage = "Miss"; } } } // Miss 的情况下 else { // 伤害设置为 "Miss" this.damage = "Miss"; } // 不在战斗中的情况下 if (!Global.game_temp.in_battle) { // 伤害设置为 null this.damage = null; } // 过程结束 return(effective); }