mana
Initial commit
bendn 2022-08-11
commit 3722f46
-rw-r--r--LICENSE21
-rw-r--r--README.md2
-rw-r--r--icon.pngbin0 -> 859 bytes
-rw-r--r--mod.hjson11
-rw-r--r--scripts/main.js108
-rw-r--r--scripts/miningai.js106
-rw-r--r--scripts/vars.js4
7 files changed, 252 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9a9763e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 bendn
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f44ca82
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# experience
+mana
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000..b704181
--- /dev/null
+++ b/icon.png
Binary files differ
diff --git a/mod.hjson b/mod.hjson
new file mode 100644
index 0000000..6f22f8b
--- /dev/null
+++ b/mod.hjson
@@ -0,0 +1,11 @@
+{
+ name: experience
+ displayName: experience
+ author: "[yellow]bendn"
+ repo: "bendnuts/experience"
+ description: "for [accent]plague\n\n[slate]i[#78858e]t [#808a8c]i[#888f8a]s [#909488]a [#989986]c[#a09e84]o[#a8a382]o[#b0a880]l [#b8ad7e]m[#c0b27c]o[accent]d"
+ version: 1.2
+ minGameVersion: 126.2
+ dependencies: [ "ui-lib" ]
+ hidden: true
+}
diff --git a/scripts/main.js b/scripts/main.js
new file mode 100644
index 0000000..5cd3c9e
--- /dev/null
+++ b/scripts/main.js
@@ -0,0 +1,108 @@
+// jshint esversion: 6
+const vars = require("vars");
+const miningai = require("experience/miningai");
+const ui = require("ui-lib/library");
+try {
+ ui.addButton("toggle-playerai", "units", () => {
+ if (vars.playerai == null) vars.playerai = true;
+ else vars.playerai = null;
+ Vars.ui.hudfrag.showToast(
+ vars.playerai == true ? "enabled playerai" : "disabled playerai"
+ );
+ });
+} catch (e) {
+ Log.info(e);
+}
+
+function check_mats(check_items, maxvalue) {
+ let current_items = Vars.player.team().items();
+ let ticks = 0;
+ for (let i = 0; i < check_items.length; i++) {
+ let current_value = current_items.get(check_items[i]);
+ if (current_value > maxvalue[i]) {
+ ticks += 1;
+ }
+ }
+ return ticks >= maxvalue.length;
+}
+
+function place_graphite_presses() {
+ if (
+ Vars.player.team() == Team.purple &&
+ !vars.has_created_graphite &&
+ check_mats([Items.copper, Items.lead], [12375, 4950])
+ ) {
+ Log.info("all set to place grap");
+ let placed = 0;
+ for (let x = 0; x < 200; x += 2) {
+ for (let y = 0; y < 200; y += 2) {
+ let tile = new Tile(x, y);
+ let buildplan = new BuildPlan(
+ tile.centerX(),
+ tile.centerY(),
+ 0,
+ Blocks.graphitePress
+ );
+ if (buildplan.placeable(Vars.player.team())) {
+ Vars.player.unit().addBuild(buildplan);
+ placed++;
+ if (placed > 164) {
+ vars.has_created_graphite = true;
+ return;
+ }
+ }
+ }
+ }
+ }
+}
+
+function check_ai() {
+ if (vars.playerai && Vars.player.unit() && Vars.player.unit().type) {
+ let base = Math.min(
+ Vars.player.team().items().get(Items.copper),
+ Vars.player.team().items().get(Items.lead)
+ );
+
+ base = Math.min(base, base, Vars.player.team().items().get(Items.coal));
+ place_graphite_presses();
+ if (Vars.player.unit().plans.size != 0) {
+ let build_plan = Vars.player.unit().plans.first();
+ Vars.player.unit().approach(Tmp.v1.set(build_plan).sub(Vars.player));
+ vars.playerai = "fakebuildpath";
+ } else if (vars.playerai != miningai.playerMiningAI && base < 1000) {
+ Log.info("becoming miningai");
+ vars.playerai = miningai.playerMiningAI;
+ } else if (!vars.playerai instanceof BuilderAI) {
+ vars.playerai = new BuilderAI();
+ Log.info("becoming builderai");
+ }
+
+ updateunits();
+ }
+}
+
+function updateunits() {
+ if (
+ vars.playerai == miningai.playerMiningAI ||
+ vars.playerai instanceof BuilderAI
+ ) {
+ if (vars.playerai == miningai.playerMiningAI) {
+ vars.playerai.unitS(Vars.player.unit());
+ } else if (vars.playerai instanceof BuilderAI) {
+ vars.playerai.unit(Vars.player.unit());
+ }
+ vars.playerai.updateUnit();
+ }
+}
+
+Events.on(EventType.PlayerConnect, (event) => {
+ print(Strings.stripColors(event.player.name));
+});
+
+Events.on(WorldLoadEvent, (event) => {
+ Log.info("debug: cleared all");
+});
+
+Events.run(Trigger.update, () => {
+ check_ai();
+});
diff --git a/scripts/miningai.js b/scripts/miningai.js
new file mode 100644
index 0000000..7be1f2b
--- /dev/null
+++ b/scripts/miningai.js
@@ -0,0 +1,106 @@
+let MiningAI = extend(AIController, {
+ // author: xeloboyo
+ mining: true,
+ targetItem: null,
+ ore: null,
+ unitS(u) {
+ if (this.unit == u) return;
+ this.unit = u;
+ this.init();
+ },
+ updateMovement() {
+ let unit = this.unit;
+
+ var core = unit.closestCore(); //core is a Building
+
+ if (!(unit.canMine()) || core == null) return;
+
+ if (unit.mineTile != null && !unit.mineTile.within(unit, unit.type.range)) {
+ unit.mineTile = null;
+ }
+
+ if (this.mining) {
+ if (this.timer.get(1, 240) || this.targetItem == null) {
+ // let mineItems = unit.team.data().mineItems;
+ let mineItems = Seq.with(Items.copper, Items.lead, Items.coal, Items.titanium, Items.thorium);
+
+ this.targetItem = mineItems.min(boolf(i => Vars.indexer.hasOre(i) && unit.canMine(i)), floatf(i => core.items.get(i) - orePriority(i)));
+
+
+ }
+
+ //core full of the target item, do nothing
+ if (this.targetItem != null && core.acceptStack(this.targetItem, 1, unit) == 0) {
+ unit.clearItem();
+ unit.mineTile = null;
+ return;
+ }
+ //custom player mining ai: todo
+ //if inventory is full, drop it off.
+ if (unit.stack.amount >= unit.type.itemCapacity || (this.targetItem != null && !unit.acceptsItem(this.targetItem))) {
+ this.mining = false;
+ } else {
+ if (this.targetItem != null) {
+ this.ore = Vars.indexer.findClosestOre(core.x, core.y, this.targetItem);
+ }
+
+ if (this.ore != null) {
+ this.moveTo(this.ore, unit.type.range / 5, 20);
+
+ if (unit.within(this.ore, unit.type.range * 0.5)) {
+ unit.mineTile = this.ore;
+ }
+
+ if (this.ore.block() != Blocks.air) {
+ this.mining = false;
+ }
+ }
+ }
+ } else {
+ unit.mineTile = null;
+
+ if (unit.stack.amount == 0) {
+ this.mining = true;
+ this.return;
+ }
+
+ if (unit.within(core, unit.type.range)) {
+ if (core.acceptStack(unit.stack.item, unit.stack.amount, unit) > 0) {
+ Call.transferInventory(Vars.player, core);
+ //Call.transferItemTo(unit, unit.stack.item, unit.stack.amount, unit.x, unit.y, core);
+ }
+
+ //unit.clearItem();
+ this.mining = true;
+ }
+ //
+ this.circle(core, unit.type.range / 1.8);
+ }
+ }
+});
+
+function orePriority(item) {
+ if (item == Items.copper) {
+ return 900;
+ }
+ if (item == Items.lead) {
+ return 850;
+ }
+ if (item == Items.sand) {
+ return 600;
+ }
+ if (item == Items.coal) {
+ return 200;
+ }
+ if (item == Items.titanium) {
+ return 100;
+ }
+ if (item == Items.thorium) {
+ return 0;
+ }
+ return 0;
+}
+
+module.exports = {
+ playerMiningAI: MiningAI
+} \ No newline at end of file
diff --git a/scripts/vars.js b/scripts/vars.js
new file mode 100644
index 0000000..447862d
--- /dev/null
+++ b/scripts/vars.js
@@ -0,0 +1,4 @@
+module.exports = {
+ has_created_graphite: false,
+ playerai: false
+} \ No newline at end of file