Skip to main content
Deno 2 is finally here 🎉️
Learn more
class InsuranceController
import { InsuranceController } from "https://deno.land/x/sptaki@1.2.0/controllers/mod.ts";

Constructors

new
InsuranceController(
logger: ILogger,
randomUtil: RandomUtil,
mathUtil: MathUtil,
jsonUtil: JsonUtil,
hashUtil: HashUtil,
eventOutputHolder: EventOutputHolder,
timeUtil: TimeUtil,
saveServer: SaveServer,
databaseServer: DatabaseServer,
itemHelper: ItemHelper,
profileHelper: ProfileHelper,
dialogueHelper: DialogueHelper,
weightedRandomHelper: WeightedRandomHelper,
traderHelper: TraderHelper,
paymentService: PaymentService,
insuranceService: InsuranceService,
mailSendService: MailSendService,
ragfairPriceService: RagfairPriceService,
configServer: ConfigServer,
)

Properties

protected
configServer: ConfigServer
protected
databaseServer: DatabaseServer
protected
dialogueHelper: DialogueHelper
protected
eventOutputHolder: EventOutputHolder
protected
hashUtil: HashUtil
protected
insuranceConfig: IInsuranceConfig
protected
insuranceService: InsuranceService
protected
itemHelper: ItemHelper
protected
jsonUtil: JsonUtil
protected
logger: ILogger
protected
mailSendService: MailSendService
protected
mathUtil: MathUtil
protected
paymentService: PaymentService
protected
profileHelper: ProfileHelper
protected
ragfairPriceService: RagfairPriceService
protected
randomUtil: RandomUtil
protected
roubleTpl: string
protected
saveServer: SaveServer
protected
timeUtil: TimeUtil
protected
traderHelper: TraderHelper
protected
weightedRandomHelper: WeightedRandomHelper

Methods

protected
countAllInsuranceItems(insurance: Insurance[]): number

Count all items in all insurance packages.

protected
filterInsuredItems(sessionID: string, time?: number): Insurance[]

Get all insured items that are ready to be processed in a specific profile.

protected
findItemsToDelete(rootItemParentID: string, insured: Insurance): Set<string>

Finds the items that should be deleted based on the given Insurance object.

protected
getAttachmentCountToRemove(weightedAttachmentByPrice: Record<string, number>, traderId: string): number

Get count of items to remove from weapon (take into account trader + price of attachment)

protected
logAttachmentsBeingRemoved(
attachmentIdsToRemove: string[],
attachments: Item[],
attachmentPrices: Record<string, number>,
): void
protected
populateParentAttachmentsMap(
rootItemParentID: string,
insured: Insurance,
itemsMap: Map<string, Item>,
): Map<string, Item[]>

Initialize a Map object that holds main-parents to all of their attachments. Note that "main-parent" in this context refers to the parent item that an attachment is attached to. For example, a suppressor attached to a gun, not the backpack that the gun is located in (the gun's parent).

protected
processAttachmentByParent(
attachments: Item[],
traderId: string,
toDelete: Set<string>,
): void

Takes an array of attachment items that belong to the same main-parent item, sorts them in descending order by their maximum price. For each attachment, a roll is made to determine if a deletion should be made. Once the number of deletions has been counted, the attachments are added to the toDelete Set, starting with the most valuable attachments first.

protected
processAttachments(
mainParentToAttachmentsMap: Map<string, Item[]>,
itemsMap: Map<string, Item>,
traderId: string,
toDelete: Set<string>,
): void

Process parent items and their attachments, updating the toDelete Set accordingly.

protected
processInsuredItems(insuranceDetails: Insurance[], sessionID: string): void

This method orchestrates the processing of insured items in a profile.

protected
processRegularItems(
insured: Insurance,
toDelete: Set<string>,
parentAttachmentsMap: Map<string, Item[]>,
): void

Process "regular" insurance items. Any insured item that is not an attached, attachment is considered a "regular" item. This method iterates over them, preforming item deletion rolls to see if they should be deleted. If so, they (and their attached, attachments, if any) are marked for deletion in the toDelete Set.

protected
removeInsurancePackageFromProfile(sessionID: string, insPackage: Insurance): void

Remove an insurance package from a profile using the package's system data information.

protected
removeItemsFromInsurance(insured: Insurance, toDelete: Set<string>): void

Remove items from the insured items that should not be returned to the player.

protected
removeNonModdableAttachments(parentAttachmentsMap: Map<string, Item[]>, itemsMap: Map<string, Item>): Map<string, Item[]>

Remove attachments that can not be moddable in-raid from the parentAttachmentsMap. If no moddable attachments remain, the parent is removed from the map as well.

protected
rollForDelete(traderId: string, insuredItem?: Item): boolean | null

Determines whether an insured item should be removed from the player's inventory based on a random roll and trader-specific return chance.

protected
sendMail(sessionID: string, insurance: Insurance): void

Handle sending the insurance message to the user that potentially contains the valid insurance items.

protected
weightAttachmentsByPrice(attachments: Item[]): Record<string, number>

Handle client/insurance/items/list/cost Calculate insurance cost

insure(
pmcData: IPmcData,
sessionID: string,
): IItemEventRouterResponse

Handle Insure event Add insurance to an item

Process insurance items of all profiles prior to being given back to the player through the mail service.

processReturnByProfile(sessionID: string): void

Process insurance items of a single profile prior to being given back to the player through the mail service.