anomalies.lua 65.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009 - 2016 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org

-- TODO
-- Singularity (major))
-- Lost in Space (major)

local Object = require "engine.Object"
local Trap = require "mod.class.Trap"

-- All anomaly damage functions come from here with a bit of randomness thrown in to mix it up
getAnomalyDamage = function(self, t)
	local dam = self:combatScale(getParadoxSpellpower(self, t), 20, 10, 220, 100, 0.75)
	return rng.avg(dam / 3, dam, 3)
end

getAnomalyDamageAoE = function(self, t)
	local dam = self:combatScale(getParadoxSpellpower(self, t), 10, 10, 50, 100, 0.75)
	return rng.avg(dam / 3, dam, 3)
end

-- Here we have Effect Power and Anomaly duration, similar to damage but less random
getAnomalyEffectPower = function(self, t)
	local dam = self:combatScale(getParadoxSpellpower(self, t), 10, 10, 50, 100, 0.75)
	return math.ceil(rng.avg(dam / 2, dam, 3))
end

getAnomalyDuration = function(self, t)
	local dam = self:combatScale(getParadoxSpellpower(self, t), 4, 10, 12, 100, 0.75)
	return math.ceil(rng.avg(dam / 2, dam, 3))
end

-- Determines the anomaly range based on current spellpower
-- Generally we just use range = 10 for anomalies, this is for stuff with much longer range (such as teleports)
getAnomalyRange = function(self, t)
	local range = math.floor(self:combatLimit(getParadoxSpellpower(self, t), 80, 20, 20, 40, 100))
	return range
end

-- Determines the anomaly radius based on current spellpower
getAnomalyRadius = function(self, t)
	local radius = math.floor(self:combatLimit(getParadoxSpellpower(self, t), 6, 2, 20, 4, 100))
	return radius
end

-- Gets targets
-- @type: an entity type
-- @range: the area to search for targets in, generally uses talent radius or range
-- @no_self: don't target the caster
getAnomalyTargets = function(self, t, x, y, type, range, no_self)
	local tgts = {}
	local grids = core.fov.circle_grids(x, y, range, true)
	for x, yy in pairs(grids) do for y, _ in pairs(grids[x]) do
		local target_type = Map.ACTOR
		if type == "PROJECTILE" then target_type = Map.PROJECTILE end
		if type == "TERRAIN" then target_type = Map.TERRAIN end
		local a = game.level.map(x, y, target_type)
		if a and not (no_self and a == self) then
			tgts[#tgts+1] = a
		end
	end end
	return tgts
end

-- Randomly find a start location for projectiles, wormholes, etc.
getAnomalyPosition = function(self, range)
	local x, y = self.x, self.y
	local poss = {}
	for i = x - range, x + range do
		for j = y - range, y + range do
			if game.level.map:isBound(i, j) and
				core.fov.distance(x, y, i, j) <= range and
				core.fov.distance(x, y, i, j) >= range/2 and
				self:canMove(i, j) and not game.level.map(i, j, engine.Map.TRAP) then
				poss[#poss+1] = {i,j}
			end
		end
	end
	if #poss == 0 then return x, y  end
	local pos = poss[rng.range(1, #poss)]
	x, y = pos[1], pos[2]
	return x, y
end

-- Check for effects when hit by an anomaly
-- This is called before immunity is checked
checkAnomalyTriggers = function(self, target)

end

-- Teleportation 
newTalent{
	name = "Anomaly Rearrange",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ causes a spacetime hiccup.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end

		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			if a:canBe("teleport") and a:canBe("anomaly") then
				game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
				a:teleportRandom(a.x, a.y, 10, 1)
				game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
			end
		end
		return true
	end,
	info = function(self, t)
		local radius = self:getTalentRadius(t)
		return ([[Teleports up to five targets in a radius of %d up to ten tiles away.]]):format(radius)
	end,
}

newTalent{
	name = "Anomaly Teleport",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = function(self, t) return getAnomalyRange(self, t) end,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=10, radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ shifts reality.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			if a:canBe("teleport") and a:canBe("anomaly") then
				game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
				a:teleportRandom(a.x, a.y, self:getTalentRange(t), self:getTalentRange(t)/2)
				game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
			end
		end
		return true
	end,
	info = function(self, t)
		local range = self:getTalentRange(t)
		local radius = self:getTalentRadius(t)
		return ([[Teleports up to five targets in a radius of %d up to %d tiles away.]]):format(radius, range)
	end,
}

newTalent{
	name = "Anomaly Swap",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ swaps places with a nearby target.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRange(t), true)

		-- Randomly take targets
		if #tgts <= 0 then return nil end
		local a, id = rng.table(tgts)
		table.remove(tgts, id)
		checkAnomalyTriggers(self, a)
		checkAnomalyTriggers(self, self)
		
		if a:canBe("teleport") and a:canBe("anomaly") and self:canBe("teleport") and self:canBe("anomaly") then
			-- first remove the target so the destination tile is empty
			game.level.map:remove(a.x, a.y, Map.ACTOR)
			local px, py 
			px, py = self.x, self.y
			if self:teleportRandom(a.x, a.y, 0) then
				-- return the target at the casters old location
				game.level.map(px, py, Map.ACTOR, a)
				self.x, self.y, a.x, a.y = a.x, a.y, px, py
				game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
				game.level.map:particleEmitter(self.x, self.y, 1, "temporal_teleport")
			else
				-- return the target without effect
				game.level.map(a.x, a.y, Map.ACTOR, a)
				game.logSeen(self, "The spell fizzles!")
			end
		end

		return true
	end,
	info = function(self, t)
		return ([[You swap locations with a random target.]]):format()
	end,
}

newTalent{
	name = "Anomaly Displacement Shield",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="hit", range=self:getTalentRange(t), nowarning=true}
	end,
	message = "@Source@ transfers damage to a nearby target.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t), true)

		-- Randomly take targets
		if #tgts <= 0 then return nil end
		local a, id = rng.table(tgts)
		table.remove(tgts, id)
		checkAnomalyTriggers(self, a)
		checkAnomalyTriggers(self, self)
		
		if a:canBe("anomaly") then
			self:setEffect(self.EFF_DISPLACEMENT_SHIELD, getAnomalyDuration(self, t)*2, {power=getAnomalyDamage(self, t)*4, target=a, chance=50})
		end
		
		game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
		game.level.map:particleEmitter(self.x, self.y, 1, "temporal_teleport")

		return true
	end,
	info = function(self, t)
		return ([[50%% chance that damage the caster takes will be warped to a set target.
		Once the maximum damage (%d) is absorbed, the time runs out, or the target dies, the shield will crumble.]]):format(getAnomalyDamage(self, t)*2)
	end,
}

newTalent{
	name = "Anomaly Wormhole",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="bolt", nowarning=true, range=10, nolock=true, simple_dir_request=true, talent=t}
	end,
	message = "@Source@ folds the space between two points.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		if (x == self.x and y == self.y) or game.level.map:checkEntity(x, y, Map.TERRAIN, "block_move")then
			x, y = getAnomalyPosition(self, self:getTalentRange(t))
		end
		local start_x, start_y = getAnomalyPosition(self, 1)
		if not x and not y and not start_x and not start_y then return false end
		
		-- Adding the entrance wormhole
		local entrance = mod.class.Trap.new{
			name = "wormhole",
			type = "annoy", subtype="teleport", id_by_type=true, unided_name = "trap",
			image = "terrain/wormhole.png",
			display = '&', color_r=255, color_g=255, color_b=255, back_color=colors.STEEL_BLUE,
			message = "@Target@ moves onto the wormhole.",
			temporary = getAnomalyDuration(self, t),
			x = start_x, y = start_y,
			canAct = false,
			energy = {value=0},
			disarm = function(self, x, y, who) return false end,
			summoner = self, beneficial_trap = true, faction=self.faction,
			triggered = function(self, x, y, who)
				if who == self.summoned or who:canBe("teleport") then
					game.level.map:particleEmitter(who.x, who.y, 1, "temporal_teleport")
					if not who:teleportRandom(self.dest.x, self.dest.y, 3, 1) then
						game.logSeen(who, "%s tries to enter the wormhole but a violent force pushes it back.", who.name:capitalize())
					elseif who ~= self.summoned_by then
						who:setEffect(who.EFF_CONTINUUM_DESTABILIZATION, 100, {power=self.dest_power})
						game.level.map:particleEmitter(who.x, who.y, 1, "temporal_teleport")
					end
				else
					game.logSeen(who, "%s ignores the wormhole.", who.name:capitalize())
				end
				return true
			end,
			act = function(self)
				self:useEnergy()
				self.temporary = self.temporary - 1
				if self.temporary <= 0 then
					game.logSeen(self, "Reality asserts itself and forces the wormhole shut.")
					if game.level.map(self.x, self.y, engine.Map.TRAP) == self then game.level.map:remove(self.x, self.y, engine.Map.TRAP) end
					game.level:removeEntity(self)
				end
			end,
		}
		entrance.faction = nil
		game.level:addEntity(entrance)
		entrance:identify(true)
		entrance:setKnown(self, true)
		game.zone:addEntity(game.level, entrance, "trap", start_x, start_y)
		game.level.map:particleEmitter(start_x, start_y, 1, "temporal_teleport")
		game:playSoundNear(self, "talents/heal")

		-- Adding the exit wormhole
		local exit = entrance:clone()
		exit.x = x
		exit.y = y
		game.level:addEntity(exit)
		exit:identify(true)
		exit:setKnown(self, true)
		game.zone:addEntity(game.level, exit, "trap", x, y)
		game.level.map:particleEmitter(x, y, 1, "temporal_teleport")

		-- Linking the wormholes
		entrance.dest = exit
		exit.dest = entrance

		return true
	end,
	info = function(self, t)
		return ([[Creates a wormhole nearby and a second wormhole up to ten tiles away.]]):format()
	end,
}

newTalent{
	name = "Anomaly Probability Travel",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), nowarning=true}
	end,
	message = "@Source@ places several targets out of phase.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			a:setEffect(a.EFF_PROBABILITY_TRAVEL, getAnomalyDuration(self, t)*2, {power=getAnomalyDuration(self, t)})
			game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")

			game:playSoundNear(self, "talents/spell_generic")
		end
		
		return true
	end,
	info = function(self, t)
		return ([[Allows up to five targets in a radius of %d to travel up to %d tiles through walls.]]):
		format(getAnomalyDuration(self, t)*2, getAnomalyDuration(self, t))
	end,
}

newTalent{
	name = "Anomaly Blink",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ makes several targets blink uncontrollably.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			a:setEffect(a.EFF_BLINK, getAnomalyDuration(self, t)*2, {power=getAnomalyDuration(self, t)})
			game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")

			game:playSoundNear(self, "talents/spell_generic")
		end
		
		return true
	end,
	info = function(self, t)
		return ([[Up to five targets in a radius of %d are teleporting %d tiles every turn.]]):
		format(self:getTalentRadius(t), getAnomalyDuration(self, t))
	end,
}

newTalent{
	name = "Anomaly Summon Townsfolk",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "warp",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	getSummonTime = function(self, t) return math.ceil(getAnomalyDuration(self, t)*2) end,
	message = "Some innocent bystanders have been teleported into the fight.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		
		-- Randomly pick a race
		local race = rng.range(1, 4)
		-- Find space
		for i = 1, 4 do
			local x, y = util.findFreeGrid(x, y, 5, true, {[Map.ACTOR]=true})
			if not x then
				game.logPlayer(self, "Not enough space to summon!")
				return
			end

			local NPC = require "mod.class.NPC"
			local m = NPC.new{
				type = "humanoid", display = "p",
				color=colors.WHITE,

				combat = { dam=resolvers.rngavg(1,2), atk=2, apr=0, dammod={str=0.4} },

				body = { INVEN = 10, MAINHAND=1, OFFHAND=1, BODY=1, QUIVER=1 },
				lite = 3,

				life_rating = 10,
				rank = 2,
				size_category = 3,

				open_door = true,

				autolevel = "warrior",
				stats = { str=12, dex=8, mag=6, con=10 },
				ai = "summoned", ai_real = "dumb_talented_simple", ai_state = { talent_in=2, },
				level_range = {1, 3},

				max_life = resolvers.rngavg(30,40),
				combat_armor = 2, combat_def = 0,

			--	summoner = self,
				summoner_gain_exp=false,
				summon_time = t.getSummonTime(self, t),
			}

			m.level = 1

			if race == 1 then
				m.name = "human farmer"
				m.subtype = "human"
				m.image = "npc/humanoid_human_human_farmer.png"
				m.desc = [[A weather-worn Human farmer, looking at a loss as to what's going on.]]
				m.faction = "allied-kingdoms"
				m[#m+1] = resolvers.inscriptions(1, "infusion")
			elseif race == 2 then
				m.name = "halfling gardener"
				m.subtype = "halfling"
				m.desc = [[A rugged Halfling gardener, looking quite confused as to what he's doing here.]]
				m.faction = "allied-kingdoms"
				m.image = "npc/humanoid_halfling_halfling_gardener.png"
				m[#m+1] = resolvers.inscriptions(1, "infusion")
			elseif race == 3 then
				m.name = "shalore scribe"
				m.subtype = "shalore"
				m.desc = [[A scrawny Elven scribe, looking bewildered at his surroundings.]]
				m.faction = "shalore"
				m.image = "npc/humanoid_shalore_shalore_rune_master.png"
				m[#m+1] = resolvers.inscriptions(1, "rune")
			elseif race == 4 then
				m.name = "dwarven lumberjack"
				m.subtype = "dwarf"
				m.desc = [[A brawny Dwarven lumberjack, looking a bit upset at his current situation.]]
				m.faction = "iron-throne"
				m.image = "npc/humanoid_dwarf_lumberjack.png"
				m[#m+1] = resolvers.inscriptions(1, "rune")
			end

			m:resolve() m:resolve(nil, true)
			m:forceLevelup(self.level)
			game.zone:addEntity(game.level, m, "actor", x, y)
			game.level.map:particleEmitter(x, y, 1, "summon")
		end

		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		return ([[Pulls innocent people into the fight.]])
	end,
}

-- Temporal
newTalent{
	name = "Anomaly Slow",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,	
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	getSlow = function(self, t) return 1 - 1 / (1 + (getAnomalyEffectPower(self, t)) / 100) end,
	message = "@Source@ creates a bubble of slow time.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			if a:canBe("anomaly") then
				a:setEffect(a.EFF_SLOW, getAnomalyDuration(self, t), {power=t.getSlow(self, t), no_ct_effect=true})
			end
			game.level.map:particleEmitter(x, y, tg.radius, "ball_temporal", {radius=self:getTalentRadius(t), tx=x, ty=y})
			game:playSoundNear(self, "talents/spell_generic")
		end
		return true
	end,
	info = function(self, t)
		return ([[Slows up to five targets in a radius %d ball by %d%%.]]):
		format(self:getTalentRadius(t), t.getSlow(self, t)*100)
	end,
}

newTalent{
	name = "Anomaly Haste",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,	
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), nowarning=true}
	end,
	getHaste = function(self, t) return 1 - 1 / (1 + (getAnomalyEffectPower(self, t)) / 100) end,
	message = "@Source@ creates a bubble of fast time.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			a:setEffect(a.EFF_SPEED, getAnomalyDuration(self, t), {power=t.getHaste(self, t)})
			game.level.map:particleEmitter(x, y, tg.radius, "ball_temporal", {radius=self:getTalentRadius(t), tx=x, ty=y})
			game:playSoundNear(self, "talents/spell_generic")
		end
		
		return true
	end,
	info = function(self, t)
		return ([[Increases global speed of up to five targets in a radius %d ball by %d%%.]]):
		format(self:getTalentRadius(t), t.getHaste(self, t)*100)
	end,
}

newTalent{
	name = "Anomaly Stop",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ creates a bubble of nul time.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			if a:canBe("anomaly") and a:canBe("stun") then
				a:setEffect(a.EFF_STUNNED, getAnomalyDuration(self, t)/2, {no_ct_effect=true, apply_power=getParadoxSpellpower(self, t)})
			end
			game.level.map:particleEmitter(x, y, tg.radius, "ball_temporal", {radius=self:getTalentRadius(t), tx=x, ty=y})
			game:playSoundNear(self, "talents/spell_generic")
		end
		
		return true
	end,
	info = function(self, t)
		return ([[Stuns up to five targets in a radius %d ball.]]):
		format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Temporal Bubble",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ removes several targets from time.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			if a:canBe("anomaly") then
				a:setEffect(a.EFF_TIME_PRISON, getAnomalyDuration(self, t), {no_ct_effect=true})
			end
			game.level.map:particleEmitter(x, y, tg.radius, "ball_temporal", {radius=self:getTalentRadius(t), tx=x, ty=y})
			game:playSoundNear(self, "talents/spell_generic")
		end
		
		return true
	end,
	info = function(self, t)
		return ([[Time Prisons up to five targets in a radius %d ball.]]):
		format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Temporal Shield",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), nowarning=true}
	end,
	message = "@Source@ creates a temporal shield around several targets.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			a:setEffect(a.EFF_TIME_SHIELD, getAnomalyDuration(self, t), {power=getAnomalyDamage(self, t)*4, dot_dur=5, time_reducer=40})
			game.level.map:particleEmitter(x, y, tg.radius, "ball_temporal", {radius=self:getTalentRadius(t), tx=x, ty=y})
			game:playSoundNear(self, "talents/spell_generic")
		end
		
		return true
	end,
	info = function(self, t)
		return ([[Time Shields up to five targets in a radius of %d.]]):
		format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Invigorate",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), nowarning=true}
	end,
	message = "@Source@ energizes several targets.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			a:setEffect(a.EFF_INVIGORATE, getAnomalyDuration(self, t), {power=getAnomalyEffectPower(self, t)/10})
			game.level.map:particleEmitter(x, y, tg.radius, "ball_temporal", {radius=self:getTalentRadius(t), tx=x, ty=y})
			game:playSoundNear(self, "talents/spell_generic")
		end
		
		return true
	end,
	info = function(self, t)
		return ([[Invigorates up to five targets in a radius of %d.]]):
		format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Temporal Clone",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), nowarning=true}
	end,
	message = "@Source@ clones a nearby creature.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		if #tgts <= 0 then return true end
		local a, id = rng.table(tgts)
		table.remove(tgts, id)
		checkAnomalyTriggers(self, a)
		
		local x, y = util.findFreeGrid(a.x, a.y, 3, true, {[Map.ACTOR]=true})
		if not x then
			return true
		end
		if a:attr("summon_time") then return end
		local m = makeParadoxClone(self, a, getAnomalyDuration(self, t)*2)
		m.ai_state = { talent_in=2, ally_compassion=10}
		game.zone:addEntity(game.level, m, "actor", x, y)
		game.level.map:particleEmitter(x, y, 1, "generic_teleport", {rm=60, rM=130, gm=20, gM=110, bm=90, bM=130, am=70, aM=180})
		
		return true
	end,
	info = function(self, t)
		return ([[Clones a random creature within range.]]):format()
	end,
}

newTalent{
	name = "Anomaly Temporal Storm",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "temporal",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown = 0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ creates a temporal storm.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		
		-- Add a lasting map effect
		game.level.map:addEffect(self,
			x, y, getAnomalyDuration(self, t)/2,
			DamageType.TEMPORAL, getAnomalyDamageAoE(self, t),
			tg.radius,
			5, nil,
			engine.MapEffect.new{color_br=180, color_bg=100, color_bb=255, effect_shader="shader_images/magic_effect.png"},
			nil, false
		)
		return true
	end,
	info = function(self, t)
		local duration = self:combatScale(getParadoxSpellpower(self, t), 4, 10, 12, 100, 0.75)/2
		local damage = self:combatScale(getParadoxSpellpower(self, t), 10, 10, 50, 100, 0.75)
		return ([[Creates a temporal storm for %d to %d turns that deals between %0.2f and %0.2f temporal damage each turn.]])
		:format(duration/2, duration, damDesc(self, DamageType.TEMPORAL, damage/3),  damDesc(self, DamageType.TEMPORAL, damage))
	end,
}

-- Physical
newTalent{
	name = "Anomaly Gravity Pull",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ increases local gravity.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end

		self:project(tg, x, y, function(px, py)
			local target = game.level.map(px, py, Map.ACTOR)
			if not target then return end
			local tx, ty = util.findFreeGrid(x, y, 5, true, {[Map.ACTOR]=true})
			checkAnomalyTriggers(self, target)
			
			if tx and ty and target:canBe("knockback") and target:canBe("anomaly") then
				target:move(tx, ty, true)
				game.logSeen(target, "%s is drawn in by gravity!", target.name:capitalize())
			end
		end)

		game.level.map:particleEmitter(x, y, tg.radius, "gravity_spike", {radius=self:getTalentRadius(t), grids=grids, tx=x, ty=y, allow=core.shader.allow("distort")})
		game:playSoundNear(self, "talents/earth")

		return true
	end,
	info = function(self, t)
		return ([[Increases localized gravity, pulling in targets in a radius of %d.]]):format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Dig",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ turns matter to dust.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end

		self:project(tg, x, y, DamageType.DIG, 1)
		game.level.map:particleEmitter(x, y, tg.radius, "ball_earth", {radius=tg.radius})
		game:playSoundNear(self, "talents/breath")
		return true
	end,
	info = function(self, t)
		return ([[Digs out all terrain in a radius %d ball.]]):format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Entomb",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = 1,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), nowarning=true}
	end,
	message = "@Source@ creates a stone wall.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		
		for i = -1, 1 do for j = -1, 1 do if game.level.map:isBound(x + i, y + j) then
			local oe = game.level.map(x + i, y + j, Map.TERRAIN)
			if oe and not oe:attr("temporary") and not game.level.map:checkAllEntities(x + i, y + j, "block_move") and not oe.special then
				-- Ok some explanation, we make a new *OBJECT* because objects can have energy and act
				-- it stores the current terrain in "old_feat" and restores it when it expires
				-- We CAN set an object as a terrain because they are all entities

				local e = Object.new{
					old_feat = oe,
					name = "stone wall", image = "terrain/granite_wall1.png",
					display = '#', color_r=255, color_g=255, color_b=255, back_color=colors.GREY,
					desc = "a summoned wall of stone",
					type = "wall", --subtype = "floor",
					always_remember = true,
					can_pass = {pass_wall=1},
					does_block_move = true,
					show_tooltip = true,
					block_move = true,
					block_sight = true,
					temporary = getAnomalyDuration(self, t),
					x = x + i, y = y + j,
					canAct = false,
					act = function(self)
						self:useEnergy()
						self.temporary = self.temporary - 1
						if self.temporary <= 0 then
							game.level.map(self.x, self.y, engine.Map.TERRAIN, self.old_feat)
							game.nicer_tiles:updateAround(game.level, self.x, self.y)
							game.level:removeEntity(self)
							game.level.map:scheduleRedisplay()
						end
					end,
					dig = function(src, x, y, old)
						game.level:removeEntity(old, true)
						game.level.map:scheduleRedisplay()
						return nil, old.old_feat
					end,
					summoner_gain_exp = true,
					summoner = self,
				}
				e.tooltip = mod.class.Grid.tooltip
				game.level:addEntity(e)
				game.level.map(x + i, y + j, Map.TERRAIN, e)
			end
		end end end

		game:playSoundNear(self, "talents/earth")
		return true
	end,
	info = function(self, t)
		return ([[Entombs a single target in a wall of stone.]]):format()
	end,
}

newTalent{
	name = "Anomaly Entropy",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ increases local entropy.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			if a:canBe("anomaly") then
				self:project(tg, a.x, a.y, function(px, py)
					local target = game.level.map(px, py, engine.Map.ACTOR)
					if not target then return end

					local tids = {}
					for tid, lev in pairs(target.talents) do
						local t = target:getTalentFromId(tid)
						if not target.talents_cd[tid] and t.mode == "activated" and not t.innate then tids[#tids+1] = t end
					end
					for i = 1, rng.avg(3, 6, 3) do
						local power = getAnomalyDuration(self, t)
						local t = rng.tableRemove(tids)
						if not t then break end
						target.talents_cd[t.id] = rng.range(2, power)
						game.logSeen(target, "%s's %s is disrupted!", target.name:capitalize(), t.name)
					end
					target.changed = true
				end, nil)
			end
		end
		return true
	end,
	info = function(self, t)
		return ([[Places between three and six talents of up to 5 targets in a radius %d ball on cooldown for up to %d turns.]]):
		format(getAnomalyRadius(self, t), getAnomalyDuration(self, t))
	end,
}

newTalent{
	name = "Anomaly Gravity Well",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,

requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ increases local gravity.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			if a:canBe("anomaly") and a:canBe("pin") then
				a:setEffect(self.EFF_PINNED, getAnomalyDuration(self, t), {apply_power=getParadoxSpellpower(self, t)})
			end
		end
		
		game.level.map:particleEmitter(x, y, tg.radius, "gravity_spike", {radius=self:getTalentRadius(t), grids=grids, tx=x, ty=y, allow=core.shader.allow("distort")})
		game:playSoundNear(self, "talents/earth")
		return true
	end,
	info = function(self, t)
		return ([[Creates a gravity well in a radius %d ball, pinning up to five targets.]]):format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Quake",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ causes an earthquake.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		
		-- Don't bury the player
		if not game.player:knowTalent(game.player.T_DIG_OBJECT) then
			return true
		end

		self:doQuake(tg, x, y)
		return true
	end,
	info = function(self, t)
		return ([[Causes an earthquake in a radius of %d.]]):
		format(getAnomalyRadius(self, t))
	end,
}

newTalent{
	name = "Anomaly Flawed Design",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ crumbles the resistances of several targets.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)

			a:setEffect(self.EFF_FLAWED_DESIGN, getAnomalyDuration(self, t), {power=getAnomalyEffectPower(self, t)})
			game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
			game:playSoundNear(self, "talents/spell_generic")
		end
		return true
	end,
	info = function(self, t)
		return ([[Reduces the resistances of up to five targets in a ball of radius %d by %d%%.]]):format(self:getTalentRadius(t), getAnomalyEffectPower(self, t))
	end,
}

newTalent{
	name = "Anomaly Dust Storm",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "physical",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ causes a dust storm.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		if not x or not y then x, y = self.x, self.y end
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRange(t))
		
		local dam = getAnomalyRadius(self, t) -- not a typo, very low damage since this isn't a major anomaly

		-- Randomly take targets
		for i = 1, rng.avg(3, 6, 3) do
			if #tgts <= 0 then break end
			local target, id = rng.table(tgts)
			table.remove(tgts, id)
			local orig_x, orig_y = getAnomalyPosition(self, self:getTalentRange(t))
			checkAnomalyTriggers(self, target)
						
			local proj = require("mod.class.Projectile"):makeHoming(
				self,
				{particle="bolt_earth", trail="lightningtrail"},
				{speed=2, name="Dust Storm", start_x=orig_x, start_y=orig_y, dam=dam, movedam=dam},
				target,
				self:getTalentRange(t),
				function(self, src)
				--	local DT = require("engine.DamageType")
					--src:project({type="ball", radius=1, x=self.x, y=self.y}, self.x, self.y, DT.SPELLKNOCKBACK, self.def.dam)
				end,
				function(self, src, target)
					if target:canBe("anomaly") then
						local DT = require("engine.DamageType")
						src:project({type="ball", radius=1, x=self.x, y=self.y}, self.x, self.y, DT.SPELLKNOCKBACK, self.def.dam)
					end
				end
			)
			
			game.zone:addEntity(game.level, proj, "projectile", orig_x, orig_y)
			game:playSoundNear(self, "talents/earth")
		end
		return true
	end,
	info = function(self, t)
		return ([[Summons three to six dust storms.]]):format()
	end,
}

-- Major
-- Major anomalies can't be manually targeted
newTalent{
	name = "Anomaly Blazing Fire",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ causes a fire.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tgts = getAnomalyTargets(self, t, self.x, self.y, "ACTOR", self:getTalentRange(t))
		
		local movedam = self:spellCrit(getAnomalyDamage(self, t))

		-- Randomly take targets
		for i = 1, rng.avg(3, 6, 3) do
			if #tgts <= 0 then break end
			local target, id = rng.table(tgts)
			table.remove(tgts, id)
			local orig_x, orig_y = getAnomalyPosition(self, self:getTalentRange(t))
			checkAnomalyTriggers(self, target)
						
			local proj = require("mod.class.Projectile"):makeHoming(
				self,
				{particle="inferno"},
				{speed=1, name="Blazing Fire", start_x=orig_x, start_y=orig_y, dam=movedam, movedam=movedam},
				target,
				self:getTalentRange(t),
				function(self, src)
					local DT = require("engine.DamageType")
					game.level.map:addEffect(src, self.x, self.y, 4, DT.FIRE, self.def.movedam, 1, 5, nil, {type="inferno"}, nil, nil)
				end,
				function(self, src, target)
					local DT = require("engine.DamageType")
					game.level.map:addEffect(src, self.x, self.y, 4, DT.FIRE, self.def.movedam, 1, 5, nil, {type="inferno"}, nil, nil)
				end
			)
			
			game.zone:addEntity(game.level, proj, "projectile", orig_x, orig_y)
			game:playSoundNear(self, "talents/earth")
		end
		return true
	end,
	info = function(self, t)
		return ([[Summons three to six blazing fires.]]):format()
	end,
}

newTalent{
	name = "Anomaly Calcify",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ calcifies several targets.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		local tgts = getAnomalyTargets(self, t, x, y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		for i = 1, rng.avg(1, 5, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			if a:canBe("anomaly") and a:canBe("stun") and a:canBe("stone") and a:canBe("instakill")then
				a:setEffect(a.EFF_STONED, getAnomalyDuration(self, t), {apply_power=getParadoxSpellpower(self, t)})
				game.level.map:particleEmitter(a.x, a.y, 1, "archery")
			end
		end
		return true
	end,
	info = function(self, t)
		return ([[Turns up to 5 targets in a radius %d ball to stone for %d turns.]]):
		format(getAnomalyRadius(self, t), getAnomalyDuration(self, t))
	end,
}

newTalent{
	name = "Anomaly Call",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 50,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="hit", range=self:getTalentRange(t), talent=t}
	end,
	message = "@Source@ teleports several targets to @Source@'s location.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tgts = getAnomalyTargets(self, t, self.x, self.y, "ACTOR", self:getTalentRange(t), true)

		-- Randomly take targets
		for i = 1, rng.avg(3, 6, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			if a:canBe("teleport") and a:canBe("anomaly") then
				game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
				a:teleportRandom(self.x, self.y, self:getTalentRadius(t)*2, self:getTalentRadius(t))
				game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
			end
		end
		return true
	end,
	info = function(self, t)
		return ([[Teleports between 3 and 6 targets to the caster.]]):
		format()
	end,
}

newTalent{
	name = "Anomaly Deus Ex",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="hit", range=self:getTalentRange(t), talent=t}
	end,
	getHaste = function(self, t) return 1 - 1 / (1 + (getAnomalyEffectPower(self, t)) / 100) end,
	message = "The odds have tilted.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tgts = getAnomalyTargets(self, t, self.x, self.y, "ACTOR", self:getTalentRange(t))

		-- Randomly take targets
		if #tgts <= 0 then return end
		local a, id = rng.table(tgts)
		table.remove(tgts, id)
		checkAnomalyTriggers(self, a)

		a:setEffect(self.EFF_SPEED, getAnomalyDuration(self, t), {power=t.getHaste(self, t)})
		a:setEffect(self.EFF_REGENERATION,  getAnomalyDuration(self, t), {power=getAnomalyEffectPower(self, t)})
		a:setEffect(self.EFF_PAIN_SUPPRESSION,  getAnomalyDuration(self, t), {power=getAnomalyEffectPower(self, t)})
		game.level.map:particleEmitter(a.x, a.y, 1, "temporal_teleport")
		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		return ([[Substantially toughens and hastes one target for %d turns.]]):format(getAnomalyDuration(self, t))
	end,
}

newTalent{
	name = "Anomaly Evil Twin",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="hit", range=self:getTalentRange(t), talent=t}
	end,
	message = "@Source@'s evil twin has come from another timeline.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)

		local x, y = util.findFreeGrid(self.x, self.y, 3, true, {[Map.ACTOR]=true})
		if not x then
			return
		end
		if self:attr("summon_time") then return end
		local m = makeParadoxClone(self, self, getAnomalyDuration(self, t)*2)
		game.zone:addEntity(game.level, m, "actor", x, y)
		m.faction = "enemies"
		m.summoner = nil
		m.target = self
		checkAnomalyTriggers(self, self)
		game.level.map:particleEmitter(x, y, 1, "generic_teleport", {rm=60, rM=130, gm=20, gM=110, bm=90, bM=130, am=70, aM=180})

		return true
	end,
	info = function(self, t)
		return ([[Clones the caster.]]):format(getAnomalyDuration(self, t))
	end,
}

newTalent{
	name = "Anomaly Intersecting Threads",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="hit", range=self:getTalentRange(t), talent=t}
	end,
	message = "@Source@ has caused two threads to merge.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tgts = getAnomalyTargets(self, t, self.x, self.y, "ACTOR", self:getTalentRange(t))

		-- Randomly take targets
		for i = 1, #tgts do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			checkAnomalyTriggers(self, a)
			
			local x, y = util.findFreeGrid(a.x, a.y, 3, true, {[Map.ACTOR]=true})
			if not x then
				return
			end
			if a:attr("summon_time") then return end
			local m = makeParadoxClone(self, a, getAnomalyDuration(self, t)*2)
			game.zone:addEntity(game.level, m, "actor", x, y)
			m.ai_state = { talent_in=1, ally_compassion=10}
			game.level.map:particleEmitter(x, y, 1, "generic_teleport", {rm=60, rM=130, gm=20, gM=110, bm=90, bM=130, am=70, aM=180})
		end

		return true
	end,
	info = function(self, t)
		return ([[Clones all creatures in a radius of 10.]]):format(getAnomalyDuration(self, t))
	end,
}

newTalent{
	name = "Anomaly Mass Dig",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,

requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ digs out a huge area.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		for i = 1, rng.avg(3, 6, 3) do
			local orig_x, orig_y = getAnomalyPosition(self, self:getTalentRange(t))

			self:project(tg, orig_x, orig_y, DamageType.DIG, 1)
			game.level.map:particleEmitter(orig_x, orig_y, tg.radius, "ball_earth", {radius=tg.radius})
		end
		game:playSoundNear(self, "talents/breath")
		return true
	end,
	info = function(self, t)
		return ([[Digs out all terrain in between three and six radius %d balls.]]):format(self:getTalentRadius(t))
	end,
}

newTalent{
	name = "Anomaly Sphere of Destruction",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ creates a sphere of destruction.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tgts = getAnomalyTargets(self, t, self.x, self.y, "ACTOR", self:getTalentRange(t))
		
		local movedam = self:spellCrit(getAnomalyDamage(self, t)) -- High damage

		-- Randomly take targets
		if #tgts <= 0 then return end
		local target, id = rng.table(tgts)
		table.remove(tgts, id)
		local orig_x, orig_y = getAnomalyPosition(self, self:getTalentRange(t))
		checkAnomalyTriggers(self, target)
					
		local proj = require("mod.class.Projectile"):makeHoming(
			self,
			{particle = "bolt_dark", trail = "darktrail"},
			{speed=1, name="Sphere of Destruction", start_x=orig_x, start_y=orig_y, dam=movedam, movedam=movedam},
			target,
			self:getTalentRange(t),
			function(self, src)
				local DT = require("engine.DamageType")
				DT:get(DT.TEMPORAL).projector(src, self.x, self.y, DT.TEMPORAL, self.def.movedam)
				DT:get(DT.DARKNESS).projector(src, self.x, self.y, DT.DARKNESS, self.def.movedam)
			end,
			function(self, src, target)
				local DT = require("engine.DamageType")
				DT:get(DT.TEMPORAL).projector(src, self.x, self.y, DT.TEMPORAL, self.def.movedam)
				DT:get(DT.DARKNESS).projector(src, self.x, self.y, DT.DARKNESS, self.def.movedam)
			end
		)
		
		game.zone:addEntity(game.level, proj, "projectile", orig_x, orig_y)
		game:playSoundNear(self, "talents/distortion")
		return true
	end,
	info = function(self, t)
		return ([[Summons a sphere of destruction.]]):format()
	end,
}

newTalent{
	name = "Anomaly Tornado",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ causes a tornado storm.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tgts = getAnomalyTargets(self, t, self.x, self.y, "ACTOR", self:getTalentRange(t))

		local movedam = self:spellCrit(getAnomalyDamage(self, t))
		local dam = self:spellCrit(getAnomalyDamage(self, t)/2)
		local apply_power = getParadoxSpellpower(self, t)

		-- Randomly take targets
		for i = 1, rng.avg(3, 6, 3) do
			if #tgts <= 0 then break end
			local target, id = rng.table(tgts)
			table.remove(tgts, id)
			local orig_x, orig_y = getAnomalyPosition(self, self:getTalentRange(t))
			checkAnomalyTriggers(self, target)
						
			local proj = require("mod.class.Projectile"):makeHoming(
				self,
				{particle="bolt_lightning", trail="lightningtrail"},
				{speed=2, name="Tornado", dam=dam, movedam=movedam, start_x=orig_x, start_y=orig_y, apply=apply_power},
				target,
				self:getTalentRange(t),
				function(self, src)
					local DT = require("engine.DamageType")
					DT:get(DT.LIGHTNING).projector(src, self.x, self.y, DT.LIGHTNING, self.def.movedam)
				end,
				function(self, src, target)
					local DT = require("engine.DamageType")
					src:project({type="ball", radius=1, x=self.x, y=self.y}, self.x, self.y, DT.LIGHTNING, self.def.dam)
					src:project({type="ball", radius=1, x=self.x, y=self.y}, self.x, self.y, DT.MINDKNOCKBACK, self.def.dam)
					if target:canBe("stun") then
						target:setEffect(target.EFF_STUNNED, 4, {apply_power=self.def.apply})
					else
						game.logSeen(target, "%s resists the tornado!", target.name:capitalize())
					end

					-- Lightning ball gets a special treatment to make it look neat
					local sradius = (1 + 0.5) * (engine.Map.tile_w + engine.Map.tile_h) / 2
					local nb_forks = 16
					local angle_diff = 360 / nb_forks
					for i = 0, nb_forks - 1 do
						local a = math.rad(rng.range(0+i*angle_diff,angle_diff+i*angle_diff))
						local tx = self.x + math.floor(math.cos(a) * 1)
						local ty = self.y + math.floor(math.sin(a) * 1)
						game.level.map:particleEmitter(self.x, self.y, 1, "lightning", {radius=1, tx=tx-self.x, ty=ty-self.y, nb_particles=25, life=8})
					end
					game:playSoundNear(self, "talents/lightning")
				end
			)
			game.zone:addEntity(game.level, proj, "projectile", orig_x, orig_y)
			game:playSoundNear(self, "talents/lightning")
		end
		return true
	end,
	info = function(self, t)
		return ([[Summons three to six tornados.]]):format()
	end,
}

newTalent{
	name = "Anomaly Meteor",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ causes a meteor to fall from the sky.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = getAnomalyPosition(self, self:getTalentRange(t))

		local terrains = t.terrains or mod.class.Grid:loadList("/data/general/grids/lava.lua")
		t.terrains = terrains -- cache

		local meteor = function(src, x, y, dam)
			game.level.map:particleEmitter(x, y, 10, "meteor", {x=x, y=y}).on_remove = function(self)
				local x, y = self.args.x, self.args.y
				game.level.map:particleEmitter(x, y, 10, "fireflash", {radius=tg.radius})
				game:playSoundNear(game.player, "talents/fireflash")

				local grids = {}
				for i = x-tg.radius, x+tg.radius do for j = y-tg.radius, y+tg.radius do
					local oe = game.level.map(i, j, engine.Map.TERRAIN)
					if oe and not oe:attr("temporary") and
					(core.fov.distance(x, y, i, j) < 1 or rng.percent(40)) and (game.level.map:checkEntity(i, j, engine.Map.TERRAIN, "dig") or game.level.map:checkEntity(i, j, engine.Map.TERRAIN, "grow")) then
						local g = terrains.LAVA_FLOOR:clone()
						g:resolve() g:resolve(nil, true)
						game.zone:addEntity(game.level, g, "terrain", i, j)
						grids[#grids+1] = {x=i,y=j,oe=oe}
					end
				end end
				for i = x-tg.radius, x+tg.radius do for j = y-tg.radius, y+tg.radius do
					game.nicer_tiles:updateAround(game.level, i, j)
				end end
				for _, spot in ipairs(grids) do
					local i, j = spot.x, spot.y
					local g = game.level.map(i, j, engine.Map.TERRAIN)
					g.temporary = 8
					g.x = i g.y = j
					g.canAct = false
					g.energy = { value = 0, mod = 1 }
					g.old_feat = spot.oe
					g.useEnergy = mod.class.Trap.useEnergy
					g.act = function(self)
						self:useEnergy()
						self.temporary = self.temporary - 1
						if self.temporary <= 0 then
							game.level.map(self.x, self.y, engine.Map.TERRAIN, self.old_feat)
							game.level:removeEntity(self)
							game.nicer_tiles:updateAround(game.level, self.x, self.y)
						end
					end
					game.level:addEntity(g)
				end

				src:project({type="ball", radius=tg.radius}, x, y, engine.DamageType.FIRE, dam/2)
				src:project({type="ball", radius=tg.radius}, x, y, engine.DamageType.PHYSICAL, dam/2)
				src:project({type="ball", radius=tg.radius}, x, y, function(px, py)
					local target = game.level.map(px, py, engine.Map.ACTOR)
					if target then
						if target:canBe("stun") then
							target:setEffect(target.EFF_STUNNED, 3, {apply_power=getParadoxSpellpower(src, t)})
						else
							game.logSeen(target, "%s resists the stun!", target.name:capitalize())
						end
					end
				end)
				if core.shader.allow("distort") then game.level.map:particleEmitter(x, y, tg.radius, "shockwave", {radius=tg.radius}) end
				game:getPlayer(true):attr("meteoric_crash", 1)
			end
		end

		local dam = self:spellCrit(getAnomalyDamage(self, t))
		meteor(self, x, y, dam)

		return true
	end,
	info = function(self, t)
		return ([[Causes a meteor to fall from the sky.]]):
		format()
	end,
}

newTalent{
	name = "Anomaly Spacetime Tear",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "@Source@ tears a hole in the fabric of spacetime.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tx, ty = getAnomalyPosition(self, self:getTalentRange(t))

		-- Make a trap so the player can shut it
		local npcs = mod.class.NPC:loadList{"/data/general/npcs/horror_temporal.lua"}
		local trap = Trap.new{
			name = "Spacetime Tear",
			type = "time", id_by_type=true, unided_name = "trap",
			display = '^', color=colors.GOLD, image = "object/temporal_instability.png",
			npc_type = npcs,
			canTrigger = function(self, x, y, who)
				if who == self.summoned_by then return mod.class.Trap.canTrigger(self, x, y, who) end
				return false
			end,
			triggered = function(self, x, y, who)
				if who == self.summoned_by then
					if game.level.map(self.x, self.y, engine.Map.TRAP) == self then game.level.map:remove(self.x, self.y, engine.Map.TRAP) end
					game.level:removeEntity(self)
					game.logPlayer(who, "%s forces the tear shut!", who.name:capitalize())
				end
				return true
			end,
			temporary = getAnomalyDuration(self, t)*10,
			x = tx, y = ty,
			canAct = false,
			energy = {value=0},
			act = function(self)
				self:useEnergy()
				self.temporary = self.temporary - 1
				if self.temporary <= 0 then
					if game.level.map(self.x, self.y, engine.Map.TRAP) == self then game.level.map:remove(self.x, self.y, engine.Map.TRAP) end
					game.level:removeEntity(self)
				end
				-- Summon Temporal Horrors each turn
				local m = game.zone:makeEntity(game.level, "actor", {base_list=self.npc_type}, nil, true)
				if self.temporary%4 == 0 and m then
					local i, j = util.findFreeGrid(self.x, self.y, 5, true, {[engine.Map.ACTOR]=true})
					if not i then
						return
					end
					m.exp_worth = 0
					game.zone:addEntity(game.level, m, "actor", i, j)
					game.level.map:particleEmitter(i, j, 1, "temporal_teleport")
					game:playSoundNear(m, "distortion")
				end
			end,
			summoned_by = self, -- 'summoner' can't trigger own traps
		}
		
		game.level:addEntity(trap)
		trap:identify(true)
		trap:setKnown(self, true)
		game.zone:addEntity(game.level, trap, "trap", tx, ty)
		game:playSoundNear(self, "talents/arcane")
		
		return true
	end,
	info = function(self, t)
		return ([[Tears a hole in the fabric of spacetime.]]):
		format()
	end,
}

newTalent{
	name = "Anomaly Summon Time Elemental",
	type = {"chronomancy/anomalies", 1},
	anomaly_type = "major",
	type_no_req = true,
	no_unlearn_last = true,
	points = 1,
	paradox = 0,
	cooldown =0,
	range = 10,
	radius = function(self, t) return getAnomalyRadius(self, t) end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	message = "Some Time Elementals have been attracted by @Source@'s meddling.",
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local tgts = getAnomalyTargets(self, t, self.x, self.y, "ACTOR", self:getTalentRadius(t))

		-- Randomly take targets
		for i = 1, rng.avg(3, 6, 3) do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)
			-- Find space
			local i, j = util.findFreeGrid(a.x, a.y, 5, true, {[Map.ACTOR]=true})
			if not i then
				return
			end
			local npcs = mod.class.NPC:loadList{"/data/general/npcs/telugoroth.lua"}
			local m = game.zone:makeEntity(game.level, "actor", {base_list=npcs}, nil, true)
			if m then
				m.exp_worth = 0
				game.zone:addEntity(game.level, m, "actor", i, j)
				game.level.map:particleEmitter(i, j, 1, "temporal_teleport")
				game:playSoundNear({x=i,y=j}, "talents/thunderstorm")
			end
		end

		return true
	end,
	info = function(self, t)
		return ([[Time elementals have been attracted to the timeline.]]):
		format()
	end,
}

--[[newTalent{
	name = "Anomaly Terrain Change",
	type = {"chronomancy/anomalies", 1},
	points = 1,
	type_no_req = true,
	no_unlearn_last = true,
	action = function(self, t)
		return true
	end,
	info = function(self, t)
		return (Random Terrain in a ball.)
	end,
}

newTalent{
	name = "Anomaly Stat Reorder",
	type = {"chronomancy/anomalies", 1},
	points = 1,
	type_no_req = true,
	no_unlearn_last = true,
	action = function(self, t)
		return true
	end,
	info = function(self, t)
		return (Target loses stats.)
	end,
}

newTalent{
	name = "Anomaly Heal",
	type = {"chronomancy/anomalies", 1},
	points = 1,
	type_no_req = true,
	no_unlearn_last = true,
	action = function(self, t)
		return true
	end,
	info = function(self, t)
		return (Target is healed to full life.)
	end,
}


newTalent{
	name = "Anomaly Vertigo",
	type = {"chronomancy/anomalies", 1},
	points = 1,
	type_no_req = true,
	no_npc_use = true,
	no_unlearn_last = true,
	action = function(self, t)
		return true
	end,
	info = function(self, t)
		return ()
	end,
}

}]]