public static async void OnEnable_Timed(BeginTurn state)
        {
            var       t         = Traverse.Create(state);
            var       selected  = t.Property("SelectedUnit");
            WuxiaUnit wuxiaUnit = Timed_Current();

            if (wuxiaUnit != null)
            {
                if (wuxiaUnit.faction != Faction.Player || autoBattle.Value)
                {
                    state.SendEvent("AI");
                }
                else
                {
                    if (wuxiaUnit[BattleRestrictedState.Fear] > 0)
                    {
                        await FearAllyAI_Timed(state);
                    }
                    t.Method("FirstUnitSelect").GetValue();//state.FirstUnitSelect();
                    state.SendEvent("FINISHED");
                }
            }
            else
            {
                BM.Time = BattleEventToggleTime.BeginTurn;
                BM.OnBattleEvent(BattleEventToggleTime.BeginTurn, Array.Empty <object>());
                BM.OnBattleEvent(BattleEventToggleTime.BeginAITurn, Array.Empty <object>());
                if (!BM.IsEvent)
                {
                    await FSM.UI.battleTurn.NextTurnAsync(true);

                    FSM.UI.battleTurn.Hide();
                    foreach (WuxiaUnit wuxiaUnit2 in BM.WuxiaUnits)
                    {
                        if (!wuxiaUnit2.IsDead)
                        {
                            wuxiaUnit2.OnTurnStart();
                        }
                    }
                    Timed_NextTurn();
                    WuxiaUnit wuxiaUnit3 = Timed_Current();
                    if (wuxiaUnit3 != null)
                    {
                        BM.Turn++;
                        if (wuxiaUnit3.faction != Faction.Player || autoBattle.Value)
                        {
                            state.SendEvent("AI");
                            return;
                        }
                        if (wuxiaUnit3[BattleRestrictedState.Fear] > 0)
                        {
                            await FearAllyAI_Timed(state);
                        }
                        t.Method("FirstUnitSelect").GetValue(); //state.FirstUnitSelect();
                        state.SendEvent("FINISHED");
                    }
                }
            }
            UpdateTimedUI();
        }
        public static async Task FearAllyAI_Timed(BeginTurn state)
        {
            var t        = Traverse.Create(state);
            var selected = t.Property("SelectedUnit");

            while (Timed_Current() != null && Timed_Current()[BattleRestrictedState.Fear] > 0)
            {
                await 0.25f;
                WuxiaUnit unit = Timed_Current();
                unit.OnBufferEvent(BufferTiming.BeginUnit);
                BM.CameraLookAt = unit.Cell.transform.position;
                List <WuxiaCell> moveInRange = t.Method("ShowMoveRange", unit).GetValue <List <WuxiaCell> >();//state.ShowMoveRange(unit);

                var ai = Traverse.Create(t.Property("FearAI").GetValue());
                ai.Field("Current").SetValue(unit);
                await 0.1f;
                AIActionInfo     aiactionInfo = ai.Method("Evaluate", moveInRange).GetValue <AIActionInfo>();//state.FearAI.Evaluate(moveInRange);
                List <WuxiaCell> list         = aiactionInfo?.path;
                List <WuxiaCell> shortestPath = new List <WuxiaCell>();
                int num = unit[BattleProperty.Move];
                foreach (WuxiaCell wuxiaCell in moveInRange)
                {
                    wuxiaCell.UnMark();
                }
                if (list.HasData <WuxiaCell>())
                {
                    foreach (WuxiaCell wuxiaCell2 in list)
                    {
                        shortestPath.Add(wuxiaCell2);
                        if (num == 0)
                        {
                            break;
                        }
                        wuxiaCell2.Mark(CellMarkType.WalkPath);
                        num--;
                    }
                    unit.Move(shortestPath[0], shortestPath);
                    while (unit.IsMoving)
                    {
                        await 0;
                    }
                    foreach (WuxiaCell wuxiaCell3 in shortestPath)
                    {
                        wuxiaCell3.UnMark();
                    }
                    unit.Actor.Move = false;
                }
                unit.OnUnitEnd();
                if (!unit.IsDead)
                {
                    unit.OnBufferEvent(BufferTiming.EndUnit);
                    Timed_EndUnit(unit.IsMoved, !unit.IsMoved);
                    UpdateTimedUI();
                }
            }
        }
 public static bool TimedPatch_BeginTurn1(BeginTurn __instance)
 {
     Console.WriteLine("BeginTurn.OnEnable()");
     if (bTimed)
     {
         OnEnable_Timed(__instance);
         return(false);
     }
     return(true);
 }
Пример #4
0
 public string[] GetDynamicArgs(BeginTurn action)
 {
     return(Group(action.Chief.Index));
 }