コード例 #1
0
    private void AddDemoBehaviors()
    {
        var proxSensor = sensors.Find(part => part is ProximitySensor) as ProximitySensor;
        var visSensor  = sensors.Find(part => part is VisionSensor) as VisionSensor;
        var wheels     = parts.Find(part => part is WheelsController) as WheelsController;

        switch (team.UserID)
        {
        case "lp0":

            switch (info.ID)
            {
            case 0:
                behaviors.Add(new Behavior(this, proxSensor.OpponentIsInRange, () =>
                {
                    for (var i = 0; i < guns.Count; i++)
                    {
                        BotController opponent = proxSensor.GetNthOpponent(i);
                        if (opponent != null)
                        {
                            guns[i].FocusOn(opponent.gameObject.transform);
                            guns[i].Fire();
                        }
                    }

                    if (!proxSensor.ShouldMoveTowardsNearestOpponent())
                    {
                        wheels.SetForward(0f);
                    }
                }));

                break;

            case 1:
                behaviors.Add(new Behavior(this, proxSensor.OpponentIsInRange, () =>
                {
                    for (var i = 0; i < guns.Count; i++)
                    {
                        BotController opponent = proxSensor.GetNthOpponent(i);
                        if (opponent != null)
                        {
                            bool shouldHoldFire = visSensor.BotHasPartOfType(opponent, "Reflective Armor") &&
                                                  visSensor.PartsOnBotOfType <ReflectiveArmorController>(
                                opponent,
                                "Reflective Armor")[0].CanReflect();

                            guns[i].FocusOn(opponent.gameObject.transform);
                            if (!shouldHoldFire)
                            {
                                guns[i].Fire();
                            }
                        }
                    }

                    if (!proxSensor.ShouldMoveTowardsNearestOpponent())
                    {
                        wheels.SetForward(0f);
                    }
                }));
                break;
            }

            break;

        case "ax1477":

            switch (info.ID)
            {
            case 0:
                behaviors.Add(new Behavior(this, proxSensor.OpponentIsInRange, () =>
                {
                    for (var i = 0; i < guns.Count; i++)
                    {
                        var opponent = proxSensor.GetNthOpponent(i);
                        if (opponent != null)
                        {
                            guns[i].FocusOn(opponent.gameObject.transform);
                            guns[i].Fire();
                        }
                    }
                }));
                break;

            case 1:
                behaviors.Add(new Behavior(this, proxSensor.OpponentIsInRange, () =>
                {
                    for (var i = 0; i < guns.Count; i++)
                    {
                        var opponent = proxSensor.GetNthOpponent(i);
                        if (opponent != null)
                        {
                            guns[i].FocusOn(opponent.gameObject.transform);
                            guns[i].Fire();
                        }
                    }

                    if (!proxSensor.ShouldMoveTowardsNearestOpponent())
                    {
                        wheels.SetForward(0f);
                    }
                }));
                break;
            }

            break;
        }

        if (wheels != null)
        {
            behaviors.Add(Behavior.BasicOffense(this, wheels));
        }
    }