Example #1
0
    // Use this for initialization
    void Start()
    {
        // choose the farest lookat
        lookat = GameObject.FindGameObjectWithTag ("dog").GetComponent<DogController> ().lookats [3];

        aiMoveCamera = new AIMoveCamera ();
        aiMoveCamera.Start (this);
        lastAI = new AITurn ();
        lastAI.Start (this);
    }
        public static bool TimedPatch_AIEnable(AITurn __instance)
        {
            Console.WriteLine("AITurn.OnEnable()");
            var t = Traverse.Create(__instance);

            t.Method("initialization").GetValue(); //__instance.initialization();

            Game.Input.Push(__instance);           //base.OnEnable();
            t.Field("disable").SetValue(false);    //__instance.disable = false;
            if (bTimed)
            {
                SimpleAIAsync_Timed(__instance);
                return(false);
            }
            t.Method("SimlpeAIAsync").GetValue();// __instance.SimlpeAIAsync();
            return(false);
        }
Example #3
0
    private AITurn ComputeTurn()
    {
        float[,] influenceMap = InfluenceMap.GetInfluenceMap(MapInfos, Team.Player);

        InfluenceMapDrawer drawer = GameObject.Find("InfluenceMapDrawer").GetComponent <InfluenceMapDrawer>();

        drawer.influenceMap = influenceMap;

        AITurn turn = new AITurn();

        turn.Actions = new List <AIAction>();

        AIActionMovement movement = new AIActionMovement();

        movement.GetHighestScore(influenceMap, CurrentCell.X, CurrentCell.Z, (int)MapInfos.Size.x, (int)MapInfos.Size.y, AttributesSheet.GetAttribute(AttributeType.MovementPoint));
        turn.Actions.Add(movement);

        /* while (enough AP to use a skill || enough MP to move) {
         *
         *  // if (enough AP to use a skill) {
         *
         *      - Get Available Skills
         *
         *      if (health == low && has a healing skill)
         *          Use healing skill
         *      else {
         *          - Get potential targets in Range
         *          - Get skill cellTarget
         *          - Add potential kills to turn
         *          - Add potential damage to turn
         *      }
         *
         *  } else (Move) {
         *      GetInfluenceMap(Team.Player);
         *      AIActionMovement movement = new AIActionMovement();
         *      if (CurrentHealth > 50%) {
         *          GetHighestScore();
         *      } else
         *          GetLowestScore();
         *      turns.Action.Add(movement);
         *  }
         */
        return(turn);
    }
Example #4
0
    void ChangeAI()
    {
        AIState state = lastAI.GetNextState ();
        lastAI.Finish ();

        if (state == AIState.None)
        {
            Instantiate(Resources.Load("Prefabs/Interact"));
            Destroy(gameObject);
            return;
        }

        AI ai;
        switch (state) {
        case AIState.Turn:
            ai = new AITurn();
            break;
        case AIState.Stay:
            ai = new AIStay();
            break;
        case AIState.Run:
            ai = new AIRun();
        break;
        case AIState.Sit:
            ai = new AISit();
            break;
        case AIState.Idle3:
            ai = new AIIdle3();
        break;
        default:
            ai = new AISit();
            break;
        }

        ai.Start(this);
        lastAI = ai;
    }
Example #5
0
 void Awake()
 {
     //called when an instance awakes in the game
     instance = this; //set our static reference to our newly initialized instance
 }
        // 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");
        }