Skip to content

Commit

Permalink
feat: add checkpoint & remove Wrench (replace with Player.ts)
Browse files Browse the repository at this point in the history
  • Loading branch information
JadlionHD committed Feb 13, 2024
1 parent 3944ca7 commit 65e4d8a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/events/Raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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: {
Expand All @@ -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 {
Expand Down
22 changes: 20 additions & 2 deletions src/structures/Peer.ts
Original file line number Diff line number Diff line change
@@ -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<PeerDataType> {
public base;
Expand Down Expand Up @@ -107,7 +109,23 @@ export class Peer extends OldPeer<PeerDataType> {

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),
Expand Down
2 changes: 2 additions & 0 deletions src/structures/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
14 changes: 14 additions & 0 deletions src/tanks/Place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
35 changes: 32 additions & 3 deletions src/tanks/Wrench.ts → src/tanks/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions src/types/peer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 65e4d8a

Please sign in to comment.