private void refreshStatus(Dictionary <string, string> iStatus) { //gridStatus foreach (KeyValuePair <string, string> status in iStatus) { int idx = -1; for (int i = 0; i < gridStatus.RowCount; i++) { if (gridStatus.Rows[i].Cells[0].Value.ToString() == status.Key) { idx = i; break; } } if (idx < 0) { gridStatus.Rows.Add(); idx = gridStatus.Rows.Count - 1; } gridStatus.Rows[idx].Cells[0].Value = status.Key; gridStatus.Rows[idx].Cells[1].Value = status.Value; } //gridChat EliteAPI.ChatEntry cl; while (chat.GetNextChatLine(out cl)) { gridChat.Rows.Add(); gridChat.Rows[gridChat.Rows.Count - 1].Cells[0].Value = cl.Index1; gridChat.Rows[gridChat.Rows.Count - 1].Cells[1].Value = cl.Index2; gridChat.Rows[gridChat.Rows.Count - 1].Cells[2].Value = cl.Timestamp; gridChat.Rows[gridChat.Rows.Count - 1].Cells[3].Value = cl.Length; gridChat.Rows[gridChat.Rows.Count - 1].Cells[4].Value = (ChatMode)cl.ChatType; gridChat.Rows[gridChat.Rows.Count - 1].Cells[5].Value = cl.Text; gridChat.FirstDisplayedScrollingRowIndex = gridChat.RowCount - 1; } }
/// <summary> /// メインスレッド /// </summary> private void threadHarakiri() { chat.CurrentIndex = chat.MaxIndex; setHarakiriStatus(HarakiriStatusKind.Normal); bool firsttime = true; logger.Debug("ハラキリスレッド開始"); chat.Reset(); while (this.RunningStatus == RunningStatusKind.Running) { //未入力チェック if (this.HarakiriFishName.Length == 0) { setRunningStatus(RunningStatusKind.Stop); setHarakiriStatus(HarakiriStatusKind.Error); setMessage("ハラキリする魚を入力してください"); return; } //鞄に入っている魚の総数を取得 uint itemId = resource.GetItem(this.HarakiriFishName).ItemID; int remain = GetHarakiriRemain(this.HarakiriFishName); if (remain <= 0) { setRunningStatus(RunningStatusKind.Stop); if (firsttime) { setHarakiriStatus(HarakiriStatusKind.Error); setMessage("ハラキリする魚が見つかりませんでした"); } else { setHarakiriStatus(HarakiriStatusKind.Normal); setMessage("ハラキリが完了しました"); } return; } firsttime = false; setMessage(string.Format("ハラキリ中:{0} 残り{1}匹", this.HarakiriFishName, remain)); //鞄に対象の魚を移動させる if (control.GetInventoryItemCount(itemId, StorageContainer.Inventory) <= 0) { if (control.GetInventoryItemCount(itemId, StorageContainer.Satchel) > 0) { control.GetItemizer(this.HarakiriFishName, StorageContainer.Satchel); } else if (control.GetInventoryItemCount(itemId, StorageContainer.Sack) > 0) { control.GetItemizer(this.HarakiriFishName, StorageContainer.Sack); } else if (control.GetInventoryItemCount(itemId, StorageContainer.Case) > 0) { control.GetItemizer(this.HarakiriFishName, StorageContainer.Case); } } //Zaldonの近くかチェック if (api.Player.ZoneId != (int)Zone.Selbina || (api.Entity.GetEntity(NPCID_ZALDON).Distance != 0f && api.Entity.GetEntity(NPCID_ZALDON).Distance > 6)) { setRunningStatus(RunningStatusKind.Stop); setHarakiriStatus(HarakiriStatusKind.Error); setMessage("セルビナのZaldonの近くで実行してください"); return; } //メニュー開いていたら閉じる if (!control.CloseDialog(10)) { setRunningStatus(RunningStatusKind.Stop); setHarakiriStatus(HarakiriStatusKind.Error); setMessage("エラー:会話を終了させてから実行してください"); break; } //ターゲット設定 control.SetTargetFromId(NPCID_ZALDON); Thread.Sleep(settings.Global.WaitChat);//Wait //プレイヤーステータスがstandingになるまで待機 while (api.Player.Status != (uint)Status.Standing) { Thread.Sleep(settings.Global.WaitBase);//wait } //アイテムトレード api.ThirdParty.SendString(string.Format("/item {0} <t>", this.HarakiriFishName)); //チャット監視開始 string itemName = string.Empty; int noResponseCount = 0; var cl = new EliteAPI.ChatEntry(); while (this.RunningStatus == RunningStatusKind.Running) { if (!chat.GetNextChatLine(out cl)) { noResponseCount++; if (noResponseCount > 10) { setRunningStatus(RunningStatusKind.Stop); setHarakiriStatus(HarakiriStatusKind.Error); setMessage("ハラキリ対象の魚ですか? 反応無し中止"); break; } Thread.Sleep(settings.Global.WaitChat);//wait continue; } //チャット区分の取得 List <string> chatKbnArgs = new List <string>(); ChatKbnKind chatKbn = getChatKbnFromChatline(cl, out chatKbnArgs); logger.Debug("Chat:{0} ChatKbn:{1}", cl.Text, chatKbn); if (chatKbn == ChatKbnKind.Zaldon) { noResponseCount = 0; if (!settings.UseEnternity) { api.ThirdParty.KeyPress(Keys.RETURN); } } else if (chatKbn == ChatKbnKind.NotFound) { noResponseCount = 0; if (!putDatabase(itemName)) { setRunningStatus(RunningStatusKind.Stop); setHarakiriStatus(HarakiriStatusKind.Error); setMessage("データベースの更新に失敗しました"); break; } EventHarakiriOnce(this.HarakiriFishName, itemName);//イベント発生 setMessage("ハラキリ結果:何も見つからなかった"); if (!settings.UseEnternity) { api.ThirdParty.KeyPress(Keys.RETURN); } } else if (chatKbn == ChatKbnKind.Found) { noResponseCount = 0; itemName = chatKbnArgs[0]; if (!putDatabase(itemName)) { setRunningStatus(RunningStatusKind.Stop); setHarakiriStatus(HarakiriStatusKind.Error); setMessage("データベースの更新に失敗しました"); break; } EventHarakiriOnce(this.HarakiriFishName, itemName);//イベント発生 setMessage(string.Format("ハラキリ結果:{0}を見つけた", itemName)); api.ThirdParty.KeyPress(Keys.RETURN); Thread.Sleep(settings.Global.WaitChat); } if (chatKbn == ChatKbnKind.Found || chatKbn == ChatKbnKind.NotFound) { noResponseCount = 0; Thread.Sleep(2000); //発見したら停止 if (chatKbn == ChatKbnKind.Found && settings.Harakiri.StopFound) { setRunningStatus(RunningStatusKind.Stop); setHarakiriStatus(HarakiriStatusKind.Normal); setMessage("アイテムを発見したので停止します"); } break; } Thread.Sleep(settings.Global.WaitBase); //wait } Thread.Sleep(settings.Global.WaitChat); //wait } logger.Debug("ハラキリスレッド終了"); }