// 6 AI!! public static async void SimpleAIAsync_Timed(AITurn state) { var t = Traverse.Create(state); BM.Time = BattleEventToggleTime.BeginAITurn; while (Timed_Current() != null && (Timed_Current().faction != Faction.Player || autoBattle.Value)) { WuxiaUnit unit = Timed_Current(); List <WuxiaUnit> second = (from u in BM.WuxiaUnits where u.faction == unit.faction select u).ToList <WuxiaUnit>(); BM.WuxiaUnits.Except(second).ToList <WuxiaUnit>(); if (Timed_GetBeginTurn(unit)) { unit.OnBufferEvent(BufferTiming.BeginTurn); unit.CalculationNumber_Of_Movements(); Timed_SetBeginTurn(unit, false); } BM.OnBattleEvent(BattleEventToggleTime.BeginUnit, Array.Empty <object>()); if (BM.IsEvent) { Debug.Log("AI回合,等待事件結束"); } else { await 0.25f; bool isMove = false; bool isRest = true; if (unit.IsBattleEventCube) { Timed_EndUnit(false, true); continue; } unit.OnBufferEvent(BufferTiming.BeginUnit); if (!t.Field("disable").GetValue <bool>()) //*state.disable*/ { BM.CameraLookAt = unit.Cell.transform.position; List <WuxiaCell> moveInRange = t.Method("ShowMoveRange", unit).GetValue <List <WuxiaCell> >(); //state.ShowMoveRange(unit); await 0.1f; AIActionInfo useinfo = Traverse.Create(t.Method("GetBattleAI", unit).GetValue()).Method("Evaluate", moveInRange).GetValue <AIActionInfo>(); //state.GetBattleAI(unit).Evaluate(moveInRange); if (useinfo == null) { foreach (WuxiaCell wuxiaCell in moveInRange) { wuxiaCell.UnMark(); } Timed_EndUnit(isMove, isRest); UpdateTimedUI(); unit.ReCover(); BM.OnBattleEvent(BattleEventToggleTime.EndUnit, Array.Empty <object>()); unit.OnBufferEvent(BufferTiming.EndUnit); continue; } if (useinfo.skill != null && useinfo.attackCell == unit.Cell) { useinfo.attackCell = useinfo.moveEnd; } AIActionInfo aiactionInfo = useinfo; List <WuxiaCell> list = aiactionInfo?.path; List <WuxiaCell> shortestPath = new List <WuxiaCell>(); int num = unit[BattleProperty.Move]; foreach (WuxiaCell wuxiaCell2 in moveInRange) { wuxiaCell2.UnMark(); } if (list.HasData <WuxiaCell>()) { foreach (WuxiaCell wuxiaCell3 in list) { shortestPath.Add(wuxiaCell3); if (num == 0) { break; } wuxiaCell3.Mark(CellMarkType.WalkPath); num--; } unit.Move(shortestPath[0], shortestPath); while (unit.IsMoving) { isMove = true; await 0; } foreach (WuxiaCell wuxiaCell4 in shortestPath) { wuxiaCell4.UnMark(); } unit.Actor.Move = false; } if (unit[BattleRestrictedState.Daze] > 0 || unit[BattleRestrictedState.Seal] > 0 || unit.IsAction) { unit.OnUnitEnd(); } else if (useinfo.attackCell != null) { WuxiaCell point = useinfo.attackCell; List <WuxiaCell> attackInRange = t.Method("ShowAttackRange", useinfo.skill, unit.Cell).GetValue <List <WuxiaCell> >();//state.ShowAttackRange(useinfo.skill, unit.Cell); await 0.1f; foreach (WuxiaCell wuxiaCell5 in attackInRange) { wuxiaCell5.UnMark(); } List <WuxiaCell> targetInRange = state.GetTargetInRange(useinfo.skill, attackInRange, unit.Cell, point); await 0.1f; foreach (WuxiaCell wuxiaCell6 in targetInRange) { wuxiaCell6.UnMark(); } List <WuxiaUnit> list2 = new List <WuxiaUnit>(); for (int i = 0; i < targetInRange.Count; i++) { if (targetInRange[i].Unit != null && Traverse.Create(BM).Method("CheckSkillUnit", targetInRange[i], useinfo.skill, unit).GetValue <bool>() /*BM.CheckSkillUnit(targetInRange[i], useinfo.skill, unit)*/ && !list2.Contains(targetInRange[i].Unit)) { list2.Add(targetInRange[i].Unit); } } if (list2.Count > 0 || useinfo.skill.Item.DamageType == DamageType.Summon) { if (unit.SpecialSkill == "specialskill0101" && list2.Count > 0 && useinfo.skill.Item.DamageType == DamageType.Damage) { t.Method("PlayChangeElement", unit.LearnedSkills["specialskill0101"], unit, list2).GetValue(); //state.PlayChangeElement(unit.LearnedSkills["specialskill0101"], unit, list2); } t.Method("PlayAbility", useinfo.skill, point, unit, list2).GetValue(); //state.PlayAbility(useinfo.skill, point, unit, list2); } while (t.Field("isPlayAbility").GetValue <bool>()) //state.isPlayAbility) { BattleGlobalVariable.AddUsedSkill(unit.UnitID, useinfo.skill.Item.Id); isRest = false; await 0; } if (!(unit.SpecialSkill == useinfo.skill.Id)) { unit.OnUnitEnd(); } } else { unit.OnUnitEnd(); } if (unit.IsEndUnit) { if (!unit.IsDead) { Timed_EndUnit(isMove, isRest); UpdateTimedUI(); } BM.OnBattleEvent(BattleEventToggleTime.EndUnit, Array.Empty <object>()); } if (!unit.IsDead) { unit.OnBufferEvent(BufferTiming.EndUnit); continue; } continue; } } return; } await 0.1f; while (BM.IsEvent) { Debug.Log("AI回合,等待事件結束"); await 0.1f; } if (Timed_Current() != null) { t.Method("FirstUnitSelect").GetValue();//state.FirstUnitSelect(); } FSM.SendEvent("ENDTURN"); }