Skip to content

Commit

Permalink
Merge pull request #249 from alborrajo/feature/crafting
Browse files Browse the repository at this point in the history
Initial crafting and bazaar implementation
  • Loading branch information
alborrajo authored Mar 22, 2024
2 parents 286f0d8 + 2c48b08 commit 3282b71
Show file tree
Hide file tree
Showing 86 changed files with 5,965 additions and 133 deletions.
60 changes: 59 additions & 1 deletion Arrowgene.Ddon.GameServer/Characters/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,65 @@ namespace Arrowgene.Ddon.GameServer.Characters
{
public class ItemManager
{
public CDataItemUpdateResult? ConsumeItemByUId(DdonServer<GameClient> server, Character character, StorageType fromStorageType, string itemUId, uint consumeNum)
{
var foundItem = character.Storage.getStorage(fromStorageType).findItemByUId(itemUId);
if(foundItem == null)
{
return null;
} else {
(ushort slotNo, Item item, uint itemNum) = foundItem;
return ConsumeItem(server, character, fromStorageType, slotNo, item, itemNum, consumeNum);
}
}
public CDataItemUpdateResult? ConsumeItemInSlot(DdonServer<GameClient> server, Character character, StorageType fromStorageType, ushort slotNo, uint consumeNum)
{
var foundItem = character.Storage.getStorageItem(fromStorageType, slotNo);
if(foundItem == null)
{
return null;
} else {
(Item item, uint itemNum) = foundItem;
return ConsumeItem(server, character, fromStorageType, slotNo, item, itemNum, consumeNum);
}
}
private CDataItemUpdateResult ConsumeItem(DdonServer<GameClient> server, Character character, StorageType fromStorageType, ushort slotNo, Item item, uint itemNum, uint consuneNum)
{
itemNum = Math.Max(0, itemNum - consuneNum);

CDataItemUpdateResult ntcData = new CDataItemUpdateResult();
ntcData.ItemList.ItemUId = item.UId;
ntcData.ItemList.ItemId = item.ItemId;
ntcData.ItemList.ItemNum = itemNum;
ntcData.ItemList.Unk3 = item.Unk3;
ntcData.ItemList.StorageType = fromStorageType;
ntcData.ItemList.SlotNo = slotNo;
ntcData.ItemList.Color = item.Color;
ntcData.ItemList.PlusValue = item.PlusValue;
ntcData.ItemList.Bind = false;
ntcData.ItemList.EquipPoint = 0;
ntcData.ItemList.EquipCharacterID = 0;
ntcData.ItemList.EquipPawnID = 0;
ntcData.ItemList.WeaponCrestDataList = item.WeaponCrestDataList;
ntcData.ItemList.ArmorCrestDataList = item.ArmorCrestDataList;
ntcData.ItemList.EquipElementParamList = item.EquipElementParamList;
ntcData.UpdateItemNum = -(int)consuneNum;

if(itemNum == 0)
{
// Delete item when ItemNum reaches 0 to free up the slot
character.Storage.setStorageItem(null, 0, fromStorageType, slotNo);
server.Database.DeleteStorageItem(character.CharacterId, fromStorageType, slotNo);
}
else
{
character.Storage.setStorageItem(item, itemNum, fromStorageType, slotNo);
server.Database.ReplaceStorageItem(character.CharacterId, fromStorageType, slotNo, item.UId, itemNum);
}

return ntcData;
}

public CDataItemUpdateResult AddItem(DdonServer<GameClient> server, Character character, bool itemBag, uint itemId, uint num)
{
if(itemBag)
Expand All @@ -25,7 +84,6 @@ public CDataItemUpdateResult AddItem(DdonServer<GameClient> server, Character ch
}

}

private CDataItemUpdateResult AddItem(IDatabase database, Character character, StorageType destinationStorageType, uint itemId, uint num, uint stackLimit = UInt32.MaxValue)
{
var tuple = character.Storage.getStorage(destinationStorageType).Items
Expand Down
15 changes: 15 additions & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ private void LoadPacketHandler()
AddHandler(new AreaGetLeaderAreaReleaseListHandler(this));

AddHandler(new BattleContentInfoListHandler(this));
AddHandler(new BazaarGetCharacterListHandler(this));
AddHandler(new BazaarGetExhibitPossibleNumHandler(this));
AddHandler(new BazaarGetItemHistoryInfoHandler(this));
AddHandler(new BazaarGetItemInfoHandler(this));
AddHandler(new BazaarGetItemListHandler(this));
AddHandler(new BazaarProceedsHandler(this));

AddHandler(new BinarySaveSetCharacterBinSavedataHandler(this));
AddHandler(new BlackListGetBlackListHandler(this));

Expand Down Expand Up @@ -212,7 +219,12 @@ private void LoadPacketHandler()
AddHandler(new ContextGetSetContextHandler(this));
AddHandler(new ContextMasterThrowHandler(this));
AddHandler(new ContextSetContextHandler(this));
AddHandler(new CraftGetCraftIRCollectionValueListHandler(this));
AddHandler(new CraftGetCraftProgressListHandler(this));
AddHandler(new CraftGetCraftSettingHandler(this));
AddHandler(new CraftRecipeGetCraftRecipeHandler(this));
AddHandler(new CraftStartCraftHandler(this));

AddHandler(new DailyMissionListGetHandler(this));

AddHandler(new EquipChangeCharacterEquipHandler(this));
Expand All @@ -221,7 +233,9 @@ private void LoadPacketHandler()
AddHandler(new EquipChangePawnEquipHandler(this));
AddHandler(new EquipChangePawnEquipJobItemHandler(this));
AddHandler(new EquipChangePawnStorageEquipHandler(this));
AddHandler(new EquipEnhancedGetPacks(this));
AddHandler(new EquipGetCharacterEquipListHandler(this));
AddHandler(new EquipGetCraftLockedElementListHandler(this));
AddHandler(new EquipUpdateHideCharacterHeadArmorHandler(this));
AddHandler(new EquipUpdateHideCharacterLanternHandler(this));
AddHandler(new EquipUpdateHidePawnHeadArmorHandler(this));
Expand Down Expand Up @@ -320,6 +334,7 @@ private void LoadPacketHandler()
AddHandler(new PawnGetPawnHistoryListHandler(this));
AddHandler(new PawnGetPawnTotalScoreHandler(this));
AddHandler(new PawnGetRegisteredPawnDataHandler(this));
AddHandler(new PawnGetRentedPawnDataHandler(this));
AddHandler(new PawnGetRentedPawnListHandler(this));
AddHandler(new PawnJoinPartyMypawnHandler(this));
AddHandler(new PawnPawnLostHandler(this));
Expand Down
35 changes: 35 additions & 0 deletions Arrowgene.Ddon.GameServer/Dump/InGameDump.cs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/BazaarGetCharacterListHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class BazaarGetCharacterListHandler : GameStructurePacketHandler<C2SBazaarGetCharacterListReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(BazaarGetCharacterListHandler));

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

public override void Handle(GameClient client, StructurePacket<C2SBazaarGetCharacterListReq> packet)
{
client.Send(new S2CBazaarGetCharacterListRes());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class BazaarGetExhibitPossibleNumHandler : GameStructurePacketHandler<C2SBazaarGetExhibitPossibleNumReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(BazaarGetExhibitPossibleNumHandler));

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

public override void Handle(GameClient client, StructurePacket<C2SBazaarGetExhibitPossibleNumReq> packet)
{
client.Send(new S2CBazaarGetExhibitPossibleNumRes());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class BazaarGetItemHistoryInfoHandler : GameStructurePacketHandler<C2SBazaarGetItemHistoryInfoReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(BazaarGetItemHistoryInfoHandler));

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

public override void Handle(GameClient client, StructurePacket<C2SBazaarGetItemHistoryInfoReq> packet)
{
client.Send(new S2CBazaarGetItemHistoryInfoRes());
}
}
}
44 changes: 44 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/BazaarGetItemInfoHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Linq;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
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;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class BazaarGetItemInfoHandler : GameStructurePacketHandler<C2SBazaarGetItemInfoReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(BazaarGetItemInfoHandler));

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

public override void Handle(GameClient client, StructurePacket<C2SBazaarGetItemInfoReq> packet)
{
// TODO: Fetch from DB

ClientItemInfo queriedItem = ClientItemInfo.GetInfoForItemId(Server.AssetRepository.ClientItemInfos, packet.Structure.ItemId);
S2CBazaarGetItemInfoRes res = new S2CBazaarGetItemInfoRes();
for (ushort i = 1; i <= 10; i++)
{
res.BazaarItemList.Add(new CDataBazaarItemInfo()
{
BazaarId = 0,
Sequence = 0,
ItemBaseInfo = new CDataBazaarItemBaseInfo() {
ItemId = packet.Structure.ItemId,
Num = i,
Price = (uint) queriedItem.Price * i,
},
ExhibitionTime = 0
});
}
client.Send(res);
}
}
}
31 changes: 31 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/BazaarGetItemListHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Linq;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class BazaarGetItemListHandler : GameStructurePacketHandler<C2SBazaarGetItemListReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(BazaarGetItemListHandler));

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

public override void Handle(GameClient client, StructurePacket<C2SBazaarGetItemListReq> packet)
{
// TODO: Fetch from DB

client.Send(new S2CBazaarGetItemListRes() {
ItemList = packet.Structure.ItemIdList.Select(itemId => new CDataBazaarItemNumOfExhibitionInfo()
{
ItemId = itemId.Value,
Num = (ushort) Enumerable.Range(1, 10).Sum()
}).ToList()
});
}
}
}
77 changes: 77 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/BazaarProceedsHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#nullable enable

using System;
using System.Linq;
using Arrowgene.Ddon.GameServer.Characters;
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;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class BazaarProceedsHandler : GameStructurePacketHandler<C2SBazaarProceedsReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(BazaarProceedsHandler));

private readonly ItemManager _itemManager;

public BazaarProceedsHandler(DdonGameServer server) : base(server)
{
_itemManager = server.ItemManager;
}

public override void Handle(GameClient client, StructurePacket<C2SBazaarProceedsReq> packet)
{
// TODO: Fetch price by the BazaarId
ClientItemInfo boughtItemInfo = ClientItemInfo.GetInfoForItemId(Server.AssetRepository.ClientItemInfos, packet.Structure.ItemId);
int totalItemAmount = packet.Structure.ItemStorageIndicateNum.Select(x => (int) x.ItemNum).Sum();
int totalPrice = boughtItemInfo.Price * totalItemAmount;

S2CBazaarProceedsRes res = new S2CBazaarProceedsRes();
res.BazaarId = packet.Structure.BazaarId;

S2CItemUpdateCharacterItemNtc updateCharacterItemNtc = new S2CItemUpdateCharacterItemNtc();
updateCharacterItemNtc.UpdateType = 0;

// UPDATE CHARACTER WALLET
CDataWalletPoint wallet = client.Character.WalletPointList.Where(wp => wp.Type == WalletType.Gold).Single();
wallet.Value = (uint) Math.Max(0, wallet.Value - totalPrice);
Database.UpdateWalletPoint(client.Character.CharacterId, wallet);
updateCharacterItemNtc.UpdateWalletList.Add(new CDataUpdateWalletPoint()
{
Type = WalletType.Gold,
AddPoint = (int) -totalPrice,
Value = wallet.Value
});

// UPDATE INVENTORY
foreach (CDataItemStorageIndicateNum itemStorageIndicateNum in packet.Structure.ItemStorageIndicateNum)
{
bool sendToItemBag;
switch(itemStorageIndicateNum.StorageType) {
case 19:
// If packet.Structure.Destination is 19: Send to corresponding item bag
sendToItemBag = true;
break;
case 20:
// If packet.Structure.Destination is 20: Send to storage
sendToItemBag = false;
break;
default:
throw new Exception("Unexpected destination when buying goods: "+itemStorageIndicateNum.StorageType);
}

CDataItemUpdateResult? itemUpdateResult = _itemManager.AddItem(Server, client.Character, sendToItemBag, packet.Structure.ItemId, itemStorageIndicateNum.ItemNum);
updateCharacterItemNtc.UpdateItemList.Add(itemUpdateResult);
}

// Send packets
client.Send(updateCharacterItemNtc);
client.Send(res);
// TODO: Send the NTC to the seller?
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class CraftGetCraftIRCollectionValueListHandler : GameStructurePacketHandler<C2SCraftGetCraftIRCollectionValueListReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(CraftGetCraftIRCollectionValueListHandler));

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

public override void Handle(GameClient client, StructurePacket<C2SCraftGetCraftIRCollectionValueListReq> packet)
{
S2CCraftGetCraftIRCollectionValueListRes res = EntitySerializer.Get<S2CCraftGetCraftIRCollectionValueListRes>().Read(InGameDump.data_Dump_109);
client.Send(res);
}
}
}
Loading

0 comments on commit 3282b71

Please sign in to comment.