コード例 #1
0
    public override void _Ready()
    {
        this.World = (WorldManager)this.FindParent("WorldManager");


        this.root = new Sequence("SelfDefense", _ => this.VisibleMobs.Any(), new ShootNearestBaddie <Lamp>(this), new DelayTask(() => 500));

        this.GetNode <Area2D>("DetectionArea").Connect("body_entered", this, nameof(this.DetectedBodyEntered));
        this.GetNode <Area2D>("DetectionArea").Connect("body_exited", this, nameof(this.DetectedBodyExited));
    }
コード例 #2
0
ファイル: Bot.cs プロジェクト: tetious/SafeLight
    public override void _Ready()
    {
        this.World = (WorldManager)this.FindParent("WorldManager");
        this.GetNode<Area2D>("DetectionArea").Connect("body_entered", this, nameof(this.DetectedBodyEntered));
        this.GetNode<Area2D>("DetectionArea").Connect("body_exited", this, nameof(this.DetectedBodyExited));


        var gatherer = new Selector(("Gatherer"), _ => this.Type == BotType.Gatherer,
            new Sequence("ResourcePop", new StandingOnResourceTask(this), new GatherResourceTask(this)),
            new FindNearest<WorldResource>(this, this.World.GetNode("Map/Resources"))
        );

        var builder = new Selector("Builder", _ => this.Type == BotType.Builder,
            new Sequence("BuildPop", new BuildBuildable(this)),
            new FindNearest<Area2D>(this, this.World.GetNode("Map/ToBuild")),
            new DelayTask(() => 1000)
        );

        var selfDefense = new Sequence("SelfDefense", _ => this.VisibleMobs.Any(), new ShootNearestBaddie<Bot>(this), new DelayTask(() => 500));
        var move = new Selector("Move", s => s.AnyCanRun, new MoveTowardPathSegmentGoalTask<Bot>(this), new NextPathSegmentTask<Bot>(this));
        this.root = new Selector("Root", new Sequence("MoveSelfDefence", move, selfDefense), gatherer, builder);
    }