示例#1
0
        public async Task <bool> CanAcceptAsync(int id)
        {
            await using var ctx = new CdClientContext();

            var mission = await ctx.MissionsTable.FirstAsync(m => m.Id == id);

            return(MissionParser.CheckPrerequiredMissions(
                       mission.PrereqMissionID,
                       GetCompletedMissions()
                       ));
        }
        // TODO: Improve
        private async Task SearchForNewAchievementsAsync <T>(MissionTaskType type, Lot lot, Func <T, Task> progress = null) where T : MissionTaskBase
        {
            await using var cdClient = new CdClientContext();

            //
            // Collect tasks which fits the requirements of this action.
            //

            var otherTasks = new List <MissionTasks>();

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var missionTask in cdClient.MissionTasksTable)
            {
                if (MissionParser.GetTargets(missionTask).Contains(lot))
                {
                    otherTasks.Add(missionTask);
                }
            }

            foreach (var task in otherTasks)
            {
                var mission = await cdClient.MissionsTable.FirstOrDefaultAsync(m => m.Id == task.Id);

                if (mission == default)
                {
                    continue;
                }

                //
                // Check if mission is an achievement and has a task of the correct type.
                //

                if (mission.OfferobjectID != -1 ||
                    mission.TargetobjectID != -1 ||
                    (mission.IsMission ?? true) ||
                    task.TaskType != (int)type)
                {
                    continue;
                }

                //
                // Get the mission on the character. If present.
                //

                var characterMission = MissionInstances.FirstOrDefault(m => m.MissionId == mission.Id);

                //
                // Check if the player could passably start this achievement.
                //

                if (characterMission != default)
                {
                    continue;
                }

                //
                // Check if player has the Prerequisites to start this achievement.
                //

                var hasPrerequisites = MissionParser.CheckPrerequiredMissions(
                    mission.PrereqMissionID,
                    GetCompletedMissions()
                    );

                if (!hasPrerequisites)
                {
                    continue;
                }

                //
                // Player can start achievement.
                //

                // Get Mission Id of new achievement.
                if (mission.Id == default)
                {
                    continue;
                }

                var missionId = mission.Id.Value;

                //
                // Setup new achievement.
                //

                var instance = new MissionInstance(GameObject as Player, missionId);

                MissionInstances.Add(instance);

                await instance.LoadAsync();

                // TODO: Silent?
                await instance.StartAsync();

                var activeTask = instance.Tasks.First(t => t.TaskId == task.Uid);

                if (progress != null)
                {
                    Detach(async() =>
                    {
                        await progress(activeTask as T);
                    });
                }
            }
        }
示例#3
0
        private async Task <bool> RequiredForNewAchievementsAsync(MissionTaskType type, Lot lot)
        {
            await using var cdClient = new CdClientContext();

            //
            // Collect tasks which fits the requirements of this action.
            //

            var otherTasks = new List <MissionTasks>();

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var missionTask in ClientCache.Tasks)
            {
                if (MissionParser.GetTargets(missionTask).Contains(lot))
                {
                    otherTasks.Add(missionTask);
                }
            }

            foreach (var task in otherTasks)
            {
                var mission = await cdClient.MissionsTable.FirstOrDefaultAsync(m => m.Id == task.Id);

                if (mission == default)
                {
                    continue;
                }

                //
                // Check if mission is an achievement and has a task of the correct type.
                //

                if (mission.OfferobjectID != -1 ||
                    mission.TargetobjectID != -1 ||
                    (mission.IsMission ?? true) ||
                    task.TaskType != (int)type)
                {
                    continue;
                }

                //
                // Get the mission on the character. If present.
                //

                MissionInstance characterMission;

                await Lock.WaitAsync();

                try
                {
                    characterMission = MissionInstances.FirstOrDefault(m => m.MissionId == mission.Id);
                }
                finally
                {
                    Lock.Release();
                }

                //
                // Check if the player could passably start this achievement.
                //

                if (characterMission != default)
                {
                    continue;
                }

                //
                // Check if player has the Prerequisites to start this achievement.
                //

                var hasPrerequisites = MissionParser.CheckPrerequiredMissions(
                    mission.PrereqMissionID,
                    GetCompletedMissions()
                    );

                if (hasPrerequisites)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
        //Engine file constructor
        public Level(string enginePath)
        {
            path = Path.GetDirectoryName(enginePath);

            // Engine elements
            using (EngineParser engineParser = new EngineParser(enginePath))
            {
                game = engineParser.GetGameType();

                //REMOVE THESE ASAP!!!!!111
                renderDefBytes   = engineParser.GetRenderDefBytes();
                collBytesEngine  = engineParser.GetCollisionBytes();
                billboardBytes   = engineParser.GetBillboardBytes();
                soundConfigBytes = engineParser.GetSoundConfigBytes();

                LOGGER.Debug("Parsing skybox...");
                skybox = engineParser.GetSkyboxModel();
                LOGGER.Debug("Success");

                LOGGER.Debug("Parsing moby models...");
                mobyModels = engineParser.GetMobyModels();
                LOGGER.Debug("Added {0} moby models", mobyModels.Count);

                LOGGER.Debug("Parsing tie models...");
                tieModels = engineParser.GetTieModels();
                LOGGER.Debug("Added {0} tie models", tieModels.Count);

                LOGGER.Debug("Parsing shrub models...");
                shrubModels = engineParser.GetShrubModels();
                LOGGER.Debug("Added {0} shrub models", shrubModels.Count);

                LOGGER.Debug("Parsing weapons...");
                gadgetModels = engineParser.GetGadgets();
                LOGGER.Debug("Added {0} weapons", gadgetModels.Count);

                LOGGER.Debug("Parsing textures...");
                textures = engineParser.GetTextures();
                LOGGER.Debug("Added {0} textures", textures.Count);

                LOGGER.Debug("Parsing ties...");
                ties = engineParser.GetTies(tieModels);
                LOGGER.Debug("Added {0} ties", ties.Count);

                LOGGER.Debug("Parsing Shrubs...");
                shrubs = engineParser.GetShrubs(shrubModels);
                LOGGER.Debug("Added {0} shrubs", shrubs.Count);

                LOGGER.Debug("Parsing Lights...");
                lights = engineParser.GetLights();
                LOGGER.Debug("Added {0} lights", lights.Count);

                LOGGER.Debug("Parsing terrain elements...");
                terrainEngine = engineParser.GetTerrainModel();
                LOGGER.Debug("Added {0} terrain elements", terrainEngine.fragments.Count);

                LOGGER.Debug("Parsing player animations...");
                playerAnimations = engineParser.GetPlayerAnimations((MobyModel)mobyModels[0]);
                LOGGER.Debug("Added {0} player animations", playerAnimations.Count);

                uiElements = engineParser.GetUiElements();
                LOGGER.Debug("Added {0} ui elements", uiElements.Count);

                lightConfig        = engineParser.GetLightConfig();
                textureConfigMenus = engineParser.GetTextureConfigMenu();

                collisionEngine = engineParser.GetCollisionModel();

                unk3 = engineParser.GetUnk3Bytes();
                unk4 = engineParser.GetUnk4Bytes();
                unk5 = engineParser.GetUnk5Bytes();
                unk8 = engineParser.GetUnk8Bytes();
                unk9 = engineParser.GetUnk9Bytes();
            }


            // Gameplay elements
            using (GameplayParser gameplayParser = new GameplayParser(game, path + @"/gameplay_ntsc"))
            {
                LOGGER.Debug("Parsing Level variables...");
                levelVariables = gameplayParser.GetLevelVariables();

                LOGGER.Debug("Parsing mobs...");
                mobs = gameplayParser.GetMobies(mobyModels);
                LOGGER.Debug("Added {0} mobs", mobs.Count);

                LOGGER.Debug("Parsing splines...");
                splines = gameplayParser.GetSplines();
                LOGGER.Debug("Added {0} splines", splines.Count);

                LOGGER.Debug("Parsing languages...");
                english   = gameplayParser.GetEnglish();
                ukenglish = gameplayParser.GetUkEnglish();
                french    = gameplayParser.GetFrench();
                german    = gameplayParser.GetGerman();
                spanish   = gameplayParser.GetSpanish();
                italian   = gameplayParser.GetItalian();
                japanese  = gameplayParser.GetJapanese();
                korean    = gameplayParser.GetKorean();

                LOGGER.Debug("Parsing other gameplay assets...");
                unk6  = gameplayParser.GetUnk6();
                unk7  = gameplayParser.GetUnk7();
                unk12 = gameplayParser.GetUnk12();
                unk13 = gameplayParser.GetUnk13();
                unk14 = gameplayParser.GetUnk14();
                unk16 = gameplayParser.GetUnk16();
                unk17 = gameplayParser.GetUnk17();
                unk18 = gameplayParser.GetUnk18();

                tieData   = gameplayParser.GetTieData(ties.Count);
                shrubData = gameplayParser.GetShrubData(shrubs.Count);

                tieGroupData   = gameplayParser.GetTieGroups();
                shrubGroupData = gameplayParser.GetShrubGroups();

                areasData = gameplayParser.GetAreasData();

                directionalLights = gameplayParser.GetDirectionalLights();
                type0Cs           = gameplayParser.GetType0Cs();
                spheres           = gameplayParser.GetSpheres();
                cylinders         = gameplayParser.GetCylinders();
                type4Cs           = gameplayParser.GetType4Cs();
                type7Cs           = gameplayParser.GetType7Cs();
                type80s           = gameplayParser.GetType80();
                type88s           = gameplayParser.GetType88s();
                type50s           = gameplayParser.GetType50s();
                type5Cs           = gameplayParser.GetType5Cs();

                pVars       = gameplayParser.GetPvars(mobs);
                cuboids     = gameplayParser.GetCuboids();
                gameCameras = gameplayParser.GetGameCameras();

                mobyIds       = gameplayParser.GetMobyIds();
                tieIds        = gameplayParser.GetTieIds();
                shrubIds      = gameplayParser.GetShrubIds();
                occlusionData = gameplayParser.GetOcclusionData();
            }

            terrainChunks   = new List <Terrain>();
            collisionChunks = new List <Model>();
            collBytesChunks = new List <byte[]>();

            for (int i = 0; i < 5; i++)
            {
                var chunkPath = Path.Join(path, @"chunk" + i + ".ps3");
                if (!File.Exists(chunkPath))
                {
                    continue;
                }

                using (ChunkParser chunkParser = new ChunkParser(chunkPath, game))
                {
                    terrainChunks.Add(chunkParser.GetTerrainModels());
                    collisionChunks.Add(chunkParser.GetCollisionModel());
                    collBytesChunks.Add(chunkParser.GetCollBytes());
                }
            }

            List <string> armorPaths = ArmorHeader.FindArmorFiles(game, enginePath);

            armorModels   = new List <Model>();
            armorTextures = new List <List <Texture> >();

            foreach (string armor in armorPaths)
            {
                LOGGER.Debug("Looking for armor data in {0}", armor);
                List <Texture> tex;
                MobyModel      model;
                using (ArmorParser parser = new ArmorParser(game, armor))
                {
                    tex   = parser.GetTextures();
                    model = parser.GetArmor();
                }

                string vram = armor.Replace(".ps3", ".vram");

                using (VramParser parser = new VramParser(vram))
                {
                    parser.GetTextures(tex);
                }

                if (model != null)
                {
                    armorModels.Add(model);
                }

                armorTextures.Add(tex);
            }

            string gadgetPath = GadgetHeader.FindGadgetFile(game, enginePath);

            gadgetTextures = new List <Texture>();

            if (gadgetPath != "")
            {
                LOGGER.Debug("Looking for gadget data in {0}", gadgetPath);
                using (GadgetParser parser = new GadgetParser(game, gadgetPath))
                {
                    gadgetModels.AddRange(parser.GetModels());
                    gadgetTextures.AddRange(parser.GetTextures());
                }

                using (VramParser parser = new VramParser(gadgetPath.Replace(".ps3", ".vram")))
                {
                    parser.GetTextures(gadgetTextures);
                }
            }

            List <string> missionPaths = MissionHeader.FindMissionFiles(game, enginePath);

            missions = new List <Mission>();

            for (int i = 0; i < missionPaths.Count; i++)
            {
                string missionPath = missionPaths[i];
                string vramPath    = missionPath.Replace(".ps3", ".vram");

                if (!File.Exists(vramPath))
                {
                    LOGGER.Warn("Could not find .vram file for {0}", missionPath);
                    continue;
                }

                LOGGER.Debug("Looking for mission data in {0}", missionPath);

                Mission mission = new Mission(i);

                using (MissionParser parser = new MissionParser(game, missionPath))
                {
                    mission.models   = parser.GetModels();
                    mission.textures = parser.GetTextures();
                }

                using (VramParser parser = new VramParser(vramPath))
                {
                    parser.GetTextures(mission.textures);
                }

                missions.Add(mission);
            }

            using (VramParser vramParser = new VramParser(path + @"/vram.ps3"))
            {
                vramParser.GetTextures(textures);
            }

            LOGGER.Info("Level parsing done");
            valid = true;
        }
 /// <summary>
 /// Checks if the player can accept a mission based on whether it's repeatable, already started and if the
 /// requirements are met.
 /// </summary>
 /// <param name="mission"></param>
 /// <returns><c>true</c> if the player can accept this mission, <c>false</c> otherwise</returns>
 public bool CanAccept(MissionInstance mission) =>
 (mission.CanRepeat || !HasMission(mission.MissionId)) &&
 MissionParser.CheckPrerequiredMissions(mission.PrerequisiteMissions, AllMissions);
示例#6
0
 /// <summary>
 /// Updates the progress for this task, a notification is sent to the client
 /// </summary>
 /// <param name="value">The value to add to the progress</param>
 /// <example>
 /// If the player were to obtain a certain amount of collectibles, <c>value</c> might be the item lot here.
 /// </example>
 protected void AddProgress(float value)
 {
     if (this.Mission.Player.TryGetComponent <MissionInventoryComponent>(out var missionInventoryComponent) && !MissionParser.CheckPrerequiredMissions(this.Mission.PrerequisiteMissions, missionInventoryComponent.AllMissions))
     {
         return;
     }
     Progress.Add(value);
     MessageUpdateMissionTask();
 }