private void TakeControlOfDummy() { entity.ReleaseControl(); GetComponentInParent <ControllableDisabler>().DisableAllInChildren(); Enabled = true; _lastInstantiatedDummy.TakeControl(); _lastInstantiatedDummy.GetComponent <ObserversSetup>().SetObservers(); _lastInstantiatedDummy.GetComponent <ControllableDisabler>().EnableAllInChildren(); _hasControlOfDummy = true; }
private void OnTriggerEnter(Collider other) { if (other.tag == Tags.PLAYER_TAG) { if (state.EntityOwner == null) // if nobody owns the tile, assign ownership { return; // do nothing if there is no owner. } if (players.Contains(other.gameObject)) { return; } else { BoltVFX.Play(); BoltVFX2.Play(); players.Add(other.gameObject); BoltEntity player = other.GetComponent <BoltEntity>(); if (!player.IsOwner) { return; } // only continue for local machine here. not a server based event. // apply damage recursion function here. if (state.EntityOwner == player) // owned guard tile { if (!state.Healing) { return; } if (coroutineGuardTile == null) { coroutineGuardTile = player.GetComponent <Health>().AreaEffectorDeltaHealth(HealRate, CooldownTime); } StartCoroutine(coroutineGuardTile); print("This is your guarded tile. Enjoy!!"); // possibly heal player here in random event? } else// tile that is not owned { if (coroutineGuardTile == null) { coroutineGuardTile = player.GetComponent <Health>().AreaEffectorDeltaHealth(-Damage, CooldownTime); } Invoke("PlayBoltSFX", 4f); StartCoroutine(coroutineGuardTile); } } // cancel the invoke with on-trigger-exit. } }
// Spawner private void SpawnGamePlayer() { playerEntity = BoltNetwork.Instantiate(BoltPrefabs.LocalPlayer); playerEntity.TakeControl(); CrisisHandler.instance.CallCrisis(NetworkGameState.instance.getCurrentCrisis()); playerEntity.GetComponent <Player>().setup(localPlayerSpellcasterID); }
public override void OnEvent(PlayerHitEvent evnt) { if (myPlayer = evnt.targetEntity) { myPlayer.GetComponent <PlayerSubScript>().HealthChange(evnt.damage, evnt.attacker, evnt.attackerEntity); } }
//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)); }
// PUBLIC public void CheckTargetInformationsBeforeSendingHitEvent(Collider target) { var itemCollisionTrigger = target.GetComponent <ItemCollisionTrigger>(); if (itemCollisionTrigger.ItemCollision.HitsPlayer) // It is an item that damages the player { BoltEntity itemEntity = target.GetComponentInParent <BoltEntity>(); Ownership itemOwnership = itemEntity.GetComponent <Ownership>(); if (itemEntity.isAttached) // It is a concrete item & it is attached { if ((int)itemOwnership.Team != state.Team && !_hitSecurity.ContainsKey(itemOwnership.OwnerID)) { if (!_health.IsInvincible) // The server checks that this kart is not invincible { Debug.Log("[HIT] Added to security."); _hitSecurity.Add(itemOwnership.OwnerID, 0f); SendPlayerHitEvent(itemOwnership); } DestroyColliderObject(target); } else if (_hitSecurity.ContainsKey(itemOwnership.OwnerID)) { Debug.Log("[HIT] Security hit."); } } } }
public BoltEntity GetParentEntity(GameObject ghost) { BoltEntity boltEntity = null; SingleAnchorStructure component = ghost.GetComponent <SingleAnchorStructure>(); if (component && component.Anchor1) { component.enabled = false; boltEntity = component.Anchor1.GetComponentInParent <BoltEntity>(); } if (this._buildingPlacer.ForcedParent) { boltEntity = this._buildingPlacer.ForcedParent.GetComponentInParent <BoltEntity>(); this._buildingPlacer.ForcedParent = null; } else if (this._buildingPlacer.LastHit != null && !this._currentBlueprint._isDynamic && !boltEntity) { boltEntity = this._buildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>(); } if (!boltEntity) { boltEntity = null; } else { DynamicBuilding component2 = boltEntity.GetComponent <DynamicBuilding>(); if (component2 && (!this._currentBlueprint._allowParentingToDynamic || !component2._allowParenting)) { boltEntity = null; } } return(boltEntity); }
public override void OnOwner(PlayerCommand cmd, BoltEntity entity) { if (entity.isOwner) { IPlayerState state = entity.GetState <IPlayerState>(); PlayerController controller = entity.GetComponent <PlayerController>(); Vector3 pos; Quaternion look; // this calculate the looking angle for this specific entity PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, state.pitch, out pos, out look); // display debug Debug.DrawRay(pos, look * Vector3.forward); using (var hits = BoltNetwork.RaycastAll(new Ray(pos, look * Vector3.forward), cmd.ServerFrame)) { for (int i = 0; i < hits.count; ++i) { var hit = hits.GetHit(i); var serializer = hit.body.GetComponent <PlayerController>(); if ((serializer != null) && (serializer.state.team != state.team)) { serializer.ApplyDamage(controller.activeWeapon.damagePerBullet); } } } } }
public override void OnEvent(TakeDamageEvent evnt) { if (evnt.Entity.IsOwner) { if (evnt.Entity.Source == null) { BoltEntity entity = evnt.Entity; PlayerHealth playerHealth = entity.GetComponent <PlayerHealth>(); playerHealth.TakeDamage(evnt.Damage); } } else { if (evnt.Entity.Source == null) { BoltConsole.Write("empty soiurce"); } else { var newEvnt = TakeDamageEvent.Create(evnt.Entity.Source); newEvnt.Damage = evnt.Damage; newEvnt.Entity = evnt.Entity; newEvnt.Send(); } } }
public static void SpawnPlayerAtPosition(Player player, Vector3 position, Quaternion rotation) { //Make sure player controlled entities are destroyed. PlayerManager.Instance.DestroyPlayerControlledEntities(player); LoadOut loadOut = new LoadOut(); loadOut.itemNames = new string[] { "Scout", "PlasmaFusor", "GrenadeLauncher", "ChainGun" }; LoadOutToken loadOutToken = new LoadOutToken(loadOut); GameObject baseMech = DatabaseManager.Instance.PrefabDatabase.GetPrefabByName("BaseMech"); BoltEntity entity = BoltNetwork.Instantiate(baseMech, loadOutToken, position, rotation); if (entity != null) { Unit unit = entity.GetComponent <Unit>(); unit.Setup(player.guid, player.teamId); unit.gameObject.AddComponent <AbilityVelocityRedirection>(); if (player.connection == null) { entity.TakeControl(); } else { entity.AssignControl(player.connection); } player.SetControlledEntity(entity); } }
public override void Attached() { this.chunks = (from x in base.GetComponentsInChildren <TreeCutChunk>() orderby int.Parse(x.transform.parent.gameObject.name) select x).ToArray <TreeCutChunk>(); base.state.AddCallback("TreeId", delegate { CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId x) => x.Id == base.state.TreeId); if (coopTreeId) { LOD_Trees component = coopTreeId.GetComponent <LOD_Trees>(); if (component) { component.enabled = false; component.DontSpawn = true; if (component.CurrentView) { component.Pool.Despawn(component.CurrentView.transform); component.CurrentView = null; component.CurrentLodTransform = null; } } } }); base.state.AddCallback("Damage", delegate { if (base.entity.isOwner && base.state.Damage == 16f) { base.entity.DestroyDelayed(10f); BoltEntity boltEntity = BoltNetwork.Instantiate(this.CoopTree.NetworkFallPrefab, base.entity.transform.position, base.entity.transform.rotation); boltEntity.GetState <ITreeFallState>().CutTree = base.entity; boltEntity.GetComponent <Rigidbody>().AddForce(new Vector3(UnityEngine.Random.value * 0.01f, 0f, UnityEngine.Random.value * 0.01f), ForceMode.VelocityChange); } }); }
public override void BoltStartDone() { BoltConsole.Write("BoltStartDone breh"); 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); //BoltNetwork.EnableLanBroadcast(); // Setup Host infoPanel.gameObject.SetActive(false); //PanelHolder.instance.hideConnectingPanel(); ChangeTo(lobbyPanel); backDelegate = Stop; SetServerInfo("Host", ""); connection_spellcaster = new Dictionary <string, int>(); //SoundManager.instance.musicSource.Play(); // Build Server Entity characterSelection = BoltNetwork.Instantiate(BoltPrefabs.CharacterSelectionEntity); characterSelection.TakeControl(); gameStateEntity = BoltNetwork.Instantiate(BoltPrefabs.GameState); gameStateEntity.TakeControl(); gameStateEntity.GetComponent <NetworkGameState>().onCreateRoom(_matchName); numPlayersInfo.text = gameStateEntity.GetComponent <NetworkGameState>().onPlayerJoined() + ""; } else if (BoltNetwork.IsClient) { backDelegate = Stop; SetServerInfo("Client", ""); } }
private void Die() { if (entity.IsOwner) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; var Event = PlayerKilled.Create(); Event.Killed = entity; Event.Killer = LastDamaged; Event.Send(); var Event2 = ClaimKill.Create(LastDamaged); Event2.Send(); var Event3 = ClaimScore.Create(LastDamaged); Event3.Score = 100; Event3.Send(); if (LastDamaged != entity) { LastDamaged.GetComponent <Player>().AddScore(100); } state.Deaths += 1; StartCoroutine(Respawn()); if (LastDamaged == entity) { GuiManager.ShowDeathScreen("You've commited suicide..."); if (state.Score > 0) { state.Score -= 100; } if (state.Score < 0) { state.Score = 0; } } else { GuiManager.ShowDeathScreen("You've been killed by: " + LastDamaged.GetComponent <Player>().state.Username); } GuiManager.ShowScoreBoard(); gameObject.GetComponent <Renderer>().enabled = false; } }
public override void ControlOfEntityLost(BoltEntity arg) { if (arg.GetComponent <PlayerController>()) { me = null; meState = null; } }
public override void ControlOfEntityGained(BoltEntity arg) { if (arg.GetComponent <PlayerController>()) { me = arg; meState = me.GetState <IPlayerState>(); } }
// PRIVATE private void TeleportOnSpawn() { var teleportTarget = GetRandomSpawnForTeam(_playerSettings.ColorSettings.TeamEnum); _kartRoot.transform.position = teleportTarget.transform.position; _kartRoot.transform.rotation = teleportTarget.transform.rotation; _kartRoot.GetComponent <Rigidbody>().velocity = Vector3.zero; }
protected virtual void SVSpawnPlayer(BoltConnection connection) { //Create a new player var spawn = spawnPositions.GetRandom(); BoltEntity playerEnt = BoltNetwork.Instantiate(playerPrefab, spawn.transform.position, Quaternion.identity); playerEnt.AssignControl(connection); PlayerController player = playerEnt.GetComponent <PlayerController>(); }
protected void SetPlayerPositionAndRotation(BoltEntity entity, Vector3 pos, Quaternion rot) { var playerController = entity.GetComponent <PlayerTDEWController>(); if (playerController != null) { playerController.SetPositionAndRotation(pos, rot); } }
private CoopComponentDisabler InitCCD(BoltEntity entity) { CoopComponentDisabler coopComponentDisabler = entity.GetComponent <CoopComponentDisabler>(); if (!coopComponentDisabler) { coopComponentDisabler = entity.gameObject.AddComponent <CoopComponentDisabler>(); } return(coopComponentDisabler); }
public override void ControlOfEntityLost(BoltEntity arg) { if (arg.GetComponent <PlayerController> ()) { meState.RemoveCallback("health", HealthChanged); me = null; meState = null; } }
// PRIVATE private void InstantiateKart(BoltEntity kart) { var spawnPosition = transform.position + (5 * transform.forward); _lastInstantiatedDummy = BoltNetwork.Instantiate(kart, spawnPosition, transform.rotation); _lastInstantiatedDummy.GetState <IKartState>().Team = (int)_playerSettings.ColorSettings.TeamEnum.OppositeTeam(); _lastInstantiatedDummy.GetState <IKartState>().OwnerID = -2; _lastInstantiatedDummy.GetComponent <PlayerInfo>().Nickname = "Dummy"; ReleaseControlOfDummy(); }
IEnumerator ExecuteAtEndOfFrameRoutine(BoltEntity entity) { yield return(new WaitForEndOfFrame()); var playerCtrl = entity.GetComponent <PlayerTDEWController>(); if (spawnPoint != null) { playerCtrl.SetPositionAndRotation(spawnPoint.position, spawnPoint.rotation); } }
private WeaponBase SV_SpawnWeapon() { if (!entity.IsOwner()) { return(null); } BoltEntity weaponEnt = BoltNetwork.Instantiate(weaponPrefab, transform.position, Quaternion.identity); return(weaponEnt.GetComponent <WeaponBase>()); }
public override void SceneLoadLocalDone(string map) { current_map = map; PlayerCamera.Instantiate(); SetSpawnPosition(current_map); BoltEntity player_entity = BoltNetwork.Instantiate(BoltPrefabs.FireDragon, spawn_position, Quaternion.identity); PlayerCamera.instance.SetTarget(player_entity, current_map); player_entity.GetComponent <Player>().SetRespawnPosition(spawn_position); CurrentLevel.InitializeLevel(true); }
public override void ControlOfEntityGained(BoltEntity arg) { if (arg.GetComponent <PlayerController> ()) { me = arg; meState = me.GetState <IPlayerState> (); meState.AddCallback("health", HealthChanged); HealthChanged(); } }
public override void ControlOfEntityGained(BoltEntity entity) { var player = entity.GetComponent <Player>(); if (player == null) { return; } if (Camera.main != null) { Camera.main.gameObject.AddComponent <CameraController>().FollowTarget = player.transform; } }
public override void ExecuteCommand(Command command, bool resetState) { PlayerCommand cmd = (PlayerCommand)command; if (resetState) { //owner has sent a correction to the controller transform.position = cmd.Result.position; } else { if (cmd.IsFirstExecution) { if (cmd.Input.shootDirection != Vector3.zero) { if (BoltNetwork.isServer) { BoltEntity BE = BoltNetwork.Instantiate(BoltPrefabs.Projectile, transform.position, Quaternion.identity); BE.transform.LookAt(transform.position + cmd.Input.shootDirection); BE.GetComponent <ProjectileController>().state.frame = cmd.ServerFrame; } else { GameObject GO = GameObject.Instantiate(projectile, transform.position, Quaternion.identity); GO.transform.LookAt(transform.position + cmd.Input.shootDirection); GO.GetComponent <ProjectileFakeController>().frame = cmd.ServerFrame; } } } if (cmd.Input.forward) { _cc.Move(Vector3.forward * Time.fixedDeltaTime * 10f); } else if (cmd.Input.back) { _cc.Move(Vector3.back * Time.fixedDeltaTime * 10f); } if (cmd.Input.left) { _cc.Move(Vector3.left * Time.fixedDeltaTime * 10f); } else if (cmd.Input.right) { _cc.Move(Vector3.right * Time.fixedDeltaTime * 10f); } cmd.Result.position = transform.position; } }
public override void StreamDataReceived(BoltConnection connection, UdpStreamData data) { int o = 0; BoltEntity boltEntity = BoltNetwork.FindEntity(new NetworkId(Blit.ReadU64(data.Data, ref o))); if (boltEntity.IsAttached()) { CoopVoice component = boltEntity.GetComponent <CoopVoice>(); if (component) { component.ReceiveVoiceData(data.Data, o); } } }
public override void OnEvent(PlaceConstruction evnt) { BoltEntity boltEntity = BoltNetwork.Instantiate(evnt.PrefabId, evnt.Position, evnt.Rotation); if (boltEntity.GetComponent <TreeStructure>()) { boltEntity.GetComponent <TreeStructure>().TreeId = evnt.TreeIndex; } if (evnt.Parent) { boltEntity.transform.parent = evnt.Parent.transform; } if (evnt.AboveGround) { FoundationArchitect component = boltEntity.GetComponent <FoundationArchitect>(); if (component) { component._aboveGround = evnt.AboveGround; } } boltEntity.SendMessage("OnDeserialized", SendMessageOptions.DontRequireReceiver); LocalPlayer.Create.RefreshGrabber(); }
public override void SceneLoadLocalDone(string map) { //instantiate the player BoltEntity entity = BoltNetwork.Instantiate(BoltPrefabs.PlayerPrefab); PlayerState ps = entity.GetComponent <PlayerState>(); ps.Name = GameManager.instance.CurrentUserName; //set their name ps.Team = GameManager.instance.Lobby.GetTeamLookup()[GameManager.instance.CurrentUserName]; if (!BoltNetwork.isServer) { entity.AssignControl(BoltNetwork.server); //this line is completely useless and should be removed } DebugHUD.setValue("load state", "Scene loaded, unsynced"); //the scene has now been loaded for this player, but we have not synchronized the players yet }
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); } } }
private CoopComponentDisabler InitCCD(BoltEntity entity) { CoopComponentDisabler coopComponentDisabler = entity.GetComponent<CoopComponentDisabler>(); if (!coopComponentDisabler) { coopComponentDisabler = entity.gameObject.AddComponent<CoopComponentDisabler>(); } return coopComponentDisabler; }