861 lines
45 KiB
C#
861 lines
45 KiB
C#
using Audio;
|
|
using Platform;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
|
|
public class BlockSecureLootGatherer : Block
|
|
{
|
|
public override void OnTriggered(EntityPlayer _player, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, List<BlockChangeInfo> _blockChanges, BlockTrigger _triggeredBy)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-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 BlockSecureLootGatherer()
|
|
{
|
|
this.HasTileEntity = true;
|
|
}
|
|
|
|
public override ulong GetTickRate()
|
|
{
|
|
System.Random random = new System.Random();
|
|
autoLootTick = random.Next(7, 15);
|
|
|
|
return (ulong)(20f * autoLootTick);
|
|
}
|
|
|
|
public override bool CanPlaceBlockAt(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, bool _bOmitCollideCheck = false)
|
|
{
|
|
bool bCanPlaceBlock = base.CanPlaceBlockAt(_world, _clrIdx, _blockPos, _blockValue, _bOmitCollideCheck);
|
|
|
|
bool blockExists = RebirthUtilities.BlockExists(_blockPos, 15, 20, "FuriousRamsayLootGatherer");
|
|
|
|
if (!bCanPlaceBlock || blockExists)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void PlaceBlock(WorldBase _world, BlockPlacement.Result _result, EntityAlive _ea)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-PlaceBlock START");
|
|
base.PlaceBlock(_world, _result, _ea);
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = _world.GetTileEntity(_result.clrIdx, _result.blockPos) as TileEntitySecureLootContainerRebirth;
|
|
if (tileEntitySecureLootContainer != null)
|
|
{
|
|
tileEntitySecureLootContainer.SetEmpty();
|
|
if (_ea != null && _ea.entityType == EntityType.Player)
|
|
{
|
|
tileEntitySecureLootContainer.bPlayerStorage = true;
|
|
tileEntitySecureLootContainer.SetOwner(PlatformManager.InternalLocalUserIdentifier);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public override void OnBlockAdded(WorldBase _world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockAdded START");
|
|
base.OnBlockAdded(_world, _chunk, _blockPos, _blockValue);
|
|
if (_blockValue.ischild)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockAdded 1");
|
|
return;
|
|
}
|
|
if (!(_world.GetTileEntity(_chunk.ClrIdx, _blockPos) is TileEntitySecureLootContainerRebirth))
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockAdded 2");
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = new TileEntitySecureLootContainerRebirth(_chunk);
|
|
tileEntitySecureLootContainer.localChunkPos = World.toBlock(_blockPos);
|
|
tileEntitySecureLootContainer.lootListName = this.lootList;
|
|
tileEntitySecureLootContainer.SetContainerSize(LootContainer.GetLootContainer(this.lootList, true).size, true);
|
|
_chunk.AddTileEntity(tileEntitySecureLootContainer);
|
|
}
|
|
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockAdded 3");
|
|
_world.GetWBT().AddScheduledBlockUpdate(_chunk.ClrIdx, _blockPos, this.blockID, this.GetTickRate());
|
|
}
|
|
}
|
|
|
|
public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockRemoved START");
|
|
base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue);
|
|
}
|
|
|
|
public override Block.DestroyedResult OnBlockDestroyedBy(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, int _entityId, bool _bUseHarvestTool)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockDestroyedBy START");
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntitySecureLootContainerRebirth;
|
|
if (tileEntitySecureLootContainer != null)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockDestroyedBy 1");
|
|
tileEntitySecureLootContainer.OnDestroy();
|
|
}
|
|
return Block.DestroyedResult.Downgrade;
|
|
}
|
|
|
|
public override bool UpdateTick(WorldBase world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, bool _bRandomTick, ulong _ticksIfLoaded, GameRandom _rnd)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick START");
|
|
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick 1");
|
|
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = world.GetTileEntity(_clrIdx, _blockPos) as TileEntitySecureLootContainerRebirth;
|
|
|
|
if (tileEntitySecureLootContainer != null)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick tileEntityLootContainer tileEntitySecureLootContainer.isLootGatheringActivated: " + tileEntitySecureLootContainer.isLootGatheringActivated);
|
|
|
|
if (tileEntitySecureLootContainer.isLootGatheringActivated)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick isLootGatheringActivated is TRUE");
|
|
|
|
PersistentPlayerData playerData = world.GetGameManager().GetPersistentPlayerList().GetPlayerData(tileEntitySecureLootContainer.GetOwner());
|
|
|
|
EntityPlayer entityPlayer = (EntityPlayer)world.GetEntity(playerData.EntityId);
|
|
if (entityPlayer == null)
|
|
{
|
|
world.GetWBT().AddScheduledBlockUpdate(_clrIdx, _blockPos, this.blockID, this.GetTickRate());
|
|
return true;
|
|
}
|
|
|
|
int minMax = 75;
|
|
|
|
World _world = GameManager.Instance.World;
|
|
List<Entity> entitiesInBounds = _world.GetEntitiesInBounds(typeof(EntityLootContainer), BoundsUtils.BoundsForMinMax(_blockPos.x - minMax, _blockPos.y - 50, _blockPos.z - minMax, _blockPos.x + minMax, _blockPos.y + 30, _blockPos.z + minMax), new List<Entity>());
|
|
|
|
if (entitiesInBounds != null && entitiesInBounds.Count > 0)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick isLootGatheringActivated entitiesInBounds.Count > 0");
|
|
|
|
for (int i = 0; i < entitiesInBounds.Count; i++)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick entitiesInBounds[i].EntityClass.entityClassName: " + entitiesInBounds[i].EntityClass.entityClassName);
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick entitiesInBounds[i].lootContainer.items.Length: " + entitiesInBounds[i].lootContainer.items.Length);
|
|
|
|
if (entitiesInBounds[i].lootContainer != null)
|
|
{
|
|
bool isUserAccessing = entitiesInBounds[i].lootContainer.IsUserAccessing();
|
|
|
|
if (!isUserAccessing)
|
|
{
|
|
entitiesInBounds[i].lootContainer.SetUserAccessing(true);
|
|
//entitiesInBounds[i].lootContainer.bTouched = true;
|
|
//entitiesInBounds[i].lootContainer.worldTimeTouched = world.GetWorldTime();
|
|
|
|
float containerMod = 0f;
|
|
float containerBonus = 0f;
|
|
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick entitiesInBounds[i].lootContainer.EntityId: " + entitiesInBounds[i].lootContainer.EntityId);
|
|
|
|
float lootStage = (float)entityPlayer.GetHighestPartyLootStage(containerMod, containerBonus);
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick lootStage: " + lootStage);
|
|
|
|
GameManager.Instance.lootManager.LootContainerOpened(entitiesInBounds[i].lootContainer, entityPlayer.entityId, entitiesInBounds[i].EntityTags);
|
|
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick EntityTags: " + entitiesInBounds[i].EntityTags);
|
|
|
|
bool addItems = false;
|
|
bool addedAllItems = true;
|
|
|
|
foreach (ItemStack itemStack in entitiesInBounds[i].lootContainer.GetItems())
|
|
{
|
|
if (!itemStack.IsEmpty())
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick Item Name: " + itemStack.itemValue.ItemClass.GetItemName());
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick Item Count: " + itemStack.count);
|
|
|
|
if (tileEntitySecureLootContainer.HasItem(itemStack.itemValue))
|
|
{
|
|
ValueTuple<bool, bool> tryStack = tileEntitySecureLootContainer.TryStackItem(_clrIdx, itemStack);
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick tryStack: " + tryStack);
|
|
if (!tryStack.Item1)
|
|
{
|
|
bool tryAdd = tileEntitySecureLootContainer.AddItem(itemStack);
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick tryAdd: " + tryAdd);
|
|
if (tryAdd)
|
|
{
|
|
addItems = true;
|
|
entitiesInBounds[i].lootContainer.RemoveItem(itemStack.itemValue);
|
|
}
|
|
else
|
|
{
|
|
addedAllItems = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
addItems = true;
|
|
entitiesInBounds[i].lootContainer.RemoveItem(itemStack.itemValue);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool tryAdd = tileEntitySecureLootContainer.AddItem(itemStack);
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick tryAdd: " + tryAdd);
|
|
if (tryAdd)
|
|
{
|
|
addItems = true;
|
|
entitiesInBounds[i].lootContainer.RemoveItem(itemStack.itemValue);
|
|
}
|
|
else
|
|
{
|
|
addedAllItems = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
entitiesInBounds[i].lootContainer.SetUserAccessing(false);
|
|
|
|
if (addItems && addedAllItems)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick REMOVED BAG: " + entitiesInBounds[i].EntityClass.entityClassName);
|
|
entitiesInBounds[i].DamageEntity(new DamageSource(EnumDamageSource.Internal, EnumDamageTypes.Suicide), 99999, false, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
entitiesInBounds = _world.GetEntitiesInBounds(typeof(EntityEnemy), BoundsUtils.BoundsForMinMax(_blockPos.x - minMax, _blockPos.y - 50, _blockPos.z - minMax, _blockPos.x + minMax, _blockPos.y + 30, _blockPos.z + minMax), new List<Entity>());
|
|
|
|
if (entitiesInBounds.Count > 0)
|
|
{
|
|
for (int i = 0; i < entitiesInBounds.Count; i++)
|
|
{
|
|
if (entitiesInBounds[i].IsDead())
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-UpdateTick REMOVED CORPSE: " + entitiesInBounds[i].EntityClass.entityClassName);
|
|
entitiesInBounds[i].DamageEntity(new DamageSource(EnumDamageSource.Internal, EnumDamageTypes.Suicide), 99999, false, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
world.GetWBT().AddScheduledBlockUpdate(_clrIdx, _blockPos, this.blockID, this.GetTickRate());
|
|
return true;
|
|
}
|
|
|
|
public override void Init()
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-Init START");
|
|
base.Init();
|
|
if (!this.Properties.Values.ContainsKey(BlockSecureLootGatherer.PropLootList))
|
|
{
|
|
throw new Exception("Block with name " + base.GetBlockName() + " doesnt have a loot list");
|
|
}
|
|
this.lootList = this.Properties.Values[BlockSecureLootGatherer.PropLootList];
|
|
if (this.Properties.Values.ContainsKey(BlockSecureLootGatherer.PropLockPickTime))
|
|
{
|
|
this.lockPickTime = StringParsers.ParseFloat(this.Properties.Values[BlockSecureLootGatherer.PropLockPickTime], 0, -1, NumberStyles.Any);
|
|
}
|
|
else
|
|
{
|
|
this.lockPickTime = 15f;
|
|
}
|
|
if (this.Properties.Values.ContainsKey(BlockSecureLootGatherer.PropLockPickItem))
|
|
{
|
|
this.lockPickItem = this.Properties.Values[BlockSecureLootGatherer.PropLockPickItem];
|
|
}
|
|
if (this.Properties.Values.ContainsKey(BlockSecureLootGatherer.PropLockPickBreakChance))
|
|
{
|
|
this.lockPickBreakChance = StringParsers.ParseFloat(this.Properties.Values[BlockSecureLootGatherer.PropLockPickBreakChance], 0, -1, NumberStyles.Any);
|
|
}
|
|
else
|
|
{
|
|
this.lockPickBreakChance = 0f;
|
|
}
|
|
this.Properties.ParseFloat(BlockSecureLootGatherer.PropLootStageMod, ref this.LootStageMod);
|
|
this.Properties.ParseFloat(BlockSecureLootGatherer.PropLootStageBonus, ref this.LootStageBonus);
|
|
|
|
this.CanPickup = true;
|
|
|
|
if (this.Properties.Values.ContainsKey("ReplacementBlockName"))
|
|
{
|
|
this.ReplacementBlockName = this.Properties.Values["ReplacementBlockName"];
|
|
}
|
|
|
|
bool flag1 = this.Properties.Values.ContainsKey("isReplacementItem");
|
|
if (flag1)
|
|
{
|
|
StringParsers.TryParseBool(this.Properties.Values["isReplacementItem"], out this.isReplacementItem, 0, -1, true);
|
|
}
|
|
bool flag2 = this.Properties.Values.ContainsKey("numBlocks");
|
|
if (flag2)
|
|
{
|
|
this.numBlocks = Int16.Parse(this.Properties.Values["numBlocks"]);
|
|
}
|
|
bool flag3 = this.Properties.Values.ContainsKey("isSecure");
|
|
if (flag3)
|
|
{
|
|
StringParsers.TryParseBool(this.Properties.Values["isSecure"], out this.isSecure, 0, -1, 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);
|
|
}
|
|
bool flag6 = this.Properties.Values.ContainsKey("isLootContainer");
|
|
if (flag6)
|
|
{
|
|
StringParsers.TryParseBool(this.Properties.Values["isLootContainer"], out this.isLootContainer, 0, -1, true);
|
|
}
|
|
}
|
|
|
|
public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
|
{
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntitySecureLootContainerRebirth;
|
|
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);
|
|
if (tileEntitySecureLootContainer == null)
|
|
{
|
|
return "";
|
|
}
|
|
string localizedBlockName = _blockValue.Block.GetLocalizedBlockName();
|
|
|
|
if (this.isSecure)
|
|
{
|
|
if (!tileEntitySecureLootContainer.IsLocked())
|
|
{
|
|
return string.Format(Localization.Get("tooltipUnlocked"), arg, localizedBlockName);
|
|
}
|
|
if (this.lockPickItem == null && !tileEntitySecureLootContainer.LocalPlayerIsOwner())
|
|
{
|
|
return string.Format(Localization.Get("tooltipJammed"), arg, localizedBlockName);
|
|
}
|
|
return string.Format(Localization.Get("tooltipLocked"), arg, localizedBlockName);
|
|
}
|
|
else
|
|
{
|
|
if (!tileEntitySecureLootContainer.bTouched)
|
|
{
|
|
return string.Format(Localization.Get("lootTooltipNew"), arg, localizedBlockName);
|
|
}
|
|
if (tileEntitySecureLootContainer.IsEmpty())
|
|
{
|
|
return string.Format(Localization.Get("lootTooltipEmpty"), arg, localizedBlockName);
|
|
}
|
|
return string.Format(Localization.Get("lootTooltipTouched"), arg, localizedBlockName);
|
|
}
|
|
}
|
|
|
|
public override bool OnBlockActivated(WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockActivated START");
|
|
if (_blockValue.ischild)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockActivated 1");
|
|
Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue);
|
|
BlockValue block = _world.GetBlock(parentPos);
|
|
return this.OnBlockActivated(_world, _cIdx, parentPos, block, _player);
|
|
}
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySecureLootContainerRebirth;
|
|
if (tileEntitySecureLootContainer == null)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockActivated 2");
|
|
return false;
|
|
}
|
|
_player.AimingGun = false;
|
|
Vector3i blockPos = tileEntitySecureLootContainer.ToWorldPos();
|
|
tileEntitySecureLootContainer.bWasTouched = tileEntitySecureLootContainer.bTouched;
|
|
_world.GetGameManager().TELockServer(_cIdx, blockPos, tileEntitySecureLootContainer.entityId, _player.entityId, null);
|
|
return true;
|
|
}
|
|
|
|
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockActivated START");
|
|
if (_blockValue.ischild)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer: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);
|
|
}
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySecureLootContainerRebirth;
|
|
if (tileEntitySecureLootContainer == null)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer:isSecure 0");
|
|
return false;
|
|
}
|
|
//Log.Out("BlockSecureLootGatherer:isSecure: " + this.isSecure);
|
|
if (this.isSecure)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer:isSecure: True");
|
|
PlatformUserIdentifierAbs getContainerOwner = tileEntitySecureLootContainer.GetOwner();
|
|
bool isUserAllowed = tileEntitySecureLootContainer.IsUserAllowed(PlatformManager.InternalLocalUserIdentifier);
|
|
//Log.Out("OnBlockActivated:_indexInBlockActivationCommands: " + _commandName);
|
|
if (_commandName == this.cmds[0].text)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-OnBlockActivated:Secure/Search");
|
|
|
|
Vector3i blockPos = tileEntitySecureLootContainer.ToWorldPos();
|
|
tileEntitySecureLootContainer.bWasTouched = tileEntitySecureLootContainer.bTouched;
|
|
if (!tileEntitySecureLootContainer.IsLocked() || isUserAllowed)
|
|
{
|
|
_world.GetGameManager().TELockServer(_cIdx, blockPos, tileEntitySecureLootContainer.entityId, _player.entityId, null);
|
|
return true;
|
|
//return base.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
|
|
}
|
|
Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locked");
|
|
return false;
|
|
}
|
|
else if (_commandName == this.cmds[1].text)
|
|
{
|
|
tileEntitySecureLootContainer.SetLocked(true);
|
|
Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locking");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerLocked");
|
|
return true;
|
|
}
|
|
else if (_commandName == this.cmds[2].text)
|
|
{
|
|
tileEntitySecureLootContainer.SetLocked(false);
|
|
Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerUnlocked");
|
|
return true;
|
|
}
|
|
else if (_commandName == this.cmds[3].text)
|
|
{
|
|
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal);
|
|
if (uiforPlayer != null)
|
|
{
|
|
XUiC_KeypadWindow.Open(uiforPlayer, tileEntitySecureLootContainer);
|
|
}
|
|
return true;
|
|
}
|
|
else if (_commandName == this.cmds[4].text)
|
|
{
|
|
if (getContainerOwner == null)
|
|
{
|
|
//Log.Out("OnBlockActivated:Pick no owner");
|
|
LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI;
|
|
ItemValue item = ItemClass.GetItem(this.lockPickItem, false);
|
|
if (playerUI.xui.PlayerInventory.GetItemCount(item) == 0)
|
|
{
|
|
playerUI.xui.CollectedItemList.AddItemStack(new ItemStack(item, 0), true);
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttLockpickMissing"));
|
|
return true;
|
|
}
|
|
|
|
bool advancedLockPicking = false;
|
|
|
|
// If they have a controller, skip the mini game
|
|
if (PlatformManager.NativePlatform.Input.CurrentInputStyle == PlayerInputManager.InputStyle.Keyboard)
|
|
{
|
|
//Log.Out("OnBlockActivated: Using a controller");
|
|
advancedLockPicking = true;
|
|
}
|
|
|
|
if (_player.Buffs.HasCustomVar("LegacyLockPick") && _player.Buffs.GetCustomVar("LegacyLockPick") > 0)
|
|
{
|
|
//Log.Out("OnBlockActivated: LegacyLockPick CVar is set");
|
|
advancedLockPicking = true;
|
|
}
|
|
|
|
//Log.Out("OnBlockActivated, advancedLockPicking: " + advancedLockPicking);
|
|
if (advancedLockPicking)
|
|
{
|
|
//Log.Out("OnBlockActivated, advancedLockPicking 1");
|
|
XUiC_PickLocking.Open(playerUI, tileEntitySecureLootContainer, _blockValue, _blockPos);
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("OnBlockActivated, advancedLockPicking 2");
|
|
playerUI.windowManager.Open("timer", true, false, true);
|
|
XUiC_Timer childByType = playerUI.xui.GetChildByType<XUiC_Timer>();
|
|
TimerEventData timerEventData = new TimerEventData();
|
|
timerEventData.CloseEvent += this.EventData_CloseEvent;
|
|
float alternateTime = -1f;
|
|
if (_player.rand.RandomRange(1f) < EffectManager.GetValue(PassiveEffects.LockPickBreakChance, _player.inventory.holdingItemItemValue, this.lockPickBreakChance, _player, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1))
|
|
{
|
|
float value = EffectManager.GetValue(PassiveEffects.LockPickTime, _player.inventory.holdingItemItemValue, this.lockPickTime, _player, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1);
|
|
float num = value - ((tileEntitySecureLootContainer.PickTimeLeft == -1f) ? (value - 1f) : (tileEntitySecureLootContainer.PickTimeLeft + 1f));
|
|
alternateTime = _player.rand.RandomRange(num + 1f, value - 1f);
|
|
}
|
|
timerEventData.Data = new object[]
|
|
{
|
|
_cIdx,
|
|
_blockValue,
|
|
_blockPos,
|
|
_player,
|
|
item
|
|
};
|
|
timerEventData.Event += this.EventData_Event;
|
|
timerEventData.alternateTime = alternateTime;
|
|
timerEventData.AlternateEvent += this.EventData_CloseEvent;
|
|
childByType.SetTimer(EffectManager.GetValue(PassiveEffects.LockPickTime, _player.inventory.holdingItemItemValue, this.lockPickTime, _player, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1), timerEventData, tileEntitySecureLootContainer.PickTimeLeft, "");
|
|
Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking");
|
|
}
|
|
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("OnBlockActivated:Pick has owner");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttNotBelongsToSomeone"), string.Empty, "ui_denied", null);
|
|
return false;
|
|
}
|
|
}
|
|
else if (_commandName == this.cmds[5].text)
|
|
{
|
|
XUiC_TriggerProperties.Show(((EntityPlayerLocal)_player).PlayerUI.xui, _cIdx, _blockPos, false, true);
|
|
return true;
|
|
}
|
|
else if (_commandName == this.cmds[6].text)
|
|
{
|
|
bool result;
|
|
//Log.Out("OnBlockActivated:Take before GetOwner");
|
|
//Log.Out("OnBlockActivated:Take after GetOwner");
|
|
if (getContainerOwner == null)
|
|
{
|
|
if (((World)_world).IsWithinTraderArea(_blockPos))
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return false;
|
|
}
|
|
|
|
//Log.Out("OnBlockActivated:Take has no owner");
|
|
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, this.TakeDelay, null, ReplacementBlockName, numBlocks, isReplacementItem);
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("OnBlockActivated:Take has owner");
|
|
bool isOwner = tileEntitySecureLootContainer.IsOwner(PlatformManager.InternalLocalUserIdentifier);
|
|
bool hasLandClaim = _world.IsMyLandProtectedBlock(_blockPos, _world.GetGameManager().GetPersistentLocalPlayer(), false);
|
|
if (!isOwner && !hasLandClaim)
|
|
{
|
|
//Log.Out("OnBlockActivated:Take am not owner");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttNotBelongsToYou"), string.Empty, "ui_denied", null);
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
if (((World)_world).IsWithinTraderArea(_blockPos))
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return false;
|
|
}
|
|
|
|
//Log.Out("OnBlockActivated:Take am owner");
|
|
//Log.Out("OnBlockActivated: ReplacementBlockName: " + ReplacementBlockName);
|
|
//Log.Out("OnBlockActivated: GetBlockName: " + _blockValue.Block.GetBlockName());
|
|
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, this.TakeDelay, null, ReplacementBlockName, numBlocks, isReplacementItem);
|
|
result = true;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
else if (_commandName == this.cmds[7].text)
|
|
{
|
|
tileEntitySecureLootContainer.SetLootGatheringActivated(true);
|
|
|
|
return true;
|
|
}
|
|
else if (_commandName == this.cmds[8].text)
|
|
{
|
|
tileEntitySecureLootContainer.SetLootGatheringActivated(false);
|
|
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer:isSecure: False");
|
|
if (_commandName == this.cmds[0].text)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer:OnBlockActivated-_commandName == this.cmds[0].text");
|
|
//Log.Out("OnBlockActivated:Insecure/Search");
|
|
if (_player.inventory.IsHoldingItemActionRunning())
|
|
{
|
|
return false;
|
|
}
|
|
_player.AimingGun = false;
|
|
Vector3i blockPos = tileEntitySecureLootContainer.ToWorldPos();
|
|
tileEntitySecureLootContainer.bWasTouched = tileEntitySecureLootContainer.bTouched;
|
|
//Log.Out("OnBlockActivated:Insecure/Search, Before Lock");
|
|
_world.GetGameManager().TELockServer(_cIdx, blockPos, tileEntitySecureLootContainer.entityId, _player.entityId, null);
|
|
//Log.Out("OnBlockActivated:Insecure/Search, After Lock");
|
|
return true;
|
|
}
|
|
else if (_commandName == this.cmds[6].text)
|
|
{
|
|
bool result;
|
|
//Log.Out("OnBlockActivated:Take before GetOwner");
|
|
PlatformUserIdentifierAbs getContainerOwner = tileEntitySecureLootContainer.GetOwner();
|
|
//Log.Out("OnBlockActivated:Take after GetOwner");
|
|
if (getContainerOwner == null)
|
|
{
|
|
if (((World)_world).IsWithinTraderArea(_blockPos))
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return false;
|
|
}
|
|
|
|
//Log.Out("OnBlockActivated:Take has no owner");
|
|
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, this.TakeDelay, null, ReplacementBlockName, numBlocks, isReplacementItem);
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("OnBlockActivated:Take has owner");
|
|
bool isOwner = tileEntitySecureLootContainer.IsOwner(PlatformManager.InternalLocalUserIdentifier);
|
|
bool hasLandClaim = _world.IsMyLandProtectedBlock(_blockPos, _world.GetGameManager().GetPersistentLocalPlayer(), false);
|
|
if (!isOwner && !hasLandClaim)
|
|
{
|
|
//Log.Out("OnBlockActivated:Take am not owner");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttNotBelongsToYou"), string.Empty, "ui_denied", null);
|
|
result = false;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (((World)_world).IsWithinTraderArea(_blockPos))
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return false;
|
|
}
|
|
|
|
//Log.Out("OnBlockActivated:Take am owner");
|
|
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, this.TakeDelay, null, ReplacementBlockName, numBlocks, isReplacementItem);
|
|
result = true;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("OnBlockActivated:Insecure/Other");
|
|
//Log.Out("BlockSecureLootGatherer:OnBlockActivated-_indexInBlockActivationCommands == other");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
object obj = array[4];
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = world.GetTileEntity(clrIdx, vector3i) as TileEntitySecureLootContainerRebirth;
|
|
if (tileEntitySecureLootContainer == null)
|
|
{
|
|
return;
|
|
}
|
|
if (tileEntitySecureLootContainer.IsUserAccessing())
|
|
{
|
|
GameManager.ShowTooltip(entityPlayerLocal, Localization.Get("ttCantPickupInUse"), string.Empty, "ui_denied", null);
|
|
return;
|
|
}
|
|
LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
|
|
if (!this.DowngradeBlock.isair)
|
|
{
|
|
BlockValue blockValue2 = this.DowngradeBlock;
|
|
blockValue2 = BlockPlaceholderMap.Instance.Replace(blockValue2, world.GetGameRandom(), vector3i.x, vector3i.z);
|
|
blockValue2.rotation = block.rotation;
|
|
blockValue2.meta = block.meta;
|
|
world.SetBlockRPC(clrIdx, vector3i, blockValue2, blockValue2.Block.Density);
|
|
}
|
|
Manager.BroadcastPlayByLocalPlayer(vector3i.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking");
|
|
this.ResetEventData(timerData);
|
|
}
|
|
|
|
private void ResetEventData(TimerEventData timerData)
|
|
{
|
|
timerData.AlternateEvent -= this.EventData_CloseEvent;
|
|
timerData.CloseEvent -= this.EventData_CloseEvent;
|
|
timerData.Event -= this.EventData_Event;
|
|
}
|
|
|
|
private void EventData_CloseEvent(TimerEventData timerData)
|
|
{
|
|
object[] array = (object[])timerData.Data;
|
|
Vector3i blockPos = (Vector3i)array[2];
|
|
EntityPlayerLocal entityPlayerLocal = array[3] as EntityPlayerLocal;
|
|
ItemValue itemValue = array[4] as ItemValue;
|
|
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
|
|
Manager.BroadcastPlayByLocalPlayer(blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locked");
|
|
ItemStack itemStack = new ItemStack(itemValue, 1);
|
|
uiforPlayer.xui.PlayerInventory.RemoveItem(itemStack);
|
|
GameManager.ShowTooltip(entityPlayerLocal, Localization.Get("ttLockpickBroken"));
|
|
uiforPlayer.xui.CollectedItemList.RemoveItemStack(itemStack);
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = GameManager.Instance.World.GetTileEntity((int)array[0], blockPos) as TileEntitySecureLootContainerRebirth;
|
|
if (tileEntitySecureLootContainer == null)
|
|
{
|
|
return;
|
|
}
|
|
tileEntitySecureLootContainer.PickTimeLeft = Mathf.Max(this.lockPickTime * 0.25f, timerData.timeLeft);
|
|
this.ResetEventData(timerData);
|
|
}
|
|
|
|
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-GetBlockActivationCommands START");
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntitySecureLootContainerRebirth;
|
|
if (tileEntitySecureLootContainer == null)
|
|
{
|
|
return new BlockActivationCommand[0];
|
|
}
|
|
PlatformUserIdentifierAbs internalLocalUserIdentifier = PlatformManager.InternalLocalUserIdentifier;
|
|
PersistentPlayerData playerData = _world.GetGameManager().GetPersistentPlayerList().GetPlayerData(tileEntitySecureLootContainer.GetOwner());
|
|
bool flag = tileEntitySecureLootContainer.LocalPlayerIsOwner();
|
|
bool flag2 = !flag && (playerData != null && playerData.ACL != null) && playerData.ACL.Contains(internalLocalUserIdentifier);
|
|
|
|
//Log.Out("BlockSecureLootGatherer-GetBlockActivationCommands flag: " + flag);
|
|
//Log.Out("BlockSecureLootGatherer-GetBlockActivationCommands flag2: " + flag2);
|
|
//Log.Out("BlockSecureLootGatherer-GetBlockActivationCommands this.canPickUpBlock: " + this.canPickUpBlock);
|
|
//Log.Out("BlockSecureLootGatherer-GetBlockActivationCommands this.isSecure: " + this.isSecure);
|
|
//Log.Out("BlockSecureLootGatherer-GetBlockActivationCommands tileEntitySecureLootContainer.IsLocked(): " + tileEntitySecureLootContainer.IsLocked());
|
|
//Log.Out("BlockSecureLootGatherer-GetBlockActivationCommands this.isLootGatheringActivated: " + this.isLootGatheringActivated);
|
|
|
|
this.cmds[0].enabled = this.canPickUpBlock;
|
|
this.cmds[1].enabled = (this.isSecure && !tileEntitySecureLootContainer.IsLocked() && (flag || flag2));
|
|
this.cmds[2].enabled = (this.isSecure && tileEntitySecureLootContainer.IsLocked() && flag);
|
|
this.cmds[3].enabled = this.isSecure && ((!tileEntitySecureLootContainer.IsUserAllowed(internalLocalUserIdentifier) && tileEntitySecureLootContainer.HasPassword() && tileEntitySecureLootContainer.IsLocked()) || flag);
|
|
this.cmds[4].enabled = (this.isSecure && this.lockPickItem != null && tileEntitySecureLootContainer.IsLocked() && !flag);
|
|
this.cmds[5].enabled = this.isSecure && _world.IsEditor();
|
|
this.cmds[6].enabled = this.canPickUpBlock && (tileEntitySecureLootContainer.IsEmpty() && tileEntitySecureLootContainer.bTouched);
|
|
this.cmds[7].enabled = (!tileEntitySecureLootContainer.isLootGatheringActivated && this.isSecure && (flag || flag2));
|
|
this.cmds[8].enabled = (tileEntitySecureLootContainer.isLootGatheringActivated && this.isSecure && (flag || flag2));
|
|
return this.cmds;
|
|
}
|
|
|
|
public BlockActivationCommand[] cmds = new BlockActivationCommand[]
|
|
{
|
|
new BlockActivationCommand("Search", "search", false, false),
|
|
new BlockActivationCommand("lock", "lock", false, false),
|
|
new BlockActivationCommand("unlock", "unlock", false, false),
|
|
new BlockActivationCommand("keypad", "keypad", false, false),
|
|
new BlockActivationCommand("pick", "unlock", false, false),
|
|
new BlockActivationCommand("trigger", "wrench", true, false),
|
|
new BlockActivationCommand("take", "hand", false, false),
|
|
new BlockActivationCommand("ActivateLootGathering", "loot_sack_green", false, false),
|
|
new BlockActivationCommand("DeactivateLootGathering", "loot_sack_red", false, false),
|
|
};
|
|
|
|
public override int DamageBlock(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, int _damagePoints, int _entityIdThatDamaged, ItemActionAttack.AttackHitInfo _attackHitInfo = null, bool _bUseHarvestTool = false, bool _bBypassMaxDamage = false)
|
|
{
|
|
//Log.Out("BlockSecureLootGatherer-DamageBlock START");
|
|
TileEntitySecureLootContainerRebirth tileEntitySecureLootContainer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntitySecureLootContainerRebirth;
|
|
PlatformUserIdentifierAbs getContainerOwner = tileEntitySecureLootContainer.GetOwner();
|
|
if (getContainerOwner == null)
|
|
{
|
|
return this.OnBlockDamaged(_world, _clrIdx, _blockPos, _blockValue, _damagePoints, _entityIdThatDamaged, _attackHitInfo, _bUseHarvestTool, _bBypassMaxDamage, 0);
|
|
}
|
|
else
|
|
{
|
|
bool isOwner = tileEntitySecureLootContainer.IsOwner(PlatformManager.InternalLocalUserIdentifier);
|
|
if (!isOwner)
|
|
{
|
|
EntityAlive entityAlive = _world.GetEntity(_entityIdThatDamaged) as EntityAlive;
|
|
if (entityAlive != null)
|
|
{
|
|
string entityClassName = entityAlive.EntityClass.entityClassName;
|
|
//Log.Out("DamageBlock:entityClassName: " + entityClassName);
|
|
if (entityClassName == "playerMale" || entityClassName == "playerFemale")
|
|
{
|
|
int @playerKillingMode = GameStats.GetInt(EnumGameStats.PlayerKillingMode);
|
|
//Log.Out("DamageBlock:EnumPlayerKillingMode-@playerKillingMode: " + @playerKillingMode);
|
|
if (@playerKillingMode == 0)
|
|
{
|
|
//Log.Out("DamageBlock:EnumPlayerKillingMode: No Killing");
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("DamageBlock:EnumPlayerKillingMode: Killing Allowed");
|
|
return this.OnBlockDamaged(_world, _clrIdx, _blockPos, _blockValue, _damagePoints, _entityIdThatDamaged, _attackHitInfo, _bUseHarvestTool, _bBypassMaxDamage, 0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return this.OnBlockDamaged(_world, _clrIdx, _blockPos, _blockValue, _damagePoints, _entityIdThatDamaged, _attackHitInfo, _bUseHarvestTool, _bBypassMaxDamage, 0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return this.OnBlockDamaged(_world, _clrIdx, _blockPos, _blockValue, _damagePoints, _entityIdThatDamaged, _attackHitInfo, _bUseHarvestTool, _bBypassMaxDamage, 0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return this.OnBlockDamaged(_world, _clrIdx, _blockPos, _blockValue, _damagePoints, _entityIdThatDamaged, _attackHitInfo, _bUseHarvestTool, _bBypassMaxDamage, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static string PropLootList = "LootList";
|
|
protected static string PropLootStageMod = "LootStageMod";
|
|
protected static string PropLootStageBonus = "LootStageBonus";
|
|
protected static string PropLockPickTime = "LockPickTime";
|
|
protected static string PropLockPickItem = "LockPickItem";
|
|
protected static string PropLockPickBreakChance = "LockPickBreakChance";
|
|
protected string lootList;
|
|
protected float lockPickTime;
|
|
protected string lockPickItem;
|
|
protected float lockPickBreakChance;
|
|
public float LootStageMod;
|
|
public float LootStageBonus;
|
|
public float TakeDelay = RebirthVariables.takeDelay;
|
|
public string ReplacementBlockName = "FuriousRamsayLootGatherer";
|
|
public int numBlocks = 1;
|
|
public bool isReplacementItem = false;
|
|
public bool isSecure = false;
|
|
public bool isLootContainer = true;
|
|
public bool canPickUpBlock = true;
|
|
public GameRandom Random;
|
|
public int autoLootTick = 10;
|
|
}
|