Files
Nathaniel Cosford 062dfab2cd Patched
2025-05-30 01:04:40 +09:30

192 lines
8.0 KiB
C#

using Audio;
using Platform;
using System.Globalization;
public class BlockTakeMine : BlockMine
{
public override void Init()
{
base.Init();
bool flag2 = this.Properties.Values.ContainsKey("TakeDelay");
if (flag2)
{
this.TakeDelay = StringParsers.ParseFloat(this.Properties.Values["TakeDelay"], 0, -1, NumberStyles.Any);
}
bool flag3 = this.Properties.Values.ContainsKey("ShowBlockName");
if (flag3)
{
StringParsers.TryParseBool(this.Properties.Values["ShowBlockName"], out this.showBlockName, 0, -1, true);
}
bool flag4 = this.Properties.Values.ContainsKey("canPickUpBlock");
if (flag4)
{
StringParsers.TryParseBool(this.Properties.Values["canPickUpBlock"], out this.canPickUpBlock, 0, -1, true);
}
}
public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
{
bool flag = this.showBlockName;
string result;
if (flag)
{
result = Localization.Get(_blockValue.Block.GetBlockName());
}
else
{
result = "";
}
return result;
}
public override void PlaceBlock(WorldBase _world, BlockPlacement.Result _result, EntityAlive _ea)
{
//Log.Out("BlockTakeBase:PlaceBlock-Init");
base.PlaceBlock(_world, _result, _ea);
TileEntitySecureBlockRebirth tileEntitySecure = _world.GetTileEntity(_result.clrIdx, _result.blockPos) as TileEntitySecureBlockRebirth;
if (tileEntitySecure != null)
{
//Log.Out("BlockTakeBase:PlaceBlock-tileEntitySecure Not Null");
tileEntitySecure.SetEmpty();
if (_ea != null && _ea.entityType == EntityType.Player)
{
tileEntitySecure.bPlayerStorage = true;
tileEntitySecure.SetOwner(PlatformManager.InternalLocalUserIdentifier);
//Log.Out("BlockTakeBase:PlaceBlock-Owner Set");
}
}
}
public override void OnBlockAdded(WorldBase _world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
{
//Log.Out("BlockTakeBase:OnBlockAdded-Init");
base.OnBlockAdded(_world, _chunk, _blockPos, _blockValue);
if (_world.IsEditor())
{
return;
}
if (_blockValue.ischild)
{
//Log.Out("BlockTakeBase:OnBlockAdded-ischild");
return;
}
TileEntitySecureBlockRebirth tileEntity = _world.GetTileEntity(_chunk.ClrIdx, _blockPos) as TileEntitySecureBlockRebirth;
if (tileEntity != null)
{
//Log.Out("BlockTakeBase:OnBlockAdded-tile entity exists");
return;
}
//Log.Out("BlockTakeBase:OnBlockAdded-create tile entity");
tileEntity = new TileEntitySecureBlockRebirth(_chunk);
tileEntity.SetDisableModifiedCheck(true);
tileEntity.localChunkPos = World.toBlock(_blockPos);
tileEntity.SetLocked((_blockValue.meta & 4) > 0);
tileEntity.SetDisableModifiedCheck(false);
_chunk.AddTileEntity(tileEntity);
}
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
{
//Log.Out("BlockTakeBase:OnBlockActivated, Shape: " + this.shape.GetName());
bool ischild = _blockValue.ischild;
bool result = false;
if (ischild)
{
//Log.Out("BlockTakeBase:OnBlockActivated-IsChild");
Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue);
BlockValue block = _world.GetBlock(parentPos);
result = this.OnBlockActivated(_commandName, _world, _cIdx, parentPos, block, _player);
}
else
{
TileEntitySecureBlockRebirth tileEntitySecure = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySecureBlockRebirth;
if (tileEntitySecure == null)
{
if (RebirthUtilities.ScenarioSkip())
{
//Log.Out("BlockTakeBase:OnBlockActivated 0");
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, this.TakeDelay, null, ReplacementBlockName, numBlocks, isReplacementItem);
result = true;
return false;
}
else
{
//Log.Out("BlockTakeBase:OnBlockActivated-tileEntitySecure == null");
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttNotBelongsToYou"), string.Empty, "ui_denied", null);
return false;
}
}
//Log.Out("BlockTakeBase:OnBlockActivated-_commandName: " + _commandName);
if (_commandName == this.cmds[0].text)
{
result = false;
}
else if (_commandName == this.cmds[1].text)
{
//Log.Out("BlockTakeBase:OnBlockActivated-_indexInBlockActivationCommands == 1");
bool isOwner = tileEntitySecure.IsOwner(PlatformManager.InternalLocalUserIdentifier);
ProgressionValue progressionValue = _player.Progression.GetProgressionValue("perkInfiltrator");
//Log.Out("BlockTakeBase:OnBlockActivated-isOwner: " + isOwner);
if (!isOwner && progressionValue != null && progressionValue.calculatedLevel < 3)
{
if (RebirthUtilities.ScenarioSkip())
{
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, this.TakeDelay, null, ReplacementBlockName, numBlocks, isReplacementItem);
result = true;
return false;
}
else
{
//Log.Out("BlockTakeBase-OnBlockActivated 1");
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttNotBelongsToYou"), string.Empty, "ui_denied", null);
result = false;
return false;
}
}
else
{
//Log.Out("BlockTakeBase-OnBlockActivated 2");
if (((World)_world).IsWithinTraderArea(_blockPos))
{
//Log.Out("BlockTakeBase-OnBlockActivated 3");
Manager.PlayInsidePlayerHead("ui_denied");
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
return false;
}
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, this.TakeDelay, null, ReplacementBlockName, numBlocks, isReplacementItem);
result = true;
}
}
else
{
//Log.Out("BlockTakeBase-OnBlockActivated 4");
result = false;
}
}
return result;
}
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
{
this.cmds[0].enabled = this.canPickUpBlock;
this.cmds[1].enabled = this.canPickUpBlock;
return this.cmds;
}
private BlockActivationCommand[] cmds = new BlockActivationCommand[]
{
new BlockActivationCommand("cancel", "x", false, false),
new BlockActivationCommand("take", "hand", false, false)
};
private float TakeDelay = RebirthVariables.takeDelay;
private bool showBlockName;
private string ReplacementBlockName = "";
private int numBlocks = 1;
private bool isReplacementItem = false;
public bool canPickUpBlock = true;
}