/// <summary> /// Initialize the 'Target Practice' quest and add it to the Quest Manager /// </summary> private void InitializeTargetPracticeQuest() { // OBJECTIVE 1 - TRAVEL TO MOON ObjectiveTarget moon = moonTravelObjective.AddComponent <ObjectiveTarget>(); Objective firstObjective = firstQuest.GetObjectiveAtIndex(0); firstObjective.AssignTarget(moon); // OBJECTIVE 2 - DEFEAT RAIDERS SpawnPrefabsForObjective(firstQuest, 1, enemyShipPrefab, 5, moonSpawnPoint.position, 50); // OBJECTIVE 3 - TRAVEL TO EARTH ObjectiveTarget earth = earthTravelObjective.AddComponent <ObjectiveTarget>(); Objective thirdObjective = firstQuest.GetObjectiveAtIndex(2); thirdObjective.AssignTarget(earth); // Setup spawn of enemies and friendlies so they only spawn when player reaches this objective thirdObjective.OnStarted += ThirdObjective_OnStarted; //TODO: unsubscribe to this!!! // OBJECTIVE 4 - AID IN THE FIGHT // AI only start battling when player approaches the area questManager.Add(firstQuest); questManager.SetActiveQuest(firstQuest); }
public Objective(JSONObject jo) { Slot = (ObjectiveSlot)(int)jo.GetField("slot").f; Name = jo.GetField("name").str; Description = jo.GetField("desc").str; Index = (int)jo.GetField("index").f; Target = new ObjectiveTarget(); Target.Kind = (ObjectiveKind)(int)jo.GetField("tkind").f; Target.Value = (int)jo.GetField("tval").f; Target.Scope = (ObjectiveScope)(int)jo.GetField("tscope").f; Target.Condition = (ObjectiveCondition)(int)jo.GetField("tcond").f; Target.DetailGround = (GroundVariation)(int)jo.GetField("tdg").f; Target.DetailAir = (AirVariation)(int)jo.GetField("tda").f; Target.DetailCollectible = (CollectibleVariation)(int)jo.GetField("tdc").f; if (jo.HasField("tdo")) //newly added { Target.DetailConsumable = (ObjectiveRewardType)(int)jo.GetField("tdo").f; } if (jo.HasField("reward")) { Reward = (int)jo.GetField("reward").f; } if (jo.HasField("value")) { Value = jo.GetField("value").f; } }
private void SpawnPrefabsForObjective(Quest quest, int ObjectiveIndex, GameObject shipPrefab, int spawnCount, Vector3 spawnCenter, float spawnRadius) { List <ObjectiveTarget> objectiveTargets = new List <ObjectiveTarget>(); List <GameObject> spawned = SpawnPrefabs(shipPrefab, spawnCount, spawnCenter, spawnRadius); foreach (var unit in spawned) { ObjectiveTarget target = unit.AddComponent <ObjectiveTarget>(); objectiveTargets.Add(target); } Objective objective = quest.GetObjectiveAtIndex(ObjectiveIndex); objective.AssignTargets(objectiveTargets.ToArray()); }
/// <summary> /// checks if a specified target has any associated objective and returns a string '[Objective.tag] Objective +20%', null if none. String is uncoloured. /// </summary> /// <param name="targetName"></param> /// <returns></returns> public string CheckObjectiveInfo(string targetName) { if (string.IsNullOrEmpty(targetName) == false) { //no need for error as list may well be null (no targets in this mission relate to objectives) if (mission.listOfObjectiveTargets != null) { //target present ObjectiveTarget objectiveTarget = mission.listOfObjectiveTargets.Find(x => x.target.name == targetName); //no need for error check as a match may not be present if (objectiveTarget != null) { //compose info string return(string.Format("\'{0}\' {1}{2}%", objectiveTarget.objective.tag, objectiveTarget.adjustment > 0 ? "+" : "", objectiveTarget.adjustment)); } } } else { Debug.LogError("Invalid targetName (Null)"); } return(null); }
public void AssignTarget(ObjectiveTarget target) { target.kind = kind; target.objective = this; targets = new ObjectiveTarget[] { target }; }
public void AssignTargets(ObjectiveTarget[] targets) { this.targets = targets; foreach(var target in this.targets) { target.kind = kind; target.objective = this; } }