MWI-Hit-Tracker-Canvas

A Tampermonkey script to track MWI hits on Canvas

  1. // ==UserScript==
  2. // @name MWI-Hit-Tracker-Canvas
  3. // @namespace MWI-Hit-Tracker-Canvas
  4. // @version 1.2.4
  5. // @author Artintel, BKN46
  6. // @description A Tampermonkey script to track MWI hits on Canvas
  7. // @icon https://www.milkywayidle.com/favicon.svg
  8. // @include https://*.milkywayidle.com/*
  9. // @match https://www.milkywayidle.com/*
  10. // @license MIT
  11. // ==/UserScript==
  12. (function (exports) {
  13. 'use strict';
  14.  
  15. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  16.  
  17. var check = function (it) {
  18. return it && it.Math == Math && it;
  19. };
  20.  
  21. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  22. var global$c =
  23. // eslint-disable-next-line es/no-global-this -- safe
  24. check(typeof globalThis == 'object' && globalThis) ||
  25. check(typeof window == 'object' && window) ||
  26. // eslint-disable-next-line no-restricted-globals -- safe
  27. check(typeof self == 'object' && self) ||
  28. check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
  29. // eslint-disable-next-line no-new-func -- fallback
  30. (function () { return this; })() || Function('return this')();
  31.  
  32. var objectGetOwnPropertyDescriptor = {};
  33.  
  34. var fails$8 = function (exec) {
  35. try {
  36. return !!exec();
  37. } catch (error) {
  38. return true;
  39. }
  40. };
  41.  
  42. var fails$7 = fails$8;
  43.  
  44. // Detect IE8's incomplete defineProperty implementation
  45. var descriptors = !fails$7(function () {
  46. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  47. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  48. });
  49.  
  50. var objectPropertyIsEnumerable = {};
  51.  
  52. var $propertyIsEnumerable = {}.propertyIsEnumerable;
  53. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  54. var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
  55.  
  56. // Nashorn ~ JDK8 bug
  57. var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
  58.  
  59. // `Object.prototype.propertyIsEnumerable` method implementation
  60. // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
  61. objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  62. var descriptor = getOwnPropertyDescriptor$1(this, V);
  63. return !!descriptor && descriptor.enumerable;
  64. } : $propertyIsEnumerable;
  65.  
  66. var createPropertyDescriptor$2 = function (bitmap, value) {
  67. return {
  68. enumerable: !(bitmap & 1),
  69. configurable: !(bitmap & 2),
  70. writable: !(bitmap & 4),
  71. value: value
  72. };
  73. };
  74.  
  75. var toString = {}.toString;
  76.  
  77. var classofRaw$1 = function (it) {
  78. return toString.call(it).slice(8, -1);
  79. };
  80.  
  81. var fails$6 = fails$8;
  82. var classof$2 = classofRaw$1;
  83.  
  84. var split = ''.split;
  85.  
  86. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  87. var indexedObject = fails$6(function () {
  88. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  89. // eslint-disable-next-line no-prototype-builtins -- safe
  90. return !Object('z').propertyIsEnumerable(0);
  91. }) ? function (it) {
  92. return classof$2(it) == 'String' ? split.call(it, '') : Object(it);
  93. } : Object;
  94.  
  95. // `RequireObjectCoercible` abstract operation
  96. // https://tc39.es/ecma262/#sec-requireobjectcoercible
  97. var requireObjectCoercible$2 = function (it) {
  98. if (it == undefined) throw TypeError("Can't call method on " + it);
  99. return it;
  100. };
  101.  
  102. // toObject with fallback for non-array-like ES3 strings
  103. var IndexedObject = indexedObject;
  104. var requireObjectCoercible$1 = requireObjectCoercible$2;
  105.  
  106. var toIndexedObject$3 = function (it) {
  107. return IndexedObject(requireObjectCoercible$1(it));
  108. };
  109.  
  110. // `IsCallable` abstract operation
  111. // https://tc39.es/ecma262/#sec-iscallable
  112. var isCallable$d = function (argument) {
  113. return typeof argument === 'function';
  114. };
  115.  
  116. var isCallable$c = isCallable$d;
  117.  
  118. var isObject$5 = function (it) {
  119. return typeof it === 'object' ? it !== null : isCallable$c(it);
  120. };
  121.  
  122. var global$b = global$c;
  123. var isCallable$b = isCallable$d;
  124.  
  125. var aFunction = function (argument) {
  126. return isCallable$b(argument) ? argument : undefined;
  127. };
  128.  
  129. var getBuiltIn$4 = function (namespace, method) {
  130. return arguments.length < 2 ? aFunction(global$b[namespace]) : global$b[namespace] && global$b[namespace][method];
  131. };
  132.  
  133. var getBuiltIn$3 = getBuiltIn$4;
  134.  
  135. var engineUserAgent = getBuiltIn$3('navigator', 'userAgent') || '';
  136.  
  137. var global$a = global$c;
  138. var userAgent = engineUserAgent;
  139.  
  140. var process = global$a.process;
  141. var Deno = global$a.Deno;
  142. var versions = process && process.versions || Deno && Deno.version;
  143. var v8 = versions && versions.v8;
  144. var match, version;
  145.  
  146. if (v8) {
  147. match = v8.split('.');
  148. version = match[0] < 4 ? 1 : match[0] + match[1];
  149. } else if (userAgent) {
  150. match = userAgent.match(/Edge\/(\d+)/);
  151. if (!match || match[1] >= 74) {
  152. match = userAgent.match(/Chrome\/(\d+)/);
  153. if (match) version = match[1];
  154. }
  155. }
  156.  
  157. var engineV8Version = version && +version;
  158.  
  159. /* eslint-disable es/no-symbol -- required for testing */
  160.  
  161. var V8_VERSION = engineV8Version;
  162. var fails$5 = fails$8;
  163.  
  164. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  165. var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$5(function () {
  166. var symbol = Symbol();
  167. // Chrome 38 Symbol has incorrect toString conversion
  168. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  169. return !String(symbol) || !(Object(symbol) instanceof Symbol) ||
  170. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  171. !Symbol.sham && V8_VERSION && V8_VERSION < 41;
  172. });
  173.  
  174. /* eslint-disable es/no-symbol -- required for testing */
  175.  
  176. var NATIVE_SYMBOL$1 = nativeSymbol;
  177.  
  178. var useSymbolAsUid = NATIVE_SYMBOL$1
  179. && !Symbol.sham
  180. && typeof Symbol.iterator == 'symbol';
  181.  
  182. var isCallable$a = isCallable$d;
  183. var getBuiltIn$2 = getBuiltIn$4;
  184. var USE_SYMBOL_AS_UID$1 = useSymbolAsUid;
  185.  
  186. var isSymbol$2 = USE_SYMBOL_AS_UID$1 ? function (it) {
  187. return typeof it == 'symbol';
  188. } : function (it) {
  189. var $Symbol = getBuiltIn$2('Symbol');
  190. return isCallable$a($Symbol) && Object(it) instanceof $Symbol;
  191. };
  192.  
  193. var tryToString$1 = function (argument) {
  194. try {
  195. return String(argument);
  196. } catch (error) {
  197. return 'Object';
  198. }
  199. };
  200.  
  201. var isCallable$9 = isCallable$d;
  202. var tryToString = tryToString$1;
  203.  
  204. // `Assert: IsCallable(argument) is true`
  205. var aCallable$5 = function (argument) {
  206. if (isCallable$9(argument)) return argument;
  207. throw TypeError(tryToString(argument) + ' is not a function');
  208. };
  209.  
  210. var aCallable$4 = aCallable$5;
  211.  
  212. // `GetMethod` abstract operation
  213. // https://tc39.es/ecma262/#sec-getmethod
  214. var getMethod$4 = function (V, P) {
  215. var func = V[P];
  216. return func == null ? undefined : aCallable$4(func);
  217. };
  218.  
  219. var isCallable$8 = isCallable$d;
  220. var isObject$4 = isObject$5;
  221.  
  222. // `OrdinaryToPrimitive` abstract operation
  223. // https://tc39.es/ecma262/#sec-ordinarytoprimitive
  224. var ordinaryToPrimitive$1 = function (input, pref) {
  225. var fn, val;
  226. if (pref === 'string' && isCallable$8(fn = input.toString) && !isObject$4(val = fn.call(input))) return val;
  227. if (isCallable$8(fn = input.valueOf) && !isObject$4(val = fn.call(input))) return val;
  228. if (pref !== 'string' && isCallable$8(fn = input.toString) && !isObject$4(val = fn.call(input))) return val;
  229. throw TypeError("Can't convert object to primitive value");
  230. };
  231.  
  232. var shared$3 = {exports: {}};
  233.  
  234. var global$9 = global$c;
  235.  
  236. var setGlobal$3 = function (key, value) {
  237. try {
  238. // eslint-disable-next-line es/no-object-defineproperty -- safe
  239. Object.defineProperty(global$9, key, { value: value, configurable: true, writable: true });
  240. } catch (error) {
  241. global$9[key] = value;
  242. } return value;
  243. };
  244.  
  245. var global$8 = global$c;
  246. var setGlobal$2 = setGlobal$3;
  247.  
  248. var SHARED = '__core-js_shared__';
  249. var store$3 = global$8[SHARED] || setGlobal$2(SHARED, {});
  250.  
  251. var sharedStore = store$3;
  252.  
  253. var store$2 = sharedStore;
  254.  
  255. (shared$3.exports = function (key, value) {
  256. return store$2[key] || (store$2[key] = value !== undefined ? value : {});
  257. })('versions', []).push({
  258. version: '3.18.3',
  259. mode: 'global',
  260. copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
  261. });
  262.  
  263. var requireObjectCoercible = requireObjectCoercible$2;
  264.  
  265. // `ToObject` abstract operation
  266. // https://tc39.es/ecma262/#sec-toobject
  267. var toObject$2 = function (argument) {
  268. return Object(requireObjectCoercible(argument));
  269. };
  270.  
  271. var toObject$1 = toObject$2;
  272.  
  273. var hasOwnProperty = {}.hasOwnProperty;
  274.  
  275. // `HasOwnProperty` abstract operation
  276. // https://tc39.es/ecma262/#sec-hasownproperty
  277. var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
  278. return hasOwnProperty.call(toObject$1(it), key);
  279. };
  280.  
  281. var id = 0;
  282. var postfix = Math.random();
  283.  
  284. var uid$2 = function (key) {
  285. return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
  286. };
  287.  
  288. var global$7 = global$c;
  289. var shared$2 = shared$3.exports;
  290. var hasOwn$8 = hasOwnProperty_1;
  291. var uid$1 = uid$2;
  292. var NATIVE_SYMBOL = nativeSymbol;
  293. var USE_SYMBOL_AS_UID = useSymbolAsUid;
  294.  
  295. var WellKnownSymbolsStore = shared$2('wks');
  296. var Symbol$1 = global$7.Symbol;
  297. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1;
  298.  
  299. var wellKnownSymbol$8 = function (name) {
  300. if (!hasOwn$8(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) {
  301. if (NATIVE_SYMBOL && hasOwn$8(Symbol$1, name)) {
  302. WellKnownSymbolsStore[name] = Symbol$1[name];
  303. } else {
  304. WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  305. }
  306. } return WellKnownSymbolsStore[name];
  307. };
  308.  
  309. var isObject$3 = isObject$5;
  310. var isSymbol$1 = isSymbol$2;
  311. var getMethod$3 = getMethod$4;
  312. var ordinaryToPrimitive = ordinaryToPrimitive$1;
  313. var wellKnownSymbol$7 = wellKnownSymbol$8;
  314.  
  315. var TO_PRIMITIVE = wellKnownSymbol$7('toPrimitive');
  316.  
  317. // `ToPrimitive` abstract operation
  318. // https://tc39.es/ecma262/#sec-toprimitive
  319. var toPrimitive$1 = function (input, pref) {
  320. if (!isObject$3(input) || isSymbol$1(input)) return input;
  321. var exoticToPrim = getMethod$3(input, TO_PRIMITIVE);
  322. var result;
  323. if (exoticToPrim) {
  324. if (pref === undefined) pref = 'default';
  325. result = exoticToPrim.call(input, pref);
  326. if (!isObject$3(result) || isSymbol$1(result)) return result;
  327. throw TypeError("Can't convert object to primitive value");
  328. }
  329. if (pref === undefined) pref = 'number';
  330. return ordinaryToPrimitive(input, pref);
  331. };
  332.  
  333. var toPrimitive = toPrimitive$1;
  334. var isSymbol = isSymbol$2;
  335.  
  336. // `ToPropertyKey` abstract operation
  337. // https://tc39.es/ecma262/#sec-topropertykey
  338. var toPropertyKey$2 = function (argument) {
  339. var key = toPrimitive(argument, 'string');
  340. return isSymbol(key) ? key : String(key);
  341. };
  342.  
  343. var global$6 = global$c;
  344. var isObject$2 = isObject$5;
  345.  
  346. var document$1 = global$6.document;
  347. // typeof document.createElement is 'object' in old IE
  348. var EXISTS$1 = isObject$2(document$1) && isObject$2(document$1.createElement);
  349.  
  350. var documentCreateElement$1 = function (it) {
  351. return EXISTS$1 ? document$1.createElement(it) : {};
  352. };
  353.  
  354. var DESCRIPTORS$5 = descriptors;
  355. var fails$4 = fails$8;
  356. var createElement = documentCreateElement$1;
  357.  
  358. // Thank's IE8 for his funny defineProperty
  359. var ie8DomDefine = !DESCRIPTORS$5 && !fails$4(function () {
  360. // eslint-disable-next-line es/no-object-defineproperty -- requied for testing
  361. return Object.defineProperty(createElement('div'), 'a', {
  362. get: function () { return 7; }
  363. }).a != 7;
  364. });
  365.  
  366. var DESCRIPTORS$4 = descriptors;
  367. var propertyIsEnumerableModule = objectPropertyIsEnumerable;
  368. var createPropertyDescriptor$1 = createPropertyDescriptor$2;
  369. var toIndexedObject$2 = toIndexedObject$3;
  370. var toPropertyKey$1 = toPropertyKey$2;
  371. var hasOwn$7 = hasOwnProperty_1;
  372. var IE8_DOM_DEFINE$1 = ie8DomDefine;
  373.  
  374. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  375. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  376.  
  377. // `Object.getOwnPropertyDescriptor` method
  378. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  379. objectGetOwnPropertyDescriptor.f = DESCRIPTORS$4 ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  380. O = toIndexedObject$2(O);
  381. P = toPropertyKey$1(P);
  382. if (IE8_DOM_DEFINE$1) try {
  383. return $getOwnPropertyDescriptor(O, P);
  384. } catch (error) { /* empty */ }
  385. if (hasOwn$7(O, P)) return createPropertyDescriptor$1(!propertyIsEnumerableModule.f.call(O, P), O[P]);
  386. };
  387.  
  388. var objectDefineProperty = {};
  389.  
  390. var isObject$1 = isObject$5;
  391.  
  392. // `Assert: Type(argument) is Object`
  393. var anObject$b = function (argument) {
  394. if (isObject$1(argument)) return argument;
  395. throw TypeError(String(argument) + ' is not an object');
  396. };
  397.  
  398. var DESCRIPTORS$3 = descriptors;
  399. var IE8_DOM_DEFINE = ie8DomDefine;
  400. var anObject$a = anObject$b;
  401. var toPropertyKey = toPropertyKey$2;
  402.  
  403. // eslint-disable-next-line es/no-object-defineproperty -- safe
  404. var $defineProperty = Object.defineProperty;
  405.  
  406. // `Object.defineProperty` method
  407. // https://tc39.es/ecma262/#sec-object.defineproperty
  408. objectDefineProperty.f = DESCRIPTORS$3 ? $defineProperty : function defineProperty(O, P, Attributes) {
  409. anObject$a(O);
  410. P = toPropertyKey(P);
  411. anObject$a(Attributes);
  412. if (IE8_DOM_DEFINE) try {
  413. return $defineProperty(O, P, Attributes);
  414. } catch (error) { /* empty */ }
  415. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  416. if ('value' in Attributes) O[P] = Attributes.value;
  417. return O;
  418. };
  419.  
  420. var DESCRIPTORS$2 = descriptors;
  421. var definePropertyModule$2 = objectDefineProperty;
  422. var createPropertyDescriptor = createPropertyDescriptor$2;
  423.  
  424. var createNonEnumerableProperty$5 = DESCRIPTORS$2 ? function (object, key, value) {
  425. return definePropertyModule$2.f(object, key, createPropertyDescriptor(1, value));
  426. } : function (object, key, value) {
  427. object[key] = value;
  428. return object;
  429. };
  430.  
  431. var redefine$3 = {exports: {}};
  432.  
  433. var isCallable$7 = isCallable$d;
  434. var store$1 = sharedStore;
  435.  
  436. var functionToString = Function.toString;
  437.  
  438. // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
  439. if (!isCallable$7(store$1.inspectSource)) {
  440. store$1.inspectSource = function (it) {
  441. return functionToString.call(it);
  442. };
  443. }
  444.  
  445. var inspectSource$2 = store$1.inspectSource;
  446.  
  447. var global$5 = global$c;
  448. var isCallable$6 = isCallable$d;
  449. var inspectSource$1 = inspectSource$2;
  450.  
  451. var WeakMap$1 = global$5.WeakMap;
  452.  
  453. var nativeWeakMap = isCallable$6(WeakMap$1) && /native code/.test(inspectSource$1(WeakMap$1));
  454.  
  455. var shared$1 = shared$3.exports;
  456. var uid = uid$2;
  457.  
  458. var keys = shared$1('keys');
  459.  
  460. var sharedKey$3 = function (key) {
  461. return keys[key] || (keys[key] = uid(key));
  462. };
  463.  
  464. var hiddenKeys$4 = {};
  465.  
  466. var NATIVE_WEAK_MAP = nativeWeakMap;
  467. var global$4 = global$c;
  468. var isObject = isObject$5;
  469. var createNonEnumerableProperty$4 = createNonEnumerableProperty$5;
  470. var hasOwn$6 = hasOwnProperty_1;
  471. var shared = sharedStore;
  472. var sharedKey$2 = sharedKey$3;
  473. var hiddenKeys$3 = hiddenKeys$4;
  474.  
  475. var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
  476. var WeakMap = global$4.WeakMap;
  477. var set, get, has;
  478.  
  479. var enforce = function (it) {
  480. return has(it) ? get(it) : set(it, {});
  481. };
  482.  
  483. var getterFor = function (TYPE) {
  484. return function (it) {
  485. var state;
  486. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  487. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  488. } return state;
  489. };
  490. };
  491.  
  492. if (NATIVE_WEAK_MAP || shared.state) {
  493. var store = shared.state || (shared.state = new WeakMap());
  494. var wmget = store.get;
  495. var wmhas = store.has;
  496. var wmset = store.set;
  497. set = function (it, metadata) {
  498. if (wmhas.call(store, it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  499. metadata.facade = it;
  500. wmset.call(store, it, metadata);
  501. return metadata;
  502. };
  503. get = function (it) {
  504. return wmget.call(store, it) || {};
  505. };
  506. has = function (it) {
  507. return wmhas.call(store, it);
  508. };
  509. } else {
  510. var STATE = sharedKey$2('state');
  511. hiddenKeys$3[STATE] = true;
  512. set = function (it, metadata) {
  513. if (hasOwn$6(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  514. metadata.facade = it;
  515. createNonEnumerableProperty$4(it, STATE, metadata);
  516. return metadata;
  517. };
  518. get = function (it) {
  519. return hasOwn$6(it, STATE) ? it[STATE] : {};
  520. };
  521. has = function (it) {
  522. return hasOwn$6(it, STATE);
  523. };
  524. }
  525.  
  526. var internalState = {
  527. set: set,
  528. get: get,
  529. has: has,
  530. enforce: enforce,
  531. getterFor: getterFor
  532. };
  533.  
  534. var DESCRIPTORS$1 = descriptors;
  535. var hasOwn$5 = hasOwnProperty_1;
  536.  
  537. var FunctionPrototype = Function.prototype;
  538. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  539. var getDescriptor = DESCRIPTORS$1 && Object.getOwnPropertyDescriptor;
  540.  
  541. var EXISTS = hasOwn$5(FunctionPrototype, 'name');
  542. // additional protection from minified / mangled / dropped function names
  543. var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something';
  544. var CONFIGURABLE = EXISTS && (!DESCRIPTORS$1 || (DESCRIPTORS$1 && getDescriptor(FunctionPrototype, 'name').configurable));
  545.  
  546. var functionName = {
  547. EXISTS: EXISTS,
  548. PROPER: PROPER,
  549. CONFIGURABLE: CONFIGURABLE
  550. };
  551.  
  552. var global$3 = global$c;
  553. var isCallable$5 = isCallable$d;
  554. var hasOwn$4 = hasOwnProperty_1;
  555. var createNonEnumerableProperty$3 = createNonEnumerableProperty$5;
  556. var setGlobal$1 = setGlobal$3;
  557. var inspectSource = inspectSource$2;
  558. var InternalStateModule$1 = internalState;
  559. var CONFIGURABLE_FUNCTION_NAME = functionName.CONFIGURABLE;
  560.  
  561. var getInternalState$1 = InternalStateModule$1.get;
  562. var enforceInternalState = InternalStateModule$1.enforce;
  563. var TEMPLATE = String(String).split('String');
  564.  
  565. (redefine$3.exports = function (O, key, value, options) {
  566. var unsafe = options ? !!options.unsafe : false;
  567. var simple = options ? !!options.enumerable : false;
  568. var noTargetGet = options ? !!options.noTargetGet : false;
  569. var name = options && options.name !== undefined ? options.name : key;
  570. var state;
  571. if (isCallable$5(value)) {
  572. if (String(name).slice(0, 7) === 'Symbol(') {
  573. name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']';
  574. }
  575. if (!hasOwn$4(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) {
  576. createNonEnumerableProperty$3(value, 'name', name);
  577. }
  578. state = enforceInternalState(value);
  579. if (!state.source) {
  580. state.source = TEMPLATE.join(typeof name == 'string' ? name : '');
  581. }
  582. }
  583. if (O === global$3) {
  584. if (simple) O[key] = value;
  585. else setGlobal$1(key, value);
  586. return;
  587. } else if (!unsafe) {
  588. delete O[key];
  589. } else if (!noTargetGet && O[key]) {
  590. simple = true;
  591. }
  592. if (simple) O[key] = value;
  593. else createNonEnumerableProperty$3(O, key, value);
  594. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  595. })(Function.prototype, 'toString', function toString() {
  596. return isCallable$5(this) && getInternalState$1(this).source || inspectSource(this);
  597. });
  598.  
  599. var objectGetOwnPropertyNames = {};
  600.  
  601. var ceil = Math.ceil;
  602. var floor = Math.floor;
  603.  
  604. // `ToIntegerOrInfinity` abstract operation
  605. // https://tc39.es/ecma262/#sec-tointegerorinfinity
  606. var toIntegerOrInfinity$2 = function (argument) {
  607. var number = +argument;
  608. // eslint-disable-next-line no-self-compare -- safe
  609. return number !== number || number === 0 ? 0 : (number > 0 ? floor : ceil)(number);
  610. };
  611.  
  612. var toIntegerOrInfinity$1 = toIntegerOrInfinity$2;
  613.  
  614. var max = Math.max;
  615. var min$1 = Math.min;
  616.  
  617. // Helper for a popular repeating case of the spec:
  618. // Let integer be ? ToInteger(index).
  619. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  620. var toAbsoluteIndex$1 = function (index, length) {
  621. var integer = toIntegerOrInfinity$1(index);
  622. return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
  623. };
  624.  
  625. var toIntegerOrInfinity = toIntegerOrInfinity$2;
  626.  
  627. var min = Math.min;
  628.  
  629. // `ToLength` abstract operation
  630. // https://tc39.es/ecma262/#sec-tolength
  631. var toLength$1 = function (argument) {
  632. return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  633. };
  634.  
  635. var toLength = toLength$1;
  636.  
  637. // `LengthOfArrayLike` abstract operation
  638. // https://tc39.es/ecma262/#sec-lengthofarraylike
  639. var lengthOfArrayLike$2 = function (obj) {
  640. return toLength(obj.length);
  641. };
  642.  
  643. var toIndexedObject$1 = toIndexedObject$3;
  644. var toAbsoluteIndex = toAbsoluteIndex$1;
  645. var lengthOfArrayLike$1 = lengthOfArrayLike$2;
  646.  
  647. // `Array.prototype.{ indexOf, includes }` methods implementation
  648. var createMethod = function (IS_INCLUDES) {
  649. return function ($this, el, fromIndex) {
  650. var O = toIndexedObject$1($this);
  651. var length = lengthOfArrayLike$1(O);
  652. var index = toAbsoluteIndex(fromIndex, length);
  653. var value;
  654. // Array#includes uses SameValueZero equality algorithm
  655. // eslint-disable-next-line no-self-compare -- NaN check
  656. if (IS_INCLUDES && el != el) while (length > index) {
  657. value = O[index++];
  658. // eslint-disable-next-line no-self-compare -- NaN check
  659. if (value != value) return true;
  660. // Array#indexOf ignores holes, Array#includes - not
  661. } else for (;length > index; index++) {
  662. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  663. } return !IS_INCLUDES && -1;
  664. };
  665. };
  666.  
  667. var arrayIncludes = {
  668. // `Array.prototype.includes` method
  669. // https://tc39.es/ecma262/#sec-array.prototype.includes
  670. includes: createMethod(true),
  671. // `Array.prototype.indexOf` method
  672. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  673. indexOf: createMethod(false)
  674. };
  675.  
  676. var hasOwn$3 = hasOwnProperty_1;
  677. var toIndexedObject = toIndexedObject$3;
  678. var indexOf = arrayIncludes.indexOf;
  679. var hiddenKeys$2 = hiddenKeys$4;
  680.  
  681. var objectKeysInternal = function (object, names) {
  682. var O = toIndexedObject(object);
  683. var i = 0;
  684. var result = [];
  685. var key;
  686. for (key in O) !hasOwn$3(hiddenKeys$2, key) && hasOwn$3(O, key) && result.push(key);
  687. // Don't enum bug & hidden keys
  688. while (names.length > i) if (hasOwn$3(O, key = names[i++])) {
  689. ~indexOf(result, key) || result.push(key);
  690. }
  691. return result;
  692. };
  693.  
  694. // IE8- don't enum bug keys
  695. var enumBugKeys$3 = [
  696. 'constructor',
  697. 'hasOwnProperty',
  698. 'isPrototypeOf',
  699. 'propertyIsEnumerable',
  700. 'toLocaleString',
  701. 'toString',
  702. 'valueOf'
  703. ];
  704.  
  705. var internalObjectKeys$1 = objectKeysInternal;
  706. var enumBugKeys$2 = enumBugKeys$3;
  707.  
  708. var hiddenKeys$1 = enumBugKeys$2.concat('length', 'prototype');
  709.  
  710. // `Object.getOwnPropertyNames` method
  711. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  712. // eslint-disable-next-line es/no-object-getownpropertynames -- safe
  713. objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  714. return internalObjectKeys$1(O, hiddenKeys$1);
  715. };
  716.  
  717. var objectGetOwnPropertySymbols = {};
  718.  
  719. // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
  720. objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols;
  721.  
  722. var getBuiltIn$1 = getBuiltIn$4;
  723. var getOwnPropertyNamesModule = objectGetOwnPropertyNames;
  724. var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols;
  725. var anObject$9 = anObject$b;
  726.  
  727. // all object keys, includes non-enumerable and symbols
  728. var ownKeys$1 = getBuiltIn$1('Reflect', 'ownKeys') || function ownKeys(it) {
  729. var keys = getOwnPropertyNamesModule.f(anObject$9(it));
  730. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  731. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  732. };
  733.  
  734. var hasOwn$2 = hasOwnProperty_1;
  735. var ownKeys = ownKeys$1;
  736. var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor;
  737. var definePropertyModule$1 = objectDefineProperty;
  738.  
  739. var copyConstructorProperties$1 = function (target, source) {
  740. var keys = ownKeys(source);
  741. var defineProperty = definePropertyModule$1.f;
  742. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  743. for (var i = 0; i < keys.length; i++) {
  744. var key = keys[i];
  745. if (!hasOwn$2(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  746. }
  747. };
  748.  
  749. var fails$3 = fails$8;
  750. var isCallable$4 = isCallable$d;
  751.  
  752. var replacement = /#|\.prototype\./;
  753.  
  754. var isForced$1 = function (feature, detection) {
  755. var value = data[normalize(feature)];
  756. return value == POLYFILL ? true
  757. : value == NATIVE ? false
  758. : isCallable$4(detection) ? fails$3(detection)
  759. : !!detection;
  760. };
  761.  
  762. var normalize = isForced$1.normalize = function (string) {
  763. return String(string).replace(replacement, '.').toLowerCase();
  764. };
  765.  
  766. var data = isForced$1.data = {};
  767. var NATIVE = isForced$1.NATIVE = 'N';
  768. var POLYFILL = isForced$1.POLYFILL = 'P';
  769.  
  770. var isForced_1 = isForced$1;
  771.  
  772. var global$2 = global$c;
  773. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  774. var createNonEnumerableProperty$2 = createNonEnumerableProperty$5;
  775. var redefine$2 = redefine$3.exports;
  776. var setGlobal = setGlobal$3;
  777. var copyConstructorProperties = copyConstructorProperties$1;
  778. var isForced = isForced_1;
  779.  
  780. /*
  781. options.target - name of the target object
  782. options.global - target is the global object
  783. options.stat - export as static methods of target
  784. options.proto - export as prototype methods of target
  785. options.real - real prototype method for the `pure` version
  786. options.forced - export even if the native feature is available
  787. options.bind - bind methods to the target, required for the `pure` version
  788. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  789. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  790. options.sham - add a flag to not completely full polyfills
  791. options.enumerable - export as enumerable property
  792. options.noTargetGet - prevent calling a getter on target
  793. options.name - the .name of the function if it does not match the key
  794. */
  795. var _export = function (options, source) {
  796. var TARGET = options.target;
  797. var GLOBAL = options.global;
  798. var STATIC = options.stat;
  799. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  800. if (GLOBAL) {
  801. target = global$2;
  802. } else if (STATIC) {
  803. target = global$2[TARGET] || setGlobal(TARGET, {});
  804. } else {
  805. target = (global$2[TARGET] || {}).prototype;
  806. }
  807. if (target) for (key in source) {
  808. sourceProperty = source[key];
  809. if (options.noTargetGet) {
  810. descriptor = getOwnPropertyDescriptor(target, key);
  811. targetProperty = descriptor && descriptor.value;
  812. } else targetProperty = target[key];
  813. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  814. // contained in target
  815. if (!FORCED && targetProperty !== undefined) {
  816. if (typeof sourceProperty === typeof targetProperty) continue;
  817. copyConstructorProperties(sourceProperty, targetProperty);
  818. }
  819. // add a flag to not completely full polyfills
  820. if (options.sham || (targetProperty && targetProperty.sham)) {
  821. createNonEnumerableProperty$2(sourceProperty, 'sham', true);
  822. }
  823. // extend global
  824. redefine$2(target, key, sourceProperty, options);
  825. }
  826. };
  827.  
  828. var anInstance$1 = function (it, Constructor, name) {
  829. if (it instanceof Constructor) return it;
  830. throw TypeError('Incorrect ' + (name ? name + ' ' : '') + 'invocation');
  831. };
  832.  
  833. var internalObjectKeys = objectKeysInternal;
  834. var enumBugKeys$1 = enumBugKeys$3;
  835.  
  836. // `Object.keys` method
  837. // https://tc39.es/ecma262/#sec-object.keys
  838. // eslint-disable-next-line es/no-object-keys -- safe
  839. var objectKeys$1 = Object.keys || function keys(O) {
  840. return internalObjectKeys(O, enumBugKeys$1);
  841. };
  842.  
  843. var DESCRIPTORS = descriptors;
  844. var definePropertyModule = objectDefineProperty;
  845. var anObject$8 = anObject$b;
  846. var objectKeys = objectKeys$1;
  847.  
  848. // `Object.defineProperties` method
  849. // https://tc39.es/ecma262/#sec-object.defineproperties
  850. // eslint-disable-next-line es/no-object-defineproperties -- safe
  851. var objectDefineProperties = DESCRIPTORS ? Object.defineProperties : function defineProperties(O, Properties) {
  852. anObject$8(O);
  853. var keys = objectKeys(Properties);
  854. var length = keys.length;
  855. var index = 0;
  856. var key;
  857. while (length > index) definePropertyModule.f(O, key = keys[index++], Properties[key]);
  858. return O;
  859. };
  860.  
  861. var getBuiltIn = getBuiltIn$4;
  862.  
  863. var html$1 = getBuiltIn('document', 'documentElement');
  864.  
  865. /* global ActiveXObject -- old IE, WSH */
  866.  
  867. var anObject$7 = anObject$b;
  868. var defineProperties = objectDefineProperties;
  869. var enumBugKeys = enumBugKeys$3;
  870. var hiddenKeys = hiddenKeys$4;
  871. var html = html$1;
  872. var documentCreateElement = documentCreateElement$1;
  873. var sharedKey$1 = sharedKey$3;
  874.  
  875. var GT = '>';
  876. var LT = '<';
  877. var PROTOTYPE = 'prototype';
  878. var SCRIPT = 'script';
  879. var IE_PROTO$1 = sharedKey$1('IE_PROTO');
  880.  
  881. var EmptyConstructor = function () { /* empty */ };
  882.  
  883. var scriptTag = function (content) {
  884. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  885. };
  886.  
  887. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  888. var NullProtoObjectViaActiveX = function (activeXDocument) {
  889. activeXDocument.write(scriptTag(''));
  890. activeXDocument.close();
  891. var temp = activeXDocument.parentWindow.Object;
  892. activeXDocument = null; // avoid memory leak
  893. return temp;
  894. };
  895.  
  896. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  897. var NullProtoObjectViaIFrame = function () {
  898. // Thrash, waste and sodomy: IE GC bug
  899. var iframe = documentCreateElement('iframe');
  900. var JS = 'java' + SCRIPT + ':';
  901. var iframeDocument;
  902. iframe.style.display = 'none';
  903. html.appendChild(iframe);
  904. // https://github.com/zloirock/core-js/issues/475
  905. iframe.src = String(JS);
  906. iframeDocument = iframe.contentWindow.document;
  907. iframeDocument.open();
  908. iframeDocument.write(scriptTag('document.F=Object'));
  909. iframeDocument.close();
  910. return iframeDocument.F;
  911. };
  912.  
  913. // Check for document.domain and active x support
  914. // No need to use active x approach when document.domain is not set
  915. // see https://github.com/es-shims/es5-shim/issues/150
  916. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  917. // avoid IE GC bug
  918. var activeXDocument;
  919. var NullProtoObject = function () {
  920. try {
  921. activeXDocument = new ActiveXObject('htmlfile');
  922. } catch (error) { /* ignore */ }
  923. NullProtoObject = typeof document != 'undefined'
  924. ? document.domain && activeXDocument
  925. ? NullProtoObjectViaActiveX(activeXDocument) // old IE
  926. : NullProtoObjectViaIFrame()
  927. : NullProtoObjectViaActiveX(activeXDocument); // WSH
  928. var length = enumBugKeys.length;
  929. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  930. return NullProtoObject();
  931. };
  932.  
  933. hiddenKeys[IE_PROTO$1] = true;
  934.  
  935. // `Object.create` method
  936. // https://tc39.es/ecma262/#sec-object.create
  937. var objectCreate = Object.create || function create(O, Properties) {
  938. var result;
  939. if (O !== null) {
  940. EmptyConstructor[PROTOTYPE] = anObject$7(O);
  941. result = new EmptyConstructor();
  942. EmptyConstructor[PROTOTYPE] = null;
  943. // add "__proto__" for Object.getPrototypeOf polyfill
  944. result[IE_PROTO$1] = O;
  945. } else result = NullProtoObject();
  946. return Properties === undefined ? result : defineProperties(result, Properties);
  947. };
  948.  
  949. var fails$2 = fails$8;
  950.  
  951. var correctPrototypeGetter = !fails$2(function () {
  952. function F() { /* empty */ }
  953. F.prototype.constructor = null;
  954. // eslint-disable-next-line es/no-object-getprototypeof -- required for testing
  955. return Object.getPrototypeOf(new F()) !== F.prototype;
  956. });
  957.  
  958. var hasOwn$1 = hasOwnProperty_1;
  959. var isCallable$3 = isCallable$d;
  960. var toObject = toObject$2;
  961. var sharedKey = sharedKey$3;
  962. var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter;
  963.  
  964. var IE_PROTO = sharedKey('IE_PROTO');
  965. var ObjectPrototype = Object.prototype;
  966.  
  967. // `Object.getPrototypeOf` method
  968. // https://tc39.es/ecma262/#sec-object.getprototypeof
  969. // eslint-disable-next-line es/no-object-getprototypeof -- safe
  970. var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? Object.getPrototypeOf : function (O) {
  971. var object = toObject(O);
  972. if (hasOwn$1(object, IE_PROTO)) return object[IE_PROTO];
  973. var constructor = object.constructor;
  974. if (isCallable$3(constructor) && object instanceof constructor) {
  975. return constructor.prototype;
  976. } return object instanceof Object ? ObjectPrototype : null;
  977. };
  978.  
  979. var fails$1 = fails$8;
  980. var isCallable$2 = isCallable$d;
  981. var getPrototypeOf = objectGetPrototypeOf;
  982. var redefine$1 = redefine$3.exports;
  983. var wellKnownSymbol$6 = wellKnownSymbol$8;
  984.  
  985. var ITERATOR$2 = wellKnownSymbol$6('iterator');
  986. var BUGGY_SAFARI_ITERATORS = false;
  987.  
  988. // `%IteratorPrototype%` object
  989. // https://tc39.es/ecma262/#sec-%iteratorprototype%-object
  990. var IteratorPrototype$2, PrototypeOfArrayIteratorPrototype, arrayIterator;
  991.  
  992. /* eslint-disable es/no-array-prototype-keys -- safe */
  993. if ([].keys) {
  994. arrayIterator = [].keys();
  995. // Safari 8 has buggy iterators w/o `next`
  996. if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
  997. else {
  998. PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator));
  999. if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype$2 = PrototypeOfArrayIteratorPrototype;
  1000. }
  1001. }
  1002.  
  1003. var NEW_ITERATOR_PROTOTYPE = IteratorPrototype$2 == undefined || fails$1(function () {
  1004. var test = {};
  1005. // FF44- legacy iterators case
  1006. return IteratorPrototype$2[ITERATOR$2].call(test) !== test;
  1007. });
  1008.  
  1009. if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype$2 = {};
  1010.  
  1011. // `%IteratorPrototype%[@@iterator]()` method
  1012. // https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
  1013. if (!isCallable$2(IteratorPrototype$2[ITERATOR$2])) {
  1014. redefine$1(IteratorPrototype$2, ITERATOR$2, function () {
  1015. return this;
  1016. });
  1017. }
  1018.  
  1019. var iteratorsCore = {
  1020. IteratorPrototype: IteratorPrototype$2,
  1021. BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
  1022. };
  1023.  
  1024. // https://github.com/tc39/proposal-iterator-helpers
  1025. var $$2 = _export;
  1026. var global$1 = global$c;
  1027. var anInstance = anInstance$1;
  1028. var isCallable$1 = isCallable$d;
  1029. var createNonEnumerableProperty$1 = createNonEnumerableProperty$5;
  1030. var fails = fails$8;
  1031. var hasOwn = hasOwnProperty_1;
  1032. var wellKnownSymbol$5 = wellKnownSymbol$8;
  1033. var IteratorPrototype$1 = iteratorsCore.IteratorPrototype;
  1034.  
  1035. var TO_STRING_TAG$3 = wellKnownSymbol$5('toStringTag');
  1036.  
  1037. var NativeIterator = global$1.Iterator;
  1038.  
  1039. // FF56- have non-standard global helper `Iterator`
  1040. var FORCED = !isCallable$1(NativeIterator)
  1041. || NativeIterator.prototype !== IteratorPrototype$1
  1042. // FF44- non-standard `Iterator` passes previous tests
  1043. || !fails(function () { NativeIterator({}); });
  1044.  
  1045. var IteratorConstructor = function Iterator() {
  1046. anInstance(this, IteratorConstructor);
  1047. };
  1048.  
  1049. if (!hasOwn(IteratorPrototype$1, TO_STRING_TAG$3)) {
  1050. createNonEnumerableProperty$1(IteratorPrototype$1, TO_STRING_TAG$3, 'Iterator');
  1051. }
  1052.  
  1053. if (FORCED || !hasOwn(IteratorPrototype$1, 'constructor') || IteratorPrototype$1.constructor === Object) {
  1054. createNonEnumerableProperty$1(IteratorPrototype$1, 'constructor', IteratorConstructor);
  1055. }
  1056.  
  1057. IteratorConstructor.prototype = IteratorPrototype$1;
  1058.  
  1059. $$2({ global: true, forced: FORCED }, {
  1060. Iterator: IteratorConstructor
  1061. });
  1062.  
  1063. var iterators = {};
  1064.  
  1065. var wellKnownSymbol$4 = wellKnownSymbol$8;
  1066. var Iterators$1 = iterators;
  1067.  
  1068. var ITERATOR$1 = wellKnownSymbol$4('iterator');
  1069. var ArrayPrototype = Array.prototype;
  1070.  
  1071. // check on default Array iterator
  1072. var isArrayIteratorMethod$1 = function (it) {
  1073. return it !== undefined && (Iterators$1.Array === it || ArrayPrototype[ITERATOR$1] === it);
  1074. };
  1075.  
  1076. var aCallable$3 = aCallable$5;
  1077.  
  1078. // optional / simple context binding
  1079. var functionBindContext = function (fn, that, length) {
  1080. aCallable$3(fn);
  1081. if (that === undefined) return fn;
  1082. switch (length) {
  1083. case 0: return function () {
  1084. return fn.call(that);
  1085. };
  1086. case 1: return function (a) {
  1087. return fn.call(that, a);
  1088. };
  1089. case 2: return function (a, b) {
  1090. return fn.call(that, a, b);
  1091. };
  1092. case 3: return function (a, b, c) {
  1093. return fn.call(that, a, b, c);
  1094. };
  1095. }
  1096. return function (/* ...args */) {
  1097. return fn.apply(that, arguments);
  1098. };
  1099. };
  1100.  
  1101. var wellKnownSymbol$3 = wellKnownSymbol$8;
  1102.  
  1103. var TO_STRING_TAG$2 = wellKnownSymbol$3('toStringTag');
  1104. var test = {};
  1105.  
  1106. test[TO_STRING_TAG$2] = 'z';
  1107.  
  1108. var toStringTagSupport = String(test) === '[object z]';
  1109.  
  1110. var TO_STRING_TAG_SUPPORT = toStringTagSupport;
  1111. var isCallable = isCallable$d;
  1112. var classofRaw = classofRaw$1;
  1113. var wellKnownSymbol$2 = wellKnownSymbol$8;
  1114.  
  1115. var TO_STRING_TAG$1 = wellKnownSymbol$2('toStringTag');
  1116. // ES3 wrong here
  1117. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments';
  1118.  
  1119. // fallback for IE11 Script Access Denied error
  1120. var tryGet = function (it, key) {
  1121. try {
  1122. return it[key];
  1123. } catch (error) { /* empty */ }
  1124. };
  1125.  
  1126. // getting tag from ES6+ `Object.prototype.toString`
  1127. var classof$1 = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) {
  1128. var O, tag, result;
  1129. return it === undefined ? 'Undefined' : it === null ? 'Null'
  1130. // @@toStringTag case
  1131. : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG$1)) == 'string' ? tag
  1132. // builtinTag case
  1133. : CORRECT_ARGUMENTS ? classofRaw(O)
  1134. // ES3 arguments fallback
  1135. : (result = classofRaw(O)) == 'Object' && isCallable(O.callee) ? 'Arguments' : result;
  1136. };
  1137.  
  1138. var classof = classof$1;
  1139. var getMethod$2 = getMethod$4;
  1140. var Iterators = iterators;
  1141. var wellKnownSymbol$1 = wellKnownSymbol$8;
  1142.  
  1143. var ITERATOR = wellKnownSymbol$1('iterator');
  1144.  
  1145. var getIteratorMethod$2 = function (it) {
  1146. if (it != undefined) return getMethod$2(it, ITERATOR)
  1147. || getMethod$2(it, '@@iterator')
  1148. || Iterators[classof(it)];
  1149. };
  1150.  
  1151. var aCallable$2 = aCallable$5;
  1152. var anObject$6 = anObject$b;
  1153. var getIteratorMethod$1 = getIteratorMethod$2;
  1154.  
  1155. var getIterator$1 = function (argument, usingIterator) {
  1156. var iteratorMethod = arguments.length < 2 ? getIteratorMethod$1(argument) : usingIterator;
  1157. if (aCallable$2(iteratorMethod)) return anObject$6(iteratorMethod.call(argument));
  1158. throw TypeError(String(argument) + ' is not iterable');
  1159. };
  1160.  
  1161. var anObject$5 = anObject$b;
  1162. var getMethod$1 = getMethod$4;
  1163.  
  1164. var iteratorClose$2 = function (iterator, kind, value) {
  1165. var innerResult, innerError;
  1166. anObject$5(iterator);
  1167. try {
  1168. innerResult = getMethod$1(iterator, 'return');
  1169. if (!innerResult) {
  1170. if (kind === 'throw') throw value;
  1171. return value;
  1172. }
  1173. innerResult = innerResult.call(iterator);
  1174. } catch (error) {
  1175. innerError = true;
  1176. innerResult = error;
  1177. }
  1178. if (kind === 'throw') throw value;
  1179. if (innerError) throw innerResult;
  1180. anObject$5(innerResult);
  1181. return value;
  1182. };
  1183.  
  1184. var anObject$4 = anObject$b;
  1185. var isArrayIteratorMethod = isArrayIteratorMethod$1;
  1186. var lengthOfArrayLike = lengthOfArrayLike$2;
  1187. var bind = functionBindContext;
  1188. var getIterator = getIterator$1;
  1189. var getIteratorMethod = getIteratorMethod$2;
  1190. var iteratorClose$1 = iteratorClose$2;
  1191.  
  1192. var Result = function (stopped, result) {
  1193. this.stopped = stopped;
  1194. this.result = result;
  1195. };
  1196.  
  1197. var iterate$1 = function (iterable, unboundFunction, options) {
  1198. var that = options && options.that;
  1199. var AS_ENTRIES = !!(options && options.AS_ENTRIES);
  1200. var IS_ITERATOR = !!(options && options.IS_ITERATOR);
  1201. var INTERRUPTED = !!(options && options.INTERRUPTED);
  1202. var fn = bind(unboundFunction, that, 1 + AS_ENTRIES + INTERRUPTED);
  1203. var iterator, iterFn, index, length, result, next, step;
  1204.  
  1205. var stop = function (condition) {
  1206. if (iterator) iteratorClose$1(iterator, 'normal', condition);
  1207. return new Result(true, condition);
  1208. };
  1209.  
  1210. var callFn = function (value) {
  1211. if (AS_ENTRIES) {
  1212. anObject$4(value);
  1213. return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
  1214. } return INTERRUPTED ? fn(value, stop) : fn(value);
  1215. };
  1216.  
  1217. if (IS_ITERATOR) {
  1218. iterator = iterable;
  1219. } else {
  1220. iterFn = getIteratorMethod(iterable);
  1221. if (!iterFn) throw TypeError(String(iterable) + ' is not iterable');
  1222. // optimisation for array iterators
  1223. if (isArrayIteratorMethod(iterFn)) {
  1224. for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) {
  1225. result = callFn(iterable[index]);
  1226. if (result && result instanceof Result) return result;
  1227. } return new Result(false);
  1228. }
  1229. iterator = getIterator(iterable, iterFn);
  1230. }
  1231.  
  1232. next = iterator.next;
  1233. while (!(step = next.call(iterator)).done) {
  1234. try {
  1235. result = callFn(step.value);
  1236. } catch (error) {
  1237. iteratorClose$1(iterator, 'throw', error);
  1238. }
  1239. if (typeof result == 'object' && result && result instanceof Result) return result;
  1240. } return new Result(false);
  1241. };
  1242.  
  1243. // https://github.com/tc39/proposal-iterator-helpers
  1244. var $$1 = _export;
  1245. var iterate = iterate$1;
  1246. var anObject$3 = anObject$b;
  1247.  
  1248. $$1({ target: 'Iterator', proto: true, real: true }, {
  1249. forEach: function forEach(fn) {
  1250. iterate(anObject$3(this), fn, { IS_ITERATOR: true });
  1251. }
  1252. });
  1253.  
  1254. var redefine = redefine$3.exports;
  1255.  
  1256. var redefineAll$1 = function (target, src, options) {
  1257. for (var key in src) redefine(target, key, src[key], options);
  1258. return target;
  1259. };
  1260.  
  1261. var aCallable$1 = aCallable$5;
  1262. var anObject$2 = anObject$b;
  1263. var create = objectCreate;
  1264. var createNonEnumerableProperty = createNonEnumerableProperty$5;
  1265. var redefineAll = redefineAll$1;
  1266. var wellKnownSymbol = wellKnownSymbol$8;
  1267. var InternalStateModule = internalState;
  1268. var getMethod = getMethod$4;
  1269. var IteratorPrototype = iteratorsCore.IteratorPrototype;
  1270.  
  1271. var setInternalState = InternalStateModule.set;
  1272. var getInternalState = InternalStateModule.get;
  1273.  
  1274. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  1275.  
  1276. var iteratorCreateProxy = function (nextHandler, IS_ITERATOR) {
  1277. var IteratorProxy = function Iterator(state) {
  1278. state.next = aCallable$1(state.iterator.next);
  1279. state.done = false;
  1280. state.ignoreArg = !IS_ITERATOR;
  1281. setInternalState(this, state);
  1282. };
  1283.  
  1284. IteratorProxy.prototype = redefineAll(create(IteratorPrototype), {
  1285. next: function next(arg) {
  1286. var state = getInternalState(this);
  1287. var args = arguments.length ? [state.ignoreArg ? undefined : arg] : IS_ITERATOR ? [] : [undefined];
  1288. state.ignoreArg = false;
  1289. var result = state.done ? undefined : nextHandler.call(state, args);
  1290. return { done: state.done, value: result };
  1291. },
  1292. 'return': function (value) {
  1293. var state = getInternalState(this);
  1294. var iterator = state.iterator;
  1295. state.done = true;
  1296. var $$return = getMethod(iterator, 'return');
  1297. return { done: true, value: $$return ? anObject$2($$return.call(iterator, value)).value : value };
  1298. },
  1299. 'throw': function (value) {
  1300. var state = getInternalState(this);
  1301. var iterator = state.iterator;
  1302. state.done = true;
  1303. var $$throw = getMethod(iterator, 'throw');
  1304. if ($$throw) return $$throw.call(iterator, value);
  1305. throw value;
  1306. }
  1307. });
  1308.  
  1309. if (!IS_ITERATOR) {
  1310. createNonEnumerableProperty(IteratorProxy.prototype, TO_STRING_TAG, 'Generator');
  1311. }
  1312.  
  1313. return IteratorProxy;
  1314. };
  1315.  
  1316. var anObject$1 = anObject$b;
  1317. var iteratorClose = iteratorClose$2;
  1318.  
  1319. // call something on iterator step with safe closing on error
  1320. var callWithSafeIterationClosing$1 = function (iterator, fn, value, ENTRIES) {
  1321. try {
  1322. return ENTRIES ? fn(anObject$1(value)[0], value[1]) : fn(value);
  1323. } catch (error) {
  1324. iteratorClose(iterator, 'throw', error);
  1325. }
  1326. };
  1327.  
  1328. // https://github.com/tc39/proposal-iterator-helpers
  1329. var $ = _export;
  1330. var aCallable = aCallable$5;
  1331. var anObject = anObject$b;
  1332. var createIteratorProxy = iteratorCreateProxy;
  1333. var callWithSafeIterationClosing = callWithSafeIterationClosing$1;
  1334.  
  1335. var IteratorProxy = createIteratorProxy(function (args) {
  1336. var iterator = this.iterator;
  1337. var result = anObject(this.next.apply(iterator, args));
  1338. var done = this.done = !!result.done;
  1339. if (!done) return callWithSafeIterationClosing(iterator, this.mapper, result.value);
  1340. });
  1341.  
  1342. $({ target: 'Iterator', proto: true, real: true }, {
  1343. map: function map(mapper) {
  1344. return new IteratorProxy({
  1345. iterator: anObject(this),
  1346. mapper: aCallable(mapper)
  1347. });
  1348. }
  1349. });
  1350.  
  1351. const isZHInGameSetting = localStorage.getItem("i18nextLng")?.toLowerCase()?.startsWith("zh"); // 获取游戏内设置语言
  1352. let isZH = isZHInGameSetting; // MWITools 本身显示的语言默认由游戏内设置语言决定
  1353.  
  1354. let settingsMap = {
  1355. projectileLimit: {
  1356. id: "projectileLimit",
  1357. desc: isZH ? "投射物数量限制" : "Projectile Limit",
  1358. value: 30,
  1359. min: 1,
  1360. max: 100,
  1361. step: 1
  1362. },
  1363. projectileScale: {
  1364. id: "projectileScale",
  1365. desc: isZH ? "投射物缩放" : "Projectile Scale",
  1366. value: 1.0,
  1367. min: 0.1,
  1368. max: 3.0,
  1369. step: 0.01
  1370. },
  1371. onHitScale: {
  1372. id: "onHitScale",
  1373. desc: isZH ? "命中效果缩放" : "On-hit Effect Scale",
  1374. value: 1.0,
  1375. min: 0.1,
  1376. max: 3.0,
  1377. step: 0.01
  1378. },
  1379. projectileHeightScale: {
  1380. id: "projectileHeightScale",
  1381. desc: isZH ? "弹道高度比例" : "Projectile Height Scale",
  1382. value: 1.0,
  1383. min: 0.1,
  1384. max: 3.0,
  1385. step: 0.01
  1386. },
  1387. projectileSpeedScale: {
  1388. id: "projectileSpeedScale",
  1389. desc: isZH ? "弹道速度比例" : "Projectile Speed Scale",
  1390. value: 1.0,
  1391. min: 0.1,
  1392. max: 3.0,
  1393. step: 0.01
  1394. },
  1395. shakeEffectScale: {
  1396. id: "shakeEffectScale",
  1397. desc: isZH ? "震动效果" : "Shake Effect Scale",
  1398. value: 1.0,
  1399. min: 0.0,
  1400. max: 3.0,
  1401. step: 0.01
  1402. },
  1403. particleEffectRatio: {
  1404. id: "particleEffectRatio",
  1405. desc: isZH ? "粒子效果数量" : "Particle Effect Ratio",
  1406. value: 1.0,
  1407. min: 0.0,
  1408. max: 5.0,
  1409. step: 0.1
  1410. },
  1411. particleLifespanRatio: {
  1412. id: "particleLifespanRatio",
  1413. desc: isZH ? "粒子效果持续时长" : "Particle Lifespan Ratio",
  1414. value: 1.0,
  1415. min: 0.1,
  1416. max: 5.0,
  1417. step: 0.1
  1418. },
  1419. particleSpeedRatio: {
  1420. id: "particleSpeedRatio",
  1421. desc: isZH ? "粒子效果初速度" : "Particle Effect Speed Ratio",
  1422. value: 1.0,
  1423. min: 0.1,
  1424. max: 5.0,
  1425. step: 0.1
  1426. },
  1427. projectileTrailLength: {
  1428. id: "projectileTrailLength",
  1429. desc: isZH ? "弹道尾迹长度" : "Projectile Trail Length",
  1430. value: 1.0,
  1431. min: 0.0,
  1432. max: 5.0,
  1433. step: 0.01
  1434. },
  1435. projectileTrailGap: {
  1436. id: "projectileTrailGap",
  1437. desc: isZH ? "弹道尾迹间隔" : "Projectile Trail Gap",
  1438. value: 1.0,
  1439. min: 0.05,
  1440. max: 3.0,
  1441. step: 0.05
  1442. },
  1443. originalDamageDisplay: {
  1444. id: "originalDamageDisplay",
  1445. desc: isZH ? "原版伤害显示" : "Original Damage Display",
  1446. value: false
  1447. },
  1448. hitAreaScale: {
  1449. id: "hitAreaScale",
  1450. desc: isZH ? "命中范围" : "Hit Area Scale",
  1451. value: 1,
  1452. min: 0.1,
  1453. max: 3.0,
  1454. step: 0.01
  1455. },
  1456. hitPositionMinGap: {
  1457. id: "hitPositionMinGap",
  1458. desc: isZH ? "命中最小间距" : "Minimum Gap Of Each Projectile Hit",
  1459. value: 0,
  1460. min: 0,
  1461. max: 10,
  1462. step: 1
  1463. },
  1464. damageTextLifespan: {
  1465. id: "damageTextLifespan",
  1466. desc: isZH ? "伤害文本持续时间" : "Damage Text Lifespan",
  1467. value: 120,
  1468. min: 30,
  1469. max: 480,
  1470. step: 10
  1471. },
  1472. damageTextScale: {
  1473. id: "damageTextScale",
  1474. desc: isZH ? "伤害文本大小" : "Damage Text Scale",
  1475. value: 1.0,
  1476. min: 0.1,
  1477. max: 3.0,
  1478. step: 0.1
  1479. },
  1480. damageTextAlpha: {
  1481. id: "damageTextAlpha",
  1482. desc: isZH ? "伤害文本不透明度" : "Damage Text Alpha",
  1483. value: 0.8,
  1484. min: 0.0,
  1485. max: 1.0,
  1486. step: 0.01
  1487. },
  1488. damageTextSizeMinimal: {
  1489. id: "damageTextSizeMinimal",
  1490. desc: isZH ? "伤害文本尺寸最小值" : "Damage Text Size Minimal",
  1491. value: 14,
  1492. min: 5,
  1493. max: 100,
  1494. step: 1
  1495. },
  1496. damageTextSizeLimit: {
  1497. id: "damageTextSizeLimit",
  1498. desc: isZH ? "伤害文本尺寸上限" : "Damage Text Size Limit",
  1499. value: 70,
  1500. min: 15,
  1501. max: 200,
  1502. step: 1
  1503. },
  1504. showSelfRegen: {
  1505. id: "showSelfRegen",
  1506. desc: isZH ? "显示玩家被动回复效果" : "Show Self Regeneration",
  1507. value: true
  1508. },
  1509. verticalCombatDisplay: {
  1510. id: "verticalCombatDisplay",
  1511. desc: isZH ? "战斗排列垂直展示" : "Display Comabt Vertically",
  1512. value: false
  1513. },
  1514. monsterDeadAnimation: {
  1515. id: "monsterDeadAnimation",
  1516. desc: isZH ? "怪物死亡效果" : "Monster Dead Animation",
  1517. value: true
  1518. },
  1519. monsterDeadAnimationStyle: {
  1520. id: "monsterDeadAnimationStyle",
  1521. desc: isZH ? "怪物死亡效果样式" : "Monster Dead Animation Style",
  1522. value: "default",
  1523. list: []
  1524. },
  1525. damageHpBarDropDelay: {
  1526. id: "damageHpBarDropDelay",
  1527. desc: isZH ? "血条掉落延迟" : "Hp Bar Drop Delay",
  1528. value: 300,
  1529. min: 50,
  1530. max: 1000,
  1531. step: 50
  1532. },
  1533. tracker0: {
  1534. id: "tracker0",
  1535. desc: isZH ? "玩家1" : "Player 1",
  1536. isTrue: true,
  1537. trackStyle: "auto",
  1538. r: 255,
  1539. g: 99,
  1540. b: 132
  1541. },
  1542. tracker1: {
  1543. id: "tracker1",
  1544. desc: isZH ? "玩家2" : "Player 2",
  1545. isTrue: true,
  1546. trackStyle: "auto",
  1547. r: 54,
  1548. g: 162,
  1549. b: 235
  1550. },
  1551. tracker2: {
  1552. id: "tracker2",
  1553. desc: isZH ? "玩家3" : "Player 3",
  1554. isTrue: true,
  1555. trackStyle: "auto",
  1556. r: 255,
  1557. g: 206,
  1558. b: 86
  1559. },
  1560. tracker3: {
  1561. id: "tracker3",
  1562. desc: isZH ? "玩家4" : "Player 4",
  1563. isTrue: true,
  1564. trackStyle: "auto",
  1565. r: 75,
  1566. g: 192,
  1567. b: 192
  1568. },
  1569. tracker4: {
  1570. id: "tracker4",
  1571. desc: isZH ? "玩家5" : "Player 5",
  1572. isTrue: true,
  1573. trackStyle: "auto",
  1574. r: 153,
  1575. g: 102,
  1576. b: 255
  1577. },
  1578. tracker6: {
  1579. id: "tracker6",
  1580. desc: isZH ? "敌人" : "Enemies",
  1581. isTrue: true,
  1582. trackStyle: "auto",
  1583. r: 255,
  1584. g: 0,
  1585. b: 0
  1586. },
  1587. renderFpsLimit: {
  1588. id: "renderFpsLimit",
  1589. desc: isZH ? "渲染帧数限制(非精确,刷新生效)" : "Render FPS Limit (Not accurate, restart required)",
  1590. value: 160,
  1591. min: 5,
  1592. max: 300,
  1593. step: 1
  1594. },
  1595. showFps: {
  1596. id: "showFps",
  1597. desc: isZH ? "显示帧数" : "Show FPS",
  1598. value: false
  1599. }
  1600. };
  1601. readSettings();
  1602. function waitForSettings(params) {
  1603. const targetNode = document.querySelector("div.SettingsPanel_profileTab__214Bj");
  1604. if (targetNode) {
  1605. if (!targetNode.querySelector("#tracker_settings")) {
  1606. targetNode.insertAdjacentHTML("beforeend", `<div id="tracker_settings"></div>`);
  1607. const insertElem = targetNode.querySelector("div#tracker_settings");
  1608. insertElem.insertAdjacentHTML("beforeend", `<div style="float: left; color: orange">${isZH ? "MWI-Hit-Tracker 设置 :" : "MWI-Hit-Tracker Settings: "}</div></br>`);
  1609. for (const setting of Object.values(settingsMap)) {
  1610. if (setting.id.startsWith("tracker")) {
  1611. insertElem.insertAdjacentHTML("beforeend", `<div class="tracker-option"><input type="checkbox" id="${setting.id}" ${setting.isTrue ? "checked" : ""}></input>${setting.desc} ${isZH ? '颜色' : 'Color'}<div class="color-preview" id="colorPreview_${setting.id}"></div>${isZH ? '样式' : 'Projectile Style'}<select id="projectileStyle_${setting.id}"></select></div>`);
  1612. const checkedBox = insertElem.querySelector("#" + setting.id);
  1613. checkedBox.addEventListener("change", e => {
  1614. settingsMap[setting.id].isTrue = e.target.checked;
  1615. saveSettings();
  1616. });
  1617. const colorPreview = document.getElementById('colorPreview_' + setting.id);
  1618. let currentColor = {
  1619. r: setting.r,
  1620. g: setting.g,
  1621. b: setting.b
  1622. };
  1623.  
  1624. // 点击打开颜色选择器
  1625. colorPreview.addEventListener('click', () => {
  1626. const settingColor = {
  1627. r: settingsMap[setting.id].r,
  1628. g: settingsMap[setting.id].g,
  1629. b: settingsMap[setting.id].b
  1630. };
  1631. const modal = createColorPicker(settingColor, newColor => {
  1632. currentColor = newColor;
  1633. settingsMap[setting.id].r = newColor.r;
  1634. settingsMap[setting.id].g = newColor.g;
  1635. settingsMap[setting.id].b = newColor.b;
  1636. localStorage.setItem("tracker_settingsMap", JSON.stringify(settingsMap));
  1637. updatePreview();
  1638. });
  1639. document.body.appendChild(modal);
  1640. });
  1641. function updatePreview() {
  1642. colorPreview.style.backgroundColor = `rgb(${currentColor.r},${currentColor.g},${currentColor.b})`;
  1643. }
  1644. updatePreview();
  1645. function createColorPicker(initialColor, callback) {
  1646. // 创建弹窗容器
  1647. const backdrop = document.createElement('div');
  1648. backdrop.className = 'modal-backdrop';
  1649. const modal = document.createElement('div');
  1650. modal.className = 'color-picker-modal';
  1651.  
  1652. // 创建SVG容器
  1653. const preview = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  1654. preview.setAttribute("width", "200");
  1655. preview.setAttribute("height", "150");
  1656. preview.style.display = 'block';
  1657. // 创建抛物线路径
  1658. const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
  1659. Object.assign(path.style, {
  1660. strokeWidth: '5px',
  1661. fill: 'none',
  1662. strokeLinecap: 'round'
  1663. });
  1664. path.setAttribute("d", "M 0 130 Q 100 0 200 130");
  1665. preview.appendChild(path);
  1666.  
  1667. // 颜色控制组件
  1668. const controls = document.createElement('div');
  1669. ['r', 'g', 'b'].forEach(channel => {
  1670. const container = document.createElement('div');
  1671. container.className = 'slider-container';
  1672.  
  1673. // 标签
  1674. const label = document.createElement('label');
  1675. label.textContent = channel.toUpperCase() + ':';
  1676. label.style.color = "white";
  1677.  
  1678. // 滑块
  1679. const slider = document.createElement('input');
  1680. slider.type = 'range';
  1681. slider.min = 0;
  1682. slider.max = 255;
  1683. slider.value = initialColor[channel];
  1684.  
  1685. // 输入框
  1686. const input = document.createElement('input');
  1687. input.type = 'number';
  1688. input.min = 0;
  1689. input.max = 255;
  1690. input.value = initialColor[channel];
  1691. input.style.width = '60px';
  1692.  
  1693. // 双向绑定
  1694. const updateChannel = value => {
  1695. value = Math.min(255, Math.max(0, parseInt(value) || 0));
  1696. slider.value = value;
  1697. input.value = value;
  1698. currentColor[channel] = value;
  1699. path.style.stroke = getColorString(currentColor);
  1700. };
  1701. slider.addEventListener('input', e => updateChannel(e.target.value));
  1702. input.addEventListener('change', e => updateChannel(e.target.value));
  1703. container.append(label, slider, input);
  1704. controls.append(container);
  1705. });
  1706.  
  1707. // 操作按钮
  1708. const actions = document.createElement('div');
  1709. actions.className = 'modal-actions';
  1710. const confirmBtn = document.createElement('button');
  1711. confirmBtn.textContent = isZH ? '确定' : 'OK';
  1712. confirmBtn.onclick = () => {
  1713. callback(currentColor);
  1714. backdrop.remove();
  1715. };
  1716. const cancelBtn = document.createElement('button');
  1717. cancelBtn.textContent = isZH ? '取消' : 'Cancel';
  1718. cancelBtn.onclick = () => backdrop.remove();
  1719. actions.append(cancelBtn, confirmBtn);
  1720.  
  1721. // 组装弹窗
  1722. const getColorString = color => `rgb(${color.r},${color.g},${color.b})`;
  1723. path.style.stroke = getColorString(settingsMap[setting.id]);
  1724. modal.append(preview, controls, actions);
  1725. backdrop.append(modal);
  1726.  
  1727. // 点击背景关闭
  1728. backdrop.addEventListener('click', e => {
  1729. if (e.target === backdrop) backdrop.remove();
  1730. });
  1731. return backdrop;
  1732. }
  1733. const select = document.querySelector("#projectileStyle_" + setting.id);
  1734. const projectileStyle = ["auto", "null", ...params.allProjectiles];
  1735. for (const option of projectileStyle) {
  1736. select.insertAdjacentHTML("beforeend", `<option value="${option}" ${option === setting.trackStyle ? "selected" : ""}>${option}</option>`);
  1737. }
  1738. select.addEventListener("change", e => {
  1739. settingsMap[setting.id].trackStyle = e.target.value;
  1740. saveSettings();
  1741. });
  1742. } else {
  1743. if (typeof setting.value === "boolean") {
  1744. insertElem.insertAdjacentHTML("beforeend", `<div class="tracker-option">${setting.desc}<input type="checkbox" id="trackerSetting_${setting.id}"></input></div>`);
  1745. const checkedBox = insertElem.querySelector("#trackerSetting_" + setting.id);
  1746. checkedBox.checked = setting.value;
  1747. checkedBox.addEventListener("change", e => {
  1748. settingsMap[setting.id].value = e.target.checked;
  1749. saveSettings();
  1750. });
  1751. } else if (typeof setting.value === "number") {
  1752. insertElem.insertAdjacentHTML("beforeend", `<div class="tracker-option">${setting.desc}<input type="range" id="trackerSetting_${setting.id}_range"></input><input type="number" id="trackerSetting_${setting.id}_value"></input></div>`);
  1753. const slider = document.querySelector("#trackerSetting_" + setting.id + "_range");
  1754. slider.min = setting.min;
  1755. slider.max = setting.max;
  1756. slider.step = setting.step || 0.05;
  1757. slider.value = setting.value;
  1758. const input = document.querySelector("#trackerSetting_" + setting.id + "_value");
  1759. input.min = setting.min;
  1760. input.max = setting.max;
  1761. input.step = setting.step || 0.05;
  1762. input.value = setting.value;
  1763. const updateChannel = value => {
  1764. value = Math.min(setting.max, Math.max(setting.min, parseFloat(value)));
  1765. slider.value = value;
  1766. input.value = value;
  1767. settingsMap[setting.id].value = value;
  1768. };
  1769. slider.addEventListener('input', e => updateChannel(e.target.value));
  1770. input.addEventListener('change', e => updateChannel(e.target.value));
  1771. } else if (setting.list) {
  1772. insertElem.insertAdjacentHTML("beforeend", `<div class="tracker-option">${setting.desc}<select id="trackerSetting_${setting.id}"></select></div>`);
  1773. const select = document.querySelector("#trackerSetting_" + setting.id);
  1774. for (const option of params[setting.id]) {
  1775. select.insertAdjacentHTML("beforeend", `<option value="${option}" ${option === setting.value ? "selected" : ""}>${option}</option>`);
  1776. }
  1777. select.addEventListener("change", e => {
  1778. settingsMap[setting.id].value = e.target.value;
  1779. saveSettings();
  1780. });
  1781. }
  1782. }
  1783. }
  1784. insertElem.addEventListener("change", saveSettings);
  1785. }
  1786. }
  1787. setTimeout(() => {
  1788. waitForSettings(params);
  1789. }, 500);
  1790. }
  1791. function saveSettings() {
  1792. localStorage.setItem("tracker_settingsMap", JSON.stringify(settingsMap));
  1793. }
  1794. function readSettings() {
  1795. const ls = localStorage.getItem("tracker_settingsMap");
  1796. if (ls) {
  1797. const lsObj = JSON.parse(ls);
  1798. for (const option of Object.values(lsObj)) {
  1799. if (option.id.startsWith("tracker")) {
  1800. if (settingsMap.hasOwnProperty(option.id)) {
  1801. settingsMap[option.id].isTrue = option.isTrue;
  1802. settingsMap[option.id].trackStyle = option.trackStyle || "auto";
  1803. settingsMap[option.id].r = option.r;
  1804. settingsMap[option.id].g = option.g;
  1805. settingsMap[option.id].b = option.b;
  1806. }
  1807. } else if (option && option.id && settingsMap[option.id]) {
  1808. settingsMap[option.id].value = option.value;
  1809. }
  1810. }
  1811. }
  1812. }
  1813. const style = document.createElement('style');
  1814. style.textContent = `
  1815. .tracker-option {
  1816. display: flex;
  1817. align-items: left;
  1818. gap: 10px;
  1819. }
  1820.  
  1821. .color-preview {
  1822. cursor: pointer;
  1823. width: 20px;
  1824. height: 20px;
  1825. margin: 3px 3px;
  1826. border: 1px solid #ccc;
  1827. border-radius: 3px;
  1828. }
  1829.  
  1830. .color-picker-modal {
  1831. position: fixed;
  1832. top: 50%;
  1833. left: 50%;
  1834. transform: translate(-50%, -50%);
  1835. background: rgba(0, 0, 0, 0.5);
  1836. padding: 20px;
  1837. border: 1px solid rgba(255, 255, 255, 0.2);
  1838. border-radius: 8px;
  1839. box-shadow: 0 0 20px rgba(0,0,0,0.2);
  1840. z-index: 1000;
  1841. }
  1842.  
  1843. .modal-backdrop {
  1844. position: fixed;
  1845. top: 0;
  1846. left: 0;
  1847. right: 0;
  1848. bottom: 0;
  1849. background: rgba(0,0,0,0.5);
  1850. z-index: 999;
  1851. }
  1852.  
  1853. .modal-actions {
  1854. margin-top: 20px;
  1855. display: flex;
  1856. gap: 10px;
  1857. justify-content: flex-end;
  1858. }
  1859. `;
  1860. document.head.appendChild(style);
  1861.  
  1862. function changeColorAlpha(rgba, alpha) {
  1863. if (rgba.startsWith('rgba')) {
  1864. return rgba.replace(/rgba\(([^,]+),([^,]+),([^,]+),[^)]+\)/, `rgba($1,$2,$3,${alpha})`);
  1865. } else if (rgba.startsWith('rgb')) {
  1866. return rgba.replace(/rgb\(([^,]+),([^,]+),([^,]+)\)/, `rgba($1,$2,$3,${alpha})`);
  1867. } else if (rgba.startsWith('hsl')) {
  1868. return rgba.replace(/hsl\(([^,]+),([^,]+),([^)]+)\)/, `hsla($1,$2,$3,${alpha})`);
  1869. } else if (rgba.startsWith('hsla')) {
  1870. return rgba.replace(/hsla\(([^,]+),([^,]+),([^)]+),[^)]+\)/, `hsla($1,$2,$3,${alpha})`);
  1871. }
  1872. return rgba;
  1873. }
  1874. function getElementCenter(element) {
  1875. const rect = element.getBoundingClientRect();
  1876. if (element.innerText.trim() === '') {
  1877. return {
  1878. x: rect.left + rect.width / 2,
  1879. y: rect.top
  1880. };
  1881. }
  1882. return {
  1883. x: rect.left + rect.width / 2,
  1884. y: rect.top + rect.height / 2
  1885. };
  1886. }
  1887.  
  1888. const shapes = {
  1889. "circle": (ctx, p = {}) => {
  1890. // {x, y, size, color}
  1891. ctx.beginPath();
  1892. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  1893. ctx.fillStyle = p.color;
  1894. ctx.fill();
  1895. },
  1896. "rectangle": (ctx, p = {}) => {
  1897. // {x, y, size, color}
  1898. ctx.beginPath();
  1899. ctx.fillStyle = p.color;
  1900. ctx.fillRect(p.x, p.y, p.size, p.size);
  1901. ctx.closePath();
  1902. },
  1903. "star": (ctx, p = {}) => {
  1904. // {x, y, size, color, angle}
  1905. ctx.save();
  1906. ctx.translate(p.x, p.y);
  1907. ctx.rotate(p.angle);
  1908. const starSize = p.size * 10;
  1909. ctx.beginPath();
  1910. const startAngle = -Math.PI / 2;
  1911. const startX = Math.cos(startAngle) * starSize;
  1912. const startY = Math.sin(startAngle) * starSize;
  1913. ctx.moveTo(startX, startY);
  1914. for (let i = 0; i < 5; i++) {
  1915. const outerAngle = i * 2 * Math.PI / 5 - Math.PI / 2;
  1916. const innerAngle = outerAngle + Math.PI / 5;
  1917. const outerX = Math.cos(outerAngle) * starSize;
  1918. const outerY = Math.sin(outerAngle) * starSize;
  1919. ctx.lineTo(outerX, outerY);
  1920. const innerX = Math.cos(innerAngle) * (starSize / 2);
  1921. const innerY = Math.sin(innerAngle) * (starSize / 2);
  1922. ctx.lineTo(innerX, innerY);
  1923. }
  1924. ctx.closePath();
  1925. ctx.fillStyle = p.color;
  1926. ctx.fill();
  1927. ctx.restore();
  1928. },
  1929. "arrow": (ctx, p = {}) => {
  1930. // {x, y, size, color, velocity, arrowLength, arrowWidth, arrowHeadLength, arrowHeadWidth, fletchingLength, fletchingWidth}
  1931. const length = p.size * (p.arrowLength || 6);
  1932. const width = p.size * (p.arrowWidth || 0.5);
  1933. const arrowHeadLength = p.size * (p.arrowHeadLength || 1.33);
  1934. const arrowHeadWidth = p.size * (p.arrowHeadWidth || 0.80);
  1935. const fletchingLength = p.size * (p.fletchingLength || 2.13);
  1936. const fletchingWidth = p.size * (p.fletchingWidth || 1.33);
  1937. ctx.save();
  1938. ctx.translate(p.x, p.y);
  1939. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  1940. // Draw arrow shaft
  1941. ctx.beginPath();
  1942. ctx.moveTo(-length / 2, -width / 2);
  1943. ctx.lineTo(length / 2 - arrowHeadLength, -width / 2);
  1944. ctx.lineTo(length / 2 - arrowHeadLength, width / 2);
  1945. ctx.lineTo(-length / 2, width / 2);
  1946. ctx.closePath();
  1947. ctx.fillStyle = p.color;
  1948. ctx.fill();
  1949. // Draw arrow head
  1950. ctx.beginPath();
  1951. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  1952. ctx.lineTo(length / 2, 0);
  1953. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  1954. ctx.closePath();
  1955. ctx.fillStyle = p.color;
  1956. ctx.fill();
  1957. // Draw fletchings
  1958. ctx.beginPath();
  1959. ctx.moveTo(-length / 2, -width / 2);
  1960. ctx.lineTo(-length / 2 - fletchingLength, -fletchingWidth / 2);
  1961. ctx.lineTo(-length / 2 - fletchingLength * 0.5, 0);
  1962. ctx.lineTo(-length / 2 - fletchingLength, fletchingWidth / 2);
  1963. ctx.lineTo(-length / 2, width / 2);
  1964. ctx.closePath();
  1965. ctx.fillStyle = p.color;
  1966. ctx.fill();
  1967. ctx.restore();
  1968. },
  1969. "pentagon": (ctx, p = {}) => {
  1970. // {x, y, size, color, angle}
  1971. ctx.save();
  1972. ctx.translate(p.x, p.y);
  1973. ctx.rotate(p.angle || 0);
  1974. ctx.beginPath();
  1975. for (let i = 0; i < 5; i++) {
  1976. const angle = i * 2 * Math.PI / 5 - Math.PI / 2;
  1977. const x = Math.cos(angle) * p.size;
  1978. const y = Math.sin(angle) * p.size;
  1979. if (i === 0) {
  1980. ctx.moveTo(x, y);
  1981. } else {
  1982. ctx.lineTo(x, y);
  1983. }
  1984. }
  1985. ctx.closePath();
  1986. ctx.fillStyle = p.color;
  1987. ctx.fill();
  1988. ctx.restore();
  1989. },
  1990. "triangle": (ctx, p = {}) => {
  1991. // {x, y, size, color, angle}
  1992. ctx.save();
  1993. ctx.translate(p.x, p.y);
  1994. ctx.rotate(p.angle || 0);
  1995. ctx.beginPath();
  1996. for (let i = 0; i < 3; i++) {
  1997. const angle = i * 2 * Math.PI / 3 - Math.PI / 2;
  1998. const x = Math.cos(angle) * p.size;
  1999. const y = Math.sin(angle) * p.size;
  2000. if (i === 0) {
  2001. ctx.moveTo(x, y);
  2002. } else {
  2003. ctx.lineTo(x, y);
  2004. }
  2005. }
  2006. ctx.closePath();
  2007. ctx.fillStyle = p.color;
  2008. ctx.fill();
  2009. ctx.restore();
  2010. },
  2011. "irregular": (ctx, p = {}) => {
  2012. // {x, y, size, color, angle, points}
  2013. ctx.save();
  2014. ctx.translate(p.x, p.y);
  2015. ctx.rotate(p.angle || 0);
  2016. const points = p.points || 6; // Default to 6 points if not specified
  2017. ctx.beginPath();
  2018. for (let i = 0; i < points; i++) {
  2019. const angle = i * 2 * Math.PI / points - Math.PI / 2;
  2020. // Add some randomness to the radius for irregularity
  2021. const radius = p.size * (0.7 + Math.random() * 0.6);
  2022. const x = Math.cos(angle) * radius;
  2023. const y = Math.sin(angle) * radius;
  2024. if (i === 0) {
  2025. ctx.moveTo(x, y);
  2026. } else {
  2027. ctx.lineTo(x, y);
  2028. }
  2029. }
  2030. ctx.closePath();
  2031. ctx.fillStyle = p.color;
  2032. ctx.fill();
  2033. ctx.restore();
  2034. },
  2035. "magnet": (ctx, p = {}) => {
  2036. // {x, y, size, color, angle}
  2037. ctx.save();
  2038. ctx.translate(p.x, p.y);
  2039. ctx.rotate(p.angle || 0);
  2040.  
  2041. // Set stroke properties
  2042. ctx.lineCap = 'butt'; // Makes strokes end exactly at the specified points
  2043. ctx.lineWidth = p.size * 0.7; // Equivalent to strokeWeight(35)
  2044.  
  2045. // Draw left L shape (red)
  2046. ctx.strokeStyle = 'rgb(255, 50, 50)'; // Muted red
  2047. ctx.beginPath();
  2048. // Vertical part
  2049. ctx.moveTo(-p.size, -p.size);
  2050. ctx.lineTo(-p.size, 0);
  2051. // Horizontal part with curve
  2052. ctx.bezierCurveTo(-p.size, p.size,
  2053. // Control point 1: (150, 300)
  2054. -p.size / 3, p.size,
  2055. // Control point 2: (200, 300)
  2056. 0, p.size // End point: (200, 300)
  2057. );
  2058. ctx.stroke();
  2059.  
  2060. // Draw right L shape (blue)
  2061. ctx.strokeStyle = 'rgb(50, 50, 255)'; // Muted blue
  2062. ctx.beginPath();
  2063. // Vertical part
  2064. ctx.moveTo(p.size, -p.size);
  2065. ctx.lineTo(p.size, 0);
  2066. // Horizontal part with curve
  2067. ctx.bezierCurveTo(p.size, p.size,
  2068. // Control point 1: (250, 300)
  2069. p.size / 3, p.size,
  2070. // Control point 2: (200, 300)
  2071. 0, p.size // End point: (200, 300)
  2072. );
  2073. ctx.stroke();
  2074.  
  2075. // Draw short grey lines
  2076. ctx.strokeStyle = 'grey';
  2077. // Left grey line
  2078. ctx.beginPath();
  2079. ctx.moveTo(-p.size, -p.size);
  2080. ctx.lineTo(-p.size, -p.size / 0.6);
  2081. ctx.stroke();
  2082.  
  2083. // Right grey line
  2084. ctx.beginPath();
  2085. ctx.moveTo(p.size, -p.size);
  2086. ctx.lineTo(p.size, -p.size / 0.6);
  2087. ctx.stroke();
  2088. ctx.restore();
  2089. }
  2090. };
  2091.  
  2092. /*
  2093. 特效编写请查阅
  2094. https://docs.qq.com/doc/DS0JjVHp3S09td2NV
  2095. */
  2096.  
  2097. const onHitEffectsMap = {
  2098. "smoke": {
  2099. angle: p => Math.random() * Math.PI * 2,
  2100. alpha: p => 0.7,
  2101. speed: p => (Math.random() * 0.05 + 0.02) * Math.sqrt(p.size),
  2102. size: p => (Math.random() * 20 + 10) * p.size,
  2103. life: p => 4000 * Math.sqrt(p.size),
  2104. gravity: p => -0.04 * Math.sqrt(p.size),
  2105. draw: (ctx, p) => {
  2106. if (!p.initialized) {
  2107. p.initialized = true;
  2108. p.y -= 3 * p.size;
  2109. p.sizeVariation = Math.random() * 0.2 + 0.9;
  2110. p.rotationSpeed = (Math.random() - 0.5) * 0.005;
  2111. p.rotation = Math.random() * Math.PI * 2;
  2112. p.verticalSpeed = 0;
  2113. }
  2114. p.speed *= 0.999;
  2115. p.verticalSpeed += p.gravity;
  2116. p.x += Math.cos(p.angle) * p.speed;
  2117. p.y += Math.sin(p.angle) * p.speed + p.verticalSpeed;
  2118. p.life -= 1;
  2119. p.alpha = Math.max(0, p.alpha - 0.0003 / p.fpsFactor);
  2120. p.rotation += p.rotationSpeed;
  2121. if (p.life > 0) {
  2122. ctx.save();
  2123. ctx.translate(p.x, p.y);
  2124. ctx.rotate(p.rotation);
  2125.  
  2126. // Draw main smoke puff
  2127. ctx.beginPath();
  2128. ctx.ellipse(0, 0, p.size * p.sizeVariation, p.size, 0, 0, Math.PI * 2);
  2129. ctx.fillStyle = `rgba(80, 80, 80, ${p.alpha * (p.life / 2000)})`;
  2130. ctx.fill();
  2131.  
  2132. // Add some variation to the smoke puff
  2133. ctx.beginPath();
  2134. ctx.ellipse(p.size * 0.3, -p.size * 0.2, p.size * 0.6, p.size * 0.8, 0, 0, Math.PI * 2);
  2135. ctx.fillStyle = `rgba(80, 80, 80, ${p.alpha * 0.7 * (p.life / 2000)})`;
  2136. ctx.fill();
  2137. ctx.restore();
  2138. }
  2139. }
  2140. },
  2141. "ember": {
  2142. angle: p => Math.random() * Math.PI * 2,
  2143. alpha: p => 1,
  2144. speed: p => (Math.random() * 2 + 0.5) * Math.sqrt(p.size),
  2145. size: p => (Math.random() * 6 + 2) * p.size,
  2146. life: p => 1200 * Math.sqrt(p.size),
  2147. gravity: p => 0.3,
  2148. draw: (ctx, p) => {
  2149. p.speed *= 0.99; // 慢慢减速
  2150. p.x += Math.cos(p.angle) * p.speed;
  2151. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2152. p.life -= 3 / p.fpsFactor;
  2153. if (p.life > 0) {
  2154. const alpha = p.life / 800;
  2155. ctx.beginPath();
  2156. ctx.arc(p.x, p.y, p.size * (p.life / 800), 0, Math.PI * 2);
  2157. ctx.fillStyle = `${p.color.slice(0, -4)}%, ${alpha})`;
  2158. ctx.fill();
  2159.  
  2160. // 余烬偶尔产生的小火花
  2161. if (Math.random() < 0.03) {
  2162. ctx.beginPath();
  2163. ctx.arc(p.x, p.y, p.size * 1.5, 0, Math.PI * 2);
  2164. ctx.fillStyle = `hsla(30, 100%, 70%, ${alpha * 0.7})`;
  2165. ctx.fill();
  2166. }
  2167. }
  2168. }
  2169. },
  2170. "shockwave": {
  2171. size: p => 10 * p.size,
  2172. life: p => 800 * Math.sqrt(p.size),
  2173. draw: (ctx, p) => {
  2174. if (!p.maxSize) {
  2175. p.maxSize = p.size * (150 + Math.random() * 100) / 10;
  2176. }
  2177. p.size += (p.maxSize - p.size) * 0.1;
  2178. p.life -= 10 / p.fpsFactor;
  2179. if (p.life > 0) {
  2180. const alpha = p.life / 400;
  2181. ctx.beginPath();
  2182. ctx.strokeStyle = p.color;
  2183. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  2184. ctx.lineWidth = 5 * alpha;
  2185. ctx.stroke();
  2186. }
  2187. }
  2188. },
  2189. "smallParticle": {
  2190. angle: p => Math.random() * Math.PI * 2,
  2191. size: p => (Math.random() * 12 + 8) * p.size,
  2192. speed: p => (Math.random() * 6 + 2) * Math.sqrt(p.size),
  2193. gravity: p => 0.3 + Math.random() * 0.1,
  2194. life: p => 400 * p.size,
  2195. draw: (ctx, p) => {
  2196. p.size = p.size * (1 - p.life / 400);
  2197. p.x += Math.cos(p.angle) * p.speed;
  2198. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2199. p.life -= 3 / p.fpsFactor;
  2200. if (p.life > 0) {
  2201. ctx.beginPath();
  2202. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  2203. ctx.fillStyle = p.color;
  2204. ctx.fill();
  2205. }
  2206. }
  2207. },
  2208. "holyCross": {
  2209. x: p => p.x + (Math.random() - 0.5) * 60,
  2210. y: p => p.y + (Math.random() - 0.5) * 10,
  2211. size: p => (8 * Math.random() + 12) * p.size,
  2212. life: p => 1200 * Math.sqrt(p.size),
  2213. speed: p => 0,
  2214. gravity: p => -0.008 * Math.random() - 0.008,
  2215. draw: (ctx, p) => {
  2216. p.speed += p.gravity * p.fpsFactor;
  2217. p.y += p.speed * p.fpsFactor;
  2218. p.life -= 3 / p.fpsFactor;
  2219. if (p.life > 0) {
  2220. ctx.save();
  2221. ctx.translate(p.x, p.y);
  2222. ctx.fillStyle = p.color;
  2223. ctx.fillRect(-p.size / 2, -p.size * 2, p.size, p.size * 4);
  2224. ctx.fillRect(-p.size * 2, -p.size / 2, p.size * 4, p.size);
  2225. ctx.restore();
  2226. }
  2227. }
  2228. },
  2229. "leaf": {
  2230. // Made by HwiteCat
  2231. x: p => p.x + (Math.random() - 0.5) * 60,
  2232. y: p => p.y + (Math.random() - 0.5) * 10,
  2233. angle: p => Math.random() * Math.PI * 2,
  2234. size: p => (12 * Math.random() + 8) * p.size,
  2235. life: p => 1250 * p.size,
  2236. speed: p => (Math.random() * 3 + 1) * Math.sqrt(p.size),
  2237. gravity: p => 0.12,
  2238. draw: (ctx, p) => {
  2239. if (!p.rotation) p.rotation = Math.random() * Math.PI * 2;
  2240. if (!p.rotationSpeed) p.rotationSpeed = (Math.random() - 0.5) * 0.02;
  2241. if (!p.sway) p.sway = (Math.random() - 0.5) * 0.2;
  2242. if (!p.swaySpeed) p.swaySpeed = (Math.random() - 0.5) * 0.02;
  2243. p.speed *= 0.98;
  2244. p.x += Math.cos(p.angle) * p.speed;
  2245. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2246. p.life -= 3 / p.fpsFactor;
  2247. if (p.rotation !== undefined) {
  2248. p.rotation += p.rotationSpeed;
  2249. }
  2250. if (p.scale !== undefined) {
  2251. p.scale += p.scaleSpeed;
  2252. p.scale = Math.max(0.1, p.scale);
  2253. }
  2254. if (p.sway !== undefined) {
  2255. p.x += Math.sin(p.y * p.swaySpeed) * p.sway;
  2256. }
  2257. if (p.life > 0) {
  2258. ctx.save();
  2259. ctx.translate(p.x, p.y);
  2260. ctx.rotate(p.rotation);
  2261. ctx.scale(p.scale, 1);
  2262. ctx.beginPath();
  2263. ctx.moveTo(0, -p.size);
  2264. ctx.bezierCurveTo(p.size / 2, -p.size / 2, p.size / 2, 0, 0, p.size);
  2265. ctx.bezierCurveTo(-p.size / 2, 0, -p.size / 2, -p.size / 2, 0, -p.size);
  2266. ctx.fillStyle = p.color;
  2267. ctx.fill();
  2268. ctx.restore();
  2269. }
  2270. }
  2271. },
  2272. "slash": {
  2273. // Main slash effect
  2274. x: p => p.x,
  2275. y: p => p.y,
  2276. angle: p => Math.random() * Math.PI * 2,
  2277. size: p => 3 * p.size,
  2278. life: p => 300 * p.size,
  2279. draw: (ctx, p) => {
  2280. if (!p.length) p.length = p.size * (120 + Math.random() * 80); // More consistent length
  2281. if (!p.maxWidth) p.maxWidth = 1.5 * Math.sqrt(p.size); // Thinner slash
  2282. p.life -= 2 / p.fpsFactor; // Even slower fade
  2283.  
  2284. if (p.life > 0) {
  2285. const alpha = p.life / 300 * p.size;
  2286. ctx.save();
  2287. ctx.translate(p.x, p.y);
  2288. ctx.rotate(p.angle);
  2289.  
  2290. // Draw main slash line with improved tapered shape
  2291. ctx.beginPath();
  2292. ctx.moveTo(-p.length / 2, 0);
  2293. ctx.quadraticCurveTo(-p.length / 4, -p.maxWidth * 0.6, -p.length / 6, -p.maxWidth);
  2294. ctx.lineTo(p.length / 6, -p.maxWidth);
  2295. ctx.quadraticCurveTo(p.length / 4, -p.maxWidth * 0.6, p.length / 2, 0);
  2296. ctx.quadraticCurveTo(p.length / 4, p.maxWidth * 0.6, p.length / 6, p.maxWidth);
  2297. ctx.lineTo(-p.length / 6, p.maxWidth);
  2298. ctx.quadraticCurveTo(-p.length / 4, p.maxWidth * 0.6, -p.length / 2, 0);
  2299. ctx.closePath();
  2300. ctx.fillStyle = p.color.replace('0.9', alpha.toString());
  2301. ctx.fill();
  2302.  
  2303. // Enhanced glow effect
  2304. ctx.beginPath();
  2305. ctx.moveTo(-p.length / 2, 0);
  2306. ctx.quadraticCurveTo(-p.length / 4, -p.maxWidth * 0.8, -p.length / 6, -p.maxWidth * 1.5);
  2307. ctx.lineTo(p.length / 6, -p.maxWidth * 1.5);
  2308. ctx.quadraticCurveTo(p.length / 4, -p.maxWidth * 0.8, p.length / 2, 0);
  2309. ctx.quadraticCurveTo(p.length / 4, p.maxWidth * 0.8, p.length / 6, p.maxWidth * 1.5);
  2310. ctx.lineTo(-p.length / 6, p.maxWidth * 1.5);
  2311. ctx.quadraticCurveTo(-p.length / 4, p.maxWidth * 0.8, -p.length / 2, 0);
  2312. ctx.closePath();
  2313. ctx.fillStyle = p.color.replace('0.9', (alpha * 0.3).toString());
  2314. ctx.fill();
  2315. ctx.restore();
  2316. }
  2317. }
  2318. },
  2319. "slashParticle": {
  2320. // Enhanced particle effect for slash
  2321. x: p => p.x + (Math.random() - 0.5) * 15,
  2322. // Tighter initial spread
  2323. y: p => p.y + (Math.random() - 0.5) * 15,
  2324. angle: p => {
  2325. const baseAngle = p.parentAngle || Math.random() * Math.PI * 2;
  2326. return baseAngle + (Math.random() - 0.5) * 0.1; // Very small variation
  2327. },
  2328. size: p => (2 * Math.random() + 2) * p.size,
  2329. // Bigger particles
  2330. life: p => 600 * p.size,
  2331. // Adjusted for faster movement
  2332. speed: p => (Math.random() * 1 + 3) * Math.sqrt(p.size),
  2333. // Much faster speed
  2334. gravity: p => 0.02,
  2335. // Minimal gravity for more directional movement
  2336. draw: (ctx, p) => {
  2337. p.speed *= 0.998; // Very smooth deceleration
  2338. p.x += Math.cos(p.angle) * p.speed;
  2339. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2340. p.life -= 3 / p.fpsFactor;
  2341. if (p.life > 0) {
  2342. const alpha = p.life / 400;
  2343. ctx.save();
  2344. ctx.translate(p.x, p.y);
  2345. ctx.rotate(p.angle);
  2346.  
  2347. // Draw particle with more elongation in movement direction
  2348. ctx.beginPath();
  2349. ctx.moveTo(-p.size / 2, 0);
  2350. ctx.quadraticCurveTo(-p.size / 4, -p.size / 2, 0, -p.size * 1.2);
  2351. ctx.quadraticCurveTo(p.size / 4, -p.size / 2, p.size / 2, 0);
  2352. ctx.quadraticCurveTo(p.size / 4, p.size / 2, 0, p.size * 1.2);
  2353. ctx.quadraticCurveTo(-p.size / 4, p.size / 2, -p.size / 2, 0);
  2354. ctx.closePath();
  2355. ctx.fillStyle = p.color.replace('0.9', alpha.toString());
  2356. ctx.fill();
  2357.  
  2358. // Add small glow to particles
  2359. ctx.beginPath();
  2360. ctx.arc(0, 0, p.size * 1.2, 0, Math.PI * 2);
  2361. ctx.fillStyle = p.color.replace('0.9', (alpha * 0.3).toString());
  2362. ctx.fill();
  2363. ctx.restore();
  2364. }
  2365. }
  2366. },
  2367. "waterRipple": {
  2368. x: p => p.x,
  2369. y: p => p.y,
  2370. size: p => 3 * p.size,
  2371. life: p => 1200 * p.size,
  2372. draw: (ctx, p) => {
  2373. if (!p.ripples) {
  2374. p.ripples = [{
  2375. radius: 0,
  2376. opacity: 0.5,
  2377. width: 3,
  2378. speed: 0.7
  2379. },
  2380. // Fast, bright inner ripple
  2381. {
  2382. radius: 0,
  2383. opacity: 0.5,
  2384. width: 2,
  2385. speed: 0.5
  2386. },
  2387. // Medium ripple
  2388. {
  2389. radius: 0,
  2390. opacity: 0.5,
  2391. width: 1.5,
  2392. speed: 0.3
  2393. } // Slow, faint outer ripple
  2394. ];
  2395. }
  2396. p.life -= 1;
  2397.  
  2398. // Update each ripple
  2399. p.ripples.forEach((ripple, index) => {
  2400. // Expand the ripple
  2401. ripple.radius += ripple.speed;
  2402.  
  2403. // Calculate opacity based on radius
  2404. const maxRadius = 30 * p.size;
  2405. const fadeStart = maxRadius * 0.6;
  2406. if (ripple.radius > fadeStart) {
  2407. ripple.opacity *= 0.98; // Gradual fade out
  2408. }
  2409.  
  2410. // Draw the ripple if it's still visible
  2411. if (ripple.opacity > 0.05 && ripple.radius < maxRadius) {
  2412. ctx.beginPath();
  2413. ctx.strokeStyle = p.color.replace('0.8', ripple.opacity.toString());
  2414. ctx.lineWidth = ripple.width * (1 - ripple.radius / maxRadius);
  2415. ctx.arc(p.x, p.y, ripple.radius, 0, Math.PI * 2);
  2416. ctx.stroke();
  2417.  
  2418. // Add a second, fainter ring for more water-like effect
  2419. if (ripple.radius > 5) {
  2420. ctx.beginPath();
  2421. ctx.strokeStyle = p.color.replace('0.8', (ripple.opacity * 0.5).toString());
  2422. ctx.lineWidth = ripple.width * 0.5 * (1 - ripple.radius / maxRadius);
  2423. ctx.arc(p.x, p.y, ripple.radius - 2, 0, Math.PI * 2);
  2424. ctx.stroke();
  2425. }
  2426. }
  2427. });
  2428. }
  2429. },
  2430. "waterSplash": {
  2431. x: p => p.x,
  2432. y: p => p.y,
  2433. size: p => (2 * Math.random() + 5) * p.size,
  2434. // Smaller size
  2435. life: p => 800 * p.size,
  2436. draw: (ctx, p) => {
  2437. if (!p.initialized) {
  2438. p.initialized = true;
  2439. p.particles = [];
  2440. // Create particles in a circular pattern
  2441. const particleCount = 7; // More particles for better coverage
  2442. for (let i = 0; i < particleCount; i++) {
  2443. const angle = i / particleCount * Math.PI * 2;
  2444. // Add some random variation to the angle
  2445. const angleVariation = (Math.random() - 0.5) * 0.5;
  2446. const finalAngle = angle + angleVariation;
  2447.  
  2448. // Create size variation with smaller base size
  2449. const sizeVariation = Math.random() * 1.5 + 0.5; // Random multiplier between 0.5 and 2
  2450. const baseSize = (Math.random() * 0.8 + 0.4) * p.size; // Reduced base size
  2451.  
  2452. p.particles.push({
  2453. x: p.x,
  2454. y: p.y,
  2455. angle: finalAngle,
  2456. speed: (Math.random() * 1.5 + 1) * Math.sqrt(p.size),
  2457. size: baseSize * sizeVariation,
  2458. initialSize: baseSize * sizeVariation,
  2459. life: 800 * p.size,
  2460. gravity: 0.9 + (Math.random() * 0.2 - 0.1) // Slight gravity variation
  2461. });
  2462. }
  2463. }
  2464. p.life -= 2 / p.fpsFactor;
  2465.  
  2466. // Update and draw particles
  2467. p.particles.forEach(particle => {
  2468. particle.speed *= 0.98; // Deceleration
  2469. particle.x += Math.cos(particle.angle) * particle.speed;
  2470. particle.y += Math.sin(particle.angle) * particle.speed + particle.gravity;
  2471. particle.life -= 2;
  2472. const lifeRatio = particle.life / (800 * p.size);
  2473. const opacity = lifeRatio * 0.6; // More transparent
  2474. // More dramatic shrinking with cubic easing
  2475. particle.size = particle.initialSize * Math.pow(lifeRatio, 3);
  2476. if (particle.life > 0) {
  2477. ctx.beginPath();
  2478. ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
  2479. ctx.fillStyle = p.color.replace('0.8', opacity.toString());
  2480. ctx.fill();
  2481. }
  2482. });
  2483. }
  2484. },
  2485. "magnet": {
  2486. x: p => p.x,
  2487. y: p => p.y,
  2488. size: p => (2 * Math.random() + 20) * p.size,
  2489. life: p => 800 * p.size,
  2490. draw: (ctx, p) => {
  2491. if (!p.initialized) {
  2492. p.initialized = true;
  2493. p.particles = [];
  2494. // Create particles in a circular pattern
  2495. const particleCount = 5; // Fewer particles for magnets
  2496. for (let i = 0; i < particleCount; i++) {
  2497. const angle = i / particleCount * Math.PI * 2;
  2498. // Add some random variation to the angle
  2499. const angleVariation = (Math.random() - 0.5) * 0.5;
  2500. const finalAngle = angle + angleVariation;
  2501.  
  2502. // Create size variation
  2503. const sizeVariation = Math.random() * 1.5 + 0.5;
  2504. const baseSize = (Math.random() * 0.8 + 0.4) * p.size;
  2505. p.particles.push({
  2506. x: p.x,
  2507. y: p.y,
  2508. angle: finalAngle,
  2509. speed: (Math.random() * 1.5 + 1) * Math.sqrt(p.size),
  2510. size: baseSize * sizeVariation,
  2511. initialSize: baseSize * sizeVariation,
  2512. life: 800 * p.size,
  2513. gravity: 0.3 + (Math.random() * 0.2 - 0.1),
  2514. // Less gravity for magnets
  2515. rotation: Math.random() * Math.PI * 2,
  2516. rotationSpeed: (Math.random() - 0.5) * 0.02
  2517. });
  2518. }
  2519. }
  2520. p.life -= 2 / p.fpsFactor;
  2521.  
  2522. // Update and draw particles
  2523. p.particles.forEach(particle => {
  2524. particle.speed *= 0.96;
  2525. particle.x += Math.cos(particle.angle) * particle.speed;
  2526. particle.y += Math.sin(particle.angle) * particle.speed + particle.gravity;
  2527. particle.life -= 1;
  2528. particle.rotation += particle.rotationSpeed;
  2529. const lifeRatio = particle.life / (800 * p.size);
  2530. const opacity = lifeRatio * 0.8;
  2531. particle.size = particle.initialSize * Math.pow(lifeRatio, 2);
  2532. if (particle.life > 0) {
  2533. ctx.save();
  2534. ctx.translate(particle.x, particle.y);
  2535. ctx.rotate(particle.rotation);
  2536.  
  2537. // Use the magnet shape from shape.js
  2538. shapes.magnet(ctx, {
  2539. x: 0,
  2540. y: 0,
  2541. size: particle.size,
  2542. color: `rgba(128, 128, 128, ${opacity})`
  2543. });
  2544. ctx.restore();
  2545. }
  2546. });
  2547. }
  2548. },
  2549. "star": {
  2550. x: p => p.x + (Math.random() - 0.5) * 60,
  2551. y: p => p.y + (Math.random() - 0.5) * 10,
  2552. angle: p => Math.random() * Math.PI * 2,
  2553. size: p => (Math.random() * 6 + 2) * p.size,
  2554. life: p => 1200 * Math.sqrt(p.size),
  2555. speed: p => (Math.random() * 6 + 2) * Math.sqrt(p.size),
  2556. gravity: p => -0.1,
  2557. draw: (ctx, p) => {
  2558. if (!p.initialized) {
  2559. p.initialized = true;
  2560. p.y -= 5 * p.size;
  2561. }
  2562. p.speed *= 0.97; // 慢慢减速
  2563. p.x += Math.cos(p.angle) * p.speed;
  2564. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2565. p.life -= 3 / p.fpsFactor;
  2566. if (p.life > 0) {
  2567. const alpha = Math.max(0, Math.min(1, p.life / 1200));
  2568. ctx.save();
  2569. ctx.translate(p.x, p.y);
  2570. ctx.rotate(p.angle);
  2571. const starSize = p.size * 10;
  2572. ctx.beginPath();
  2573. const startAngle = -Math.PI / 2;
  2574. const startX = Math.cos(startAngle) * starSize;
  2575. const startY = Math.sin(startAngle) * starSize;
  2576. ctx.moveTo(startX, startY);
  2577. for (let i = 0; i < 5; i++) {
  2578. const outerAngle = i * 2 * Math.PI / 5 - Math.PI / 2;
  2579. const innerAngle = outerAngle + Math.PI / 5;
  2580. const outerX = Math.cos(outerAngle) * starSize;
  2581. const outerY = Math.sin(outerAngle) * starSize;
  2582. ctx.lineTo(outerX, outerY);
  2583. const innerX = Math.cos(innerAngle) * (starSize / 2);
  2584. const innerY = Math.sin(innerAngle) * (starSize / 2);
  2585. ctx.lineTo(innerX, innerY);
  2586. }
  2587. ctx.closePath();
  2588. ctx.fillStyle = p.color.replace(/rgba\(([^,]+),([^,]+),([^,]+),[^)]+\)/, `rgba($1,$2,$3,${alpha})`);
  2589. ctx.fill();
  2590. ctx.restore();
  2591. }
  2592. }
  2593. },
  2594. "pierce": {
  2595. x: p => p.x,
  2596. y: p => p.y,
  2597. size: p => 4 * p.size,
  2598. life: p => 1200 * p.size,
  2599. draw: (ctx, p) => {
  2600. if (!p.initialized) {
  2601. p.initialized = true;
  2602. p.pierceLength = p.size * 16;
  2603. p.pierceWidth = p.size / 10;
  2604. p.time = 0;
  2605. p.ripples = [];
  2606. // Create initial ripples
  2607. for (let i = 0; i < 3; i++) {
  2608. p.ripples.push({
  2609. radius: 0,
  2610. speed: 0.5 + i * 0.2,
  2611. opacity: 0.6 - i * 0.15,
  2612. width: 2 - i * 0.5
  2613. });
  2614. }
  2615. }
  2616. p.life -= 2 / p.fpsFactor;
  2617. p.time += 0.1;
  2618. const alpha = p.life / 1200;
  2619. if (p.life > 0) {
  2620. ctx.save();
  2621. ctx.translate(p.x, p.y);
  2622.  
  2623. // Draw dynamic ripples
  2624. p.ripples.forEach(ripple => {
  2625. ripple.radius += ripple.speed;
  2626. const rippleAlpha = ripple.opacity * alpha * (1 - ripple.radius / (p.size * 8));
  2627. if (rippleAlpha > 0.01) {
  2628. ctx.beginPath();
  2629. ctx.strokeStyle = p.color.replace('0.8', rippleAlpha.toString());
  2630. ctx.lineWidth = ripple.width;
  2631. ctx.arc(0, 0, ripple.radius, 0, Math.PI * 2);
  2632. ctx.stroke();
  2633. }
  2634. });
  2635.  
  2636. // 4角星星
  2637. const vertices = {
  2638. top: {
  2639. x: 0,
  2640. y: -p.pierceLength / 2.5
  2641. },
  2642. // Reduced vertical height
  2643. right: {
  2644. x: p.pierceLength,
  2645. y: 0
  2646. },
  2647. // Maintained horizontal stretch
  2648. bottom: {
  2649. x: 0,
  2650. y: p.pierceLength / 2.5
  2651. },
  2652. // Reduced vertical height
  2653. left: {
  2654. x: -p.pierceLength,
  2655. y: 0
  2656. } // Maintained horizontal stretch
  2657. };
  2658.  
  2659. // Define inner points for curved connections (closer to center)
  2660. const innerPoints = {
  2661. topRight: {
  2662. x: p.pierceLength / 7,
  2663. y: -p.pierceLength / 10
  2664. },
  2665. // Moved closer to center
  2666. bottomRight: {
  2667. x: p.pierceLength / 7,
  2668. y: p.pierceLength / 10
  2669. },
  2670. // Moved closer to center
  2671. bottomLeft: {
  2672. x: -p.pierceLength / 7,
  2673. y: p.pierceLength / 10
  2674. },
  2675. // Moved closer to center
  2676. topLeft: {
  2677. x: -p.pierceLength / 7,
  2678. y: -p.pierceLength / 10
  2679. } // Moved closer to center
  2680. };
  2681.  
  2682. // Draw the shape with straight lines
  2683. ctx.beginPath();
  2684. ctx.moveTo(vertices.top.x, vertices.top.y);
  2685.  
  2686. // Draw straight lines between vertices and inner points
  2687. // Top to right
  2688. ctx.lineTo(innerPoints.topRight.x, innerPoints.topRight.y);
  2689. ctx.lineTo(vertices.right.x, vertices.right.y);
  2690.  
  2691. // Right to bottom
  2692. ctx.lineTo(innerPoints.bottomRight.x, innerPoints.bottomRight.y);
  2693. ctx.lineTo(vertices.bottom.x, vertices.bottom.y);
  2694.  
  2695. // Bottom to left
  2696. ctx.lineTo(innerPoints.bottomLeft.x, innerPoints.bottomLeft.y);
  2697. ctx.lineTo(vertices.left.x, vertices.left.y);
  2698.  
  2699. // Left to top
  2700. ctx.lineTo(innerPoints.topLeft.x, innerPoints.topLeft.y);
  2701. ctx.lineTo(vertices.top.x, vertices.top.y);
  2702. ctx.closePath();
  2703.  
  2704. // Add main fill with enhanced opacity
  2705. ctx.fillStyle = p.color.replace('0.8', (alpha * 0.9).toString());
  2706. ctx.fill();
  2707. ctx.restore();
  2708. }
  2709. }
  2710. },
  2711. "poison": {
  2712. x: p => p.x,
  2713. y: p => p.y,
  2714. size: p => 5 * p.size,
  2715. // Increased base size
  2716. life: p => 800 * p.size,
  2717. // Longer lifetime
  2718. draw: (ctx, p) => {
  2719. if (!p.initialized) {
  2720. p.initialized = true;
  2721. p.bubbles = [];
  2722. for (let i = 0; i < 6; i++) {
  2723. // More bubbles
  2724. p.bubbles.push({
  2725. x: p.x + (Math.random() - 0.5) * p.size * 4,
  2726. // Wider spread
  2727. y: p.y + (Math.random() - 0.5) * p.size * 4,
  2728. size: p.size * (Math.random() * 1.2 + 1.2),
  2729. // Bigger bubbles
  2730. speed: Math.random() * 0.8 + 0.4,
  2731. // Faster rise
  2732. wobble: Math.random() * Math.PI * 2,
  2733. // For side-to-side movement
  2734. wobbleSpeed: Math.random() * 0.05 + 0.02
  2735. });
  2736. }
  2737. }
  2738. p.life -= 1;
  2739. const alpha = Math.pow(p.life / p.maxLife, 0.7);
  2740. if (p.life > 0) {
  2741. // Draw main poison cloud
  2742. ctx.beginPath();
  2743. ctx.arc(p.x, p.y, p.size * alpha, 0, Math.PI * 2);
  2744. ctx.fillStyle = changeColorAlpha(p.color, alpha * 0.8);
  2745. ctx.fill();
  2746.  
  2747. // Draw and update bubbles
  2748. p.bubbles.forEach(bubble => {
  2749. bubble.y -= bubble.speed;
  2750. bubble.wobble += bubble.wobbleSpeed;
  2751. bubble.x += Math.sin(bubble.wobble) * 0.5;
  2752. ctx.beginPath();
  2753. ctx.arc(bubble.x, bubble.y, bubble.size, 0, Math.PI * 2);
  2754. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  2755. ctx.fill();
  2756.  
  2757. // Add bubble highlight
  2758. ctx.beginPath();
  2759. ctx.arc(bubble.x - bubble.size * 0.3, bubble.y - bubble.size * 0.3, bubble.size * 0.3, 0, Math.PI * 2);
  2760. ctx.fillStyle = `rgba(255, 255, 255, ${alpha * 0.3})`;
  2761. ctx.fill();
  2762. });
  2763. }
  2764. }
  2765. },
  2766. "ice": {
  2767. x: p => p.x,
  2768. y: p => p.y,
  2769. speed: p => (Math.random() * 3 + 1.5) * Math.sqrt(p.size),
  2770. size: p => (2 * Math.random() + 3) * p.size,
  2771. life: p => 1200 * p.size,
  2772. draw: (ctx, p) => {
  2773. p.length = p.size * 7;
  2774. p.speed *= 0.96;
  2775. p.x += Math.cos(p.angle) * p.speed;
  2776. p.y += Math.sin(p.angle) * p.speed;
  2777. p.life -= 1;
  2778. const lifeRatio = p.life / p.maxLife;
  2779. const alpha = Math.pow(lifeRatio, 0.2);
  2780. if (p.life > 0) {
  2781. ctx.save();
  2782. ctx.translate(p.x, p.y);
  2783. ctx.rotate(p.angle + Math.PI / 2);
  2784. ctx.beginPath();
  2785. ctx.moveTo(0, -p.length / 2);
  2786. ctx.lineTo(p.size / 2, 0);
  2787. ctx.lineTo(0, p.length / 2);
  2788. ctx.lineTo(-p.size / 2, 0);
  2789. ctx.closePath();
  2790. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  2791. ctx.fill();
  2792. ctx.strokeStyle = changeColorAlpha(p.color, alpha);
  2793. ctx.lineWidth = 2;
  2794. ctx.stroke();
  2795.  
  2796. // Add white glow
  2797. ctx.beginPath();
  2798. ctx.moveTo(0, -p.length / 2);
  2799. ctx.lineTo(p.size / 2, 0);
  2800. ctx.lineTo(0, p.length / 2);
  2801. ctx.lineTo(-p.size / 2, 0);
  2802. ctx.closePath();
  2803.  
  2804. // Create gradient for glow
  2805. const gradient = ctx.createLinearGradient(0, -p.length / 2, 0, p.length / 2);
  2806. gradient.addColorStop(0, `rgba(255, 255, 255, ${alpha * 0.8})`);
  2807. gradient.addColorStop(0.5, `rgba(255, 255, 255, ${alpha * 0.4})`);
  2808. gradient.addColorStop(1, `rgba(255, 255, 255, ${alpha * 0.8})`);
  2809. ctx.fillStyle = gradient;
  2810. ctx.fill();
  2811.  
  2812. // Add shiny highlight
  2813. ctx.beginPath();
  2814. ctx.moveTo(-p.size / 4, -p.length / 4);
  2815. ctx.lineTo(p.size / 4, -p.length / 4);
  2816. ctx.lineTo(0, 0);
  2817. ctx.closePath();
  2818. const highlightGradient = ctx.createLinearGradient(-p.size / 4, -p.length / 4, 0, 0);
  2819. highlightGradient.addColorStop(0, `rgba(255, 255, 255, ${alpha * 0.9})`);
  2820. highlightGradient.addColorStop(1, `rgba(255, 255, 255, 0)`);
  2821. ctx.fillStyle = highlightGradient;
  2822. ctx.fill();
  2823. ctx.restore();
  2824. }
  2825. }
  2826. },
  2827. "lava": {
  2828. x: p => p.x + (Math.random() - 0.5) * p.size * 5,
  2829. y: p => p.y + (Math.random() - 0.5) * p.size * 2,
  2830. size: p => (14 * Math.random() + 20) * p.size,
  2831. angle: p => (Math.random() - 0.5) * Math.PI / 5 * 2 - Math.PI / 2,
  2832. speed: p => (Math.random() * 7 + 5) * Math.sqrt(p.size),
  2833. gravity: p => 1.2 + (Math.random() * 0.2 - 0.1),
  2834. life: p => 1200 * p.size,
  2835. draw: (ctx, p) => {
  2836. if (!p.initialized) {
  2837. p.initialized = true;
  2838. p.particles = [];
  2839.  
  2840. // Particle configuration
  2841. const numPoints = 16;
  2842. p.numPoints = numPoints;
  2843. p.noiseOffsets = Array.from({
  2844. length: numPoints
  2845. }, () => Math.random() * Math.PI * 2);
  2846. p.noiseAmplitudes = Array.from({
  2847. length: numPoints
  2848. }, () => Math.random() * 0.15 + 0.85);
  2849. p.noiseSpeeds = Array.from({
  2850. length: numPoints
  2851. }, () => Math.random() * 0.03 + 0.02);
  2852. p.time = 0;
  2853. p.rotation = Math.random() * Math.PI * 2;
  2854. p.rotationSpeed = (Math.random() - 0.5) * 0.05;
  2855. p.oringinalSize = p.size;
  2856. }
  2857. p.life -= 1;
  2858. p.speed *= 0.98;
  2859. p.x += Math.cos(p.angle) * p.speed;
  2860. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2861. p.life -= 1;
  2862. p.rotation += p.rotationSpeed;
  2863. p.time += 0.15;
  2864. const lifeRatio = p.life / p.maxLife;
  2865. const opacity = lifeRatio * 0.8;
  2866. const sizeReduction = Math.pow(lifeRatio, 0.1);
  2867. p.size = Math.min(p.size * sizeReduction, p.oringinalSize);
  2868. if (p.life > 0) {
  2869. ctx.save();
  2870. ctx.translate(p.x, p.y);
  2871. ctx.rotate(p.rotation);
  2872.  
  2873. // Enable blending for better transparency
  2874. ctx.globalCompositeOperation = 'lighter';
  2875.  
  2876. // Draw base particle shape
  2877. ctx.beginPath();
  2878. for (let i = 0; i < p.numPoints; i++) {
  2879. const angle = i / p.numPoints * Math.PI * 2;
  2880. const noise = Math.sin(angle + p.noiseOffsets[i] + p.time * p.noiseSpeeds[i]) * p.noiseAmplitudes[i];
  2881. const surfaceTension = Math.sin(angle * 3 + p.time * 0.5) * 0.15;
  2882. const radius = p.size * (1 + noise * 0.2 + surfaceTension);
  2883. const x = Math.cos(angle) * radius;
  2884. const y = Math.sin(angle) * radius;
  2885. if (i === 0) {
  2886. ctx.moveTo(x, y);
  2887. } else {
  2888. const prevAngle = (i - 1) / p.numPoints * Math.PI * 2;
  2889. const prevNoise = Math.sin(prevAngle + p.noiseOffsets[i - 1] + p.time * p.noiseSpeeds[i - 1]) * p.noiseAmplitudes[i - 1];
  2890. const prevSurfaceTension = Math.sin(prevAngle * 3 + p.time * 0.5) * 0.15;
  2891. const prevRadius = p.size * (1 + prevNoise * 0.2 + prevSurfaceTension);
  2892. const prevX = Math.cos(prevAngle) * prevRadius;
  2893. const prevY = Math.sin(prevAngle) * prevRadius;
  2894. const cpX = (prevX + x) / 2;
  2895. const cpY = (prevY + y) / 2;
  2896. ctx.quadraticCurveTo(cpX, cpY, x, y);
  2897. }
  2898. }
  2899. ctx.closePath();
  2900.  
  2901. // Draw particle with glow effects
  2902. // Base layer with reduced opacity
  2903. ctx.fillStyle = changeColorAlpha(p.color, opacity);
  2904. ctx.fill();
  2905.  
  2906. // Glow layers with adjusted opacity
  2907. const drawGlowLayer = (radius, color, alpha) => {
  2908. ctx.beginPath();
  2909. ctx.arc(0, 0, radius, 0, Math.PI * 2);
  2910. ctx.fillStyle = changeColorAlpha(p.color, opacity);
  2911. ctx.fill();
  2912. };
  2913.  
  2914. // Core and inner glow with reduced opacity
  2915. drawGlowLayer(p.size * 0.6);
  2916. drawGlowLayer(p.size * (1.2 + Math.sin(p.time * 0.5) * 0.2));
  2917.  
  2918. // Middle aura with softer gradient
  2919. const middleGlow = ctx.createRadialGradient(0, 0, p.size, 0, 0, p.size * 2);
  2920. middleGlow.addColorStop(0, changeColorAlpha(p.color, opacity * 0.2));
  2921. middleGlow.addColorStop(0.5, `rgba(255, 50, 0, ${opacity * 0.1})`);
  2922. middleGlow.addColorStop(1, `rgba(255, 0, 0, 0)`);
  2923. ctx.beginPath();
  2924. ctx.arc(0, 0, p.size * 2, 0, Math.PI * 2);
  2925. ctx.fillStyle = middleGlow;
  2926. ctx.fill();
  2927.  
  2928. // Outer aura with softer gradient
  2929. const outerGlow = ctx.createRadialGradient(0, 0, p.size * 1.5, 0, 0, p.size * (2.5 + Math.sin(p.time * 0.5) * 0.3));
  2930. outerGlow.addColorStop(0, changeColorAlpha(p.color, opacity * 0.1));
  2931. outerGlow.addColorStop(0.5, `rgba(200, 0, 0, ${opacity * 0.03})`);
  2932. outerGlow.addColorStop(1, `rgba(150, 0, 0, 0)`);
  2933. ctx.beginPath();
  2934. ctx.arc(0, 0, p.size * (2.5 + Math.sin(p.time * 0.5) * 0.3), 0, Math.PI * 2);
  2935. ctx.fillStyle = outerGlow;
  2936. ctx.fill();
  2937.  
  2938. // Reset composite operation
  2939. ctx.globalCompositeOperation = 'source-over';
  2940. ctx.restore();
  2941. }
  2942. }
  2943. },
  2944. "tornado": {
  2945. x: p => p.x,
  2946. y: p => p.y + 20,
  2947. size: p => 3 * p.size,
  2948. life: p => 2000 * p.size,
  2949. speed: p => (Math.random() * 3 + 1) * Math.sqrt(p.size),
  2950. gravity: p => 0.12,
  2951. draw: (ctx, p) => {
  2952. if (!p.initialized) {
  2953. p.initialized = true;
  2954. p.particles = [];
  2955. p.maxParticles = 6;
  2956. p.amplitude = 60 * p.size;
  2957. p.frequency = 7;
  2958. p.timeSpeed = 0.4;
  2959. p.maxHeight = 200 * p.size;
  2960.  
  2961. // Parse the base color once
  2962. const colorMatch = p.color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/);
  2963. if (colorMatch) {
  2964. p.baseColor = {
  2965. r: parseInt(colorMatch[1]),
  2966. g: parseInt(colorMatch[2]),
  2967. b: parseInt(colorMatch[3])
  2968. };
  2969. }
  2970.  
  2971. // Initialize particles with staggered heights
  2972. for (let i = 0; i < p.maxParticles; i++) {
  2973. const startAngle = Math.random() * Math.PI * 2;
  2974. const startRadius = Math.random() * 40 * p.size;
  2975. p.particles.push({
  2976. angle: startAngle,
  2977. radius: Math.random() * 150 + 5,
  2978. height: i / p.maxParticles * p.maxHeight,
  2979. speed: Math.random() * 0.04 + 0.01,
  2980. size: Math.random() * 3 + 2,
  2981. baseSpeed: Math.random() * 0.04 + 0.01,
  2982. startX: Math.cos(startAngle) * startRadius,
  2983. startY: Math.sin(startAngle) * startRadius,
  2984. initialSize: Math.random() * 3 + 2,
  2985. rotation: Math.random() * Math.PI * 2,
  2986. rotationSpeed: (Math.random() - 0.5) * 0.02,
  2987. sway: (Math.random() - 0.5) * 0.2,
  2988. swaySpeed: (Math.random() - 0.5) * 0.02
  2989. });
  2990. }
  2991. }
  2992. p.life -= 1;
  2993. if (p.life > 0) {
  2994. const alpha = Math.min(p.life / p.maxLife, 1);
  2995. for (let particle of p.particles) {
  2996. const heightRatio = particle.height / p.maxHeight;
  2997. const currentSpeed = particle.baseSpeed * Math.pow(1 - heightRatio, 3);
  2998. particle.angle += p.frequency * currentSpeed * p.timeSpeed * p.fpsFactor;
  2999. particle.radius += (Math.random() - 0.5) * 0.5;
  3000. particle.height += 1.5 * p.timeSpeed * p.fpsFactor;
  3001.  
  3002. // Add leaf-like movement
  3003. particle.rotation += particle.rotationSpeed;
  3004. if (particle.sway !== undefined) {
  3005. particle.startX += Math.sin(particle.height * particle.swaySpeed) * particle.sway;
  3006. }
  3007. if (particle.height > p.maxHeight) {
  3008. particle.height = 0;
  3009. const startAngle = Math.random() * Math.PI * 2;
  3010. const startRadius = Math.random() * 40 * p.size;
  3011. particle.startX = Math.cos(startAngle) * startRadius;
  3012. particle.startY = Math.sin(startAngle) * startRadius;
  3013. particle.angle = startAngle;
  3014. particle.initialSize = Math.random() * 3 + 2;
  3015. particle.rotation = Math.random() * Math.PI * 2;
  3016. particle.rotationSpeed = (Math.random() - 0.5) * 0.02;
  3017. particle.sway = (Math.random() - 0.5) * 0.2;
  3018. particle.swaySpeed = (Math.random() - 0.5) * 0.02;
  3019. }
  3020. const spiral = particle.height / p.maxHeight * p.amplitude;
  3021. const x = p.x + particle.startX + Math.cos(particle.angle) * spiral;
  3022. const y = p.y - particle.height + particle.startY;
  3023.  
  3024. // Calculate current size based on height and apply size limit
  3025. const currentSize = Math.min(particle.initialSize * (1 - heightRatio * 0.7) * p.size, Math.min(Math.ceil(p.size * 6), 10));
  3026.  
  3027. // Calculate gradient color based on height
  3028. const gradientFactor = heightRatio * 1; // 100% 上面白
  3029. const r = Math.min(255, p.baseColor.r + (255 - p.baseColor.r) * gradientFactor);
  3030. const g = Math.min(255, p.baseColor.g + (255 - p.baseColor.g) * gradientFactor);
  3031. const b = Math.min(255, p.baseColor.b + (255 - p.baseColor.b) * gradientFactor);
  3032.  
  3033. // Draw main particle with size reduction
  3034. ctx.save();
  3035. ctx.translate(x, y);
  3036. ctx.rotate(particle.rotation);
  3037. ctx.beginPath();
  3038. ctx.arc(0, 0, currentSize, 0, Math.PI * 2);
  3039. ctx.fillStyle = `rgba(${Math.floor(r)}, ${Math.floor(g)}, ${Math.floor(b)}, ${alpha})`;
  3040. ctx.fill();
  3041.  
  3042. // Add glow effect with size reduction
  3043. ctx.beginPath();
  3044. ctx.arc(0, 0, currentSize * 1.5, 0, Math.PI * 2);
  3045. ctx.fillStyle = `rgba(${Math.floor(r)}, ${Math.floor(g)}, ${Math.floor(b)}, ${alpha * 0.5})`;
  3046. ctx.fill();
  3047. ctx.restore();
  3048. }
  3049. }
  3050. }
  3051. },
  3052. "pixelSmoke": {
  3053. x: p => p.x + (Math.random() - 0.5) * 80,
  3054. y: p => p.y + (Math.random() - 0.5) * 80,
  3055. angle: p => (Math.random() - 0.5) * Math.PI / 5 * 2 - Math.PI / 2,
  3056. color: p => `hsl(0, 0%, ${Math.round(Math.random() * 65 + 10)}%)`,
  3057. size: p => (Math.random() * 40 + 10) * p.size,
  3058. speed: p => Math.random() * 0.5 * Math.sqrt(p.size),
  3059. gravity: p => -0.3 + Math.random() * 0.2 * p.size,
  3060. life: p => Math.floor((Math.random() * 700 + 100) * p.size),
  3061. draw: (ctx, p) => {
  3062. const alpha = Math.pow(p.life / p.maxLife, 0.2);
  3063. p.x += Math.cos(p.angle) * p.speed * 0.3;
  3064. p.speed *= 0.992;
  3065. p.y += -Math.sin(p.speed) * 0.5;
  3066. p.color = changeColorAlpha(p.color, alpha);
  3067. p.life -= 1;
  3068. if (p.life > 0) {
  3069. shapes.rectangle(ctx, p);
  3070. }
  3071. }
  3072. },
  3073. "shatter": {
  3074. x: p => p.x,
  3075. y: p => p.y,
  3076. size: p => (1 * Math.random() + 5) * p.size,
  3077. life: p => 500 * p.size,
  3078. draw: (ctx, p) => {
  3079. if (!p.initialized) {
  3080. p.initialized = true;
  3081. p.particles = [];
  3082. // Create particles in a circular pattern
  3083. const particleCount = Math.max(2, Math.min(0.1, Math.floor(p.size * 1))); // Scale particle count with size
  3084.  
  3085. // Define the main direction and spread
  3086. const mainAngle = Math.random() * Math.PI * 2; // Random main direction
  3087. const spreadAngle = Math.PI / 3; // 60 degree spread
  3088.  
  3089. for (let i = 0; i < particleCount; i++) {
  3090. // Calculate angle within the spread range
  3091. const angleProgress = i / (particleCount - 1);
  3092. const angleVariation = (Math.random() - 0.5) * 0.3; // Small random variation
  3093. const finalAngle = mainAngle - spreadAngle / 2 + spreadAngle * angleProgress + angleVariation;
  3094.  
  3095. // Create size variation
  3096. const sizeVariation = Math.random() * 0.8 + 0.6; // More consistent size
  3097. const baseSize = (Math.random() * 0.6 + 5) * p.size;
  3098.  
  3099. // Generate initial radius variations for each point
  3100. const points = Math.floor(Math.random() * 3) + 3;
  3101. const radiusVariations = Array.from({
  3102. length: points
  3103. }, () => 0.7 + Math.random() * 0.6);
  3104. p.particles.push({
  3105. x: p.x,
  3106. y: p.y,
  3107. angle: finalAngle,
  3108. speed: (Math.random() * 2 + 1) * Math.sqrt(p.size) * p.fpsFactor,
  3109. // Reduced initial speed
  3110. size: baseSize * sizeVariation,
  3111. initialSize: baseSize * sizeVariation,
  3112. life: 500 * p.size,
  3113. maxLife: 500 * p.size,
  3114. gravity: 0.05,
  3115. points: points,
  3116. shapeAngle: Math.floor(Math.random() * 6),
  3117. rotationSpeed: (Math.random() - 0.5) * 0.05,
  3118. // Add rotation speed
  3119. radiusVariations: radiusVariations,
  3120. verticalSpeed: 0 // Add vertical speed for better gravity effect
  3121. });
  3122. }
  3123. }
  3124. p.life -= 10 / p.fpsFactor;
  3125.  
  3126. // Update and draw particles
  3127. p.particles.forEach(particle => {
  3128. // Update vertical speed with gravity
  3129. particle.verticalSpeed += particle.gravity;
  3130.  
  3131. // Update position with both horizontal and vertical movement
  3132. particle.speed *= 0.98; // Slower deceleration
  3133. particle.x += Math.cos(particle.angle) * particle.speed;
  3134. particle.y += Math.sin(particle.angle) * particle.speed + particle.verticalSpeed;
  3135.  
  3136. // Update rotation
  3137. particle.shapeAngle += particle.rotationSpeed;
  3138. particle.life -= 10 / p.fpsFactor;
  3139. const lifeRatio = particle.life / particle.maxLife;
  3140. const opacity = Math.pow(lifeRatio, 0.5);
  3141. particle.size = particle.initialSize * Math.pow(lifeRatio, 0.5);
  3142. if (particle.life > 0) {
  3143. ctx.save();
  3144. ctx.translate(particle.x, particle.y);
  3145.  
  3146. // Draw irregular shape with stored radius variations
  3147. ctx.rotate(particle.shapeAngle);
  3148. ctx.beginPath();
  3149. for (let i = 0; i < particle.points; i++) {
  3150. const angle = i * 2 * Math.PI / particle.points - Math.PI / 2;
  3151. const radius = particle.size * particle.radiusVariations[i];
  3152. const x = Math.cos(angle) * radius;
  3153. const y = Math.sin(angle) * radius;
  3154. if (i === 0) {
  3155. ctx.moveTo(x, y);
  3156. } else {
  3157. ctx.lineTo(x, y);
  3158. }
  3159. }
  3160. ctx.closePath();
  3161. ctx.fillStyle = p.color.replace('0.2', opacity.toString());
  3162. ctx.fill();
  3163. ctx.restore();
  3164. }
  3165. });
  3166. }
  3167. },
  3168. "crescentSlash": {
  3169. x: p => p.x,
  3170. y: p => p.y,
  3171. size: p => 10 * p.size,
  3172. // Reduced base size
  3173. life: p => 1200 * p.size,
  3174. speed: p => (Math.random() * 10 + 4) * Math.sqrt(p.size) * 0.01,
  3175. angle: p => Math.random() * Math.PI * 2,
  3176. curveAmount: p => 5.3 * p.size * 2,
  3177. distance: p => 60 * p.size,
  3178. alpha: p => 1,
  3179. draw: (ctx, p) => {
  3180. if (!p.initialized) {
  3181. p.initialized = true;
  3182. p.trail = [];
  3183. p.fadeStartTime = 0;
  3184. p.isSlashing = true;
  3185. p.progress = 0;
  3186. p.speed = (Math.random() * 10 + 4) * Math.sqrt(p.size) * 0.01 * p.fpsFactor;
  3187. p.angle = Math.random() * Math.PI * 2;
  3188. p.curveAmount = 5.3 * p.size * 2;
  3189. p.distance = 60 * p.size;
  3190. p.totalPoints = Math.max(30, Math.min(100, Math.floor(p.distance / 2)));
  3191. }
  3192. p.life -= 3 / p.fpsFactor;
  3193. const alpha = Math.pow(Math.min(1, p.life / p.maxLife), 0.5);
  3194. if (p.life > 0) {
  3195. if (p.isSlashing) {
  3196. p.progress = Math.min(1, p.progress + p.speed);
  3197. p.trail = [];
  3198. const currentPoints = Math.floor(p.totalPoints * p.progress);
  3199. for (let i = 0; i < currentPoints; i++) {
  3200. const progress = i / p.totalPoints - 0.5;
  3201. const distance = progress * p.distance;
  3202.  
  3203. // Calculate base position
  3204. let x = Math.cos(p.angle) * distance;
  3205. let y = Math.sin(p.angle) * distance;
  3206.  
  3207. // Add crescent curve
  3208. const curveOffset = Math.sin((progress + 0.5) * Math.PI) * p.curveAmount;
  3209. x += Math.cos(p.angle + Math.PI / 2) * curveOffset;
  3210. y += Math.sin(p.angle + Math.PI / 2) * curveOffset;
  3211. let size = p.size * 1.2; // Reduced multiplier
  3212. if (progress < -0.2) {
  3213. size = p.size * (0.3 + (progress + 0.5) * 3); // Reduced size scaling
  3214. } else if (progress > 0.2) {
  3215. size = p.size * (1.2 - (progress - 0.2) * 3); // Reduced size scaling
  3216. }
  3217. p.trail.push({
  3218. x: x,
  3219. y: y,
  3220. size: size,
  3221. alpha: 1,
  3222. age: 0
  3223. });
  3224. }
  3225. if (p.progress >= 1) {
  3226. p.isSlashing = false;
  3227. p.fadeStartTime = Date.now();
  3228. }
  3229. }
  3230. ctx.save();
  3231. ctx.translate(p.x, p.y);
  3232. for (let i = 0; i < p.trail.length; i++) {
  3233. const point = p.trail[i];
  3234. let pointAlpha;
  3235. if (p.isSlashing) {
  3236. pointAlpha = Math.exp(-point.age / 150) * alpha;
  3237. point.age += 0.5;
  3238. } else {
  3239. const timeSinceFade = Date.now() - p.fadeStartTime;
  3240. const fadeProgress = timeSinceFade / 1000;
  3241. pointAlpha = Math.exp(-fadeProgress * 2) * alpha;
  3242. }
  3243. ctx.beginPath();
  3244. ctx.arc(point.x, point.y, point.size, 0, Math.PI * 2);
  3245. ctx.fillStyle = changeColorAlpha(p.color, pointAlpha);
  3246. ctx.fill();
  3247. if (p.isSlashing && point.age >= 200 || !p.isSlashing && Date.now() - p.fadeStartTime >= 1000) {
  3248. p.trail.splice(i, 1);
  3249. i--;
  3250. }
  3251. }
  3252. ctx.restore();
  3253. }
  3254. }
  3255. }
  3256. };
  3257.  
  3258. /*
  3259. 特效编写请查阅
  3260. https://docs.qq.com/doc/DS0JjVHp3S09td2NV
  3261. */
  3262.  
  3263. const projectileEffectsMap = {
  3264. 'fireball': {
  3265. speedFactor: 1,
  3266. trailLength: 35,
  3267. shake: true,
  3268. onHit: {
  3269. "smoke": size => Math.min(Math.ceil(size * 4), 8),
  3270. "ember": size => Math.min(Math.ceil(size * 10), 40),
  3271. "shockwave": size => Math.min(Math.ceil(size), 4),
  3272. "smallParticle": size => Math.min(Math.ceil(size * 4), 10)
  3273. },
  3274. onCrit: {
  3275. "star": size => Math.min(Math.ceil(size * 10), 20)
  3276. },
  3277. draw: (ctx, p) => {
  3278. ctx.beginPath();
  3279. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3280. ctx.fillStyle = p.color;
  3281. ctx.fill();
  3282. },
  3283. glow: (ctx, p) => {
  3284. const gradient = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 2);
  3285. gradient.addColorStop(0, `${p.color}`);
  3286. gradient.addColorStop(1, `${p.color}`);
  3287. ctx.fillStyle = gradient;
  3288. },
  3289. trail: (ctx, p, i) => {
  3290. const alpha = Math.min(i / p.totalLength, 1);
  3291. ctx.beginPath();
  3292. ctx.arc(p.x, p.y, p.size * alpha, 0, Math.PI * 2);
  3293. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  3294. ctx.fill();
  3295. }
  3296. },
  3297. 'nature': {
  3298. speedFactor: 1,
  3299. gravity: 0.1,
  3300. trailLength: 60,
  3301. shake: true,
  3302. onHit: {
  3303. "leaf": size => Math.min(Math.ceil(size * 30), 32)
  3304. },
  3305. draw: (ctx, p) => {
  3306. const size = p.size * 3;
  3307. p.rotation = Math.atan2(p.velocity.y, p.velocity.x) - Math.PI / 2;
  3308. ctx.save();
  3309. ctx.translate(p.x, p.y);
  3310. ctx.rotate(p.rotation);
  3311. ctx.scale(p.scale, 1);
  3312. ctx.beginPath();
  3313. ctx.moveTo(0, -size);
  3314. ctx.bezierCurveTo(size / 2, -size / 2, size / 2, 0, 0, size);
  3315. ctx.bezierCurveTo(-size / 2, 0, -size / 2, -size / 2, 0, -size);
  3316. ctx.fillStyle = p.color;
  3317. ctx.fill();
  3318. ctx.restore();
  3319. },
  3320. trail: (ctx, p, i) => {
  3321. const alpha = Math.min(i / p.totalLength, 1);
  3322. p.x = p.x + (Math.random() - 0.5) * 5;
  3323. p.y = p.y - (Math.random() - 0.5) * 1 + 0.02;
  3324. ctx.beginPath();
  3325. const lineWidth = p.size * Math.sqrt(alpha);
  3326. ctx.strokeStyle = `${changeColorAlpha(p.color, alpha)}`;
  3327. ctx.lineWidth = lineWidth;
  3328. ctx.moveTo(p.x, p.y);
  3329. ctx.lineTo(p.x + (Math.random() - 0.5) * 20, p.y + (Math.random() - 0.5) * 20);
  3330. ctx.stroke();
  3331. ctx.fill();
  3332. }
  3333. },
  3334. 'slash': {
  3335. speedFactor: 2,
  3336. gravity: -0.2,
  3337. trailLength: 30,
  3338. shake: true,
  3339. onHit: {
  3340. "crescentSlash": size => Math.min(Math.ceil(size * 4), 8),
  3341. "slashParticle": size => Math.min(Math.ceil(size * 8), 20)
  3342. }
  3343. // draw: (ctx, p) => {
  3344. // ctx.beginPath();
  3345. // ctx.moveTo(p.x, p.y + p.size * 2);
  3346. // ctx.lineTo(p.x - p.size * 2, p.y - p.size * 2);
  3347. // ctx.lineTo(p.x + p.size * 2, p.y - p.size * 2);
  3348. // ctx.closePath();
  3349. // ctx.fillStyle = p.color;
  3350. // ctx.fill();
  3351. // }
  3352. },
  3353. 'water': {
  3354. speedFactor: 1.2,
  3355. trailLength: 60,
  3356. shake: true,
  3357. onHit: {
  3358. "waterRipple": size => Math.min(Math.ceil(size * 8), 12),
  3359. "waterSplash": size => Math.min(Math.ceil(size * 8), 20)
  3360. },
  3361. draw: (ctx, p) => {
  3362. ctx.beginPath();
  3363. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3364. ctx.fillStyle = p.color;
  3365. ctx.fill();
  3366. },
  3367. trail: (ctx, p, i) => {
  3368. const alpha = Math.min(i / p.totalLength, 1);
  3369. p.x = p.x + (Math.random() - 0.5) * 5;
  3370. p.y = p.y - (Math.random() - 0.5) * 1;
  3371. ctx.beginPath();
  3372. ctx.arc(p.x, p.y, p.size * alpha, 0, Math.PI * 2);
  3373. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  3374. ctx.fill();
  3375. }
  3376. },
  3377. 'heal': {
  3378. trailLength: 60,
  3379. shake: false,
  3380. color: 'rgba(93, 212, 93, 0.8)',
  3381. onHit: {
  3382. "holyCross": size => Math.min(Math.ceil(size * 12), 10)
  3383. },
  3384. draw: (ctx, p) => {
  3385. ctx.beginPath();
  3386. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3387. ctx.fillStyle = p.color;
  3388. ctx.fill();
  3389. }
  3390. },
  3391. 'range': {
  3392. speedFactor: 1.5,
  3393. gravity: 0.15,
  3394. trailLength: 30,
  3395. shake: true,
  3396. onHit: {
  3397. "shockwave": size => Math.min(Math.ceil(size), 4),
  3398. "slashParticle": size => Math.min(Math.ceil(size * 8), 20)
  3399. },
  3400. draw: (ctx, p) => {
  3401. const length = p.size * 6.65;
  3402. const width = p.size * 0.47;
  3403. const arrowHeadLength = p.size * 1.33;
  3404. const arrowHeadWidth = p.size * 0.80;
  3405. const fletchingLength = p.size * 2.13;
  3406. const fletchingWidth = p.size * 1.33;
  3407. ctx.save();
  3408. ctx.translate(p.x, p.y);
  3409. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  3410.  
  3411. // Draw arrow shaft
  3412. ctx.beginPath();
  3413. ctx.moveTo(-length / 2, -width / 2);
  3414. ctx.lineTo(length / 2 - arrowHeadLength, -width / 2);
  3415. ctx.lineTo(length / 2 - arrowHeadLength, width / 2);
  3416. ctx.lineTo(-length / 2, width / 2);
  3417. ctx.closePath();
  3418. ctx.fillStyle = p.color;
  3419. ctx.fill();
  3420.  
  3421. // Draw arrow head
  3422. ctx.beginPath();
  3423. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  3424. ctx.lineTo(length / 2, 0);
  3425. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  3426. ctx.closePath();
  3427. ctx.fillStyle = p.color;
  3428. ctx.fill();
  3429.  
  3430. // Draw fletchings
  3431. ctx.beginPath();
  3432. ctx.moveTo(-length / 2, -width / 2);
  3433. ctx.lineTo(-length / 2 - fletchingLength, -fletchingWidth / 2);
  3434. ctx.lineTo(-length / 2 - fletchingLength * 0.5, 0);
  3435. ctx.lineTo(-length / 2 - fletchingLength, fletchingWidth / 2);
  3436. ctx.lineTo(-length / 2, width / 2);
  3437. ctx.closePath();
  3438. ctx.fillStyle = p.color;
  3439. ctx.fill();
  3440. ctx.restore();
  3441. },
  3442. trail: (ctx, p, i) => {
  3443. // Only show trail after the arrow has traveled some distance
  3444. const startDelay = 5; // Number of frames to wait before showing trail
  3445. if (i < startDelay) return;
  3446. const trailLength = p.size * 20;
  3447. const trailWidth = p.size * 0.27;
  3448. ctx.save();
  3449. ctx.translate(p.x, p.y);
  3450. ctx.rotate(Math.atan2(p.vY, p.vX));
  3451.  
  3452. // Draw simple line trail behind the arrow
  3453. ctx.beginPath();
  3454. ctx.moveTo(-trailLength / 2, -trailWidth / 2);
  3455. ctx.lineTo(0, -trailWidth / 2); // Only draw up to the arrow's position
  3456. ctx.lineTo(0, trailWidth / 2);
  3457. ctx.lineTo(-trailLength / 2, trailWidth / 2);
  3458. ctx.closePath();
  3459. ctx.fillStyle = 'rgba(255, 255, 255, 0.1)'; // Fixed low opacity white
  3460. ctx.fill();
  3461. ctx.restore();
  3462. }
  3463. },
  3464. 'selfHeal': {
  3465. speedFactor: 10,
  3466. trailLength: 0,
  3467. gravity: 0,
  3468. shake: false,
  3469. color: 'rgba(93, 212, 93, 0.5)',
  3470. onHit: {
  3471. "holyCross": size => Math.min(Math.ceil(size * 12), 10)
  3472. },
  3473. draw: (ctx, p) => {}
  3474. },
  3475. 'selfManaRegen': {
  3476. speedFactor: 10,
  3477. trailLength: 0,
  3478. gravity: 0,
  3479. shake: false,
  3480. color: 'rgba(68, 120, 241, 0.8)',
  3481. onHit: {
  3482. "holyCross": size => Math.min(Math.ceil(size * 12), 10)
  3483. },
  3484. draw: (ctx, p) => {}
  3485. },
  3486. 'debug': {
  3487. speedFactor: 2,
  3488. trailLength: 3,
  3489. shake: true,
  3490. onHit: {
  3491. "magnet": size => Math.min(Math.ceil(size * 3), 6)
  3492. },
  3493. draw: (ctx, p) => {
  3494. ctx.beginPath();
  3495. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3496. ctx.fillStyle = p.color;
  3497. ctx.fill();
  3498. }
  3499. },
  3500. 'lavaPlume': {
  3501. speedFactor: 0.8,
  3502. trailLength: 40,
  3503. gravity: 0.1,
  3504. shake: true,
  3505. onHit: {
  3506. "lava": size => Math.min(Math.ceil(size * 20), 20),
  3507. "smallParticle": size => Math.min(Math.ceil(size * 10), 60)
  3508. },
  3509. draw: (ctx, p) => {
  3510. // Draw main projectile
  3511. ctx.beginPath();
  3512. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3513. ctx.fillStyle = p.color;
  3514. ctx.fill();
  3515.  
  3516. // Create inner glow gradient
  3517. const innerGlow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 1.5);
  3518. innerGlow.addColorStop(0, 'rgba(255, 255, 255, 0.8)');
  3519. innerGlow.addColorStop(0.5, p.color);
  3520. innerGlow.addColorStop(1, 'rgba(255, 0, 0, 0)');
  3521. ctx.beginPath();
  3522. ctx.arc(p.x, p.y, p.size * 1.5, 0, Math.PI * 2);
  3523. ctx.fillStyle = innerGlow;
  3524. ctx.fill();
  3525. },
  3526. glow: (ctx, p) => {
  3527. // Create outer glow gradient
  3528. const outerGlow = ctx.createRadialGradient(p.x, p.y, p.size * 1.5, p.x, p.y, p.size * 4);
  3529. outerGlow.addColorStop(0, p.color);
  3530. // outerGlow.addColorStop(0.5, 'rgba(250, 178, 24, 0.2)');
  3531. outerGlow.addColorStop(1, 'rgba(255, 50, 0, 0)');
  3532. ctx.beginPath();
  3533. ctx.arc(p.x, p.y, p.size * 4, 0, Math.PI * 2);
  3534. ctx.fillStyle = outerGlow;
  3535. ctx.fill();
  3536.  
  3537. // Add pulsing effect
  3538. const pulseSize = p.size * (3 + Math.sin(Date.now() * 0.01) * 0.5);
  3539. const pulseGlow = ctx.createRadialGradient(p.x, p.y, p.size * 2, p.x, p.y, pulseSize);
  3540. pulseGlow.addColorStop(0, changeColorAlpha(p.color, 0.1));
  3541. pulseGlow.addColorStop(1, 'rgba(255, 100, 0, 0)');
  3542. ctx.beginPath();
  3543. ctx.arc(p.x, p.y, pulseSize, 0, Math.PI * 2);
  3544. ctx.fillStyle = pulseGlow;
  3545. ctx.fill();
  3546. },
  3547. trail: (ctx, p, i) => {
  3548. const alpha = Math.min(i / p.totalLength, 1);
  3549. const trailSize = p.size * alpha;
  3550.  
  3551. // Create glowing trail gradient
  3552. // const trailGlow = ctx.createRadialGradient(
  3553. // p.x, p.y, 0,
  3554. // p.x, p.y, trailSize * 2
  3555. // );
  3556. // trailGlow.addColorStop(0, changeColorAlpha(p.color, alpha));
  3557. // trailGlow.addColorStop(1, changeColorAlpha(p.color, 0));
  3558.  
  3559. ctx.beginPath();
  3560. ctx.arc(p.x, p.y, trailSize * 2, 0, Math.PI * 2);
  3561. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  3562. ctx.fill();
  3563. }
  3564. },
  3565. 'iceBlast': {
  3566. speedFactor: 1.3,
  3567. trailLength: 35,
  3568. shake: true,
  3569. onHit: {
  3570. "ice": size => Math.min(Math.ceil(size * 30), 40)
  3571. },
  3572. draw: (ctx, p) => {
  3573. const length = p.size * 6.65;
  3574. const arrowHeadLength = p.size * 3;
  3575. const arrowHeadWidth = p.size * 2;
  3576.  
  3577. // Draw main projectile
  3578. ctx.save();
  3579. ctx.translate(p.x, p.y);
  3580. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  3581.  
  3582. // Draw arrow head
  3583. ctx.beginPath();
  3584. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  3585. ctx.lineTo(length / 2, 0);
  3586. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  3587. ctx.closePath();
  3588. ctx.fillStyle = p.color;
  3589. ctx.fill();
  3590. ctx.restore();
  3591. },
  3592. glow: (ctx, p) => {
  3593. // Create outer glow gradient
  3594. const outerGlow = ctx.createRadialGradient(p.x, p.y, p.size * 1.5, p.x, p.y, p.size * 4);
  3595. outerGlow.addColorStop(0, 'rgba(200, 230, 255, 0.3)');
  3596. outerGlow.addColorStop(0.5, 'rgba(150, 200, 255, 0.2)');
  3597. outerGlow.addColorStop(1, 'rgba(100, 150, 255, 0)');
  3598. const length = p.size * 6.65;
  3599. const arrowHeadLength = p.size * 3;
  3600. const arrowHeadWidth = p.size * 2;
  3601. ctx.beginPath();
  3602. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  3603. ctx.lineTo(length / 2, 0);
  3604. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  3605. ctx.closePath();
  3606. ctx.fillStyle = p.color;
  3607. ctx.fill();
  3608. },
  3609. trail: (ctx, p, i) => {
  3610. const alpha = Math.min(i / p.totalLength, 1);
  3611. const trailSize = p.size * (1 + Math.sin(Date.now() * 0.01) * 0.2);
  3612.  
  3613. // Create glowing trail gradient
  3614. const trailGlow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, trailSize * 2);
  3615. trailGlow.addColorStop(0, changeColorAlpha(p.color, alpha));
  3616. trailGlow.addColorStop(1, `rgba(150, 200, 255, 0)`);
  3617. ctx.beginPath();
  3618. ctx.arc(p.x, p.y, trailSize, 0, Math.PI * 2);
  3619. ctx.fillStyle = trailGlow;
  3620. ctx.fill();
  3621. }
  3622. },
  3623. 'poisonDust': {
  3624. speedFactor: 1,
  3625. trailLength: 35,
  3626. shake: true,
  3627. onHit: {
  3628. "poison": size => Math.min(Math.ceil(size * 8), 12)
  3629. },
  3630. draw: (ctx, p) => {
  3631. // Draw main projectile
  3632. ctx.beginPath();
  3633. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3634. ctx.fillStyle = p.color;
  3635. ctx.fill();
  3636.  
  3637. // Create inner glow gradient
  3638. const innerGlow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 1.5);
  3639. innerGlow.addColorStop(0, 'rgba(255, 255, 255, 0.8)');
  3640. innerGlow.addColorStop(0.5, changeColorAlpha(p.color, 0.5));
  3641. innerGlow.addColorStop(1, 'rgba(50, 200, 50, 0)');
  3642. ctx.beginPath();
  3643. ctx.arc(p.x, p.y, p.size * 1.5, 0, Math.PI * 2);
  3644. ctx.fillStyle = innerGlow;
  3645. ctx.fill();
  3646. },
  3647. glow: (ctx, p) => {
  3648. // Create outer glow gradient
  3649. const outerGlow = ctx.createRadialGradient(p.x, p.y, p.size * 1.5, p.x, p.y, p.size * 4);
  3650. outerGlow.addColorStop(0, changeColorAlpha(p.color, 0.5));
  3651. // outerGlow.addColorStop(0.5, 'rgba(50, 200, 50, 0.2)');
  3652. outerGlow.addColorStop(1, 'rgba(0, 150, 0, 0)');
  3653. ctx.beginPath();
  3654. ctx.arc(p.x, p.y, p.size * 4, 0, Math.PI * 2);
  3655. ctx.fillStyle = outerGlow;
  3656. ctx.fill();
  3657. },
  3658. trail: (ctx, p, i) => {
  3659. const alpha = Math.min(i / p.totalLength, 1);
  3660. p.x = p.x + (Math.random() - 0.5) * 5;
  3661. p.y = p.y - (Math.random() - 0.5) * 1 + 0.02;
  3662. ctx.beginPath();
  3663. const lineWidth = p.size * Math.sqrt(alpha);
  3664. ctx.strokeStyle = `${changeColorAlpha(p.color, alpha)}`;
  3665. ctx.lineWidth = lineWidth;
  3666. ctx.moveTo(p.x, p.y);
  3667. ctx.lineTo(p.x + (Math.random() - 0.5) * 20, p.y + (Math.random() - 0.5) * 20);
  3668. ctx.stroke();
  3669. ctx.fill();
  3670. }
  3671. },
  3672. 'thrust': {
  3673. speedFactor: 3,
  3674. gravity: -0.001,
  3675. trailLength: 0,
  3676. shake: true,
  3677. onHit: {
  3678. "smallParticle": size => Math.min(Math.ceil(size * 4), 10),
  3679. "pierce": size => Math.min(Math.ceil(size * 4), 6),
  3680. "shockwave": size => Math.min(Math.ceil(size * 2), 6)
  3681. },
  3682. draw: (ctx, p) => {
  3683. const shaftLength = p.size * 12; // Longer shaft
  3684. const shaftWidth = p.size * 0.8; // Thicker shaft
  3685. const tipLength = p.size * 3; // Length of the pointed tip
  3686. const tipWidth = p.size * 1.2; // Width at the base of the tip
  3687.  
  3688. ctx.save();
  3689. ctx.translate(p.x, p.y);
  3690. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  3691.  
  3692. // Draw shaft
  3693. ctx.beginPath();
  3694. ctx.moveTo(-shaftLength / 2, -shaftWidth / 2);
  3695. ctx.lineTo(shaftLength / 2 - tipLength, -shaftWidth / 2);
  3696. ctx.lineTo(shaftLength / 2 - tipLength, shaftWidth / 2);
  3697. ctx.lineTo(-shaftLength / 2, shaftWidth / 2);
  3698. ctx.closePath();
  3699. ctx.fillStyle = p.color;
  3700. ctx.fill();
  3701.  
  3702. // Draw tip
  3703. ctx.beginPath();
  3704. ctx.moveTo(shaftLength / 2 - tipLength, -tipWidth / 2);
  3705. ctx.lineTo(shaftLength / 2, 0);
  3706. ctx.lineTo(shaftLength / 2 - tipLength, tipWidth / 2);
  3707. ctx.closePath();
  3708. ctx.fillStyle = p.color;
  3709. ctx.fill();
  3710.  
  3711. // Add highlight to shaft
  3712. ctx.beginPath();
  3713. ctx.moveTo(-shaftLength / 2, -shaftWidth / 2);
  3714. ctx.lineTo(shaftLength / 2 - tipLength, -shaftWidth / 2);
  3715. ctx.lineTo(shaftLength / 2 - tipLength, 0);
  3716. ctx.lineTo(-shaftLength / 2, 0);
  3717. ctx.closePath();
  3718. ctx.fillStyle = 'rgba(255, 255, 255, 0.4)';
  3719. ctx.fill();
  3720.  
  3721. // Add highlight to tip
  3722. ctx.beginPath();
  3723. ctx.moveTo(shaftLength / 2 - tipLength, -tipWidth / 2);
  3724. ctx.lineTo(shaftLength / 2, 0);
  3725. ctx.lineTo(shaftLength / 2 - tipLength, 0);
  3726. ctx.closePath();
  3727. ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
  3728. ctx.fill();
  3729. ctx.restore();
  3730. }
  3731. },
  3732. 'fireTornado': {
  3733. speedFactor: 1,
  3734. trailLength: 40,
  3735. shake: true,
  3736. onHit: {
  3737. "smoke": size => Math.min(Math.ceil(size * 10), 10),
  3738. "tornado": size => Math.min(Math.ceil(size * 5), 8)
  3739. },
  3740. draw: (ctx, p) => {
  3741. // Draw main projectile
  3742. ctx.beginPath();
  3743. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3744. ctx.fillStyle = p.color;
  3745. ctx.fill();
  3746.  
  3747. // Create inner glow gradient
  3748. const innerGlow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 1.5);
  3749. innerGlow.addColorStop(0, 'rgba(255, 255, 255, 0.8)');
  3750. innerGlow.addColorStop(0.5, p.color);
  3751. innerGlow.addColorStop(1, 'rgba(255, 0, 0, 0)');
  3752. ctx.beginPath();
  3753. ctx.arc(p.x, p.y, p.size * 1.5, 0, Math.PI * 2);
  3754. ctx.fillStyle = innerGlow;
  3755. ctx.fill();
  3756. },
  3757. glow: (ctx, p) => {
  3758. // Create outer glow gradient
  3759. const outerGlow = ctx.createRadialGradient(p.x, p.y, p.size * 1.5, p.x, p.y, p.size * 3);
  3760. outerGlow.addColorStop(0, p.color);
  3761. // outerGlow.addColorStop(0.5, 'rgba(250, 178, 24, 0.2)');
  3762. outerGlow.addColorStop(1, 'rgba(255, 50, 0, 0)');
  3763. ctx.beginPath();
  3764. ctx.arc(p.x, p.y, p.size * 4, 0, Math.PI * 2);
  3765. ctx.fillStyle = outerGlow;
  3766. ctx.fill();
  3767.  
  3768. // Add pulsing effect
  3769. const pulseSize = p.size * (3 + Math.sin(Date.now() * 0.01) * 0.5);
  3770. const pulseGlow = ctx.createRadialGradient(p.x, p.y, p.size * 2, p.x, p.y, pulseSize);
  3771. pulseGlow.addColorStop(0, changeColorAlpha(p.color, 0.1));
  3772. pulseGlow.addColorStop(1, 'rgba(255, 100, 0, 0)');
  3773. ctx.beginPath();
  3774. ctx.arc(p.x, p.y, pulseSize, 0, Math.PI * 2);
  3775. ctx.fillStyle = pulseGlow;
  3776. ctx.fill();
  3777. },
  3778. trail: (ctx, p, i) => {
  3779. const alpha = Math.min(i / p.totalLength, 1);
  3780. const trailSize = p.size * alpha;
  3781.  
  3782. // Create glowing trail gradient
  3783. // const trailGlow = ctx.createRadialGradient(
  3784. // p.x, p.y, 0,
  3785. // p.x, p.y, trailSize * 2
  3786. // );
  3787. // trailGlow.addColorStop(0, changeColorAlpha(p.color, alpha));
  3788. // trailGlow.addColorStop(1, changeColorAlpha(p.color, 0));
  3789.  
  3790. ctx.beginPath();
  3791. ctx.arc(p.x, p.y, trailSize * 2, 0, Math.PI * 2);
  3792. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  3793. ctx.fill();
  3794. }
  3795. },
  3796. 'blunt': {
  3797. speedFactor: 3,
  3798. gravity: -0.1,
  3799. trailLength: 20,
  3800. shake: true,
  3801. onHit: {
  3802. "shatter": size => Math.min(Math.ceil(size * 5), 10),
  3803. "shockwave": size => Math.min(Math.ceil(size * 2), 6)
  3804. },
  3805. trail: (ctx, p, i) => {
  3806. const alpha = Math.min(i / p.totalLength, 1);
  3807. const trailSize = p.size * alpha;
  3808.  
  3809. // Create glowing trail gradient
  3810. // const trailGlow = ctx.createRadialGradient(
  3811. // p.x, p.y, 0,
  3812. // p.x, p.y, trailSize * 2
  3813. // );
  3814. // trailGlow.addColorStop(0, changeColorAlpha(p.color, alpha));
  3815. // trailGlow.addColorStop(1, changeColorAlpha(p.color, 0));
  3816.  
  3817. ctx.beginPath();
  3818. ctx.arc(p.x, p.y, trailSize * 2, 0, Math.PI * 2);
  3819. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  3820. ctx.fill();
  3821. }
  3822. },
  3823. 'magneteer': {
  3824. speedFactor: 0.8,
  3825. trailLength: 40,
  3826. gravity: -0.001,
  3827. shake: true,
  3828. onHit: {
  3829. "magnet": size => Math.min(Math.ceil(size * 2), 6),
  3830. "shockwave": size => Math.min(Math.ceil(size), 2)
  3831. },
  3832. draw: (ctx, p) => {
  3833. ctx.save();
  3834. ctx.translate(p.x, p.y);
  3835. // Combine direction and continuous spin
  3836. const direction = Math.atan2(p.velocity.y, p.velocity.x);
  3837. const spin = p.life * 0.05 % (Math.PI * 2); // Slower continuous spin
  3838. ctx.rotate(direction + spin);
  3839.  
  3840. // Use the magnet shape from shape.js
  3841. shapes.magnet(ctx, {
  3842. x: 0,
  3843. y: 0,
  3844. size: p.size * 2,
  3845. angle: 0
  3846. });
  3847. ctx.restore();
  3848. },
  3849. trail: (ctx, p, i) => {
  3850. const alpha = Math.min(i / p.totalLength, 1);
  3851. p.x = p.x + (Math.random() - 0.5) * 5;
  3852. p.y = p.y - (Math.random() - 0.5) * 1 + 0.02;
  3853. ctx.beginPath();
  3854. const lineWidth = p.size * Math.sqrt(alpha);
  3855. ctx.strokeStyle = `${changeColorAlpha(p.color, alpha)}`;
  3856. ctx.lineWidth = lineWidth;
  3857. ctx.moveTo(p.x, p.y);
  3858. ctx.lineTo(p.x + (Math.random() - 0.5) * 20, p.y + (Math.random() - 0.5) * 20);
  3859. ctx.stroke();
  3860. ctx.fill();
  3861. }
  3862. }
  3863. };
  3864.  
  3865. const abilityEffectsMap = {
  3866. 'autoAttack': 'slash',
  3867. 'default': 'fireball',
  3868. 'heal': 'heal',
  3869. '/abilities/fireball': "fireball",
  3870. '/abilities/firestorm': "fireTornado",
  3871. '/abilities/flame_blast': "lavaPlume",
  3872. '/abilities/smoke_burst': "fireball",
  3873. '/abilities/aqua_arrow': "water",
  3874. '/abilities/frost_surge': "iceBlast",
  3875. '/abilities/ice_spear': "iceBlast",
  3876. '/abilities/mana_spring': "water",
  3877. '/abilities/water_strike': "water",
  3878. '/abilities/entangle': "nature",
  3879. '/abilities/natures_veil': "nature",
  3880. '/abilities/toxic_pollen': "poisonDust",
  3881. '/abilities/penetrating_shot': "range",
  3882. '/abilities/pestilent_shot': "range",
  3883. '/abilities/steady_shot': "range",
  3884. '/abilities/quick_shot': "range",
  3885. '/abilities/rain_of_arrows': "range",
  3886. '/abilities/silencing_shot': "range",
  3887. '/abilities/crippling_slash': "slash",
  3888. '/abilities/penetrating_strike': "slash",
  3889. '/abilities/impale': "thrust",
  3890. '/abilities/maim': "slash",
  3891. '/abilities/poke': "thrust",
  3892. '/abilities/puncture': "thrust",
  3893. '/abilities/scratch': "slash",
  3894. '/abilities/smack': "blunt",
  3895. '/abilities/sweep': "blunt",
  3896. '/abilities/stunning_blow': "blunt",
  3897. '/abilities/fracturing_impact': "blunt",
  3898. '/abilities/shield_bash': "blunt"
  3899. };
  3900.  
  3901. let activeEffects = [];
  3902. function addEffect({
  3903. effects,
  3904. active = true,
  3905. lifespan = 120,
  3906. color = "rgba(255, 255, 255, 0.8)",
  3907. otherInfo = {},
  3908. isFpsOptimized = false
  3909. }) {
  3910. activeEffects.push({
  3911. effects,
  3912. active,
  3913. life: 0,
  3914. lifespan,
  3915. color,
  3916. otherInfo,
  3917. isFpsOptimized
  3918. });
  3919. }
  3920. function clearEffects() {
  3921. activeEffects.splice(0, activeEffects.length);
  3922. }
  3923.  
  3924. function applyShakeEffect(element, intensity = 1, duration = 500) {
  3925. if (!element) return;
  3926.  
  3927. // Store the element's original position/transform
  3928. const originalTransform = element.style.transform || '';
  3929. const originalTransition = element.style.transition || '';
  3930. intensity *= settingsMap.shakeEffectScale.value || 1;
  3931.  
  3932. // Scale intensity based on size/damage
  3933. const scaledIntensity = Math.min(10, intensity);
  3934.  
  3935. // Apply CSS animation
  3936. element.style.transition = 'transform 50ms ease-in-out';
  3937. let shakeCount = 0;
  3938. const maxShakes = Math.ceil(intensity);
  3939. const shakeInterval = 50;
  3940. const interval = setInterval(() => {
  3941. if (shakeCount >= maxShakes) {
  3942. // Ensure element returns to original position
  3943. clearInterval(interval);
  3944. element.style.transform = originalTransform;
  3945. element.style.transition = originalTransition;
  3946. return;
  3947. }
  3948.  
  3949. // Random offset for shaking effect
  3950. const xOffset = (Math.random() - 0.5) * 2 * scaledIntensity;
  3951. const yOffset = (Math.random() - 0.5) * 2 * scaledIntensity;
  3952. element.style.transform = `${originalTransform} translate(${xOffset}px, ${yOffset}px)`;
  3953. shakeCount++;
  3954. }, shakeInterval);
  3955.  
  3956. // Additional safeguard: ensure element returns to original position after max duration
  3957. setTimeout(() => {
  3958. clearInterval(interval);
  3959. element.style.transform = 'translate(0, 0)';
  3960. element.style.transition = originalTransition;
  3961. }, shakeInterval * (maxShakes + 1)); // Slightly longer than maxShakes * interval time
  3962. }
  3963. function addDamageHPBar(element, damage) {
  3964. const hpBarContainer = element.querySelector(".HitpointsBar_hitpointsBar__2vIqC");
  3965. const hpBarFront = hpBarContainer.querySelector(".HitpointsBar_currentHp__5exLr");
  3966. // hpBarFront.style.zIndex = "1";
  3967. const hpBarValue = hpBarContainer.querySelector(".HitpointsBar_hpValue__xNp7m");
  3968. // hpBarValue.style.zIndex = "2";
  3969. const hpStat = hpBarValue.innerHTML.split("/");
  3970. const currentHp = parseInt(hpStat[0]);
  3971. const maxHp = parseInt(hpStat[1]);
  3972.  
  3973. // Insert a HpBar behind and set the color to red
  3974. const hpBarBack = document.createElement("div");
  3975. hpBarBack.className = "HitpointsBar_currentHp__5exLr HitTracker_hpDrop";
  3976. hpBarBack.style.background = "var(--color-warning)";
  3977. hpBarBack.style.position = "absolute";
  3978. hpBarBack.style.top = "0px";
  3979. hpBarBack.style.left = "0px";
  3980. // hpBarBack.style.zIndex = "1"; // Ensure the back bar is below the front bar
  3981. hpBarBack.style.width = `${hpBarFront.offsetWidth}px`;
  3982. hpBarBack.style.height = `${hpBarFront.offsetHeight}px`;
  3983. hpBarBack.style.transformOrigin = "left center";
  3984. hpBarBack.style.transform = `scaleX(${(currentHp + damage) / maxHp})`;
  3985. // add animation to drop down
  3986. hpBarBack.style.transition = "transform 0.5s ease-in-out";
  3987. hpBarFront.parentNode.insertBefore(hpBarBack, hpBarFront); // Insert the back bar before the front bar
  3988.  
  3989. const dropDelay = Math.ceil(settingsMap.damageHpBarDropDelay.value || 300);
  3990. setTimeout(() => {
  3991. hpBarBack.style.transform = `scaleX(0)`;
  3992. }, dropDelay);
  3993. setTimeout(() => {
  3994. hpBarBack.remove();
  3995. }, dropDelay + 500);
  3996. }
  3997. function resetAllMonsterSvg() {
  3998. const monsterArea = document.querySelector(".BattlePanel_monstersArea__2dzrY");
  3999. if (monsterArea) {
  4000. const monsterSvgs = monsterArea.querySelectorAll(".Icon_icon__2LtL_");
  4001. monsterSvgs.forEach(monsterSvg => {
  4002. monsterSvg.style.transition = "none";
  4003. monsterSvg.style.transform = "rotate(0deg)";
  4004. monsterSvg.style.opacity = "1";
  4005. });
  4006. }
  4007. }
  4008. const deathEffect = {
  4009. default: element => {
  4010. const monsterSvg = element.querySelector(".Icon_icon__2LtL_");
  4011. monsterSvg.style.transition = "transform 0.1s ease-in-out";
  4012. monsterSvg.style.transformOrigin = "bottom center";
  4013. monsterSvg.style.transform = "rotate(15deg)";
  4014. setTimeout(() => {
  4015. monsterSvg.style.transition = "transform 0.5s ease-in-out, opacity 0.5s ease-in-out";
  4016. monsterSvg.style.transform = "rotate(-180deg)";
  4017. monsterSvg.style.opacity = "0";
  4018. }, 300);
  4019. // fade out
  4020. // setTimeout(() => {
  4021. // monsterSvg.style.transition = "opacity 0.5s ease-in-out";
  4022. // }, 800);
  4023. },
  4024. minecraftStyle: element => {
  4025. const monsterSvg = element.querySelector(".Icon_icon__2LtL_");
  4026.  
  4027. // First get dimensions and viewBox of original SVG
  4028. const svgRect = monsterSvg.getBoundingClientRect();
  4029. const viewBox = monsterSvg.getAttribute('viewBox') || '0 0 24 24'; // 默认值,以防未设置
  4030.  
  4031. // Get SVG content before changing anything else
  4032. const svgContent = monsterSvg.innerHTML;
  4033.  
  4034. // Create container that will match exact position of original SVG
  4035. const overlayContainer = document.createElement('div');
  4036. overlayContainer.style.position = 'absolute';
  4037. overlayContainer.style.top = '0';
  4038. overlayContainer.style.left = '0';
  4039. overlayContainer.style.width = '100%';
  4040. overlayContainer.style.height = '100%';
  4041. overlayContainer.style.pointerEvents = 'none';
  4042. // overlayContainer.style.zIndex = '5';
  4043.  
  4044. // Match the exact positioning and sizing of the original SVG
  4045. const parentBounds = element.getBoundingClientRect();
  4046. const relativeTop = (svgRect.top - parentBounds.top) / parentBounds.height * 100;
  4047. const relativeLeft = (svgRect.left - parentBounds.left) / parentBounds.width * 100;
  4048. const relativeWidth = svgRect.width / parentBounds.width * 100;
  4049. const relativeHeight = svgRect.height / parentBounds.height * 100;
  4050.  
  4051. // Create SVG overlay with the same dimensions and position
  4052. const svgOverlay = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  4053. svgOverlay.setAttribute('width', '100%');
  4054. svgOverlay.setAttribute('height', '100%');
  4055. svgOverlay.setAttribute('viewBox', viewBox);
  4056. svgOverlay.style.position = 'absolute';
  4057. svgOverlay.style.top = `${relativeTop}%`;
  4058. svgOverlay.style.left = `${relativeLeft}%`;
  4059. svgOverlay.style.width = `${relativeWidth}%`;
  4060. svgOverlay.style.height = `${relativeHeight}%`;
  4061. setTimeout(() => {
  4062. // Apply rotation to original SVG
  4063. monsterSvg.style.transition = "transform 0.1s ease-in-out";
  4064. monsterSvg.style.transformOrigin = "center left";
  4065. monsterSvg.style.transform = "rotate(15deg)";
  4066. // Apply same transform as original to maintain alignment
  4067. svgOverlay.style.transition = "transform 0.1s ease-in-out";
  4068. svgOverlay.style.transform = "rotate(15deg)";
  4069. svgOverlay.style.transformOrigin = "center left";
  4070. }, 300);
  4071.  
  4072. // Create defs for the mask
  4073. const defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4074. const mask = document.createElementNS('http://www.w3.org/2000/svg', 'mask');
  4075. mask.setAttribute('id', `monster-mask-${Date.now()}`); // Unique ID
  4076.  
  4077. // Clone the original SVG content for the mask
  4078. const maskContent = document.createElementNS('http://www.w3.org/2000/svg', 'g');
  4079. maskContent.innerHTML = svgContent;
  4080.  
  4081. // Set all elements in mask to white (opaque parts of mask)
  4082. const maskElements = maskContent.querySelectorAll('*');
  4083. maskElements.forEach(el => {
  4084. if (el.tagName === 'path' || el.tagName === 'circle' || el.tagName === 'rect' || el.tagName === 'polygon' || el.tagName === 'polyline') {
  4085. el.setAttribute('fill', 'white');
  4086. el.setAttribute('stroke', 'white');
  4087. }
  4088. });
  4089. mask.appendChild(maskContent);
  4090. defs.appendChild(mask);
  4091. svgOverlay.appendChild(defs);
  4092.  
  4093. // Create the red overlay rectangle that will be masked
  4094. const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
  4095. rect.setAttribute('width', '100%');
  4096. rect.setAttribute('height', '100%');
  4097. rect.setAttribute('fill', 'rgba(255, 0, 0, 0.6)'); // slightly more opaque
  4098. rect.setAttribute('mask', `url(#${mask.id})`);
  4099. svgOverlay.appendChild(rect);
  4100. overlayContainer.appendChild(svgOverlay);
  4101.  
  4102. // Add to parent element (usually the monster container)
  4103. element.style.position = 'relative'; // Ensure positioning context
  4104. element.appendChild(overlayContainer);
  4105. const svgCenter = getElementCenter(element);
  4106.  
  4107. // Make overlay match any subsequent animations of the original SVG
  4108. const observer = new MutationObserver(mutations => {
  4109. mutations.forEach(mutation => {
  4110. if (mutation.attributeName === 'style' || mutation.attributeName === 'transform') {
  4111. // Copy transform properties to keep in sync
  4112. svgOverlay.style.transform = monsterSvg.style.transform;
  4113. svgOverlay.style.opacity = monsterSvg.style.opacity;
  4114. svgOverlay.style.transition = monsterSvg.style.transition;
  4115. }
  4116. });
  4117. });
  4118.  
  4119. // Start observing the original SVG for changes
  4120. observer.observe(monsterSvg, {
  4121. attributes: true,
  4122. attributeFilter: ['style', 'transform']
  4123. });
  4124.  
  4125. // Fade out after delay
  4126. setTimeout(() => {
  4127. // monsterSvg.style.transition = "opacity 0.5s ease-in-out";
  4128. monsterSvg.style.opacity = "0";
  4129.  
  4130. // Remove overlay and stop observer after animation
  4131. observer.disconnect();
  4132. overlayContainer.remove();
  4133. let effects = [];
  4134. const p = {
  4135. x: svgCenter.x,
  4136. y: svgCenter.y + 30,
  4137. color: "rgba(0, 0, 0, 0.6)",
  4138. size: 0.2
  4139. };
  4140. for (let i = 0; i < 25; i++) {
  4141. p.life = onHitEffectsMap.pixelSmoke.life({
  4142. size: 0.5
  4143. });
  4144. effects.push({
  4145. x: onHitEffectsMap.pixelSmoke.x(p),
  4146. y: onHitEffectsMap.pixelSmoke.y(p),
  4147. angle: onHitEffectsMap.pixelSmoke.angle(p),
  4148. color: onHitEffectsMap.pixelSmoke.color(p),
  4149. size: onHitEffectsMap.pixelSmoke.size(p),
  4150. speed: onHitEffectsMap.pixelSmoke.speed({
  4151. size: 5
  4152. }),
  4153. gravity: onHitEffectsMap.pixelSmoke.gravity(p),
  4154. life: p.life,
  4155. maxLife: p.life,
  4156. draw: onHitEffectsMap.pixelSmoke.draw
  4157. });
  4158. }
  4159.  
  4160. // Add particle effect
  4161. addEffect({
  4162. effects: effects,
  4163. active: true,
  4164. lifespan: 500
  4165. });
  4166. }, 1000);
  4167. }
  4168. };
  4169.  
  4170. const canvas = initTrackerCanvas();
  4171. const ctx = canvas.getContext('2d');
  4172. function initTrackerCanvas() {
  4173. const gamePanel = document.querySelector("body");
  4174. const canvas = document.createElement('canvas');
  4175. canvas.id = 'hitTrackerCanvas';
  4176. canvas.style.position = 'fixed';
  4177. canvas.style.top = '0';
  4178. canvas.style.left = '0';
  4179. canvas.style.pointerEvents = 'none';
  4180. canvas.style.zIndex = '200';
  4181. canvas.style.width = '100%';
  4182. canvas.style.height = '100%';
  4183. canvas.width = window.innerWidth;
  4184. canvas.height = window.innerHeight;
  4185. canvas.pointerEvents = 'none';
  4186. gamePanel.appendChild(canvas);
  4187. window.addEventListener('resize', () => {
  4188. canvas.width = window.innerWidth;
  4189. canvas.height = window.innerHeight;
  4190. });
  4191. return canvas;
  4192. }
  4193.  
  4194. // Update shake animation effect to ensure element returns to original position
  4195. let fpsStatTime = new Date().getTime();
  4196. let fpsQueue = [];
  4197. let fps = 60;
  4198.  
  4199. // 动画循环
  4200. function animate() {
  4201. // 计算FPS
  4202. const now = Date.now();
  4203. const frameTime = now - fpsStatTime;
  4204. fpsStatTime = now;
  4205. const fpsNow = Math.round(1000 / frameTime);
  4206. fpsQueue.push(fpsNow);
  4207. if (fpsQueue.length > 120) {
  4208. fpsQueue.shift();
  4209. }
  4210. fps = Math.round(fpsQueue.reduce((a, b) => a + b) / fpsQueue.length);
  4211. fps = Math.min(Math.max(fps, 10), 300);
  4212.  
  4213. // 完全清空画布
  4214. ctx.clearRect(0, 0, canvas.width, canvas.height);
  4215.  
  4216. // 更新并绘制所有弹丸
  4217. for (let i = projectiles.length - 1; i >= 0; i--) {
  4218. const proj = projectiles[i];
  4219. proj.update();
  4220. proj.draw(ctx);
  4221. if (proj.isArrived()) {
  4222. createOnHitEffect(proj); // 将弹丸大小传递给爆炸效果
  4223. projectiles.splice(i, 1);
  4224. } else if (proj.isOutOfBounds()) {
  4225. // 超出边界则移除弹丸,不产生爆炸效果
  4226. projectiles.splice(i, 1);
  4227. }
  4228. }
  4229.  
  4230. // 更新和渲染所有爆炸效果
  4231. updateOnHits();
  4232. }
  4233. function startAnimation() {
  4234. const fpsLimit = settingsMap.renderFpsLimit.value || 60;
  4235. const fpsInterval = 1000 / fpsLimit;
  4236. setInterval(() => {
  4237. animate();
  4238. }, fpsInterval);
  4239. }
  4240. function getFpsFactor() {
  4241. return Math.min(Math.max(160 / fps, 0.125), 8);
  4242. }
  4243. class Projectile {
  4244. constructor(startX, startY, endX, endY, color, initialSpeed = 1, size = 10, otherInfo = {}) {
  4245. // 基础属性
  4246. this.x = startX;
  4247. this.y = startY;
  4248. this.start = {
  4249. x: startX,
  4250. y: startY
  4251. };
  4252. this.target = {
  4253. x: endX,
  4254. y: endY
  4255. };
  4256. this.otherInfo = otherInfo;
  4257. this.shakeApplied = false;
  4258. this.life = 0;
  4259. this.type = otherInfo.type || 'default';
  4260. this.effect = projectileEffectsMap[this.type] || projectileEffectsMap['fireball'];
  4261. this.doShake = this.effect.shake;
  4262.  
  4263. // 运动参数 - 向斜上方抛物线轨迹
  4264. this.gravity = this.effect.gravity || 0.2; // 重力加速度
  4265. this.gravity *= settingsMap.projectileHeightScale.value || 1; // 高度缩放因子
  4266.  
  4267. this.initialSpeed = initialSpeed * (this.effect.speedFactor || 1); // 初始速度参数
  4268. this.initialSpeed *= settingsMap.projectileSpeedScale.value || 1; // 速度缩放因子
  4269.  
  4270. // 计算水平距离和高度差
  4271. const dx = endX - startX;
  4272. const dy = endY - startY;
  4273.  
  4274. // 重新设计飞行时间计算,确保合理
  4275. // const timeInAir = distance / this.initialSpeed / 10;
  4276. this.timeInAir = 80 / this.initialSpeed;
  4277.  
  4278. // FPS因子,确保在不同FPS下效果一致
  4279. this.fpsFactor = getFpsFactor();
  4280. this.gravity *= Math.pow(this.fpsFactor, 2);
  4281. this.timeInAir /= this.fpsFactor;
  4282.  
  4283. // 计算初始速度,修正公式确保能够到达目标
  4284. this.velocity = {
  4285. x: dx / this.timeInAir,
  4286. y: dy / this.timeInAir - this.gravity * this.timeInAir / 2
  4287. };
  4288. this.initialVelocity = {
  4289. ...this.velocity
  4290. };
  4291. this.trajectory = time => {
  4292. return {
  4293. x: startX + this.initialVelocity.x * time,
  4294. y: startY + this.initialVelocity.y * time + this.gravity * time * time / 2
  4295. };
  4296. };
  4297.  
  4298. // 大小参数 (范围1-100)
  4299. const projectileScale = settingsMap.projectileScale.value || 1;
  4300. this.sizeScale = Math.max(1, Math.min(100, size)) / 10 * projectileScale; // 转换为比例因子
  4301.  
  4302. // 外观属性
  4303. this.size = 10 * this.sizeScale;
  4304. this.color = this.effect.color || color;
  4305.  
  4306. // 拖尾效果
  4307. this.trail = [];
  4308. this.independentTrail = this.effect.independentTrail || false; // 是否独立拖尾
  4309. this.maxTrailLength = Math.floor((this.effect.trailLength || 35) * Math.sqrt(this.sizeScale)); // 拖尾长度随大小增加
  4310. this.maxTrailLength *= settingsMap.projectileTrailLength.value || 1; // 拖尾缩放因子
  4311. this.trailGap = (settingsMap.projectileTrailGap.value || 1) / this.fpsFactor;
  4312. }
  4313. update() {
  4314. this.life += 1;
  4315. const pos = this.trajectory(this.life);
  4316. this.velocity.y += this.gravity;
  4317. this.x = pos.x;
  4318. this.y = pos.y;
  4319.  
  4320. // 更新拖尾
  4321. if (this.independentTrail) {
  4322. if (this.effect.trailLength > 0) {
  4323. this.trail.push({
  4324. x: this.x,
  4325. y: this.y,
  4326. vX: this.velocity.x,
  4327. vY: this.velocity.y,
  4328. color: this.color,
  4329. size: this.size,
  4330. totalLength: Math.max(this.trail.length, 1)
  4331. });
  4332. }
  4333. if (this.trail.length > this.maxTrailLength) {
  4334. this.trail.shift();
  4335. }
  4336. } else {
  4337. this.trail = [];
  4338. for (let i = 0; i < this.maxTrailLength; i++) {
  4339. const trailTime = this.life - (this.maxTrailLength - i - 1) * this.trailGap;
  4340. if (trailTime <= 0) continue;
  4341. const trailPos = this.trajectory(trailTime);
  4342. this.trail.push({
  4343. x: trailPos.x,
  4344. y: trailPos.y,
  4345. vX: this.velocity.x,
  4346. vY: this.velocity.y,
  4347. color: this.color,
  4348. size: this.size,
  4349. totalLength: Math.min(this.maxTrailLength, this.life)
  4350. });
  4351. }
  4352. }
  4353. }
  4354. draw(canvas) {
  4355. // 绘制拖尾
  4356. this.trail.forEach((pos, index) => {
  4357. if (this.effect.trail) {
  4358. this.effect.trail(canvas, pos, index);
  4359. } else {
  4360. projectileEffectsMap['fireball'].trail(canvas, pos, index);
  4361. }
  4362. });
  4363.  
  4364. // 绘制主体
  4365. if (this.effect.draw) {
  4366. this.effect.draw(canvas, this);
  4367. } else {
  4368. projectileEffectsMap['fireball'].draw(canvas, this);
  4369. }
  4370.  
  4371. // 添加光晕效果
  4372. if (this.effect.glow) {
  4373. this.effect.glow(canvas, this);
  4374. }
  4375. }
  4376. isArrived() {
  4377. if (this.life >= this.timeInAir) {
  4378. this.x = this.target.x;
  4379. this.y = this.target.y;
  4380. return true;
  4381. }
  4382. // 判断是否到达目标点 (调整判定距离)
  4383. const arrivalDistance = 20;
  4384. const hasArrived = Math.hypot(this.x - this.target.x, this.y - this.target.y) < arrivalDistance;
  4385. if (hasArrived && this.doShake && !this.shakeApplied && this.otherInfo.endElement) {
  4386. const shakeIntensity = Math.min(this.sizeScale * 5, 10);
  4387. applyShakeEffect(this.otherInfo.endElement, shakeIntensity);
  4388. this.shakeApplied = true;
  4389. }
  4390. return hasArrived;
  4391. }
  4392. isOutOfBounds() {
  4393. return this.x < 0 || this.x > canvas.width || this.y < 0 || this.y > canvas.height;
  4394. }
  4395. }
  4396.  
  4397. // Projectiles管理
  4398. let projectiles = [];
  4399. function clearProjectiles() {
  4400. projectiles.splice(0, projectiles.length);
  4401. }
  4402.  
  4403. // 爆炸效果函数
  4404. function createOnHitEffect(projectile) {
  4405. const x = projectile.x;
  4406. const y = projectile.y;
  4407. const color = projectile.color;
  4408. const otherInfo = projectile.otherInfo;
  4409. const projectileScale = settingsMap.projectileScale.value || 1;
  4410.  
  4411. // Resize for onHit effect
  4412. projectile.size = Math.max(1, Math.min(100, projectile.size)) / 20 / projectileScale;
  4413. const sizeFactor = settingsMap.onHitScale.value || 1;
  4414. const particleFactor = settingsMap.particleEffectRatio.value || 1;
  4415. const particleSpeedFactor = settingsMap.particleSpeedRatio.value || 1;
  4416. const particleLifespanFactor = settingsMap.particleLifespanRatio.value || 1;
  4417. const fpsFactor = getFpsFactor();
  4418.  
  4419. // 存储命中动画的活跃状态,用于跟踪
  4420. const damageTextLifespan = settingsMap.damageTextLifespan.value || 120;
  4421. const lifeSpan = Math.ceil(damageTextLifespan / Math.pow(fpsFactor, 0.33));
  4422. const effects = [];
  4423. let onHitEffect = projectile.effect.onHit;
  4424. if (projectile.otherInfo.isCrit) {
  4425. const onCrit = projectile.effect.onCrit || projectileEffectsMap.fireball.onCrit;
  4426. onHitEffect = {
  4427. ...onHitEffect,
  4428. ...onCrit
  4429. };
  4430. }
  4431. for (const effectName in onHitEffect) {
  4432. const effect = onHitEffectsMap[effectName];
  4433. if (!effect) continue;
  4434. const effectCount = Math.ceil(onHitEffect[effectName](projectile.size) * particleFactor);
  4435. for (let i = 0; i < effectCount; i++) {
  4436. const effectSize = (effect.size ? effect.size(projectile) : Math.random() * 10 + 5) * sizeFactor;
  4437. let effectLife = Math.ceil((effect.life ? effect.life(projectile) : 1000) * particleLifespanFactor / Math.pow(fpsFactor, 0.33));
  4438. // effectLife = Math.min(effectLife, lifeSpan);
  4439. const effectSpeed = Math.ceil((effect.speed ? effect.speed(projectile) : Math.random() * 5 + 2) / Math.pow(fpsFactor, 0.33) * particleSpeedFactor);
  4440. effects.push({
  4441. x: effect.x ? effect.x(projectile) : x,
  4442. y: effect.y ? effect.y(projectile) : y,
  4443. angle: effect.angle ? effect.angle(projectile) : Math.random() * Math.PI * 2,
  4444. alpha: effect.alpha ? effect.alpha(projectile) : 0.8,
  4445. size: effectSize,
  4446. speed: effectSpeed,
  4447. gravity: effect.gravity ? effect.gravity(projectile) : 0,
  4448. life: effectLife,
  4449. maxLife: effectLife,
  4450. color: effect.color ? effect.color(projectile) : projectile.color,
  4451. fpsFactor: fpsFactor,
  4452. draw: effect.draw ? effect.draw : (ctx, p) => {}
  4453. });
  4454. }
  4455. }
  4456. const onHitEffectData = {
  4457. effects: [...effects],
  4458. active: true,
  4459. lifespan: lifeSpan,
  4460. color: color,
  4461. otherInfo: otherInfo,
  4462. isFpsOptimized: true
  4463. };
  4464. addEffect(onHitEffectData);
  4465. }
  4466.  
  4467. // 更新和渲染所有命中效果
  4468. function updateOnHits() {
  4469. // 遍历所有活跃的命中
  4470. for (let i = activeEffects.length - 1; i >= 0; i--) {
  4471. const effect = activeEffects[i];
  4472. effect.life++;
  4473. if (effect.life >= effect.lifespan) {
  4474. activeEffects.splice(i, 1);
  4475. continue;
  4476. }
  4477. if (!effect.isFpsOptimized) {
  4478. const fpsFactor = getFpsFactor();
  4479. for (const e of effect.effects) {
  4480. e.speed *= fpsFactor;
  4481. e.life /= fpsFactor;
  4482. e.fpsFactor = fpsFactor;
  4483. }
  4484. effect.lifespan /= fpsFactor;
  4485. effect.isFpsOptimized = true;
  4486. }
  4487. ctx.save();
  4488.  
  4489. // 更新各自效果
  4490. effect.effects.forEach((e, index) => {
  4491. e.draw(ctx, e);
  4492. });
  4493.  
  4494. // 伤害文本
  4495. if (effect.otherInfo && effect.otherInfo.damage) {
  4496. const fontSizeScale = settingsMap.damageTextScale.value || 1;
  4497. const fontSizeMinimal = settingsMap.damageTextSizeMinimal.value || 14;
  4498. const fontSizeLimit = settingsMap.damageTextSizeLimit.value || 70;
  4499. const fontAlpha = settingsMap.damageTextAlpha.value || 0.8;
  4500. const fontSize = Math.min(Math.max(fontSizeMinimal, Math.pow(effect.otherInfo.damage, 0.65) / 2 * fontSizeScale), fontSizeLimit);
  4501. const damageText = `${effect.otherInfo.damage}`;
  4502. ctx.font = `${fontSize}px Arial`;
  4503. ctx.textAlign = 'center';
  4504. ctx.textBaseline = 'middle';
  4505. const textSize = ctx.measureText(damageText);
  4506. const textPosition = {
  4507. x: effect.otherInfo.end.x - textSize.width / 2 + 5,
  4508. y: effect.otherInfo.end.y - 20
  4509. };
  4510.  
  4511. // border
  4512. ctx.strokeStyle = effect.color.replace(/rgba\(([^,]+),([^,]+),([^,]+),[^)]+\)/, `rgba($1,$2,$3,${fontAlpha})`);
  4513. ctx.lineWidth = 6;
  4514. ctx.strokeText(damageText, textPosition.x, textPosition.y);
  4515. // main
  4516. const fillColor = effect.otherInfo.isCrit ? 'rgba(255, 213, 89, 1)' : 'white';
  4517. ctx.fillStyle = fillColor;
  4518. ctx.fillText(damageText, textPosition.x, textPosition.y);
  4519. }
  4520. ctx.restore();
  4521. }
  4522. }
  4523. function createProjectile(startElement, endElement, color, initialSpeed = 1, damage = 200, projectileType = 'default', isCrit = false, isKill = false) {
  4524. if (!startElement || !endElement) {
  4525. return;
  4526. }
  4527. const combatUnitContainer = endElement.querySelector(".CombatUnit_splatsContainer__2xcc0");
  4528. if (!settingsMap.originalDamageDisplay.value) {
  4529. combatUnitContainer.style.visibility = "hidden";
  4530. }
  4531. const padding = 30;
  4532. const randomRangeRatio = settingsMap.hitAreaScale.value || 1;
  4533. const randomRange = {
  4534. x: () => Math.floor((Math.random() - 0.5) * (combatUnitContainer.offsetWidth - 2 * padding)) * randomRangeRatio,
  4535. y: () => Math.floor((Math.random() - 0.1) * (combatUnitContainer.offsetHeight - padding)) * randomRangeRatio
  4536. };
  4537. const projectileLimit = settingsMap.projectileLimit.value || 30;
  4538. const start = getElementCenter(startElement);
  4539. const end = getElementCenter(endElement);
  4540. let endX = Math.floor(end.x + randomRange.x());
  4541. let endY = Math.floor(end.y + randomRange.y());
  4542. const minimalGap = (settingsMap.hitPositionMinGap.value || 0) * randomRangeRatio;
  4543. if (minimalGap > 0) {
  4544. let attempts = 100;
  4545. while (attempts > 0 && projectiles.some(p => {
  4546. const distance = Math.hypot(p.otherInfo.end.x - end.x, p.otherInfo.end.y - end.y);
  4547. return distance < minimalGap;
  4548. })) {
  4549. endX = Math.floor(end.x + randomRange.x());
  4550. endY = Math.floor(end.y + randomRange.y());
  4551. attempts -= 1;
  4552. }
  4553. if (attempts <= 0) {
  4554. console.warn("[MWI-Hit-Tracker-Canvas]Hit position is too crowded, hit gap may not work as expected.");
  4555. }
  4556. }
  4557. const size = Math.min(Math.max(Math.pow(damage + 200, 0.7) / 20, 4), 16);
  4558. projectileType = abilityEffectsMap[projectileType] || projectileType;
  4559. const otherInfo = {
  4560. type: projectileType,
  4561. start: start,
  4562. end: {
  4563. x: endX,
  4564. y: endY
  4565. },
  4566. damage: damage,
  4567. color: color,
  4568. isCrit: isCrit,
  4569. isKill: isKill,
  4570. startElement: startElement,
  4571. endElement: endElement
  4572. };
  4573. if (projectiles.length <= projectileLimit) {
  4574. if (damage > 0) {
  4575. addDamageHPBar(endElement, damage);
  4576. }
  4577. if (otherInfo.isKill && settingsMap.monsterDeadAnimation.value) {
  4578. deathEffect[settingsMap.monsterDeadAnimationStyle.value](otherInfo.endElement);
  4579. }
  4580. const projectile = new Projectile(start.x, start.y, endX, endY, color, initialSpeed, size, otherInfo);
  4581. projectiles.push(projectile);
  4582. } else {
  4583. projectiles.shift();
  4584. }
  4585. }
  4586.  
  4587. // 其他低频DOM操作
  4588. setInterval(() => {
  4589. if (settingsMap.showFps.value) {
  4590. const fpsElement = document.querySelector('#hitTracker_fpsCounter');
  4591. if (fpsElement) {
  4592. fpsElement.innerText = `FPS: ${fps}`;
  4593. } else {
  4594. const parenetElement = document.querySelector(".BattlePanel_battleArea__U9hij");
  4595. if (parenetElement) {
  4596. const newFpsElement = document.createElement('div');
  4597. const center = getElementCenter(parenetElement);
  4598. newFpsElement.id = 'hitTracker_fpsCounter';
  4599. newFpsElement.style.position = 'fixed';
  4600. newFpsElement.style.top = `${center.x - parenetElement.innerWidth}px`;
  4601. newFpsElement.style.left = `${center.y - parenetElement.innerHeight}px`;
  4602. newFpsElement.style.color = 'rgba(200, 200, 200, 0.8)';
  4603. newFpsElement.style.zIndex = '9999';
  4604. newFpsElement.innerText = `FPS: ${fps}`;
  4605. parenetElement.appendChild(newFpsElement);
  4606. }
  4607. }
  4608. }
  4609. if (settingsMap.verticalCombatDisplay.value) {
  4610. const battleGrids = document.querySelectorAll(".BattlePanel_combatUnitGrid__2hTAM");
  4611. if (battleGrids) {
  4612. for (let i = 0; i < battleGrids.length; i++) {
  4613. const grid = battleGrids[i];
  4614. grid.style['grid-template-columns'] = `repeat(1,120px)`;
  4615. }
  4616. }
  4617. }
  4618. }, 500);
  4619.  
  4620. // #region Setting
  4621. waitForSettings({
  4622. monsterDeadAnimationStyle: Object.keys(deathEffect),
  4623. allProjectiles: Object.keys(projectileEffectsMap)
  4624. });
  4625. hookWS();
  4626. let isPageHidden = false;
  4627.  
  4628. // 监听页面可见性变化
  4629. document.addEventListener('visibilitychange', function () {
  4630. isPageHidden = document.hidden;
  4631. if (isPageHidden) {
  4632. clearProjectiles();
  4633. clearEffects();
  4634. }
  4635. });
  4636.  
  4637. // #region Hook WS
  4638. function hookWS() {
  4639. const dataProperty = Object.getOwnPropertyDescriptor(MessageEvent.prototype, "data");
  4640. const oriGet = dataProperty.get;
  4641. dataProperty.get = hookedGet;
  4642. Object.defineProperty(MessageEvent.prototype, "data", dataProperty);
  4643. function hookedGet() {
  4644. const socket = this.currentTarget;
  4645. if (!(socket instanceof WebSocket)) {
  4646. return oriGet.call(this);
  4647. }
  4648. if (socket.url.indexOf("api.milkywayidle.com/ws") <= -1 && socket.url.indexOf("api-test.milkywayidle.com/ws") <= -1) {
  4649. return oriGet.call(this);
  4650. }
  4651. const message = oriGet.call(this);
  4652. Object.defineProperty(this, "data", {
  4653. value: message
  4654. }); // Anti-loop
  4655.  
  4656. try {
  4657. return handleMessage(message);
  4658. } catch (error) {
  4659. console.log("Error in hit-tracker handleMessage:", error);
  4660. return message;
  4661. }
  4662. }
  4663. }
  4664. let monstersHP = [];
  4665. let monstersMP = [];
  4666. let playersHP = [];
  4667. let playersMP = [];
  4668. let playersAbility = [];
  4669. function handleMessage(message) {
  4670. let obj = JSON.parse(message);
  4671. if (obj && obj.type === "new_battle") {
  4672. monstersHP = obj.monsters.map(monster => monster.currentHitpoints);
  4673. monstersMP = obj.monsters.map(monster => monster.currentManapoints);
  4674. playersHP = obj.players.map(player => player.currentHitpoints);
  4675. playersMP = obj.players.map(player => player.currentManapoints);
  4676. resetAllMonsterSvg();
  4677. } else if (obj && obj.type === "battle_updated" && monstersHP.length) {
  4678. const mMap = obj.mMap;
  4679. const pMap = obj.pMap;
  4680. const monsterIndices = Object.keys(obj.mMap);
  4681. const playerIndices = Object.keys(obj.pMap);
  4682. let castMonster = -1;
  4683. monsterIndices.forEach(monsterIndex => {
  4684. if (mMap[monsterIndex].cMP < monstersMP[monsterIndex]) {
  4685. castMonster = monsterIndex;
  4686. }
  4687. monstersMP[monsterIndex] = mMap[monsterIndex].cMP;
  4688. });
  4689. let castPlayer = -1;
  4690. playerIndices.forEach(userIndex => {
  4691. if (pMap[userIndex].cMP < playersMP[userIndex]) {
  4692. castPlayer = userIndex;
  4693. }
  4694. if (pMap[userIndex].cMP > playersMP[userIndex]) {
  4695. registProjectile({
  4696. from: userIndex,
  4697. to: userIndex,
  4698. hpDiff: pMap[userIndex].cMP - playersMP[userIndex],
  4699. reversed: false,
  4700. abilityHrid: 'selfManaRegen',
  4701. toPlayer: true
  4702. });
  4703. }
  4704. playersMP[userIndex] = pMap[userIndex].cMP;
  4705. if (pMap[userIndex].abilityHrid) {
  4706. playersAbility[userIndex] = pMap[userIndex].abilityHrid;
  4707. }
  4708. });
  4709. monstersHP.forEach((mHP, mIndex) => {
  4710. const monster = mMap[mIndex];
  4711. if (monster) {
  4712. const hpDiff = mHP - monster.cHP;
  4713. monstersHP[mIndex] = monster.cHP;
  4714. if (hpDiff > 0 && playerIndices.length > 0) {
  4715. const isCrit = monster.dmgCounter == monster.critCounter;
  4716. const isKill = monster.cHP <= 0;
  4717. if (playerIndices.length > 1) {
  4718. playerIndices.forEach(userIndex => {
  4719. if (userIndex === castPlayer) {
  4720. registProjectile({
  4721. from: userIndex,
  4722. to: mIndex,
  4723. hpDiff: hpDiff,
  4724. reversed: false,
  4725. abilityHrid: playersAbility[userIndex],
  4726. toPlayer: false,
  4727. isCrit: isCrit,
  4728. isKill: isKill
  4729. });
  4730. }
  4731. });
  4732. } else {
  4733. registProjectile({
  4734. from: playerIndices[0],
  4735. to: mIndex,
  4736. hpDiff: hpDiff,
  4737. reversed: false,
  4738. abilityHrid: playersAbility[playerIndices[0]],
  4739. toPlayer: false,
  4740. isCrit: isCrit,
  4741. isKill: isKill
  4742. });
  4743. }
  4744. }
  4745. }
  4746. });
  4747. playersHP.forEach((pHP, pIndex) => {
  4748. const player = pMap[pIndex];
  4749. if (player) {
  4750. const hpDiff = pHP - player.cHP;
  4751. playersHP[pIndex] = player.cHP;
  4752. if (hpDiff > 0 && monsterIndices.length > 0) {
  4753. const isCrit = player.dmgCounter == player.critCounter;
  4754. if (monsterIndices.length > 1) {
  4755. monsterIndices.forEach(monsterIndex => {
  4756. if (monsterIndex === castMonster) {
  4757. registProjectile({
  4758. from: pIndex,
  4759. to: monsterIndex,
  4760. hpDiff: hpDiff,
  4761. reversed: true,
  4762. abilityHrid: 'autoAttack',
  4763. toPlayer: false,
  4764. isCrit: isCrit
  4765. });
  4766. }
  4767. });
  4768. } else {
  4769. registProjectile({
  4770. from: pIndex,
  4771. to: monsterIndices[0],
  4772. hpDiff: hpDiff,
  4773. reversed: true,
  4774. abilityHrid: 'autoAttack',
  4775. toPlayer: false,
  4776. isCrit: isCrit
  4777. });
  4778. }
  4779. } else if (hpDiff < 0) {
  4780. if (castPlayer > -1) {
  4781. registProjectile({
  4782. from: castPlayer,
  4783. to: pIndex,
  4784. hpDiff: -hpDiff,
  4785. reversed: false,
  4786. abilityHrid: 'heal',
  4787. toPlayer: true
  4788. });
  4789. } else {
  4790. registProjectile({
  4791. from: pIndex,
  4792. to: pIndex,
  4793. hpDiff: -hpDiff,
  4794. reversed: false,
  4795. abilityHrid: 'selfHeal',
  4796. toPlayer: true
  4797. });
  4798. }
  4799. }
  4800. }
  4801. });
  4802. } else if (obj && obj.type === "battle_updated") {
  4803. const pMap = obj.pMap;
  4804. const playerIndices = Object.keys(obj.pMap);
  4805. playerIndices.forEach(userIndex => {
  4806. if (pMap[userIndex].abilityHrid) {
  4807. playersAbility[userIndex] = pMap[userIndex].abilityHrid;
  4808. }
  4809. });
  4810. playersHP.forEach((pHP, pIndex) => {
  4811. const player = pMap[pIndex];
  4812. if (player) {
  4813. const hpDiff = pHP - player.cHP;
  4814. playersHP[pIndex] = player.cHP;
  4815. if (hpDiff < 0) {
  4816. registProjectile({
  4817. from: pIndex,
  4818. to: pIndex,
  4819. hpDiff: -hpDiff,
  4820. reversed: false,
  4821. abilityHrid: 'selfHeal',
  4822. toPlayer: true
  4823. });
  4824. }
  4825. }
  4826. });
  4827. playersMP.forEach((pMP, pIndex) => {
  4828. const player = pMap[pIndex];
  4829. if (player) {
  4830. const mpDiff = pMP - player.pMP;
  4831. playersMP[pIndex] = player.pMP;
  4832. if (mpDiff < 0) {
  4833. registProjectile({
  4834. from: pIndex,
  4835. to: pIndex,
  4836. hpDiff: -mpDiff,
  4837. reversed: false,
  4838. abilityHrid: 'selfManaRegen',
  4839. toPlayer: true
  4840. });
  4841. }
  4842. }
  4843. });
  4844. }
  4845. return message;
  4846. }
  4847.  
  4848. // #region Main Logic
  4849.  
  4850. // 动画效果
  4851. function registProjectile({
  4852. from,
  4853. to,
  4854. hpDiff,
  4855. reversed = false,
  4856. abilityHrid = "default",
  4857. toPlayer = true,
  4858. isCrit = false,
  4859. isKill = false
  4860. }) {
  4861. if (isPageHidden) {
  4862. return;
  4863. }
  4864. if (reversed) {
  4865. if (settingsMap.tracker6 && !settingsMap.tracker6.isTrue) {
  4866. return null;
  4867. }
  4868. } else {
  4869. if (settingsMap["tracker" + from] && !settingsMap["tracker" + from].isTrue) {
  4870. return null;
  4871. }
  4872. }
  4873. if (["selfHeal", "selfManaRegen"].indexOf(abilityHrid) > -1 && !settingsMap.showSelfRegen.value) {
  4874. return null;
  4875. }
  4876. const container = document.querySelector(".BattlePanel_playersArea__vvwlB");
  4877. if (container && container.children.length > 0) {
  4878. const playersContainer = container.children[0];
  4879. const effectFrom = playersContainer.children[from];
  4880. const monsterContainer = document.querySelector(".BattlePanel_monstersArea__2dzrY").children[0];
  4881. const effectTo = toPlayer ? playersContainer.children[to] : monsterContainer.children[to];
  4882. const trackerSetting = reversed ? settingsMap[`tracker6`] : settingsMap["tracker" + from];
  4883. let lineColor = "rgba(" + trackerSetting.r + ", " + trackerSetting.g + ", " + trackerSetting.b + ", 1)";
  4884. if (["selfHeal", "selfManaRegen", "heal"].indexOf(abilityHrid) <= -1) {
  4885. if (trackerSetting.trackStyle === "null") {
  4886. return null;
  4887. } else if (trackerSetting.trackStyle != "auto") {
  4888. abilityHrid = trackerSetting.trackStyle;
  4889. }
  4890. }
  4891. if (!reversed) {
  4892. createProjectile(effectFrom, effectTo, lineColor, 1, hpDiff, abilityHrid, isCrit, isKill);
  4893. } else {
  4894. createProjectile(effectTo, effectFrom, lineColor, 1, hpDiff, abilityHrid, isCrit, isKill);
  4895. }
  4896. }
  4897. }
  4898.  
  4899. // 启动动画
  4900. startAnimation();
  4901.  
  4902. exports.registProjectile = registProjectile;
  4903.  
  4904. Object.defineProperty(exports, '__esModule', { value: true });
  4905.  
  4906. return exports;
  4907.  
  4908. })({});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址