Skip to content

Commit

Permalink
refactor: pickup logic; fix: fix missing playerGhillie color on map defs
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Apr 8, 2024
1 parent 27b4326 commit 1c40736
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 273 deletions.
2 changes: 1 addition & 1 deletion server/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class GameMap {
const def = GameObjectDefs[loot];
if ("lootImg" in def) {
this.game.grid.addObject(new Loot(this.game, loot, lootPos, 0, 1, 0));
this.game.grid.addObject(new Loot(this.game, loot, v2.add(lootPos, { x: 1, y: 1 }), 0, 1, 0));
lootPos.x += 3.5;
if (lootPos.x > this.width / 2 + 80) {
Expand All @@ -80,7 +81,6 @@ export class GameMap {
} */

this.generateTerrain();

this.generateObjects();

this.mapStream.serializeMsg(MsgType.Map, this.msg);
Expand Down
5 changes: 3 additions & 2 deletions server/src/objects/loot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export class LootBarn {
}

/**
* spawns gun loot without ammo attached, use addLoot() if you want the respective ammo to drop alongside the gun
* spawns loot without ammo attached, use addLoot() if you want the respective ammo to drop alongside the gun
*/
addGun(type: string, pos: Vec2, layer: number, count: number) {
addLootWithoutAmmo(type: string, pos: Vec2, layer: number, count: number) {
const loot = new Loot(this.game, type, pos, layer, count);
this.game.grid.addObject(loot);
}
Expand All @@ -40,6 +40,7 @@ export class LootBarn {

if (def.type === "gun" && GameObjectDefs[def.ammo]) {
const ammoCount = useCountForAmmo ? count : def.ammoSpawnCount;
if (ammoCount <= 0) return;
const halfAmmo = Math.ceil(ammoCount / 2);

const leftAmmo = new Loot(this.game, def.ammo, v2.add(pos, v2.create(-0.2, -0.2)), layer, halfAmmo, 0);
Expand Down
408 changes: 165 additions & 243 deletions server/src/objects/player.ts

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions server/src/utils/weaponManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,55 @@ export class WeaponManager {
this.player.doAction(this.activeWeapon, GameConfig.Action.Reload, duration);
}

dropGun(weapIdx: number, switchToMelee = true): void {
const weaponDef = GameObjectDefs[this.weapons[weapIdx].type] as GunDef;
const weaponAmmoType = weaponDef.ammo;
const weaponAmmoCount = this.weapons[weapIdx].ammo;

let item = this.weapons[weapIdx].type;
this.weapons[weapIdx].type = "";
this.weapons[weapIdx].ammo = 0;
this.weapons[weapIdx].cooldown = 0;
if (this.curWeapIdx == weapIdx && switchToMelee) {
this.curWeapIdx = GameConfig.WeaponSlot.Melee;
}

const backpackLevel = this.player.getGearLevel(this.player.backpack);
const bagSpace = GameConfig.bagSizes[weaponAmmoType][backpackLevel];
let amountToDrop = 0;
if (this.player.inventory[weaponAmmoType] + weaponAmmoCount <= bagSpace) {
this.player.inventory[weaponAmmoType] += weaponAmmoCount;
this.player.dirty.inventory = true;
} else {
const spaceLeft = bagSpace - this.player.inventory[weaponAmmoType];
const amountToAdd = spaceLeft;

this.player.inventory[weaponAmmoType] += amountToAdd;
this.player.dirty.inventory = true;
amountToDrop = weaponAmmoCount - amountToAdd;
}

if (weaponDef.isDual) {
item = item.replace("_dual", "");
this.player.game.lootBarn.addLoot(item, this.player.pos, this.player.layer, 0, true);
}
this.player.game.lootBarn.addLoot(item, this.player.pos, this.player.layer, amountToDrop, true);
this.player.dirty.weapons = true;
if (weapIdx === this.curWeapIdx) this.player.setDirty();
}

dropMelee(): void {
const slot = GameConfig.WeaponSlot.Melee;
if (this.weapons[slot].type != "fists") {
this.player.game.lootBarn.addLoot(this.weapons[slot].type, this.player.pos, this.player.layer, 1);
this.weapons[slot].type = "fists";
this.weapons[slot].ammo = 0;
this.weapons[slot].cooldown = 0;
this.player.dirty.weapons = true;
if (slot === this.curWeapIdx) this.player.setDirty();
}
}

offHand = false;

fireWeapon(skipDelayCheck = false) {
Expand Down
1 change: 1 addition & 0 deletions shared/defs/mapDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface MapDef {
grass: number
underground: number
playerSubmerge: number
playerGhillie: number
}
valueAdjust: number
sound: {
Expand Down
3 changes: 2 additions & 1 deletion shared/defs/maps/baseDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const Main: MapDef = {
riverbank: 9461284,
grass: 8433481,
underground: 1772803,
playerSubmerge: 2854052
playerSubmerge: 2854052,
playerGhillie: 8630096
},
valueAdjust: 1,
sound: { riverShore: "sand" },
Expand Down
3 changes: 2 additions & 1 deletion shared/defs/maps/mainSpringDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const mapDef = {
riverbank: 9079434,
grass: 6066442,
underground: 1772803,
playerSubmerge: 2854052
playerSubmerge: 2854052,
playerGhillie: 4285194
},
sound: { riverShore: "stone" },
particles: { camera: "falling_leaf_spring" }
Expand Down
3 changes: 2 additions & 1 deletion shared/defs/maps/mainSummerDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const mapDef = {
riverbank: 10711321,
grass: 6460706,
underground: 1772803,
playerSubmerge: 2854052
playerSubmerge: 2854052,
playerGhillie: 6658085
}
},
mapGen: {
Expand Down
42 changes: 20 additions & 22 deletions shared/defs/objectsTypings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,60 +39,62 @@ interface ExplosionDef {
teamDamage?: boolean
}

interface AmmoDef {
interface BaseLootDef {
noDrop?: boolean
noDropOnDeath?: boolean
}

interface AmmoDef extends BaseLootDef {
type: "ammo"
name: string
minStackSize: number
special?: boolean
hideUi?: boolean
}

interface HealDef {
interface HealDef extends BaseLootDef {
type: "heal"
name: string
useTime: number
heal: number
maxHeal: number
}

interface BoostDef {
interface BoostDef extends BaseLootDef {
type: "boost"
name: string
useTime: number
boost: number
}

interface BackpackDef {
interface BackpackDef extends BaseLootDef {
type: "backpack"
name: string
level: number
noDrop?: boolean
}

interface HelmetDef {
interface HelmetDef extends BaseLootDef {
type: "helmet"
name: string
level: number
damageReduction: number
noDrop?: boolean
role?: string
}

interface ChestDef {
interface ChestDef extends BaseLootDef {
type: "chest"
name: string
level: number
damageReduction: number
noDrop?: boolean
}

interface ScopeDef {
interface ScopeDef extends BaseLootDef {
type: "scope"
name: string
level: number
}

interface GunDef {
interface GunDef extends BaseLootDef {
name: string
type: "gun"
quality: number
Expand Down Expand Up @@ -128,15 +130,14 @@ interface GunDef {
outsideOnly?: boolean
ignoreEndlessAmmo?: boolean
noPotatoSwap?: boolean
noDrop?: boolean
noDropOnDeath?: boolean
speed: {
equip: number
attack: number
}
}

interface MeleeDef {
interface MeleeDef extends BaseLootDef {
type: "melee"
name: string
quality: number
Expand All @@ -149,7 +150,6 @@ interface MeleeDef {
armorPiercing?: boolean
stonePiercing?: boolean
noDropOnDeath?: boolean
noDrop?: boolean
noPotatoSwap?: boolean
wallCheck?: boolean
attack: {
Expand Down Expand Up @@ -180,19 +180,18 @@ interface MeleeDef {
}
}

interface OutfitDef {
interface OutfitDef extends BaseLootDef {
type: "outfit"
name: string
noDropOnDeath?: boolean
obstacleType?: string
}

interface PerkDef {
interface PerkDef extends BaseLootDef {
type: "perk"
name: string
}

interface PingDef {
interface PingDef extends BaseLootDef {
type: "ping"
pingMap: boolean
pingLife: number
Expand All @@ -201,7 +200,7 @@ interface PingDef {
worldDisplay: number
}

interface RoleDef {
interface RoleDef extends BaseLootDef {
type: "role"
announce: boolean
killFeed: {
Expand All @@ -211,7 +210,7 @@ interface RoleDef {
perks: string[]
}

interface ThrowableDef {
interface ThrowableDef extends BaseLootDef {
type: "throwable"
name: string
quality: number
Expand All @@ -225,7 +224,6 @@ interface ThrowableDef {
rad: number
noPotatoSwap?: boolean
noDropOnDeath?: boolean
noDrop?: boolean
throwPhysics: {
playerVelMult: number
velZ: number
Expand All @@ -240,7 +238,7 @@ interface ThrowableDef {
}
}

interface XPDef {
interface XPDef extends BaseLootDef {
type: "xp"
name: string
xp: number
Expand Down
6 changes: 4 additions & 2 deletions shared/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ setSerializeFns(

s.writeBoolean(data.hasPerks);
if (data.hasPerks) {
s.writeBits(data.perks.length, 3);
for (const perk of data.perks) {
const perkAmount = math.min(data.perks.length, Constants.MaxPerks - 1);
s.writeBits(perkAmount, 3);
for (let i = 0; i < perkAmount; i++) {
const perk = data.perks[i];
s.writeGameType(perk.type);
s.writeBoolean(perk.droppable);
}
Expand Down

0 comments on commit 1c40736

Please sign in to comment.