warcraft-3-w3ts-utils 0.1.3 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/utils/abilities.d.ts +35 -0
- package/dist/utils/abilities.js +125 -0
- package/dist/utils/camera.d.ts +1 -0
- package/dist/utils/camera.js +37 -0
- package/dist/utils/chat-command.d.ts +12 -0
- package/dist/utils/chat-command.js +22 -0
- package/{src/utils/color.ts → dist/utils/color.d.ts} +109 -139
- package/dist/utils/color.js +141 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.js +32 -0
- package/dist/utils/item.d.ts +9 -0
- package/dist/utils/item.js +124 -0
- package/dist/utils/math.d.ts +13 -0
- package/dist/utils/math.js +17 -0
- package/dist/utils/minimapIcons.d.ts +13 -0
- package/dist/utils/minimapIcons.js +27 -0
- package/dist/utils/misc.d.ts +56 -0
- package/dist/utils/misc.js +175 -0
- package/dist/utils/physics.d.ts +52 -0
- package/dist/utils/physics.js +194 -0
- package/dist/utils/players.d.ts +50 -0
- package/dist/utils/players.js +189 -0
- package/dist/utils/point.d.ts +15 -0
- package/dist/utils/point.js +74 -0
- package/dist/utils/quests.d.ts +2 -0
- package/dist/utils/quests.js +30 -0
- package/dist/utils/textTag.d.ts +29 -0
- package/dist/utils/textTag.js +72 -0
- package/dist/utils/timer.d.ts +5 -0
- package/dist/utils/timer.js +16 -0
- package/dist/utils/units.d.ts +26 -0
- package/dist/utils/units.js +81 -0
- package/package.json +12 -3
- package/tsconfig.json +2 -4
- package/src/utils/abilities.ts +0 -161
- package/src/utils/camera.ts +0 -63
- package/src/utils/chat-command.ts +0 -22
- package/src/utils/item.ts +0 -155
- package/src/utils/math.ts +0 -14
- package/src/utils/minimapIcons.ts +0 -34
- package/src/utils/misc.ts +0 -179
- package/src/utils/physics.ts +0 -295
- package/src/utils/players.ts +0 -214
- package/src/utils/point.ts +0 -81
- package/src/utils/quests.ts +0 -38
- package/src/utils/textTag.ts +0 -80
- package/src/utils/timer.ts +0 -14
- package/src/utils/units.ts +0 -109
- package/tsconfig.tsbuildinfo +0 -1
package/src/utils/math.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated
|
|
3
|
-
* @param a
|
|
4
|
-
* @param b
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export function distanceBetweenCoords(a: { x: number; y: number }, b: { x: number; y: number }) {
|
|
8
|
-
const deltaX = a.x - b.x;
|
|
9
|
-
const deltaY = a.y - b.y;
|
|
10
|
-
const squaredDist = Math.pow(deltaX, 2) + Math.pow(deltaY, 2);
|
|
11
|
-
const dist = Math.sqrt(squaredDist);
|
|
12
|
-
|
|
13
|
-
return dist;
|
|
14
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type MINIMAP_ICONS =
|
|
2
|
-
| "UI\\Minimap\\MiniMap-ControlPoint.mdl"
|
|
3
|
-
| "UI\\Minimap\\MiniMap-QuestGiver.mdl"
|
|
4
|
-
| "UI\\Minimap\\Minimap-QuestObjectiveBonus.mdl"
|
|
5
|
-
| "UI\\Minimap\\Minimap-QuestObjectivePrimary.mdl"
|
|
6
|
-
| "UI\\Minimap\\Minimap-QuestTurnIn.mdl"
|
|
7
|
-
| "UI\\Minimap\\MiniMap-Hero.mdl"
|
|
8
|
-
| "UI\\Minimap\\Minimap-Ping.mdl"
|
|
9
|
-
| "UI\\Minimap\\MiniMap-Item.mdl"
|
|
10
|
-
| "UI\\Minimap\\MiniMap-NeutralBuilding.mdl";
|
|
11
|
-
|
|
12
|
-
export enum MinimapIconPath {
|
|
13
|
-
controlPoint = "UI\\Minimap\\MiniMap-ControlPoint.mdl",
|
|
14
|
-
questGiver = "UI\\Minimap\\MiniMap-QuestGiver.mdl",
|
|
15
|
-
questObjectiveBonus = "UI\\Minimap\\Minimap-QuestObjectiveBonus.mdl",
|
|
16
|
-
questObjectivePrimary = "UI\\Minimap\\Minimap-QuestObjectivePrimary.mdl",
|
|
17
|
-
questTurnIn = "UI\\Minimap\\Minimap-QuestTurnIn.mdl",
|
|
18
|
-
hero = "UI\\Minimap\\MiniMap-Hero.mdl",
|
|
19
|
-
item = "UI\\Minimap\\MiniMap-Item.mdl",
|
|
20
|
-
neutralBuilding = "UI\\Minimap\\MiniMap-NeutralBuilding.mdl",
|
|
21
|
-
ping = "UI\\Minimap\\Minimap-Ping.mdl",
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const minimapIconPathsSet = new Set<MINIMAP_ICONS>([
|
|
25
|
-
"UI\\Minimap\\MiniMap-ControlPoint.mdl",
|
|
26
|
-
"UI\\Minimap\\MiniMap-Hero.mdl",
|
|
27
|
-
"UI\\Minimap\\MiniMap-Item.mdl",
|
|
28
|
-
"UI\\Minimap\\MiniMap-NeutralBuilding.mdl",
|
|
29
|
-
"UI\\Minimap\\MiniMap-QuestGiver.mdl",
|
|
30
|
-
"UI\\Minimap\\Minimap-Ping.mdl",
|
|
31
|
-
"UI\\Minimap\\Minimap-QuestObjectiveBonus.mdl",
|
|
32
|
-
"UI\\Minimap\\Minimap-QuestObjectivePrimary.mdl",
|
|
33
|
-
"UI\\Minimap\\Minimap-QuestTurnIn.mdl",
|
|
34
|
-
]);
|
package/src/utils/misc.ts
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { Effect, MapPlayer, Timer, Unit } from "w3ts";
|
|
2
|
-
|
|
3
|
-
type ProperColors = "goldenrod" | "magenta" | "green" | "yellow" | "red" | "player1-red" | "player2-blue" | "player3-teal" | "player4-purple" | "player5-yellow" | "player6-orange";
|
|
4
|
-
|
|
5
|
-
export function tColor(text: string | number, color?: ProperColors | null, hex?: PlayerColorHex | string | null, alpha?: string) {
|
|
6
|
-
if (color) {
|
|
7
|
-
return `|cff${properColorHexes.get(color) || "FFFFFF"}${alpha || ""}${text}|r`;
|
|
8
|
-
} else if (hex) {
|
|
9
|
-
return `|cff${hex}${alpha || ""}${text}|r`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return String(text);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Colorizes the string according to the map player
|
|
17
|
-
*/
|
|
18
|
-
export function ptColor(player: MapPlayer, text: string) {
|
|
19
|
-
return `${tColor(text, undefined, playerColors[player.id])}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const properColorHexes = new Map<ProperColors, string>([
|
|
23
|
-
["goldenrod", "ffcc00"],
|
|
24
|
-
["green", "00FF00"],
|
|
25
|
-
["yellow", "FFFF00"],
|
|
26
|
-
["red", "FF0000"],
|
|
27
|
-
["magenta", "FF00FF"],
|
|
28
|
-
["player1-red", "ff0303"],
|
|
29
|
-
["player2-blue", "0042ff"],
|
|
30
|
-
["player3-teal", "1ce6b9"],
|
|
31
|
-
["player4-purple", "540081"],
|
|
32
|
-
["player5-yellow", "fffc00"],
|
|
33
|
-
["player6-orange", "fe8a0e"],
|
|
34
|
-
]);
|
|
35
|
-
// enum PlayerColors {
|
|
36
|
-
// Player1 = "ff0303", // Red
|
|
37
|
-
// Player2 = "0042ff", // Blue
|
|
38
|
-
// Player3 = "1be7ba", // Teal
|
|
39
|
-
// Player4 = "550081", // Purple
|
|
40
|
-
// Player5 = "fefc00", // Yellow
|
|
41
|
-
// Player6 = "fe890d", // Orange
|
|
42
|
-
// Player7 = "21bf00", // Green
|
|
43
|
-
// Player8 = "e45caf", // Pink
|
|
44
|
-
// Player9 = "939596", // Gray
|
|
45
|
-
// Player10 = "7ebff1", // Light Blue
|
|
46
|
-
// Player11 = "106247", // Dark Green
|
|
47
|
-
// Player12 = "4f2b05", // Brown
|
|
48
|
-
// Player13 = "9c0000", // Maroon
|
|
49
|
-
// Player14 = "0000c3", // Navy
|
|
50
|
-
// Player15 = "00ebff", // Turquoise
|
|
51
|
-
// Player16 = "bd00ff", // Violet
|
|
52
|
-
// Player17 = "ecce87", // Wheat
|
|
53
|
-
// Player18 = "f7a58b", // Peach
|
|
54
|
-
// Player19 = "bfff81", // Mint
|
|
55
|
-
// Player20 = "dbb8eb", // Lavender
|
|
56
|
-
// Player21 = "4f5055", // Coal
|
|
57
|
-
// Player22 = "ecf0ff", // Snow
|
|
58
|
-
// Player23 = "00781e", // Emerald
|
|
59
|
-
// Player24 = "a56f34", // Peanut
|
|
60
|
-
// PlayerNeutral = "2e2d2e", // Black
|
|
61
|
-
// }
|
|
62
|
-
|
|
63
|
-
export enum PlayerColorHex {
|
|
64
|
-
Red = "ff0303",
|
|
65
|
-
Blue = "0042ff",
|
|
66
|
-
Teal = "1be7ba",
|
|
67
|
-
Purple = "550081",
|
|
68
|
-
Yellow = "fefc00",
|
|
69
|
-
Orange = "fe890d",
|
|
70
|
-
Green = "21bf00",
|
|
71
|
-
Pink = "e45caf",
|
|
72
|
-
Gray = "939596",
|
|
73
|
-
LightBlue = "7ebff1",
|
|
74
|
-
DarkGreen = "106247",
|
|
75
|
-
Brown = "4f2b05",
|
|
76
|
-
Maroon = "9c0000",
|
|
77
|
-
Navy = "0000c3",
|
|
78
|
-
Turquoise = "00ebff",
|
|
79
|
-
Violet = "bd00ff",
|
|
80
|
-
Wheat = "ecce87",
|
|
81
|
-
Peach = "f7a58b",
|
|
82
|
-
Mint = "bfff81",
|
|
83
|
-
Lavender = "dbb8eb",
|
|
84
|
-
Coal = "4f5055",
|
|
85
|
-
Snow = "ecf0ff",
|
|
86
|
-
Emerald = "00781e",
|
|
87
|
-
Peanut = "a56f34",
|
|
88
|
-
Black = "2e2d2e",
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const playerColors = [
|
|
92
|
-
"ff0303", // Player 1: Red
|
|
93
|
-
"0042ff", // Player 2: Blue
|
|
94
|
-
"1be7ba", // Player 3: Teal
|
|
95
|
-
"550081", // Player 4: Purple
|
|
96
|
-
"fefc00", // Player 5: Yellow
|
|
97
|
-
"fe890d", // Player 6: Orange
|
|
98
|
-
"21bf00", // Player 7: Green
|
|
99
|
-
"e45caf", // Player 8: Pink
|
|
100
|
-
"939596", // Player 9: Gray
|
|
101
|
-
"7ebff1", // Player 10: Light Blue
|
|
102
|
-
"106247", // Player 11: Dark Green
|
|
103
|
-
"4f2b05", // Player 12: Brown
|
|
104
|
-
"9c0000", // Player 13: Maroon
|
|
105
|
-
"0000c3", // Player 14: Navy
|
|
106
|
-
"00ebff", // Player 15: Turquoise
|
|
107
|
-
"bd00ff", // Player 16: Violet
|
|
108
|
-
"ecce87", // Player 17: Wheat
|
|
109
|
-
"f7a58b", // Player 18: Peach
|
|
110
|
-
"bfff81", // Player 19: Mint
|
|
111
|
-
"dbb8eb", // Player 20: Lavender
|
|
112
|
-
"4f5055", // Player 21: Coal
|
|
113
|
-
"ecf0ff", // Player 22: Snow
|
|
114
|
-
"00781e", // Player 23: Emerald
|
|
115
|
-
"a56f34", // Player 24: Peanut
|
|
116
|
-
"2e2d2e", // Player Neutral: Black
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Standardized format for notifying player of events.
|
|
121
|
-
*/
|
|
122
|
-
export function notifyPlayer(msg: string) {
|
|
123
|
-
print(`${tColor("!", "goldenrod")} - ${msg}`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function displayError(msg: string) {
|
|
127
|
-
print(`[ ${tColor("WARNING", "red")} ]: ${msg}`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Returns degrees or radians?
|
|
132
|
-
*/
|
|
133
|
-
export function getRelativeAngleToUnit(unit: Unit, relativeUnit: Unit) {
|
|
134
|
-
const locA = GetUnitLoc(unit.handle);
|
|
135
|
-
const locB = GetUnitLoc(relativeUnit.handle);
|
|
136
|
-
const angle = AngleBetweenPoints(locA, locB);
|
|
137
|
-
|
|
138
|
-
RemoveLocation(locA);
|
|
139
|
-
RemoveLocation(locB);
|
|
140
|
-
|
|
141
|
-
return angle;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Manages state of effects in this context so you don't have to!
|
|
146
|
-
*/
|
|
147
|
-
export function useEffects() {
|
|
148
|
-
const effects: Effect[] = [];
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
addEffect: (effect: Effect | undefined) => {
|
|
152
|
-
if (effect) {
|
|
153
|
-
effects.push(effect);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
/**
|
|
157
|
-
* @returns reference to effects array
|
|
158
|
-
*/
|
|
159
|
-
getEffects: () => {
|
|
160
|
-
return effects;
|
|
161
|
-
},
|
|
162
|
-
destroyAllEffects: () => {
|
|
163
|
-
effects.forEach((e) => {
|
|
164
|
-
e.destroy();
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function useTempEffect(effect: Effect | undefined, duration: number = 1.5) {
|
|
171
|
-
if (effect) {
|
|
172
|
-
const timer = Timer.create();
|
|
173
|
-
|
|
174
|
-
timer.start(duration, false, () => {
|
|
175
|
-
effect.destroy();
|
|
176
|
-
timer.destroy();
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
package/src/utils/physics.ts
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
// import { WTS_Units } from "src/enums/WTS_Enums";
|
|
2
|
-
// import { PlayerIndex } from "src/player/player-data";
|
|
3
|
-
import { Effect, Timer, Unit } from "w3ts";
|
|
4
|
-
import { OrderId, Players } from "w3ts/globals";
|
|
5
|
-
|
|
6
|
-
interface ApplyForceConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Default: 0
|
|
9
|
-
*/
|
|
10
|
-
sustainedForceDuration?: number;
|
|
11
|
-
/**
|
|
12
|
-
* Default: -2400 units per second
|
|
13
|
-
*/
|
|
14
|
-
frictionConstant?: number;
|
|
15
|
-
/**
|
|
16
|
-
* The unit will not phase through unpathable areas
|
|
17
|
-
*/
|
|
18
|
-
obeyPathing?: boolean;
|
|
19
|
-
whileActive?: (currentSpeed?: number, timeElapsed?: number) => void;
|
|
20
|
-
onStart?: (currentSpeed?: number, timeElapsed?: number) => void;
|
|
21
|
-
onEnd?: (currentSpeed?: number, timeElapsed?: number) => void;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
targetSpeed?: number;
|
|
26
|
-
/**
|
|
27
|
-
* In seconds
|
|
28
|
-
*/
|
|
29
|
-
accelerationTime?: number;
|
|
30
|
-
/**
|
|
31
|
-
* This will be used to decide if the unit the force is applied on is allowed to deviate from their current path.
|
|
32
|
-
*/
|
|
33
|
-
strictPathing?: boolean;
|
|
34
|
-
animationIndexNumber?: number;
|
|
35
|
-
dummyUnitPlayerIndex: number;
|
|
36
|
-
dummyUnitFourCC: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param angle degrees
|
|
41
|
-
* @param unit
|
|
42
|
-
* @param initialSpeed meters per second
|
|
43
|
-
* @param affectHeight determines whether or not to change unit height whilst force is applied
|
|
44
|
-
*/
|
|
45
|
-
export function applyForce(
|
|
46
|
-
angle: number,
|
|
47
|
-
unit: Unit,
|
|
48
|
-
initialSpeed: number,
|
|
49
|
-
config: ApplyForceConfig
|
|
50
|
-
) {
|
|
51
|
-
const timer = Timer.create();
|
|
52
|
-
const refreshInterval = 0.01;
|
|
53
|
-
const updatesPerSecond = 1 / refreshInterval;
|
|
54
|
-
const frictionConstant = 4800; //meters per second friction decay
|
|
55
|
-
let currentSpeed = initialSpeed;
|
|
56
|
-
let timeElapsed = 0;
|
|
57
|
-
|
|
58
|
-
const clickMoveOrder = 851971;
|
|
59
|
-
const moveOrders = [
|
|
60
|
-
OrderId.Move,
|
|
61
|
-
OrderId.Attackground,
|
|
62
|
-
OrderId.Patrol,
|
|
63
|
-
OrderId.Attack,
|
|
64
|
-
clickMoveOrder,
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
let forceDummyUnit: Unit | undefined = undefined;
|
|
68
|
-
const defaultX = 11800;
|
|
69
|
-
const defaultY = -5700;
|
|
70
|
-
|
|
71
|
-
//Cancel unit commands - if a unit already has a move command and are applied a force, they will bug out sometimes and walk in the opposite direction
|
|
72
|
-
// unit.issueImmediateOrder(OrderId.Stop);
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Prematurely end the force effect
|
|
76
|
-
*/
|
|
77
|
-
function destroyForceEffect(runOnEnd: boolean = false) {
|
|
78
|
-
if (runOnEnd && config?.onEnd) {
|
|
79
|
-
config.onEnd();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
ResetUnitAnimation(unit.handle);
|
|
83
|
-
forceDummyUnit?.destroy();
|
|
84
|
-
timer.destroy();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* These are the positions the unit would be if there were no minor disturbances
|
|
89
|
-
*/
|
|
90
|
-
let theoreticalX = unit.x;
|
|
91
|
-
let theoreticalY = unit.y;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* The distance the true unit position can be from the theoretical position. Helps stop sliding against walls, etc.
|
|
95
|
-
*/
|
|
96
|
-
// const BREAK_DISTANCE = 100;
|
|
97
|
-
|
|
98
|
-
if (!forceDummyUnit) {
|
|
99
|
-
forceDummyUnit = Unit.create(
|
|
100
|
-
Players[config.dummyUnitPlayerIndex],
|
|
101
|
-
config.dummyUnitPlayerIndex,
|
|
102
|
-
defaultX,
|
|
103
|
-
defaultY
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// unit.issueImmediateOrder(OrderId.Stop);
|
|
108
|
-
|
|
109
|
-
if (config?.animationIndexNumber) {
|
|
110
|
-
ResetUnitAnimation(unit.handle);
|
|
111
|
-
SetUnitAnimationByIndex(unit.handle, config.animationIndexNumber);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
timer.start(refreshInterval, true, () => {
|
|
115
|
-
//If for whatever reason the unit no longer exists.
|
|
116
|
-
if (!unit) {
|
|
117
|
-
destroyForceEffect();
|
|
118
|
-
return destroyForceEffect;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// if (distanceBetweenPoints(unit.x, unit.y, theoreticalX, theoreticalY) > BREAK_DISTANCE) {
|
|
122
|
-
// print("unit was to far away from theoretical distance");
|
|
123
|
-
// const e = Effect.create("Abilities\\Spells\\Other\\TalkToMe\\TalkToMe", theoreticalX, theoreticalY);
|
|
124
|
-
// e?.setScaleMatrix(2, 2, 2);
|
|
125
|
-
// unit.issueImmediateOrder(OrderId.Stop);
|
|
126
|
-
|
|
127
|
-
// destroyForceEffect(true);
|
|
128
|
-
// return;
|
|
129
|
-
// }
|
|
130
|
-
|
|
131
|
-
//if the unit's move speed vector is greater than the remaining applied force vector then we may stop the applied force function; should only run while the unit has the move order
|
|
132
|
-
// if (config?.obeyPathing && !config.strictPathing && currentSpeed > unit.moveSpeed) {
|
|
133
|
-
// unit.issueImmediateOrder(OrderId.Stop);
|
|
134
|
-
// }
|
|
135
|
-
|
|
136
|
-
//should probably only do strict pathing so nothing else interfers with the unit moving
|
|
137
|
-
if (forceDummyUnit && config?.strictPathing) {
|
|
138
|
-
const isWindWalked = UnitHasBuffBJ(forceDummyUnit.handle, FourCC("BOwk"));
|
|
139
|
-
|
|
140
|
-
if (!isWindWalked) {
|
|
141
|
-
forceDummyUnit.issueImmediateOrder(OrderId.Windwalk);
|
|
142
|
-
}
|
|
143
|
-
// forceDummyUnit.issueImmediateOrder(OrderId.Stop);
|
|
144
|
-
|
|
145
|
-
//Move dummy to the position we want the unit to be in
|
|
146
|
-
forceDummyUnit.x = unit.x;
|
|
147
|
-
forceDummyUnit.y = unit.y;
|
|
148
|
-
|
|
149
|
-
forceDummyUnit.issueImmediateOrder(OrderId.Stop);
|
|
150
|
-
|
|
151
|
-
//flooring values since it can be off sometimes by a thousandth
|
|
152
|
-
if (
|
|
153
|
-
Math.floor(forceDummyUnit.x) !== Math.floor(unit.x) ||
|
|
154
|
-
Math.floor(forceDummyUnit.y) !== Math.floor(unit.y)
|
|
155
|
-
) {
|
|
156
|
-
// print(`Collision detected! Dummy x: ${forceDummyUnit.x} y: ${forceDummyUnit.y} Unit x: ${unit.x} y: ${unit.y}`);
|
|
157
|
-
const e = Effect.create(
|
|
158
|
-
"Abilities\\Spells\\Other\\TalkToMe\\TalkToMe",
|
|
159
|
-
forceDummyUnit.x,
|
|
160
|
-
forceDummyUnit.y
|
|
161
|
-
);
|
|
162
|
-
e?.setScaleMatrix(2, 2, 2);
|
|
163
|
-
destroyForceEffect(true);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const xVelocity =
|
|
169
|
-
(currentSpeed / updatesPerSecond) * Math.cos(Deg2Rad(angle));
|
|
170
|
-
const yVelocity =
|
|
171
|
-
(currentSpeed / updatesPerSecond) * Math.sin(Deg2Rad(angle));
|
|
172
|
-
|
|
173
|
-
//Complete execution when current speed of the initial force has decayed
|
|
174
|
-
if (currentSpeed <= 0) {
|
|
175
|
-
destroyForceEffect(true);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
//Runs when the force is first applied
|
|
180
|
-
if (config?.onStart && currentSpeed === initialSpeed) {
|
|
181
|
-
config.onStart(currentSpeed, timeElapsed);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
//Runs at any point while the function is executing
|
|
185
|
-
if (config?.whileActive) {
|
|
186
|
-
config.whileActive(currentSpeed, timeElapsed);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
theoreticalX += xVelocity;
|
|
190
|
-
theoreticalY += yVelocity;
|
|
191
|
-
|
|
192
|
-
//basically the same thing now since we are no longer issuing the stop command on the unit.
|
|
193
|
-
//also the moment another force is applied to the unit the previous force will stop being applied.
|
|
194
|
-
if (config?.strictPathing) {
|
|
195
|
-
unit.x = theoreticalX;
|
|
196
|
-
unit.y = theoreticalY;
|
|
197
|
-
} else {
|
|
198
|
-
unit.x += xVelocity;
|
|
199
|
-
unit.y += yVelocity;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
timeElapsed += refreshInterval;
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
config?.sustainedForceDuration &&
|
|
206
|
-
timeElapsed <= config.sustainedForceDuration
|
|
207
|
-
) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
currentSpeed -= frictionConstant / updatesPerSecond;
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
return { destroyForceEffect };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* @param angle degrees
|
|
219
|
-
* @param effect
|
|
220
|
-
* @param initialSpeed meters per second
|
|
221
|
-
* @param affectHeight determines whether or not to change unit height whilst force is applied
|
|
222
|
-
*/
|
|
223
|
-
export function applyForceForEffect(
|
|
224
|
-
angle: number,
|
|
225
|
-
effect: Effect,
|
|
226
|
-
initialSpeed: number,
|
|
227
|
-
config?: ApplyForceConfig
|
|
228
|
-
) {
|
|
229
|
-
const timer = Timer.create();
|
|
230
|
-
const refreshInterval = 0.01;
|
|
231
|
-
const updatesPerSecond = 1 / refreshInterval;
|
|
232
|
-
const frictionConstant = 1200; //meters per second friction decay
|
|
233
|
-
let currentSpeed = initialSpeed;
|
|
234
|
-
let timeElapsed = 0;
|
|
235
|
-
|
|
236
|
-
//Cancel unit commands - if a unit already has a move command and are applied a force, they will bug out sometimes and walk in the opposite direction
|
|
237
|
-
|
|
238
|
-
timer.start(refreshInterval, true, () => {
|
|
239
|
-
//if the unit's move speed vector is greater than the remaining applied force vector then we may stop the applied force function; should only run while the unit has the move order
|
|
240
|
-
const xVelocity =
|
|
241
|
-
(currentSpeed / updatesPerSecond) * Math.cos(Deg2Rad(angle));
|
|
242
|
-
const yVelocity =
|
|
243
|
-
(currentSpeed / updatesPerSecond) * Math.sin(Deg2Rad(angle));
|
|
244
|
-
|
|
245
|
-
//On end hook runs before the timer is destroyed and the function ends
|
|
246
|
-
if (config?.onEnd && currentSpeed <= 0) {
|
|
247
|
-
config.onEnd(currentSpeed, timeElapsed);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
//Complete execution when current speed of the initial force has decayed
|
|
251
|
-
if (currentSpeed <= 0) {
|
|
252
|
-
timer.destroy();
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
//Runs when the force is first applied
|
|
257
|
-
if (config?.onStart && currentSpeed === initialSpeed) {
|
|
258
|
-
config.onStart(currentSpeed, timeElapsed);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
//Runs at any point while the function is executing
|
|
262
|
-
if (config?.whileActive) {
|
|
263
|
-
config.whileActive(currentSpeed, timeElapsed);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
effect.x += xVelocity;
|
|
267
|
-
effect.y += yVelocity;
|
|
268
|
-
|
|
269
|
-
timeElapsed += refreshInterval;
|
|
270
|
-
|
|
271
|
-
if (
|
|
272
|
-
config?.sustainedForceDuration &&
|
|
273
|
-
timeElapsed <= config.sustainedForceDuration
|
|
274
|
-
) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
currentSpeed -= frictionConstant / updatesPerSecond;
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
function destroyForceEffect() {
|
|
282
|
-
timer.destroy();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return { destroyForceEffect };
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// const unitIsMovingVector_x = (unit.moveSpeed / updatesPerSecond) * Math.cos(Deg2Rad(unit.facing));
|
|
289
|
-
// const unitIsMovingVector_y = (unit.moveSpeed / updatesPerSecond) * Math.sin(Deg2Rad(unit.facing));
|
|
290
|
-
// if ((moveOrders.includes(unit.currentOrder) && unitIsMovingVector_x > xVelocity) || unitIsMovingVector_y > yVelocity) {
|
|
291
|
-
// print("moving velocity exceeded applied force velocity");
|
|
292
|
-
// timer.destroy();
|
|
293
|
-
|
|
294
|
-
// return;
|
|
295
|
-
// }
|