Пример #1
0
        public void TestProperty()
        {
            PropertyStruct model = new PropertyStruct();

            model.ValueProperty = 100;
            model.RefProperty   = "Test";
            PropertyStruct.StaticRefProeprty   = "Static";
            PropertyStruct.StaticValueProperty = 200;
            Delegate test = EHandler.CreateMethod <PropertyStruct>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);
                modelHandler.Set("ValueProperty", modelHandler.DLoad("ValueProperty").Operator + modelHandler.DLoad("StaticValueProperty").DelayAction);
                modelHandler.Set("StaticValueProperty", modelHandler.DLoad("ValueProperty").Operator + modelHandler.DLoad("StaticValueProperty").DelayAction);
                modelHandler.Set("RefProperty", modelHandler.DLoad("RefProperty").Operator + modelHandler.DLoad("StaticRefProeprty").DelayAction);
                modelHandler.Load();
            }).Compile();
            Func <PropertyStruct> action = (Func <PropertyStruct>)test;

            PropertyStruct.StaticValueProperty = 200;
            PropertyStruct result = action();

            Assert.Equal((ulong)300, result.ValueProperty);
            Assert.Equal((ulong)500, PropertyStruct.StaticValueProperty);
            Assert.Equal("TestStatic", result.RefProperty);
        }
        public static ArkContainer GetCryopodCreature(this GameObject gameObject)
        {
            StructPropertyList customData      = gameObject.GetPropertyValue <IArkArray, ArkArrayStruct>("CustomItemDatas").FirstOrDefault() as StructPropertyList;
            PropertyStruct     customDataBytes = customData?.Properties.FirstOrDefault(p => p.NameString == "CustomDataBytes") as PropertyStruct;
            PropertyArray      byteArrays      = (customDataBytes?.Value as StructPropertyList)?.Properties.FirstOrDefault(property => property.NameString == "ByteArrays") as PropertyArray;
            ArkArrayStruct     byteArraysValue = byteArrays?.Value as ArkArrayStruct;

            if (!(((byteArraysValue?[0] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value is ArkArrayUInt8 creatureBytes))
            {
                return(null);
            }
            ArkContainer creature = new ArkContainer(creatureBytes);

            /*
             * ArkArrayUInt8 saddleBytes = ((byteArraysValue?[1] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value as ArkArrayUInt8;
             *
             * using (MemoryStream stream = new MemoryStream(saddleBytes?.ToArray())) {
             *  using (ArkArchive archive = new ArkArchive(stream)) {
             *      int objectCount = archive.ReadInt();
             *
             *      //List<GameObject> objects = new List<GameObject>();
             *      //for (int i = 0; i < objectCount; i++) {
             *      //    //objects.Add(new GameObject(archive));
             *      //}
             *  }
             * }
             */
            return(creature);
        }
Пример #3
0
        public CharacterAction(ActionType type, string name, int consume, int logic, int talk, int athletics, int creativity, int money, string caption)
        {
            Type     = type;
            Name     = name;
            Consume  = consume;
            Property = new PropertyStruct(logic, athletics, talk, creativity);
            Money    = money;
            Captions = new string[3];
            switch (type)
            {
            case ActionType.Amusement:
                SelfControlIncrement = -2;
                ConsumeBonus         = 0;
                break;

            case ActionType.Labor:
                SelfControlIncrement = 2;
                ConsumeBonus         = -1;
                break;

            case ActionType.Study:
                SelfControlIncrement = 1;
                ConsumeBonus         = 0;
                break;
            }
        }
Пример #4
0
        public void TestPropertyStruct()
        {
            var value = new PropertyStruct {
                Value = "Execute Order 66"
            };

            _serializer.ShouldRoundtrip(value);
        }
Пример #5
0
        public void ReadBinary(ArkArchive archive, ReadingOptions options)
        {
            readBinaryHeader(archive);

            if (SaveVersion > 5)
            {
                // Name table is located after the objects block, but will be needed to read the objects block
                readBinaryNameTable(archive);
            }

            readBinaryDataFiles(archive, options);
            readBinaryEmbeddedData(archive, options);
            readBinaryDataFilesObjectMap(archive, options);
            readBinaryObjects(archive, options);
            readBinaryObjectProperties(archive, options);

            if (SaveVersion > 6)
            {
                readBinaryHibernation(archive, options);
            }

            // Now parse cryo creature data
            foreach (GameObject cryo in Objects.Where(x => x.ClassName.ToString().Contains("Cryop")).ToList())
            {
                StructPropertyList customData      = cryo.GetPropertyValue <IArkArray, ArkArrayStruct>("CustomItemDatas")?.FirstOrDefault() as StructPropertyList;
                PropertyStruct     customDataBytes = customData?.Properties.FirstOrDefault(p => p.NameString == "CustomDataBytes") as PropertyStruct;
                PropertyArray      byteArrays      = (customDataBytes?.Value as StructPropertyList)?.Properties.FirstOrDefault(property => property.NameString == "ByteArrays") as PropertyArray;
                ArkArrayStruct     byteArraysValue = byteArrays?.Value as ArkArrayStruct;
                ArkArrayUInt8      creatureBytes   = ((byteArraysValue?[0] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value as ArkArrayUInt8;
                if (creatureBytes == null)
                {
                    continue;
                }

                MemoryStream cryoStream = new MemoryStream(creatureBytes.ToArray <byte>());

                using (ArkArchive cryoArchive = new ArkArchive(cryoStream)) {
                    cryoArchive.ReadBytes(4);
                    GameObject dino         = new GameObject(cryoArchive);
                    GameObject statusObject = new GameObject(cryoArchive);
                    dino.LoadProperties(cryoArchive, new GameObject(), 0);
                    statusObject.LoadProperties(cryoArchive, new GameObject(), 0);
                    dino.IsCryo = true;

                    addObject(dino, true);
                    addObject(statusObject, true);

                    //hack the id's so that the dino points to the appropriate dino status component
                    PropertyObject statusComponentRef = dino.GetTypedProperty <PropertyObject>("MyCharacterStatusComponent");
                    statusComponentRef.Value.ObjectId = statusObject.Id;
                }
            }

            OldNameList    = archive.HasUnknownNames ? archive.NameTable : null;
            HasUnknownData = archive.HasUnknownData;
        }
Пример #6
0
    public bool CheckPlayerProperty(int logic, int talk, int athletics, int creativity)
    {
        // TODO:参数得改
        PropertyStruct PS = new PropertyStruct(logic, athletics, talk, creativity);

        if (GlobalManager.Instance.player.propertyStruct > PS)
        {
            return(true);
        }
        return(false);
    }
Пример #7
0
    /// <summary>
    /// 检测指定ID舍友是否满足属性标准
    /// </summary>
    /// <param name="id"></param>
    /// <param name="logic"></param>
    /// <param name="talk"></param>
    /// <param name="athletics"></param>
    /// <param name="creativity"></param>
    /// <returns></returns>
    public bool CheckRoommateProperty(int id, int logic, int talk, int athletics, int creativity)
    {
        Roommate       roommate = GlobalManager.Instance.roommates[id];
        PropertyStruct PS       = new PropertyStruct(logic, athletics, talk, creativity);

        if (roommate.propertyStruct > PS)
        {
            return(true);
        }
        return(false);
    }
Пример #8
0
    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="name"></param>
    /// <param name="logic"></param>
    /// <param name="talk"></param>
    /// <param name="athletics"></param>
    /// <param name="creativity"></param>
    /// <param name="money"></param>
    public Player(string name, int logic, int talk, int athletics, int creativity, int money)
    {
        Name           = name;
        propertyStruct = new PropertyStruct(logic, athletics, talk, creativity);
        Money          = money;
        // 成长值均为0
        bonus = new BonusStruct(0, 0, 0, 0);

        m_Strength = 5;
        CurWeek    = 1;
        curRound   = 1;
        stateDic   = new System.Collections.Generic.Dictionary <string, State>();
        records    = new string[24, 5];
    }
    /// <summary>
    /// 初始化,配置表初始化之后弄
    /// </summary>
    /// <param name="name"></param>
    /// <param name="talk"></param>
    /// <param name="athletics"></param>
    /// <param name="creativity"></param>
    /// <param name="money"></param>
    /// <param name="selfControl"></param>
    /// <param name="relationShip"></param>
    /// <param name="id"></param>
    /// <param name="logic"></param>
    public Roommate(string name, int logic, int talk, int athletics, int creativity, int money, int selfControl, int relationShip, int id)
    {
        Name           = name;
        propertyStruct = new PropertyStruct(logic, athletics, talk, creativity);
        Money          = money;
        SelfControl    = selfControl;
        RelationShip   = relationShip;
        ID             = id;

        // 成长值均为0
        bonus    = new BonusStruct(0, 0, 0, 0);
        stateDic = new Dictionary <string, State>();
        records  = new string[24, 5];
    }
Пример #10
0
        /// <summary>
        /// 检查解锁条件
        /// </summary>
        /// <returns></returns>
        public bool CheckUnlockCondition()
        {
            PropertyStruct PS1  = new PropertyStruct(NeedLogic, NeedAthletics, NeedTalk, NeedCreativity);
            bool           flag = GlobalManager.Instance.player.propertyStruct >= PS1 &&
                                  GlobalManager.Instance.player.CurRound >= NeedMinRound &&
                                  GlobalManager.Instance.player.CurRound <= NeedMaxRound;

            // TODO:这里关联舍友写死了,之后如果还要用,需要写活
            // 如果跟林青水关系小于所需值
            if (PlotManager.Instance.CheckRelationShip(0) < NeedRelationShip)
            {
                flag = false;
            }
            //// 检测状态,物品 状态物品目前支线用不到
            //if (!needState.Equals(""))
            //{
            //    string[] strs = needState.ToString().Split(',');
            //    Debug.Log("需要状态为:" + needState);
            //    for (int i = 0; i < strs.Length; i++)
            //    {
            //        if (!GlobalVariable.instance.player.stateDic.ContainsKey(strs[i]))
            //        {
            //            Debug.Log("当前情节所需状态为:" + strs[i] + ",玩家未存在此状态,故不符合");
            //            flag = false;
            //            break;
            //        }
            //    }
            //}
            //if (!needSlot.Equals(""))
            //{
            //    string[] strs = needState.ToString().Split(',');
            //    int index = 0;
            //    for (int i = 0; i < strs.Length; i++)
            //    {
            //        for (int j = 0; j < GlobalVariable.instance.MyBag.itemList.Count; j++)
            //        {
            //            if (GlobalVariable.instance.MyBag.itemList[j].ItemName.Equals(strs[i]))
            //
            //                index++;
            //            }
            //        }
            //    }
            //    if(index<strs.Length)
            //    {
            //        flag = false;
            //    }
            //}
            return(flag);
        }
        private PropertyStruct GetProperty(string targetIdentifier)
        {
            var len           = properties.Length;
            var foundProperty = new PropertyStruct();

            for (var i = len - 1; i >= 0; --i)
            {
                var property = properties[i];
                if (property.identifier == targetIdentifier)
                {
                    foundProperty = property;
                    break;
                }
            }
            return(foundProperty);
        }
Пример #12
0
        public void TestProperty()
        {
            Delegate test = EHandler.CreateMethod <PropertyStruct>((il) =>
            {
                EModel modelHandler = EModel.CreateModel <PropertyStruct>().UseDefaultConstructor();
                modelHandler.Set("ValueProperty", ulong.MinValue);
                modelHandler.Set("StaticValueProperty", ulong.MaxValue);
                modelHandler.Set("RefProperty", "Hello World");
                modelHandler.Load();
            }).Compile();
            Func <PropertyStruct> action = (Func <PropertyStruct>)test;
            PropertyStruct        result = action();

            Assert.Equal(ulong.MinValue, result.ValueProperty);
            Assert.Equal(ulong.MaxValue, PropertyStruct.StaticValueProperty);
            Assert.Equal("Hello World", result.RefProperty);
        }
Пример #13
0
        public void WarnUserAgainstPropertyStruct()
        {
            Assert.Throws <WarningException>(() =>
            {
                var config = new SerializerConfig();
                config.VersionTolerance.Mode = VersionToleranceMode.Standard;

                var tc = config.ConfigType <PropertyStruct>();

                CerasSerializer ceras = new CerasSerializer(config);
                var obj           = new PropertyStruct();
                obj.DeviceAddress = 1235;
                obj.SwitchId      = 45454545;

                var data  = ceras.Serialize(obj);
                var clone = ceras.Deserialize <PropertyStruct>(data);
            });
        }
        private void SetAnimationParameter(ref PropertyStruct property)
        {
            //send corresponding animator message
            switch (property.parameterType)
            {   //all cases are present
            case ParameterType.TRIGGER:
                animator.SetTrigger(property.identifier);
                break;

            case ParameterType.BOOL:
                animator.SetBool(property.identifier, property.boolParameter);
                break;

            case ParameterType.INT:
                animator.SetInteger(property.identifier, property.integerParameter);
                break;

            case ParameterType.FLOAT:
                animator.SetFloat(property.identifier, property.floatParameter);
                break;
            }
        }
Пример #15
0
    /// <summary>
    /// 从action对应的xml文件中加载action,并添加到actions中
    /// </summary>
    /// <param name="action"></param>
    /// <param name="actions"></param>
    private void LoadAction(XmlElement action, List <CharacterAction> actions)
    {
        CharacterAction ac = new CharacterAction();

        m_Type = action.GetAttribute("id").Split('_')[1];
        switch (m_Type)
        {
        case "Study":
            ac.Type = ActionType.Study;
            m_StudyActions.Add(ac);
            ac.SelfControlIncrement = 1;
            ac.ConsumeBonus         = 0;
            break;

        case "Amusement":
            ac.Type = ActionType.Amusement;
            m_AmusementActions.Add(ac);
            ac.SelfControlIncrement = -2;
            ac.ConsumeBonus         = 0;
            break;

        case "Labor":
            ac.Type = ActionType.Labor;
            m_LaborActions.Add(ac);
            ac.SelfControlIncrement = 2;
            ac.ConsumeBonus         = -1;
            break;
        }
        ac.Name    = action.ChildNodes[0].InnerText;
        ac.Consume = int.Parse(action.ChildNodes[1].InnerText);
        PropertyStruct PS1 = new PropertyStruct(Parse(action.ChildNodes[2].InnerText),
                                                Parse(action.ChildNodes[4].InnerText),
                                                Parse(action.ChildNodes[3].InnerText),
                                                Parse(action.ChildNodes[5].InnerText));

        ac.Property    = PS1;
        ac.Money       = int.Parse(action.ChildNodes[6].InnerText);
        ac.SelfControl = int.Parse(action.ChildNodes[8].InnerText);
        ac.SuccessRate = float.Parse(action.ChildNodes[9].InnerText);
        PropertyStruct PS2 = new PropertyStruct(Parse(action.ChildNodes[10].InnerText),
                                                Parse(action.ChildNodes[12].InnerText),
                                                Parse(action.ChildNodes[11].InnerText),
                                                Parse(action.ChildNodes[13].InnerText));

        ac.NeedProperty = PS2;

        ac.Captions     = new string[3];
        ac.Captions[0]  = action.ChildNodes[14].InnerText;
        ac.Captions[1]  = action.ChildNodes[15].InnerText;
        ac.Captions[2]  = action.ChildNodes[16].InnerText;
        ac.EventCaption = action.ChildNodes[17].InnerText;
        ac.Option       = action.ChildNodes[18].InnerText;
        ac.End          = action.ChildNodes[19].InnerText;
        ac.NeedMaxRound = Parse(action.ChildNodes[20].InnerText);
        ac.NeedMinRound = Parse(action.ChildNodes[21].InnerText);
        // TODO:不知是否会与存档冲突
        ac.Count = new[] { 0, 0, 0, 0 };

        actions.Add(ac);
        characterActionArray[0] = m_StudyActions;
        characterActionArray[1] = m_AmusementActions;
        characterActionArray[2] = m_LaborActions;
    }
Пример #16
0
    public void AddFiveRecordAction()
    {
        List <CharacterAction> characterActions = new List <CharacterAction>();

        // 筛选出自控力符合的action
        for (int i = 0; i < XMLManager.Instance.characterActionArray.Length; i++)
        {
            for (int j = 0; j < XMLManager.Instance.characterActionArray[i].Count; j++)
            {
                if (SelfControl >= XMLManager.Instance.characterActionArray[i][j].SelfControl)
                {
                    characterActions.Add(XMLManager.Instance.characterActionArray[i][j]);
                }
            }
        }
        for (int i = 0; i < 5; i++)
        {
            var randomNum = Random.Range(0, characterActions.Count);

            if (!characterActions[randomNum].EventCaption.Equals(""))
            {
                if (Name.Equals(GlobalManager.Instance.roommates[0]))
                {
                    characterActions[randomNum].Count[1]++;
                }
                if (Name.Equals(GlobalManager.Instance.roommates[1]))
                {
                    characterActions[randomNum].Count[2]++;
                }
                if (Name.Equals(GlobalManager.Instance.roommates[2]))
                {
                    characterActions[randomNum].Count[3]++;
                }
            }
            var promoteProperty = new PropertyStruct(0, 0, 0, 0);
            promoteProperty += characterActions[randomNum].Property;
            promoteProperty += bonus;
            int   promoteMoney = characterActions[randomNum].Money;
            int   increment    = characterActions[randomNum].SelfControlIncrement;
            float multiple;
            // 成功
            if (Widget.JudgingFirstSuccess(characterActions[randomNum], this))
            {
                multiple = 1;

                records[GlobalManager.Instance.player.CurRound - 1, i] = characterActions[randomNum].Captions[1];

                if (Widget.JudgingSecondSuccess(characterActions[randomNum], this))
                {
                    // 大成功
                    records[GlobalManager.Instance.player.CurRound - 1, i] = characterActions[randomNum].Captions[2];
                    if (increment > 0)
                    {
                        increment++;
                    }
                    else
                    {
                        increment--;
                    }
                }
            }
            else
            {
                // 失败
                records[GlobalManager.Instance.player.CurRound - 1, i] = characterActions[randomNum].Captions[0];
                multiple  = 0.5f;
                increment = -increment;
            }
            SelfControl    += increment;
            propertyStruct += promoteProperty * increment;
            Money          += (int)Widget.ChinaRound(promoteMoney * multiple, 0);
        }
    }
Пример #17
0
        /// <summary>
        /// 根据当前选择的action为player加属性
        /// 在舍友不会自己获取状态的时候,就全部用玩家的属性加成
        /// </summary>
        public static void AddProperty(BasePerson person, CharacterAction action)
        {
            // 是玩家
            if (person.GetType() == GlobalManager.Instance.player.GetType())
            {
                if (!action.EventCaption.Equals(""))
                {
                    action.Count[0]++;
                }
            }
            else
            {
                if (person.Name == GlobalManager.Instance.roommates[0].Name)
                {
                    if (!action.EventCaption.Equals(""))
                    {
                        action.Count[1]++;
                    }
                }
                else if (person.Name == GlobalManager.Instance.roommates[1].Name)
                {
                    if (!action.EventCaption.Equals(""))
                    {
                        action.Count[2]++;
                    }
                }
                else if (person.Name == GlobalManager.Instance.roommates[2].Name)
                {
                    if (!action.EventCaption.Equals(""))
                    {
                        action.Count[3]++;
                    }
                }
            }

            float          multiple;
            int            promote_Money;
            PropertyStruct promoteProperty = new PropertyStruct(0, 0, 0, 0);

            promoteProperty += action.Property;
            promoteProperty += GlobalManager.Instance.player.bonus;

            promote_Money = action.Money;
            if (JudgingFirstSuccess(action, person))
            {
                multiple = 1;
                person.AddRecordAction(action.Captions[1]);
                if (JudgingSecondSuccess(action, person))
                {
                    multiple = 2;
                    person.AddRecordAction(action.Captions[2]);
                }
            }
            else
            {
                multiple = 0.5f;
                person.AddRecordAction(action.Captions[0]);
            }

            promoteProperty       *= multiple;
            person.propertyStruct += promoteProperty;
            person.Money          += (int)ChinaRound(promote_Money * multiple, 0);
        }
Пример #18
0
        private void extractBinaryObjectCryopods(ReadingOptions options)
        {
            if (!options.CryopodCreatures)
            {
                return;
            }

            // Parse creatures in cryopods and soultraps (from the mod DinoStorageV2)
            var cryopods = Objects.Where(x => x.ClassString.Contains("Cryop") || x.ClassString.Contains("SoulTrap_")).ToArray();

            foreach (var cryo in cryopods)
            {
                ArkArrayStruct     customItemDatas = cryo.GetPropertyValue <IArkArray, ArkArrayStruct>("CustomItemDatas");
                StructPropertyList customDinoData  = (StructPropertyList)customItemDatas?.FirstOrDefault(cd => ((StructPropertyList)cd).GetTypedProperty <PropertyName>("CustomDataName").Value.Name == "Dino");
                PropertyStruct     customDataBytes = customDinoData?.Properties.FirstOrDefault(p => p.NameString == "CustomDataBytes") as PropertyStruct;
                PropertyArray      byteArrays      = (customDataBytes?.Value as StructPropertyList)?.Properties.FirstOrDefault(property => property.NameString == "ByteArrays") as PropertyArray;
                ArkArrayStruct     byteArraysValue = byteArrays?.Value as ArkArrayStruct;
                if (!(byteArraysValue?.Any() ?? false))
                {
                    continue;
                }

                ArkArrayUInt8 creatureBytes = ((byteArraysValue[0] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value as ArkArrayUInt8;
                if (creatureBytes == null)
                {
                    continue;
                }

                var cryoStream = new System.IO.MemoryStream(creatureBytes.ToArray <byte>());

                using (ArkArchive cryoArchive = new ArkArchive(cryoStream))
                {
                    // number of serialized objects
                    int objCount = cryoArchive.ReadInt();
                    if (objCount == 0)
                    {
                        continue;
                    }

                    var storedGameObjects = new List <GameObject>(objCount);
                    for (int oi = 0; oi < objCount; oi++)
                    {
                        storedGameObjects.Add(new GameObject(cryoArchive));
                    }
                    foreach (var ob in storedGameObjects)
                    {
                        ob.LoadProperties(cryoArchive, new GameObject(), 0);
                    }

                    // assume the first object is the creature object
                    string creatureActorId = storedGameObjects[0].Names[0].ToString();
                    storedGameObjects[0].IsCryo = true;

                    // the tribe name is stored in `TamerString`, non-cryoed creatures have the property `TribeName` for that.
                    if (!storedGameObjects[0].HasAnyProperty("TribeName") && storedGameObjects[0].HasAnyProperty("TamerString"))
                    {
                        storedGameObjects[0].Properties.Add(new PropertyString("TribeName", storedGameObjects[0].GetPropertyValue <string>("TamerString")));
                    }

                    // add cryopod object as parent to all child objects of the creature object (ActorIDs are not unique across cryopodded and non-cryopodded creatures)
                    // assume that child objects are stored after their parent objects
                    for (int i = 0; i < objCount; i++)
                    {
                        var ob     = storedGameObjects[i];
                        int nIndex = ob.Names.FindIndex(n => n.ToString() == creatureActorId);
                        if (nIndex != -1)
                        {
                            ob.Names.Insert(nIndex + 1, cryo.Names[0]);
                            addObject(ob, false); // processing the names can cause conflicts with reused ids
                        }

                        if (i == 0)
                        {
                            for (int ii = 1; ii < objCount; ii++)
                            {
                                ob.AddComponent(storedGameObjects[ii]);
                            }
                        }
                        else
                        {
                            ob.Parent = storedGameObjects[0];
                        }
                    }

                    // assign the created ID of the components to the creature's properties
                    AssignComponentId("DinoCharacterStatusComponent", "MyCharacterStatusComponent");
                    AssignComponentId("DinoTamedInventoryComponent", "MyInventoryComponent");

                    void AssignComponentId(string classStringStartsWith, string propertyName)
                    {
                        var statusComponentObject = storedGameObjects.FirstOrDefault(ob => ob.ClassString?.StartsWith(classStringStartsWith) ?? false);

                        if (statusComponentObject == null)
                        {
                            return;
                        }
                        var statusComponentRef = storedGameObjects[0].GetTypedProperty <PropertyObject>(propertyName);

                        if (statusComponentRef != null)
                        {
                            statusComponentRef.Value.ObjectId = statusComponentObject.Id;
                        }
                    }
                }
            }
        }
Пример #19
0
 public CharacterAction()
 {
     Property     = new PropertyStruct(0, 0, 0, 0);
     NeedProperty = new PropertyStruct(0, 0, 0, 0);
 }
Пример #20
0
        public void ReadBinary(ArkArchive archive, ReadingOptions options)
        {
            readBinaryHeader(archive);

            if (SaveVersion > 5)
            {
                // Name table is located after the objects block, but will be needed to read the objects block
                readBinaryNameTable(archive);
            }

            readBinaryDataFiles(archive, options);
            readBinaryEmbeddedData(archive, options);
            readBinaryDataFilesObjectMap(archive, options);
            readBinaryObjects(archive, options);
            readBinaryObjectProperties(archive, options);

            if (SaveVersion > 6)
            {
                readBinaryHibernation(archive, options);
            }

            // Parse creatures in cryopods and soultraps (from the mod DinoStorageV2)
            foreach (var cryo in this.Objects.Where(x => x.ClassString.Contains("Cryop") || x.ClassString.Contains("SoulTrap_")).ToList())
            {
                ArkArrayStruct     customItemDatas = cryo.GetPropertyValue <IArkArray, ArkArrayStruct>("CustomItemDatas");
                StructPropertyList customDinoData  = (StructPropertyList)customItemDatas?.FirstOrDefault(cd => ((StructPropertyList)cd).GetTypedProperty <PropertyName>("CustomDataName").Value.Name == "Dino");
                PropertyStruct     customDataBytes = customDinoData?.Properties.FirstOrDefault(p => p.NameString == "CustomDataBytes") as PropertyStruct;
                PropertyArray      byteArrays      = (customDataBytes?.Value as StructPropertyList)?.Properties.FirstOrDefault(property => property.NameString == "ByteArrays") as PropertyArray;
                ArkArrayStruct     byteArraysValue = byteArrays?.Value as ArkArrayStruct;
                if (!(byteArraysValue?.Any() ?? false))
                {
                    continue;
                }

                ArkArrayUInt8 creatureBytes = ((byteArraysValue?[0] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value as ArkArrayUInt8;
                if (creatureBytes == null)
                {
                    continue;
                }

                var cryoStream = new System.IO.MemoryStream(creatureBytes.ToArray <byte>());

                using (ArkArchive cryoArchive = new ArkArchive(cryoStream))
                {
                    // number of serialized objects
                    int objCount = cryoArchive.ReadInt();
                    if (objCount == 0)
                    {
                        continue;
                    }

                    var storedGameObjects = new List <GameObject>(objCount);
                    for (int oi = 0; oi < objCount; oi++)
                    {
                        storedGameObjects.Add(new GameObject(cryoArchive));
                    }
                    foreach (var ob in storedGameObjects)
                    {
                        ob.LoadProperties(cryoArchive, new GameObject(), 0);
                    }

                    // assume the first object is the creature object
                    string creatureActorId = storedGameObjects[0].Names[0].ToString();
                    storedGameObjects[0].IsCryo = true;

                    // the tribe name is stored in `TamerString`, non-cryoed creatures have the property `TribeName` for that.
                    if (!storedGameObjects[0].HasAnyProperty("TribeName") && storedGameObjects[0].HasAnyProperty("TamerString"))
                    {
                        storedGameObjects[0].Properties.Add(new PropertyString("TribeName", storedGameObjects[0].GetPropertyValue <string>("TamerString")));
                    }

                    // add cryopod object as parent to all child objects of the creature object (ActorIDs are not unique across cryopodded and non-cryopodded creatures)
                    // assume that child objects are stored after their parent objects
                    foreach (var ob in storedGameObjects)
                    {
                        int nIndex = ob.Names.FindIndex(n => n.ToString() == creatureActorId);
                        if (nIndex != -1)
                        {
                            ob.Names.Insert(nIndex + 1, cryo.Names[0]);
                            addObject(ob, true);
                        }
                    }

                    // assign the created ID of the dinoStatusComponent to the creature's property.
                    var statusComponentObject = storedGameObjects.FirstOrDefault(ob => ob.ClassString?.StartsWith("DinoCharacterStatusComponent") ?? false);
                    if (statusComponentObject != null)
                    {
                        var statusComponentRef = storedGameObjects[0].GetTypedProperty <PropertyObject>("MyCharacterStatusComponent");
                        statusComponentRef.Value.ObjectId = statusComponentObject.Id;
                    }
                }
            }

            OldNameList    = archive.HasUnknownNames ? archive.NameTable : null;
            HasUnknownData = archive.HasUnknownData;
        }