214 lines
9.3 KiB
C#
214 lines
9.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Audio;
|
|
using Platform;
|
|
using UnityEngine;
|
|
using UnityEngine.Scripting;
|
|
|
|
[Preserve]
|
|
public class BlockTempSecureDoorRebirth : BlockDoor
|
|
{
|
|
public override bool AllowBlockTriggers
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public BlockTempSecureDoorRebirth()
|
|
{
|
|
this.HasTileEntity = true;
|
|
}
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
this.Properties.ParseString(BlockTempSecureDoorRebirth.PropLockedSound, ref this.lockedSound);
|
|
this.Properties.ParseString(BlockTempSecureDoorRebirth.PropLockingSound, ref this.lockingSound);
|
|
this.Properties.ParseString(BlockTempSecureDoorRebirth.PropUnLockingSound, ref this.unlockingSound);
|
|
}
|
|
|
|
public override void PlaceBlock(WorldBase _world, BlockPlacement.Result _result, EntityAlive _ea)
|
|
{
|
|
Block block = _result.blockValue.Block;
|
|
if (block.shape.IsTerrain())
|
|
{
|
|
_world.SetBlockRPC(_result.clrIdx, _result.blockPos, _result.blockValue, this.Density);
|
|
}
|
|
else if (!block.IsTerrainDecoration)
|
|
{
|
|
_world.SetBlockRPC(_result.clrIdx, _result.blockPos, _result.blockValue, MarchingCubes.DensityAir);
|
|
}
|
|
else
|
|
{
|
|
_world.SetBlockRPC(_result.clrIdx, _result.blockPos, _result.blockValue);
|
|
}
|
|
}
|
|
|
|
public override void OnBlockAdded(WorldBase _world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
|
{
|
|
base.OnBlockAdded(_world, _chunk, _blockPos, _blockValue);
|
|
if (_world.IsEditor())
|
|
{
|
|
return;
|
|
}
|
|
if (_blockValue.ischild)
|
|
{
|
|
return;
|
|
}
|
|
TileEntityTimedBlockRebirth TileEntityTimedBlockRebirth = _world.GetTileEntity(_chunk.ClrIdx, _blockPos) as TileEntityTimedBlockRebirth;
|
|
if (TileEntityTimedBlockRebirth != null)
|
|
{
|
|
return;
|
|
}
|
|
TileEntityTimedBlockRebirth = new TileEntityTimedBlockRebirth(_chunk);
|
|
TileEntityTimedBlockRebirth.SetDisableModifiedCheck(true);
|
|
TileEntityTimedBlockRebirth.localChunkPos = World.toBlock(_blockPos);
|
|
TileEntityTimedBlockRebirth.SetDisableModifiedCheck(false);
|
|
_chunk.AddTileEntity(TileEntityTimedBlockRebirth);
|
|
|
|
if (this.Properties.Values.ContainsKey("Duration"))
|
|
{
|
|
this.totalDuration = Int32.Parse(this.Properties.Values["Duration"]);
|
|
}
|
|
|
|
this.OnBlockActivated(_world, _chunk.ClrIdx, _blockPos, _blockValue, null);
|
|
|
|
_world.GetWBT().AddScheduledBlockUpdate(_chunk.ClrIdx, _blockPos, this.blockID, 20UL);
|
|
}
|
|
|
|
public override bool FilterIndexType(BlockValue bv)
|
|
{
|
|
return !(this.IndexName == "TraderOnOff") || (bv.meta & 4) == 0;
|
|
}
|
|
|
|
public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
|
{
|
|
base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue);
|
|
TileEntityTimedBlockRebirth tileTimedBlockPlot = world.GetTileEntity(_chunk.ClrIdx, _blockPos) as TileEntityTimedBlockRebirth;
|
|
if (tileTimedBlockPlot != null)
|
|
{
|
|
tileTimedBlockPlot.OnDestroy();
|
|
}
|
|
_chunk.RemoveTileEntityAt<TileEntityTimedBlockRebirth>((World)world, World.toBlock(_blockPos));
|
|
}
|
|
|
|
public override bool HasBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
|
{
|
|
return _world.GetTileEntity(_clrIdx, _blockPos) is TileEntityTimedBlockRebirth || _world.IsEditor();
|
|
}
|
|
|
|
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
|
{
|
|
if (_blockValue.ischild)
|
|
{
|
|
Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue);
|
|
BlockValue block = _world.GetBlock(parentPos);
|
|
return this.GetBlockActivationCommands(_world, block, _clrIdx, parentPos, _entityFocusing);
|
|
}
|
|
TileEntityTimedBlockRebirth TileEntityTimedBlockRebirth = (TileEntityTimedBlockRebirth)_world.GetTileEntity(_clrIdx, _blockPos);
|
|
if (TileEntityTimedBlockRebirth == null && !_world.IsEditor())
|
|
{
|
|
return Array.Empty<BlockActivationCommand>();
|
|
}
|
|
((Chunk)_world.ChunkClusters[_clrIdx].GetChunkSync(World.toChunkXZ(_blockPos.x), _blockPos.y, World.toChunkXZ(_blockPos.z))).GetBlockTrigger(World.toBlock(_blockPos));
|
|
this.cmds[0].enabled = BlockDoor.IsDoorOpen(_blockValue.meta);
|
|
this.cmds[1].enabled = !BlockDoor.IsDoorOpen(_blockValue.meta);
|
|
this.cmds[2].enabled = false;
|
|
this.cmds[3].enabled = false;
|
|
this.cmds[4].enabled = false;
|
|
this.cmds[5].enabled = (_world.IsEditor() && !GameUtils.IsWorldEditor());
|
|
return this.cmds;
|
|
}
|
|
|
|
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
if (_blockValue.ischild)
|
|
{
|
|
Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue);
|
|
BlockValue block = _world.GetBlock(parentPos);
|
|
return this.OnBlockActivated(_commandName, _world, _cIdx, parentPos, block, _player);
|
|
}
|
|
TileEntityTimedBlockRebirth TileEntityTimedBlockRebirth = (TileEntityTimedBlockRebirth)_world.GetTileEntity(_cIdx, _blockPos);
|
|
if (TileEntityTimedBlockRebirth == null && !_world.IsEditor())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!(_commandName == "close"))
|
|
{
|
|
if (_world.IsEditor())
|
|
{
|
|
base.HandleTrigger((EntityPlayer)_player, (World)_world, _cIdx, _blockPos, _blockValue);
|
|
return this.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
|
|
}
|
|
Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, this.lockedSound);
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (_world.IsEditor())
|
|
{
|
|
base.HandleTrigger((EntityPlayer)_player, (World)_world, _cIdx, _blockPos, _blockValue);
|
|
return this.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
|
|
}
|
|
Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, this.lockedSound);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
|
{
|
|
if (_blockValue.ischild)
|
|
{
|
|
Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue);
|
|
BlockValue block = _world.GetBlock(parentPos);
|
|
return this.GetActivationText(_world, block, _clrIdx, parentPos, _entityFocusing);
|
|
}
|
|
TileEntityTimedBlockRebirth TileEntityTimedBlockRebirth = (TileEntityTimedBlockRebirth)_world.GetTileEntity(_clrIdx, _blockPos);
|
|
if (TileEntityTimedBlockRebirth == null && !_world.IsEditor())
|
|
{
|
|
return "";
|
|
}
|
|
|
|
PlayerActionsLocal playerInput = ((EntityPlayerLocal)_entityFocusing).playerInput;
|
|
string arg = playerInput.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain, null) + playerInput.PermanentActions.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain, null);
|
|
string arg2 = Localization.Get("door");
|
|
|
|
return string.Format(Localization.Get("tooltipUnlocked"), arg, arg2);
|
|
}
|
|
|
|
public override void OnTriggered(EntityPlayer _player, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, List<BlockChangeInfo> _blockChanges, BlockTrigger _triggeredBy)
|
|
{
|
|
base.OnTriggered(_player, _world, _cIdx, _blockPos, _blockValue, _blockChanges, _triggeredBy);
|
|
bool flag = !BlockDoor.IsDoorOpen(_blockValue.meta);
|
|
_blockValue.meta = (byte)((flag ? 1 : 0) | ((int)_blockValue.meta & -2));
|
|
_blockChanges.Add(new BlockChangeInfo(_cIdx, _blockPos, _blockValue));
|
|
if (flag)
|
|
{
|
|
Manager.BroadcastPlay(_blockPos.ToVector3() + Vector3.one * 0.5f, this.openSound, 0f);
|
|
return;
|
|
}
|
|
Manager.BroadcastPlay(_blockPos.ToVector3() + Vector3.one * 0.5f, this.closeSound, 0f);
|
|
}
|
|
|
|
public int totalDuration = 0;
|
|
private const int cDoorIsLockedMask = 4;
|
|
protected string lockedSound = "Misc/locked";
|
|
protected string lockingSound = "Misc/locking";
|
|
protected string unlockingSound = "Misc/unlocking";
|
|
protected static string PropLockedSound = "LockedSound";
|
|
protected static string PropLockingSound = "LockingSound";
|
|
protected static string PropUnLockingSound = "UnlockingSound";
|
|
private BlockActivationCommand[] cmds = new BlockActivationCommand[]
|
|
{
|
|
new BlockActivationCommand("close", "door", false, false),
|
|
new BlockActivationCommand("open", "door", false, false),
|
|
new BlockActivationCommand("lock", "lock", false, false),
|
|
new BlockActivationCommand("unlock", "unlock", false, false),
|
|
new BlockActivationCommand("keypad", "keypad", false, false),
|
|
new BlockActivationCommand("trigger", "wrench", true, false)
|
|
};
|
|
}
|