Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
feat: a lot of halloween stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Oct 9, 2024
1 parent d6ccafb commit 6bfaf88
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 69 deletions.
2 changes: 1 addition & 1 deletion server/src/game/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ export class GameMap {
} else if (def.terrain?.beach) {
this.genOnBeach(type);
} else {
console.log(`Unknown map spawn rules for ${type}`);
this.genOnGrass(type);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/game/objects/bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class Bullet {
this.startPos = v2.copy(params.pos);
this.bulletType = params.bulletType;
this.reflectCount = params.reflectCount ?? 0;
this.reflectObjId = params.reflectObjId ?? -1;
this.reflectObjId = params.reflectObjId ?? 0;
this.lastShot = params.lastShot ?? false;
this.speed = bulletDef.speed * variance;
this.onHitFx = bulletDef.onHit ?? params.onHitFx;
Expand Down Expand Up @@ -359,7 +359,7 @@ export class Bullet {
obj.dead ||
!util.sameLayer(obj.layer, this.layer) ||
obj.height < GameConfig.bullet.height ||
(this.reflectCount > 0 && obj.__id === this.reflectObjId)
obj.__id === this.reflectObjId
) {
continue;
}
Expand Down
7 changes: 3 additions & 4 deletions server/src/game/objects/plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class PlaneBarn {
this.game.gas.posNew,
util.randomPointInCircle(this.game.gas.radNew),
),
scheduledPlane.options.airdropType,
);
break;
}
Expand All @@ -87,7 +88,7 @@ export class PlaneBarn {
});
}

addAirdrop(pos: Vec2) {
addAirdrop(pos: Vec2, type?: string) {
let id = 1;
if (this.idNext < MAX_ID) {
id = this.idNext++;
Expand All @@ -104,9 +105,7 @@ export class PlaneBarn {
return;
}

const type = util.weightedRandom(
this.game.map.mapDef.gameConfig.planes.crates,
).name;
type ||= util.weightedRandom(this.game.map.mapDef.gameConfig.planes.crates).name;

const def = MapObjectDefs[type] as ObstacleDef;

Expand Down
186 changes: 143 additions & 43 deletions server/src/game/objects/player.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GameObjectDefs, type LootDef } from "../../../../shared/defs/gameObjectDefs";
import type { EmoteDef } from "../../../../shared/defs/gameObjects/emoteDefs";
import { type EmoteDef, EmotesDefs } from "../../../../shared/defs/gameObjects/emoteDefs";
import {
type BackpackDef,
type BoostDef,
Expand All @@ -13,6 +13,7 @@ import {
import type { GunDef } from "../../../../shared/defs/gameObjects/gunDefs";
import { type MeleeDef, MeleeDefs } from "../../../../shared/defs/gameObjects/meleeDefs";
import type { OutfitDef } from "../../../../shared/defs/gameObjects/outfitDefs";
import { PerkProperties } from "../../../../shared/defs/gameObjects/perkDefs";
import type { RoleDef } from "../../../../shared/defs/gameObjects/roleDefs";
import type { ThrowableDef } from "../../../../shared/defs/gameObjects/throwableDefs";
import { UnlockDefs } from "../../../../shared/defs/gameObjects/unlockDefs";
Expand Down Expand Up @@ -613,6 +614,9 @@ export class Player extends BaseGameObject {
role = "";
isKillLeader = false;

// "Gabby Ghost" perk random emojis
chattyTicker = 0;

promoteToRole(role: string) {
if (!GameObjectDefs[role]) return;

Expand Down Expand Up @@ -770,43 +774,47 @@ export class Player extends BaseGameObject {
this.setDirty();
}

perks: Array<{ type: string; droppable: boolean }> = [];
perks: Array<{ type: string; droppable: boolean; replaceOnDeath?: string }> = [];

perkTypes: string[] = [];

addPerk(type: string, droppable = false) {
addPerk(type: string, droppable = false, replaceOnDeath?: string) {
this.perks.push({
type,
droppable,
replaceOnDeath,
});
this.perkTypes.push(type);

if (type == "leadership") {
this.boost = 100;
this.scale += 0.25;
} else if (type == "steelskin") {
this.scale += 0.4;
} else if (type == "flak_jacket") {
this.scale += 0.2;
} else if (type == "small_arms") {
this.scale -= 0.25;
if (type === "trick_m9") {
const ammo = this.weaponManager.getTrueAmmoStats(
GameObjectDefs["m9_cursed"] as GunDef,
);
this.weaponManager.setWeapon(
GameConfig.WeaponSlot.Secondary,
"m9_cursed",
ammo.trueMaxClip,
);
}

this.recalculateScale();
}

removePerk(type: string): void {
const idx = this.perks.findIndex((perk) => perk.type === type);
this.perks.splice(idx, 1);
this.perkTypes.splice(this.perkTypes.indexOf(type), 1);

if (type == "leadership") {
this.scale -= 0.25;
} else if (type == "steelskin") {
this.scale -= 0.4;
} else if (type == "flak_jacket") {
this.scale -= 0.2;
} else if (type == "small_arms") {
this.scale += 0.25;
if (type === "trick_m9") {
const slot = this.weapons.findIndex((weap) => {
return weap.type === "m9_cursed";
});
if (slot !== -1) {
this.weaponManager.setWeapon(slot, "", 0);
}
}

this.recalculateScale();
}

get hasPerks(): boolean {
Expand Down Expand Up @@ -1032,19 +1040,50 @@ export class Player extends BaseGameObject {
) {
this.cancelAction();
}
} else if (this.downed) {
this.bleedTicker += dt;
if (this.bleedTicker >= GameConfig.player.bleedTickRate) {
const bleedDamageMult = this.game.map.mapDef.gameConfig.bleedDamageMult;
const multiplier =
bleedDamageMult != 1 ? this.downedCount * bleedDamageMult : 1;
this.damage({
amount: this.game.map.mapDef.gameConfig.bleedDamage * multiplier,
damageType: GameConfig.DamageType.Bleeding,
dir: this.dir,
});
this.bleedTicker = 0;
}
}

// Take bleeding damage
this.bleedTicker -= dt;
if (
((this.downed && this.actionType == GameConfig.Action.None) ||
this.hasPerk("trick_drain")) &&
this.bleedTicker < 0
) {
const hasDrain = this.hasPerk("trick_drain");
this.bleedTicker = hasDrain
? GameConfig.player.bleedTickRate * 3
: GameConfig.player.bleedTickRate;

const mapConfig = this.game.map.mapDef.gameConfig;

const bleedDamageMult = mapConfig.bleedDamageMult;

const multiplier =
bleedDamageMult != 1 ? this.downedCount * bleedDamageMult : 1;

let damage = hasDrain ? 1 : mapConfig.bleedDamage * multiplier;
this.damage({
amount: damage,
damageType: GameConfig.DamageType.Bleeding,
dir: this.dir,
});
}

this.chattyTicker -= dt;

if (this.hasPerk("trick_chatty") && this.chattyTicker < 0) {
this.chattyTicker = util.random(5, 15);

const emotes = Object.keys(EmotesDefs);

this.game.playerBarn.emotes.push(
new Emote(
this.__id,
this.pos,
emotes[Math.floor(Math.random() * emotes.length)],
false,
),
);
}

if (this.game.gas.doDamage && this.game.gas.isInGas(this.pos)) {
Expand Down Expand Up @@ -1166,7 +1205,7 @@ export class Player extends BaseGameObject {
this.lastBreathActive = false;
this._lastBreathTicker = 0;

this.scale -= 0.2;
this.recalculateScale();
}
}

Expand Down Expand Up @@ -1855,10 +1894,16 @@ export class Player extends BaseGameObject {
const gameSourceDef = GameObjectDefs[params.gameSourceType ?? ""];

if (this.hasPerk("flak_jacket")) {
finalDamage *= params.isExplosion ? 0.1 : 0.9;
finalDamage -=
finalDamage *
(params.isExplosion
? PerkProperties.flak_jacket.explosionDamageReduction
: PerkProperties.flak_jacket.damageReduction);
}

if (this.hasPerk("steelskin")) finalDamage *= 0.5;
if (this.hasPerk("steelskin")) {
finalDamage -= finalDamage * PerkProperties.steelskin.damageReduction;
}

let isHeadShot = false;

Expand Down Expand Up @@ -2268,8 +2313,13 @@ export class Player extends BaseGameObject {

for (let i = this.perks.length - 1; i >= 0; i--) {
const perk = this.perks[i];
if (perk.droppable) {
this.game.lootBarn.addLoot(perk.type, this.pos, this.layer, 1);
if (perk.droppable || perk.replaceOnDeath) {
this.game.lootBarn.addLoot(
perk.replaceOnDeath || perk.type,
this.pos,
this.layer,
1,
);
}
}
this.perks.length = 0;
Expand Down Expand Up @@ -3137,20 +3187,49 @@ export class Player extends BaseGameObject {
this.setDirty();
break;
case "perk":
let type = obj.type;

const isMistery = type === "halloween_mystery";

if (isMistery) {
type = this.game.lootBarn.getLootTable(
"tier_halloween_mystery_perks",
)[0].name;
}

pickupMsg.item = type;

if (this.hasPerk(obj.type)) {
amountLeft = 1;
pickupMsg.type = net.PickupMsgType.AlreadyEquipped;
break;
}

const perkSlotType = this.perks.find((p) => p.droppable)?.type;
const emoteType = `emote_${type}`;
if (GameObjectDefs[`emote_${type}`]) {
this.game.playerBarn.emotes.push(
new Emote(this.__id, this.pos, emoteType, false),
);
}

const perkSlotType = this.perks.find(
(p) => p.droppable || p.replaceOnDeath === "halloween_mystery",
)?.type;
if (perkSlotType) {
amountLeft = 1;
lootToAdd = perkSlotType;
lootToAdd = isMistery ? "" : perkSlotType;
this.removePerk(perkSlotType);
this.addPerk(obj.type, true);
this.addPerk(
type,
!isMistery,
isMistery ? "halloween_mystery" : undefined,
);
} else {
this.addPerk(obj.type, true);
this.addPerk(
type,
!isMistery,
isMistery ? "halloween_mystery" : undefined,
);
}
this.setDirty();
break;
Expand Down Expand Up @@ -3466,8 +3545,8 @@ export class Player extends BaseGameObject {
player.lastBreathActive = true;
player._lastBreathTicker = 5;

player.scale += 0.2;
player.giveHaste(GameConfig.HasteType.Inspire, 5);
this.recalculateScale();
}
}

Expand Down Expand Up @@ -3507,6 +3586,27 @@ export class Player extends BaseGameObject {
this.setDirty();
}

recalculateScale() {
let scale = 1;
for (let i = 0; i < this.perks.length; i++) {
const perk = this.perks[i].type;
const perkProps = PerkProperties[perk as keyof typeof PerkProperties];
if (typeof perkProps === "object" && "scale" in perkProps) {
scale += perkProps.scale as number;
}
}

if (this.lastBreathActive) {
scale += PerkProperties.final_bugle.scaleOnDeath;
}

this.scale = math.clamp(
scale,
net.Constants.PlayerMinScale,
net.Constants.PlayerMaxScale,
);
}

recalculateSpeed(): void {
// this.speed = this.downed ? GameConfig.player.downedMoveSpeed : GameConfig.player.moveSpeed;

Expand Down
Loading

0 comments on commit 6bfaf88

Please sign in to comment.