コード例 #1
0
    public override bool OnMessage(FieldPlayer player, Telegram_CH4 telegram)
    {
        switch (telegram.GetMessageIndex())
        {
            case SoccerMessages.Msg_ReceiveBall:
                {
                    // set the target for this player
                    player.Steering().SetTarget(telegram.infos.position);
                    // change the state.
                    player.GetFSM().ChangeState(ReceiveBall.instance);

                    return true;
                }
            case SoccerMessages.Msg_SupportAttacker:
                {
                    if (player.GetFSM().IsInstate(SupportAttacker.instance))
                    {
                        return true;
                    }
                    player.Steering().SetTarget(SupportSpotCalculator.instance.DetermineBestSupportingPosition(player.transform.parent.GetComponent<SoccerTeam>().teamColor));

                    player.GetFSM().ChangeState(SupportAttacker.instance);
                    return true;
                }
            case SoccerMessages.Msg_GoHome:
                {
                    player.SetHomeRegion(player.transform.parent.GetComponent<SoccerTeam>().initialRegion[int.Parse(player.transform.name) - 1]);
                    player.GetFSM().ChangeState(ReturnToHomeRegion.instance);
                    return true;
                }
            case SoccerMessages.Msg_Wait:
                {
                    player.GetFSM().ChangeState(Wait.instance);
                    return true;
                }
            case SoccerMessages.Msg_PassToMe:
                {
                    FieldPlayer receiver = telegram.infos.gameObject.GetComponent<FieldPlayer>();

                    if (player.Team().Receiver() != null && !player.BallWithKickingRange())
                    {
                        return true;
                    }

                    player.Ball().SetOwner(receiver.gameObject);

                    player.Ball().Kick((receiver.transform.position - player.Ball().transform.position).normalized, Prm.instance.MaxPassingForce);
                    MessageDispatcher_CH4.instance.DispatchMessage(0f, player.Id(), receiver.Id(), SoccerMessages.Msg_ReceiveBall, receiver.transform);

                    player.GetFSM().ChangeState(Wait.instance);

                    player.FindSupport();
                    return true;
                }
        }

        return false;

    }
コード例 #2
0
    public override bool OnMessage(GoalKeeper keeper, Telegram_CH4 telegram)
    {
        switch (telegram.GetMessageIndex())
        {
        case SoccerMessages.Msg_GoHome:
        {
            // set the target for this player(original location of keeper)
            keeper.Steering().SetTarget(keeper.Team().initialRegion[0]);
            // change the state.
            keeper.GetFSM().ChangeState(ReturnHome.instance);

            return(true);
        }

        case SoccerMessages.Msg_ReceiveBall:
        {
            keeper.GetFSM().ChangeState(InterceptBall.instance);
            return(true);
        }
        }
        return(false);
    }