343 lines
16 KiB
C#
343 lines
16 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|