示例#1
0
        private bool CheckWater(CraftingJobWaterInstance instance)
        {
            if (instance.WaterPosition != Pipliz.Vector3Int.invalidPos)
            {
                ushort val;
                if (!World.TryGetTypeAt(instance.WaterPosition, out val))
                {
                    return(false);
                }
                if ((int)val == (int)BuiltinBlocks.Indices.water)
                {
                    return(true);
                }
                instance.WaterPosition = Pipliz.Vector3Int.invalidPos;
            }
            UnityEngine.Assertions.Assert.IsTrue(instance.WaterPosition == Pipliz.Vector3Int.invalidPos, "waterpos wasn't invalid");
            for (int a = -1; a <= 1; ++a)
            {
                for (int b = -1; b <= 1; ++b)
                {
                    for (int c = -1; c <= 1; ++c)
                    {
                        ushort val;
                        if (!World.TryGetTypeAt(instance.Position.Add(a, b, c), out val))
                        {
                            return(false);
                        }
                        if ((int)val == (int)BuiltinBlocks.Indices.water)
                        {
                            instance.WaterPosition = instance.Position.Add(a, b, c);
                            return(true);
                        }
                    }
                }
            }
            int num = (int)ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, new BlockChangeRequestOrigin(instance.Owner));

            return(false);
        }
示例#2
0
        public void PerformGoal(ref NPCBase.NPCState state)
        {
            CraftingJobWaterInstance instance = JobInstance;
            Colony owner = instance.Owner;

            state.JobIsDone = true;
            if (!this.CheckWater(instance))
            {
                state.SetCooldown(0.3, 0.5);
            }
            else
            {
                int index1;
                if (WaterSettings.BlockTypes.ContainsByReference <ItemTypes.ItemType>(instance.BlockType, out index1))
                {
                    UnityEngine.Vector3 vector = instance.NPC.Position.Vector;
                    switch (index1)
                    {
                    case 1:
                        ++vector.x;
                        break;

                    case 2:
                        --vector.x;
                        break;

                    case 3:
                        ++vector.z;
                        break;

                    case 4:
                        --vector.z;
                        break;
                    }
                    instance.NPC.LookAt(vector);
                }

                recipeMatch = Recipe.MatchRecipe <AvailableRecipesEnumerator>(owner.RecipeData.GetAvailableRecipes(WaterSettings.NPCTypeString), owner);
                switch (recipeMatch.MatchType)
                {
                case Recipe.RecipeMatchType.FoundCraftable:
                    Recipe foundRecipe = recipeMatch.FoundRecipe;
                    if (state.Inventory.TryRemove(foundRecipe.Requirements))
                    {
                        CraftingResults.Clear();
                        for (int index2 = 0; index2 < foundRecipe.Results.Count; ++index2)
                        {
                            CraftingResults.Add(foundRecipe.Results[index2]);
                        }
                        if (WaterSettings.OnCraftedAudio != null)
                        {
                            AudioManager.SendAudio(instance.Position.Vector, WaterSettings.OnCraftedAudio);
                        }
                        ModLoader.Callbacks.OnNPCCraftedRecipe.Invoke(Job, foundRecipe, CraftingResults);
                        RecipeResult weightedRandom = RecipeResult.GetWeightedRandom(CraftingResults);
                        float        timeToShow     = WaterSettings.Cooldown * Pipliz.Random.NextFloat(0.9f, 1.1f);
                        if (weightedRandom.Amount > 0)
                        {
                            state.SetIndicator(new IndicatorState(timeToShow, weightedRandom.Type));
                        }
                        else
                        {
                            state.SetCooldown((double)timeToShow);
                        }
                        state.Inventory.Add(CraftingResults);
                        ++instance.GatheredCount;
                        if (instance.GatheredCount < WaterSettings.MaxGatheredBeforeCrate)
                        {
                            break;
                        }
                        instance.GatheredCount = 0;
                        PutItemsInCrate(ref state);
                        break;
                    }
                    else
                    {
                        GetItemsFromCrate(ref state);
                    }
                    break;

                case Recipe.RecipeMatchType.FoundMissingRequirements:
                case Recipe.RecipeMatchType.AllDone:
                    if (state.Inventory.IsEmpty)
                    {
                        state.JobIsDone = true;
                        if (recipeMatch.MatchType == Recipe.RecipeMatchType.AllDone)
                        {
                            state.SetIndicator(new IndicatorState(WaterSettings.Cooldown, BuiltinBlocks.Indices.erroridle));
                        }
                        else
                        {
                            state.SetIndicator(new IndicatorState(WaterSettings.Cooldown, recipeMatch.FoundRecipe.FindMissingType(owner.Stockpile), true, false));
                        }
                        Job.Owner.Stats.RecordNPCIdleSeconds(WaterSettings.NPCType, WaterSettings.Cooldown);
                        GetItemsFromCrate(ref state);
                        break;
                    }
                    GetItemsFromCrate(ref state);
                    break;
                }
            }
        }
示例#3
0
 public WaterGatherGoal(CraftingJobWaterInstance blockJobInstance, PandaCraftingJobWaterSettings pandaJobSettings)
 {
     JobInstance   = blockJobInstance;
     Job           = blockJobInstance;
     WaterSettings = pandaJobSettings;
 }