Пример #1
0
        void CreateHooks(MissionDefinition mission)
        {
            if (mission.MissionHooks == null)
            {
                createHookAsset(mission);
            }

            if (soHooks == null || hooks != mission.MissionHooks)
            {
                hooks     = mission.MissionHooks;
                soHooks   = new SerializedObject(hooks);
                listHooks = new ReorderableList(soHooks, soHooks.FindProperty("MissionHooks"), false, true, true, true);
                listHooks.drawHeaderCallback = rect =>
                {
                    EditorGUI.LabelField(rect, "Interactive hooks", EditorStyles.boldLabel);
                };
                listHooks.drawElementCallback =
                    (Rect rect, int index, bool isActive, bool isFocused) => {
                    EditorGUI.PropertyField(rect, listHooks.serializedProperty.GetArrayElementAtIndex(index));
                };
            }

            soHooks.Update();
            listHooks.DoLayoutList();
            soHooks.ApplyModifiedProperties();
        }
Пример #2
0
        public void ConditionsMetTest_True()
        {
            factory.teamManager.calcGameProgress().ReturnsForAnyArgs(3);
            factory.gameTime.GetData().ReturnsForAnyArgs(new GameTimeData()
            {
                Date = new GameDate()
                {
                    DateTime = new DateTime(1, 1, 20)
                }
            });

            var mission = new MissionDefinition();

            mission.MissionHooks = new MissionHookList();
            mission.MissionHooks.MissionHooks = new List <MissionHook>();

            var empDef = Substitute.For <EmployeeDefinition>();

            empDef.SpawnWhenAllConditionsAreMet = true;
            empDef.GameProgress = 2;
            empDef.NumberOfDaysTillEmpCanSpawn = 10;
            empDef.MissionSucceeded            = new MissionDefinition[] { mission };
            factory.missionManager.GetData().Completed.Add(new Mission(mission));
            empDef.ItemsBought = new ItemDefinition[0];

            Assert.True(factory.ConditionsMet(empDef));
        }
Пример #3
0
    public static ActiveMission Create(MissionDefinition definition)
    {
        var result = CreateInstance<ActiveMission>();

        result.missionDefinition = definition;
        result.teams = new ActiveTeam[definition.Teams.Count];
        result.name = definition.name;

        bool firstSlot = true;

        for (int team = 0; team < result.teams.Length; ++team)
        {
            var newTeam = new ActiveTeam(definition.Teams[team]);
            
            foreach (var slot in newTeam.Slots)
            {
                slot.Status = firstSlot ? SlotStatus.Human : SlotStatus.AI;
                firstSlot = false;
            }

            result.teams[team] = newTeam;
        }

        return result;
    }
Пример #4
0
        private void createHookAsset(MissionDefinition asset)
        {
            var hooks = CreateInstance <MissionHookList>();

            CreateDirectories("Assets/Data/Missions/HookLists/");
            AssetDatabase.CreateAsset(hooks, "Assets/Data/Missions/HookLists/" + Guid.NewGuid() + ".asset");
            hooks.MissionHooks = new List <MissionHook>();
            asset.MissionHooks = hooks;
        }
Пример #5
0
 // only supporting one mission right now
 public MissionDefinition GetCurrentMission()
 {
     if (currentMission != null)
     {
         return(currentMission);
     }
     currentMission = CreateAsset <MissionDefinition>();
     return(currentMission);
 }
Пример #6
0
        public void SpawnAll(MissionDefinition.TeamDefinition teamDefinition, ActiveTeam activeTeam)
        {
            /* loop around slots, spawning players at each slot in turn until there are
             * no more players 
             */
            var slotsCount = teamDefinition.Slots.Count;
                        
            var allSpawnPoints = new List<Transform>();

            foreach (Transform spawnRoot in spawnPoints)
            {
                foreach (Transform spawnPoint in spawnRoot)
                {
                    allSpawnPoints.Add(spawnPoint);
                }
            }

            Ship firstSpawned = null;

            var spawnsCount = allSpawnPoints.Count;

            for (int slotIndex = 0; slotIndex < slotsCount; ++slotIndex)
            {
                var slotDefinition = teamDefinition.Slots[slotIndex];
                var spawnPoint = allSpawnPoints[slotIndex % spawnsCount];

                var activeSlot = activeTeam.Slots[slotIndex];
                
                if (activeSlot.Status != SlotStatus.Closed || activeSlot.Status == SlotStatus.Open)
                {
                    var ship = slotDefinition.SpawnShip(spawnPoint.position, spawnPoint.rotation, teamDefinition);

                    //first spawned ship becomnes the leader of the fleet
                    if (firstSpawned == null)
                    {
                        firstSpawned = ship;
                    }
                    else
                    {
                        SpaceTraderConfig.FleetManager.AddToFleet(firstSpawned, ship);
                    }

                    switch (activeSlot.Status)
                    {
                        case SlotStatus.AI:
                            SetupAIPlayer(ship);
                            break;
                        case SlotStatus.Human:
                            SetupHumanPlayer(ship, teamDefinition);                            
                            break;
                    }

                    activeSlot.SpawnedShip = ship;
                }
            }
        }
Пример #7
0
        public static MissionDetails generateNewMission(DestinationDetails destinationDetails)
        {
            //retrieve the matching mission definition (currently always exploration for testing)
            MissionDefinition missionDefinition = getMissionDefinition(MissionDefinition.MissionType.EXPLORATION);

            //generate mission information
            MissionDetails missionDetails = generateMissionDetails(missionDefinition, destinationDetails);

            return(missionDetails);
        }
Пример #8
0
        void CreateMissionGui()
        {
            if (asset.missionList.Count < 1)
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("This mission list is empty.");
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                return;
            }

            MissionDefinition mission = asset.missionList[viewIndex - 1];

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Filename", GUILayout.Width(146));
            EditorGUILayout.LabelField(mission.name);
            GUILayout.EndHorizontal();

            scrollPos     = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth));
            mission.Title = EditorGUILayout.TextField("Title", mission.Title);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Description", GUILayout.Width(146));
            mission.Description = EditorGUILayout.TextArea(mission.Description, EditorStyles.textArea, GUILayout.Height(80));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Success Message", GUILayout.Width(146));
            mission.MissionSucceeded = EditorGUILayout.TextArea(mission.MissionSucceeded, EditorStyles.textArea, GUILayout.Height(80));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Failure Message", GUILayout.Width(146));
            mission.MissionFailed = EditorGUILayout.TextArea(mission.MissionFailed, EditorStyles.textArea, GUILayout.Height(80));
            GUILayout.EndHorizontal();

            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            //Difficulty Dropdown
            dropdownSelected   = EditorGUILayout.Popup("Difficulty", dropdownSelected, difficultyOptions);
            mission.Difficulty = (MissionList.DifficultyOption)dropdownSelected;
            GUILayout.Label("Hardness", GUILayout.Width(146));
            mission.Hardness = EditorGUILayout.Slider(mission.Hardness, 0.5f, 10f);
            GUILayout.EndHorizontal();

            GUILayout.Space(10);
            CreateSkillSelector(mission);
            GUILayout.Space(10);
            CreateRequirements(mission);
            GUILayout.Space(10);
            CreateHooks(mission);

            EditorGUILayout.EndScrollView();
        }
Пример #9
0
        public static MissionDetails generateMissionDetails(MissionDefinition missionDefinition, DestinationDetails destinationDetails)
        {
            //generate the time it will take to complete this mission (5 seconds - 2 days)
            long missionTime = new System.Random().Next(5, 172800);

            //generate the pass rate chance of completing this mission
            float passRate = missionDefinition.basePassRate;

            //generate and return a new set of mission details using the generated data
            return(new MissionDetails(missionDefinition, destinationDetails, missionTime, passRate));
        }
Пример #10
0
        void CreateRequirements(MissionDefinition mission)
        {
            requirementsFold = EditorGUILayout.Foldout(requirementsFold, "Requirements");
            if (requirementsFold)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(25f);
                EditorGUILayout.BeginVertical();

                mission.ForceAppear = EditorGUILayout.ToggleLeft("Story mission (force appear only once)", mission.ForceAppear);
                GUILayout.Space(10);

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Appear after days", GUILayout.Width(146));
                mission.AppearAfterDays = EditorGUILayout.IntSlider(mission.AppearAfterDays, 0, 365);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Required Level", GUILayout.Width(146));
                mission.RequiredLevel = EditorGUILayout.IntSlider(mission.RequiredLevel, 0, 100);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Required Employees", GUILayout.Width(146));
                mission.RequiredEmployees = EditorGUILayout.IntSlider(mission.RequiredEmployees, 0, 4);
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(10);

                if (soRequiredMissions == null || requiredMissions != mission.RequiredMissions)
                {
                    requiredMissions     = mission.RequiredMissions;
                    soRequiredMissions   = new SerializedObject(requiredMissions);
                    listRequiredMissions = new ReorderableList(soRequiredMissions, soRequiredMissions.FindProperty("RequiredMissions"), false, true, true, true);
                    listRequiredMissions = new ReorderableList(soRequiredMissions, soRequiredMissions.FindProperty("RequiredMissions"), false, true, true, true);
                    listRequiredMissions.drawHeaderCallback = rect =>
                    {
                        EditorGUI.LabelField(rect, "Required completion of missions", EditorStyles.boldLabel);
                    };
                    listRequiredMissions.drawElementCallback =
                        (Rect rect, int index, bool isActive, bool isFocused) => {
                        EditorGUI.PropertyField(rect, listRequiredMissions.serializedProperty.GetArrayElementAtIndex(index));
                    };
                }

                soRequiredMissions.Update();
                listRequiredMissions.DoLayoutList();
                soRequiredMissions.ApplyModifiedProperties();

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }
        }
Пример #11
0
    public void ShowMissions(int index, Vector3 position)
    {
        HideMissions();
        int count = selectedMissionSet.missionDefinitions.Count;

        Add(missions = new Layout("MissionLayout", 4, count + 1, 0.25f, 0.1f, count + 1, container));
        missions.SetPosition(position + (Vector3.right * missions.width * 0.5f) + (Vector3.back * missions.height * 0.5f));

        missions.Add(new List <RenameableDeletableButton>(RenameableDeletableButton.GetButtons(count,
                                                                                               (int capturedIndex) => new RenameableDeletableButton(GetMission(capturedIndex).name, 3, 1, container,
                                                                                                                                                    fontSize: 20,
                                                                                                                                                    DeleteStay: (Button button) =>
        {
            if (Input.GetMouseButtonUp(0))
            {
                selectedMissionSet.Remove(GetMission(capturedIndex));
                ShowMissions(index, position);
            }
        },
                                                                                                                                                    EndInput: (Field field) =>
        {
            GetMission(capturedIndex).name = field.label.text;
            ShowMissions(index, position);
        },
                                                                                                                                                    Enter: (Button button) => button.SetColor(Color.green),
                                                                                                                                                    Stay: (Button button) =>
        {
            if (Input.GetMouseButtonDown(0))
            {
                selectedMission = GetMission(capturedIndex);
                selectedCampaign.Add(selectedMission, index);
                ShowCampaignMap();
                HideMissionSets();
                HideMissions();
            }
        },
                                                                                                                                                    Exit: (Button button) => button.SetColor(Color.white)))));

        missions.Add(new Button("New Mission", 4, 1, container, "NewMission",
                                fontSize: 20,
                                Enter: (Button button) => button.SetColor(Color.green),
                                Stay: (Button button) =>
        {
            if (Input.GetMouseButtonDown(0))
            {
                ScriptableObjects.Add(MissionDefinition.Default(), selectedMissionSet);
                ShowMissions(index, position);
            }
        },
                                Exit: (Button button) => button.SetColor(Color.white)), true);
    }
Пример #12
0
 public override void Remove(ScriptableObject toRemove)
 {
     if (toRemove is MissionDefinition)
     {
         MissionDefinition missionDefinition = toRemove as MissionDefinition;
         missionIndices.RemoveAt(missionDefinitions.IndexOf(missionDefinition));
         missionDefinitions.Remove(missionDefinition);
     }
     else
     {
         Connection connection = toRemove as Connection;
         connections.Remove(connection);
     }
 }
Пример #13
0
    /// <summary>
    /// Adds a mission.
    /// </summary>
    /// <param name="action">Action to be performed to complete the mission</param>
    /// <param name="quantity">Amount of targets the action must be applied to.</param>
    /// <param name="what">Target of the mission.</param>
    /// <param name="type">Type of target.</param>
    /// <param name="priority">Priority of the mission.</param>
    /// <param name="isMain">If set to <c>false</c> it is a secondary mission.</param>
    /// <param name="information">Additional information for this mission (such as a description).</param>
    public void AddMission(MissionType action, uint quantity,
                           Storage.EntityType what,
                           MissionDefinition.TargetType type, uint priority,
                           bool isMain, string information)
    {
        MissionDefinition definition = new MissionDefinition();

        definition.amount      = quantity;
        definition.information = information;
        definition.main        = isMain;
        definition.priority    = priority;
        definition.purpose     = action;
        definition.target      = what;
        definition.targetType  = type;
        missions.Add(definition);
    }
Пример #14
0
        public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label)
        {
            MissionDefinition mission = GameDatabase.ActiveInstance.GetCurrentMission();

            Debug.Assert(property.DeclaredType == typeof(int), "property.DeclaredType == typeof(int)");

            List <FactionDefinition> factions = mission.GetFactions();

            entities.Clear();
            entityNames.Clear();

            int counter      = 0;
            int currentIndex = -1;
            int currentId    = property.intValue;

            foreach (FactionDefinition faction in factions)
            {
                string factionName = $"[{faction.name}]";

                foreach (FlightGroupDefinition flightGroup in faction.flightGroups)
                {
                    string flightGroupName = $"[{flightGroup.name}]";

                    foreach (EntityDefinition entity in flightGroup.entities)
                    {
                        entityNames.Add($"{factionName}::{flightGroupName} {entity.name}");
                        if (entity.id == currentId)
                        {
                            currentIndex = counter;
                        }
                        entities.Add(entity);
                        counter++;
                    }
                }
            }

            int newIndex = EditorGUI.Popup(position, property.Label, currentIndex, entityNames.ToArray());

            if (currentIndex != newIndex)
            {
                property.Value = entities[newIndex].id;
            }
        }
Пример #15
0
    public void SelectMission(MissionDefinition mission)
    {
        selectedMission = mission;

        if (!selectedMission)
        {
            selectedMissionTitle.text = "No mission selected";
            selectedMissionDescription.text = "";
        }
        else
        {
            selectedMissionTitle.text = selectedMission.MissionName;
            selectedMissionDescription.text = selectedMission.Description;
        }

        foreach (var button in missionActionButtons)
        {
            button.interactable = !!selectedMission;
        }
    }
Пример #16
0
        public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label)
        {
            MissionDefinition mission = GameDatabase.ActiveInstance.GetCurrentMission();

            Debug.Assert(property.DeclaredType == typeof(int), "property.DeclaredType == typeof(int)");

            List <FactionDefinition> factions = mission.GetFactions();

            foreach (FactionDefinition faction in factions)
            {
                factionNames.Add(faction.name);
            }

            int currentIndex = factions.FindIndex((f) => f.id == property.intValue);
            int newIndex     = EditorGUI.Popup(position, property.Label, currentIndex, factionNames.ToArray());

            if (currentIndex != newIndex)
            {
                property.Value = factions[newIndex].id;
            }
        }
Пример #17
0
        /// <summary>
        /// Tests whether a missions requirements are fulfilled or not.
        /// </summary>
        /// <returns></returns>
        public bool RequirementsFullfilled(MissionDefinition mission)
        {
            if (mission == null)
            {
                return(false);
            }

            if (mission.Difficulty != GameSettings.Difficulty)
            {
                return(false);
            }

            if (mission.RequiredLevel != 0 &&
                EmployeeManager.Instance.GetCurrentMaxEmployeeLevel() < mission.RequiredLevel)
            {
                return(false);
            }

            if (mission.RequiredEmployees != 0 &&
                EmployeeManager.Instance.HiredEmployees < mission.RequiredEmployees)
            {
                return(false);
            }

            if (mission.AppearAfterDays != 0 && GameTime.GameTime.Instance.GetTotalGameDays() < mission.AppearAfterDays)
            {
                return(false);
            }

            foreach (var requirement in mission.RequiredMissions.RequiredMissions)
            {
                if (MissionManager.Instance.GetData().Completed.All(m => m.Definition != requirement))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #18
0
        public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label)
        {
            MissionDefinition mission = GameDatabase.ActiveInstance.GetCurrentMission();

            Debug.Assert(property.DeclaredType == typeof(int), "property.DeclaredType == typeof(int)");

            List <FlightGroupDefinition> flightGroups = mission.GetFlightGroups();

            flightGroupNames.Clear();
            foreach (FlightGroupDefinition fg in flightGroups)
            {
                string factionName = $"[{mission.GetFactionById(fg.factionId).name}]";
                flightGroupNames.Add($"{factionName} {fg.name}");
            }

            int index    = flightGroups.FindIndex((f) => f.id == property.intValue);
            int newIndex = EditorGUI.Popup(position, property.Label, index, flightGroupNames.ToArray());

            if (index != newIndex)
            {
                property.Value = flightGroups[newIndex].id;
            }
        }
Пример #19
0
        public void ConditionsMetTest_FalseMissionNotSucceeded()
        {
            factory.teamManager.calcGameProgress().ReturnsForAnyArgs(0);
            factory.gameTime.GetData().ReturnsForAnyArgs(new GameTimeData()
            {
                Date = new GameDate()
                {
                    DateTime = new DateTime(1, 1, 1)
                }
            });

            var mission = new MissionDefinition();

            var empDef = Substitute.For <EmployeeDefinition>();

            empDef.SpawnWhenAllConditionsAreMet = true;
            empDef.GameProgress                = 0;
            empDef.MissionSucceeded            = new MissionDefinition[] { mission };
            empDef.ItemsBought                 = new ItemDefinition[0];
            empDef.NumberOfDaysTillEmpCanSpawn = 0;

            Assert.False(factory.ConditionsMet(empDef));
        }
Пример #20
0
        void CreateSkillSelector(MissionDefinition mission)
        {
            skillFold = EditorGUILayout.Foldout(skillFold, "Required Skills");
            if (skillFold)
            {
                if (!EditorPrefs.HasKey("AssetPath" + "Skill"))
                {
                    GUILayout.Label("Please create a SkillSet first. This is required.");
                    return;
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(25f);
                EditorGUILayout.BeginVertical();
                string objectPath = EditorPrefs.GetString("AssetPath" + "Skill");
                var    skillSet   = AssetDatabase.LoadAssetAtPath(objectPath, typeof(SkillSet)) as SkillSet;
                CleanSkills(skillSet);
                if (skillSet != null)
                {
                    foreach (var skillDefinition in skillSet.keys)
                    {
                        bool isUsed = mission.SkillsRequired.Contains(skillDefinition);
                        isUsed = EditorGUILayout.ToggleLeft(skillDefinition.skillName, isUsed);
                        if (isUsed && !mission.SkillsRequired.Contains(skillDefinition))
                        {
                            mission.SkillsRequired.Add(skillDefinition);
                        }
                        else if (!isUsed && mission.SkillsRequired.Contains(skillDefinition))
                        {
                            mission.SkillsRequired.Remove(skillDefinition);
                        }
                    }
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }
        }
Пример #21
0
 /// <summary>
 /// Adds a mission.
 /// </summary>
 /// <param name="action">Action to be performed to complete the mission</param>
 /// <param name="quantity">Amount of targets the action must be applied to.</param>
 /// <param name="what">Target of the mission.</param>
 /// <param name="type">Type of target.</param>
 /// <param name="priority">Priority of the mission.</param>
 /// <param name="isMain">If set to <c>false</c> it is a secondary mission.</param>
 /// <param name="information">Additional information for this mission (such as a description).</param>
 public void AddMission(MissionType action, uint quantity,
                        Storage.EntityType what,
                        MissionDefinition.TargetType type, uint priority,
                        bool isMain, string information)
 {
     MissionDefinition definition = new MissionDefinition();
     definition.amount = quantity;
     definition.information = information;
     definition.main = isMain;
     definition.priority = priority;
     definition.purpose = action;
     definition.target = what;
     definition.targetType = type;
     missions.Add(definition);
 }
Пример #22
0
 public void AddMission(MissionDefinition definition)
 {
     missions.Add(definition);
 }
Пример #23
0
 private void SetupHumanPlayer(Ship ship, MissionDefinition.TeamDefinition teamDef)
 {
     var player = ship.gameObject.AddComponent<PlayerShip>();
     SpaceTraderConfig.LocalPlayer = player;
 }
Пример #24
0
 public void AddMission(MissionDefinition definition)
 {
     missions.Add(definition);
 }
Пример #25
0
 public int GetMissionIndex(MissionDefinition missionDefinition) => missionIndices[missionDefinitions.IndexOf(missionDefinition)];
Пример #26
0
 private void SetSelectedMission(MissionDefinition missionDefinition) => _editor.missionEditor.SetSelectedMission(missionDefinition);
Пример #27
0
 public Mission(int index, MissionDefinition missionDefinition)
 {
     this.index         = index;
     _missionDefinition = missionDefinition;
 }
Пример #28
0
    public IEnumerator SessionHandler(Session session, CampaignDefinition selectedCampaign, int selectedCampaignIndex)
    {
        if (!Definitions.initialized)
        {
            Definitions.Initialize(Assets.Get(Assets.ObjectDataSets.Default));
        }

        session.Hide();

        while (!session.player.progress.HasCampaignProgress(selectedCampaignIndex))
        {
            session.player.progress.AddCampaignProgress();
        }

        MissionDefinition missionDefinition = session.player.progress.IsNewGame(selectedCampaignIndex) ? selectedCampaign.GetMissionDefinition(selectedCampaign.firstMissionIndex) : null;
        int missionIndex = selectedCampaign.firstMissionIndex;

        if (missionDefinition == null)
        {
            Vector3     offset         = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, Camera.main.transform.position.y)) + (Vector3.left * selectedCampaign.width * 0.5f) + (Vector3.forward * selectedCampaign.height * 0.5f);
            CampaignMap campaignMap    = new CampaignMap(selectedCampaign.width, selectedCampaign.height, selectedCampaign.columns, selectedCampaign.rows, offset);
            Layout      campaignLayout = new Layout("Campaign", gameObject);

            for (int i = 0; campaignMap.tileMap.count > i; i++)
            {
                int iIndex = i;

                if (selectedCampaign.Has(i) && session.player.progress.HasCompleted(selectedCampaignIndex, i))
                {
                    Button button = new Button(selectedCampaign.GetMissionDefinition(i).name, campaignMap.tileMap.tileWidth - 1, campaignMap.tileMap.tileHeight * 0.5f, gameObject, "CampaignMap" + i,
                                               fontSize: 20,
                                               Enter: (Button b) => b.SetColor(Color.green),
                                               Stay: (Button b) =>
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            missionIndex      = iIndex;
                            missionDefinition = selectedCampaign.GetMissionDefinition(iIndex);
                        }
                    },
                                               Exit: (Button b) => b.SetColor(Color.cyan));

                    campaignLayout.Add(button);
                    button.SetColor(Color.cyan);
                    button.SetPosition(campaignMap.tileMap.PositionOf(i));

                    for (int j = 0; selectedCampaign.connections.Count > j; j++)
                    {
                        int jIndex = j;
                        if (selectedCampaign.connections[j].fromIndex == i)
                        {
                            if (!session.player.progress.HasCompleted(selectedCampaignIndex, selectedCampaign.connections[j].toIndex))
                            {
                                Button butt = new Button(selectedCampaign.GetMissionDefinition(selectedCampaign.connections[j].toIndex).name, campaignMap.tileMap.tileWidth - 1, campaignMap.tileMap.tileHeight * 0.5f, gameObject, "CampaignMap" + selectedCampaign.connections[j].toIndex,
                                                         fontSize: 20,
                                                         Enter: (Button b) => b.SetColor(Color.green),
                                                         Stay: (Button b) =>
                                {
                                    if (Input.GetMouseButtonDown(0))
                                    {
                                        missionIndex      = selectedCampaign.connections[jIndex].toIndex;
                                        missionDefinition = selectedCampaign.GetMissionDefinition(selectedCampaign.connections[jIndex].toIndex);
                                    }
                                },
                                                         Exit: (Button b) => b.SetColor(Color.white));

                                campaignLayout.Add(butt);
                                butt.SetPosition(campaignMap.tileMap.PositionOf(selectedCampaign.connections[jIndex].toIndex));
                            }
                        }
                    }
                }
            }

            while (missionDefinition == null)
            {
                campaignLayout.Update();
                yield return(null);
            }

            campaignLayout.Hide();
            campaignLayout.Destroy();
        }

        GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);

        quad.transform.rotation   = Quaternion.Euler(90, 0, 0);
        quad.transform.position   = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, Camera.main.transform.position.y));
        quad.transform.localScale = new Vector3(12, 4, 1);

        TextMesh textMesh = new GameObject("StartText").AddComponent <TextMesh>();

        textMesh.transform.localRotation = quad.transform.rotation;
        textMesh.transform.SetPositionAndRotation(quad.transform.position + Vector3.up, quad.transform.rotation);
        textMesh.fontSize      = 200;
        textMesh.color         = Color.black;
        textMesh.characterSize = 0.15f;
        textMesh.anchor        = TextAnchor.MiddleCenter;
        textMesh.alignment     = TextAlignment.Center;
        textMesh.text          = "START";

        float wait = Time.time + 3;

        while (wait > Time.time)
        {
            yield return(null);
        }

        quad.SetActive(false);
        textMesh.gameObject.SetActive(false);

        StageDefinition stageDefinition = missionDefinition.stageDefinition;

        session.SetConveyor(new Conveyor(
                                speed: 7,
                                width: 4,
                                height: 15 + (1 * (stageDefinition.laneCount - 1)),
                                itemInterval: 1,
                                itemLimit: 8,
                                itemWidthPadding: 1,
                                itemSpacing: 0.1f));

        session.SetStage(new Stage(stageDefinition, session.player, session.conveyor));

        Level level = new Level(missionDefinition.duration);

        for (int i = 0; missionDefinition.waveDefinitions.Count > i; i++)
        {
            Wave wave = new Wave(missionDefinition.waveTimes[i] * missionDefinition.duration, session.stage);
            level.Add(wave);

            for (int j = 0; missionDefinition.waveDefinitions[i].waveEvents.Count > j; j++)
            {
                switch ((WaveEvent.Type)missionDefinition.waveDefinitions[i].waveEvents[j].type)
                {
                case WaveEvent.Type.SpawnEnemy:
                    wave.Add(new SpawnEnemyEvent(Definitions.Enemy(Definitions.Enemies.Mini), missionDefinition.waveDefinitions[i].waveEvents[j]));
                    break;
                }
            }
        }

        session.SetLevel(level);
        session.Show();

        int heroCount = session.player.inventory.heroes.Count;
        int start     = heroCount == 1
            ? 2
            : heroCount == 2
                ? 1
                : 0;

        int stride = start == 2
            ? 0
            : 2;

        for (int i = 0; session.player.inventory.heroes.Count > i; i++)
        {
            session.stage.AddHero(session.stage.LaneBy(start + (stride * i)), Definitions.Hero(Definitions.Heroes.Default));
        }

        while (1 > session.level.progress || session.stage.enemies > 0 || session.stage.items > 0)
        {
            session.Update(1 > session.level.progress || session.stage.enemies > 0);
            yield return(null);
        }

        quad.SetActive(true);
        textMesh.gameObject.SetActive(true);
        session.stage.DestroyLanes();
        session.level.HideProgress();
        session.coinCounter.Hide();

        if (session.heldItem != null)
        {
            session.heldItem.conveyorItem.Destroy();
            session.heldItem.Destroy();
        }

        session.Destroy();

        textMesh.text = "STOP";
        wait          = Time.time + 3;

        while (wait > Time.time)
        {
            yield return(null);
        }

        quad.SetActive(false);
        textMesh.gameObject.SetActive(false);
        Destroy(textMesh.gameObject);
        Destroy(quad);

        //boss warning?
        //boss battle?

        //end of level fanfare

        if (!session.player.progress.HasCompleted(selectedCampaignIndex, missionIndex))
        {
            session.player.progress.AddCompleted(selectedCampaignIndex, missionIndex);
        }

        Shop shop = new Shop();

        shop.Show(session.player);

        while (!Input.GetMouseButtonDown(1))
        {
            shop.Update();
            yield return(null);
        }

        shop.Hide();

        PlayerPrefs.SetString(session.player.name, JsonUtility.ToJson(session.player));
        PlayerPrefs.Save();

        StartSession(session.player, selectedCampaign, selectedCampaignIndex);
    }
Пример #29
0
 public void SetSelectedMission(MissionDefinition selectedMission) => this.selectedMission          = selectedMission;
Пример #30
0
 public void Add(int index, MissionDefinition missionDefinition) => missions.Add(new Mission(index, missionDefinition));