private void OnTriggerProjectile(BaseEventParameters baseParams) { float ownerLocalScaleX = m_Owner.transform.localScale.x; GameObject projectile = GameObject.Instantiate(m_Config.m_ProjectilePrefab, m_ProjectileHook.position, Quaternion.AngleAxis(m_Config.m_ProjectileAngle, Vector3.forward * ownerLocalScaleX)); projectile.transform.localScale = new Vector3(ownerLocalScaleX, projectile.transform.localScale.y, projectile.transform.localScale.z); ProjectileComponent projectileComponent = projectile.GetComponentInChildren <ProjectileComponent>(); if (projectileComponent) { projectileComponent.OnInit(this, m_Config); m_MyProjectile = projectileComponent; } else { KakutoDebug.LogError("ProjectileComponent could not be found on " + projectile); GameObject.Destroy(projectile); } if (m_IsGuardCrush) { SetNextNonSuperProjectileGuardCrush(m_InfoComponent.GetPlayerIndex(), false); PlayerGuardCrushTriggerAttackLogic.SetTriggerPointStatus(m_InfoComponent, PlayerGuardCrushTriggerAttackLogic.ETriggerPointStatus.Inactive); } }
private static bool HitTargetsCooldownLogic(ProjectileComponent actor, Component target, GameTime gameTime) //TODO f**k this gives me headaches { if (!actor.IsPhasing) { return(false); } ProjectileComponent.HitTarget foundTarget = null; foreach (var hitTarget in actor.HitTargets) { if (hitTarget.Component.Equals(target)) { foundTarget = hitTarget; break; } } if (foundTarget == null) { actor.HitTargets.Add(new ProjectileComponent.HitTarget(target, true, new TimerComponent(TimerType.Flag, gameTime, actor.HitCooldownMilliseconds))); } else if (actor.HasHitCooldown && foundTarget.Cooldown.Over) { foundTarget.Cooldown = new TimerComponent(TimerType.Flag, gameTime, actor.HitCooldownMilliseconds); } else { return(true); //Target was found and is on cooldown } return(false); }
public virtual void Init(ProjectileComponent projector, Vector2 relativePosition, float relativeDirection) { owner = projector.owner; MovementComponent ownerMovement = owner.GetComponent <MovementComponent>(); MovementComponent movement = GetComponent <MovementComponent>(); target = owner.target; switch (projector.targetType) { case ProjectileComponent.TargetType.LOCATION: { movement.Direction = VEasyCalculator.GetDirection(owner.transform.position, projector.targetPosition) + relativeDirection; } break; case ProjectileComponent.TargetType.UNIT: { } break; case ProjectileComponent.TargetType.NONE: { movement.Direction = ownerMovement.Direction + relativeDirection; } break; } gameObject.transform.position = owner.transform.position + new Vector3(relativePosition.x, relativePosition.y, 0); }
private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args) { // This is so entities that shouldn't get a collision are ignored. if (args.OurFixture.ID != ProjectileFixture || !args.OtherFixture.Hard || component.DamagedEntity) { return; } var otherEntity = args.OtherFixture.Body.Owner; var modifiedDamage = _damageableSystem.TryChangeDamage(otherEntity, component.Damage); component.DamagedEntity = true; if (modifiedDamage is not null && EntityManager.EntityExists(component.Shooter)) { _adminLogger.Add(LogType.BulletHit, HasComp <ActorComponent>(otherEntity) ? LogImpact.Extreme : LogImpact.High, $"Projectile {ToPrettyString(component.Owner):projectile} shot by {ToPrettyString(component.Shooter):user} hit {ToPrettyString(otherEntity):target} and dealt {modifiedDamage.Total:damage} damage"); } _guns.PlayImpactSound(otherEntity, modifiedDamage, component.SoundHit, component.ForceSound); // Damaging it can delete it if (HasComp <CameraRecoilComponent>(otherEntity)) { var direction = args.OurFixture.Body.LinearVelocity.Normalized; _cameraRecoil.KickCamera(otherEntity, direction); } if (component.DeleteOnCollide) { QueueDel(uid); } }
ProjectileComponent DecorateProjectile(ProjectileComponent projectileComponent) { switch (projectileComponent.projectile.type) { case ProjectileType.Fireball: { projectileComponent.projectile.OnDamageDealt.Add(() => { Instantiate( this.explosionPrefab, projectileComponent.transform.position, Quaternion.identity ); }); break; } case ProjectileType.Smite: { projectileComponent.projectile.OnDamageDealt.Add(() => { Instantiate( this.smitePrefab, projectileComponent.transform.position, Quaternion.identity ); }); break; } } return(projectileComponent); }
public void HandleCollision(CollisionComponent actor, CollisionComponent target, GameTime gameTime) { if (actor.Allegiance == target.Allegiance || !actor.CollisionRectangle.Intersects(target.CollisionRectangle)) { return; } if (actor.Bindings.TryGetValue(typeof(ProjectileComponent), out var actorProjectileBinding)) { ProjectileComponent actorProjectileComponent = actorProjectileBinding as ProjectileComponent; if (target.Bindings.TryGetValue(typeof(ProjectileComponent), out var targetProjectileComponent)) { if (HitTargetsCooldownLogic(actorProjectileComponent, target, gameTime)) { return; } ProjectileOnProjectile(actorProjectileComponent, targetProjectileComponent as ProjectileComponent); } if (target.Bindings.TryGetValue(typeof(HealthComponent), out var targetHealthComponent)) { if (HitTargetsCooldownLogic(actorProjectileComponent, target, gameTime)) { return; } ProjectileOnHealth(actorProjectileComponent, targetHealthComponent as HealthComponent); } } }
public void fireProjectile(UnitComponent.EventArgsFireProjectile args) { foreach (ProjectileComponent pc in projectiles) { ProjectileComponent newProjectile = (ProjectileComponent)Instantiate(pc, transform.position, transform.rotation); newProjectile.FireProjectile(args); } }
public void Fire() { foreach (GameObject point in shootPoints) { ProjectileComponent bullet = Instantiate(bulletPrefab, point.transform.position, point.transform.rotation).GetComponent <ProjectileComponent>(); bullet.mainRB.AddForce(transform.up * 100); bullet.parentShip = this.transform.parent.gameObject; } }
public AttachedVfxModifier(ModifierInfo info, Entity casterEntity, Entity targetEntity, Environment environment, CollectionOfInteractions modifierInteractionCollection, ProjectileComponent projectile) : base(info, casterEntity, targetEntity, environment, modifierInteractionCollection) { this.projectile = projectile; projectileDirectionAtAttachment = projectile.Entity.GetComponent <ProjectileTrajectoryComponent>() .ShowTrajectoryDirection().ToLeftOrRightDirectionEnum(); }
public void PlayerOneFireball() { if (wizard1.IsRemoved == false) { ProjectileComponent magicball = AddProjectile(wizard1, "magicball", 1); magicball.Body.Restitution = .8f; magicball.OverlayColor = Color.Violet; } }
private void OnHandleState(EntityUid uid, ProjectileComponent component, ref ComponentHandleState args) { if (args.Current is not ProjectileComponentState state) { return; } component.Shooter = state.Shooter; component.IgnoreShooter = state.IgnoreShooter; }
public override void Process(Entity entity) { ProjectileComponent pc = entity.GetComponent <ProjectileComponent>(); if (DateTime.UtcNow.Subtract(pc.Birth) > pc.LifeSpan) { pc.Alive = false; entity.Delete(); } }
public static Source FromSkill(Skill skill, SkillId skillId, ProjectileComponent projectile) { return(new SourceFromSkill() { type = SourceType.Skill, value = skill, skillId = skillId, projectile = projectile }); }
private void Awake() { projectileClass = projectile.GetComponent <ProjectileComponent>(); audioSource = GetComponent <AudioSource>(); if (trackAmmo) { ammoText = GameObject.FindGameObjectWithTag("AmmoText").GetComponent <Text>(); } }
public virtual void OnProjectileHitTargets(ProjectileComponent projectile, List <Character> hitTargets, List <float> weights, List <Vector2> impactPositions) { if (IsProjectileTriggerNextPhase(projectile)) { SwitchToNextPhase(); } }
private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args) { // This is so entities that shouldn't get a collision are ignored. if (!args.OtherFixture.Hard || component.DamagedEntity) { return; } var otherEntity = args.OtherFixture.Body.Owner; var coordinates = EntityManager.GetComponent <TransformComponent>(args.OtherFixture.Body.Owner).Coordinates; var playerFilter = Filter.Pvs(coordinates); if (!EntityManager.GetComponent <MetaDataComponent>(otherEntity).EntityDeleted&& component.SoundHitSpecies != null && EntityManager.HasComponent <SharedBodyComponent>(otherEntity)) { SoundSystem.Play(playerFilter, component.SoundHitSpecies.GetSound(), coordinates); } else { var soundHit = component.SoundHit?.GetSound(); if (!string.IsNullOrEmpty(soundHit)) { SoundSystem.Play(playerFilter, soundHit, coordinates); } } if (!EntityManager.GetComponent <MetaDataComponent>(otherEntity).EntityDeleted) { var dmg = _damageableSystem.TryChangeDamage(otherEntity, component.Damage); component.DamagedEntity = true; if (dmg is not null && EntityManager.EntityExists(component.Shooter)) { _adminLogSystem.Add(LogType.BulletHit, HasComp <ActorComponent>(otherEntity) ? LogImpact.Extreme : LogImpact.High, $"Projectile {ToPrettyString(component.Owner):projectile} shot by {ToPrettyString(component.Shooter):user} hit {ToPrettyString(otherEntity):target} and dealt {dmg.Total:damage} damage"); } } // Damaging it can delete it if (!EntityManager.GetComponent <MetaDataComponent>(otherEntity).EntityDeleted&& EntityManager.HasComponent <CameraRecoilComponent>(otherEntity)) { var direction = args.OurFixture.Body.LinearVelocity.Normalized; _cameraRecoil.KickCamera(otherEntity, direction); } if (component.DeleteOnCollide) { EntityManager.QueueDeleteEntity(uid); } }
private void ApplyKnockback(ProjectileComponent actor, BindableComponent target) { if (actor.Bindings.TryGetValue(typeof(MovementComponent), out var actorBinding)) { if (target.Bindings.TryGetValue(typeof(MovementComponent), out var targetBinding)) { MovementComponent actorMovement = actorBinding as MovementComponent; MovementComponent targetMovement = targetBinding as MovementComponent; targetMovement.Speed.SetVector2(new Coord2(actorMovement.Speed.Cartesian).ChangePolarLength(actor.Knockback).Cartesian); } } }
private void Start() { // Ensure the interface and projectile component are attached to the ball m_interface = GetComponent <InfoUI>(); Assert.IsNotNull(m_interface, "ERROR: InfoUI is not attached!"); m_projectile = GetComponent <ProjectileComponent>(); Assert.IsNotNull(m_projectile, "ERROR: ProjectileComponent is not attached!"); // Update the HUD with starting information m_interface.OnRequestUpdateUI(m_iGoals, m_iMisses, m_projectile.m_fLaunchPower, m_projectile.m_iVerticalAngle, m_projectile.m_iHorizontalAngle, m_bGoalScored); }
private void ProjectileOnHealth(ProjectileComponent actor, HealthComponent target) { if (target.Invincible) { return; } if (actor.Power >= actor.Damage) //actor can afford full strike { if (target.ProcessedHealth >= actor.Damage) //target can afford full strike { target.ProcessedHealth -= actor.Damage; actor.Power -= actor.Damage; } else //target takes partial strike { actor.Power -= target.ProcessedHealth; target.ProcessedHealth = 0; } } else //actor can only afford partial strike { if (target.ProcessedHealth >= actor.Power) //target can afford full strike { target.ProcessedHealth -= actor.Power; actor.Power = 0; } else //target takes partial strike { actor.Power -= target.ProcessedHealth; target.ProcessedHealth = 0; } } if (actor.Power <= 0) { actor.CurrentEntityState.Dead = true; } if (target.ProcessedHealth <= 0) { target.CurrentEntityState.Dead = true; } else { if (!actor.IsPhasing) { actor.CurrentEntityState.Dead = true; //projectile didnt penetrate } ApplyKnockback(actor, target); } SoundEffect effect = Assets.GetSound("Schlag"); effect.Play(); }
private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args) { // This is so entities that shouldn't get a collision are ignored. if (!args.OtherFixture.Hard || component.DamagedEntity) { return; } var otherEntity = args.OtherFixture.Body.Owner; var coordinates = args.OtherFixture.Body.Owner.Transform.Coordinates; var playerFilter = Filter.Pvs(coordinates); if (!otherEntity.Deleted && component.SoundHitSpecies != null && otherEntity.HasComponent <SharedBodyComponent>()) { SoundSystem.Play(playerFilter, component.SoundHitSpecies.GetSound(), coordinates); } else { var soundHit = component.SoundHit?.GetSound(); if (!string.IsNullOrEmpty(soundHit)) { SoundSystem.Play(playerFilter, soundHit, coordinates); } } if (!otherEntity.Deleted && otherEntity.TryGetComponent(out IDamageableComponent? damage)) { EntityManager.TryGetEntity(component.Shooter, out var shooter); foreach (var(damageTypeID, amount) in component.Damages) { damage.TryChangeDamage(_prototypeManager.Index <DamageTypePrototype>(damageTypeID), amount); } component.DamagedEntity = true; } // Damaging it can delete it if (!otherEntity.Deleted && otherEntity.TryGetComponent(out CameraRecoilComponent? recoilComponent)) { var direction = args.OurFixture.Body.LinearVelocity.Normalized; recoilComponent.Kick(direction); } if (component.DeleteOnCollide) { EntityManager.QueueDeleteEntity(uid); } }
void HandleCollision(Collider2D collision) { if (isActiveAndEnabled && m_Collider.isActiveAndEnabled) { if (collision.CompareTag(Utils.GetEnemyTag(m_PlayerTag)) && collision.gameObject != gameObject) // Collision with an enemy player { #if UNITY_EDITOR || DEBUG_DISPLAY if (!collision.gameObject.GetComponent <PlayerHurtBoxHandler>()) { KakutoDebug.LogError("Projectile has collided with something else than HurtBox !"); } #endif if (m_Logic != null) { m_Logic.OnHandleCollision(true, true, m_Collider, collision); PlaySFX(EProjectileSFXType.Impact); if (m_Config.m_ApplyConstantSpeedOnPlayerHit) { m_KeepConstantSpeedUntilFrame = Time.frameCount + m_Config.FramesToKeepProjectileAtConstantSpeed; } if (m_Logic.GetCurrentHitCount() >= m_Logic.GetMaxHitCount()) { RequestProjectileDestruction(); } } } else if (collision.CompareTag(gameObject.tag) && collision.gameObject != gameObject) // Collision with another projectile { ProjectileComponent collisionProjectile = collision.gameObject.GetComponent <ProjectileComponent>(); if (collisionProjectile != null && collisionProjectile.GetLogic().GetOwner().CompareTag(Utils.GetEnemyTag(m_PlayerTag))) // Collision with an enemy projectile { m_Logic.OnHandleCollision(false, false, m_Collider, collision); PlaySFX(EProjectileSFXType.Impact); if (m_Config.m_ApplyConstantSpeedOnProjectileHit) { m_KeepConstantSpeedUntilFrame = Time.frameCount + m_Config.FramesToKeepProjectileAtConstantSpeed; } if (m_Logic.GetCurrentHitCount() >= m_Logic.GetMaxHitCount()) { RequestProjectileDestruction(); } } } else if (collision.CompareTag(K_GROUND_TAG)) // Collision with Ground { RequestProjectileDestruction(); } } }
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { ProjectileComponent projectile = animator.GetComponentInChildren <ProjectileComponent>(); if (projectile != null) { projectile.OnEndOfDestructionAnim(); } else { KakutoDebug.LogError("ProjectileComponent has not been found."); } }
public override void OnAttackLaunched() { m_IsGuardCrush = !IsASuper() && IsNextNonSuperProjectileGuardCrush(m_InfoComponent.GetPlayerIndex()); // Need to be before base.OnAttackLaunched for GetAnimationAttackName() // If a projectile is launched before the previous one has been completely destroyed // stop listening previous callback as it won't be stopped in OnProjectileDestroyed as m_MyProjectile will be replaced if (m_MyProjectile != null) { Utils.GetEnemyEventManager(m_Owner).StopListening(EPlayerEvent.DamageTaken, OnEnemyTakesDamage); m_MyProjectile = null; } base.OnAttackLaunched(); Utils.GetPlayerEventManager(m_Owner).StartListening(EPlayerEvent.TriggerProjectile, OnTriggerProjectile); }
private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args) { // This is so entities that shouldn't get a collision are ignored. if (!args.OtherFixture.Hard || component.DamagedEntity) { return; } var coordinates = args.OtherFixture.Body.Owner.Transform.Coordinates; var playerFilter = Filter.Pvs(coordinates); if (args.OtherFixture.Body.Owner.TryGetComponent(out IDamageableComponent? damage) && component.SoundHitSpecies != null) { SoundSystem.Play(playerFilter, component.SoundHitSpecies, coordinates); }
private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args) { // This is so entities that shouldn't get a collision are ignored. if (!args.OtherFixture.Hard || component.DamagedEntity) { return; } var otherEntity = args.OtherFixture.Body.Owner; var coordinates = args.OtherFixture.Body.Owner.Transform.Coordinates; var playerFilter = Filter.Pvs(coordinates); if (!otherEntity.Deleted && component.SoundHitSpecies != null && otherEntity.HasComponent <SharedBodyComponent>()) { SoundSystem.Play(playerFilter, component.SoundHitSpecies.GetSound(), coordinates); } else { var soundHit = component.SoundHit?.GetSound(); if (!string.IsNullOrEmpty(soundHit)) { SoundSystem.Play(playerFilter, soundHit, coordinates); } } if (!otherEntity.Deleted) { _damageableSystem.TryChangeDamage(otherEntity.Uid, component.Damage); component.DamagedEntity = true; // "DamagedEntity" is misleading. Hit entity may be more accurate, as the damage may have been resisted // by resistance sets. } // Damaging it can delete it if (!otherEntity.Deleted && otherEntity.TryGetComponent(out CameraRecoilComponent? recoilComponent)) { var direction = args.OurFixture.Body.LinearVelocity.Normalized; recoilComponent.Kick(direction); } if (component.DeleteOnCollide) { EntityManager.QueueDeleteEntity(uid); } }
private void OnProjectileDestroyed(BaseEventParameters baseParams) { ProjectileDestroyedEventParameters projectileDestroyedParams = (ProjectileDestroyedEventParameters)baseParams; ProjectileComponent destroyedProjectile = projectileDestroyedParams.m_Projectile; if (m_CurrentProjectile != null && m_CurrentProjectile == destroyedProjectile) { // If the attack's launched and teleport has not been requested yet if (m_AttackLaunched && !m_TeleportRequested) { // Save the last know projectile position m_LastProjectilePosition = m_CurrentProjectile.transform.position; } m_CurrentProjectile = null; } }
public void Use(Actor by, Coord target) { Direction fireDirection = Direction.GetDirection(by.Parent.Position, target); Coord spawnPos = by.Parent.Position + fireDirection; GameObject projectile = new UpdatingGameObject(spawnPos, Layers.Main, null, by.GameObject.Timeline); Characters[] alignChars = new[] {Characters.VERTICAL_LINE, Characters.SLASH, Characters.HYPHEN, Characters.BACK_SLASH, Characters.VERTICAL_LINE, Characters.SLASH, Characters.HYPHEN, Characters.BACK_SLASH}; int dX = target.X - spawnPos.X; int dY = target.Y - spawnPos.Y; int dist = (int) Distance.MANHATTAN.Calculate(dX, dY); int speed = 30; int xVel = dX == 0 ? 0 : speed * dist / dX; int yVel = dY == 0 ? 0 : speed * dist / dY; Damagable damagable = new Damagable(1); projectile.AddComponent(damagable); projectile.AddComponent(new GlyphComponent(new Glyph(alignChars[(int) fireDirection.Type], Color.SaddleBrown))); projectile.AddComponent(new NameComponent(new Title("an", "arrow"))); ProjectileComponent projectileComponent = new ProjectileComponent(xVel, yVel, damagable); projectileComponent.OnCollide += (gameObject) => { EffectTarget effectTarget = gameObject?.GetComponent<EffectTargetComponent>()?.EffectTarget; effectTarget?.ApplyEffect(new DamageEffect(_damage)); by.MainBus.Send(new ParticleEvent(new GlyphFlash(new Glyph(Characters.ASTERISK, Color.Red), 200, gameObject.Position))); if(gameObject.GetComponent<NameComponent>() is NameComponent nameComponent) by.MainBus.Send(new LogMessage($"{{0}} was hit by {{1}}'s arrow", new LogLink(nameComponent.Title.ToString(), Color.Aquamarine, by), new LogLink(by.Being.Name, Color.Aquamarine, by))); }; projectile.AddComponent(projectileComponent); by.MainBus.Send(new SpawnEvent(projectile)); }
public override void Update(float dt) { foreach (Entity entity in _projectileSyncEntities) { ProjectileComponent projectileComp = entity.GetComponent <ProjectileComponent>(); Console.WriteLine(projectileComp.Color.ToString()); if (entity.HasComponent <VectorSpriteComponent>()) { entity.GetComponent <VectorSpriteComponent>().ChangeColor(projectileComp.Color); } if (entity.HasComponent <ColoredExplosionComponent>()) { entity.GetComponent <ColoredExplosionComponent>().Color = projectileComp.Color; } } }
public void AcceptDamage(ProjectileComponent projectile) { if (partyMember != null && !projectile.friendly) { if (partyMember.Damage(projectile.damage)) { Destroy(projectile.gameObject); } } else if (worldItem != null && projectile.friendly) { if (worldItem.Damage(projectile.damage)) { Destroy(projectile.gameObject); } } }
public void FireProjectile(Vector3 _startPosition, Vector3 _target, float _speed) { //Find disabled object and fire it towards target ProjectileComponent availableProjectile = m_projectileList.Find(x => !x.gameObject.activeInHierarchy); if (availableProjectile != null) { availableProjectile.gameObject.SetActive(true); availableProjectile.transform.position = _startPosition; Vector3 direction = (_target - _startPosition).normalized; availableProjectile.FireProjectile(direction, _speed); } else { Debug.LogWarning("Projectile not fired because no active projectile was found in the scene"); } }