Upload from upload_mods.ps1

This commit is contained in:
Nathaniel Cosford
2025-06-04 16:44:53 +09:30
commit f1fbbe67bb
1722 changed files with 165268 additions and 0 deletions

View File

@@ -0,0 +1,684 @@
using Audio;
using System.Collections.Generic;
using System.Diagnostics;
public class BlockVehicleRebirth : BlockCarExplodeLoot
{
public GameRandom rng = null;
public bool isRepairable = false;
public bool isLootable = false;
public bool canContainGas = false;
public bool canContainOil = false;
public bool canContainFLHeadlight = false;
public bool canContainFRHeadlight = false;
public bool canContainEngine = false;
public bool canContainBattery = false;
public bool canContainCarburetor = false;
public bool canContainAltenator = false;
public bool canContainTransmission = false;
public bool canContainFLTire = false;
public bool canContainFRTire = false;
public bool canContainRLTire = false;
public bool canContainRRTire = false;
public float spawn_min_gas_percent = 0f;
public float spawn_max_gas_percent = 0f;
public float spawn_min_repaired_percent = 0f;
public float spawn_max_repaired_percent = 0f;
public float spawn_entity_y_offset = 0f;
public string vehicle_entity_class = "";
public override int OnBlockDamaged(
WorldBase _world,
int _clrIdx,
Vector3i _blockPos,
BlockValue _blockValue,
int _damagePoints,
int _entityIdThatDamaged,
ItemActionAttack.AttackHitInfo _attackHitInfo,
bool _bUseHarvestTool,
bool _bBypassMaxDamage,
int _recDepth = 0)
{
//Log.Out("BlockVehicleRebirth-OnBlockDamaged _bUseHarvestTool: " + _bUseHarvestTool);
if (_bUseHarvestTool && _entityIdThatDamaged > 0)
{
if ((EntityPlayer)_world.GetEntity(_entityIdThatDamaged) is EntityPlayer player && _world.GetTileEntity(_clrIdx, _blockPos) is TileEntityDriveableLootContainer tileEntity)
{
if (tileEntity.bPlayerStorage && player.inventory.holdingItem.HasAnyTags(FastTags<TagGroup.Global>.Parse("salvageTool")))
{
return 0;
}
}
}
return base.OnBlockDamaged(_world, _clrIdx, _blockPos, _blockValue, _damagePoints, _entityIdThatDamaged, _attackHitInfo, _bUseHarvestTool, _bBypassMaxDamage, _recDepth);
}
public override void Init()
{
base.Init();
CanPickup = true;
rng = new GameRandom();
if (Properties.Values.ContainsKey("isRepairable"))
{
isRepairable = Convert.ToBoolean(Properties.Values["isRepairable"]);
}
if (Properties.Values.ContainsKey("isLootable"))
{
isLootable = Convert.ToBoolean(Properties.Values["isLootable"]);
}
if (Properties.Values.ContainsKey("canContainGas"))
{
canContainGas = Convert.ToBoolean(Properties.Values["canContainGas"]);
}
if (Properties.Values.ContainsKey("canContainOil"))
{
canContainOil = Convert.ToBoolean(Properties.Values["canContainOil"]);
}
if (Properties.Values.ContainsKey("canContainFLHeadlight"))
{
canContainFLHeadlight = Convert.ToBoolean(Properties.Values["canContainFLHeadlight"]);
}
if (Properties.Values.ContainsKey("canContainFRHeadlight"))
{
canContainFRHeadlight = Convert.ToBoolean(Properties.Values["canContainFRHeadlight"]);
}
if (Properties.Values.ContainsKey("canContainEngine"))
{
canContainEngine = Convert.ToBoolean(Properties.Values["canContainEngine"]);
}
if (Properties.Values.ContainsKey("canContainBattery"))
{
canContainBattery = Convert.ToBoolean(Properties.Values["canContainBattery"]);
}
if (Properties.Values.ContainsKey("canContainCarburetor"))
{
canContainCarburetor = Convert.ToBoolean(Properties.Values["canContainCarburetor"]);
}
if (Properties.Values.ContainsKey("canContainAltenator"))
{
canContainAltenator = Convert.ToBoolean(Properties.Values["canContainAltenator"]);
}
if (Properties.Values.ContainsKey("canContainTransmission"))
{
canContainTransmission = Convert.ToBoolean(Properties.Values["canContainTransmission"]);
}
if (Properties.Values.ContainsKey("canContainFLTire"))
{
canContainFLTire = Convert.ToBoolean(Properties.Values["canContainFLTire"]);
}
if (Properties.Values.ContainsKey("canContainFRTire"))
{
canContainFRTire = Convert.ToBoolean(Properties.Values["canContainFRTire"]);
}
if (Properties.Values.ContainsKey("canContainRLTire"))
{
canContainRLTire = Convert.ToBoolean(Properties.Values["canContainRLTire"]);
}
if (Properties.Values.ContainsKey("canContainRRTire"))
{
canContainRRTire = Convert.ToBoolean(Properties.Values["canContainRRTire"]);
}
if (Properties.Values.ContainsKey("spawn_min_gas_percent"))
{
spawn_min_gas_percent = Mathf.Clamp01(Convert.ToSingle(Properties.Values["spawn_min_gas_percent"]));
}
if (Properties.Values.ContainsKey("spawn_max_gas_percent"))
{
spawn_max_gas_percent = Mathf.Clamp01(Convert.ToSingle(Properties.Values["spawn_max_gas_percent"]));
}
if (Properties.Values.ContainsKey("spawn_min_repaired_percent"))
{
spawn_min_repaired_percent = Mathf.Clamp01(Convert.ToSingle(Properties.Values["spawn_min_repaired_percent"]));
}
if (Properties.Values.ContainsKey("spawn_max_repaired_percent"))
{
spawn_max_repaired_percent = Mathf.Clamp01(Convert.ToSingle(Properties.Values["spawn_max_repaired_percent"]));
}
if (Properties.Values.ContainsKey("spawn_entity_y_offset"))
{
spawn_entity_y_offset = Convert.ToSingle(Properties.Values["spawn_entity_y_offset"]);
}
if (Properties.Values.ContainsKey("vehicle_entity_class"))
{
vehicle_entity_class = Properties.Values["vehicle_entity_class"];
}
}
public override void LateInit()
{
base.LateInit();
cmds = new BlockActivationCommand[]
{
new BlockActivationCommand("Search", "loot_sack", false, false),
new BlockActivationCommand("Siphon", "gas", false, false),
new BlockActivationCommand("Repair", "wrench", false, false),
};
}
public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
{
//Log.Out($"BlockVehicleRebirth-OnBlockActivated GetBlockActivationCommands isLootable: {isLootable}");
TileEntityDriveableLootContainer vehicleTE = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityDriveableLootContainer;
string vehicleType = "";
if (Properties.Values.ContainsKey("VehicleType"))
{
vehicleType = Properties.Values["VehicleType"];
}
//bool cantSearch = !RebirthUtilities.CanBeLooted(_blockPos, _blockValue, _cIdx);
cmds[0].enabled = false; // !cantSearch && isLootable;
cmds[1].enabled = false; // vehicleType != "BicycleRepair" && vehicleTE.GasPerc > 0f; // && spawn_max_repaired_percent > 0f;
cmds[2].enabled = isRepairable && !string.IsNullOrEmpty(vehicle_entity_class);
return cmds;
}
public override void OnBlockAdded(WorldBase _world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
{
if (!_blockValue.ischild)
{
shape.OnBlockAdded(_world, _chunk, _blockPos, _blockValue);
if (isMultiBlock)
{
multiBlockPos.AddChilds(_world, _chunk, _blockPos, _blockValue);
}
if (!string.IsNullOrEmpty(blockAddedEvent))
{
GameEventManager.Current.HandleAction(blockAddedEvent, null, null, twitchActivated: false, _blockPos);
}
}
addTileEntity(_world, _chunk, _blockPos, _blockValue);
TileEntityDriveableLootContainer vehicleTE = _chunk.GetTileEntity(World.toBlock(_blockPos)) as TileEntityDriveableLootContainer;
if (canContainGas)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + (int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount)));
vehicleTE.GasPerc = rng.RandomRange(spawn_min_gas_percent, spawn_max_gas_percent);
}
else
{
vehicleTE.GasPerc = 0.0f;
}
if (spawn_max_repaired_percent > 0f)
{
if (canContainOil)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.OilPerc = rng.RandomRange(0, 1f);
}
else
{
vehicleTE.OilPerc = 0.0f;
}
if (canContainFLHeadlight)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.FLHeadlightPerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.FLHeadlightPerc = 0.0f;
}
if (canContainFRHeadlight)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.FRHeadlightPerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.FRHeadlightPerc = 0.0f;
}
if (canContainEngine)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.EnginePerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.EnginePerc = 0.0f;
}
if (canContainBattery)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.BatteryPerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.BatteryPerc = 0.0f;
}
if (canContainCarburetor)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.CarburetorPerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.CarburetorPerc = 0.0f;
}
if (canContainAltenator)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.AltenatorPerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.AltenatorPerc = 0.0f;
}
if (canContainTransmission)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.TransmissionPerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.TransmissionPerc = 0.0f;
}
if (canContainFLTire)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.FLTirePerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.FLTirePerc = 0.0f;
}
if (canContainFRTire)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.FRTirePerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.FRTirePerc = 0.0f;
}
if (canContainRLTire)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.RLTirePerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.RLTirePerc = 0.0f;
}
if (canContainRRTire)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
vehicleTE.RRTirePerc = rng.RandomRange(spawn_min_repaired_percent, spawn_max_repaired_percent);
}
else
{
vehicleTE.RRTirePerc = 0.0f;
}
}
}
public override void OnBlockValueChanged(WorldBase _world, Chunk _chunk, int _clrIdx, Vector3i _blockPos, BlockValue _oldBlockValue, BlockValue _newBlockValue)
{
base.OnBlockValueChanged(_world, _chunk, _clrIdx, _blockPos, _oldBlockValue, _newBlockValue);
if (_newBlockValue.isair)
{
removeTileEntity(_world, _chunk, _blockPos, _newBlockValue);
}
}
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
{
//Log.Out($"BlockVehicleRebirth-OnBlockActivated _commandName: {_commandName}, player: {_player}");
TileEntityDriveableLootContainer vehicleTE = _world.GetTileEntity(_cIdx, _blockPos) as TileEntityDriveableLootContainer;
switch (_commandName)
{
case "Search":
//Log.Out("<color=cyan>Vehicle was searched!</color>");
if (_player.inventory.IsHoldingItemActionRunning())
{
return false;
}
if (_commandName == "Search" && !RebirthUtilities.CanBeLooted(_blockPos, _blockValue, _cIdx))
{
Manager.PlayInsidePlayerHead("ui_denied");
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
return false;
}
_player.AimingGun = false;
Vector3i blockPos = vehicleTE.ToWorldPos();
vehicleTE.bWasTouched = vehicleTE.bTouched;
_world.GetGameManager().TELockServer(_cIdx, blockPos, vehicleTE.entityId, _player.entityId);
return true;
/*case "inspect":
Log.Out($"<color=cyan>Vehicle was inspected!</color>");
Log.Out($"<color=yellow>Gas is at {vehicleTE.GasPerc}!</color>");
Log.Out($"<color=yellow>Oil is at {vehicleTE.OilPerc}!</color>");
Log.Out($"<color=yellow>Front left headlight is at {vehicleTE.FLHeadlightPerc}!</color>");
Log.Out($"<color=yellow>Front right headlight is at {vehicleTE.FRHeadlightPerc}!</color>");
Log.Out($"<color=yellow>Engine is at {vehicleTE.EnginePerc}!</color>");
Log.Out($"<color=yellow>Battery is at {vehicleTE.BatteryPerc}!</color>");
Log.Out($"<color=yellow>Carburetor is at {vehicleTE.CarburetorPerc}!</color>");
Log.Out($"<color=yellow>Altenator is at {vehicleTE.AltenatorPerc}!</color>");
Log.Out($"<color=yellow>Transmission is at {vehicleTE.TransmissionPerc}!</color>");
Log.Out($"<color=yellow>Front left tire is at {vehicleTE.FLTirePerc}!</color>");
Log.Out($"<color=yellow>Front right tire is at {vehicleTE.FRTirePerc}!</color>");
Log.Out($"<color=yellow>Rear left tire is at {vehicleTE.RLTirePerc}!</color>");
Log.Out($"<color=yellow>Rear right tire is at {vehicleTE.RRTirePerc}!</color>");
break;*/
case "Repair":
if (Properties.Values.ContainsKey("VehicleType"))
{
string vehicleType = Properties.Values["VehicleType"];
RebirthUtilities.OpenTileEntity(_player, _blockPos, vehicleType, "window" + vehicleType, "UseActions/service_vehicle");
}
break;
case "Siphon":
RebirthUtilities.addToPlayerBag(ItemClass.GetItem("ammoGasCan"), _player, Mathf.RoundToInt(vehicleTE.GasPerc * 500), "useactions/gas_refill");
vehicleTE.GasPerc = 0f;
break;
}
return true;
}
public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
{
base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue);
removeTileEntity(world, _chunk, _blockPos, _blockValue);
}
public override void addTileEntity(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
{
TileEntityDriveableLootContainer vehicleTE = new TileEntityDriveableLootContainer(_chunk)
{
localChunkPos = World.toBlock(_blockPos),
lootListName = lootList,
};
vehicleTE.SetContainerSize(LootContainer.GetLootContainer(lootList).size);
vehicleTE.InitRepairableVehicleParts();
_chunk.AddTileEntity(vehicleTE);
}
public override void removeTileEntity(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
{
_chunk.RemoveTileEntityAt<TileEntityDriveableLootContainer>((World)world, World.toBlock(_blockPos));
}
}
public class TileEntityDriveableLootContainer : TileEntityLootContainer
{
public Block block = null;
public ItemValue[] itemValues = new ItemValue[] { };
public float Durability, baseDurability, maxDurability, vehicleHealth, baseVehicleHealth, GasPerc, OilPerc, FLHeadlightPerc, FRHeadlightPerc, EnginePerc, BatteryPerc, CarburetorPerc, AltenatorPerc, TransmissionPerc, FLTirePerc, FRTirePerc, RLTirePerc, RRTirePerc;
public TileEntityDriveableLootContainer(Chunk _chunk) : base(_chunk)
{
block = base.blockValue.Block;
for (int i = 0; i < itemValues.Length; i++)
{
itemValues[i] = ItemValue.None;
}
Durability = 0f;
baseDurability = 0f;
maxDurability = 0f;
vehicleHealth = 0f;
baseVehicleHealth = 0f;
GasPerc = 0f;
OilPerc = 0f;
FLHeadlightPerc = 0f;
FRHeadlightPerc = 0f;
EnginePerc = 0f;
BatteryPerc = 0f;
CarburetorPerc = 0f;
AltenatorPerc = 0f;
TransmissionPerc = 0f;
FLTirePerc = 0f;
FRTirePerc = 0f;
RLTirePerc = 0f;
RRTirePerc = 0f;
}
public override void read(PooledBinaryReader _br, StreamModeRead _eStreamMode)
{
base.read(_br, _eStreamMode);
try
{
itemValues = GameUtils.ReadItemValueArray(_br);
}
catch
{
//Log.Error("BlockVehicleRebirth-read block: " + this.block.GetBlockName());
return;
}
Durability = _br.ReadSingle();
baseDurability = _br.ReadSingle();
maxDurability = _br.ReadSingle();
vehicleHealth = _br.ReadSingle();
baseVehicleHealth = _br.ReadSingle();
GasPerc = _br.ReadSingle();
OilPerc = _br.ReadSingle();
FLHeadlightPerc = _br.ReadSingle();
FRHeadlightPerc = _br.ReadSingle();
EnginePerc = _br.ReadSingle();
BatteryPerc = _br.ReadSingle();
CarburetorPerc = _br.ReadSingle();
AltenatorPerc = _br.ReadSingle();
TransmissionPerc = _br.ReadSingle();
FLTirePerc = _br.ReadSingle();
FRTirePerc = _br.ReadSingle();
RLTirePerc = _br.ReadSingle();
RRTirePerc = _br.ReadSingle();
}
public override void write(PooledBinaryWriter stream, StreamModeWrite _eStreamMode)
{
base.write(stream, _eStreamMode);
GameUtils.WriteItemValueArray(stream, itemValues);
stream.Write(Durability);
stream.Write(baseDurability);
stream.Write(maxDurability);
stream.Write(vehicleHealth);
stream.Write(baseVehicleHealth);
stream.Write(GasPerc);
stream.Write(OilPerc);
stream.Write(FLHeadlightPerc);
stream.Write(FRHeadlightPerc);
stream.Write(EnginePerc);
stream.Write(BatteryPerc);
stream.Write(CarburetorPerc);
stream.Write(AltenatorPerc);
stream.Write(TransmissionPerc);
stream.Write(FLTirePerc);
stream.Write(FRTirePerc);
stream.Write(RLTirePerc);
stream.Write(RRTirePerc);
}
public void InitRepairableVehicleParts()
{
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts BEFORE block: " + block.GetBlockName());
block = blockValue.Block as BlockVehicleRebirth;
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts AFTER block: " + block.GetBlockName());
GameRandom rng = new GameRandom();
if (block.Properties.Values.ContainsKey("VehicleType"))
{
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts VehicleType: " + block.Properties.Values["VehicleType"]);
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount));
int health = 0;
if (block.Properties.Values.ContainsKey("vehicle_entity_class"))
{
ItemValue itemVehicle = ItemClass.GetItem(block.Properties.Values["vehicle_entity_class"] + "Placeable", false);
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts A");
if (itemVehicle != null)
{
health = (int)EffectManager.GetValue(PassiveEffects.DegradationMax, itemVehicle, 0f, null, null, (itemVehicle.ItemClass != null) ? itemVehicle.ItemClass.ItemTags : FastTags<TagGroup.Global>.none, true, true, true, true, true, 1, false);
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts health: " + health);
}
}
vehicleHealth = health; // * 0.75f;
baseVehicleHealth = vehicleHealth;
maxDurability = vehicleHealth;
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts maxDurability: " + maxDurability);
baseDurability = rng.RandomRange(Convert.ToSingle(block.Properties.Values["spawn_min_repaired_percent"]) * vehicleHealth, Convert.ToSingle(block.Properties.Values["spawn_max_repaired_percent"]) * vehicleHealth);
Durability = baseDurability;
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts baseDurability: " + baseDurability);
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts spawn_max_repaired_percent: " + block.Properties.Values["spawn_max_repaired_percent"]);
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts baseVehicleHealth: " + baseVehicleHealth);
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts Durability: " + Durability);
List<RepairableVehicleSlotsEnum> itemValueEnums = RebirthVariables.localVehicleTypes[block.Properties.Values["VehicleType"]];
itemValues = new ItemValue[itemValueEnums.Count];
foreach (RepairableVehicleSlotsEnum part in itemValueEnums)
{
ItemValue item = ItemClass.GetItem(RebirthVariables.localVehicleParts[part].itemName);
DictionarySave<string, string> propValues = item.ItemClass.Properties.Values;
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts part: " + part);
//Log.Out("TileEntityDriveableLootContainer-InitRepairableVehicleParts item: " + item.ItemClass.GetItemName());
RepairableVehicleSlotsEnum slot = (RepairableVehicleSlotsEnum)Enum.Parse(typeof(RepairableVehicleSlotsEnum), propValues["VehicleSlot"]);
for (int i = 0; i < itemValueEnums.Count; i++)
{
rng.SetSeed((int)((float)Stopwatch.GetTimestamp() + GameManager.frameCount) + i);
itemValues[i] = ItemValue.None;
}
}
float increase = 0;
foreach (ItemValue item in itemValues)
{
if (item != ItemValue.None)
{
string itemName = item.ItemClass.GetItemName();
foreach (RepairableVehicleSlotsEnum part in itemValueEnums)
{
if (RebirthVariables.localVehicleParts[part].itemName == itemName)
{
increase += ((item.MaxUseTimes - item.UseTimes) / item.MaxUseTimes) * RebirthVariables.localVehicleParts[part].durabilityPerQuality * item.Quality;
//maxDurability += RebirthVariables.localVehicleParts[part].durabilityPerQuality * item.Quality;
/*Log.Out("XUiC_RepairableVehicleWindow-BtnHotwire_OnPress itemName: " + itemName);
Log.Out("XUiC_RepairableVehicleWindow-BtnHotwire_OnPress PercUsed: " + ((item.MaxUseTimes - item.UseTimes) / item.MaxUseTimes));
Log.Out("XUiC_RepairableVehicleWindow-BtnHotwire_OnPress Quality: " + item.Quality);
Log.Out("XUiC_RepairableVehicleWindow-BtnHotwire_OnPress durabilityPerQuality: " + RebirthVariables.localVehicleParts[part].durabilityPerQuality);
Log.Out("XUiC_RepairableVehicleWindow-BtnHotwire_OnPress durability: " + durability);*/
break;
}
}
}
}
vehicleHealth += increase;
setModified();
}
}
public void SetRepairableVehicleParts(ItemValue[] newItemValues)
{
itemValues = newItemValues;
}
public ItemValue[] GetRepairableVehicleParts()
{
return itemValues;
}
public override TileEntityType GetTileEntityType()
{
//return (TileEntityType)243;
return (TileEntityType)RebirthUtilities.TileEntityRebirth.TileEntityDriveableLootContainer;
}
}

View File

@@ -0,0 +1,342 @@
using System.Collections.Generic;
public class EntityVehicleRebirth : EntityVJeep
{
public ItemValue[] itemValues = new ItemValue[] { };
public float OilPerc = 0f;
public float bodyDurability = 0f;
public float baseBodyDurability = 0f;
public float maxBodyDurability = 0f;
public bool autoLoot = false;
public int autoLootTick = 10;
public float autoLootCheck = 0f;
public int vehicleDumpTick = 5;
public float vehicleDumpCheck = 0f;
public float SpeedBoostMultiplier = 1f; // temp - for player buffs that boost the vehicle speed
public override int Health { get; set; } = 1;
public EntityVehicleRebirth() : base()
{
}
public override void Init(int _entityClass)
{
base.Init(_entityClass);
Health = GetMaxHealth();
}
public override void Read(byte _version, BinaryReader _br)
{
base.Read(_version, _br);
Health = _br.ReadInt32();
itemValues = GameUtils.ReadItemValueArray(_br);
//Log.Out("EntityVehicleRebirth-Read itemValues.Length: " + itemValues.Length);
//Log.Out("EntityVehicleRebirth-Read bodyDurability: " + bodyDurability);
//Log.Out("EntityVehicleRebirth-Read baseBodyDurability: " + baseBodyDurability);
//Log.Out("EntityVehicleRebirth-Read maxBodyDurability: " + maxBodyDurability);
OilPerc = _br.ReadSingle();
bodyDurability = _br.ReadSingle();
baseBodyDurability = _br.ReadSingle();
maxBodyDurability = _br.ReadSingle();
autoLoot = _br.ReadBoolean();
if (autoLoot)
{
Buffs.SetCustomVar("$autoLoot", 1f);
}
else
{
Buffs.SetCustomVar("$autoLoot", 0f);
}
}
public override void Write(BinaryWriter _bw, bool _bNetworkWrite)
{
base.Write(_bw, _bNetworkWrite);
_bw.Write(Health);
//Log.Out("EntityVehicleRebirth-Write itemValues.Length: " + itemValues.Length);
//Log.Out("EntityVehicleRebirth-Write bodyDurability: " + bodyDurability);
//Log.Out("EntityVehicleRebirth-Write baseBodyDurability: " + baseBodyDurability);
//Log.Out("EntityVehicleRebirth-Write maxBodyDurability: " + maxBodyDurability);
GameUtils.WriteItemValueArray(_bw, itemValues);
_bw.Write(OilPerc);
_bw.Write(bodyDurability);
_bw.Write(baseBodyDurability);
_bw.Write(maxBodyDurability);
int isAutoLootOn = (int)Buffs.GetCustomVar("$autoLoot");
if (isAutoLootOn == 1)
{
autoLoot = true;
}
else
{
autoLoot = false;
}
_bw.Write(autoLoot);
}
public override void OnAddedToWorld()
{
base.OnAddedToWorld();
//Log.Out($"<color=yellow>EnittyVehicleRebirth entity {EntityName} contains these parts: </color>");
//Log.Out("EntityVehicleRebirth-OnAddedToWorld itemValues.Length: " + itemValues.Length);
if (itemValues.Length == 1 && EntityClass.Properties.Values.ContainsKey("VehicleType"))
{
string vehicleType = EntityClass.Properties.Values["VehicleType"];
//Log.Out("EntityVehicleRebirth-OnAddedToWorld vehicleType: " + vehicleType);
ItemValue[] newItemValues = new ItemValue[] { ItemValue.None };
List<RepairableVehicleSlotsEnum> itemValueEnums = RebirthVariables.localVehicleTypes[vehicleType];
itemValues = new ItemValue[itemValueEnums.Count];
foreach (string vehicleTypeKey in RebirthVariables.localVehicleTypes.Keys)
{
if (vehicleTypeKey == vehicleType)
{
List<RepairableVehicleSlotsEnum> partsList = RebirthVariables.localVehicleTypes[vehicleTypeKey];
//Log.Out("EntityVehicleRebirth-OnAddedToWorld partsList: " + partsList.Count);
for (int i = 0; i < partsList.Count; i++)
{
//Log.Out("EntityVehicleRebirth-OnAddedToWorld part: " + RebirthVariables.localVehicleParts[partsList[i]].itemName);
itemValues[i] = ItemValue.None; // ItemClass.GetItem(RebirthVariables.localVehicleParts[partsList[i]].itemName);
}
break;
}
}
//Log.Out("EntityVehicleRebirth-OnAddedToWorld itemValues.Length: " + itemValues.Length);
}
/*foreach(ItemValue item in itemValues)
{
Log.Out($"<color=magenta>Item: {item.ItemClass.GetLocalizedItemName()}</color>\t<color=cyan>Quality: {item.Quality}</color>\t<color=yellow>Degradation: {item.MaxUseTimes - item.UseTimes}</color>");
}*/
}
public override void UpdateWheelsSteering()
{
if (wheels.Length > 2)
{
wheels[0].wheelC.steerAngle = wheelDir;
wheels[1].wheelC.steerAngle = wheelDir;
}
else
{
wheels[0].wheelC.steerAngle = wheelDir;
for (int i = 1; i < wheels.Length; i++)
{
wheels[i].wheelC.steerAngle = 0f;
}
}
}
private void takeFromEntityContainer(EntityAlive entity, string itemGroupOrName, FastTags<TagGroup.Global> fastTags)
{
ItemStack[] array = entity.bag.GetSlots();
if (entity.lootContainer != null)
{
array = entity.lootContainer.GetItems();
}
for (int i = 0; i < array.Length; i++)
{
if (array[i] != null && array[i].itemValue != null && array[i].itemValue.ItemClass != null && array[i].itemValue.ItemClass.HasAnyTags(fastTags) && array[i].count > 0 && array[i].itemValue.ItemClass.Name.ContainsCaseInsensitive(itemGroupOrName))
{
array[i].count--;
if (array[i].count == 0)
{
array[i] = ItemStack.Empty.Clone();
}
entity.bag.SetSlots(array);
entity.bag.OnUpdate();
if (entity.lootContainer != null)
{
entity.lootContainer.UpdateSlot(i, array[i]);
}
}
}
}
public override void Update()
{
//Log.Out("EntityBicycleRebirth-Update START");
base.Update();
/*if (vehicle.entity.EntityClass.entityClassName.ContainsCaseInsensitive("Bicycle"))
{
//Log.Out("EntityBicycleRebirth-Update this.HasDriver: " + this.HasDriver);
if (HasDriver && AttachedMainEntity != null)
{
//Log.Out("EntityBicycleRebirth-Update AttachedMainEntity: " + this.AttachedMainEntity.EntityClass.entityClassName);
EntityAlive driver = (EntityAlive)AttachedMainEntity;
if(driver.Buffs.HasBuff("FuriousRamsayMobilityBoostRedTea"))
{
// todo fix - temp - this needs a better implementation
SpeedBoostMultiplier = 1.5f; // red tea boosts speed by 1.5 or ?
vehicle.VelocityMaxTurboForward *= SpeedBoostMultiplier;
//Buffs.AddBuff("FuriousRamsayVehicleBoost"); // do we need a buff on the vehicle itself?
}
}
else
{
SpeedBoostMultiplier = 1f;
vehicle.VelocityMaxForward *= SpeedBoostMultiplier;
//Buffs.AddBuff("FuriousRamsayVehicleBoost");
}
}*/
if (!HasDriver && SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
{
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated autoLoot: " + autoLoot);
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated autoLootTick: " + autoLootTick);
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated autoLootTick: " + autoLootCheck);
if ((Time.time - autoLootCheck) > autoLootTick)
{
System.Random random = new System.Random();
autoLootTick = random.Next(5, 9);
autoLootCheck = Time.time;
float isAutoLootOn = Buffs.GetCustomVar("$autoLoot");
if (isAutoLootOn == 1)
{
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated this.bag.GetUsedSlotCount(): " + this.bag.GetUsedSlotCount());
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated autoLootTick: " + autoLootTick);
PersistentPlayerData playerData = world.GetGameManager().GetPersistentPlayerList().GetPlayerData(this.GetOwner());
EntityPlayer entityPlayer = (EntityPlayer)world.GetEntity(playerData.EntityId);
if (entityPlayer != null)
{
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated Found Owner");
int minMax = 80;
World _world = GameManager.Instance.World;
List<Entity> entitiesInBounds = _world.GetEntitiesInBounds(typeof(EntityLootContainer), BoundsUtils.BoundsForMinMax(position.x - minMax, position.y - 30, position.z - minMax, position.x + minMax, position.y + 30, position.z + minMax), new List<Entity>());
if (entitiesInBounds != null && entitiesInBounds.Count > 0)
{
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated entitiesInBounds.Count > 0");
for (int i = 0; i < entitiesInBounds.Count; i++)
{
//Log.Out("EntityBicycleRebirth-Update entitiesInBounds[i].EntityClass.entityClassName: " + entitiesInBounds[i].EntityClass.entityClassName);
//Log.Out("EntityBicycleRebirth-Update entitiesInBounds[i].lootContainer.items.Length: " + entitiesInBounds[i].lootContainer.items.Length);
//Log.Out("EntityBicycleRebirth-Update entitiesInBounds[i].lootContainer.lootListName: " + entitiesInBounds[i].lootContainer.lootListName);
if (entitiesInBounds[i].lootContainer != null && entitiesInBounds[i].EntityClass.entityClassName != "BackpackNPC")
{
bool isUserAccessing = entitiesInBounds[i].lootContainer.IsUserAccessing();
//Log.Out("EntityBicycleRebirth-Update isUserAccessing: " + isUserAccessing);
if (!isUserAccessing)
{
entitiesInBounds[i].lootContainer.SetUserAccessing(true);
float containerMod = 0f;
float containerBonus = 0f;
float lootStage = (float)entityPlayer.GetHighestPartyLootStage(containerMod, containerBonus);
GameManager.Instance.lootManager.LootContainerOpened(entitiesInBounds[i].lootContainer, entityPlayer.entityId, entitiesInBounds[i].EntityTags);
bool addItems = false;
bool addedAllItems = true;
//Log.Out("EntityBicycleRebirth-Update entitiesInBounds[i].lootContainer.EntityId: " + entitiesInBounds[i].lootContainer.EntityId);
//Log.Out("EntityBicycleRebirth-Update lootStage: " + lootStage);
//Log.Out("EntityBicycleRebirth-Update EntityTags: " + entitiesInBounds[i].EntityTags);
foreach (ItemStack itemStack in entitiesInBounds[i].lootContainer.GetItems())
{
if (!itemStack.IsEmpty())
{
//Log.Out("EntityBicycleRebirth-Update Item Name: " + itemStack.itemValue.ItemClass.GetItemName());
//Log.Out("EntityBicycleRebirth-Update Item Count: " + itemStack.count);
if (bag.HasItem(itemStack.itemValue))
{
ValueTuple<bool, bool> tryStack = bag.TryStackItem(0, itemStack);
//Log.Out("EntityBicycleRebirth-Update tryStack: " + tryStack);
if (!tryStack.Item1)
{
bool tryAdd = bag.AddItem(itemStack);
//Log.Out("EntityBicycleRebirth-Update tryAdd: " + tryAdd);
if (tryAdd)
{
addItems = true;
entitiesInBounds[i].lootContainer.RemoveItem(itemStack.itemValue);
}
else
{
addedAllItems = false;
}
}
else
{
addItems = true;
}
}
else
{
bool tryAdd = bag.AddItem(itemStack);
//Log.Out("EntityBicycleRebirth-Update 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("EntityBicycleRebirth-Update REMOVED BAG: " + entitiesInBounds[i].EntityClass.entityClassName);
entitiesInBounds[i].DamageEntity(new DamageSource(EnumDamageSource.Internal, EnumDamageTypes.Suicide), 99999, false, 1f);
}
else
{
//Log.Out("EntityBicycleRebirth-Update isLootGatheringActivated this.bag.GetUsedSlotCount(): " + this.bag.GetUsedSlotCount());
//Log.Out("EntityBicycleRebirth-Update autoLootTick = 15");
autoLootTick = 15;
}
}
}
}
}
}
}
}
}
}
}