Пример #1
0
        public void SetTarget(Entity target)
        {
            if (Target != null)
            {
                return;
            }

            Target = target;

            _moveComp = Target.GetComponent <HexMovementComp>();
            movementGroup.SetActive(_moveComp != null);
            if (_moveComp != null)
            {
                _moveComp.MovementChanged += OnMovementChanged;
                OnMovementChanged();
            }

            _vitalityComp = Target.GetComponent <VitalityComp>();
            vitalityGroup.SetActive(_vitalityComp != null);
            if (_vitalityComp != null)
            {
                _vitalityComp.HealthChanged += OnHealthChanged;
                OnHealthChanged();
            }

            _weaponComp = Target.GetComponent <WeaponComp>();
            weaponGroup.SetActive(false);
            if (_weaponComp != null)
            {
                _weaponComp.StatusChanged += OnWeaponStatusChanged;
                UpdateWeapon();
            }

            nameText.text = Target.name;
        }
        private static void ExecuteAttack(Entity entity)
        {
            var combat = entity.GetComponent <TargetComp>();

            var weaponsToShoot = combat.GetComponent <ShipFittingsComp>().fittingList;

            foreach (var fitting in weaponsToShoot.Where(x => x.IsEnabled))
            {
                WeaponComp selectedWeapon = fitting.FittedWeapon;
                if (selectedWeapon == null || !UnitCanAttack(selectedWeapon))
                {
                    return;
                }

                bool attacked = FireProjectile(selectedWeapon, entity.Wrapper.transform.forward);

                if (!attacked)
                {
                    return;
                }

                PlayAttackNoise(selectedWeapon);
                SetNextAttackTime(selectedWeapon);
            }
        }
Пример #3
0
    // Use this for initialization
    void Awake()
    {
        Health = GetComponent <PlayerHealth>();
        if (Health == null)
        {
            Health = gameObject.AddComponent <PlayerHealth>();
            //Debug.LogError(name + " HealthComponent added with DEFAULT VALUES");
        }

        Move = GetComponent <Movement>();
        if (Move == null)
        {
            Move = gameObject.AddComponent <Movement>();
            //Debug.LogError(name + " Movement component added with DEFAULT VALUES");
        }

        CameraMove = GetComponent <CameraMovement>();
        if (CameraMove == null)
        {
            //Debug.LogError(name + " Camera follow script is NULL");
        }

        Weapon = GetComponent <WeaponComp>();
        if (Weapon == null)
        {
            //Debug.LogError(name + " Weapon Component script is NULL");
        }

        SFX = GetComponent <AudioSource>();
        if (SFX == null)
        {
            //Debug.LogError(name + " AudioSource is NULL");
        }
    }
 private static void PlayAttackNoise(WeaponComp weapon)
 {
     if (weapon.Owner.HasComponent(ComponentTypes.AudioSourceComp))
     {
         weapon.Owner.GetComponent <AudioSourceComp>().TriggerSfx(weapon.FiringSoundEffect);
     }
 }
        /// <summary>
        /// Make sure bullets don't immediately collide with their firing entity
        /// </summary>
        /// <param name="firer"></param>
        /// <param name="projectile"></param>
        private static void IgnoreProjectileCollisions(WeaponComp firer, GameObject projectile)
        {
            var projectileCollider = projectile.GetComponentInChildren <Collider>();

            foreach (var col in firer.Owner.Wrapper.GetComponentsInChildren <Collider>())
            {
                Physics.IgnoreCollision(projectileCollider, col);
            }
        }
        public void FireProjectile(WeaponComp attacker, Transform target)
        {
            if (target == null)
            {
                return;
            }
            line.enabled       = true;
            line.useWorldSpace = true;
            line.SetPosition(0, attacker.Owner.GetComponent <PositionComp>().Position);
            line.SetPosition(1, target.position);

            Timing.KillCoroutines(gameObject.GetInstanceID());
            Timing.RunCoroutine(DisableLaser(), gameObject.GetInstanceID());
        }
        private static void CreateLaserInfoPacket(WeaponComp selectedWeapon, PositionComp pc, Vector3 direction)
        {
            //laser info packet laser fire type wrong
            LaserComp lc = (LaserComp)selectedWeapon;

            lc.laserInfoPacket.TimeToLive    = selectedWeapon.AttackRange / selectedWeapon.ProjectileSpeed;
            lc.laserInfoPacket.fireDirection = direction;
            lc.laserInfoPacket.StartPosition = pc.transform.TransformPoint(
                selectedWeapon.fittingAttached.PositionOffset + selectedWeapon.fittingAttached.ProjectileSpawnPositionOffset);
            lc.laserInfoPacket.OwningActorPos   = pc;
            lc.laserInfoPacket.FiringWeaponComp = selectedWeapon;
            lc.laserInfoPacket.ProjectileSpeed  = selectedWeapon.ProjectileSpeed;
            //lc.laserInfoPacket.laserFireType = lc.laserInfoPacket.laserFireType;
        }
Пример #8
0
    public void AddWeaponToPlayer(GameObject Player)
    {
        WeaponComp WeaponComponent = Player.GetComponent <WeaponComp>();

        if (WeaponComponent == null)
        {
            return;
        }

        WeaponComponent.AddWeapon(WeaponToAdd, this);

        if (switchToNewWeapon)
        {
            WeaponComponent.SwitchWeapon(true);
        }
    }
        private static void CreateMissileInfoPacket(WeaponComp selectedWeapon, PositionComp pc, Vector3 direction)
        {
            MissileComp mc = (MissileComp)selectedWeapon;

            if (mc.missileInfoPacket.TimeToLive.IsAlmost(-1f))
            {
                mc.missileInfoPacket.TimeToLive = selectedWeapon.AttackRange / selectedWeapon.ProjectileSpeed;
            }
            mc.missileInfoPacket.fireDirection = direction;
            mc.missileInfoPacket.StartPosition = pc.transform.TransformPoint(
                selectedWeapon.fittingAttached.PositionOffset + selectedWeapon.fittingAttached.ProjectileSpawnPositionOffset);
            mc.missileInfoPacket.OwningActorPos   = pc;
            mc.missileInfoPacket.FiringWeaponComp = selectedWeapon;
            mc.missileInfoPacket.FlightSpeed      = mc.ProjectileSpeed;
            mc.missileInfoPacket.target           = mc.GetComponent <TargetComp>().target;
        }
Пример #10
0
    void Awake()
    {
        if (!Health)
        {
            Health = GetComponent <PlayerHealth>();
        }

        if (!Weapon)
        {
            Weapon = GetComponent <WeaponComp>();
        }

        if (!Move)
        {
            Move = GetComponent <Movement>();
        }

        //if (!controller) controller = GetComponent<Controller>();
    }
        private static bool FireProjectile(WeaponComp selectedWeapon, Vector3 direction)
        {
            var pc = selectedWeapon.GetComponent <PositionComp>();

            if (selectedWeapon.WeaponType == WeaponTypes.Laser)
            {
                //need to set weapon comp owner properly i think?
                CreateLaserInfoPacket(selectedWeapon, pc, direction);
                LaserFireManager.Instance.Fire((LaserComp)selectedWeapon);
                return(true);
            }
            else if (selectedWeapon.WeaponType == WeaponTypes.Missile)
            {
                CreateMissileInfoPacket(selectedWeapon, pc, direction);
                MissileFireManager.Instance.Fire((MissileComp)selectedWeapon);
                return(true);
            }

            Debug.LogError($"Selected weapon type not found");
            return(false);
        }
Пример #12
0
 protected override void Initialized()
 {
     Guns = GetComponent <WeaponComp>();
 }
 private static bool UnitCanAttack(WeaponComp selectedWeapon)
 {
     return(selectedWeapon.NextAttackTime < Time.time);
 }
 private static void SetNextAttackTime(WeaponComp selectedWeapon)
 {
     selectedWeapon.NextAttackTime = Time.time + selectedWeapon.AttackRate;
 }