public void ServerPlayerDropGrenades(Server server, PlayerObjectComponent playerObjectComponent, int grenadeSlotIndex) { var playerGrenadeSlots = playerObjectComponent.State.GrenadeSlots; var grenadeSlot = playerGrenadeSlots[grenadeSlotIndex]; if ((grenadeSlot == null) || (grenadeSlot.GrenadeCount == 0)) { return; } for (var i = 0; i < grenadeSlot.GrenadeCount; i++) { var grenadeState = new GrenadeState { Id = server.GenerateNetworkId(), Type = grenadeSlot.GrenadeType, RigidBodyState = new RigidBodyState { Position = playerObjectComponent.HandsPointObject.transform.position, EulerAngles = Vector3.zero, Velocity = Vector3.zero, AngularVelocity = Vector3.zero }, IsActive = false, TimeUntilDetonation = null }; GrenadeSpawnerSystem.Instance.SpawnLocalGrenadeObject(grenadeState); } playerGrenadeSlots[grenadeSlotIndex] = null; }
public void ServerSpawnGrenade(Server server, GrenadeSpawnerState grenadeSpawnerState) { if (grenadeSpawnerState.TimeUntilNextSpawn > 0) { return; } var weaponDefinition = GrenadeSystem.Instance.GetGrenadeDefinitionByType(grenadeSpawnerState.Type); var weaponSpawnerComponent = FindGrenadeSpawnerComponent(grenadeSpawnerState.Id); var weaponObjectState = new GrenadeState { Id = server.GenerateNetworkId(), Type = grenadeSpawnerState.Type, RigidBodyState = new RigidBodyState { Position = weaponSpawnerComponent.transform.position, EulerAngles = weaponSpawnerComponent.transform.eulerAngles, Velocity = Vector3.zero, AngularVelocity = Vector3.zero }, IsActive = false, GrenadeSpawnerId = grenadeSpawnerState.Id }; SpawnLocalGrenadeObject(weaponObjectState); }
void Update() { if (CurrentGrenadeState == GrenadeState.InPool) { transform.position = FindObjectOfType <PoolManager> ().PoolManagerPosition; hasBeenShooted = false; ReduceExplosionRadius(); } if (CurrentGrenadeState == GrenadeState.InScene) { timer += Time.deltaTime; transform.localScale += new Vector3(enlargment, enlargment, enlargment); if (hasBeenShooted == false) { rb.velocity = direction * grenadeSpeed; hasBeenShooted = true; } if (timer >= 1.5f) { Explode(); CurrentGrenadeState = GrenadeState.InPool; timer = 0f; } } }
private void ApplyStateFromServer(object newState) { var newGrenadeState = (GrenadeState)newState; Client.ApplyRigidbodyState( newGrenadeState.RigidBodyState, State.RigidBodyState, Rigidbody, OsFps.Instance.Client.ClientPeer.RoundTripTimeInSeconds ?? 0 ); State = newGrenadeState; }
public Grenades(Vector2 parent_position, float angle) { this.position = parent_position; dimensions = new Vector2(16, 16); velocity = new Vector2((float)(8 * Math.Cos(angle)), (float)(8 * Math.Sin(angle))); state = GrenadeState.Travel; active = false; active_timer = 0.0f; explosion_timer = 0.0f; nextStep_temp = Vector2.Zero; on_wall = false; }
void Start() { CurrentGrenadeState = GrenadeState.InPool; rb = gameObject.GetComponent <Rigidbody> (); if (!gameObject.GetComponent <Rigidbody> ()) { rb = gameObject.AddComponent <Rigidbody> (); } rb.freezeRotation = true; grenadeSpeed = 15f; enlargment = 0.01f; explosionForce = 0.025f; hasBeenShooted = false; timer = 0f; }
public GameObject SpawnLocalGrenadeObject(GrenadeState grenadeState) { var grenadePrefab = GrenadeSystem.Instance.GetGrenadeDefinitionByType(grenadeState.Type).Prefab; var grenadeObject = GameObject.Instantiate( grenadePrefab, grenadeState.RigidBodyState.Position, Quaternion.Euler(grenadeState.RigidBodyState.EulerAngles) ); var grenadeComponent = grenadeObject.GetComponent <GrenadeComponent>(); grenadeComponent.State = grenadeState; var rigidbody = grenadeComponent.Rigidbody; rigidbody.velocity = grenadeState.RigidBodyState.Velocity; rigidbody.angularVelocity = grenadeState.RigidBodyState.AngularVelocity; return(grenadeObject); }
public void ServerPlayerThrowGrenade(Server server, PlayerObjectComponent playerObjectComponent) { var playerObjectState = playerObjectComponent.State; if (!playerObjectState.CanThrowGrenade) { return; } var throwRay = GetShotRay(playerObjectComponent); throwRay.origin += (0.5f * throwRay.direction); var currentGrenadeSlot = playerObjectState.GrenadeSlots[playerObjectState.CurrentGrenadeSlotIndex]; var grenadeState = new GrenadeState { Id = server.GenerateNetworkId(), Type = currentGrenadeSlot.GrenadeType, IsActive = true, TimeUntilDetonation = null, RigidBodyState = new RigidBodyState { Position = throwRay.origin, EulerAngles = Quaternion.LookRotation(throwRay.direction, Vector3.up).eulerAngles, Velocity = OsFps.GrenadeThrowSpeed * throwRay.direction, AngularVelocity = Vector3.zero }, ThrowerPlayerId = playerObjectState.Id }; var grenadeObject = GrenadeSpawnerSystem.Instance.SpawnLocalGrenadeObject(grenadeState); // Make grenade ignore collisions with thrower. GameObjectExtensions.IgnoreCollisionsRecursive(grenadeObject, playerObjectComponent.gameObject); currentGrenadeSlot.GrenadeCount--; playerObjectState.TimeUntilCanThrowGrenade = OsFps.GrenadeThrowInterval; }
public void update(LevelState parentWorld, GameTime currentTime, Entity parent) { active_timer += currentTime.ElapsedGameTime.Milliseconds; if (active) { switch (state) { case GrenadeState.Travel: if (active_timer > max_active_time) { state = GrenadeState.Explosion; active_timer = 0.0f; dimensions = new Vector2(96, 96); position = CenterPoint - (dimensions / 2); } else { nextStep_temp = new Vector2(position.X - (dimensions.X / 2) + velocity.X, (position.Y + velocity.X)); on_wall = parentWorld.Map.hitTestWall(nextStep_temp); int check_corners = 0; while (check_corners != 4) { if (on_wall == false) { if (check_corners == 0) { nextStep_temp = new Vector2(position.X + (dimensions.X / 2) + velocity.X, position.Y + velocity.Y); } else if (check_corners == 1) { nextStep_temp = new Vector2(position.X + velocity.X, position.Y - (dimensions.Y / 2) + velocity.Y); } else if (check_corners == 2) { nextStep_temp = new Vector2(position.X + velocity.X, position.Y + dimensions.Y + velocity.Y); } else { position += velocity; } on_wall = parentWorld.Map.hitTestWall(nextStep_temp); } else { state = GrenadeState.Explosion; AudioLib.playSoundEffect("testExplosion"); active_timer = 0.0f; dimensions = new Vector2(96, 96); position = position - (dimensions / 2); break; } check_corners++; } } if (on_wall == false) { foreach (Entity en in parentWorld.EntityList) { if (en == parent) { continue; } else if (grenadeHitTest(en)) { state = GrenadeState.Explosion; active_timer = 0.0f; dimensions = new Vector2(96, 96); position = position - (dimensions / 2); AudioLib.playSoundEffect("testExplosion"); break; } } } position += velocity; break; case GrenadeState.Explosion: explosion_timer += currentTime.ElapsedGameTime.Milliseconds; foreach (Entity en in parentWorld.EntityList) { if (grenadeHitTest(en)) { Vector2 direction = en.CenterPoint - CenterPoint; en.knockBack(direction, 3.0f, 10); } } if (explosion_timer > max_explosion_timer) { active_timer = 0.0f; state = GrenadeState.Reset; } break; case GrenadeState.Reset: dimensions = new Vector2(16, 16); position = new Vector2(0, 0); active = false; break; } } }