MWI-Hit-Tracker-Canvas

A Tampermonkey script to track MWI hits on Canvas

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

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