private void OnPlaced() { base.enabled = false; Transform child = this._ghosts[this._currentGhost]._go.transform.GetChild(0); if (!BoltNetwork.isRunning) { if (LocalPlayer.Create.BuildingPlacer.LastHit != null && LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>()) { child.parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>().transform; } else { child.parent = null; } child.SendMessage("OnPlaced", SendMessageOptions.DontRequireReceiver); GameObject gameObject = child.Find("Trigger").gameObject; gameObject.SetActive(true); if (this._ghosts[this._currentGhost]._initialize) { gameObject.GetComponent <Craft_Structure>().Initialize(); } UnityEngine.Object.Destroy(base.gameObject); } else { CoopConstructionEx component = child.GetComponent <CoopConstructionEx>(); if (component) { BoltEntity component2 = child.GetComponent <BoltEntity>(); BoltEntity parentEntity = LocalPlayer.Create.GetParentEntity(child.gameObject); component.SendMessage("OnSerializing"); CoopConstructionExToken coopConstructionExToken = LocalPlayer.Create.GetCoopConstructionExToken(component, parentEntity); PlaceFoundationEx placeFoundationEx = PlaceFoundationEx.Create(GlobalTargets.OnlyServer); placeFoundationEx.Parent = parentEntity; placeFoundationEx.Position = child.transform.position; placeFoundationEx.Prefab = component2.prefabId; placeFoundationEx.Token = coopConstructionExToken; placeFoundationEx.Send(); } else { PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer); if (LocalPlayer.Create.BuildingPlacer.LastHit != null) { placeConstruction.Parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>(); } placeConstruction.PrefabId = child.GetComponent <BoltEntity>().prefabId; placeConstruction.Position = child.position; placeConstruction.Rotation = child.rotation; FoundationArchitect component3 = child.GetComponent <FoundationArchitect>(); if (component3) { placeConstruction.AboveGround = component3._aboveGround; } placeConstruction.Send(); } UnityEngine.Object.Destroy(base.gameObject, 0.05f); } }
private void PlaceBulletHoleDecal(Vector3 Point, Vector3 Hit) { Debug.Log("Cheeaase!"); BoltEntity Decal = BoltNetwork.Instantiate(BoltPrefabs.Bullethole1, Point, Quaternion.FromToRotation(Vector3.up, Hit) * Quaternion.Euler(Vector3.up * Random.Range(0, 360))) as BoltEntity; Decal.transform.Translate(Vector3.up * 0.01f, Space.Self); }
private void OnDestroy() { if (this._replaceByPrefab && (!this._onlyIfActive || base.gameObject.activeSelf) && Prefabs.Instance && !BoltNetwork.isClient) { Transform parent = base.transform.parent; if (BoltNetwork.isServer && this._replaceByPrefab.GetComponent <BoltEntity>()) { if (this._oneFrameDelay) { Prefabs.Instance.SpawnNextFrameMP(this._replaceByPrefab, base.transform.position, base.transform.rotation, parent); } else { BoltEntity boltEntity = BoltNetwork.Instantiate(this._replaceByPrefab.gameObject, base.transform.position, base.transform.rotation); if (parent) { boltEntity.transform.parent = parent; } } } else if (this._oneFrameDelay) { Prefabs.Instance.SpawnNextFrame(this._replaceByPrefab, base.transform.position, base.transform.rotation, parent); } else { Transform transform = UnityEngine.Object.Instantiate <Transform>(this._replaceByPrefab, base.transform.position, base.transform.rotation); if (parent) { transform.parent = parent; } } } }
internal TheForestPlayer(BoltEntity entity) : this(entity.controller.RemoteEndPoint.SteamId.Id, SteamFriends.GetFriendPersonaName(new CSteamID(entity.controller.RemoteEndPoint.SteamId.Id))) { // Store user object this.entity = entity; cSteamId = new CSteamID(entity.controller.RemoteEndPoint.SteamId.Id); }
private void OnProjectileThrown(GameObject projectileGO) { if (this._targetView.ActiveBonus == this._bonus) { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this._prefab); gameObject.transform.parent = projectileGO.transform; gameObject.transform.localPosition = this._position.localPosition; gameObject.transform.localRotation = this._position.localRotation; Rigidbody component = gameObject.GetComponent <Rigidbody>(); if (component) { component.useGravity = false; component.isKinematic = true; } if (!gameObject.GetComponent <destroyAfter>()) { gameObject.AddComponent <destroyAfter>().destroyTime = 20f; } if (BoltNetwork.isRunning) { BoltEntity component2 = gameObject.GetComponent <BoltEntity>(); if (component2 && !component2.isAttached) { BoltNetwork.Attach(component2); } } this._targetView.ActiveBonus = (WeaponStatUpgrade.Types)(-1); } }
public void Kill() { if (BoltNetwork.IsRunning) { BoltEntity entity = GetComponent <NetworkBlockBehaviour>().entity; if (entity != null && entity.IsOwner) { BoltNetwork.Destroy(entity); } return; } else { try { GlobalReferences.Parts.Remove(gameObject); GlobalReferences.FreeParts.Remove(gameObject); } catch { throw new System.Exception("Part not Containes in global Collections"); } Destroy(gameObject); } }
public override void DisplayEffects(BoltEntity entity) { Vector3 pos; Quaternion rot; //TODO replace with the rotation of the right entity PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, entity.GetState <ITicTacState> ().Pitch, out pos, out rot); Ray r = new Ray(pos, rot * Vector3.forward); RaycastHit rh; if (Physics.Raycast(r, out rh) && impactPrefab) { var en = rh.transform.GetComponent <BoltEntity>(); var hit = GameObject.Instantiate(impactPrefab, rh.point, Quaternion.LookRotation(rh.normal)) as GameObject; if (en) { hit.GetComponent <RandomSound>().enabled = false; } if (trailPrefab) { var trailGo = GameObject.Instantiate(trailPrefab, muzzleFlash.position, Quaternion.identity) as GameObject; var trail = trailGo.GetComponent <LineRenderer>(); trail.SetPosition(0, muzzleFlash.position); trail.SetPosition(1, rh.point); } } GameObject go = (GameObject)GameObject.Instantiate(shellPrefab, shellEjector.position, shellEjector.rotation); go.GetComponent <Rigidbody>().AddRelativeForce(0, 0, 2, ForceMode.VelocityChange); go.GetComponent <Rigidbody>().AddTorque(new Vector3(Random.Range(-32f, +32f), Random.Range(-32f, +32f), Random.Range(-32f, +32f)), ForceMode.VelocityChange); }
public override void ControlOfEntityGained(BoltEntity arg) { print("C ControlOfEntityGained"); //print("Setting cam position"); //PlayerCamera.instance.SetTarget(arg); //PlayerCamera.instance.transform.position = new Vector3(0, 0, -20); }
private void throwRocks() { if (BoltNetwork.isClient) { return; } for (int i = 0; i < this.ammoCount; i++) { Vector3 position = this.releasePos.position + this.releasePos.up * 2f + (this.releasePos.forward * UnityEngine.Random.Range(-0.6f, 0.6f) + this.releasePos.right * UnityEngine.Random.Range(-0.6f, 0.6f)); MultiThrowerProjectile multiThrowerProjectile = UnityEngine.Object.Instantiate <MultiThrowerProjectile>(this.projectilePrefab, position, Quaternion.identity); Rigidbody rigidbody = multiThrowerProjectile._rigidbody; Vector2 vector = this.randomCircle2(2.2f); Vector3 target = new Vector3(this.landTarget.x + vector.x, this.landTarget.y, this.landTarget.z + vector.y); Vector3 a = this.calculateBestThrowSpeed(this.releasePos.position, target, UnityEngine.Random.Range(2.4f, 2.6f)); rigidbody.AddForce(a * (0.016666f / Time.fixedDeltaTime), ForceMode.VelocityChange); rigidbody.AddTorque(base.transform.right * UnityEngine.Random.Range(20f, 35f), ForceMode.VelocityChange); multiThrowerProjectile.InitProjectile(this.itemHolder.AmmoLoaded[i], (this.rockAmmo[i].transform.childCount <= 0) ? null : this.rockAmmo[i].transform.GetChild(0)); if (BoltNetwork.isRunning) { BoltEntity component = multiThrowerProjectile.GetComponent <BoltEntity>(); if (component) { BoltNetwork.Attach(multiThrowerProjectile.gameObject); IMultiThrowerProjectileState state = component.GetState <IMultiThrowerProjectileState>(); state.Thrower = this.entity; state.AmmoId = i + 1; } } } foreach (GameObject gameObject in this.rockAmmo) { gameObject.SetActive(false); } }
public static void SetDifuser(BoltEntity be) { if (!instance) { instance._difuser = be; } }
//PRIVATE private float ServerRewindDistCheck(Vector3 localCollisionPosition, BoltEntity target, int framesToRewind) { var targetHitbox = target.GetComponent <BoltHitboxBody>(); Vector3 targetRewindPos = BoltNetwork.PositionAtFrame(targetHitbox, BoltNetwork.Frame - framesToRewind); return(Vector3.Distance(localCollisionPosition, targetRewindPos)); }
internal void EntityDetached(BoltEntity entity) { if (entity.PrefabId == BoltPrefabs.Movement) { Player player = FindPlayer(entity.Source); if (player == null) { Object.Destroy(entity.gameObject); } else { player.Motion.DetachMoveState(false); } } if (playerInfosByPlayerId.ContainsKey(entity.NetworkId.PackedValue)) { PlayerServerInfo removeInfo = playerInfosByPlayerId[entity.NetworkId.PackedValue]; playerInfos.Remove(removeInfo); playerInfosByPlayerId.Remove(entity.NetworkId.PackedValue); if (serverPlayerInfo == removeInfo) { serverPlayerInfo = null; } if (removeInfo.IsClient) { playerInfosByConnection.Remove(removeInfo.BoltConnection); } } }
public override void EntityAttached(BoltEntity entity) { if ((entity.StateIs <IConstructionState>() || entity.StateIs <IConstructionStateEx>()) && (this.count -= 1f) <= 0f) { UnityEngine.Object.Destroy(base.gameObject, this.delay); } }
public void Launch(Vector3 force, Guid guid, BoltEntity entity) { player = entity.gameObject.GetComponent <Player>(); this.guid = guid; _rigidBody.AddForce(force); _launch = true; }
internal TheForestLivePlayer(BoltEntity entity) { this.entity = entity; steamId = entity.source.RemoteEndPoint.SteamId.Id; Character = this; Object = entity.gameObject; }
public static void AttachAnimalToNetwork(AnimalSpawnZone zone, AnimalSpawnConfig spawn, GameObject gameObject) { AnimalDespawner animalDespawner = gameObject.GetComponent <AnimalDespawner>(); if (!animalDespawner) { animalDespawner = gameObject.AddComponent <AnimalDespawner>(); } animalDespawner.SpawnedFromZone = zone; animalDespawner.DespawnRadius = 70f; animalDespawner.UpdateRate = 1f; if (BoltNetwork.isServer) { BoltEntity boltEntity = gameObject.AddComponent <BoltEntity>(); BoltEntity component = gameObject.GetComponent <CoopAnimalServer>().NetworkContainerPrefab.GetComponent <BoltEntity>(); using (BoltEntitySettingsModifier boltEntitySettingsModifier = component.ModifySettings()) { using (BoltEntitySettingsModifier boltEntitySettingsModifier2 = boltEntity.ModifySettings()) { boltEntitySettingsModifier2.clientPredicted = boltEntitySettingsModifier.clientPredicted; boltEntitySettingsModifier2.persistThroughSceneLoads = boltEntitySettingsModifier.persistThroughSceneLoads; boltEntitySettingsModifier2.allowInstantiateOnClient = boltEntitySettingsModifier.allowInstantiateOnClient; boltEntitySettingsModifier2.prefabId = boltEntitySettingsModifier.prefabId; boltEntitySettingsModifier2.updateRate = boltEntitySettingsModifier.updateRate; boltEntitySettingsModifier2.serializerId = boltEntitySettingsModifier.serializerId; } } BoltNetwork.Attach(gameObject); } }
public override void BoltStartDone() { if (!BoltNetwork.IsRunning) { return; } if (BoltNetwork.IsServer) { RoomProtocolToken token = new RoomProtocolToken() { ArbitraryData = "My DATA", }; BoltLog.Info("Starting Server"); // Start Photon Room BoltNetwork.SetServerInfo(_matchName, token); // Setup Host infoPanel.gameObject.SetActive(false); ChangeTo(lobbyPanel); backDelegate = Stop; SetServerInfo("Host", ""); // Build Server Entity BoltEntity entity = BoltNetwork.Instantiate(BoltPrefabs.PlayerInfo); entity.TakeControl(); } else if (BoltNetwork.IsClient) { backDelegate = Stop; SetServerInfo("Client", ""); } }
public override void EntityAttached(BoltEntity entity) { if (entity.StateIs <IPlayerTDWEState>()) { StartCoroutine(ExecuteAtEndOfFrameRoutine(entity)); } }
//PUBLIC public void ServerCollisionCheck(Vector3 localCollisionPosition, BoltEntity item, BoltEntity target, int framestoRewind, float collisionDistance) { if (ServerRewindDistCheck(localCollisionPosition, target, framestoRewind) <= collisionDistance) { bool alreadySentInformations = false; foreach (Transform child in item.transform) { if (!alreadySentInformations) { if (child.CompareTag(Constants.Tag.ItemCollisionHitBox)) { var itemCollider = child.GetComponent <Collider>(); target.GetComponentInChildren <KartCollisionTrigger>().CheckTargetInformationsBeforeSendingHitEvent(itemCollider); alreadySentInformations = true; } else { foreach (Transform secondChild in child.transform) { if (secondChild.CompareTag(Constants.Tag.ItemCollisionHitBox)) { var itemCollider = secondChild.GetComponent <Collider>(); target.GetComponentInChildren <KartCollisionTrigger>().CheckTargetInformationsBeforeSendingHitEvent(itemCollider); alreadySentInformations = true; } } } } } } }
private IEnumerator UpdateSetups() { while (true) { yield return(null); if (Players.Any(x => x == null)) { Players.Clear(); AllPlayerEntities.Clear(); PlayerStates.Clear(); Players.AddRange(Scene.SceneTracker.allPlayers); for (int i = 0; i < Scene.SceneTracker.allPlayers.Count; i++) { BoltEntity b = Scene.SceneTracker.allPlayers[i].GetComponent <BoltEntity>(); if (b != null) { AllPlayerEntities.Add(b); PlayerStates.Add(b.GetState <IPlayerState>()); } } } yield return(new WaitForSeconds(10)); } }
protected virtual bool DoFakeDrop() { bool flag = false; if (!this._preventFakeDropReUse) { Rigidbody rigidbody; if (!this._spawnAfterPickupPrefab) { rigidbody = this._destroyTarget.GetComponentInChildren <Rigidbody>(); } else { rigidbody = null; } if (rigidbody) { Collider component = rigidbody.GetComponent <Collider>(); if (component.isTrigger) { rigidbody = null; } else if (rigidbody.gameObject != this._destroyTarget) { rigidbody.transform.localPosition = Vector3.zero; } flag = rigidbody; } if (!flag) { if (BoltNetwork.isClient && !this._spawnAfterPickupPrefab) { BoltEntity component2 = this._destroyTarget.GetComponent <BoltEntity>(); if (component2) { flag = component2.isAttached; } } if (BoltNetwork.isRunning && !rigidbody) { BoltEntity component3 = this._destroyTarget.GetComponent <BoltEntity>(); if (component3 && component3.isAttached) { return(false); } } } else if (BoltNetwork.isRunning) { BoltEntity component4 = this._destroyTarget.GetComponent <BoltEntity>(); if (!component4 || !component4.isAttached) { flag = false; } } } LocalPlayer.Inventory.FakeDrop(this._itemId, (!flag) ? null : this._destroyTarget); return(flag); }
private void LateUpdate() { if (this._logMat) { bool flag = false; bool flag2 = false; if (this._lockMode == GardenArchitect.LockModes.Position) { flag = (LocalPlayer.Create.BuildingPlacer.ClearOfCollision && LocalPlayer.Create.BuildingPlacer.OnDynamicClear); LocalPlayer.Create.BuildingPlacer.SetNotclear(); if (flag && TheForest.Utils.Input.GetButtonDown("Fire1")) { LocalPlayer.Create.BuildingPlacer.SetClear(); if (LocalPlayer.Create.BuildingPlacer.LastHit != null) { BoltEntity componentInParent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>(); if (componentInParent) { LocalPlayer.Create.BuildingPlacer.ForcedParent = componentInParent.gameObject; } } this._lockMode = GardenArchitect.LockModes.Size; base.transform.parent = null; LocalPlayer.Sfx.PlayWhoosh(); } } else { Vector3 vector = base.transform.InverseTransformPoint(LocalPlayer.Create.BuildingPlacer.transform.position); this._size.x = Mathf.Clamp(Mathf.Abs(vector.x) + 5f, 1f, this._maxSize) * (float)((vector.x >= 0f) ? 1 : -1); this._size.y = Mathf.Clamp(Mathf.Abs(vector.z) + 5f, 1f, this._maxSize) * (float)((vector.z >= 0f) ? 1 : -1); if (TheForest.Utils.Input.GetButtonDown("AltFire")) { this._size.x = 5f; this._size.y = 5f; base.transform.parent = LocalPlayer.Create.BuildingPlacer.transform; base.transform.localPosition = Vector3.zero; base.transform.localRotation = Quaternion.identity; this._lockMode = GardenArchitect.LockModes.Position; LocalPlayer.Sfx.PlayWhoosh(); } flag2 = (vector.y <0.25f && vector.y> -0.25f); } if (LocalPlayer.Create.BuildingPlacer.Clear != flag2) { LocalPlayer.Create.BuildingPlacer.Clear = flag2; } this._logMat.SetColor("_TintColor", (!flag && !flag2) ? LocalPlayer.Create.BuildingPlacer.RedMat.GetColor("_TintColor") : LocalPlayer.Create.BuildingPlacer.ClearMat.GetColor("_TintColor")); this.CreateStructure(false); bool showManualfillLockIcon = this._lockMode == GardenArchitect.LockModes.Position && LocalPlayer.Create.BuildingPlacer.ClearOfCollision; bool flag3 = this._lockMode == GardenArchitect.LockModes.Size; bool showManualPlace = this._lockMode == GardenArchitect.LockModes.Size; Scene.HudGui.FoundationConstructionIcons.Show(showManualfillLockIcon, false, false, showManualPlace, false, flag3, false); if (Scene.HudGui.RotateIcon.activeSelf == flag3) { Scene.HudGui.RotateIcon.SetActive(!flag3); } } }
public static void DoBlink() { RaycastHit[] hits = Physics.RaycastAll(Camera.main.transform.position, Camera.main.transform.forward, BlinkRange); foreach (RaycastHit hit in hits) { if (BlinkDamage != 0) { if (hit.transform.root.CompareTag("enemyCollide")) { float dmg = BlinkDamage + ModdedPlayer.instance.SpellDamageBonus / 5; dmg *= ModdedPlayer.instance.SpellAMP; int dmgInt = Mathf.RoundToInt(dmg); if (GameSetup.IsMpClient) { BoltEntity enemyEntity = hit.transform.root.GetComponent <BoltEntity>(); if (enemyEntity == null) { enemyEntity = hit.transform.root.GetComponentInChildren <BoltEntity>(); } if (enemyEntity != null) { PlayerHitEnemy playerHitEnemy = PlayerHitEnemy.Create(enemyEntity); playerHitEnemy.hitFallDown = true; playerHitEnemy.Hit = dmgInt; playerHitEnemy.Send(); } } else { hit.transform.SendMessageUpwards("Hit", dmgInt, SendMessageOptions.DontRequireReceiver); } } } if (hit.transform.root != LocalPlayer.Transform.root && Vector3.Distance(hit.point, LocalPlayer.Transform.position) > 4) { int tries = 0; Vector3 hitPoint = hit.point; while (Physics.Raycast(hitPoint, Vector3.up, 2f) && tries < 5) { hitPoint += -Camera.main.transform.forward; tries++; } if (tries < 5) { BlinkTowards(hitPoint); return; } } } Vector3 checkPos = Camera.main.transform.position + new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z).normalized *BlinkRange; if (Physics.Raycast(checkPos + Vector3.up * 2, Vector3.down, out RaycastHit hit1, 10f)) { BlinkTowards(hit1.point + Vector3.up); return; } BlinkTowards(Camera.main.transform.position + Camera.main.transform.forward * (BlinkRange - 1)); }
public override void EntityAttached(BoltEntity entity) { if (entity.StateIs <ICoopServerInfo>()) { entity.GetState <ICoopServerInfo>().AddCallback("PlanePosition", new PropertyCallbackSimple(this.PlanePositionArrived)); entity.GetState <ICoopServerInfo>().AddCallback("PlaneRotation", new PropertyCallbackSimple(this.PlaneRotationArrived)); } }
public override void EntityReceived(BoltEntity entity) { if (entity.StateIs <IPlayerState>() && GameSetup.IsMpServer) { NetworkInformation.playerCount = TheForest.Utils.Scene.SceneTracker.allPlayers.Count + 1; } base.EntityReceived(entity); }
public override void ControlOfEntityGained(BoltEntity arg) { if (arg.GetComponent <PlayerController>()) { me = arg; meState = me.GetState <IPlayerState>(); } }
public override void ControlOfEntityLost(BoltEntity arg) { if (arg.GetComponent <PlayerController>()) { me = null; meState = null; } }
//once each player has finished loading the scene and spawning their players, they must give control back to the server //to indicate that they're ready and compliant. this function will be called when they do. Due to timing issues, this method //cannot be used for the server's local player, so that one is handled in Update() public override void ControlOfEntityGained(BoltEntity entity) { if (entity.prefabId == BoltPrefabs.PlayerPrefab && !entity.isOwner) {//first ensure that its a player that this event is being called on IPlayer player = entity.gameObject.GetComponentInChildren<AbstractPlayer>(); controlledPlayers.Add(player);//add them to the list PlayerRegistry.SetPlayer(player); //add them to the PlayerRegistry, if this is the server's player, it will be done elsewhere } }
public override void SceneLoadLocalDone(string scene) { if (BoltNetwork.IsServer) { BoltEntity entity = BoltNetwork.Instantiate(BoltPrefabs.Cube); entity.TakeControl(); } }
internal TheForestPlayer(BoltEntity entity) { steamId = entity.source.RemoteEndPoint.SteamId.Id; cSteamId = new CSteamID(steamId); Id = steamId.ToString(); Name = entity.GetState <IPlayerState>().name.Sanitize(); this.entity = entity; }
public override void EntityAttached(BoltEntity entity) { if (entity.StateIs<ICoopServerInfo>()) { entity.GetState<ICoopServerInfo>().AddCallback("PlanePosition", new PropertyCallbackSimple(this.PlanePositionArrived)); entity.GetState<ICoopServerInfo>().AddCallback("PlaneRotation", new PropertyCallbackSimple(this.PlaneRotationArrived)); } }
public ItemUseEvent ToBoltItemUseEventEvent(BoltEntity reciever) { ItemUseEvent evnt = ItemUseEvent.Create(reciever); evnt.Slot = SlotId; return(evnt); }
/// <summary> /// Broadcasts a chat message /// </summary> /// <param name="entity"></param> /// <param name="message"></param> public void BroadcastChat(BoltEntity entity, string message) { if (!BoltNetwork.isRunning) return; var e = ChatEvent.Create(GlobalTargets.AllClients); e.Message = message; e.Sender = entity.networkId; e.Send(); }
public void Spawn() { if (isServer && !coconut) { coconut = BoltNetwork.Instantiate (BoltPrefabs.Coconut_1, new Vector3 (1000f, 5f, 1000f), Quaternion.identity); coconut.TakeControl (); } // teleport entity to a random spawn position //coconut.transform.position = new Vector3 (1000f, 5f, 1000f); }
public override void EntityReceived(BoltEntity entity) { if (entity.StateIs<IPlayerState>() && Scene.SceneTracker) { if (!Scene.SceneTracker.allPlayers.Contains(entity.gameObject)) { Scene.SceneTracker.allPlayers.Add(entity.gameObject); } if (!Scene.SceneTracker.allPlayerEntities.Contains(entity)) { Scene.SceneTracker.allPlayerEntities.Add(entity); } } }
public override void EntityDetached(BoltEntity entity) { if (entity.StateIs<IPlayerState>() && Scene.SceneTracker) { if (Scene.SceneTracker.allPlayers.Contains(entity.gameObject)) { Scene.SceneTracker.allPlayers.Remove(entity.gameObject); } if (Scene.SceneTracker.allPlayerEntities.Contains(entity)) { Scene.SceneTracker.allPlayerEntities.Remove(entity); } } }
void IProtocolToken.Read(UdpPacket packet) { this.Parent = packet.ReadBoltEntity(); this.Height = packet.ReadFloat(); this.Support = packet.ReadBoltEntity(); if (packet.ReadBool()) { this.Holes = new Hole[packet.ReadInt()]; for (int i = 0; i < this.Holes.Length; i++) { this.Holes[i]._position = packet.ReadVector3(); this.Holes[i]._size = packet.ReadVector2(); } } }
public static float CalculatePriorityFor(BoltConnection connection, BoltEntity entity, float multiplier, int skipped) { if (!entity || !entity.isAttached) { return 0f; } skipped = Mathf.Max(1, skipped); if (BoltNetwork.isClient) { return 256f; } if (entity.StateIs<IPlayerState>()) { return 256f * multiplier * (float)skipped; } if (entity.StateIs<ITreeCutState>()) { return 256f * multiplier * (float)skipped; } if (entity.StateIs<ITreeFallState>()) { return 256f * multiplier * (float)skipped; } if (entity.StateIs<IMutantFemaleDummyState>()) { return 256f * multiplier * (float)skipped; } if (entity.StateIs<IMutantMaleDummyState>()) { return 256f * multiplier * (float)skipped; } BoltEntity boltEntity = connection.UserData as BoltEntity; if (boltEntity != null) { float num = Vector3.Distance(entity.transform.position, boltEntity.transform.position); if (num < 256f) { if (entity.StateIs<IMutantState>()) { return 256f * multiplier * (float)skipped; } return Mathf.Clamp(256f - num, 0f, 256f) * multiplier * (float)skipped; } } return 0f; }
void IProtocolToken.Read(UdpPacket packet) { this.Scale = packet.ReadVector3(); this.HipPosition = packet.ReadVector3(); this.HipRotation = packet.ReadQuaternion(); this.MaterialIndex = packet.ReadInt(); this.skinDamage1 = packet.ReadFloat(); this.skinDamage2 = packet.ReadFloat(); this.skinDamage3 = packet.ReadFloat(); this.skinDamage4 = packet.ReadFloat(); this.storedRagDollName = packet.ReadInt(); if (packet.ReadBool()) { this.OriginalMutant = packet.ReadBoltEntity(); } this.Skinny = packet.ReadBool(); this.Props = packet.ReadInt(); }
public override void EntityThawed(BoltEntity entity) { if (entity.StateIs<IMutantState>() || entity.StateIs<IAnimalState>()) { if (entity.StateIs<IMutantFemaleDummyState>()) { return; } if (entity.StateIs<IMutantMaleDummyState>()) { return; } if (!entity.transform.GetComponent<CoopMutantDummy>()) { CoopComponentDisabler coopComponentDisabler = this.InitCCD(entity); coopComponentDisabler.EnableComponents(); } } }
public void Spawn() { //character = BoltNetwork.Instantiate (BoltPrefabs.PlayerObject3d); if (!character) { character = BoltNetwork.Instantiate (BoltPrefabs.PlayerObject3dWithColliders); if (MenuScript.hasPickedTeamOne) { //character.renderer.material.color = Color.red; teamId = 1; foreach (SkinnedMeshRenderer smr in character.GetComponentsInChildren<SkinnedMeshRenderer>()) { smr.material.mainTexture = Resources.Load<Texture>("Textures/Layer_lambert1_u1_v2_Diffuse_merged_wNoise_Fish"); smr.material.SetTexture(1, Resources.Load<Texture>("Textures/Layer_lambert1_u1_v2_Diffuse_merged_wNoise_Fish_normal")); } } else if (MenuScript.hasPickedTeamTwo) { // character.renderer.material.color = Color.green; teamId = 2; foreach (SkinnedMeshRenderer smr in character.GetComponentsInChildren<SkinnedMeshRenderer>()) { smr.material.mainTexture = Resources.Load<Texture>("Textures/Layer_lambert1_u1_v2_Diffuse_merged_wNoise_Banana"); smr.material.SetTexture(1, Resources.Load<Texture>("Textures/Layer_lambert1_u1_v2_Diffuse_merged_wNoise_Banana_normal")); } } if (isServer) { //character = BoltNetwork.Instantiate (BoltPrefabs.PlayerObject3d); character.TakeControl (); //Coconut.Instantiate (); } else if (isClient) { // character = BoltNetwork.Instantiate (BoltPrefabs.PlayerObject3d); character.AssignControl (connection); GameObject.FindWithTag ("nut").GetComponent<Coconut> ().entity.AssignControl (connection); } } // teleport entity to a random spawn position if (MenuScript.hasPickedTeamOne == true) { character.transform.position = SpawnRandomPositionTeamOne (); } else if (MenuScript.hasPickedTeamTwo == true) { character.transform.position = SpawnRandomPositionTeamTwo(); } }
public ulong IdFromPlayer(BoltEntity player) => player.source.RemoteEndPoint.SteamId.Id;
private void OnPlayerSpawn(BoltEntity player) { // Call covalence hook Interface.Call("OnUserSpawn", covalence.PlayerManager.GetPlayer(player.source.RemoteEndPoint.SteamId.Id.ToString())); }
/// <summary> /// Checks if the permission system has loaded, shows an error if it failed to load /// </summary> /// <returns></returns> private bool PermissionsLoaded(BoltEntity player) { if (permission.IsLoaded) return true; // TODO: PermissionsNotLoaded reply to player return false; }
public override void EntityAttached(BoltEntity entity) { // SMUtils.log("entity attached:", entity, entity.isOwner); }
private void OnEntityThaw(BoltEntity entity) { HookCalled("OnEntityThaw"); // TODO: Show entity info }
private CoopComponentDisabler InitCCD(BoltEntity entity) { CoopComponentDisabler coopComponentDisabler = entity.GetComponent<CoopComponentDisabler>(); if (!coopComponentDisabler) { coopComponentDisabler = entity.gameObject.AddComponent<CoopComponentDisabler>(); } return coopComponentDisabler; }
private void OnPlayerSpawn(BoltEntity player) { HookCalled("OnPlayerSpawn"); // TODO: Show player info }
internal void NotifyPlayerConnect(BoltEntity player) { var id = player.source.RemoteEndPoint.SteamId.Id; NotifyPlayerJoin(id, SteamFriends.GetFriendPersonaName(new CSteamID(id))); livePlayers[id.ToString()] = new TheForestLivePlayer(player); }
void IProtocolToken.Read(UdpPacket packet) { this.Anchor = packet.ReadBoltEntity(); this.Index = packet.ReadInt(); }
public static void AttachBuildingBoltEntity(BoltEntity entity) { if (!BoltNetwork.isServer) { return; } if (!CoopSteamServerStarter.SaveIsLoading) { return; } if (!entity) { return; } if (entity.IsAttached()) { return; } BoltEntitySettingsModifier boltEntitySettingsModifier = entity.ModifySettings(); BridgeArchitect component = entity.GetComponent<BridgeArchitect>(); if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IFireState) { BoltNetwork.Attach(entity); } else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IRaftState) { BoltNetwork.Attach(entity); if (entity && entity.isAttached && entity.StateIs<IRaftState>()) { entity.GetState<IRaftState>().IsReal = true; } } else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IMultiHolderState) { BoltNetwork.Attach(entity); if (entity && entity.isAttached && entity.StateIs<IMultiHolderState>()) { entity.GetState<IMultiHolderState>().IsReal = true; MultiHolder[] componentsInChildren = entity.GetComponentsInChildren<MultiHolder>(true); if (componentsInChildren.Length > 0) { componentsInChildren[0]._contentActual = componentsInChildren[0]._contentAmount; componentsInChildren[0]._contentTypeActual = componentsInChildren[0]._content; } } } else if (component) { BoltNetwork.Attach(entity, component.CustomToken); } else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IFoundationState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IBuildingState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IRabbitCage || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.ITreeBuildingState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.ITrapLargeState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IBuildingDestructibleState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IWallChunkBuildingState) { CoopBuildingEx component2 = entity.GetComponent<CoopBuildingEx>(); WallChunkArchitect component3 = entity.GetComponent<WallChunkArchitect>(); if (component3) { BoltNetwork.Attach(entity, component3.CustomToken); } else if (component2) { CoopConstructionExToken coopConstructionExToken = new CoopConstructionExToken(); coopConstructionExToken.Architects = new CoopConstructionExToken.ArchitectData[component2.Architects.Length]; for (int i = 0; i < component2.Architects.Length; i++) { coopConstructionExToken.Architects[i].PointsCount = (component2.Architects[i] as ICoopStructure).MultiPointsCount; coopConstructionExToken.Architects[i].PointsPositions = (component2.Architects[i] as ICoopStructure).MultiPointsPositions.ToArray(); coopConstructionExToken.Architects[i].CustomToken = (component2.Architects[i] as ICoopStructure).CustomToken; if (component2.Architects[i] is FoundationArchitect) { coopConstructionExToken.Architects[i].AboveGround = ((FoundationArchitect)component2.Architects[i])._aboveGround; } if (component2.Architects[i] is RoofArchitect && (component2.Architects[i] as RoofArchitect).CurrentSupport != null) { coopConstructionExToken.Architects[i].Support = ((component2.Architects[i] as RoofArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>(); } if (component2.Architects[i] is FloorArchitect && (component2.Architects[i] as FloorArchitect).CurrentSupport != null) { coopConstructionExToken.Architects[i].Support = ((component2.Architects[i] as FloorArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>(); } CoopSteamServerStarter.AttachBuildingBoltEntity(coopConstructionExToken.Architects[i].Support); } BoltNetwork.Attach(entity, coopConstructionExToken); } else { BoltNetwork.Attach(entity); } } else if (boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IConstructionState || boltEntitySettingsModifier.serializerId == StateSerializerTypeIds.IWallChunkConstructionState) { CoopConstructionEx component4 = entity.GetComponent<CoopConstructionEx>(); WallChunkArchitect component5 = entity.GetComponent<WallChunkArchitect>(); if (component5) { BoltNetwork.Attach(entity, component5.CustomToken); } else if (component4) { CoopConstructionExToken coopConstructionExToken2 = new CoopConstructionExToken(); coopConstructionExToken2.Architects = new CoopConstructionExToken.ArchitectData[component4.Architects.Length]; for (int j = 0; j < component4.Architects.Length; j++) { coopConstructionExToken2.Architects[j].PointsCount = (component4.Architects[j] as ICoopStructure).MultiPointsCount; coopConstructionExToken2.Architects[j].PointsPositions = (component4.Architects[j] as ICoopStructure).MultiPointsPositions.ToArray(); coopConstructionExToken2.Architects[j].CustomToken = (component4.Architects[j] as ICoopStructure).CustomToken; if (component4.Architects[j] is FoundationArchitect) { coopConstructionExToken2.Architects[j].AboveGround = ((FoundationArchitect)component4.Architects[j])._aboveGround; } if (component4.Architects[j] is RoofArchitect && (component4.Architects[j] as RoofArchitect).CurrentSupport != null) { coopConstructionExToken2.Architects[j].Support = ((component4.Architects[j] as RoofArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>(); } if (component4.Architects[j] is FloorArchitect && (component4.Architects[j] as FloorArchitect).CurrentSupport != null) { coopConstructionExToken2.Architects[j].Support = ((component4.Architects[j] as FloorArchitect).CurrentSupport as MonoBehaviour).GetComponent<BoltEntity>(); } CoopSteamServerStarter.AttachBuildingBoltEntity(coopConstructionExToken2.Architects[j].Support); } BoltNetwork.Attach(entity, coopConstructionExToken2); } else { BoltNetwork.Attach(entity); } } }
public static void KickPlayer(BoltEntity playerEntity, int duration, string message = "Host kicked you from the game") { if (BoltNetwork.isServer) { if (duration >= 0 && !CoopKick.IsBanned(playerEntity.source.RemoteEndPoint.SteamId)) { CoopKick.Instance.kickedSteamIds.Add(new CoopKick.KickedPlayer { Name = playerEntity.GetState<IPlayerState>().name, SteamId = playerEntity.source.RemoteEndPoint.SteamId.Id, BanEndTime = (duration <= 0) ? 0L : (DateTime.UtcNow.ToUnixTimestamp() + (long)duration) }); CoopKick.SaveList(); } playerEntity.source.Disconnect(new CoopKickToken { KickMessage = message, Banned = duration == 0 }); } }
public static void BanPlayer(BoltEntity playerEntity) { CoopKick.KickPlayer(playerEntity, 0, "Host banned you permanently from his games"); }
private void OnPlayerConnected(BoltEntity player) { var id = player.source.RemoteEndPoint.SteamId.Id; var name = SteamFriends.GetFriendPersonaName(new CSteamID(id)); Debug.Log($"{id}/{name} joined"); // Do permission stuff if (permission.IsLoaded) { permission.UpdateNickname(id.ToString(), name); // Add player to default group if (!permission.UserHasGroup(id.ToString(), DefaultGroups[0])) permission.AddUserGroup(id.ToString(), DefaultGroups[0]); } // Let covalence know covalence.PlayerManager.NotifyPlayerConnect(player); Interface.Call("OnUserConnected", covalence.PlayerManager.GetPlayer(id.ToString())); }
private void OnEntityFrozen(BoltEntity entity) { HookCalled("OnEntityFrozen"); // TODO: Show entity info }
private void OnPlayerInit(BoltEntity player) { HookCalled("OnPlayerInit"); // TODO: Show player info }
internal void NotifyPlayerDisconnect(BoltEntity player) => livePlayers.Remove(player.source.RemoteEndPoint.SteamId.Id.ToString());
public void SetTarget(BoltEntity entity) { _target = entity.transform; }