add DlgAward

This commit is contained in:
MinhHai
2025-12-05 22:00:00 +07:00
parent 6faa7a7904
commit 9bc02e1fef
18 changed files with 3706 additions and 30 deletions
@@ -15,3 +15,5 @@ MonoBehaviour:
lstPrefabDialog:
- id: DialogNPC
prefab: {fileID: 8237288432181259026, guid: 7653e7e64393ec24c903f0606499b8c4, type: 3}
- id: Win_Award
prefab: {fileID: 903595479696773158, guid: cf26d96ae7d984ba8a5b6cef44adffeb, type: 3}
@@ -546,6 +546,7 @@ namespace BrewMonster.Scripts.Managers
/// This class intentionally keeps C++-style naming and layout so other C++ systems
/// can be ported over with minimal friction.
/// </summary>
/// TODO: have to rename to CECIvtrItem to match C++ naming
public class EC_IvtrItem
{
// NOTE: The nested enums and fields mirror the original C++ names and values.
@@ -1360,6 +1360,25 @@ namespace CSNetwork.GPDataType
Marshal.FreeHGlobal(ptr);
}
}
public static T FromBytes<T>(byte[] data, ref long startIndex) where T : struct
{
int size = Marshal.SizeOf<T>();
if (data.Length - startIndex < size)
throw new ArgumentException("Buffer không đủ dữ liệu");
IntPtr ptr = Marshal.AllocHGlobal(size);
try
{
Marshal.Copy(data, (int)startIndex, ptr, size);
startIndex += size;
return Marshal.PtrToStructure<T>(ptr);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}
public static bool ISPLAYERID(int id)
{
+278 -10
View File
@@ -4,6 +4,7 @@ using ModelRenderer.Scripts.GameData;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using CSNetwork.GPDataType;
using PerfectWorld.Scripts.Task;
using UnityEngine;
@@ -21,6 +22,16 @@ namespace BrewMonster.Scripts.Task
public const ulong TASK_PACK_MAGIC = 0x93858361;
public const ulong _task_templ_cur_version = 121;
private const int DYN_TASK_CUR_VERSION = 10;
private const int DYN_TASK_VERIFY_SVR = 8711;
private const int DYN_TASK_DELIVER_SVR = 8889;
private const int TASK_NPC_INFO_VERSION = 1;
private const int SEEK_SET = 0; /* set file offset to offset */
private const int SEEK_CUR = 1; /* set file offset to current plus offset */
private const int SEEK_END = 2; /* set file offset to EOF plus offset */
private ulong g_ulNewCount = 0;// do we need this? // MH: I think not, it look like a debug counter
private Dictionary<ulong, ATaskTempl> m_TaskTemplMap = new Dictionary<ulong, ATaskTempl>();
@@ -40,11 +51,22 @@ namespace BrewMonster.Scripts.Task
private List<ATaskTempl> m_SkillTaskLst = new List<ATaskTempl>();
private List<ATaskTempl> m_TmLmtChkLst = new List<ATaskTempl>();
private List<ATaskTempl> m_TasksCanSeekOut = new List<ATaskTempl>();
private elementdataman m_pEleDataMan;
// Dictionary<uint, ATaskTempl> m_DynTaskMap = new ();
uint m_ulDynTasksTimeMark;
byte[] m_pDynTasksData;
uint m_ulDynTasksDataSize;
byte[] m_pNPCInfoData;
uint m_ulNPCInfoDataSize;
uint m_ulNPCInfoTimeMark;
private Dictionary<uint, NPC_INFO> m_NPCInfoMap = new ();
#if _TASK_CLIENT
// char m_szDynPackPath[512];
private string m_szDynPackPath;
bool m_bDynTasksVerified;
protected special_award m_SpecialAward;
#endif
@@ -121,11 +143,17 @@ namespace BrewMonster.Scripts.Task
// //todo: check
// // LOG_DELETE_ARR(pOffs);
fs.Close();
// UpdateTimeLimitCheckList();
#if !_TASK_CLIENT
UpdateTimeLimitCheckList();
#else
SortTasksCanSeekOut();
#endif
#if _ELEMENTCLIENT
_task_err.Release();
_task_err.Init("Configs\\task_err.txt", true);
// TODO: implement task error logging if needed
// _task_err.Release();
// _task_err.Init("Configs\\task_err.txt", true);
#endif
return true;
@@ -151,11 +179,92 @@ namespace BrewMonster.Scripts.Task
}
public bool LoadNPCInfoFromPack(string szPath)
{
// TODO: Implement NPC info loading if needed
// FILE* fp = fopen(szPath, "rb");
FileStream fp = new FileStream(szPath, FileMode.Open, FileAccess.Read);
// if (fp == null)
// {
// TaskInterface::WriteLog(0, 0, 0, "LoadNPCInfoFromPack, no such file");
// return false;
// }
// fseek(fp, 0, SEEK_END);
// size_t sz = ftell(fp);
// fseek(fp, 0, SEEK_SET);
long sz = fp.Length;
if (sz == 0)
{
BMLogger.LogError("[ATaskTemplMan] LoadNPCInfoFromPack, file size is 0");
fp.Close();
return false;
}
long offset = 0;
byte[] buf = new Byte[sz];
g_ulNewCount++;
// fread(buf, 1, sz, fp);
buf = AAssit.ReadArrayFromBinary<byte>( fp, (int)sz, ref offset);
// fclose(fp);
fp.Close();
if (!UnmarshalNPCInfo(buf, (int)sz, false))
{
// LOG_DELETE_ARR(buf);
return false;
}
#if _TASK_CLIENT
// LOG_DELETE_ARR(buf);
#else
m_pNPCInfoData = buf;
m_ulNPCInfoDataSize = (uint)sz;
#endif
return true;
}
public void VerifyDynTasksPack(string szPath)
{
// TODO: Implement dynamic task pack verification if needed
// strcpy(m_szDynPackPath, szPath);
m_szDynPackPath = szPath;
// FILE* fp = fopen(szPath, "rb");
FileStream fp = new FileStream(szPath, FileMode.Open, FileAccess.Read);
// if (fp == NULL) return;
// C++
// fseek(fp, 0, SEEK_END);
// size_t sz = ftell(fp);
// fseek(fp, 0, SEEK_SET);
// C#
long offset = 0;
long sz = fp.Length;
int header_sz = Marshal.SizeOf<DYN_TASK_PACK_HEADER>();
if (sz < header_sz)
{
// fclose(fp);
fp.Close();
return;
}
// C++
// char* buf = new char[header_sz];
// g_ulNewCount++;
// fread(buf, 1, header_sz, fp);
// fclose(fp);
byte[] buf = new byte[header_sz];
g_ulNewCount++;
buf = AAssit.ReadArrayFromBinary<byte>(fp, header_sz, ref offset);
fp.Close();
UnmarshalDynTasks(buf, header_sz, true);
// LOG_DELETE_ARR(buf);
}
public ATaskTempl GetTopTaskByID(uint ulID)
@@ -241,7 +350,7 @@ namespace BrewMonster.Scripts.Task
pChild = pChild.m_pNextSibling;
}
}
#if !_TASK_CLIENT
void UpdateTimeLimitCheckList()
{
m_TmLmtChkLst.Clear();
@@ -255,7 +364,7 @@ namespace BrewMonster.Scripts.Task
}
}
#endif
public bool InitStorageTask()
{
m_StorageEssenseMap.Clear();
@@ -430,6 +539,40 @@ namespace BrewMonster.Scripts.Task
ATaskTempl._notify_svr(pTask, uReason, uTaskID);
}
static bool compare_tasks_canseekout( ATaskTempl lhs, ATaskTempl rhs)
{
if (lhs.m_FixedData.m_ulPremItems != 0 && rhs.m_FixedData.m_ulPremItems == 0) return true;
else if (lhs.m_FixedData.m_ulPremItems == 0 && rhs.m_FixedData.m_ulPremItems != 0) return false;
else if (lhs.m_FixedData.m_ulPremItems != 0 && rhs.m_FixedData.m_ulPremItems != 0) return lhs.m_FixedData.m_ID > rhs.m_FixedData.m_ID;
else return lhs.m_FixedData.m_ulPremise_Lev_Min > rhs.m_FixedData.m_ulPremise_Lev_Min;
}
/// <summary>
/// Comparator tương đương C++ version
/// </summary>
private static int CompareTasksCanSeekOut(ATaskTempl lhs, ATaskTempl rhs)
{
// Rule 1: Ưu tiên task có PremItems
bool lhsHasPrem = lhs.m_FixedData.m_ulPremItems != 0;
bool rhsHasPrem = rhs.m_FixedData.m_ulPremItems != 0;
if (lhsHasPrem && !rhsHasPrem) return -1; // lhs lên trước
if (!lhsHasPrem && rhsHasPrem) return 1; // rhs lên trước
// Rule 2: Nếu cả hai có PremItems → sắp theo ID giảm dần
if (lhsHasPrem && rhsHasPrem)
return rhs.m_FixedData.m_ID.CompareTo(lhs.m_FixedData.m_ID); // ID lớn đứng trước
// Rule 3: Nếu không có PremItems → LevelMin giảm dần
return rhs.m_FixedData.m_ulPremise_Lev_Min.CompareTo(lhs.m_FixedData.m_ulPremise_Lev_Min);
}
void SortTasksCanSeekOut()
{
// std::sort(m_TasksCanSeekOut.begin(), m_TasksCanSeekOut.end(), compare_tasks_canseekout);
m_TasksCanSeekOut.Sort(CompareTasksCanSeekOut);
}
public void CheckAutoDelv(TaskInterface pTask)
{
ATaskTempl pTempl = null;
@@ -488,13 +631,15 @@ namespace BrewMonster.Scripts.Task
}
// extarn from TaskServer
#endif
#if !_TASK_CLIENT
private void OnTaskGiveUpOneTask(TaskInterface pTask, uint ulTaskId, bool bForce)
{
TaskServer.OnTaskGiveUpOneTask(pTask, ulTaskId, bForce);
}
#endif
public void OnForgetLivingSkill(TaskInterface pTask)
{
// FinishedTaskList* pList = static_cast<FinishedTaskList*>(pTask->GetFinishedTaskList()); // C++
@@ -504,12 +649,12 @@ namespace BrewMonster.Scripts.Task
{
pList.RemoveTask(m_SkillTaskLst[i].GetID());
#if _TASK_CLIENT
#if !_TASK_CLIENT
OnTaskGiveUpOneTask(pTask, m_SkillTaskLst[i].GetID(), false);
#endif
}
#if _TASK_CLIENT
#if !_TASK_CLIENT
task_notify_base notify = new task_notify_base();
notify.reason = TaskTemplConstants.TASK_SVR_NOTIFY_FORGET_SKILL;
@@ -556,5 +701,128 @@ namespace BrewMonster.Scripts.Task
bool UpdateStorage(TaskInterface* pTask, StorageTaskList* pLst, unsigned long ulCurTime, unsigned long idStorage);
bool UpdateOneStorageDebug(TaskInterface* pTask, unsigned long ulCurTime, int idStorage, bool bUseDayAsSeed);
#endif
bool UnmarshalNPCInfo(byte[] data, int data_size, bool header_only)
{
if (data_size < Marshal.SizeOf<TASK_NPC_PACK_HEADER>())
{
// TaskInterface::WriteLog(0, 0, 0, "UnmarshalNPCInfo, wrong size");
BMLogger.LogError($" [ATaskTemplMan] UnmarshalNPCInfo, wrong size: {data_size} < {Marshal.SizeOf<TASK_NPC_PACK_HEADER>()}");
return false;
}
// const char* p = data;
// TASK_NPC_PACK_HEADER* header = (TASK_NPC_PACK_HEADER*)p;
// p += sizeof(TASK_NPC_PACK_HEADER);
TASK_NPC_PACK_HEADER header = GPDataTypeHelper.FromBytes<TASK_NPC_PACK_HEADER>(data);
var p = Marshal.SizeOf<TASK_NPC_PACK_HEADER>();
if (header.version != TASK_NPC_INFO_VERSION)
{
// TaskInterface::WriteLog(0, 0, 0, "UnmarshalNPCInfo, wrong version");
BMLogger.LogError($" [ATaskTemplMan] UnmarshalNPCInfo, wrong version: {header.version}");
return false;
}
if (header.pack_size != data_size)
{
// TaskInterface::WriteLog(0, 0, 0, "UnmarshalNPCInfo, wrong header");
BMLogger.LogError($" [ATaskTemplMan] UnmarshalNPCInfo, wrong header: pack_size {header.pack_size} != data_size {data_size}");
return false;
}
m_ulNPCInfoTimeMark = (uint)header.time_mark;
if (header_only)
return true;
// const NPC_INFO* pInfos = (const NPC_INFO*)p;
for (int i = 0; i < header.npc_count; i++)
{
// const NPC_INFO& info = pInfos[i];
// m_NPCInfoMap[info.id] = info;
NPC_INFO info = GPDataTypeHelper.FromBytes<NPC_INFO>(data, p);
p += Marshal.SizeOf<NPC_INFO>();
m_NPCInfoMap[info.id] = info;
}
return true;
}
bool UnmarshalDynTasks(byte[] data, int data_size, bool header_only)
{
if (data_size < Marshal.SizeOf<DYN_TASK_PACK_HEADER>())
{
// TaskInterface::WriteLog(0, 0, 0, "UnmarshalDynTasks, wrong size");
BMLogger.LogError(" [ATaskTemplMan] UnmarshalDynTasks, wrong size");
return false;
}
// C++
// const char* p = data;
// DYN_TASK_PACK_HEADER* header = (DYN_TASK_PACK_HEADER*)p;
// p += sizeof(DYN_TASK_PACK_HEADER);
DYN_TASK_PACK_HEADER header = GPDataTypeHelper.FromBytes<DYN_TASK_PACK_HEADER>(data);
long p = Marshal.SizeOf<DYN_TASK_PACK_HEADER>();
if (header.version != DYN_TASK_CUR_VERSION)
{
// TaskInterface::WriteLog(0, 0, 0, "UnmarshalDynTasks, wrong version");
BMLogger.LogError($" [ATaskTemplMan] UnmarshalDynTasks, wrong version: {header.version}");
return false;
}
if (header.pack_size != data_size)
{
// TaskInterface::WriteLog(0, 0, 0, "UnmarshalDynTasks, wrong header");
BMLogger.LogError($" [ATaskTemplMan] UnmarshalDynTasks, wrong header: pack_size {header.pack_size} != data_size {data_size}");
return false;
}
m_ulDynTasksTimeMark = (uint)header.time_mark;
if (header_only)
return true;
for (int i = 0; i < header.task_count; i++)
{
ATaskTempl pTempl = new ATaskTempl();
g_ulNewCount++;
pTempl.UnmarshalDynTask(data, ref p);
AddOneTaskTempl(pTempl);
// TaskInterface::WriteLog(0, pTempl->GetID(), 2, "LoadDynTask");
}
#if _TASK_CLIENT
SortTasksCanSeekOut();
#endif
// assert(p == data + data_size);
return true;
}
}
[ StructLayout(LayoutKind.Sequential, Pack = 1) ]
public struct TASK_NPC_PACK_HEADER
{
public uint pack_size;
public int time_mark;
public short version;
public short npc_count;
};
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DYN_TASK_PACK_HEADER
{
public uint pack_size;
public int time_mark;
public ushort version;
public ushort task_count;
};
}
@@ -2,6 +2,7 @@ using BrewMonster.Network;
using CSNetwork.GPDataType;
using PerfectWorld.Scripts.Task;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using CSNetwork;
using UnityEngine;
@@ -403,16 +404,19 @@ namespace BrewMonster.Scripts.Task
}
else
{
//string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
//pTaskMan.LoadTasksFromPack(task_data_path, true);
string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
pTaskMan.LoadTasksFromPack(task_data_path, true);
}
#else
string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
pTaskMan.LoadTasksFromPack(task_data_path, true);
#endif
var task_npc_path = Path.Combine(Application.streamingAssetsPath, "data/task_npc.data");
pTaskMan.LoadNPCInfoFromPack(task_npc_path);
var dyn_tasks_path = Path.Combine(Application.streamingAssetsPath, "data/dyn_tasks.data");
pTaskMan.VerifyDynTasksPack(dyn_tasks_path);
pTaskMan.LoadNPCInfoFromPack("data\\task_npc.data");
pTaskMan.VerifyDynTasksPack("userdata\\dyn_tasks.data");
InitActiveTaskList();
m_bForceNavigateFinish = false;
@@ -711,9 +715,8 @@ namespace BrewMonster.Scripts.Task
else
entry.m_ulTemplAddr = 0;
}
#if _TASK_CLIENT
#if !_TASK_CLIENT
#elif _TASK_CLIENT
// if (entry.m_ulTemplAddr != 0)
// {
@@ -747,9 +750,8 @@ namespace BrewMonster.Scripts.Task
else
entry.m_ulCapTemplAddr = 0;
#if _TASK_CLIENT
#if !_TASK_CLIENT
#else
// if (bTimeMarkUpdated != 0)
// {
@@ -760,8 +762,7 @@ namespace BrewMonster.Scripts.Task
// }
#endif
#if _TASK_CLIENT
#elif _TASK_CLIENT
#if !_TASK_CLIENT
// ʼеءʾ
// if (entry.m_ParentIndex == 0xff)
// {
@@ -776,8 +777,7 @@ namespace BrewMonster.Scripts.Task
i1++;
}
#if _TASK_CLIENT
#elif _TASK_CLIENT
#if !_TASK_CLIENT
// pLst->SetTimeMarkUpdate();
// pLst->UpdateTaskMask(*GetTaskMask());
#endif
@@ -1244,6 +1244,7 @@ namespace BrewMonster.Scripts.Task
// }
}
#endif
@@ -442,6 +442,7 @@ namespace BrewMonster.Scripts.Task
// ȥõƷ
#if _TASK_CLIENT
#else
if (bRemoveItem && pTempl != null)
{
if (bRemoveAcquired || pTempl.m_FixedData.m_bClearAcquired) pTempl.RemoveAcquiredItem(pTask, bClearTask, false);
+678 -6
View File
@@ -1432,6 +1432,9 @@ namespace BrewMonster.Scripts.Task
/* °´»ñµÃÎï±ÈÀý·½Ê½ */
AWARD_ITEMS_SCALE m_AwByItems_S;
AWARD_ITEMS_SCALE m_AwByItems_F;
uint g_ulNewCount = 0;
public bool LoadFromBinFile(FileStream fp)
{
LoadBinary(fp);
@@ -1644,12 +1647,13 @@ namespace BrewMonster.Scripts.Task
LoadTributeBin(fp);
pointerLog += $" After LoadTributeBin : {fp.Position}\n";
// TODO: Check task type consistency
# if _TASK_CLIENT
CheckMask();
#else
SyncTaskType();
#endif
// Check task type consistency
# if _TASK_CLIENT
SyncTaskType();
#else
CheckMask();
#endif
// namechar code = (namechar)m_ID;
@@ -4365,5 +4369,673 @@ namespace BrewMonster.Scripts.Task
return true;
}
public uint GetType() { return m_FixedData.m_ulType; }
void Init()
{
m_FixedData.m_bCanRedo = true;
m_FixedData.m_bParentAlsoFail = true;
m_FixedData.m_bCanGiveUp = true;
m_FixedData.m_bCanRedoAfterFailure = true;
m_FixedData.m_bClearAcquired = true;
m_FixedData.m_enumMethod = (uint)TaskCompletionMethod.enumTMNone;
m_FixedData.m_enumFinishType = (uint)TaskFinishType.enumTFTDirect;
m_FixedData.m_bShowByDeposit = true;
m_FixedData.m_bShowByGender = true;
m_FixedData.m_bShowByItems = true;
m_FixedData.m_bShowByFactionContrib = true;
m_FixedData.m_bShowByNeedRecordTasksNum = true;
m_FixedData.m_bShowByLev = true;
m_FixedData.m_bShowByOccup = true;
m_FixedData.m_bShowByPreTask = true;
m_FixedData.m_bShowByRepu = true;
m_FixedData.m_bShowByTeam = true;
m_FixedData.m_bShowByFaction = true;
m_FixedData.m_bShowByPeriod = true;
m_FixedData.m_bShowPrompt = true;
m_FixedData.m_bShowByCharTime = true;
m_FixedData.m_bShowByRMB = true;
m_FixedData.m_bShowBySpouse = true;
m_FixedData.m_bShowByWeddingOwner = true;
m_FixedData.m_bShowByKing = true;
m_FixedData.m_bShowByNotInTeam = true;
m_FixedData.m_bShowByGeneralCard = true;
m_FixedData.m_ulDelvWorld = 1;
m_FixedData.m_ulTransWldId = 1;
m_FixedData.m_ulReachSiteId = 1;
m_FixedData.m_lPeriodLimit = 1;
m_FixedData.m_bCanSeekOut = false;
m_FixedData.m_bShowDirection = true;
m_FixedData.m_bDeliverySkill = false; // verison 77
m_FixedData.m_iDeliveredSkillID = 0;
m_FixedData.m_iDeliveredSkillLevel = 0;
m_FixedData.m_bShowGfxFinished = false; // version 78
m_FixedData.m_bChangePQRanking = false; // version 79. Ĭ PQ ı
m_FixedData.m_bDisplayInExclusiveUI = false;
m_FixedData.m_bReadyToNotifyServer = false;
m_FixedData.m_bDistinguishedOcc = false;
m_FixedData.m_bUsedInTokenShop = false;
m_FixedData.m_iPremise_FactionRole = 6;
m_FixedData.m_TreasureStartZone.x = 0;
m_FixedData.m_TreasureStartZone.y = 0;
m_FixedData.m_TreasureStartZone.z = 0;
m_FixedData.m_ucZonesNumX = 1;
m_FixedData.m_ucZonesNumZ = 1;
m_FixedData.m_ucZoneSide = 10;
m_FixedData.m_ucPremiseTransformedForm = 0xFF;
m_FixedData.m_bShowByForce = true;
m_FixedData.m_bShowByForceContribution = true;
m_FixedData.m_bShowByForceReputation = true;
m_FixedData.m_bShowByForceExp = true;
m_FixedData.m_bShowByForceSP = true;
m_FixedData.m_bShowByForceActivityLevel = true;
m_FixedData.m_bShowByReincarnation = true;
m_FixedData.m_bShowByRealmLevel = true;
m_FixedData.m_bShowByGeneralCardRank = true;
m_FixedData.m_bShowByHistoryStage = true;
m_FixedData.m_iPremForceActivityLevel = -1;
m_FixedData.m_iPremGeneralCardRank = -1;
}
void UnmarshalSpecialAwardData(byte[] data, ref long p)
{
// const char* p = pData;
// m_ulSpecialAward = *(long*)p;
// p += sizeof(long);
m_FixedData.m_ulSpecialAward = GPDataTypeHelper.FromBytes<uint>(data, ref p);
// return p - pData;
}
void UnmarshalKillMonster(byte[] data, ref long p)
// int ATaskTempl::UnmarshalKillMonster(const char* pData)
{
// const char* p = pData;
m_FixedData.m_ulMonsterWanted = GPDataTypeHelper.FromBytes<byte>(data, ref p);
#if !TASK_TEMPL_EDITOR
if (m_FixedData.m_ulMonsterWanted != 0)
{
m_FixedData.m_MonsterWanted = new MONSTER_WANTED[m_FixedData.m_ulMonsterWanted];
g_ulNewCount++;
}
#endif
int sz = (int)(m_FixedData.m_ulMonsterWanted * Marshal.SizeOf<MONSTER_WANTED>());
if (sz != 0)
{
// memcpy(m_FixedData.m_MonsterWanted, p, sz);
for( int i = 0; i < m_FixedData.m_MonsterWanted.Length; i++)
{
m_FixedData.m_MonsterWanted[i] = GPDataTypeHelper.FromBytes<MONSTER_WANTED>(data, ref p);
}
}
// return p - pData;
}
void UnmarshalCollectItems(byte[] data, ref long p)
// int ATaskTempl::UnmarshalCollectItems(const char* pData)
{
// const char* p = pData;
m_FixedData.m_ulItemsWanted = GPDataTypeHelper.FromBytes<byte>(data, ref p);
if (m_FixedData.m_ulItemsWanted != 0)
{
#if !TASK_TEMPL_EDITOR
m_FixedData.m_ItemsWanted = new ITEM_WANTED[m_FixedData.m_ulItemsWanted];
g_ulNewCount++;
#endif
int sz = (int)(m_FixedData.m_ulItemsWanted * Marshal.SizeOf<ITEM_WANTED>());
// memcpy(m_FixedData.m_ItemsWanted, p, sz);
// p += sz;
for( int i = 0; i < m_FixedData.m_ItemsWanted.Length; i++)
{
m_FixedData.m_ItemsWanted[i] = GPDataTypeHelper.FromBytes<ITEM_WANTED>(data, ref p);
}
}
m_FixedData.m_ulGoldWanted = GPDataTypeHelper.FromBytes<uint>(data, ref p);
m_FixedData.m_iFactionContribWanted = GPDataTypeHelper.FromBytes<int>(data, ref p);
m_FixedData.m_iFactionExpContribWanted = GPDataTypeHelper.FromBytes<int>(data, ref p);
// return p - pData;
}
void unmarshal_str(byte[] data, ushort[] s, ref long p)
// inline int unmarshal_str(const char* data, task_char*& s)
{
// const char* p = data;
int len = GPDataTypeHelper.FromBytes<int>( data, ref p);
s = new ushort[len + 1];
g_ulNewCount++;
s[len] = 0;
if (len != 0)
{
// len *= sizeof(task_char);
// memcpy(s, p, len);
// p += len;
for (int i = 0; i < len; i++)
{
s[i] = GPDataTypeHelper.FromBytes<ushort>(data, ref p);
}
}
// return p - data;
}
void unmarshal_option(ref talk_proc.option opt, byte[] data, ref long p)
// int unmarshal_option(talk_proc::option* opt, const char* data)
{
// const char* p = data;
opt.id = GPDataTypeHelper.FromBytes<uint>( data, ref p);
opt.param = GPDataTypeHelper.FromBytes<uint>(data, ref p);
uint sz = GPDataTypeHelper.FromBytes<uint>(data, ref p);
if (sz != 0)
{
// memcpy(opt->text, p, sz);
// p += sz;
opt.text = new ushort[sz / sizeof(ushort)];
for (int i = 0; i < opt.text.Length; i++)
{
opt.text[i] = GPDataTypeHelper.FromBytes<ushort>(data, ref p);
}
}
// return p - data;
}
void unmarshal_window(ref talk_proc.window win, byte[] data, ref long p)
// int unmarshal_window(talk_proc::window* win, const char* data)
{
// const char* p = data;
win.id = GPDataTypeHelper.FromBytes<byte>(data, ref p);
win.id_parent = GPDataTypeHelper.FromBytes<byte>(data, ref p);
win.talk_text_len = GPDataTypeHelper.FromBytes<int>(data, ref p);
if (win.talk_text_len != 0)
{
// C++
// win->talk_text = new namechar[win->talk_text_len];
// size_t sz = sizeof(namechar) * win->talk_text_len;
// memcpy(win->talk_text, p, sz);
// p += sz;
// g_ulNewCount++;
win.talk_text = new ushort[win.talk_text_len];
for (int i = 0; i < win.talk_text_len; i++)
{
win.talk_text[i] = GPDataTypeHelper.FromBytes<ushort>(data, ref p);
}
g_ulNewCount++;
}
win.num_option = GPDataTypeHelper.FromBytes<byte>( data, ref p);
if (win.num_option != 0)
{
// C++
// win->options = new talk_proc::option[win->num_option];
// memset(win->options, 0, sizeof(talk_proc::option) * win->num_option);
// g_ulNewCount++;
//
// for (int i = 0; i < win->num_option; i++)
// p += unmarshal_option(&win->options[i], p);
win.options = new talk_proc.option[win.num_option];
g_ulNewCount++;
for (int i = 0; i < win.num_option; i++)
{
win.options[i] = new talk_proc.option();
unmarshal_option(ref win.options[i], data, ref p);
}
}
// return p - data;
}
void unmarshal_talk_proc(ref talk_proc talk, byte[] data, ref long p)
// int unmarshal_talk_proc(talk_proc* talk, const char* data)
{
// const char* p = data;
int sz = GPDataTypeHelper.FromBytes<int>(data, ref p);
if (sz != 0)
{
// memcpy(talk->text, p, sz);
// p += sz;
for( int i = 0; i < talk.text.Length; i++)
{
talk.text[i] = GPDataTypeHelper.FromBytes<ushort>(data, ref p);
}
}
talk.num_window = GPDataTypeHelper.FromBytes<byte>(data, ref p);
if (talk.num_window != 0)
{
// C++
// talk->windows = new talk_proc::window[talk->num_window];
// memset(talk->windows, 0, sizeof(talk_proc::window) * talk->num_window);
// g_ulNewCount++;
//
// for (int i = 0; i < talk->num_window; i++)
// p += unmarshal_window(&talk->windows[i], p);
talk.windows = new talk_proc.window[talk.num_window];
g_ulNewCount++;
for (int i = 0; i < talk.num_window; i++)
{
talk.windows[i] = new talk_proc.window();
unmarshal_window(ref talk.windows[i], data, ref p);
}
}
// return p - data;
}
public void UnmarshalDynTask(byte[] pData, ref long p)
{
Init();
// const char* p = pData;
// int p = 0;
uint token_mask1, token_mask2;
token_mask1 = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
token_mask2 = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
int token_count = 0;
// dyn type
m_FixedData.m_DynTaskType = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
// top task
if (m_pParent == null)
{
switch (m_FixedData.m_DynTaskType)
{
case (byte)DynTaskType.enumDTTSpecialAward:
break;
case (byte)DynTaskType.enumDTTGiftCard:
UnmarshalSpecialAwardData(pData, ref p);
break;
default:
break;
}
}
// id
m_FixedData.m_ID = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
// name
// char len = *p; p++;
// len *= sizeof(task_char);
// memcpy(m_szName, p, len);
// p += len;
byte nameLen = pData[p++];
// int nameByteLen = nameLen * sizeof(ushort);
m_FixedData.m_szName = new ushort[nameLen];
for (int i = 0; i < nameLen; i++)
{
m_FixedData.m_szName[i] = GPDataTypeHelper.FromBytes<ushort>(pData, ref p);
}
// choose one
m_FixedData.m_bChooseOne = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// rand one
m_FixedData.m_bRandOne = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// in order
m_FixedData.m_bExeChildInOrder = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// parent fail
m_FixedData.m_bParentAlsoFail = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// parent succ
m_FixedData.m_bParentAlsoSucc = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// give up
m_FixedData.m_bCanGiveUp = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// redo
m_FixedData.m_bCanRedo = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// redo after fail
m_FixedData.m_bCanRedoAfterFailure = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// clear as give up
m_FixedData.m_bClearAsGiveUp = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// record
m_FixedData.m_bNeedRecord = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// die
m_FixedData.m_bFailAsPlayerDie = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// auto deliver
m_FixedData.m_bAutoDeliver = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// death trig
m_FixedData.m_bDeathTrig = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// clear acquired
m_FixedData.m_bClearAcquired = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// spouse
m_FixedData.m_bPremise_Spouse = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// teamwork
m_FixedData.m_bTeamwork = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// direction
m_FixedData.m_bShowDirection = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
// level
m_FixedData.m_ulPremise_Lev_Min = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
m_FixedData.m_ulPremise_Lev_Max = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
// 0: time limit
if (((1 << token_count++) & token_mask1) != 0)
{
m_ulTimeLimit = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
}
// 1: reputation
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_lPremise_Reputation = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
}
// 2: period
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulPremise_Period = GPDataTypeHelper.FromBytes<ushort>(pData, ref p);
}
// 3: prem items
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulPremItems = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
#if !TASK_TEMPL_EDITOR
m_FixedData.m_PremItems = new ITEM_WANTED[m_FixedData.m_ulPremItems];
g_ulNewCount++;
#endif
int sz = (int)(m_FixedData.m_ulPremItems * Marshal.SizeOf<ITEM_WANTED>());
// memcpy(m_PremItems, p, sz);
Array.Copy( pData, p, m_FixedData.m_PremItems, 0, sz );
p += sz;
}
// 4: delv in zone
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_bDelvInZone = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
m_FixedData.m_ulDelvWorld = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
m_FixedData.m_ulDelvRegionCnt = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
for (int i=0; i< m_FixedData.m_ulDelvRegionCnt; i++)
{
m_FixedData.m_pDelvRegion[i] = GPDataTypeHelper.FromBytes<Task_Region>(pData, ref p);
}
/* m_DelvMinVert = *(ZONE_VERT*)p;
p += sizeof(ZONE_VERT);
m_DelvMaxVert = *(ZONE_VERT*)p;
p += sizeof(ZONE_VERT);*/
}
// 5: trans to
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_bTransTo = GPDataTypeHelper.FromBytes<byte>(pData, ref p) != 0;
m_FixedData.m_ulTransWldId = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
m_FixedData.m_TransPt = GPDataTypeHelper.FromBytes<ZONE_VERT>(pData, ref p);
}
// 6: given items
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulGivenItems =GPDataTypeHelper.FromBytes<byte>(pData, ref p);
m_FixedData.m_ulGivenCmnCount = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
m_FixedData.m_ulGivenTskCount = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
#if !TASK_TEMPL_EDITOR
m_FixedData.m_GivenItems = new ITEM_WANTED[m_FixedData.m_ulGivenItems];
g_ulNewCount++;
#endif
int sz = (int)(m_FixedData.m_ulGivenItems * Marshal.SizeOf<ITEM_WANTED>());
// memcpy(m_GivenItems, p, sz);
Array.Copy( pData, p, m_FixedData.m_GivenItems, 0, sz );
p += sz;
}
// 7: deposit
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulPremise_Deposit = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
}
// 8: pre task
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulPremise_Task_Count = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
m_FixedData.m_ulPremise_Task_Least_Num = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
int sz = (int)(4 * m_FixedData.m_ulPremise_Task_Count);
// memcpy(m_ulPremise_Tasks, p, sz);
for (int i = 0; i < m_FixedData.m_ulPremise_Task_Count; i++)
{
m_FixedData.m_ulPremise_Tasks[i] = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
}
}
// 9: gender
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulGender = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
}
// 10: occupation
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulOccupations = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
int sz = (int)(m_FixedData.m_ulOccupations * Marshal.SizeOf<uint>());
for (int i = 0; i < m_FixedData.m_ulOccupations; i++)
{
m_FixedData.m_Occupations[i] = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
}
}
// 11: mutex task
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulMutexTaskCount = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
int sz = (int)(Marshal.SizeOf<uint>() * m_FixedData.m_ulMutexTaskCount);
// memcpy(m_ulMutexTasks, p, sz);
for( int i = 0; i < m_FixedData.m_ulMutexTaskCount; i++ )
{
m_FixedData.m_ulMutexTasks[i] = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
}
}
// 12: time table
if (((1 << token_count++) & token_mask1) != 0)
{
m_FixedData.m_ulTimetable = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
#if !TASK_TEMPL_EDITOR
m_FixedData.m_tmStart = new task_tm[m_FixedData.m_ulTimetable];
g_ulNewCount++;
m_FixedData.m_tmEnd = new task_tm[m_FixedData.m_ulTimetable];
g_ulNewCount++;
#endif
int sz=0;
sz = (int)(sizeof(byte) * m_FixedData.m_ulTimetable);
// memcpy(m_tmType, p, sz);
Array.Copy( pData, p, m_FixedData.m_tmType, 0, sz );
p += sz;
sz = (int)(Marshal.SizeOf<task_tm>() * m_FixedData.m_ulTimetable);
// memcpy(m_tmStart, p, sz);
// p += sz;
for (int i = 0; i < m_FixedData.m_ulTimetable; i++)
{
m_FixedData.m_tmStart[i] = GPDataTypeHelper.FromBytes<task_tm>(pData, ref p);
}
// memcpy(m_tmEnd, p, sz);
// p += sz;
for (int i = 0; i < m_FixedData.m_ulTimetable; i++)
{
m_FixedData.m_tmEnd[i] = GPDataTypeHelper.FromBytes<task_tm>(pData, ref p);
}
}
// method
m_FixedData.m_enumMethod = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
switch (m_FixedData.m_enumMethod)
{
case (uint)TaskCompletionMethod.enumTMKillNumMonster:
// p += UnmarshalKillMonster(p);
UnmarshalKillMonster( pData, ref p);
break;
case (uint)TaskCompletionMethod.enumTMCollectNumArticle:
// p += UnmarshalCollectItems(p);
UnmarshalCollectItems(data:pData, ref p);
break;
case (uint)TaskCompletionMethod.enumTMReachSite:
m_FixedData.m_ulReachSiteId = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
// C++
// memcpy(m_pReachSite, p, sizeof(Task_Region)*m_ulReachSiteCnt);
// p += sizeof(Task_Region)*m_ulReachSiteCnt;
for (int i = 0; i < m_FixedData.m_ulReachSiteId; i++)
{
m_FixedData.m_pReachSite[i] = GPDataTypeHelper.FromBytes<Task_Region>(pData, ref p);
}
// memcpy(&m_ReachSiteMax, p, sizeof(ZONE_VERT));
// p += sizeof(ZONE_VERT);
break;
case (uint)TaskCompletionMethod.enumTMLeaveSite:
m_FixedData.m_ulLeaveSiteId = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
// memcpy(m_pLeaveSite, p, sizeof(Task_Region)*m_ulLeaveSiteCnt);
// p += sizeof(ZONE_VERT);
for (int i = 0; i < m_FixedData.m_ulLeaveSiteId; i++)
{
m_FixedData.m_pLeaveSite[i] = GPDataTypeHelper.FromBytes<Task_Region>(pData, ref p);
}
// memcpy(&m_LeaveSiteMax, p, sizeof(ZONE_VERT));
// p += sizeof(ZONE_VERT);
break;
case (uint)TaskCompletionMethod.enumTMWaitTime:
m_FixedData.m_ulWaitTime = GPDataTypeHelper.FromBytes<uint>(pData, ref p);
break;
}
// finish type
m_FixedData.m_enumFinishType = GPDataTypeHelper.FromBytes<byte>(pData, ref p);
p++;
// award
byte[] award_byte_copy = new byte[pData.Length];
Array.Copy( pData, p, award_byte_copy, 0, pData.Length - p );
p += m_Award_S.UnmarshalBasicData(pData);
// talks
unmarshal_str(pData, m_pwstrDescript, ref p);
unmarshal_str(pData, m_pwstrOkText, ref p);
unmarshal_str(pData, m_pwstrNoText, ref p);
unmarshal_talk_proc(ref m_DelvTaskTalk, pData, ref p);
unmarshal_talk_proc(ref m_UnqualifiedTalk, pData, ref p);
unmarshal_talk_proc(ref m_DelvItemTalk, pData, ref p);
unmarshal_talk_proc(ref m_ExeTalk, pData, ref p);
unmarshal_talk_proc(ref m_AwardTalk, pData, ref p);
#if !_TASK_CLIENT
CheckMask();
#else
SyncTaskType();
#endif
m_nSubCount = GPDataTypeHelper.FromBytes<int>( pData, ref p);
for (int i = 0; i < m_nSubCount; i++)
{
// ATaskTempl* pSub = new ATaskTempl;
// g_ulNewCount++;
// AddSubTaskTempl(pSub);
// p += pSub->UnmarshalDynTask(p);
ATaskTempl pSub = new ATaskTempl();
g_ulNewCount++;
AddSubTaskTempl( pSub );
pSub.UnmarshalDynTask( pData , ref p);
}
SynchID();
if (m_pParent == null) CheckDepth();
// return p - pData;
}
}
}
@@ -4,6 +4,7 @@ using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using BrewMonster.Scripts.Task.UI;
using CSNetwork.Common;
using ModelRenderer.Scripts.Common;
using PerfectWorld.Scripts.Task;
using UnityEngine;
@@ -32,6 +33,12 @@ namespace BrewMonster.Scripts.Task
#endif
}
[ContextMenu("Test Npc Service Log")]
public void LogNpcService()
{
Debug.Log($" idFun = {(ExpTypes.SERVICE_TYPE)(-2147483641)} | idService = {44515} ");
}
[ContextMenu("Show Task Name")]
public void ShowTaskName()
{
@@ -262,6 +262,23 @@ namespace BrewMonster.UI
{
return dlg;
}
else
{
var prefab = m_dialogResouce.GetPrefabDialog(pszName);
if(prefab != null)
{
var instance = GameObject.Instantiate(prefab, m_canvas.transform);
var dialog = instance.GetComponent<AUIDialog>();
if (dialog != null)
{
dialog.SetAUIManager(this);
m_DlgName[pszName] = dialog;
return dialog;
}
}
}
return null;
}
}
@@ -17,6 +17,7 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using BrewMonster.Scripts.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -2826,6 +2827,7 @@ namespace BrewMonster.UI
}
else if (idFunction == (int)SERVICE_TYPE.NPC_MAKE)
{
// C++
//NPC_MAKE_SERVICE pMake = (NPC_MAKE_SERVICE)pData;
//if (pMake.produce_type == 2)
// pShow1 = m_pAUIManager.GetDialog("Win_Produce1");
@@ -2841,6 +2843,22 @@ namespace BrewMonster.UI
// GetGameUIMan().m_pDlgProduce.ClearMaterial();
//pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
//GetGameUIMan().m_pDlgProduce.UpdateProduce(1, 0);
// NPC_MAKE_SERVICE pMake = (NPC_MAKE_SERVICE)pData;
// if (pMake.produce_type == 2)
// pShow1 = m_pAUIManager.GetDialog("Win_Produce1");
// else
// pShow1 = m_pAUIManager.GetDialog("Win_Produce");
// GetGameUIMan().m_pDlgProduce = (CDlgProduce*)pShow1;
// GetHostPlayer().PrepareNPCService(iService);
// pShow1.SetDataPtr(pMake, "ptr_NPC_MAKE_SERVICE");
// if (pMake.produce_type == 1 ||
// pMake.produce_type == 3 ||
// pMake.produce_type == 4 ||
// pMake.produce_type == 5)
// GetGameUIMan().m_pDlgProduce.ClearMaterial();
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// GetGameUIMan().m_pDlgProduce.UpdateProduce(1, 0);
}
else if (idFunction == (int)SERVICE_TYPE.NPC_DECOMPOSE)
{
@@ -2970,8 +2988,8 @@ namespace BrewMonster.UI
if (ad.m_ulCandItems > 1)
{
pShow1 = m_pAUIManager.GetDialog("Win_Award");
//CDlgAward pAward = (pShow1) as CDlgAward;
//if (pAward) pAward.UpdateAwardItem(opt.param, true);
CDlgAward pAward = (pShow1) as CDlgAward;
if (pAward) pAward.UpdateAwardItem((ushort)opt.param, true);
}
else
{
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e3a8de291089473f9d21a99f27014a68
timeCreated: 1764934713
@@ -0,0 +1,52 @@
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster.Scripts.UI
{
public class AwardItem : MonoBehaviour
{
[SerializeField] private Image img;
[SerializeField] private Button btn;
private Vector2Int _position;
public Vector2Int Position => _position;
public void SetPositionIndex(int row, int column)
{
_position = new Vector2Int(row, column);
this.gameObject.name = "Item_" + row + "_" + column;
}
public void SetImage(Sprite sprite)
{
img.sprite = sprite;
}
public void SetText(string text)
{
// TODO: Add a Text component and set its text
}
public void SetColor(Color color)
{
// TODO : Set color to relevant UI components
}
public void SetHint(string text)
{
// TODO : Implement hint functionality
}
public void ClearCover()
{
// TODO : Implement cover clearing functionality
}
public void Show(bool show)
{
gameObject.SetActive(show);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9d87c7b8ac564f919171a5173812980e
timeCreated: 1764940671
@@ -0,0 +1,304 @@
using BrewMonster.Scripts.Managers;
using BrewMonster.Scripts.Task;
using BrewMonster.UI;
using PerfectWorld.Scripts.Managers;
using PerfectWorld.Scripts.Task;
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster.Scripts.UI
{
public class CDlgAward : AUIDialog
{
#region FIELDS AND PROPERTIES
private const int MIN_ROW_COUNT_TO_SHOW = 6;
[SerializeField] private Button m_pBtn_Confirm;
[SerializeField] private Vector2Int _itemSize = new Vector2Int(50, 50);
[SerializeField] private AwardItem _awardItemPrefab;
[SerializeField] private Toggle[] _radioButtons;
[Header("DEBUG")]
[SerializeField] private AwardItem[] _awardItems;
bool m_bThroughNPC;
bool m_bSpendContribution;
#endregion
int _rowCount => _itemSize.x;
int _columnCount => _itemSize.y;
#region UNITY METHODS
void Awake()
{
SpawnItems();
}
private void SpawnItems()
{
for (int i = 1; i <= _rowCount; i++)
{
for (int j = 1; j <= _columnCount; j++)
{
AwardItem item = Instantiate(_awardItemPrefab, this.transform);
item.SetPositionIndex(i, j);
// Positioning logic can be added here
}
}
_awardItemPrefab.gameObject.SetActive(false);
}
#endregion
protected bool OnInitDialog()
{
m_bThroughNPC = false;
m_bSpendContribution = false;
return true;
}
public void UpdateAwardItem(ushort idTask, bool throughNPC, bool spendContribution = false)
{
AWARD_DATA ad = new AWARD_DATA();
CECTaskInterface pTask = GetHostPlayer().GetTaskInterface();
m_bThroughNPC = throughNPC;
m_bSpendContribution = spendContribution;
pTask.GetAwardCandidates(idTask, ref ad);
if (ad.m_ulCandItems > 1)
{
string szName;
string strFile = "";
string szText;
EC_IvtrItem pItem;
// AUICTranslate trans; // TODO
// int i, j, idItem, nNum;
uint idItem, nNum;
// Image pImage;
// Image pImage2;
AwardItem pImage; // Using AwardItem instead of Image
SetData(idTask, "");
// CheckRadioButton(1, 0); // TODO:
// GetDlgItem("Btn_Confirm")->Enable(false);
for (int i=1; i < _rowCount; i++)
{
// sprintf(out szName, "Item_%02d01", i);
// pImage = (PAUIIMAGEPICTURE)GetDlgItem(szName);
// if (!pImage) break; // All done.
// TODO: Show/Hide radio button
// sprintf(out szName, "Rdo_Award%d", i);
// GetDlgItem(szName)->Show(false);
_radioButtons[i].gameObject.SetActive(false);
// for (j = 1;; j++)
for (int j=1; j < _columnCount; j++)
{
// sprintf(out szName, "Item_%02d%02d", i, j);
// pImage = (PAUIIMAGEPICTURE)GetDlgItem(szName);
// if (!pImage) break; // Line done.
pImage = GetAwardItemAt(i, j);
if(!pImage) break;
if (i - 1 < (int)ad.m_ulCandItems &&
j - 1 < (int)ad.m_CandItems[i - 1].m_ulAwardItems)
{
idItem = ad.m_CandItems[i - 1].m_AwardItems[j - 1].m_ulItemTemplId;
pItem = EC_IvtrItem.CreateItem((int)idItem, 0, 1);
nNum = ad.m_CandItems[i - 1].m_AwardItems[j - 1].m_ulItemNum;
if (nNum > 1)
{
a_sprintf(out szText, _AL("%d"), nNum);
pImage.SetText(szText);
}
else
pImage.SetText(_AL(""));
pItem.GetDetailDataFromLocal();
// pImage.SetHint(trans.Translate(pItem.GetDesc())); // TODO
// af_GetFileTitle(pItem.GetIconFile(), strFile); // TODO
strFile.ToLower();
// TODO: Set the image cover here
// pImage.SetCover(GetGameUIMan().m_pA2DSpriteIcons[CECGameUIMan::ICONS_INVENTORY],
// GetGameUIMan().m_IconMap[CECGameUIMan::ICONS_INVENTORY][strFile]);
EC_IvtrEquip pEquip = new EC_IvtrEquip(pItem.m_tid, pItem.m_expire_date);
pImage.SetColor(
(pItem.IsEquipment() && pEquip.IsDestroying())
? new Color32(128, 128, 128, 255)
: new Color32(255, 255, 255, 255));
// delete pItem;
pItem = null;
// sprintf(out szName, "Rdo_Award%d", i);
// GetDlgItem(szName)->Show(true);
_radioButtons[i].gameObject.SetActive(true);
}
else
{
pImage.ClearCover();
pImage.SetHint(_AL(""));
pImage.SetText(_AL(""));
}
}
}
// turn off uneccessary rows
if (ad.m_ulCandItems <= MIN_ROW_COUNT_TO_SHOW)
{
// ٣ʣ
// for (i = MIN_ROW_COUNT_TO_SHOW + 1;; i++)
for (int i = MIN_ROW_COUNT_TO_SHOW + 1; i < _rowCount; i++)
{
// sprintf(out szName, "Item_%02d01", i);
// pImage = (PAUIIMAGEPICTURE)GetDlgItem(szName);
// if (!pImage) break; // All done.
pImage = GetAwardItemAt(i, i);
if (!pImage) break;
// sprintf(out szName, "Rdo_Award%d", i);
// GetDlgItem(szName)->Show(false);
_radioButtons[i].gameObject.SetActive(false);
for (int j = 1; j < _columnCount; j++)
{
// sprintf(out szName, "Item_%02d%02d", i, j);
// pImage = (PAUIIMAGEPICTURE)GetDlgItem(szName);
// if (!pImage) break;
// pImage->Show(false);
pImage = GetAwardItemAt(i, j);
pImage.Show(false);
// pImage2 = (PAUIIMAGEPICTURE)GetDlgItem(AString().Format("Img_%02d%02d", i, j));
// pImage2->Show(false);
// pImage2 = GetAwardItemAt(i, j);
}
}
// ȷϰťλãöԻС
// TODO: Thiết lập vị trí của nút xác nhận, thiết lập kích thước của hộp thoại.
// var pBtnConfirm = m_pBtn_Confirm;
// AUIObject* pImgLineMid = GetDlgItem(AString().Format("Item_%02d01", MIN_ROW_COUNT_TO_SHOW));
// AUIObject* pEdiBg = GetDlgItem("background");
// pBtnConfirm->SetPos(pBtnConfirm->GetPos(true).x,
// pImgLineMid->GetPos(true).y + pImgLineMid->GetSize().cy + 10);
// SetSize(GetSize().cx, pBtnConfirm->GetPos(true).y + pBtnConfirm->GetSize().cy + 30);
// pEdiBg->SetSize(pEdiBg->GetSize().cx, GetSize().cy - pEdiBg->GetPos(true).y - 25);
}
else
{
// ʾȫ / Show all rows
for (int i = MIN_ROW_COUNT_TO_SHOW + 1; i < _rowCount; i++)
{
// sprintf(out szName, "Item_%02d01", i);
// pImage = (PAUIIMAGEPICTURE)GetDlgItem(szName);
// if (!pImage) break; // All done.
pImage = GetAwardItemAt(i, 1);
if (!pImage) break; // All done.
if (ad.m_ulCandItems >= i)
{
// sprintf(out szName, "Rdo_Award%d", i);
// GetDlgItem(szName)->Show(true);
_radioButtons[i].gameObject.SetActive(true);
}
for (int j = 1; j < _columnCount; j++)
{
// sprintf(out szName, "Item_%02d%02d", i, j);
// pImage = (PAUIIMAGEPICTURE)GetDlgItem(szName);
// if (!pImage) break;
pImage = GetAwardItemAt(i, j);
if (!pImage) break;
pImage.Show(true);
// pImage2 = (PAUIIMAGEPICTURE)GetDlgItem(AString().Format("Img_%02d%02d", i, j));
// pImage2->Show(true);
// TODO: Handle pImage2 if needed
// AwardItem pImage2 = GetAwardItemAt(i, j);
// pImage2?.Show(true);
}
}
// ȷϰťλãöԻС
// TODO: Thiết lập vị trí của nút xác nhận, thiết lập kích thước của hộp thoại.
// AUIObject* pBtnConfirm = GetDlgItem("Btn_Confirm");
// AUIObject* pImgLineLast = GetDlgItem(AString().Format("Item_%02d01", i - 1));
// AUIObject* pEdiBg = GetDlgItem("background");
// pBtnConfirm->SetPos(pBtnConfirm->GetPos(true).x,
// pImgLineLast->GetPos(true).y + pImgLineLast->GetSize().cy + 10);
// SetSize(GetSize().cx, pBtnConfirm->GetPos(true).y + pBtnConfirm->GetSize().cy + 30);
// pEdiBg->SetSize(pEdiBg->GetSize().cx, GetSize().cy - pEdiBg->GetPos(true).y - 25);
}
}
}
void sprintf(out string szName, string format, int i)
{
// Convert C-style format specifiers to C# format
// %02d -> zero-padded 2-digit integer (D2 format)
// %d -> regular integer
string csharpFormat = format
.Replace("%02d", "{0:D2}")
.Replace("%d", "{0}");
szName = string.Format(csharpFormat, i);
}
void sprintf(out string szName, string format, int i, int j)
{
// Convert C-style format specifiers to C# format for two parameters
// %02d -> zero-padded 2-digit integer (D2 format)
// %d -> regular integer
// Replace occurrences sequentially: first -> {0}, second -> {1}
string csharpFormat = format;
int paramIndex = 0;
csharpFormat = System.Text.RegularExpressions.Regex.Replace(csharpFormat, @"%02d|%d", match =>
{
string replacement = paramIndex == 0
? (match.Value == "%02d" ? "{0:D2}" : "{0}")
: (match.Value == "%02d" ? "{1:D2}" : "{1}");
paramIndex++;
return replacement;
});
szName = string.Format(csharpFormat, i, j);
}
void a_sprintf(out string szText, string format, uint nNum)
{
// Convert C-style format specifiers to C# format
// %d -> regular integer (for uint)
string csharpFormat = format.Replace("%d", "{0}");
szText = string.Format(csharpFormat, nNum);
}
string _AL(string text)
{
// Localization helper - returns the string as-is
// In C++ this would typically handle localization, but for now just return the text
return text;
}
AwardItem GetAwardItemAt(int row, int column)
{
foreach (var item in _awardItems)
{
if (item.Position.x == row &&
item.Position.y == column)
{
return item;
}
}
return null;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1fac4acd7d2948cb81a522265a3f3863
timeCreated: 1764934733
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ce7649e37400b4c67baf894c0f5c049b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: cf26d96ae7d984ba8a5b6cef44adffeb
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: