Skip to content

Instantly share code, notes, and snippets.

@kuboon
Last active November 28, 2022 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuboon/1a2e6e8487c7d866fa9e331af5be0fc7 to your computer and use it in GitHub Desktop.
Save kuboon/1a2e6e8487c7d866fa9e331af5be0fc7 to your computer and use it in GitHub Desktop.
phasefabric 補充, 回復
// https://mlogjs.github.io/mlogjs/editor.html
const pid = Vars.thisx * 10000 + Vars.thisy * 10;
const flagGo = pid;
// const flagRepair = pid + 1;
unitBind(Units.mega);
const [, , , core] = unitLocate.building({
group: "core",
enemy: false,
});
while (true) {
printFlush(getBuilding("message1"))
let target
let [comingEnemy] = unitLocate.damaged()
if (comingEnemy) {
target = needsFabric(null);
}
let coreFab = sensor(Items.phaseFabric, core)
print`v2 enemy: ${comingEnemy}`
let unitsCount = 0;
let startTick = Vars.tick;
let lastUnit = Vars.unit;
do {
unitBind(Units.mega);
unitsCount++;
print`\n${unitsCount}:`
if (Vars.unit.health < Vars.unit.maxHealth) {
const [found, x, y] = unitLocate.building({
group: "repair",
enemy: false,
});
if (found) {
unitControl.approach({ x, y, radius: 6 })
print("go to nearest repair,")
} else {
const turret1 = getBuilding('turret1')
if (turret1) {
goBuilding(turret1)
print("go to turret1,")
}
}
continue;
}
if (avoidDanger()) continue;
switch (Vars.unit.flag) {
case 0:
if (core && coreFab > 480 && Vars.unit.phaseFabric < 10) {
if (goBuilding(core)) {
unitControl.itemTake(core, Items.phaseFabric, core.phaseFabric / 24);
}
} else if (target) {
print`go ${target},`
unitControl.flag(flagGo)
goBuilding(target)
unitControl.itemDrop(target, Vars.unit.totalItems);
target = needsFabric(target);
}
break;
case flagGo:
print("flagGo,")
if (target) {
print`to ${target} `
if (goBuilding(target)) {
print("and drop,")
unitControl.itemDrop(target, Vars.unit.totalItems);
unitControl.flag(0)
}
target = needsFabric(target);
} else {
unitControl.flag(0)
}
break;
default:
// asm`ucontrol unbind 0 0 0 0 0`;
}
} while (lastUnit != Vars.unit && unitsCount < 30)
print`end\nunits: ${unitsCount}, sec: ${Math.floor((Vars.tick - startTick)/6)/10}`
}
function needsFabric(nextOf: AnyBuilding) {
let index = 0
let found = !nextOf;
while (index < Vars.links) {
let myBlock = getLink(index);
index++;
if (nextOf == myBlock) {
found = true
continue
}
if(!found) continue
if (myBlock.type == Blocks.mendProjector ||
myBlock.type == Blocks.forceProjector){
if(myBlock.phaseFabric < 3) return myBlock
}
}
return null;
}
function goBuilding(b: AnyBuilding) {
const { x, y } = b;
if (unitControl.within({ x, y, radius: 5 })) {
return true
} else {
unitControl.approach({ x, y, radius: 4 });
return false
}
}
function avoidDanger() {
// const danger = { x0: 210, y0: 200, x1: 230, y1: 170 }
const dangerRange = 15
const ux = Vars.unit.x
const uy = Vars.unit.y
let dy = uy - 400 + ux
if (200 < ux && ux < 240) {
if (-dangerRange < dy && dy < 0) {
unitControl.move(ux - dangerRange, uy - dangerRange)
return true
} else if (0 <= dy && dy < dangerRange) {
unitControl.move(ux + dangerRange, uy + dangerRange)
return true
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment