public PandaMiningJobSettings(string blockType, string npcType, int maxCraftsPerRun, string recruitmentItem, float miningCooldown, HashSet <string> minableTypes, string onCraftedAudio = "stoneDelete")
        {
            ItemTypes.ItemType type = ItemTypes.GetType(blockType);
            if (type.RotatedXMinus != null)
            {
                BlockTypes = new ItemTypes.ItemType[5]
                {
                    type,
                    ItemTypes.GetType(type.RotatedXPlus),
                    ItemTypes.GetType(type.RotatedXMinus),
                    ItemTypes.GetType(type.RotatedZPlus),
                    ItemTypes.GetType(type.RotatedZMinus)
                };
            }
            else
            {
                BlockTypes = new ItemTypes.ItemType[5]
                {
                    type,
                    ItemTypes.GetType(blockType + "x+"),
                    ItemTypes.GetType(blockType + "x-"),
                    ItemTypes.GetType(blockType + "z+"),
                    ItemTypes.GetType(blockType + "z-")
                };
            }

            RecruitmentItem = new InventoryItem(recruitmentItem);
            MiningCooldown  = miningCooldown;
            MinableTypes    = minableTypes;
            NPCTypeKey      = npcType;
            NPCType         = NPC.NPCType.GetByKeyNameOrDefault(npcType);
            OnCraftedAudio  = onCraftedAudio;
            MaxCraftsPerRun = maxCraftsPerRun;
        }
Exemple #2
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            Vector3 rotate = usedNPC.Position.Vector;

            if (type == BuiltinBlocks.MinerJobXN)
            {
                rotate += Vector3.left;
            }
            else if (type == BuiltinBlocks.MinerJobXP)
            {
                rotate += Vector3.right;
            }
            else if (type == BuiltinBlocks.MinerJobZP)
            {
                rotate += Vector3.forward;
            }
            else if (type == BuiltinBlocks.MinerJobZN)
            {
                rotate += Vector3.back;
            }
            usedNPC.LookAt(rotate);

            ServerManager.SendAudio(position.Vector, "stoneDelete");
            var itemList = ItemTypes.GetType(typeBelow).OnRemoveItems;

            state.Inventory.Add(itemList);
            state.JobIsDone = true;
            state.SetIndicator(NPCIndicatorType.Crafted, cooldown, itemList[0].item.Type);
        }
Exemple #3
0
        public static void OnTryChangeBlock(ModLoader.OnTryChangeBlockData blockData)
        {
            if (antigrief)
            {
                if (blockData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player)
                {
                    if (blockData.TypeNew == ItemTypes.GetType("water"))
                    {
                        Helpers.Chat.Send(blockData.RequestOrigin.AsPlayer, "Not allowed to place water!");
                        blockData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
                        blockData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
                        return;
                    }

                    if (OutofSpawn(blockData.Position, blockData.RequestOrigin.AsPlayer) == false)
                    {
                        Helpers.Chat.Send(blockData.RequestOrigin.AsPlayer, string.Format("Too close to spawn!  Must be {0} blocks from spawn!", spawnprotectionrange));
                        blockData.InventoryItemResults.Clear();
                        blockData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
                        blockData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
                        return;
                    }
                    if (OutofBannerRange(blockData.TypeNew, blockData.Position, blockData.RequestOrigin.AsPlayer, out BlockEntities.Implementations.BannerTracker.Banner banner) == false)
                    {
                        Helpers.Chat.Send(blockData.RequestOrigin.AsPlayer, string.Format("Too close to {0} : {1}, must be {2} blocks from a banner", banner.Colony.Name, banner.Position, GetBannerRadius()));
                        blockData.InventoryItemResults.Clear();
                        blockData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
                        blockData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
                        return;
                    }
                }
            }
        }
Exemple #4
0
        public void SetConstructionType(string type, JSONNode args = null)
        {
            switch (type)
            {
            case "pipliz.digger":
                SetConstructionType(new Types.DiggerBasic());
                SetIterationType(new Iterators.TopToBottom(this));
                break;

            case "pipliz.builder":
                if (args != null)
                {
                    ItemTypes.ItemType buildType = ItemTypes.GetType(ItemTypes.IndexLookup.GetIndex(args.GetAsOrDefault("builderBlockType", "air")));
                    if (buildType != null && buildType.ItemIndex != 0)
                    {
                        SetConstructionType(new Types.BuilderBasic(buildType));
                        SetIterationType(new Iterators.BottomToTop(this));
                    }
                }
                break;

            default:
                Log.WriteWarning("Unexpected construction type: {0}", type);
                break;
            }
        }
Exemple #5
0
        public ForagingJobSettings(string blockType, string npcTypeKey, ILootTable lootTable, int foragingTimeMinSec, int foragingTimeMaxSec, float lootLuckModifier = 0f)
        {
            ItemTypes.ItemType type = ItemTypes.GetType(blockType);
            if (type.RotatedXMinus != null)
            {
                BlockTypes = new ItemTypes.ItemType[5]
                {
                    type,
                    ItemTypes.GetType(type.RotatedXPlus),
                    ItemTypes.GetType(type.RotatedXMinus),
                    ItemTypes.GetType(type.RotatedZPlus),
                    ItemTypes.GetType(type.RotatedZMinus)
                };
            }
            else
            {
                BlockTypes = new ItemTypes.ItemType[5]
                {
                    type,
                    ItemTypes.GetType(blockType + "x+"),
                    ItemTypes.GetType(blockType + "x-"),
                    ItemTypes.GetType(blockType + "z+"),
                    ItemTypes.GetType(blockType + "z-")
                };
            }

            NPCType            = NPCType.GetByKeyNameOrDefault(npcTypeKey);
            RecruitmentItem    = new InventoryItem(LeafSash.NAME);
            LootTable          = lootTable;
            ForagingTimeMaxSec = foragingTimeMaxSec;
            ForagingTimeMinSec = foragingTimeMinSec;
            LuckMod            = lootLuckModifier;
        }
Exemple #6
0
 public static void onButtonPushed(ButtonPressCallbackData data)
 {
     if (!data.ButtonIdentifier.StartsWith(MODNAMESPACE))
     {
         return;
     }
     data.ButtonIdentifier = data.ButtonIdentifier.Remove(0, 22);
     if (data.ButtonIdentifier.StartsWith("RemoveType"))
     {
         data.ButtonIdentifier = data.ButtonIdentifier.Remove(0, 11);
         if (ProductionItems[data.Player.ActiveColony.ColonyID].ContainsKey(data.ButtonIdentifier))
         {
             ProductionItems[data.Player.ActiveColony.ColonyID].Remove(data.ButtonIdentifier);
             Chat.Send(data.Player, "<color=yellow>" + data.ButtonIdentifier + " has been removed</color>");
             SendUI(data.Player);
             return;
         }
         Chat.Send(data.Player, "<color=yellow>" + data.ButtonIdentifier + " was not being recorded, could not remove</color>");
     }
     else if (data.ButtonIdentifier.StartsWith("AddType"))
     {
         string typeName = ItemTypes.GetType(data.Player.Inventory.Items[0].Type).Name;
         if (!ProductionItems[data.Player.ActiveColony.ColonyID].ContainsKey(typeName))
         {
             ProductionItems[data.Player.ActiveColony.ColonyID][typeName] = new int[10];
             Chat.Send(data.Player, "<color=yellow>Added " + typeName + " to production chain will take 5 ingame days to see all data</color>");
             SendUI(data.Player);
             return;
         }
         Chat.Send(data.Player, "<color=yellow>" + typeName + " is already being recorded</color>");
     }
 }
        public GeneratorJobLitSettings(string blockType, string npcTypeKey, InventoryItem energyitem, float craftingCooldown = 5f, int maxCraftsPerHaul = 5, string onCraftedAudio = null) : base(null, npcTypeKey, energyitem, craftingCooldown, maxCraftsPerHaul, onCraftedAudio)
        {
            if (blockType != null)
            {
                ItemTypes.ItemType baseType = ItemTypes.GetType(blockType);
                bool baseHasRotated         = baseType.RotatedXPlus != null;
                ItemTypes.ItemType litType  = ItemTypes.GetType(blockType + "Lit");
                bool litHasRotated          = litType.RotatedXPlus != null;

                BlockTypes = new ItemTypes.ItemType[]
                {
                    baseType,
                    baseHasRotated ? ItemTypes.GetType(baseType.RotatedXPlus) : ItemTypes.GetType(blockType + "x+"),
                    baseHasRotated ? ItemTypes.GetType(baseType.RotatedXMinus) : ItemTypes.GetType(blockType + "x-"),
                    baseHasRotated ? ItemTypes.GetType(baseType.RotatedZPlus) : ItemTypes.GetType(blockType + "z+"),
                    baseHasRotated ? ItemTypes.GetType(baseType.RotatedZMinus) : ItemTypes.GetType(blockType + "z-"),

                    litType,
                    litHasRotated ? ItemTypes.GetType(litType.RotatedXPlus) : ItemTypes.GetType(litType.Name + "x+"),
                    litHasRotated ? ItemTypes.GetType(litType.RotatedXMinus) : ItemTypes.GetType(litType.Name + "x-"),
                    litHasRotated ? ItemTypes.GetType(litType.RotatedZPlus) : ItemTypes.GetType(litType.Name + "z+"),
                    litHasRotated ? ItemTypes.GetType(litType.RotatedZMinus) : ItemTypes.GetType(litType.Name + "z-"),
                };
            }
        }
Exemple #8
0
 public static void UIManagement(Players.Player player, PlayerClickedData data)
 {
     if (data.TypeSelected == ItemTypes.GetType(QuestBookType.NAME).ItemIndex&& data.ClickType == PlayerClickedData.EClickType.Right && player.ActiveColony != null)
     {
         QuestingSystem.OnPlayerPushedNetworkUIButton(data);
     }
 }
        public static void OnNPCCraftedRecipe(IJob job, Recipe recipe, List <RecipeResult> results)
        {
            IncrimentSkill(job.NPC);

            var inv = SettlerInventory.GetSettlerInventory(job.NPC);

            inv.IncrimentStat("Number of Crafts");

            double weightSum = 0;
            double roll      = Random.Next() + inv.GetSkillModifier();
            List <RecipeResult> bonusItems = new List <RecipeResult>();

            foreach (var item in results)
            {
                weightSum += 1;

                if (roll > weightSum)
                {
                    bonusItems.Add(new RecipeResult(item.Type, item.Amount));
                }

                inv.IncrimentStat(ItemTypes.GetType(item.Type).Name, item.Amount);
            }

            results.AddRange(bonusItems);
        }
Exemple #10
0
        public AngryGuardJobSettings(string blockTypeKey, string npcTypeKey, EGuardSleepType sleepType, int damage, int range, int cooldownShot, string shootAudio, InventoryItem shootItem, InventoryItem recruitmentItem)
        {
            this.BlockTypes = new ItemTypes.ItemType[5] {
                ItemTypes.GetType(blockTypeKey),
                ItemTypes.GetType(blockTypeKey + "x+"),
                ItemTypes.GetType(blockTypeKey + "x-"),
                ItemTypes.GetType(blockTypeKey + "z+"),
                ItemTypes.GetType(blockTypeKey + "z-")
            };
            this.OnShootAudio = shootAudio;
            this.ShootItem    = new List <InventoryItem> {
                shootItem
            };
            this.NPCType         = NPCType.GetByKeyNameOrDefault(npcTypeKey);
            this.SleepType       = sleepType;
            this.Damage          = damage;
            this.Range           = range;
            this.RecruitmentItem = recruitmentItem;
            this.CooldownShot    = cooldownShot;

            // those are static for all
            this.CooldownSearchingTarget = 0.5f;
            this.CooldownMissingItem     = 1.5f;
            this.SleepSafetyPeriod       = 1f;
            this.OnHitAudio = "fleshHit";
        }
        public static void RemoveInventory(Colony colony, ushort type, int amount)
        {
            DebugLog.Write(MethodBase.GetCurrentMethod().DeclaringType + "::" + MethodBase.GetCurrentMethod().Name, "Type: " + type.ToString() + ", Amount: " + amount.ToString());

            ColonyStatistics    stats     = Statistics.GetColonyStats(colony);
            TimedItemStatistics itemStats = stats.GetTimedItemStats(type);

            itemStats.RemoveInventory(amount);

            AddConsumerRemoveProducer(itemStats, ScientistJobSettingsHookOnNPCAtJob.npc, amount);
            AddConsumerRemoveProducer(itemStats, GuardJobSettingsHookShootAtTarget.npc, amount);
            AddConsumerRemoveProducer(itemStats, BlockFarmAreaJobHookOnNPCAtJob.npc, amount);
            AddConsumerRemoveProducer(itemStats, FarmAreaJobHookOnNPCAtJob.npc, amount);
            AddConsumerRemoveProducer(itemStats, BuilderBasicHookDoJob.npc, amount);
            AddConsumerRemoveProducer(itemStats, ColonyShopVisitTrackerHookOnVisit.npc, amount);
            AddConsumerRemoveProducer(itemStats, AbstractAreaJobHookOnNPCAtStockpile.npc, amount);

            if (ItemTypes.GetType(type).ColonyPointsMeal > 0)
            {
                itemStats.UseAsFood(amount);
            }

            if (RuleHookTryExecute.trading)
            {
                itemStats.TradeOut(amount);
            }
        }
Exemple #12
0
        public static void OnPlayerClicked(Players.Player player, Box <Shared.PlayerClickedData> playerClickedData)
        {
            BaseType myTypeOn   = null;
            BaseType myTypeWith = null;

            ItemTypes.ItemType typeOn   = null;
            ItemTypes.ItemType typeWith = null;

            bool clickOnType   = playerClickedData.item1.typeHit != 0;      // Has clicked ON type (block in world)
            bool clickWithType = playerClickedData.item1.typeSelected != 0; // Has clicked WITH type (on hand)

            if (!clickOnType && !clickWithType)
            {
                return;
            }

            if (clickOnType)
            {
                typeOn = ItemTypes.GetType(playerClickedData.item1.typeHit);
            }

            if (clickWithType)
            {
                typeWith = ItemTypes.GetType(playerClickedData.item1.typeSelected);
            }

            while (typeOn != null && !types.TryGetValue(typeOn.Name, out myTypeOn))
            {
                typeOn = typeOn.ParentItemType;
            }

            while (typeWith != null && !types.TryGetValue(typeWith.Name, out myTypeWith))
            {
                typeWith = typeWith.ParentItemType;
            }

            if (null != myTypeOn)
            {
                if (playerClickedData.item1.clickType == ClickType.Left)
                {
                    myTypeOn.OnLeftClickOn(player, playerClickedData);
                }
                else if (playerClickedData.item1.clickType == ClickType.Right)
                {
                    myTypeOn.OnRightClickOn(player, playerClickedData);
                }
            }

            if (null != myTypeWith)
            {
                if (playerClickedData.item1.clickType == ClickType.Left)
                {
                    myTypeWith.OnLeftClickWith(player, playerClickedData);
                }
                else if (playerClickedData.item1.clickType == ClickType.Right)
                {
                    myTypeWith.OnRightClickWith(player, playerClickedData);
                }
            }
        }
Exemple #13
0
        private static SchematicMetadata GenerateMetaData(string metadataPath, string name, Schematic schematic)
        {
            var metadata = new SchematicMetadata();

            metadata.Name = name;

            for (int Y = 0; Y <= schematic.YMax; Y++)
            {
                for (int Z = 0; Z <= schematic.ZMax; Z++)
                {
                    for (int X = 0; X <= schematic.XMax; X++)
                    {
                        if (schematic.Blocks.GetLength(0) > X &&
                            schematic.Blocks.GetLength(1) > Y &&
                            schematic.Blocks.GetLength(2) > Z &&
                            schematic.Blocks[X, Y, Z] != null)
                        {
                            var block = schematic.Blocks[X, Y, Z].MappedBlock;

                            if (block.CSIndex != ColonyBuiltIn.ItemTypes.AIR.Id)
                            {
                                var buildType = ItemTypes.GetType(block.CSIndex);

                                if (!buildType.Name.Contains("bedend"))
                                {
                                    var index = block.CSIndex;

                                    if (!string.IsNullOrWhiteSpace(buildType.ParentType) && !buildType.Name.Contains("grass") && !buildType.Name.Contains("leaves"))
                                    {
                                        index = ItemTypes.GetType(buildType.ParentType).ItemIndex;
                                    }

                                    if (metadata.Blocks.TryGetValue(index, out var blockMeta))
                                    {
                                        blockMeta.Count++;
                                    }
                                    else
                                    {
                                        blockMeta = new SchematicBlockMetadata();
                                        blockMeta.Count++;
                                        blockMeta.ItemId = index;

                                        metadata.Blocks.Add(blockMeta.ItemId, blockMeta);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            metadata.MaxX = schematic.XMax;
            metadata.MaxY = schematic.YMax;
            metadata.MaxZ = schematic.ZMax;

            JSON.Serialize(metadataPath, metadata.JsonSerialize());

            return(metadata);
        }
Exemple #14
0
        private static bool HasCollisionHelper(ref VoxelRay centerRay, Pipliz.Vector3Int pos, RayCastType type, ref RayHit.VoxelHit hit)
        {
            ushort hitType = default(ushort);

            if (!World.TryGetTypeAt(pos, out hitType))
            {
                return(true);
            }
            if (hitType == 0)
            {
                return(false);
            }
            if (hitType == BuiltinBlocks.Indices.water)
            {
                return(false);
            }
            if ((type & RayCastType.HitBoxesSelection) != 0)
            {
                ItemTypes.ItemType itemType = ItemTypes.GetType(hitType);
                if (itemType.BoxColliders != null && itemType.CollideSelection)
                {
                    Vector3          vector = pos.Vector;
                    List <BoundsPip> boxes  = itemType.BoxColliders;
                    for (int i = 0; i < boxes.Count; i++)
                    {
                        BoundsPip bounds2 = boxes[i];
                        bounds2.Shift(pos.Vector);
                        if (centerRay.Intersects(bounds2, out float hitDist2, out VoxelSide hitSides2) && hitDist2 < hit.Distance)
                        {
                            hit.TypeHit          = hitType;
                            hit.Distance         = hitDist2;
                            hit.VoxelPositionHit = pos;
                            hit.VoxelSideHit     = hitSides2;
                            hit.BoundsHit        = new RotatedBounds(boxes[i], Quaternion.identity);
                            hit.BoundsCenter     = pos.Vector;
                        }
                    }
                    return(false);
                }
            }
            if ((type & RayCastType.HitNonSolidAsSolid) == 0 && !ItemTypes.Solids[hitType])
            {
                return(false);
            }
            BoundsPip bounds = default(BoundsPip);

            bounds.SetCenterSize(pos.Vector, Vector3.one);
            if (centerRay.Intersects(bounds, out float hitDist, out VoxelSide hitSides) && hitDist < hit.Distance)
            {
                hit.TypeHit          = hitType;
                hit.Distance         = hitDist;
                hit.VoxelPositionHit = pos;
                hit.VoxelSideHit     = hitSides;
                hit.BoundsHit        = new RotatedBounds(Vector3.zero, Vector3.one, Quaternion.identity);
                hit.BoundsCenter     = pos.Vector;
            }
            return(false);
        }
Exemple #15
0
        public static void OnAdd(Vector3Int position, ushort type, Players.Player player)
        {
            ushort num;

            if (World.TryGetTypeAt(position.Add(0, -1, 0), out num) && ItemTypes.GetType(num).IsFertile)
            {
                BlockTracker.Add(new Herbs(position));
            }
        }
Exemple #16
0
 public static void OnPlayerClicked(Players.Player player, PlayerClickedData data)
 {
     if (data.TypeSelected == ItemTypes.GetType("NACH0.Types.ProductionStats").ItemIndex)
     {
         if (data.ClickType == PlayerClickedData.EClickType.Left)
         {
             SendUI(player);
         }
     }
 }
Exemple #17
0
 public static void PlaceItem(Players.Player player, PlayerClickedData data)
 {
     if (data.TypeSelected == ItemTypes.GetType("NACH0.Types.FoodGen").ItemIndex)
     {
         if (data.ClickType == PlayerClickedData.EClickType.Left)
         {
             SendUI(player);
         }
     }
 }
            public ReplaceType(JSONNode node)
            {
                ushort dig;
                ushort place;

                node.TryGetAs <ushort>("wingdings.construction.selection1", out dig);
                node.TryGetAs <ushort>("wingdings.construction.selection2", out place);

                this.dig   = ItemTypes.GetType(dig);
                this.place = ItemTypes.GetType(place);
            }
Exemple #19
0
        public void DumpItemsToJSON(string filenameandpath, List <ushort> itemlist)
        {
            HelperFunctions hf   = new HelperFunctions();
            JSONNode        root = new JSONNode();

            foreach (ushort i in itemlist)
            {
                root = hf.ConvertItemToJson(root, ItemTypes.GetType(i));
            }
            JSON.Serialize(filenameandpath, root);
        }
Exemple #20
0
        private void NPCRemoveBlock(Vector3Int position)
        {
            if (World.TryGetTypeAt(position, out ushort type))
            {
                List <ItemTypes.ItemTypeDrops> ItemDrops = ItemTypes.GetType(type).OnRemoveItems;

                NPC.Inventory.Add(ItemDrops);

                GetStockpile().Add(type);
            }
            NPCPlaceBlock(position, BuiltinBlocks.Air, Owner);
        }
Exemple #21
0
        public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
        {
            typeBelow = ItemTypes.IndexLookup.GetOrGenerate(node.GetAs <string>("typeBelow"));
            JSONNode customDataNode = ItemTypes.GetType(typeBelow).CustomDataNode;

            if (customDataNode != null)
            {
                MiningCooldown = customDataNode.GetAsOrDefault("minerMiningTime", 8f);
            }
            InitializeJob(player, (Vector3Int)node["position"], node.GetAs <int>("npcID"));
            return(this);
        }
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
        {
            if (userData.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            var suffix  = "bottom";
            var newType = userData.TypeNew;

            if (userData.CallbackOrigin == ModLoader.OnTryChangeBlockData.ECallbackOrigin.ClientPlayerManual)
            {
                var side = userData.PlayerClickedData.GetVoxelHit().SideHit;

                switch (side)
                {
                case VoxelSide.xPlus:
                    suffix = "right";
                    break;

                case VoxelSide.xMin:
                    suffix = "left";
                    break;

                case VoxelSide.yPlus:
                    suffix = "bottom";
                    break;

                case VoxelSide.yMin:
                    suffix = "top";
                    break;

                case VoxelSide.zPlus:
                    suffix = "front";
                    break;

                case VoxelSide.zMin:
                    suffix = "back";
                    break;
                }
            }

            if (newType != userData.TypeOld && ItemTypes.IndexLookup.TryGetName(newType.ItemIndex, out var typename))
            {
                var otherTypename = typename + suffix;

                if (ItemTypes.IndexLookup.TryGetIndex(otherTypename, out var otherIndex))
                {
                    userData.TypeNew = ItemTypes.GetType(otherIndex);
                }
            }
        }
Exemple #23
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            state.JobIsDone = true;
            if (positionSub.IsValid)
            {
                ushort num;
                if (World.TryGetTypeAt(positionSub, out num))
                {
                    if (num == 0)
                    {
                        if (state.Inventory.TryGetOneItem(HerbalistRegister.HerbStage1.ItemIndex) || usedNPC.Colony.UsedStockpile.TryRemove(HerbalistRegister.HerbStage1.ItemIndex, 1))
                        {
                            ServerManager.TryChangeBlock(positionSub, HerbalistRegister.HerbStage1.ItemIndex, ServerManager.SetBlockFlags.DefaultAudio);
                            Items.UpdatableBlocks.Herbs.OnAdd(positionSub, HerbalistRegister.HerbStage1.ItemIndex, Owner);
                            state.SetCooldown(1.0);
                            shouldDumpInventory = false;
                        }
                        else
                        {
                            state.SetIndicator(NPCIndicatorType.MissingItem, 2f, HerbalistRegister.HerbStage1.ItemIndex);
                            shouldDumpInventory = (state.Inventory.UsedCapacity > 0f);
                        }
                    }
                    else if (num == HerbalistRegister.HerbStage2.ItemIndex)
                    {
                        if (ServerManager.TryChangeBlock(positionSub, 0, ServerManager.SetBlockFlags.DefaultAudio))
                        {
                            usedNPC.Inventory.Add(ItemTypes.GetType(HerbalistRegister.HerbStage2.ItemIndex).OnRemoveItems);
                            Items.UpdatableBlocks.Herbs.OnRemove(positionSub, HerbalistRegister.HerbStage2.ItemIndex, Owner);
                        }

                        state.SetCooldown(1.0);
                        shouldDumpInventory = false;
                    }
                    else
                    {
                        state.SetCooldown(5.0);
                        shouldDumpInventory = (state.Inventory.UsedCapacity > 0f);
                    }
                }
                else
                {
                    state.SetCooldown((double)Pipliz.Random.NextFloat(3f, 6f));
                }

                positionSub = Vector3Int.invalidPos;
            }
            else
            {
                state.SetCooldown(10.0);
            }
        }
Exemple #24
0
        public static void OnPlayerClicked(Players.Player player, Shared.PlayerClickedData playerClickedData)
        {
            if (playerClickedData.ClickType != PlayerClickedData.EClickType.Right)
            {
                return;
            }

            if (playerClickedData.HitType != PlayerClickedData.EHitType.Block)
            {
                return;
            }

            if (!ItemTypes.GetType(playerClickedData.GetVoxelHit().TypeHit).HasParentType(ItemTypes.GetType("Khanx.Sign")))
            {
                return;
            }

            Vector3Int position = playerClickedData.GetVoxelHit().BlockHit;

            if (!signs.ContainsKey(position))
            {
                signs.Add(position, new Sign(player.ID, "-"));
            }

            Sign s = signs[position];

            NetworkMenu signMenu = new NetworkMenu
            {
                Identifier = "Sign"
            };

            signMenu.LocalStorage.SetAs("header", "Sign");

            if (signs[position].owner == player.ID || PermissionsManager.HasPermission(player, "khanx.setsign"))
            {
                InputField inputField = new InputField("Khanx.Sign." + position.x + "." + position.y + "." + position.z, -1, 100)
                {
                    Multiline = true
                };

                //default value
                signMenu.LocalStorage.SetAs("Khanx.Sign." + position.x + "." + position.y + "." + position.z, s.text);

                signMenu.Items.Add(inputField);
            }
            else
            {
                signMenu.Items.Add(new Label(new LabelData(signs[position].text, UnityEngine.Color.white, UnityEngine.TextAnchor.MiddleCenter, 32)));
            }

            NetworkMenuManager.SendServerPopup(player, signMenu);
        }
        public PorterJobSettings(string blockType, string npcTypeKey)
        {
            if (blockType != null)
            {
                BlockTypes = new ItemTypes.ItemType[1]
                {
                    ItemTypes.GetType(blockType)
                };
            }

            NPCType         = NPCType.GetByKeyNameOrDefault(npcTypeKey);
            RecruitmentItem = new InventoryItem(LeafBag.NAME);
        }
Exemple #26
0
 public ITrackableBlock InitializeOnAdd(Vector3Int position, ushort type, Players.Player player)
 {
     if (World.TryGetTypeAt(position.Add(0, -1, 0), out typeBelow))
     {
         JSONNode customDataNode = ItemTypes.GetType(typeBelow).CustomDataNode;
         if (customDataNode != null)
         {
             MiningCooldown = customDataNode.GetAsOrDefault("minerMiningTime", 8f);
         }
     }
     InitializeJob(player, position, 0);
     return(this);
 }
Exemple #27
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            if (worldTypeChecked)
            {
                Vector3 rotate = usedNPC.Position.Vector;
                if (worldType == BuiltinBlocks.MinerJobXN)
                {
                    rotate += Vector3.left;
                }
                else if (worldType == BuiltinBlocks.MinerJobXP)
                {
                    rotate += Vector3.right;
                }
                else if (worldType == BuiltinBlocks.MinerJobZP)
                {
                    rotate += Vector3.forward;
                }
                else if (worldType == BuiltinBlocks.MinerJobZN)
                {
                    rotate += Vector3.back;
                }
                usedNPC.LookAt(rotate);
            }

            ServerManager.SendAudio(position.Vector, "stoneDelete");

            GatherResults.Clear();
            var itemList = ItemTypes.GetType(typeBelow).OnRemoveItems;

            for (int i = 0; i < itemList.Count; i++)
            {
                GatherResults.Add(itemList[i]);
            }

            ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, this as IJob, position.Add(0, -1, 0), GatherResults);

            InventoryItem toShow = ItemTypes.ItemTypeDrops.GetWeightedRandom(GatherResults);

            if (toShow.Amount > 0)
            {
                state.SetIndicator(new Shared.IndicatorState(MiningCooldown, toShow.Type));
            }
            else
            {
                state.SetCooldown(MiningCooldown);
            }

            state.Inventory.Add(GatherResults);
            state.JobIsDone = true;
        }
        public void ApplyTypes(ConstructionArea area, JSONNode node)
        {
            JSONNode arr;

            if (node != null && node.TryGetChild("selectedTypes", out arr) && arr.NodeType == NodeType.Array && arr.ChildCount > 0)
            {
                ItemTypes.ItemType buildType = ItemTypes.GetType(ItemTypes.IndexLookup.GetIndex(arr[0].GetAs <string>()));
                if (buildType != null && buildType.ItemIndex != 0)
                {
                    area.ConstructionType = new Types.BuilderBasic(buildType);
                    area.IterationType    = new Iterators.BottomToTop(area);
                }
            }
        }
        public void ApplyTypes(ConstructionArea area, JSONNode node)
        {
            JSONNode arr;

            if (node != null && node.TryGetChild("selectedTypes", out arr) && arr.NodeType == NodeType.Array && arr.ChildCount > 0)
            {
                ItemTypes.ItemType digTpe = ItemTypes.GetType(ItemTypes.IndexLookup.GetIndex(arr[0].GetAs <string>()));
                if (digTpe != null && digTpe.ItemIndex != 0)
                {
                    area.ConstructionType = new Types.DiggerSpecial(digTpe);
                    area.IterationType    = new Iterators.TopToBottom(area);
                }
            }
        }
 public MachineJobSettings(string blockType, string npcTypeKey, float craftingCooldown = 5f, int maxCraftsPerHaul = 5, string onCraftedAudio = null)
 {
     if (blockType != null)
     {
         BlockTypes = new ItemTypes.ItemType[1]
         {
             ItemTypes.GetType(blockType)
         };
     }
     NPCTypeKey       = npcTypeKey;
     NPCType          = NPC.NPCType.GetByKeyNameOrDefault(npcTypeKey);
     CraftingCooldown = craftingCooldown;
     MaxCraftsPerHaul = maxCraftsPerHaul;
     OnCraftedAudio   = onCraftedAudio;
 }