Skip to content

Commit

Permalink
Bug fixes for my bad code lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis committed Jan 2, 2024
1 parent ff516a4 commit 77a7081
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 123 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "wc3-ts-template",
"version": "1.1.0",
"version": "1.3.1",
"description": "",
"author": "TriggerHappy",
"license": "MIT",
"main": "src/main.ts",
"scripts": {
"test": "ts-node --transpile-only scripts/test.ts",
"build": "ts-node --transpile-only scripts/build.ts",
"run": "ts-node --transpile-only scripts/run.ts",
"dev": "npm-watch",
"build:defs": "ts-node scripts/dev"
},
Expand Down
13 changes: 7 additions & 6 deletions scripts/main.debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class CustomPrinter extends tstl.LuaPrinter {
private config: IProjectConfig;

private blacklist = [
'onForceTakeOrDealDamage',
'addAggressionLog',
'aggressionBetweenTwoPlayers'
// 'onForceTakeOrDealDamage',
// 'addAggressionLog',
// 'aggressionBetweenTwoPlayers',
'DisplayTimedTextToPlayer',
];

private blacklistCalc = new RegExp(this.blacklist.join('|'));
Expand All @@ -41,10 +42,7 @@ class CustomPrinter extends tstl.LuaPrinter {
// console.log("Source: "+source);
if (source.includes('.ts')) {
const text = originalResult.toString();

const blacklist = [];
const containsBlacklisted = !!text.match(this.blacklistCalc);
// console.log("text: "+text);
if (text.includes('local') && !containsBlacklisted) {
const tabs = text.split(regex);
const tabSpacer = (tabs && tabs[1].length > 0) ? tabs[1] : undefined;
Expand All @@ -57,6 +55,9 @@ class CustomPrinter extends tstl.LuaPrinter {
app = `${tabSpacer}if (MessageAllPlayers~=nil) then\n${tabSpacer} MessageAllPlayers("uuid ${uuid}")\n${tabSpacer}end\n`;
}
}
else if (containsBlacklisted) {
console.log("Blacklisted Func: "+text);
}
}
// if (originalResult.source)
// console.log("printing statement: "+originalResult);
Expand Down
24 changes: 24 additions & 0 deletions scripts/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {exec, execFile, execSync} from "child_process";
import {loadJsonFile, logger, compileMap, IProjectConfig} from "./utils";

function runMap() {
const config: IProjectConfig = loadJsonFile("config.json");
const cwd = process.cwd();
const filename = `${cwd}/dist/${config.mapFolder}`;

logger.info(`Launching map "${filename.replace(/\\/g, "/")}"...`);

if(config.winePath) {
const wineFilename = `"Z:${filename}"`
const prefix = config.winePrefix ? `WINEPREFIX=${config.winePrefix}` : ''
execSync(`${prefix} ${config.winePath} "${config.gameExecutable}" ${["-loadfile", wineFilename, ...config.launchArgs].join(' ')}`, { stdio: 'ignore' });
} else {
execFile(config.gameExecutable, ["-loadfile", filename, ...config.launchArgs], (err: any) => {
if (err && err.code === 'ENOENT') {
logger.error(`No such file or directory "${config.gameExecutable}". Make sure gameExecutable is configured properly in config.json.`);
}
});
}
}

runMap();
80 changes: 55 additions & 25 deletions src/app/abilities/ability-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ export class AbilityHooks extends Entity {
castAbilityTrigger.registerAnyUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT);
castAbilityTrigger.addAction(() => {
const u = Unit.fromHandle(GetTriggerUnit());

// showOverheadText(u.x, u.y, 88, 171, 174, 255, `${GetAbilityName(GetSpellAbilityId())}`);
this.unitCastsSpell();
this.sendBehaviourEvent(u, ABILITY_HOOK.UnitCastsAbility);
});
Expand Down Expand Up @@ -156,22 +154,52 @@ export class AbilityHooks extends Entity {
}

private unitAttacks(attackingUnit: unit) {
this.sendBehaviourEvent(Unit.fromHandle(attackingUnit), ABILITY_HOOK.UnitAttacks);
if (attackingUnit !== undefined) {
this.sendBehaviourEvent(Unit.fromHandle(attackingUnit), ABILITY_HOOK.UnitAttacks);
}
else {
Log.Error("Null unit passed to unitAttacks");
}
}
private unitAttacked(attackedUnit: unit) {
this.sendBehaviourEvent(Unit.fromHandle(attackedUnit), ABILITY_HOOK.UnitIsAttacked);
if (attackedUnit !== undefined) {
this.sendBehaviourEvent(Unit.fromHandle(attackedUnit), ABILITY_HOOK.UnitIsAttacked);
}
else {
Log.Error("Null unit passed to unitAttacked");
}
}
private unitPreDamaged(damagedUnit: unit) {
this.sendBehaviourEvent(Unit.fromHandle(damagedUnit), ABILITY_HOOK.PreUnitTakesDamage);
if (damagedUnit !== undefined) {
this.sendBehaviourEvent(Unit.fromHandle(damagedUnit), ABILITY_HOOK.PreUnitTakesDamage);
}
else {
Log.Error("Null unit passed to unitPreDamaged");
}
}
private unitPreDamaging(damagingUnit: unit) {
this.sendBehaviourEvent(Unit.fromHandle(damagingUnit), ABILITY_HOOK.PreUnitDealsDamage);
if (damagingUnit !== undefined) {
this.sendBehaviourEvent(Unit.fromHandle(damagingUnit), ABILITY_HOOK.PreUnitDealsDamage);
}
else {
Log.Error("Null unit passed to unitPreDamaging");
}
}
private unitPostDamaged(damagedUnit: unit) {
this.sendBehaviourEvent(Unit.fromHandle(damagedUnit), ABILITY_HOOK.PostUnitTakesDamage);
if (damagedUnit !== undefined) {
this.sendBehaviourEvent(Unit.fromHandle(damagedUnit), ABILITY_HOOK.PostUnitTakesDamage);
}
else {
Log.Error("Null unit passed to unitPostDamaged");
}
}
private unitPostDamaging(damagingUnit: unit) {
this.sendBehaviourEvent(Unit.fromHandle(damagingUnit), ABILITY_HOOK.PostUnitDealsDamage);
if (damagingUnit !== undefined) {
this.sendBehaviourEvent(Unit.fromHandle(damagingUnit), ABILITY_HOOK.PostUnitDealsDamage);
}
else {
Log.Error("Null unit passed to PostDamaging");
}
}

private checkBehaviourKeysFor(u: Unit) {
Expand Down Expand Up @@ -200,24 +228,26 @@ export class AbilityHooks extends Entity {
}
}

private sendBehaviourEvent(u: Unit, ev: ABILITY_HOOK) {
const behaviours = this.behavioursForUnit.get(u.id);
if (behaviours && behaviours.length > 0) {
for (let index = 0; index < behaviours.length; index++) {
const b = behaviours[index];
try {
b.onEvent(ev);
if (b.doDestroy()) {
b.destroy();
behaviours.splice(index--, 1);
if (behaviours.length === 0) {
this.behavioursForUnit.delete(u.id);
}
}
private sendBehaviourEvent(u: Unit | undefined, ev: ABILITY_HOOK) {
if (u && u.id) {
const behaviours = this.behavioursForUnit.get(u.id);
if (behaviours && behaviours.length > 0) {
for (let index = 0; index < behaviours.length; index++) {
const b = behaviours[index];
try {
b.onEvent(ev);
if (b.doDestroy()) {
b.destroy();
behaviours.splice(index--, 1);
if (behaviours.length === 0) {
this.behavioursForUnit.delete(u.id);
}
}
}
catch(e) {
Log.Error("Behaviour Error: ", e);
}
}
catch(e) {
Log.Error("Behaviour Error: ", e);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/abilities/global-ability-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class GlobalCooldownAbilityEntity extends Entity {
* @param u
*/
private onUnitRemove(u: Unit) {

const uAbils = this.unitsListeningToAbility.get(u.id);
if (!uAbils) return;

Expand Down
6 changes: 4 additions & 2 deletions src/app/buff/buffs/purity-seal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ export class PuritySeal extends DynamicBuff {
EventEntity.getInstance().addListener(this.levelUpTracker);
}
else {
this.damageTracker.destroy();
this.damageTracker = undefined;
if (this.damageTracker) {
this.damageTracker.destroy();
this.damageTracker = undefined;
}
EventEntity.getInstance().removeListener(this.levelUpTracker);
this.levelUpTracker = undefined;

Expand Down
33 changes: 21 additions & 12 deletions src/app/cinematics/intro-cinematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class IntroCinematic {
this.portalSfx = portalSFX;
this.warpStormSound.playSound();

const hostileDummy = new Unit(MapPlayer.fromIndex(25), FourCC('dumy'), 0, 0, bj_UNIT_FACING);


for (let i = 0; i < 12; i++) {
Expand All @@ -102,15 +101,15 @@ export class IntroCinematic {

SetCameraTargetController(mainShip.unit.handle, 0, 0, false);


// const hostileDummy = new Unit(MapPlayer.fromIndex(25), FourCC('dumy'), 0, 0, bj_UNIT_FACING);
await Promise.all([
this.captainChatMessages(),
this.inquistorChatMessages(),
this.navigatorChatMessages(),
this.engineerChatMessages(),
this.systemChatMessages(),
this.shipSounds(),
// this.hostileProjectiles(mainShip.unit, hostileDummy)
// this.hostileProjectiles(mainShip.unit)
]);

return;
Expand Down Expand Up @@ -167,34 +166,43 @@ export class IntroCinematic {
await Timers.wait(2);
PlayNewSound("Sounds\\ComplexBeep.mp3", 127);
MessageAllPlayers(`[${COL_ATTATCH}DANGER|r] Simulation results: VESSEL DAMAGED 80%, VESSEL DESTROYED 19%`);
CinematicFadeBJ(bj_CINEFADETYPE_FADEOUTIN, 4, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0);

await Timers.wait(2);
PlayNewSound("Sounds\\ComplexBeep.mp3", 127);
MessageAllPlayers(`[${COL_ATTATCH}DANGER|r] WARP ENTITY INTERCEPTING VESSEL`);
CinematicFadeBJ(bj_CINEFADETYPE_FADEOUTIN, 4, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0);
EnableUserUI(true);
}

private async hostileProjectiles(mainShip: Unit, hostileDummy: Unit) {
const shipLoc = Vector3.fromWidget(mainShip.handle).add(new Vector3(1200, 1200, 0));
const sourceLoc = Vector3.fromWidget(mainShip.handle).projectTowards2D(90, 1800);
private async hostileProjectiles(mainShip: Unit) {

// const snd1 = new SoundRef("Sounds\\ExplosionBassHeavy.mp3", false, true);
// const snd2 = new SoundRef("Sounds\\ExplosionBassHeavy.mp3", false, true);
// const snd3 = new SoundRef("Sounds\\ExplosionBassHeavy.mp3", false, true);

// const hostileDummy = new Unit(PlayerStateFactory.AlienAIPlayer1, UNIT_ID_DUMMY_CASTER, sourceLoc.x, sourceLoc.y);
await Timers.wait(0.1);
let sourceLoc = Vector3.fromWidget(mainShip.handle)
.projectTowards2D(mainShip.facing, -2000)
.add(new Vector3(-200 + 400 * Math.random(), -200 + 400 * Math.random(), 0));
const hostileDummy = new Unit(PlayerStateFactory.NeutralHostile, UNIT_ID_DUMMY_CASTER, sourceLoc.x, sourceLoc.y);



for (let index = 0; index < 20; index++) {
let shipLoc = Vector3.fromWidget(mainShip.handle);
let sourceLoc = Vector3.fromWidget(mainShip.handle)
.projectTowards2D(mainShip.facing, -2000)
.add(new Vector3(-200 + 400 * Math.random(), -200 + 400 * Math.random(), 0));

// snd1.playSound();
this.spawnProj(hostileDummy, shipLoc, sourceLoc);
await Timers.wait(0.2);
await Timers.wait(0.2);
// snd2.playSound();
this.spawnProj(hostileDummy, shipLoc, sourceLoc);
await Timers.wait(0.2);
// snd3.playSound();
this.spawnProj(hostileDummy, shipLoc, sourceLoc);
await Timers.wait(1.6);
await Timers.wait(0.2 + Math.random() * 1);
}
}

Expand All @@ -216,8 +224,9 @@ export class IntroCinematic {
startLoc,
new ProjectileTargetStatic(deltaLoc)
)
.setVelocity(2000)
.onCollide(() => true);
.setVelocity(2000)
.onCollide(() => true);

projectile.addEffect(SFX_LASER_5, new Vector3(0, 0, 0), deltaLoc.normalise(), 1);
EventEntity.send(EVENT_TYPE.ADD_PROJECTILE, { source: forDummy, data: { projectile: projectile }});
}
Expand Down
9 changes: 7 additions & 2 deletions src/app/events/unit-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,15 @@ export class UnitDex {

private static onGameStart() {
DestroyTimer(GetExpiredTimer());
for (let index = 0; index < this.counter; index++) {
for (let index = 1; index < this.counter; index++) {
this.lastIndex = index;
this.eventUnit = this.unit[index];
this.indexTrig[UnitDexEvent.INDEX].exec();
if (this.eventUnit?.handle) {
this.indexTrig[UnitDexEvent.INDEX].exec();
}
else {
Log.Error(`UDexGameStart: Unit not found at ${index} of ${this.counter}`)
}
}
this.lastIndex = this.counter;
this.initialized = true;
Expand Down
19 changes: 8 additions & 11 deletions src/app/force/forces/alien-force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ABIL_TRANSFORM_HUMAN_ALIEN, TECH_MAJOR_HEALTHCARE, TECH_ROACH_DUMMY_UPG
import { Crewmember } from "app/crewmember/crewmember-type";
import { alienTooltipToAlien, alienTooltipToHuman } from "resources/ability-tooltips";
import { PlayNewSound } from "lib/translators";
import { Trigger, MapPlayer, Unit, playerColors, getElapsedTime } from "w3ts";
import { Trigger, MapPlayer, Unit, playerColors, getElapsedTime, playerColorNames } from "w3ts";
import { ROLE_TYPES } from "resources/crewmember-names";
import { SoundRef, SoundWithCooldown } from "app/types/sound-ref";
import { STR_CHAT_ALIEN_HOST, STR_CHAT_ALIEN_SPAWN, STR_CHAT_ALIEN_TAG, STR_ALIEN_DEATH } from "resources/strings";
Expand Down Expand Up @@ -125,10 +125,11 @@ export class AlienForce extends ForceType {
const killingUnit = Unit.fromHandle(GetKillingUnit());

const validKillingPlayer =
killingUnit != undefined && (
// If it's an alien AI killer
PlayerStateFactory.isAlienAI(killingUnit.owner) ||
// If it's a player killer
(this.hasPlayer(killingUnit.owner) && this.getAlienFormForPlayer(killingUnit.owner) === killingUnit);
(this.hasPlayer(killingUnit.owner) && this.getAlienFormForPlayer(killingUnit.owner) === killingUnit));
const validDyingUnit = !this.hasPlayer(dyingUnit.owner) && !PlayerStateFactory.isAlienAI(dyingUnit.owner) && dyingUnit.typeId !== CREWMEMBER_UNIT_ID;
const validDyingType = !IsUnitType(dyingUnit.handle, UNIT_TYPE_MECHANICAL);

Expand Down Expand Up @@ -178,11 +179,7 @@ export class AlienForce extends ForceType {
TooltipEntity.getInstance().registerTooltip(who, alienTooltipToHuman);

this.registerAlienDeath(alien);
// Also register the crewmember for the event
// this.registerAlienDealsDamage(who);


// TODO Change how vision is handled
const pData = PlayerStateFactory.get(owner);
const crewmember = pData.getCrewmember();

Expand All @@ -192,7 +189,6 @@ export class AlienForce extends ForceType {
}

this.applyAlienMinionHost(alien, owner === this.alienHost);
// alien.nameProper = "|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|n|nAlien";

// Add ability tooltip
TooltipEntity.getInstance().registerTooltip(who, alienTooltipToAlien);
Expand Down Expand Up @@ -334,7 +330,7 @@ export class AlienForce extends ForceType {
// Ensure player name reverts
const pData = PlayerStateFactory.get(player);
player.name = pData.originalName;
player.color = pData.originalColour;
player.color = pData.originalColour.playerColor;

PlayNewSound("Sounds\\Nazgul.wav", 50);
Players.forEach(p => {
Expand Down Expand Up @@ -403,9 +399,10 @@ export class AlienForce extends ForceType {
const alienUnit = this.getAlienFormForPlayer(player);

this.setHost(player);
playerColorNames
this.applyAlienMinionHost(alienUnit, true);
this.players.forEach(p => {
MessagePlayer(p, `|cff${pData.originalColour}${crew.name}|r${COL_ALIEN} is your new host.`);
MessagePlayer(p, `${pData.originalColour.code}${crew.name}|r${COL_ALIEN} is your new host.`);
});
}

Expand All @@ -420,7 +417,7 @@ export class AlienForce extends ForceType {

transform(who: MapPlayer, toAlien: boolean): Unit | void {
this.playerIsTransformed.set(who.id, toAlien);

const alien = this.playerAlienUnits.get(who.id);
let unit = this.playerUnits.get(who.id);

Expand Down Expand Up @@ -484,7 +481,7 @@ export class AlienForce extends ForceType {
// Ensure player name reverts
const pData = PlayerStateFactory.get(who);
who.name = pData.originalName;
who.color = pData.originalColour;
who.color = pData.originalColour.playerColor;

// Post event
EventEntity.getInstance().sendEvent(EVENT_TYPE.ALIEN_TRANSFORM_CREW, { crewmember: crewmember, source: alien });
Expand Down
Loading

0 comments on commit 77a7081

Please sign in to comment.