public void CanNowBlowFire() { PetInteractionManager.Instance.isInteractable = false; //once pet is in position for fire breathing. Idle animations need to be turn off //otherwise it might break the breathe fire animation PetAnimationManager.Instance.DisableIdleAnimation(); // if the pet is happy and healthy, add the fire button PetHealthStates healthState = DataManager.Instance.GameData.Stats.GetHealthState(); PetMoods moodState = DataManager.Instance.GameData.Stats.GetMoodState(); if (healthState == PetHealthStates.Healthy && moodState == PetMoods.Happy) { ArrivedShowFireButton(); //if can't breathe fire show message bool canBreatheFire = DataManager.Instance.GameData.PetInfo.CanBreathFire(); if (!canBreatheFire) { IndicateNoFire(); } } else { ShowUnhealthyNoFireSpeech(); } }
void OnTap(TapGesture gesture) { if (isInteractable) { try { string colliderName = gesture.Selection.GetComponent <Collider>().name; if (colliderName == this.gameObject.name) { if (colliderName == "HeadCollider") { PetMoods moodState = DataManager.Instance.GameData.Stats.GetMoodState(); PetHealthStates healthState = DataManager.Instance.GameData.Stats.GetHealthState(); if (moodState == PetMoods.Sad || healthState == PetHealthStates.Sick || healthState == PetHealthStates.VerySick) { PetAnimationManager.Instance.Swat(); } } else if (colliderName == "HighFiveCollider") { PetAnimationManager.Instance.FinishHighFive(); } } } catch (NullReferenceException e) { Debug.LogException(e); } } }
/// <summary> /// Gets the state of the mood. Based on the numerical value of the mood stat, /// returns an enum of the pet's mood /// </summary> /// <returns>The mood state.</returns> public PetMoods GetMoodState() { PetMoods eMood = PetMoods.Happy; if (Mood <= SAD_THRESH) { eMood = PetMoods.Sad; } return(eMood); }
//--------------------------------------------------- // GetMoodHash() // Returns a valid hashtable for the incoming mood, // from the incoming health hashtable. //--------------------------------------------------- private static Hashtable GetMoodHash(Hashtable hashHealth, PetMoods eMood) { // create the hashtable if it doesn't exist if (!hashHealth.ContainsKey(eMood)) { hashHealth[eMood] = new Hashtable(); } Hashtable hashMood = (Hashtable)hashHealth[eMood]; return(hashMood); }
//--------------------------------------------------- // StoreData() // Storing data for pet animations is a little complex, // so I created this function for it. //--------------------------------------------------- private static void StoreData(DataPetAnimation data) { // first let's just put it in the unrestricted hash based on the categories of the data StoreCategories(hashDataUnrestricted, data); // second store the data in a plain hash table for a list of all animations string strID = data.GetID(); if (hashDataList.ContainsKey(strID)) { Debug.LogError("Warning! Multiple pet animations with the same ID!"); } else { hashDataList[strID] = data; } // now let's do the real complex stuff... // the first hash for data is based on health PetHealthStates eHealth = data.GetHealth(); // create hashtable for the healt if it doesn't exist if (!hashData.ContainsKey(eHealth)) { hashData[eHealth] = new Hashtable(); } Hashtable hashHealth = (Hashtable)hashData[eHealth]; // next is mood PetMoods eMood = data.GetMood(); // slightly special case-y here...if the mood is "any", we want to duplicate the data across all hashes if (eMood == PetMoods.Any) { // iterate through all the moods, -1 (for any) for (int i = 0; i < System.Enum.GetValues(typeof(PetMoods)).Length - 1; ++i) { Hashtable hashMood = GetMoodHash(hashHealth, (PetMoods)i); // store the categories for this mood StoreCategories(hashMood, data); } } else { Hashtable hashMood = GetMoodHash(hashHealth, eMood); // store the categories for this mood StoreCategories(hashMood, data); } }
public DataPetAnimation(string id, Hashtable hashAttr, Hashtable hashData, string strError) { // set id strID = id; // get the animation state that this animation reflects string strState = HashUtils.GetHashValue <string>(hashAttr, "state", "Idling", strError); eAnimState = (PetAnimStates)System.Enum.Parse(typeof(PetAnimStates), strState); // get the clip name strClipName = XMLUtils.GetString(hashData["Clip"] as IXMLNode, id); if (hashData.ContainsKey("Sound")) { soundClip = XMLUtils.GetString(hashData["Sound"] as IXMLNode, strError); } // get whether or not this animation can be interrupted bCanInterrupt = XMLUtils.GetBool(hashData["CanInterrupt"] as IXMLNode, true); // get the weight nWeight = XMLUtils.GetInt(hashData["Weight"] as IXMLNode, 1, strError); // get the health state string strHealth = XMLUtils.GetString(hashData["Health"] as IXMLNode, "Healthy", strError); eHealthState = (PetHealthStates)System.Enum.Parse(typeof(PetHealthStates), strHealth); // get the mood // NOTE if the health for this anim is NOT set to healthy, the mood should be "Any" if (eHealthState != PetHealthStates.Healthy) { eMood = PetMoods.Any; } else { string strMood = XMLUtils.GetString(hashData["Mood"] as IXMLNode, "Happy", strError); eMood = (PetMoods)System.Enum.Parse(typeof(PetMoods), strMood); } //Debug.Log("Loading pet anim data: " + strID + " - " + eAnimState + " - " + strClipName + " - " + nWeight + " - " + eMood + " - " + eHealthState); // get the list of categories string strCats = XMLUtils.GetString(hashData["Categories"] as IXMLNode, "Idle", strError); string[] arrayCats = strCats.Split(","[0]); for (int i = 0; i < arrayCats.Length; ++i) { listCategories.Add(arrayCats[i]); } }
/// <summary> /// Shows the no fire notification. Calling this function assumes the player /// cannot breathe fire /// </summary> private void ShowUnhealthyNoFireSpeech() { PetHealthStates healthState = DataManager.Instance.GameData.Stats.GetHealthState(); PetMoods moodState = DataManager.Instance.GameData.Stats.GetMoodState(); if (healthState != PetHealthStates.Healthy) { PetSpeechAI.Instance.ShowNoFireSickMsg(); } else if (moodState != PetMoods.Happy) { PetSpeechAI.Instance.ShowNoFireHungryMsg(); } }
//--------------------------------------------------- // GetRestrictedData() // Get a random animation for a category that is // restricted; i.e. based on the pet's current mood, // health, etc. //--------------------------------------------------- public static DataPetAnimation GetRestrictedData(string strCat, bool bUseWeights = true) { if (hashData == null) { SetupData(); } // get the pet's mood and health states PetMoods eMood = DataManager.Instance.GameData.Stats.GetMoodState(); PetHealthStates eHealth = DataManager.Instance.GameData.Stats.GetHealthState(); // if the pet is NOT healthy, their mood does not matter //if ( eHealth != PetHealthStates.Healthy ) // eMood = PetMoods.Any; DataPetAnimation data = null; // this is a little complex...there are a bunch of checks we need to do so that we don't access any null objects if (hashData.ContainsKey(eHealth)) { Hashtable hashHealth = (Hashtable)hashData[eHealth]; if (hashHealth.ContainsKey(eMood)) { Hashtable hashMood = (Hashtable)hashHealth[eMood]; if (hashMood.ContainsKey(strCat)) { List <DataPetAnimation> listAnims = (List <DataPetAnimation>)hashMood[strCat]; // if we get here, all the data existed just right...so return a random, weighted animation data = GetRandomData(listAnims, true); } } } if (data == null) { Debug.LogError("A query for a restricted animation(" + eMood + ", " + eHealth + ", " + strCat + ") came up with nothing!"); } return(data); }
//--------------------------------------------------- // CheckForMoodTransition() // Checks to see if a mood transition is appropriate, // and if so, kicks it off on the pet animator. //--------------------------------------------------- private void CheckForMoodTransition(PetMoods oldMood, PetMoods newMood) { if (bBeingDestroyed) { return; } // if, at this moment, the pet is not healthy, there will be no mood transitions PetHealthStates health = DataManager.Instance.GameData.Stats.GetHealthState(); if (health != PetHealthStates.Healthy) { return; } // otherwise, let's actually check for a transition if (oldMood == PetMoods.Happy && newMood == PetMoods.Sad) { // fire event to notify listeners if (OnHappyToSad != null) { OnHappyToSad(this, EventArgs.Empty); } } else if (oldMood == PetMoods.Sad && newMood == PetMoods.Happy) { if (GatingManager.Instance.activeGates.ContainsKey(scriptPan.currentLocalPartition)) { GatingManager.Instance.CanNowBlowFire(); } // fire event if (OnSadToHappy != null) { OnSadToHappy(this, EventArgs.Empty); } } }
private void RefreshNotificationListener() { //listen to health -> sick or start out sick //we will check this only once every play period for 3 consecutive play period bool isRemindedThisPlayPeriod = DataManager.Instance.GameData.SickNotification.IsRemindedThisPlayPeriod; bool isReminderActive = DataManager.Instance.GameData.SickNotification.IsReminderActive; PetHealthStates healthState = DataManager.Instance.GameData.Stats.GetHealthState(); if (healthState == PetHealthStates.Sick || healthState == PetHealthStates.VerySick) { if (isReminderActive && !isRemindedThisPlayPeriod) { Invoke("ShowPopupPetSick", 0.25f); } } //else register for health state change and check if mood needs a notification else { if (isReminderActive && !isRemindedThisPlayPeriod) { StatsManager.OnHealthyToSick += OnHealthyToSickHandler; StatsManager.OnHealthyToVerySick += OnHealthyToSickHandler; } PetMoods moodState = DataManager.Instance.GameData.Stats.GetMoodState(); if (moodState == PetMoods.Sad && SceneUtils.CurrentScene == SceneUtils.BEDROOM) { bool isMoodDecayTutorialDone = DataManager.Instance.GameData.Tutorial.IsTutorialFinished(TutorialManagerBedroom.TUT_MOOD_DEGRADE); if (!isMoodDecayTutorialDone) { Invoke("ShowPopupNoEnergy", 0.25f); } } } }
/// <summary> /// Pets the reached destination. It is critical this function is only /// called if the pet is entering a gated room. /// </summary> /// <param name="sender">Sender.</param> /// <param name="args">Arguments.</param> private void PetReachedDest(object inhasender, EventArgs args) { if (OnReachedGate != null) { OnReachedGate(this, EventArgs.Empty); } PetInteractionManager.Instance.isInteractable = false; //once pet is in position for fire breathing. Idle animations need to be turn off //otherwise it might break the breathe fire animation PetAnimationManager.Instance.DisableIdleAnimation(); // if the pet is happy and healthy, add the fire button PetHealthStates healthState = DataManager.Instance.GameData.Stats.GetHealthState(); PetMoods moodState = DataManager.Instance.GameData.Stats.GetMoodState(); if (healthState == PetHealthStates.Healthy && moodState == PetMoods.Happy) { ArrivedShowFireButton(); //if can't breathe fire show message bool canBreatheFire = DataManager.Instance.GameData.PetInfo.CanBreathFire(); if (!canBreatheFire) { IndicateNoFire(); } } else { ShowUnhealthyNoFireSpeech(); } // regardless, stop listening for the callback now that we've received it ListenForMovementFinished(false); }
/// <summary> /// Changes the stats. /// Locations are on screen space /// </summary> /// <param name="xpDelta">Delta points.</param> /// <param name="xpPos">Points location.</param> /// <param name="coinsDelta">Delta stars.</param> /// <param name="coinsPos">Stars location.</param> /// <param name="healthDelta">Delta health.</param> /// <param name="healthPos">Health location.</param> /// <param name="hungerDelta">Delta mood.</param> /// <param name="hungerPos">Mood location.</param> /// <param name="bFloaty">If set to <c>true</c> spawn floaty on the pet. (this will not play sound)</param> /// <param name="isInternal">If set to <c>true</c> skip all animations + rewarding</param> public void ChangeStats(int xpDelta = 0, Vector3 xpPos = default(Vector3), int coinsDelta = 0, Vector3 coinsPos = default(Vector3), int healthDelta = 0, Vector3 healthPos = default(Vector3), int hungerDelta = 0, Vector3 hungerPos = default(Vector3), bool isFloaty = false, bool is3DObject = false, float animDelay = 0f, bool isInternal = false) { // Make necessary changes in the DataManager and HUDAnimator if (xpDelta != 0) { if (xpDelta > 0) { DataManager.Instance.GameData.Stats.AddCurrentLevelXp(xpDelta); } else if (xpDelta < 0) // Invalid case { Debug.LogError("Subtracting experience points"); } } if (coinsDelta != 0) { DataManager.Instance.GameData.Stats.UpdateCoins(coinsDelta); } // NOTE: so that the pet animations play properly, make sure to change and check mood BEFORE health if (hungerDelta != 0) { PetMoods oldMood = DataManager.Instance.GameData.Stats.GetMoodState(); DataManager.Instance.GameData.Stats.UpdateHunger(hungerDelta); PetMoods newMood = DataManager.Instance.GameData.Stats.GetMoodState(); if (isPetAnimationManagerPresent) { CheckForMoodTransition(oldMood, newMood); } } if (healthDelta != 0) { PetHealthStates oldHealth = DataManager.Instance.GameData.Stats.GetHealthState(); DataManager.Instance.GameData.Stats.UpdateHealth(healthDelta); PetHealthStates newHealth = DataManager.Instance.GameData.Stats.GetHealthState(); if (isPetAnimationManagerPresent) { CheckForHealthTransition(oldHealth, newHealth); CheckForZeroHealth(); } } // If internal checked, skip all animations and reward checking if (isInternal == false) { if (isFloaty && !bBeingDestroyed && PetFloatyUIManager.Instance) { PetFloatyUIManager.Instance.CreateStatsFloaty(xpDelta, healthDelta, hungerDelta, coinsDelta); } //when stats are modified make sure PetAnimationManager knows about it if (isPetAnimationManagerPresent) { PetAnimationManager.Instance.PetStatsModified(DataManager.Instance.GameData.Stats.Health, DataManager.Instance.GameData.Stats.Mood); } // Adjust for custom positions using screen position for 3D objects if (is3DObject) { if (xpPos != default(Vector3)) { // WorldToScreen returns screen coordinates based on 0,0 being bottom left, so we need to transform those into respective NGUI Anchors xpPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, xpPos); Debug.LogWarning("COMMENTED OUT THINGS HERE, fix"); //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Points_Anchor")); //xpPos = CameraManager.Instance.TransformAnchorPosition(xpPos, InterfaceAnchors.BottomLeft, endAnchor); } if (coinsPos != default(Vector3)) { coinsPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, coinsPos); Debug.LogWarning("COMMENTED OUT THINGS HERE, fix"); //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Stars_Anchor")); //coinsPos = CameraManager.Instance.TransformAnchorPosition(coinsPos, InterfaceAnchors.BottomLeft, endAnchor); } if (healthPos != default(Vector3)) { healthPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, healthPos); Debug.LogWarning("COMMENTED OUT THINGS HERE, fix"); //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Health_Anchor")); //healthPos = CameraManager.Instance.TransformAnchorPosition(healthPos, InterfaceAnchors.BottomLeft, endAnchor); } if (hungerPos != default(Vector3)) { hungerPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, hungerPos); Debug.LogWarning("COMMENTED OUT THINGS HERE, fix"); //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Mood_Anchor")); //hungerPos = CameraManager.Instance.TransformAnchorPosition(hungerPos, InterfaceAnchors.BottomLeft, endAnchor); } } // Adjust for custom position using screen position for NGUI objects else { // Not needed yet } // Tell HUDAnimator to animate and change List <StatPair> listStats = new List <StatPair>(); listStats.Add(new StatPair(StatType.Xp, xpDelta, xpPos, xpDelta > 0 ? "XpSingleTick" : null)); listStats.Add(new StatPair(StatType.Coin, coinsDelta, coinsPos, coinsDelta > 0 ? "CoinSingleTick" : null)); listStats.Add(new StatPair(StatType.Health, healthDelta, healthPos, healthDelta > 0 ? "HealthSingleTick" : null)); listStats.Add(new StatPair(StatType.Hunger, hungerDelta, hungerPos, hungerDelta > 0 ? "HungerSingleTick" : null)); if (hudAnimator != null && !bBeingDestroyed) { // Push this into the reward queue RewardQueueData.GenericDelegate function1 = delegate { StartCoroutine(hudAnimator.StartCurveStats(listStats, isFloaty, animDelay)); }; RewardManager.Instance.AddToRewardQueue(function1); } //Check if there are enough coins/stars to unlock badge, we want to do this last after reward BadgeManager.Instance.CheckSeriesUnlockProgress(BadgeType.Coin, DataManager.Instance.GameData.Stats.TotalStars, true); } }
void Update() { meshCollider.enabled = canMove ? true : false; if (moving && petSprite != null) { //move the pet location if allowed if (ClickManager.Instance.CanRespondToTap(gameObject, ClickLockExceptions.Moving)) { PetMoods mood = DataManager.Instance.GameData.Stats.GetMoodState(); PetHealthStates health = DataManager.Instance.GameData.Stats.GetHealthState(); float movementSpeed = normalSpeed; //show pet movement down if pet is sick if (health == PetHealthStates.Sick || mood != PetMoods.Happy) { movementSpeed = sickSpeed; } else if (health == PetHealthStates.VerySick) { movementSpeed = verySickSpeed; } petSprite.transform.position = Vector3.MoveTowards(petSprite.transform.position, destinationPoint, movementSpeed * Time.deltaTime); } else if (moving && gateDestroyed) { petSprite.transform.position = Vector3.MoveTowards(petSprite.transform.position, destinationPoint, normalSpeed * Time.deltaTime); } else if (movingToAccessory) { PetMoods mood = DataManager.Instance.GameData.Stats.GetMoodState(); PetHealthStates health = DataManager.Instance.GameData.Stats.GetHealthState(); float movementSpeed = normalSpeed; //show pet movement down if pet is sick if (health == PetHealthStates.Sick || mood != PetMoods.Happy) { movementSpeed = sickSpeed; } else if (health == PetHealthStates.VerySick) { movementSpeed = verySickSpeed; } petSprite.transform.position = Vector3.MoveTowards(petSprite.transform.position, destinationPoint, movementSpeed * Time.deltaTime); } else { StopMoving(); } //when the sprite reaches destination. stop transform and animation if (petSprite.transform.position == destinationPoint) { // send out an event because the pet has reached their destination if (OnReachedDest != null) { OnReachedDest(this, EventArgs.Empty); } if (movingToAccessory) { movingToAccessory = false; } StopMoving(); } } if (!isWandering && ClickManager.Instance.CanRespondToTap()) { isWandering = true; StartCoroutine("WanderAround"); } }