Ejemplo n.º 1
0
 public void PutWeaponBack(AWeapon weapon)
 {
     weapon.transform.parent = null;
     weapon.gameObject.SetActiveRecursively(false);
     weapon.enabled = false;
     pool[weapon.GetType().ToString()].Enqueue(weapon);
 }
Ejemplo n.º 2
0
 public override void Launch(IElementAttackable target, AWeapon weapon, Topography topography) {
     base.Launch(target, weapon, topography);
     AdjustHeadingForInaccuracy();
     InitializeVelocity();
     enabled = true;
     _collider.enabled = true;
 }
Ejemplo n.º 3
0
    public virtual void Launch(IElementAttackableTarget target, AWeapon weapon, bool toShowEffects) {
        Target = target;
        Weapon = weapon;

        var tgtBearing = (target.Position - _transform.position).normalized;
        _transform.rotation = Quaternion.LookRotation(tgtBearing); // point ordnance in direction of target so _transform.forward is bearing

        var owner = weapon.RangeMonitor.ParentElement.Owner;
        _range = weapon.RangeCategory.GetWeaponRange(owner);

        ToShowEffects = toShowEffects;
    }
Ejemplo n.º 4
0
    public override void Launch(IElementAttackableTarget target, AWeapon weapon, bool toShowEffects) {
        base.Launch(target, weapon, toShowEffects);
        weapon.OnFiringInitiated(target, this);
        _durationInSeconds = (weapon as BeamProjector).Duration / GameTime.HoursPerSecond;

        _lineRenderer.SetPosition(0, Vector3.zero);  // start beam where ordnance located
        //_lineRenderer.enabled = toShowEffects;
        //if (toShowEffects) {
        //    muzzleEffect.Play();
        //}
        _operateAndAnimateBeamJob = InitiateBeam();
    }
Ejemplo n.º 5
0
    protected override void Apply(Unit target)
    {
        base.Apply(target);
        Shooter shooterComponent = target.GetComponent <Shooter>();

        if (shooterComponent != null)
        {
            AWeapon shooterWeapon = shooterComponent.GetWeaponOfType(this.weapon.GetType());
            if (shooterWeapon != null)
            {
                shooterWeapon.Ammo += this.quantity;
            }
        }
    }
Ejemplo n.º 6
0
 public Poisoning(float health, AWeapon weapon, AGameObject afflicted)        //3--Наш страдалец.
     : base(health)
 {
     Weapon         = weapon;
     Weapon.Owner   = this;
     Target         = afflicted; //Только один будет жертвой.
     Radius         = 1;         //Должен помещаться в игрока, и не взаимодействовать ни с чем.
     Speed          = Constants.POISONING_MOB_SPEED;
     _shootingDelay = Constants.POISONTICK_ATTACK_RATE;
     Damage         = Constants.POISONTICK_DAMAGE;
     TeamIdentity   = null;
     Coordinates.X  = -300;           //Отравление прячется за границей карты, и наносит здоровье удалённо
     Coordinates.Y  = -300;
 }
Ejemplo n.º 7
0
    public void DisplayWeapon(ref byte offset, ref byte weaponIndex)
    {
        AWeapon <TModuleType> weapon = this.inventory.Weapons[weaponIndex];

        if (GUI.Button(MultiResolutions.Rectangle(0, offset * 0.05f, 0.17f, 0.05f), StuffGUI <TModuleType> .GetEquippedStuffName(weapon)))
        {
            this.SelectAndMaybeEquipItem(weapon, weaponIndex);
        }

        if (inventory.Weapons[weaponIndex].Selected)
        {
            this.SelectThisItem(weaponIndex, ItemExtension.FiltreWeapon);
        }

        ++weaponIndex;
        ++offset;
    }
Ejemplo n.º 8
0
    public virtual bool Equip(AWeapon otherWeapon)
    {
        if (!CanEquip(otherWeapon) || otherWeapon == null)
        {
            return(false);
        }

        otherWeapon.transform.SetParent(Hand.transform);
        otherWeapon.transform.localPosition    = Vector3.zero;
        otherWeapon.transform.localEulerAngles = Vector3.zero;

        otherWeapon.Carrier = this;

        Weapon = otherWeapon;

        return(true);
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Called when another client has equiped a weapon
    /// </summary>
    void EquipWeaponRemote(string weaponType, Vector3 localPosition)
    {
        // If there was a previous weapon, put it back in the pool
        if (_weapon != null)
        {
            WeaponManager.Instance.PutWeaponBack(_weapon);
            _weapon = null;
        }

        // Get an instance of the weapon type, and add it as a child of the owner
        _weapon = WeaponManager.Instance.GetWeapon(weaponType);
        _weapon.gameObject.SetActiveRecursively(true);
        _weapon.enabled                 = true;
        _weapon.owner                   = this.GetComponent <Unit>();
        _weapon.transform.parent        = _weapon.owner.transform; // Mettre en parent une fois que le mec a bien été replacé
        _weapon.transform.localPosition = localPosition;
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Checks the firing solution of this weapon on the enemyTarget. Returns <c>true</c> if the target
    /// fits within the weapon's firing solution, aka within range and can be acquired, if required.
    /// </summary>
    /// <param name="weapon">The weapon.</param>
    /// <param name="enemyTarget">The enemy target.</param>
    /// <returns></returns>
    public override bool CheckFiringSolution(AWeapon weapon, IElementAttackableTarget enemyTarget) {
        D.Assert(enemyTarget.IsOperational);
        D.Assert(enemyTarget.Owner.IsEnemyOf(weapon.Owner));

        float distanceToPushover = TempGameValues.__ReqdMissileTravelDistanceBeforePushover;
        Vector3 vectorToPushover = CurrentFacing * distanceToPushover;
        Vector3 pushoverPosition = MuzzleLocation + vectorToPushover;

        Vector3 targetPosition = enemyTarget.Position;
        Vector3 vectorToTargetFromPushover = targetPosition - pushoverPosition;
        float targetDistanceFromPushover = vectorToTargetFromPushover.magnitude;
        if (distanceToPushover + targetDistanceFromPushover > weapon.RangeDistance) {
            D.Log("{0}.CheckFiringSolution({1}) has determined target is out of range.", Name, enemyTarget.FullName);
            return false;
        }
        return true;
    }
Ejemplo n.º 11
0
 public override void TakeDamages(float damageAmount, AWeapon source)
 {
     if (isParrying && source is MeleeWeapon && AngleBetween(transform, source.Carrier.transform) <= angle)
     {
         if (damageAmount > strengh)
         {
             weapon.Carrier.Parried();
         }
         else
         {
             source.Carrier.Parried();
         }
     }
     else
     {
         base.TakeDamages(damageAmount, source);
     }
 }
Ejemplo n.º 12
0
 public Turret(float health, AWeapon weapon, int shootingDelay, AGameObject owner, Vector2 coordinates)
     : base(health, weapon, shootingDelay)
 {
     lifeTime        = Constants.TURRET_LIFETIME;
     Weapon          = weapon;
     Weapon.Owner    = owner;
     Owner           = owner;
     Target          = null;
     Coordinates     = coordinates;
     ObjectType      = EnumObjectType.Turret;
     TeamIdentity    = (owner.TeamIdentity);
     Radius          = Constants.TURRET_RADIUS;
     Speed           = 0f;
     DefaultSpeed    = Speed;
     ThinkCounter    = 0;
     Id              = Guid.NewGuid();
     MaxHealthAmount = HealthAmount = health;
     Damage          = 20;
 }
Ejemplo n.º 13
0
    public void Sell(int itemSelectedIndex, byte itemFiltre)
    {
        //this.itemManagerGUI.ResetItemSelected();
        if (this.DoesItemExistInInventory(itemSelectedIndex, itemFiltre, "sell"))
        {
            if (itemFiltre == ItemExtension.FiltreWeapon)
            {
                AWeapon <TModuleType> item = this.inventory.Weapons[itemSelectedIndex];

                this.inventory.Gold += item.Price;

                if (item.Filtre == ItemExtension.FiltreWeapon)
                {
                    this.Unequip(item);
                }

                this.inventory.RemoveItem(item);
            }
            else if (itemFiltre == ItemExtension.FiltreClothe)
            {
                AClothe <TModuleType> item = this.inventory.Clothes[itemSelectedIndex];

                this.inventory.Gold += item.Price;

                if (item.Filtre == ItemExtension.FiltreWeapon)
                {
                    this.Unequip(item);
                }

                this.inventory.RemoveItem(item);
            }
            else if (itemFiltre == ItemExtension.FiltreConsommable)
            {
                AItem <TModuleType> item = this.inventory.Consommables[itemSelectedIndex];

                this.inventory.Gold += item.Price;

                this.inventory.RemoveItem(item);
            }
        }
    }
Ejemplo n.º 14
0
    void EquipWeapon(int weaponIndex)
    {
        // First, we deactivate the previous weapon
        if (_weapon != null)
        {
            _weapon.gameObject.SetActiveRecursively(false);
            _weapon.enabled = false;
        }

        // We activate the new weapon
        _weapon = _weapons[weaponIndex];
        _weapon.gameObject.SetActiveRecursively(true);
        _weapon.enabled = true;
        _currentWeapon  = weaponIndex;

        _weapon.transform.localPosition = _weapon.positionInCamera;
        Vector3 weaponPosition = _weapon.transform.TransformPoint(Vector3.zero);
        Vector3 weaponPositionInPlayerSpace = this.transform.InverseTransformPoint(weaponPosition); // We retrieve the position of the weapon in the player's local space

        networkView.RPC("EquipWeaponRemote", RPCMode.OthersBuffered, _weapon.GetType().ToString(), weaponPositionInPlayerSpace);
    }
    public void ChangeWeapon(float weaponNum)
    {
        if (weapons.Count > 0)
        {
            if (weaponNum > weapons.Count)
            {
                weaponNum = 0;
            }

            if (currentWeapon != null)
            {
                if (currentWeapon.IsAttack)
                {
                    return;
                }
            }
            if (currentWeapon != null && currentWeapon != weapons[(int)weaponNum])
            {
                currentWeapon.WeaponObject.SetActive(false);
            }
            currentWeapon = weapons[(int)weaponNum];
            currentWeapon.WeaponObject.SetActive(true);
        }
    }
Ejemplo n.º 16
0
 public virtual bool CanEquip(AWeapon otherWeapon)
 {
     return(Weapon == null);
 }
Ejemplo n.º 17
0
 public abstract bool CanSwap(AWeapon newWeapon);
Ejemplo n.º 18
0
    void EquipWeapon(int weaponIndex)
    {
        // First, we deactivate the previous weapon
        if (_weapon != null) {
            _weapon.gameObject.SetActiveRecursively(false);
            _weapon.enabled = false;
        }

        // We activate the new weapon
        _weapon = _weapons[weaponIndex];
        _weapon.gameObject.SetActiveRecursively(true);
        _weapon.enabled = true;
        _currentWeapon = weaponIndex;

        _weapon.transform.localPosition = _weapon.positionInCamera;
        Vector3 weaponPosition = _weapon.transform.TransformPoint(Vector3.zero);
        Vector3 weaponPositionInPlayerSpace = this.transform.InverseTransformPoint(weaponPosition); // We retrieve the position of the weapon in the player's local space
        networkView.RPC("EquipWeaponRemote", RPCMode.OthersBuffered, _weapon.GetType().ToString(), weaponPositionInPlayerSpace);
    }
Ejemplo n.º 19
0
 public static string GetWeaponCategory(AWeapon <TModuleType> weapon)
 {
     return(weapon.equipmentQuality.ToString() + " " + weapon.WeaponType.ToString().Replace("_", " "));
 }
Ejemplo n.º 20
0
    protected void PrepareForLaunch(IElementAttackable target, AWeapon weapon) {
        //D.Log(ShowDebugLog, "{0} is assigning target {1}.", DebugName, target.DebugName);
        Target = target;
        Weapon = weapon;
        Subscribe();

        DeliveryVehicleStrength = weapon.DeliveryVehicleStrength;

        AssignName();
        weapon.HandleFiringInitiated(target, this);

        _range = weapon.RangeDistance;
        IsOperational = true;
    }
Ejemplo n.º 21
0
    /// <summary>
    /// Spawns and launches the ordnance.
    /// <remarks>12.1.16 Fixed in Unity 5.5. Physics.IgnoreCollision below resets the trigger state of each collider, thereby
    /// generating sequential OnTriggerExit and OnTriggerEnter events in any Monitor in the area.</remarks>
    /// <see cref="http://forum.unity3d.com/threads/physics-ignorecollision-that-does-not-reset-trigger-state.340836/"/>
    /// </summary>
    /// <param name="weapon">The weapon.</param>
    /// <param name="target">The target.</param>
    private void LaunchOrdnance(AWeapon weapon, IElementAttackable target) {
        Vector3 launchLoc = weapon.WeaponMount.MuzzleLocation;
        Quaternion launchRotation = Quaternion.LookRotation(weapon.WeaponMount.MuzzleFacing);
        WDVCategory category = weapon.DeliveryVehicleCategory;
        Transform ordnanceTransform;
        if (category == WDVCategory.Beam) {
            ordnanceTransform = MyPoolManager.Instance.Spawn(category, launchLoc, launchRotation, weapon.WeaponMount.Muzzle);
            Beam beam = ordnanceTransform.GetComponent<Beam>();
            beam.Launch(target, weapon);
        }
        else {
            // Projectiles are located under PoolManager in the scene
            ordnanceTransform = MyPoolManager.Instance.Spawn(category, launchLoc, launchRotation);
            Collider ordnanceCollider = UnityUtility.ValidateComponentPresence<Collider>(ordnanceTransform.gameObject);
            ////D.Assert(!ordnanceCollider.enabled);
            D.Assert(ordnanceTransform.gameObject.activeSelf);  // ordnanceGo must be active for IgnoreCollision
            Physics.IgnoreCollision(ordnanceCollider, _primaryCollider);
            ////D.Assert(!ordnanceCollider.enabled);    // makes sure IgnoreCollision doesn't enable collider

            if (category == WDVCategory.Missile) {
                Missile missile = ordnanceTransform.GetComponent<Missile>();
                ////D.Assert(!missile.enabled);
                missile.ElementVelocityAtLaunch = Rigidbody.velocity;
                missile.Launch(target, weapon, Topography);
            }
            else {
                D.AssertEqual(WDVCategory.Projectile, category);
                Projectile projectile = ordnanceTransform.GetComponent<Projectile>();
                ////D.Assert(!projectile.enabled);
                projectile.Launch(target, weapon, Topography);
            }
        }
        //D.Log(ShowDebugLog, "{0} has fired {1} against {2} on {3}.", DebugName, ordnance.Name, target.DebugName, GameTime.Instance.CurrentDate);
        /***********************************************************************************************************************************************
         * Note on Target Death: When a target dies, the fired ordnance detects it and takes appropriate action. All ordnance types will no longer
         * apply damage to a dead target, but the impact effect will still show if applicable. This is so the viewer still sees impacts even while the
         * death cinematic plays out. Once the target is destroyed, its collider becomes disabled, allowing ordnance to pass through and potentially
         * collide with other items until it runs out of range and self terminates. This behaviour holds for both projectile and beam ordnance. In the
         * case of missile ordnance, once its target is dead it self destructs as waiting until the target is destroyed results in 'transform destroyed' errors.
         **************************************************************************************************************************************************/
    }
Ejemplo n.º 22
0
 public override bool CanEquip(AWeapon weapon)
 {
     return(true);
 }
Ejemplo n.º 23
0
 public override bool CanSwap(AWeapon newWeapon)
 {
     return(true);
 }
Ejemplo n.º 24
0
 protected virtual void Awake()
 {
     m_weapon    = GetComponent <AWeapon>();
     m_CurrentHP = m_MaxHP;
 }
Ejemplo n.º 25
0
    public void Launch(IElementAttackable target, AWeapon weapon) {
        PrepareForLaunch(target, weapon);
        D.Assert((Layers)gameObject.layer == Layers.TransparentFX, "{0} is not on Layer {1}.".Inject(Name, Layers.TransparentFX.GetValueName()));
        weapon.isOperationalChanged += WeaponIsOperationalChangedEventHandler;
        _operatingEffectRenderer.SetPosition(index: 0, position: Vector3.zero);  // start beam where ordnance located

        _beamEnd = TrackingWidgetFactory.Instance.MakeTrackableLocation(parent: gameObject);
        _beamEndListener = TrackingWidgetFactory.Instance.MakeInvisibleCameraLosChangedListener(_beamEnd, Layers.Cull_15);
        _beamEndListener.inCameraLosChanged += BeamEndInCameraLosChangedEventHandler;

        AssessShowMuzzleEffects();
        AssessShowOperatingEffects();
        enabled = true;
    }
Ejemplo n.º 26
0
 public override void Launch(IElementAttackable target, AWeapon weapon, Topography topography) {
     base.Launch(target, weapon, topography);
     InitializeVelocity();
     enabled = true;
 }
Ejemplo n.º 27
0
 void ExecuteAttackOrder_OnWeaponReady(AWeapon weapon) {
     LogEvent();
     if (_primaryTarget != null) {
         _attackTarget = _primaryTarget;
         _attackStrength = weapon.Strength;
         D.Log("{0}.{1} firing at {2} from {3}.", FullName, weapon.Name, _attackTarget.FullName, CurrentState.GetValueName());
         Call(FacilityState.Attacking);
     }
     else {
         TryFireOnAnyTarget(weapon);    // Valid in this state as the state can exist for quite a while if the orderTarget is staying out of range
     }
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Attempts to fire the provided weapon at a target within range.
 /// </summary>
 /// <param name="weapon">The weapon.</param>
 private void TryFireOnAnyTarget(AWeapon weapon) {
     if (_weaponRangeMonitorLookup[weapon.MonitorID].__TryGetRandomEnemyTarget(out _attackTarget)) {
         D.Log("{0}.{1} firing at {2} from State {3}.", FullName, weapon.Name, _attackTarget.FullName, CurrentState.GetValueName());
         //_attackDamage = weapon.Damage;
         _attackStrength = weapon.Strength;
         Call(FacilityState.Attacking);
     }
     else {
         D.Warn("{0}.{1} could not lockon to a target from State {2}.", FullName, weapon.Name, CurrentState.GetValueName());
     }
 }
Ejemplo n.º 29
0
 void Repairing_OnWeaponReady(AWeapon weapon) {
     LogEvent();
     TryFireOnAnyTarget(weapon);
 }
Ejemplo n.º 30
0
    public virtual void Launch(IElementAttackable target, AWeapon weapon, Topography topography) {
        if (_displayMgr == null) {
            // 8.9.16 moved from Awake() as PoolMgr spawns ordnance as soon as it wakes. In scene change from Lobby, this occurs 
            // way before OnLevelIsLoaded() is called which is when GameMgr refreshes static References - aka TrackingWidgetFactory
            _displayMgr = InitializeDisplayMgr();
        }
        _displayMgr.IsDisplayEnabled = true;

        PrepareForLaunch(target, weapon);
        D.AssertEqual(Layers.Projectiles, (Layers)gameObject.layer, ((Layers)gameObject.layer).GetValueName());
        _launchPosition = transform.position;

        _rigidbody.drag = OpenSpaceDrag * topography.GetRelativeDensity();
        _rigidbody.mass = Mass;
        AssessShowMuzzleEffects();
        _hasWeaponFired = true;
        weapon.HandleFiringComplete(this);
    }
Ejemplo n.º 31
0
 /// <summary>
 /// Called when this weapon is ready to fire on a target in range.
 /// </summary>
 /// <param name="weapon">The weapon.</param>
 void OnWeaponReady(AWeapon weapon) {
     RelayToCurrentState(weapon);
 }
    public virtual void Launch(IElementAttackable target, AWeapon weapon, Topography topography) {
        PrepareForLaunch(target, weapon);
        D.Assert((Layers)gameObject.layer == Layers.Projectiles, "{0} is not on Layer {1}.".Inject(Name, Layers.Projectiles.GetValueName()));
        _launchPosition = transform.position;

        _rigidbody.drag = OpenSpaceDrag * topography.GetRelativeDensity();
        _rigidbody.mass = Mass;
        AssessShowMuzzleEffects();
        _hasWeaponFired = true;
        weapon.HandleFiringComplete(this);

        _displayMgr = InitializeDisplayMgr();
    }
Ejemplo n.º 33
0
 protected virtual void OnDespawned() {
     //D.Log(ShowDebugLog, "{0}.OnDespawned called.", DebugName);
     Unsubscribe();
     Target = null;
     Weapon = null;
     __instanceID = Constants.Zero;
     _range = Constants.ZeroF;
     RestoreRootName();
 }
Ejemplo n.º 34
0
    public override void Launch(IElementAttackableTarget target, AWeapon weapon, bool toShowEffects) {
        base.Launch(target, weapon, toShowEffects);
        weapon.OnFiringInitiated(target, this);
        _launchPosition = _transform.position;
        _rangeSqrd = _range * _range;

        if (toShowEffects) {
            ShowMuzzleEffect();
        }
        enabled = true;
        //D.Log("{0} launching from {1} on Heading: {2} (resultingRotation = {3}), Range: {4}.", _transform.name, _launchPosition, heading, _transform.rotation, range);
        //OnWeaponFiringComplete();
        weapon.OnFiringComplete(this);
    }
Ejemplo n.º 35
0
    protected void PrepareForLaunch(IElementAttackable target, AWeapon weapon) {
        Target = target;
        Weapon = weapon;
        SubscribeToWeaponChanges();

        DeliveryVehicleStrength = weapon.DeliveryVehicleStrength;

        SyncName();
        weapon.HandleFiringInitiated(target, this);

        _range = weapon.RangeDistance;
        IsOperational = true;
    }
Ejemplo n.º 36
0
    public void Launch(IElementAttackable target, AWeapon weapon) {
        PrepareForLaunch(target, weapon);
        D.AssertEqual(Layers.TransparentFX, (Layers)gameObject.layer, ((Layers)gameObject.layer).GetValueName());

        _operatingEffectRenderer.SetPosition(index: 0, position: Vector3.zero);
        AdjustHeadingForInaccuracy();

        AssessShowMuzzleEffects();
        AssessShowOperatingEffects();
        enabled = true;
    }
Ejemplo n.º 37
0
    /********************************************************************************************************************************************
     * Equipment (Weapons, Sensors and Countermeasures) no longer added or removed while the item is operating. 
     * Changes in an item's equipment can only occur during a refit where a new item is created to replace the item being refitted.
     ********************************************************************************************************************************************/

    #region Weapons

    /*******************************************************************************************************************************************
     * This implementation attempts to calculate a firing solution against every target thought to be in range and leaves it up to the 
     * element to determine which one to use, if any. If the element declines to fire (would be ineffective, not proper state (IE. refitting), target 
     * died or diplomatic relations changed while weapon being aimed, etc.), then the weapon continues to look for firing solutions to put forward.
     * This approach works best where many weapons or countermeasures may not bear even when the target is in range.
     ********************************************************************************************************************************************/

    /// <summary>
    /// Attaches the weapon and its monitor to this item.
    /// </summary>
    /// <param name="weapon">The weapon.</param>
    private void Attach(AWeapon weapon) {
        D.AssertNotNull(weapon.RangeMonitor);
        var monitor = weapon.RangeMonitor;
        if (!WeaponRangeMonitors.Contains(monitor)) {
            // only need to record and setup range monitors once. The same monitor can have more than 1 weapon
            WeaponRangeMonitors.Add(monitor);
        }
        weapon.readytoFire += WeaponReadyToFireEventHandler;
    }
Ejemplo n.º 38
0
 private void WeaponReadyToFireEventHandler(object sender, AWeapon.WeaponFiringSolutionEventArgs e) {
     HandleWeaponReadyToFire(e.FiringSolutions);
 }
Ejemplo n.º 39
0
    void EquipWeaponRemote(string weaponType, Vector3 localPosition)
    {
        // If there was a previous weapon, put it back in the pool
        if (_weapon != null) {
            WeaponManager.Instance.PutWeaponBack(_weapon);
            _weapon = null;
        }

        // Get an instance of the weapon type, and add it as a child of the owner
        _weapon = WeaponManager.Instance.GetWeapon(weaponType);
        _weapon.gameObject.SetActiveRecursively(true);
        _weapon.enabled = true;
        _weapon.owner = this.GetComponent<Unit>();
        _weapon.transform.parent = _weapon.owner.transform;   // Mettre en parent une fois que le mec a bien été replacé
        _weapon.transform.localPosition = localPosition;
    }
Ejemplo n.º 40
0
    /// <summary>
    /// Adds the weapon to this element, paired with the provided range monitor. Clients wishing to add
    /// a weapon to this element should use UnitFactory.AddWeapon(weapon, element).
    /// </summary>
    /// <param name="weapon">The weapon.</param>
    /// <param name="rangeMonitor">The range monitor to pair with this weapon.</param>
    public void AddWeapon(AWeapon weapon, IWeaponRangeMonitor rangeMonitor) {
        if (_weaponRangeMonitorLookup == null) {
            _weaponRangeMonitorLookup = new Dictionary<Guid, IWeaponRangeMonitor>();
        }
        if (!_weaponRangeMonitorLookup.ContainsKey(rangeMonitor.ID)) {
            // only need to record and setup range trackers once. The same rangeTracker can have more than 1 weapon
            _weaponRangeMonitorLookup.Add(rangeMonitor.ID, rangeMonitor);
            rangeMonitor.ParentFullName = FullName;
            rangeMonitor.RangeCategory = weapon.RangeCategory;
            rangeMonitor.Owner = Data.Owner;
            rangeMonitor.onEnemyInRange += OnEnemyInRange;
        }
        // rangeMonitors enable themselves

        Data.AddWeapon(weapon, rangeMonitor.ID);
        // IMPROVE how to keep track ranges from overlapping
    }
Ejemplo n.º 41
0
    public override void Launch(IElementAttackable target, AWeapon weapon, Topography topography) {
        base.Launch(target, weapon, topography);
        _positionLastRangeCheck = Position;
        _rigidbody.velocity = ElementVelocityAtLaunch;
        _courseUpdatePeriod = new GameTimeDuration(1F / CourseUpdateFrequency);
        SteeringInaccuracy = CalcSteeringInaccuracy();
        target.deathOneShot += TargetDeathEventHandler;
        _driftCorrector = new DriftCorrector(FullName, transform, _rigidbody);

        enabled = true;
    }
Ejemplo n.º 42
0
 /// <summary>
 /// Removes the weapon from this element, destroying any associated range tracker
 /// if it is no longer in use.
 /// </summary>
 /// <param name="weapon">The weapon.</param>
 public void RemoveWeapon(AWeapon weapon) {
     bool isRangeTrackerStillInUse = Data.RemoveWeapon(weapon);
     if (!isRangeTrackerStillInUse) {
         IWeaponRangeMonitor rangeTracker;
         if (_weaponRangeMonitorLookup.TryGetValue(weapon.MonitorID, out rangeTracker)) {
             _weaponRangeMonitorLookup.Remove(weapon.MonitorID);
             D.Log("{0} is destroying unused {1} as a result of removing {2}.", FullName, typeof(IWeaponRangeMonitor).Name, weapon.Name);
             GameObject.Destroy((rangeTracker as Component).gameObject);
             return;
         }
         D.Error("{0} could not find {1} for {2}.", FullName, typeof(IWeaponRangeMonitor).Name, weapon.Name);
     }
 }
Ejemplo n.º 43
0
 public abstract void TakeDamages(float damageAmount, AWeapon source);
Ejemplo n.º 44
0
 private IEnumerator ReloadWeapon(AWeapon weapon) {
     while (true) {
         OnWeaponReady(weapon);
         yield return new WaitForSeconds(weapon.ReloadPeriod);
     }
 }
Ejemplo n.º 45
0
 void ExecuteAttackOrder_OnWeaponReady(AWeapon weapon) {
     LogEvent();
     if (_primaryTarget != null) {   // OnWeaponReady can occur before _primaryTarget is picked
         _attackTarget = _primaryTarget;
         _attackStrength = weapon.Strength;
         D.Log("{0}.{1} firing at {2} from {3}.", FullName, weapon.Name, _attackTarget.FullName, CurrentState.GetValueName());
         Call(ShipState.Attacking);
     }
     // No potshots at random enemies as the ship is either Moving or the primary target is in range
 }
Ejemplo n.º 46
0
 void ExecuteRepairOrder_OnWeaponReady(AWeapon weapon) {
     LogEvent();
     TryFireOnAnyTarget(weapon);
 }