Go to file
Refringe 7948e3473c Refactor of InsuranceController & New ItemHelper Methods (!151)
This commit is my second go-around at refactoring the `InsuranceController`, attempting to improving the code's modularity, maintainability, and efficiency while squashing a few bugs along the way.

1. **InsuranceController.ts**
    - Removed `ITemplateItem` import, as it is no longer used.
    - Introduced the `adoptOrphanedItems` method to manage orphaned items in the insurance list.
        - Since "normal" items are individually rolled for deletion, and can be nested within one another, there are situations where a parent item is deleted, leaving its children orphaned. This method moves those orphaned children from their missing parent into the root of the insurance container.
    - Overhauled `findItemsToDelete` method to improve its efficiency and readability:
        - Divided the original monolithic method into smaller, specialized methods like `populateItemsMap`, `populateParentAttachmentsMap`, `processRegularItems`, and `processAttachments`.
        - Changed the return type to `Set<string>` for better performance.
        - Introduced `EnrichedItem` interface (a simple extension of the `Item` interface) to add additional item data, like `name` and `maxPrice` to `Item` objects as they're processed throughout the class. This is done in place of repeatedly querying for this data, or complicating return types.
        - Enhanced logging capabilities to debug the item deletion process. Due to the *current* lack of testing available I've stepped up the amount of debug logging that is done. This will hopefully help us find issues in the future.
    - Modified the `rollForItemDelete` method, now renamed to `rollForDelete`, to include more detailed logging, return a boolean directly, and changed the `insuredItem` parameter to be optional.
    - Added new methods for dealing with some of the particulars that arise from item adoption and creating item maps.
    - Improved inline comments and documentation for better code maintainability.

2. **ItemHelper.ts**
    - Added the `isRaidModdable` method to check if an item is *actually* modifiable in-raid, which takes into account not just the item, but the item that it's attached to.
    - Added the `getAttachmentMainParent` method to fetch the main parent item of a given attachment, useful for item hierarchy traversal. For example, if you pass it an item ID of a suppressor, it will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately attached to, even if that gun is located within other multiple containers.
    - Added the `isAttachmentAttached` method to check if an item is an attachment that is currently attached to its parent.

**Fixes:**
 - Resolved an issue that caused item attachments from being property grouped together for deletion rolls. This issue prevented valuable attachments from being taken first.
 - Resolved an issue that caused child items being orphaned when their parent was removed due to an insurance roll. Probable cause of the bug that made the client spaz out and send repeated insurance packages to the profile---Though I'm still unable to reproduce.
 - Probably more...

Co-authored-by: Refringe <brownelltyler@gmail.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/151
Co-authored-by: Refringe <refringe@noreply.dev.sp-tarkov.com>
Co-committed-by: Refringe <refringe@noreply.dev.sp-tarkov.com>
2023-10-14 09:05:49 +00:00
project Refactor of InsuranceController & New ItemHelper Methods (!151) 2023-10-14 09:05:49 +00:00
.drone.yml Updated dependencies + A few other things (!150) 2023-10-14 09:01:41 +00:00
.gitattributes Add Repo 2023-03-03 15:23:46 +00:00
.gitignore 0.13.5.0 (!147) 2023-10-10 11:03:20 +00:00
LICENSE.md Updated dependencies + A few other things (!150) 2023-10-14 09:01:41 +00:00
README.md Update readme 2023-10-12 15:12:55 +01:00
set_gitcredential.sh Add Repo 2023-03-03 15:23:46 +00:00

Server

Modding framework for Escape From Tarkov

Build Status Quality Gate Status

Privacy

SPT is an open source project. Your commit credentials as author of a commit will be visible by anyone. Please make sure you understand this before submitting a PR. Feel free to use a "fake" username and email on your commits by using the following commands:

git config --local user.name "USERNAME"
git config --local user.email "USERNAME@SOMETHING.com"

Requirements

  • NodeJS (with npm)
  • Visual Studio Code
  • git LFS

Observations

  • The server was tested to work with NodeJS 18.15.0, if you are using a different version and experiencing difficulties change it before looking for support
  • If you are updating a branch you've had for some time, run npm ci before running any tasks. This will run the clean and install target from npm.
  • You can debug your mods using the server, just copy your mod files into the user/mods folder and put breakpoints on the JS files. DO NOT contact the dev team for support on this.

Pulling

  • Run git lfs fetch and git lfs pull to acquire loot files

Setup

  1. Visual Studio Code > File > Open Workspace... > project\Server.code-workspace
  2. Visual Studio Code > Terminal > Run Task... > npm > npm: Install

Build

This is for preparing for a release, not to run locally.

Mode Location
release Visual Studio Code > Terminal > Run Build Task... > build:release
debug Visual Studio Code > Terminal > Run Build Task... > build:debug

Test / Run locally

Visual Studio Code > Run > Start Debugging

Features

Progression

Player profile is stored in SPT folder as a JSON file, allowing for changes to persist

  • Scav:
    • Stats increase by doing scav raids
    • Skills increase by doing scav raids
    • Scav reputation system (Karma)
      • Scavs hostile below certain level
      • Scav run cooldown adjustment
      • Scav follow chance adjustment
      • Scav case
        • Completion time adjustment NOT IMPLEMENTED
        • Equipment chance adjustment NOT IMPLEMENTED
      • Bosses hostile below certain level
      • Exfil price adjustment NOT IMPLEMENTED
      • Improved gear with higher rep
      • Increase rep by exiting through car extracts
  • PMC:
    • Stats increase by doing PMC raids
    • Skills increase by doing PMC raids
    • Hydration/food
      • Increase out of raid
      • Post-raid levels are persisted to profile
    • Raid stat tracking
      • Raid count
      • Survived count
      • KIA count
      • MIA count
      • AWOL count
      • Kills count

Bots

  • Emulated bots:
    • assault (scav)
    • bossBully (Reshalla)
    • bossGluhar
    • bossKilla
    • bossKnight
    • bossKojainy (Shturman)
    • bossSanitar
    • bossTagilla
    • bossZryachiy
    • bossBoar (Kaban)
    • bossBoarSniper
    • curedAssault
    • exUsec (Rogue)
    • followerBigPipe
      • Grenade launcher
    • followerBirdEye
    • followerBoar
    • followerBully
    • followerGluharAssault
    • followerGluharScout
    • followerGluharSecurity
    • followerGluharSnipe
    • followerKojaniy
    • followerSanitar
    • followerzryachiy
    • gifter (santa)
      • Gives gifts NOT IMPLEMENTED
    • marksman
    • pmcBot (raider)
    • sectantPriest (Cultist)
    • sectantWarrior (Cultist)
  • Gear
    • Semi-randomised gear chosen with weighting system
    • Randomised durability of gear
  • Ammo
    • Ammo weighting system to mimic live
  • Loot
    • Semi-randomised loot
    • Item type spawn limit system
  • Per-map AI types

PMCs

  • Simulated PMC players
    • Custom weapons
      • Semi-randomly generated with weighting system
      • Semi-randomly chosen ammo with weighting system
    • Custom gear
      • Semi-randomly generated with weighting system
    • Custom headgear
      • Randomised attachments with percentage based chance to appear
        • Face shields
        • Flashlights
    • Randomised AI brains
      • Chooses random AI behaviour from pool of possible bot types (e.g. raider/rogue/killa)
    • Dogtags
      • Random level
      • Random name
    • Voices
      • Bear/usec voices for each faction
    • Loot item blacklist/whitelist
    • Highly configurable in config
    • Level-relative gear for PMCs from levels 1-15 and 15+
      • 1-15 bots have lower-tier items
      • 15+ bots have access to anything

Inventory

  • Move/split/delete stacks
  • Tags (add/modify/remove)
  • Armor/weapon kit item repair
  • Auto-sort
  • Out of raid healing
  • Out of raid eating
  • Special slots (compass etc)

Traders

  • Buy/Sell
  • Listed items are refreshed every hour
  • purchase limits per refresh period
  • Track sold rouble count
  • Loyalty levels
  • Build reputation
  • Item repair
    • Calculate randomised durability level based on item type/values
  • Alternate clothing from Ragman
    • Buy/unlock new clothing
  • Insurance
    • chance for items to be returned - higher chance for more expensive trader
    • Chance parts will be stripped from returned weapons
  • Fence
    • Lists random items for sale
    • Emulated system of 'churn' for items sold by fence
      • every 4 minutes 20% of fences' items are replaced
    • Configurable through config

Flea market

  • Buy and sell items
  • Prices pulled from live data
  • Listing tax fee
  • Offer filtering
  • Offer search
  • Filter by item
  • Linked search
  • Simulated player offers
    • Generated with random names/ratings/expiry times
    • Variable prices based on live price (20% above/below)
    • Weapon presets as offers
    • Bartering offers
    • Listed currency
      • Rouble
      • Euro
      • Dollar
  • Rating
    • Increase flea rating by selling items
    • Decrease flea rating by failing to sell items
    • Will be purchased by simulated players
    • Greater chance listed item will be purchased the lower it is listed for
  • Adjust flea prices that are massively below trader buy price
  • Receive purchased item through mail from seller
  • Sorting by
    • Rating
    • Price
    • Name
  • Configurable using config

Quests

  • Accurate quest list INCOMPLETE (85% complete)
  • Trader quests
    • Accept/Complete
  • Daily Quests
    • Simulated system of daily quests
    • Replace daily quest
      • Replace quest with new one
      • Charged fee
    • Scav daily quests
    • Types
      • Elimination
      • Exit location
      • Find
  • Trader item unlocks through completion of quests
  • Receive mail from traders after accepting/completing/failing a quest
  • Item rewards given through mail

Hideout

  • Areas supported
    • Air filter
      • Air filter degradation speed calculation
      • Skill levelling boost + 40%
    • Bitcoin farm
      • Coin generation speed calculation
    • Booze generator
      • Create moonshine
    • Generator
      • Fuel usage calculation
    • Heating
      • Energy regen rate
      • Negative effects removal rate x2
    • Illumination
    • Intel centre
      • Unlocks scav tasks from fence NOT IMPLEMENTED
      • Reduces insurance return time by 20% NOT IMPLEMENTED
      • Quest money reward boost
    • Lavatory
    • Library
    • Medstation
    • Nutrition unit
    • Rest space
    • Scav case
      • Custom reward system
      • Configurable in config
    • Security
    • Shooting range
    • Solar power
    • Stash
      • Gives bonus storage space
    • Vents
    • Water collector
    • Workbench
    • Christmas tree
  • Item crafting
    • Found in raid on completion
    • Crafts when server not running

Weapon building

  • Create weapon presets
  • Saving of presets

Raids

  • Supported maps
    • Customs
    • Factory day
    • Factory night
    • Reserve
    • Woods
    • Lighthouse
    • Laboratory
    • Shoreline
    • Streets
  • Loot
    • Generated from over 30,000 loot runs on live, spawn chances calculated from all runs to give fairly accurate depiction of live loot.
    • Static loot (containers)
      • Each container type can contain items appropriate to that type
    • Loose loot
      • Randomised loose items found on map
  • Airdrops
    • Randomised chance of spawning
    • Fire red flare to request an airdrop
    • Drops 1 of 3 randomised loot crate types NOT IMPLEMENTED
    • Drops lootable crate in:
      • Customs
      • Reserve
      • Woods
      • Lighthouse
      • Shoreline
      • Streets
    • Can be adjusted via config file
  • Raid damage
    • Exiting a raid with injury to player character will be persisted out of raid
  • Post-raid therapist healing

Messages

  • Receive from traders
  • Pin/unpin senders
  • Accept all attachments
  • Accept individual mail attachment

Modding

  • Extensive system that allows for the modification of nearly any aspect of SPT
  • Example mods covering a good slice of modding capabilities

Misc

  • Profiles
    • Standard/Left Behind/Prepare To Escape/Edge Of Darkness
    • Custom profiles
      • SPT Easy start
        • Lots of money / some QoL skills level 20 / level 69
      • SPT Zero to hero
        • No money, skills, trader rep or items, only a knife
      • SPT Developer
        • Testing profile, level 69, most skills maxed, max trader rep
        • USEC have all quests ready to start
        • BEAR have all quests ready to hand in
  • Note system
    • Add
    • Edit
    • Delete
  • Extensive config system
    • Alter how SPT works
  • Holiday themes in hideout on appropriate days
    • Halloween
    • Christmas

Code

  • TypeScript
    • Majority of EFT request/response classes passed from client to server have been mapped
  • Unit Tests
    • Supports tests via jest
  • Dependency injection
  • Config files accessible from Aki_Data\Server\configs / project\assets\configs