Skip to content

Commit

Permalink
Random chance for gathering items to break
Browse files Browse the repository at this point in the history
  • Loading branch information
alborrajo committed May 8, 2024
1 parent 8a1702a commit bf117ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Characters/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Arrowgene.Ddon.GameServer.Characters
{
public class ItemManager
{
private static readonly StorageType[] ItemBagStorageTypes = new StorageType[] { StorageType.ItemBagConsumable, StorageType.ItemBagMaterial, StorageType.ItemBagEquipment, StorageType.ItemBagJob };
public static readonly List<StorageType> ItemBagStorageTypes = new List<StorageType> { StorageType.ItemBagConsumable, StorageType.ItemBagMaterial, StorageType.ItemBagEquipment, StorageType.ItemBagJob };

private static readonly Dictionary<uint, (WalletType Type, uint Quantity)> ItemIdWalletTypeAndQuantity = new Dictionary<uint, (WalletType Type, uint Amount)>() {
{7789, (WalletType.Gold, 1)},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Arrowgene.Ddon.GameServer.Characters;
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 InstanceGetGatheringItemListHandler : StructurePacketHandler<GameClient, C2SInstanceGetGatheringItemListReq>
public class InstanceGetGatheringItemListHandler : GameStructurePacketHandler<C2SInstanceGetGatheringItemListReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(InstanceGetGatheringItemListHandler));

// TODO: Different chances for each gathering item type
private static readonly double BREAK_CHANCE = 0.1;

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

public override void Handle(GameClient client, StructurePacket<C2SInstanceGetGatheringItemListReq> req)
{
bool isGatheringItemBreak = false;
if(!client.InstanceGatheringItemManager.HasAssetsInstanced(req.Structure.LayoutId, req.Structure.PosId) && req.Structure.GatheringItemUId.Length > 0 && Random.Shared.NextDouble() < BREAK_CHANCE)
{
isGatheringItemBreak = true;

S2CItemUpdateCharacterItemNtc ntc = new S2CItemUpdateCharacterItemNtc();
ntc.UpdateItemList.AddRange(Server.ItemManager.ConsumeItemByUIdFromMultipleStorages(Server, client.Character, ItemManager.ItemBagStorageTypes, req.Structure.GatheringItemUId, 1));
client.Send(ntc);
}

List<InstancedGatheringItem> gatheringItems = client.InstanceGatheringItemManager.GetAssets(req.Structure.LayoutId, req.Structure.PosId);

S2CInstanceGetGatheringItemListRes res = new S2CInstanceGetGatheringItemListRes();
res.LayoutId = req.Structure.LayoutId;
res.PosId = req.Structure.PosId;
res.GatheringItemUId = "PROBANDO"; // TODO: Find out somehow what gathering item was used and send it back
res.IsGatheringItemBreak = false; // TODO: False by default. True if lockpick?, or random if other gathering item. Update broken item by sending S2CItemUpdateCharacterItemNtc
res.GatheringItemUId = req.Structure.GatheringItemUId;
res.IsGatheringItemBreak = isGatheringItemBreak;
res.Unk0 = false;
res.Unk1 = new List<CDataGatheringItemListUnk1>();
res.ItemList = gatheringItems
Expand Down
12 changes: 11 additions & 1 deletion Arrowgene.Ddon.GameServer/InstanceAssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ public InstanceAssetManager()

private readonly Dictionary<(StageId, T1), List<T3>> _instancedAssetsDictionary;

public bool HasAssetsInstanced(CDataStageLayoutId stageLayoutId, T1 subGroupId)
{
return _instancedAssetsDictionary.ContainsKey((StageId.FromStageLayoutId(stageLayoutId), subGroupId));
}

public bool HasAssetsInstanced(StageId stageId, T1 subGroupId)
{
return _instancedAssetsDictionary.ContainsKey((stageId, subGroupId));
}

public List<T3> GetAssets(CDataStageLayoutId stageLayoutId, T1 subGroupId)
{
return GetAssets(StageId.FromStageLayoutId(stageLayoutId), subGroupId);
}

public List<T3> GetAssets(StageId stageId, T1 subGroupId)
{
if(!_instancedAssetsDictionary.ContainsKey((stageId, subGroupId)))
if(!HasAssetsInstanced(stageId, subGroupId))
{
List<T2> items = FetchAssetsFromRepository(stageId, subGroupId);
List<T3> instancedAssets = InstanceAssets(items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public class C2SInstanceGetGatheringItemListReq : IPacketStructure

public CDataStageLayoutId LayoutId { get; set; }
public uint PosId { get; set; }
public string GatheringItemUId { get; set; }

public C2SInstanceGetGatheringItemListReq()
{
LayoutId = new CDataStageLayoutId();
GatheringItemUId = string.Empty;
}

public class Serializer : PacketEntitySerializer<C2SInstanceGetGatheringItemListReq>
Expand All @@ -22,12 +24,14 @@ public override void Write(IBuffer buffer, C2SInstanceGetGatheringItemListReq ob
{
WriteEntity(buffer, obj.LayoutId);
WriteUInt32(buffer, obj.PosId);
WriteMtString(buffer, obj.GatheringItemUId);
}
public override C2SInstanceGetGatheringItemListReq Read(IBuffer buffer)
{
C2SInstanceGetGatheringItemListReq obj = new C2SInstanceGetGatheringItemListReq();
obj.LayoutId = ReadEntity<CDataStageLayoutId>(buffer);
obj.PosId = ReadUInt32(buffer);
obj.GatheringItemUId = ReadMtString(buffer);
return obj;
}
}
Expand Down

0 comments on commit bf117ef

Please sign in to comment.