Your browser lacks required capabilities. Please upgrade it or switch to another to continue.
<<Map 60px 5 5 setup.mapToDisplay($map)>>
<<countdown>><<widget "Map">>
<<nobr>>
<<set _size = $args[0]>>
<<set _x = $args[1]>>
<<set _y = $args[2]>>
<<set _map = $args[3] || {}>>
<<set _mapId = "map_" + Math.floor(Math.random() * 0x10000).toString(16)>>
<</nobr>>
<<if _size && _x && _y && _x > 0 && _y > 0>>\
<<= "<html><div class='map' id='" + _mapId + "' style='--size: " + _size + "'>"
+ Array.from({length: _x}).map((u, col) =>
Array.from({length: _y}).map((u, row) => {
var cell = (col + 1) + "x" + (row + 1);
return "<map-hex style='--x: " + (col+1) + "; --y: " + (row+1) + ";' data-row='" + (row+1) + "' data-col='" + (col+1) + "' data-cell='" + cell + "'>" + (_map[cell] ? _map[cell] : "") + "<span class='loc'>" + cell + "</span></map-hex>"}
).join("")).join("")
+ "</div></html>">>
<<script>>
var mapId = State.temporary.mapId;
jQuery(function() {
var map = jQuery("#" + mapId);
var size = map.get(0).style.getPropertyValue("--size").trim();
map.children("map-hex")
.on("click", function() {
var target = this.getAttribute("data-cell").trim();
Engine.play(target);
})
.filter((i, el) => 1 - Number(el.style.getPropertyValue("--y")) % 2)
.css("margin-left", "calc(" + size + " * 1.732 / 2)");
});
<</script>>
<</if>>
<</widget>>
<<widget "plantTree">>
<<set _field = $args[0]>>
<<if $seeds gt 0>>
<<button "Plant tree">>
<<set $map[_field].trees ++>>
<<replace "#treeCount">><<print $map[_field].trees>><</replace>>
<<set $seeds -->>
<<if $seeds eq 0>>
<<run Dialog.wiki("No more seeds!").open()>>
<<replace "#plantButton">><</replace>>
<</if>>
<<replace "#seedCount">><<print $seeds>><</replace>>
<<set $vitality to $vitality-6>>
<<replace "#vitalityCount">><<print $vitality>><</replace>>
<<if $map[_field].trees gt 2>>
<<set $map[_field].protected to true>>
<<replace "#protected">>It is protected.<</replace>>
<</if>>
<</button>>
<</if>>
<</widget>>
<<widget "useSpell">>
<<set _field = $args[0]>>
<<if $spells gt 0>>
<<button "Use spell">>
<<set $map[_field].hasSpell to true>>
<<set $map[_field].protected to true>>
<<set $spells -->>
<<if $spells eq 0>>
<<run Dialog.wiki("No more spells!").open()>>
<<replace "#spellButton">><</replace>>
<</if>>
<<replace "#spellCount">><<print $spells>><</replace>>
<</button>>
<</if>>
<</widget>>
<<widget "countdown">>
<<set $seconds to $attackTime>>\
Countdown: <span id="countdown">$seconds </span> till Kylo attacks!\
<<silently>>
<<repeat 1s>>
<<set $seconds to $seconds - 1>>
<<if $seconds gt 0>>
<<replace "#countdown">>$seconds seconds remaining<</replace>>
<<else>>
<<goto "KyloAttack">>
<<stop>>
<</if>>
<</repeat>>
<</silently>>
<</widget>><<set $map = {
"1x1": {trees: 1, hasSpell: false, protected: false, home: false},
"1x2": {trees: 1, hasSpell: false, protected: false, home: false},
"1x3": {trees: 1, hasSpell: false, protected: false, home: false},
"1x4": {trees: 1, hasSpell: false, protected: false, home: false},
"1x5": {trees: 1, hasSpell: false, protected: false, home: false},
"2x1": {trees: 1, hasSpell: false, protected: false, home: false},
"2x2": {trees: 0, hasSpell: false, protected: false, home: false},
"2x3": {trees: 0, hasSpell: false, protected: false, home: false},
"2x4": {trees: 0, hasSpell: false, protected: false, home: false},
"2x5": {trees: 1, hasSpell: false, protected: false, home: false},
"3x1": {trees: 1, hasSpell: false, protected: false, home: false},
"3x2": {trees: 0, hasSpell: false, protected: false, home: false},
"3x3": {trees: 0, hasSpell: false, protected: false, home: true},
"3x4": {trees: 0, hasSpell: false, protected: false, home: false},
"3x5": {trees: 1, hasSpell: false, protected: false, home: false},
"4x1": {trees: 0, hasSpell: false, protected: false, home: false},
"4x2": {trees: 0, hasSpell: false, protected: false, home: false},
"4x3": {trees: 0, hasSpell: false, protected: false, home: false},
"4x4": {trees: 0, hasSpell: false, protected: false, home: false},
"4x5": {trees: 1, hasSpell: true, protected: true, home: false},
"5x1": {trees: 1, hasSpell: false, protected: false, home: false},
"5x2": {trees: 1, hasSpell: false, protected: false, home: false},
"5x3": {trees: 1, hasSpell: false, protected: false, home: false},
"5x4": {trees: 1, hasSpell: false, protected: false, home: false},
"5x5": {trees: 1, hasSpell: false, protected: false, home: false},
}>>
<<set $seeds to 12>>
<<set $vitality to 80>>
<<set $mana to 40>>
<<set $spells to 2>>
<<set $attackTime to 10>>Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.Double-click this passage to edit it.<<if tags().includes("field")>>
<h3>Field <<print passage()>></h3>
<<set _id to passage()>>
This field has <span id="treeCount"><<print $map[_id].trees>></span> trees.
<span id="protected">
<<if $map[_id].protected eq true>>It is protected.<<else>>It is not protected.<</if>></span>
<span id="plantButton"><<plantTree _id>></span>
<span id="spellButton"><<useSpell _id>></span>
<<button "back to the wood">><<goto "Start">><</button>>
<</if>>seeds:<span id="seedCount"><<print $seeds>></span>
vitality: <span id="vitalityCount"><<print $vitality>></span>
mana: <span id="manaCount"><<print $mana>></span>
spells: <span id="spellCount"><<print $spells>></span><<silently>>
<<set $valueA to either(1,2,3,4,5)>>
<<print "a:" + $valueA>>
<<if $valueA eq 1 || $valueA eq 5>>
<<set $attackFieldX to $valueA>>
<<set $attackFieldY to random(5)>>
<<if $attackFieldY eq 0>>
<<set $attackFieldY to 1>>
<</if>>
<<else>>
<<set $attackFieldY to $valueA>>
<<set $attackFieldX to either(1,5)>>
<</if>>
<<set $attackField to $attackFieldX + "x" + $attackFieldY>>
<</silently>>
<<timed 2s>>
Kylo attacks field <<print $attackField>>!
<<if $map[$attackField].protected eq true>>
<<set _protected to true>>
<</if>>
<<next>>
Field <<print $attackField>> is <<if _protected eq true>>PROTECTED<<else>>NOT PROTECTED!<</if>>
<<next>>
<<if _protected eq true>>
Kylo cannot attack the field. YOU WIN!
<<set _giftSeeds to either(1,2)>>\
You receive <<print _giftSeeds>> seeds!
<<set $seeds to $seeds + _giftSeeds>>\
Having helped the animals raises your spirit. You receive <<set _manaPlus to either(8,10,12)>><<print _manaPlus>> mana!
<<set $mana to $mana + _manaPlus>>\
As a token of gratefulness, the animals give you food. You gain <<set _vitalityPlus to either(4,6,8)>><<print _vitalityPlus>> vitality!
<<set $vitality to $vitality + _vitalityPlus>>\
<<else>>
Kylo destructs <<print $map[$attackField].trees>> trees on the field. All of the animals lose their homes!
YOU LOSE!
<<set _loseMana to either (3,5,7)>>\
The defeat darkens your thoughts. You lose <<print _loseMana>> mana!
<<set $mana to $mana - _loseMana>>\
<<set $map[$attackField].trees to 0>>\
<<set $map[$attackField].protected to false>>\
<</if>>
<<next>>
<<button "back to the wood">><<goto "Start">><</button>>
<</timed>>