Esempio n. 1
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);
     }
 }
Esempio n. 2
0
        public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData)
        {
            if (ItemTypes.IndexLookup.TryGetIndex(SchematicTool.NAME, out var schematicItem) &&
                playerClickData.TypeSelected == schematicItem)
            {
                if (player.ActiveColony == null)
                {
                    PandaChat.Send(player, _localizationHelper, "ErrorOpening", ChatColor.red);
                    return;
                }

                if (!_awaitingClick.ContainsKey(player))
                {
                    SendMainMenu(player);
                }
                else
                {
                    var tuple = _awaitingClick[player];
                    _awaitingClick.Remove(player);

                    switch (tuple.Item1)
                    {
                    case SchematicClickType.Build:
                        Vector3Int location = playerClickData.GetVoxelHit().BlockHit.Add(0, 1, 0);
                        var        args     = new JSONNode();
                        args.SetAs("constructionType", GameLoader.NAMESPACE + ".SchematicBuilder");
                        args.SetAs(SchematicBuilderLoader.NAME + ".SchematicName", tuple.Item2);
                        args.SetAs(SchematicBuilderLoader.NAME + ".Rotation", tuple.Item3);

                        if (SchematicReader.TryGetSchematic(tuple.Item2, player.ActiveColony.ColonyID, location, out var schematic))
                        {
                            if (tuple.Item3 >= Schematic.Rotation.Right)
                            {
                                schematic.Rotate();
                            }

                            if (tuple.Item3 >= Schematic.Rotation.Back)
                            {
                                schematic.Rotate();
                            }

                            if (tuple.Item3 >= Schematic.Rotation.Left)
                            {
                                schematic.Rotate();
                            }

                            var maxSize = location.Add(schematic.XMax - 1, schematic.YMax - 1, schematic.ZMax - 1);
                            AreaJobTracker.CreateNewAreaJob("pipliz.constructionarea", args, player.ActiveColony, location, maxSize);
                            AreaJobTracker.SendData(player);
                        }

                        break;

                    case SchematicClickType.Archetect:

                        break;
                    }
                }
            }
        }
Esempio n. 3
0
 public PlayerClickedData.VoxelHit ToPlayerClick()
 {
     PlayerClickedData.VoxelHit hit = PlayerClickedData.PoolGet <PlayerClickedData.VoxelHit>();
     hit.BlockHit      = VoxelPositionHit;
     hit.DistanceToHit = Distance;
     hit.SideHit       = VoxelSideHit;
     hit.TypeHit       = TypeHit;
     return(hit);
 }
Esempio n. 4
0
 private static void OnClicked(Players.Player sender, PlayerClickedData data)
 {
     if (data.ConsumedType != PlayerClickedData.EConsumedType.Not || data.IsHoldingButton || (data.ClickType != PlayerClickedData.EClickType.Right || data.OnBuildCooldown) || (data.HitType != PlayerClickedData.EHitType.Block || (int)data.TypeSelected != (int)ItemTypes.GetType(settings.ItemTypeName).ItemIndex || !sender.Inventory.TryRemove(data.TypeSelected, 1, -1, true)))
     {
         return;
     }
     data.ConsumedType = PlayerClickedData.EConsumedType.UsedAsTool;
     FastGlider.CreateGlider(data.GetExactHitPositionWorld() + settings.SpawnOffset, Quaternion.identity, FastGlider.CreateVehicleDescription(MeshedObjectID.GetNew()), (Players.Player)null);
 }
Esempio n. 5
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);
         }
     }
 }
Esempio n. 6
0
 public static void OnPlayerClicked(Players.Player player, PlayerClickedData boxedData)
 {
     if (boxedData.ClickType == PlayerClickedData.EClickType.Left)
     {
         if (boxedData.TypeSelected == ItemTypes.IndexLookup.GetIndex("Colony wand"))
         {
             ColonyWandUI.ColonyManager.SendUI(player);
         }
     }
 }
Esempio n. 7
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 static void OnPlayerClicked(Players.Player player, PlayerClickedData playerClickData)
 {
     if (playerClickData.ClickType == PlayerClickedData.EClickType.Right &&
         playerClickData.HitType == PlayerClickedData.EHitType.Block &&
         World.TryGetTypeAt(playerClickData.GetVoxelHit().BlockHit, out ushort blockHit) &&
         blockHit == ColonyBuiltIn.ItemTypes.BERRYBUSH)
     {
         var inv = player.Inventory;
         inv.TryAdd(ColonyBuiltIn.ItemTypes.BERRY, 1);
     }
 }
Esempio n. 9
0
 public static void OnPlayerClicked(Players.Player player, PlayerClickedData clickedData)
 {
     if (Helpers.Player.ExactPermission(player, "Master"))
     {
         if (clickedData.ClickType == PlayerClickedData.EClickType.Left)
         {
             if (clickedData.HitType == PlayerClickedData.EHitType.Block)
             {
                 Helpers.Chat.SendSilent(player, ItemTypes.IndexLookup.GetName(clickedData.GetVoxelHit().TypeHit));
             }
         }
     }
 }
Esempio n. 10
0
        public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData)
        {
            //Only launch on RIGHT click
            if (player == null || playerClickData.ClickType != PlayerClickedData.EClickType.Right)
            {
                return;
            }

            if (ItemTypes.IndexLookup.TryGetIndex(GameLoader.NAMESPACE + ".Backpack", out var backpackItem) &&
                playerClickData.TypeSelected == backpackItem)
            {
                NetworkMenuManager.SendServerPopup(player, MainMenu(player));
            }
        }
Esempio n. 11
0
        public void OnClicked(Players.Player sender, PlayerClickedData click)
        {
            int countConnected = Players.CountConnected;

            Players.Player player = null;

            for (int index = 0; index < countConnected; ++index)
            {
                Players.Player           connectedByIndex = Players.GetConnectedByIndex(index);
                MeshedVehicleDescription description;

                if (connectedByIndex != null &&
                    MeshedObjectManager.TryGetVehicle(connectedByIndex, out description) &&
                    description.Object.ObjectID.ID == _meshedVehicleDescription.Object.ObjectID.ID)
                {
                    player = connectedByIndex;
                }
            }

            if (click.ClickType == PlayerClickedData.EClickType.Right)
            {
                if (player == null)
                {
                    _player = sender;
                    MeshedObjectManager.Attach(sender, _meshedVehicleDescription);
                }
                else
                {
                    _player = null;
                    MeshedObjectManager.Detach(player);
                }
            }
            else
            {
                if (click.ClickType != PlayerClickedData.EClickType.Left || player != null)
                {
                    return;
                }

                if (Train.TrainTransports.TryGetValue(TrainType.ConnectedBlock.BlockType, out var trainTransportsList) && trainTransportsList.Contains(this))
                {
                    trainTransportsList.Remove(this);
                }

                _removed = true;
                _meshedVehicleDescription.Object.SendRemoval(Position, _animatedObject.ObjSettings);
                sender.Inventory.TryAdd(_trainId, 1, -1, true);
            }
        }
Esempio n. 12
0
 public static void PlaceItem(Players.Player player, PlayerClickedData data)
 {
     if (data.TypeSelected != ItemTypes.GetType(itemName).ItemIndex)
     {
         return;
     }
     else if (data.TypeSelected == ItemTypes.GetType(itemName).ItemIndex)
     {
         if (data.ClickType == PlayerClickedData.EClickType.Left)
         {
             Dictionary <string, JobCounts> jobCounts = SendColonyUI.GetJobCounts(player.ActiveColony);
             NetworkMenuManager.SendServerPopup(player, SendColonyUI.BuildMenu(player, jobCounts, false, string.Empty, 0));
         }
     }
 }
Esempio n. 13
0
        public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData)
        {
            //Only launch on RIGHT click
            if (player == null || playerClickData.ClickType != PlayerClickedData.EClickType.Right || player.ActiveColony == null)
            {
                return;
            }

            if (ItemTypes.IndexLookup.TryGetIndex(GameInitializer.NAMESPACE + ".ColonyManagementTool", out var toolItem) &&
                playerClickData.TypeSelected == toolItem)
            {
                Dictionary <string, JobCounts> jobCounts = GetJobCounts(player.ActiveColony);
                NetworkMenuManager.SendServerPopup(player, BuildMenu(player, jobCounts, false, string.Empty, 0));
            }
        }
Esempio n. 14
0
        private static void OnClicked(Players.Player sender, PlayerClickedData data)
        {
            if (data == null ||
                data.TypeSelected == default(ushort) ||
                data.ConsumedType != PlayerClickedData.EConsumedType.Not ||
                data.IsHoldingButton ||
                (data.ClickType != PlayerClickedData.EClickType.Right || data.OnBuildCooldown) ||
                (data.HitType != PlayerClickedData.EHitType.Block ||
                 !TrainTypes.TryGetValue(ItemId.GetItemId(data.TypeSelected), out var cSType) || !sender.Inventory.TryRemove(data.TypeSelected, 1, -1, true)))
            {
                return;
            }

            data.ConsumedType = PlayerClickedData.EConsumedType.UsedAsTool;
            CreateTrain(cSType, data.GetExactHitPositionWorld());
        }
        public static void ConnectedBlockInfo(Players.Player player, PlayerClickedData playerClickData)
        {
            //Only launch on RIGHT click
            if (player == null || playerClickData.ClickType != PlayerClickedData.EClickType.Right || player.ActiveColony == null)
            {
                return;
            }

            if (playerClickData.HitType == PlayerClickedData.EHitType.Block &&
                ItemTypes.IndexLookup.TryGetIndex(GameLoader.NAMESPACE + ".ConnectedBlockTool", out var toolItem) &&
                playerClickData.TypeSelected == toolItem &&
                ConnectedBlockSystem.BlockLookup.TryGetValue(ItemId.GetItemId(playerClickData.GetVoxelHit().TypeHit), out var cSType))
            {
                PandaChat.Send(player, "Side Hit: " + playerClickData.GetVoxelHit().SideHit);
                PandaChat.Send(player, "Connected Sides: " + string.Join(", ", cSType.ConnectedBlock.Connections.Select(c => c.ToString()).ToArray()));
                PandaChat.Send(player, "Origin Sides: " + string.Join(", ", cSType.ConnectedBlock.Origin.Select(c => c.ToString()).ToArray()));                PandaChat.Send(player, "BlockRotationDegrees: " + cSType.ConnectedBlock.BlockRotationDegrees.ToString());
                PandaChat.Send(player, "RotationAxis: " + cSType.ConnectedBlock.RotationAxis.ToString());
            }
        }
Esempio n. 16
0
        public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData)
        {
            //Only launch on RIGHT click
            if (player == null || playerClickData.ClickType != PlayerClickedData.EClickType.Right || playerClickData.HitType != PlayerClickedData.EHitType.Block || player.ActiveColony == null)
            {
                return;
            }

            var voxel   = playerClickData.GetVoxelHit();
            var itemHit = ItemId.GetItemId(voxel.TypeHit);

            if (StorageFactory.CrateTypes.ContainsKey(itemHit.Name) &&
                StorageFactory.CrateLocations.TryGetValue(player.ActiveColony, out var positions) &&
                positions.ContainsKey(voxel.BlockHit))
            {
                LastCrateClick[player] = voxel.BlockHit;
                NetworkMenuManager.SendServerPopup(player, MainMenu(player));
            }
        }
Esempio n. 17
0
 public static void PlaceItem(Players.Player player, PlayerClickedData data)
 {
     if (data.TypeSelected == ItemTypes.GetType(Nach0ColonyBuiltIn.ItemTypes.COMMANDTOOL).ItemIndex)
     {
         PlayerClickedData.VoxelHit voxelData = data.GetVoxelHit();
         if (data.ClickType == PlayerClickedData.EClickType.Left)
         {
             SendCommandUI.SendUI(player);
         }
         else if (data.ClickType == PlayerClickedData.EClickType.Right)
         {
             if (PlayerClickedData.EHitType.Block == data.HitType && voxelData.SideHit == VoxelSide.yPlus)
             {
                 if (commandUIInteraction.item_placer_dict.ContainsKey(player))
                 {
                     ServerManager.TryChangeBlock(voxelData.PositionBuild, ItemTypes.GetType(commandUIInteraction.item_placer_dict[player]).ItemIndex, player);
                 }
             }
         }
     }
 }
Esempio n. 18
0
        public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData)
        {
            if (player == null)
            {
                return;
            }

            foreach (var item in OpenMenuItems)
            {
                if (playerClickData.ClickType != item.ActivateClickType)
                {
                    continue;
                }

                if (ItemTypes.IndexLookup.TryGetIndex(item.ItemName, out var menuItem) &&
                    playerClickData.TypeSelected == menuItem)
                {
                    SendMenu(player, item.UIUrl);
                }
            }
        }
Esempio n. 19
0
        public static void Click(Players.Player player, PlayerClickedData playerClickData)
        {
            var healed = false;

            if (!_coolDown.ContainsKey(player))
            {
                _coolDown.Add(player, 0);
            }

            if (playerClickData.ClickType == PlayerClickedData.EClickType.Right &&
                playerClickData.TypeSelected == Item.ItemIndex)
            {
                if (Time.MillisecondsSinceStart > _coolDown[player])
                {
                    var healing = new HealingOverTimePC(player, INITIALHEAL, TOTALHOT, 5);
                    healed = true;
                }
            }
            else if (playerClickData.ClickType == PlayerClickedData.EClickType.Left &&
                     playerClickData.TypeSelected == Item.ItemIndex &&
                     playerClickData.HitType == PlayerClickedData.EHitType.NPC)
            {
                if (NPCTracker.TryGetNPC(playerClickData.GetNPCHit().NPCID, out var npc))
                {
                    if (Time.MillisecondsSinceStart > _coolDown[player])
                    {
                        var heal = new HealingOverTimeNPC(npc, INITIALHEAL, TOTALHOT, 5, Item.ItemIndex);
                        healed = true;
                    }
                }
            }

            if (healed)
            {
                _coolDown[player]            = Time.MillisecondsSinceStart + COOLDOWN;
                playerClickData.ConsumedType = PlayerClickedData.EConsumedType.UsedByMod;
                AudioManager.SendAudio(player.Position, GameLoader.NAMESPACE + ".Bandage");
                player.Inventory.TryRemove(Item.ItemIndex);
            }
        }
Esempio n. 20
0
        public static void OnPlayerClicked(Players.Player player, PlayerClickedData playerClickData)
        {
            if (playerClickData.ClickType == PlayerClickedData.EClickType.Right &&
                playerClickData.HitType == PlayerClickedData.EHitType.Block &&
                ItemTypes.TryGetType(playerClickData.GetVoxelHit().TypeHit, out ItemTypes.ItemType itemHit))
            {
                var baseType = itemHit.GetRootParentType();

                if (baseType.Categories != null &&
                    baseType.Categories.Count != 0 &&
                    baseType.Categories.Contains("door", StringComparer.CurrentCultureIgnoreCase))
                {
                    ushort replacement = ColonyBuiltIn.ItemTypes.AIR;

                    if (itemHit.Name == baseType.RotatedXMinus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedZMinus);
                    }
                    else if (itemHit.Name == baseType.RotatedZMinus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedXMinus);
                    }
                    else if (itemHit.Name == baseType.RotatedXPlus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedZPlus);
                    }
                    else if (itemHit.Name == baseType.RotatedZPlus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedXPlus);
                    }

                    if (replacement != ColonyBuiltIn.ItemTypes.AIR)
                    {
                        ServerManager.TryChangeBlock(playerClickData.GetVoxelHit().BlockHit, replacement, new BlockChangeRequestOrigin(player));
                    }
                }
            }
        }
Esempio n. 21
0
        public static void OnPlayerClicked(Players.Player player, PlayerClickedData boxedData)
        {
            if (player == null)
            {
                return;
            }

            if (boxedData.ClickType == PlayerClickedData.EClickType.Right)
            {
                if (boxedData.HitType == PlayerClickedData.EHitType.Block)
                {
                    if (boxedData.GetVoxelHit().TypeHit != BlockTypes.BuiltinBlocks.Types.air.ItemIndex || boxedData.GetVoxelHit().TypeHit != BlockTypes.BuiltinBlocks.Types.water.ItemIndex)
                    {
                        if (boxedData.TypeSelected == ItemTypes.IndexLookup.GetIndex("bucketempty"))
                        {
                            foreach (var item in _fluids)
                            {
                                if (boxedData.GetVoxelHit().TypeHit == item.source)
                                {
                                    FluidManager.Remove(boxedData.GetVoxelHit().BlockHit, EFluids.Water);
                                    if (player.Inventory.TryRemove(boxedData.TypeSelected))
                                    {
                                        if (player.Inventory.TryAdd(ItemTypes.IndexLookup.GetIndex("bucketwater")) == false)
                                        {
                                            if (player.ActiveColony != null)
                                            {
                                                player.ActiveColony.Stockpile.Add(ItemTypes.IndexLookup.GetIndex("bucketwater"));
                                            }
                                            else
                                            {
                                                Helpers.Chat.Send(player, "Inventory is full and no active colony, deleting item!");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (boxedData.TypeSelected == ItemTypes.IndexLookup.GetIndex("bucketwater"))
                        {
                            Vector3Int newPos = boxedData.GetVoxelHit().BlockHit;
                            switch (boxedData.GetVoxelHit().SideHit)
                            {
                            case VoxelSide.xMin:
                                newPos = newPos.Add(-1, 0, 0);
                                break;

                            case VoxelSide.xPlus:
                                newPos = newPos.Add(1, 0, 0);
                                break;

                            case VoxelSide.yMin:
                                newPos = newPos.Add(0, -1, 0);
                                break;

                            case VoxelSide.yPlus:
                                newPos = newPos.Add(0, 1, 0);
                                break;

                            case VoxelSide.zMin:
                                newPos = newPos.Add(0, 0, -1);
                                break;

                            case VoxelSide.zPlus:
                                newPos = newPos.Add(0, 0, 1);
                                break;
                            }
                            if (World.TryGetTypeAt(newPos, out ushort actualType) && actualType == BlockTypes.BuiltinBlocks.Types.air.ItemIndex)
                            {
                                FluidManager.Spread(newPos, EFluids.Water);

                                player.Inventory.TryRemove(ItemTypes.IndexLookup.GetIndex("bucketwater"));
                                if (!player.Inventory.TryAdd(ItemTypes.IndexLookup.GetIndex("bucketempty")))
                                {
                                    if (player.ActiveColony != null)
                                    {
                                        player.ActiveColony.Stockpile.Add(ItemTypes.IndexLookup.GetIndex("bucketempty"));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 22
0
        public static void OnPlayerClicked(Players.Player player, PlayerClickedData boxedData)
        {
            if (boxedData.ClickType == PlayerClickedData.EClickType.Right)
            {
                if (boxedData.HitType == PlayerClickedData.EHitType.Block)
                {
                    string itemname = ItemTypes.IndexLookup.GetName(boxedData.GetVoxelHit().TypeHit);
                    if (itemname.Contains("Geo Dasher"))
                    {
                        NetworkUI.NetworkMenu menu = new NetworkUI.NetworkMenu();
                        menu.LocalStorage.SetAs("header", "Geo Dasher");
                        menu.Width  = 600;
                        menu.Height = 400;

                        List <ValueTuple <NetworkUI.IItem, int> > items = new List <ValueTuple <IItem, int> >
                        {
                            ValueTuple.Create <NetworkUI.IItem, int>(new NetworkUI.Items.InputField("teleporterID"), 200),
                            (new NetworkUI.Items.ButtonCallback("PG.RotNC.Teleporter.SetKey", new NetworkUI.LabelData("Set Teleporter Key", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200),
                            (new NetworkUI.Items.DropDown("Availability", "PG.RotNC.Teleporter.Availability", new List <string>()
                            {
                                "public", "private", "spawn"
                            }), 200)
                        };
                        menu.Items.Add(new NetworkUI.Items.HorizontalRow(items));
                        menu.LocalStorage.SetAs("PG.RotNC.Teleporter.SetKey", 0);
                        menu.LocalStorage.SetAs("PG.RotNC.Teleporter.Availability", 0);

                        menu.Items.Add(new NetworkUI.Items.Line(UnityEngine.Color.black));

                        items = new List <ValueTuple <IItem, int> >
                        {
                            ValueTuple.Create <NetworkUI.IItem, int>(new NetworkUI.Items.InputField("gototeleporter"), 200),
                            (new NetworkUI.Items.ButtonCallback("PG.RotNC.Teleporter.GoToKey", new NetworkUI.LabelData("Go To Key", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200)
                        };
                        menu.Items.Add(new NetworkUI.Items.HorizontalRow(items));
                        menu.LocalStorage.SetAs("PG.RotNC.Teleporter.GoToKey", 0);

                        menu.Items.Add(new NetworkUI.Items.Line(UnityEngine.Color.black));

                        foreach (var colony in player.Colonies)
                        {
                            if (TeleporterManager.GetKey(colony.ColonyID, out string output))
                            {
                                items = new List <ValueTuple <IItem, int> >
                                {
                                    ValueTuple.Create <NetworkUI.IItem, int>(new NetworkUI.Items.Label(colony.Name), 200),
                                    ValueTuple.Create <NetworkUI.IItem, int>(new NetworkUI.Items.Label(output), 200)
                                };
                                menu.Items.Add(new NetworkUI.Items.HorizontalRow(items));
                            }
                        }

                        if (itemname.Contains("x-"))
                        {
                            Vector3Int pos = boxedData.GetVoxelHit().BlockHit.Add(-1, 0, 0);
                            menu.LocalStorage.SetAs("location", NewColonyAPI.Helpers.Utilities.Vector3IntToNode(pos));
                        }
                        if (itemname.Contains("x+"))
                        {
                            Vector3Int pos = boxedData.GetVoxelHit().BlockHit.Add(1, 0, 0);
                            menu.LocalStorage.SetAs("location", NewColonyAPI.Helpers.Utilities.Vector3IntToNode(pos));
                        }
                        if (itemname.Contains("z-"))
                        {
                            Vector3Int pos = boxedData.GetVoxelHit().BlockHit.Add(0, 0, -1);
                            menu.LocalStorage.SetAs("location", NewColonyAPI.Helpers.Utilities.Vector3IntToNode(pos));
                        }
                        if (itemname.Contains("z+"))
                        {
                            Vector3Int pos = boxedData.GetVoxelHit().BlockHit.Add(0, 0, 1);
                            menu.LocalStorage.SetAs("location", NewColonyAPI.Helpers.Utilities.Vector3IntToNode(pos));
                        }
                        NetworkUI.NetworkMenuManager.SendServerPopup(player, menu);
                        return;
                    }
                }
Esempio n. 23
0
        public static void PlacePatrol(Players.Player player, PlayerClickedData playerClickData)
        {
            if (playerClickData.IsConsumed || player.ActiveColony == null || playerClickData.HitType != PlayerClickedData.EHitType.Block)
            {
                return;
            }

            var click      = playerClickData;
            var state      = PlayerState.GetPlayerState(player);
            var rayCastHit = click.GetVoxelHit();

            if (click.TypeSelected == Item.ItemIndex)
            {
                if (rayCastHit.TypeHit != PatrolFlag.ItemIndex)
                {
                    var flagPoint = rayCastHit.BlockHit.Add(0, 1, 0);

                    if (click.ClickType == PlayerClickedData.EClickType.Left)
                    {
                        var hasFlags = player.TakeItemFromInventory(PatrolFlag.ItemIndex);

                        if (!hasFlags)
                        {
                            if (player.ActiveColony.Stockpile.Contains(PatrolFlag.ItemIndex))
                            {
                                hasFlags = true;
                                player.ActiveColony.Stockpile.TryRemove(PatrolFlag.ItemIndex);
                            }
                        }

                        if (!hasFlags)
                        {
                            PandaChat.Send(player, _localizationHelper, "NoFlags", ChatColor.orange);
                        }
                        else
                        {
                            state.FlagsPlaced.Add(flagPoint);
                            ServerManager.TryChangeBlock(flagPoint, PatrolFlag.ItemIndex);
                            PandaChat.Send(player, _localizationHelper, "CreateJob", ChatColor.orange, state.FlagsPlaced.Count.ToString());
                        }
                    }
                }
                else
                {
                    foreach (var knight in Knight.Knights[player.ActiveColony])
                    {
                        if (knight.PatrolPoints.Contains(rayCastHit.BlockHit))
                        {
                            var patrol = string.Empty;

                            if (knight.PatrolType == PatrolType.RoundRobin)
                            {
                                patrol            = "RoundRobinDescription";
                                knight.PatrolType = PatrolType.WaitRoundRobin;
                            }
                            if (knight.PatrolType == PatrolType.WaitRoundRobin)
                            {
                                patrol            = "ZipperDescription";
                                knight.PatrolType = PatrolType.Zipper;
                            }
                            if (knight.PatrolType == PatrolType.Zipper)
                            {
                                patrol            = "WaitRoundRobinDescription";
                                knight.PatrolType = PatrolType.WaitZipper;
                            }
                            else
                            {
                                patrol            = "WaitZipperDescription";
                                knight.PatrolType = PatrolType.RoundRobin;
                            }

                            PandaChat.Send(player, _localizationHelper, "PatrolTypeSet", ChatColor.orange, knight.PatrolType.ToString());
                            PandaChat.Send(player, _localizationHelper, patrol, ChatColor.orange);
                            break;
                        }
                    }
                }
            }

            if (click.TypeSelected == Item.ItemIndex && click.ClickType == PlayerClickedData.EClickType.Right)
            {
                if (state.FlagsPlaced.Count == 0)
                {
                    PandaChat.Send(player, _localizationHelper, "MustPlaceFlag", ChatColor.orange);
                }
                else
                {
                    var knight = new Knight(new List <Vector3Int>(state.FlagsPlaced), player.ActiveColony);
                    state.FlagsPlaced.Clear();
                    player.ActiveColony.JobFinder.RegisterJobAdded(knight);

                    PandaChat.Send(player, _localizationHelper, "Active", ChatColor.orange);

                    player.ActiveColony.JobFinder.Update();
                    player.ActiveColony.SendCommonData();
                }
            }
        }
Esempio n. 24
0
        public static void PlayerClicked(Players.Player player, PlayerClickedData playerClickData)
        {
            if (playerClickData.IsConsumed || playerClickData.TypeSelected != Item.ItemIndex)
            {
                return;
            }

            var click      = playerClickData;
            var rayCastHit = click.GetVoxelHit();
            var ps         = PlayerState.GetPlayerState(player);

            if (!_WandModes.ContainsKey(ps))
            {
                _WandModes.Add(ps, WandMode.Horizontal);
            }

            if (click.ClickType != PlayerClickedData.EClickType.Right)
            {
                if (ps.BuildersWandPreview.Count != 0)
                {
                    foreach (var pos in ps.BuildersWandPreview)
                    {
                        if (World.TryGetTypeAt(pos, out ushort objType) && objType == Selector.ItemIndex)
                        {
                            ServerManager.TryChangeBlock(pos, ColonyBuiltIn.ItemTypes.AIR.Id, new BlockChangeRequestOrigin(player));
                        }
                    }

                    ps.BuildersWandPreview.Clear();
                    ps.BuildersWandTarget = ColonyBuiltIn.ItemTypes.AIR.Id;
                }
                else
                {
                    _WandModes[ps] = _WandModes[ps].Next();
                    PandaChat.Send(player, _localizationHelper, "WandMode", ChatColor.green, _WandModes[ps].ToString(), ps.BuildersWandCharge.ToString());
                }
            }
            else
            {
                if (ps.BuildersWandPreview.Count != 0)
                {
                    var stockpile  = player?.ActiveColony?.Stockpile;
                    var item       = ItemTypes.GetType(ps.BuildersWandTarget);
                    var removeItem = item.OnRemoveItems.FirstOrDefault();
                    foreach (var pos in ps.BuildersWandPreview)
                    {
                        if ((stockpile != null && stockpile.TryRemove(ps.BuildersWandTarget)) || player.Inventory.TryRemove(ps.BuildersWandTarget) ||
                            (removeItem.Type != 0 && stockpile != null && stockpile.TryRemove(removeItem.Type)) || (removeItem.Type != 0 && player.Inventory.TryRemove(removeItem.Type)))
                        {
                            ps.BuildersWandCharge--;
                            ServerManager.TryChangeBlock(pos, ps.BuildersWandTarget, new BlockChangeRequestOrigin(player));
                        }
                        else
                        {
                            ServerManager.TryChangeBlock(pos, ColonyBuiltIn.ItemTypes.AIR.Id, new BlockChangeRequestOrigin(player));
                        }
                    }

                    ps.BuildersWandPreview.Clear();
                    ps.BuildersWandTarget = ColonyBuiltIn.ItemTypes.AIR.Id;

                    if (ps.BuildersWandCharge <= 0)
                    {
                        var inv = player.Inventory;
                        inv.TryRemove(Item.ItemIndex);
                        ps.BuildersWandCharge = DURABILITY + ps.BuildersWandMaxCharge;
                        PandaChat.Send(player, _localizationHelper, "OutOfEnergy", ChatColor.red);
                    }
                }
                else
                {
                    var startingPos = rayCastHit.BlockHit;
                    ps.BuildersWandTarget = rayCastHit.TypeHit;

                    switch (_WandModes[ps])
                    {
                    case WandMode.Horizontal:

                        switch (rayCastHit.SideHit)
                        {
                        case VoxelSide.xMin:
                            startingPos = rayCastHit.BlockHit.Add(-1, 0, 0);
                            zxPos(ps, startingPos);
                            break;

                        case VoxelSide.xPlus:
                            startingPos = rayCastHit.BlockHit.Add(1, 0, 0);
                            zxNeg(ps, startingPos);
                            break;

                        case VoxelSide.zMin:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, -1);
                            xzPos(ps, startingPos);
                            break;

                        case VoxelSide.zPlus:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, 1);
                            xzNeg(ps, startingPos);
                            break;

                        case VoxelSide.yMin:
                            startingPos = rayCastHit.BlockHit.Add(0, -1, 0);
                            xyPos(ps, startingPos);
                            zyPos(ps, startingPos, true);
                            break;

                        case VoxelSide.yPlus:
                            startingPos = rayCastHit.BlockHit.Add(0, 1, 0);
                            xyNeg(ps, startingPos);
                            zyNeg(ps, startingPos, true);
                            break;
                        }

                        break;

                    case WandMode.Vertical:

                        switch (rayCastHit.SideHit)
                        {
                        case VoxelSide.xMin:
                            startingPos = rayCastHit.BlockHit.Add(-1, 0, 0);
                            yxPos(ps, startingPos);
                            break;

                        case VoxelSide.xPlus:
                            startingPos = rayCastHit.BlockHit.Add(1, 0, 0);
                            yxNeg(ps, startingPos);
                            break;

                        case VoxelSide.zMin:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, -1);
                            yzPos(ps, startingPos);
                            break;

                        case VoxelSide.zPlus:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, 1);
                            yzNeg(ps, startingPos);
                            break;

                        default:
                            PandaChat.Send(player, _localizationHelper, "NotValidTopOrBottom", ChatColor.red, _WandModes[ps].ToString());
                            break;
                        }

                        break;

                    case WandMode.TopAndBottomX:

                        switch (rayCastHit.SideHit)
                        {
                        case VoxelSide.yMin:
                            startingPos = rayCastHit.BlockHit.Add(0, -1, 0);
                            xyPos(ps, startingPos);
                            break;

                        case VoxelSide.yPlus:
                            startingPos = rayCastHit.BlockHit.Add(0, 1, 0);
                            xyNeg(ps, startingPos);
                            break;

                        case VoxelSide.xMin:
                            startingPos = rayCastHit.BlockHit.Add(-1, 0, 0);
                            xyNeg(ps, startingPos);
                            break;

                        case VoxelSide.xPlus:
                            startingPos = rayCastHit.BlockHit.Add(1, 0, 0);
                            xyNeg(ps, startingPos);
                            break;

                        case VoxelSide.zMin:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, -1);
                            xyNeg(ps, startingPos);
                            break;

                        case VoxelSide.zPlus:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, 1);
                            xyNeg(ps, startingPos);
                            break;

                        default:
                            PandaChat.Send(player, _localizationHelper, "NotValidTopOrBottom", ChatColor.red, _WandModes[ps].ToString());
                            break;
                        }

                        break;

                    case WandMode.TopAndBottomZ:

                        switch (rayCastHit.SideHit)
                        {
                        case VoxelSide.yMin:
                            startingPos = rayCastHit.BlockHit.Add(0, -1, 0);
                            zyPos(ps, startingPos);
                            break;

                        case VoxelSide.yPlus:
                            startingPos = rayCastHit.BlockHit.Add(0, 1, 0);
                            zyNeg(ps, startingPos);
                            break;

                        case VoxelSide.xMin:
                            startingPos = rayCastHit.BlockHit.Add(-1, 0, 0);
                            zyNeg(ps, startingPos);
                            break;

                        case VoxelSide.xPlus:
                            startingPos = rayCastHit.BlockHit.Add(1, 0, 0);
                            zyNeg(ps, startingPos);
                            break;

                        case VoxelSide.zMin:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, -1);
                            zyNeg(ps, startingPos);
                            break;

                        case VoxelSide.zPlus:
                            startingPos = rayCastHit.BlockHit.Add(0, 0, 1);
                            zyNeg(ps, startingPos);
                            break;

                        default:
                            PandaChat.Send(player, _localizationHelper, "NotValidTopOrBottom", ChatColor.red, _WandModes[ps].ToString());
                            break;
                        }

                        break;
                    }
                }
            }
        }
Esempio n. 25
0
        public static void WeaponAttack(Players.Player player, PlayerClickedData playerClickData)
        {
            if (playerClickData.IsConsumed)
            {
                return;
            }

            var click = playerClickData;
            var state = PlayerState.GetPlayerState(player);

            if (WeaponLookup.ContainsKey(click.TypeSelected) &&
                click.HitType == PlayerClickedData.EHitType.NPC &&
                click.ClickType == PlayerClickedData.EClickType.Left)
            {
                var millisecondsSinceStart = Time.MillisecondsSinceStart;

                if (state.Weapon.IsEmpty() || state.Weapon.Id != click.TypeSelected)
                {
                    state.Weapon = new ItemState
                    {
                        Id         = click.TypeSelected,
                        Durability = WeaponLookup[click.TypeSelected].WepDurability
                    }
                }
                ;

                if (Players.LastPunches.TryGetValue(player, out var num) &&
                    num.TimeSinceThis < Players.PlayerPunchCooldownMS)
                {
                    return;
                }

                Players.LastPunches[player]  = ServerTimeStamp.Now;
                playerClickData.ConsumedType = PlayerClickedData.EConsumedType.UsedByMod;
                var rayCastHit = click.GetNPCHit();

                if (ZombieID.IsZombieID(rayCastHit.NPCID))
                {
                    if (MonsterTracker.TryGetMonsterByID(rayCastHit.NPCID, out var monster))
                    {
                        var dmg = WeaponLookup[click.TypeSelected].Damage.TotalDamage();
                        state.IncrimentStat("Damage Delt", dmg);
                        monster.OnHit(dmg);
                        state.Weapon.Durability--;
                        AudioManager.SendAudio(monster.PositionToAimFor, "punch");
                    }
                }
                else if (NPCTracker.TryGetNPC(rayCastHit.NPCID, out var nPCBase))
                {
                    var dmg = WeaponLookup[click.TypeSelected].Damage.TotalDamage();
                    state.IncrimentStat("Damage Delt", dmg);
                    nPCBase.OnHit(dmg, player, ModLoader.OnHitData.EHitSourceType.PlayerClick);
                    state.Weapon.Durability--;
                    AudioManager.SendAudio(nPCBase.Position.Vector, "punch");
                }

                if (state.Weapon.Durability <= 0)
                {
                    state.Weapon = new ItemState();
                    player.TakeItemFromInventory(click.TypeSelected);

                    PandaChat.Send(player,
                                   _localizationHelper,
                                   "Broke",
                                   ChatColor.orange,
                                   ItemId.GetItemId(click.TypeSelected).LocalizedName(player));
                }
            }
        }