diff --git a/src/events/Raw.ts b/src/events/Raw.ts index ce27f3d..f64915c 100644 --- a/src/events/Raw.ts +++ b/src/events/Raw.ts @@ -13,7 +13,7 @@ import { World } from "../structures/World"; import { DroppedItem } from "../types/world"; import { Place } from "../tanks/Place"; import { Punch } from "../tanks/Punch"; -import { Wrench } from "../tanks/Wrench"; +import { Player } from "../tanks/Player"; export default class extends Listener<"raw"> { constructor(base: BaseServer) { @@ -67,7 +67,7 @@ export default class extends Listener<"raw"> { "www.growtopia1.com", "growtopia/cache/", "cc.cz.madkite.freedom org.aqua.gg idv.aqua.bulldog com.cih.gamecih2 com.cih.gamecih com.cih.game_cih cn.maocai.gamekiller com.gmd.speedtime org.dax.attack com.x0.strai.frep com.x0.strai.free org.cheatengine.cegui org.sbtools.gamehack com.skgames.traffikrider org.sbtoods.gamehaca com.skype.ralder org.cheatengine.cegui.xx.multi1458919170111 com.prohiro.macro me.autotouch.autotouch com.cygery.repetitouch.free com.cygery.repetitouch.pro com.proziro.zacro com.slash.gamebuster", - "proto=200|choosemusic=audio/mp3/about_theme.mp3|active_holiday=6|wing_week_day=0|ubi_week_day=0|server_tick=638729041|clash_active=0|drop_lavacheck_faster=1|isPayingUser=0|usingStoreNavigation=1|enableInventoryTab=1|bigBackpack=1|" + "proto=204|choosemusic=audio/mp3/about_theme.mp3|active_holiday=6|wing_week_day=0|ubi_week_day=0|server_tick=638729041|clash_active=0|drop_lavacheck_faster=1|isPayingUser=0|usingStoreNavigation=1|enableInventoryTab=1|bigBackpack=1|" ), Variant.from("SetHasGrowID", 1, user.name, decrypt(user.password)), Variant.from("SetHasAccountSecured", 1) @@ -260,6 +260,7 @@ export default class extends Listener<"raw"> { case TankTypes.PEER_MOVE: { if (peer.data?.world === "EXIT") break; + const world = peer.hasWorld(peer.data.world) as World; tank.data.netID = peer.data?.netID; peer.data.x = tank.data.xPos; @@ -272,6 +273,9 @@ export default class extends Listener<"raw"> { p.send(tank); } }); + + const player = new Player(this.base, peer, tank, world); + player.onPlayerMove(); break; } case TankTypes.TILE_PUNCH: { @@ -283,8 +287,8 @@ export default class extends Listener<"raw"> { const punch = new Punch(this.base, peer, tank, world); punch.onPunch(); } else if (tank.data.info === 32) { - const wrench = new Wrench(this.base, peer, tank, world); - wrench.onWrench(); + const player = new Player(this.base, peer, tank, world); + player.onTileWrench(); } // Others else { diff --git a/src/structures/Peer.ts b/src/structures/Peer.ts index 0ad7078..9aee517 100644 --- a/src/structures/Peer.ts +++ b/src/structures/Peer.ts @@ -1,10 +1,12 @@ import { Peer as OldPeer, TankPacket, TextPacket, Variant } from "growtopia.js"; -import { PeerDataType } from "../types/peer"; +import { CheckPoint, PeerDataType } from "../types/peer"; import { Role, WORLD_SIZE } from "../utils/Constants"; import { DataTypes } from "../utils/enums/DataTypes"; import { TankTypes } from "../utils/enums/TankTypes"; import { BaseServer } from "./BaseServer"; import { World } from "./World"; +import { ActionTypes } from "../utils/enums/Tiles"; +import { Block } from "../types/world"; export class Peer extends OldPeer { public base; @@ -107,7 +109,23 @@ export class Peer extends OldPeer { public respawn() { const world = this.hasWorld(this.data.world); - const mainDoor = world?.data.blocks?.find((block) => block.fg === 6); + let mainDoor = world?.data.blocks.find((block) => block.fg === 6); + + if (this.data.lastCheckpoint) { + const pos = this.data.lastCheckpoint.x + this.data.lastCheckpoint.y * (world?.data.width as number); + const block = world?.data.blocks[pos]; + const itemMeta = this.base.items.metadata.items[(block?.fg as number) || (block?.bg as number)]; + + if (itemMeta && itemMeta.type === ActionTypes.CHECKPOINT) { + mainDoor = this.data.lastCheckpoint as Block; // only have x,y. + } else { + this.data.lastCheckpoint = undefined; + this.send(Variant.from({ netID: this.data.netID, delay: 0 }, "SetRespawnPos", 0)); + mainDoor = world?.data.blocks?.find((block) => block.fg === 6); + } + } else { + mainDoor = world?.data.blocks.find((block) => block.fg === 6); + } this.send( Variant.from({ netID: this.data.netID }, "OnSetFreezeState", 1), diff --git a/src/structures/World.ts b/src/structures/World.ts index f2403b0..b255041 100644 --- a/src/structures/World.ts +++ b/src/structures/World.ts @@ -96,6 +96,8 @@ export class World { public leave(peer: Peer, sendMenu = true) { this.data.playerCount ? this.data.playerCount-- : 0; + + peer.data.lastCheckpoint = undefined; peer.send(TextPacket.from(DataTypes.ACTION, "action|play_sfx", "file|audio/door_shut.wav", "delayMS|0")); peer.everyPeer((p) => { diff --git a/src/tanks/Place.ts b/src/tanks/Place.ts index f1d4e11..cc8b762 100644 --- a/src/tanks/Place.ts +++ b/src/tanks/Place.ts @@ -202,6 +202,20 @@ export class Place { return true; } + case ActionTypes.STEAMPUNK: + case ActionTypes.CHECKPOINT: { + this.world.place({ + peer: this.peer, + x: p.block.x, + y: p.block.y, + isBg: p.isBg, + id: p.id + }); + + this.tileUpdate(p.actionType, p.block); + return true; + } + case ActionTypes.PORTAL: case ActionTypes.DOOR: case ActionTypes.MAIN_DOOR: { diff --git a/src/tanks/Wrench.ts b/src/tanks/Player.ts similarity index 81% rename from src/tanks/Wrench.ts rename to src/tanks/Player.ts index 76c0722..dc53ee0 100644 --- a/src/tanks/Wrench.ts +++ b/src/tanks/Player.ts @@ -2,10 +2,10 @@ import { Tank, TankPacket, Variant } from "growtopia.js"; import { BaseServer } from "../structures/BaseServer"; import { Peer } from "../structures/Peer"; import { World } from "../structures/World"; -import { DialogBuilder } from "../utils/builders/DialogBuilder"; import { ActionTypes } from "../utils/enums/Tiles"; +import { DialogBuilder } from "../utils/builders/DialogBuilder"; -export class Wrench { +export class Player { public base: BaseServer; public peer: Peer; public tank: TankPacket; @@ -18,7 +18,36 @@ export class Wrench { this.world = world; } - public onWrench() { + public onPlayerMove() { + const tankData = this.tank.data as Tank; + if ((tankData.xPunch as number) > 0 || (tankData.yPunch as number) > 0) return; + + const pos = Math.round((tankData.xPos as number) / 32) + Math.round((tankData.yPos as number) / 32) * (this.world.data.width as number); + + const block = this.world.data.blocks[pos]; + if (block === undefined) return; + const itemMeta = this.base.items.metadata.items[block.fg || block.bg]; + + switch (itemMeta.type) { + case ActionTypes.CHECKPOINT: { + this.peer.send(Variant.from({ netID: this.peer.data.netID, delay: 0 }, "SetRespawnPos", pos)); + this.peer.data.lastCheckpoint = { + x: Math.round((tankData.xPos as number) / 32), + y: Math.round((tankData.yPos as number) / 32) + }; + break; + } + + case ActionTypes.FOREGROUND: { + if (itemMeta.id === 3496 || itemMeta.id === 3270) { + // Steam testing + } + break; + } + } + } + + public onTileWrench() { const tankData = this.tank.data as Tank; const pos = (tankData.xPunch as number) + (tankData.yPunch as number) * (this.world.data.width as number); const block = this.world.data.blocks[pos]; diff --git a/src/types/peer.d.ts b/src/types/peer.d.ts index b00ab89..d8204df 100644 --- a/src/types/peer.d.ts +++ b/src/types/peer.d.ts @@ -22,6 +22,11 @@ export interface PeerDataType { clothing: Clothing; exp: number; level: number; + lastCheckpoint?: CheckPoint; +} +export interface CheckPoint { + x: number; + y: number; } export interface Clothing {