private void ApplyAttackingPawnJob(Pawn pawn) { var pId = pawn.thingIDNumber; AttackPawnCommand comm = null; bool stopJob = !AttackingPawnDic.ContainsKey(pId) || !AttackingPawnJobDic.TryGetValue(pId, out comm); try { var tick = (long)Find.TickManager.TicksGame; APJBT check; if (ApplyPawnJobByTick.TryGetValue(pId, out check)) { //Если в один тик мы второй раз пытаемся установить задачу, значит система её сразу отменяет //В этом случае сбрасываем задачу, считаем что цель достигнута или недоступна if (check.Comm == comm && check.Tick == tick) { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("HostAttackUpdate ApplyAttackingPawnJob stopJob(repeat) " + comm.TargetPos.Get().ToString()); } stopJob = true; } } //UIEventNewJobDisable = true; Thing target = null; if (!stopJob && (comm.Command == AttackPawnCommand.PawnCommand.Attack || comm.Command == AttackPawnCommand.PawnCommand.AttackMelee)) { var mapPawns = GameMap.mapPawns.AllPawnsSpawned; target = mapPawns.Where(p => p.thingIDNumber == comm.TargetID).FirstOrDefault(); if (target == null) { target = GameMap.listerThings.AllThings.Where(p => p.thingIDNumber == comm.TargetID).FirstOrDefault(); } if (target == null) { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("HostAttackUpdate ApplyAttackingPawnJob TargetThing == null " + comm.HostPawnID.ToString()); } stopJob = true; } } if (!stopJob) { if (comm.Command == AttackPawnCommand.PawnCommand.Attack) { //задаем команду атаковать if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("HostAttackUpdate ApplyAttackingPawnJob StartJob Attack " + comm.TargetID.ToString()); } pawn.jobs.StartJob(new Job(JobDefOf.AttackStatic, target) { playerForced = true, expiryInterval = int.MaxValue, checkOverrideOnExpire = false, } , JobCondition.InterruptForced); } else if (comm.Command == AttackPawnCommand.PawnCommand.AttackMelee) { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("HostAttackUpdate ApplyAttackingPawnJob StartJob AttackMelee " + comm.TargetID.ToString()); } pawn.jobs.StartJob(new Job(JobDefOf.AttackMelee, target) { playerForced = true, expiryInterval = int.MaxValue, checkOverrideOnExpire = false, } , JobCondition.InterruptForced); } else if (comm.Command == AttackPawnCommand.PawnCommand.Goto) { //задаем команду идти if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("HostAttackUpdate ApplyAttackingPawnJob StartJob Goto " + comm.TargetPos.Get().ToString()); } pawn.jobs.StartJob(new Job(JobDefOf.Goto, comm.TargetPos.Get()) { playerForced = true, expiryInterval = int.MaxValue, checkOverrideOnExpire = false, } , JobCondition.InterruptForced); } else { stopJob = true; } } if (stopJob) { if (AttackingPawnJobDic.ContainsKey(pId)) { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("HostAttackUpdate ApplyAttackingPawnJob Remove Job " + comm.TargetPos.Get().ToString()); } AttackingPawnJobDic.Remove(pId); } pawn.jobs.StartJob(new Job(JobDefOf.Wait_Combat) { playerForced = true, expiryInterval = int.MaxValue, checkOverrideOnExpire = false, } , JobCondition.InterruptForced); } else { ApplyPawnJobByTick[pId] = new APJBT() { Comm = comm, Tick = tick }; } } catch (Exception exp) { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("HostAttackUpdate ApplyAttackingPawnJob " + exp.ToString()); } if (AttackingPawnJobDic.ContainsKey(pId)) { AttackingPawnJobDic.Remove(pId); } } //UIEventNewJobDisable = false; }
public void UIEventNewJob(Pawn pawn, Job job) //если job == null значит команда стоять и не двигаться Wait_Combat { try { int id; if (!AttackerPawns.TryGetValue(pawn, out id)) { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("AttackUpdate UIEventNewJob Out of event " + pawn.Label + " " + pawn.thingIDNumber.ToString()); } return; } var comm = new AttackPawnCommand() { HostPawnID = id }; if (job != null) { if (job.targetA.HasThing) { int tid; if (!ThingsIDDic.TryGetValue(job.targetA.Thing.thingIDNumber, out tid)) { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("AttackUpdate UIEventNewJob Error " + pawn.Label + " ThingID " + job.targetA.Thing.Label + " " + job.targetA.Thing.thingIDNumber.ToString()); } return; } comm.TargetID = tid; } else { comm.TargetPos = new IntVec3S(job.targetA.Cell); } if (job.def == JobDefOf.AttackStatic) { comm.Command = AttackPawnCommand.PawnCommand.Attack; } else if (job.def == JobDefOf.AttackMelee) { comm.Command = AttackPawnCommand.PawnCommand.AttackMelee; } else if (job.def == JobDefOf.Goto) { comm.Command = AttackPawnCommand.PawnCommand.Goto; } else { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("AttackUpdate UIEventNewJob " + pawn.Label + " job=" + (job == null ? "null" : job.def.defName.ToString()) + " -> ignore"); } return; //левые команды игнорятся, но перед ними идет отмена предыдущего с job == null //comm.Command = AttackPawnCommand.PawnCommand.Wait_Combat; } } else { if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("AttackUpdate UIEventNewJob " + pawn.Label + " job=" + (job == null ? "null" : job.def.defName.ToString()) + " -> ignore2"); } return; //comm.Command = AttackPawnCommand.PawnCommand.Wait_Combat; } if (MainHelper.DebugMode && pawn.Label == "Douglas, Клерк") { Loger.Log("AttackUpdate UIEventNewJob " + pawn.Label + " job=" + (job == null ? "null" : job.def.defName.ToString()) + " -> " + comm.Command.ToString()); } ToSendCommand[id] = comm; } catch (Exception exp) { Loger.Log("AttackUpdate UIEventNewJob " + exp.ToString()); } }