-
-
Notifications
You must be signed in to change notification settings - Fork 821
perf/refactor: implement player batch updates #3701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dudantas
wants to merge
54
commits into
main
Choose a base branch
from
dudantas/implement-player-batch-updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
37f0883
Add batch update and reward chest improvements
dudantas 6816cb9
Refactor NPC loot selling logic for efficiency
dudantas a3a6231
Add backpack and loot pouch access to Player Lua API
dudantas 4ff4cac
Notify player on sale letter delivery failure
dudantas 492f69d
Fix typo in variable name in internalCollectManagedItems
dudantas 1f926fd
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas 8024f6f
Refactor tests to use Google Test framework
dudantas d02388f
Code format - (CMake-format)
github-actions[bot] fe1d290
Code format - (Clang-format)
github-actions[bot] 4dad28d
Apply suggestions from code review
dudantas db61b3a
Replace std::find with std::ranges::find in loot logic
dudantas 3e006d8
Call updateState only when not batching in sendBatchUpdateContainer
dudantas d70797e
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas f5fdcd6
Refactor BatchUpdate to use shared_ptr and improve safety
dudantas e3c2304
Fix container cache updates and improve batch update tests
dudantas 8320dcc
Remove redundant item weight update in addItemBack
dudantas 06df817
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas 8688375
Add tests for batch update deduplication and player storage
dudantas 51fd09c
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas e2d70e5
Refactor batch update and NPC item selling logic
dudantas c22690c
Fix NPC sell logic and improve container safety checks
dudantas 104c6a8
Refactor NPC sell logic and improve batch update handling
dudantas b306c44
Improve error handling for custom currency sales
dudantas 34ea1e7
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas abc2cf7
fix: sonar changes
dudantas 5fd9501
Update cmake-lint.yml
dudantas 45cc00d
fix: compilation on linux
dudantas 1f60e5d
fix: review
dudantas 096c8c3
fix: review and build
dudantas 52cb4bb
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas 9f29a8f
improve: add missing tests and fix others
dudantas ae57cff
fix: add missing functions
dudantas 92471a9
Code format - (Clang-format)
github-actions[bot] 8ec23f2
Ensure container cache stays consistent
dudantas bc0e2fa
Collect items before removing all
dudantas 824cae9
fix: sonar
dudantas 68c6c19
Code format - (Clang-format)
github-actions[bot] 86117ff
fix: sonar
dudantas e60cca4
Ensure equip hooks fire during batching
dudantas 442c0cb
Ensure loot sale proceeds are atomic
dudantas 07ec9a4
Fix loot sale context labels
dudantas 12771bf
Update npc.cpp
dudantas b641d3a
Update src/creatures/npcs/npc.cpp
dudantas 7c7d3c4
Code format - (Clang-format)
github-actions[bot] f43597a
Update src/creatures/npcs/npc.cpp
dudantas 299cf0f
Code format - (Clang-format)
github-actions[bot] 50f5e78
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas 817ee12
Update src/creatures/npcs/npc.cpp
dudantas 32c2b38
Update src/creatures/npcs/npc.cpp
dudantas 6a3c443
Code format - (Clang-format)
github-actions[bot] fa64879
Fix type mismatches for cost calculations and cleanup guard
dudantas 1a47fd7
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas 436313e
Move balance_decrease metric to successful purchase
dudantas 5d2f3d5
Merge branch 'main' into dudantas/implement-player-batch-updates
dudantas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| local internalNpcName = "The Lootmonger" | ||
| local npcType = Game.createNpcType(internalNpcName) | ||
| local npcConfig = {} | ||
|
|
||
| npcConfig.name = internalNpcName | ||
| npcConfig.description = internalNpcName | ||
|
|
||
| npcConfig.health = 100 | ||
| npcConfig.maxHealth = npcConfig.health | ||
| npcConfig.walkInterval = 2000 | ||
| npcConfig.walkRadius = 2 | ||
|
|
||
| npcConfig.outfit = { | ||
| lookType = 1575, | ||
| lookHead = 96, | ||
| lookBody = 101, | ||
| lookLegs = 120, | ||
| lookFeet = 120, | ||
| lookAddons = 2, | ||
| } | ||
|
|
||
| npcConfig.flags = { | ||
| floorchange = false, | ||
| } | ||
|
|
||
| local keywordHandler = KeywordHandler:new() | ||
| local npcHandler = NpcHandler:new(keywordHandler) | ||
|
|
||
| npcType.onThink = function(npc, interval) | ||
| npcHandler:onThink(npc, interval) | ||
| end | ||
|
|
||
| npcType.onAppear = function(npc, creature) | ||
| npcHandler:onAppear(npc, creature) | ||
| end | ||
|
|
||
| npcType.onDisappear = function(npc, creature) | ||
| npcHandler:onDisappear(npc, creature) | ||
| end | ||
|
|
||
| npcType.onMove = function(npc, creature, fromPosition, toPosition) | ||
| npcHandler:onMove(npc, creature, fromPosition, toPosition) | ||
| end | ||
|
|
||
| npcType.onSay = function(npc, creature, type, message) | ||
| npcHandler:onSay(npc, creature, type, message) | ||
| end | ||
|
|
||
| npcType.onCloseChannel = function(npc, creature) | ||
| npcHandler:onCloseChannel(npc, creature) | ||
| end | ||
|
|
||
| npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) | ||
|
|
||
| npcConfig.shop = LootShopConfig | ||
|
|
||
| local function creatureSayCallback(npc, player, type, message) | ||
| if not npcHandler:checkInteraction(npc, player) then | ||
| return false | ||
| end | ||
| local categoryTable = LootShopConfigTable[message:lower()] | ||
| if MsgContains(message, "shop options") then | ||
| npcHandler:say("I sell a selection of " .. GetFormattedShopCategoryNames(LootShopConfigTable), npc, player) | ||
| elseif categoryTable then | ||
| local remainingCategories = npc:getRemainingShopCategories(message:lower(), LootShopConfigTable) | ||
| npcHandler:say("Of course, just browse through my wares. You can also look at " .. remainingCategories .. ".", npc, player) | ||
| npc:openShopWindowTable(player, categoryTable) | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) | ||
| npcHandler:setMessage(MESSAGE_GREET, "Ah, a customer! Be greeted, |PLAYERNAME|! I buy all kinds of loot, would you like a {trade}? I can also show you my {shop options}.") | ||
| npcHandler:setMessage(MESSAGE_SENDTRADE, "Ah, a customer! Be greeted, |PLAYERNAME|! I buy all kinds of loot, would you look at " .. GetFormattedShopCategoryNames(LootShopConfigTable) .. ".") | ||
|
|
||
| -- On buy npc shop message | ||
| npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost) | ||
| npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks) | ||
| end | ||
| -- On sell npc shop message | ||
| npcType.onSellItem = function(npc, player, itemId, subtype, amount, ignore, name, totalCost) | ||
| player:sendTextMessage(MESSAGE_TRADE, string.format("Sold %ix %s for %i gold.", amount, name, totalCost)) | ||
| end | ||
| -- On check npc shop message (look item) | ||
| npcType.onCheckItem = function(npc, player, clientId, subType) end | ||
|
|
||
| npcType:register(npcConfig) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| local addReward = TalkAction("/addreward") | ||
|
|
||
| function addReward.onSay(player, words, param) | ||
| local args = param:split(",") | ||
| local itemInput = (args[1] or ""):trim() | ||
| local amount = tonumber(args[2]) or 1 | ||
| local targetName = args[3] and args[3]:trim() or player:getName() | ||
|
|
||
| if itemInput == "" then | ||
| player:sendCancelMessage("Usage: /addreward item_name_or_id, amount[, target_player]") | ||
| return false | ||
| end | ||
|
|
||
| -- resolve target | ||
| local target = Player(targetName) | ||
| if not target then | ||
| player:sendCancelMessage("Target player not found.") | ||
| return false | ||
| end | ||
|
|
||
| -- resolve item | ||
| local it = ItemType(itemInput) | ||
| if it:getId() == 0 then | ||
| it = ItemType(tonumber(itemInput) or -1) | ||
| end | ||
| if it:getId() == 0 then | ||
| player:sendCancelMessage("Invalid item name or ID.") | ||
| return false | ||
| end | ||
|
|
||
| if amount < 1 then | ||
| player:sendCancelMessage("Invalid amount.") | ||
| return false | ||
| end | ||
|
|
||
| -- create/get the reward chest with a unique timestamp | ||
| local timestamp = systemTime() | ||
| local rewardBag = target:getReward(timestamp, true) | ||
|
|
||
| -- **this** will split your `amount` across as many | ||
| -- containers as necessary and return the total added | ||
| local added = target:addItemBatchToPaginedContainer(rewardBag, it:getId(), amount) | ||
| if added > 0 then | ||
| player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Added %d x %s to %s's reward chest(s).", added, it:getName(), target:getName())) | ||
| target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You received %d x %s in your reward chest(s).", added, it:getName())) | ||
| target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) | ||
| else | ||
| player:sendCancelMessage("Could not add item to reward chest.") | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| addReward:separator(" ") | ||
| addReward:groupType("god") | ||
| addReward:register() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.