Esempio n. 1
0
        public static WorldData CreateInitData(int id, bool cleared = false)
        {
            WorldData worldData = new WorldData();

            worldData.WorldID = id;
            AIProject.SaveData.Environment environment = worldData.Environment;
            environment.Time        = new AIProject.SaveData.Environment.SerializableDateTime(1, 1, 1, 10, 0, 0);
            environment.Weather     = Weather.Cloud1;
            environment.Temperature = Temperature.Normal;
            if (cleared)
            {
                environment.TutorialProgress = 29;
                Dictionary <int, bool> dictionary1;
                if (!environment.BasePointOpenState.TryGetValue(0, out dictionary1))
                {
                    Dictionary <int, bool> dictionary2 = new Dictionary <int, bool>();
                    environment.BasePointOpenState[0] = dictionary2;
                    dictionary1 = dictionary2;
                }
                dictionary1[-1] = true;
            }
            worldData.PlayerData.InventorySlotMax = Singleton <Resources> .Instance.PlayerProfile.DefaultInventoryMax;
            int agentMax        = Singleton <Resources> .Instance.DefinePack.MapDefines.AgentMax;
            int agentDefaultNum = Singleton <Resources> .Instance.DefinePack.MapDefines.AgentDefaultNum;

            for (int index = 0; index < agentMax; ++index)
            {
                AgentData agentData1 = new AgentData();
                worldData.AgentTable[index] = agentData1;
                AgentData agentData2 = agentData1;
                agentData2.OpenState      = index < 1;
                agentData2.PlayEnterScene = index < 1;
            }
            return(worldData);
        }
        private void OnRecyclingDataUpdate()
        {
            if (!Singleton <Game> .IsInstance())
            {
                return;
            }
            AIProject.SaveData.Environment  environment = Singleton <Game> .Instance.Environment;
            Dictionary <int, RecyclingData> source      = environment == null ? (Dictionary <int, RecyclingData>)null : environment.RecyclingDataTable;

            if (source.IsNullOrEmpty <int, RecyclingData>())
            {
                return;
            }
            foreach (KeyValuePair <int, RecyclingData> keyValuePair in source)
            {
                RecyclingData data = keyValuePair.Value;
                if (data != null)
                {
                    if (!data.CreateCountEnabled)
                    {
                        data.CreateCounter = 0.0f;
                    }
                    else if ((double)this.CountLimit <= (double)data.CreateCounter)
                    {
                        this.CreateItem(keyValuePair.Key, data);
                    }
                }
            }
        }
Esempio n. 3
0
        private void SetRecyclingData()
        {
            this.RecyclingData = (RecyclingData)null;
            int num = -1;

            this.CraftPointID  = num;
            this._craftPointID = num;
            CraftPoint currentCraftPoint = Manager.Map.GetPlayer()?.CurrentCraftPoint;

            if (!Object.op_Inequality((Object)currentCraftPoint, (Object)null))
            {
                return;
            }
            int       key       = this._craftPointID = currentCraftPoint.RegisterID;
            WorldData worldData = !Singleton <Game> .IsInstance() ? (WorldData)null : Singleton <Game> .Instance.WorldData;

            AIProject.SaveData.Environment  environment = worldData == null ? (AIProject.SaveData.Environment)null : worldData.Environment;
            Dictionary <int, RecyclingData> dictionary  = environment == null ? (Dictionary <int, RecyclingData>)null : environment.RecyclingDataTable;

            if (dictionary == null)
            {
                return;
            }
            RecyclingData recyclingData1 = (RecyclingData)null;

            if (dictionary.TryGetValue(key, out recyclingData1) && recyclingData1 != null)
            {
                this.RecyclingData = recyclingData1;
            }
            else
            {
                RecyclingData recyclingData2 = new RecyclingData();
                dictionary[key]    = recyclingData2;
                this.RecyclingData = recyclingData2;
            }
        }
Esempio n. 4
0
        public bool CanDelete()
        {
            if (this._kind != CraftPoint.CraftKind.Recycling || !Singleton <Manager.Map> .IsInstance() || !Singleton <Game> .IsInstance())
            {
                return(true);
            }
            WorldData worldData = Singleton <Game> .Instance.WorldData;

            AIProject.SaveData.Environment environment = worldData == null ? (AIProject.SaveData.Environment)null : worldData.Environment;
            if (environment == null)
            {
                return(true);
            }
            RecyclingData recyclingData = (RecyclingData)null;

            if (!environment.RecyclingDataTable.TryGetValue(this.RegisterID, out recyclingData) || recyclingData == null)
            {
                return(true);
            }
            recyclingData.DecidedItemList.RemoveAll((Predicate <StuffItem>)(x => x == null || x.Count <= 0));
            recyclingData.CreatedItemList.RemoveAll((Predicate <StuffItem>)(x => x == null || x.Count <= 0));
            if (recyclingData.DecidedItemList.IsNullOrEmpty <StuffItem>() && recyclingData.CreatedItemList.IsNullOrEmpty <StuffItem>())
            {
                return(true);
            }
            List <StuffItem> stuffItemList1 = ListPool <StuffItem> .Get();

            foreach (StuffItem decidedItem in recyclingData.DecidedItemList)
            {
                StuffItem itemInstance = CraftPoint.GetItemInstance();
                CraftPoint.CopyItem(decidedItem, itemInstance);
                stuffItemList1.AddItem(itemInstance);
            }
            foreach (StuffItem createdItem in recyclingData.CreatedItemList)
            {
                StuffItem itemInstance = CraftPoint.GetItemInstance();
                CraftPoint.CopyItem(createdItem, itemInstance);
                stuffItemList1.AddItem(itemInstance);
            }
            Manager.Map instance = Singleton <Manager.Map> .Instance;
            List <ValueTuple <int, List <StuffItem> > > inventoryList  = instance.GetInventoryList();
            List <ValueTuple <int, List <StuffItem> > > valueTupleList = ListPool <ValueTuple <int, List <StuffItem> > > .Get();

            using (List <ValueTuple <int, List <StuffItem> > > .Enumerator enumerator = inventoryList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ValueTuple <int, List <StuffItem> > current = enumerator.Current;
                    int num = (int)current.Item1;
                    List <StuffItem> source         = (List <StuffItem>)current.Item2;
                    List <StuffItem> stuffItemList2 = ListPool <StuffItem> .Get();

                    valueTupleList.Add(new ValueTuple <int, List <StuffItem> >(num, stuffItemList2));
                    if (!source.IsNullOrEmpty <StuffItem>())
                    {
                        foreach (StuffItem from in source)
                        {
                            StuffItem itemInstance = CraftPoint.GetItemInstance();
                            CraftPoint.CopyItem(from, itemInstance);
                            stuffItemList2.Add(itemInstance);
                        }
                    }
                }
            }
            using (List <ValueTuple <int, List <StuffItem> > > .Enumerator enumerator = valueTupleList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ValueTuple <int, List <StuffItem> > current = enumerator.Current;
                    int num = (int)current.Item1;
                    List <StuffItem> self = (List <StuffItem>)current.Item2;
                    for (int index = 0; index < stuffItemList1.Count; ++index)
                    {
                        StuffItem element = stuffItemList1.GetElement <StuffItem>(index);
                        if (element == null || element.Count <= 0)
                        {
                            stuffItemList1.RemoveAt(index);
                            --index;
                        }
                        else
                        {
                            StuffItem itemInstance = CraftPoint.GetItemInstance();
                            CraftPoint.CopyItem(element, itemInstance);
                            int possible = 0;
                            StuffItemExtensions.CanAddItem((IReadOnlyCollection <StuffItem>)self, num, itemInstance, out possible);
                            if (0 < possible)
                            {
                                possible = Mathf.Min(possible, itemInstance.Count);
                                self.AddItem(itemInstance, possible, num);
                            }
                            element.Count -= possible;
                            if (element.Count <= 0)
                            {
                                stuffItemList1.RemoveAt(index);
                                --index;
                            }
                        }
                    }
                }
            }
            stuffItemList1.RemoveAll((Predicate <StuffItem>)(x => x == null || x.Count <= 0));
            bool flag = stuffItemList1.IsNullOrEmpty <StuffItem>();

            if (flag)
            {
                using (List <ValueTuple <int, List <StuffItem> > > .Enumerator enumerator = inventoryList.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ValueTuple <int, List <StuffItem> > current = enumerator.Current;
                        int slotMax = (int)current.Item1;
                        List <StuffItem> receiver = (List <StuffItem>)current.Item2;
                        instance.SendItemListToList(slotMax, recyclingData.DecidedItemList, receiver);
                        instance.SendItemListToList(slotMax, recyclingData.CreatedItemList, receiver);
                    }
                }
            }
            using (List <ValueTuple <int, List <StuffItem> > > .Enumerator enumerator = valueTupleList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ValueTuple <int, List <StuffItem> > current = enumerator.Current;
                    if (current.Item2 != null)
                    {
                        foreach (StuffItem stuffItem in (List <StuffItem>)current.Item2)
                        {
                            CraftPoint.ReturnItemInstance(stuffItem);
                        }
                        ListPool <StuffItem> .Release((List <StuffItem>) current.Item2);
                    }
                }
            }
            foreach (StuffItem stuffItem in stuffItemList1)
            {
                CraftPoint.ReturnItemInstance(stuffItem);
            }
            ListPool <StuffItem> .Release(stuffItemList1);

            instance.ReturnInventoryList(inventoryList);
            return(flag);
        }