Difference between revisions of "AI Craftapalooza"

From The Perfect Tower II
Jump to navigation Jump to search
Line 1: Line 1:
 
IN PROGRESS.  USE AT YOUR OWN RISK
 
IN PROGRESS.  USE AT YOUR OWN RISK
  
<br />{{AIScript
+
<br />
| source = ; Cutter
 
:global double craft_inventory
 
:local int tier
 
:local double count
 
  
tier = global.int.get("craft_tier:2.5")
+
== Overview ==
count = global.double.get("craft_count:2.5")
+
Craftapalooza is a set of scripts to manage the factory directly, rather than having to manually craft anything.
gotoif(99, tier < 1 {{!}} tier > 10 {{!}} count < 1.0 {{!}} global.int.get("craft_status") > 199)
 
  
executesync("craft 2:5:in")
+
It is separated into sections: The general scripts, which are always required and from the UX of the crafting system (see Usage below), and collections of crafting scripts further broken up into parts, machines and producers.  Note that the parts scripts are required as they are used by the machine and producer scripts, but the latter are for the most part optional.
  
; blocks = count * floor((64400000001.0 / (10.0 ^ i2d(tier))) % 10.0)
+
If you leave the CRAFT_INVENTORY variable to its default value of 1.0, then the scripts will try to reuse items that are already in your inventory to minimise the required work. This also enables the scripts to be interrupted and resumed later - for the most part, the scripts will determine what has already been made and simply pick up where they left off. There is a notable exception that the AI cannot see the contents of machines, so for the best reliability, ensure that none of the machines are busy processing anything before starting any craft.
global.int.set("craft_tier:3.4", tier)
 
global.double.set("craft_count:3.4", count * floor((64400000001.0 / (10.0 ^ i2d(tier))) % 10.0) - craft_inventory * count("block", tier))
 
executesync("craft 3:4")
 
  
; denseplates = count * floor((22244333331.0 / (10.0 ^ i2d(tier))) % 10.0)
+
Conversely you can toggle CRAFT_INVENTORY to 0.0 and then any crafts will create all required items to create your desired output. Note that this can cause an increase in the number of cables, rods, screws etc in your inventory if the requested craft doesn't consume all of the created parts.
global.int.set("craft_tier:3.3", tier)
 
global.double.set("craft_count:3.3", count * floor((22244333331.0 / (10.0 ^ i2d(tier))) % 10.0) - craft_inventory * count("plate.dense", tier))
 
executesync("craft 3:3")
 
  
; plates = count * floor((00022222221.0 / (10.0 ^ i2d(tier))) % 10.0)
+
=== Usage ===
global.int.set("craft_tier:3.2", tier)
 
global.double.set("craft_count:3.2", count * floor((00022222221.0 / (10.0 ^ i2d(tier))) % 10.0) - craft_inventory * count("plate", tier))
 
executesync("craft 3:2")
 
gotoif(99, global.int.get("craft_status") > 199)
 
  
craft("machine.cutter", tier, count)
+
# Choose the crafting MODE with '2' and OUTPUT with '3'. Refer to the following table to see what will be produced.
| code = CWNyYWZ0IDI6NQAAAAAAAAAADwAAAA1sb2NhbC5pbnQuc2V0CGNvbnN0YW50BAR0aWVyDmdsb2JhbC5p
+
# Choose the TIER you want to produce with '1' (loops from 1 to 10).  Note that some items can only be crafted for tiers 1 to 5.
bnQuZ2V0CGNvbnN0YW50BA5jcmFmdF90aWVyOjIuNRBsb2NhbC5kb3VibGUuc2V0CGNvbnN0YW50BAVj
+
# Choose the COUNT of items you want to produce with '8' to decrease and '9' to increase the target count. The count increments in units from 1-10, then by tens through 20, 30... 90, 100, then 200, 300 etc
b3VudBFnbG9iYWwuZG91YmxlLmdldAhjb25zdGFudAQPY3JhZnRfY291bnQ6Mi41DmdlbmVyaWMuZ290
+
# Optionally toggle CRAFT_INVENTORY as described above with '5'.
b2lmCGNvbnN0YW50AmMAAAAPY29tcGFyaXNvbi5ib29sD2NvbXBhcmlzb24uYm9vbA9jb21wYXJpc29u
+
# Hit '0' while in the factory to start production.
LmJvb2wOY29tcGFyaXNvbi5pbnQNbG9jYWwuaW50LmdldAhjb25zdGFudAQEdGllcghjb25zdGFudAQB
+
 
PAhjb25zdGFudAIBAAAACGNvbnN0YW50BAF8DmNvbXBhcmlzb24uaW50DWxvY2FsLmludC5nZXQIY29u
+
{| class="wikitable"
c3RhbnQEBHRpZXIIY29uc3RhbnQEAT4IY29uc3RhbnQCCgAAAAhjb25zdGFudAQBfBFjb21wYXJpc29u
+
!MODE
LmRvdWJsZRBsb2NhbC5kb3VibGUuZ2V0CGNvbnN0YW50BAVjb3VudAhjb25zdGFudAQBPAhjb25zdGFu
+
!1 (producers)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50BA5jcmFmdF90aWVyOjMuMw1sb2NhbC5pbnQuZ2V0CGNv
+
|-
bnN0YW50BAR0aWVyEWdsb2JhbC5kb3VibGUuc2V0CGNvbnN0YW50BA9jcmFmdF9jb3VudDozLjMRYXJp
+
|2
dGhtZXRpYy5kb3VibGURYXJpdGhtZXRpYy5kb3VibGUQbG9jYWwuZG91YmxlLmdldAhjb25zdGFudAQF
+
|Yellow (powerplant)
Y291bnQIY29uc3RhbnQEASoMZG91YmxlLmZsb29yEWFyaXRobWV0aWMuZG91YmxlEWFyaXRobWV0aWMu
+
|Assembler
ZG91YmxlCGNvbnN0YW50AwAATFx2txRCCGNvbnN0YW50BAEvEWFyaXRobWV0aWMuZG91YmxlCGNvbnN0
+
|Plates
YW50AwAAAAAAACRACGNvbnN0YW50BANwb3cDaTJkDWxvY2FsLmludC5nZXQIY29uc3RhbnQEBHRpZXII
+
|-
Y29uc3RhbnQEA21vZAhjb25zdGFudAMAAAAAAAAkQAhjb25zdGFudAQBLRFhcml0aG1ldGljLmRvdWJs
+
|3
ZRFnbG9iYWwuZG91YmxlLmdldAhjb25zdGFudAQPY3JhZnRfaW52ZW50b3J5CGNvbnN0YW50BAEqE2Zh
+
|Orange (mine)
Y3RvcnkuaXRlbXMuY291bnQIY29uc3RhbnQEC3BsYXRlLmRlbnNlDWxvY2FsLmludC5nZXQIY29uc3Rh
+
|Refiner
bnQEBHRpZXITZ2VuZXJpYy5leGVjdXRlc3luYwhjb25zdGFudAQJY3JhZnQgMzozDmdsb2JhbC5pbnQu
+
|Dense plates
c2V0CGNvbnN0YW50BA5jcmFmdF90aWVyOjMuMg1sb2NhbC5pbnQuZ2V0CGNvbnN0YW50BAR0aWVyEWds
+
|-
b2JhbC5kb3VibGUuc2V0CGNvbnN0YW50BA9jcmFmdF9jb3VudDozLjIRYXJpdGhtZXRpYy5kb3VibGUR
+
|4
YXJpdGhtZXRpYy5kb3VibGUQbG9jYWwuZG91YmxlLmdldAhjb25zdGFudAQFY291bnQIY29uc3RhbnQE
+
|Red (factory)
ASoMZG91YmxlLmZsb29yEWFyaXRobWV0aWMuZG91YmxlEWFyaXRobWV0aWMuZG91YmxlCGNvbnN0YW50
+
|Crusher
AwAAANBYMXVBCGNvbnN0YW50BAEvEWFyaXRobWV0aWMuZG91YmxlCGNvbnN0YW50AwAAAAAAACRACGNv
+
|Blocks
bnN0YW50BANwb3cDaTJkDWxvY2FsLmludC5nZXQIY29uc3RhbnQEBHRpZXIIY29uc3RhbnQEA21vZAhj
+
|-
b25zdGFudAMAAAAAAAAkQAhjb25zdGFudAQBLRFhcml0aG1ldGljLmRvdWJsZRFnbG9iYWwuZG91Ymxl
+
|5
LmdldAhjb25zdGFudAQPY3JhZnRfaW52ZW50b3J5CGNvbnN0YW50BAEqE2ZhY3RvcnkuaXRlbXMuY291
+
|Purple (headquarters)
bnQIY29uc3RhbnQEBXBsYXRlDWxvY2FsLmludC5nZXQIY29uc3RhbnQEBHRpZXITZ2VuZXJpYy5leGVj
+
|Cutter
dXRlc3luYwhjb25zdGFudAQJY3JhZnQgMzoyDmdlbmVyaWMuZ290b2lmCGNvbnN0YW50AmMAAAAOY29t
+
|Cables
cGFyaXNvbi5pbnQOZ2xvYmFsLmludC5nZXQIY29uc3RhbnQEDGNyYWZ0X3N0YXR1cwhjb25zdGFudAQB
+
|-
Pghjb25zdGFudALHAAAADWZhY3RvcnkuY3JhZnQIY29uc3RhbnQEDm1hY2hpbmUuY3V0dGVyDWxvY2Fs
+
|6
LmludC5nZXQIY29uc3RhbnQEBHRpZXIQbG9jYWwuZG91YmxlLmdldAhjb25zdGFudAQFY291bnQ=
+
|Pink (arcade)
}}<br />{{PerfectNavigation}}
+
|Presser
 +
|Insulated cables
 +
|-
 +
|7
 +
|Green (laboratory)
 +
|Mixer
 +
|Rods
 +
|-
 +
|8
 +
|Cyan (shipyard)
 +
|Belt
 +
|Motors
 +
|-
 +
|9
 +
|Light blue (trading post)
 +
|Shaper
 +
|Pumps
 +
|-
 +
|10
 +
|Dark blue (workshop)
 +
|Boiler
 +
|Dust (tier up)
 +
|-
 +
|11
 +
|Grey (museum)
 +
| -
 +
| -
 +
|-
 +
|12
 +
|Brown (construction firm)
 +
| -
 +
| -
 +
|-
 +
|13
 +
|Black (statue of Cubos)
 +
| -
 +
| -
 +
|}
 +
 
 +
=== Importing the scripts ===
 +
The import codes for each script can be found in the tables below.  The easiest way to import them is to install GreaseMonkey or TamperMonkey and install the following tamperscript which will add a <code></></code> button to the top of each code block.  If you click on this button, the contents of the block will be copied into your clipboard for ease of pasting into the game's import window.
 +
{| class="wikitable mw-collapsible mw-collapsed"
 +
!Click to copy (tamperscript)
 +
|-
 +
|<syntaxhighlight lang="javascript">
 +
// ==UserScript==
 +
// @name        Click to copy on <pre> tags
 +
// @namespace    http://tampermonkey.net/
 +
// @version      0.1
 +
// @description  Add click to copy buttons to <pre> tags
 +
// @author      Troy.Laurin@gmail.com
 +
// @match        https://www.perfecttower2.com/wiki/*
 +
// @grant        GM_addStyle
 +
// @require      https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js
 +
// @require      http://code.jquery.com/jquery-3.5.1.slim.min.js
 +
// ==/UserScript==
 +
 
 +
(function() {
 +
    'use strict';
 +
 
 +
    // ------------------------------------------
 +
    // CSS part injected in the page
 +
    GM_addStyle(" \
 +
.precontainer { \
 +
position: relative; \
 +
} \
 +
.copy-btn { \
 +
background: #DDD; \
 +
font-family: monospace; \
 +
font-weight: bolder; \
 +
margin: 0; \
 +
opacity: 0; \
 +
padding: 4px; \
 +
position: absolute; \
 +
right: 1px; \
 +
top: 1px; \
 +
cursor: pointer; \
 +
-webkit-transition: opacity 0.3s ease-in-out; \
 +
-o-transition: opacity 0.3s ease-in-out; \
 +
transition: opacity 0.3s ease-in-out; \
 +
} \
 +
.precontainer:hover >.copy-btn { \
 +
opacity: 1; \
 +
} \
 +
table { width: 100% } \
 +
");
 +
 
 +
    $('pre').wrap('<div class="precontainer"></div>');
 +
    $('pre').before($('<span class="copy-btn">&lt;/&gt;</span>'));
 +
 
 +
    new ClipboardJS('.copy-btn', {
 +
        text: function(trigger) {
 +
            return $(trigger.nextElementSibling).text();
 +
        }
 +
    })
 +
        .on('success',function (e) {
 +
        $(e.trigger).html("&lt;copied/&gt;")
 +
        setTimeout(function() {
 +
            $(e.trigger).html("&lt;/&gt;");
 +
        }, 3000);
 +
    })
 +
        .on('error',function (e) {
 +
        $(e.trigger).html("Error!")
 +
        setTimeout(function() {
 +
            $(e.trigger).html("&lt;/&gt;");
 +
        }, 3000);
 +
    });
 +
})();
 +
 
 +
</syntaxhighlight>
 +
|}
 +
 
 +
== The scripts ==
 +
 
 +
=== Command scripts ===
 +
<br />
 +
 
 +
=== Parts scripts ===
 +
<br />
 +
 
 +
=== Machine scripts ===
 +
<br />
 +
 
 +
=== Producer scripts ===
 +
<br />{{PerfectNavigation}}

Revision as of 17:32, 21 January 2021

IN PROGRESS. USE AT YOUR OWN RISK


Overview

Craftapalooza is a set of scripts to manage the factory directly, rather than having to manually craft anything.

It is separated into sections: The general scripts, which are always required and from the UX of the crafting system (see Usage below), and collections of crafting scripts further broken up into parts, machines and producers. Note that the parts scripts are required as they are used by the machine and producer scripts, but the latter are for the most part optional.

If you leave the CRAFT_INVENTORY variable to its default value of 1.0, then the scripts will try to reuse items that are already in your inventory to minimise the required work. This also enables the scripts to be interrupted and resumed later - for the most part, the scripts will determine what has already been made and simply pick up where they left off. There is a notable exception that the AI cannot see the contents of machines, so for the best reliability, ensure that none of the machines are busy processing anything before starting any craft.

Conversely you can toggle CRAFT_INVENTORY to 0.0 and then any crafts will create all required items to create your desired output. Note that this can cause an increase in the number of cables, rods, screws etc in your inventory if the requested craft doesn't consume all of the created parts.

Usage

  1. Choose the crafting MODE with '2' and OUTPUT with '3'. Refer to the following table to see what will be produced.
  2. Choose the TIER you want to produce with '1' (loops from 1 to 10). Note that some items can only be crafted for tiers 1 to 5.
  3. Choose the COUNT of items you want to produce with '8' to decrease and '9' to increase the target count. The count increments in units from 1-10, then by tens through 20, 30... 90, 100, then 200, 300 etc
  4. Optionally toggle CRAFT_INVENTORY as described above with '5'.
  5. Hit '0' while in the factory to start production.
MODE 1 (producers) 2 (machines) 3 (parts)
OUTPUT
1 White (town) Oven Chips (T1-5)
2 Yellow (powerplant) Assembler Plates
3 Orange (mine) Refiner Dense plates
4 Red (factory) Crusher Blocks
5 Purple (headquarters) Cutter Cables
6 Pink (arcade) Presser Insulated cables
7 Green (laboratory) Mixer Rods
8 Cyan (shipyard) Belt Motors
9 Light blue (trading post) Shaper Pumps
10 Dark blue (workshop) Boiler Dust (tier up)
11 Grey (museum) - -
12 Brown (construction firm) - -
13 Black (statue of Cubos) - -

Importing the scripts

The import codes for each script can be found in the tables below. The easiest way to import them is to install GreaseMonkey or TamperMonkey and install the following tamperscript which will add a </> button to the top of each code block. If you click on this button, the contents of the block will be copied into your clipboard for ease of pasting into the game's import window.

Click to copy (tamperscript)
// ==UserScript==
// @name         Click to copy on <pre> tags
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add click to copy buttons to <pre> tags
// @author       Troy.Laurin@gmail.com
// @match        https://www.perfecttower2.com/wiki/*
// @grant        GM_addStyle
// @require      https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js
// @require      http://code.jquery.com/jquery-3.5.1.slim.min.js
// ==/UserScript==

(function() {
    'use strict';

    // ------------------------------------------
    // CSS part injected in the page
    GM_addStyle(" \
.precontainer { \
position: relative; \
} \
.copy-btn { \
background: #DDD; \
font-family: monospace; \
font-weight: bolder; \
margin: 0; \
opacity: 0; \
padding: 4px; \
position: absolute; \
right: 1px; \
top: 1px; \
cursor: pointer; \
-webkit-transition: opacity 0.3s ease-in-out; \
-o-transition: opacity 0.3s ease-in-out; \
transition: opacity 0.3s ease-in-out; \
} \
.precontainer:hover >.copy-btn { \
opacity: 1; \
} \
table { width: 100% } \
");

    $('pre').wrap('<div class="precontainer"></div>');
    $('pre').before($('<span class="copy-btn">&lt;/&gt;</span>'));

    new ClipboardJS('.copy-btn', {
        text: function(trigger) {
            return $(trigger.nextElementSibling).text();
        }
    })
        .on('success',function (e) {
        $(e.trigger).html("&lt;copied/&gt;")
        setTimeout(function() {
            $(e.trigger).html("&lt;/&gt;");
        }, 3000);
    })
        .on('error',function (e) {
        $(e.trigger).html("Error!")
        setTimeout(function() {
            $(e.trigger).html("&lt;/&gt;");
        }, 3000);
    });
})();

The scripts

Command scripts


Parts scripts


Machine scripts


Producer scripts