using System.Collections.Generic; public class ObjectiveGotoNamedPOIRebirth : ObjectiveRandomPOIGoto { public string POIName = ""; public override void ParseProperties(DynamicProperties properties) { if (properties.Values.ContainsKey("PrefabName")) POIName = properties.Values["PrefabName"]; if (properties.Values.ContainsKey("PrefabNames")) { var TempList = new List(); var strTemp = properties.Values["PrefabNames"]; var array = strTemp.Split(','); for (var i = 0; i < array.Length; i++) { if (TempList.Contains(array[i])) continue; TempList.Add(array[i]); } var random = new System.Random(); var index = random.Next(TempList.Count); if (TempList.Count == 0) Debug.Log(" ObjectiveGotoPOIRebirth PrefabNames Contains no prefabs."); else POIName = TempList[index]; } base.ParseProperties(properties); } public override void SetupObjective() { //Log.Out("ObjectiveGotoNamedPOIRebirth-SetupObjective"); this.keyword = Localization.Get("ObjectiveRallyPointHeadTo"); } public override void SetupIcon() { //Log.Out("ObjectiveGotoNamedPOIRebirth-SetupIcon"); this.icon = "ui_game_symbol_quest"; } public override bool NeedsNPCSetPosition { get { //Log.Out("ObjectiveGotoNamedPOIRebirth-NeedsNPCSetPosition"); return true; } } public override bool SetupPosition(EntityNPC ownerNPC = null, EntityPlayer player = null, List usedPOILocations = null, int entityIDforQuests = -1) { //Log.Out("ObjectiveGotoNamedPOIRebirth-SetupPosition"); return this.GetPosition(ownerNPC, player, usedPOILocations, entityIDforQuests) != Vector3.zero; } public override void AddHooks() { //Log.Out("ObjectiveGotoNamedPOIRebirth-AddHooks"); base.AddHooks(); base.OwnerQuest.HandleMapObject(Quest.PositionDataTypes.POIPosition, this.NavObjectName, -1); } public void SetDistanceOffset(Vector3 POISize) { //Log.Out("ObjectiveGotoNamedPOIRebirth-SetDistanceOffset"); if (POISize.x > POISize.z) { this.distanceOffset = POISize.x; return; } this.distanceOffset = POISize.z; } public override void SetPosition(Vector3 POIPosition, Vector3 POISize) { //Log.Out("ObjectiveGotoNamedPOIRebirth-SetPosition"); this.SetDistanceOffset(POISize); base.OwnerQuest.SetPositionData(Quest.PositionDataTypes.POIPosition, POIPosition); base.OwnerQuest.SetPositionData(Quest.PositionDataTypes.POISize, POISize); base.OwnerQuest.Position = POIPosition; this.position = POIPosition; } public override Vector3 GetPosition(EntityNPC ownerNPC = null, EntityPlayer entityPlayer = null, List usedPOILocations = null, int entityIDforQuests = -1) { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition START"); /*//Log.Out("ObjectiveGotoNamedPOIRebirth-GetPosition"); //Log.Out("ObjectiveGotoNamedPOIRebirth-GetPosition, X: " + ownerNPC.position.x); //Log.Out("ObjectiveGotoNamedPOIRebirth-GetPosition, Y: " + ownerNPC.position.y); //Log.Out("ObjectiveGotoNamedPOIRebirth-GetPosition, Z: " + ownerNPC.position.z);*/ if (base.OwnerQuest.GetPositionData(out this.position, Quest.PositionDataTypes.POIPosition)) { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition-1"); Vector3 vector; base.OwnerQuest.GetPositionData(out vector, Quest.PositionDataTypes.POISize); Vector2 vector2 = new Vector2(this.position.x + vector.x / 2f, this.position.z + vector.z / 2f); int num = (int)vector2.x; int num2 = (int)vector2.y; int num3 = (int)GameManager.Instance.World.GetHeightAt(vector2.x, vector2.y); this.position = new Vector3((float)num, (float)num3, (float)num2); base.OwnerQuest.Position = this.position; this.SetDistanceOffset(vector); this.positionSet = true; base.OwnerQuest.HandleMapObject(Quest.PositionDataTypes.POIPosition, this.NavObjectName, -1); base.CurrentValue = 2; return this.position; } //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition 2"); EntityAlive entityAlive = null; if (ownerNPC == null) { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition 3"); entityAlive = base.OwnerQuest.OwnerJournal.OwnerPlayer; } else { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition 4"); entityAlive = ownerNPC; } if (SingletonMonoBehaviour.Instance.IsServer) { //Log.Out("ObjectiveGotoNamedPOIRebirth-GetPosition 5 prefab:" + this.POIName); List prefabInstances = GameManager.Instance.World.ChunkClusters[0].ChunkProvider.GetDynamicPrefabDecorator().GetDynamicPrefabs().FindAll(instance => instance.name.Contains(this.POIName)); if (prefabInstances.Count == 0) { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition 6"); return Vector3.zero; } var prefab = RebirthUtilities.FindClosesPrefabs(entityAlive.position, prefabInstances, usedPOILocations, biomeFilterType, biomeFilter); if (prefab == null) { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition 7"); return Vector3.zero; } //Log.Out("ObjectiveGotoNamedPOIRebirth-GetPosition prefab.boundingBoxPosition: " + prefab.boundingBoxPosition); Vector2 vector3 = new Vector2((float)prefab.boundingBoxPosition.x + (float)prefab.boundingBoxSize.x / 2f, (float)prefab.boundingBoxPosition.z + (float)prefab.boundingBoxSize.z / 2f); if (vector3.x == -0.1f && vector3.y == -0.1f) { Log.Error("ObjectiveRandomGoto: No POI found."); return Vector3.zero; } int num4 = (int)vector3.x; int num5 = (int)GameManager.Instance.World.GetHeightAt(vector3.x, vector3.y); int num6 = (int)vector3.y; this.position = new Vector3((float)num4, (float)num5, (float)num6); if (GameManager.Instance.World.IsPositionInBounds(this.position)) { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition 8"); base.OwnerQuest.Position = this.position; base.FinalizePoint(new Vector3((float)prefab.boundingBoxPosition.x, (float)prefab.boundingBoxPosition.y, (float)prefab.boundingBoxPosition.z), new Vector3((float)prefab.boundingBoxSize.x, (float)prefab.boundingBoxSize.y, (float)prefab.boundingBoxSize.z)); base.OwnerQuest.QuestPrefab = prefab; base.OwnerQuest.DataVariables.Add("POIName", base.OwnerQuest.QuestPrefab.location.Name); return this.position; } return Vector3.zero; } else { //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition 9"); SingletonMonoBehaviour.Instance.SendToServer(NetPackageManager.GetPackage().Setup(this.POIName, entityAlive.entityId, base.OwnerQuest.QuestTags, base.OwnerQuest.QuestCode, NetPackageQuestNamedPOIGotoRebirth.QuestGotoTypes.RandomPOI, base.OwnerQuest.QuestClass.DifficultyTier, 0, -1, 0f, 0f, 0f, -1f, this.biomeFilterType, this.biomeFilter), false); base.CurrentValue = 1; } //Log.Out("ObjectiveGotoNamedPOIRebirth GetPosition END"); return Vector3.zero; } public override BaseObjective Clone() { //Log.Out("ObjectiveGotoNamedPOIRebirth-Clone"); ObjectiveGotoNamedPOIRebirth objectiveRandomPOIGoto = new ObjectiveGotoNamedPOIRebirth(); this.CopyValues(objectiveRandomPOIGoto); objectiveRandomPOIGoto.POIName = POIName; return objectiveRandomPOIGoto; } public override string ParseBinding(string bindingName) { //Log.Out("ObjectiveGotoNamedPOIRebirth-ParseBinding"); string id = base.ID; string value = base.Value; if (bindingName != null) { if (!(bindingName == "name")) { if (!(bindingName == "distance")) { if (bindingName == "direction") { if (base.OwnerQuest.QuestGiverID != -1) { EntityNPC entityNPC = GameManager.Instance.World.GetEntity(base.OwnerQuest.QuestGiverID) as EntityNPC; if (entityNPC != null) { this.position.y = 0f; Vector3 position = entityNPC.position; position.y = 0f; return ValueDisplayFormatters.Direction(GameUtils.GetDirByNormal(new Vector2(this.position.x - position.x, this.position.z - position.z)), false); } } } } else if (base.OwnerQuest.QuestGiverID != -1) { EntityNPC entityNPC2 = GameManager.Instance.World.GetEntity(base.OwnerQuest.QuestGiverID) as EntityNPC; if (entityNPC2 != null) { Vector3 position2 = entityNPC2.position; this.currentDistance = Vector3.Distance(position2, this.position); return ValueDisplayFormatters.Distance(this.currentDistance); } } } else if (SingletonMonoBehaviour.Instance.IsServer) { if (base.OwnerQuest.DataVariables.ContainsKey("POIName")) { return base.OwnerQuest.DataVariables["POIName"]; } if (base.OwnerQuest.QuestPrefab == null) { return ""; } return base.OwnerQuest.QuestPrefab.location.Name; } else { if (!base.OwnerQuest.DataVariables.ContainsKey("POIName")) { return ""; } return base.OwnerQuest.DataVariables["POIName"]; } } return ""; } }