Skip to content

Commit

Permalink
Merge pull request #784 from QuentinGruber/feature/useSchedulerApi
Browse files Browse the repository at this point in the history
Feature/useSchedulerApi
  • Loading branch information
QuentinGruber committed Apr 4, 2022
2 parents afa20aa + c6d2c81 commit 6cbcbbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/servers/ZoneServer2016/classes/craftmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Based on https://github.com/psemu/soe-network
// ======================================================================

import { Scheduler } from "../../../utils/utils";
import { ZoneServer2016 } from "../zoneserver";
import { ZoneClient2016 as Client } from "./zoneclient";
const debug = require("debug")("ZoneServer");
Expand Down Expand Up @@ -74,7 +75,7 @@ export class CraftManager {
count: number
): Promise<boolean> {
// if craftItem gets stuck in an infinite loop somehow, setImmediate will prevent the server from crashing
server.pSetImmediate();
Scheduler.yield()
if (!count) return true;
debug(`[CraftManager] Crafting ${count} of itemDefinitionId ${recipeId}`);
const recipe = server._recipes[recipeId];
Expand Down
7 changes: 3 additions & 4 deletions src/servers/ZoneServer2016/zoneserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
isPosInRadius,
getDistance,
randomIntFromInterval,
Scheduler,
} from "../../utils/utils";

import { Db, MongoClient } from "mongodb";
Expand Down Expand Up @@ -860,7 +861,7 @@ export class ZoneServer2016 extends ZoneServer2015 {
if (isPosInRadius(5, vehicle.npcData.position, position)) {
const distance = getDistance(position, vehicle.npcData.position);
const damage = 250000 / distance;
await this.pSetTimeout(150);
await Scheduler.wait(150);
this.damageVehicle(damage, vehicle);
}
}
Expand All @@ -869,7 +870,7 @@ export class ZoneServer2016 extends ZoneServer2015 {
const explosiveObj = this._explosives[explosive];
if (explosiveObj.characterId != npcTriggered) {
if (getDistance(position, explosiveObj.position) < 2) {
await this.pSetTimeout(150);
await Scheduler.wait(150);
this.explodeExplosive(explosiveObj);
}
}
Expand Down Expand Up @@ -3745,8 +3746,6 @@ export class ZoneServer2016 extends ZoneServer2015 {
).zonePacketHandlers();
await this._packetHandlers.reloadCommandCache();
}
pSetImmediate = promisify(setImmediate);
pSetTimeout = promisify(setTimeout)
}

if (process.env.VSCODE_DEBUG === "true") {
Expand Down

0 comments on commit 6cbcbbc

Please sign in to comment.