MWI-Hit-Tracker-Canvas

A Tampermonkey script to track MWI hits on Canvas

当前为 2025-05-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MWI-Hit-Tracker-Canvas
  3. // @namespace MWI-Hit-Tracker-Canvas
  4. // @version 1.1.5
  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. damageTextLifespan: {
  1449. id: "damageTextLifespan",
  1450. desc: isZH ? "伤害文本持续时间" : "Damage Text Lifespan",
  1451. value: 120,
  1452. min: 30,
  1453. max: 480,
  1454. step: 10
  1455. },
  1456. damageTextScale: {
  1457. id: "damageTextScale",
  1458. desc: isZH ? "伤害文本大小" : "Damage Text Scale",
  1459. value: 1.0,
  1460. min: 0.1,
  1461. max: 3.0,
  1462. step: 0.1
  1463. },
  1464. damageTextAlpha: {
  1465. id: "damageTextAlpha",
  1466. desc: isZH ? "伤害文本不透明度" : "Damage Text Alpha",
  1467. value: 0.8,
  1468. min: 0.0,
  1469. max: 1.0,
  1470. step: 0.01
  1471. },
  1472. damageTextSizeMinimal: {
  1473. id: "damageTextSizeMinimal",
  1474. desc: isZH ? "伤害文本尺寸最小值" : "Damage Text Size Minimal",
  1475. value: 14,
  1476. min: 5,
  1477. max: 100,
  1478. step: 1
  1479. },
  1480. damageTextSizeLimit: {
  1481. id: "damageTextSizeLimit",
  1482. desc: isZH ? "伤害文本尺寸上限" : "Damage Text Size Limit",
  1483. value: 70,
  1484. min: 15,
  1485. max: 200,
  1486. step: 1
  1487. },
  1488. showSelfRegen: {
  1489. id: "showSelfRegen",
  1490. desc: isZH ? "显示玩家被动回复效果" : "Show Self Regeneration",
  1491. value: true
  1492. },
  1493. monsterDeadAnimation: {
  1494. id: "monsterDeadAnimation",
  1495. desc: isZH ? "怪物死亡效果" : "Monster Dead Animation",
  1496. value: true
  1497. },
  1498. monsterDeadAnimationStyle: {
  1499. id: "monsterDeadAnimationStyle",
  1500. desc: isZH ? "怪物死亡效果样式" : "Monster Dead Animation Style",
  1501. value: "default",
  1502. list: []
  1503. },
  1504. damageHpBarDropDelay: {
  1505. id: "damageHpBarDropDelay",
  1506. desc: isZH ? "血条掉落延迟" : "Hp Bar Drop Delay",
  1507. value: 300,
  1508. min: 50,
  1509. max: 1000,
  1510. step: 50
  1511. },
  1512. tracker0: {
  1513. id: "tracker0",
  1514. desc: isZH ? "玩家1" : "Player 1",
  1515. isTrue: true,
  1516. trackStyle: "auto",
  1517. r: 255,
  1518. g: 99,
  1519. b: 132
  1520. },
  1521. tracker1: {
  1522. id: "tracker1",
  1523. desc: isZH ? "玩家2" : "Player 2",
  1524. isTrue: true,
  1525. trackStyle: "auto",
  1526. r: 54,
  1527. g: 162,
  1528. b: 235
  1529. },
  1530. tracker2: {
  1531. id: "tracker2",
  1532. desc: isZH ? "玩家3" : "Player 3",
  1533. isTrue: true,
  1534. trackStyle: "auto",
  1535. r: 255,
  1536. g: 206,
  1537. b: 86
  1538. },
  1539. tracker3: {
  1540. id: "tracker3",
  1541. desc: isZH ? "玩家4" : "Player 4",
  1542. isTrue: true,
  1543. trackStyle: "auto",
  1544. r: 75,
  1545. g: 192,
  1546. b: 192
  1547. },
  1548. tracker4: {
  1549. id: "tracker4",
  1550. desc: isZH ? "玩家5" : "Player 5",
  1551. isTrue: true,
  1552. trackStyle: "auto",
  1553. r: 153,
  1554. g: 102,
  1555. b: 255
  1556. },
  1557. tracker6: {
  1558. id: "tracker6",
  1559. desc: isZH ? "敌人" : "Enemies",
  1560. isTrue: true,
  1561. trackStyle: "auto",
  1562. r: 255,
  1563. g: 0,
  1564. b: 0
  1565. },
  1566. renderFpsLimit: {
  1567. id: "renderFpsLimit",
  1568. desc: isZH ? "渲染帧数限制(非精确,刷新生效)" : "Render FPS Limit (Not accurate, restart required)",
  1569. value: 160,
  1570. min: 5,
  1571. max: 300,
  1572. step: 1
  1573. },
  1574. showFps: {
  1575. id: "showFps",
  1576. desc: isZH ? "显示帧数" : "Show FPS",
  1577. value: false
  1578. }
  1579. };
  1580. readSettings();
  1581. function waitForSettings(params) {
  1582. const targetNode = document.querySelector("div.SettingsPanel_profileTab__214Bj");
  1583. if (targetNode) {
  1584. if (!targetNode.querySelector("#tracker_settings")) {
  1585. targetNode.insertAdjacentHTML("beforeend", `<div id="tracker_settings"></div>`);
  1586. const insertElem = targetNode.querySelector("div#tracker_settings");
  1587. insertElem.insertAdjacentHTML("beforeend", `<div style="float: left; color: orange">${isZH ? "MWI-Hit-Tracker 设置 :" : "MWI-Hit-Tracker Settings: "}</div></br>`);
  1588. for (const setting of Object.values(settingsMap)) {
  1589. if (setting.id.startsWith("tracker")) {
  1590. 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>`);
  1591. const checkedBox = insertElem.querySelector("#" + setting.id);
  1592. checkedBox.addEventListener("change", e => {
  1593. settingsMap[setting.id].isTrue = e.target.checked;
  1594. saveSettings();
  1595. });
  1596. const colorPreview = document.getElementById('colorPreview_' + setting.id);
  1597. let currentColor = {
  1598. r: setting.r,
  1599. g: setting.g,
  1600. b: setting.b
  1601. };
  1602.  
  1603. // 点击打开颜色选择器
  1604. colorPreview.addEventListener('click', () => {
  1605. const settingColor = {
  1606. r: settingsMap[setting.id].r,
  1607. g: settingsMap[setting.id].g,
  1608. b: settingsMap[setting.id].b
  1609. };
  1610. const modal = createColorPicker(settingColor, newColor => {
  1611. currentColor = newColor;
  1612. settingsMap[setting.id].r = newColor.r;
  1613. settingsMap[setting.id].g = newColor.g;
  1614. settingsMap[setting.id].b = newColor.b;
  1615. localStorage.setItem("tracker_settingsMap", JSON.stringify(settingsMap));
  1616. updatePreview();
  1617. });
  1618. document.body.appendChild(modal);
  1619. });
  1620. function updatePreview() {
  1621. colorPreview.style.backgroundColor = `rgb(${currentColor.r},${currentColor.g},${currentColor.b})`;
  1622. }
  1623. updatePreview();
  1624. function createColorPicker(initialColor, callback) {
  1625. // 创建弹窗容器
  1626. const backdrop = document.createElement('div');
  1627. backdrop.className = 'modal-backdrop';
  1628. const modal = document.createElement('div');
  1629. modal.className = 'color-picker-modal';
  1630.  
  1631. // 创建SVG容器
  1632. const preview = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  1633. preview.setAttribute("width", "200");
  1634. preview.setAttribute("height", "150");
  1635. preview.style.display = 'block';
  1636. // 创建抛物线路径
  1637. const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
  1638. Object.assign(path.style, {
  1639. strokeWidth: '5px',
  1640. fill: 'none',
  1641. strokeLinecap: 'round'
  1642. });
  1643. path.setAttribute("d", "M 0 130 Q 100 0 200 130");
  1644. preview.appendChild(path);
  1645.  
  1646. // 颜色控制组件
  1647. const controls = document.createElement('div');
  1648. ['r', 'g', 'b'].forEach(channel => {
  1649. const container = document.createElement('div');
  1650. container.className = 'slider-container';
  1651.  
  1652. // 标签
  1653. const label = document.createElement('label');
  1654. label.textContent = channel.toUpperCase() + ':';
  1655. label.style.color = "white";
  1656.  
  1657. // 滑块
  1658. const slider = document.createElement('input');
  1659. slider.type = 'range';
  1660. slider.min = 0;
  1661. slider.max = 255;
  1662. slider.value = initialColor[channel];
  1663.  
  1664. // 输入框
  1665. const input = document.createElement('input');
  1666. input.type = 'number';
  1667. input.min = 0;
  1668. input.max = 255;
  1669. input.value = initialColor[channel];
  1670. input.style.width = '60px';
  1671.  
  1672. // 双向绑定
  1673. const updateChannel = value => {
  1674. value = Math.min(255, Math.max(0, parseInt(value) || 0));
  1675. slider.value = value;
  1676. input.value = value;
  1677. currentColor[channel] = value;
  1678. path.style.stroke = getColorString(currentColor);
  1679. };
  1680. slider.addEventListener('input', e => updateChannel(e.target.value));
  1681. input.addEventListener('change', e => updateChannel(e.target.value));
  1682. container.append(label, slider, input);
  1683. controls.append(container);
  1684. });
  1685.  
  1686. // 操作按钮
  1687. const actions = document.createElement('div');
  1688. actions.className = 'modal-actions';
  1689. const confirmBtn = document.createElement('button');
  1690. confirmBtn.textContent = isZH ? '确定' : 'OK';
  1691. confirmBtn.onclick = () => {
  1692. callback(currentColor);
  1693. backdrop.remove();
  1694. };
  1695. const cancelBtn = document.createElement('button');
  1696. cancelBtn.textContent = isZH ? '取消' : 'Cancel';
  1697. cancelBtn.onclick = () => backdrop.remove();
  1698. actions.append(cancelBtn, confirmBtn);
  1699.  
  1700. // 组装弹窗
  1701. const getColorString = color => `rgb(${color.r},${color.g},${color.b})`;
  1702. path.style.stroke = getColorString(settingsMap[setting.id]);
  1703. modal.append(preview, controls, actions);
  1704. backdrop.append(modal);
  1705.  
  1706. // 点击背景关闭
  1707. backdrop.addEventListener('click', e => {
  1708. if (e.target === backdrop) backdrop.remove();
  1709. });
  1710. return backdrop;
  1711. }
  1712. const select = document.querySelector("#projectileStyle_" + setting.id);
  1713. const projectileStyle = ["auto", "null", ...params.allProjectiles];
  1714. for (const option of projectileStyle) {
  1715. select.insertAdjacentHTML("beforeend", `<option value="${option}" ${option === setting.trackStyle ? "selected" : ""}>${option}</option>`);
  1716. }
  1717. select.addEventListener("change", e => {
  1718. settingsMap[setting.id].trackStyle = e.target.value;
  1719. saveSettings();
  1720. });
  1721. } else {
  1722. if (typeof setting.value === "boolean") {
  1723. insertElem.insertAdjacentHTML("beforeend", `<div class="tracker-option">${setting.desc}<input type="checkbox" id="trackerSetting_${setting.id}"></input></div>`);
  1724. const checkedBox = insertElem.querySelector("#trackerSetting_" + setting.id);
  1725. checkedBox.checked = setting.value;
  1726. checkedBox.addEventListener("change", e => {
  1727. settingsMap[setting.id].value = e.target.checked;
  1728. saveSettings();
  1729. });
  1730. } else if (typeof setting.value === "number") {
  1731. 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>`);
  1732. const slider = document.querySelector("#trackerSetting_" + setting.id + "_range");
  1733. slider.min = setting.min;
  1734. slider.max = setting.max;
  1735. slider.step = setting.step || 0.05;
  1736. slider.value = setting.value;
  1737. const input = document.querySelector("#trackerSetting_" + setting.id + "_value");
  1738. input.min = setting.min;
  1739. input.max = setting.max;
  1740. input.step = setting.step || 0.05;
  1741. input.value = setting.value;
  1742. const updateChannel = value => {
  1743. value = Math.min(setting.max, Math.max(setting.min, parseFloat(value)));
  1744. slider.value = value;
  1745. input.value = value;
  1746. settingsMap[setting.id].value = value;
  1747. };
  1748. slider.addEventListener('input', e => updateChannel(e.target.value));
  1749. input.addEventListener('change', e => updateChannel(e.target.value));
  1750. } else if (setting.list) {
  1751. insertElem.insertAdjacentHTML("beforeend", `<div class="tracker-option">${setting.desc}<select id="trackerSetting_${setting.id}"></select></div>`);
  1752. const select = document.querySelector("#trackerSetting_" + setting.id);
  1753. for (const option of params[setting.id]) {
  1754. select.insertAdjacentHTML("beforeend", `<option value="${option}" ${option === setting.value ? "selected" : ""}>${option}</option>`);
  1755. }
  1756. select.addEventListener("change", e => {
  1757. settingsMap[setting.id].value = e.target.value;
  1758. saveSettings();
  1759. });
  1760. }
  1761. }
  1762. }
  1763. insertElem.addEventListener("change", saveSettings);
  1764. }
  1765. }
  1766. setTimeout(() => {
  1767. waitForSettings(params);
  1768. }, 500);
  1769. }
  1770. function saveSettings() {
  1771. localStorage.setItem("tracker_settingsMap", JSON.stringify(settingsMap));
  1772. }
  1773. function readSettings() {
  1774. const ls = localStorage.getItem("tracker_settingsMap");
  1775. if (ls) {
  1776. const lsObj = JSON.parse(ls);
  1777. for (const option of Object.values(lsObj)) {
  1778. if (option.id.startsWith("tracker")) {
  1779. if (settingsMap.hasOwnProperty(option.id)) {
  1780. settingsMap[option.id].isTrue = option.isTrue;
  1781. settingsMap[option.id].trackStyle = option.trackStyle || "auto";
  1782. settingsMap[option.id].r = option.r;
  1783. settingsMap[option.id].g = option.g;
  1784. settingsMap[option.id].b = option.b;
  1785. }
  1786. } else if (option && option.value && option.id && settingsMap[option.id]) {
  1787. settingsMap[option.id].value = option.value;
  1788. }
  1789. }
  1790. }
  1791. }
  1792. const style = document.createElement('style');
  1793. style.textContent = `
  1794. .tracker-option {
  1795. display: flex;
  1796. align-items: left;
  1797. gap: 10px;
  1798. }
  1799.  
  1800. .color-preview {
  1801. cursor: pointer;
  1802. width: 20px;
  1803. height: 20px;
  1804. margin: 3px 3px;
  1805. border: 1px solid #ccc;
  1806. border-radius: 3px;
  1807. }
  1808.  
  1809. .color-picker-modal {
  1810. position: fixed;
  1811. top: 50%;
  1812. left: 50%;
  1813. transform: translate(-50%, -50%);
  1814. background: rgba(0, 0, 0, 0.5);
  1815. padding: 20px;
  1816. border: 1px solid rgba(255, 255, 255, 0.2);
  1817. border-radius: 8px;
  1818. box-shadow: 0 0 20px rgba(0,0,0,0.2);
  1819. z-index: 1000;
  1820. }
  1821.  
  1822. .modal-backdrop {
  1823. position: fixed;
  1824. top: 0;
  1825. left: 0;
  1826. right: 0;
  1827. bottom: 0;
  1828. background: rgba(0,0,0,0.5);
  1829. z-index: 999;
  1830. }
  1831.  
  1832. .modal-actions {
  1833. margin-top: 20px;
  1834. display: flex;
  1835. gap: 10px;
  1836. justify-content: flex-end;
  1837. }
  1838. `;
  1839. document.head.appendChild(style);
  1840.  
  1841. function changeColorAlpha(rgba, alpha) {
  1842. if (rgba.startsWith('rgba')) {
  1843. return rgba.replace(/rgba\(([^,]+),([^,]+),([^,]+),[^)]+\)/, `rgba($1,$2,$3,${alpha})`);
  1844. } else if (rgba.startsWith('rgb')) {
  1845. return rgba.replace(/rgb\(([^,]+),([^,]+),([^,]+)\)/, `rgba($1,$2,$3,${alpha})`);
  1846. } else if (rgba.startsWith('hsl')) {
  1847. return rgba.replace(/hsl\(([^,]+),([^,]+),([^)]+)\)/, `hsla($1,$2,$3,${alpha})`);
  1848. } else if (rgba.startsWith('hsla')) {
  1849. return rgba.replace(/hsla\(([^,]+),([^,]+),([^)]+),[^)]+\)/, `hsla($1,$2,$3,${alpha})`);
  1850. }
  1851. return rgba;
  1852. }
  1853. function getElementCenter(element) {
  1854. const rect = element.getBoundingClientRect();
  1855. if (element.innerText.trim() === '') {
  1856. return {
  1857. x: rect.left + rect.width / 2,
  1858. y: rect.top
  1859. };
  1860. }
  1861. return {
  1862. x: rect.left + rect.width / 2,
  1863. y: rect.top + rect.height / 2
  1864. };
  1865. }
  1866.  
  1867. const shapes = {
  1868. "circle": (ctx, p = {}) => {
  1869. // {x, y, size, color}
  1870. ctx.beginPath();
  1871. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  1872. ctx.fillStyle = p.color;
  1873. ctx.fill();
  1874. },
  1875. "rectangle": (ctx, p = {}) => {
  1876. // {x, y, size, color}
  1877. ctx.beginPath();
  1878. ctx.fillStyle = p.color;
  1879. ctx.fillRect(p.x, p.y, p.size, p.size);
  1880. ctx.closePath();
  1881. },
  1882. "star": (ctx, p = {}) => {
  1883. // {x, y, size, color, angle}
  1884. ctx.save();
  1885. ctx.translate(p.x, p.y);
  1886. ctx.rotate(p.angle);
  1887. const starSize = p.size * 10;
  1888. ctx.beginPath();
  1889. const startAngle = -Math.PI / 2;
  1890. const startX = Math.cos(startAngle) * starSize;
  1891. const startY = Math.sin(startAngle) * starSize;
  1892. ctx.moveTo(startX, startY);
  1893. for (let i = 0; i < 5; i++) {
  1894. const outerAngle = i * 2 * Math.PI / 5 - Math.PI / 2;
  1895. const innerAngle = outerAngle + Math.PI / 5;
  1896. const outerX = Math.cos(outerAngle) * starSize;
  1897. const outerY = Math.sin(outerAngle) * starSize;
  1898. ctx.lineTo(outerX, outerY);
  1899. const innerX = Math.cos(innerAngle) * (starSize / 2);
  1900. const innerY = Math.sin(innerAngle) * (starSize / 2);
  1901. ctx.lineTo(innerX, innerY);
  1902. }
  1903. ctx.closePath();
  1904. ctx.fillStyle = p.color;
  1905. ctx.fill();
  1906. ctx.restore();
  1907. },
  1908. "arrow": (ctx, p = {}) => {
  1909. // {x, y, size, color, velocity, arrowLength, arrowWidth, arrowHeadLength, arrowHeadWidth, fletchingLength, fletchingWidth}
  1910. const length = p.size * (p.arrowLength || 6);
  1911. const width = p.size * (p.arrowWidth || 0.5);
  1912. const arrowHeadLength = p.size * (p.arrowHeadLength || 1.33);
  1913. const arrowHeadWidth = p.size * (p.arrowHeadWidth || 0.80);
  1914. const fletchingLength = p.size * (p.fletchingLength || 2.13);
  1915. const fletchingWidth = p.size * (p.fletchingWidth || 1.33);
  1916. ctx.save();
  1917. ctx.translate(p.x, p.y);
  1918. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  1919. // Draw arrow shaft
  1920. ctx.beginPath();
  1921. ctx.moveTo(-length / 2, -width / 2);
  1922. ctx.lineTo(length / 2 - arrowHeadLength, -width / 2);
  1923. ctx.lineTo(length / 2 - arrowHeadLength, width / 2);
  1924. ctx.lineTo(-length / 2, width / 2);
  1925. ctx.closePath();
  1926. ctx.fillStyle = p.color;
  1927. ctx.fill();
  1928. // Draw arrow head
  1929. ctx.beginPath();
  1930. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  1931. ctx.lineTo(length / 2, 0);
  1932. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  1933. ctx.closePath();
  1934. ctx.fillStyle = p.color;
  1935. ctx.fill();
  1936. // Draw fletchings
  1937. ctx.beginPath();
  1938. ctx.moveTo(-length / 2, -width / 2);
  1939. ctx.lineTo(-length / 2 - fletchingLength, -fletchingWidth / 2);
  1940. ctx.lineTo(-length / 2 - fletchingLength * 0.5, 0);
  1941. ctx.lineTo(-length / 2 - fletchingLength, fletchingWidth / 2);
  1942. ctx.lineTo(-length / 2, width / 2);
  1943. ctx.closePath();
  1944. ctx.fillStyle = p.color;
  1945. ctx.fill();
  1946. ctx.restore();
  1947. }
  1948. };
  1949.  
  1950. /*
  1951. 特效编写请查阅
  1952. https://docs.qq.com/doc/DS0JjVHp3S09td2NV
  1953. */
  1954.  
  1955. const onHitEffectsMap = {
  1956. "smoke": {
  1957. angle: p => Math.random() * Math.PI * 2,
  1958. alpha: p => 0.7,
  1959. speed: p => (Math.random() * 0.2 + 0.1) * Math.sqrt(p.size),
  1960. size: p => (Math.random() * 20 + 10) * p.size,
  1961. life: p => 4000 * Math.sqrt(p.size),
  1962. gravity: p => -0.2 * Math.sqrt(p.size),
  1963. draw: (ctx, p) => {
  1964. if (!p.initialized) {
  1965. p.initialized = true;
  1966. p.y -= 5 * p.size;
  1967. p.sizeVariation = Math.random() * 0.2 + 0.9; // Size variation for billowing effect
  1968. p.rotationSpeed = (Math.random() - 0.5) * 0.02; // Slow rotation
  1969. p.rotation = Math.random() * Math.PI * 2;
  1970. }
  1971. p.speed *= 0.995; // Slower deceleration
  1972. p.x += Math.cos(p.angle) * p.speed;
  1973. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  1974. p.life -= 1;
  1975. p.alpha = Math.max(0, p.alpha - 0.001);
  1976. p.rotation += p.rotationSpeed;
  1977. if (p.life > 0) {
  1978. ctx.save();
  1979. ctx.translate(p.x, p.y);
  1980. ctx.rotate(p.rotation);
  1981.  
  1982. // Draw main smoke puff
  1983. ctx.beginPath();
  1984. ctx.ellipse(0, 0, p.size * p.sizeVariation, p.size, 0, 0, Math.PI * 2);
  1985. ctx.fillStyle = `rgba(80, 80, 80, ${p.alpha * (p.life / 2000)})`;
  1986. ctx.fill();
  1987.  
  1988. // Add some variation to the smoke puff
  1989. ctx.beginPath();
  1990. ctx.ellipse(p.size * 0.3, -p.size * 0.2, p.size * 0.6, p.size * 0.8, 0, 0, Math.PI * 2);
  1991. ctx.fillStyle = `rgba(80, 80, 80, ${p.alpha * 0.7 * (p.life / 2000)})`;
  1992. ctx.fill();
  1993. ctx.restore();
  1994. }
  1995. }
  1996. },
  1997. "ember": {
  1998. angle: p => Math.random() * Math.PI * 2,
  1999. alpha: p => 1,
  2000. speed: p => (Math.random() * 2 + 0.5) * Math.sqrt(p.size),
  2001. size: p => (Math.random() * 6 + 2) * p.size,
  2002. life: p => 1200 * Math.sqrt(p.size),
  2003. gravity: p => 0.3,
  2004. draw: (ctx, p) => {
  2005. p.speed *= 0.99; // 慢慢减速
  2006. p.x += Math.cos(p.angle) * p.speed;
  2007. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2008. p.life -= 3;
  2009. if (p.life > 0) {
  2010. const alpha = p.life / 800;
  2011. ctx.beginPath();
  2012. ctx.arc(p.x, p.y, p.size * (p.life / 800), 0, Math.PI * 2);
  2013. ctx.fillStyle = `${p.color.slice(0, -4)}%, ${alpha})`;
  2014. ctx.fill();
  2015.  
  2016. // 余烬偶尔产生的小火花
  2017. if (Math.random() < 0.03) {
  2018. ctx.beginPath();
  2019. ctx.arc(p.x, p.y, p.size * 1.5, 0, Math.PI * 2);
  2020. ctx.fillStyle = `hsla(30, 100%, 70%, ${alpha * 0.7})`;
  2021. ctx.fill();
  2022. }
  2023. }
  2024. }
  2025. },
  2026. "shockwave": {
  2027. size: p => 10 * p.size,
  2028. life: p => 800 * Math.sqrt(p.size),
  2029. draw: (ctx, p) => {
  2030. if (!p.maxSize) {
  2031. p.maxSize = p.size * (150 + Math.random() * 100) / 10;
  2032. }
  2033. p.size += (p.maxSize - p.size) * 0.1;
  2034. p.life -= 10;
  2035. if (p.life > 0) {
  2036. const alpha = p.life / 400;
  2037. ctx.beginPath();
  2038. ctx.strokeStyle = p.color;
  2039. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  2040. ctx.lineWidth = 5 * alpha;
  2041. ctx.stroke();
  2042. }
  2043. }
  2044. },
  2045. "smallParticle": {
  2046. angle: p => Math.random() * Math.PI * 2,
  2047. size: p => (Math.random() * 12 + 8) * p.size,
  2048. speed: p => (Math.random() * 6 + 2) * Math.sqrt(p.size),
  2049. gravity: p => 0.3 + Math.random() * 0.1,
  2050. life: p => 400 * p.size,
  2051. draw: (ctx, p) => {
  2052. p.size = p.size * (1 - p.life / 400);
  2053. p.x += Math.cos(p.angle) * p.speed;
  2054. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2055. p.life -= 3;
  2056. if (p.life > 0) {
  2057. ctx.beginPath();
  2058. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  2059. ctx.fillStyle = p.color;
  2060. ctx.fill();
  2061. }
  2062. }
  2063. },
  2064. "holyCross": {
  2065. x: p => p.x + (Math.random() - 0.5) * 60,
  2066. y: p => p.y + (Math.random() - 0.5) * 10,
  2067. size: p => (8 * Math.random() + 12) * p.size,
  2068. life: p => 1200 * Math.sqrt(p.size),
  2069. speed: p => 0,
  2070. gravity: p => -0.008 * Math.random() - 0.008,
  2071. draw: (ctx, p) => {
  2072. p.speed += p.gravity;
  2073. p.y += p.speed;
  2074. p.life -= 3;
  2075. if (p.life > 0) {
  2076. ctx.save();
  2077. ctx.translate(p.x, p.y);
  2078. ctx.fillStyle = p.color;
  2079. ctx.fillRect(-p.size / 2, -p.size * 2, p.size, p.size * 4);
  2080. ctx.fillRect(-p.size * 2, -p.size / 2, p.size * 4, p.size);
  2081. ctx.restore();
  2082. }
  2083. }
  2084. },
  2085. "leaf": {
  2086. // Made by HwiteCat
  2087. x: p => p.x + (Math.random() - 0.5) * 60,
  2088. y: p => p.y + (Math.random() - 0.5) * 10,
  2089. angle: p => Math.random() * Math.PI * 2,
  2090. size: p => (12 * Math.random() + 8) * p.size,
  2091. life: p => 1250 * p.size,
  2092. speed: p => (Math.random() * 3 + 1) * Math.sqrt(p.size),
  2093. gravity: p => 0.12,
  2094. draw: (ctx, p) => {
  2095. if (!p.rotation) p.rotation = Math.random() * Math.PI * 2;
  2096. if (!p.rotationSpeed) p.rotationSpeed = (Math.random() - 0.5) * 0.02;
  2097. if (!p.sway) p.sway = (Math.random() - 0.5) * 0.2;
  2098. if (!p.swaySpeed) p.swaySpeed = (Math.random() - 0.5) * 0.02;
  2099. p.speed *= 0.98;
  2100. p.x += Math.cos(p.angle) * p.speed;
  2101. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2102. p.life -= 3;
  2103. if (p.rotation !== undefined) {
  2104. p.rotation += p.rotationSpeed;
  2105. }
  2106. if (p.scale !== undefined) {
  2107. p.scale += p.scaleSpeed;
  2108. p.scale = Math.max(0.1, p.scale);
  2109. }
  2110. if (p.sway !== undefined) {
  2111. p.x += Math.sin(p.y * p.swaySpeed) * p.sway;
  2112. }
  2113. if (p.life > 0) {
  2114. ctx.save();
  2115. ctx.translate(p.x, p.y);
  2116. ctx.rotate(p.rotation);
  2117. ctx.scale(p.scale, 1);
  2118. ctx.beginPath();
  2119. ctx.moveTo(0, -p.size);
  2120. ctx.bezierCurveTo(p.size / 2, -p.size / 2, p.size / 2, 0, 0, p.size);
  2121. ctx.bezierCurveTo(-p.size / 2, 0, -p.size / 2, -p.size / 2, 0, -p.size);
  2122. ctx.fillStyle = p.color;
  2123. ctx.fill();
  2124. ctx.restore();
  2125. }
  2126. }
  2127. },
  2128. "slash": {
  2129. // Main slash effect
  2130. x: p => p.x,
  2131. y: p => p.y,
  2132. angle: p => Math.random() * Math.PI * 2,
  2133. size: p => 3 * p.size,
  2134. life: p => 300 * p.size,
  2135. draw: (ctx, p) => {
  2136. if (!p.length) p.length = p.size * (120 + Math.random() * 80); // More consistent length
  2137. if (!p.maxWidth) p.maxWidth = 1.5 * Math.sqrt(p.size); // Thinner slash
  2138. p.life -= 2; // Even slower fade
  2139.  
  2140. if (p.life > 0) {
  2141. const alpha = p.life / 300 * p.size;
  2142. ctx.save();
  2143. ctx.translate(p.x, p.y);
  2144. ctx.rotate(p.angle);
  2145.  
  2146. // Draw main slash line with improved tapered shape
  2147. ctx.beginPath();
  2148. ctx.moveTo(-p.length / 2, 0);
  2149. ctx.quadraticCurveTo(-p.length / 4, -p.maxWidth * 0.6, -p.length / 6, -p.maxWidth);
  2150. ctx.lineTo(p.length / 6, -p.maxWidth);
  2151. ctx.quadraticCurveTo(p.length / 4, -p.maxWidth * 0.6, p.length / 2, 0);
  2152. ctx.quadraticCurveTo(p.length / 4, p.maxWidth * 0.6, p.length / 6, p.maxWidth);
  2153. ctx.lineTo(-p.length / 6, p.maxWidth);
  2154. ctx.quadraticCurveTo(-p.length / 4, p.maxWidth * 0.6, -p.length / 2, 0);
  2155. ctx.closePath();
  2156. ctx.fillStyle = p.color.replace('0.9', alpha.toString());
  2157. ctx.fill();
  2158.  
  2159. // Enhanced glow effect
  2160. ctx.beginPath();
  2161. ctx.moveTo(-p.length / 2, 0);
  2162. ctx.quadraticCurveTo(-p.length / 4, -p.maxWidth * 0.8, -p.length / 6, -p.maxWidth * 1.5);
  2163. ctx.lineTo(p.length / 6, -p.maxWidth * 1.5);
  2164. ctx.quadraticCurveTo(p.length / 4, -p.maxWidth * 0.8, p.length / 2, 0);
  2165. ctx.quadraticCurveTo(p.length / 4, p.maxWidth * 0.8, p.length / 6, p.maxWidth * 1.5);
  2166. ctx.lineTo(-p.length / 6, p.maxWidth * 1.5);
  2167. ctx.quadraticCurveTo(-p.length / 4, p.maxWidth * 0.8, -p.length / 2, 0);
  2168. ctx.closePath();
  2169. ctx.fillStyle = p.color.replace('0.9', (alpha * 0.3).toString());
  2170. ctx.fill();
  2171. ctx.restore();
  2172. }
  2173. }
  2174. },
  2175. "slashParticle": {
  2176. // Enhanced particle effect for slash
  2177. x: p => p.x + (Math.random() - 0.5) * 15,
  2178. // Tighter initial spread
  2179. y: p => p.y + (Math.random() - 0.5) * 15,
  2180. angle: p => {
  2181. const baseAngle = p.parentAngle || Math.random() * Math.PI * 2;
  2182. return baseAngle + (Math.random() - 0.5) * 0.1; // Very small variation
  2183. },
  2184. size: p => (2 * Math.random() + 2) * p.size,
  2185. // Bigger particles
  2186. life: p => 600 * p.size,
  2187. // Adjusted for faster movement
  2188. speed: p => (Math.random() * 1 + 3) * Math.sqrt(p.size),
  2189. // Much faster speed
  2190. gravity: p => 0.02,
  2191. // Minimal gravity for more directional movement
  2192. draw: (ctx, p) => {
  2193. p.speed *= 0.998; // Very smooth deceleration
  2194. p.x += Math.cos(p.angle) * p.speed;
  2195. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2196. p.life -= 3;
  2197. if (p.life > 0) {
  2198. const alpha = p.life / 400;
  2199. ctx.save();
  2200. ctx.translate(p.x, p.y);
  2201. ctx.rotate(p.angle);
  2202.  
  2203. // Draw particle with more elongation in movement direction
  2204. ctx.beginPath();
  2205. ctx.moveTo(-p.size / 2, 0);
  2206. ctx.quadraticCurveTo(-p.size / 4, -p.size / 2, 0, -p.size * 1.2);
  2207. ctx.quadraticCurveTo(p.size / 4, -p.size / 2, p.size / 2, 0);
  2208. ctx.quadraticCurveTo(p.size / 4, p.size / 2, 0, p.size * 1.2);
  2209. ctx.quadraticCurveTo(-p.size / 4, p.size / 2, -p.size / 2, 0);
  2210. ctx.closePath();
  2211. ctx.fillStyle = p.color.replace('0.9', alpha.toString());
  2212. ctx.fill();
  2213.  
  2214. // Add small glow to particles
  2215. ctx.beginPath();
  2216. ctx.arc(0, 0, p.size * 1.2, 0, Math.PI * 2);
  2217. ctx.fillStyle = p.color.replace('0.9', (alpha * 0.3).toString());
  2218. ctx.fill();
  2219. ctx.restore();
  2220. }
  2221. }
  2222. },
  2223. "waterRipple": {
  2224. x: p => p.x,
  2225. y: p => p.y,
  2226. size: p => 3 * p.size,
  2227. life: p => 1200 * p.size,
  2228. draw: (ctx, p) => {
  2229. if (!p.ripples) {
  2230. p.ripples = [{
  2231. radius: 0,
  2232. opacity: 0.5,
  2233. width: 3,
  2234. speed: 0.7
  2235. },
  2236. // Fast, bright inner ripple
  2237. {
  2238. radius: 0,
  2239. opacity: 0.5,
  2240. width: 2,
  2241. speed: 0.5
  2242. },
  2243. // Medium ripple
  2244. {
  2245. radius: 0,
  2246. opacity: 0.5,
  2247. width: 1.5,
  2248. speed: 0.3
  2249. } // Slow, faint outer ripple
  2250. ];
  2251. }
  2252. p.life -= 1;
  2253.  
  2254. // Update each ripple
  2255. p.ripples.forEach((ripple, index) => {
  2256. // Expand the ripple
  2257. ripple.radius += ripple.speed;
  2258.  
  2259. // Calculate opacity based on radius
  2260. const maxRadius = 30 * p.size;
  2261. const fadeStart = maxRadius * 0.6;
  2262. if (ripple.radius > fadeStart) {
  2263. ripple.opacity *= 0.98; // Gradual fade out
  2264. }
  2265.  
  2266. // Draw the ripple if it's still visible
  2267. if (ripple.opacity > 0.05 && ripple.radius < maxRadius) {
  2268. ctx.beginPath();
  2269. ctx.strokeStyle = p.color.replace('0.8', ripple.opacity.toString());
  2270. ctx.lineWidth = ripple.width * (1 - ripple.radius / maxRadius);
  2271. ctx.arc(p.x, p.y, ripple.radius, 0, Math.PI * 2);
  2272. ctx.stroke();
  2273.  
  2274. // Add a second, fainter ring for more water-like effect
  2275. if (ripple.radius > 5) {
  2276. ctx.beginPath();
  2277. ctx.strokeStyle = p.color.replace('0.8', (ripple.opacity * 0.5).toString());
  2278. ctx.lineWidth = ripple.width * 0.5 * (1 - ripple.radius / maxRadius);
  2279. ctx.arc(p.x, p.y, ripple.radius - 2, 0, Math.PI * 2);
  2280. ctx.stroke();
  2281. }
  2282. }
  2283. });
  2284. }
  2285. },
  2286. "waterSplash": {
  2287. x: p => p.x,
  2288. y: p => p.y,
  2289. size: p => (2 * Math.random() + 5) * p.size,
  2290. // Smaller size
  2291. life: p => 800 * p.size,
  2292. draw: (ctx, p) => {
  2293. if (!p.initialized) {
  2294. p.initialized = true;
  2295. p.particles = [];
  2296. // Create particles in a circular pattern
  2297. const particleCount = 7; // More particles for better coverage
  2298. for (let i = 0; i < particleCount; i++) {
  2299. const angle = i / particleCount * Math.PI * 2;
  2300. // Add some random variation to the angle
  2301. const angleVariation = (Math.random() - 0.5) * 0.5;
  2302. const finalAngle = angle + angleVariation;
  2303.  
  2304. // Create size variation with smaller base size
  2305. const sizeVariation = Math.random() * 1.5 + 0.5; // Random multiplier between 0.5 and 2
  2306. const baseSize = (Math.random() * 0.8 + 0.4) * p.size; // Reduced base size
  2307.  
  2308. p.particles.push({
  2309. x: p.x,
  2310. y: p.y,
  2311. angle: finalAngle,
  2312. speed: (Math.random() * 1.5 + 1) * Math.sqrt(p.size),
  2313. size: baseSize * sizeVariation,
  2314. initialSize: baseSize * sizeVariation,
  2315. life: 800 * p.size,
  2316. gravity: 0.9 + (Math.random() * 0.2 - 0.1) // Slight gravity variation
  2317. });
  2318. }
  2319. }
  2320. p.life -= 2;
  2321.  
  2322. // Update and draw particles
  2323. p.particles.forEach(particle => {
  2324. particle.speed *= 0.98; // Deceleration
  2325. particle.x += Math.cos(particle.angle) * particle.speed;
  2326. particle.y += Math.sin(particle.angle) * particle.speed + particle.gravity;
  2327. particle.life -= 2;
  2328. const lifeRatio = particle.life / (800 * p.size);
  2329. const opacity = lifeRatio * 0.6; // More transparent
  2330. // More dramatic shrinking with cubic easing
  2331. particle.size = particle.initialSize * Math.pow(lifeRatio, 3);
  2332. if (particle.life > 0) {
  2333. ctx.beginPath();
  2334. ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
  2335. ctx.fillStyle = p.color.replace('0.8', opacity.toString());
  2336. ctx.fill();
  2337. }
  2338. });
  2339. }
  2340. },
  2341. "star": {
  2342. x: p => p.x + (Math.random() - 0.5) * 60,
  2343. y: p => p.y + (Math.random() - 0.5) * 10,
  2344. angle: p => Math.random() * Math.PI * 2,
  2345. size: p => (Math.random() * 6 + 2) * p.size,
  2346. life: p => 1200 * Math.sqrt(p.size),
  2347. speed: p => (Math.random() * 6 + 2) * Math.sqrt(p.size),
  2348. gravity: p => -0.1,
  2349. draw: (ctx, p) => {
  2350. if (!p.initialized) {
  2351. p.initialized = true;
  2352. p.y -= 5 * p.size;
  2353. }
  2354. p.speed *= 0.97; // 慢慢减速
  2355. p.x += Math.cos(p.angle) * p.speed;
  2356. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2357. p.life -= 3;
  2358. if (p.life > 0) {
  2359. const alpha = Math.max(0, Math.min(1, p.life / 1200));
  2360. ctx.save();
  2361. ctx.translate(p.x, p.y);
  2362. ctx.rotate(p.angle);
  2363. const starSize = p.size * 10;
  2364. ctx.beginPath();
  2365. const startAngle = -Math.PI / 2;
  2366. const startX = Math.cos(startAngle) * starSize;
  2367. const startY = Math.sin(startAngle) * starSize;
  2368. ctx.moveTo(startX, startY);
  2369. for (let i = 0; i < 5; i++) {
  2370. const outerAngle = i * 2 * Math.PI / 5 - Math.PI / 2;
  2371. const innerAngle = outerAngle + Math.PI / 5;
  2372. const outerX = Math.cos(outerAngle) * starSize;
  2373. const outerY = Math.sin(outerAngle) * starSize;
  2374. ctx.lineTo(outerX, outerY);
  2375. const innerX = Math.cos(innerAngle) * (starSize / 2);
  2376. const innerY = Math.sin(innerAngle) * (starSize / 2);
  2377. ctx.lineTo(innerX, innerY);
  2378. }
  2379. ctx.closePath();
  2380. ctx.fillStyle = p.color.replace(/rgba\(([^,]+),([^,]+),([^,]+),[^)]+\)/, `rgba($1,$2,$3,${alpha})`);
  2381. ctx.fill();
  2382. ctx.restore();
  2383. }
  2384. }
  2385. },
  2386. "pierce": {
  2387. x: p => p.x,
  2388. y: p => p.y,
  2389. size: p => 4 * p.size,
  2390. life: p => 1200 * p.size,
  2391. draw: (ctx, p) => {
  2392. if (!p.initialized) {
  2393. p.initialized = true;
  2394. p.pierceLength = p.size * 16;
  2395. p.pierceWidth = p.size / 10;
  2396. p.time = 0;
  2397. p.ripples = [];
  2398. // Create initial ripples
  2399. for (let i = 0; i < 3; i++) {
  2400. p.ripples.push({
  2401. radius: 0,
  2402. speed: 0.5 + i * 0.2,
  2403. opacity: 0.6 - i * 0.15,
  2404. width: 2 - i * 0.5
  2405. });
  2406. }
  2407. }
  2408. p.life -= 2;
  2409. p.time += 0.1;
  2410. const alpha = p.life / 1200;
  2411. if (p.life > 0) {
  2412. ctx.save();
  2413. ctx.translate(p.x, p.y);
  2414.  
  2415. // Draw dynamic ripples
  2416. p.ripples.forEach(ripple => {
  2417. ripple.radius += ripple.speed;
  2418. const rippleAlpha = ripple.opacity * alpha * (1 - ripple.radius / (p.size * 8));
  2419. if (rippleAlpha > 0.01) {
  2420. ctx.beginPath();
  2421. ctx.strokeStyle = p.color.replace('0.8', rippleAlpha.toString());
  2422. ctx.lineWidth = ripple.width;
  2423. ctx.arc(0, 0, ripple.radius, 0, Math.PI * 2);
  2424. ctx.stroke();
  2425. }
  2426. });
  2427.  
  2428. // 4角星星
  2429. const vertices = {
  2430. top: {
  2431. x: 0,
  2432. y: -p.pierceLength / 2.5
  2433. },
  2434. // Reduced vertical height
  2435. right: {
  2436. x: p.pierceLength,
  2437. y: 0
  2438. },
  2439. // Maintained horizontal stretch
  2440. bottom: {
  2441. x: 0,
  2442. y: p.pierceLength / 2.5
  2443. },
  2444. // Reduced vertical height
  2445. left: {
  2446. x: -p.pierceLength,
  2447. y: 0
  2448. } // Maintained horizontal stretch
  2449. };
  2450.  
  2451. // Define inner points for curved connections (closer to center)
  2452. const innerPoints = {
  2453. topRight: {
  2454. x: p.pierceLength / 7,
  2455. y: -p.pierceLength / 10
  2456. },
  2457. // Moved closer to center
  2458. bottomRight: {
  2459. x: p.pierceLength / 7,
  2460. y: p.pierceLength / 10
  2461. },
  2462. // Moved closer to center
  2463. bottomLeft: {
  2464. x: -p.pierceLength / 7,
  2465. y: p.pierceLength / 10
  2466. },
  2467. // Moved closer to center
  2468. topLeft: {
  2469. x: -p.pierceLength / 7,
  2470. y: -p.pierceLength / 10
  2471. } // Moved closer to center
  2472. };
  2473.  
  2474. // Draw the shape with straight lines
  2475. ctx.beginPath();
  2476. ctx.moveTo(vertices.top.x, vertices.top.y);
  2477.  
  2478. // Draw straight lines between vertices and inner points
  2479. // Top to right
  2480. ctx.lineTo(innerPoints.topRight.x, innerPoints.topRight.y);
  2481. ctx.lineTo(vertices.right.x, vertices.right.y);
  2482.  
  2483. // Right to bottom
  2484. ctx.lineTo(innerPoints.bottomRight.x, innerPoints.bottomRight.y);
  2485. ctx.lineTo(vertices.bottom.x, vertices.bottom.y);
  2486.  
  2487. // Bottom to left
  2488. ctx.lineTo(innerPoints.bottomLeft.x, innerPoints.bottomLeft.y);
  2489. ctx.lineTo(vertices.left.x, vertices.left.y);
  2490.  
  2491. // Left to top
  2492. ctx.lineTo(innerPoints.topLeft.x, innerPoints.topLeft.y);
  2493. ctx.lineTo(vertices.top.x, vertices.top.y);
  2494. ctx.closePath();
  2495.  
  2496. // Add main fill with enhanced opacity
  2497. ctx.fillStyle = p.color.replace('0.8', (alpha * 0.9).toString());
  2498. ctx.fill();
  2499. ctx.restore();
  2500. }
  2501. }
  2502. },
  2503. "poison": {
  2504. x: p => p.x,
  2505. y: p => p.y,
  2506. size: p => 5 * p.size,
  2507. // Increased base size
  2508. life: p => 800 * p.size,
  2509. // Longer lifetime
  2510. draw: (ctx, p) => {
  2511. if (!p.initialized) {
  2512. p.initialized = true;
  2513. p.bubbles = [];
  2514. for (let i = 0; i < 6; i++) {
  2515. // More bubbles
  2516. p.bubbles.push({
  2517. x: p.x + (Math.random() - 0.5) * p.size * 4,
  2518. // Wider spread
  2519. y: p.y + (Math.random() - 0.5) * p.size * 4,
  2520. size: p.size * (Math.random() * 1.2 + 1.2),
  2521. // Bigger bubbles
  2522. speed: Math.random() * 0.8 + 0.4,
  2523. // Faster rise
  2524. wobble: Math.random() * Math.PI * 2,
  2525. // For side-to-side movement
  2526. wobbleSpeed: Math.random() * 0.05 + 0.02
  2527. });
  2528. }
  2529. }
  2530. p.life -= 1;
  2531. const alpha = Math.pow(p.life / p.maxLife, 0.7);
  2532. if (p.life > 0) {
  2533. // Draw main poison cloud
  2534. ctx.beginPath();
  2535. ctx.arc(p.x, p.y, p.size * alpha, 0, Math.PI * 2);
  2536. ctx.fillStyle = changeColorAlpha(p.color, alpha * 0.8);
  2537. ctx.fill();
  2538.  
  2539. // Draw and update bubbles
  2540. p.bubbles.forEach(bubble => {
  2541. bubble.y -= bubble.speed;
  2542. bubble.wobble += bubble.wobbleSpeed;
  2543. bubble.x += Math.sin(bubble.wobble) * 0.5;
  2544. ctx.beginPath();
  2545. ctx.arc(bubble.x, bubble.y, bubble.size, 0, Math.PI * 2);
  2546. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  2547. ctx.fill();
  2548.  
  2549. // Add bubble highlight
  2550. ctx.beginPath();
  2551. ctx.arc(bubble.x - bubble.size * 0.3, bubble.y - bubble.size * 0.3, bubble.size * 0.3, 0, Math.PI * 2);
  2552. ctx.fillStyle = `rgba(255, 255, 255, ${alpha * 0.3})`;
  2553. ctx.fill();
  2554. });
  2555. }
  2556. }
  2557. },
  2558. "ice": {
  2559. x: p => p.x,
  2560. y: p => p.y,
  2561. speed: p => (Math.random() * 3 + 1.5) * Math.sqrt(p.size),
  2562. size: p => (2 * Math.random() + 3) * p.size,
  2563. life: p => 1200 * p.size,
  2564. draw: (ctx, p) => {
  2565. p.length = p.size * 7;
  2566. p.speed *= 0.96;
  2567. p.x += Math.cos(p.angle) * p.speed;
  2568. p.y += Math.sin(p.angle) * p.speed;
  2569. p.life -= 1;
  2570. const lifeRatio = p.life / p.maxLife;
  2571. const alpha = Math.pow(lifeRatio, 0.2);
  2572. if (p.life > 0) {
  2573. ctx.save();
  2574. ctx.translate(p.x, p.y);
  2575. ctx.rotate(p.angle + Math.PI / 2);
  2576. ctx.beginPath();
  2577. ctx.moveTo(0, -p.length / 2);
  2578. ctx.lineTo(p.size / 2, 0);
  2579. ctx.lineTo(0, p.length / 2);
  2580. ctx.lineTo(-p.size / 2, 0);
  2581. ctx.closePath();
  2582. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  2583. ctx.fill();
  2584. ctx.strokeStyle = changeColorAlpha(p.color, alpha);
  2585. ctx.lineWidth = 2;
  2586. ctx.stroke();
  2587.  
  2588. // Add white glow
  2589. ctx.beginPath();
  2590. ctx.moveTo(0, -p.length / 2);
  2591. ctx.lineTo(p.size / 2, 0);
  2592. ctx.lineTo(0, p.length / 2);
  2593. ctx.lineTo(-p.size / 2, 0);
  2594. ctx.closePath();
  2595.  
  2596. // Create gradient for glow
  2597. const gradient = ctx.createLinearGradient(0, -p.length / 2, 0, p.length / 2);
  2598. gradient.addColorStop(0, `rgba(255, 255, 255, ${alpha * 0.8})`);
  2599. gradient.addColorStop(0.5, `rgba(255, 255, 255, ${alpha * 0.4})`);
  2600. gradient.addColorStop(1, `rgba(255, 255, 255, ${alpha * 0.8})`);
  2601. ctx.fillStyle = gradient;
  2602. ctx.fill();
  2603.  
  2604. // Add shiny highlight
  2605. ctx.beginPath();
  2606. ctx.moveTo(-p.size / 4, -p.length / 4);
  2607. ctx.lineTo(p.size / 4, -p.length / 4);
  2608. ctx.lineTo(0, 0);
  2609. ctx.closePath();
  2610. const highlightGradient = ctx.createLinearGradient(-p.size / 4, -p.length / 4, 0, 0);
  2611. highlightGradient.addColorStop(0, `rgba(255, 255, 255, ${alpha * 0.9})`);
  2612. highlightGradient.addColorStop(1, `rgba(255, 255, 255, 0)`);
  2613. ctx.fillStyle = highlightGradient;
  2614. ctx.fill();
  2615. ctx.restore();
  2616. }
  2617. }
  2618. },
  2619. "lava": {
  2620. x: p => p.x + (Math.random() - 0.5) * p.size * 5,
  2621. y: p => p.y + (Math.random() - 0.5) * p.size * 2,
  2622. size: p => (14 * Math.random() + 20) * p.size,
  2623. angle: p => (Math.random() - 0.5) * Math.PI / 5 * 2 - Math.PI / 2,
  2624. speed: p => (Math.random() * 7 + 5) * Math.sqrt(p.size),
  2625. gravity: p => 1.2 + (Math.random() * 0.2 - 0.1),
  2626. life: p => 1200 * p.size,
  2627. draw: (ctx, p) => {
  2628. if (!p.initialized) {
  2629. p.initialized = true;
  2630. p.particles = [];
  2631.  
  2632. // Particle configuration
  2633. const numPoints = 16;
  2634. p.numPoints = numPoints;
  2635. p.noiseOffsets = Array.from({
  2636. length: numPoints
  2637. }, () => Math.random() * Math.PI * 2);
  2638. p.noiseAmplitudes = Array.from({
  2639. length: numPoints
  2640. }, () => Math.random() * 0.15 + 0.85);
  2641. p.noiseSpeeds = Array.from({
  2642. length: numPoints
  2643. }, () => Math.random() * 0.03 + 0.02);
  2644. p.time = 0;
  2645. p.rotation = Math.random() * Math.PI * 2;
  2646. p.rotationSpeed = (Math.random() - 0.5) * 0.05;
  2647. p.oringinalSize = p.size;
  2648. }
  2649. p.life -= 1;
  2650. p.speed *= 0.98;
  2651. p.x += Math.cos(p.angle) * p.speed;
  2652. p.y += Math.sin(p.angle) * p.speed + p.gravity;
  2653. p.life -= 1;
  2654. p.rotation += p.rotationSpeed;
  2655. p.time += 0.15;
  2656. const lifeRatio = p.life / p.maxLife;
  2657. const opacity = lifeRatio * 0.8;
  2658. const sizeReduction = Math.pow(lifeRatio, 0.1);
  2659. p.size = Math.min(p.size * sizeReduction, p.oringinalSize);
  2660. if (p.life > 0) {
  2661. ctx.save();
  2662. ctx.translate(p.x, p.y);
  2663. ctx.rotate(p.rotation);
  2664.  
  2665. // Enable blending for better transparency
  2666. ctx.globalCompositeOperation = 'lighter';
  2667.  
  2668. // Draw base particle shape
  2669. ctx.beginPath();
  2670. for (let i = 0; i < p.numPoints; i++) {
  2671. const angle = i / p.numPoints * Math.PI * 2;
  2672. const noise = Math.sin(angle + p.noiseOffsets[i] + p.time * p.noiseSpeeds[i]) * p.noiseAmplitudes[i];
  2673. const surfaceTension = Math.sin(angle * 3 + p.time * 0.5) * 0.15;
  2674. const radius = p.size * (1 + noise * 0.2 + surfaceTension);
  2675. const x = Math.cos(angle) * radius;
  2676. const y = Math.sin(angle) * radius;
  2677. if (i === 0) {
  2678. ctx.moveTo(x, y);
  2679. } else {
  2680. const prevAngle = (i - 1) / p.numPoints * Math.PI * 2;
  2681. const prevNoise = Math.sin(prevAngle + p.noiseOffsets[i - 1] + p.time * p.noiseSpeeds[i - 1]) * p.noiseAmplitudes[i - 1];
  2682. const prevSurfaceTension = Math.sin(prevAngle * 3 + p.time * 0.5) * 0.15;
  2683. const prevRadius = p.size * (1 + prevNoise * 0.2 + prevSurfaceTension);
  2684. const prevX = Math.cos(prevAngle) * prevRadius;
  2685. const prevY = Math.sin(prevAngle) * prevRadius;
  2686. const cpX = (prevX + x) / 2;
  2687. const cpY = (prevY + y) / 2;
  2688. ctx.quadraticCurveTo(cpX, cpY, x, y);
  2689. }
  2690. }
  2691. ctx.closePath();
  2692.  
  2693. // Draw particle with glow effects
  2694. // Base layer with reduced opacity
  2695. ctx.fillStyle = changeColorAlpha(p.color, opacity);
  2696. ctx.fill();
  2697.  
  2698. // Glow layers with adjusted opacity
  2699. const drawGlowLayer = (radius, color, alpha) => {
  2700. ctx.beginPath();
  2701. ctx.arc(0, 0, radius, 0, Math.PI * 2);
  2702. ctx.fillStyle = changeColorAlpha(p.color, opacity);
  2703. ctx.fill();
  2704. };
  2705.  
  2706. // Core and inner glow with reduced opacity
  2707. drawGlowLayer(p.size * 0.6);
  2708. drawGlowLayer(p.size * (1.2 + Math.sin(p.time * 0.5) * 0.2));
  2709.  
  2710. // Middle aura with softer gradient
  2711. const middleGlow = ctx.createRadialGradient(0, 0, p.size, 0, 0, p.size * 2);
  2712. middleGlow.addColorStop(0, changeColorAlpha(p.color, opacity * 0.2));
  2713. middleGlow.addColorStop(0.5, `rgba(255, 50, 0, ${opacity * 0.1})`);
  2714. middleGlow.addColorStop(1, `rgba(255, 0, 0, 0)`);
  2715. ctx.beginPath();
  2716. ctx.arc(0, 0, p.size * 2, 0, Math.PI * 2);
  2717. ctx.fillStyle = middleGlow;
  2718. ctx.fill();
  2719.  
  2720. // Outer aura with softer gradient
  2721. const outerGlow = ctx.createRadialGradient(0, 0, p.size * 1.5, 0, 0, p.size * (2.5 + Math.sin(p.time * 0.5) * 0.3));
  2722. outerGlow.addColorStop(0, changeColorAlpha(p.color, opacity * 0.1));
  2723. outerGlow.addColorStop(0.5, `rgba(200, 0, 0, ${opacity * 0.03})`);
  2724. outerGlow.addColorStop(1, `rgba(150, 0, 0, 0)`);
  2725. ctx.beginPath();
  2726. ctx.arc(0, 0, p.size * (2.5 + Math.sin(p.time * 0.5) * 0.3), 0, Math.PI * 2);
  2727. ctx.fillStyle = outerGlow;
  2728. ctx.fill();
  2729.  
  2730. // Reset composite operation
  2731. ctx.globalCompositeOperation = 'source-over';
  2732. ctx.restore();
  2733. }
  2734. }
  2735. },
  2736. "tornado": {
  2737. x: p => p.x,
  2738. y: p => p.y + 20,
  2739. size: p => 3 * p.size,
  2740. life: p => 1250 * p.size,
  2741. speed: p => (Math.random() * 3 + 1) * Math.sqrt(p.size),
  2742. gravity: p => 0.12,
  2743. draw: (ctx, p) => {
  2744. if (!p.initialized) {
  2745. p.initialized = true;
  2746. p.particles = [];
  2747. p.maxParticles = 6;
  2748. p.amplitude = 60 * p.size;
  2749. p.frequency = 15;
  2750. p.timeSpeed = 0.8;
  2751. p.maxHeight = 100;
  2752.  
  2753. // Parse the base color once
  2754. const colorMatch = p.color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/);
  2755. if (colorMatch) {
  2756. p.baseColor = {
  2757. r: parseInt(colorMatch[1]),
  2758. g: parseInt(colorMatch[2]),
  2759. b: parseInt(colorMatch[3])
  2760. };
  2761. }
  2762.  
  2763. // Initialize particles with staggered heights
  2764. for (let i = 0; i < p.maxParticles; i++) {
  2765. const startAngle = Math.random() * Math.PI * 2;
  2766. const startRadius = Math.random() * 40 * p.size;
  2767. p.particles.push({
  2768. angle: startAngle,
  2769. radius: Math.random() * 150 + 5,
  2770. height: i / p.maxParticles * p.maxHeight,
  2771. speed: Math.random() * 0.04 + 0.01,
  2772. size: Math.random() * 3 + 2,
  2773. baseSpeed: Math.random() * 0.04 + 0.01,
  2774. startX: Math.cos(startAngle) * startRadius,
  2775. startY: Math.sin(startAngle) * startRadius,
  2776. initialSize: Math.random() * 3 + 2,
  2777. rotation: Math.random() * Math.PI * 2,
  2778. rotationSpeed: (Math.random() - 0.5) * 0.02,
  2779. sway: (Math.random() - 0.5) * 0.2,
  2780. swaySpeed: (Math.random() - 0.5) * 0.02
  2781. });
  2782. }
  2783. }
  2784. p.life -= 3;
  2785. if (p.life > 0) {
  2786. const alpha = p.life;
  2787. for (let particle of p.particles) {
  2788. const heightRatio = particle.height / p.maxHeight;
  2789. const currentSpeed = particle.baseSpeed * Math.pow(1 - heightRatio, 3);
  2790. particle.angle += p.frequency * currentSpeed * p.timeSpeed;
  2791. particle.radius += (Math.random() - 0.5) * 0.5;
  2792. particle.height += 1.5 * p.timeSpeed;
  2793.  
  2794. // Add leaf-like movement
  2795. particle.rotation += particle.rotationSpeed;
  2796. if (particle.sway !== undefined) {
  2797. particle.startX += Math.sin(particle.height * particle.swaySpeed) * particle.sway;
  2798. }
  2799. if (particle.height > p.maxHeight) {
  2800. particle.height = 0;
  2801. const startAngle = Math.random() * Math.PI * 2;
  2802. const startRadius = Math.random() * 40 * p.size;
  2803. particle.startX = Math.cos(startAngle) * startRadius;
  2804. particle.startY = Math.sin(startAngle) * startRadius;
  2805. particle.angle = startAngle;
  2806. particle.initialSize = Math.random() * 3 + 2;
  2807. particle.rotation = Math.random() * Math.PI * 2;
  2808. particle.rotationSpeed = (Math.random() - 0.5) * 0.02;
  2809. particle.sway = (Math.random() - 0.5) * 0.2;
  2810. particle.swaySpeed = (Math.random() - 0.5) * 0.02;
  2811. }
  2812. const spiral = particle.height / p.maxHeight * p.amplitude;
  2813. const x = p.x + particle.startX + Math.cos(particle.angle) * spiral;
  2814. const y = p.y - particle.height + particle.startY;
  2815.  
  2816. // Calculate current size based on height and apply size limit
  2817. const currentSize = Math.min(particle.initialSize * (1 - heightRatio * 0.7) * p.size, Math.min(Math.ceil(p.size * 6), 10));
  2818.  
  2819. // Calculate gradient color based on height
  2820. const gradientFactor = heightRatio * 1; // 100% 上面白
  2821. const r = Math.min(255, p.baseColor.r + (255 - p.baseColor.r) * gradientFactor);
  2822. const g = Math.min(255, p.baseColor.g + (255 - p.baseColor.g) * gradientFactor);
  2823. const b = Math.min(255, p.baseColor.b + (255 - p.baseColor.b) * gradientFactor);
  2824.  
  2825. // Draw main particle with size reduction
  2826. ctx.save();
  2827. ctx.translate(x, y);
  2828. ctx.rotate(particle.rotation);
  2829. ctx.beginPath();
  2830. ctx.arc(0, 0, currentSize, 0, Math.PI * 2);
  2831. ctx.fillStyle = `rgba(${Math.floor(r)}, ${Math.floor(g)}, ${Math.floor(b)}, ${alpha * 0.8})`;
  2832. ctx.fill();
  2833.  
  2834. // Add glow effect with size reduction
  2835. ctx.beginPath();
  2836. ctx.arc(0, 0, currentSize * 1.5, 0, Math.PI * 2);
  2837. ctx.fillStyle = `rgba(${Math.floor(r)}, ${Math.floor(g)}, ${Math.floor(b)}, ${alpha * 0.3})`;
  2838. ctx.fill();
  2839. ctx.restore();
  2840. }
  2841. }
  2842. }
  2843. },
  2844. "pixelSmoke": {
  2845. x: p => p.x + (Math.random() - 0.5) * 80,
  2846. y: p => p.y + (Math.random() - 0.5) * 80,
  2847. angle: p => (Math.random() - 0.5) * Math.PI / 5 * 2 - Math.PI / 2,
  2848. color: p => `hsl(0, 0%, ${Math.round(Math.random() * 65 + 10)}%)`,
  2849. size: p => (Math.random() * 40 + 10) * p.size,
  2850. speed: p => Math.random() * 0.5 * Math.sqrt(p.size),
  2851. gravity: p => -0.3 + Math.random() * 0.2 * p.size,
  2852. life: p => Math.floor((Math.random() * 700 + 100) * p.size),
  2853. draw: (ctx, p) => {
  2854. const alpha = Math.pow(p.life / p.maxLife, 0.2);
  2855. p.x += Math.cos(p.angle) * p.speed * 0.3;
  2856. p.speed *= 0.992;
  2857. p.y += -Math.sin(p.speed) * 0.5;
  2858. p.color = changeColorAlpha(p.color, alpha);
  2859. p.life -= 1;
  2860. if (p.life > 0) {
  2861. shapes.rectangle(ctx, p);
  2862. }
  2863. }
  2864. }
  2865. };
  2866.  
  2867. /*
  2868. 特效编写请查阅
  2869. https://docs.qq.com/doc/DS0JjVHp3S09td2NV
  2870. */
  2871.  
  2872. const projectileEffectsMap = {
  2873. 'fireball': {
  2874. speedFactor: 1,
  2875. trailLength: 35,
  2876. shake: true,
  2877. onHit: {
  2878. "smoke": size => Math.min(Math.ceil(size * 4), 8),
  2879. "ember": size => Math.min(Math.ceil(size * 10), 40),
  2880. "shockwave": size => Math.min(Math.ceil(size), 4),
  2881. "smallParticle": size => Math.min(Math.ceil(size * 4), 10)
  2882. },
  2883. onCrit: {
  2884. "star": size => Math.min(Math.ceil(size * 10), 20)
  2885. },
  2886. draw: (ctx, p) => {
  2887. ctx.beginPath();
  2888. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  2889. ctx.fillStyle = p.color;
  2890. ctx.fill();
  2891. },
  2892. glow: (ctx, p) => {
  2893. const gradient = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 2);
  2894. gradient.addColorStop(0, `${p.color}`);
  2895. gradient.addColorStop(1, `${p.color}`);
  2896. ctx.fillStyle = gradient;
  2897. },
  2898. trail: (ctx, p, i) => {
  2899. const alpha = i / p.totalLength;
  2900. ctx.beginPath();
  2901. ctx.arc(p.x, p.y, p.size * alpha, 0, Math.PI * 2);
  2902. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  2903. ctx.fill();
  2904. }
  2905. },
  2906. 'nature': {
  2907. speedFactor: 1,
  2908. gravity: 0.1,
  2909. trailLength: 60,
  2910. shake: true,
  2911. onHit: {
  2912. "leaf": size => Math.min(Math.ceil(size * 30), 32)
  2913. },
  2914. draw: (ctx, p) => {
  2915. const size = p.size * 3;
  2916. p.rotation = Math.atan2(p.velocity.y, p.velocity.x) - Math.PI / 2;
  2917. ctx.save();
  2918. ctx.translate(p.x, p.y);
  2919. ctx.rotate(p.rotation);
  2920. ctx.scale(p.scale, 1);
  2921. ctx.beginPath();
  2922. ctx.moveTo(0, -size);
  2923. ctx.bezierCurveTo(size / 2, -size / 2, size / 2, 0, 0, size);
  2924. ctx.bezierCurveTo(-size / 2, 0, -size / 2, -size / 2, 0, -size);
  2925. ctx.fillStyle = p.color;
  2926. ctx.fill();
  2927. ctx.restore();
  2928. },
  2929. trail: (ctx, p, i) => {
  2930. const alpha = i / p.totalLength;
  2931. p.x = p.x + (Math.random() - 0.5) * 5;
  2932. p.y = p.y - (Math.random() - 0.5) * 1 + 0.02;
  2933. ctx.beginPath();
  2934. const lineWidth = p.size * Math.sqrt(alpha);
  2935. ctx.strokeStyle = `${changeColorAlpha(p.color, alpha)}`;
  2936. ctx.lineWidth = lineWidth;
  2937. ctx.moveTo(p.x, p.y);
  2938. ctx.lineTo(p.x + (Math.random() - 0.5) * 20, p.y + (Math.random() - 0.5) * 20);
  2939. ctx.stroke();
  2940. ctx.fill();
  2941. }
  2942. },
  2943. 'slash': {
  2944. speedFactor: 2,
  2945. gravity: -0.2,
  2946. trailLength: 30,
  2947. shake: true,
  2948. onHit: {
  2949. "slash": size => Math.min(Math.ceil(size * 4), 8),
  2950. "slashParticle": size => Math.min(Math.ceil(size * 8), 20)
  2951. }
  2952. // draw: (ctx, p) => {
  2953. // ctx.beginPath();
  2954. // ctx.moveTo(p.x, p.y + p.size * 2);
  2955. // ctx.lineTo(p.x - p.size * 2, p.y - p.size * 2);
  2956. // ctx.lineTo(p.x + p.size * 2, p.y - p.size * 2);
  2957. // ctx.closePath();
  2958. // ctx.fillStyle = p.color;
  2959. // ctx.fill();
  2960. // }
  2961. },
  2962. 'water': {
  2963. speedFactor: 1.2,
  2964. trailLength: 60,
  2965. shake: true,
  2966. onHit: {
  2967. "waterRipple": size => Math.min(Math.ceil(size * 8), 12),
  2968. "waterSplash": size => Math.min(Math.ceil(size * 8), 20)
  2969. },
  2970. draw: (ctx, p) => {
  2971. ctx.beginPath();
  2972. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  2973. ctx.fillStyle = p.color;
  2974. ctx.fill();
  2975. },
  2976. trail: (ctx, p, i) => {
  2977. const alpha = i / p.totalLength;
  2978. p.x = p.x + (Math.random() - 0.5) * 5;
  2979. p.y = p.y - (Math.random() - 0.5) * 1;
  2980. ctx.beginPath();
  2981. ctx.arc(p.x, p.y, p.size * alpha, 0, Math.PI * 2);
  2982. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  2983. ctx.fill();
  2984. }
  2985. },
  2986. 'heal': {
  2987. trailLength: 60,
  2988. shake: false,
  2989. color: 'rgba(93, 212, 93, 0.8)',
  2990. onHit: {
  2991. "holyCross": size => Math.min(Math.ceil(size * 12), 10)
  2992. },
  2993. draw: (ctx, p) => {
  2994. ctx.beginPath();
  2995. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  2996. ctx.fillStyle = p.color;
  2997. ctx.fill();
  2998. }
  2999. },
  3000. 'range': {
  3001. speedFactor: 1.5,
  3002. gravity: 0.15,
  3003. trailLength: 30,
  3004. shake: true,
  3005. onHit: {
  3006. "shockwave": size => Math.min(Math.ceil(size), 4),
  3007. "slashParticle": size => Math.min(Math.ceil(size * 8), 20)
  3008. },
  3009. draw: (ctx, p) => {
  3010. const length = p.size * 6.65;
  3011. const width = p.size * 0.47;
  3012. const arrowHeadLength = p.size * 1.33;
  3013. const arrowHeadWidth = p.size * 0.80;
  3014. const fletchingLength = p.size * 2.13;
  3015. const fletchingWidth = p.size * 1.33;
  3016. ctx.save();
  3017. ctx.translate(p.x, p.y);
  3018. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  3019.  
  3020. // Draw arrow shaft
  3021. ctx.beginPath();
  3022. ctx.moveTo(-length / 2, -width / 2);
  3023. ctx.lineTo(length / 2 - arrowHeadLength, -width / 2);
  3024. ctx.lineTo(length / 2 - arrowHeadLength, width / 2);
  3025. ctx.lineTo(-length / 2, width / 2);
  3026. ctx.closePath();
  3027. ctx.fillStyle = p.color;
  3028. ctx.fill();
  3029.  
  3030. // Draw arrow head
  3031. ctx.beginPath();
  3032. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  3033. ctx.lineTo(length / 2, 0);
  3034. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  3035. ctx.closePath();
  3036. ctx.fillStyle = p.color;
  3037. ctx.fill();
  3038.  
  3039. // Draw fletchings
  3040. ctx.beginPath();
  3041. ctx.moveTo(-length / 2, -width / 2);
  3042. ctx.lineTo(-length / 2 - fletchingLength, -fletchingWidth / 2);
  3043. ctx.lineTo(-length / 2 - fletchingLength * 0.5, 0);
  3044. ctx.lineTo(-length / 2 - fletchingLength, fletchingWidth / 2);
  3045. ctx.lineTo(-length / 2, width / 2);
  3046. ctx.closePath();
  3047. ctx.fillStyle = p.color;
  3048. ctx.fill();
  3049. ctx.restore();
  3050. },
  3051. trail: (ctx, p, i) => {
  3052. // Only show trail after the arrow has traveled some distance
  3053. const startDelay = 5; // Number of frames to wait before showing trail
  3054. if (i < startDelay) return;
  3055. const trailLength = p.size * 20;
  3056. const trailWidth = p.size * 0.27;
  3057. ctx.save();
  3058. ctx.translate(p.x, p.y);
  3059. ctx.rotate(Math.atan2(p.vY, p.vX));
  3060.  
  3061. // Draw simple line trail behind the arrow
  3062. ctx.beginPath();
  3063. ctx.moveTo(-trailLength / 2, -trailWidth / 2);
  3064. ctx.lineTo(0, -trailWidth / 2); // Only draw up to the arrow's position
  3065. ctx.lineTo(0, trailWidth / 2);
  3066. ctx.lineTo(-trailLength / 2, trailWidth / 2);
  3067. ctx.closePath();
  3068. ctx.fillStyle = 'rgba(255, 255, 255, 0.1)'; // Fixed low opacity white
  3069. ctx.fill();
  3070. ctx.restore();
  3071. }
  3072. },
  3073. 'selfHeal': {
  3074. speedFactor: 10,
  3075. trailLength: 0,
  3076. gravity: 0,
  3077. shake: false,
  3078. color: 'rgba(93, 212, 93, 0.5)',
  3079. onHit: {
  3080. "holyCross": size => Math.min(Math.ceil(size * 12), 10)
  3081. },
  3082. draw: (ctx, p) => {}
  3083. },
  3084. 'selfManaRegen': {
  3085. speedFactor: 10,
  3086. trailLength: 0,
  3087. gravity: 0,
  3088. shake: false,
  3089. color: 'rgba(68, 120, 241, 0.8)',
  3090. onHit: {
  3091. "holyCross": size => Math.min(Math.ceil(size * 12), 10)
  3092. },
  3093. draw: (ctx, p) => {}
  3094. },
  3095. 'debug': {
  3096. speedFactor: 2,
  3097. trailLength: 3,
  3098. shake: true,
  3099. onHit: {
  3100. "pixelSmoke": size => Math.min(Math.ceil(size * 80), 50)
  3101. },
  3102. draw: (ctx, p) => {
  3103. ctx.beginPath();
  3104. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3105. ctx.fillStyle = p.color;
  3106. ctx.fill();
  3107. }
  3108. },
  3109. 'lavaPlume': {
  3110. speedFactor: 0.8,
  3111. trailLength: 40,
  3112. gravity: 0.1,
  3113. shake: true,
  3114. onHit: {
  3115. "lava": size => Math.min(Math.ceil(size * 20), 20),
  3116. "smallParticle": size => Math.min(Math.ceil(size * 10), 60)
  3117. },
  3118. draw: (ctx, p) => {
  3119. // Draw main projectile
  3120. ctx.beginPath();
  3121. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3122. ctx.fillStyle = p.color;
  3123. ctx.fill();
  3124.  
  3125. // Create inner glow gradient
  3126. const innerGlow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 1.5);
  3127. innerGlow.addColorStop(0, 'rgba(255, 255, 255, 0.8)');
  3128. innerGlow.addColorStop(0.5, p.color);
  3129. innerGlow.addColorStop(1, 'rgba(255, 0, 0, 0)');
  3130. ctx.beginPath();
  3131. ctx.arc(p.x, p.y, p.size * 1.5, 0, Math.PI * 2);
  3132. ctx.fillStyle = innerGlow;
  3133. ctx.fill();
  3134. },
  3135. glow: (ctx, p) => {
  3136. // Create outer glow gradient
  3137. const outerGlow = ctx.createRadialGradient(p.x, p.y, p.size * 1.5, p.x, p.y, p.size * 4);
  3138. outerGlow.addColorStop(0, p.color);
  3139. // outerGlow.addColorStop(0.5, 'rgba(250, 178, 24, 0.2)');
  3140. outerGlow.addColorStop(1, 'rgba(255, 50, 0, 0)');
  3141. ctx.beginPath();
  3142. ctx.arc(p.x, p.y, p.size * 4, 0, Math.PI * 2);
  3143. ctx.fillStyle = outerGlow;
  3144. ctx.fill();
  3145.  
  3146. // Add pulsing effect
  3147. const pulseSize = p.size * (3 + Math.sin(Date.now() * 0.01) * 0.5);
  3148. const pulseGlow = ctx.createRadialGradient(p.x, p.y, p.size * 2, p.x, p.y, pulseSize);
  3149. pulseGlow.addColorStop(0, changeColorAlpha(p.color, 0.1));
  3150. pulseGlow.addColorStop(1, 'rgba(255, 100, 0, 0)');
  3151. ctx.beginPath();
  3152. ctx.arc(p.x, p.y, pulseSize, 0, Math.PI * 2);
  3153. ctx.fillStyle = pulseGlow;
  3154. ctx.fill();
  3155. },
  3156. trail: (ctx, p, i) => {
  3157. const alpha = i / p.totalLength;
  3158. const trailSize = p.size * alpha;
  3159.  
  3160. // Create glowing trail gradient
  3161. // const trailGlow = ctx.createRadialGradient(
  3162. // p.x, p.y, 0,
  3163. // p.x, p.y, trailSize * 2
  3164. // );
  3165. // trailGlow.addColorStop(0, changeColorAlpha(p.color, alpha));
  3166. // trailGlow.addColorStop(1, changeColorAlpha(p.color, 0));
  3167.  
  3168. ctx.beginPath();
  3169. ctx.arc(p.x, p.y, trailSize * 2, 0, Math.PI * 2);
  3170. ctx.fillStyle = changeColorAlpha(p.color, alpha);
  3171. ctx.fill();
  3172. }
  3173. },
  3174. 'iceBlast': {
  3175. speedFactor: 1.3,
  3176. trailLength: 35,
  3177. shake: true,
  3178. onHit: {
  3179. "ice": size => Math.min(Math.ceil(size * 30), 40)
  3180. },
  3181. draw: (ctx, p) => {
  3182. const length = p.size * 6.65;
  3183. const arrowHeadLength = p.size * 3;
  3184. const arrowHeadWidth = p.size * 2;
  3185.  
  3186. // Draw main projectile
  3187. ctx.save();
  3188. ctx.translate(p.x, p.y);
  3189. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  3190.  
  3191. // Draw arrow head
  3192. ctx.beginPath();
  3193. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  3194. ctx.lineTo(length / 2, 0);
  3195. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  3196. ctx.closePath();
  3197. ctx.fillStyle = p.color;
  3198. ctx.fill();
  3199. ctx.restore();
  3200. },
  3201. glow: (ctx, p) => {
  3202. // Create outer glow gradient
  3203. const outerGlow = ctx.createRadialGradient(p.x, p.y, p.size * 1.5, p.x, p.y, p.size * 4);
  3204. outerGlow.addColorStop(0, 'rgba(200, 230, 255, 0.3)');
  3205. outerGlow.addColorStop(0.5, 'rgba(150, 200, 255, 0.2)');
  3206. outerGlow.addColorStop(1, 'rgba(100, 150, 255, 0)');
  3207. const length = p.size * 6.65;
  3208. const arrowHeadLength = p.size * 3;
  3209. const arrowHeadWidth = p.size * 2;
  3210. ctx.beginPath();
  3211. ctx.moveTo(length / 3 - arrowHeadLength, -arrowHeadWidth / 2);
  3212. ctx.lineTo(length / 2, 0);
  3213. ctx.lineTo(length / 3 - arrowHeadLength, arrowHeadWidth / 2);
  3214. ctx.closePath();
  3215. ctx.fillStyle = p.color;
  3216. ctx.fill();
  3217. },
  3218. trail: (ctx, p, i) => {
  3219. const alpha = i / p.totalLength;
  3220. const trailSize = p.size * (1 + Math.sin(Date.now() * 0.01) * 0.2);
  3221.  
  3222. // Create glowing trail gradient
  3223. const trailGlow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, trailSize * 2);
  3224. trailGlow.addColorStop(0, changeColorAlpha(p.color, alpha));
  3225. trailGlow.addColorStop(1, `rgba(150, 200, 255, 0)`);
  3226. ctx.beginPath();
  3227. ctx.arc(p.x, p.y, trailSize, 0, Math.PI * 2);
  3228. ctx.fillStyle = trailGlow;
  3229. ctx.fill();
  3230. }
  3231. },
  3232. 'poisonDust': {
  3233. speedFactor: 1,
  3234. trailLength: 35,
  3235. shake: true,
  3236. onHit: {
  3237. "poison": size => Math.min(Math.ceil(size * 8), 12)
  3238. },
  3239. draw: (ctx, p) => {
  3240. // Draw main projectile
  3241. ctx.beginPath();
  3242. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3243. ctx.fillStyle = p.color;
  3244. ctx.fill();
  3245.  
  3246. // Create inner glow gradient
  3247. const innerGlow = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.size * 1.5);
  3248. innerGlow.addColorStop(0, 'rgba(255, 255, 255, 0.8)');
  3249. innerGlow.addColorStop(0.5, changeColorAlpha(p.color, 0.5));
  3250. innerGlow.addColorStop(1, 'rgba(50, 200, 50, 0)');
  3251. ctx.beginPath();
  3252. ctx.arc(p.x, p.y, p.size * 1.5, 0, Math.PI * 2);
  3253. ctx.fillStyle = innerGlow;
  3254. ctx.fill();
  3255. },
  3256. glow: (ctx, p) => {
  3257. // Create outer glow gradient
  3258. const outerGlow = ctx.createRadialGradient(p.x, p.y, p.size * 1.5, p.x, p.y, p.size * 4);
  3259. outerGlow.addColorStop(0, changeColorAlpha(p.color, 0.5));
  3260. // outerGlow.addColorStop(0.5, 'rgba(50, 200, 50, 0.2)');
  3261. outerGlow.addColorStop(1, 'rgba(0, 150, 0, 0)');
  3262. ctx.beginPath();
  3263. ctx.arc(p.x, p.y, p.size * 4, 0, Math.PI * 2);
  3264. ctx.fillStyle = outerGlow;
  3265. ctx.fill();
  3266. },
  3267. trail: (ctx, p, i) => {
  3268. const alpha = i / p.totalLength;
  3269. p.x = p.x + (Math.random() - 0.5) * 5;
  3270. p.y = p.y - (Math.random() - 0.5) * 1 + 0.02;
  3271. ctx.beginPath();
  3272. const lineWidth = p.size * Math.sqrt(alpha);
  3273. ctx.strokeStyle = `${changeColorAlpha(p.color, alpha)}`;
  3274. ctx.lineWidth = lineWidth;
  3275. ctx.moveTo(p.x, p.y);
  3276. ctx.lineTo(p.x + (Math.random() - 0.5) * 20, p.y + (Math.random() - 0.5) * 20);
  3277. ctx.stroke();
  3278. ctx.fill();
  3279. }
  3280. },
  3281. 'thrust': {
  3282. speedFactor: 3,
  3283. gravity: -0.001,
  3284. trailLength: 0,
  3285. shake: true,
  3286. onHit: {
  3287. "smallParticle": size => Math.min(Math.ceil(size * 4), 10),
  3288. "pierce": size => Math.min(Math.ceil(size * 4), 6),
  3289. "shockwave": size => Math.min(Math.ceil(size * 2), 6)
  3290. },
  3291. draw: (ctx, p) => {
  3292. const shaftLength = p.size * 12; // Longer shaft
  3293. const shaftWidth = p.size * 0.8; // Thicker shaft
  3294. const tipLength = p.size * 3; // Length of the pointed tip
  3295. const tipWidth = p.size * 1.2; // Width at the base of the tip
  3296.  
  3297. ctx.save();
  3298. ctx.translate(p.x, p.y);
  3299. ctx.rotate(Math.atan2(p.velocity.y, p.velocity.x));
  3300.  
  3301. // Draw shaft
  3302. ctx.beginPath();
  3303. ctx.moveTo(-shaftLength / 2, -shaftWidth / 2);
  3304. ctx.lineTo(shaftLength / 2 - tipLength, -shaftWidth / 2);
  3305. ctx.lineTo(shaftLength / 2 - tipLength, shaftWidth / 2);
  3306. ctx.lineTo(-shaftLength / 2, shaftWidth / 2);
  3307. ctx.closePath();
  3308. ctx.fillStyle = p.color;
  3309. ctx.fill();
  3310.  
  3311. // Draw tip
  3312. ctx.beginPath();
  3313. ctx.moveTo(shaftLength / 2 - tipLength, -tipWidth / 2);
  3314. ctx.lineTo(shaftLength / 2, 0);
  3315. ctx.lineTo(shaftLength / 2 - tipLength, tipWidth / 2);
  3316. ctx.closePath();
  3317. ctx.fillStyle = p.color;
  3318. ctx.fill();
  3319.  
  3320. // Add highlight to shaft
  3321. ctx.beginPath();
  3322. ctx.moveTo(-shaftLength / 2, -shaftWidth / 2);
  3323. ctx.lineTo(shaftLength / 2 - tipLength, -shaftWidth / 2);
  3324. ctx.lineTo(shaftLength / 2 - tipLength, 0);
  3325. ctx.lineTo(-shaftLength / 2, 0);
  3326. ctx.closePath();
  3327. ctx.fillStyle = 'rgba(255, 255, 255, 0.4)';
  3328. ctx.fill();
  3329.  
  3330. // Add highlight to tip
  3331. ctx.beginPath();
  3332. ctx.moveTo(shaftLength / 2 - tipLength, -tipWidth / 2);
  3333. ctx.lineTo(shaftLength / 2, 0);
  3334. ctx.lineTo(shaftLength / 2 - tipLength, 0);
  3335. ctx.closePath();
  3336. ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
  3337. ctx.fill();
  3338. ctx.restore();
  3339. }
  3340. },
  3341. 'fireTornado': {
  3342. speedFactor: 2,
  3343. trailLength: 3,
  3344. shake: true,
  3345. onHit: {
  3346. "tornado": size => Math.min(Math.ceil(size * 5), 8)
  3347. },
  3348. draw: (ctx, p) => {
  3349. ctx.beginPath();
  3350. ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
  3351. ctx.fillStyle = p.color;
  3352. ctx.fill();
  3353. }
  3354. }
  3355. };
  3356.  
  3357. const abilityEffectsMap = {
  3358. 'autoAttack': 'slash',
  3359. 'default': 'fireball',
  3360. 'heal': 'heal',
  3361. '/abilities/fireball': "fireball",
  3362. '/abilities/firestorm': "fireTornado",
  3363. '/abilities/flame_blast': "lavaPlume",
  3364. '/abilities/smoke_burst': "fireball",
  3365. '/abilities/aqua_arrow': "water",
  3366. '/abilities/frost_surge': "iceBlast",
  3367. '/abilities/ice_spear': "iceBlast",
  3368. '/abilities/mana_spring': "water",
  3369. '/abilities/water_strike': "water",
  3370. '/abilities/entangle': "nature",
  3371. '/abilities/natures_veil': "nature",
  3372. '/abilities/toxic_pollen': "poisonDust",
  3373. '/abilities/penetrating_shot': "range",
  3374. '/abilities/pestilent_shot': "range",
  3375. '/abilities/steady_shot': "range",
  3376. '/abilities/quick_shot': "range",
  3377. '/abilities/rain_of_arrows': "range",
  3378. '/abilities/silencing_shot': "range",
  3379. '/abilities/crippling_slash': "slash",
  3380. '/abilities/penetrating_strike': "slash",
  3381. '/abilities/impale': "thrust",
  3382. '/abilities/maim': "slash",
  3383. '/abilities/poke': "thrust",
  3384. '/abilities/puncture': "thrust",
  3385. '/abilities/scratch': "slash",
  3386. '/abilities/smack': "slash",
  3387. '/abilities/sweep': "slash",
  3388. '/abilities/stunning_blow': "slash"
  3389. };
  3390.  
  3391. let activeEffects = [];
  3392. function addEffect({
  3393. effects,
  3394. active = true,
  3395. lifespan = 120,
  3396. color = "rgba(255, 255, 255, 0.8)",
  3397. otherInfo = {},
  3398. isFpsOptimization = false
  3399. }) {
  3400. activeEffects.push({
  3401. effects,
  3402. active,
  3403. life: 0,
  3404. lifespan,
  3405. color,
  3406. otherInfo,
  3407. isFpsOptimization
  3408. });
  3409. }
  3410. function clearEffects() {
  3411. activeEffects.splice(0, activeEffects.length);
  3412. }
  3413.  
  3414. function applyShakeEffect(element, intensity = 1, duration = 500) {
  3415. if (!element) return;
  3416.  
  3417. // Store the element's original position/transform
  3418. const originalTransform = element.style.transform || '';
  3419. const originalTransition = element.style.transition || '';
  3420. intensity *= settingsMap.shakeEffectScale.value || 1;
  3421.  
  3422. // Scale intensity based on size/damage
  3423. const scaledIntensity = Math.min(10, intensity);
  3424.  
  3425. // Apply CSS animation
  3426. element.style.transition = 'transform 50ms ease-in-out';
  3427. let shakeCount = 0;
  3428. const maxShakes = Math.ceil(intensity);
  3429. const shakeInterval = 50;
  3430. const interval = setInterval(() => {
  3431. if (shakeCount >= maxShakes) {
  3432. // Ensure element returns to original position
  3433. clearInterval(interval);
  3434. element.style.transform = originalTransform;
  3435. element.style.transition = originalTransition;
  3436. return;
  3437. }
  3438.  
  3439. // Random offset for shaking effect
  3440. const xOffset = (Math.random() - 0.5) * 2 * scaledIntensity;
  3441. const yOffset = (Math.random() - 0.5) * 2 * scaledIntensity;
  3442. element.style.transform = `${originalTransform} translate(${xOffset}px, ${yOffset}px)`;
  3443. shakeCount++;
  3444. }, shakeInterval);
  3445.  
  3446. // Additional safeguard: ensure element returns to original position after max duration
  3447. setTimeout(() => {
  3448. clearInterval(interval);
  3449. element.style.transform = 'translate(0, 0)';
  3450. element.style.transition = originalTransition;
  3451. }, shakeInterval * (maxShakes + 1)); // Slightly longer than maxShakes * interval time
  3452. }
  3453. function addDamageHPBar(element, damage) {
  3454. const hpBarContainer = element.querySelector(".HitpointsBar_hitpointsBar__2vIqC");
  3455. const hpBarFront = hpBarContainer.querySelector(".HitpointsBar_currentHp__5exLr");
  3456. // hpBarFront.style.zIndex = "1";
  3457. const hpBarValue = hpBarContainer.querySelector(".HitpointsBar_hpValue__xNp7m");
  3458. // hpBarValue.style.zIndex = "2";
  3459. const hpStat = hpBarValue.innerHTML.split("/");
  3460. const currentHp = parseInt(hpStat[0]);
  3461. const maxHp = parseInt(hpStat[1]);
  3462.  
  3463. // Insert a HpBar behind and set the color to red
  3464. const hpBarBack = document.createElement("div");
  3465. hpBarBack.className = "HitpointsBar_currentHp__5exLr HitTracker_hpDrop";
  3466. hpBarBack.style.background = "var(--color-warning)";
  3467. hpBarBack.style.position = "absolute";
  3468. hpBarBack.style.top = "0px";
  3469. hpBarBack.style.left = "0px";
  3470. // hpBarBack.style.zIndex = "1"; // Ensure the back bar is below the front bar
  3471. hpBarBack.style.width = `${hpBarFront.offsetWidth}px`;
  3472. hpBarBack.style.height = `${hpBarFront.offsetHeight}px`;
  3473. hpBarBack.style.transformOrigin = "left center";
  3474. hpBarBack.style.transform = `scaleX(${(currentHp + damage) / maxHp})`;
  3475. // add animation to drop down
  3476. hpBarBack.style.transition = "transform 0.5s ease-in-out";
  3477. hpBarFront.parentNode.insertBefore(hpBarBack, hpBarFront); // Insert the back bar before the front bar
  3478.  
  3479. const dropDelay = Math.ceil(settingsMap.damageHpBarDropDelay.value || 300);
  3480. setTimeout(() => {
  3481. hpBarBack.style.transform = `scaleX(0)`;
  3482. }, dropDelay);
  3483. setTimeout(() => {
  3484. hpBarBack.remove();
  3485. }, dropDelay + 500);
  3486. }
  3487. function resetAllMonsterSvg() {
  3488. const monsterArea = document.querySelector(".BattlePanel_monstersArea__2dzrY");
  3489. if (monsterArea) {
  3490. const monsterSvgs = monsterArea.querySelectorAll(".Icon_icon__2LtL_");
  3491. monsterSvgs.forEach(monsterSvg => {
  3492. monsterSvg.style.transition = "none";
  3493. monsterSvg.style.transform = "rotate(0deg)";
  3494. monsterSvg.style.opacity = "1";
  3495. });
  3496. }
  3497. }
  3498. const deathEffect = {
  3499. default: element => {
  3500. const monsterSvg = element.querySelector(".Icon_icon__2LtL_");
  3501. monsterSvg.style.transition = "transform 0.1s ease-in-out";
  3502. monsterSvg.style.transformOrigin = "bottom center";
  3503. monsterSvg.style.transform = "rotate(15deg)";
  3504. setTimeout(() => {
  3505. monsterSvg.style.transition = "transform 0.5s ease-in-out, opacity 0.5s ease-in-out";
  3506. monsterSvg.style.transform = "rotate(-180deg)";
  3507. monsterSvg.style.opacity = "0";
  3508. }, 300);
  3509. // fade out
  3510. // setTimeout(() => {
  3511. // monsterSvg.style.transition = "opacity 0.5s ease-in-out";
  3512. // }, 800);
  3513. },
  3514. minecraftStyle: element => {
  3515. const monsterSvg = element.querySelector(".Icon_icon__2LtL_");
  3516.  
  3517. // First get dimensions and viewBox of original SVG
  3518. const svgRect = monsterSvg.getBoundingClientRect();
  3519. const viewBox = monsterSvg.getAttribute('viewBox') || '0 0 24 24'; // 默认值,以防未设置
  3520.  
  3521. // Get SVG content before changing anything else
  3522. const svgContent = monsterSvg.innerHTML;
  3523.  
  3524. // Create container that will match exact position of original SVG
  3525. const overlayContainer = document.createElement('div');
  3526. overlayContainer.style.position = 'absolute';
  3527. overlayContainer.style.top = '0';
  3528. overlayContainer.style.left = '0';
  3529. overlayContainer.style.width = '100%';
  3530. overlayContainer.style.height = '100%';
  3531. overlayContainer.style.pointerEvents = 'none';
  3532. // overlayContainer.style.zIndex = '5';
  3533.  
  3534. // Match the exact positioning and sizing of the original SVG
  3535. const parentBounds = element.getBoundingClientRect();
  3536. const relativeTop = (svgRect.top - parentBounds.top) / parentBounds.height * 100;
  3537. const relativeLeft = (svgRect.left - parentBounds.left) / parentBounds.width * 100;
  3538. const relativeWidth = svgRect.width / parentBounds.width * 100;
  3539. const relativeHeight = svgRect.height / parentBounds.height * 100;
  3540.  
  3541. // Create SVG overlay with the same dimensions and position
  3542. const svgOverlay = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  3543. svgOverlay.setAttribute('width', '100%');
  3544. svgOverlay.setAttribute('height', '100%');
  3545. svgOverlay.setAttribute('viewBox', viewBox);
  3546. svgOverlay.style.position = 'absolute';
  3547. svgOverlay.style.top = `${relativeTop}%`;
  3548. svgOverlay.style.left = `${relativeLeft}%`;
  3549. svgOverlay.style.width = `${relativeWidth}%`;
  3550. svgOverlay.style.height = `${relativeHeight}%`;
  3551. setTimeout(() => {
  3552. // Apply rotation to original SVG
  3553. monsterSvg.style.transition = "transform 0.1s ease-in-out";
  3554. monsterSvg.style.transformOrigin = "center left";
  3555. monsterSvg.style.transform = "rotate(15deg)";
  3556. // Apply same transform as original to maintain alignment
  3557. svgOverlay.style.transition = "transform 0.1s ease-in-out";
  3558. svgOverlay.style.transform = "rotate(15deg)";
  3559. svgOverlay.style.transformOrigin = "center left";
  3560. }, 300);
  3561.  
  3562. // Create defs for the mask
  3563. const defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3564. const mask = document.createElementNS('http://www.w3.org/2000/svg', 'mask');
  3565. mask.setAttribute('id', `monster-mask-${Date.now()}`); // Unique ID
  3566.  
  3567. // Clone the original SVG content for the mask
  3568. const maskContent = document.createElementNS('http://www.w3.org/2000/svg', 'g');
  3569. maskContent.innerHTML = svgContent;
  3570.  
  3571. // Set all elements in mask to white (opaque parts of mask)
  3572. const maskElements = maskContent.querySelectorAll('*');
  3573. maskElements.forEach(el => {
  3574. if (el.tagName === 'path' || el.tagName === 'circle' || el.tagName === 'rect' || el.tagName === 'polygon' || el.tagName === 'polyline') {
  3575. el.setAttribute('fill', 'white');
  3576. el.setAttribute('stroke', 'white');
  3577. }
  3578. });
  3579. mask.appendChild(maskContent);
  3580. defs.appendChild(mask);
  3581. svgOverlay.appendChild(defs);
  3582.  
  3583. // Create the red overlay rectangle that will be masked
  3584. const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
  3585. rect.setAttribute('width', '100%');
  3586. rect.setAttribute('height', '100%');
  3587. rect.setAttribute('fill', 'rgba(255, 0, 0, 0.6)'); // slightly more opaque
  3588. rect.setAttribute('mask', `url(#${mask.id})`);
  3589. svgOverlay.appendChild(rect);
  3590. overlayContainer.appendChild(svgOverlay);
  3591.  
  3592. // Add to parent element (usually the monster container)
  3593. element.style.position = 'relative'; // Ensure positioning context
  3594. element.appendChild(overlayContainer);
  3595. const svgCenter = getElementCenter(element);
  3596.  
  3597. // Make overlay match any subsequent animations of the original SVG
  3598. const observer = new MutationObserver(mutations => {
  3599. mutations.forEach(mutation => {
  3600. if (mutation.attributeName === 'style' || mutation.attributeName === 'transform') {
  3601. // Copy transform properties to keep in sync
  3602. svgOverlay.style.transform = monsterSvg.style.transform;
  3603. svgOverlay.style.opacity = monsterSvg.style.opacity;
  3604. svgOverlay.style.transition = monsterSvg.style.transition;
  3605. }
  3606. });
  3607. });
  3608.  
  3609. // Start observing the original SVG for changes
  3610. observer.observe(monsterSvg, {
  3611. attributes: true,
  3612. attributeFilter: ['style', 'transform']
  3613. });
  3614.  
  3615. // Fade out after delay
  3616. setTimeout(() => {
  3617. // monsterSvg.style.transition = "opacity 0.5s ease-in-out";
  3618. monsterSvg.style.opacity = "0";
  3619.  
  3620. // Remove overlay and stop observer after animation
  3621. observer.disconnect();
  3622. overlayContainer.remove();
  3623. let effects = [];
  3624. const p = {
  3625. x: svgCenter.x,
  3626. y: svgCenter.y + 30,
  3627. color: "rgba(0, 0, 0, 0.6)",
  3628. size: 0.2
  3629. };
  3630. for (let i = 0; i < 25; i++) {
  3631. p.life = onHitEffectsMap.pixelSmoke.life({
  3632. size: 0.5
  3633. });
  3634. effects.push({
  3635. x: onHitEffectsMap.pixelSmoke.x(p),
  3636. y: onHitEffectsMap.pixelSmoke.y(p),
  3637. angle: onHitEffectsMap.pixelSmoke.angle(p),
  3638. color: onHitEffectsMap.pixelSmoke.color(p),
  3639. size: onHitEffectsMap.pixelSmoke.size(p),
  3640. speed: onHitEffectsMap.pixelSmoke.speed({
  3641. size: 5
  3642. }),
  3643. gravity: onHitEffectsMap.pixelSmoke.gravity(p),
  3644. life: p.life,
  3645. maxLife: p.life,
  3646. draw: onHitEffectsMap.pixelSmoke.draw
  3647. });
  3648. }
  3649.  
  3650. // Add particle effect
  3651. addEffect({
  3652. effects: effects,
  3653. active: true,
  3654. lifespan: 500
  3655. });
  3656. }, 1000);
  3657. }
  3658. };
  3659.  
  3660. const canvas = initTrackerCanvas();
  3661. const ctx = canvas.getContext('2d');
  3662. function initTrackerCanvas() {
  3663. const gamePanel = document.querySelector("body");
  3664. const canvas = document.createElement('canvas');
  3665. canvas.id = 'hitTrackerCanvas';
  3666. canvas.style.position = 'fixed';
  3667. canvas.style.top = '0';
  3668. canvas.style.left = '0';
  3669. canvas.style.pointerEvents = 'none';
  3670. canvas.style.zIndex = '200';
  3671. canvas.style.width = '100%';
  3672. canvas.style.height = '100%';
  3673. canvas.width = window.innerWidth;
  3674. canvas.height = window.innerHeight;
  3675. canvas.pointerEvents = 'none';
  3676. gamePanel.appendChild(canvas);
  3677. window.addEventListener('resize', () => {
  3678. canvas.width = window.innerWidth;
  3679. canvas.height = window.innerHeight;
  3680. });
  3681. return canvas;
  3682. }
  3683.  
  3684. // Update shake animation effect to ensure element returns to original position
  3685. let fpsStatTime = new Date().getTime();
  3686. let fpsQueue = [];
  3687. let fps = 60;
  3688.  
  3689. // 动画循环
  3690. function animate() {
  3691. // 计算FPS
  3692. const now = Date.now();
  3693. const frameTime = now - fpsStatTime;
  3694. fpsStatTime = now;
  3695. const fpsNow = Math.round(1000 / frameTime);
  3696. fpsQueue.push(fpsNow);
  3697. if (fpsQueue.length > 120) {
  3698. fpsQueue.shift();
  3699. }
  3700. fps = Math.round(fpsQueue.reduce((a, b) => a + b) / fpsQueue.length);
  3701. fps = Math.min(Math.max(fps, 10), 300);
  3702. if (settingsMap.showFps.value) {
  3703. const fpsElement = document.querySelector('#hitTracker_fpsCounter');
  3704. if (fpsElement) {
  3705. fpsElement.innerText = `FPS: ${fps}`;
  3706. } else {
  3707. const parenetElement = document.querySelector(".BattlePanel_battleArea__U9hij");
  3708. if (parenetElement) {
  3709. const newFpsElement = document.createElement('div');
  3710. const center = getElementCenter(parenetElement);
  3711. newFpsElement.id = 'hitTracker_fpsCounter';
  3712. newFpsElement.style.position = 'fixed';
  3713. newFpsElement.style.top = `${center.x - parenetElement.innerWidth}px`;
  3714. newFpsElement.style.left = `${center.y - parenetElement.innerHeight}px`;
  3715. newFpsElement.style.color = 'rgba(200, 200, 200, 0.8)';
  3716. newFpsElement.style.zIndex = '9999';
  3717. newFpsElement.innerText = `FPS: ${fps}`;
  3718. parenetElement.appendChild(newFpsElement);
  3719. }
  3720. }
  3721. }
  3722.  
  3723. // 完全清空画布
  3724. ctx.clearRect(0, 0, canvas.width, canvas.height);
  3725.  
  3726. // 更新并绘制所有弹丸
  3727. for (let i = projectiles.length - 1; i >= 0; i--) {
  3728. const proj = projectiles[i];
  3729. proj.update();
  3730. proj.draw(ctx);
  3731. if (proj.isArrived()) {
  3732. createOnHitEffect(proj); // 将弹丸大小传递给爆炸效果
  3733. projectiles.splice(i, 1);
  3734. } else if (proj.isOutOfBounds()) {
  3735. // 超出边界则移除弹丸,不产生爆炸效果
  3736. projectiles.splice(i, 1);
  3737. }
  3738. }
  3739.  
  3740. // 更新和渲染所有爆炸效果
  3741. updateOnHits();
  3742. }
  3743. function startAnimation() {
  3744. const fpsLimit = settingsMap.renderFpsLimit.value || 60;
  3745. const fpsInterval = 1000 / fpsLimit;
  3746. setInterval(() => {
  3747. animate();
  3748. }, fpsInterval);
  3749. }
  3750. function getFpsFactor() {
  3751. return Math.min(Math.max(160 / fps, 0.125), 8);
  3752. }
  3753. class Projectile {
  3754. constructor(startX, startY, endX, endY, color, initialSpeed = 1, size = 10, otherInfo = {}) {
  3755. // 基础属性
  3756. this.x = startX;
  3757. this.y = startY;
  3758. this.start = {
  3759. x: startX,
  3760. y: startY
  3761. };
  3762. this.target = {
  3763. x: endX,
  3764. y: endY
  3765. };
  3766. this.otherInfo = otherInfo;
  3767. this.shakeApplied = false;
  3768. this.life = 0;
  3769. this.type = otherInfo.type || 'default';
  3770. this.effect = projectileEffectsMap[this.type] || projectileEffectsMap['fireball'];
  3771. this.doShake = this.effect.shake;
  3772.  
  3773. // 运动参数 - 向斜上方抛物线轨迹
  3774. this.gravity = this.effect.gravity || 0.2; // 重力加速度
  3775. this.gravity *= settingsMap.projectileHeightScale.value || 1; // 高度缩放因子
  3776.  
  3777. this.initialSpeed = initialSpeed * (this.effect.speedFactor || 1); // 初始速度参数
  3778. this.initialSpeed *= settingsMap.projectileSpeedScale.value || 1; // 速度缩放因子
  3779.  
  3780. // 计算水平距离和高度差
  3781. const dx = endX - startX;
  3782. const dy = endY - startY;
  3783.  
  3784. // 重新设计飞行时间计算,确保合理
  3785. // const timeInAir = distance / this.initialSpeed / 10;
  3786. this.timeInAir = 80 / this.initialSpeed;
  3787.  
  3788. // FPS因子,确保在不同FPS下效果一致
  3789. const fpsFactor = getFpsFactor();
  3790. this.gravity *= Math.pow(fpsFactor, 2);
  3791. this.timeInAir /= fpsFactor;
  3792.  
  3793. // 计算初始速度,修正公式确保能够到达目标
  3794. this.velocity = {
  3795. x: dx / this.timeInAir,
  3796. y: dy / this.timeInAir - this.gravity * this.timeInAir / 2
  3797. };
  3798. this.initialVelocity = {
  3799. ...this.velocity
  3800. };
  3801. this.trajectory = time => {
  3802. return {
  3803. x: startX + this.initialVelocity.x * time,
  3804. y: startY + this.initialVelocity.y * time + this.gravity * time * time / 2
  3805. };
  3806. };
  3807.  
  3808. // 大小参数 (范围1-100)
  3809. const projectileScale = settingsMap.projectileScale.value || 1;
  3810. this.sizeScale = Math.max(1, Math.min(100, size)) / 10 * projectileScale; // 转换为比例因子
  3811.  
  3812. // 外观属性
  3813. this.size = 10 * this.sizeScale;
  3814. this.color = this.effect.color || color;
  3815.  
  3816. // 拖尾效果
  3817. this.trail = [];
  3818. this.independentTrail = this.effect.independentTrail || false; // 是否独立拖尾
  3819. this.maxTrailLength = Math.floor((this.effect.trailLength || 35) * Math.sqrt(this.sizeScale)); // 拖尾长度随大小增加
  3820. this.maxTrailLength *= settingsMap.projectileTrailLength.value || 1; // 拖尾缩放因子
  3821. this.trailGap = (settingsMap.projectileTrailGap.value || 1) / fpsFactor;
  3822. }
  3823. update() {
  3824. this.life += 1;
  3825. const pos = this.trajectory(this.life);
  3826. this.velocity.y += this.gravity;
  3827. this.x = pos.x;
  3828. this.y = pos.y;
  3829.  
  3830. // 更新拖尾
  3831. if (this.independentTrail) {
  3832. if (this.effect.trailLength > 0) {
  3833. this.trail.push({
  3834. x: this.x,
  3835. y: this.y,
  3836. vX: this.velocity.x,
  3837. vY: this.velocity.y,
  3838. color: this.color,
  3839. size: this.size,
  3840. totalLength: Math.max(this.trail.length, 1)
  3841. });
  3842. }
  3843. if (this.trail.length > this.maxTrailLength) {
  3844. this.trail.shift();
  3845. }
  3846. } else {
  3847. this.trail = [];
  3848. for (let i = 0; i < this.maxTrailLength; i++) {
  3849. const trailTime = this.life - (this.maxTrailLength - i - 1) * this.trailGap;
  3850. if (trailTime <= 0) break;
  3851. const trailPos = this.trajectory(trailTime);
  3852. this.trail.push({
  3853. x: trailPos.x,
  3854. y: trailPos.y,
  3855. vX: this.velocity.x,
  3856. vY: this.velocity.y,
  3857. color: this.color,
  3858. size: this.size,
  3859. totalLength: this.maxTrailLength
  3860. });
  3861. }
  3862. }
  3863. }
  3864. draw(canvas) {
  3865. // 绘制拖尾
  3866. this.trail.forEach((pos, index) => {
  3867. if (this.effect.trail) {
  3868. this.effect.trail(canvas, pos, index);
  3869. } else {
  3870. projectileEffectsMap['fireball'].trail(canvas, pos, index);
  3871. }
  3872. });
  3873.  
  3874. // 绘制主体
  3875. if (this.effect.draw) {
  3876. this.effect.draw(canvas, this);
  3877. } else {
  3878. projectileEffectsMap['fireball'].draw(canvas, this);
  3879. }
  3880.  
  3881. // 添加光晕效果
  3882. if (this.effect.glow) {
  3883. this.effect.glow(canvas, this);
  3884. }
  3885. }
  3886. isArrived() {
  3887. if (this.life >= this.timeInAir) {
  3888. this.x = this.target.x;
  3889. this.y = this.target.y;
  3890. return true;
  3891. }
  3892. // 判断是否到达目标点 (调整判定距离)
  3893. const arrivalDistance = 20;
  3894. const hasArrived = Math.hypot(this.x - this.target.x, this.y - this.target.y) < arrivalDistance;
  3895. if (hasArrived && this.doShake && !this.shakeApplied && this.otherInfo.endElement) {
  3896. const shakeIntensity = Math.min(this.sizeScale * 5, 10);
  3897. applyShakeEffect(this.otherInfo.endElement, shakeIntensity);
  3898. this.shakeApplied = true;
  3899. }
  3900. return hasArrived;
  3901. }
  3902. isOutOfBounds() {
  3903. return this.x < 0 || this.x > canvas.width || this.y < 0 || this.y > canvas.height;
  3904. }
  3905. }
  3906.  
  3907. // Projectiles管理
  3908. let projectiles = [];
  3909. function clearProjectiles() {
  3910. projectiles.splice(0, projectiles.length);
  3911. }
  3912.  
  3913. // 爆炸效果函数
  3914. function createOnHitEffect(projectile) {
  3915. const x = projectile.x;
  3916. const y = projectile.y;
  3917. const color = projectile.color;
  3918. const otherInfo = projectile.otherInfo;
  3919. const projectileScale = settingsMap.projectileScale.value || 1;
  3920.  
  3921. // Resize for onHit effect
  3922. projectile.size = Math.max(1, Math.min(100, projectile.size)) / 20 / projectileScale;
  3923. const sizeFactor = settingsMap.onHitScale.value || 1;
  3924. const particleFactor = settingsMap.particleEffectRatio.value || 1;
  3925. const particleSpeedFactor = settingsMap.particleSpeedRatio.value || 1;
  3926. const particleLifespanFactor = settingsMap.particleLifespanRatio.value || 1;
  3927. const fpsFactor = getFpsFactor();
  3928. const effects = [];
  3929. let onHitEffect = projectile.effect.onHit;
  3930. if (projectile.otherInfo.isCrit) {
  3931. const onCrit = projectile.effect.onCrit || projectileEffectsMap.fireball.onCrit;
  3932. onHitEffect = {
  3933. ...onHitEffect,
  3934. ...onCrit
  3935. };
  3936. }
  3937. for (const effectName in onHitEffect) {
  3938. const effect = onHitEffectsMap[effectName];
  3939. if (!effect) continue;
  3940. const effectCount = Math.ceil(onHitEffect[effectName](projectile.size) * particleFactor);
  3941. for (let i = 0; i < effectCount; i++) {
  3942. const effectSize = (effect.size ? effect.size(projectile) : Math.random() * 10 + 5) * sizeFactor;
  3943. const effectLife = Math.ceil((effect.life ? effect.life(projectile) : 1000) * particleLifespanFactor / Math.pow(fpsFactor, 0.33));
  3944. const effectSpeed = Math.ceil((effect.speed ? effect.speed(projectile) : Math.random() * 5 + 2) / Math.pow(fpsFactor, 0.33) * particleSpeedFactor);
  3945. effects.push({
  3946. x: effect.x ? effect.x(projectile) : x,
  3947. y: effect.y ? effect.y(projectile) : y,
  3948. angle: effect.angle ? effect.angle(projectile) : Math.random() * Math.PI * 2,
  3949. alpha: effect.alpha ? effect.alpha(projectile) : 0.8,
  3950. size: effectSize,
  3951. speed: effectSpeed,
  3952. gravity: effect.gravity ? effect.gravity(projectile) : 0,
  3953. life: effectLife,
  3954. maxLife: effectLife,
  3955. color: effect.color ? effect.color(projectile) : projectile.color,
  3956. draw: effect.draw ? effect.draw : (ctx, p) => {}
  3957. });
  3958. }
  3959. }
  3960.  
  3961. // 存储命中动画的活跃状态,用于跟踪
  3962. const damageTextLifespan = settingsMap.damageTextLifespan.value || 120;
  3963. const lifeSpan = Math.ceil(damageTextLifespan / Math.pow(fpsFactor, 0.33));
  3964. const onHitEffectData = {
  3965. effects: [...effects],
  3966. active: true,
  3967. lifespan: lifeSpan,
  3968. color: color,
  3969. otherInfo: otherInfo,
  3970. isFpsOptimized: true
  3971. };
  3972. addEffect(onHitEffectData);
  3973. }
  3974.  
  3975. // 更新和渲染所有命中效果
  3976. function updateOnHits() {
  3977. // 遍历所有活跃的命中
  3978. for (let i = activeEffects.length - 1; i >= 0; i--) {
  3979. const effect = activeEffects[i];
  3980. effect.life++;
  3981. if (effect.life >= effect.lifespan) {
  3982. activeEffects.splice(i, 1);
  3983. continue;
  3984. }
  3985. if (!effect.isFpsOptimized) {
  3986. const fpsFactor = getFpsFactor();
  3987. for (const e of effect.effects) {
  3988. e.speed *= fpsFactor;
  3989. e.life /= fpsFactor;
  3990. }
  3991. effect.lifespan /= fpsFactor;
  3992. effect.isFpsOptimized = true;
  3993. }
  3994. ctx.save();
  3995.  
  3996. // 更新各自效果
  3997. effect.effects.forEach((e, index) => {
  3998. e.draw(ctx, e);
  3999. });
  4000.  
  4001. // 伤害文本
  4002. if (effect.otherInfo && effect.otherInfo.damage) {
  4003. const fontSizeScale = settingsMap.damageTextScale.value || 1;
  4004. const fontSizeMinimal = settingsMap.damageTextSizeMinimal.value || 14;
  4005. const fontSizeLimit = settingsMap.damageTextSizeLimit.value || 70;
  4006. const fontAlpha = settingsMap.damageTextAlpha.value || 0.8;
  4007. const fontSize = Math.min(Math.max(fontSizeMinimal, Math.pow(effect.otherInfo.damage, 0.65) / 2 * fontSizeScale), fontSizeLimit);
  4008. const damageText = `${effect.otherInfo.damage}`;
  4009. ctx.font = `${fontSize}px Arial`;
  4010. ctx.textAlign = 'center';
  4011. ctx.textBaseline = 'middle';
  4012. const textSize = ctx.measureText(damageText);
  4013. const textPosition = {
  4014. x: effect.otherInfo.end.x - textSize.width / 2 + 5,
  4015. y: effect.otherInfo.end.y - 20
  4016. };
  4017.  
  4018. // border
  4019. ctx.strokeStyle = effect.color.replace(/rgba\(([^,]+),([^,]+),([^,]+),[^)]+\)/, `rgba($1,$2,$3,${fontAlpha})`);
  4020. ctx.lineWidth = 6;
  4021. ctx.strokeText(damageText, textPosition.x, textPosition.y);
  4022. // main
  4023. const fillColor = effect.otherInfo.isCrit ? 'rgba(255, 213, 89, 1)' : 'white';
  4024. ctx.fillStyle = fillColor;
  4025. ctx.fillText(damageText, textPosition.x, textPosition.y);
  4026. }
  4027. ctx.restore();
  4028. }
  4029. }
  4030. function createProjectile(startElement, endElement, color, initialSpeed = 1, damage = 200, projectileType = 'default', isCrit = false, isKill = false) {
  4031. if (!startElement || !endElement) {
  4032. return;
  4033. }
  4034. const combatUnitContainer = endElement.querySelector(".CombatUnit_splatsContainer__2xcc0");
  4035. if (!settingsMap.originalDamageDisplay.value) {
  4036. combatUnitContainer.style.visibility = "hidden";
  4037. }
  4038. const padding = 30;
  4039. const randomRange = {
  4040. x: Math.floor((Math.random() - 0.5) * (combatUnitContainer.offsetWidth - 2 * padding)),
  4041. y: Math.floor((Math.random() - 0.1) * (combatUnitContainer.offsetHeight - padding))
  4042. };
  4043. const projectileLimit = settingsMap.projectileLimit.value || 30;
  4044. const start = getElementCenter(startElement);
  4045. const end = getElementCenter(endElement);
  4046. end.x = Math.floor(end.x + randomRange.x);
  4047. end.y = Math.floor(end.y + randomRange.y);
  4048. const size = Math.min(Math.max(Math.pow(damage + 200, 0.7) / 20, 4), 16);
  4049. projectileType = abilityEffectsMap[projectileType] || projectileType;
  4050. const otherInfo = {
  4051. type: projectileType,
  4052. start: start,
  4053. end: end,
  4054. damage: damage,
  4055. color: color,
  4056. isCrit: isCrit,
  4057. isKill: isKill,
  4058. startElement: startElement,
  4059. endElement: endElement
  4060. };
  4061. if (projectiles.length <= projectileLimit) {
  4062. if (damage > 0) {
  4063. addDamageHPBar(endElement, damage);
  4064. }
  4065. if (otherInfo.isKill && settingsMap.monsterDeadAnimation.value) {
  4066. deathEffect[settingsMap.monsterDeadAnimationStyle.value](otherInfo.endElement);
  4067. }
  4068. const projectile = new Projectile(start.x, start.y, end.x, end.y, color, initialSpeed, size, otherInfo);
  4069. projectiles.push(projectile);
  4070. } else {
  4071. projectiles.shift();
  4072. }
  4073. }
  4074.  
  4075. // #region Setting
  4076. waitForSettings({
  4077. monsterDeadAnimationStyle: Object.keys(deathEffect),
  4078. allProjectiles: Object.keys(projectileEffectsMap)
  4079. });
  4080. hookWS();
  4081. let isPageHidden = false;
  4082.  
  4083. // 监听页面可见性变化
  4084. document.addEventListener('visibilitychange', function () {
  4085. isPageHidden = document.hidden;
  4086. if (isPageHidden) {
  4087. clearProjectiles();
  4088. clearEffects();
  4089. }
  4090. });
  4091.  
  4092. // #region Hook WS
  4093. function hookWS() {
  4094. const dataProperty = Object.getOwnPropertyDescriptor(MessageEvent.prototype, "data");
  4095. const oriGet = dataProperty.get;
  4096. dataProperty.get = hookedGet;
  4097. Object.defineProperty(MessageEvent.prototype, "data", dataProperty);
  4098. function hookedGet() {
  4099. const socket = this.currentTarget;
  4100. if (!(socket instanceof WebSocket)) {
  4101. return oriGet.call(this);
  4102. }
  4103. if (socket.url.indexOf("api.milkywayidle.com/ws") <= -1 && socket.url.indexOf("api-test.milkywayidle.com/ws") <= -1) {
  4104. return oriGet.call(this);
  4105. }
  4106. const message = oriGet.call(this);
  4107. Object.defineProperty(this, "data", {
  4108. value: message
  4109. }); // Anti-loop
  4110.  
  4111. try {
  4112. return handleMessage(message);
  4113. } catch (error) {
  4114. console.log("Error in hit-tracker handleMessage:", error);
  4115. return message;
  4116. }
  4117. }
  4118. }
  4119. let monstersHP = [];
  4120. let monstersMP = [];
  4121. let playersHP = [];
  4122. let playersMP = [];
  4123. let playersAbility = [];
  4124. function handleMessage(message) {
  4125. let obj = JSON.parse(message);
  4126. if (obj && obj.type === "new_battle") {
  4127. monstersHP = obj.monsters.map(monster => monster.currentHitpoints);
  4128. monstersMP = obj.monsters.map(monster => monster.currentManapoints);
  4129. playersHP = obj.players.map(player => player.currentHitpoints);
  4130. playersMP = obj.players.map(player => player.currentManapoints);
  4131. resetAllMonsterSvg();
  4132. } else if (obj && obj.type === "battle_updated" && monstersHP.length) {
  4133. const mMap = obj.mMap;
  4134. const pMap = obj.pMap;
  4135. const monsterIndices = Object.keys(obj.mMap);
  4136. const playerIndices = Object.keys(obj.pMap);
  4137. let castMonster = -1;
  4138. monsterIndices.forEach(monsterIndex => {
  4139. if (mMap[monsterIndex].cMP < monstersMP[monsterIndex]) {
  4140. castMonster = monsterIndex;
  4141. }
  4142. monstersMP[monsterIndex] = mMap[monsterIndex].cMP;
  4143. });
  4144. let castPlayer = -1;
  4145. playerIndices.forEach(userIndex => {
  4146. if (pMap[userIndex].cMP < playersMP[userIndex]) {
  4147. castPlayer = userIndex;
  4148. }
  4149. if (pMap[userIndex].cMP > playersMP[userIndex]) {
  4150. registProjectile({
  4151. from: userIndex,
  4152. to: userIndex,
  4153. hpDiff: pMap[userIndex].cMP - playersMP[userIndex],
  4154. reversed: false,
  4155. abilityHrid: 'selfManaRegen',
  4156. toPlayer: true
  4157. });
  4158. }
  4159. playersMP[userIndex] = pMap[userIndex].cMP;
  4160. if (pMap[userIndex].abilityHrid) {
  4161. playersAbility[userIndex] = pMap[userIndex].abilityHrid;
  4162. }
  4163. });
  4164. monstersHP.forEach((mHP, mIndex) => {
  4165. const monster = mMap[mIndex];
  4166. if (monster) {
  4167. const hpDiff = mHP - monster.cHP;
  4168. monstersHP[mIndex] = monster.cHP;
  4169. if (hpDiff > 0 && playerIndices.length > 0) {
  4170. const isCrit = monster.dmgCounter == monster.critCounter;
  4171. const isKill = monster.cHP <= 0;
  4172. if (playerIndices.length > 1) {
  4173. playerIndices.forEach(userIndex => {
  4174. if (userIndex === castPlayer) {
  4175. registProjectile({
  4176. from: userIndex,
  4177. to: mIndex,
  4178. hpDiff: hpDiff,
  4179. reversed: false,
  4180. abilityHrid: playersAbility[userIndex],
  4181. toPlayer: false,
  4182. isCrit: isCrit,
  4183. isKill: isKill
  4184. });
  4185. }
  4186. });
  4187. } else {
  4188. registProjectile({
  4189. from: playerIndices[0],
  4190. to: mIndex,
  4191. hpDiff: hpDiff,
  4192. reversed: false,
  4193. abilityHrid: playersAbility[playerIndices[0]],
  4194. toPlayer: false,
  4195. isCrit: isCrit,
  4196. isKill: isKill
  4197. });
  4198. }
  4199. }
  4200. }
  4201. });
  4202. playersHP.forEach((pHP, pIndex) => {
  4203. const player = pMap[pIndex];
  4204. if (player) {
  4205. const hpDiff = pHP - player.cHP;
  4206. playersHP[pIndex] = player.cHP;
  4207. if (hpDiff > 0 && monsterIndices.length > 0) {
  4208. const isCrit = player.dmgCounter == player.critCounter;
  4209. if (monsterIndices.length > 1) {
  4210. monsterIndices.forEach(monsterIndex => {
  4211. if (monsterIndex === castMonster) {
  4212. registProjectile({
  4213. from: pIndex,
  4214. to: monsterIndex,
  4215. hpDiff: hpDiff,
  4216. reversed: true,
  4217. abilityHrid: 'autoAttack',
  4218. toPlayer: false,
  4219. isCrit: isCrit
  4220. });
  4221. }
  4222. });
  4223. } else {
  4224. registProjectile({
  4225. from: pIndex,
  4226. to: monsterIndices[0],
  4227. hpDiff: hpDiff,
  4228. reversed: true,
  4229. abilityHrid: 'autoAttack',
  4230. toPlayer: false,
  4231. isCrit: isCrit
  4232. });
  4233. }
  4234. } else if (hpDiff < 0) {
  4235. if (castPlayer > -1) {
  4236. registProjectile({
  4237. from: castPlayer,
  4238. to: pIndex,
  4239. hpDiff: -hpDiff,
  4240. reversed: false,
  4241. abilityHrid: 'heal',
  4242. toPlayer: true
  4243. });
  4244. } else {
  4245. registProjectile({
  4246. from: pIndex,
  4247. to: pIndex,
  4248. hpDiff: -hpDiff,
  4249. reversed: false,
  4250. abilityHrid: 'selfHeal',
  4251. toPlayer: true
  4252. });
  4253. }
  4254. }
  4255. }
  4256. });
  4257. } else if (obj && obj.type === "battle_updated") {
  4258. const pMap = obj.pMap;
  4259. const playerIndices = Object.keys(obj.pMap);
  4260. playerIndices.forEach(userIndex => {
  4261. if (pMap[userIndex].abilityHrid) {
  4262. playersAbility[userIndex] = pMap[userIndex].abilityHrid;
  4263. }
  4264. });
  4265. playersHP.forEach((pHP, pIndex) => {
  4266. const player = pMap[pIndex];
  4267. if (player) {
  4268. const hpDiff = pHP - player.cHP;
  4269. playersHP[pIndex] = player.cHP;
  4270. if (hpDiff < 0) {
  4271. registProjectile({
  4272. from: pIndex,
  4273. to: pIndex,
  4274. hpDiff: -hpDiff,
  4275. reversed: false,
  4276. abilityHrid: 'selfHeal',
  4277. toPlayer: true
  4278. });
  4279. }
  4280. }
  4281. });
  4282. playersMP.forEach((pMP, pIndex) => {
  4283. const player = pMap[pIndex];
  4284. if (player) {
  4285. const mpDiff = pMP - player.pMP;
  4286. playersMP[pIndex] = player.pMP;
  4287. if (mpDiff < 0) {
  4288. registProjectile({
  4289. from: pIndex,
  4290. to: pIndex,
  4291. hpDiff: -mpDiff,
  4292. reversed: false,
  4293. abilityHrid: 'selfManaRegen',
  4294. toPlayer: true
  4295. });
  4296. }
  4297. }
  4298. });
  4299. }
  4300. return message;
  4301. }
  4302.  
  4303. // #region Main Logic
  4304.  
  4305. // 动画效果
  4306. function registProjectile({
  4307. from,
  4308. to,
  4309. hpDiff,
  4310. reversed = false,
  4311. abilityHrid = "default",
  4312. toPlayer = true,
  4313. isCrit = false,
  4314. isKill = false
  4315. }) {
  4316. if (isPageHidden) {
  4317. return;
  4318. }
  4319. if (reversed) {
  4320. if (settingsMap.tracker6 && !settingsMap.tracker6.isTrue) {
  4321. return null;
  4322. }
  4323. } else {
  4324. if (settingsMap["tracker" + from] && !settingsMap["tracker" + from].isTrue) {
  4325. return null;
  4326. }
  4327. }
  4328. if (["selfHeal", "selfManaRegen"].indexOf(abilityHrid) > -1 && !settingsMap.showSelfRegen.value) {
  4329. return null;
  4330. }
  4331. const container = document.querySelector(".BattlePanel_playersArea__vvwlB");
  4332. if (container && container.children.length > 0) {
  4333. const playersContainer = container.children[0];
  4334. const effectFrom = playersContainer.children[from];
  4335. const monsterContainer = document.querySelector(".BattlePanel_monstersArea__2dzrY").children[0];
  4336. const effectTo = toPlayer ? playersContainer.children[to] : monsterContainer.children[to];
  4337. const trackerSetting = reversed ? settingsMap[`tracker6`] : settingsMap["tracker" + from];
  4338. let lineColor = "rgba(" + trackerSetting.r + ", " + trackerSetting.g + ", " + trackerSetting.b + ", 1)";
  4339. if (["selfHeal", "selfManaRegen", "heal"].indexOf(abilityHrid) <= -1) {
  4340. if (trackerSetting.trackStyle === "null") {
  4341. return null;
  4342. } else if (trackerSetting.trackStyle != "auto") {
  4343. abilityHrid = trackerSetting.trackStyle;
  4344. }
  4345. }
  4346. if (!reversed) {
  4347. createProjectile(effectFrom, effectTo, lineColor, 1, hpDiff, abilityHrid, isCrit, isKill);
  4348. } else {
  4349. createProjectile(effectTo, effectFrom, lineColor, 1, hpDiff, abilityHrid, isCrit, isKill);
  4350. }
  4351. }
  4352. }
  4353.  
  4354. // 启动动画
  4355. startAnimation();
  4356.  
  4357. exports.registProjectile = registProjectile;
  4358.  
  4359. Object.defineProperty(exports, '__esModule', { value: true });
  4360.  
  4361. return exports;
  4362.  
  4363. })({});