Compare commits

...

7 Commits

Author SHA1 Message Date
tamilpp25
04b3566261 change to fromPartial() 2022-08-12 22:16:28 +05:30
tamilpp25
89d2cc73f0 fix conflicts and beautify 2022-08-08 10:15:02 +05:30
tamilpp25
90c6290cea Merge branch 'main' into patch-2 2022-08-08 10:07:11 +05:30
tamilpp25
1d5d7c1f40 Update scene.ts 2022-08-06 15:25:16 +05:30
tamilpp25
5c6ae768b8 prevent saving some scenes to db
as they cause invalid scene bug during login
2022-08-06 15:20:15 +05:30
tamilpp25
e65a807f62 better nesting 2022-08-05 23:56:29 +05:30
tamilpp25
9f1d85b5c1 scene command again
hope its fine now
2022-08-05 23:20:04 +05:30
2 changed files with 83 additions and 41 deletions

View File

@ -1,50 +1,88 @@
import Logger from "../util/Logger";
import { ActorEntity } from "../game/entities/Actor";
import Interface, { Command } from "./Interface";
import { GetCurSceneInfoScRsp } from "../data/proto/StarRail";
import MazePlaneExcel from "../util/excel/MazePlaneExcel";
import MapEntryExcel from "../util/excel/MapEntryExcel";
const c = new Logger("/scene", "blue");
import Logger from '../util/Logger';
import { ActorEntity } from '../game/entities/Actor';
import Interface, { Command } from './Interface';
import { GetCurSceneInfoScRsp } from '../data/proto/StarRail';
import MazePlaneExcel from '../util/excel/MazePlaneExcel';
import MapEntryExcel from '../util/excel/MapEntryExcel';
const c = new Logger('/scene', 'blue');
export default async function handle(command: Command) {
if (!Interface.target) {
c.log("No target specified");
return;
if (!Interface.target) {
c.log('No target specified');
return;
}
if (command.args.length == 0) {
c.log('Usage: /scene <planeID|floorID>');
return;
}
const planeData =
MazePlaneExcel.fromFloorId(parseInt(command.args[0])) ||
MazePlaneExcel.fromPlaneId(parseInt(command.args[0])); //Get plane data
let floorId = 10001001; // Default floor data
if (planeData!) {
if (command.args[0].length === 5) {
// If input is planeId
floorId = planeData.StartFloorID;
} else if (
command.args[0].length === 8 &&
planeData.FloorIDList.includes(parseInt(command.args[0]))
) {
// If input is floorId
floorId = parseInt(command.args[0]);
} else {
c.error('cannot find Scene data!', false);
return;
}
} else {
c.error('cannot find Scene data!', false);
return;
}
const planeID = MazePlaneExcel.fromPlaneId(parseInt(command.args[0]));
const entryId = MapEntryExcel.fromFloorId(planeID.StartFloorID).ID;
const posData = Interface.target.player.db.posData;
const lineup2 = await Interface.target.player.getLineup();
const curAvatarEntity = new ActorEntity(Interface.target.player.scene, lineup2.avatarList[0].id, posData.pos);
const entryId = MapEntryExcel.fromFloorId(planeData.StartFloorID).ID;
if (!planeID) return c.log("Usage: /scene <planeID>");
const posData = Interface.target.player.db.posData;
const lineup = await Interface.target.player.getLineup();
const curAvatarEntity = new ActorEntity(
Interface.target.player.scene,
lineup.leaderSlot,
posData.pos
);
// Update scene information on player.
Interface.target.player.db.posData.planeID = planeID!.PlaneID;
Interface.target.player.db.posData.floorID = planeID!.StartFloorID;
await Interface.target.player.save()
const allowedScenes = ['Train', 'Town', 'Maze']; //Scenes that won't break when you relog
// Update scene information on player.
if (allowedScenes.includes(planeData.PlaneType)) {
Interface.target.player.db.posData.planeID = planeData.PlaneID;
Interface.target.player.db.posData.floorID = floorId;
await Interface.target.player.save();
}
//ty for tamilpp25 scene
Interface.target.send(GetCurSceneInfoScRsp, {
retcode: 0,
scene: {
planeId: planeID.PlaneID,
floorId: planeID.StartFloorID,
entityList: [
curAvatarEntity
],
entityBuffList: [],
entryId: entryId,
envBuffList: [],
gameModeType: MazePlaneExcel.getGameModeForPlaneType(planeID.PlaneType),
lightenSectionList: []
},
} as unknown as GetCurSceneInfoScRsp);
Interface.target.player.scene.spawnEntity(curAvatarEntity, true);
//change scene for player
Interface.target.send(
GetCurSceneInfoScRsp,
GetCurSceneInfoScRsp.fromPartial({
retcode: 0,
scene: {
planeId: planeData.PlaneID,
floorId: floorId,
entityList: [curAvatarEntity.getSceneEntityInfo()],
leaderEntityId: curAvatarEntity.entityId,
entityBuffList: [],
entryId: entryId,
envBuffList: [],
gameModeType: MazePlaneExcel.getGameModeForPlaneType(
planeData.PlaneType
),
lightenSectionList: [],
},
})
);
Interface.target.sync();
Interface.target.player.scene.spawnEntity(curAvatarEntity, true);
c.log(`Scene set to PlaneID: ${planeID.PlaneID}`);
Interface.target.sync();
c.log(`Scene set to floorId: ${floorId}`);
}

View File

@ -25,6 +25,11 @@ export default class MazePlaneExcel {
return MazePlaneExcelTable[planeId.toString()];
}
public static fromFloorId(floorId: number): MazePlaneExcelTableEntry {
return MazePlaneExcelTable[floorId.toString().slice(0,5)];
}
public static getGameModeForPlaneType(planeType: string): number {
switch (planeType) {
case "Town": return 1;
@ -39,7 +44,6 @@ export default class MazePlaneExcel {
case "Client": return 10;
case "ChallengeActivity": return 11;
}
return 0;
}
}