723 lines
32 KiB
C#
723 lines
32 KiB
C#
using Audio;
|
|
using System.Collections.Generic;
|
|
using Twitch;
|
|
using static RebirthManager;
|
|
using static SharedChunkObserverCache.SharedChunkObserver;
|
|
|
|
namespace Harmony.GameManagerPatches
|
|
{
|
|
/*[HarmonyPatch(typeof(ApplyExplosionForce))]
|
|
[HarmonyPatch("Explode")]
|
|
public class ExplodePatch
|
|
{
|
|
private static bool Prefix(ApplyExplosionForce __instance, Vector3 explosionPos, float power, float radius)
|
|
{
|
|
//Log.Out("GameManagerPatches-Explode explosionPos: " + explosionPos);
|
|
explosionPos -= Origin.position;
|
|
power *= 20f;
|
|
radius *= 1.75f;
|
|
int num = Physics.OverlapSphereNonAlloc(explosionPos, radius, ApplyExplosionForce.colliderList);
|
|
if (num > 1024)
|
|
num = 1024;
|
|
for (int index = 0; index < num; ++index)
|
|
{
|
|
Rigidbody component = ApplyExplosionForce.colliderList[index].GetComponent<Rigidbody>();
|
|
if ((bool)(UnityEngine.Object)component)
|
|
component.AddExplosionForce(power, explosionPos, radius, 3f);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}*/
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("ExplosionClient")]
|
|
public class ExplosionClientPatch
|
|
{
|
|
private static bool Prefix(GameManager __instance, ref GameObject __result, int _clrIdx,
|
|
Vector3 _center,
|
|
Quaternion _rotation,
|
|
int _index,
|
|
int _blastPower,
|
|
float _blastRadius,
|
|
float _blockDamage,
|
|
int _entityId,
|
|
List<BlockChangeInfo> _explosionChanges)
|
|
{
|
|
//Log.Out("GameManagerPatches-ExplosionClient START");
|
|
if (__instance.m_World == null)
|
|
{
|
|
//Log.Out("GameManagerPatches-ExplosionClient 1");
|
|
__result = (GameObject)null;
|
|
return false;
|
|
}
|
|
GameObject gameObject = (GameObject)null;
|
|
if (_index > 0 && _index < WorldStaticData.prefabExplosions.Length && (UnityEngine.Object)WorldStaticData.prefabExplosions[_index] != (UnityEngine.Object)null)
|
|
{
|
|
//Log.Out("GameManagerPatches-ExplosionClient 2");
|
|
gameObject = UnityEngine.Object.Instantiate<GameObject>(WorldStaticData.prefabExplosions[_index].gameObject, _center - Origin.position, _rotation);
|
|
ApplyExplosionForce.Explode(_center, (float)_blastPower, _blastRadius);
|
|
}
|
|
if (_index == 0 && _blastPower == 201)
|
|
{
|
|
//Log.Out("GameManagerPatches-ExplosionClient 3");
|
|
ApplyExplosionForce.Explode(_center, (float)_blastPower, _blastRadius);
|
|
}
|
|
if (_explosionChanges.Count > 0)
|
|
{
|
|
//Log.Out("GameManagerPatches-ExplosionClient 4");
|
|
__instance.ChangeBlocks((PlatformUserIdentifierAbs)null, _explosionChanges);
|
|
}
|
|
QuestEventManager.Current.DetectedExplosion(_center, _entityId, _blockDamage);
|
|
__result = gameObject;
|
|
//Log.Out("GameManagerPatches-ExplosionClient END");
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("SharedKillClient")]
|
|
public class SharedKillClientPatch
|
|
{
|
|
private static bool Prefix(GameManager __instance, int _entityTypeID, int _xp, EntityPlayerLocal _player = null, int _entityID = -1)
|
|
{
|
|
if ((UnityEngine.Object)_player == (UnityEngine.Object)null)
|
|
_player = __instance.myEntityPlayerLocal;
|
|
if ((UnityEngine.Object)_player == (UnityEngine.Object)null)
|
|
return false;
|
|
string entityClassName = EntityClass.list[_entityTypeID].entityClassName;
|
|
|
|
float partyMultiplierOption = float.Parse(RebirthVariables.customPartyXPMultiplier) / 100;
|
|
|
|
//Log.Out("GameManagerPatches-SharedKillClient 1, _xp: " + _xp);
|
|
//Log.Out("GameManagerPatches-SharedKillClient 1, partyMultiplierOption: " + partyMultiplierOption);
|
|
_xp = (int)(_xp * partyMultiplierOption);
|
|
|
|
if (RebirthUtilities.IsHordeNight())
|
|
{
|
|
//Log.Out("GameManagerPatches-SharedKillClient IS HORDE NIGHT, BEFORE: " + _xp);
|
|
_xp = (int)(_xp * RebirthVariables.hordeNightXPMultiplier);
|
|
}
|
|
|
|
//Log.Out("GameManagerPatches-SharedKillClient XP AFTER: " + _xp);
|
|
|
|
_xp = _player.Progression.AddLevelExp(_xp, "_xpFromParty", Progression.XPTypes.Kill);
|
|
//Log.Out("GameManagerPatches-SharedKillClient AddLevelExp, _xp: " + _xp);
|
|
|
|
_player.bPlayerStatsChanged = true;
|
|
if (_xp > 0)
|
|
GameManager.ShowTooltip(_player, string.Format(Localization.Get("ttPartySharedXPReceived"), (object)_xp));
|
|
QuestEventManager.Current.EntityKilled((EntityAlive)_player, _entityID == -1 ? (EntityAlive)null : __instance.m_World.GetEntity(_entityID) as EntityAlive);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("PlayerSpawnedInWorld")]
|
|
public class PlayerSpawnedInWorldPatch
|
|
{
|
|
private static void Postfix(GameManager __instance, ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _pos, int _entityId)
|
|
{
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld START, _respawnReason: " + _respawnReason);
|
|
|
|
RebirthUtilities.LoadRebirthXMLOptions();
|
|
|
|
Entity entity;
|
|
if (_entityId == -1 || !__instance.m_World.Entities.dict.TryGetValue(_entityId, out entity))
|
|
{
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld 0, _entityId: " + _entityId);
|
|
return;
|
|
}
|
|
|
|
bool isPlayer = entity is EntityPlayer;
|
|
bool isLoadedGame = _respawnReason == RespawnType.LoadedGame || (_respawnReason == RespawnType.JoinMultiplayer && SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer);
|
|
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld isPlayer: " + isPlayer);
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld isLoadedGame: " + isLoadedGame);
|
|
|
|
if (isPlayer && isLoadedGame)
|
|
{
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld 1");
|
|
EntityPlayer player = (EntityPlayer)entity;
|
|
player.Buffs.AddBuff("FuriousRamsaySpawningDelay");
|
|
|
|
SpawnPosition spawnPoint = RebirthUtilities.GetSpawnPoint(player);
|
|
|
|
if (!spawnPoint.IsUndef())
|
|
{
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld ADD CHUNK OBSERVER");
|
|
RebirthVariables.chunkObserver = GameManager.Instance.AddChunkObserver(spawnPoint.position, false, 3, -1);
|
|
}
|
|
|
|
foreach (hireInfo hire in playerHires)
|
|
{
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld 2");
|
|
if (hire.playerID == player.entityId)
|
|
{
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld hire.name: " + hire.name);
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld hire.order: " + hire.order);
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld hire.spawnPosition: " + hire.spawnPosition);
|
|
if (hire.order == 1)
|
|
{
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld 3");
|
|
bool foundObserver = false;
|
|
|
|
foreach (chunkObservers observer in observers)
|
|
{
|
|
if (observer.entityID == hire.hireID)
|
|
{
|
|
foundObserver = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//Log.Out("GameManagerPatches-PlayerSpawnedInWorld foundObserver: " + foundObserver);
|
|
|
|
if (!foundObserver)
|
|
{
|
|
float height1 = GameManager.Instance.World.GetTerrainHeight((int)hire.spawnPosition.x, (int)hire.spawnPosition.z);
|
|
float height2 = GameManager.Instance.World.GetHeight((int)hire.spawnPosition.x, (int)hire.spawnPosition.z);
|
|
|
|
float height = ((height1 + height2) / 2f) + 1.5f;
|
|
|
|
ChunkManager.ChunkObserver observerRef = GameManager.Instance.AddChunkObserver(new Vector3(hire.spawnPosition.x, height, hire.spawnPosition.z), false, 3, -1);
|
|
observers.Add(new chunkObservers(hire.hireID, observerRef));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("ItemDropServer")]
|
|
[HarmonyPatch(new[] { typeof(ItemStack), typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(int), typeof(float), typeof(bool), typeof(int) })]
|
|
public class ItemDropServerPatch
|
|
{
|
|
public static bool Prefix(GameManager __instance, ItemStack _itemStack, Vector3 _dropPos, Vector3 _randomPosAdd, Vector3 _initialMotion, int _entityId, float _lifetime, bool _bDropPosIsRelativeToHead, int _clientEntityId)
|
|
{
|
|
//Log.Out("GameManagerPatches-ItemDropServer _itemStack.itemValue.ItemClass.Name: " + _itemStack.itemValue.ItemClass.Name);
|
|
|
|
Log.Out("StackTrace: '{0}'", Environment.StackTrace);
|
|
|
|
if (__instance.m_World == null)
|
|
return false;
|
|
bool flag = SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer;
|
|
Entity entity1 = __instance.m_World.GetEntity(_entityId);
|
|
if (_clientEntityId != 0)
|
|
{
|
|
if (!(bool)(UnityEngine.Object)entity1)
|
|
return false;
|
|
flag = !entity1.isEntityRemote;
|
|
}
|
|
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
if (_clientEntityId == -1)
|
|
_clientEntityId = --__instance.m_World.clientLastEntityId;
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer((NetPackage)NetPackageManager.GetPackage<NetPackageItemDrop>().Setup(_itemStack, _dropPos, _initialMotion, _randomPosAdd, _lifetime, _entityId, _bDropPosIsRelativeToHead, _clientEntityId));
|
|
if (!flag)
|
|
return false;
|
|
}
|
|
if (_bDropPosIsRelativeToHead)
|
|
{
|
|
if ((UnityEngine.Object)entity1 == (UnityEngine.Object)null)
|
|
return false;
|
|
_dropPos += entity1.getHeadPosition();
|
|
}
|
|
if (!_randomPosAdd.Equals(Vector3.zero))
|
|
_dropPos += new Vector3(__instance.m_World.RandomRange(-_randomPosAdd.x, _randomPosAdd.x), __instance.m_World.RandomRange(-_randomPosAdd.y, _randomPosAdd.y), __instance.m_World.RandomRange(-_randomPosAdd.z, _randomPosAdd.z));
|
|
EntityCreationData _ecd = new EntityCreationData();
|
|
_ecd.entityClass = EntityClass.FromString("item");
|
|
_ecd.id = SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer || _clientEntityId >= -1 ? EntityFactory.nextEntityID++ : _clientEntityId;
|
|
_ecd.itemStack = _itemStack.Clone();
|
|
_ecd.pos = _dropPos;
|
|
_ecd.rot = new Vector3(20f, 0.0f, 20f);
|
|
_ecd.lifetime = _lifetime;
|
|
_ecd.belongsPlayerId = _entityId;
|
|
if (_clientEntityId != -1)
|
|
_ecd.clientEntityId = _clientEntityId;
|
|
EntityItem entity2 = (EntityItem)EntityFactory.CreateEntity(_ecd);
|
|
|
|
entity2.isPhysicsMaster = flag;
|
|
if ((double)_initialMotion.sqrMagnitude > 0.0099999997764825821)
|
|
entity2.AddVelocity(_initialMotion);
|
|
__instance.m_World.SpawnEntityInWorld((Entity)entity2);
|
|
Chunk chunkSync = (Chunk)__instance.m_World.GetChunkSync(World.toChunkXZ((int)_dropPos.x), World.toChunkXZ((int)_dropPos.z));
|
|
if (chunkSync == null)
|
|
return false;
|
|
List<EntityItem> entityItemList = new List<EntityItem>();
|
|
for (int index1 = 0; index1 < chunkSync.entityLists.Length; ++index1)
|
|
{
|
|
if (chunkSync.entityLists[index1] != null)
|
|
{
|
|
for (int index2 = 0; index2 < chunkSync.entityLists[index1].Count; ++index2)
|
|
{
|
|
if (chunkSync.entityLists[index1][index2] is EntityItem)
|
|
entityItemList.Add(chunkSync.entityLists[index1][index2] as EntityItem);
|
|
}
|
|
}
|
|
}
|
|
int num = entityItemList.Count - 50;
|
|
if (num <= 0)
|
|
return false;
|
|
entityItemList.Sort((IComparer<EntityItem>)new GameManager.EntityItemLifetimeComparer());
|
|
for (int index = entityItemList.Count - 1; index >= 0 && num > 0; --index)
|
|
{
|
|
entityItemList[index].MarkToUnload();
|
|
--num;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}*/
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("DestroyLootOnClose")]
|
|
public class DestroyLootOnClosePatch
|
|
{
|
|
private static bool Prefix(GameManager __instance, TileEntity _te, Vector3i _blockPos, int _lootEntityId)
|
|
{
|
|
//Log.Out("GameManagerPatches-DestroyLootOnClose START, _te: " + _te);
|
|
if (_te is TileEntitySecureLootContainer)
|
|
{
|
|
//Log.Out("GameManagerPatches-DestroyLootOnClose IS SECURE LOOT");
|
|
|
|
TileEntitySecureLootContainer tileEntity = (TileEntitySecureLootContainer)_te;
|
|
|
|
//Log.Out("GameManagerPatches-DestroyLootOnClose tileEntity.bPlayerStorage: " + tileEntity.bPlayerStorage);
|
|
|
|
if (tileEntity.bPlayerStorage)
|
|
{
|
|
//Log.Out("GameManagerPatches-DestroyLootOnClose PLAYER PLACED");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("Disconnect")]
|
|
public class DisconnectPatch
|
|
{
|
|
private static bool Prefix(GameManager __instance)
|
|
{
|
|
//Log.Out("GameManagerPatches-Disconnect START");
|
|
|
|
if (!GameManager.IsDedicatedServer)
|
|
{
|
|
RebirthVariables.musicMode = -1;
|
|
RebirthVariables.purgePrefabsLoaded = false;
|
|
|
|
float volume = Mathf.Clamp01(GamePrefs.GetFloat(EnumGamePrefs.OptionsMenuMusicVolumeLevel));
|
|
|
|
//Log.Out("GameManagerPatches-Disconnect volume: " + volume);
|
|
|
|
if (volume > 0f)
|
|
{
|
|
//Log.Out("GameManagerPatches-Disconnect RebirthVariables.musicMode: " + RebirthVariables.musicMode);
|
|
RebirthVariables.audioSource.Stop();
|
|
RebirthVariables.audioSource.volume = volume;
|
|
RebirthVariables.musicMode = -1;
|
|
/*Log.Out("GameManagerPatches-Disconnect MenuMusic.musicLeft.Count: " + MenuMusic.musicLeft.Count);
|
|
|
|
if (MenuMusic.musicLeft.Count > 0)
|
|
{
|
|
int num = UnityEngine.Random.Range(0, MenuMusic.musicLeft.Count - 1);
|
|
|
|
Log.Out("GameManagerPatches-Disconnect BEFORE RebirthVariables.songIndex: " + RebirthVariables.songIndex);
|
|
|
|
Log.Out("GameManagerPatches-Disconnect num: " + num);
|
|
|
|
RebirthVariables.songIndex = MenuMusic.musicLeft[num];
|
|
|
|
Log.Out("GameManagerPatches-Disconnect AFTER RebirthVariables.songIndex: " + RebirthVariables.songIndex);
|
|
|
|
MenuMusic.musicLeft.Remove(RebirthVariables.songIndex);
|
|
|
|
if (RebirthVariables.audioClip[RebirthVariables.songIndex - 1] != null)
|
|
{
|
|
Log.Out("GameManagerPatches-Disconnect NEW CLIP");
|
|
RebirthVariables.audioSource.clip = RebirthVariables.audioClip[RebirthVariables.songIndex - 1];
|
|
}
|
|
}
|
|
|
|
RebirthVariables.audioSource.loop = false;
|
|
RebirthVariables.secondsToFadeIn = 1f;
|
|
RebirthVariables.secondsToFadeOut = 10f;
|
|
RebirthVariables.controlOption = MusicControlOption.FadeIn;
|
|
RebirthVariables.audioSource.Play();*/
|
|
}
|
|
|
|
EntityPlayerLocal ___entityPlayerLocal = GameManager.Instance.World.GetPrimaryPlayer();
|
|
|
|
GameManager.Instance.StartCoroutine(RebirthVariables.UpdateLocalVariables(___entityPlayerLocal, 1));
|
|
|
|
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
foreach (hireInfo hire in playerHires)
|
|
{
|
|
if (hire.playerID == ___entityPlayerLocal.entityId)
|
|
{
|
|
hire.playerSpawned = false;
|
|
//Log.Out("GameManagerPatches-Disconnect hire.playerSpawned: " + hire.playerSpawned);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("DropContentOfLootContainerServer")]
|
|
[HarmonyPatch(new Type[] { typeof(BlockValue), typeof(Vector3i), typeof(int), typeof(ITileEntityLootable) })]
|
|
public class DropContentOfLootContainerServerPatch
|
|
{
|
|
private static bool Prefix(GameManager __instance, BlockValue _bvOld, Vector3i _worldPos, int _lootEntityId, ITileEntityLootable _teOld = null)
|
|
{
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer START");
|
|
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
//Log.Warning("DropContentOfLootContainerServer can not be called on clients! From:\n" + StackTraceUtility.ExtractStackTrace());
|
|
}
|
|
else
|
|
{
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer 1");
|
|
string str = "DroppedLootContainer";
|
|
FastTags<TagGroup.Global> none = FastTags<TagGroup.Global>.none;
|
|
ITileEntityLootable tileEntityLootable;
|
|
Vector3 vector3;
|
|
if (_lootEntityId == -1)
|
|
{
|
|
tileEntityLootable = _teOld ?? __instance.m_World.GetTileEntity(_worldPos).GetSelfOrFeature<ITileEntityLootable>();
|
|
if (tileEntityLootable == null || __instance.lockedTileEntities.ContainsKey((ITileEntity)tileEntityLootable))
|
|
return false;
|
|
vector3 = tileEntityLootable.ToWorldPos().ToVector3() + new Vector3(0.5f, 0.75f, 0.5f);
|
|
if (_bvOld.Block.Properties.Values.ContainsKey("DroppedEntityClass"))
|
|
{
|
|
FastTags<TagGroup.Global> tags = _bvOld.Block.Tags;
|
|
str = _bvOld.Block.Properties.Values["DroppedEntityClass"];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer 2");
|
|
Entity entity1 = __instance.m_World.GetEntity(_lootEntityId);
|
|
if (!(bool)entity1)
|
|
return false;
|
|
FastTags<TagGroup.Global> entityTags = entity1.EntityTags;
|
|
vector3 = entity1.GetPosition();
|
|
vector3.y += 0.9f;
|
|
if ((double)entity1.lootDropProb != 0.0)
|
|
{
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer 3");
|
|
int lootDropClass = EntityClass.list[entity1.entityClass].lootDropEntityClass;
|
|
|
|
if (entity1 is EntityZombieSDX)
|
|
{
|
|
EntityZombieSDX entityClone = (EntityZombieSDX)entity1;
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer entityClone.lootDropEntityClass: " + entityClone.lootDropEntityClass);
|
|
if (entityClone.lootDropEntityClass != "")
|
|
{
|
|
lootDropClass = EntityClass.FromString(entityClone.lootDropEntityClass);
|
|
}
|
|
}
|
|
else if (entity1 is EntityNPCRebirth)
|
|
{
|
|
EntityNPCRebirth npc = (EntityNPCRebirth)entity1;
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer npc.lootDropEntityClass: " + npc.lootDropEntityClass);
|
|
|
|
if (npc.lootDropEntityClass != "")
|
|
{
|
|
lootDropClass = EntityClass.FromString(npc.lootDropEntityClass);
|
|
}
|
|
}
|
|
|
|
//Log.Out("Gamemanagerpatches-DropContentOfLootContainerServer entity1: " + entity1.EntityClass.entityClassName);
|
|
//Log.Out("Gamemanagerpatches-DropContentOfLootContainerServer lootDropClass: " + lootDropClass);
|
|
EntityLootContainer entity2 = EntityFactory.CreateEntity(lootDropClass, vector3, Vector3.zero) as EntityLootContainer;
|
|
__instance.m_World.SpawnEntityInWorld((Entity)entity2);
|
|
entity2.transform.localScale = new Vector3(1.25f, 1.25f, 1.25f);
|
|
Manager.BroadcastPlay(vector3, "zpack_spawn");
|
|
return false;
|
|
|
|
}
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer 4");
|
|
tileEntityLootable = __instance.m_World.GetTileEntity(_lootEntityId).GetSelfOrFeature<ITileEntityLootable>();
|
|
if (tileEntityLootable == null)
|
|
return false;
|
|
}
|
|
if (!tileEntityLootable.bTouched)
|
|
__instance.lootManager.LootContainerOpened(tileEntityLootable, -1, _bvOld.Block.Tags);
|
|
if (!tileEntityLootable.IsEmpty())
|
|
{
|
|
Entity entity1 = __instance.m_World.GetEntity(_lootEntityId);
|
|
if (!(bool)entity1)
|
|
return false;
|
|
|
|
if (entity1 is EntityNPCRebirth)
|
|
{
|
|
str = "BackpackNPC";
|
|
}
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer 5, str: " + str);
|
|
|
|
EntityLootContainer entity = EntityFactory.CreateEntity(str.GetHashCode(), vector3, Vector3.zero) as EntityLootContainer;
|
|
if (entity != null)
|
|
{
|
|
//Log.Warning("GameManagerPatches-DropContentOfLootContainerServer 5, str: " + str);
|
|
entity.SetContent(ItemStack.Clone((IList<ItemStack>)tileEntityLootable.items));
|
|
}
|
|
__instance.m_World.SpawnEntityInWorld((Entity)entity);
|
|
}
|
|
tileEntityLootable.SetEmpty();
|
|
}
|
|
|
|
return false;
|
|
|
|
/*
|
|
|
|
todo fix Needs updating to 1.0 code
|
|
|
|
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageLootContainerDropContent>().Setup(_worldPos, _entityId), false);
|
|
return false;
|
|
}
|
|
|
|
string text = "DroppedLootContainer";
|
|
FastTags<TagGroup.Global> none = FastTags<TagGroup.Global>.none;
|
|
TileEntityLootContainer tileEntityLootContainer;
|
|
Vector3 vector;
|
|
|
|
if (_entityId == -1)
|
|
{
|
|
tileEntityLootContainer = (TileEntityLootContainer)__instance.m_World.GetTileEntity(0, _worldPos);
|
|
if (tileEntityLootContainer == null || __instance.lockedTileEntities.ContainsKey(tileEntityLootContainer))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
vector = tileEntityLootContainer.ToWorldPos().ToVector3() + new Vector3(0.5f, 0.75f, 0.5f);
|
|
|
|
if (_bvOld.Block.Properties.Values.ContainsKey("DroppedEntityClass"))
|
|
{
|
|
FastTags<TagGroup.Global> tags = _bvOld.Block.Tags;
|
|
text = _bvOld.Block.Properties.Values["DroppedEntityClass"];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Entity entity = __instance.m_World.GetEntity(_entityId);
|
|
|
|
if (entity == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
FastTags<TagGroup.Global> entityTags = entity.EntityTags;
|
|
vector = entity.GetPosition();
|
|
vector.y += 0.9f;
|
|
|
|
if (entity.lootDropProb != 0f)
|
|
{
|
|
int lootDropClass = EntityClass.list[entity.entityClass].lootDropEntityClass;
|
|
//Log.Out("GameManagerPatches-DropContentOfLootContainerServer BEFORE lootDropClass: " + lootDropClass);
|
|
|
|
if (entity is EntityZombieSDX)
|
|
{
|
|
EntityZombieSDX entityClone = (EntityZombieSDX)entity;
|
|
if (entityClone.lootDropEntityClass.Trim().Length > 0)
|
|
{
|
|
lootDropClass = EntityClass.FromString(entityClone.lootDropEntityClass);
|
|
}
|
|
}
|
|
else if (entity is EntityMeleeBanditSDX)
|
|
{
|
|
EntityMeleeBanditSDX entityClone = (EntityMeleeBanditSDX)entity;
|
|
|
|
if (entityClone.lootDropEntityClass.Trim().Length > 0)
|
|
{
|
|
lootDropClass = EntityClass.FromString(entityClone.lootDropEntityClass);
|
|
}
|
|
}
|
|
else if (entity is EntityMeleeCyborgRebirth)
|
|
{
|
|
EntityMeleeCyborgRebirth entityClone = (EntityMeleeCyborgRebirth)entity;
|
|
|
|
if (entityClone.lootDropEntityClass.Trim().Length > 0)
|
|
{
|
|
lootDropClass = EntityClass.FromString(entityClone.lootDropEntityClass);
|
|
}
|
|
}
|
|
else if (entity is EntityMeleeRangedBanditSDX)
|
|
{
|
|
EntityMeleeRangedBanditSDX entityClone = (EntityMeleeRangedBanditSDX)entity;
|
|
|
|
if (entityClone.lootDropEntityClass.Trim().Length > 0)
|
|
{
|
|
lootDropClass = EntityClass.FromString(entityClone.lootDropEntityClass);
|
|
}
|
|
}
|
|
else if (entity is EntityMeleeWerewolfSDX)
|
|
{
|
|
EntityMeleeWerewolfSDX entityClone = (EntityMeleeWerewolfSDX)entity;
|
|
|
|
if (entityClone.lootDropEntityClass.Trim().Length > 0)
|
|
{
|
|
lootDropClass = EntityClass.FromString(entityClone.lootDropEntityClass);
|
|
}
|
|
}
|
|
|
|
//Log.Out("GameManagerPatches-DropContentOfLootContainerServer AFTER lootDropClass: " + lootDropClass);
|
|
|
|
EntityLootContainer entityLootContainer = EntityFactory.CreateEntity(lootDropClass, vector, Vector3.zero) as EntityLootContainer;
|
|
__instance.m_World.SpawnEntityInWorld(entityLootContainer);
|
|
entityLootContainer.transform.localScale = new Vector3(1.25f, 1.25f, 1.25f);
|
|
Manager.BroadcastPlay(vector, "zpack_spawn", 0f);
|
|
return false;
|
|
}
|
|
|
|
tileEntityLootContainer = (TileEntityLootContainer)__instance.m_World.GetTileEntity(_entityId);
|
|
|
|
if (tileEntityLootContainer == null)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (!tileEntityLootContainer.bTouched)
|
|
{
|
|
__instance.lootManager.LootContainerOpened(tileEntityLootContainer, -1, _bvOld.Block.Tags);
|
|
}
|
|
|
|
bool flag = true;
|
|
int num = 0;
|
|
|
|
while (flag && num < tileEntityLootContainer.items.Length)
|
|
{
|
|
flag &= tileEntityLootContainer.items[num].IsEmpty();
|
|
num++;
|
|
}
|
|
|
|
if (!flag)
|
|
{
|
|
EntityLootContainer entityLootContainer2 = EntityFactory.CreateEntity(text.GetHashCode(), vector, Vector3.zero) as EntityLootContainer;
|
|
|
|
if (entityLootContainer2 != null)
|
|
{
|
|
entityLootContainer2.SetContent(ItemStack.Clone(tileEntityLootContainer.items));
|
|
}
|
|
|
|
__instance.m_World.SpawnEntityInWorld(entityLootContainer2);
|
|
}
|
|
|
|
tileEntityLootContainer.SetEmpty();
|
|
|
|
return false;*/
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("gmUpdate")]
|
|
public class gmUpdatePatch
|
|
{
|
|
private static bool Prefix(GameManager __instance, ref float ___gcCountdownTimer)
|
|
{
|
|
___gcCountdownTimer = 120f;
|
|
|
|
if (GameManager.IsDedicatedServer)
|
|
{
|
|
Application.targetFrameRate = 20;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void Postfix(GameManager __instance, ref float ___unloadAssetsDuration, ref bool ___isUnloadAssetsReady)
|
|
{
|
|
___unloadAssetsDuration = 0f;
|
|
___isUnloadAssetsReady = false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("isAnyModalWindowOpen")]
|
|
public class isAnyModalWindowOpen
|
|
{
|
|
private static bool Prefix(ref bool __result)
|
|
{
|
|
__result = false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(GameManager))]
|
|
[HarmonyPatch("lootContainerOpened")]
|
|
public class lootContainerOpened
|
|
{
|
|
private static bool Prefix(GameManager __instance, TileEntityLootContainer _te, LocalPlayerUI _playerUI, int _entityIdThatOpenedIt)
|
|
{
|
|
ITileEntityLootable selfOrFeature = _te.GetSelfOrFeature<ITileEntityLootable>();
|
|
if (selfOrFeature == null)
|
|
{
|
|
Log.Error(string.Format("Can not open container UI for TE {0}", (object)_te));
|
|
}
|
|
else
|
|
{
|
|
FastTags<TagGroup.Global> _containerTags = FastTags<TagGroup.Global>.none;
|
|
if (_playerUI != null)
|
|
{
|
|
bool flag = true;
|
|
string _lootContainerName = string.Empty;
|
|
if (selfOrFeature.EntityId != -1)
|
|
{
|
|
Entity entity = __instance.m_World.GetEntity(selfOrFeature.EntityId);
|
|
if (entity != null)
|
|
{
|
|
if (entity.spawnById > 0 && entity.spawnById != _playerUI.entityPlayer.entityId && TwitchManager.Current.StealingCrateEvent != "")
|
|
GameEventManager.Current.HandleAction(TwitchManager.Current.StealingCrateEvent, (EntityPlayer)_playerUI.entityPlayer, (Entity)_playerUI.entityPlayer, false);
|
|
_containerTags = entity.EntityTags;
|
|
_lootContainerName = Localization.Get(EntityClass.list[entity.entityClass].entityClassName);
|
|
|
|
if (entity.EntityClass.entityClassName == "BackpackNPC")
|
|
{
|
|
_te.lootListName = EntityClass.list[entity.entityClass].Properties.GetString(EntityClass.PropLootListOnDeath);
|
|
}
|
|
|
|
if (entity is EntityVehicle)
|
|
flag = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
BlockValue block = __instance.m_World.GetBlock(selfOrFeature.ToWorldPos());
|
|
_containerTags = block.Block.Tags;
|
|
_lootContainerName = block.Block.GetLocalizedBlockName();
|
|
}
|
|
if (flag)
|
|
{
|
|
((XUiC_LootWindowGroup)((XUiWindowGroup)_playerUI.windowManager.GetWindow("looting")).Controller).SetTileEntityChest(_lootContainerName, selfOrFeature);
|
|
_playerUI.windowManager.Open("looting", true);
|
|
}
|
|
LootContainer lootContainer = LootContainer.GetLootContainer(selfOrFeature.lootListName);
|
|
if (lootContainer != null && _playerUI.entityPlayer != null)
|
|
lootContainer.ExecuteBuffActions(selfOrFeature.EntityId, (EntityAlive)_playerUI.entityPlayer);
|
|
}
|
|
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
return false;
|
|
__instance.lootManager.LootContainerOpened(selfOrFeature, _entityIdThatOpenedIt, _containerTags);
|
|
selfOrFeature.bTouched = true;
|
|
selfOrFeature.SetModified();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |