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