コード例 #1
0
ファイル: Miner.cs プロジェクト: pipliz/Pandaros.Settlers
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (d.TypeNew == Item.ItemIndex && d.TypeOld == BuiltinBlocks.Air)
            {
                if (World.TryGetTypeAt(d.Position.Add(0, -1, 0), out var itemBelow))
                {
                    if (CanMineBlock(itemBelow))
                    {
                        MachineManager.RegisterMachineState(d.RequestedByPlayer,
                                                            new MachineState(d.Position, d.RequestedByPlayer,
                                                                             nameof(Miner)));

                        return;
                    }
                }

                PandaChat.Send(d.RequestedByPlayer, "The mining machine must be placed on stone or ore.",
                               ChatColor.orange);

                d.CallbackState = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
            }
        }
コード例 #2
0
        public void OnTryChangeBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData)
        {
            if (tryChangeBlockData.PlayerClickedData != null && tryChangeBlockData.PlayerClickedData.HitType != Shared.PlayerClickedData.EHitType.Block)
            {
                return;
            }

            var colony = tryChangeBlockData?.RequestOrigin.AsPlayer?.ActiveColony;

            if (colony == null)
            {
                colony = tryChangeBlockData.RequestOrigin.AsColony;
            }

            if (colony != null && StorageFactory.CrateLocations.TryGetValue(colony, out var crateLocs))
            {
                PlacementEventType placementEventType = PlacementEventType.Placed;

                if (StorageFactory.CrateTypes.ContainsKey(tryChangeBlockData.TypeOld.Name))
                {
                    placementEventType = PlacementEventType.Removed;
                }

                if (crateLocs.ContainsKey(tryChangeBlockData.Position))
                {
                    foreach (var s in callbacks)
                    {
                        s.CratePlacementUpdate(colony, placementEventType, tryChangeBlockData.Position);
                    }
                }
            }
        }
コード例 #3
0
 public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
 {
     if (d.RequestOrigin.AsPlayer != null &&
         d.RequestOrigin.AsPlayer.ID.type != NetworkID.IDType.Server &&
         d.RequestOrigin.AsPlayer.ID.type != NetworkID.IDType.Invalid)
     {
         _recordPositionFactory.Enqueue(new TrackedPosition()
         {
             BlockId     = d.TypeOld.ItemIndex,
             X           = d.Position.x,
             Y           = d.Position.y,
             Z           = d.Position.z,
             TimeTracked = DateTime.UtcNow,
             PlayerId    = d.RequestOrigin.AsPlayer.ID.ToString()
         });
     }
     else if (d.RequestOrigin.AsColony != null)
     {
         _recordPositionFactory.Enqueue(new TrackedPosition()
         {
             BlockId     = d.TypeOld.ItemIndex,
             X           = d.Position.x,
             Y           = d.Position.y,
             Z           = d.Position.z,
             TimeTracked = DateTime.UtcNow,
             ColonyId    = d.RequestOrigin.AsColony.Name
         });
     }
 }
コード例 #4
0
        public static void OnTryChangeBlock(ModLoader.OnTryChangeBlockData userData)
        {
            Players.Player causedBy = null;
            if (userData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player)
            {
                causedBy = userData.RequestOrigin.AsPlayer;
            }
            if (causedBy == null || AngryGuards.ModeSetting != GuardMode.Passive || PermissionsManager.HasPermission(causedBy, AngryGuards.PERMISSION_PREFIX + ".peacekeeper"))
            {
                return;
            }

            // check if the block change is within range of a banner(colony)
            foreach (Colony checkColony in ServerManager.ColonyTracker.ColoniesByID.Values)
            {
                if (IsOwnerOrFriendly(checkColony, causedBy))
                {
                    continue;
                }
                foreach (BannerTracker.Banner checkBanner in checkColony.Banners)
                {
                    int distanceX = (int)System.Math.Abs(causedBy.Position.x - checkBanner.Position.x);
                    int distanceZ = (int)System.Math.Abs(causedBy.Position.z - checkBanner.Position.z);
                    if (distanceX < PassiveProtectionRange && distanceZ < PassiveProtectionRange)
                    {
                        PlayerTracker.AddEnemy(checkColony, causedBy);
                        return;
                    }
                }
            }
            return;
        }
コード例 #5
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;
                    }
                }
            }
        }
コード例 #6
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
        {
            if (userData.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (userData.CallbackOrigin == ModLoader.OnTryChangeBlockData.ECallbackOrigin.ClientPlayerManual)
            {
                var side    = userData.PlayerClickedData.VoxelSideHit;
                var newType = userData.TypeNew;
                var suffix  = string.Empty;

                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, out var typename))
                {
                    var otherTypename = typename + suffix;

                    if (ItemTypes.IndexLookup.TryGetIndex(otherTypename, out var otherIndex))
                    {
                        var position = userData.Position;

                        ThreadManager
                        .InvokeOnMainThread(delegate { ServerManager.TryChangeBlock(position, otherIndex); }, 0.1f);
                    }
                }
            }
        }
コード例 #7
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
        {
            if (userData.TypeNew == ItemTypes.IndexLookup.GetIndex("Ulfric.ColonyAddOns.Blocks.AppleBasket") && userData.TypeOld == BuiltinBlocks.Air)
            {
                Logger.Log("Check if area is clear for AppleFarmer");
                Vector3Int position = userData.Position;
                int        xlen     = 7;
                int        zlen     = 7;
                int        radius   = 3;

                //set NW corner
                Vector3Int nwcorner = new Vector3Int(position.x - radius, position.y, position.z - radius);
                Vector3Int secorner = new Vector3Int(position.x + radius, position.y, position.z + radius);

                bool blocked = false;
                for (int x = 0; x <= xlen; x++)
                {
                    for (int z = 0; z <= zlen; z++)
                    {
                        if (World.TryGetTypeAt(nwcorner.Add(x, 0, z), out ushort val) && val != BuiltinBlocks.Air)
                        {
                            blocked = true;
                        }
                    }
                }

                if (blocked)
                {
                    Chat.Send(userData.RequestedByPlayer, "Apple Farmer 9 x 9 area is blocked.");
                }
                else
                {
                    AreaJobTracker.CreateNewAreaJob("Ulfric.ColonyAddOns.AreaJobs.AppleFarm", userData.RequestedByPlayer, nwcorner, secorner);

                    ThreadManager.InvokeOnMainThread(delegate()
                    {
                        ServerManager.TryChangeBlock(position, userData.TypeNew);
                    }, 0.1f);
                }
            }
            if (userData.TypeOld == ItemTypes.IndexLookup.GetIndex("Ulfric.ColonyAddOns.Blocks.AppleBasket") && userData.TypeNew == BuiltinBlocks.Air)
            {
                Logger.Log("Remove job");
                Vector3Int position = userData.Position;
                int        xlen     = 7;
                int        zlen     = 7;
                int        radius   = 3;

                //set NW corner
                Vector3Int nwcorner = new Vector3Int(position.x - radius, position.y, position.z - radius);
                Vector3Int secorner = new Vector3Int(position.x + radius, position.y, position.z + radius);
                AreaJobTracker.RemoveJobAt(nwcorner, secorner);
            }
        }
コード例 #8
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.RequestOrigin.AsPlayer == null ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Server ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Invalid)
            {
                return;
            }

            var ps = PlayerState.GetPlayerState(d.RequestOrigin.AsPlayer);

            if (ps != null)
            {
                if (d.TypeNew.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeNew.ItemIndex, out var item))
                {
                    ushort itemId = GetParentId(d.TypeNew.ItemIndex, item);

                    if (!ps.ItemsPlaced.ContainsKey(itemId))
                    {
                        ps.ItemsPlaced.Add(itemId, 0);
                    }

                    if (!ps.ItemsInWorld.ContainsKey(itemId))
                    {
                        ps.ItemsInWorld.Add(itemId, 0);
                    }

                    ps.ItemsPlaced[itemId]++;
                    ps.ItemsInWorld[itemId]++;
                }

                if (d.TypeNew.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id && d.TypeOld.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeOld.ItemIndex, out var itemOld))
                {
                    ushort itemId = GetParentId(d.TypeOld.ItemIndex, itemOld);

                    if (!ps.ItemsRemoved.ContainsKey(itemId))
                    {
                        ps.ItemsRemoved.Add(itemId, 0);
                    }

                    if (!ps.ItemsInWorld.ContainsKey(itemId))
                    {
                        ps.ItemsInWorld.Add(itemId, 0);
                    }
                    else
                    {
                        ps.ItemsInWorld[itemId]--;
                    }

                    ps.ItemsRemoved[itemId]++;
                }
            }
        }
コード例 #9
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (d.TypeNew == BuiltinBlocks.Air && d.RequestedByPlayer != null)
            {
                RemoveMachine(d.RequestedByPlayer, d.Position);
            }
        }
コード例 #10
0
 public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
 {
     if (ServerManager.BlockEntityTracker.BannerTracker.TryGetClosest(userData.Position, out BannerTracker.Banner existingBanner, ServerManager.ServerSettings.Colony.ExclusiveRadius * 2))
     {
         if (userData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player && !existingBanner.Colony.Owners.Contains(userData.RequestOrigin.AsPlayer))
         {
             PandaChat.SendThrottle(userData.RequestOrigin.AsPlayer, _LocalizationHelper.LocalizeOrDefault("NotYourColony", userData.RequestOrigin.AsPlayer) + string.Join(", ", existingBanner.Colony.Owners.Select(o => o.Name)), ChatColor.red);
             userData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
             userData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
         }
     }
 }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
        public void OnTryChangeBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData)
        {
            if (tryChangeBlockData.PlayerClickedData != null && tryChangeBlockData.PlayerClickedData.HitType != Shared.PlayerClickedData.EHitType.Block)
            {
                return;
            }

            if (tryChangeBlockData.TypeOld.Name == ColonyBuiltIn.ItemTypes.BERRYBUSH)
            {
                tryChangeBlockData.InventoryItemResults.Clear();
                tryChangeBlockData.InventoryItemResults.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.BERRY.Id, Pipliz.Random.Next(30, 51)));
            }
        }
コード例 #13
0
 public static void OnChangedBlock(ModLoader.OnTryChangeBlockData blockData)
 {
     if (blockData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player)
     {
         if (blockData.RequestOrigin.AsPlayer.ActiveColony != null)
         {
             if (blockData.TypeOld.Name.Contains("Geo Dasher"))
             {
                 RemoveTeleporter(blockData.RequestOrigin.AsPlayer.ActiveColony.ColonyID, blockData.Position);
             }
         }
     }
 }
コード例 #14
0
ファイル: Blocks.cs プロジェクト: Barklc/Ulfric.ColonyAddOns
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
        {
            if (userData.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (userData.TypeNew == BuiltinBlocks.Dirt)
            {
                if (ItemTypes.TryGetType(userData.TypeOld, out ItemTypes.ItemType itemtype))
                {
                    if (itemtype.IsFertile && itemtype.CustomDataNode.TryGetAs <float>("fertilizervalue", out float result))
                    {
                        userData.TypeNew = userData.TypeOld;
                    }
                }
            }

            if (userData.CallbackOrigin == ModLoader.OnTryChangeBlockData.ECallbackOrigin.ClientPlayerManual)
            {
                VoxelSide side    = userData.PlayerClickedData.VoxelSideHit;
                ushort    newType = userData.TypeNew;
                string    suffix  = "bottom";

                switch (side)
                {
                case VoxelSide.yPlus:
                    suffix = "bottom";
                    break;

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

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

                    if (ItemTypes.IndexLookup.TryGetIndex(otherTypename, out ushort otherIndex))
                    {
                        Vector3Int position = userData.Position;
                        ThreadManager.InvokeOnMainThread(delegate()
                        {
                            ServerManager.TryChangeBlock(position, otherIndex);
                        }, 0.1f);
                    }
                }
            }
        }
コード例 #15
0
 public static void OnChangedBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData)
 {
     foreach (var extension in GetCallbacks <IOnChangedBlockExtender>())
     {
         try
         {
             extension.OnChangedBlock(tryChangeBlockData);
         }
         catch (Exception ex)
         {
             APILogger.LogError(ex);
         }
     }
 }
コード例 #16
0
 public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
 {
     if (ServerManager.BlockEntityTracker.BannerTracker.TryGetClosest(userData.Position, out BannerTracker.Banner existingBanner, ServerManager.ServerSettings.Colony.ExclusiveRadius))
     {
         if (userData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player &&
             userData.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Steam &&
             !PermissionsManager.HasPermission(userData.RequestOrigin.AsPlayer, new PermissionsManager.Permission("god")) &&
             !existingBanner.Colony.Owners.Contains(userData.RequestOrigin.AsPlayer))
         {
             Chatting.Chat.Send(userData.RequestOrigin.AsPlayer, "You may not build near this colony. Maybe you can ask one of the owners for an invite! The owners are: " + string.Join(", ", existingBanner.Colony.Owners.Select(o => o.Name)));
             userData.InventoryItemResults.Clear();
             userData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
             userData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
         }
     }
 }
コード例 #17
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled ||
                d.RequestedByPlayer == null)
            {
                return;
            }

            if (d.TypeNew == Item.ItemIndex && d.TypeOld == BuiltinBlocks.Air)
            {
                MachineManager.RegisterMachineState(d.RequestedByPlayer,
                                                    new MachineState(d.Position, d.RequestedByPlayer,
                                                                     nameof(GateLever)));
            }
            else if (d.TypeOld == BuiltinBlocks.Air && (d.TypeNew == GateItem.ItemIndex ||
                                                        d.TypeNew == GateItemXN.ItemIndex ||
                                                        d.TypeNew == GateItemXP.ItemIndex ||
                                                        d.TypeNew == GateItemZN.ItemIndex ||
                                                        d.TypeNew == GateItemZP.ItemIndex))
            {
                if (!_gatePositions.ContainsKey(d.RequestedByPlayer))
                {
                    _gatePositions.Add(d.RequestedByPlayer, new Dictionary <Vector3Int, GateState>());
                }

                _gatePositions[d.RequestedByPlayer]
                .Add(d.Position, new GateState(GatePosition.Closed, VoxelSide.None, d.Position));
            }

            if (d.TypeNew == BuiltinBlocks.Air)
            {
                if (!_gatePositions.ContainsKey(d.RequestedByPlayer))
                {
                    _gatePositions.Add(d.RequestedByPlayer, new Dictionary <Vector3Int, GateState>());
                }

                if (_gatePositions[d.RequestedByPlayer].ContainsKey(d.Position))
                {
                    _gatePositions[d.RequestedByPlayer].Remove(d.Position);

                    if (!Inventory.GetInventory(d.RequestedByPlayer).TryAdd(GateItem.ItemIndex))
                    {
                        Stockpile.GetStockPile(d.RequestedByPlayer).Add(GateItem.ItemIndex);
                    }
                }
            }
        }
コード例 #18
0
        public static void OnChangedBlock(ModLoader.OnTryChangeBlockData onTryChangeBlockData)
        {
            var connectedBlock = default(ICSType);

            if (onTryChangeBlockData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player &&
                (BlockLookup.TryGetValue(onTryChangeBlockData.TypeNew.Name, out connectedBlock) ||
                 BlockLookup.TryGetValue(onTryChangeBlockData.TypeOld.Name, out connectedBlock)) &&
                ConnectedBlockCalculator.CalculationTypes.TryGetValue(connectedBlock.ConnectedBlock.CalculationType, out var connectedBlockCalculationType))
            {
                ChangeBlocksForPos(onTryChangeBlockData.Position, connectedBlock.ConnectedBlock.BlockType, connectedBlockCalculationType);

                foreach (var block in connectedBlockCalculationType.AvailableBlockSides)
                {
                    ChangeBlocksForPos(onTryChangeBlockData.Position.GetBlockOffset(block), connectedBlock.ConnectedBlock.BlockType, connectedBlockCalculationType);
                }
            }
        }
コード例 #19
0
ファイル: WallSign.cs プロジェクト: Khanx/Sign
        // Thanks to Zun for this code!
        public void OnTryChangeBlock(ModLoader.OnTryChangeBlockData data)
        {
            if (data.CallbackOrigin != ModLoader.OnTryChangeBlockData.ECallbackOrigin.ClientPlayerManual)
            {
                return;
            }

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

            if (data.TypeOld != BlockTypes.BuiltinBlocks.Types.air)
            {
                return;
            }

            var rootTestType = ItemTypes.GetType("Khanx.Sign");

            if (data.TypeNew.ParentItemType != rootTestType)
            {
                return;
            }

            var hitData = data.PlayerClickedData.GetVoxelHit();

            switch (hitData.SideHit)
            {
            case VoxelSide.xPlus:
                data.TypeNew = ItemTypes.GetType("Khanx.WallSignx+");
                break;

            case VoxelSide.xMin:
                data.TypeNew = ItemTypes.GetType("Khanx.WallSignx-");
                break;

            case VoxelSide.zPlus:
                data.TypeNew = ItemTypes.GetType("Khanx.WallSignz+");
                break;

            case VoxelSide.zMin:
                data.TypeNew = ItemTypes.GetType("Khanx.WallSignz-");
                break;
            }
        }
コード例 #20
0
ファイル: Turret.cs プロジェクト: pipliz/Pandaros.Settlers
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (d.TypeOld == BuiltinBlocks.Air)
            {
                var turret = TurretSettings.FirstOrDefault(t => t.Value.TurretItem.ItemIndex == d.TypeNew).Value;

                if (turret != null)
                {
                    MachineManager.RegisterMachineState(d.RequestedByPlayer,
                                                        new MachineState(d.Position, d.RequestedByPlayer, turret.Name));
                }
            }
        }
コード例 #21
0
 public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
 {
     if (SettlersConfiguration.GetorDefault("AntigriefEnabled", true) &&
         ServerManager.BlockEntityTracker.BannerTracker.TryGetClosest(userData.Position, out BannerTracker.Banner existingBanner, ServerManager.ServerSettings.Colony.ExclusiveRadius))
     {
         if (userData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player &&
             userData.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Steam &&
             !PermissionsManager.HasPermission(userData.RequestOrigin.AsPlayer, new PermissionsManager.Permission(GameLoader.NAMESPACE + ".Permissions.Antigrief")) &&
             !PermissionsManager.HasPermission(userData.RequestOrigin.AsPlayer, new PermissionsManager.Permission("god")) &&
             !existingBanner.Colony.Owners.Contains(userData.RequestOrigin.AsPlayer))
         {
             PandaChat.SendThrottle(userData.RequestOrigin.AsPlayer, _LocalizationHelper, _LocalizationHelper.LocalizeOrDefault("NotYourColony", userData.RequestOrigin.AsPlayer) + string.Join(", ", existingBanner.Colony.Owners.Select(o => o.Name)), ChatColor.red);
             userData.InventoryItemResults.Clear();
             userData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
             userData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
         }
     }
 }
コード例 #22
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (IsBed(d.TypeNew.ItemIndex) || IsBed(d.TypeOld.ItemIndex))
            {
                if (d.RequestOrigin.AsColony != null)
                {
                    CalculateBeds(d.RequestOrigin.AsColony);
                }
                else if (d.RequestOrigin.AsPlayer != null && d.RequestOrigin.AsPlayer.ActiveColony != null)
                {
                    CalculateBeds(d.RequestOrigin.AsPlayer.ActiveColony);
                }
            }
        }
コード例 #23
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled ||
                d.RequestOrigin.AsPlayer == null ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Server ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Invalid ||
                d.RequestOrigin.AsPlayer.ActiveColony == null)
            {
                return;
            }

            if (d.TypeOld.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id && (d.TypeNew.ItemIndex == GateItem.ItemIndex ||
                                                                          d.TypeNew.ItemIndex == GateItemXN.ItemIndex ||
                                                                          d.TypeNew.ItemIndex == GateItemXP.ItemIndex ||
                                                                          d.TypeNew.ItemIndex == GateItemZN.ItemIndex ||
                                                                          d.TypeNew.ItemIndex == GateItemZP.ItemIndex))
            {
                if (!_gatePositions.ContainsKey(d.RequestOrigin.AsPlayer.ActiveColony))
                {
                    _gatePositions.Add(d.RequestOrigin.AsPlayer.ActiveColony, new Dictionary <Vector3Int, GateState>());
                }

                _gatePositions[d.RequestOrigin.AsPlayer.ActiveColony].Add(d.Position, new GateState(GatePosition.Closed, VoxelSide.None, d.Position));
            }

            if (d.TypeNew.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id)
            {
                if (!_gatePositions.ContainsKey(d.RequestOrigin.AsPlayer.ActiveColony))
                {
                    _gatePositions.Add(d.RequestOrigin.AsPlayer.ActiveColony, new Dictionary <Vector3Int, GateState>());
                }

                if (_gatePositions[d.RequestOrigin.AsPlayer.ActiveColony].ContainsKey(d.Position))
                {
                    _gatePositions[d.RequestOrigin.AsPlayer.ActiveColony].Remove(d.Position);

                    if (!d.RequestOrigin.AsPlayer.Inventory.TryAdd(GateItem.ItemIndex))
                    {
                        d.RequestOrigin.AsPlayer.ActiveColony.Stockpile.Add(GateItem.ItemIndex);
                    }
                }
            }
        }
コード例 #24
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            IRoamingJobObjective roamingJobObjective = null;
            Colony colony = null;

            if (d.RequestOrigin.AsPlayer != null &&
                d.RequestOrigin.AsPlayer.ID.type != NetworkID.IDType.Server &&
                d.RequestOrigin.AsPlayer.ID.type != NetworkID.IDType.Invalid &&
                d.RequestOrigin.AsPlayer.ActiveColony != null)
            {
                colony = d.RequestOrigin.AsPlayer.ActiveColony;
            }

            if (d.RequestOrigin.AsColony != null)
            {
                colony = d.RequestOrigin.AsColony;
            }

            if (colony != null)
            {
                if (d.TypeNew.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id)
                {
                    RemoveObjective(colony, d.Position);
                }
                else if (ItemTypes.TryGetType(d.TypeNew.ItemIndex, out ItemTypes.ItemType item))
                {
                    if (ObjectiveCallbacks.TryGetValue(item.Name, out roamingJobObjective))
                    {
                        RegisterRoamingJobState(colony, new RoamingJobState(d.Position, colony, roamingJobObjective.ItemIndex, roamingJobObjective));
                    }
                    else if (!string.IsNullOrEmpty(item.ParentType) && ObjectiveCallbacks.TryGetValue(item.ParentType, out roamingJobObjective))
                    {
                        RegisterRoamingJobState(colony, new RoamingJobState(d.Position, colony, roamingJobObjective.ItemIndex, roamingJobObjective));
                    }
                }
            }
        }
コード例 #25
0
        public void OnChangedBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData)
        {
            var colony = tryChangeBlockData?.RequestOrigin.AsPlayer?.ActiveColony;

            if (colony == null)
            {
                colony = tryChangeBlockData.RequestOrigin.AsColony;
            }

            if (colony != null &&
                (StorageBlockTypes.ContainsKey(tryChangeBlockData.TypeNew.Name) ||
                 StorageBlockTypes.ContainsKey(tryChangeBlockData.TypeOld.Name)))
            {
                RecalcStockpileMaxSize(colony);
                return;
            }

            if (colony != null && CrateTypes.TryGetValue(tryChangeBlockData.TypeOld.Name, out var oldCrate))
            {
                /// empty the crate. TODO may want to do something other than magically teleporting.
                if (CrateLocations[colony].TryGetValue(tryChangeBlockData.Position, out var inv))
                {
                    StoreItems(colony, inv.GetAllItems().Values);
                }

                CrateLocations[colony].Remove(tryChangeBlockData.Position);

                foreach (var item in ItemCrateLocations[colony])
                {
                    item.Value.Remove(tryChangeBlockData.Position);
                }
            }
            else if (CrateTypes.TryGetValue(tryChangeBlockData.TypeNew.Name, out var newCrate))
            {
                if (!CrateLocations.ContainsKey(colony))
                {
                    CrateLocations.Add(colony, new Dictionary <Vector3Int, CrateInventory>());
                }

                CrateLocations[colony][tryChangeBlockData.Position] = new CrateInventory(newCrate, tryChangeBlockData.Position, colony);
            }
        }
コード例 #26
0
        private static void AddToCount(ModLoader.OnTryChangeBlockData d, Dictionary <ushort, int> ItemsPlaced, Dictionary <ushort, int> ItemsInWorld, Dictionary <ushort, int> ItemsRemoved)
        {
            if (d.TypeNew.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeNew.ItemIndex, out var item))
            {
                ushort itemId = GetParentId(d.TypeNew.ItemIndex, item);

                if (!ItemsPlaced.ContainsKey(itemId))
                {
                    ItemsPlaced.Add(itemId, 0);
                }

                if (!ItemsInWorld.ContainsKey(itemId))
                {
                    ItemsInWorld.Add(itemId, 0);
                }

                ItemsPlaced[itemId]++;
                ItemsInWorld[itemId]++;
            }

            if (d.TypeNew.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id && d.TypeOld.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeOld.ItemIndex, out var itemOld))
            {
                ushort itemId = GetParentId(d.TypeOld.ItemIndex, itemOld);

                if (!ItemsRemoved.ContainsKey(itemId))
                {
                    ItemsRemoved.Add(itemId, 0);
                }

                if (!ItemsInWorld.ContainsKey(itemId))
                {
                    ItemsInWorld.Add(itemId, 0);
                }
                else
                {
                    ItemsInWorld[itemId]--;
                }

                ItemsRemoved[itemId]++;
            }
        }
コード例 #27
0
        public void OnTryChangeBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData)
        {
            if (tryChangeBlockData.PlayerClickedData != null && tryChangeBlockData.PlayerClickedData.HitType != Shared.PlayerClickedData.EHitType.Block)
            {
                return;
            }

            if (callbacks.TryGetValue(tryChangeBlockData.TypeOld.Name, out var holdingType))
            {
                var holdingItem = ItemId.GetItemId(tryChangeBlockData.PlayerClickedData.TypeSelected).Name;

                if (!holdingType.TryGetValue(holdingItem, out var replacements) && !holdingType.TryGetValue(ColonyBuiltIn.ItemTypes.AIR, out replacements))
                {
                    return;
                }
                else
                {
                    tryChangeBlockData.InventoryItemResults = replacements.Values.Select(s => new InventoryItem(s.Name, s.Amount)).ToList();
                }
            }
        }
コード例 #28
0
        internal static void AddRemovePowerObject(ModLoader.OnTryChangeBlockData blockData)
        {
            if (Enabled)
            {
                if (blockData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player)
                {
                    switch (PowerType(blockData.TypeNew.Name))
                    {
                    case "Generator":
                        if (PowerManager.GetPowerObject(blockData.TypeNew.Name, out PowerObject generator))
                        {
                            Generator gen = (Generator)generator as Generator;
                            MarkObject(EPowerType.Generator, blockData.Position, gen);
                        }
                        break;

                    case "Machine":
                        if (PowerManager.GetPowerObject(blockData.TypeNew.Name, out PowerObject machine))
                        {
                            Machine mac = (Machine)machine as Machine;
                            MarkObject(EPowerType.Machine, blockData.Position, mac);
                        }
                        break;

                    case "Battery":
                        if (PowerManager.GetPowerObject(blockData.TypeNew.Name, out PowerObject battery))
                        {
                            Battery bat = (Battery)battery as Battery;
                            MarkObject(EPowerType.Battery, blockData.Position, bat);
                        }
                        break;
                    }

                    if (validblockIDs.ContainsKey(blockData.TypeOld.Name))
                    {
                        PowerManager.UnMarkObject(blockData.Position);
                    }
                }
            }
        }
コード例 #29
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (d.TypeNew == Item.ItemIndex && d.TypeOld == BuiltinBlocks.Air)
            {
                var ps = PlayerState.GetPlayerState(d.RequestedByPlayer);
                var ms = new MachineState(d.Position, d.RequestedByPlayer, nameof(TeleportPad));

                if (ps.TeleporterPlaced == Vector3Int.invalidPos)
                {
                    ps.TeleporterPlaced = d.Position;

                    PandaChat.Send(d.RequestedByPlayer, $"Place one more teleportation pad to link to.",
                                   ChatColor.orange);
                }
                else
                {
                    if (GetPadAt(ps.TeleporterPlaced, out var machineState))
                    {
                        _paired[ms.Position]           = machineState.Position;
                        _paired[machineState.Position] = ms.Position;
                        PandaChat.Send(d.RequestedByPlayer, $"Teleportation pads linked!", ChatColor.orange);
                        ps.TeleporterPlaced = Vector3Int.invalidPos;
                    }
                    else
                    {
                        ps.TeleporterPlaced = d.Position;

                        PandaChat.Send(d.RequestedByPlayer, $"Place one more teleportation pad to link to.",
                                       ChatColor.orange);
                    }
                }

                MachineManager.RegisterMachineState(d.RequestedByPlayer, ms);
            }
        }
コード例 #30
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.RequestOrigin.AsPlayer == null ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Server ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Invalid)
            {
                return;
            }

            var ps = PlayerState.GetPlayerState(d.RequestOrigin.AsPlayer);
            var cs = ColonyState.GetColonyState(ps.Player.ActiveColony);

            if (ps != null)
            {
                AddToCount(d, ps.ItemsPlaced, ps.ItemsInWorld, ps.ItemsRemoved);
            }

            if (cs != null)
            {
                AddToCount(d, cs.ItemsPlaced, cs.ItemsInWorld, cs.ItemsRemoved);
            }
        }