本文整理汇总了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 };
示例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 };
示例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 };
示例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 };
示例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 };
示例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 };
示例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 };
示例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 };
示例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 };
示例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 };