Files
2025-05-01 07:20:41 +09:00

216 lines
10 KiB
C#

using Amazon.DynamoDBv2.Model.Internal.MarshallTransformations;
using GameServer;
using Google.Protobuf.WellKnownTypes;
using MetaAssets;
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Runtime.Intrinsics.Arm;
// TODO: spooky000 테이블 코드 교체 작업으로 인해 현재 안 쓰는 코드는 주석 처리해 둠.
// questTaskFunctionProgress 함수 호출되지 않아 reward 관련 코드 주석 처리.
namespace GameServer
{
public abstract class QuestBase : IQuest
{
public EQuestEventTargetType m_target_type;
public EQuestEventNameType m_name_type;
public int m_request_idx { get; set; }
public string m_active_event_string { get; set; } = string.Empty;
public string m_condition_1 { get; set; } = string.Empty;
public string m_condition_2 { get; set; } = string.Empty;
public string m_condition_3 { get; set; } = string.Empty;
public QuestBase(EQuestEventTargetType targetType, EQuestEventNameType eventNameType, int requestIdx, string cond1, string cond2, string cond3)
{
m_target_type = targetType;
m_name_type = eventNameType;
m_request_idx = requestIdx;
m_condition_1 = cond1;
m_condition_2 = cond2;
m_condition_3 = cond3;
}
public QuestBase(EQuestEventTargetType targetType, EQuestEventNameType eventNameType, string eventString, string cond1, string cond2, string cond3)
{
m_target_type = targetType;
m_name_type = eventNameType;
m_active_event_string = eventString;
m_condition_1 = cond1;
m_condition_2 = cond2;
m_condition_3 = cond3;
}
public virtual bool checkValidTaskScript(QuestAttribute questAttribute, QuestTaskUpdateHandler questTaskUpdateHandler)
{
var quest_task = questTaskUpdateHandler.m_quest_task_group;
var event_string = questTaskUpdateHandler.m_active_event;
NullReferenceCheckHelper.throwIfNull(quest_task, () => $"quest_task is null !!!");
var result = QuestMetaHelper.getQuestTaskEventGroupByEventString(quest_task, event_string, out var events);
if (result.isFail()) return false;
NullReferenceCheckHelper.throwIfNull(events, () => $"events is null !!!");
if (!events.EventTarget.Equals(m_target_type.ToString()) || !events.EventName.Equals(m_name_type.ToString())) return false;
bool subCheck = checkSubValidTaskScript(questAttribute, events);
return subCheck;
}
public virtual bool checkSubValidTaskScript(QuestAttribute questAttribute, QuestEventInfo events) { return true; }
public virtual async Task<Result> postProcess(Player player, QuestTaskUpdateHandler questTaskUpdateHandler)
{
await Task.CompletedTask;
return new Result();
}
public virtual Result questTaskFunctionProgress(Player player, ref QuestTaskUpdateHandler questTaskUpdateHandler)
{
var quest_action = player.getEntityAction<QuestAction>();
var quest_id = questTaskUpdateHandler.m_quest_id;
var quest = questTaskUpdateHandler.m_quest;
NullReferenceCheckHelper.throwIfNull(quest, () => $"quest is null !!!");
var quest_attribute = quest.getEntityAttribute<QuestAttribute>();
NullReferenceCheckHelper.throwIfNull(quest_attribute, () => $"quest_attribute is null !!!");
var active_evnet = questTaskUpdateHandler.m_active_event;
var quest_task_group = questTaskUpdateHandler.m_quest_task_group;
NullReferenceCheckHelper.throwIfNull(quest_task_group, () => $"quest_task_group is null !!!");
var result = QuestMetaHelper.getQuestTaskEventGroupByEventString(quest_task_group, active_evnet, out var questEventInfo);
if(result.isFail()) return result;
NullReferenceCheckHelper.throwIfNull(questEventInfo, () => $"questEventInfo is null !!!");
result = functionCheck(player, questEventInfo, quest_attribute, ref questTaskUpdateHandler);
if (result.isFail()) return result;
quest_attribute.ActiveEvents.Remove(active_evnet);
//패러럴일경우 문자열을 가지고 있는다.
if (quest_task_group.EventStringList.Count >= 2)
{
string str = MetaData.Instance.makeEventScriptStringByEventInfo(questEventInfo);
quest_attribute.CompletedIdxStrings.Add(str);
}
return result;
}
private Result functionCheck(Player player, QuestEventInfo questEventInfo, QuestAttribute quest_attribute, ref QuestTaskUpdateHandler questTaskUpdateHandler)
{
var result = new Result();
foreach (var funcInfo in questEventInfo.QuestEventFunctionList)
{
if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.QUEST)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.COMPLETE)))
{
quest_attribute.IsComplete = true ? 1 : 0;
quest_attribute.ActiveEvents.Clear();
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.COUNTER)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.INCREASE)))
{
int counter = int.Parse(funcInfo.FunctionCondition1);
quest_attribute.CurrentCounter += counter;
questTaskUpdateHandler.m_need_counter_check = true;
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.TASK)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.COMPLETE)))
{
quest_attribute.CurrentTaskComplete = 1;
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.TASK)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.ACTIVE)))
{
questTaskUpdateHandler.m_next_task_number = int.Parse(funcInfo.FunctionCondition1);
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.REWARD)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.SET)))
{
quest_attribute.ReplacedRewardGroupId = int.Parse(funcInfo.FunctionCondition1);
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.TIMER)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.START)))
{
quest_attribute.HasTimer = 1;
if (long.TryParse(funcInfo.FunctionCondition1, out long elapsedTime) == false)
{
Log.getLogger().error($"{funcInfo.FunctionCondition1} is not number");
elapsedTime = 10000000;
}
DateTime now = DateTime.UtcNow;
quest_attribute.TimerCompleteTime = now.AddSeconds(elapsedTime);
QuestManager.It.m_timer_check_users.TryAdd(player.getUserGuid(), string.Empty);
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.ITEM)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.GIVE)))
{
(result, var reward) = RewardManager.It.makeRewardFromItemStr(funcInfo.FunctionCondition1, funcInfo.FunctionCondition2);
if (result.isFail()) return result;
NullReferenceCheckHelper.throwIfNull(reward, () => $"reward is null !!!");
questTaskUpdateHandler.m_rewards.Add(reward);
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.ITEM)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.DELETE)))
{
if (false == int.TryParse(funcInfo.FunctionCondition1, out int delete_item_id))
{
string err_msg = $"delete item id is not number : {funcInfo.FunctionCondition1}";
result.setFail(ServerErrorCode.ItemParsingFromStringToIntErorr, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (false == int.TryParse(funcInfo.FunctionCondition2, out int delete_item_cnt))
{
string err_msg = $"delete item id is not number : {funcInfo.FunctionCondition2}";
result.setFail(ServerErrorCode.ItemParsingFromStringToIntErorr, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
questTaskUpdateHandler.m_deletable_items.TryAdd(delete_item_id, delete_item_cnt);
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.REWARD)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.GIVE)))
{
(var resutlt, var reward_metas) = RewardManager.It.makeRewardsInfo(funcInfo.FunctionCondition1);
if (resutlt.isFail())
{
return resutlt;
}
NullReferenceCheckHelper.throwIfNull(reward_metas, () => $"reward_metas is null !!!");
foreach (var meta in reward_metas)
{
questTaskUpdateHandler.m_rewards.Add(meta.Reward);
}
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.QUEST)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.ASSIGN)))
{
questTaskUpdateHandler.m_last_check_functions.Add(funcInfo);
}
else if (funcInfo.FunctionTarget.Equals(nameof(EQuestFunctionTargetType.PROP)) && funcInfo.FunctionName.Equals(nameof(EQuestFunctionNameType.SWITCH)))
{
questTaskUpdateHandler.m_last_check_functions.Add(funcInfo);
}
}
return result;
}
}
}