Upload from upload_mods.ps1
This commit is contained in:
277
Scripts/Blocks/BlockWaterTankRebirth.cs
Normal file
277
Scripts/Blocks/BlockWaterTankRebirth.cs
Normal file
@@ -0,0 +1,277 @@
|
||||
using Audio;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
public class BlockWaterTankRebirth : Block
|
||||
{
|
||||
private float TakeDelay = RebirthVariables.takeDelay;
|
||||
private int waterMax = 100;
|
||||
private bool canPickUpBlock = true;
|
||||
public ulong TickRate = 3000UL;
|
||||
|
||||
private BlockActivationCommand[] cmds = new BlockActivationCommand[]
|
||||
{
|
||||
new BlockActivationCommand("cancel", "x", false, false),
|
||||
new BlockActivationCommand("take", "hand", false)
|
||||
};
|
||||
|
||||
public override bool HasBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-Init START");
|
||||
base.Init();
|
||||
this.canPickUpBlock = true;
|
||||
bool flag = this.Properties.Values.ContainsKey("TakeDelay");
|
||||
if (flag)
|
||||
{
|
||||
this.TakeDelay = StringParsers.ParseFloat(this.Properties.Values["TakeDelay"], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
bool flag2 = this.Properties.Values.ContainsKey("canPickUpBlock");
|
||||
if (flag2)
|
||||
{
|
||||
StringParsers.TryParseBool(this.Properties.Values["canPickUpBlock"], out this.canPickUpBlock, 0, -1, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void addTileEntity(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-addTileEntity START");
|
||||
TileEntityWaterTankRebirth tileEntityWaterTank = new TileEntityWaterTankRebirth(_chunk);
|
||||
tileEntityWaterTank.localChunkPos = World.toBlock(_blockPos);
|
||||
tileEntityWaterTank.waterCount = 0;
|
||||
tileEntityWaterTank.timeLapsed = RebirthUtilities.TotalGameSecondsPassed();
|
||||
_chunk.AddTileEntity(tileEntityWaterTank);
|
||||
}
|
||||
|
||||
protected virtual void removeTileEntity(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-removeTileEntity START");
|
||||
_chunk.RemoveTileEntityAt<TileEntityWaterTankRebirth>((World)world, World.toBlock(_blockPos));
|
||||
|
||||
/*int minMax = 100;
|
||||
List<Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(typeof(EntityChunkObserver), BoundsUtils.BoundsForMinMax(_blockPos.x - minMax, _blockPos.y - 20, _blockPos.z - minMax, _blockPos.x + minMax, _blockPos.y + 20, _blockPos.z + minMax), new List<Entity>());
|
||||
|
||||
if (entitiesInBounds != null && entitiesInBounds.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < entitiesInBounds.Count; i++)
|
||||
{
|
||||
if (entitiesInBounds[i].EntityClass.entityClassName == "FuriousRamsayObserver")
|
||||
{
|
||||
var entity = entitiesInBounds[i] as EntityAlive;
|
||||
entity.bWillRespawn = false;
|
||||
GameManager.Instance.World.RemoveEntity(entity.entityId, EnumRemoveEntityReason.Unloaded);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-OnBlockRemoved START");
|
||||
base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue);
|
||||
TileEntityWaterTankRebirth tileEntityWaterTank = world.GetTileEntity(_chunk.ClrIdx, _blockPos) as TileEntityWaterTankRebirth;
|
||||
if (tileEntityWaterTank != null)
|
||||
{
|
||||
tileEntityWaterTank.OnDestroy();
|
||||
}
|
||||
this.removeTileEntity(world, _chunk, _blockPos, _blockValue);
|
||||
}
|
||||
|
||||
public override void OnBlockAdded(WorldBase _world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-OnBlockAdded START");
|
||||
base.OnBlockAdded(_world, _chunk, _blockPos, _blockValue);
|
||||
this.addTileEntity(_world, _chunk, _blockPos, _blockValue);
|
||||
|
||||
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer) return;
|
||||
if (GameManager.Instance.IsEditMode()) return;
|
||||
|
||||
_blockValue.meta = 0;
|
||||
|
||||
_world.GetWBT().AddScheduledBlockUpdate(_chunk.ClrIdx, _blockPos, this.blockID, this.TickRate);
|
||||
}
|
||||
|
||||
public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-GetActivationText START");
|
||||
string activationText = Localization.Get("ttTankEmpty");
|
||||
|
||||
TileEntityWaterTankRebirth tileEntity = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityWaterTankRebirth;
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity.waterCount > 0)
|
||||
{
|
||||
string color = "e3dc5b";
|
||||
string colorMax = "5ed680";
|
||||
|
||||
if (this.Properties.Values.ContainsKey("MaxWater"))
|
||||
{
|
||||
this.waterMax = Int16.Parse(this.Properties.Values["MaxWater"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.waterMax = tileEntity.waterMax;
|
||||
}
|
||||
|
||||
if (tileEntity.waterCount == this.waterMax)
|
||||
{
|
||||
color = colorMax;
|
||||
|
||||
}
|
||||
activationText = Localization.Get("ttWaterContent") + " [[" + color + "]" + tileEntity.waterCount + "[-]/[" + colorMax + "]" + this.waterMax + "[-]]";
|
||||
}
|
||||
}
|
||||
|
||||
return (activationText);
|
||||
}
|
||||
|
||||
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-OnBlockActivated START");
|
||||
bool ischild = _blockValue.ischild;
|
||||
bool result = false;
|
||||
|
||||
if (ischild)
|
||||
{
|
||||
Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue);
|
||||
BlockValue block = _world.GetBlock(parentPos);
|
||||
result = this.OnBlockActivated(_commandName, _world, _cIdx, parentPos, block, _player);
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntityWaterTankRebirth tileEntity = _world.GetTileEntity(_cIdx, _blockPos) as TileEntityWaterTankRebirth;
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (_commandName == this.cmds[0].text)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else if (_commandName == this.cmds[1].text)
|
||||
{
|
||||
if (((World)_world).IsWithinTraderArea(_blockPos))
|
||||
{
|
||||
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);
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public BlockWaterTankRebirth()
|
||||
{
|
||||
this.HasTileEntity = true;
|
||||
}
|
||||
|
||||
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-GetBlockActivationCommands START");
|
||||
this.cmds[0].enabled = this.canPickUpBlock;
|
||||
this.cmds[1].enabled = this.canPickUpBlock;
|
||||
return this.cmds;
|
||||
}
|
||||
|
||||
public override bool UpdateTick(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, bool _bRandomTick, ulong _ticksIfLoaded, GameRandom _rnd)
|
||||
{
|
||||
TileEntityWaterTankRebirth tileEntity = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityWaterTankRebirth;
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick tileEntity.timeLapsed: " + tileEntity.timeLapsed);
|
||||
|
||||
int totalSecondsPassed = RebirthUtilities.TotalGameSecondsPassed();
|
||||
|
||||
int timeLapsed = (int)((totalSecondsPassed - tileEntity.timeLapsed) / 0.86f) + 1;
|
||||
|
||||
tileEntity.timeLapsed = totalSecondsPassed;
|
||||
|
||||
int cycle = (int)(this.TickRate / 20);
|
||||
|
||||
int numIterations = timeLapsed / cycle;
|
||||
|
||||
if (numIterations == 0 && totalSecondsPassed > (cycle / 2))
|
||||
{
|
||||
numIterations = 1;
|
||||
}
|
||||
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick totalSecondsPassed: " + totalSecondsPassed);
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick timeLapsed: " + timeLapsed);
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick cycle: " + cycle);
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick numIterations: " + numIterations);
|
||||
|
||||
for (int i = 0; i < numIterations; i++)
|
||||
{
|
||||
if (this.blockName == "FuriousRamsayDewCollector")
|
||||
{
|
||||
BiomeDefinition biomeAt = null;
|
||||
|
||||
if (!_world.IsEditor())
|
||||
{
|
||||
biomeAt = _world.ChunkCache.ChunkProvider.GetBiomeProvider().GetBiomeAt((int)_blockPos.x, (int)_blockPos.z);
|
||||
}
|
||||
|
||||
if (biomeAt != null)
|
||||
{
|
||||
System.Random rnd = new System.Random();
|
||||
int randomInt = rnd.Next(0, 100 + 1);
|
||||
int randomPerc = 0;
|
||||
|
||||
if (biomeAt.m_sBiomeName == "forest" || biomeAt.m_sBiomeName == "pine_forest")
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick FOREST");
|
||||
randomPerc = rnd.Next(80, 100 + 1);
|
||||
}
|
||||
else if (biomeAt.m_sBiomeName == "desert")
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick DESERT");
|
||||
randomPerc = rnd.Next(40, 60 + 1);
|
||||
}
|
||||
else if (biomeAt.m_sBiomeName == "snow")
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick SNOW");
|
||||
randomPerc = rnd.Next(40, 60 + 1);
|
||||
}
|
||||
else if (biomeAt.m_sBiomeName == "burnt_forest")
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick BURNT");
|
||||
randomPerc = rnd.Next(60, 80 + 1);
|
||||
}
|
||||
else if (biomeAt.m_sBiomeName == "wasteland")
|
||||
{
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick WASTELAND");
|
||||
randomPerc = rnd.Next(40, 60 + 1);
|
||||
}
|
||||
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick randomPerc: " + randomPerc);
|
||||
//Log.Out("BlockWaterTankRebirth-UpdateTick randomInt: " + randomInt);
|
||||
|
||||
if (randomPerc >= randomInt && tileEntity.waterCount < Int16.Parse(this.Properties.Values["MaxWater"]))
|
||||
{
|
||||
tileEntity.waterCount++;
|
||||
tileEntity.setModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_world.GetWBT().AddScheduledBlockUpdate(_clrIdx, _blockPos, this.blockID, this.TickRate);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user