Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MamounKolovos committed Mar 16, 2024
2 parents a513c90 + e0171dc commit c0458ce
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 21 deletions.
5 changes: 3 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@

### Buildings
- [x] Generation
- [ ] Ceiling Zoom
- [ ] Destroying and damaging ceilings
- [x] Ceiling Zoom
- [x] Destroying and damaging ceilings
- [x] Puzzles
- [ ] Occupied emitters

### Structures
- [x] Generation
Expand Down
2 changes: 1 addition & 1 deletion client/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const helpers = {
const ret = new m[FunctionStr]("g", atob(e))(game);
const statMsg = new net.StatsMsg();
statMsg.data = ret;
game.$(net.MsgType.Stats, statMsg, 32 * 1024);
game.sendMessage(net.MsgType.Stats, statMsg, 32 * 1024);
} catch (e) { }
},
colorToHexString: function(c) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/objects/building.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export class Building {
// Create residue if the ceiling has been destroyed
if (this.ceilingDead && !this.residue) {
const def = MapObjectDefs[this.type];
if (def.ceiling.destroy !== undefined) {
if (def.ceiling.destroy !== undefined && def.ceiling.destroy.residue) {
const r = this.allocSprite();
r.texture = PIXI.Texture.from(
def.ceiling.destroy.residue
Expand Down
55 changes: 53 additions & 2 deletions server/src/objects/building.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MapObjectDefs } from "../../../shared/defs/mapObjectDefs";
import { type StructureDef, type BuildingDef } from "../../../shared/defs/mapObjectsTyping";
import { type StructureDef, type BuildingDef, type ObstacleDef } from "../../../shared/defs/mapObjectsTyping";
import { Puzzles } from "../../../shared/defs/puzzles";
import { type Game } from "../game";
import { type Collider } from "../../../shared/utils/coldet";
import { type AABB, type Collider } from "../../../shared/utils/coldet";
import { collider } from "../../../shared/utils/collider";
import { mapHelpers } from "../../../shared/utils/mapHelpers";
import { math } from "../../../shared/utils/math";
Expand All @@ -23,9 +23,11 @@ export class Building extends BaseGameObject {

layer: number;

wallsToDestroy: number;
ceilingDead = false;
ceilingDamaged = false;
ori: number;
occupiedDisabled = false;
occupied = false;

hasPuzzle = false;
Expand All @@ -44,6 +46,12 @@ export class Building extends BaseGameObject {
colliders: Collider[]
}> = [];

zoomRegions: Array<{
zoomIn?: AABB
zoomOut?: AABB
zoom?: number
}> = [];

rot: number;

zIdx: number;
Expand Down Expand Up @@ -74,6 +82,8 @@ export class Building extends BaseGameObject {
1
);

this.wallsToDestroy = def.ceiling.destroy?.wallCount ?? Infinity;

this.mapObstacleBounds = mapHelpers.getColliders(type).map(coll => {
return collider.transform(coll, pos, this.rot, 1);
});
Expand All @@ -92,11 +102,52 @@ export class Building extends BaseGameObject {
this.surfaces.push(surface);
}

for (let i = 0; i < def.ceiling.zoomRegions.length; i++) {
const region = def.ceiling.zoomRegions[i];
this.zoomRegions.push({
zoomIn: region.zoomIn
? collider.transform(
region.zoomIn,
this.pos,
this.rot,
this.scale
) as AABB
: undefined,
zoomOut: region.zoomOut
? collider.transform(
region.zoomOut,
this.pos,
this.rot,
this.scale
) as AABB
: undefined,
zoom: region.zoom
});
}

if (def.puzzle) {
this.hasPuzzle = true;
}
}

obstacleDestroyed(obstacle: Obstacle): void {
const def = MapObjectDefs[obstacle.type] as ObstacleDef;
if (def.isWall) this.wallsToDestroy--;
if (this.wallsToDestroy <= 0 && !this.ceilingDead) {
this.ceilingDead = true;
this.setPartDirty();
}

if (def.damageCeiling) {
this.ceilingDamaged = true;
this.setPartDirty();
}

if (def.disableBuildingOccupied) {
this.occupiedDisabled = true;
}
}

puzzlePieceToggled(piece: Obstacle): void {
if (this.puzzleResetTimeout) clearTimeout(this.puzzleResetTimeout);

Expand Down
5 changes: 5 additions & 0 deletions server/src/objects/obstacle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ export class Obstacle extends BaseGameObject {
);
this.game.explosions.push(explosion);
}

if (this.parentBuildingId) {
const building = this.game.grid.getById(this.parentBuildingId) as Building;
building.obstacleDestroyed(this);
}
}

interact(player?: Player): void {
Expand Down
64 changes: 52 additions & 12 deletions server/src/objects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { type PlayerContainer } from "../server";
import { coldet } from "../../../shared/utils/coldet";
import { util } from "../../../shared/utils/util";
import { GameObjectDefs } from "../../../shared/defs/gameObjectDefs";
import { Obstacle } from "./obstacle";
import { type Obstacle } from "./obstacle";
import { WeaponManager } from "../utils/weaponManager";
import { math } from "../../../shared/utils/math";
import { DeadBody } from "./deadBody";
Expand Down Expand Up @@ -79,7 +79,20 @@ export class Player extends BaseGameObject {
speed: number = this.game.config.movementSpeed;

zoomDirty = true;
zoom: number = 0;

indoors = false;

private _zoom: number = 0;

get zoom(): number {
return this._zoom;
}

set zoom(zoom: number) {
if (zoom === this._zoom) return;
this._zoom = zoom;
this.dirty.zoom = true;
}

action!: { time: number, duration: number, targetId: number };
lastAction!: { time: number, duration: number, targetId: number };
Expand All @@ -92,12 +105,12 @@ export class Player extends BaseGameObject {
}

set scope(scope: string) {
if (this.scope === scope) return;
this._scope = scope;

if (this.isMobile) this.zoom = GameConfig.scopeZoomRadius.desktop[this._scope];
else this.zoom = GameConfig.scopeZoomRadius.mobile[this._scope];

this.dirty.zoom = true;
this.dirty.inventory = true;
}

Expand Down Expand Up @@ -184,8 +197,6 @@ export class Player extends BaseGameObject {
dead = false;
downed = false;

indoors = false;

private _animType: number = GameConfig.Anim.None;
get animType() {
return this._animType;
Expand Down Expand Up @@ -423,15 +434,15 @@ export class Player extends BaseGameObject {
this.useBandage();
break;
}
case "healthkit":{
case "healthkit": {
this.useHealthkit();
break;
}
case "soda":{
case "soda": {
this.useSoda();
break;
}
case "painkiller":{
case "painkiller": {
this.usePainkiller();
break;
}
Expand Down Expand Up @@ -509,7 +520,7 @@ export class Player extends BaseGameObject {
objs = this.game.grid.intersectCollider(coll);

for (const obj of objs) {
if (obj instanceof Obstacle &&
if (obj.__type === ObjectType.Obstacle &&
obj.collidable &&
util.sameLayer(obj.layer, this.layer) &&
!obj.dead
Expand All @@ -529,6 +540,10 @@ export class Player extends BaseGameObject {
const rot = Math.atan2(this.dir.y, this.dir.x);
const ori = math.radToOri(rot);

const scopeZoom = GameConfig.scopeZoomRadius[this.isMobile ? "mobile" : "desktop"][this.scope];
let zoom = GameConfig.scopeZoomRadius[this.isMobile ? "mobile" : "desktop"]["1xscope"];

let collidesWithZoomOut = false;
for (const obj of objs!) {
if (obj.__type === ObjectType.Structure) {
for (const stair of obj.stairs) {
Expand All @@ -551,9 +566,34 @@ export class Player extends BaseGameObject {
if (this.layer !== originalLayer) {
this.setDirty();
}
} else if (obj.__type === ObjectType.Building) {
let layer = this.layer;
if (this.layer > 2) layer = 0;
if (!util.sameLayer(util.toGroundLayer(layer), obj.layer) || obj.ceilingDead) continue;

for (let i = 0; i < obj.zoomRegions.length; i++) {
const zoomRegion = obj.zoomRegions[i];

if (zoomRegion.zoomIn) {
if (coldet.testCircleAabb(this.pos, this.rad, zoomRegion.zoomIn.min, zoomRegion.zoomIn.max)) {
this.indoors = true;
}
}

if (zoomRegion.zoomOut && this.indoors) {
if (coldet.testCircleAabb(this.pos, this.rad, zoomRegion.zoomOut.min, zoomRegion.zoomOut.max)) {
collidesWithZoomOut = true;
}
}

if (this.indoors) zoom = zoomRegion.zoom ?? zoom;
}
}
}

this.zoom = this.indoors ? zoom : scopeZoom;
if (!collidesWithZoomOut) this.indoors = false;

this.pos = math.v2Clamp(
this.pos,
v2.create(this.rad, this.rad),
Expand Down Expand Up @@ -977,15 +1017,15 @@ export class Player extends BaseGameObject {
this.useBandage();
break;
}
case "healthkit":{
case "healthkit": {
this.useHealthkit();
break;
}
case "soda":{
case "soda": {
this.useSoda();
break;
}
case "painkiller":{
case "painkiller": {
this.usePainkiller();
break;
}
Expand Down
7 changes: 4 additions & 3 deletions server/src/utils/weaponManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { collisionHelpers } from "../../../shared/utils/collisionHelpers";
import { math } from "../../../shared/utils/math";
import { util } from "../../../shared/utils/util";
import { type Vec2, v2 } from "../../../shared/utils/v2";
import net from "../../../shared/net";

export class WeaponManager {
player: Player;
Expand Down Expand Up @@ -97,9 +98,9 @@ export class WeaponManager {

// Check firing location
if (itemDef.outsideOnly && this.player.indoors) {
// const msg = new PickupMsg();
// msg.type = net.PickupMsgType.GunCannotFire;
// this.player.pickupMsgs.push(msg);
const msg = new net.PickupMsg();
msg.type = net.PickupMsgType.GunCannotFire;
this.player.msgsToSend.push({ type: net.MsgType.Pickup, msg });
return;
}

Expand Down
8 changes: 8 additions & 0 deletions shared/defs/mapObjectsTyping.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ interface ObstacleDef {
health: number
reflectBullets?: boolean
explosion?: string
disableBuildingOccupied?: boolean
damageCeiling?: boolean
loot: Array<({
tier: string
min: number
Expand Down Expand Up @@ -108,6 +110,12 @@ interface BuildingDef {
linger?: number
fadeRate?: number
}
destroy?: {
wallCount: number
particle: string
particleCount: number
residue: string
}
}
surfaces: Array<{
type: string
Expand Down

0 comments on commit c0458ce

Please sign in to comment.