using Emgu.CV;
using Emgu.CV.Structure;
using RichCreator.Dnf;
using RichCreator.Jobs.StateMachines;
using RichCreator.Utility;
using RichCreator.Utility.Captures;
using RichCreator.Utility.CV;
using RichCreator.Utility.InputControl;
using RichCreator.Utility.Maps;
using RichCreator.Utility.Structs;
using RichCreator.Utility.Utilitys;
using RichCreator.Utilitys;
using System;
using System.Collections.Generic;
using System.Threading;
namespace RichCreator.Maps.Kalete
{
///
/// 卡勒特地图
///
public class KaleteMap : ShikongzhimenMapBase
{
public KaleteMap(ZTRectangle gameRect, CancellationToken cancelToken) : base(MapType.Lingdong, gameRect, cancelToken)
{
this.MiniMap = new KaleteMiniMap(gameRect);
}
///
/// 地图的所有房间
/// NextIndex=-1,完成
/// NextIndex=-2,出错
///
private static readonly HouseInfo[] Houses = new HouseInfo[] {
new HouseInfo (0 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (1 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (2 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (3 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (4 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (5 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (6 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (7 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (8 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},new int[]{20,21,22,23 }),
new HouseInfo (9 ,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (10,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (11,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (12,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (13,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (14,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (15,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (16,MapType.Kalete,true ,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (17,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (18,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
new HouseInfo (19,MapType.Kalete,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null)
};
private Int32 runningStep = RunningStep.None;
///
/// 开始
///
///
///
///
///
public override ZTResult Start(Int32 runningStep)
{
this.runningStep = runningStep;
WindowUtils.SetDnfToTop();
if (runningStep < RunningStep.War)
{
if (!MoveToSunan())
{
return ZTResult.Failed;
}
if (!MoveToShikongzhimen())
{
return ZTResult.Failed;
}
if (!MoveToChoiceTaskPage())
{
return ZTResult.Failed;
}
if (!IntoHouse())
{
return ZTResult.Failed;
}
G.Instance.InfoWriter("成功进入副本");
}
while (true)
{
//重复刷,直到疲劳值不够了
if (this.CancelToken.IsCancellationRequested)
{
return ZTResult.Cancel;
}
DateTime startHouse = DateTime.Now;
ZTResult killResult = KillMonster();
if (killResult == ZTResult.Success)
{
//捡东西
G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.V);
Thread.Sleep(1000);
for (int i = 0; i < 5; i++)
{
G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.X);
Thread.Sleep(RandomUtils.KeyPressDuration * 3);
}
//卖装备并关闭商店
SaleEquipment();
Int32 houseTotalSecond = (Int32)(DateTime.Now - startHouse).TotalSeconds;
G.Instance.InfoWriter("单次刷图成功,用时:" + (houseTotalSecond / 60) + "分" + (houseTotalSecond % 60) + "秒");
//查询疲劳值
Int32 pilaozhi = DnfCVHelper.GetPiLaoZhi(this.GameRect);
G.Instance.InfoWriter("疲劳值:" + pilaozhi);
if (pilaozhi <= 0)
{
ExitToTown();
return ZTResult.Success;
}
ReplayGame();
continue;
}
else
{
return killResult;
}
}
}
///
/// 是否进入打怪地图
///
///
public override bool IsEntryMap()
{
//查找顶端卡勒特之初文字
bool findResult = FuncUtils.TimeoutCancelableWrap(2 * 60 * 1000, CancelToken, () =>
{
using (Image image = ScreenCapture.Instance.CaptureScreenReturnImage())
{
return KaleteCVHelper.ExistKaleteText(image, this.GameRect);
}
}, 10);
return findResult;
}
///
/// 进入房间后的预先工作
///
///
///
public override void EntryHousePrework(int houseIndex, int preHouseIndex)
{
//移动和发招
switch (houseIndex)
{
case 0:
this.Role.SyncMove(new ZTPoint(297, 0));
this.Role.ReleaseSkill(HIDCode.R);
this.Role.ReleaseSkill(HIDCode.E);
break;
case 1:
this.Role.SyncMove(new ZTPoint(241, 0));
this.Role.ReleaseSkill(HIDCode.Q);
this.Role.ReleaseSkill(HIDCode.W);
break;
case 6:
this.Role.SyncMove(new ZTPoint(139, 90));
this.Role.ReleaseSkill(HIDCode.G);
break;
case 7:
this.Role.SyncMove(new ZTPoint(330, 90));
this.Role.ReleaseSkill(HIDCode.R);
break;
case 8:
this.Role.SyncMove(new ZTPoint(305, 0));
this.Role.ReleaseSkill(HIDCode.H);
break;
case 13:
this.Role.SyncMove(new ZTPoint(-104, 82));
this.Role.ReleaseSkill(HIDCode.Q);
this.Role.ReleaseSkill(HIDCode.E);
break;
case 12:
this.Role.SyncMove(new ZTPoint(-550, 90));
this.Role.ReleaseSkill(HIDCode.T);
break;
case 17:
this.Role.SyncMove(new ZTPoint(-200, 60));
this.Role.ReleaseSkill(HIDCode.Q);
this.Role.ReleaseSkill(HIDCode.F);//用w代替
break;
case 16:
this.Role.SyncMove(new ZTPoint(-174, 0));
this.Role.ReleaseSkill(HIDCode.Y);
break;
}
}
///
/// 刷房间
///
///
private ZTResult KillMonster()
{
bool ret = false;
if (!IsEntryMap())
{
G.Instance.InfoWriter("未找到进入凛冬");
return ZTResult.Failed;
}
G.Instance.InfoWriter("进入卡勒特");
Int32 preHouseIndex = -1;
Int32 houseIndex = -1;
//技能加成
G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Space);
//循环刷房间
while (true)
{
preHouseIndex = houseIndex;
//看房间号
ret = this.MiniMap.GetCurrentHouseIndexWaitTimeout(out houseIndex, null, this.CancelToken, 3 * 1000);
if (!ret)
{
G.Instance.InfoWriter("未找到人物所在房间");
return ZTResult.Failed;
}
G.Instance.InfoWriter("进入房间->" + houseIndex.ToString());
HouseInfo houseInfo = Houses[houseIndex];
this.Role.SetHouse(houseInfo);
DateTime startTime = DateTime.Now;
KillMonsterStateMachine kmsm = new KillMonsterStateMachine(this, houseInfo,this.Role);
ZTResult smresult = kmsm.Work(2 * 60 * 1000,preHouseIndex,this.runningStep);
Int32 roomTotalSecond = (Int32)(DateTime.Now - startTime).TotalSeconds;
G.Instance.InfoWriter("房间刷完,用时:" + (roomTotalSecond / 60) + "分" + (roomTotalSecond % 60) + "秒");
runningStep = RunningStep.None;
if (smresult == ZTResult.Success)
{
if (houseInfo.IsEnd)
{
//所有房间刷完
return ZTResult.Success;
}
//刷其它房间
continue;
}
else
{
return smresult;
}
}
}
///
/// 进入指定房间
///
///
private bool IntoHouse()
{
bool result = false;
//选择卡勒特之初
G.Instance.InfoWriter("开始选择卡勒特之初");
Int32 nandu = 0;
if (!SelectKalete(out nandu))
{
G.Instance.InfoWriter("选择卡勒特之初失败");
return false;
}
G.Instance.InfoWriter("选择卡勒特之初成功,难度:" + nandu);
if (nandu != 4)
{
G.Instance.InfoWriter("开始选择难度");
result = SelectNandu(nandu);
if (!result)
{
G.Instance.InfoWriter("选择难度失败");
return false;
}
G.Instance.InfoWriter("选择难度成功");
}
//开始
G.Instance.InputControl.PressKey(80, HIDCode.Space);
return true;
}
///
/// 选择凛冬
///
///
private bool SelectKalete(out Int32 nandu)
{
Image image = ScreenCapture.Instance.CaptureScreenReturnImage();
if (KaleteCVHelper.GetChoiceKaleteNandu(out nandu, image, this.GameRect))
{
return true;
}
G.Instance.InputControl.MoveToAndClick(new ZTPoint(this.GameRect.Start.X + 568, this.GameRect.Start.Y + 141));
Thread.Sleep(5000);
image = ScreenCapture.Instance.CaptureScreenReturnImage();
if (KaleteCVHelper.GetChoiceKaleteNandu(out nandu, image, this.GameRect))
{
return true;
}
return false;
}
///
/// 选择难度
///
///
///
///
private bool SelectNandu(Int32 nandu)
{
Int32 count = 4 - nandu;
for (int i = 0; i < Math.Abs(count); i++)
{
if (count < 0)
{
G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.LeftArrow);
}
else
{
G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightArrow);
}
Thread.Sleep(400);
}
Image image = ScreenCapture.Instance.CaptureScreenReturnImage();
if (!KaleteCVHelper.GetChoiceKaleteNandu(out nandu, image, this.GameRect))
{
return false;
}
if (nandu == 4)
{
return true;
}
return false;
}
}
}