Little update to item giving handling (#2363)

* Little update to HandlerItemGivingReq.java

GIVING_METHOD_GROUP is used in cooking girl's quest

* Send the giving packet at the start of relogs, even if encountered before.

* Make item checking not exact

You can have more items in your inventory than what you are submitting.
This commit is contained in:
Nazrin 2023-09-14 17:44:08 -07:00 committed by GitHub
parent 2b64814534
commit f955bb1e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 12 deletions

View File

@ -216,14 +216,14 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
}
/**
* Checks to see if the player has the item in their inventory. This is exact.
* Checks to see if the player has the item in their inventory. This is not exact.
*
* @param items A map of item game IDs to their count.
* @return True if the player has the items, false otherwise.
*/
public boolean hasAllItems(Collection<ItemParam> items) {
for (var item : items) {
if (!this.hasItem(item.getItemId(), item.getCount(), true)) return false;
if (!this.hasItem(item.getItemId(), item.getCount(), false)) return false;
}
return true;

View File

@ -101,21 +101,16 @@ public final class QuestManager extends BasePlayerManager {
* Attempts to add the giving action.
*
* @param givingId The giving action ID.
* @throws IllegalStateException If the giving action is already active.
*/
public void addGiveItemAction(int givingId) throws IllegalStateException {
var progress = this.player.getPlayerProgress();
var givings = progress.getItemGivings();
// Check if the action is already present.
if (givings.containsKey(givingId)) {
throw new IllegalStateException("Giving action " + givingId + " is already active.");
}
// Add the action.
// Check if the action is not present.
if (!givings.containsKey(givingId)) {
givings.put(givingId, ItemGiveRecord.resolve(givingId));
// Save the givings.
player.save();
}
this.sendGivingRecords();
}

View File

@ -55,7 +55,7 @@ public final class HandlerItemGivingReq extends PacketHandler {
questManager.queueEvent(QuestContent.QUEST_CONTENT_FINISH_ITEM_GIVING, giveId, 0);
questManager.queueEvent(QuestCond.QUEST_COND_ITEM_GIVING_FINISHED, giveId, 0);
}
case GIVING_METHOD_VAGUE_GROUP -> {
case GIVING_METHOD_VAGUE_GROUP, GIVING_METHOD_GROUP -> {
var matchedGroups = new ArrayList<Integer>();
var givenItems = new HashMap<Integer, Integer>();