Upload from upload_mods.ps1
This commit is contained in:
155
Scripts/Blocks/BlockHamRadio.cs
Normal file
155
Scripts/Blocks/BlockHamRadio.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using Audio;
|
||||
using Platform;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using static RebirthManager;
|
||||
using static SleeperVolume;
|
||||
|
||||
public class BlockHamRadio : Block
|
||||
{
|
||||
public override void OnTriggered(EntityPlayer _player, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, List<BlockChangeInfo> _blockChanges, BlockTrigger _triggeredBy)
|
||||
{
|
||||
//Log.Out("BlockHamRadio-OnTriggered START");
|
||||
base.OnTriggered(_player, _world, _cIdx, _blockPos, _blockValue, _blockChanges, _triggeredBy);
|
||||
|
||||
if (!this.DowngradeBlock.isair)
|
||||
{
|
||||
BlockValue blockValue = this.DowngradeBlock;
|
||||
blockValue = BlockPlaceholderMap.Instance.Replace(blockValue, _world.GetGameRandom(), _blockPos.x, _blockPos.z);
|
||||
blockValue.rotation = _blockValue.rotation;
|
||||
blockValue.meta = _blockValue.meta;
|
||||
_world.SetBlockRPC(_cIdx, _blockPos, blockValue, blockValue.Block.Density);
|
||||
}
|
||||
Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking");
|
||||
}
|
||||
|
||||
public override bool IsWaterBlocked(IBlockAccess _world, Vector3i _blockPos, BlockValue _blockValue, BlockFaceFlag _sides)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool AllowBlockTriggers
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
//Log.Out("BlockHamRadio-Init START");
|
||||
base.Init();
|
||||
//this.CanPickup = true;
|
||||
bool flag4 = this.Properties.Values.ContainsKey("TakeDelay");
|
||||
if (flag4)
|
||||
{
|
||||
this.TakeDelay = StringParsers.ParseFloat(this.Properties.Values["TakeDelay"], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
bool flag5 = this.Properties.Values.ContainsKey("canPickUpBlock");
|
||||
if (flag5)
|
||||
{
|
||||
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)
|
||||
{
|
||||
//Log.Out("BlockHamRadio-GetActivationText START");
|
||||
Block block = _blockValue.Block;
|
||||
if (!this.CanPickup && (double)EffectManager.GetValue(PassiveEffects.BlockPickup, _entity: _entityFocusing, tags: _blockValue.Block.Tags) <= 0.0)
|
||||
{
|
||||
//Log.Out("BlockHamRadio-GetActivationText 1");
|
||||
return (string)null;
|
||||
}
|
||||
if (!_world.CanPickupBlockAt(_blockPos, _world.GetGameManager().GetPersistentLocalPlayer()))
|
||||
{
|
||||
//Log.Out("BlockHamRadio-GetActivationText 2");
|
||||
return (string)null;
|
||||
}
|
||||
string _key = block.GetBlockName();
|
||||
if (!string.IsNullOrEmpty(block.PickedUpItemValue))
|
||||
{
|
||||
//Log.Out("BlockHamRadio-GetActivationText 3");
|
||||
_key = block.PickedUpItemValue;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(block.PickupTarget))
|
||||
{
|
||||
//Log.Out("BlockHamRadio-GetActivationText 4");
|
||||
_key = block.PickupTarget;
|
||||
}
|
||||
//Log.Out("BlockHamRadio-GetActivationText END");
|
||||
return string.Format(Localization.Get("pickupPrompt"), (object)Localization.Get(_key));
|
||||
}
|
||||
|
||||
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
||||
{
|
||||
//Log.Out("BlockHamRadio-OnBlockActivated START, _commandName: " + _commandName);
|
||||
if (_blockValue.ischild)
|
||||
{
|
||||
//Log.Out("BlockHamRadio:isSecure _blockValue.ischild");
|
||||
Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue);
|
||||
BlockValue block = _world.GetBlock(parentPos);
|
||||
return this.OnBlockActivated(_commandName, _world, _cIdx, parentPos, block, _player);
|
||||
}
|
||||
|
||||
if (_commandName == this.cmds[0].text)
|
||||
{
|
||||
//Log.Out("BlockHamRadio:OnBlockActivated-_commandName == this.cmds[1].text");
|
||||
|
||||
var uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player);
|
||||
|
||||
if (uiforPlayer != null)
|
||||
{
|
||||
uiforPlayer.windowManager.Open("ManageNPCs", true, false, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (_commandName == this.cmds[1].text)
|
||||
{
|
||||
//Log.Out("BlockHamRadio:OnBlockActivated-_commandName == this.cmds[0].text");
|
||||
bool isWithinTraderArea = ((World)_world).GetTraderAreaAt(_blockPos) != null;
|
||||
|
||||
if (isWithinTraderArea)
|
||||
{
|
||||
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, "", 1, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("OnBlockActivated:Insecure/Other");
|
||||
//Log.Out("BlockHamRadio:OnBlockActivated-_indexInBlockActivationCommands == other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
||||
{
|
||||
//Log.Out("BlockHamRadio-GetBlockActivationCommands START");
|
||||
this.cmds[0].enabled = true;
|
||||
this.cmds[1].enabled = this.canPickUpBlock;
|
||||
return this.cmds;
|
||||
}
|
||||
|
||||
public BlockActivationCommand[] cmds = new BlockActivationCommand[]
|
||||
{
|
||||
new BlockActivationCommand("TeleportHires", "followers", false, false),
|
||||
new BlockActivationCommand("take", "hand", false, false),
|
||||
};
|
||||
|
||||
|
||||
public float TakeDelay = RebirthVariables.takeDelay;
|
||||
public bool canPickUpBlock = true;
|
||||
}
|
||||
Reference in New Issue
Block a user