280 lines
11 KiB
C#
280 lines
11 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Harmony.QuestJournalPatches
|
|
{
|
|
[HarmonyPatch(typeof(QuestJournal))]
|
|
[HarmonyPatch("Read")]
|
|
public class ReadPatch
|
|
{
|
|
public static bool Prefix(ref QuestJournal __instance, PooledBinaryReader _br)
|
|
{
|
|
__instance.quests.Clear();
|
|
byte version = _br.ReadByte();
|
|
if (version >= (byte)2)
|
|
{
|
|
int num = (int)_br.ReadByte();
|
|
__instance.TraderPOIs.Clear();
|
|
for (int index = 0; index < num; ++index)
|
|
__instance.TraderPOIs.Add(StreamUtils.ReadVector2((BinaryReader)_br));
|
|
}
|
|
if (version > (byte)2)
|
|
{
|
|
int num1 = (int)_br.ReadByte();
|
|
__instance.TradersByFaction.Clear();
|
|
for (int index1 = 0; index1 < num1; ++index1)
|
|
{
|
|
int key = _br.ReadInt32();
|
|
List<Vector2> vector2List = new List<Vector2>();
|
|
int num2 = _br.ReadInt32();
|
|
for (int index2 = 0; index2 < num2; ++index2)
|
|
vector2List.Add(StreamUtils.ReadVector2((BinaryReader)_br));
|
|
__instance.TradersByFaction.Add(key, vector2List);
|
|
}
|
|
}
|
|
int num3 = (int)_br.ReadInt16();
|
|
for (int index = 0; index < num3; ++index)
|
|
{
|
|
PooledBinaryReader.StreamReadSizeMarker _sizeMarker = new PooledBinaryReader.StreamReadSizeMarker();
|
|
if (version >= (byte)5)
|
|
_sizeMarker = _br.ReadSizeMarker(PooledBinaryWriter.EMarkerSize.UInt16);
|
|
string str = _br.ReadString();
|
|
uint _bytesReceived;
|
|
try
|
|
{
|
|
byte num4 = _br.ReadByte();
|
|
if (QuestClass.GetQuest(str) == null)
|
|
{
|
|
Log.Error("Loading player quests: Quest with ID " + str + " not found, ignoring");
|
|
_br.ValidateSizeMarker(ref _sizeMarker, out _bytesReceived);
|
|
}
|
|
else
|
|
{
|
|
Quest quest1 = QuestClass.CreateQuest(str);
|
|
Quest quest2 = quest1.Clone();
|
|
quest2.CurrentQuestVersion = num4;
|
|
quest2.Read(_br);
|
|
if ((int)quest1.CurrentQuestVersion != (int)num4)
|
|
quest2 = quest1.Clone();
|
|
quest2.OwnerJournal = __instance;
|
|
__instance.quests.Add(quest2);
|
|
|
|
//Log.Out("QuestJournalPatches-Read quest2.ID: " + quest2.ID);
|
|
//Log.Out("QuestJournalPatches-Read quest2.CurrentState: " + quest2.CurrentState);
|
|
//Log.Out("QuestJournalPatches-Read quest2.QuestGiverID: " + quest2.QuestGiverID);
|
|
//Log.Out("QuestJournalPatches-Read RebirthUtilities.IsVanillaTrader(quest2.QuestGiverID): " + RebirthUtilities.IsVanillaTrader(quest2.QuestGiverID));
|
|
|
|
if (quest2.CurrentState == Quest.QuestState.Completed)
|
|
{
|
|
//Log.Out("QuestJournalPatches-Read COMPLETED");
|
|
if (quest2.QuestClass.AddsToTierComplete)
|
|
{
|
|
//Log.Out("QuestJournalPatches-Read ADDS TO TIER COMPLETE");
|
|
//Log.Out("QuestJournalPatches-Read quest2.QuestGiverID: " + quest2.QuestGiverID);
|
|
//Log.Out("QuestJournalPatches-Read IsVanillaTrader: " + RebirthUtilities.IsVanillaTrader(quest2.QuestGiverID));
|
|
//if (RebirthUtilities.IsVanillaTrader(quest2.QuestGiverID))
|
|
{
|
|
//Log.Out("QuestJournalPatches-Read IS FROM VANILLA TRADER");
|
|
__instance.AddQuestFactionPoint(quest2.QuestFaction, (int)quest2.QuestClass.DifficultyTier);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
if (version >= (byte)5 && !_br.ValidateSizeMarker(ref _sizeMarker, out _bytesReceived))
|
|
Log.Error("Loading player quests: Error loading quest " + str + ", ignoring");
|
|
}
|
|
}
|
|
if (version <= (byte)3)
|
|
return false;
|
|
__instance.TraderData.Clear();
|
|
int num5 = (int)_br.ReadByte();
|
|
for (int index = 0; index < num5; ++index)
|
|
{
|
|
QuestTraderData questTraderData = new QuestTraderData()
|
|
{
|
|
Owner = __instance
|
|
};
|
|
questTraderData.Read((BinaryReader)_br, version);
|
|
__instance.TraderData.Add(questTraderData);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(QuestJournal))]
|
|
[HarmonyPatch("CompleteQuest")]
|
|
public class CompleteQuestPatch
|
|
{
|
|
public static bool Prefix(ref QuestJournal __instance, Quest q)
|
|
{
|
|
q.CurrentState = Quest.QuestState.Completed;
|
|
q.FinishTime = GameManager.Instance.World.worldTime;
|
|
__instance.OwnerPlayer.TriggerQuestChangedEvent(q);
|
|
|
|
bool includeParty = RebirthVariables.customShareParty;
|
|
|
|
if (!includeParty)
|
|
{
|
|
if (q.SharedOwnerID == -1)
|
|
{
|
|
includeParty = true;
|
|
}
|
|
}
|
|
|
|
if (q.QuestClass.AddsToTierComplete && includeParty)
|
|
{
|
|
/*if (RebirthUtilities.ScenarioSkip())
|
|
{
|
|
int currentTier = __instance.GetCurrentFactionTier((byte)1);
|
|
int questTier = q.QuestClass.DifficultyTier;
|
|
|
|
Log.Out("QuestJournalPatches-CompleteQuest currentTier: " + currentTier);
|
|
Log.Out("QuestJournalPatches-CompleteQuest BEFORE questTier: " + questTier);
|
|
|
|
if (q.QuestClass.ExtraTags.Test_AnySet(FastTags<TagGroup.Global>.Parse("infested")))
|
|
{
|
|
Log.Out("QuestJournalPatches-CompleteQuest AFTERIS INFESTED");
|
|
questTier--;
|
|
}
|
|
|
|
Log.Out("QuestJournalPatches-CompleteQuest AFTER questTier: " + questTier);
|
|
|
|
if (currentTier != questTier)
|
|
{
|
|
return false;
|
|
}
|
|
}*/
|
|
|
|
__instance.AddQuestFactionPoint(q.QuestFaction, (int)q.QuestClass.DifficultyTier);
|
|
if (q.SharedOwnerID == -1 && q.PositionData.ContainsKey(Quest.PositionDataTypes.TraderPosition) && q.PositionData.ContainsKey(Quest.PositionDataTypes.POIPosition) && SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient)
|
|
{
|
|
Vector3 vector3_1 = q.PositionData[Quest.PositionDataTypes.TraderPosition];
|
|
Vector3 vector3_2 = q.PositionData[Quest.PositionDataTypes.POIPosition];
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer((NetPackage)NetPackageManager.GetPackage<NetPackageNPCQuestList>().Setup(__instance.OwnerPlayer.entityId, new Vector2(vector3_1.x, vector3_1.z), (int)q.QuestClass.DifficultyTier, new Vector2(vector3_2.x, vector3_2.z)));
|
|
}
|
|
}
|
|
if (__instance.ActiveQuest == q)
|
|
{
|
|
__instance.ActiveQuest = (Quest)null;
|
|
__instance.RefreshRallyMarkerPositions();
|
|
}
|
|
|
|
GameManager.Instance.persistentPlayers.GetPlayerDataFromEntityID(__instance.OwnerPlayer.entityId).RemovePositionsForQuest(q.QuestCode);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(QuestJournal))]
|
|
[HarmonyPatch("RemoveQuest")]
|
|
public class RemoveQuestPatch
|
|
{
|
|
public static bool Prefix(ref QuestJournal __instance, Quest q)
|
|
{
|
|
bool staticQuest = q.QuestClass.Properties.Values.ContainsKey("StaticQuest");
|
|
|
|
if (staticQuest)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(QuestJournal))]
|
|
[HarmonyPatch("GetCurrentFactionTier")]
|
|
public class GetCurrentFactionTierPatch
|
|
{
|
|
public static bool Prefix(ref QuestJournal __instance, ref int __result, byte id, int offset = 0, bool allowExtraTierOverMax = false)
|
|
{
|
|
int jobsToNextTier = RebirthVariables.customJobsToNextTier;
|
|
|
|
//Log.Out("QuestJournalPatches-GetCurrentFactionTier jobsToNextTier: " + jobsToNextTier);
|
|
|
|
int num = __instance.GetQuestFactionPoints(id) + offset;
|
|
|
|
//Log.Out("QuestJournalPatches-GetCurrentFactionTier A num: " + num);
|
|
|
|
for (int i = 1; i < 100; i++)
|
|
{
|
|
num -= i * jobsToNextTier;
|
|
|
|
//Log.Out("QuestJournalPatches-GetCurrentFactionTier i: " + i + ", num: " + num);
|
|
|
|
if (num < 0)
|
|
{
|
|
//Log.Out("QuestJournalPatches-GetCurrentFactionTier Quest.MaxQuestTier: " + Quest.MaxQuestTier);
|
|
|
|
//Log.Out("QuestJournalPatches-GetCurrentFactionTier allowExtraTierOverMax: " + allowExtraTierOverMax);
|
|
|
|
__result = Math.Min(i, Quest.MaxQuestTier + (allowExtraTierOverMax ? 1 : 0));
|
|
return false;
|
|
}
|
|
}
|
|
__result = 1;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
[HarmonyPatch(typeof(QuestJournal))]
|
|
[HarmonyPatch("AddQuestFactionPoint")]
|
|
public class AddQuestFactionPointPatch
|
|
{
|
|
public static bool Prefix(ref QuestJournal __instance, byte id, int difficultyTier)
|
|
{
|
|
if (difficultyTier == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (RebirthUtilities.ScenarioSkip())
|
|
{
|
|
int currentTier = __instance.GetCurrentFactionTier((byte)1);
|
|
|
|
//Log.Out("QuestJournalPatches-CompleteQuest currentTier: " + currentTier);
|
|
//Log.Out("QuestJournalPatches-CompleteQuest difficultyTier: " + difficultyTier);
|
|
|
|
if (currentTier > difficultyTier)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
int max = 0;
|
|
for (int i = 1; i <= 5; i++)
|
|
{
|
|
if (!__instance.QuestFactionPoints.ContainsKey((byte)i))
|
|
{
|
|
__instance.QuestFactionPoints.Add((byte)i, 0);
|
|
}
|
|
int points = __instance.GetQuestFactionPoints((byte)i);
|
|
|
|
if (points > max)
|
|
{
|
|
max = points;
|
|
}
|
|
}
|
|
|
|
max = max + difficultyTier;
|
|
|
|
Dictionary<byte, int> questFactionPoints = __instance.QuestFactionPoints;
|
|
for (int i = 1; i <= 5; i++)
|
|
{
|
|
questFactionPoints[(byte)i] = max;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|