Example #1
0
 public static bool ProcessBlockDamage(GameManager __instance, string _persistentPlayerId, List <BlockChangeInfo> _blocksToChange)
 {
     try
     {
         World _world = __instance.World;
         if (__instance != null && _blocksToChange != null && !string.IsNullOrEmpty(_persistentPlayerId) && _blocksToChange != null)
         {
             for (int i = 0; i < _blocksToChange.Count; i++)
             {
                 BlockChangeInfo _newBlockInfo = _blocksToChange[i];                 //new block info
                 BlockValue      _blockValue   = _world.GetBlock(_newBlockInfo.pos); //old block value
                 if (_newBlockInfo != null && _newBlockInfo.bChangeBlockValue)       //new block value
                 {
                     if (_blockValue.type == BlockValue.Air.type)                    //old block was air
                     {
                         if (_newBlockInfo.blockValue.Block is BlockSleepingBag)     //placed a sleeping bag
                         {
                             PersistentOperations.BedBug(_persistentPlayerId);
                         }
                         else if (_newBlockInfo.blockValue.Block is BlockLandClaim)//placed a land claim
                         {
                         }
                         if (BlockLogger.IsEnabled)//placed block
                         {
                             BlockLogger.Log(_persistentPlayerId, _newBlockInfo);
                         }
                         return(true);
                     }
                     if (Damage_Detector)
                     {
                         if (_newBlockInfo.blockValue.type == BlockValue.Air.type) //new block is air
                         {
                             if (_blockValue.type == BlockValue.Air.type)          //replaced block
                             {
                                 return(true);
                             }
                             if (_blockValue.Block is BlockLandClaim)            //removed claim
                             {
                                 if (!string.IsNullOrEmpty(_persistentPlayerId)) //id is valid
                                 {
                                     if (!PersistentOperations.ClaimedByAllyOrSelf(_persistentPlayerId, _newBlockInfo.pos))
                                     {
                                         int _total = _blockValue.Block.MaxDamage - _blockValue.damage;
                                         if (_blockValue.Block.MaxDamage - _blockValue.damage >= Block_Damage_Limit)
                                         {
                                             BlockPenalty(_total, _persistentPlayerId);
                                         }
                                     }
                                 }
                             }
                             if (!_blockValue.Block.CanPickup && !PersistentOperations.ClaimedByAllyOrSelf(_persistentPlayerId, _newBlockInfo.pos))//old block can not be picked up and unclaimed space
                             {
                                 int _total = _blockValue.Block.MaxDamage - _blockValue.damage;
                                 if (_total >= Block_Damage_Limit)
                                 {
                                     BlockPenalty(_total, _persistentPlayerId);
                                 }
                             }
                         }
                         else if (_blockValue.Block.blockID == _newBlockInfo.blockValue.Block.blockID) //block is the same
                         {
                             if (_newBlockInfo.bChangeDamage)                                          //block took damage
                             {
                                 int _total = _newBlockInfo.blockValue.damage - _blockValue.damage;
                                 if (_total >= Block_Damage_Limit)
                                 {
                                     BlockPenalty(_total, _persistentPlayerId);
                                 }
                             }
                             if (_blockValue.damage == _newBlockInfo.blockValue.damage || _newBlockInfo.blockValue.damage == 0)//block replaced
                             {
                                 return(true);
                             }
                         }
                         else if (_blockValue.Block.DowngradeBlock.Block.blockID == _newBlockInfo.blockValue.Block.blockID)//downgraded
                         {
                             if (_blockValue.damage == _newBlockInfo.blockValue.damage || _newBlockInfo.blockValue.damage == 0)
                             {
                                 return(true);
                             }
                             int _total = _blockValue.Block.MaxDamage - _blockValue.damage + _newBlockInfo.blockValue.damage;
                             if (_total >= Block_Damage_Limit)
                             {
                                 BlockPenalty(_total, _persistentPlayerId);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in ProcessDamage.ProcessBlockDamage: {0}", e.Message));
     }
     return(true);
 }
Example #2
0
 public static bool ProcessBlockChange(GameManager __instance, string _persistentPlayerId, List <BlockChangeInfo> _blocksToChange)
 {
     try
     {
         World _world = __instance.World;
         if (__instance != null && _blocksToChange != null && !string.IsNullOrEmpty(_persistentPlayerId) && _blocksToChange != null)
         {
             for (int i = 0; i < _blocksToChange.Count; i++)
             {
                 BlockChangeInfo _newBlockInfo  = _blocksToChange[i];                 //new block info
                 BlockValue      _oldBlockValue = _world.GetBlock(_newBlockInfo.pos); //old block value
                 Block           _oldBlock      = _oldBlockValue.Block;
                 if (_newBlockInfo != null && _newBlockInfo.bChangeBlockValue)        //new block value
                 {
                     Block _newBlock = _newBlockInfo.blockValue.Block;
                     if (_oldBlockValue.type == BlockValue.Air.type) //old block was air
                     {
                         if (_newBlock is BlockSleepingBag)          //placed a sleeping bag
                         {
                             if (POIProtection.IsEnabled && POIProtection.Bed && _world.IsPositionWithinPOI(_newBlockInfo.pos.ToVector3(), 5))
                             {
                                 ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId);
                                 if (_cInfo != null)
                                 {
                                     GameManager.Instance.World.SetBlockRPC(_newBlockInfo.pos, BlockValue.Air);
                                     PersistentOperations.ReturnBlock(_cInfo, _newBlock.GetBlockName(), 1);
                                     Phrases.Dict.TryGetValue(1031, out string _phrase1031);
                                     ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase1031 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                     return(false);
                                 }
                             }
                         }
                         else if (_newBlock is BlockLandClaim)//placed a land claim
                         {
                             if (POIProtection.IsEnabled && POIProtection.Claim && _world.IsPositionWithinPOI(_newBlockInfo.pos.ToVector3(), 5))
                             {
                                 ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId);
                                 if (_cInfo != null)
                                 {
                                     GameManager.Instance.World.SetBlockRPC(_newBlockInfo.pos, BlockValue.Air);
                                     PersistentOperations.ReturnBlock(_cInfo, _newBlock.GetBlockName(), 1);
                                     Phrases.Dict.TryGetValue(1032, out string _phrase1032);
                                     ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase1032 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                     return(false);
                                 }
                             }
                         }
                         else if (_newBlock is BlockPowered)//placed a electric block
                         {
                             Log.Out(string.Format("[SERVERTOOLS] New block is a powered block named {0}", _newBlock.GetBlockName()));
                         }
                         if (BlockLogger.IsEnabled)//placed block
                         {
                             BlockLogger.Log(_persistentPlayerId, _newBlockInfo);
                         }
                         return(true);
                     }
                     if (Damage_Detector)
                     {
                         if (_newBlockInfo.blockValue.type == BlockValue.Air.type) //new block is air
                         {
                             if (_oldBlockValue.type == BlockValue.Air.type)       //replaced block
                             {
                                 return(true);
                             }
                             if (_oldBlockValue.Block is BlockLandClaim)         //removed claim
                             {
                                 if (!string.IsNullOrEmpty(_persistentPlayerId)) //id is valid
                                 {
                                     if (!PersistentOperations.ClaimedByAllyOrSelf(_persistentPlayerId, _newBlockInfo.pos))
                                     {
                                         int _total = _oldBlock.MaxDamage - _oldBlockValue.damage;
                                         if (_oldBlock.MaxDamage - _oldBlockValue.damage >= Block_Damage_Limit)
                                         {
                                             ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId);
                                             if (_cInfo != null)
                                             {
                                                 if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level)
                                                 {
                                                     BlockPenalty(_total, _persistentPlayerId);
                                                     return(false);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if (!_oldBlock.CanPickup && !PersistentOperations.ClaimedByAllyOrSelf(_persistentPlayerId, _newBlockInfo.pos))//old block can not be picked up and unclaimed space
                             {
                                 int _total = _oldBlock.MaxDamage - _oldBlockValue.damage;
                                 if (_total >= Block_Damage_Limit)
                                 {
                                     ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId);
                                     if (_cInfo != null)
                                     {
                                         if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level)
                                         {
                                             BlockPenalty(_total, _persistentPlayerId);
                                             return(false);
                                         }
                                     }
                                 }
                             }
                         }
                         else if (_oldBlock.blockID == _newBlock.blockID) //block is the same
                         {
                             if (_newBlockInfo.bChangeDamage)             //block took damage
                             {
                                 int _total = _newBlockInfo.blockValue.damage - _oldBlockValue.damage;
                                 if (_total >= Block_Damage_Limit)
                                 {
                                     ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId);
                                     if (_cInfo != null)
                                     {
                                         if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level)
                                         {
                                             BlockPenalty(_total, _persistentPlayerId);
                                             return(false);
                                         }
                                     }
                                 }
                             }
                             if (_oldBlockValue.damage == _newBlockInfo.blockValue.damage || _newBlockInfo.blockValue.damage == 0)//block replaced
                             {
                                 return(true);
                             }
                         }
                         else if (_oldBlock.DowngradeBlock.Block.blockID == _newBlock.blockID)//downgraded
                         {
                             if (_oldBlockValue.damage == _newBlockInfo.blockValue.damage || _newBlockInfo.blockValue.damage == 0)
                             {
                                 return(true);
                             }
                             int _total = _oldBlock.MaxDamage - _oldBlockValue.damage + _newBlockInfo.blockValue.damage;
                             if (_total >= Block_Damage_Limit)
                             {
                                 ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId);
                                 if (_cInfo != null)
                                 {
                                     if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level)
                                     {
                                         BlockPenalty(_total, _persistentPlayerId);
                                         return(false);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in ProcessDamage.ProcessBlockDamage: {0}", e.Message));
     }
     return(true);
 }