public UnitAction GetAction(Unit unit, Game game, Debug debug) { _game = game; _unit = unit; _debug = debug; if (_pointMaster == null) { _pointMaster = new PointMaster(ref game); } if (_pathFinder == null) { _pathFinder = new PathFinder(_pointMaster); } if (_rayTracer == null) { _rayTracer = new RayTracer(ref game); } _pointMaster.DebugDraw(debug); var action = new UnitAction(); var enemy = _game.Units.First(u => u.PlayerId != unit.PlayerId); if (!_unit.Weapon.HasValue || unit.Weapon.Value.Typ == WeaponType.RocketLauncher) { action.SwapWeapon = true; var lootbox = _game.LootBoxes .Where(lb => lb.Item is Item.Weapon) .Select(lb => (lb, Math.Abs(lb.Position.X - unit.Position.X) + Math.Abs(lb.Position.Y - unit.Position.Y))) .OrderBy(x => (x.Item1.Item as Item.Weapon).WeaponType == WeaponType.RocketLauncher ? x.Item2 * 100 : x.Item2) .First().Item1; if (GoToTarget(lootbox.Position, lootbox.Size.X / 2, ref action)) { return(action); } } else { action.Aim = new Vec2Double(enemy.Position.X - _unit.Position.X, enemy.Position.Y - _unit.Position.Y); var hitProb = _rayTracer.PercentOfHit(ref _unit, Math.Atan2(action.Aim.Y, action.Aim.X), ref enemy); action.Shoot = hitProb > 0.5; } if (_unit.Health < _game.Properties.UnitMaxHealth && _game.LootBoxes.Count(x => x.Item is Item.HealthPack) > 0) { var hpkit = _game.LootBoxes .Where(lb => lb.Item is Item.HealthPack) .Select(lb => (lb, Math.Abs(lb.Position.X - unit.Position.X) + Math.Abs(lb.Position.Y - unit.Position.Y))) .OrderBy(x => x.Item2) .First().Item1; if (GoToTarget(hpkit.Position, hpkit.Size.X / 2, ref action)) { return(action); } } if (GoToTarget(enemy.Position, enemy.Size.X / 2, ref action)) { return(action); } return(action); }
/// <summary> /// 異常状態チェックで /// MUエラーチェック /// </summary> private void UpdateErrorForMu() { // m_errorInfo.ResetMuInfo(); string locale_code = CommonUtil.GetAppLocaleCode(); MuMaster[] mu_masters = BaseModel.GetRows <MuMaster>(m_db.Conn, "SELECT * FROM mu_master WHERE mu_enable=1"); foreach (MuMaster mu_master in mu_masters) { int mu_id = mu_master.mu_id; MuStatusLog mu_status_log = BaseModel.GetFirst <MuStatusLog>(m_db.Conn, "SELECT * FROM mu_status_log WHERE mu_log_mu_id=" + mu_id + " ORDER BY mu_log_index DESC LIMIT 1"); string message = null; bool is_error = true; if (mu_status_log.mu_log_com == 0) { // 未接続のとき // 前回のエラー情報とオペモードをリセット // ResetMuErrCode(mu_id); m_errorInfo.RemoveByMu(mu_id); ResetMuOpeMode(mu_id); int errcode = 999900009; // オフライン用に存在しないエラーコードを設定 if (!IsSameErrCode(mu_id, errcode)) { message = Properties.Resources.MLD_MUORDER_STATUS_NOCON; } is_error = false; } else if (mu_status_log.mu_log_errcode == 0) { // エラーなしのとき // 前回のエラー情報リセット ResetMuErrCode(mu_id); int ope_mode = mu_status_log.mu_log_ope_mode; if (!IsSameOpeMode(mu_id, ope_mode)) { // ope_modeに対応するメッセージを取得 message = CommonUtil.GetValueFromCSV(Properties.Resources.MLD_OPE_MODE, ope_mode); is_error = false; } } else { // エラーありのとき // 前回のope_modeリセット ResetMuOpeMode(mu_id); int errcode = mu_status_log.mu_log_errcode; if (!IsSameErrCode(mu_id, errcode)) { // levelかcodeに異常がある場合はメッセージを取得 message = CommonUtil.MuErrorMessageFormat(m_db.Conn, locale_code, mu_id, mu_status_log.mu_log_errlevel, errcode); } } if (message != null) { string mu_name = BaseModel.GetFirstValue <string>(m_db.Conn, MuMaster.SelectNameSql(locale_code, mu_id.ToString()), "mu_name_" + locale_code); // エラー発生日時を取得 DateTime updatedAt = mu_status_log.mu_log_datetime; // 発部署、着部署 // ①の mu_statusテーブルの同一レコードにあるmu_stat_order_id(搬送オーダID)がNULLの場合(搬送していない)は、発部署、着部署はブランク表示します。 // mu_stat_order_id<> NULLの場合は、このmu_stat_order_idの一致する搬送オーダテーブル(order_reserve)から該当するレコード情報から発部署、着部署(巡回、不在転送含む表示)を表示する。 (string fromSectNames, string toSectNames) = OrderReserve.GetSectNames(m_db.Conn, mu_status_log.mu_log_order_id); string other_name = "value"; // 棟名称 string hospital_name = BaseModel.GetFirstValue <string>(m_db.Conn, HospitalMaster.SelectNameSql(locale_code, mu_status_log.mu_log_hospital_id.ToString(), other_name)); // フロア名称 string floor_name = BaseModel.GetFirstValue <string>(m_db.Conn, FloorMaster.SelectNameSql(locale_code, mu_status_log.mu_log_floor_id.ToString(), other_name)); // ポイント名称 string point_name = BaseModel.GetFirstValue <string>(m_db.Conn, PointMaster.SelectNameSql(locale_code, mu_status_log.mu_log_point_last.ToString(), other_name)); // メッセージを追加 (オフラインのときは黒) this.addMessage(updatedAt, is_error ? "Red" : "Black", message, mu_name); // システム状態のリストにもメッセージが表示されるように if (m_systemStatusControl != null) { m_systemStatusControl.addMessage(updatedAt, is_error ? "Red" : "Black", message, mu_name); } int muorder_status = mu_status_log.mu_log_muorder_status; if (is_error) { // 異常情報ようにエラー情報設定 m_errorInfo.UpdateMuError(updatedAt, GetErrorBrush(muorder_status), mu_id, mu_name, message, fromSectNames, toSectNames, hospital_name, floor_name, mu_status_log.mu_log_pos_x, mu_status_log.mu_log_pos_y, point_name); } } } }