Example #1
0
    public override void onTaskStop()
    {
        base.onTaskStop();

        if (this.bed != null)
        {
            // Try to move away from the bed so it "looks free".
            // If there no walkable space, stay on the bed.  Others will still be able to claim it.
            Position?freeSpot = this.getFreeSpot(this.owner.position);
            if (freeSpot == null)
            {
                freeSpot = this.getFreeSpot(this.owner.position + Rotation.UP); // Head of the bed.
            }

            if (freeSpot != null)
            {
                NavPath path = this.agent.calculatePath(
                    (Position)freeSpot,
                    false);

                if (path != null)
                {
                    this.agent.setPath(path);
                }
            }

            this.bed.setOccupant(null);
            this.owner.setSleeping(false);
        }

        this.bed = null;

        this.owner.emote.cancelEmote();
    }
Example #2
0
    public override bool shouldExecute()
    {
        if (this.owner.energy.value <= this._seekBedAt + this.owner.info.personality.sleepStartOffset)
        {
            // Find a bed.
            this.bed = this.calculateAndSetPathToClosest <CellBehaviorBed>(
                false,
                behavior => !behavior.isOccupied());

            if (this.bed != null)
            {
                this.bed.setOccupant(this.owner); // Reserve it, so no one takes it.
                return(true);
            }
            else
            {
                this.owner.emote.startEmote(new Emote("exclamation", 0.1f).setTooltip("Can't find a bed"));
            }
        }

        return(false);
    }