Skip to content

Commit

Permalink
Merge pull request #253 from sebastian-heinz/feature/drops
Browse files Browse the repository at this point in the history
Enemy drops and random item gathering amounts
  • Loading branch information
alborrajo authored Apr 5, 2024
2 parents 44e759d + 08ef163 commit 6c5cbd7
Show file tree
Hide file tree
Showing 43 changed files with 213,582 additions and 11,231 deletions.
78 changes: 78 additions & 0 deletions Arrowgene.Ddon.GameServer/Characters/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,91 @@
using System.Linq;
using Arrowgene.Ddon.Database;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;

namespace Arrowgene.Ddon.GameServer.Characters
{
public class ItemManager
{
private static readonly Dictionary<uint, (WalletType Type, uint Quantity)> ItemIdWalletTypeAndQuantity = new Dictionary<uint, (WalletType Type, uint Amount)>() {
{7789, (WalletType.Gold, 1)},
{7790, (WalletType.Gold, 10)},
{7791, (WalletType.Gold, 100)},
{7792, (WalletType.RiftPoints,1)},
{7793, (WalletType.RiftPoints,10)},
{7794, (WalletType.RiftPoints,100)},
{7795, (WalletType.BloodOrbs,1)}, // Doesn't show up
{7796, (WalletType.BloodOrbs,10)}, // Doesn't show up
{7797, (WalletType.BloodOrbs,100)}, // Doesn't show up
{18742, (WalletType.HighOrbs,1)},
{18743, (WalletType.HighOrbs,10)},
{18744, (WalletType.HighOrbs,100)},
{18828,(WalletType.Gold,7500)},
{18829,(WalletType.RiftPoints,1250)},
{18830,(WalletType.BloodOrbs,750)},
{19508,(WalletType.Gold,1000)},
{19509,(WalletType.Gold,10000)},
{19510,(WalletType.RiftPoints,1000)},
{19511,(WalletType.BloodOrbs,1000)}
// TODO: Find all items that add wallet points
};

// [[item]]
// id = 16822 (Adds 100 XP)
// old = '経験値結晶'
// new = 'Experience Crystal'
// [[item]]
// id = 16831 (Adds 10000 XP)
// old = '経験値結晶'
// new = 'Experience Crystal'
// [[item]]
// id = 18831 (Adds 63000 XP)
// old = '経験値結晶'
// new = 'Experience Crystal'

// [[item]]
// id = 18832 (Adds 18 PP)
// old = 'プレイポイント'
// new = 'Play Point'
// [[item]]
// id = 25651 (Adds 1 PP)
// old = 'プレイポイント'
// new = 'Play Point'
// [[item]]
// id = 25652 (Adds 10 PP)
// old = 'プレイポイント'
// new = 'Play Point'
// [[item]]
// id = 25653 (Adds 100 PP)
// old = 'プレイポイント'
// new = 'Play Point'

public void GatherItem(DdonServer<GameClient> server, Character character, S2CItemUpdateCharacterItemNtc ntc, InstancedGatheringItem gatheringItem, uint pickedGatherItems)
{
if(ItemIdWalletTypeAndQuantity.ContainsKey(gatheringItem.ItemId)) {
var walletTypeAndQuantity = ItemIdWalletTypeAndQuantity[gatheringItem.ItemId];
uint totalQuantityToAdd = walletTypeAndQuantity.Quantity * gatheringItem.ItemNum;

CDataWalletPoint characterWalletPoint = character.WalletPointList.Where(wp => wp.Type == walletTypeAndQuantity.Type).First();
characterWalletPoint.Value += totalQuantityToAdd; // TODO: Cap to maximum for that wallet
server.Database.UpdateWalletPoint(character.CharacterId, characterWalletPoint);

CDataUpdateWalletPoint walletUpdate = new CDataUpdateWalletPoint();
walletUpdate.Type = walletTypeAndQuantity.Type;
walletUpdate.AddPoint = (int) totalQuantityToAdd;
walletUpdate.Value = characterWalletPoint.Value;
ntc.UpdateWalletList.Add(walletUpdate);

gatheringItem.ItemNum -= pickedGatherItems;
} else {
CDataItemUpdateResult? result = AddItem(server, character, true, gatheringItem.ItemId, pickedGatherItems);
ntc.UpdateItemList.Add(result);
gatheringItem.ItemNum -= (uint) result.UpdateItemNum;
}
}

public CDataItemUpdateResult? ConsumeItemByUId(DdonServer<GameClient> server, Character character, StorageType fromStorageType, string itemUId, uint consumeNum)
{
var foundItem = character.Storage.getStorage(fromStorageType).findItemByUId(itemUId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Execute(string[] command, GameClient client, ChatMessage me
LayerNo = layerNo,
GroupId = groupId
};
List<EnemySpawn> enemySpawns = Server.EnemyManager.GetAssets(enemyGroup, subGroupId);
List<Enemy> enemySpawns = Server.AssetRepository.EnemySpawnAsset.Enemies[(StageId.FromStageLayoutId(enemyGroup), subGroupId)];

if (enemySpawns.Count <= positionIndex)
{
Expand All @@ -59,7 +59,7 @@ public override void Execute(string[] command, GameClient client, ChatMessage me
S2CInstanceEnemyRepopNtc ntc = new S2CInstanceEnemyRepopNtc();
ntc.LayoutId = enemyGroup;
ntc.EnemyData.PositionIndex = positionIndex;
ntc.EnemyData.EnemyInfo = enemySpawns[positionIndex].Enemy;
ntc.EnemyData.EnemyInfo = enemySpawns[positionIndex].asCDataStageLayoutEnemyPresetEnemyInfoClient();
ntc.WaitSecond = waitSeconds;
client.Party.SendToAll(ntc);

Expand Down
12 changes: 3 additions & 9 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Linq;
/*
* This file is part of Arrowgene.Ddon.GameServer
*
Expand Down Expand Up @@ -29,8 +28,6 @@
using Arrowgene.Ddon.GameServer.Chat.Command;
using Arrowgene.Ddon.GameServer.Chat.Log;
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.GameServer.Enemy;
using Arrowgene.Ddon.GameServer.GatheringItems;
using Arrowgene.Ddon.GameServer.Handler;
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.Server;
Expand All @@ -39,7 +36,6 @@
using Arrowgene.Ddon.Shared.Entity;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Logging;
using Arrowgene.Networking.Tcp;
using Arrowgene.Ddon.GameServer.Shop;
Expand All @@ -62,9 +58,7 @@ public DdonGameServer(GameServerSetting setting, IDatabase database, AssetReposi
ClientLookup = new GameClientLookup();
ChatLogHandler = new ChatLogHandler();
ChatManager = new ChatManager(this, Router);
EnemyManager = new EnemyManager(assetRepository, database);
ItemManager = new ItemManager();
GatheringItemManager = new GatheringItemManager(assetRepository, database);
PartyManager = new PartyManager();
ExpManager = new ExpManager(database, ClientLookup);
JobManager = new JobManager();
Expand All @@ -79,9 +73,7 @@ public DdonGameServer(GameServerSetting setting, IDatabase database, AssetReposi
public event EventHandler<ClientConnectionChangeArgs> ClientConnectionChangeEvent;
public GameServerSetting Setting { get; }
public ChatManager ChatManager { get; }
public EnemyManager EnemyManager { get; }
public ItemManager ItemManager { get; }
public GatheringItemManager GatheringItemManager { get; }
public PartyManager PartyManager { get; }
public ExpManager ExpManager { get; }
public ShopManager ShopManager { get; }
Expand Down Expand Up @@ -146,7 +138,7 @@ ClientConnectionChangeArgs connectionChangeEventArgs
public override GameClient NewClient(ITcpSocket socket)
{
GameClient newClient = new GameClient(socket,
new PacketFactory(Setting.ServerSetting, PacketIdResolver.GamePacketIdResolver), ShopManager, GatheringItemManager);
new PacketFactory(Setting.ServerSetting, PacketIdResolver.GamePacketIdResolver), ShopManager, AssetRepository);
ClientLookup.Add(newClient);
return newClient;
}
Expand Down Expand Up @@ -261,6 +253,8 @@ private void LoadPacketHandler()
AddHandler(new InstanceEnemyGroupLeaveHandler(this));
AddHandler(new InstanceEnemyKillHandler(this));
AddHandler(new InstanceExchangeOmInstantKeyValueHandler(this));
AddHandler(new InstanceGetDropItemListHandler(this));
AddHandler(new InstanceGetDropItemHandler(this));
AddHandler(new InstanceGetEnemySetListHandler(this));
AddHandler(new InstanceGetGatheringItemHandler(this));
AddHandler(new InstanceGetGatheringItemListHandler(this));
Expand Down
14 changes: 0 additions & 14 deletions Arrowgene.Ddon.GameServer/Enemy/EnemyManager.cs

This file was deleted.

7 changes: 5 additions & 2 deletions Arrowgene.Ddon.GameServer/GameClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.GameServer.Shop;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Networking.Tcp;

namespace Arrowgene.Ddon.GameServer
{
public class GameClient : Client
{
public GameClient(ITcpSocket socket, PacketFactory packetFactory, ShopManager shopManager, GatheringItemManager gatheringItemManager) : base(socket, packetFactory)
public GameClient(ITcpSocket socket, PacketFactory packetFactory, ShopManager shopManager, AssetRepository assetRepository) : base(socket, packetFactory)
{
UpdateIdentity();
InstanceGatheringItemManager = new InstanceGatheringItemManager(gatheringItemManager);
InstanceGatheringItemManager = new InstanceGatheringItemManager(assetRepository);
InstanceDropItemManager = new InstanceDropItemManager(assetRepository);
InstanceShopManager = new InstanceShopManager(shopManager);
}

Expand All @@ -41,6 +43,7 @@ public void UpdateIdentity()
public PartyGroup Party { get; set; }
public InstanceShopManager InstanceShopManager { get; set; }
public InstanceGatheringItemManager InstanceGatheringItemManager { get; set; }
public InstanceDropItemManager InstanceDropItemManager { get; set; }

// TODO: Place somewhere else more sensible
public uint LastWarpPointId { get; set; }
Expand Down
14 changes: 0 additions & 14 deletions Arrowgene.Ddon.GameServer/GatheringItems/GatheringItemManager.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Model;

namespace Arrowgene.Ddon.GameServer.GatheringItems
{
public class InstanceDropItemManager : InstanceItemManager<uint>
{
public InstanceDropItemManager(AssetRepository assetRepository) : base()
{
this.assetRepository = assetRepository;
}

private readonly AssetRepository assetRepository;

protected override List<GatheringItem> FetchItemsFromRepository(StageId stage, uint setId)
{
List<Enemy> enemiesInSet = assetRepository.EnemySpawnAsset.Enemies.GetValueOrDefault((stage, (byte) 0));
if(enemiesInSet != null && setId < enemiesInSet.Count)
{
Enemy enemy = enemiesInSet[(int) setId];
if(enemy.DropsTable != null)
{
return enemy.DropsTable.Items;
}
}
return new List<GatheringItem>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
using System.Collections.Generic;
using System.Linq;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;

namespace Arrowgene.Ddon.GameServer.GatheringItems
{
public class InstanceGatheringItemManager
public class InstanceGatheringItemManager : InstanceItemManager<uint>
{
public InstanceGatheringItemManager(GatheringItemManager gatheringItemManager)
public InstanceGatheringItemManager(AssetRepository assetRepository) : base()
{
this._gatheringItemManager = gatheringItemManager;
this._gatheringItemsDictionary = new MultiKeyMultiValueDictionary<StageId, uint, GatheringItem>();
this.assetRepository = assetRepository;
}

private readonly GatheringItemManager _gatheringItemManager;
private readonly MultiKeyMultiValueDictionary<StageId, uint, GatheringItem> _gatheringItemsDictionary;
private readonly AssetRepository assetRepository;

public List<GatheringItem> GetAssets(CDataStageLayoutId stageLayoutId, uint subGroupId)
protected override List<GatheringItem> FetchItemsFromRepository(StageId stage, uint subGroupId)
{
return GetAssets(StageId.FromStageLayoutId(stageLayoutId), subGroupId);
}

public List<GatheringItem> GetAssets(StageId stageId, uint subGroupId)
{
if(!_gatheringItemsDictionary.Has(stageId, subGroupId))
{
List<GatheringItem> items = _gatheringItemManager.GetAssets(stageId, subGroupId);
List<GatheringItem> itemsClone = items.Select(item => (GatheringItem) item.Clone()).ToList();
_gatheringItemsDictionary.AddRange(stageId, subGroupId, itemsClone);
return items;
}

return _gatheringItemsDictionary.Get(stageId, subGroupId);
}

public void Clear()
{
_gatheringItemsDictionary.Clear();
return assetRepository.GatheringItems.GetValueOrDefault((stage, subGroupId)) ?? new List<GatheringItem>();
}
}
}
41 changes: 41 additions & 0 deletions Arrowgene.Ddon.GameServer/GatheringItems/InstanceItemManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Linq;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;

namespace Arrowgene.Ddon.GameServer.GatheringItems
{
public abstract class InstanceItemManager<T>
{
public InstanceItemManager()
{
this._gatheringItemsDictionary = new Dictionary<(StageId, T), List<InstancedGatheringItem>>();
}

private readonly Dictionary<(StageId, T), List<InstancedGatheringItem>> _gatheringItemsDictionary;

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

public List<InstancedGatheringItem> GetAssets(StageId stageId, T subGroupId)
{
if(!_gatheringItemsDictionary.ContainsKey((stageId, subGroupId)))
{
List<GatheringItem> items = FetchItemsFromRepository(stageId, subGroupId);
List<InstancedGatheringItem> instancedItems = items.Select(item => new InstancedGatheringItem(item)).ToList();
_gatheringItemsDictionary.Add((stageId, subGroupId), instancedItems);
return instancedItems;
}
return _gatheringItemsDictionary[(stageId, subGroupId)];
}

public void Clear()
{
_gatheringItemsDictionary.Clear();
}

protected abstract List<GatheringItem> FetchItemsFromRepository(StageId stage, T subGroupId);
}
}
22 changes: 22 additions & 0 deletions Arrowgene.Ddon.GameServer/GatheringItems/InstancedGatheringItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Arrowgene.Ddon.Shared.Model;

public class InstancedGatheringItem
{
public InstancedGatheringItem()
{
}

public InstancedGatheringItem(GatheringItem gatheringItem)
{
ItemId = gatheringItem.ItemId;
ItemNum = (uint) Random.Shared.Next((int) gatheringItem.ItemNum, (int) gatheringItem.MaxItemNum+1);
Quality = gatheringItem.Quality;
IsHidden = gatheringItem.IsHidden;
}

public uint ItemId { get; set; }
public uint ItemNum { get; set; }
public uint Quality { get; set; }
public bool IsHidden { get; set; }
}
Loading

0 comments on commit 6c5cbd7

Please sign in to comment.