248 lines
7.9 KiB
C#
248 lines
7.9 KiB
C#
using Audio;
|
|
using System;
|
|
using System.Globalization;
|
|
|
|
public class BlockCampfireRebirthOld : BlockParticle
|
|
{
|
|
public BlockCampfireRebirthOld()
|
|
{
|
|
this.HasTileEntity = true;
|
|
}
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
if (this.Properties.Values.ContainsKey("TakeDelay"))
|
|
{
|
|
this.TakeDelay = StringParsers.ParseFloat(this.Properties.Values["TakeDelay"], 0, -1, NumberStyles.Any);
|
|
}
|
|
else
|
|
{
|
|
this.TakeDelay = 2f;
|
|
}
|
|
this.WorkstationData = new WorkstationData(base.GetBlockName(), this.Properties);
|
|
CraftingManager.AddWorkstationData(this.WorkstationData);
|
|
}
|
|
|
|
public override void OnBlockAdded(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
|
{
|
|
base.OnBlockAdded(world, _chunk, _blockPos, _blockValue);
|
|
if (_blockValue.ischild)
|
|
{
|
|
return;
|
|
}
|
|
_chunk.AddTileEntity(new TileEntityWorkstation(_chunk)
|
|
{
|
|
localChunkPos = World.toBlock(_blockPos)
|
|
});
|
|
}
|
|
|
|
public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
|
{
|
|
base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue);
|
|
_chunk.RemoveTileEntityAt<TileEntityWorkstation>((World)world, World.toBlock(_blockPos));
|
|
}
|
|
|
|
public override void PlaceBlock(WorldBase _world, BlockPlacement.Result _result, EntityAlive _ea)
|
|
{
|
|
base.PlaceBlock(_world, _result, _ea);
|
|
TileEntityWorkstation tileEntityWorkstation = (TileEntityWorkstation)_world.GetTileEntity(_result.clrIdx, _result.blockPos);
|
|
if (tileEntityWorkstation != null)
|
|
{
|
|
tileEntityWorkstation.IsPlayerPlaced = true;
|
|
}
|
|
}
|
|
|
|
public override bool OnBlockActivated(WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
TileEntityWorkstation tileEntityWorkstation = (TileEntityWorkstation)_world.GetTileEntity(_cIdx, _blockPos);
|
|
if (tileEntityWorkstation == null)
|
|
{
|
|
return false;
|
|
}
|
|
_player.AimingGun = false;
|
|
Vector3i blockPos = tileEntityWorkstation.ToWorldPos();
|
|
if (tileEntityWorkstation.IsUserAccessing())
|
|
{
|
|
_player.PlayOneShot("ui_denied", false);
|
|
return false;
|
|
}
|
|
_world.GetGameManager().TELockServer(_cIdx, blockPos, tileEntityWorkstation.entityId, _player.entityId, null);
|
|
return true;
|
|
}
|
|
|
|
public override void OnBlockValueChanged(WorldBase _world, Chunk _chunk, int _clrIdx, Vector3i _blockPos, BlockValue _oldBlockValue, BlockValue _newBlockValue)
|
|
{
|
|
base.OnBlockValueChanged(_world, _chunk, _clrIdx, _blockPos, _oldBlockValue, _newBlockValue);
|
|
this.checkParticles(_world, _clrIdx, _blockPos, _newBlockValue);
|
|
}
|
|
|
|
public override byte GetLightValue(BlockValue _blockValue)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public override void checkParticles(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue)
|
|
{
|
|
if (_blockValue.ischild)
|
|
{
|
|
return;
|
|
}
|
|
bool flag = _world.GetGameManager().HasBlockParticleEffect(_blockPos);
|
|
if (_blockValue.meta != 0 && !flag)
|
|
{
|
|
this.addParticles(_world, _clrIdx, _blockPos.x, _blockPos.y, _blockPos.z, _blockValue);
|
|
return;
|
|
}
|
|
if (_blockValue.meta == 0 && flag)
|
|
{
|
|
this.removeParticles(_world, _blockPos.x, _blockPos.y, _blockPos.z, _blockValue);
|
|
}
|
|
}
|
|
|
|
public static bool IsCampfireLit(BlockValue _blockValue)
|
|
{
|
|
return _blockValue.meta > 0;
|
|
}
|
|
|
|
public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
|
{
|
|
return Localization.Get("useCampfire");
|
|
}
|
|
|
|
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
if (_commandName == this.cmds[0].text)
|
|
{
|
|
return OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
|
|
}
|
|
if (_commandName != this.cmds[1].text)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (((World)_world).IsWithinTraderArea(_blockPos))
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return false;
|
|
}
|
|
|
|
this.TakeItemWithTimer(_cIdx, _blockPos, _blockValue, _player);
|
|
return true;
|
|
}
|
|
|
|
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
|
{
|
|
bool flag = _world.IsMyLandProtectedBlock(_blockPos, _world.GetGameManager().GetPersistentLocalPlayer(), false);
|
|
TileEntityWorkstation tileEntityWorkstation = (TileEntityWorkstation)_world.GetTileEntity(_clrIdx, _blockPos);
|
|
bool flag2 = false;
|
|
if (tileEntityWorkstation != null)
|
|
{
|
|
flag2 = tileEntityWorkstation.IsPlayerPlaced;
|
|
}
|
|
this.cmds[1].enabled = (flag && flag2 && this.TakeDelay > 0f);
|
|
return this.cmds;
|
|
}
|
|
|
|
public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
|
|
{
|
|
if (_blockValue.damage > 0)
|
|
{
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttRepairBeforePickup"), string.Empty, "ui_denied", null);
|
|
return;
|
|
}
|
|
LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI;
|
|
playerUI.windowManager.Open("timer", true, false, true);
|
|
XUiC_Timer childByType = playerUI.xui.GetChildByType<XUiC_Timer>();
|
|
TimerEventData timerEventData = new TimerEventData();
|
|
timerEventData.Data = new object[]
|
|
{
|
|
_cIdx,
|
|
_blockValue,
|
|
_blockPos,
|
|
_player
|
|
};
|
|
timerEventData.Event += this.EventData_Event;
|
|
timerEventData.CloseEvent += ResetEventData;
|
|
childByType.SetTimer(this.TakeDelay, timerEventData, -1f, "");
|
|
}
|
|
|
|
private void ResetEventData(TimerEventData timerData)
|
|
{
|
|
timerData.Event -= this.EventData_Event;
|
|
}
|
|
|
|
private void EventData_Event(TimerEventData timerData)
|
|
{
|
|
World world = GameManager.Instance.World;
|
|
object[] array = (object[])timerData.Data;
|
|
int clrIdx = (int)array[0];
|
|
BlockValue blockValue = (BlockValue)array[1];
|
|
Vector3i vector3i = (Vector3i)array[2];
|
|
BlockValue block = world.GetBlock(vector3i);
|
|
EntityPlayerLocal entityPlayerLocal = array[3] as EntityPlayerLocal;
|
|
if (block.damage > 0)
|
|
{
|
|
GameManager.ShowTooltip(entityPlayerLocal, Localization.Get("ttRepairBeforePickup"), string.Empty, "ui_denied", null);
|
|
return;
|
|
}
|
|
if (block.type != blockValue.type)
|
|
{
|
|
GameManager.ShowTooltip(entityPlayerLocal, Localization.Get("ttBlockMissingPickup"), string.Empty, "ui_denied", null);
|
|
return;
|
|
}
|
|
TileEntityWorkstation tileEntityWorkstation = world.GetTileEntity(clrIdx, vector3i) as TileEntityWorkstation;
|
|
if (tileEntityWorkstation.IsUserAccessing())
|
|
{
|
|
GameManager.ShowTooltip(entityPlayerLocal, Localization.Get("ttCantPickupInUse"), string.Empty, "ui_denied", null);
|
|
return;
|
|
}
|
|
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
|
|
this.HandleTakeInternalItems(tileEntityWorkstation, uiforPlayer);
|
|
ItemStack itemStack = new ItemStack(block.ToItemValue(), 1);
|
|
if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack))
|
|
{
|
|
uiforPlayer.xui.PlayerInventory.DropItem(itemStack);
|
|
}
|
|
world.SetBlockRPC(clrIdx, vector3i, BlockValue.Air);
|
|
}
|
|
|
|
protected virtual void HandleTakeInternalItems(TileEntityWorkstation te, LocalPlayerUI playerUI)
|
|
{
|
|
ItemStack[] array = te.Output;
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
if (!array[i].IsEmpty() && !playerUI.xui.PlayerInventory.AddItem(array[i]))
|
|
{
|
|
playerUI.xui.PlayerInventory.DropItem(array[i]);
|
|
}
|
|
}
|
|
array = te.Tools;
|
|
for (int j = 0; j < array.Length; j++)
|
|
{
|
|
if (!array[j].IsEmpty() && !playerUI.xui.PlayerInventory.AddItem(array[j]))
|
|
{
|
|
playerUI.xui.PlayerInventory.DropItem(array[j]);
|
|
}
|
|
}
|
|
array = te.Fuel;
|
|
for (int k = 0; k < array.Length; k++)
|
|
{
|
|
if (!array[k].IsEmpty() && !playerUI.xui.PlayerInventory.AddItem(array[k]))
|
|
{
|
|
playerUI.xui.PlayerInventory.DropItem(array[k]);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected int lootList;
|
|
private float TakeDelay = 2f;
|
|
public WorkstationData WorkstationData;
|
|
private BlockActivationCommand[] cmds = new BlockActivationCommand[]
|
|
{
|
|
new BlockActivationCommand("open", "assemble", true, false),
|
|
new BlockActivationCommand("take", "hand", false, false)
|
|
};
|
|
}
|