Skip to content
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

Fix: Small Fixes 1/10 #690

Merged
merged 11 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Arrowgene.Ddon.Database/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,13 @@ uint commonId
List<BazaarExhibition> FetchCharacterBazaarExhibitions(uint characterId);
List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdExcludingOwn(
uint itemId,
uint excludedCharacterId
uint excludedCharacterId,
DbConnection? connectionIn = null
);
List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdsExcludingOwn(
List<uint> itemIds,
uint excludedCharacterId
uint excludedCharacterId,
DbConnection? connectionIn = null
);

// Rewards
Expand Down
35 changes: 14 additions & 21 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbBazaarExhibition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,13 @@ public List<BazaarExhibition> SelectBazaarExhibitionsByCharacterId(TCon conn, ui

return entities;
}


public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdExcludingOwn(uint itemId, uint excludedCharacterId)
{
using TCon conn = OpenNewConnection();
return SelectActiveBazaarExhibitionsByItemIdExcludingOwn(conn, itemId, excludedCharacterId);
}

public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdExcludingOwn(TCon conn, uint itemId, uint excludedCharacterId)

public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdExcludingOwn(uint itemId, uint excludedCharacterId, DbConnection? connectionIn = null)
{
List<BazaarExhibition> entities = new List<BazaarExhibition>();
ExecuteReader(conn, SqlSelectActiveBazaarExhibitionsByItemIdExcludingOwn,
ExecuteQuerySafe(connectionIn, conn =>
{
ExecuteReader(conn, SqlSelectActiveBazaarExhibitionsByItemIdExcludingOwn,
command =>
{
AddParameter(command, "@item_id", itemId);
Expand All @@ -180,24 +175,22 @@ public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdExcludingOwn(
entities.Add(e);
}
});
});

return entities;
}

public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdsExcludingOwn(List<uint> itemIds, uint excludedCharacterId)
{
using TCon conn = OpenNewConnection();
return SelectActiveBazaarExhibitionsByItemIdsExcludingOwn(conn, itemIds, excludedCharacterId);
}

public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdsExcludingOwn(TCon conn, List<uint> itemIds, uint excludedCharacterId)
public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdsExcludingOwn(List<uint> itemIds, uint excludedCharacterId, DbConnection? connectionIn = null)
{
List<BazaarExhibition> entities = new List<BazaarExhibition>();
foreach (uint itemId in itemIds)
ExecuteQuerySafe(connectionIn, conn =>
{
List<BazaarExhibition> exhibitionsForItemId = SelectActiveBazaarExhibitionsByItemIdExcludingOwn(conn, itemId, excludedCharacterId);
entities.AddRange(exhibitionsForItemId);
}
foreach (uint itemId in itemIds)
{
List<BazaarExhibition> exhibitionsForItemId = SelectActiveBazaarExhibitionsByItemIdExcludingOwn(itemId, excludedCharacterId, conn);
entities.AddRange(exhibitionsForItemId);
}
});
return entities;
}

Expand Down
5 changes: 3 additions & 2 deletions Arrowgene.Ddon.GameServer/BazaarManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
Expand Down Expand Up @@ -194,9 +195,9 @@ public List<BazaarExhibition> GetExhibitionsByCharacter(Character character)
return Server.Database.FetchCharacterBazaarExhibitions(character.CharacterId);
}

public List<BazaarExhibition> GetActiveExhibitionsForItemId(uint itemId, Character filterOutCharacter)
public List<BazaarExhibition> GetActiveExhibitionsForItemId(uint itemId, Character filterOutCharacter, DbConnection? connectionIn = null)
{
return Server.Database.SelectActiveBazaarExhibitionsByItemIdExcludingOwn(itemId, filterOutCharacter.CharacterId);
return Server.Database.SelectActiveBazaarExhibitionsByItemIdExcludingOwn(itemId, filterOutCharacter.CharacterId, connectionIn);
}

public List<BazaarExhibition> GetActiveExhibitionsForItemIds(List<uint> itemIds, Character filterOutCharacter)
Expand Down
4 changes: 4 additions & 0 deletions Arrowgene.Ddon.GameServer/Characters/HubManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ private void NaiveLobbyHandling(GameClient client, uint sourceStageId)

foreach (GameClient otherClient in Server.ClientLookup.GetAll())
{
if (otherClient.Character is null)
{
continue;
}
targetClients.Add(otherClient);
gatherClients.Add(otherClient);
}
Expand Down
42 changes: 32 additions & 10 deletions Arrowgene.Ddon.GameServer/Characters/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,41 @@ public bool IsItemWalletPoint(uint itemId)
// old = 'プレイポイント'
// new = 'Play Point'

public void GatherItem(DdonGameServer server, Character character, S2CItemUpdateCharacterItemNtc ntc, InstancedGatheringItem gatheringItem, uint pickedGatherItems, DbConnection? connectionIn = null)
public void GatherItem(Character character, S2CItemUpdateCharacterItemNtc ntc, InstancedGatheringItem gatheringItem, uint pickedGatherItems, DbConnection? connectionIn = null)
{
if(ItemIdWalletTypeAndQuantity.ContainsKey(gatheringItem.ItemId)) {
if (ItemIdWalletTypeAndQuantity.ContainsKey(gatheringItem.ItemId))
{
var walletTypeAndQuantity = ItemIdWalletTypeAndQuantity[gatheringItem.ItemId];
uint totalQuantityToAdd = walletTypeAndQuantity.Quantity * gatheringItem.ItemNum;

ntc.UpdateWalletList.Add(
server.WalletManager.AddToWallet(character, walletTypeAndQuantity.Type, totalQuantityToAdd, 0, connectionIn
_Server.WalletManager.AddToWallet(character, walletTypeAndQuantity.Type, totalQuantityToAdd, 0, connectionIn
));

if (pickedGatherItems > gatheringItem.ItemNum)
{
throw new ResponseErrorException(ErrorCode.ERROR_CODE_ITEM_INVALID_ITEM_NUM,
$"Overflow error, trying to remove {pickedGatherItems} from stack of ID {gatheringItem.ItemId} x{gatheringItem.ItemNum}",
critical:true);
}

gatheringItem.ItemNum -= pickedGatherItems;
} else {
List<CDataItemUpdateResult> results = AddItem(server, character, true, gatheringItem.ItemId, pickedGatherItems, connectionIn:connectionIn);
}
else
{
List<CDataItemUpdateResult> results = AddItem(_Server, character, true, gatheringItem.ItemId, pickedGatherItems, connectionIn:connectionIn);
ntc.UpdateItemList.AddRange(results);
gatheringItem.ItemNum -= (uint) results.Select(result => result.UpdateItemNum).Sum();

uint totalRemoved = (uint)results.Select(result => result.UpdateItemNum).Sum();

if (totalRemoved > gatheringItem.ItemNum)
{
throw new ResponseErrorException(ErrorCode.ERROR_CODE_ITEM_INVALID_ITEM_NUM,
$"Overflow error, trying to remove {totalRemoved} from stack of ID {gatheringItem.ItemId} x{gatheringItem.ItemNum}",
critical: true);
}

gatheringItem.ItemNum -= totalRemoved;
}
}

Expand Down Expand Up @@ -952,24 +972,26 @@ public void SetSafetySetting(GameClient client, Character character, List<CDataI
}

[Serializable]
internal class ItemDoesntExistException : Exception
internal class ItemDoesntExistException : ResponseErrorException
{
private string itemUID;

public ItemDoesntExistException(string itemUID) : base ($"An item with the UID {itemUID} is missing in the database")
public ItemDoesntExistException(string itemUID)
: base (ErrorCode.ERROR_CODE_ITEM_NOT_FOUND, $"An item with the UID {itemUID} is missing in the database")
{
this.itemUID = itemUID;
}
}

[Serializable]
internal class NotEnoughItemsException : Exception
internal class NotEnoughItemsException : ResponseErrorException
{
private string itemUId;
private uint consumeNum;
private int remainingItems;

public NotEnoughItemsException(string itemUId, uint consumeNum, int remainingItems) : base($"Required {consumeNum} items of UID {itemUId}, missing {remainingItems} items")
public NotEnoughItemsException(string itemUId, uint consumeNum, int remainingItems)
: base(ErrorCode.ERROR_CODE_ITEM_NUM_SHORT, $"Required {consumeNum} items of UID {itemUId}, missing {remainingItems} items")
{
this.itemUId = itemUId;
this.consumeNum = consumeNum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ protected override List<GatheringItem> FetchAssetsFromRepository(StageId stage,
List<InstancedEnemy> enemiesInSet = _client.Party.InstanceEnemyManager.GetAssets(stage);
if(enemiesInSet != null && setId < enemiesInSet.Count)
{
Enemy enemy = enemiesInSet[(int) setId];
Enemy enemy = enemiesInSet[setId];

if (enemy.DropsTable != null)
{
return enemy.DropsTable.Items;
}
return enemy?.DropsTable?.Items ?? new();
}
return new List<GatheringItem>();
}
Expand Down
30 changes: 15 additions & 15 deletions Arrowgene.Ddon.GameServer/Handler/BazaarGetItemListHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using System.Collections.Generic;

namespace Arrowgene.Ddon.GameServer.Handler
{
Expand All @@ -18,24 +17,25 @@ public BazaarGetItemListHandler(DdonGameServer server) : base(server)

public override S2CBazaarGetItemListRes Handle(GameClient client, C2SBazaarGetItemListReq request)
{
// TODO: Optimize to run in one DB connection
S2CBazaarGetItemListRes response = new S2CBazaarGetItemListRes();
foreach (CDataCommonU32 itemId in request.ItemIdList)
{
List<BazaarExhibition> exhibitionsForItemId = Server.BazaarManager.GetActiveExhibitionsForItemId(itemId.Value, client.Character);
if(exhibitionsForItemId.Count > 0)
Server.Database.ExecuteInTransaction(connection => {
foreach (CDataCommonU32 itemId in request.ItemIdList)
{
CDataBazaarItemNumOfExhibitionInfo exhibitionInfo = new CDataBazaarItemNumOfExhibitionInfo();
exhibitionInfo.ItemId = itemId.Value;
foreach (BazaarExhibition exhibition in exhibitionsForItemId)
List<BazaarExhibition> exhibitionsForItemId = Server.BazaarManager.GetActiveExhibitionsForItemId(itemId.Value, client.Character, connection);
if (exhibitionsForItemId.Count > 0)
{
exhibitionInfo.Num += exhibition.Info.ItemInfo.ItemBaseInfo.Num;
CDataBazaarItemNumOfExhibitionInfo exhibitionInfo = new CDataBazaarItemNumOfExhibitionInfo();
exhibitionInfo.ItemId = itemId.Value;
foreach (BazaarExhibition exhibition in exhibitionsForItemId)
{
exhibitionInfo.Num += exhibition.Info.ItemInfo.ItemBaseInfo.Num;
}
response.ItemList.Add(exhibitionInfo);
}
response.ItemList.Add(exhibitionInfo);
}
}
// TODO: response.Unk0
});

return response;
}
}
}
}
26 changes: 12 additions & 14 deletions Arrowgene.Ddon.GameServer/Handler/InstanceGetDropItemHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,62 @@
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using System.Collections.Generic;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class InstanceGetDropItemHandler : GameStructurePacketHandler<C2SInstanceGetDropItemReq>
public class InstanceGetDropItemHandler : GameRequestPacketHandler<C2SInstanceGetDropItemReq, S2CInstanceGetDropItemRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(InstanceGetDropItemHandler));

public InstanceGetDropItemHandler(DdonGameServer server) : base(server)
{
}

public override void Handle(GameClient client, StructurePacket<C2SInstanceGetDropItemReq> packet)
public override S2CInstanceGetDropItemRes Handle(GameClient client, C2SInstanceGetDropItemReq request)
{
// This call is for when an item is claimed from a bag. It needs the drops rolled from the enemy to keep track of the items left.

List<InstancedGatheringItem> items = new List<InstancedGatheringItem>();

if (client.InstanceQuestDropManager.IsQuestDrop(packet.Structure.LayoutId, packet.Structure.SetId))
if (client.InstanceQuestDropManager.IsQuestDrop(request.LayoutId, request.SetId))
{
items.AddRange(client.InstanceQuestDropManager.FetchEnemyLoot());
} else
{
items.AddRange(client.InstanceDropItemManager.GetAssets(packet.Structure.LayoutId, (int)packet.Structure.SetId));
items.AddRange(client.InstanceDropItemManager.GetAssets(request.LayoutId, (int)request.SetId));
}

// Special Event Items
items.AddRange(client.InstanceEventDropItemManager.FetchEventItems(client, packet.Structure.LayoutId, packet.Structure.SetId));
items.AddRange(client.InstanceEventDropItemManager.FetchEventItems(client, request.LayoutId, request.SetId));

// Add Epitaph Items
items.AddRange(client.InstanceEpiDropItemManager.FetchItems(client, packet.Structure.LayoutId, packet.Structure.SetId));
items.AddRange(client.InstanceEpiDropItemManager.FetchItems(client, request.LayoutId, request.SetId));

S2CInstanceGetDropItemRes res = new()
{
LayoutId = packet.Structure.LayoutId,
SetId = packet.Structure.SetId,
GatheringItemGetRequestList = packet.Structure.GatheringItemGetRequestList
LayoutId = request.LayoutId,
SetId = request.SetId,
GatheringItemGetRequestList = request.GatheringItemGetRequestList
};

client.Send(res);

S2CItemUpdateCharacterItemNtc ntc = new S2CItemUpdateCharacterItemNtc()
{
UpdateType = ItemNoticeType.Drop
};

Server.Database.ExecuteInTransaction(connection =>
{
foreach (CDataGatheringItemGetRequest gatheringItemRequest in packet.Structure.GatheringItemGetRequestList)
foreach (CDataGatheringItemGetRequest gatheringItemRequest in request.GatheringItemGetRequestList)
{
InstancedGatheringItem dropItem = items[(int)gatheringItemRequest.SlotNo];
Server.ItemManager.GatherItem(Server, client.Character, ntc, dropItem, gatheringItemRequest.Num, connection);
Server.ItemManager.GatherItem(client.Character, ntc, dropItem, gatheringItemRequest.Num, connection);
}
});

client.Send(ntc);
return res;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using System.Collections.Generic;

Expand Down Expand Up @@ -48,13 +49,20 @@ public override PacketQueue Handle(GameClient client, C2SInstanceGetGatheringIte
gatheredItem = client.InstanceGatheringItemManager.GetAssets(request.LayoutId, (int)request.PosId)[(int)gatheringItemRequest.SlotNo];
}

Server.ItemManager.GatherItem(Server, client.Character, ntc, gatheredItem, gatheringItemRequest.Num, connection);
Server.ItemManager.GatherItem(client.Character, ntc, gatheredItem, gatheringItemRequest.Num, connection);
}
});

client.Enqueue(ntc, packetQueue);

S2CInstanceGetGatheringItemRes res = new S2CInstanceGetGatheringItemRes();
res.LayoutId = request.LayoutId;
res.PosId = request.PosId;
res.GatheringItemGetRequestList = request.GatheringItemGetRequestList;
client.Enqueue(res, packetQueue);

if (request.EquipToCharacter == 1)
{

var itemInfo = ClientItemInfo.GetInfoForItemId(Server.AssetRepository.ClientItemInfos, ntc.UpdateItemList[0].ItemList.ItemId);
var equipInfo = new CDataCharacterEquipInfo()
{
Expand All @@ -63,23 +71,19 @@ public override PacketQueue Handle(GameClient client, C2SInstanceGetGatheringIte
EquipType = EquipType.Performance,
};

packetQueue.AddRange(Server.EquipManager.HandleChangeEquipList(
Server,
client,
client.Character,
new List<CDataCharacterEquipInfo>() { equipInfo },
ItemNoticeType.GatherEquipItem,
new List<StorageType>() { StorageType.ItemBagEquipment }));
Server.Database.ExecuteInTransaction(connection =>
{
packetQueue.AddRange(Server.EquipManager.HandleChangeEquipList(
Server,
client,
client.Character,
new List<CDataCharacterEquipInfo>() { equipInfo },
ItemNoticeType.GatherEquipItem,
new List<StorageType>() { StorageType.ItemBagEquipment },
connection));
});
}

client.Enqueue(ntc, packetQueue);

S2CInstanceGetGatheringItemRes res = new S2CInstanceGetGatheringItemRes();
res.LayoutId = request.LayoutId;
res.PosId = request.PosId;
res.GatheringItemGetRequestList = request.GatheringItemGetRequestList;
client.Enqueue(res, packetQueue);

return packetQueue;
}
}
Expand Down
Loading
Loading