Ejemplo n.º 1
0
            static void Postfix(CookingStation __instance, ZNetView ___m_nview)
            {
                if (!modEnabled.Value || !___m_nview.IsValid() || !___m_nview.IsOwner() || !EffectArea.IsPointInsideArea(__instance.transform.position, EffectArea.Type.Burning, 0.25f))
                {
                    return;
                }
                for (int i = 0; i < __instance.m_slots.Length; i++)
                {
                    string itemName = ___m_nview.GetZDO().GetString("slot" + i, "");

                    float num = ___m_nview.GetZDO().GetFloat("slot" + i, 0f);
                    if (itemName != "" && itemName != __instance.m_overCookedItem.name && itemName != null)
                    {
                        CookingStation.ItemConversion itemConversion = Traverse.Create(__instance).Method("GetItemConversion", new object[] { itemName }).GetValue <CookingStation.ItemConversion>();
                        if (num > itemConversion.m_cookTime && itemName == itemConversion.m_to.name)
                        {
                            if (autoPop.Value)
                            {
                                Traverse.Create(__instance).Method("SpawnItem", new object[] { itemName }).GetValue();
                                ___m_nview.GetZDO().Set("slot" + i, "");
                                ___m_nview.GetZDO().Set("slot" + i, 0f);
                                ___m_nview.InvokeRPC(ZNetView.Everybody, "SetSlotVisual", new object[] { i, "" });
                            }
                            else if (preventBurning.Value)
                            {
                                ___m_nview.GetZDO().Set("slot" + i, itemConversion.m_cookTime);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 2
0
    private CookingStation GetClosest()
    {
        var stations = COMPONENT_DATABASE.RetrieveComponents <CookingStation>();

        if (stations.Count == 0)
        {
            return(null);
        }

        CookingStation closest     = null;
        float          closestDist = float.MaxValue;

        foreach (var tree in stations)
        {
            float dist = (tree.gameObject.transform.position - transform.position).magnitude;

            if (dist < closestDist)
            {
                closest     = (CookingStation)tree;
                closestDist = dist;
            }
        }

        return(closest);
    }
 public static void Postfix(ref List <GameObject> __result, ref CookingStation __instance)
 {
     if (!Settings.Instance.Kitchen.IncludeRoom)
     {
         return;
     }
     ModifyKitchenResultUnits(ref __result, ref __instance);
 }
Ejemplo n.º 4
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.F) && isTriggered)
        {
            bool showWarningMsg = false;

            // If in restaurant scene, check for any current food before transiting
            Scene currScene = SceneManager.GetActiveScene();

            if (currScene.name == "TestRestaurant")
            {
                //Check if any leftover food
                CookingStation cookingStation = GameObject.Find("Recipe Controller").GetComponent <CookingStation>();
                GameObject[]   spawnFoodAreas = cookingStation.spawnFoodAreas;
                for (int i = 0; i < spawnFoodAreas.Length; i++)
                {
                    if (spawnFoodAreas[i].transform.childCount != 0)
                    {
                        showWarningMsg = true;
                        break;
                    }
                }

                // If there if leftover food, show warning message
                // Else, let player transit
                if (showWarningMsg)
                {
                    UIController uiController = GameObject.Find("UI Controller").GetComponent <UIController>();
                    uiController.ShowConfirmLeaveNotifPanel();
                }
                else
                {
                    if (enableGameSave)
                    {
                        saveGameDataSystem.SaveGameData((int)sceneIndex);
                    }
                    LoadScene();
                }
            }
            else // in dungeon
            {
                if (enableGameSave)
                {
                    saveGameDataSystem.SaveGameData((int)sceneIndex);
                }
                LoadScene();
            }

            /*
             * Debug.Log("Player can transit");
             * if (enableGameSave)
             * {
             *  saveGameDataSystem.SaveGameData(sceneIndex);
             * }
             * LoadScene();
             */
        }
    }
Ejemplo n.º 5
0
 private IEnumerator UpdateUIData(CookingStation cookingStation)
 {
     HighlightButton();
     while (_UISlotData.Ingredient != null && (cookingStation.State == CookingStation.CookingStationState.AVAILABLE || cookingStation.State == CookingStation.CookingStationState.NOT_VISIBLE_TO_LOCAL_PLAYER))
     {
         yield return(null);
     }
     DeHighlightButton();
 }
Ejemplo n.º 6
0
        private static bool GetHoverText(CookingStation __instance, ref string __result)
        {
            if (Main.timeLeftStyleCookingStation.Value == 0)
            {
                return(true);
            }

            return(Patches.HoverText.PatchCookingStation(__instance, ref __result));
        }
Ejemplo n.º 7
0
    private void Awake()
    {
        _CookingStation = GetComponentInParent <CookingStation>();
        _StateImage     = GetComponent <SpriteRenderer>();
        _Animator       = GetComponent <Animator>();

        // Initial sprite update
        _DefaultCookingStationIcon = _StateImage.sprite;
        UpdateUI();
    }
Ejemplo n.º 8
0
    private void OnHeroNearCookingStation(object data)
    {
        CookingStation cookingStation = (CookingStation)data;

        // Check if the ingredient is compatible and the station is available
        if (_UISlotData.Ingredient != null && _UISlotData.Ingredient.CheckIfCompatible(cookingStation.CookingStepPerformed))
        {
            StartCoroutine(UpdateUIData(cookingStation));
        }
    }
Ejemplo n.º 9
0
    public override void SetTarget()
    {
        var closest = GetClosest();

        if (closest != null)
        {
            m_TargetStation = closest;
            target          = m_TargetStation.transform;
        }
    }
Ejemplo n.º 10
0
            static bool Prefix(ref CookingStation __instance, ref ZNetView ___m_nview, Humanoid user, bool hold)
            {
                if (hold)
                {
                    return(false);
                }

                Traverse t_cookingStation = Traverse.Create(__instance);
                ZDO      zdo = ___m_nview.GetZDO();

                for (int slot = 0; slot < __instance.m_slots.Length; ++slot)
                {
                    string itemName   = zdo.GetString(nameof(slot) + slot);
                    bool   isItemDone = t_cookingStation.Method("IsItemDone", itemName).GetValue <bool>();

                    if (itemName != "" && itemName != __instance.m_overCookedItem.name && isItemDone)
                    {
                        JustAnotherCookingSkill.raiseCookingSkill(user, JustAnotherCookingSkill.cookingStaticExperienceGain.Value * 0.5f);

                        string qualityPrefix = JustAnotherCookingSkill.getQualityBasedOnSkill(user);

                        // check if such object exist
                        string qualifyMealName = qualityPrefix + itemName;
                        if (Prefab.Cache.GetPrefab <ItemDrop>(qualifyMealName) == null)
                        {
                            Log.LogError($"No object registered for qualify meal: {qualifyMealName}");
                            return(true);
                        }

                        // instead of processing normal food, we spawn qualified variant
                        MethodInfo method = __instance.GetType().GetMethod("SpawnItem");
                        if (method == null)
                        {
                            Log.LogError("Method SpawnItem does not exist on type CookingStation");
                            return(true);
                        }

                        method.Invoke(__instance, new object[] { qualifyMealName });

                        zdo.Set("slot" + slot, "");

                        ___m_nview.InvokeRPC(ZNetView.Everybody, "SetSlotVisual", new object[]
                        {
                            slot,
                            ""
                        });

                        // Unfortunately we replace this hook totally and extra modifications will conflict on those. I gonna find better way
                        return(false);
                    }
                }

                return(true);
            }
Ejemplo n.º 11
0
    public void Cook(int playerWhoIsCooking, CookingStation cookingStation, SO_Tag cookingStepPerformed)
    {
        cookingStation.Use(this);
        MinionStartedCookingEvent.Invoke();

        // Recording the task performed
        CookingStationStepsPerformed.Add(cookingStepPerformed);
        CookingStationStepsToPerform.Remove(cookingStepPerformed);

        // Listening to cooked event
        cookingStation.StationInCoolDownEvent.AddListener(OnIngredientCooked);

        GetCooked();
    }
        private static void ModifyKitchenResultUnits(ref List <GameObject> __result, ref CookingStation __instance)
        {
            if (!Settings.Instance.Kitchen.IncludeRoom)
            {
                return;
            }

            if (RoomTypes_AllModded.IsInTheRoom(__instance, RoomTypeKitchenData.RoomId) &&
                Settings.Instance.Kitchen.Bonus.HasValue)
            {
                foreach (GameObject go in __result)
                {
                    go.GetComponent <PrimaryElement>().Units *= (1 + Settings.Instance.Kitchen.Bonus.Value);
                }
            }
        }
Ejemplo n.º 13
0
    public void Cook(IngredientMinion ingredient, CookingPot cookingPot)
    {
        // Cooking the ingredient
        bool ingredientCooked = _TargetCookingStation.Use(ingredient);

        // Setting target cooking station to null
        _TargetCookingStation = null;

        // Updating ui and inventory only on the local machine
        if (IsLocal && ingredientCooked)
        {
            RemoveIngredientFromInventory(ingredient);

            // Telling the UI that something has happened to some ingredient, so that they update themselves
            _IngredientModifiedEvent.Invoke(null);
        }
    }
Ejemplo n.º 14
0
            static void Postfix(CookingStation __instance, ZNetView ___m_nview)
            {
                Traverse traverse = Traverse.Create(__instance);

                if (!modEnabled.Value || !___m_nview.IsValid() || !___m_nview.IsOwner() || (__instance.m_requireFire && !traverse.Method("IsFireLit").GetValue <bool>()) || (__instance.m_useFuel && traverse.Method("GetFuel").GetValue <float>() <= 0f))
                {
                    return;
                }

                //Dbgl($"Updating {__instance.name}");
                for (int i = 0; i < __instance.m_slots.Length; i++)
                {
                    string itemName   = ___m_nview.GetZDO().GetString("slot" + i, "");
                    float  cookedTime = ___m_nview.GetZDO().GetFloat("slot" + i, 0f);
                    int    status     = ___m_nview.GetZDO().GetInt("slotstatus" + i, 0);

                    if (itemName == "")
                    {
                        continue;
                    }

                    CookingStation.ItemConversion itemConversion = traverse.Method("GetItemConversion", new object[] { itemName }).GetValue <CookingStation.ItemConversion>();
                    //Dbgl($"Updating slot {i} {cookedTime}/{itemConversion.m_cookTime} {status}");

                    if (itemName != "" && status != 2)
                    {
                        //Dbgl($"Updating slot {i} {itemName} {cookedTime}");
                        if (itemConversion != null && cookedTime > itemConversion.m_cookTime && itemName == itemConversion.m_to.name)
                        {
                            if (autoPop.Value)
                            {
                                Dbgl($"Popping {__instance.name} slot {i} {itemName}");
                                Traverse.Create(__instance).Method("SpawnItem", new object[] { itemName, i, __instance.m_slots[i].position }).GetValue();
                                ___m_nview.GetZDO().Set("slot" + i, "");
                                ___m_nview.GetZDO().Set("slot" + i, 0f);
                                ___m_nview.InvokeRPC(ZNetView.Everybody, "SetSlotVisual", new object[] { i, "" });
                            }
                            else if (preventBurning.Value)
                            {
                                ___m_nview.GetZDO().Set("slot" + i, itemConversion.m_cookTime);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 15
0
        public static bool Prefix(CookingStation __instance, string name)
        {
            var itemPrefab = ObjectDB.instance.GetItemPrefab(name);
            var itemDrop   = itemPrefab.GetComponent <ItemDrop>();

            if (itemDrop != null)
            {
                itemDrop.m_itemData = new ExtendedItemData(itemDrop.m_itemData);
            }
            var pos        = __instance.transform.position + Vector3.up * __instance.m_spawnOffset;
            var quaternion = Quaternion.Euler(0.0f, Random.Range(0, 360), 0.0f);
            var position   = pos;
            var rotation   = quaternion;
            var newObject  = Object.Instantiate(itemPrefab, position, rotation);

            newObject.GetComponent <Rigidbody>().velocity = Vector3.up * __instance.m_spawnForce;
            __instance.m_pickEffector.Create(pos, Quaternion.identity);
            return(false);
        }
Ejemplo n.º 16
0
    public void Resume()
    {
        mainPauseButtons.SetActive(true);
        optionButtons.SetActive(false);
        pauseMenuUI.SetActive(false);
        Time.timeScale = 1f;
        isGamePaused   = false;

        Scene currScene = SceneManager.GetActiveScene();

        if (currScene.name == "TestRestaurant")
        {
            CookingStation cookingStation = GameObject.Find("Recipe Controller").GetComponent <CookingStation>();
            if (cookingStation.isCooking == true)
            {
                cookingStation.DisableMovementOfPlayer();
            }
        }
    }
Ejemplo n.º 17
0
    public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag)
    {
        go.AddOrGet <BuildingComplete>().isManuallyOperated = true;
        CookingStation cookingStation = go.AddOrGet <CookingStation>();

        cookingStation.resultState       = ComplexFabricator.ResultState.Heated;
        cookingStation.heatedTemperature = 368.15f;
        go.AddOrGet <FabricatorIngredientStatusManager>();
        go.AddOrGet <CopyBuildingSettings>();
        go.AddOrGet <ComplexFabricatorWorkable>().overrideAnims = new KAnimFile[1]
        {
            Assets.GetAnim("anim_interacts_cookstation_kanim")
        };
        cookingStation.sideScreenStyle = ComplexFabricatorSideScreen.StyleSetting.ListQueueHybrid;
        Prioritizable.AddRef(go);
        go.AddOrGet <DropAllWorkable>();
        ConfigureRecipes();
        go.AddOrGetDef <PoweredController.Def>();
        BuildingTemplates.CreateComplexFabricatorStorage(go, cookingStation);
    }
Ejemplo n.º 18
0
        private static ItemDrop.ItemData PullCookableItemFromNearbyChests(CookingStation station)
        {
            if (station.GetFreeSlot() == -1)
            {
                return(null);
            }

            Stopwatch delta = GameObjectAssistant.GetStopwatch(station.gameObject);

            int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;

            if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
            {
                nearbyChests = InventoryAssistant.GetNearbyChests(station.gameObject, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck);
                delta.Restart();
            }

            foreach (CookingStation.ItemConversion itemConversion in station.m_conversion)
            {
                ItemDrop.ItemData itemData = itemConversion.m_from.m_itemData;

                foreach (Container c in nearbyChests)
                {
                    if (c.GetInventory().HaveItem(itemData.m_shared.m_name))
                    {
                        // Remove one item from chest
                        InventoryAssistant.RemoveItemFromChest(c, itemData);
                        // Instantiate cookabled GameObject
                        GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemConversion.m_from.gameObject.name);

                        ZNetView.m_forceDisableInit = true;
                        GameObject cookabledItem = UnityEngine.Object.Instantiate <GameObject>(itemPrefab);
                        ZNetView.m_forceDisableInit = false;

                        return(cookabledItem.GetComponent <ItemDrop>().m_itemData);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 19
0
        public static bool PatchCookingStation(CookingStation cookingStation, ref string hoverText)
        {
            if (cookingStation.m_nview.IsOwner() && cookingStation.IsFireLit())
            {
                string cookingItems = "";
                int    items        = 0;

                for (int i = 0; i < cookingStation.m_slots.Length; i++)
                {
                    cookingStation.GetSlot(i, out string text, out float num);
                    if (text != "" && text != cookingStation.m_overCookedItem.name)
                    {
                        CookingStation.ItemConversion itemConversion = cookingStation.GetItemConversion(text);
                        if (text != null)
                        {
                            items++;
                            if (num > itemConversion.m_cookTime) // Item overCooking
                            {
                                string time = Main.timeLeftStyleCookingStation.Value == 1 ? $"{num / (itemConversion.m_cookTime * 2f):P0}" : Helpers.TimeString(itemConversion.m_cookTime * 2f - num);
                                cookingItems += $"\n{cookingStation.m_overCookedItem.GetHoverName()}: <color={overCookColor}>{time}</color>";
                            }
                            else
                            {
                                string time = Main.timeLeftStyleCookingStation.Value == 1 ? $"{num / itemConversion.m_cookTime:P0}" : Helpers.TimeString(itemConversion.m_cookTime - num);
                                cookingItems += $"\n{itemConversion.m_to.GetHoverName()}: {time}";
                            }
                        }
                    }
                }
                if (items > 0)
                {
                    hoverText = items >= cookingStation.m_slots.Length ?
                                Localization.instance.Localize($"{cookingStation.m_name}{cookingItems}") :
                                Localization.instance.Localize($"{cookingStation.m_name}\n{_cookItem}\n{_selectItem}{cookingItems}");
                    return(false); // Overwrite games default string
                }
            }
            return(true);
        }
Ejemplo n.º 20
0
            static void Prefix(ref CookingStation __instance, ref ZNetView ___m_nview, Humanoid user, bool hold)
            {
                if (hold)
                {
                    return;
                }

                Traverse t_cookingStation = Traverse.Create(__instance);
                ZDO      zdo = ___m_nview.GetZDO();

                for (int slot = 0; slot < __instance.m_slots.Length; ++slot)
                {
                    string itemName   = zdo.GetString(nameof(slot) + slot);
                    bool   isItemDone = t_cookingStation.Method("IsItemDone", itemName).GetValue <bool>();

                    if (itemName != "" && itemName != __instance.m_overCookedItem.name && isItemDone)
                    {
                        ((Player)user).RaiseSkill((Skills.SkillType)COOKING_SKILL_ID, configCookingStationXPIncrease.Value * 0.75f);
                        //Log($"[Removed Cooked Item from Cook Station] Increase Cooking Skill by {configCookingStationXPIncrease.Value * 0.75f}");
                        break;
                    }
                }
            }
Ejemplo n.º 21
0
            static void Postfix(CookingStation __instance, ref ItemDrop.ItemData __result)
            {
                Dbgl($"looking for cookable");

                if (!AllowByKey() || __result != null || !((bool)typeof(CookingStation).GetMethod("IsFireLit", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { })) || ((int)typeof(CookingStation).GetMethod("GetFreeSlot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { })) == -1)
                {
                    return;
                }

                Dbgl($"missing cookable in player inventory");


                List <Container> nearbyContainers = GetNearbyContainers(__instance.transform.position);

                foreach (CookingStation.ItemConversion itemConversion in __instance.m_conversion)
                {
                    foreach (Container c in nearbyContainers)
                    {
                        ItemDrop.ItemData item = c.GetInventory().GetItem(itemConversion.m_from.m_itemData.m_shared.m_name);
                        if (item != null)
                        {
                            if (oreDisallowTypes.Value.Split(',').Contains(item.m_dropPrefab.name))
                            {
                                Dbgl($"container at {c.transform.position} has {item.m_stack} {item.m_dropPrefab.name} but it's forbidden by config");
                                continue;
                            }

                            Dbgl($"container at {c.transform.position} has {item.m_stack} {item.m_dropPrefab.name}, taking one");
                            __result = item;
                            c.GetInventory().RemoveItem(itemConversion.m_from.m_itemData.m_shared.m_name, 1);
                            typeof(Container).GetMethod("Save", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(c, new object[] { });
                            typeof(Inventory).GetMethod("Changed", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(c.GetInventory(), new object[] { });
                            return;
                        }
                    }
                }
            }
Ejemplo n.º 22
0
    private IEnumerator MovingToNode(Vector3 positionToMoveTo)
    {
        _Mover.SetDestination(positionToMoveTo);

        while (Vector3.Distance(transform.position, _TargetNode.SpotToStandIn.position) >= _MinimumDistanceBeforeStoppingFromNode)
        {
            yield return(null);
        }

        _TargetCookingStation = _TargetNode.GetComponent <CookingStation>();
        if (_TargetCookingStation != null)
        {
            // Invoking the near cooking station event only if the hero is controlled locally
            if (IsLocal)
            {
                _HeroNearCookingStationEvent.Invoke(_TargetCookingStation);
            }

            _TargetCookingStation.PickUpCookedFood(OwnerID, IsLocal);
        }

        //_Mover.StopMoving();
        _TargetNode = null;
    }
Ejemplo n.º 23
0
            static void Prefix(CookingStation __instance)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                int count = __instance.m_slots.Length;
                List <Transform> newSlots = new List <Transform>(__instance.m_slots);
                float            target   = Mathf.RoundToInt(count * slotMultiplier.Value);

                Dbgl($"Cooking station {__instance.name} awake. Slots {count}, target {target}");
                while (count < target)
                {
                    bool             neg          = true;
                    List <Transform> currentSlots = new List <Transform>(newSlots);
                    int off = 0;
                    for (int i = 0; i <= currentSlots.Count; i++)
                    {
                        int       idx = currentSlots.Count / 2 - 1 + (neg ? -off : off);
                        Transform a   = null;
                        Transform b   = null;
                        if (idx >= 0)
                        {
                            a = currentSlots[idx]; // 0, 1, -1, 2
                        }
                        if (idx < currentSlots.Count - 1)
                        {
                            b = currentSlots[idx + 1]; // 1, 2, 0, 3
                        }
                        Transform c;
                        if (a == null)
                        {
                            c          = Instantiate(b, b.parent);
                            c.position = b.position * 2 - Vector3.Lerp(b.position, currentSlots[idx + 2].position, 0.5f);
                            newSlots.Insert(0, c);
                        }
                        else if (b == null)
                        {
                            c          = Instantiate(a, a.parent);
                            c.position = a.position * 2 - Vector3.Lerp(a.position, currentSlots[idx - 1].position, 0.5f);
                            newSlots.Add(c);
                        }
                        else
                        {
                            c          = Instantiate(a, a.parent);
                            c.position = Vector3.Lerp(a.position, b.position, 0.5f);
                            newSlots.Insert(idx + 1, c);
                        }
                        count++;
                        if (count >= target)
                        {
                            break;
                        }
                        neg = !neg;
                        if (i % 2 == 0)
                        {
                            off++;
                        }
                    }
                }
                Dbgl($"New number of slots {newSlots.Count}");
                for (int i = 0; i < newSlots.Count; i++)
                {
                    newSlots[i].name = "slot" + i;
                }
                __instance.m_slots = newSlots.ToArray();
            }
Ejemplo n.º 24
0
 protected override void DoReset()
 {
     m_TargetStation = null;
     m_Cooked        = false;
     m_StartTime     = 0f;
 }
Ejemplo n.º 25
0
        private static void GenerateReferenceLists()
        {
            //Start surfing through all items
            foreach (GameObject go in ObjectDB.instance.m_items)
            {
                //Add to reference lists if not in their already
                MyReferences.TryAddToItemList(go);

                ItemDrop id = go.GetComponent <ItemDrop>();
                if (id != null)
                {
                    //var s = id.m_itemData.m_shared;
                    //Log.LogMessage($"{id.name},{s.m_weight},{s.m_attackForce}");
                    ParticleSystemRenderer ps = go.GetComponent <ParticleSystemRenderer>();
                    if (ps != null)
                    {
                        if (!MyReferences.listOfMaterials.ContainsKey("item_particle".GetStableHashCode()))
                        {
                            MyReferences.TryAddToMaterialList(ps.sharedMaterial, "item_particle");
                        }
                    }

                    var shared = id.m_itemData.m_shared;
                    //Start looking for weapon effects (fx, sfx, vfx)
                    if (shared.m_itemType == ItemDrop.ItemData.ItemType.OneHandedWeapon ||
                        shared.m_itemType == ItemDrop.ItemData.ItemType.TwoHandedWeapon ||
                        shared.m_itemType == ItemDrop.ItemData.ItemType.Bow)
                    {
                        if (!MyReferences.listOfMaterials.ContainsKey("club_trail".GetStableHashCode()))
                        {
                            Transform thing = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(go.transform, "attach");
                            if (thing != null)
                            {
                                thing = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(thing, "equiped");
                                if (thing != null)
                                {
                                    Transform trail = RecursiveSearchFunctions.ChildNodeFinderDepthFirst(thing, "trail");
                                    if (trail != null)
                                    {
                                        MeleeWeaponTrail mwt = trail.gameObject.GetComponent <MeleeWeaponTrail>();
                                        MyReferences.TryAddToMaterialList(mwt._material, "club_trail");
                                    }
                                }
                            }
                        }
                        MyReferences.TryExtractEffectsFromItemDropShared(shared);
                    }

                    //Check to see if item can also build things
                    if (shared.m_buildPieces != null)
                    {
                        var pieceTable = shared.m_buildPieces.m_pieces;
                        if (pieceTable != null)
                        {
                            foreach (var pieceTableItem in pieceTable)
                            {
                                MyReferences.TryAddToPieceList(pieceTableItem);

                                //One off capture of a station extension's line effect
                                StationExtension stationExtension = pieceTableItem.GetComponent <StationExtension>();
                                if (stationExtension != null && !MyReferences.listOfEffects.ContainsKey(stationExtension.m_connectionPrefab.name.GetStableHashCode()))
                                {
                                    MyReferences.listOfEffects.Add(stationExtension.m_connectionPrefab.name.GetStableHashCode(), stationExtension.m_connectionPrefab);
                                }

                                //Collect this for items and pieces, for proper referencing
                                CraftingStation craftingStation = pieceTableItem.GetComponent <CraftingStation>();
                                if (craftingStation != null && !MyReferences.listOfCraftingStations.ContainsKey(pieceTableItem.name.GetStableHashCode()))
                                {
                                    MyReferences.listOfCraftingStations.Add(pieceTableItem.name.GetStableHashCode(), craftingStation);
                                }

                                CookingStation cookingStation = pieceTableItem.GetComponent <CookingStation>();
                                if (cookingStation != null && !MyReferences.listOfCookingStations.ContainsKey(pieceTableItem.name.GetStableHashCode()))
                                {
                                    MyReferences.listOfCookingStations.Add(pieceTableItem.name.GetStableHashCode(), cookingStation);
                                }


                                //Extracting any Piece Placement Effects
                                var PieceScript = pieceTableItem.GetComponent <Piece>();
                                if (PieceScript != null)
                                {
                                    ExtractEffectsFromPiece(PieceScript.m_placeEffect);
                                }

                                //Extracting WearNTear effects
                                var WearNTearScript = pieceTableItem.GetComponent <WearNTear>();
                                if (WearNTearScript != null)
                                {
                                    ExtractEffectsFromPiece(WearNTearScript.m_destroyedEffect);
                                    ExtractEffectsFromPiece(WearNTearScript.m_hitEffect);
                                    ExtractEffectsFromPiece(WearNTearScript.m_switchEffect);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
            static void Prefix(CookingStation __instance, ref ParticleSystem[] ___m_burntPS, ref ParticleSystem[] ___m_donePS, ref ParticleSystem[] ___m_ps, ref AudioSource[] ___m_as)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                if (cookTimeMultiplier.Value != 1f)
                {
                    for (int i = 0; i < __instance.m_conversion.Count; i++)
                    {
                        __instance.m_conversion[i].m_cookTime *= cookTimeMultiplier.Value;
                    }
                }

                int count = __instance.m_slots.Length;
                List <Transform> newSlots = new List <Transform>(__instance.m_slots);

                Transform burnt = null;
                Transform done  = null;

                float target = Mathf.RoundToInt(count * slotMultiplier.Value);

                Dbgl($"Cooking station {__instance.name} awake. Slots {count}, target {target}");
                while (count < target)
                {
                    bool             neg          = true;
                    List <Transform> currentSlots = new List <Transform>(newSlots);
                    int off = 0;
                    for (int i = 0; i <= currentSlots.Count; i++)
                    {
                        int       idx = currentSlots.Count / 2 - 1 + (neg ? -off : off);
                        Transform a   = null;
                        Transform b   = null;
                        if (idx >= 0)
                        {
                            a = currentSlots[idx]; // 0, 1, -1, 2
                        }
                        if (idx < currentSlots.Count - 1)
                        {
                            b = currentSlots[idx + 1]; // 1, 2, 0, 3
                        }
                        Transform c;
                        if (a == null)
                        {
                            c          = Instantiate(b, b.parent);
                            c.position = b.position * 2 - Vector3.Lerp(b.position, currentSlots[idx + 2].position, 0.5f);
                            newSlots.Insert(0, c);
                        }
                        else if (b == null)
                        {
                            c          = Instantiate(a, a.parent);
                            c.position = a.position * 2 - Vector3.Lerp(a.position, currentSlots[idx - 1].position, 0.5f);
                            newSlots.Add(c);
                        }
                        else
                        {
                            c          = Instantiate(a, a.parent);
                            c.position = Vector3.Lerp(a.position, b.position, 0.5f);
                            newSlots.Insert(idx + 1, c);
                        }

                        count++;
                        if (count >= target)
                        {
                            break;
                        }
                        neg = !neg;
                        if (i % 2 == 0)
                        {
                            off++;
                        }
                    }
                }
                Dbgl($"New number of slots {newSlots.Count}");
                for (int i = 0; i < newSlots.Count; i++)
                {
                    newSlots[i].name = "slot" + i;
                }
                __instance.m_slots = newSlots.ToArray();

                ___m_ps = new ParticleSystem[__instance.m_slots.Length];
                ___m_as = new AudioSource[__instance.m_slots.Length];


                List <ParticleSystem> oldBurnt = new List <ParticleSystem>(___m_burntPS);
                List <ParticleSystem> oldDone  = new List <ParticleSystem>(___m_donePS);

                if (___m_burntPS.Length != 0)
                {
                    Dbgl("setting burnt");

                    burnt        = ___m_burntPS[0].transform;
                    ___m_burntPS = new ParticleSystem[__instance.m_slots.Length];
                }
                if (___m_donePS.Length != 0)
                {
                    Dbgl("setting done");

                    done        = ___m_donePS[0].transform;
                    ___m_donePS = new ParticleSystem[__instance.m_slots.Length];
                }

                for (int i = 0; i < __instance.m_slots.Length; i++)
                {
                    ___m_ps[i] = __instance.m_slots[i].GetComponent <ParticleSystem>();
                    ___m_as[i] = __instance.m_slots[i].GetComponent <AudioSource>();
                    if (burnt)
                    {
                        ___m_burntPS[i]      = Instantiate(burnt, burnt.parent).GetComponent <ParticleSystem>();
                        ___m_burntPS[i].name = "burnt" + i;
                        ___m_burntPS[i].transform.localPosition = __instance.m_slots[i].localPosition;
                        ParticleSystem.EmissionModule emissionModule = ___m_burntPS[i].emission;
                        emissionModule.enabled = false;
                    }
                    if (done)
                    {
                        ___m_donePS[i]      = Instantiate(done, done.parent).GetComponent <ParticleSystem>();
                        ___m_donePS[i].name = "done" + i;
                        ___m_donePS[i].transform.localPosition = __instance.m_slots[i].localPosition;
                        ParticleSystem.EmissionModule emissionModule = ___m_donePS[i].emission;
                        emissionModule.enabled = false;
                    }
                }
                foreach (var ps in oldBurnt)
                {
                    Destroy(ps.gameObject);
                }
                foreach (var ps in oldDone)
                {
                    Destroy(ps.gameObject);
                }
            }