Пример #1
0
    public static int MakeCreation(string path)
    {
        TextAsset aseet = Resources.Load <TextAsset>(path);
        VCIsoData iso   = new VCIsoData();

        iso.Import(aseet.bytes, new VCIsoOption(false));
        // Multi player
        if (s_MultiplayerMode)
        {
            if (!VCConfig.s_Categories.ContainsKey(iso.m_HeadInfo.Category))
            {
                return(-1);
            }
            byte[] isodata = iso.Export();
            if (isodata == null || isodata.Length <= 0)
            {
                return(-1);
            }
            ulong hash   = CRC64.Compute(isodata);
            ulong fileId = SteamWorkShop.GetFileHandle(hash);
            VCGameMediator.SendIsoDataToServer(iso.m_HeadInfo.Name, iso.m_HeadInfo.SteamDesc,
                                               iso.m_HeadInfo.SteamPreview, isodata, SteamWorkShop.AddNewVersionTag(iso.m_HeadInfo.ScenePaths()), true, fileId, true);

            return(0);
        }
        else
        {
            CreationData new_creation = new CreationData();
            new_creation.m_ObjectID   = CreationMgr.QueryNewId();
            new_creation.m_RandomSeed = UnityEngine.Random.value;
            new_creation.m_Resource   = iso.Export();
            new_creation.ReadRes();

            // Attr
            new_creation.GenCreationAttr();
            if (new_creation.m_Attribute.m_Type == ECreation.Null)
            {
                Debug.LogWarning("Creation is not a valid type !");
                new_creation.Destroy();
                return(-1);
            }

            // SaveRes
            if (new_creation.SaveRes())
            {
                new_creation.BuildPrefab();
                new_creation.Register();
                CreationMgr.AddCreation(new_creation);
                ItemAsset.ItemObject item;
                int send_retval = new_creation.SendToPlayer(out item);

                Debug.Log("Make creation succeed !");
                if (send_retval == 0)
                {
                    return(-1);  // Error
                }
                else if (send_retval == -1)
                {
                    return(-4);  // Item Package Full
                }
                else
                {
                    if (OnMakeCreation != null)
                    {
                        OnMakeCreation();
                    }
                    return(0);   // Succeed
                }
            }
            else
            {
                Debug.LogWarning("Save creation resource file failed !");
                new_creation.Destroy();
                return(-3);
            }
        }
    }
Пример #2
0
    public static void CopyCretion(ECreation type)
    {
        Pathea.PlayerPackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>();
        if (null == pkg)
        {
            return;
        }
        List <int> creationInstanceid = pkg.package.GetCreationInstanceId(type);

        if (creationInstanceid == null || creationInstanceid.Count == 0)
        {
            return;
        }
        CreationData cd = CreationMgr.GetCreation(creationInstanceid[0]);

        if (Pathea.PeGameMgr.IsMulti)
        {
            ulong hash   = CRC64.Compute(cd.m_Resource);
            ulong fileId = SteamWorkShop.GetFileHandle(hash);
            VCGameMediator.SendIsoDataToServer(cd.m_IsoData.m_HeadInfo.Name, cd.m_IsoData.m_HeadInfo.SteamDesc,
                                               cd.m_IsoData.m_HeadInfo.SteamPreview, cd.m_Resource, SteamWorkShop.AddNewVersionTag(cd.m_IsoData.m_HeadInfo.ScenePaths()), true, fileId, true);
        }
        else
        {
            CreationData new_creation = new CreationData();
            new_creation.m_ObjectID   = CreationMgr.QueryNewId();
            new_creation.m_RandomSeed = UnityEngine.Random.value;
            new_creation.m_Resource   = cd.m_Resource;
            new_creation.ReadRes();

            // Attr
            new_creation.GenCreationAttr();
            if (new_creation.m_Attribute.m_Type == ECreation.Null)
            {
                Debug.LogWarning("Creation is not a valid type !");
                new_creation.Destroy();
                return;
            }

            // SaveRes
            if (new_creation.SaveRes())
            {
                new_creation.BuildPrefab();
                new_creation.Register();
                CreationMgr.AddCreation(new_creation);
                ItemAsset.ItemObject item;
                int send_retval = new_creation.SendToPlayer(out item);

                Debug.Log("Make creation succeed !");
                if (send_retval == 0)
                {
                    return; // Error
                }
                else if (send_retval == -1)
                {
                    return; // Item Package Full
                }
                else
                {
                    return; // Succeed
                }
            }
            else
            {
                Debug.LogWarning("Save creation resource file failed !");
                new_creation.Destroy();
                return;
            }
        }
    }
Пример #3
0
    public static void ExportRandIso(string fullpath, int dungeonId, int index)
    {
        if (fullpath == "")
        {
            return;
        }

        if (!File.Exists(fullpath))
        {
            return;
        }
        ulong     fileId = DungeonIsos.GetFileId(dungeonId, index);
        VCIsoData iso    = new VCIsoData();

        using (FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read))
        {
            byte[] iso_buffer = new byte[(int)(fs.Length)];
            fs.Read(iso_buffer, 0, (int)(fs.Length));
            fs.Close();
            iso.Import(iso_buffer, new VCIsoOption(true));

            if (Pathea.PeGameMgr.IsMulti)
            {
                ulong hash = CRC64.Compute(iso_buffer);
                VCGameMediator.SendIsoDataToServer(iso.m_HeadInfo.Name, iso.m_HeadInfo.SteamDesc,
                                                   iso.m_HeadInfo.SteamPreview, iso_buffer, SteamWorkShop.AddNewVersionTag(iso.m_HeadInfo.ScenePaths()), true, fileId, true);
                NetworkManager.SyncServer(EPacketType.PT_Common_SendRandIsoHash, dungeonId, index, hash);
            }
            else
            {
                CreationData new_creation = new CreationData();
                new_creation.m_ObjectID   = CreationMgr.QueryNewId();
                new_creation.m_RandomSeed = UnityEngine.Random.value;
                new_creation.m_Resource   = iso_buffer;
                new_creation.ReadRes();
                ulong hash = CRC64.Compute(iso_buffer);
                // Attr
                new_creation.GenCreationAttr();
                if (new_creation.m_Attribute.m_Type == ECreation.Null)
                {
                    Debug.LogWarning("Creation is not a valid type !");
                    new_creation.Destroy();
                    return;
                }

                // SaveRes
                if (new_creation.SaveRes())
                {
                    new_creation.BuildPrefab();
                    new_creation.Register();
                    CreationMgr.AddCreation(new_creation);
                    ItemObject item;
                    new_creation.SendToPlayer(out item, false);

                    Debug.Log("Make creation succeed !");
                    RandomDungenMgr.Instance.ReceiveIsoObj(dungeonId, hash, item.instanceId);
                }
                else
                {
                    Debug.LogWarning("Save creation resource file failed !");
                    new_creation.Destroy();
                    return;
                }
            }
        }
    }