protected IEnumerator UseHold() { if (!HasProjectile) { ToolState = PlayerToolState.Equipped; yield break; } //the only tool type where use hold applies is equippable + weapon/ProjectileLauncher //Equippable equippable = null; //Weapon weapon = null; if (worlditem.Is <Equippable>(out mEquippable) && worlditem.Is <Weapon>(out mWeapon) && mWeapon.Style == PlayerToolStyle.ProjectileLaunch) { //meets all the requirements LaunchForce = Mathf.Clamp(LaunchForce + gHoldForceIncrease, mWeapon.MinLaunchForce, mWeapon.MaxLaunchForce); //player.Projections.WeaponTrajectory.UpdateForce (LaunchForce); if (UsesTensionMorph) { TensionChannel.Percent = ((LaunchForce - mWeapon.MinLaunchForce) / mWeapon.MaxLaunchForce) * 100f; } } else { ToolState = PlayerToolState.Equipped; } //wait a tick yield return(null); yield break; }
protected IEnumerator Unequip() { //turn off the player projection (even if it's not already on) player.Projections.WeaponTrajectory.Hide(); ToolState = PlayerToolState.Unequipping; //clear all actions mActions.Clear(); yield return(StartCoroutine(PlayAnimation("ToolGenericUnequip"))); ToolState = PlayerToolState.Unequipped; RefreshToolDoppleganger(false); if (HasWorldItem) { //parent the worlditem back under its group just in case //this will become unnecessary eventually //worlditem.UnlockTransform (tr); UnlockWorldItem(); worlditem.SetMode(WIMode.Stacked); worlditem = null; } //if we're unequipping because the AQI is changing //then wait here until it's finished while (player.Inventory.LockQuickslots) { yield return(null); } yield break; }
protected IEnumerator FindAndLoadProjectile(Equippable equippable, Weapon weapon, bool playLoadAnimation) { //get the projectile - if we don't find one, we don't need to do anything else if (!player.Inventory.FindProjectileForWeapon(weapon, out ProjectileObject, out ProjectileStack)) { //this will shut off the doppleganger //RefreshToolDoppleganger (false); yield break; } //otherwise move on //if playLoadAnimation is true, play the unequip/equip animations to simulate reaching down for the projectile if (playLoadAnimation) { yield return(StartCoroutine(PlayAnimation("ToolGenericUnequip"))); } //refresh the doppleganger here to add it to the weapon //break it down first RefreshToolDoppleganger(false); //then rebuild it RefreshToolDoppleganger(true); //if we're playing the animation, we have to play the 'equip' animation here to bring the weapon back up if (playLoadAnimation) { yield return(StartCoroutine(PlayAnimation("ToolGenericEquip"))); } ToolState = PlayerToolState.Equipped; yield break; }
protected IEnumerator UseCancel() { LaunchForce = 0f; //return projectile to inventory if we have one //turn off trajectory player.Projections.WeaponTrajectory.Hide(); //set state to equipped ToolState = PlayerToolState.Equipped; yield break; }
protected IEnumerator Unequip() { //turn off the player projection (even if it's not already on) player.Projections.WeaponTrajectory.Hide(); ToolState = PlayerToolState.Unequipping; //clear all actions mActions.Clear(); LaunchForce = 0f; yield return(StartCoroutine(PlayAnimation("ToolGenericUnequip"))); //clear dopplegangers, projectiles, etc if (HasProjectile) { WIStackError stackError = WIStackError.None; if (ProjectileStack != null) { //push the projectile onto the bottom of its stack //this will prevent rampant AQI switching Stacks.Push.Item(ProjectileStack, ProjectileObject, false, StackPushMode.Auto, ref stackError); } else { //if we don't have the stack any more just add it to the player inventory player.Inventory.AddItems(ProjectileObject, ref stackError); } ProjectileObject = null; ProjectileStack = null; } ToolState = PlayerToolState.Unequipped; RefreshToolDoppleganger(false); if (HasWorldItem) { //parent the worlditem back under its group just in case //this will become unnecessary eventually //worlditem.UnlockTransform (tr); UnlockWorldItem(); if (worlditem.Is(WIMode.Equipped)) { worlditem.SetMode(WIMode.Stacked); } worlditem = null; } //if we're unequipping because the AQI is changing //then wait here until it's finished while (player.Inventory.LockQuickslots) { yield return(null); } yield break; }
public IEnumerator OnLoseTool() { //this can happen with stuff like item placement / dropping //we want to reset the tool so it's ready for the next item ToolState = PlayerToolState.Unequipped; worlditem = null; BreakDownToolDoppleganger(); yield return(StartCoroutine(PlayAnimation("ToolGenericUnequip"))); yield break; }
protected IEnumerator LaunchProjectile(Equippable equippable, Weapon weapon) { if (!HasProjectile) { //if we don't have a projectile it doesn't matter //MasterAudio.PlaySound (mEquippable.Sounds.SoundType, ToolDoppleganger.transform, mEquippable.Sounds.SoundUseUnuccessfully); mEquippable.UseUnsuccessfully(); ToolState = PlayerToolState.Equipped; yield break; } //convert the projectile object to a world item if it isn't already Projectile projectile = null; if (ProjectileObject.IsWorldItem) { //get the projectile from the existing worlditem projectile = ProjectileObject.worlditem.Get <Projectile>(); } else { WorldItem worlditemProjectile = null; //clone the projectile from the stack item WorldItems.CloneFromStackItem(ProjectileObject.GetStackItem(WIMode.Stacked), WIGroups.Get.Player, out worlditemProjectile); //initialize immediately worlditemProjectile.Initialize(); worlditemProjectile.transform.position = ToolActionPointObject.position; worlditemProjectile.transform.rotation = ToolActionPointObject.rotation; //set the projectile object to null ProjectileObject = null; //give it a second to initialze projectile = worlditemProjectile.Get <Projectile>(); } if (projectile != null) { projectile.Launch(ToolActionPointObject, weapon, LaunchForce); //play the launching sound mEquippable.UseSuccessfully(); //MasterAudio.PlaySound (mEquippable.Sounds.SoundType, ToolDoppleganger.transform, mEquippable.Sounds.SoundUseSuccessfully); yield return(null); } else { Debug.Log("Projectile was null"); } RefreshToolDoppleganger(false); yield return(null); if (UsesTensionMorph) { TensionChannel.Percent = 0f; } yield break; }
protected IEnumerator CycleTool(ToolAction cycleType) { //Equippable equippable = null; if (worlditem.Is <Equippable>(out mEquippable)) { if (cycleType == ToolAction.CycleNext) { mEquippable.OnCycleNext.SafeInvoke(); } else { mEquippable.OnCyclePrev.SafeInvoke(); } while (!mEquippable.CyclingFinished) { yield return(null); } } ToolState = PlayerToolState.Equipped; }
protected IEnumerator Equip() { if (Holstered) { Debug.Log("Holstered"); yield break; } ToolState = PlayerToolState.Equipping; //set equipped mode worlditem.SetMode(WIMode.Equipped); //clear all actions mActions.Clear(); //see if the worlditem is a weapon //if it is, find a projectile for it Weapon weapon = null; Equippable equippable = null; if (worlditem.Is <Equippable> (out equippable)) //tell equippable that we're equipping { equippable.EquipStart(); } //refresh our dopplegangers //we do this BEFORE playing the generic equip animation //so it actually has something to show RefreshToolDoppleganger(true); if (equippable != null) { equippable.EquipFinish(); } yield return(StartCoroutine(PlayAnimation("ToolGenericEquip"))); ToolState = PlayerToolState.Equipped; yield break; }
protected IEnumerator UseStartProjectile(Equippable equippable, Weapon weapon) { if (!HasProjectile) { yield return(StartCoroutine(FindAndLoadProjectile(equippable, weapon, true))); } //if we still don't have a projectile, do nothing if (!HasProjectile) { //just play the sound without launching anything mEquippable.UseSuccessfully(); //MasterAudio.PlaySound (mEquippable.Sounds.SoundType, ToolDoppleganger.transform, mEquippable.Sounds.SoundUseSuccessfully); ToolState = PlayerToolState.Equipped; yield break; } //show the trajectory of the projectile LaunchForce = weapon.MinLaunchForce; //set its force to min projectile force player.Projections.WeaponTrajectory.Show(ToolActionPointObject, LaunchForce, 1f); //set state to increasing force so use hold and use release have the right effect ToolState = PlayerToolState.IncreasingForce; yield break; }
protected IEnumerator UseRelease() { //the only tool type where use hold applies is equippable + weapon/ProjectileLauncher //Equippable equippable = null; //Weapon weapon = null; if (worlditem.Is <Equippable>(out mEquippable) && worlditem.Is <Weapon>(out mWeapon) && mWeapon.Style == PlayerToolStyle.ProjectileLaunch) { //meets all the requirements player.Projections.WeaponTrajectory.Hide(); yield return(StartCoroutine(LaunchProjectile(mEquippable, mWeapon))); yield return(StartCoroutine(FindAndLoadProjectile(mEquippable, mWeapon, true))); } //wait a tick yield return(null); //once we've sent the projectile we're just equipped player.Projections.WeaponTrajectory.Hide(); LaunchForce = 0f; ToolState = PlayerToolState.Equipped; yield break; }
protected IEnumerator UseStart() { //(no equippable) - (do nothing) //Equippable/Generic + (no weapon) - (do nothing) //Equippable/Generic + Weapon/Swing - UseStartSwing //Equippable/Generic + Weapon/Slice - UseStartSlice //Equippable/Generic + Weapon/ProjectileLauncher - UseStartProjectile //Equippable/GenericUsable - UseStartStatic //Equippable equippable = null; if (worlditem.Is <Equippable>(out mEquippable)) { mEquippable.UseStart(); switch (mEquippable.Type) { case PlayerToolType.Generic: //get the weapon type //Weapon weapon = null; if (worlditem.Is <Weapon>(out mWeapon)) { switch (mWeapon.Style) { case PlayerToolStyle.Swing: yield return(StartCoroutine(UseStartSwing(mWeapon))); break; case PlayerToolStyle.Slice: yield return(StartCoroutine(UseStartSlice(mWeapon))); break; case PlayerToolStyle.ProjectileLaunch: yield return(StartCoroutine(UseStartProjectile(mEquippable, mWeapon))); break; default: //do nothing ToolState = PlayerToolState.Equipped; break; } } else { //if we're generic equippable and have no weapon //we're done here ToolState = PlayerToolState.Equipped; } break; case PlayerToolType.GenericUsable: //just spawn an option menu yield return(StartCoroutine(UseStartGenericUsable())); ToolState = PlayerToolState.Equipped; break; case PlayerToolType.CustomAction: //this kind of equippable performs an action //start the action, then wait yield return(StartCoroutine(UseStartCustomAction(mEquippable))); ToolState = PlayerToolState.Equipped; break; //case PlayerToolType.PathEditor: default: //TODO re-implement path editor break; } } else { //if we're not equippable then we're done ToolState = PlayerToolState.Equipped; } yield break; }
public IEnumerator UpdateTool() { mUpdatingTool = true; while (mUpdatingTool) { while (!GameManager.Is(Frontiers.FGameState.InGame | Frontiers.FGameState.GamePaused) || !player.HasSpawned || player.IsDead || player.Status.State.IsSleeping || Cutscene.IsActive) { if (IsEquipped) { yield return(StartCoroutine(Unequip())); } //wait it out yield return(null); } if (HasWorldItem) { if (!worlditem.Is(WIMode.Equipped)) { yield return(StartCoroutine(OnLoseTool())); } } ToolAction nextAction = ToolAction.None; switch (ToolState) { case PlayerToolState.Unequipping: case PlayerToolState.Equipping: //wait break; case PlayerToolState.Unequipped: default: nextAction = NextAction(); switch (nextAction) { case ToolAction.Equip: if (CanEquip()) //if we're unequipped, start equipping { yield return(StartCoroutine(Equip())); } break; default: //check to see if there's an AQI break; } break; case PlayerToolState.Equipped: //handle actions nextAction = NextAction(); switch (nextAction) { case ToolAction.Equip: case ToolAction.Unequip: //equipping/unequipping are handled here ////Debug.Log ("We're equipped and our next action is to equip..."); if (CanUnequip()) //if we can unequip, get to it right away ////Debug.Log ("Unequipping in update"); { yield return(StartCoroutine(Unequip())); } //after that's done... yield return(null); //wait a tick... if (CanEquip()) //this will automatically fail if there's nothing to equip ////Debug.Log ("Equipping in update"); { yield return(StartCoroutine(Equip())); } break; case ToolAction.UseStart: if (CanUse()) //if we can use, get to it! { ToolState = PlayerToolState.InUse; yield return(StartCoroutine(UseStart())); } break; case ToolAction.UseHold: //if we're holding down the tool if (CanUse() && !WaitingForImpact) //if we can use, get to it! { double waitUntil = WorldClock.AdjustedRealTime + 0.5f; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } ToolState = PlayerToolState.InUse; yield return(StartCoroutine(UseStart())); } break; case ToolAction.CycleNext: case ToolAction.CyclePrev: if (CanCycle()) { ToolState = PlayerToolState.Cycling; yield return(StartCoroutine(CycleTool(nextAction))); } break; default: break; } break; case PlayerToolState.IncreasingForce: //this means we've equipped a projectile launcher and we're increasing force nextAction = NextAction(); switch (nextAction) { case ToolAction.UseHold: //add force to the projectile yield return(StartCoroutine(UseHold())); break; case ToolAction.UseRelease: //launch the projectile by calling use finish yield return(StartCoroutine(UseRelease())); break; case ToolAction.Unequip: default: //if we unequip, or anything else //OnFinishUsing yield return(StartCoroutine(UseCancel())); break; } break; case PlayerToolState.InUse: nextAction = NextAction(); switch (nextAction) { case ToolAction.UseFinish: default: //Equippable equippable = null; if (worlditem.Is <Equippable>(out mEquippable)) { mEquippable.UseFinish(); } ToolState = PlayerToolState.Equipped; break; case ToolAction.Equip: if (CanUnequip()) //if we can unequip, get to it right away ////Debug.Log ("Unequipping due to equip call"); { yield return(StartCoroutine(Unequip())); if (CanEquip()) { yield return(StartCoroutine(Equip())); } } break; case ToolAction.Unequip: if (CanUnequip()) //if we can unequip, get to it right away ////Debug.Log ("Unequipping due to unequip call"); { yield return(StartCoroutine(Unequip())); } break; } break; } //wait a tick yield return(null); } mUpdatingTool = false; yield break; }
protected IEnumerator Equip() { ToolState = PlayerToolState.Equipping; //set equipped mode worlditem.SetMode(WIMode.Equipped); //clear all actions mActions.Clear(); LaunchForce = 0f; //see if the worlditem is a weapon //if it is, find a projectile for it if (worlditem.Is <Equippable>(out mEquippable)) //tell equippable that we're equipping { mEquippable.EquipStart(); if (worlditem.Is <Weapon>(out mWeapon)) { player.FPSMelee.CurrentWeapon = mWeapon; bool loadProjectile = false; if (mWeapon.Style == PlayerToolStyle.ProjectileLaunch) { //first see if the projectile is compaitble if (HasProjectile) { if (!Weapon.CanLaunch(mWeapon, ProjectileObject)) { //if we can't launch it, load it loadProjectile = true; } } else { //if we don't have one, find it and load it loadProjectile = true; } } if (loadProjectile) { //load the projectile before we create the doppleganger //don't play animations because we're already playing the equipping animation yield return(StartCoroutine(FindAndLoadProjectile(mEquippable, mWeapon, false))); } } } //refresh our dopplegangers //we do this BEFORE playing the generic equip animation //so it actually has something to show RefreshToolDoppleganger(true); if (mEquippable != null) { mEquippable.EquipFinish(); } yield return(StartCoroutine(PlayAnimation("ToolGenericEquip"))); if (mEquippable != null) { mEquippable.FullyEquipped = true; } ToolState = PlayerToolState.Equipped; yield break; }