public bool OriginalPutDown(bool fake, bool drop, bool equipPrevious, GameObject preSpawned) { if (this._infiniteLogHack) { return(true); } if (!fake) { if (this._logs <= 0) { return(false); } this.RemoveLog(equipPrevious); } if (drop) { bool flag = this._logs == 1; Transform transform = this._logsHeld[Mathf.Min(this._logs, 1)].transform; Vector3 vector = transform.position + transform.forward * -2f; Quaternion quaternion = LocalPlayer.Transform.rotation; quaternion *= Quaternion.AngleAxis(90f, Vector3.up); if (LocalPlayer.FpCharacter.PushingSled) { vector += transform.forward * -1.25f + transform.right * -2f; } Vector3 origin = vector; origin.y += 3f; if (Physics.Raycast(origin, Vector3.down, out RaycastHit raycastHit, 5f, this._layerMask)) { vector.y = raycastHit.point.y + 2.2f; } if (flag) { vector.y += 1f; } if (BoltNetwork.isRunning) { DropItem dropItem = DropItem.Create(GlobalTargets.OnlyServer); dropItem.PrefabId = BoltPrefabs.Log; dropItem.Position = vector; dropItem.Rotation = quaternion; dropItem.PreSpawned = ((!preSpawned) ? null : preSpawned.GetComponent <BoltEntity>()); dropItem.Send(); } else if (preSpawned) { preSpawned.transform.position = vector; preSpawned.transform.rotation = quaternion; } else { Instantiate(this._logPrefab, vector, quaternion); } FMODCommon.PlayOneshotNetworked("event:/player/foley/log_drop_exert", transform, FMODCommon.NetworkRole.Any); } this.UpdateLogCount(); return(true); }
private bool PutDownNew(bool fake, bool drop, bool equipPrev, GameObject preSpawned) { if (additional_logs > 0 && !_infiniteLogHack) { if (drop) { additional_logs--; Transform heldLog = this._logsHeld[Mathf.Min(this._logs, 1)].transform; Vector3 logPosition = heldLog.position + heldLog.forward * -2f; Quaternion playerRotation = LocalPlayer.Transform.rotation; playerRotation *= Quaternion.AngleAxis(90f, Vector3.up); if (LocalPlayer.FpCharacter.PushingSled) { logPosition += heldLog.forward * -1.25f + heldLog.right * -2f; } Vector3 rayOrigin = logPosition; rayOrigin.y += 3f; if (Physics.Raycast(rayOrigin, Vector3.down, out RaycastHit raycastHit, 5f, this._layerMask)) { logPosition.y = raycastHit.point.y + 2.2f; } if (_logs == 1) { logPosition.y += 1f; } if (BoltNetwork.isRunning) { DropItem dropItem2 = DropItem.Create(GlobalTargets.OnlyServer); dropItem2.PrefabId = BoltPrefabs.Log; dropItem2.Position = logPosition; dropItem2.Rotation = playerRotation; dropItem2.PreSpawned = ((preSpawned != null) ? null : preSpawned.GetComponent <BoltEntity>()); dropItem2.Send(); } else if ((bool)preSpawned) { preSpawned.transform.position = logPosition; preSpawned.transform.rotation = playerRotation; } else { UnityEngine.Object.Instantiate <GameObject>(this._logPrefab, logPosition, playerRotation); } FMODCommon.PlayOneshotNetworked("event:/player/foley/log_drop_exert", heldLog, FMODCommon.NetworkRole.Any); } return(true); } else { return(OriginalPutDown(fake, drop, equipPrev, preSpawned)); } }
public static void Spawn(PrefabId prefabId, Vector3 position, Quaternion rotation) { if (prefabId == BoltPrefabs.Log) { DropItem dropItem = DropItem.Create(GlobalTargets.OnlyServer); dropItem.PrefabId = prefabId; dropItem.Position = position; dropItem.Rotation = rotation; //PacketQueue.Add(dropItem); dropItem.Send(); return; } BoltNetwork.Instantiate(prefabId, position, rotation); }
public static GameObject SpawnItem(int itemId, Vector3 position, Quaternion rotation, bool avoidImpacts = false) { Item item = ItemDatabase.ItemById(itemId); GameObject gameObject = null; if (item != null) { if (BoltNetwork.isRunning) { if (item._pickupPrefabMP != null) { if (BoltNetwork.isServer) { Transform pickupPrefabMP = item._pickupPrefabMP; BoltEntity boltEntity = BoltNetwork.Instantiate(pickupPrefabMP.gameObject, position, rotation); gameObject = boltEntity.gameObject; } else { DropItem dropItem = DropItem.Create(GlobalTargets.OnlyServer); dropItem.PrefabId = item._pickupPrefabMP.gameObject.GetComponent <BoltEntity>().prefabId; dropItem.Position = position; dropItem.Rotation = rotation; dropItem.PreSpawned = null; dropItem.AvoidImpacts = avoidImpacts; dropItem.Send(); } } else if (item._pickupPrefab != null) { Debug.LogError(string.Concat(new object[] { "Item #", item._id, " name ", item._name, " no MP version at itemdatabase." })); } else { Debug.LogError(string.Concat(new object[] { "Item #", item._id, " name ", item._name, " not found at itemdatabase." })); } } else { Transform transform = (!item._pickupPrefab) ? item._pickupPrefabMP : item._pickupPrefab; if (transform) { gameObject = UnityEngine.Object.Instantiate <GameObject>(transform.gameObject, position, rotation); } else { Debug.LogError(string.Concat(new object[] { "Item #", item._id, " name ", item._name, " not found at itemdatabase." })); } } if (gameObject != null && avoidImpacts && !gameObject.GetComponent <flyingObjectFixerFrame>()) { flyingObjectFixerFrame flyingObjectFixerFrame = gameObject.AddComponent <flyingObjectFixerFrame>(); } } return(gameObject); }
private void FixedUpdate() { if (this._targetObject && !this._noValidTargetObject) { if (!this._locked && !Grabber.IsFocused && LocalPlayer.Inventory.HasInSlot(this._slot, this._itemId)) { if (Physics.Raycast(LocalPlayer.MainCamTr.position, LocalPlayer.MainCamTr.forward, out this._hit, 10f, this._layerMask.value) && !this._hit.collider.isTrigger) { Rigidbody component = this._hit.transform.GetComponent <Rigidbody>(); if (!component) { component = this._hit.transform.parent.GetComponent <Rigidbody>(); } if (component && component.useGravity) { this._noValidTargetObject = true; return; } if (this._targetObject.CompareTag("trapTrigger")) { this._placeIconSheen.transform.position = this._targetObject.transform.position; } else { this._placeIconSheen.transform.position = this._hit.point + LocalPlayer.MainCamTr.forward * -0.1f; } if (!this._placeIconSheen.activeSelf) { this._placeIconSheen.transform.parent = null; this._placeIconSheen.SetActive(true); } if (TheForest.Utils.Input.GetButtonDown("Craft")) { if (this._playWhooshOnInput) { LocalPlayer.Sfx.PlayWhoosh(); } bool flag = true; if (LocalPlayer.ActiveBurnableItem != null) { flag = !LocalPlayer.ActiveBurnableItem.IsUnlit(); } if ((this._slot != Item.EquipmentSlot.RightHand) ? LocalPlayer.Inventory.RemoveItem(this._itemId, 1, false, true) : LocalPlayer.Inventory.ShuffleRemoveRightHandItem()) { Vector3 forward; if (this._rotationMode == DistractionDevicePlacer.RotationModes.LookAtCenterOfTarget) { forward = this._hit.point - this._hit.transform.position; } else { forward = this._hit.normal; } forward.y = 0f; Vector3 position = this._hit.point; if (this._targetObject.CompareTag("trapTrigger")) { position = this._targetObject.transform.position; } if (BoltNetwork.isRunning && this._spawnMode == DistractionDevicePlacer.SpawnModes.ServerSide) { DropItem dropItem = DropItem.Create(GlobalTargets.OnlyServer); dropItem.PrefabId = ((!flag) ? this._distractionDevicePrefabUnlit : this._distractionDevicePrefab).GetComponent <BoltEntity>().prefabId; dropItem.Position = position; dropItem.Rotation = Quaternion.LookRotation(forward); dropItem.PreSpawned = null; dropItem.AvoidImpacts = false; dropItem.Send(); } else { GameObject gameObject; if (flag) { gameObject = UnityEngine.Object.Instantiate <GameObject>(this._distractionDevicePrefab, position, Quaternion.LookRotation(forward)); } else { gameObject = UnityEngine.Object.Instantiate <GameObject>(this._distractionDevicePrefabUnlit, position, Quaternion.LookRotation(forward)); } if (this._targetObject.CompareTag("Tree") || this._targetObject.transform.root.CompareTag("Tree")) { TreeHealth component2 = this._targetObject.GetComponent <TreeHealth>(); if (!component2) { component2 = this._targetObject.transform.root.GetComponent <TreeHealth>(); } if (component2 && component2.LodTree) { component2.LodTree.AddTreeCutDownTarget(gameObject); } } if (BoltNetwork.isRunning) { BoltEntity component3 = BoltNetwork.Attach(gameObject).GetComponent <BoltEntity>(); if (component3 && this._playAudio && WalkmanControler.HasCassetteReady) { component3.GetState <IDistractionDevice>().MusicTrack = WalkmanControler.CurrentTrack + 10; } } else if (this._playAudio) { EventInstance eventInstance = LocalPlayer.Sfx.RelinquishMusicTrack(); if (eventInstance == null && WalkmanControler.HasCassetteReady) { eventInstance = LocalPlayer.Sfx.InstantiateMusicTrack(WalkmanControler.CurrentTrack); } if (eventInstance != null) { gameObject.SendMessage("ActivateDevice", eventInstance); } gameObject.SendMessage("SetPlayerSfx", LocalPlayer.Sfx); } } this._placeIconSheen.SetActive(false); this._placeIconSheen.transform.parent = base.transform; this.Deactivate(); } } } } else if (this._placeIconSheen.activeSelf) { this._placeIconSheen.transform.parent = base.transform; this._placeIconSheen.SetActive(false); } } else { this.Deactivate(); } }