Skip to content

Commit

Permalink
Merge pull request #642 from RyanYappert/fix/fixes-11-22
Browse files Browse the repository at this point in the history
Fix: Small fixes 11/22
  • Loading branch information
RyanYappert authored Nov 29, 2024
2 parents 174a238 + a0a23bd commit a0236d2
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 163 deletions.
5 changes: 4 additions & 1 deletion Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ public Character SelectCharacter(uint characterId, DbConnection? connectionIn =
}
});

QueryCharacterData(conn, character);
if (character != null)
{
QueryCharacterData(conn, character);
}
});
return character;
}
Expand Down
6 changes: 2 additions & 4 deletions Arrowgene.Ddon.Database/Sql/SqlDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ public bool ExecuteInTransaction(Action<TCon> action)
transaction.Commit();
return true;
}
catch (Exception ex)
catch (Exception)
{
transaction.Rollback();
connection.Close();
Exception(ex);
return false;
throw;
}
finally
{
Expand Down
23 changes: 8 additions & 15 deletions Arrowgene.Ddon.GameServer/Characters/ClanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Model.Clan;
using Arrowgene.Ddon.Shared.Model.Rpc;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data.Common;
Expand Down Expand Up @@ -520,8 +520,11 @@ public PacketQueue CompleteClanQuest(Quest quest, GameClient client)
{
ClanQuestClearCount[characterId][quest.QuestScheduleId] = ClanQuestClearCount[characterId].GetValueOrDefault(quest.QuestScheduleId) + 1;

// TODO: Revise this; this is a hacky solution so I don't need a dedicated route just for this one mechanic.
Server.RpcManager.AnnounceClanPacket(character.ClanId, ntc, characterId);
Server.RpcManager.AnnounceOthers("internal/tracking", RpcInternalCommand.NotifyClanQuestCompletion, new RpcQuestCompletionData()
{
CharacterId = characterId,
QuestStatus = ClanQuestClearCount[characterId]
});
}

if (ClanQuestClearCount[characterId].GetValueOrDefault(quest.QuestScheduleId) == quest.LightQuestDetail.OrderLimit)
Expand All @@ -534,19 +537,9 @@ public PacketQueue CompleteClanQuest(Quest quest, GameClient client)
}

// For syncing across channels.
public void CompleteClanQuestForeign(Quest quest, uint characterId)
public void UpdateClanQuestCompletion(uint characterId, Dictionary<uint, uint> questStatus)
{
if (!ClanQuestClearCount.ContainsKey(characterId))
{
ClanQuestClearCount[characterId] = new();
}
lock (ClanQuestClearCount[characterId])
{
if (ClanQuestClearCount[characterId].GetValueOrDefault(quest.QuestScheduleId) < quest.LightQuestDetail.OrderLimit)
{
ClanQuestClearCount[characterId][quest.QuestScheduleId] = ClanQuestClearCount[characterId].GetValueOrDefault(quest.QuestScheduleId) + 1;
}
}
ClanQuestClearCount[characterId] = questStatus;
}

public uint ClanQuestCompletionStatistics(uint characterId, uint questScheduleId)
Expand Down
6 changes: 2 additions & 4 deletions Arrowgene.Ddon.GameServer/Characters/EquipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class EquipManager
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(EquipManager));

private static readonly List<EquipSlot> EnsembleSlots = new List<EquipSlot>()
public static readonly List<EquipSlot> EnsembleSlots = new List<EquipSlot>()
{
EquipSlot.ArmorLeg,
EquipSlot.ArmorHelm,
Expand Down Expand Up @@ -157,7 +157,7 @@ public void EquipJobItem(DdonGameServer server, GameClient client, CharacterComm

// Set in equipment template
//TODO: Move this lookup to memory instead of the DB if possible.
characterToEquipTo.EquipmentTemplate.SetEquipItem(server.Database.SelectStorageItemByUId(itemUId), characterToEquipTo.Job, equipType, equipSlot);
characterToEquipTo.EquipmentTemplate.SetEquipItem(server.Database.SelectStorageItemByUId(itemUId, connectionIn), characterToEquipTo.Job, equipType, equipSlot);

server.Database.ReplaceEquipItem(characterToEquipTo.CommonId, characterToEquipTo.Job, equipType, equipSlot, itemUId, connectionIn);

Expand Down Expand Up @@ -407,7 +407,5 @@ public uint CalculateItemRank(DdonGameServer server, CharacterCommon characterCo

return itemRank > 0 ? itemRank : 1;
}


}
}
8 changes: 4 additions & 4 deletions Arrowgene.Ddon.GameServer/Characters/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private List<CDataItemUpdateResult> SwapEquipmentAndStorage(GameClient client, C
}
else
{
throw ex;
throw;
}
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ private List<CDataItemUpdateResult> SwapEquipmentAndStorage(GameClient client, C
}
else
{
throw ex;
throw;
}
}
break;
Expand All @@ -249,7 +249,7 @@ private List<CDataItemUpdateResult> SwapEquipmentAndStorage(GameClient client, C
}
else
{
throw ex;
throw;
}
}
}
Expand All @@ -275,7 +275,7 @@ private List<CDataItemUpdateResult> SwapEquipmentAndStorage(GameClient client, C
}
else
{
throw ex;
throw;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Arrowgene.Ddon.GameServer/Characters/QuestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public static Quest GetQuestByScheduleId(uint questScheduleId)
{
if (!gQuests.ContainsKey(questScheduleId))
{
Logger.Error($"GetQuestByScheduleId: Invalid questScheduleId {questScheduleId}");
return null;
}

Expand Down
73 changes: 62 additions & 11 deletions Arrowgene.Ddon.GameServer/GameStructure.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Linq;
using System.Collections.Generic;
using Arrowgene.Ddon.GameServer.Characters;
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.GameServer.Characters;
using Arrowgene.Ddon.Server.Network;
using System.Collections.Generic;
using System.Linq;

namespace Arrowgene.Ddon.GameServer;

Expand Down Expand Up @@ -163,19 +162,71 @@ public static void CDataPawnInfo(CDataPawnInfo cDataPawnInfo, Pawn pawn)
cDataPawnInfo.SpSkillList = pawn.SpSkills.GetValueOrDefault(pawn.Job, new List<CDataSpSkill>());
}

public static void CDataNoraPawnInfo(CDataNoraPawnInfo cDataNoraPawnInfo, Pawn pawn)
public static void CDataNoraPawnInfo(CDataNoraPawnInfo cDataNoraPawnInfo, Pawn pawn, DdonGameServer server)
{
cDataNoraPawnInfo.Name = pawn.Name;
cDataNoraPawnInfo.EditInfo = pawn.EditInfo;
cDataNoraPawnInfo.Job = (byte)pawn.Job;
cDataNoraPawnInfo.CharacterEquipData = new() // TODO: ???

// Merge visual and performance equips
var performanceEquips = pawn.Equipment.GetItems(EquipType.Performance);
var visualEquips = pawn.Equipment.GetItems(EquipType.Visual);

List<ClientItemInfo> perfInfo = performanceEquips.Select(x => x is not null ? server.ItemManager.LookupInfoByItem(server, x) : new()).ToList();
List<ClientItemInfo> visualInfo = visualEquips.Select(x => x is not null ? server.ItemManager.LookupInfoByItem(server, x) : new()).ToList();

List<Item?> mergedEquips = new();
List<ClientItemInfo> mergedInfo = new();

for (int i = 0; i < visualEquips.Count; i++)
{
mergedEquips.Add(visualEquips[i] ?? performanceEquips[i]);
mergedInfo.Add(mergedEquips[i] is not null ? server.ItemManager.LookupInfoByItem(server, mergedEquips[i]) : new ClientItemInfo());
}

// Check for ensembles
bool overwriteBody = perfInfo.Any(x => x.SubCategory == ItemSubCategory.EquipEnsemble)
&& visualInfo.Any(x => x.EquipSlot is not null && EquipManager.EnsembleSlots.Contains((EquipSlot)x.EquipSlot));
bool overwriteOthers = visualInfo.Any(x => x.SubCategory == ItemSubCategory.EquipEnsemble);

if (overwriteBody && !overwriteOthers)
{
mergedEquips[(byte)EquipSlot.ArmorBody - 1] = null;
}
else if (overwriteOthers && !overwriteBody)
{
for (int i = 0; i < mergedInfo.Count; i++)
{
if (mergedInfo[i].EquipSlot is null) continue;
if (EquipManager.EnsembleSlots.Contains((EquipSlot)mergedInfo[i].EquipSlot))
{
mergedEquips[i] = null;
}
}
}

// Process to CDataEquipItemInfo
var mergedCData = mergedEquips.Select((item, index) => new CDataEquipItemInfo()
{
ItemId = item?.ItemId ?? 0,
Unk0 = item?.SafetySetting ?? 0,
EquipType = EquipType.Performance,
EquipSlot = (byte)(index + 1),
Color = item?.Color ?? 0,
PlusValue = item?.PlusValue ?? 0,
EquipElementParamList = item?.EquipElementParamList ?? new List<CDataEquipElementParam>(),
AddStatusParamList = item?.AddStatusParamList ?? new List<CDataAddStatusParam>(),
Unk2List = item?.Unk2List ?? new List<CDataEquipItemInfoUnk2>()
})
.ToList();


cDataNoraPawnInfo.CharacterEquipData = new()
{
new CDataCharacterEquipData() {
Equips = pawn.Equipment.AsCDataEquipItemInfo(EquipType.Performance)
Equips = mergedCData
},
new CDataCharacterEquipData() {
Equips = pawn.Equipment.AsCDataEquipItemInfo(EquipType.Visual)
}
new CDataCharacterEquipData() // The client expects a second element to this list, even if its not used.
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override S2CClanClanPartnerPawnDataGetRes Handle(GameClient client, C2SCl

res.PawnId = request.PawnId;

Pawn pawn = null;
Server.Database.ExecuteInTransaction(connection =>
{
uint ownerCharacterId = Server.Database.GetPawnOwnerCharacterId((uint)request.PawnId);
Expand All @@ -28,11 +29,11 @@ public override S2CClanClanPartnerPawnDataGetRes Handle(GameClient client, C2SCl
}

var ownerCharacter = Server.CharacterManager.SelectCharacter(ownerCharacterId);
Pawn pawn = ownerCharacter.Pawns.Find(x => x.PawnId == request.PawnId)
pawn = ownerCharacter.Pawns.Find(x => x.PawnId == request.PawnId)
?? throw new ResponseErrorException(ErrorCode.ERROR_CODE_PAWN_INVALID);
GameStructure.CDataNoraPawnInfo(res.PawnInfo, pawn);
});

GameStructure.CDataNoraPawnInfo(res.PawnInfo, pawn, Server);

return res;
}

Expand Down
12 changes: 4 additions & 8 deletions Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public override S2CInstanceEnemyKillRes Handle(GameClient client, C2SInstanceEne
}
};
client.Party.EnqueueToAll(repopNtc, queuedPackets);
//client.Send(repopNtc);
}
else
{
Expand Down Expand Up @@ -121,7 +120,6 @@ public override S2CInstanceEnemyKillRes Handle(GameClient client, C2SInstanceEne
IsAreaBoss = IsAreaBoss && (client.GameMode == GameMode.Normal)
};
client.Party.EnqueueToAll(groupDestroyedNtc, queuedPackets);
//client.Party.SendToAll(groupDestroyedNtc);

if (IsAreaBoss && client.GameMode == GameMode.BitterblackMaze)
{
Expand All @@ -142,7 +140,7 @@ public override S2CInstanceEnemyKillRes Handle(GameClient client, C2SInstanceEne
{
LayoutId = packet.LayoutId,
SetId = packet.SetId,
MdlType = enemyKilled.DropsTable.MdlType,
MdlType = enemyKilled.DropsTable?.MdlType ?? 0,
PosX = packet.DropPosX,
PosY = packet.DropPosY,
PosZ = packet.DropPosZ
Expand All @@ -169,14 +167,12 @@ public override S2CInstanceEnemyKillRes Handle(GameClient client, C2SInstanceEne
}

// If the roll was unlucky, there is a chance that no bag will show.
if (instancedGatheringItems.Where(x => x.ItemNum > 0).Any())
if (instancedGatheringItems.Any(x => x.ItemNum > 0))
{
partyMemberClient.Enqueue(dropItemNtc, queuedPackets);
//partyMemberClient.Send(dropItemNtc);
}
}


uint calcExp = _gameServer.ExpManager.GetAdjustedExp(client.GameMode, RewardSource.Enemy, client.Party, enemyKilled.GetDroppedExperience(), enemyKilled.Lv);
uint calcPP = (uint)(enemyKilled.GetDroppedPlayPoints() * _gameServer.Setting.GameLogicSetting.PpModifier);

Expand Down Expand Up @@ -223,13 +219,13 @@ public override S2CInstanceEnemyKillRes Handle(GameClient client, C2SInstanceEne
{
// Drop HO
uint gainedHo = (uint)(enemyKilled.HighOrbs * _gameServer.Setting.GameLogicSetting.HoModifier);
CDataUpdateWalletPoint hoUpdateWalletPoint = _gameServer.WalletManager.AddToWallet(memberClient.Character, WalletType.HighOrbs, gainedHo, connectionIn: connectionIn);
CDataUpdateWalletPoint hoUpdateWalletPoint = _gameServer.WalletManager.AddToWallet(memberClient.Character, WalletType.HighOrbs, gainedHo, connectionIn: connectionIn);
updateCharacterItemNtc.UpdateWalletList.Add(hoUpdateWalletPoint);
}

if (updateCharacterItemNtc.UpdateItemList.Count != 0 || updateCharacterItemNtc.UpdateWalletList.Count != 0)
{
memberClient.Enqueue(updateCharacterItemNtc, queuedPackets);
//memberClient.Send(updateCharacterItemNtc);
}

if (gainedPP > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void OnClientConnectionChangeEvent(object sender, ClientConnectionChange

private void NotifyDisconnect(GameClient client)
{
if(client.Character != null) {
if(client.Character != null && client.Character.Stage.Id != 0) {
// Notice all other users
S2CUserListLeaveNtc ntc = new S2CUserListLeaveNtc();
ntc.CharacterList.Add(new CDataCommonU32(client.Character.CharacterId));
Expand Down
15 changes: 4 additions & 11 deletions Arrowgene.Ddon.GameServer/Handler/QuestGetMainQuestListHandler.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
using Arrowgene.Ddon.GameServer.Characters;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Asset;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model.Quest;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using System.Dynamic;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class QuestGetMainQuestListHandler : PacketHandler<GameClient>
public class QuestGetMainQuestListHandler : GameRequestPacketHandler<C2SQuestGetMainQuestListReq, S2CQuestGetMainQuestListRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(QuestGetMainQuestListHandler));

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

public override PacketId Id => PacketId.C2S_QUEST_GET_MAIN_QUEST_LIST_REQ;

public override void Handle(GameClient client, IPacket packet)
public override S2CQuestGetMainQuestListRes Handle(GameClient client, C2SQuestGetMainQuestListReq request)
{
// client.Send(GameFull.Dump_123);

Expand All @@ -29,7 +22,7 @@ public override void Handle(GameClient client, IPacket packet)
foreach (var questId in client.Party.QuestState.GetActiveQuestScheduleIds())
{
var quest = client.Party.QuestState.GetQuest(questId);
if (quest.QuestType == QuestType.Main)
if (quest != null && quest.QuestType == QuestType.Main)
{
var questState = client.Party.QuestState.GetQuestState(questId);
res.MainQuestList.Add(quest.ToCDataQuestList(questState.Step));
Expand All @@ -44,7 +37,7 @@ public override void Handle(GameClient client, IPacket packet)
// res.MainQuestList.Add(Quest30270); // Those Who Follow the Dragon (White Dragon)
// res.MainQuestList.Add(Quest30410); // Japanese Name (Joseph Historian)

client.Send(res);
return res;
}
}
}
Loading

0 comments on commit a0236d2

Please sign in to comment.