public void PutWeaponBack(AWeapon weapon) { weapon.transform.parent = null; weapon.gameObject.SetActiveRecursively(false); weapon.enabled = false; pool[weapon.GetType().ToString()].Enqueue(weapon); }
public override void Launch(IElementAttackable target, AWeapon weapon, Topography topography) { base.Launch(target, weapon, topography); AdjustHeadingForInaccuracy(); InitializeVelocity(); enabled = true; _collider.enabled = true; }
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; }
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(); }
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; } } }
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; }
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; }
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); }
/// <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; }
/// <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; }
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); } }
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; }
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); } } }
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); } }
public virtual bool CanEquip(AWeapon otherWeapon) { return(Weapon == null); }
public abstract bool CanSwap(AWeapon newWeapon);
public static string GetWeaponCategory(AWeapon <TModuleType> weapon) { return(weapon.equipmentQuality.ToString() + " " + weapon.WeaponType.ToString().Replace("_", " ")); }
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; }
/// <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. **************************************************************************************************************************************************/ }
public override bool CanEquip(AWeapon weapon) { return(true); }
public override bool CanSwap(AWeapon newWeapon) { return(true); }
protected virtual void Awake() { m_weapon = GetComponent <AWeapon>(); m_CurrentHP = m_MaxHP; }
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; }
public override void Launch(IElementAttackable target, AWeapon weapon, Topography topography) { base.Launch(target, weapon, topography); InitializeVelocity(); enabled = true; }
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 } }
/// <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()); } }
void Repairing_OnWeaponReady(AWeapon weapon) { LogEvent(); TryFireOnAnyTarget(weapon); }
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); }
/// <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(); }
protected virtual void OnDespawned() { //D.Log(ShowDebugLog, "{0}.OnDespawned called.", DebugName); Unsubscribe(); Target = null; Weapon = null; __instanceID = Constants.Zero; _range = Constants.ZeroF; RestoreRootName(); }
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); }
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; }
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; }
/******************************************************************************************************************************************** * 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; }
private void WeaponReadyToFireEventHandler(object sender, AWeapon.WeaponFiringSolutionEventArgs e) { HandleWeaponReadyToFire(e.FiringSolutions); }
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; }
/// <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 }
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; }
/// <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); } }
public abstract void TakeDamages(float damageAmount, AWeapon source);
private IEnumerator ReloadWeapon(AWeapon weapon) { while (true) { OnWeaponReady(weapon); yield return new WaitForSeconds(weapon.ReloadPeriod); } }
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 }
void ExecuteRepairOrder_OnWeaponReady(AWeapon weapon) { LogEvent(); TryFireOnAnyTarget(weapon); }