public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddDestroyWholeUnitChunk] Adding encounter structure");
            EncounterLayerData     encounterLayerData = MissionControl.Instance.EncounterLayerData;
            DestroyWholeLanceChunk destroyWholeChunk  = ChunkFactory.CreateDestroyWholeLanceChunk();

            destroyWholeChunk.encounterObjectGuid = System.Guid.NewGuid().ToString();

            this.objectiveLabel = MissionControl.Instance.CurrentContract.Interpolate(this.objectiveLabel).ToString();

            bool spawnOnActivation             = true;
            LanceSpawnerGameLogic lanceSpawner = LanceSpawnerFactory.CreateLanceSpawner(
                destroyWholeChunk.gameObject,
                spawnerName,
                lanceGuid,
                teamGuid,
                spawnOnActivation,
                SpawnUnitMethodType.InstantlyAtSpawnPoint,
                unitGuids
                );
            LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef(lanceSpawner);

            bool showProgress = true;
            DestroyLanceObjective objective = ObjectiveFactory.CreateDestroyLanceObjective(
                objectiveGuid,
                destroyWholeChunk.gameObject,
                lanceSpawnerRef,
                lanceGuid,
                objectiveLabel,
                showProgress,
                ProgressFormat.PERCENTAGE_COMPLETE,
                "The primary objective to destroy the enemy lance",
                priority,
                displayToUser,
                ObjectiveMark.AttackTarget,
                contractObjectiveGameLogicGuid,
                Main.Settings.ActiveAdditionalLances.GetRewards()
                );

            if (isPrimary)
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objective, true);
            }
            else
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objective, false);
            }

            DestroyLanceObjectiveRef destroyLanceObjectiveRef = new DestroyLanceObjectiveRef();

            destroyLanceObjectiveRef.encounterObject = objective;

            destroyWholeChunk.lanceSpawner     = lanceSpawnerRef;
            destroyWholeChunk.destroyObjective = destroyLanceObjectiveRef;
        }
Esempio n. 2
0
        private void BuildDestroyWholeLanceObjective(GameObject parent, JObject objective, string name, string title, string guid,
                                                     bool isPrimaryObjectve, int priority, bool displayToUser, string contractObjectiveGuid)
        {
            DestroyWholeLanceChunk destroyWholeLanceChunk = parent.GetComponent <DestroyWholeLanceChunk>();
            string lanceToDestroyGuid          = objective["LanceToDestroyGuid"].ToString();
            Dictionary <string, float> rewards = (objective.ContainsKey("Rewards")) ? objective["Rewards"].ToObject <Dictionary <string, float> >() : new Dictionary <string, float>();
            bool showProgress = true;

            LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef();

            lanceSpawnerRef.EncounterObjectGuid = lanceToDestroyGuid;

            DestroyLanceObjective objectiveLogic = ObjectiveFactory.CreateDestroyLanceObjective(
                guid,
                parent,
                lanceSpawnerRef,
                lanceToDestroyGuid,
                title,
                showProgress,
                ChunkLogic.ProgressFormat.PERCENTAGE_COMPLETE,
                "The primary objective to destroy the enemy lance",
                priority,
                displayToUser,
                ObjectiveMark.AttackTarget,
                contractObjectiveGuid,
                rewards,
                rewards.Count > 0
                );

            if (isPrimaryObjectve)
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objectiveLogic, true);
            }
            else
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objectiveLogic, false);
            }

            DestroyLanceObjectiveRef destroyLanceObjectiveRef = new DestroyLanceObjectiveRef();

            destroyLanceObjectiveRef.encounterObject = objectiveLogic;

            if (destroyWholeLanceChunk != null)
            {
                destroyWholeLanceChunk.lanceSpawner     = lanceSpawnerRef;
                destroyWholeLanceChunk.destroyObjective = destroyLanceObjectiveRef;
            }
        }
Esempio n. 3
0
        private void BuildDestroyWholeLanceObjective(GameObject parent, JObject objective, string name, string title, string guid,
                                                     bool isPrimaryObjectve, int priority, string contractObjectiveGuid)
        {
            DestroyWholeLanceChunk destroyWholeLanceChunk = parent.GetComponent <DestroyWholeLanceChunk>();
            string lanceToDestroyGuid = objective["LanceToDestroyGuid"].ToString();
            bool   showProgress       = true;
            bool   displayToUser      = true;

            LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef();

            lanceSpawnerRef.EncounterObjectGuid = lanceToDestroyGuid;

            DestroyLanceObjective objectiveLogic = ObjectiveFactory.CreateDestroyLanceObjective(
                guid,
                parent,
                lanceSpawnerRef,
                lanceToDestroyGuid,
                title,
                showProgress,
                ChunkLogic.ProgressFormat.PERCENTAGE_COMPLETE,
                "The primary objective to destroy the enemy lance",
                priority,
                displayToUser,
                ObjectiveMark.AttackTarget,
                contractObjectiveGuid,
                false // Don't create the objective override as it's provided by the contract json
                );

            if (isPrimaryObjectve)
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objectiveLogic, true);
            }
            else
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objectiveLogic, false);
            }

            DestroyLanceObjectiveRef destroyLanceObjectiveRef = new DestroyLanceObjectiveRef();

            destroyLanceObjectiveRef.encounterObject = objectiveLogic;

            destroyWholeLanceChunk.lanceSpawner     = lanceSpawnerRef;
            destroyWholeLanceChunk.destroyObjective = destroyLanceObjectiveRef;
        }
        public static DestroyLanceObjective CreateDestroyLanceObjective(string objectiveGuid, GameObject parent, LanceSpawnerRef lanceToDestroy, string lanceGuid, string title, bool showProgress,
                                                                        string progressFormat, string description, int priority, bool displayToUser, ObjectiveMark markUnitsWith, string contractObjectiveGameLogicGuid, bool createObjectiveOverride = true)
        {
            // TODO: Probably want to split out these two main chunks into their own methods
            // OBJECTIVE OBJECTIVE GAME LOGIC
            GameObject destroyWholeLanceObjectiveGo = CreateGameObject(parent, $"Objective_DestroyLance_{lanceGuid}");

            DestroyLanceObjective destroyLanceObjective = destroyWholeLanceObjectiveGo.AddComponent <DestroyLanceObjective>();

            destroyLanceObjective.encounterObjectGuid = objectiveGuid;
            destroyLanceObjective.title          = title;
            destroyLanceObjective.showProgress   = showProgress;
            destroyLanceObjective.progressFormat = progressFormat;
            destroyLanceObjective.description    = description;
            destroyLanceObjective.priority       = priority;
            destroyLanceObjective.displayToUser  = displayToUser;
            destroyLanceObjective.markUnitsWith  = markUnitsWith;
            destroyLanceObjective.lanceToDestroy = lanceToDestroy;

            // Rewards
            List <SimGameEventResult>           onSuccessResults = new List <SimGameEventResult>();
            List <Dictionary <string, string> > rewards          = Main.Settings.ActiveAdditionalLances.RewardsPerLance;

            foreach (Dictionary <string, string> reward in rewards)
            {
                string type  = Main.Settings.ActiveAdditionalLances.GetRewardType(reward);
                float  value = Main.Settings.ActiveAdditionalLances.GetRewardValue(reward);
                onSuccessResults.Add(CreateRewardResult(type, value));
            }

            destroyLanceObjective.OnSuccessResults  = onSuccessResults;
            destroyLanceObjective.onSuccessDialogue = new DialogueRef();
            destroyLanceObjective.onFailureDialogue = new DialogueRef();

            ContractObjectiveGameLogic contractObjectiveGameLogic = null;

            if (contractObjectiveGameLogicGuid == null)
            {
                // For ease of user we track objectives, by default, against the first contract objective
                contractObjectiveGameLogic = MissionControl.Instance.EncounterLayerData.GetComponent <ContractObjectiveGameLogic>();
            }
            else
            {
                contractObjectiveGameLogic = MissionControl.Instance.EncounterLayerData.GetContractObjectiveGameLogicByGUID(contractObjectiveGameLogicGuid);
            }

            if (contractObjectiveGameLogic == null)
            {
                Main.Logger.LogError($"[CreateDestroyLanceObjective] Contract Objective is null!");
            }

            ObjectiveRef objectiveRef = new ObjectiveRef(destroyLanceObjective);

            contractObjectiveGameLogic.objectiveRefList.Add(objectiveRef);

            // OBJECTIVE OVERRIDE - This is needed otherwise the results don't apply in the 'End Contract' screen
            // IF - the objective override is not specified in the contract override .json
            if (createObjectiveOverride)
            {
                ObjectiveOverride objectiveOverride = new ObjectiveOverride(destroyLanceObjective);
                objectiveOverride.title                 = destroyLanceObjective.title;
                objectiveOverride.description           = destroyLanceObjective.description;
                objectiveOverride.OnSuccessResults      = destroyLanceObjective.OnSuccessResults;
                objectiveOverride.OnFailureResults      = destroyLanceObjective.OnFailureResults;
                objectiveOverride.OnSuccessDialogueGUID = destroyLanceObjective.onSuccessDialogue.EncounterObjectGuid;
                objectiveOverride.OnFailureDialogueGUID = destroyLanceObjective.onFailureDialogue.EncounterObjectGuid;
                MissionControl.Instance.CurrentContract.Override.objectiveList.Add(objectiveOverride);
            }

            return(destroyLanceObjective);
        }