@@ -765,7 +765,7 @@ function Pointshop2Controller:sendPoints( ply, targetPly, points )
765
765
-- TODO: Send the targetPlayer a nice notification, similar to iten added
766
766
end
767
767
768
- local function calculateRefundAmounts ( itemsToRefund )
768
+ local function calculateRefundAmounts ( itemsToRefund , currentPrice )
769
769
local refundsByPlayer = LibK ._ ( itemsToRefund ):chain ()
770
770
:groupBy ( function ( item )
771
771
return item .ownerId
@@ -783,24 +783,28 @@ local function calculateRefundAmounts( itemsToRefund )
783
783
return refundsByPlayer
784
784
end
785
785
786
- local function removeSingleItem ( itemClass , refund )
786
+ local function removeSingleItem ( itemClass , refund , refundCurrentPrice )
787
787
return Pointshop2 .DB .DoQuery ( Format ( [[
788
788
SELECT item.id, item.data, COALESCE(inventories.ownerId, ps2_equipmentslot.ownerId) AS ownerId, ps2_equipmentslot.slotName
789
789
FROM kinv_items AS item
790
790
LEFT JOIN inventories ON inventories.id = item.inventory_id
791
791
LEFT JOIN ps2_equipmentslot ON ps2_equipmentslot.itemId = item.id
792
792
WHERE item.itemClass = %s
793
- ]] , Pointshop2 .DB .SQLStr ( itemClass ) ) )
793
+ ]] , Pointshop2 .DB .SQLStr ( itemClass . name ) ) )
794
794
:Then ( function ( results )
795
795
results = results or {}
796
796
-- Deserialize purchaseData (this is usually done in LibK but we're querying manually)
797
797
results = LibK ._ .map ( results , function ( row )
798
- row .purchaseData = util .JSONToTable ( row .data ).purchaseData
798
+ return row .purchaseData = util .JSONToTable ( row .data ).purchaseData
799
799
end )
800
800
801
801
local refundPromise = Promise .Resolve ()
802
802
if refund then
803
- local refundsByPlayer = calculateRefundAmounts ( refund )
803
+ local currentPrice = false
804
+ if refundCurrentPrice then
805
+ currentPrice = table .Inherit (itemClass .static .Price , { points = 0 , premiumPoints = 0 })
806
+ end
807
+ local refundsByPlayer = calculateRefundAmounts ( refund , currentPrice )
804
808
-- Remove players that get refunded 0 points
805
809
local toRefund = LibK ._ ( refundsByPlayer ):chain ()
806
810
:entries ( )
@@ -812,7 +816,7 @@ local function removeSingleItem( itemClass, refund )
812
816
813
817
-- Create a query for each player
814
818
refundPromise = Promise .Map ( toRefund , function ( entry )
815
- local ownerId , amountsToRefund = entry [0 ], entry [1 ]
819
+ local ownerId , amountsToRefund = entry [1 ], entry [2 ]
816
820
return Pointshop2 .DB .DoQuery ( Format (
817
821
" UPDATE ps2_wallet SET points = points + %i, premiumPoints = premiumPoints + %i WHERE ownerId = %i" ,
818
822
amountsToRefund .points ,
@@ -836,13 +840,13 @@ local function removeSingleItem( itemClass, refund )
836
840
end )
837
841
end
838
842
839
- function Pointshop2Controller :removeItem ( ply , itemClassName , refund )
843
+ function Pointshop2Controller :removeItem ( ply , itemClassName , refund , refundCurrentPrice )
840
844
local itemClass = Pointshop2 .GetItemClassByName ( itemClassName )
841
845
if not itemClass then
842
846
return Promise .Reject ( " An item " .. itemClassName .. " doesn't exist!" )
843
847
end
844
848
845
- return removeSingleItem ( itemClass , refund )
849
+ return removeSingleItem ( itemClass , refund , refundCurrentPrice )
846
850
:Then ( function ( )
847
851
return self :moduleItemsChanged ( )
848
852
end )
@@ -851,7 +855,7 @@ function Pointshop2Controller:removeItem( ply, itemClassName, refund )
851
855
end )
852
856
end
853
857
854
- function Pointshop2Controller :removeItems ( ply , itemClassNames , refund )
858
+ function Pointshop2Controller :removeItems ( ply , itemClassNames , refund , refundCurrentPrice )
855
859
local itemClassses = LibK ._ .map ( itemClassNames , function ( itemClassName )
856
860
local itemClass = Pointshop2 .GetItemClassByName ( itemClassName )
857
861
if not itemClass then
@@ -862,7 +866,7 @@ function Pointshop2Controller:removeItems( ply, itemClassNames, refund )
862
866
863
867
return Promise .Map ( itemClassses , function ( itemClass )
864
868
local itemClassName = itemClass .className
865
- return removeSingleItem ( itemClass , refund ):Then ( function ( )
869
+ return removeSingleItem ( itemClass , refund , refundCurrentPrice ):Then ( function ( )
866
870
return itemClassName
867
871
end )
868
872
end ):Then ( function ( removedClassNames )
0 commit comments