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

Commit

Permalink
feat: initial work on loot and loot tables
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Jan 4, 2024
1 parent 0592bb2 commit 4419232
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 14 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
- [ ] Doors
- [ ] Sliding doors
- [ ] Buttons
- [ ] Loot
- [x] Loot

### Buildings
- [x] Generation
Expand All @@ -62,7 +62,9 @@
- [ ] River generation

### Loot
- [ ] Loot game object and physics
- [x] Loot game object
- [x] Loot tables
- [ ] Physics
- [ ] Picking up loot
- [ ] Switching layers
- [ ] River flow
Expand Down
15 changes: 10 additions & 5 deletions src/defs/mapObjectsTyping.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ interface ObstacleDef {
health: number
reflectBullets?: boolean
explosion?: string
loot: Array<{
tier: any
min: any
max: any
props: any
loot: Array<({
tier: string
min: number
max: number
} | {
type: string
count: number
}) & {
// eslint-disable-next-line @typescript-eslint/ban-types
props: {} | number
}>
isBush?: boolean
isWindow?: boolean
Expand Down
222 changes: 220 additions & 2 deletions src/defs/modes/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { GameConfig } from "../../gameConfig";
import { v2 } from "../../utils/v2";
import { type ModeDefinition } from "./modes";

export const Main = {
export const Main: ModeDefinition = {
mapId: 0,
desc: { name: "Normal", icon: "", buttonCss: "" },
assets: {
Expand Down Expand Up @@ -59,7 +60,224 @@ export const Main = {
bleedDamage: 2,
bleedDamageMult: 1
},
lootTable: {},
// NOTE: this loot table is not the original one so its not accurate
lootTable: {
tier_world: [
{ name: "tier_scopes", count: 1, weight: 1 },
{ name: "tier_armor", count: 1, weight: 1 },
{ name: "tier_packs", count: 1, weight: 1 },
{ name: "tier_medical", count: 1, weight: 1 },
{ name: "tier_ammo", count: 1, weight: 0.9 },
{ name: "tier_guns", count: 1, weight: 2 }
],
tier_surviv: [
{ name: "tier_scopes", count: 1, weight: 1 },
{ name: "tier_armor", count: 1, weight: 1 },
{ name: "tier_medical", count: 1, weight: 1 },
{ name: "tier_packs", count: 1, weight: 1 }
],
tier_container: [
{ name: "tier_scopes", count: 1, weight: 0.15 },
{ name: "tier_armor", count: 1, weight: 0.1 },
{ name: "tier_packs", count: 1, weight: 0.09 },
{ name: "tier_medical", count: 1, weight: 0.17 },
{ name: "tier_ammo", count: 1, weight: 0.04 },
{ name: "tier_guns", count: 1, weight: 0.29 }
],
tier_leaf_pile: [
{ name: "tier_scopes", count: 1, weight: 0.2 },
{ name: "tier_armor", count: 1, weight: 0.2 },
{ name: "tier_packs", count: 1, weight: 0.2 },
{ name: "tier_medical", count: 1, weight: 0.2 },
{ name: "tier_ammo", count: 1, weight: 0.1 }
],
tier_soviet: [
{ name: "tier_scopes", count: 1, weight: 1 },
{ name: "tier_armor", count: 1, weight: 1 },
{ name: "tier_packs", count: 1, weight: 1 },
{ name: "tier_medical", count: 1, weight: 1.5 },
{ name: "tier_ammo", count: 1, weight: 1 },
{ name: "tier_guns", count: 1, weight: 4 }
],
tier_toilet: [
{ name: "tier_scopes", count: 1, weight: 0.1 },
{ name: "tier_guns", count: 1, weight: 0.2 },
{ name: "tier_medical", count: 1, weight: 0.6 }
],
tier_scopes: [
{ name: "2xscope", count: 1, weight: 0.75 },
{ name: "4xscope", count: 1, weight: 0.2 },
{ name: "8xscope", count: 1, weight: 0.049 },
{ name: "15xscope", count: 1, weight: 0.001 }
],
tier_armor: [
{ name: "helmet01", count: 1, weight: 9 },
{ name: "helmet02", count: 1, weight: 6 },
{ name: "helmet03", count: 1, weight: 0.2 },
{ name: "chest01", count: 1, weight: 15 },
{ name: "chest02", count: 1, weight: 6 },
{ name: "chest03", count: 1, weight: 0.2 }
],
tier_packs: [
{ name: "backpack01", count: 1, weight: 15 },
{ name: "backpack02", count: 1, weight: 6 },
{ name: "backpack03", count: 1, weight: 0.2 }
],
tier_medical: [
{ name: "bandage", count: 5, weight: 16 },
{ name: "healthkit", count: 1, weight: 4 },
{ name: "soda", count: 1, weight: 15 },
{ name: "painkiller", count: 1, weight: 5 }
],
tier_throwables: [
{ name: "frag", count: 1, weight: 1 },
{ name: "smoke", count: 1, weight: 1 },
{ name: "mirv", count: 1, weight: 0.05 }
],
tier_ammo: [
{ name: "9mm", count: 60, weight: 3 },
{ name: "762mm", count: 60, weight: 3 },
{ name: "556mm", count: 60, weight: 3 },
{ name: "12gauge", count: 10, weight: 3 }
],
tier_ammo_crate: [
{ name: "9mm", count: 60, weight: 3 },
{ name: "762mm", count: 60, weight: 3 },
{ name: "556mm", count: 60, weight: 3 },
{ name: "12gauge", count: 10, weight: 3 },
{ name: "50AE", count: 21, weight: 1 },
{ name: "308sub", count: 5, weight: 1 },
{ name: "flare", count: 1, weight: 1 }
],
tier_vending_soda: [
{ name: "soda", count: 1, weight: 5 },
{ name: "tier_ammo", count: 1, weight: 1 }
],
tier_sv98: [{ name: "sv98", count: 1, weight: 1 }],
tier_scopes_sniper: [
{ name: "4xscope", count: 1, weight: 0.2 },
{ name: "8xscope", count: 1, weight: 0.049 },
{ name: "15xscope", count: 1, weight: 0.001 }
],
tier_mansion_floor: [
{ name: "outfitCasanova", count: 1, weight: 1 }
],
tier_vault_floor: [
{ name: "outfitJester", count: 1, weight: 1 }
],
tier_police_floor: [
{ name: "outfitPrisoner", count: 1, weight: 1 }
],
tier_chrys_01: [
{ name: "outfitImperial", count: 1, weight: 1 }
],
tier_chrys_02: [{ name: "katana", count: 1, weight: 1 }],
tier_chrys_03: [
{ name: "outfitImperial", count: 1, weight: 1 }
],
tier_chrys_chest: [
{ name: "", count: 1, weight: 1 },
{ name: "katana", count: 1, weight: 1 },
{ name: "katana_rusted", count: 1, weight: 1 },
{ name: "katana_orchid", count: 1, weight: 1 }
],
tier_eye_block: [
{ name: "m9", count: 1, weight: 1 },
{ name: "ots38_dual", count: 1, weight: 1 },
{ name: "flare_gun", count: 1, weight: 1 },
{ name: "colt45", count: 1, weight: 1 },
{ name: "45acp", count: 1, weight: 1 },
{ name: "painkiller", count: 1, weight: 1 },
{ name: "m4a1", count: 1, weight: 0.4 },
{ name: "m249", count: 1, weight: 0.05 },
{ name: "awc", count: 1, weight: 0.05 },
{ name: "pkp", count: 1, weight: 0.05 }
],
tier_sledgehammer: [{ name: "sledgehammer", count: 1, weight: 1 }],
tier_chest_04: [
{ name: "p30l", count: 1, weight: 1 },
{ name: "p30l_dual", count: 1, weight: 0.001 }
],
tier_woodaxe: [{ name: "woodaxe", count: 1, weight: 1 }],
tier_club_melee: [{ name: "machete_taiga", count: 1, weight: 1 }],
tier_guns: [
{ name: "famas", count: 1, weight: 0.9 },
{ name: "hk416", count: 1, weight: 4 },
{ name: "mk12", count: 1, weight: 0.1 },
{ name: "pkp", count: 1, weight: 0.005 },
{ name: "m249", count: 1, weight: 0.006 },
{ name: "ak47", count: 1, weight: 2.7 },
{ name: "scar", count: 1, weight: 0.01 },
{ name: "dp28", count: 1, weight: 0.5 },
{ name: "mosin", count: 1, weight: 0.1 },
{ name: "m39", count: 1, weight: 0.1 },
{ name: "vss", count: 1, weight: 0.1 },
{ name: "mp5", count: 1, weight: 10 },
{ name: "mac10", count: 1, weight: 6 },
{ name: "ump9", count: 1, weight: 3 },
{ name: "m870", count: 1, weight: 9 },
{ name: "m1100", count: 1, weight: 6 },
{ name: "mp220", count: 1, weight: 2 },
{ name: "saiga", count: 1, weight: 0.1 },
{ name: "ot38", count: 1, weight: 8 },
{ name: "m9", count: 1, weight: 19 },
{ name: "m93r", count: 1, weight: 5 },
{ name: "glock", count: 1, weight: 7 },
{ name: "deagle", count: 1, weight: 0.05 },
{ name: "vector", count: 1, weight: 0.01 },
{ name: "sv98", count: 1, weight: 0.01 },
{ name: "spas12", count: 1, weight: 1 },
{ name: "qbb97", count: 1, weight: 0.01 },
{ name: "flare_gun", count: 1, weight: 0.1 },
{ name: "flare_gun_dual", count: 1, weight: 0.00017 },
{ name: "groza", count: 1, weight: 0.8 },
{ name: "scout", count: 1, weight: 0.05 }
],
tier_police: [
{ name: "scar", count: 1, weight: 2 },
{ name: "helmet03", count: 1, weight: 1 },
{ name: "chest03", count: 1, weight: 1 },
{ name: "backpack03", count: 1, weight: 1 }
],
tier_ring_case: [
{ name: "grozas", count: 1, weight: 1 },
{ name: "ots38_dual", count: 1, weight: 0.1 },
{ name: "m9", count: 1, weight: 0.01 },
{ name: "pkp", count: 1, weight: 0.01 }
],
tier_chest: [
{ name: "hk416", count: 1, weight: 2 },
{ name: "ak47", count: 1, weight: 2 },
{ name: "groza", count: 1, weight: 2 },
{ name: "famas", count: 1, weight: 1 },
{ name: "mk12", count: 1, weight: 1 },
{ name: "mp220", count: 1, weight: 1 },
{ name: "spas12", count: 1, weight: 1 },
{ name: "dp28", count: 1, weight: 1 },
{ name: "mosin", count: 1, weight: 1 },
{ name: "m39", count: 1, weight: 1 },
{ name: "scar", count: 1, weight: 0.5 },
{ name: "saiga", count: 1, weight: 0.5 },
{ name: "deagle", count: 1, weight: 0.5 },
{ name: "sv98", count: 1, weight: 0.5 },
{ name: "vector", count: 1, weight: 0.5 },
{ name: "m249", count: 1, weight: 0.1 },
{ name: "pkp", count: 1, weight: 0.1 },
{ name: "helmet01", count: 1, weight: 2 },
{ name: "helmet02", count: 1, weight: 1 },
{ name: "helmet03", count: 1, weight: 0.5 },
{ name: "4xscope", count: 1, weight: 1 },
{ name: "8xscope", count: 1, weight: 0.5 }
],
tier_hatchet: [
{ name: "vector", count: 1, weight: 5 },
{ name: "hk416", count: 1, weight: 2 },
{ name: "mp220", count: 1, weight: 1 },
{ name: "m249", count: 1, weight: 0.1 },
{ name: "pkp", count: 1, weight: 0.05 },
{ name: "m9", count: 1, weight: 0.01 }
]
},
mapGen: {
map: {
baseWidth: 512,
Expand Down
38 changes: 38 additions & 0 deletions src/defs/modes/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@ export const ModeDefinitions: Record<string, ModeDefinition> = {

export interface ModeDefinition {
mapId: number
desc: {
name: string
icon: string
buttonCss: string
}
assets: {
audio: Array<{
name: string
channel: string
}>
atlases: string[]
}
biome: {
colors: {
background: number
water: number
waterRipple: number
beach: number
riverbank: number
grass: number
underground: number
playerSubmerge: number
}
valueAdjust: number
sound: {
riverShore: string
}
particles: {
camera: string
}
tracerColors: Record<string, number>
airdrop: {
planeImg: string
planeSound: string
airdropImg: string
}
}

gameMode: {
maxPlayers: number
killLeaderEnabled: boolean
Expand Down
11 changes: 11 additions & 0 deletions src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MapMsg } from "./net/mapMsg";
import { MsgStream } from "./net/net";
import { Building } from "./objects/building";
import { Decal } from "./objects/decal";
import { Loot, getLootTable } from "./objects/loot";
import { Obstacle } from "./objects/obstacle";
import { Structure } from "./objects/structure";
import { coldet, type AABB } from "./utils/coldet";
Expand Down Expand Up @@ -227,6 +228,16 @@ export class GameMap {
this.game.grid.addObject(decal);
break;
}
case "loot_spawner": {
for (const tier of part.loot) {
const items = getLootTable(this.game.config.mode, tier.tier);

for (const item of items) {
const loot = new Loot(this.game, item.name, partPosition, layer, item.count);
this.game.grid.addObject(loot);
}
}
}
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/net/objectSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ export interface ObjectsFullData {
[ObjectType.Loot]: {
type: string
layer: number
isOld: number
isOld: boolean
isPreloadedGun: boolean
count: number
hasOwner: boolean
ownerId: number
}
[ObjectType.LootSpawner]: null
Expand Down Expand Up @@ -309,10 +308,10 @@ export const ObjectSerializeFns: { [K in ObjectType]: ObjectSerialization<K> } =
s.writeGameType(data.type);
s.writeUint8(data.count);
s.writeBits(data.layer, 2);
s.writeBits(data.isOld, 3);
s.writeBoolean(data.isOld);
s.writeBoolean(data.isPreloadedGun);
s.writeBoolean(data.hasOwner);
if (data.hasOwner) {
s.writeBoolean(data.ownerId !== 0);
if (data.ownerId !== 0) {
s.writeUint16(data.ownerId);
}
s.readBits(1);
Expand Down
Loading

0 comments on commit 4419232

Please sign in to comment.