Compare commits
	
		
			2 Commits
		
	
	
		
			0fa23009ad
			...
			57277eff2d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 57277eff2d | |||
| 182e672086 | 
							
								
								
									
										3
									
								
								document/command.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								document/command.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "建筑":"storage.db['rooms.objects'].find({ type: 'constructionSite' }).then(resp => resp.map(cs => storage.db['rooms.objects'].findOne({ _id: cs._id }).then(csDetail => storage.db['rooms.objects'].update({_id: cs._id }, {$set: { progress: csDetail.progressTotal - 1 }}))))"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -20,7 +20,7 @@ export const loop = errorMapper(() => {
 | 
				
			|||||||
        } else if (creep.memory.role == "Upgrader") {
 | 
					        } else if (creep.memory.role == "Upgrader") {
 | 
				
			||||||
            Upgrade(creep);
 | 
					            Upgrade(creep);
 | 
				
			||||||
        } else if (creep.memory.role == "Builder") {
 | 
					        } else if (creep.memory.role == "Builder") {
 | 
				
			||||||
            Build(creep, STRUCTURE_CONTAINER);
 | 
					            Build(creep);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
import { MAIN_SOURCE_ID } from "./setting";
 | 
					import { MAIN_SOURCE_ID } from "./setting";
 | 
				
			||||||
import { FindCapacity, GetConstructureSet, GetSource } from "./util";
 | 
					import { FindCapacity, GetConstructureSet, GetContainer, GetSource } from "./util";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function Build(creep: Creep, structureType: string | null = null) {
 | 
					export function Build(creep: Creep, structureType: string | null = null) {
 | 
				
			||||||
    if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
 | 
					    if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
 | 
				
			||||||
@@ -27,9 +27,9 @@ export function Build(creep: Creep, structureType: string | null = null) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        creep.memory.working = false
 | 
					        creep.memory.working = false
 | 
				
			||||||
        let source = GetSource(MAIN_SOURCE_ID);
 | 
					        var target = GetContainer(creep);
 | 
				
			||||||
        if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
 | 
					        if (creep.withdraw(target[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
 | 
				
			||||||
            creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
 | 
					            creep.moveTo(target[0], { visualizePathStyle: { stroke: '#ffaa00' } });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,8 +1,11 @@
 | 
				
			|||||||
import { FindCapacity, GetSource } from "./util"
 | 
					import { FindCapacity, GetContainer, GetSource } from "./util"
 | 
				
			||||||
import { MAIN_SOURCE_ID } from "./setting";
 | 
					import { MAIN_SOURCE_ID } from "./setting";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function Harvest(creep: Creep) {
 | 
					export function Harvest(creep: Creep) {
 | 
				
			||||||
    if (creep.store.getFreeCapacity() > 0) {
 | 
					    if (creep.store.getFreeCapacity() == null) {
 | 
				
			||||||
 | 
					        BigHarvest(creep);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else if (creep.store.getFreeCapacity() > 0) {
 | 
				
			||||||
        let source: Source = GetSource(MAIN_SOURCE_ID);
 | 
					        let source: Source = GetSource(MAIN_SOURCE_ID);
 | 
				
			||||||
        if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
 | 
					        if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
 | 
				
			||||||
            creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
 | 
					            creep.moveTo(source, { visualizePathStyle: { stroke: "#ffaa00" } });
 | 
				
			||||||
@@ -10,9 +13,18 @@ export function Harvest(creep: Creep) {
 | 
				
			|||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        let targets = FindCapacity(creep);
 | 
					        let targets = FindCapacity(creep);
 | 
				
			||||||
        if (targets.length > 0) {
 | 
					        if (targets.length > 0) {
 | 
				
			||||||
            if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE){
 | 
					            if (creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
 | 
				
			||||||
                creep.moveTo(targets[0], { visualizePathStyle: { stroke: "#ffffff" } });
 | 
					                creep.moveTo(targets[0], { visualizePathStyle: { stroke: "#ffffff" } });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function BigHarvest(creep: Creep) {
 | 
				
			||||||
 | 
					    let source: Source = GetSource(MAIN_SOURCE_ID);
 | 
				
			||||||
 | 
					    let container = GetContainer(creep);
 | 
				
			||||||
 | 
					    if (container[0].store.getFreeCapacity(RESOURCE_ENERGY) == 0) { }
 | 
				
			||||||
 | 
					    else if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
 | 
				
			||||||
 | 
					        creep.moveTo(container[0], { visualizePathStyle: { stroke: "#ffaa00" } });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
let HARVESTER_COUNT: number = 2;
 | 
					let HARVESTER_COUNT: number = 0;
 | 
				
			||||||
let BUILDER_COUNT: number = 3;
 | 
					let BUILDER_COUNT: number = 1;
 | 
				
			||||||
let UPGRADER_COUNT: number = 5;
 | 
					let UPGRADER_COUNT: number = 6;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let MAIN_SOURCE_ID: Id<Source> = "ef990774d80108c" as Id<Source>;
 | 
					let MAIN_SOURCE_ID: Id<Source> = "ef990774d80108c" as Id<Source>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +1,11 @@
 | 
				
			|||||||
import { MAIN_SOURCE_ID } from "./setting";
 | 
					import { MAIN_SOURCE_ID } from "./setting";
 | 
				
			||||||
import { GetSource } from "./util";
 | 
					import { GetContainer, GetSource } from "./util";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**@param {Creep} creep */
 | 
					/**@param {Creep} creep */
 | 
				
			||||||
export function Upgrade(creep: Creep) {
 | 
					export function Upgrade(creep: Creep) {
 | 
				
			||||||
    if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
 | 
					    if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
 | 
				
			||||||
        creep.memory.working = false;
 | 
					        creep.memory.working = false;
 | 
				
			||||||
        creep.say('🔄 harvest');
 | 
					        creep.say('🔄 carry');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!creep.memory.working && creep.store.getFreeCapacity() == 0) {
 | 
					    if (!creep.memory.working && creep.store.getFreeCapacity() == 0) {
 | 
				
			||||||
        creep.memory.working = true;
 | 
					        creep.memory.working = true;
 | 
				
			||||||
@@ -18,9 +18,9 @@ export function Upgrade(creep: Creep) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
        var source = GetSource(MAIN_SOURCE_ID);
 | 
					        var target = GetContainer(creep);
 | 
				
			||||||
        if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
 | 
					        if (creep.withdraw(target[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
 | 
				
			||||||
            creep.moveTo(source, { visualizePathStyle: { stroke: '#ffaa00' } });
 | 
					            creep.moveTo(target[0], { visualizePathStyle: { stroke: '#ffaa00' } });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -4,7 +4,8 @@ export function FindCapacity(creep: Creep): AnyStructure[] {
 | 
				
			|||||||
            let type = structure.structureType;
 | 
					            let type = structure.structureType;
 | 
				
			||||||
            return (
 | 
					            return (
 | 
				
			||||||
                (type == STRUCTURE_EXTENSION ||
 | 
					                (type == STRUCTURE_EXTENSION ||
 | 
				
			||||||
                    type == STRUCTURE_SPAWN) &&
 | 
					                    type == STRUCTURE_SPAWN||
 | 
				
			||||||
 | 
					                    type == STRUCTURE_CONTAINER) &&
 | 
				
			||||||
                structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
 | 
					                structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -23,3 +24,14 @@ export function GetConstructureSet(creep: Creep, structureType: string | null =
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function GetConstructure(creep: Creep, structureType: string, ){
 | 
				
			||||||
 | 
					    return creep.room.find(FIND_STRUCTURES, {filter:(structure: AnyStructure)=>{
 | 
				
			||||||
 | 
					        return structure.structureType == structureType;
 | 
				
			||||||
 | 
					    }})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function GetContainer(creep: Creep): StructureContainer[]{
 | 
				
			||||||
 | 
					    let target = GetConstructure(creep, STRUCTURE_CONTAINER) as StructureContainer[];
 | 
				
			||||||
 | 
					    return target
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user