public void Fire() { if (state == WeaponState.Idle) { Projectile projectile = Instantiate(projectilePrefab); projectile.origin = GetComponent <Combatant>(); Vector3 spawnPos = spawnPoint == null ? transform.position : spawnPoint.position; Entity entity = projectile.GetComponent <Entity>(); Vector3 fireDirection = transform.forward; if (target != null) { Vector3 targetPos = target.transform.position; Entity targetEntity = target.GetComponent <Entity>(); if (targetEntity != null) { targetPos += targetEntity.Velocity * 20 * Time.deltaTime; } fireDirection = targetPos - spawnPos; } entity.Velocity = fireDirection.normalized * (firePower / entity.mass); if (projectile.GetComponent <HomingProjectile>() != null) { projectile.GetComponent <HomingProjectile>().SetTarget(target); } entity.transform.position = spawnPos; state = WeaponState.Firing; } }
IEnumerator FireTurretSequenceRobot(Transform target, WeaponState ws) { if (ws.isProcessing) { yield break; } Coroutine analyze = ws.FireTurretT2(); while (ws.FXFiring.activeSelf) { yield return(new WaitForEndOfFrame()); } if (target == null) { ws.Fire(shipREF.Velocity.magnitude, target); } else { if (GameObject.Find("UIGame").GetComponent <UIGame>().IsBigCursorAligned()) { ws.Fire(shipREF.Velocity.magnitude, target); } else { ws.Fire(shipREF.Velocity.magnitude, null); } } }
public void Shoot() { if (type != WeaponType.None) { CheckBullet(); if (state == WeaponState.Ready || (type == WeaponType.ParticleCannon && state == WeaponState.Reloading)) { Vector2 fire_at_cursor; fire_at_cursor = (Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position); fire_at_cursor.Normalize(); GameObject newBullet = Instantiate(bullet[(int)type], transform.position, Quaternion.identity); newBullet.GetComponent <Rigidbody2D>().velocity = fire_at_cursor * bulletSpeed[(int)type]; newBullet.transform.LookAt(Vector3.forward + newBullet.transform.position, fire_at_cursor); Bullet buletScript = newBullet.GetComponent <Bullet>(); buletScript.miss = Random.Range(0, 100) > accuracy; if (!buletScript.miss) { buletScript.crit = Random.Range(0, 100) < critChance; } bulletCount--; cdTimer = 0; state = WeaponState.Cooldown; } } }
void Start() { State = GetComponent<WeaponState>(); EventTire = this.GetEventTire(); EventTire.AddEventListener(TireEventType.ControlEvent, OnControlEvent); EventTire.AddEventListener(TireEventType.AmmoPickupEvent, OnAmmoPickupEvent); }
public void Update() { if (Debug.isDebugBuild && Barrel) { Debug.DrawRay(Barrel.position, 50.0f * Barrel.forward, Color.green); } if (m_State != WeaponState.READY && Time.time >= m_StateReleaseTimeout) { switch (m_State) { case WeaponState.RELOADING: if (ContinuousReload) { Ammo++; m_StateReleaseTimeout = Time.time + ReloadDuration; } else { Ammo = MagazineSize; } if (Ammo >= MagazineSize) { Ammo = MagazineSize; m_State = WeaponState.READY; } break; default: m_State = WeaponState.READY; break; } } }
/// <summary> /// Updates the GameField /// </summary> /// <param name="gameTime">A valid Gametime</param> /// <param name="moveVector">A valid Vector2</param> /// <param name="weaponDirection">A valid WeaponState</param> /// <param name="speedPercent">A valid float, from 0 to 100</param> public void Update(GameTime gameTime, Vector2 moveVector, WeaponState weaponDirection) { //Moves the character this.MoveCharacter(gameFloor.GetCurrentRoom().GetObstacles(), moveVector); //Checks if the player is firing a projectile this.player.FireProjectile(ref projectileField, weaponDirection, gameTime); //Updates projectile field this.UpdateProjectiles(); //Checks for contact damage to the player this.UpdateContactDamage(); //Updates invincibility this.UpdateGracePeriod(gameTime); //Updates the current room's data PlayerStats playerStats = player.GetStats(); gameFloor.GetCurrentRoom().Update(ref projectileField, ref particleField, player.GetProjectileHitbox().GetCenter(), ref playerStats, gameTime); //Allows player to pick up any items they are standing over this.UpdateItemPedestals(); //Updates all particles on screen this.UpdateParticles(gameTime); //Checks if the player will move between rooms if (gameFloor.GetCurrentRoom().GetEnemies().Count == 0) { this.UpdateRoomLocation(); } }
private void UpdateTimers() { switch (currentState) { case WeaponState.IDLE: //Do nothing break; case WeaponState.AIMING: castTimer += Time.deltaTime; if (castTimer >= castTime) { if (photonView.isMine) { Vector3[] controlPoints = ((CurvedTargeting)targeting).ControlPoints(); Shoot(controlPoints); } CurrentState = WeaponState.RELOADING; } break; case WeaponState.RELOADING: reloadTimer += Time.deltaTime; if (reloadTimer >= reloadTime) { CurrentState = WeaponState.IDLE; } break; default: throw new UnhandledEnumCase(currentState); } }
public override bool SharedOnFire(ICharacter character, WeaponState weaponState) { base.SharedOnFire(character, weaponState); // spawn minions after a nova attack MobBossPragmiumKing king = character.ProtoGameObject as MobBossPragmiumKing; if (king is not null) { if (mobs is null) { mobs = Api.FindProtoEntities <ProtoCharacterMob>(); mobs.RemoveAll(m => m.StatDefaultHealthMax < 80); mobs.RemoveAll(m => m.AiIsRunAwayFromHeavyVehicles); } int r = RandomHelper.Next(mobs.Count); ProtoCharacterMob mob = mobs[r]; king.ServerTrySpawnMinions(character, 6.0, 8.0, mob); king.ServerTrySpawnMinions(character, 10.0, 15.0, Api.GetProtoEntity <MobPsiGrove>()); } return(true); }
public WeaponMode InitializeWeaponState(WeaponMode mode, float radius, RedemptionTDColor color) { if (mode == WeaponMode.GATHER) { var resourceLayer = 1 << LayerMask.NameToLayer("Resource"); var hit = Physics2D.OverlapCircle(transform.position, radius, resourceLayer); if (hit != null && hit.GetComponent <LiteUnit>().HeavyReference.Color == color) { CurrentWeaponState = gatherState; CurrentWeaponState.EnterWeaponState(hit.GetComponent <ResourceLite>()); return(WeaponMode.GATHER); } else { CurrentWeaponState = nullState; CurrentWeaponState.EnterWeaponState(); return(WeaponMode.NONE); } } else { CurrentWeaponState = blastState; CurrentWeaponState.EnterWeaponState(); return(WeaponMode.WAVE); } }
/// <summary> /// Reload the weapon to a full clip. /// Unequip the weapon if there is no ammo remaining. /// </summary> public void Reload() { if (m_CurrentState != WeaponState.Idle || weaponConfiguration.Clip.size == weaponConfiguration.Clip.rounds) { return; } int remainingAmmo = weaponConfiguration.Ammo.Amount; if (remainingAmmo == 0) { //m_Character.UnequipWeapon(); return; } if (ReloadAudio != null) { m_AudioSource.PlayOneShot(ReloadAudio); } int roundsToLoad = Mathf.Min(remainingAmmo, weaponConfiguration.Clip.size - weaponConfiguration.Clip.rounds); m_CurrentState = WeaponState.Reloading; weaponConfiguration.Clip.rounds += roundsToLoad; // TODO : Update UI m_Animator.SetTrigger("reload"); weaponConfiguration.Ammo.UpdateAmount(-roundsToLoad, m_Character.Stats); // TODO : Update UI }
private void Update() { switch ((int)wState) { case 0: ChargingForce = 0f; break; case 1: GetComponent<PlayerControl>().mAnimator.SetBool("Charging", true); ChargingForce += Chargerate * Time.unscaledDeltaTime; break; case 2: GetComponent<PlayerControl>().mAnimator.SetBool("Charging", false); GetComponent<PlayerControl>().mAnimator.SetTrigger("Release"); wState = WeaponState.cooldown; break; case 3: ChargingForce -= DischargeRate * Time.unscaledDeltaTime; if (ChargingForce <= 0f) wState = WeaponState.idle; break; default: Debug.Log("What is this"); break; } ChargingForce = Mathf.Clamp(ChargingForce, 0f, 100f); Debug.DrawRay(transform.GetChild(0).position, transform.GetChild(0).forward, Color.blue); }
public void FireWeapon(WeaponState weaponState) { if (weaponState != WeaponState.Still) { weapon.Fire(); } }
private void computeWeaponState() { if (weaponState == WeaponState.IDLE) { if (Input.GetMouseButton(0)) { weaponState = WeaponState.CHARGING; } } if (weaponState == WeaponState.CHARGING) { chargeWeapon(); weaponShootWithDelta(); if (!Input.GetMouseButton(0)) { weaponState = WeaponState.DISCHARGING; return; } } if (weaponState == WeaponState.DISCHARGING) { if (Input.GetMouseButton(0)) { weaponState = WeaponState.CHARGING; return; } dischargeWeapon(); } }
// Use this for initialization void Start() { trackedObject = viveCntrl.GetComponent <SteamVR_TrackedObject>(); m_Pool = PoolSystem.FindPool("Projectile"); g_Pool = PoolSystem.FindPool("Grenade"); m_Stock = GetComponentInChildren <StockAttributes>(); m_Barrel = GetComponentInChildren <BarrelAttributes>(); activeBarrelList.Add(m_BarrelParts[0]); activeStockList.Add(m_StockParts[0]); m_BarrelIndex = 0; m_StockIndex = 0; //manager = GetComponentInChildren<PartManager>(); Commander = GetComponent <SquadCommand>(); aSource = GetComponent <AudioSource>(); isShooting = false; m_Ammunition = 200; m_Part = Part.Barrel; m_StateMachine = WeaponState.Weapon; reset = false; resetParts = true; feedback.enabled = false; }
/// <summary> /// Core weapon checks /// </summary> protected virtual void Checks() { if (!IsActive) { EffectsOff(); return; } delay.TimerUpdate(); if (CurrentAmmoInClip > 0 && delay.Elapsed < 0) { weaponState = WeaponState.ReadyToFire; } if (CurrentAmmoInClip <= 0) { currentAmmoInClip = 0; weaponState = WeaponState.Empty; } if (WeaponState == WeaponState.Empty) { animator?.SetTrigger("Reload"); } if (WeaponState != WeaponState.Firing) { EffectsOff(); animator?.SetTrigger("Idle"); } }
/// <summary> /// Core weapon's 'Init' /// </summary> public virtual void Init() { IsActive = true; weaponState = WeaponState.ReadyToFire; currentAmmoInClip = clipSize; delay = new Timer(); animator = GetComponentInParent <Animator>(); audioSource = GetComponent <AudioSource>(); audioSource?.Stop(); damageEffect?.SetActive(true); foreach (var ps in damageEffect.GetComponentsInChildren <ParticleSystem>()) { hitPS.Add(ps); ps.Stop(); } fireEffect?.gameObject.SetActive(true); foreach (var ps in fireEffect.GetComponentsInChildren <ParticleSystem>()) { firePS.Add(ps); ps.Stop(); } }
public void Update() { _previousState = _stateComponent.PeekState(); switch (_stateComponent.PeekState()) { case WeaponState.IdleState: break; case WeaponState.ChargingState: _weaponCharge += Artillery.Constants.WeaponChargeSpeed; if (_weaponCharge > _weaponMaxCharge) { _weaponCharge = _weaponMaxCharge; } break; case WeaponState.FireState: break; } if (_parent.Direction == Direction.Right) { _relativeAngle = (float)_parent.AbsAngle; } else { _relativeAngle = (float)_parent.AbsAngle * -1; } }
protected Weapon(Texture2D texture, Vector2 position, int bulletInWeapon, WeaponState weaponState, Camera currentCamera) : base(texture, position) { _currentCamera = currentCamera; _bulletsFired = new List <Bullet>(); _totalBullet = bulletInWeapon; _weaponState = weaponState; }
public void Update() { if(Debug.isDebugBuild && Barrel) { Debug.DrawRay(Barrel.position, 50.0f*Barrel.forward, Color.green); } if(m_State != WeaponState.READY && Time.time >= m_StateReleaseTimeout) { switch(m_State) { case WeaponState.RELOADING: if(ContinuousReload) { Ammo++; m_StateReleaseTimeout = Time.time + ReloadDuration; } else { Ammo = MagazineSize; } if(Ammo >= MagazineSize) { Ammo = MagazineSize; m_State = WeaponState.READY; } break; default: m_State = WeaponState.READY; break; } } }
// Method for weapon fire and change to Reload or CD state dependents on the ammo remain (called after Instaite a bullet object) public void Fire() { // Reduce ammon on each fire curAmmoAmount -= 1; // If have ammo remain, change to CD state if (ammoAmount == -1) { // Keep curAmmoAmount in -1 curAmmoAmount = -1; state = WeaponState.onCD; } else if (curAmmoAmount > 0) { state = WeaponState.onCD; } // If ammo is run out, change to reload state else if (clipAmount == -1) { curClipAmount = -1; state = WeaponState.onReload; curReloadTime = reloadTime; } else if (curClipAmount > 0) { state = WeaponState.onReload; curReloadTime = reloadTime; } // If clip is run out, change to end state else { state = WeaponState.onEnd; } // Reset fire CD time curFireCD = fireCD; }
/// <summary> /// Load ammo if there's any left /// </summary> public void Selected() { int remainingAmmo = weaponConfiguration.Ammo.Amount; //gameObject.SetActive(remainingAmmo != 0 || weaponConfiguration.Clip.rounds != 0); if (FireAnimation != null) { m_Animator.SetFloat("fireSpeed", FireAnimation.length / weaponConfiguration.fireRate); } if (ReloadAnimation != null) { m_Animator.SetFloat("reloadSpeed", ReloadAnimation.length / weaponConfiguration.reloadTime); } m_CurrentState = WeaponState.Idle; triggerDown = false; m_ShotDone = false; // TODO : Update UI // Load the clip if its empty if (weaponConfiguration.Clip.rounds == 0 && remainingAmmo != 0) { int roundsToLoad = Mathf.Min(remainingAmmo, weaponConfiguration.Clip.size); weaponConfiguration.Clip.rounds += roundsToLoad; weaponConfiguration.Ammo.UpdateAmount(-roundsToLoad, m_Character.Stats); // TODO : Update UI } m_Animator.SetTrigger("selected"); }
private void StateChanged(WeaponState o, WeaponState n) { //try //{ // bool shooting = IsShooting; // bool oldshoot = ((o & WeaponState.AIShoot) == WeaponState.AIShoot || // (o & WeaponState.ManualShoot) == WeaponState.ManualShoot || // (o & WeaponState.TerminalShoot) == WeaponState.TerminalShoot || // (o & WeaponState.TerminalShootOnce) == WeaponState.TerminalShootOnce); // if (oldshoot != shooting) // { // if (shooting) // { // ControlLayer.NeedsUpdate = VRage.ModAPI.MyEntityUpdateEnum.EACH_FRAME; // } // else if (!IsAnimated) // { // ControlLayer.NeedsUpdate = VRage.ModAPI.MyEntityUpdateEnum.NONE; // } // } //} //catch (Exception e) //{ // Tools.Error(e.ToString()); //} }
public void MakeIntoCopyOfWeapon(Weapon weaponToCopy) { this.weaponName = weaponToCopy.weaponName; //this.owner = weaponToCopy.owner; //this.float timeSinceLastShot; //this.reloadTime = weaponToCopy.reloadTime; //this.fireRate = weaponToCopy.fireRate; //this.magazines = weaponToCopy.magazines; //list of magazines with number of bullets in them. this.magNum = weaponToCopy.magNum; //Which mag is currently being used. this.stateOfWeapon = weaponToCopy.stateOfWeapon; this.fireModes = new FireMode[weaponToCopy.fireModes.Length]; for (int i = 0; i < fireModes.Length; i++) { fireModes[i] = weaponToCopy.fireModes[i].Copy(); } for (int j = 0; j < weaponToCopy.magazines.Count; j++) { magazines.Add(weaponToCopy.magazines[j]); } this.currentFireMode = weaponToCopy.currentFireMode; //this.DictionaryOfFireModeAndGameObject projectileDictionary; //used to fire a different projectile based on the fire mode. this.barrelEnd = weaponToCopy.barrelEnd; this.barrelStart = weaponToCopy.barrelStart; this.prefabToSpawnOnDrop = weaponToCopy.prefabToSpawnOnDrop; this.discardOnFire = weaponToCopy.discardOnFire; this.reloadable = weaponToCopy.reloadable; }
public override void GetPose(PlayerState basePose) { switch (SlashAction) { default: case (SwingAction.StartSwing): basePose.RightArm = ArmState.Angular(5); basePose.Weapon = WeaponState.Knife(MathHelper.ToRadians(90 + 45)); break; case (SwingAction.UpSwing): basePose.RightArm = ArmState.Angular(6); basePose.Weapon = WeaponState.Knife(MathHelper.ToRadians(90 + 45 + 22)); break; case (SwingAction.DownSwing): basePose.Body = BodyState.Crouch(1); basePose.RightArm = ArmState.Angular(0); basePose.Weapon = WeaponState.None; break; case (SwingAction.FinishSwing): basePose.Body = BodyState.Crouch(2); basePose.RightArm = ArmState.Angular(0); basePose.Weapon = WeaponState.None; break; } }
public override bool SharedCanFire(ICharacter character, WeaponState weaponState) { var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(character.TilePosition); return(areasGroup is not null && PowerGridSystem.ServerBaseHasCharge(areasGroup, this.EnergyUsagePerShot)); }
public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance) { if (!componentInstance.HasAblity <WeaponState>()) { var wpnState = new WeaponState(); wpnState.WeaponType = "Missile Launcher"; wpnState.WeaponStats = new (string name, double value, ValueTypeStruct valueType)[3];
IEnumerator Fire(Vector3 Direction) { switch (Type) { case WeaponType.SemiAutomatic: { if (Magazine > 0) // more than 0 rounds in the magazine { TestFire(); Magazine--; CanFire = false; yield return(new WaitForSeconds(FireInterval)); CanFire = true; } else if (Magazine == 0 && AutomaticReload) { StartCoroutine(Reload()); } else if (Magazine == 0 && !AutomaticReload) { // Click!, the hammer just dropped on an empty chamber. State = WeaponState.Idle; } break; } } }
private void FormBambulanci_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Left: playerMovement = Direction.Left; break; case Keys.Right: playerMovement = Direction.Right; break; case Keys.Up: playerMovement = Direction.Up; break; case Keys.Down: playerMovement = Direction.Down; break; case Keys.Space: weaponState = WeaponState.Fired; break; default: break; } }
IEnumerator TimedFire(float time) { yield return(new WaitForSeconds(time)); currentState = WeaponState.Ready; accuracyModifier = CurrentMode.AccuracyModifier; }
void Update() { switch (currentState) { case WeaponState.Off : beamEffect.SetColors(Color.black, Color.black); if (hitEffect.isPlaying) hitEffect.Stop(); if (muzzleEffect.isPlaying) muzzleEffect.Stop(); break; case WeaponState.WarmingUp : beamEffect.SetColors(Color.black, Color.black); if (hitEffect.isPlaying) hitEffect.Stop(); if (!muzzleEffect.isPlaying) muzzleEffect.Play(); muzzleEffect.emissionRate = (spinUpTimer / spinUp) * 30; muzzleEffect.startSize = (spinUpTimer / spinUp) * 0.5f; spinUpTimer += Time.deltaTime; if (spinUpTimer > spinUp) { spinUpTimer = 0.0f; currentState = WeaponState.Firing; } break; case WeaponState.Firing : if (!muzzleEffect.isPlaying) muzzleEffect.Play(); int layer1 = LayerMask.NameToLayer("PlayerRagDoll"); int layer2 = LayerMask.NameToLayer("Player"); int layer3 = LayerMask.NameToLayer("AreaOfEffect"); int layer4 = LayerMask.NameToLayer("Obstacle"); int layermask = ~((1 << layer1) | (1 << layer2) | (1 << layer3) | (1 << layer4)); RaycastHit hit; Vector3 startPos = transform.position + new Vector3(0.0f,0.0f,0.0f); Vector3 endPos = startPos + transform.forward * range; endPos.y = 1.0f; beamEffect.SetPosition(0, startPos); beamEffect.SetPosition(1, endPos); if (Physics.Linecast (startPos, endPos, out hit, layermask)) { hitEffect.transform.position = hit.point; beamEffect.SetPosition(1, hit.point); if (!hitEffect.isPlaying) hitEffect.Play(); beamEffect.SetColors(Color.red, Color.red); if (hit.transform.tag.Equals("Enemy")) { hit.transform.GetComponent<EnemyController>().Blinded(5); } } else { if (hitEffect.isPlaying) hitEffect.Stop(); beamEffect.SetColors(Color.red, Color.black); } break; } }
public bool CeaseFire() { if (CurrentState != WeaponState.Firing) return false; // TODO Begin Cooldown Timer, put weapon on cooldown CurrentState = WeaponState.OnCooldown; return true; }
public static Weapon Build(IIdResolver resolver, WeaponState state) { if ( state == null ) { return null; } var weaponInfo = resolver.GetById<WeaponInfo>(ItemType.ShipWeapons.ToId(state.Code)); return Build(state.ObjectId, weaponInfo); }
internal WeaponNode(string JSON) : base(JSON) { Name = GetString("name"); Paintkit = GetString("paintkit"); Type = GetEnum<WeaponType>("type"); AmmoClip = GetInt32("ammo_clip"); AmmoClipMax = GetInt32("ammo_clip_max"); AmmoReserve = GetInt32("ammo_reserve"); State = GetEnum<WeaponState>("state"); }
void Update() { if (currentState == WeaponState.Ready) { coolDownTimer -= Time.deltaTime; if (coolDownTimer < -spinUp) { currentState = WeaponState.Off; coolDownTimer = 0.0f; } } if (currentState == WeaponState.WarmingUp) { spinUpTimer += Time.deltaTime; if (spinUpTimer > spinUp) { spinUpTimer = 0.0f; currentState = WeaponState.Ready; } } }
public void Fire(Vector3 target) { switch (currentState) { case WeaponState.Off : currentState = WeaponState.WarmingUp; break; case WeaponState.WarmingUp : break; case WeaponState.Ready : if (coolDownTimer > 0) return; Rigidbody newBullet = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody; Vector3 shootVector = ( target - transform.position).normalized; newBullet.AddForce(shootVector * 10, ForceMode.Impulse); coolDownTimer = coolDown; break; } }
/// <summary> /// Checks to see if the weapon is actually overheated or /// if it has cooled down /// </summary> /// <returns><c>true</c>, if overheated <c>false</c> otherwise.</returns> public bool isOverheated() { // If we're not overheated if(currentState != WeaponState.Overheated) return false; // Check if enough time has passed to consider completely cooled down. if(getCurrentHeat() == 0f){ // Change the state back to normal because it's cooled down now currentState = WeaponState.Normal; return false; } // Nothing is saying we're not overheated so we must be return true; }
public void ReleaseThrow() { ChargingForce = Mathf.Round(ChargingForce * 100f) / 100f; wState = WeaponState.released; }
// sets the target weapon state, which changes color/emission public virtual void SetWeaponState(WeaponState state) { curState = state; }
/// <summary> /// Fires the weapon if able to. /// </summary> public void fire() { // Make sure we can fire gun // // Make sure we're in the correct state if (isOverheated ()) { return; } // Make sure enough time has elapsed since last fire if(Time.time - timeOfLastFire < weaponConfiguration.fireRate){ return; } // Update heat since last fire currentHeat = getCurrentHeat(); // Hurt whatever got in our way if (weaponConfiguration.IsProjectileBased) { launchProjectile(); } else { castPain (); } // Add heat to the gun currentHeat = Mathf.Clamp01(currentHeat + weaponConfiguration.heatPerFireIncrement); // Go into overheated state if we've become overheated if(currentHeat == 1f){ currentState = WeaponState.Overheated; } // Update our last firing time timeOfLastFire = Time.time; // Create Effects animateFire (); }
protected override void UpdateState() { hexScaleTimer += Time.deltaTime; Color curColor = Color.white; Color curEmis = Color.white * .01f; Vector3 targScale = originalHexScale; float rotationSpeed = originalSpinSpeed; // determine our color and target scale switch (curState) { case WeaponState.OFF_CD: curColor = plCol; curColor.a = offOpacity; curEmis = plCol; targScale *= offHexScale; break; case WeaponState.ON_CD: curColor = plCol; curColor.a = onOpacity; targScale *= onHexScale; break; case WeaponState.ACTIVE: rotationSpeed = 0; curColor = plCol + (Color.white * .3f); curEmis = plCol + (Color.white * .3f); curColor.a = activeOpacity; targScale *= activeHexScale; break; case WeaponState.WHITE: curColor = Color.white; curColor.a = offOpacity; curEmis = plCol; targScale *= offHexScale; break; } // set barrier color and opacity Color barColor = curColor; barColor.a = .15f; barrier.material.SetColor("_Color", barColor); GetComponent<CoreAnimator>().rotationSpeed = rotationSpeed; // if this is a new state, begin scaling and set color if (lastState != curState) { hexScaleTimer = 0; foreach (Renderer hexRend in hexes) { // we don't want the parent renderer if (hexRend == barrier) continue; hold = hexRend.material; hold.SetColor("_Color", curColor); hold.SetColor("_EmissionColor", curEmis); startHexScale = hexRend.transform.localScale; } } // then if we're still scaling, change the hex scale if (hexScaleTimer < hexScaleTime) { foreach (Renderer hexRend in hexes) { // we don't want the parent renderer if (hexRend == barrier) continue; hexRend.transform.localScale = startHexScale + ((targScale - startHexScale) * surge.Evaluate(hexScaleTimer / hexScaleTime)); } } lastState = curState; }
public void Fire() { if (currentState == WeaponState.Off) currentState = WeaponState.WarmingUp; }
/// <summary> /// reloads weapon. /// plays reloading particle depending on unit type. /// </summary> /// <param name="type">unit type</param> /// <returns></returns> public bool Reload(UnitTypeId type) { this.state = WeaponState.Reloading; ParticleType reloadParticle = ParticleType.Count; SoundTrack reloadSound = SoundTrack.Count; switch (this.WeaponType) { case WeaponType.PlayerMachineGun: { reloadParticle = ParticleType.PlayerMachineGunReload; switch (type) { case UnitTypeId.Grund: case UnitTypeId.Kiev: reloadSound = SoundTrack.PlayerMachineGunGrundReload; break; case UnitTypeId.Mark: case UnitTypeId.Yager: reloadSound = SoundTrack.PlayerMachineGunMarkReload; break; } } break; case WeaponType.PlayerShotgun: { // Shotgun reload is no particle reloadSound = SoundTrack.PlayerShotgunReload; } break; case WeaponType.PlayerHandgun: { reloadParticle = ParticleType.PlayerHandgunReload; reloadSound = SoundTrack.PlayerHandgunReload; } break; } // Play a reloading particle if (reloadParticle != ParticleType.Count) { for (int i = 0; i < SpecData.ModelCount; i++) { int boneIdx = -1; Matrix boneTransform = Matrix.Identity; boneIdx = this.indexWeaponFireDummy[i]; boneTransform = modelWeapon[i].BoneTransforms[boneIdx]; if (reloadParticle != ParticleType.Count) { GameParticle.PlayParticle(reloadParticle, boneTransform, Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } } } switch (this.WeaponType) { case WeaponType.PlayerMachineGun: { if (GameSound.IsPlaying(soundFire)) GameSound.Stop(soundFire); } break; } // Play a reload sound if (reloadSound != SoundTrack.Count) { if (RobotGameGame.CurrentGameLevel.Info.GamePlayType == GamePlayTypeId.Versus) { soundReload = GameSound.Play3D(reloadSound, RobotGameGame.SinglePlayer.Emitter); } else { soundReload = GameSound.Play3D(reloadSound, this.OwnerUnit.Emitter); } } return true; }
/// <summary> /// checks for the collision at the aiming angle. /// If it collides with an enemy mech, calls ActionHit() function. /// Weapon’s collision checks the world and enemy both. /// When playing firing particle, the number of the weapon’s model /// must be considered. /// Since the player’s weapon is a dual weapon system, there are two models. /// However, for enemies, there are enemies with single weapon system. /// Therefore, it plays firing particle at the gun point /// as many as the number of models. /// </summary> /// <param name="position">the start position of firing</param> /// <param name="direction">the direction of firing</param> /// <param name="distance">the range of firing</param> /// <param name="targetCollisionLayer">target collision layer</param> /// <param name="worldCollisionLayer">world collision layer</param> /// <param name="fireBone1">the fire matrix of first weapon</param> /// <param name="fireBone2">the fire matrix of second weapon</param> /// <returns></returns> public bool Fire(Vector3 position, Vector3 direction, float distance, ref CollisionLayer targetCollisionLayer, ref CollisionLayer worldCollisionLayer, Matrix? fireBone1, Matrix? fireBone2) { bool hit = false; Vector3 firePosition = Vector3.Zero; Vector3 targetPosition = position + (direction * distance); SoundTrack fireSound = SoundTrack.Count; ParticleType fireParticle = ParticleType.Count; ParticleType unitHitParticle = ParticleType.Count; ParticleType worldHitParticle = ParticleType.Count; Matrix fixedAxis = Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)); this.state = WeaponState.Firing; if (this.currentAmmo <= 0) return hit; // Reduces a bullet. this.currentAmmo--; switch (this.WeaponType) { case WeaponType.PlayerMachineGun: { fireSound = SoundTrack.PlayerMachineGunFire; fireParticle = ParticleType.PlayerMachineGunFire; unitHitParticle = ParticleType.PlayerMachineGunUnitHit; worldHitParticle = ParticleType.PlayerMachineGunWorldHit; } break; case WeaponType.PlayerShotgun: { fireSound = SoundTrack.PlayerShotgunFire; fireParticle = ParticleType.PlayerShotgunFire; unitHitParticle = ParticleType.PlayerShotgunUnitHit; worldHitParticle = ParticleType.PlayerShotgunWorldHit; } break; case WeaponType.PlayerHandgun: { fireSound = SoundTrack.PlayerHandgunFire; fireParticle = ParticleType.PlayerHandgunFire; unitHitParticle = ParticleType.PlayerHandgunUnitHit; worldHitParticle = ParticleType.PlayerHandgunWorldHit; } break; case WeaponType.CameleerGun: { fireSound = SoundTrack.CameleerFire; fireParticle = ParticleType.EnemyGunFire; unitHitParticle = ParticleType.EnemyGunUnitHit; worldHitParticle = ParticleType.EnemyGunWorldHit; } break; case WeaponType.MaomingGun: { fireSound = SoundTrack.MaomingFire; fireParticle = ParticleType.PlayerMachineGunFire; unitHitParticle = ParticleType.EnemyGunUnitHit; worldHitParticle = ParticleType.EnemyGunWorldHit; } break; case WeaponType.DuskmasCannon: { fireSound = SoundTrack.DuskmasFire; fireParticle = ParticleType.EnemyCannonFire; unitHitParticle = ParticleType.EnemyCannonUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; case WeaponType.TigerCannon: { fireSound = SoundTrack.TankFire; fireParticle = ParticleType.EnemyCannonFire; unitHitParticle = ParticleType.EnemyCannonUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; case WeaponType.HammerCannon: { fireSound = SoundTrack.HammerFire; fireParticle = ParticleType.EnemyCannonFire; unitHitParticle = ParticleType.EnemyCannonUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; case WeaponType.PhantomMelee: { fireSound = SoundTrack.BossMelee; fireParticle = ParticleType.Count; unitHitParticle = ParticleType.EnemyMeleeUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; } if (this.WeaponType != WeaponType.PlayerShotgun && this.WeaponType != WeaponType.PlayerHandgun) { StopFireSound(); } // Play a weapon firing sound if (RobotGameGame.CurrentGameLevel.Info.GamePlayType == GamePlayTypeId.Versus) { soundFire = GameSound.Play3D(fireSound, RobotGameGame.SinglePlayer.Emitter); } else { soundFire = GameSound.Play3D(fireSound, this.OwnerUnit.Emitter); } // Play firing particles if (specData.ModelAlone ) { // Multi fire if (this.SpecData.FireCount == 1) { for (int i = 0; i < SpecData.ModelCount; i++) { int boneIdx = indexWeaponFireDummy[i]; Matrix boneTransform = modelWeapon[i].BoneTransforms[boneIdx]; GameParticle.PlayParticle(fireParticle, boneTransform, fixedAxis); } // In case of two handed weapons, the index is changed // so that the tracer bullet will fire alternatively. if (dummySwichingIndex == 0) dummySwichingIndex = 1; else dummySwichingIndex = 0; int boneIndex = indexWeaponFireDummy[dummySwichingIndex]; firePosition = modelWeapon[dummySwichingIndex].BoneTransforms[ boneIndex].Translation; } // Delayed fire else { if (this.fireCount == 0) { GameParticle.PlayParticle(fireParticle, this.RightFireBone, fixedAxis); firePosition = this.RightFireBone.Translation; } else if (this.fireCount == 1) { GameParticle.PlayParticle(fireParticle, this.LeftFireBone, fixedAxis); firePosition = this.LeftFireBone.Translation; } } } else { Matrix fireMatrix = Matrix.Identity; if (fireBone1 != null) GameParticle.PlayParticle(fireParticle, (Matrix)fireBone1, fixedAxis); if (fireBone2 != null) GameParticle.PlayParticle(fireParticle, (Matrix)fireBone2, fixedAxis); if (fireBone1 != null && fireBone2 != null) { // In case of two handed weapons, the index is changed // so that the tracer bullet will fire alternatively. if (dummySwichingIndex == 0) { fireMatrix = (Matrix)fireBone1; dummySwichingIndex = 1; } else { fireMatrix = (Matrix)fireBone2; dummySwichingIndex = 0; } } else if( fireBone1 != null) fireMatrix = (Matrix)fireBone1; else if (fireBone2 != null) fireMatrix = (Matrix)fireBone2; firePosition = fireMatrix.Translation; } // Hit testing CollisionResult collideResult = FireHitTest(position, direction, distance, ref targetCollisionLayer, ref worldCollisionLayer); if (collideResult != null) { // Play hitting particle { ParticleType hitParticle = ParticleType.Count; // To player if (collideResult.detectedCollide.Owner is GameUnit) { GameUnit detectGameUnit = collideResult.detectedCollide.Owner as GameUnit; // Calculate a random intersect point for // hitting particle in unit sphere CollideSphere sphere = collideResult.detectedCollide as CollideSphere; switch (this.WeaponType) { case WeaponType.PlayerMachineGun: case WeaponType.PlayerShotgun: case WeaponType.PlayerHandgun: case WeaponType.CameleerGun: case WeaponType.MaomingGun: { Vector3 dir = this.OwnerUnit.Position - detectGameUnit.Position; dir.Normalize(); dir.X += HelperMath.RandomNormal2(); dir.Y += HelperMath.RandomNormal2(); dir.Normalize(); collideResult.normal = (Vector3)dir; collideResult.intersect = sphere.BoundingSphere.Center + ((Vector3)dir * sphere.Radius); } break; case WeaponType.DuskmasCannon: case WeaponType.HammerCannon: case WeaponType.TigerCannon: case WeaponType.PhantomMelee: { Vector3 dir = this.OwnerUnit.Position - sphere.BoundingSphere.Center; dir.Normalize(); collideResult.normal = (Vector3)dir; collideResult.intersect = sphere.BoundingSphere.Center; } break; } hitParticle = unitHitParticle; targetPosition = (Vector3)collideResult.intersect; } // To world else { hitParticle = worldHitParticle; targetPosition = (Vector3)collideResult.intersect; } if (collideResult.normal != null) { GameParticle.PlayParticle(hitParticle, (Vector3)collideResult.intersect, (Vector3)collideResult.normal, Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } else { GameParticle.PlayParticle(hitParticle, Matrix.CreateTranslation((Vector3)collideResult.intersect), Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } } // Hit to other mech if (collideResult.detectedCollide.Owner is GameUnit) { GameUnit HitUnit = (GameUnit)collideResult.detectedCollide.Owner; // Call hit function to unit HitUnit.ActionHit(this.OwnerUnit); if (HitUnit.IsDead ) { if (this.OwnerUnit is GamePlayer) { // If the versus mode, you'll be get kill point if( RobotGameGame.CurrentStage is VersusStageScreen) { VersusStageScreen stage = RobotGameGame.CurrentStage as VersusStageScreen; GamePlayer player = this.OwnerUnit as GamePlayer; player.KillPoint++; stage.DisplayKillPoint((int)player.PlayerIndex, player.KillPoint); } } } hit = true; } } // Fire the tracer bullet particle if( this.specData.TracerBulletFire ) { RobotGameGame.CurrentStage.TracerBulletManager.Fire(0, firePosition, targetPosition, this.specData.TracerBulletSpeed, this.specData.TracerBulletLength, this.specData.TracerBulletThickness, true); } // Cannot fire return hit; }
public void ChargeThrow() { wState = WeaponState.charging; }
public void StopFiring() { currentState = WeaponState.Off; }
public void Fire(Transform fire_point = null) { RaycastHit hit_info; if(!fire_point) { fire_point = Barrel; } if(m_State != WeaponState.FIRING && Ammo > 0) { for(int projectile_i = 0; projectile_i < ProjectilesPerShot; ++projectile_i) { float offset_spin = 360.0f*Random.value; float offset_tilt = SpreadAngle*(Random.value*Random.value*Random.value); Quaternion rotation_offset = fire_point.rotation*Quaternion.Inverse(Quaternion.Euler(new Vector3(0.0f, offset_tilt, offset_spin))); // FIXME: Do this with quaternions. Converting is really childish. Vector3 firing_direction = rotation_offset*Vector3.forward; if(Debug.isDebugBuild) { Debug.DrawRay(fire_point.position, 50.0f*(firing_direction), new Color(0.8f, 0.4f, 0.0f), 1.2f); } if(RaycastProjectileEnabled) { if(Physics.Raycast(fire_point.position, firing_direction, out hit_info)) { float distance_damage = (RaycastFalloffDamage ? RaycastDamage - Mathf.InverseLerp(RaycastFalloffCloseDistance, RaycastFalloffFarDistance, hit_info.distance)*(RaycastDamage - RaycastFalloffFarDamage) : RaycastDamage); if(RaycastImpactPrefab) { GameObject impact = (GameObject)Instantiate(RaycastImpactPrefab, hit_info.point, Quaternion.FromToRotation(Vector3.up, hit_info.normal)); impact.transform.localRotation = impact.transform.localRotation*Quaternion.Euler(new Vector3(0.0f, 360.0f*Random.value, 0.0f)); impact.transform.SetParent(hit_info.collider.transform, true); Destroy(impact, RaycastImpactDuration); } } } else if(ProjectilePrefab) { GameObject projectile = (GameObject)Instantiate(ProjectilePrefab, fire_point.position + fire_point.TransformDirection(ProjectileOffset), rotation_offset); Rigidbody projectile_body = projectile.GetComponent<Rigidbody>(); if(projectile_body) { projectile_body.AddForce(ProjectileForce*projectile.transform.forward, ProjectileForceMode); } } } m_State = WeaponState.FIRING; m_StateReleaseTimeout = Time.time + CycleTime; Ammo = (Ammo <= 0 ? 0 : Ammo - 1); } }
public IEnumerator MainAction() { isActive = true; //if(PreAttackClip!=null) //{ myState = WeaponState.preattacking; rootAnimationTarget.CrossFade(PreAttackClip.name); yield return new WaitForSeconds(PreAttackClip.length); //} myState = WeaponState.attacking; //if(AttackClip != null) //{ rootAnimationTarget.CrossFade(AttackClip.name); if(usageType == UsageType.click) { yield return new WaitForSeconds(AttackClip.length); StartCoroutine("EndMainAction"); } //} yield return null; }
// Resets Weapon State, // Resets all timers. public void ResetWeapon() { CurrentState = WeaponState.Ready; FiringTimer = 0.0f; LastHitCheckTimer = 0.0f; CooldownTimer = 0.0f; }
public void DoWeaponFrame(float time) { /* anims (TR1 - TR5): * pistols: * 0: idle to fire; * 1: draw weapon (short?); * 2: draw weapon (full); * 3: fire process; * * shotgun, rifles, crossbow, harpoon, launchers (2 handed weapons): * 0: idle to fire; * 1: draw weapon; * 2: fire process; * 3: hide weapon; * 4: idle to fire (targeted); */ if (Command.ReadyWeapon && CurrentWeapon > 0 && WeaponCurrentState == WeaponState.Hide) { SetWeaponModel(CurrentWeapon, 1); } float dt; int t; for (var ssAnim = Bf.Animations.Next; ssAnim != null; ssAnim = ssAnim.Next) { if (ssAnim.Model != null && ssAnim.Model.Animations.Count > 4) { switch (WeaponCurrentState) { case WeaponState.Hide: if (Command.ReadyWeapon) // ready weapon { ssAnim.CurrentAnimation = TR_ANIMATION.LaraWalkForward; ssAnim.NextAnimation = TR_ANIMATION.LaraWalkForward; ssAnim.CurrentFrame = 0; ssAnim.NextFrame = 0; ssAnim.FrameTime = 0.0f; WeaponCurrentState = WeaponState.HideToReady; } break; case WeaponState.HideToReady: ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; if (ssAnim.CurrentFrame < t - 1) { ssAnim.NextFrame = (short) ((ssAnim.CurrentFrame + 1) % t); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else if (ssAnim.CurrentFrame < t) { ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraRun; } else { ssAnim.CurrentFrame = 0; ssAnim.CurrentAnimation = TR_ANIMATION.LaraRun; ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraRun; ssAnim.FrameTime = 0.0f; WeaponCurrentState = WeaponState.Idle; } break; case WeaponState.Idle: ssAnim.CurrentFrame = 0; ssAnim.CurrentAnimation = TR_ANIMATION.LaraRun; ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraRun; ssAnim.FrameTime = 0.0f; if (Command.ReadyWeapon) { ssAnim.CurrentAnimation = ssAnim.NextAnimation = TR_ANIMATION.LaraEndWalkLeft; ssAnim.CurrentFrame = ssAnim.NextFrame = 0; ssAnim.FrameTime = 0.0f; WeaponCurrentState = WeaponState.IdleToHide; } else if (Command.Action) { WeaponCurrentState = WeaponState.IdleToFire; } else { // do nothing here, may be; } break; case WeaponState.FireToIdle: // Yes, same animation, reverse frames order; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; ssAnim.CurrentFrame = (short) (t - 1 - ssAnim.CurrentFrame); if (ssAnim.CurrentFrame > 0) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame - 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else { ssAnim.NextFrame = ssAnim.CurrentFrame = 0; ssAnim.NextAnimation = ssAnim.CurrentAnimation; WeaponCurrentState = WeaponState.Idle; } break; case WeaponState.IdleToFire: ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; if (ssAnim.CurrentFrame < t - 1) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame + 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else if (ssAnim.CurrentFrame < t) { ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraEndWalkRight; } else if (Command.Action) { ssAnim.CurrentFrame = 0; ssAnim.NextFrame = 1; ssAnim.NextAnimation = ssAnim.CurrentAnimation = TR_ANIMATION.LaraEndWalkRight; WeaponCurrentState = WeaponState.Fire; } else { ssAnim.FrameTime = 0.0f; ssAnim.CurrentFrame = (short) (ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count - 1); WeaponCurrentState = WeaponState.FireToIdle; } break; case WeaponState.Fire: if (Command.Action) { // inc time, loop; ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; if (ssAnim.CurrentFrame < t - 1) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame + 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else if (ssAnim.CurrentFrame < t) { ssAnim.NextFrame = 0; ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else { ssAnim.FrameTime = dt; ssAnim.CurrentFrame = 0; ssAnim.NextFrame = 1; } } else { ssAnim.FrameTime = 0.0f; ssAnim.NextAnimation = ssAnim.CurrentAnimation = TR_ANIMATION.LaraRun; ssAnim.CurrentFrame = (short) (ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count - 1); ssAnim.NextFrame = (short) (ssAnim.CurrentFrame > 0 ? ssAnim.CurrentFrame - 1 : 0); WeaponCurrentState = WeaponState.FireToIdle; } break; case WeaponState.IdleToHide: t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; if (ssAnim.CurrentFrame < t - 1) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame + 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else { ssAnim.NextFrame = ssAnim.CurrentFrame = 0; ssAnim.NextAnimation = ssAnim.CurrentAnimation; WeaponCurrentState = WeaponState.Hide; SetWeaponModel(CurrentWeapon, 0); } break; } } else if (ssAnim.Model != null && ssAnim.Model.Animations.Count == 4) { switch (WeaponCurrentState) { case WeaponState.Hide: if (Command.ReadyWeapon) // ready weapon { ssAnim.CurrentAnimation = TR_ANIMATION.LaraEndWalkRight; ssAnim.NextAnimation = TR_ANIMATION.LaraEndWalkRight; ssAnim.CurrentFrame = 0; ssAnim.NextFrame = 0; ssAnim.FrameTime = 0.0f; WeaponCurrentState = WeaponState.HideToReady; } break; case WeaponState.HideToReady: ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; if (ssAnim.CurrentFrame < t - 1) { ssAnim.NextFrame = (short) ((ssAnim.CurrentFrame + 1) % t); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else if (ssAnim.CurrentFrame < t) { ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraRun; } else { ssAnim.CurrentFrame = 0; ssAnim.CurrentAnimation = TR_ANIMATION.LaraRun; ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraRun; ssAnim.FrameTime = 0.0f; WeaponCurrentState = WeaponState.Idle; } break; case WeaponState.Idle: ssAnim.CurrentFrame = 0; ssAnim.CurrentAnimation = TR_ANIMATION.LaraRun; ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraRun; ssAnim.FrameTime = 0.0f; if (Command.ReadyWeapon) { ssAnim.CurrentAnimation = ssAnim.NextAnimation = TR_ANIMATION.LaraEndWalkRight; ssAnim.CurrentFrame = ssAnim.NextFrame = (short) (ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count - 1); ssAnim.FrameTime = 0.0f; WeaponCurrentState = WeaponState.IdleToHide; } else if (Command.Action) { WeaponCurrentState = WeaponState.IdleToFire; } else { // do nothing here, may be; } break; case WeaponState.FireToIdle: // Yes, same animation, reverse frames order; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; ssAnim.CurrentFrame = (short) (t - 1 - ssAnim.CurrentFrame); if (ssAnim.CurrentFrame > 0) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame - 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else { ssAnim.NextFrame = ssAnim.CurrentFrame = 0; ssAnim.NextAnimation = ssAnim.CurrentAnimation; WeaponCurrentState = WeaponState.Idle; } break; case WeaponState.IdleToFire: ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; if (ssAnim.CurrentFrame < t - 1) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame + 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else if (ssAnim.CurrentFrame < t) { ssAnim.NextFrame = 0; ssAnim.NextAnimation = TR_ANIMATION.LaraEndWalkLeft; } else if (Command.Action) { ssAnim.CurrentFrame = 0; ssAnim.NextFrame = 1; ssAnim.NextAnimation = ssAnim.CurrentAnimation = TR_ANIMATION.LaraEndWalkLeft; WeaponCurrentState = WeaponState.Fire; } else { ssAnim.FrameTime = 0.0f; ssAnim.CurrentFrame = (short) (ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count - 1); WeaponCurrentState = WeaponState.FireToIdle; } break; case WeaponState.Fire: if (Command.Action) { // inc time, loop; ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; if (ssAnim.CurrentFrame < t - 1) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame + 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else if (ssAnim.CurrentFrame < t) { ssAnim.NextFrame = 0; ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else { ssAnim.FrameTime = dt; ssAnim.CurrentFrame = 0; ssAnim.NextFrame = 1; } } else { ssAnim.FrameTime = 0.0f; ssAnim.NextAnimation = ssAnim.CurrentAnimation = TR_ANIMATION.LaraRun; ssAnim.CurrentFrame = (short) (ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count - 1); ssAnim.NextFrame = (short) (ssAnim.CurrentFrame > 0 ? ssAnim.CurrentFrame - 1 : 0); WeaponCurrentState = WeaponState.FireToIdle; } break; case WeaponState.IdleToHide: // Yes, same animation, reverse frames order; t = ssAnim.Model.Animations[(int) ssAnim.CurrentAnimation].Frames.Count; ssAnim.FrameTime += time; ssAnim.CurrentFrame = (short) (ssAnim.FrameTime / ssAnim.Period); dt = ssAnim.FrameTime - ssAnim.CurrentFrame * ssAnim.Period; ssAnim.Lerp = dt / ssAnim.Period; ssAnim.CurrentFrame = (short) (t - 1 - ssAnim.CurrentFrame); if (ssAnim.CurrentFrame > 0) { ssAnim.NextFrame = (short) (ssAnim.CurrentFrame - 1); ssAnim.NextAnimation = ssAnim.CurrentAnimation; } else { ssAnim.NextFrame = ssAnim.CurrentFrame = 0; ssAnim.NextAnimation = ssAnim.CurrentAnimation; WeaponCurrentState = WeaponState.Hide; SetWeaponModel(CurrentWeapon, 0); } break; } } DoAnimCommands(ssAnim, 0); } }
/// <summary> /// Begins the Firing Process. /// </summary> /// <returns>true if we successfully started firing. False if not</returns> public bool CommenceFire() { if (CurrentState == WeaponState.Firing || CurrentState == WeaponState.OnCooldown) return false; Owner.ApplyHeat(Proto.HeatGeneration); FiringTimer = 0.0f; LastHitCheckTimer = Proto.ChainDamageRate; CurrentState = WeaponState.Firing; return true; }
public void ReleaseThrow(Vector3 LookDir) { wState = WeaponState.released; ReleaseBall(LookDir); }
public void Reload() { if(m_State == WeaponState.READY && Ammo != MagazineSize) { m_State = WeaponState.RELOADING; m_StateReleaseTimeout = Time.time + ReloadDuration; } }
//=================================================================================================================o void DoSwitchWeapons() { // Not while Drawing/holstering, not in combat modus if (mainState == MainState.Combat || isWeaponDraw) return; // Epuip weapon set switch (weaponState) { case WeaponState.Unarmed: break; case WeaponState.Sword: if (sword_Holster.name == "emptyObj") // Skip if no weapon is assigned { weaponState = WeaponState.Bow; if (lastWeapon != null) { lastWeapon.active = false; lastWeapon = null; } goto case WeaponState.Bow; } // Switch set else if (lastWeapon != null) { StartCoroutine( OnOffSwitch(sword_Holster, lastWeapon)); } else sword_Holster.active = true; // In first cycle, lastweapon is null lastWeapon = sword_Holster; break; case WeaponState.Bow: if (bow_Holster.name == "emptyObj") // Skip if no weapon is assigned { weaponState = WeaponState.Rifle; if (lastWeapon != null) { lastWeapon.active = false; lastWeapon = null; } goto case WeaponState.Rifle; } // Switch set else if (lastWeapon != null) { StartCoroutine( OnOffSwitch(bow_Holster, lastWeapon)); } lastWeapon = bow_Holster; break; case WeaponState.Rifle: if (rifle_Holster.name == "emptyObj") // Skip if no weapon is assigned { weaponState = WeaponState.Pistol; if (lastWeapon != null) { lastWeapon.active = false; lastWeapon = null; } goto case WeaponState.Pistol; } // Switch set else if (lastWeapon != null) { StartCoroutine( OnOffSwitch(rifle_Holster, lastWeapon)); } lastWeapon = rifle_Holster; break; case WeaponState.Pistol: if (pistol_Holster.name == "emptyObj") // Skip if no weapon is assigned { weaponState = WeaponState.None; if (lastWeapon != null) { lastWeapon.active = false; lastWeapon = null; } goto case WeaponState.None; } // Switch set else if (lastWeapon != null) { StartCoroutine( OnOffSwitch(pistol_Holster, lastWeapon)); } lastWeapon = pistol_Holster; break; case WeaponState.None: if (lastWeapon != null) lastWeapon.active = false; // Weaponless break; } }
void Start() { WeaponState = GetComponent<WeaponState>(); EventTire = this.GetEventTire(); LoadWeaponState(); }
public IEnumerator EndMainAction() { if(!isActive) yield return null; else { StopCoroutine("MainAction"); myState = WeaponState.postattacking; if(PostAttackClip != null) { rootAnimationTarget.CrossFade(PostAttackClip.name); isActive = false; yield return new WaitForSeconds(PostAttackClip.length); } myState = WeaponState.idle; isActive = false; } }
//=================================================================================================================o // Next Weapon + cool-down IEnumerator NextWeapon() { if (baseState == BaseState.Base) { canNextWeapon = false; weaponState += 1; // Next if (weaponState == WeaponState.Sword) // Skip if no weapon is assigned { if (weapons.sword_Holster == null) // No weapon - next { weaponState += 1; } else { if (weapons.sword_Hand) weapons.sword_Hand.GetComponent<Renderer>().enabled = false; if (weapons.sword_Holster) weapons.sword_Holster.GetComponent<Renderer>().enabled = true; // On if (weapons.bow_Hand) weapons.bow_Hand.GetComponent<Renderer>().enabled = false; if (weapons.bow_Holster) weapons.bow_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Quiver) weapons.bow_Quiver.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Hand) weapons.rifle_Hand.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Holster) weapons.rifle_Holster.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Hand) weapons.pistol_Hand.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Holster) weapons.pistol_Holster.GetComponent<Renderer>().enabled = false; } } if (weaponState == WeaponState.Bow) // Skip if no weapon is assigned { if (weapons.bow_Holster == null) // No weapon - next { weaponState += 1; } else { if (weapons.sword_Hand) weapons.sword_Hand.GetComponent<Renderer>().enabled = false; if (weapons.sword_Holster) weapons.sword_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Hand) weapons.bow_Hand.GetComponent<Renderer>().enabled = false; if (weapons.bow_Holster) weapons.bow_Holster.GetComponent<Renderer>().enabled = true; // On if (weapons.bow_Quiver) weapons.bow_Quiver.GetComponent<Renderer>().enabled = true; // On if (weapons.rifle_Hand) weapons.rifle_Hand.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Holster) weapons.rifle_Holster.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Hand) weapons.pistol_Hand.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Holster) weapons.pistol_Holster.GetComponent<Renderer>().enabled = false; } } if (weaponState == WeaponState.Rifle) // Skip if no weapon is assigned { if (weapons.rifle_Holster == null) // No weapon - next { weaponState += 1; } else { if (weapons.sword_Hand) weapons.sword_Hand.GetComponent<Renderer>().enabled = false; if (weapons.sword_Holster) weapons.sword_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Hand) weapons.bow_Hand.GetComponent<Renderer>().enabled = false; if (weapons.bow_Holster) weapons.bow_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Quiver) weapons.bow_Quiver.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Hand) weapons.rifle_Hand.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Holster) weapons.rifle_Holster.GetComponent<Renderer>().enabled = true; // On if (weapons.pistol_Hand) weapons.pistol_Hand.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Holster) weapons.pistol_Holster.GetComponent<Renderer>().enabled = false; } } if (weaponState == WeaponState.Pistol) // Skip if no weapon is assigned { if (weapons.pistol_Holster == null) // No weapon - next { weaponState += 1; } else { if (weapons.sword_Hand) weapons.sword_Hand.GetComponent<Renderer>().enabled = false; if (weapons.sword_Holster) weapons.sword_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Hand) weapons.bow_Hand.GetComponent<Renderer>().enabled = false; if (weapons.bow_Holster) weapons.bow_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Quiver) weapons.bow_Quiver.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Hand) weapons.rifle_Hand.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Holster) weapons.rifle_Holster.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Hand) weapons.pistol_Hand.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Holster) weapons.pistol_Holster.GetComponent<Renderer>().enabled = true; // On } } // No weapon if (weaponState == WeaponState.None /*|| weaponState == WeaponState.Unarmed*/) { if (weapons.sword_Hand) weapons.sword_Hand.GetComponent<Renderer>().enabled = false; if (weapons.sword_Holster) weapons.sword_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Hand) weapons.bow_Hand.GetComponent<Renderer>().enabled = false; if (weapons.bow_Holster) weapons.bow_Holster.GetComponent<Renderer>().enabled = false; if (weapons.bow_Quiver) weapons.bow_Quiver.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Hand) weapons.rifle_Hand.GetComponent<Renderer>().enabled = false; if (weapons.rifle_Holster) weapons.rifle_Holster.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Hand) weapons.pistol_Hand.GetComponent<Renderer>().enabled = false; if (weapons.pistol_Holster) weapons.pistol_Holster.GetComponent<Renderer>().enabled = false; } // Last in the enum if (weaponState > (WeaponState)System.Enum.GetValues(typeof(WeaponState)).Length - 1) weaponState = WeaponState.None; // Start at the first again yield return new WaitForSeconds(0.3f); // Cool-down canNextWeapon = true; } }