<commit_before>import { BaseTask, Task } from './task';

interface TaskTarget {
  id?: string;
  name?: string;
  pos: RoomPosition;
}

export abstract class TargettedTask<T extends TaskTarget> extends BaseTask {

  public get pos() {
    return this.target && this.target.pos;
  }

  constructor(public target: T, creep?: Creep) {
    super(creep);
  }

  public run(): void {
    if (this.hasValidTarget()) {
      super.run();
    } else if (this.creep) {
      this.creep.stopTask();
    }
  }

  public isSameAs(other: Task): boolean {
    return super.isSameAs(other) && other instanceof TargettedTask && this.isSameTargetAs(other.target);
  }

  public toString(): string {
    return `${this.type}(${this.target},${this.priority})`;
  }

  public hasValidTarget(): boolean {
    return this.isValidTarget(this.target);
  }

  public abstract isValidTarget(_target: T): boolean;

  public toJSON(): any {
    return { type: this.type, target: this.targetToJSON(this.target) };
  }

  public fromJSON({target}: any): void {
    this.target = this.targetFromJSON(target);<commit_msg>stopTask leftover.<commit_after>import { BaseTask, Task } from './task';

interface TaskTarget {
  id?: string;
  name?: string;
  pos: RoomPosition;
}

export abstract class TargettedTask<T extends TaskTarget> extends BaseTask {

  public get pos() {
    return this.target && this.target.pos;
  }

  constructor(public target: T, creep?: Creep) {
    super(creep);
  }

  public run(): void {
    if (this.hasValidTarget()) {
      super.run();
    } else if (this.creep) {
      this.creep.stopTask(`Target ${this.target} is not valid anymore`);
    }
  }

  public isSameAs(other: Task): boolean {
    return super.isSameAs(other) && other instanceof TargettedTask && this.isSameTargetAs(other.target);
  }

  public toString(): string {
    return `${this.type}(${this.target},${this.priority})`;
  }

  public hasValidTarget(): boolean {
    return this.isValidTarget(this.target);
  }

  public abstract isValidTarget(_target: T): boolean;

  public toJSON(): any {
    return { type: this.type, target: this.targetToJSON(this.target) };
  }

  public fromJSON({target}: any): void {
    this.target = this.targetFromJSON(target);
{'fraction_non_alphanumeric': 0.14337078651685392, 'fraction_numerical': 0.0, 'mean_word_length': 3.6471816283924845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7424362', 'n_tokens_mistral': 711, 'n_tokens_neox': 695, 'n_words': 169}