• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript screeps-profiler.registerObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中screeps-profiler.registerObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript registerObject函数的具体用法?TypeScript registerObject怎么用?TypeScript registerObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了registerObject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: trimExtraPartsToEnergyCapacity

   * Trims parts off of the given body array until the cost of the given body is
   * less than or equal to energyCapacity.
   * @param {number} energyCapacity
   * @param {BodyPartConstant[]} body
   */
  trimExtraPartsToEnergyCapacity(energyCapacity: number, body: BodyPartConstant[]): BodyPartConstant[] {
    const cost = this.bodyCost(body);

    if (cost > energyCapacity) {
      const trimmedBody: BodyPartConstant[] = [];
      let newCost = 0;
      for (const bodyPart of body) {
        if (newCost + BODYPART_COST[bodyPart] > energyCapacity) {
          return trimmedBody;
        }

        newCost += BODYPART_COST[bodyPart];
        trimmedBody.push(bodyPart);
      }
    }

    if (!body.length) {
      console.log("creepBody.trimExtraPartsToEnergyCapacity: Empty trimmedBody being returned.");
    }
    return body;
  }
};

profiler.registerObject(creepBody, "creepBody");
export { creepBody };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:creepBody.ts


示例2: findSourceIdMissingMiner

   * Check if any sources in this room are missing an assigned miner.
   * If there is a source that is missing a miner, this method returns the
   * id of that source. Returns undefined otherwise.
   * @param {Room} room
   */
  findSourceIdMissingMiner(room: Room): string | undefined {
    let result: string | undefined;

    _.forEach(room.memory.sourceAssignments, (sourceAssignment, sourceId) => {
      const miner = Game.creeps[sourceAssignment.minerName];
      if (!miner) {
        result = sourceId;
      } else if (!miner.spawning && sourceAssignment.path && sourceAssignment.path.length) {
        // if the miner will die in the time it takes a new miner to arrive,
        // then we need a new miner.
        const distanceFromSource = sourceAssignment.path.length;
        const MINER_TICKS_PER_MOVE = creepBody.calculateTicksPerMove(creepBody.miner);
        const MINER_SPAWN_TIME = creepBody.calculateSpawnTime(creepBody.miner);
        if (miner.ticksToLive! < (distanceFromSource * MINER_TICKS_PER_MOVE) + MINER_SPAWN_TIME) {
          result = sourceId;
        }
      }
    });

    return result;
  }
};

profiler.registerObject(roomFunctions, "room");
export { roomFunctions };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:room.ts


示例3:

          }
        });

        // prioritize healing creeps over repairing structures
        if (damagedCreeps.length) {
          tower.heal(damagedCreeps[0]);
        } else {
          const structures = tower.room.find(FIND_MY_STRUCTURES, this.TOWER_REPAIR_TARGET);

          let lowestHitsStructure;
          for (const structure of structures) {
            if (lowestHitsStructure === undefined ||
              structure.hits < lowestHitsStructure.hits) {
              lowestHitsStructure = structure;
            }
          }
          // Only repair if enough energy is saved up (in case of attacks)
          if (lowestHitsStructure &&
            tower.energy > this.TOWER_MINIMUM_ENERGY &&
            lowestHitsStructure.hits < this.TOWER_REPAIR_MAX_HEALTH) {
            tower.repair(lowestHitsStructure);
          }
        }
      }
    }
  }
};

profiler.registerObject(towerFunctions, "tower");
export { towerFunctions };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:tower.ts


示例4: placeStorage

      if (lowestTowersAssignedSource && lowestTowerAssignmentSourceId) {
        this.placeBuildingAdjacentToPathDestination(
          startPosition,
          lowestTowersAssignedSource.pos,
          STRUCTURE_TOWER
        );
        room.memory.sourceAssignments[lowestTowerAssignmentSourceId].towersAssigned++;
      }
    }
  },

  /**
   * Places the storage for this room near the room's controller.
   * @param {Room} room
   * @param {RoomPosition} startPosition
   */
  placeStorage(room: Room, startPosition: RoomPosition): void {
    const storageCount = this.countStructuresAndConstructionSites(room, STRUCTURE_STORAGE);
    if (storageCount < CONTROLLER_STRUCTURES[STRUCTURE_STORAGE][room.controller!.level]) {
      this.placeBuildingAdjacentToPathDestination(
        startPosition,
        room.controller!.pos,
        STRUCTURE_STORAGE
      );
    }
  }
};

profiler.registerObject(roomConstruction, "roomConstruction");
export { roomConstruction };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:roomConstruction.ts


示例5: run

import profiler from "screeps-profiler";

/**
 * Basic miner that takes advantage of being assigned to a source. Creeps of
 * this role will move to the source until they can gather from it, then
 * they will harvest until they die.
 */
const roleMiner = {
  /**
   * Runs role logic on the given creep.
   * @param {Creep} creep
   */
  run(creep: Creep) {
    const source = Game.getObjectById(creep.memory.assignedSourceId) as Source;
    if (creep.harvest(source) === ERR_NOT_IN_RANGE) {
      creep.moveTo(source, {
        visualizePathStyle: {
          stroke: "#ffaa00"
        }
      });
    }
  }
};

profiler.registerObject(roleMiner, "role.miner");
export { roleMiner };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:26,代码来源:role.miner.ts


示例6:

        creep.say("building spawn");
      }

      if (!creep.memory.colonizing) {
        creepBehavior.gatherFromClosestSource(creep);
      } else {
        // if the creep does not have the spawn constructionsiteID
        // in memory, get it.
        if (!creep.memory.colonySpawnSiteID) {
          creep.memory.colonySpawnSiteID = creep.room.find(FIND_MY_CONSTRUCTION_SITES, {
            filter: (structure) => {
              return structure.structureType === STRUCTURE_SPAWN;
            }
          })[0].id;
        }
        const colonySpawn = Game.getObjectById(creep.memory.colonySpawnSiteID) as ConstructionSite;
        if (creep.build(colonySpawn) === ERR_NOT_IN_RANGE) {
          creep.moveTo(colonySpawn, {
            visualizePathStyle: {
              stroke: "#ffffff"
            }
          });
        }
      }
    }
  }
};

profiler.registerObject(roleColonist, "role.colonist");
export { roleColonist };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:role.colonist.ts


示例7: run

 * Simple melee defender that rushes a hostile Creep in its room and attacks it.
 * Creeps of this role are idle, checking for new targets, otherwise.
 */
const roleDefender = {
  /**
   * Runs role logic on the given creep.
   * @param {Creep} creep
   */
  run(creep: Creep) {
    let target = Game.getObjectById(creep.memory.targetHostileCreep) as Creep;
    if (!target || target.room === creep.room) {
      target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
      if (target) {
        creep.memory.targetHostileCreep = target.id;
      }
    }

    if (target) {
      creep.moveTo(target, {
        visualizePathStyle: {
          stroke: "#ff0000"
        }
      });
      creep.attack(target);
    }
  }
};

profiler.registerObject(roleDefender, "role.defender");
export { roleDefender };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:role.defender.ts


示例8:

    if (claimFlag) {
      // Move towards the controller (even if not in the room)
      // until in range to claim the controller.
      if (creep.room.name !== claimFlag.pos.roomName) {
        creep.moveTo(claimFlag.pos, {
          visualizePathStyle: {
            stroke: "#B99CFB"
          }
        });
      } else {
        const claimResult = creep.claimController(creep.room.controller!);
        if (claimResult === ERR_NOT_IN_RANGE) {
          creep.moveTo(creep.room.controller!, {
            visualizePathStyle: {
              stroke: "#B99CFB"
            }
          });
        } else {
          console.log(creep.name + " cannot claim room due to error: " + claimResult);
        }
      }
    } else {
      console.log("Claimer " + creep.name + " Cannot find a newClaim flag.");
      creep.suicide();
    }
  }
};

profiler.registerObject(roleClaimer, "role.claimer");
export { roleClaimer };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:role.claimer.ts


示例9: displayCreateCreepVisual

    spawn: StructureSpawn,
    role: string,
    body: BodyPartConstant[] = [WORK, WORK, CARRY, MOVE],
    name?: string): string | ScreepsReturnCode {
    return this.createCreepWithMemory(spawn, { role }, body, name);
  },

  /**
   * Display a visual if the spawn is creating a creep.
   * @param {StructureSpawn} spawn
   */
  displayCreateCreepVisual(spawn: StructureSpawn) {
    if (spawn.spawning) {
      const spawningCreep = Game.creeps[spawn.spawning.name];
      const progressPercentage = Math.round(((spawn.spawning.needTime -
        (spawn.spawning.remainingTime - 1)) / spawn.spawning.needTime) * 100);
      spawn.room.visual.text(
        spawningCreep.memory.role + " " + spawningCreep.name +
        " (" + progressPercentage + "%)",
        spawn.pos.x + 1,
        spawn.pos.y, {
          align: "left",
          opacity: 0.8
        });
    }
  }
};

profiler.registerObject(spawnFunctions, "spawn");
export { spawnFunctions };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:spawn.ts


示例10: run

/**
 * Basic harvester that will gather from the closest source to this creep,
 * then return the energy to a nearby structure.
 */
const roleHarvester = {
  /**
   * Runs role logic on the given creep.
   * @param {Creep} creep
   */
  run(creep: Creep) {
    if (creep.memory.carting && creep.carry.energy === 0) {
      creep.memory.carting = false;
      creep.say("harvesting");
    }

    if (!creep.memory.carting && creep.carry.energy === creep.carryCapacity) {
      creep.memory.carting = true;
      creep.say("carting");
    }

    if (!creep.memory.carting) {
      creepBehavior.gatherFromClosestSource(creep);
    } else {
      creepBehavior.dropOffEnergyAtNearbyStructure(creep);
    }
  }
};

profiler.registerObject(roleHarvester, "role.harvester");
export { roleHarvester };
开发者ID:AlexABallWebDev,项目名称:screeps-scripts,代码行数:30,代码来源:role.harvester.ts



注:本文中的screeps-profiler.registerObject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript self.data类代码示例发布时间:2022-05-25
下一篇:
TypeScript screenfull.toggle函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap