public override BTResult Process() { if (MyParty == null) { return(Exit(BTResult.Fail)); } if (MyParty.IsPlayerParty) { if (MyAI.MyShip == GameManager.Inst.PlayerControl.PlayerShip) { MyAI.OnTravelCompletion(); } return(Exit(BTResult.Fail)); } MacroAITaskType prevType = MacroAITaskType.None; if (MyParty.CurrentTask != null) { prevType = MyParty.CurrentTask.TaskType; } GameManager.Inst.NPCManager.MacroAI.AssignMacroAITask(prevType, MyParty); return(Exit(BTResult.Success)); }
public MacroAITask AssignMacroAITask(MacroAITaskType prevTaskType, MacroAIParty party) { MacroAITask task = new MacroAITask(); if (prevTaskType == MacroAITaskType.None) { if (UnityEngine.Random.value > 0.0f) { prevTaskType = MacroAITaskType.Stay; } else { prevTaskType = MacroAITaskType.Travel; } } party.PrevNode = null; if (party.NextTwoNodes != null) { party.NextTwoNodes.Clear(); } if (prevTaskType == MacroAITaskType.Travel) { if (!string.IsNullOrEmpty(party.DockedStationID) && UnityEngine.Random.value < 0.75f) { task.TaskType = MacroAITaskType.Trade; task.StayDuration = UnityEngine.Random.Range(10f, 30f); party.WaitTimer = 0; party.RunningNodeHist.UniquePush("Trading for " + task.StayDuration); Debug.LogError("Party " + party.PartyNumber + " Task has been assigned to party: Trade, current station" + party.DockedStationID); TradeCommodity(party, GameManager.Inst.WorldManager.DockableStationDatas[party.DockedStationID]); } else { task.TaskType = MacroAITaskType.Stay; task.StayDuration = UnityEngine.Random.Range(15f, 35f); party.WaitTimer = 0; party.RunningNodeHist.UniquePush("Stay for " + task.StayDuration); Debug.LogError("Party " + party.PartyNumber + " Task has been assigned to party: " + task.TaskType + " for " + task.StayDuration); } } else if (prevTaskType == MacroAITaskType.Stay || prevTaskType == MacroAITaskType.Trade) { task.TaskType = MacroAITaskType.Travel; List <string> keyList = new List <string>(GameManager.Inst.WorldManager.AllSystems.Keys); if (Time.time < 0) { Debug.LogError("new task for initial test"); StarSystemData destSystem = GameManager.Inst.WorldManager.AllSystems[keyList[UnityEngine.Random.Range(0, keyList.Count)]]; //StarSystemData destSystem = GameManager.Inst.WorldManager.AllSystems["washington_system"]; //StarSystemData destSystem = GameManager.Inst.WorldManager.AllSystems["new_england_system"]; task.TravelDestSystemID = destSystem.ID; task.TravelDestNodeID = destSystem.Stations[UnityEngine.Random.Range(0, destSystem.Stations.Count)].ID; //task.TravelDestNodeID = "annandale_station";//"planet_colombia_landing";//"bethesda_station"; task.IsDestAStation = true; //task.TravelDestCoord = new RelLoc(destSystem.OriginPosition, new Vector3(-28.3f, 5f, 418.8f), null); } else { Debug.LogError("new task to random station in random system"); StarSystemData destSystem = GameManager.Inst.WorldManager.AllSystems[keyList[UnityEngine.Random.Range(0, keyList.Count)]]; //StarSystemData destSystem = GameManager.Inst.WorldManager.AllSystems["washington_system"]; task.TravelDestSystemID = destSystem.ID; task.TravelDestNodeID = destSystem.Stations[UnityEngine.Random.Range(0, destSystem.Stations.Count)].ID; //task.TravelDestNodeID = "planet_colombia_landing"; task.IsDestAStation = true; } party.WaitTimer = 0; Debug.LogError("Party " + party.PartyNumber + " Task has been assigned to party: " + task.TaskType + " to " + (task.IsDestAStation ? task.TravelDestNodeID : task.TravelDestCoord.ToString())); } party.CurrentTask = task; party.HasReachedDestNode = false; if (party.CurrentTask.TaskType == MacroAITaskType.Travel) { if (party.CurrentTask.IsDestAStation) { party.DestNode = GameManager.Inst.WorldManager.AllNavNodes[party.CurrentTask.TravelDestNodeID]; } else { //party.DestNode = CreateTempNode(party.CurrentTask.TravelDestCoord, "tempdest", GameManager.Inst.WorldManager.AllSystems[party.CurrentTask.TravelDestSystemID]); party.DestNode = GetClosestNodeToLocation(party.CurrentTask.TravelDestCoord.RealPos, GameManager.Inst.WorldManager.AllSystems[party.CurrentTask.TravelDestSystemID]); } } return(task); }