821 lines
45 KiB
C#
821 lines
45 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Harmony.EntityTraderPatches
|
|
{
|
|
/*
|
|
[HarmonyPatch(typeof(EntityTrader))]
|
|
[HarmonyPatch("OnEntityActivated")]
|
|
public class OnEntityActivatedPatch
|
|
{
|
|
public static void Postfix(EntityTrader __instance, int _indexInBlockActivationCommands, Vector3i _tePos, EntityAlive _entityFocusing)
|
|
{
|
|
_entityFocusing.Buffs.SetCustomVar("CurrentNPC", __instance.entityId);
|
|
}
|
|
}
|
|
*/
|
|
|
|
[HarmonyPatch(typeof(EntityTrader))]
|
|
[HarmonyPatch("GetActivationCommands")]
|
|
public class GetActivationCommandsPatch
|
|
{
|
|
public static bool Prefix(EntityTrader __instance, ref EntityActivationCommand[] __result, Vector3i _tePos, EntityAlive _entityFocusing)
|
|
{
|
|
if (__instance.IsDead() || __instance.NPCInfo == null)
|
|
{
|
|
__result = new EntityActivationCommand[0];
|
|
return false;
|
|
}
|
|
|
|
bool canTrade = true;
|
|
|
|
if (__instance.EntityClass.entityClassName == "TraderFarmer_POI_FR")
|
|
{
|
|
canTrade = _entityFocusing.Progression.GetProgressionValue("FuriousRamsayAchievementFarmerTrader").calculatedLevel == 1;
|
|
}
|
|
if (__instance.EntityClass.entityClassName == "TraderHandyman_POI_FR")
|
|
{
|
|
canTrade = _entityFocusing.Progression.GetProgressionValue("FuriousRamsayAchievementHandymanTrader").calculatedLevel == 1;
|
|
}
|
|
if (__instance.EntityClass.entityClassName == "TraderBlackShield_POI_FR")
|
|
{
|
|
canTrade = _entityFocusing.Progression.GetProgressionValue("FuriousRamsayAchievementBlackShieldTrader").calculatedLevel == 1;
|
|
}
|
|
|
|
__result = new EntityActivationCommand[3]
|
|
{
|
|
new EntityActivationCommand("talk", "talk", true),
|
|
new EntityActivationCommand("trade", "map_trader", canTrade),
|
|
new EntityActivationCommand("remove", "x", GamePrefs.GetBool(EnumGamePrefs.DebugMenuEnabled) && !GameUtils.IsPlaytesting())
|
|
};
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/*[HarmonyPatch(typeof(EntityTrader))]
|
|
[HarmonyPatch("OnUpdateLive")]
|
|
public class OnUpdateLivePatch
|
|
{
|
|
private static float traderTick = 5f;
|
|
private static float traderCheck = 0f;
|
|
|
|
public static void Postfix(EntityTrader __instance)
|
|
{
|
|
//Log.Out("EntityTrader-OnUpdateLive Trader: " + __instance.EntityClass.entityClassName + " / visible: " + __instance.emodel.visible + " / active: " + __instance.emodel.isActiveAndEnabled + " / avatar: " + (__instance.emodel.avatarController != null));
|
|
|
|
if ((Time.time - traderCheck) > traderTick)
|
|
{
|
|
traderCheck = Time.time;
|
|
|
|
if (__instance.TraderData.TraderID > 100)
|
|
{
|
|
Log.Out("EntityTrader-OnUpdateLive TraderID: " + __instance.TraderData.TraderID + " / entity: " + __instance.EntityClass.entityClassName);
|
|
}
|
|
}
|
|
}
|
|
}*/
|
|
|
|
[HarmonyPatch(typeof(XUiC_CharacterFrameWindow))]
|
|
[HarmonyPatch("OnClose")]
|
|
public class OnClosePatch2
|
|
{
|
|
public static bool Prefix(XUiC_CharacterFrameWindow __instance)
|
|
{
|
|
EntityPlayerLocal player = __instance.xui.playerUI.entityPlayer;
|
|
|
|
int traderId = (int)player.Buffs.GetCustomVar("$CurrentTrader_FR");
|
|
//Log.Out("EntityTrader-OnClose traderId: " + traderId);
|
|
|
|
EntityTrader entityTrader = GameManager.Instance.World.GetEntity(traderId) as EntityTrader;
|
|
|
|
if (entityTrader != null)
|
|
{
|
|
if (RebirthUtilities.IsVanillaTrader(traderId))
|
|
{
|
|
entityTrader.ClearActiveQuests(player.entityId);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityTrader))]
|
|
[HarmonyPatch("HandleClientQuests")]
|
|
public class HandleClientQuestsPatch
|
|
{
|
|
public static bool Prefix(EntityTrader __instance, EntityPlayer player)
|
|
{
|
|
player.Buffs.SetCustomVar("$CurrentTrader_FR", __instance.entityId);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/*[HarmonyPatch(typeof(EntityTrader))]
|
|
[HarmonyPatch("ActivateTrader")]
|
|
public class ActivateTraderPatch
|
|
{
|
|
private static bool Prefix(EntityTrader __instance, bool traderIsOpen,
|
|
int ___outstandingIndexInBlockActivationCommands,
|
|
Vector3i ___outstandingTePos,
|
|
global::EntityAlive ___outstandingEntityFocusing
|
|
)
|
|
{
|
|
if (traderIsOpen)
|
|
{
|
|
int num = ___outstandingIndexInBlockActivationCommands;
|
|
Vector3i blockPos = ___outstandingTePos;
|
|
global::EntityAlive entityAlive = ___outstandingEntityFocusing;
|
|
EntityPlayerLocal entityPlayerLocal = entityAlive as EntityPlayerLocal;
|
|
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
|
|
QuestEventManager.Current.NPCInteracted(__instance);
|
|
QuestEventManager.Current.NPCMet((EntityNPC)__instance);
|
|
Quest nextCompletedQuest = (entityAlive as EntityPlayerLocal).QuestJournal.GetNextCompletedQuest(null, __instance.entityId);
|
|
|
|
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
__instance.activeQuests = QuestEventManager.Current.GetQuestList(GameManager.Instance.World, __instance.entityId, entityAlive.entityId);
|
|
|
|
if (__instance.activeQuests == null)
|
|
{
|
|
// OLD CODE
|
|
//__instance.activeQuests = __instance.PopulateActiveQuests(entityPlayerLocal, -1);
|
|
//QuestEventManager.Current.SetupQuestList(__instance.entityId, entityAlive.entityId, __instance.activeQuests);
|
|
__instance.SetupActiveQuestsForPlayer((EntityPlayer)entityPlayerLocal);
|
|
}
|
|
}
|
|
switch (num)
|
|
{
|
|
case 0:
|
|
uiforPlayer.xui.Dialog.Respondent = __instance;
|
|
|
|
if (nextCompletedQuest == null)
|
|
{
|
|
if (uiforPlayer.windowManager.IsWindowOpen("dialog"))
|
|
break;
|
|
uiforPlayer.windowManager.CloseAllOpenWindows(null, false);
|
|
uiforPlayer.windowManager.Open("dialog", true, false, true);
|
|
QuestEventManager.Current.NPCInteracted(__instance);
|
|
|
|
return false;
|
|
}
|
|
uiforPlayer.xui.Dialog.QuestTurnIn = nextCompletedQuest;
|
|
uiforPlayer.windowManager.CloseAllOpenWindows(null, false);
|
|
__instance.PlayVoiceSetEntry("quest_complete", (EntityPlayer)entityPlayerLocal, true, true);
|
|
uiforPlayer.windowManager.Open("questTurnIn", true, false, true);
|
|
return false;
|
|
case 1:
|
|
uiforPlayer.xui.Trader.TraderEntity = __instance;
|
|
if (nextCompletedQuest == null)
|
|
{
|
|
GameManager.Instance.TELockServer(0, blockPos, __instance.TileEntityTrader.entityId, entityAlive.entityId, null);
|
|
__instance.PlayVoiceSetEntry("trade", (EntityPlayer)entityPlayerLocal, true, true);
|
|
return false;
|
|
}
|
|
uiforPlayer.xui.Dialog.QuestTurnIn = nextCompletedQuest;
|
|
uiforPlayer.windowManager.CloseAllOpenWindows(null, false);
|
|
__instance.PlayVoiceSetEntry("quest_complete", (EntityPlayer)entityPlayerLocal, true, true);
|
|
uiforPlayer.windowManager.Open("questTurnIn", true, false, true);
|
|
return false;
|
|
case 2:
|
|
{
|
|
Waypoint entityVehicleWaypoint = entityPlayerLocal.Waypoints.GetEntityVehicleWaypoint(__instance.entityId);
|
|
if (entityVehicleWaypoint != null)
|
|
{
|
|
entityPlayerLocal.Waypoints.Collection.Remove(entityVehicleWaypoint);
|
|
NavObjectManager.Instance.UnRegisterNavObjectByPosition(entityVehicleWaypoint.pos, "waypoint");
|
|
}
|
|
GameEventManager.Current.HandleAction("game_remove_entity", entityPlayerLocal, __instance, false, "", "", false, true, "", null);
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}*/
|
|
|
|
[HarmonyPatch(typeof(EntityTrader))]
|
|
[HarmonyPatch("PopulateActiveQuests")]
|
|
public class PopulateActiveQuestsPatch
|
|
{
|
|
private static bool Prefix(global::EntityPlayer player, int currentTier, EntityTrader __instance, ref List<Quest> __result, ref Dictionary<int, List<QuestEntry>> ___questDictionary, ref List<int> ___tempTopTierQuests, ref List<int> ___tempSpecialQuests, ref List<string> ___uniqueKeysUsed, ref TraderArea ___traderArea, ref Vector3 ___position, ref List<Vector2> ___usedPOILocations, ref GameRandom ___rand, ref int ___entityId, ref List<QuestEntry> ___specialQuestList)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests START");
|
|
if (___questDictionary.Count == 0)
|
|
{
|
|
__instance.PopulateQuestList();
|
|
if (___questDictionary.Count == 0)
|
|
{
|
|
__result = null;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
int maxJobs = RebirthVariables.customMaxJobs;
|
|
|
|
if (maxJobs == 0)
|
|
{
|
|
__result = null;
|
|
return false;
|
|
}
|
|
|
|
bool @bool = GameStats.GetBool(EnumGameStats.EnemySpawnMode);
|
|
List<Quest> list = new List<Quest>();
|
|
List<Quest> listCurrentQuests = player.QuestJournal.quests;
|
|
|
|
___tempTopTierQuests.Clear();
|
|
___tempSpecialQuests.Clear();
|
|
___uniqueKeysUsed.Clear();
|
|
Vector2 vector;
|
|
if (___traderArea != null)
|
|
{
|
|
vector = new Vector2((float)___traderArea.Position.x, (float)___traderArea.Position.z);
|
|
}
|
|
else
|
|
{
|
|
vector = new Vector2(___position.x, ___position.z);
|
|
}
|
|
if (currentTier == -1)
|
|
{
|
|
currentTier = player.QuestJournal.GetCurrentFactionTier(__instance.NPCInfo.QuestFaction, 0, false);
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests currentTier: " + currentTier);
|
|
|
|
int questFactionPoints = player.QuestJournal.GetQuestFactionPoints(__instance.NPCInfo.QuestFaction);
|
|
QuestTraderData traderData = player.QuestJournal.GetTraderData(vector);
|
|
if (traderData != null)
|
|
{
|
|
traderData.CheckReset(player);
|
|
}
|
|
//___usedPOILocations.Clear();
|
|
|
|
bool playerHasFetchQuest = false;
|
|
|
|
for (int i = 0; i < listCurrentQuests.Count; i++)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[i].CurrentState: " + listCurrentQuests[i].CurrentState);
|
|
bool isOpen = RebirthUtilities.IsVanillaTrader(listCurrentQuests[i].QuestGiverID) && (listCurrentQuests[i].CurrentState == Quest.QuestState.NotStarted ||
|
|
listCurrentQuests[i].CurrentState == Quest.QuestState.InProgress ||
|
|
listCurrentQuests[i].CurrentState == Quest.QuestState.ReadyForTurnIn)
|
|
;
|
|
|
|
int questOwnerId = listCurrentQuests[i].SharedOwnerID;
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests isOpen: " + isOpen);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests questOwnerId: " + questOwnerId);
|
|
|
|
/*if (listCurrentQuests[i].QuestPrefab != null)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[i].GetPOIName(): " + listCurrentQuests[i].GetPOIName());
|
|
}*/
|
|
|
|
if (isOpen)
|
|
{
|
|
if (questOwnerId == -1)
|
|
{
|
|
for (int k = 0; k < listCurrentQuests[i].QuestClass.Objectives.Count; k++)
|
|
{
|
|
if (listCurrentQuests[i].QuestClass.Objectives[k] is ObjectiveFetchFromContainer)
|
|
{
|
|
playerHasFetchQuest = true;
|
|
break;
|
|
}
|
|
}
|
|
if (playerHasFetchQuest)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests playerHasFetchQuest: " + playerHasFetchQuest);
|
|
|
|
List<Quest> listRestrictedQuests = new List<Quest>();
|
|
List<string> listFoundQuests = new List<string>();
|
|
|
|
int num = 0;
|
|
int buriedSupplies = 0;
|
|
int restorePower = 0;
|
|
int fetchContainer = 0;
|
|
int numCustomQuests = 0;
|
|
int maxCustomQuests = (int)maxJobs / 4;
|
|
int maxBuriedSupplies = (int)maxJobs / 5;
|
|
int numJobs = 0;
|
|
|
|
for (int k = 0; k < listCurrentQuests.Count; k++)
|
|
{
|
|
/*if (listCurrentQuests[k].QuestPrefab != null)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests list[" + k + "].GetPOIName(): " + listCurrentQuests[k].GetPOIName());
|
|
}*/
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[" + k + "].QuestGiverID: " + listCurrentQuests[k].QuestGiverID);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[" + k + "].NPCInfo.QuestFaction: " + listCurrentQuests[k].QuestFaction);
|
|
|
|
if (listCurrentQuests[k].SharedOwnerID == -1 &&
|
|
listCurrentQuests[k].QuestClass.DifficultyTier == currentTier &&
|
|
RebirthUtilities.IsVanillaTrader(listCurrentQuests[k].QuestGiverID)
|
|
)
|
|
{
|
|
numJobs++;
|
|
listRestrictedQuests.Add(listCurrentQuests[k]);
|
|
}
|
|
|
|
if (currentTier == 1 && numJobs == 8) break;
|
|
if (currentTier == 2 && numJobs == 6) break;
|
|
if (currentTier == 3 && numJobs == 5) break;
|
|
if (currentTier == 4 && numJobs == 4) break;
|
|
if (currentTier == 5 && numJobs == 3) break;
|
|
if (currentTier == 6 && numJobs == 2) break;
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests numJobs: " + numJobs);
|
|
|
|
/*for (int k = 0; k < listRestrictedQuests.Count; k++)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listRestrictedQuests[" + k + "].GetPOIName(): " + listRestrictedQuests[k].GetPOIName());
|
|
}*/
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests maxCustomQuests: " + maxCustomQuests);
|
|
|
|
int startTier = 1;
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests BEFORE currentTier: " + currentTier);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests BEFORE startTier: " + startTier);
|
|
|
|
if (RebirthUtilities.ScenarioSkip())
|
|
{
|
|
if (__instance.EntityClass.entityClassName == "npcTraderRekt")
|
|
{
|
|
startTier = 1;
|
|
currentTier = 1;
|
|
}
|
|
else if (__instance.EntityClass.entityClassName == "npcTraderBob")
|
|
{
|
|
if (currentTier < 2)
|
|
{
|
|
__result = null;
|
|
return false;
|
|
}
|
|
startTier = 1;
|
|
currentTier = 2;
|
|
}
|
|
else if (__instance.EntityClass.entityClassName == "npcTraderHugh")
|
|
{
|
|
if (currentTier < 3)
|
|
{
|
|
__result = null;
|
|
return false;
|
|
}
|
|
startTier = 1;
|
|
currentTier = 3;
|
|
}
|
|
else if (__instance.EntityClass.entityClassName == "npcTraderJoel")
|
|
{
|
|
if (currentTier < 4)
|
|
{
|
|
__result = null;
|
|
return false;
|
|
}
|
|
startTier = 1;
|
|
currentTier = 4;
|
|
}
|
|
else if (__instance.EntityClass.entityClassName == "npcTraderJen")
|
|
{
|
|
if (currentTier < 5)
|
|
{
|
|
__result = null;
|
|
return false;
|
|
}
|
|
startTier = 1;
|
|
currentTier = 5;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests AFTER currentTier: " + currentTier);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests AFTER startTier: " + startTier);
|
|
|
|
for (int i = startTier; i <= currentTier; i++)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests ___usedPOILocations.Count: " + ___usedPOILocations.Count);
|
|
|
|
num = 0;
|
|
|
|
for (int j = 0; j < 1000; j++)
|
|
{
|
|
int index = ___rand.RandomRange(___questDictionary[i].Count);
|
|
QuestEntry questEntry = ___questDictionary[i][index];
|
|
if (___rand.RandomFloat < questEntry.Prob)
|
|
{
|
|
QuestClass questClass = questEntry.QuestClass;
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests questClass: " + questClass.ID);
|
|
|
|
bool optionCustomQuests = RebirthVariables.customCustomQuests;
|
|
|
|
bool skipQuest = false;
|
|
|
|
bool customQuest = questClass.Properties.Values.ContainsKey("CustomQuest");
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests customQuest: " + customQuest);
|
|
|
|
if (!optionCustomQuests && customQuest)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests A");
|
|
skipQuest = true;
|
|
}
|
|
|
|
if (optionCustomQuests && customQuest)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests B");
|
|
if (numCustomQuests >= maxCustomQuests)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests C");
|
|
skipQuest = true;
|
|
}
|
|
else if (num < (numCustomQuests / 3))
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests D");
|
|
skipQuest = true;
|
|
}
|
|
}
|
|
|
|
if (questClass.Properties.Values.ContainsKey("SkipQuest") && player.IsInParty())
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests E1");
|
|
skipQuest = true;
|
|
}
|
|
|
|
if (questClass.Properties.Values.ContainsKey("SkipJobList"))
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests E2");
|
|
skipQuest = true;
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests num: " + num);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests numCustomQuests: " + numCustomQuests);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests skipQuest: " + skipQuest);
|
|
|
|
if (!skipQuest) // QuestStage removed - Do we need an alternative? // && (questClass.QuestStage == -1 || questFactionPoints >= questClass.QuestStage))
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests F");
|
|
Quest quest = questEntry.QuestClass.CreateQuest();
|
|
quest.QuestGiverID = ___entityId;
|
|
quest.QuestFaction = __instance.NPCInfo.QuestFaction;
|
|
quest.SetPositionData(Quest.PositionDataTypes.QuestGiver, ___position);
|
|
quest.SetPositionData(Quest.PositionDataTypes.TraderPosition, (___traderArea != null) ? ___traderArea.Position : ___position);
|
|
quest.SetupTags();
|
|
|
|
if (@bool || !quest.QuestTags.Test_AnySet(QuestEventManager.clearTag))
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests F1");
|
|
___usedPOILocations.Clear();
|
|
|
|
if (quest.SetupPosition(__instance, player, ___usedPOILocations, player.entityId))
|
|
{
|
|
string POIName = quest.GetPOIName().ToLower();
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests Quest POIName: " + POIName);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests quest.QuestClass.DifficultyTier: " + quest.QuestClass.DifficultyTier);
|
|
|
|
int distance = (int)Vector3.Distance(quest.Position, ___position) / 50 * 50;
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests distance: " + distance);
|
|
|
|
int maxDistance = 2500;
|
|
|
|
if (currentTier == 2)
|
|
{
|
|
maxDistance = 3500;
|
|
}
|
|
else if (currentTier == 3)
|
|
{
|
|
maxDistance = 4500;
|
|
}
|
|
else if (currentTier == 4)
|
|
{
|
|
maxDistance = 7000;
|
|
}
|
|
else if (currentTier == 5)
|
|
{
|
|
maxDistance = 10000;
|
|
}
|
|
else if (currentTier == 6)
|
|
{
|
|
maxDistance = 15000;
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests maxDistance: " + maxDistance);
|
|
|
|
if (distance <= maxDistance)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests IS WITHIN MAX DISTANCE");
|
|
bool bypassPOI = false;
|
|
bool foundBuriedSupplies = false;
|
|
bool foundRestorePower = false;
|
|
bool foundFetchContainer = false;
|
|
int numDuplicates = 0;
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listFoundQuests.Count: " + listFoundQuests.Count);
|
|
|
|
for (int k = 0; k < listFoundQuests.Count; k++)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listFoundQuests[" + k + "]: " + listFoundQuests[k]);
|
|
|
|
if (POIName.Trim() != "" && POIName == listFoundQuests[k].ToLower()
|
|
)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests 00a");
|
|
bypassPOI = true;
|
|
}
|
|
}
|
|
|
|
if (!RebirthVariables.customRepeatPOI)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests.Count: " + listCurrentQuests.Count);
|
|
for (int k = 0; k < listCurrentQuests.Count; k++)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[" + k + "].GetPOIName(): " + listCurrentQuests[k].GetPOIName());
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[" + k + "] IS VANILLA TRADER: " + RebirthUtilities.IsVanillaTrader(listCurrentQuests[k].QuestGiverID));
|
|
if (RebirthUtilities.IsVanillaTrader(listCurrentQuests[k].QuestGiverID))
|
|
{
|
|
bool isOpen = (listCurrentQuests[k].CurrentState == Quest.QuestState.NotStarted ||
|
|
listCurrentQuests[k].CurrentState == Quest.QuestState.InProgress ||
|
|
listCurrentQuests[k].CurrentState == Quest.QuestState.ReadyForTurnIn ||
|
|
listCurrentQuests[k].CurrentState == Quest.QuestState.Completed);
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[" + k + "].CurrentState: " + listCurrentQuests[k].CurrentState);
|
|
|
|
/*//Log.Out("EntityTraderPatches-PopulateActiveQuests listCurrentQuests[" + k + "].Position: " + listCurrentQuests[k].Position);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests quest.position: " + quest.position);
|
|
|
|
BiomeDefinition biomeAt1 = GameManager.Instance.World.ChunkCache.ChunkProvider.GetBiomeProvider().GetBiomeAt((int)listCurrentQuests[k].Position.x, (int)listCurrentQuests[k].Position.z);
|
|
BiomeDefinition biomeAt2 = GameManager.Instance.World.ChunkCache.ChunkProvider.GetBiomeProvider().GetBiomeAt((int)quest.position.x, (int)quest.position.z);
|
|
|
|
bool sameBiome = false;
|
|
|
|
if (biomeAt1 != null && biomeAt2 != null && biomeAt1.m_sBiomeName == biomeAt2.m_sBiomeName)
|
|
{
|
|
sameBiome = true;
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests sameBiome: " + sameBiome);*/
|
|
|
|
if (POIName.Trim() != "" && POIName == listCurrentQuests[k].GetPOIName().ToLower() && isOpen
|
|
)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests ALREADY DID POI POIName: " + POIName);
|
|
bypassPOI = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests A bypassPOI: " + bypassPOI);
|
|
|
|
if (!bypassPOI)
|
|
{
|
|
/*if (quest.QuestPrefab != null)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests FOUND quest.GetPOIName(): " + quest.GetPOIName());
|
|
}*/
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests listRestrictedQuests.Count: " + listRestrictedQuests.Count);
|
|
|
|
for (int k = 0; k < listRestrictedQuests.Count; k++)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests list[" + k + "].GetPOIName(): " + listRestrictedQuests[k].GetPOIName());
|
|
if (POIName.Trim() != "" && listRestrictedQuests[k].SharedOwnerID == -1 &&
|
|
POIName == listRestrictedQuests[k].GetPOIName().ToLower()
|
|
)
|
|
{
|
|
numDuplicates++;
|
|
}
|
|
}
|
|
|
|
if (numDuplicates >= RebirthVariables.customMaxSamePOI)
|
|
{
|
|
Log.Out("EntityTraderPatches-PopulateActiveQuests numDuplicates: " + numDuplicates);
|
|
Log.Out("EntityTraderPatches-PopulateActiveQuests RebirthVariables.customMaxSamePOI: " + RebirthVariables.customMaxSamePOI);
|
|
bypassPOI = true;
|
|
}
|
|
|
|
for (int k = 0; k < quest.QuestClass.Objectives.Count; k++)
|
|
{
|
|
if (quest.QuestClass.Objectives[k] is ObjectiveFetchFromContainer)
|
|
{
|
|
if (quest.QuestClass.Objectives[k].Properties.Values.ContainsKey("default_container"))
|
|
{
|
|
if (quest.QuestClass.Objectives[k].Properties.Values["default_container"] == "cntFetchQuestSatchel")
|
|
{
|
|
foundFetchContainer = true;
|
|
fetchContainer++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests foundFetchContainer: " + foundFetchContainer);
|
|
|
|
for (int k = 0; k < quest.QuestClass.Objectives.Count; k++)
|
|
{
|
|
//Log.Out("quest.QuestClass.Objectives[" + k + "].ToString(): " + quest.QuestClass.Objectives[k].ToString());
|
|
//Log.Out("quest.QuestClass.Objectives[" + k + "].ObjectiveValueType: " + quest.QuestClass.Objectives[k].ObjectiveValueType);
|
|
if (quest.QuestClass.Objectives[k] is ObjectiveTreasureChest)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests FOUND TREASURE CHEST OBJECTIVE");
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests UniqueKey: " + quest.QuestClass.UniqueKey);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests ID: " + quest.QuestClass.ID);
|
|
if (quest.QuestClass.ID.ToLower().Contains("buried_supplies"))
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests FOUND BURIED SUPPLIES");
|
|
foundBuriedSupplies = true;
|
|
buriedSupplies++;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int k = 0; k < quest.QuestClass.Objectives.Count; k++)
|
|
{
|
|
//Log.Out("quest.QuestClass.Objectives[" + k + "].ToString(): " + quest.QuestClass.Objectives[k].ToString());
|
|
//Log.Out("quest.QuestClass.Objectives[" + k + "].ObjectiveValueType: " + quest.QuestClass.Objectives[k].ObjectiveValueType);
|
|
if (quest.QuestClass.Objectives[k] is ObjectivePOIBlockActivate)
|
|
{
|
|
foundRestorePower = true;
|
|
restorePower++;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests foundBuriedSupplies: " + foundBuriedSupplies);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests buriedSupplies: " + buriedSupplies);
|
|
|
|
if (POIName == "" && foundBuriedSupplies && buriedSupplies > maxBuriedSupplies)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests BYPASS POI");
|
|
bypassPOI = true;
|
|
}
|
|
else if (customQuest && numCustomQuests > 3)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests DO NOT BYPASS POI");
|
|
bypassPOI = true;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests B bypassPOI: " + bypassPOI);
|
|
|
|
if (!bypassPOI)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests quest.QuestClass.Name: " + quest.QuestClass.Name);
|
|
if (foundRestorePower)
|
|
{
|
|
//Log.Out("FOUND RESTORE POWER, restorePower: " + restorePower);
|
|
if (restorePower < 4)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests CC ADD QUEST");
|
|
//if (quest.QuestPrefab != null)
|
|
{
|
|
//Log.Out("QUEST NAME: " + POIName + " / DISTANCE: " + ((int)Vector3.Distance(quest.Position, ___position) / 50 * 50));
|
|
}
|
|
|
|
if (customQuest)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests CC CUSTOM QUEST");
|
|
numCustomQuests++;
|
|
}
|
|
list.Add(quest);
|
|
listFoundQuests.Add(POIName);
|
|
num++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests NOT RESTORE POWER");
|
|
if (!playerHasFetchQuest || (playerHasFetchQuest && !foundFetchContainer))
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests EE ADD QUEST");
|
|
if (customQuest && quest.QuestClass.DifficultyTier == player.QuestJournal.GetCurrentFactionTier((byte)1))
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests FF SUTOM QUEST");
|
|
numCustomQuests++;
|
|
}
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests ADDED quest.GetPOIName(): " + POIName);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests ADDED DifficultyTier: " + quest.QuestClass.DifficultyTier);
|
|
|
|
/*//Log.Out("EntityTraderPatches-PopulateActiveQuests ID: " + quest.QuestClass.ID);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests Name: " + quest.QuestClass.Name);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests SubTitle: " + quest.QuestClass.SubTitle);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests StatementText: " + quest.QuestClass.StatementText);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests ResponseText: " + quest.QuestClass.ResponseText);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests Description: " + quest.QuestClass.Description);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests POIName: " + POIName);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests Difficulty: " + quest.QuestClass.Difficulty);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests DifficultyTier: " + quest.QuestClass.DifficultyTier);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests Offer: " + quest.QuestClass.Offer);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests StatementText: " + quest.QuestClass.StatementText);*/
|
|
list.Add(quest);
|
|
listFoundQuests.Add(POIName);
|
|
num++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (quest.QuestTags.Test_AnySet(QuestEventManager.treasureTag) && GameSparksCollector.CollectGamePlayData)
|
|
{
|
|
GameSparksCollector.IncrementCounter(GameSparksCollector.GSDataKey.QuestOfferedDistance, ((int)Vector3.Distance(quest.Position, ___position) / 50 * 50).ToString(), 1, true, GameSparksCollector.GSDataCollection.SessionUpdates);
|
|
}
|
|
if (num == maxJobs)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests REACHED MAX JOBS num: " + num);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests maxJobs: " + maxJobs);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests NumQuests: " + list.Count);
|
|
|
|
List<Quest> listSort = new List<Quest>();
|
|
int iteration = 0;
|
|
|
|
while (list.Count > 0)
|
|
{
|
|
int position = -1;
|
|
int distance = 999999;
|
|
iteration++;
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests Iteration: " + iteration);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests distance: " + distance);
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
int distanceQuest = (int)Vector3.Distance(list[i].Position, ___position);
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests i: " + i + " distanceQuest: " + distanceQuest);
|
|
if (distanceQuest < distance)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests distanceQuest < distance");
|
|
distance = distanceQuest;
|
|
position = i;
|
|
}
|
|
}
|
|
if (position >= 0)
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests position >= 0: " + position);
|
|
listSort.Add(list[position]);
|
|
list.RemoveAt(position);
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests position < 0: " + position);
|
|
break;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityTraderPatches-PopulateActiveQuests NumQuests (Sorted): " + listSort.Count);
|
|
|
|
list = listSort;
|
|
|
|
for (int k = 0; k < ___specialQuestList.Count; k++)
|
|
{
|
|
if (___specialQuestList[k].QuestClass.UniqueKey == "" || !___uniqueKeysUsed.Contains(___specialQuestList[k].QuestClass.UniqueKey))
|
|
{
|
|
QuestClass questClass = ___specialQuestList[k].QuestClass;
|
|
if ((int)(questClass.DifficultyTier - 1) <= currentTier && player.QuestJournal.FindQuest(questClass.ID, (int)__instance.NPCInfo.QuestFaction) == null)
|
|
{
|
|
Quest quest2 = questClass.CreateQuest();
|
|
quest2.QuestGiverID = ___entityId;
|
|
quest2.QuestFaction = __instance.NPCInfo.QuestFaction;
|
|
quest2.SetPositionData(Quest.PositionDataTypes.QuestGiver, ___position);
|
|
quest2.SetPositionData(Quest.PositionDataTypes.TraderPosition, (___traderArea != null) ? ___traderArea.Position : ___position);
|
|
quest2.SetupTags();
|
|
___usedPOILocations.Clear();
|
|
if (!quest2.NeedsNPCSetPosition || quest2.SetupPosition(__instance, player, ___usedPOILocations, player.entityId))
|
|
{
|
|
list.Add(quest2);
|
|
if (questClass.UniqueKey != "")
|
|
{
|
|
___uniqueKeysUsed.Add(questClass.UniqueKey);
|
|
}
|
|
if (GameSparksCollector.CollectGamePlayData)
|
|
{
|
|
GameSparksCollector.IncrementCounter(GameSparksCollector.GSDataKey.QuestTraderToTraderDistance, ((int)Vector3.Distance(quest2.Position, ___position) / 50 * 50).ToString(), 1, true, GameSparksCollector.GSDataCollection.SessionUpdates);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
__result = list;
|
|
return false;
|
|
}
|
|
}
|
|
}
|