enderalse/scripts/source/_00e_phasmalist_apparationinventory.psc

110 lines
4.4 KiB
Plaintext
Raw Normal View History

Scriptname _00E_Phasmalist_ApparationInventory extends ReferenceAlias
{total strength = (speed * base damage) or (base armor rating) or 0 + enchantement strength * magicEffectStrengthWeight +
magicEffectStrengthWeight * spellbook spellstrength}
; script that manages the spectralizing process. It is attached to the alias that contains the spectralizing container.
; this alias is filled and the functions of this script are called mainly from _00E_Phasmalist_Workbench.
Message Property spectralizingCost auto
Message Property cannotSpectralize auto
Message Property updateCostCannotPay auto
Message Property updateCostCanPay auto
float Property strengthPointsPerSoulGem = 20.0 autoreadonly
float Property strengthPointsPerBonemealOrEctoplasma = 8.0 autoreadonly
Formlist Property soulGemTypesOrderedByStrength auto
Formlist Property bonemealEctoplasmaTypesOrderedByStrength auto
function removeItemsUntilLimitReached(Actor that, Formlist itemList, int amount)
int index = 0
int maxSize = itemList.getSize()
int amountLeft = amount
While index < maxSize
If that.getItemCount(itemList.getat(index)) >= amountLeft
that.removeItem(itemList.getat(index), amountLeft)
return
Else
int amountThatHad = that.getItemCount(itemList.getAt(index))
that.removeItem(itemList.getat(index), amountThatHad)
amountLeft -= amountThatHad
EndIf
index = index + 1
EndWhile
Endfunction
bool function evaluateAndClose(ObjectReference apparationContainer)
{calculates the strength of all the items in the container and asks the player wether to spectralize them or not. Appropriatly, the spectralizing cost are removed from the player and the items are
returned to him or added to the apparation. The return value is true when any item was added to the apparation}
;returns if an item has been added to the apparation
If self.getRef().getNumItems() == 0
return false
EndIf
float strength = calculateTotalStrength()
int soulGemAmount = Math.floor(strength / strengthPointsPerSoulGem)
If soulGemAmount <= 0
soulGemAmount = 1
EndIf
int bonemealAmount = Math.ceiling(strength / strengthPointsPerBonemealOrEctoplasma)
Actor player = Game.getPlayer()
int soulGemAmountPlayerHas = player.getItemCount(soulGemTypesOrderedByStrength)
int bonemealAmountPlayerHas = player.getItemCount(bonemealEctoplasmaTypesOrderedByStrength)
bool didAddItems = false
If (soulGemAmountPlayerHas >= soulGemAmount && bonemealAmountPlayerHas >= bonemealAmount && self.getRef().getNumItems() > 0)
int button = spectralizingCost.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
If (button == 0)
didAddItems = true
self.getRef().removeallitems(apparationContainer, false, true)
removeItemsUntilLimitReached(player, soulGemTypesOrderedByStrength, soulGemAmount)
removeItemsUntilLimitReached(player, bonemealEctoplasmaTypesOrderedByStrength, bonemealAmount)
Else
addItemsToPlayer()
EndIf
Else
cannotSpectralize.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
addItemsToPlayer()
EndIf
return didAddItems
Endfunction
Function addItemsToPlayer()
self.getRef().removeallitems(akTransferTo = Game.getPlayer(), abRemoveQuestItems = true)
EndFunction
float Function calculateTotalStrength()
return self.getRef().calculateContentStrength()
EndFunction
Function UpdateCost()
float strength = calculateTotalStrength()
int soulGemAmount = Math.floor(strength / strengthPointsPerSoulGem)
If soulGemAmount <= 0
soulGemAmount = 1
EndIf
int bonemealAmount = Math.ceiling(strength / strengthPointsPerBonemealOrEctoplasma)
Actor player = Game.getPlayer()
int soulGemAmountPlayerHas = player.getItemCount(soulGemTypesOrderedByStrength)
int bonemealAmountPlayerHas = player.getItemCount(bonemealEctoplasmaTypesOrderedByStrength)
If (soulGemAmountPlayerHas >= soulGemAmount && bonemealAmountPlayerHas >= bonemealAmount)
updateCostCanPay.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
Else
updateCostCannotPay.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
EndIf
EndFunction
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
UpdateCost()
Endevent
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
If (self.getRef().getNumItems() == 0)
return
EndIf
UpdateCost()
Endevent