Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
2.7 kB
1
Indexable
Never
        class GoToThrowSpotState : MinionState
        {
            public override string Name => GoToThrowSpotStateName;


            public override void Init(IFiniteStateMachine<MinionFSMData> parentFSM, MinionFSMData minFSMData)
            {
                base.Init(parentFSM, minFSMData);
            }

            public override void Enter()
            {
                base.Enter();

                if (Mgr.FindClosestNonPrisonerOpponentIndex(Minion.transform.position, Team, out opponentIndex))
                {
                    if (hasOpponent = Mgr.GetOpponentInfo(Team, opponentIndex, out opponentInfo))
                    {
                        Minion.FaceTowards(opponentInfo.Pos);
                    }
                }

            }

            public override void Exit(bool globalTransition)
            {

            }

            public override StateTransitionBase<MinionFSMData> Update()
            {

                // Just in case something bad happened
                if (!Minion.HasBall)
                {
                    return ParentFSM.CreateStateTransition(CollectBallStateName);
                }

                // Check if there is an opponent
                if (hasOpponent)
                {
                    // Check the throw selection
                    var selection = ShotSelection.SelectThrow(Minion, opponentInfo, navmask, MaxAllowedThrowPositionError, Time.deltaTime, out var projectileDir, out var projectileSpeed, out var interceptT, out var interceptPos);

                    // If the throw selection is valid, transition to ThrowBallState
                    if (selection == ShotSelection.SelectThrowReturn.DoThrow)
                    {
                        return ParentFSM.CreateStateTransition(ThrowBallStateName);
                    }

                    Vector3 directionToOpponent = (opponentInfo.Pos - Minion.transform.position).normalized;
                    Vector3 newTargetPosition = Minion.transform.position + directionToOpponent * 2;

                    Minion.GoTo(newTargetPosition);
                }

                // Check if the minion has reached the target
                if (Minion.ReachedTarget())
                {
                    if (FindRescuableTeammate(out var m))
                    {
                        return ParentFSM.CreateStateTransition<MinionScript>(RescueStateName, m, true);
                    }
                    else
                    {
                        return ParentFSM.CreateStateTransition(ThrowBallStateName);
                    }
                }

                return null;
            }
        }
Leave a Comment