@falloutmp/types 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,130 @@
1
- import type { Entity, EventHandler, KeyHandler, MessageHandler, MessageReply, Quaternion, Unsubscribe, Vector3, WebEventHandler } from "../shared.js";
1
+ import type { Entity, EventHandler, KeyHandler, MessageHandler, MessageReply, Unsubscribe, WebEventHandler } from "../shared.js";
2
2
 
3
3
  declare global {
4
4
  /**
5
5
  * Native events dispatched through `Events.on`. Each property is the exact callback argument tuple for that event.
6
6
  */
7
7
  interface EventMap {
8
+ /**
9
+ * Dispatched when a game menu opens, by its registered name, such as "PipboyMenu" or "ContainerMenu".
10
+ */
11
+ menuOpen: [name: string];
12
+
13
+ /**
14
+ * Dispatched when a game menu closes, by its registered name.
15
+ */
16
+ menuClose: [name: string];
17
+
18
+ /**
19
+ * Dispatched once when the local player goes down. The server decides when they come back.
20
+ */
21
+ localPlayerDeath: [];
22
+
23
+ /**
24
+ * Dispatched once when the local player is back up after a death.
25
+ */
26
+ localPlayerRespawn: [];
27
+
28
+ /**
29
+ * Dispatched when the local player moves into another worldspace or interior cell.
30
+ */
31
+ spaceChange: [space: PlayerSpace, previous: PlayerSpace];
32
+
33
+ /**
34
+ * Dispatched once when the local player gets into a power armor frame (`entered`) and once when they get out.
35
+ */
36
+ powerArmorChange: [entered: boolean];
37
+
38
+ /**
39
+ * Dispatched when the weapon in the local player's hands changes, its mods or ammo included; null for empty hands.
40
+ */
41
+ weaponChange: [weapon: PlayerWeapon | null];
42
+
43
+ /**
44
+ * Dispatched when what the local player wears changes; `outfit` is all of it.
45
+ */
46
+ outfitChange: [outfit: OutfitPiece[]];
47
+
48
+ /**
49
+ * Dispatched each time the local player fires: the TESObjectWEAP form ID and the ammo it took, 0 for none.
50
+ */
51
+ weaponFire: [weapon: number, ammo: number];
52
+
53
+ /**
54
+ * Dispatched when the local player starts a reload. `event` is the animation event their game played.
55
+ */
56
+ weaponReload: [event: string];
57
+
58
+ /**
59
+ * Dispatched when the local player's game awards XP, already scaled by the game.
60
+ */
61
+ xpGain: [amount: number];
62
+
63
+ /**
64
+ * Dispatched when the local player's level changes, from a level-up or the server's record.
65
+ */
66
+ levelChange: [level: number, previous: number];
67
+
68
+ /**
69
+ * Dispatched when the local player's game adds a perk rank (the chart, a magazine, a quest) or takes one away. `perk` is the rank's BGSPerk form ID.
70
+ */
71
+ perkChange: [perk: number, added: boolean];
72
+
73
+ /**
74
+ * Dispatched when the local player's game moves the base of a SPECIAL value: a bobblehead, the SPECIAL menu. `value` is the ActorValueInfo form ID.
75
+ */
76
+ valueChange: [value: number, base: number];
77
+
78
+ /**
79
+ * Dispatched in the frame after items moved into or out of the local player's inventory, with every count that moved.
80
+ */
81
+ inventoryChange: [changes: InventoryDelta[]];
82
+
83
+ /**
84
+ * Dispatched when the local player opens or closes a door the session shares, as the server is told. `ref` is the placed reference's form ID.
85
+ */
86
+ doorChange: [ref: number, open: boolean];
87
+
88
+ /**
89
+ * Dispatched when the local player picks, unlocks or locks a lock the session shares.
90
+ */
91
+ lockChange: [ref: number, locked: boolean];
92
+
93
+ /**
94
+ * Dispatched when the local player opens a container's menu and asks the server for it. The server may still refuse it, while another player holds it.
95
+ */
96
+ containerOpen: [ref: number];
97
+
98
+ /**
99
+ * Dispatched when the local player closes a container they had open, as its contents go to the server.
100
+ */
101
+ containerClose: [ref: number];
102
+
103
+ /**
104
+ * Dispatched when the local player drops items into the world: the base object and how many.
105
+ */
106
+ itemDrop: [form: number, count: number];
107
+
108
+ /**
109
+ * Dispatched when the server grants the local player a loose item they picked up: the base object and how many.
110
+ */
111
+ itemPickUp: [form: number, count: number];
112
+
113
+ /**
114
+ * Dispatched when the local player builds an object in workshop mode, as the server is asked for it: the base object, the workbench reference and where it stands.
115
+ */
116
+ workshopPlace: [form: number, workbench: number, position: { x: number; y: number; z: number }];
117
+
118
+ /**
119
+ * Dispatched when the local player puts a built object down somewhere else.
120
+ */
121
+ workshopMove: [form: number, position: { x: number; y: number; z: number }];
122
+
123
+ /**
124
+ * Dispatched when the local player scraps or stores a built object the session shares.
125
+ */
126
+ workshopRemove: [form: number];
127
+
8
128
  /**
9
129
  * Dispatched after a resource entry point has run and immediately before the resource becomes running.
10
130
  */
@@ -249,6 +369,512 @@ declare global {
249
369
  setRotation(pitch: number, yaw: number): boolean;
250
370
  };
251
371
 
372
+ /**
373
+ * Objects only the local player sees: the server and the other players never learn of them. Each stays in the cell or worldspace the local player was in when it was created, and shows again on coming back there. The resource that created one owns it: it is removed once that resource stops, and every one on disconnect.
374
+ */
375
+ const LocalObjects: {
376
+ /**
377
+ * Places an object in the local player's cell or worldspace; it appears over the next frames. The object's ID, or 0 when the form is unknown or not scenery, or 512 objects already exist.
378
+ * @param form The form ID of scenery: a static, movable static, static collection, tree or light. Nothing that can be taken, looted or activated. Editor IDs are not accepted: the game drops them for these types once loaded.
379
+ * @param placement World units, and radians about the X, Y and Z axes; yaw 0 faces +Y, clockwise.
380
+ * @param onLoad Called each time the object's 3D is loaded, the first time included. Not called once this resource stops.
381
+ */
382
+ create(form: number | string, placement: { x: number; y: number; z: number; pitch?: number; roll?: number; yaw?: number }, onLoad?: (id: number) => void): number;
383
+
384
+ /**
385
+ * Moves an object within its cell or worldspace. False when there is no such object.
386
+ * @param id From create.
387
+ * @param x World units.
388
+ * @param y World units.
389
+ * @param z World units.
390
+ */
391
+ setPosition(id: number, x: number, y: number, z: number): boolean;
392
+
393
+ /**
394
+ * Turns an object. False when there is no such object.
395
+ * @param id From create.
396
+ * @param pitch Radians about X.
397
+ * @param roll Radians about Y.
398
+ * @param yaw Radians about Z.
399
+ */
400
+ setRotation(id: number, pitch: number, roll: number, yaw: number): boolean;
401
+
402
+ /**
403
+ * Removes an object. False when there is no such object.
404
+ * @param id From create.
405
+ */
406
+ remove(id: number): boolean;
407
+
408
+ /**
409
+ * Where an object stands and how it is turned, as it was last placed or moved: world units and radians. Null when there is no such object.
410
+ * @param id From create.
411
+ */
412
+ getPose(id: number): { x: number; y: number; z: number; pitch: number; roll: number; yaw: number } | null;
413
+
414
+ /**
415
+ * Whether the object still exists: not removed, not refused by the game, and its resource still running.
416
+ * @param id From create.
417
+ */
418
+ exists(id: number): boolean;
419
+ };
420
+
421
+ /**
422
+ * The camera the world renders through, as of the last frame, whichever state holds it: first or third person, the fly camera, a scripted one.
423
+ */
424
+ const Camera: {
425
+ /**
426
+ * Where the camera is, in world units; null before the world is built.
427
+ */
428
+ getPosition(): { x: number; y: number; z: number } | null;
429
+
430
+ /**
431
+ * Where the camera looks: pitch in radians, positive down; yaw in radians in [0, 2pi), 0 facing +Y, clockwise. Null before the world is built.
432
+ */
433
+ getRotation(): { pitch: number; yaw: number } | null;
434
+
435
+ /**
436
+ * The field of view the world renders with, in degrees, across and up the screen. Null before the world is built.
437
+ */
438
+ getFov(): { horizontal: number; vertical: number } | null;
439
+
440
+ /**
441
+ * The game's back buffer, in pixels: the space worldToScreen answers in.
442
+ */
443
+ getScreenSize(): { width: number; height: number };
444
+
445
+ /**
446
+ * Projects a world point through last frame's camera into back-buffer pixels, origin top left (see getScreenSize; scale by the web view's size over it). onScreen is false for a point in front of the camera but outside the view. Null for a point behind the camera, or before the world is built.
447
+ * @param x World units.
448
+ * @param y World units.
449
+ * @param z World units.
450
+ */
451
+ worldToScreen(x: number, y: number, z: number): { x: number; y: number; onScreen: boolean } | null;
452
+ };
453
+
454
+ /**
455
+ * Markers on the local player's HUD compass and Pip-Boy map, drawn by the game's own widgets. Only this client sees them; they go when the resource that made them stops.
456
+ */
457
+ const Markers: {
458
+ /**
459
+ * Adds a marker and returns its ID, or 0 while the local player is in no cell. The compass shows it once placed, a frame or so later; the map from its next refresh, which every Pip-Boy value change brings.
460
+ * @param options Where, in world units of the worldspace or interior the local player is in now; the marker shows only while the player is there. label: the map's tooltip. compass and map: where it shows, both by default. kind: the icon, "quest" by default; "custom" is the player's own map marker, "powerArmor" the power armor one.
461
+ */
462
+ create(options: { x: number; y: number; z: number; label?: string; compass?: boolean; map?: boolean; kind?: "quest" | "custom" | "powerArmor" }): number;
463
+
464
+ /**
465
+ * Moves a marker. False for an unknown ID.
466
+ * @param id The marker's ID.
467
+ * @param x World units.
468
+ * @param y World units.
469
+ * @param z World units.
470
+ */
471
+ setPosition(id: number, x: number, y: number, z: number): boolean;
472
+
473
+ /**
474
+ * Removes a marker. False for an unknown ID.
475
+ * @param id The marker's ID.
476
+ */
477
+ remove(id: number): boolean;
478
+
479
+ /**
480
+ * Removes every marker this resource made.
481
+ */
482
+ clear(): void;
483
+ };
484
+
485
+ /**
486
+ * Game sounds only the local player hears, played through the game's audio as Sound.Play does. A resource's sounds stop when it stops.
487
+ */
488
+ const Sound: {
489
+ /**
490
+ * Plays a sound for this client alone. The instance ID, or 0 when nothing played: no such sound, 64 already playing, or the game refused it.
491
+ * @param sound A sound descriptor (SNDR), or a sound marker (SOUN) for its descriptor: its editor ID, or its form ID (a number, or a string starting 0x).
492
+ * @param options x, y, z: play at this world point, all three or none; without them the sound is unpositioned, heard the same wherever the camera is. volume: 0 to 1, 1 by default.
493
+ */
494
+ play(sound: string | number, options?: { x?: number; y?: number; z?: number; volume?: number }): number;
495
+
496
+ /**
497
+ * Stops a sound play started. False when it already ended or was never played here.
498
+ * @param id What play returned.
499
+ */
500
+ stop(id: number): boolean;
501
+
502
+ /**
503
+ * Whether a sound play started has yet to end; true while it is still starting.
504
+ * @param id What play returned.
505
+ */
506
+ isPlaying(id: number): boolean;
507
+ };
508
+
509
+ /**
510
+ * Screen and controller effects only the local player sees and feels. Fades are on Hud.fade.
511
+ */
512
+ const Effects: {
513
+ /**
514
+ * Applies an image space modifier, as ImageSpaceModifier.Apply does; it runs its own length, and is removed once this resource stops. False when there is no such modifier or no world to run it in.
515
+ * @param modifier An image space modifier (IMAD): its editor ID, or its form ID (a number, or a string starting 0x).
516
+ * @param strength 0 to 1, 1 by default.
517
+ */
518
+ applyImageSpace(modifier: string | number, strength?: number): boolean;
519
+
520
+ /**
521
+ * Stops as many instances of a modifier as this resource applied and are still running. The game stops the oldest instances of the record, which may be ones it started itself. False when none of this resource's are running.
522
+ * @param modifier The modifier's editor ID, or its form ID (a number, or a string starting 0x).
523
+ */
524
+ removeImageSpace(modifier: string | number): boolean;
525
+
526
+ /**
527
+ * Shakes the camera, as Game.ShakeCamera does from the player. False while there is no player in the world.
528
+ * @param strength 0 to 1.
529
+ * @param seconds How long; 0 for the game's default.
530
+ */
531
+ shakeCamera(strength: number, seconds: number): boolean;
532
+
533
+ /**
534
+ * Rumbles the gamepad, as Game.ShakeController does.
535
+ * @param left Left motor, 0 to 1.
536
+ * @param right Right motor, 0 to 1.
537
+ * @param seconds How long.
538
+ */
539
+ shakeController(left: number, right: number, seconds: number): void;
540
+ };
541
+
542
+ /**
543
+ * Where the player is: the worldspace it stands in, or the interior cell, which has none.
544
+ */
545
+ interface PlayerSpace {
546
+ /**
547
+ * The TESWorldSpace form ID; 0 inside an interior.
548
+ */
549
+ worldSpace: number;
550
+
551
+ /**
552
+ * The interior TESObjectCELL form ID; 0 outside.
553
+ */
554
+ interiorCell: number;
555
+ }
556
+
557
+ /**
558
+ * The weapon in the player's hands, drawn or holstered.
559
+ */
560
+ interface PlayerWeapon {
561
+ /**
562
+ * The TESObjectWEAP form ID.
563
+ */
564
+ form: number;
565
+
566
+ /**
567
+ * The ammo form ID it loads; 0 for none.
568
+ */
569
+ ammo: number;
570
+
571
+ /**
572
+ * The OMOD form IDs attached to it.
573
+ */
574
+ mods: number[];
575
+ }
576
+
577
+ /**
578
+ * One armor piece the player wears, with the mods attached to it.
579
+ */
580
+ interface OutfitPiece {
581
+ /**
582
+ * The TESObjectARMO form ID.
583
+ */
584
+ form: number;
585
+
586
+ /**
587
+ * The OMOD form IDs attached to it.
588
+ */
589
+ mods: number[];
590
+ }
591
+
592
+ /**
593
+ * The power armor frame the player wears.
594
+ */
595
+ interface PlayerPowerArmor {
596
+ /**
597
+ * The frame's reference form ID when the data files placed it; null for one the game created at runtime.
598
+ */
599
+ frame: number | null;
600
+
601
+ /**
602
+ * The frame's TESFurniture form ID; null when the game created that record at runtime.
603
+ */
604
+ base: number | null;
605
+
606
+ /**
607
+ * The charge left in the inserted fusion core, in whole units rounded up; 0 when it is empty or there is none.
608
+ */
609
+ battery: number;
610
+
611
+ /**
612
+ * The inserted fusion core's capacity, 100 for the game's own; 0 while none was ever inserted.
613
+ */
614
+ batteryMax: number;
615
+ }
616
+
617
+ /**
618
+ * What the player's body is doing.
619
+ */
620
+ interface PlayerMovement {
621
+ /**
622
+ * In the sneak stance.
623
+ */
624
+ sneaking: boolean;
625
+
626
+ /**
627
+ * Off the ground from a jump or a fall.
628
+ */
629
+ airborne: boolean;
630
+
631
+ /**
632
+ * Sprinting.
633
+ */
634
+ sprinting: boolean;
635
+
636
+ /**
637
+ * The weapon is out.
638
+ */
639
+ weaponDrawn: boolean;
640
+
641
+ /**
642
+ * Aiming down the sights of a drawn gun.
643
+ */
644
+ aiming: boolean;
645
+
646
+ /**
647
+ * A drawn gun lowered against a wall.
648
+ */
649
+ gunDown: boolean;
650
+
651
+ /**
652
+ * The Pip-Boy is up.
653
+ */
654
+ pipBoyOpen: boolean;
655
+ }
656
+
657
+ /**
658
+ * The player's health and armor.
659
+ */
660
+ interface PlayerVitals {
661
+ /**
662
+ * Current health.
663
+ */
664
+ health: number;
665
+
666
+ /**
667
+ * Health at full.
668
+ */
669
+ maxHealth: number;
670
+
671
+ /**
672
+ * Damage resistance from the armor worn.
673
+ */
674
+ armor: number;
675
+ }
676
+
677
+ /**
678
+ * The player this client controls, as it was captured this frame. Read-only: the server's `Player` changes it. Other players are not reachable on the client, which holds one only while it streams in.
679
+ */
680
+ const LocalPlayer: {
681
+ /**
682
+ * Where the player stands, in world units of their space.
683
+ * @returns Null outside a session or before the player stands in the world.
684
+ */
685
+ getPosition(): { x: number; y: number; z: number } | null;
686
+
687
+ /**
688
+ * How fast the player moves, in world units per second.
689
+ * @returns Null outside a session or before the player stands in the world.
690
+ */
691
+ getVelocity(): { x: number; y: number; z: number } | null;
692
+
693
+ /**
694
+ * Facing, in radians around Z.
695
+ * @returns Null outside a session or before the player stands in the world.
696
+ */
697
+ getHeading(): number | null;
698
+
699
+ /**
700
+ * Aim pitch, in radians.
701
+ * @returns Null outside a session or before the player stands in the world.
702
+ */
703
+ getAimPitch(): number | null;
704
+
705
+ /**
706
+ * What the player's body is doing: stance, weapon, Pip-Boy.
707
+ * @returns Null outside a session or before the player stands in the world.
708
+ */
709
+ getMovement(): PlayerMovement | null;
710
+
711
+ /**
712
+ * Health and armor, as captured at most a tenth of a second ago.
713
+ * @returns Null outside a session or before the player stands in the world.
714
+ */
715
+ getVitals(): PlayerVitals | null;
716
+
717
+ /**
718
+ * Whether the player is down.
719
+ * @returns False outside a session.
720
+ */
721
+ isDead(): boolean;
722
+
723
+ /**
724
+ * The worldspace or interior cell the player is in.
725
+ * @returns Null outside a session or before the player stands in the world.
726
+ */
727
+ getSpace(): PlayerSpace | null;
728
+
729
+ /**
730
+ * The weapon in the player's hands.
731
+ * @returns Null for empty hands, and outside a session.
732
+ */
733
+ getWeapon(): PlayerWeapon | null;
734
+
735
+ /**
736
+ * What the player wears.
737
+ * @returns One entry per armor piece; empty outside a session.
738
+ */
739
+ getOutfit(): OutfitPiece[];
740
+
741
+ /**
742
+ * The power armor frame the player wears.
743
+ * @returns Null when they wear none, and outside a session.
744
+ */
745
+ getPowerArmor(): PlayerPowerArmor | null;
746
+
747
+ /**
748
+ * The player's level.
749
+ * @returns 0 before the player stands in the world.
750
+ */
751
+ getLevel(): number;
752
+
753
+ /**
754
+ * The player's XP.
755
+ * @returns 0 before the player stands in the world.
756
+ */
757
+ getXp(): number;
758
+
759
+ /**
760
+ * Perk points the player has to spend.
761
+ * @returns 0 before the player stands in the world.
762
+ */
763
+ getPerkPoints(): number;
764
+
765
+ /**
766
+ * Whether the player holds a perk rank.
767
+ * @param perk The rank's BGSPerk form ID.
768
+ */
769
+ hasPerk(perk: number | string): boolean;
770
+
771
+ /**
772
+ * An actor value's current value on the player.
773
+ * @param value The ActorValueInfo form ID, such as 0x2D4 for Health.
774
+ * @returns Null for a form ID that is no actor value, or before the player stands in the world.
775
+ */
776
+ getValue(value: number | string): number | null;
777
+
778
+ /**
779
+ * An actor value's base on the player.
780
+ * @param value The ActorValueInfo form ID, such as 0x2D4 for Health.
781
+ * @returns Null for a form ID that is no actor value, or before the player stands in the world.
782
+ */
783
+ getBaseValue(value: number | string): number | null;
784
+
785
+ /**
786
+ * What the player carries, counted from their game.
787
+ * @returns One entry per base object and condition; empty before the player stands in the world.
788
+ */
789
+ getInventory(): InventoryItem[];
790
+
791
+ /**
792
+ * How many of an item the player carries.
793
+ * @param form The base object.
794
+ * @returns The count; 0 when they carry none.
795
+ */
796
+ getItemCount(form: number | string): number;
797
+ };
798
+
799
+ /**
800
+ * A stack the local player carries.
801
+ */
802
+ interface InventoryItem {
803
+ /**
804
+ * The base object's form ID.
805
+ */
806
+ form: number;
807
+
808
+ /**
809
+ * How many.
810
+ */
811
+ count: number;
812
+
813
+ /**
814
+ * The stack's condition in percent of full, 0 to 100: the charge a fusion core has left. 100 for an item that has none.
815
+ */
816
+ condition: number;
817
+ }
818
+
819
+ /**
820
+ * How many of an item came or went.
821
+ */
822
+ interface InventoryDelta {
823
+ /**
824
+ * The base object's form ID.
825
+ */
826
+ form: number;
827
+
828
+ /**
829
+ * Positive for items that came, negative for items that went.
830
+ */
831
+ delta: number;
832
+
833
+ /**
834
+ * The stack's condition in percent of full, 0 to 100; 100 for an item that has none.
835
+ */
836
+ condition: number;
837
+
838
+ /**
839
+ * The reference on the other side of the move (a container, a corpse, a world item); null when nothing named one.
840
+ */
841
+ counterpart: number | null;
842
+ }
843
+
844
+ /**
845
+ * The server's clock and sky, as this client holds them. Read-only: the server's `World` sets them.
846
+ */
847
+ const World: {
848
+ /**
849
+ * The game hour the server keeps, 0 to 24.
850
+ * @returns Null before the server's world streams in.
851
+ */
852
+ getHour(): number | null;
853
+
854
+ /**
855
+ * Game minutes per real minute; 0 holds the clock.
856
+ * @returns Null before the server's world streams in.
857
+ */
858
+ getTimeScale(): number | null;
859
+
860
+ /**
861
+ * The TESWeather form ID the server holds the sky to.
862
+ * @returns Null while the region decides the weather, and before the server's world streams in.
863
+ */
864
+ getWeather(): number | null;
865
+ };
866
+
867
+ /**
868
+ * The server's radio stations, as this client's Pip-Boy radio lists them. Read-only: the server's `RadioStation` creates them.
869
+ */
870
+ const Radio: {
871
+ /**
872
+ * Every station the server streams to this client.
873
+ * @returns One entry per station, in no particular order; empty outside a session.
874
+ */
875
+ getStations(): { name: string; frequency: number }[];
876
+ };
877
+
252
878
  /**
253
879
  * Mutable two-dimensional vector.
254
880
  */