예제 #1
0
 public static void Trigger(Character affectedCharacter, GameObject instigator, float currentHealth, float damageCaused, float previousHealth)
 {
     e.AffectedCharacter = affectedCharacter;
     e.Instigator        = instigator;
     e.CurrentHealth     = currentHealth;
     e.DamageCaused      = damageCaused;
     e.PreviousHealth    = previousHealth;
     MMEventManager.TriggerEvent(e);
 }
예제 #2
0
 /// <summary>
 /// When that slot gets selected (via a mouse over or a touch), triggers an event for other classes to act on
 /// </summary>
 /// <param name="eventData">Event data.</param>
 public override void OnSelect(BaseEventData eventData)
 {
     base.OnSelect(eventData);
     if (ParentInventoryDisplay != null)
     {
         InventoryItem item = ParentInventoryDisplay.TargetInventory.Content[Index];
         MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Select, this, ParentInventoryDisplay.TargetInventoryName, item, 0, Index));
     }
 }
예제 #3
0
 public static void Trigger(FollowerEventTypes eventType, FollowerData origin, FollowerData cost, FollowerData option, FollowerData requirement, string reason)
 {
     e.EventType   = eventType;
     e.Origin      = origin;
     e.Cost        = cost;
     e.Option      = option;
     e.Requirement = requirement;
     e.Reason      = reason;
     MMEventManager.TriggerEvent(e);
 }
        private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            MMEventManager.TriggerEvent(new MMGameEvent(MMGameEvent.LOAD));

            GUIManager.Instance.CloseGUIMenuInstantly();

            onSceneLoadCompleted?.Invoke();

            m_IsLoading = false;
        }
예제 #5
0
 public static void Trigger(MMInventoryEventType eventType, InventorySlot slot, string targetInventoryName, InventoryItem eventItem, int quantity, int index)
 {
     e.InventoryEventType = eventType;
     e.Slot = slot;
     e.TargetInventoryName = targetInventoryName;
     e.EventItem           = eventItem;
     e.Quantity            = quantity;
     e.Index = index;
     MMEventManager.TriggerEvent(e);
 }
예제 #6
0
 /// <summary>
 /// If the pause button has been pressed, we change the pause state
 /// </summary>
 protected virtual void TriggerPause()
 {
     if (!AbilityPermitted &&
         (_condition.CurrentState == CharacterStates.CharacterConditions.Normal || _condition.CurrentState == CharacterStates.CharacterConditions.Paused))
     {
         return;
     }
     // we trigger a Pause event for the GameManager and other classes that could be listening to it too
     MMEventManager.TriggerEvent(new CorgiEngineEvent(CorgiEngineEventTypes.Pause));
 }
        /// <summary>
        /// Changes the current character to the next one in line
        /// </summary>
        public virtual void SwapCharacter()
        {
            if (!SwapDisabled)
            {
                if (_characterSwapList.Count == 0)
                {
                    return;
                }

                int newIndex = -1;

                for (int i = 0; i < _characterSwapList.Count; i++)
                {
                    if (_characterSwapList[i].Current())
                    {
                        newIndex = i + 1;
                    }
                    _characterSwapList[i].ResetCharacterSwap();
                }

                if (newIndex == -1)
                {
                    return;
                }

                if (newIndex >= _characterSwapList.Count)
                {
                    newIndex = 0;
                }
                _characterSwapList[newIndex].SwapToThisCharacter();

                //chỗ này fix vì phải đổi chỗ chứ ko phải gán
                LevelManager.Instance.Players[0] = _characterSwapList[newIndex].gameObject.MMGetComponentNoAlloc <Character>();
                MMEventManager.TriggerEvent(_swapEvent);

                if (imgSwap != null)
                {
                    imgSwap.sprite = imgSwaps[newIndex];
                    imgSwap.transform.DOBlendableLocalRotateBy(new Vector3(0f, 0f, -180f), 0.35f);
                }

                if (colorBtns != null && colorBtns.Length > 0)
                {
                    var count = imgBtns.Length;
                    for (int i = 0; i < count; i++)
                    {
                        var imgBtn = imgBtns[i];

                        imgBtn.color = colorBtns[newIndex];
                        imgBtn.DOFade(0.25f, 0.35f).From();
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Gets the player to the specified level
        /// </summary>
        /// <param name="levelName">Level name.</param>
        public virtual void GotoLevel(string levelName)
        {
            MMEventManager.TriggerEvent(new CorgiEngineEvent(CorgiEngineEventTypes.LevelEnd));
            MMEventManager.TriggerEvent(new MMGameEvent("Save"));

            if (GUIManager.Instance != null)
            {
                MMEventManager.TriggerEvent(new MMFadeInEvent(OutroFadeDuration));
            }
            StartCoroutine(GotoLevelCo(levelName));
        }
예제 #9
0
 /// <summary>
 /// Drops the item, removing it from the inventory and potentially spawning an item on the ground near the character
 /// </summary>
 /// <param name="item">Item.</param>
 /// <param name="index">Index.</param>
 /// <param name="slot">Slot.</param>
 public virtual void DropItem(InventoryItem item, int index, InventorySlot slot = null)
 {
     if (InventoryItem.IsNull(item))
     {
         MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, slot, this.name, null, 0, index));
         return;
     }
     item.SpawnPrefab();
     item.UnEquip();
     DestroyItem(index);
 }
예제 #10
0
        /// <summary>
        /// Initialization
        /// </summary>
        protected virtual void Awake()
        {
            GUIManager.Instance.SetHUDActive(false);
            MMEventManager.TriggerEvent(new MMFadeOutEvent(FadeInDuration));

            if (AutoSkipDelay > 1f)
            {
                FadeOutDuration = AutoSkipDelay;
                StartCoroutine(LoadFirstLevel());
            }
        }
예제 #11
0
        /// <summary>
        /// Opens the popup
        /// </summary>
        public virtual void Open()
        {
            if (CurrentlyOpen)
            {
                return;
            }

            MMEventManager.TriggerEvent(new MMFadeEvent(FaderOpenDuration, FaderOpacity));
            _animator.SetTrigger("Open");
            CurrentlyOpen = true;
        }
예제 #12
0
 override public void TriggerButtonAction()
 {
     if (GameObject.FindObjectOfType <PaintingButton>().stolenPainting == true)
     {
         MMEventManager.TriggerEvent(new CorgiEngineEvent(CorgiEngineEventTypes.Pause));                      //Pause Game
         GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterPause>().AbilityPermitted = false; //Turns off Ability to Pause/Unpause
         GUIManager gui = FindObjectOfType <GUIManager>();
         gui.PauseScreen.SetActive(false);
         gui.Win.SetActive(true);
     } //If Stolen Painting
 }
예제 #13
0
        /// <summary>
        /// Closes the popup
        /// </summary>
        public virtual void Close()
        {
            if (!CurrentlyOpen)
            {
                return;
            }

            MMEventManager.TriggerEvent(new MMFadeEvent(FaderCloseDuration, 0f));
            _animator.SetTrigger("Close");
            CurrentlyOpen = false;
        }
예제 #14
0
 /// <summary>
 /// Initializes GUI stuff
 /// </summary>
 protected virtual void LevelGUIStart()
 {
     // if we have a GUI manager
     if (GUIManager.Instance != null)
     {
         // set the level name in the GUI
         GUIManager.Instance.SetLevelName(SceneManager.GetActiveScene().name);
         // fade in
         MMEventManager.TriggerEvent(new MMFadeOutEvent(IntroFadeDuration));
     }
 }
예제 #15
0
 /// <summary>
 /// Tries to add an item of the specified type. Note that this is name based.
 /// </summary>
 /// <returns><c>true</c>, if item was added, <c>false</c> if it couldn't be added (item null, inventory full).</returns>
 /// <param name="itemToAdd">Item to add.</param>
 public virtual bool AddItem(InventoryItem itemToAdd, int quantity)
 {
     // if the item to add is null, we do nothing and exit
     if (itemToAdd == null)
     {
         Debug.LogWarning(this.name + " : The item you want to add to the inventory is null");
         return(false);
     }
     // if there's at least one item like this already in the inventory and it's stackable
     if (InventoryContains(itemToAdd.ItemID).Count > 0 && itemToAdd.MaximumStack > 1)
     {
         // we add the required number of items to the stack
         List <int> list      = InventoryContains(itemToAdd.ItemID);
         int        lastFound = list[list.Count - 1];
         // if there's still room in the last item of this kind in the inventory, we add to it
         if (Content[lastFound].Quantity < itemToAdd.MaximumStack)
         {
             // we increase the quantity of our item
             Content[lastFound].Quantity += quantity;
             // if this exceeds the maximum stack
             if (Content[lastFound].Quantity > Content[lastFound].MaximumStack)
             {
                 InventoryItem restToAdd         = itemToAdd;
                 int           restToAddQuantity = Content[lastFound].Quantity - Content[lastFound].MaximumStack;
                 // we clamp the quantity and add the rest as a new item
                 Content[lastFound].Quantity = Content[lastFound].MaximumStack;
                 AddItem(restToAdd, restToAddQuantity);
             }
             MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ContentChanged, null, this.name, null, 0, 0));
             return(true);
         }
     }
     // if we've reached the max size of our inventory, we don't add the item
     if (NumberOfFilledSlots >= Content.Length)
     {
         return(false);
     }
     while (quantity > 0)
     {
         if (quantity > itemToAdd.MaximumStack)
         {
             AddItem(itemToAdd, itemToAdd.MaximumStack);
             quantity -= itemToAdd.MaximumStack;
         }
         else
         {
             AddItemToArray(itemToAdd, quantity);
             quantity = 0;
         }
     }
     // if we're still here, we add the item in the first available slot
     MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ContentChanged, null, this.name, null, 0, 0));
     return(true);
 }
예제 #16
0
        /// <summary>
        /// Switches to the next character in the list
        /// </summary>
        protected virtual void SwitchCharacter()
        {
            if (_instantiatedCharacters.Length <= 1)
            {
                return;
            }

            // we determine the next index
            if (NextCharacterChoice == NextCharacterChoices.Random)
            {
                CurrentIndex = Random.Range(0, _instantiatedCharacters.Length);
            }
            else
            {
                CurrentIndex = CurrentIndex + 1;
                if (CurrentIndex >= _instantiatedCharacters.Length)
                {
                    CurrentIndex = 0;
                }
            }

            // we disable the old main character, and enable the new one
            LevelManager.Instance.Players[0].gameObject.SetActive(false);
            _instantiatedCharacters[CurrentIndex].gameObject.SetActive(true);

            // we move the new one at the old one's position
            _instantiatedCharacters[CurrentIndex].transform.position = LevelManager.Instance.Players[0].transform.position;
            _instantiatedCharacters[CurrentIndex].transform.rotation = LevelManager.Instance.Players[0].transform.rotation;

            // we keep the health if needed
            if (CommonHealth)
            {
                _instantiatedCharacters[CurrentIndex].gameObject.MMGetComponentNoAlloc <Health>().CurrentHealth = LevelManager.Instance.Players[0].gameObject.MMGetComponentNoAlloc <Health>().CurrentHealth;
            }

            // we put it in the same state the old one was in
            _instantiatedCharacters[CurrentIndex].MovementState.ChangeState(LevelManager.Instance.Players[0].MovementState.CurrentState);
            _instantiatedCharacters[CurrentIndex].ConditionState.ChangeState(LevelManager.Instance.Players[0].ConditionState.CurrentState);

            // we make it the current character
            LevelManager.Instance.Players[0] = _instantiatedCharacters[CurrentIndex];

            // we play our vfx
            if (_instantiatedVFX != null)
            {
                _instantiatedVFX.gameObject.SetActive(true);
                _instantiatedVFX.transform.position = _instantiatedCharacters[CurrentIndex].transform.position;
                _instantiatedVFX.Play();
            }

            // we trigger a switch event (for the camera to know, mostly)
            MMEventManager.TriggerEvent(_switchEvent);
        }
        protected override IEnumerator TeleportEnd()
        {
            if (FadeToBlack)
            {
                if (TeleportCamera)
                {
                    LevelManager.Instance.LevelCameraController.FollowsPlayer = false;
                }
                MMEventManager.TriggerEvent(new MMFadeInEvent(FadeDuration));
                yield return(new WaitForSeconds(FadeDuration));

                if (TeleportCamera)
                {
                    LevelManager.Instance.LevelCameraController.TeleportCameraToTarget();
                    LevelManager.Instance.LevelCameraController.FollowsPlayer = true;
                }
                MMEventManager.TriggerEvent(new MMFadeOutEvent(FadeDuration));
            }
            else
            {
                if (TeleportCamera)
                {
                    LevelManager.Instance.LevelCameraController.TeleportCameraToTarget();
                }
            }

            yield return(new WaitForSeconds(TimeWithoutControl));

            _character.UnFreeze();

            //mutes the 'touch the ground' sfx for a second
            lucyHorizontalMovement.JustTeleported();

            //Moving the parallax root position to the new room
            cameraLocation = Camera.main.transform.position;

            var ParallaxClass = FindObjectOfType <ProCamera2DParallax>();

            if (ParallaxClass != null)
            {
                ParallaxClass.RootPosition = cameraLocation;
            }

            //fade back after the player has hit the ground
            StartCoroutine(HitTheGroundThenFadeOut());

            //Start the boss room cinematic
            if (bossOpeningCinematic != null)
            {
                StartCoroutine(bossOpeningCinematic.BossCinematic());
            }
        }
예제 #18
0
        /// <summary>
        /// Causes the character to start jumping.
        /// </summary>
        public virtual void JumpStart()
        {
            if (!EvaluateJumpConditions())
            {
                return;
            }
            // we reset our walking speed
            if ((_movement.CurrentState == CharacterStates.MovementStates.Crawling) ||
                (_movement.CurrentState == CharacterStates.MovementStates.Crouching) ||
                (_movement.CurrentState == CharacterStates.MovementStates.LadderClimbing))
            {
                _characterHorizontalMovement.ResetHorizontalSpeed();
            }

            if (_movement.CurrentState == CharacterStates.MovementStates.LadderClimbing)
            {
                _characterLadder.GetOffTheLadder();
            }

            _controller.ResetColliderSize();

            // if we're still here, the jump will happen
            // we set our current state to Jumping
            _movement.ChangeState(CharacterStates.MovementStates.Jumping);

            // we trigger a character event
            MMEventManager.TriggerEvent(new MMCharacterEvent(_character, MMCharacterEventTypes.Jump));

            // we start our sounds
            PlayAbilityStartSfx();

            if (NumberOfJumpsLeft != NumberOfJumps)
            {
                _doubleJumping = true;
            }

            // we decrease the number of jumps left
            NumberOfJumpsLeft = NumberOfJumpsLeft - 1;

            // we reset our current condition and gravity
            _condition.ChangeState(CharacterStates.CharacterConditions.Normal);
            _controller.GravityActive(true);
            _controller.CollisionsOn();

            // we set our various jump flags and counters
            SetJumpFlags();


            // we make the character jump
            _controller.SetVerticalForce(Mathf.Sqrt(2f * JumpHeight * Mathf.Abs(_controller.Parameters.Gravity)));
            JumpHappenedThisFrame = true;
        }
예제 #19
0
        public async void Continue(int Lives = 1)
        {
            GUIManager.Instance.SetGameOverScreenContinue(false);
            GameManager.Instance.SetStatus(GameManager.GameStatus.GameInProgress);
            GameManager.Instance.SetLives(Lives);
            MMEventManager.TriggerEvent(new MMGameEvent("Continue"));
            GameManager.Instance.UnPause();
            GameManager.Instance.Continues -= 1;
            await Task.Delay(500);

            LevelManager.Instance.Continue();
            GameManager.Instance.AddCoins(-LevelManager.Instance.ContinueCost);
        }
예제 #20
0
 /// <summary>
 /// When that slot gets clicked, triggers an event for other classes to act on
 /// </summary>
 public virtual void SlotClicked()
 {
     if (ParentInventoryDisplay != null)
     {
         InventoryItem item = ParentInventoryDisplay.TargetInventory.Content[Index];
         MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Click, this, ParentInventoryDisplay.TargetInventoryName, item, 0, Index));
         // if we're currently moving an object
         if (ParentInventoryDisplay.CurrentlyBeingMovedItemIndex != -1)
         {
             Move();
         }
     }
 }
예제 #21
0
 /// <summary>
 /// Drops this item.
 /// </summary>
 public virtual void Drop()
 {
     if (!SlotEnabled)
     {
         return;
     }
     if (InventoryItem.IsNull(ParentInventoryDisplay.TargetInventory.Content[Index]))
     {
         MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, this, ParentInventoryDisplay.TargetInventoryName, null, 0, Index));
         return;
     }
     MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Drop, this, ParentInventoryDisplay.TargetInventoryName, ParentInventoryDisplay.TargetInventory.Content[Index], 0, Index));
 }
 protected virtual void EquipWeapon(string weaponID)
 {
     for (int i = 0; i < MainInventory.Content.Length; i++)
     {
         if (InventoryItem.IsNull(MainInventory.Content[i]))
         {
             continue;
         }
         if (MainInventory.Content[i].ItemID == weaponID)
         {
             MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.EquipRequest, null, MainInventory.name, MainInventory.Content[i], 0, i));
         }
     }
 }
예제 #23
0
 //called by the item picker to destroy the old beam when you pick up the upgraded version
 public virtual void DestroyWeaponOnPickup(string weaponID)
 {
     for (int i = 0; i < MainInventory.Content.Length; i++)
     {
         if (InventoryItem.IsNull(MainInventory.Content[i]))
         {
             continue;
         }
         if (MainInventory.Content[i].ItemID == weaponID)
         {
             MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Destroy, null, MainInventory.name, MainInventory.Content[i], 0, i));
         }
     }
 }
예제 #24
0
    public virtual void ChangeState(T newState)
    {
        if (newState.Equals(CurrentState))
        {
            return;
        }
        PreviousState = CurrentState;
        CurrentState  = newState;

        if (TriggerEvents)
        {
            MMEventManager.TriggerEvent(new MMStateChangeEvent <T>(this));
        }
    }
예제 #25
0
 /// <summary>
 /// Check if the item is pickable and if yes, proceeds with triggering the effects and disabling the object
 /// </summary>
 public virtual void PickItem()
 {
     if (CheckIfPickable())
     {
         Effects();
         MMEventManager.TriggerEvent(new PickableItemEvent(this));
         Pick();
         if (DisableObjectOnPick)
         {
             // we desactivate the gameobject
             gameObject.SetActive(false);
         }
     }
 }
예제 #26
0
        /// <summary>
        /// Tries to move the item at the first parameter slot to the second slot
        /// </summary>
        /// <returns><c>true</c>, if item was moved, <c>false</c> otherwise.</returns>
        /// <param name="startIndex">Start index.</param>
        /// <param name="endIndex">End index.</param>
        public virtual bool MoveItem(int startIndex, int endIndex)
        {
            bool swap = false;

            // if what we're trying to move is null, this means we're trying to move an empty slot
            if (InventoryItem.IsNull(Content[startIndex]))
            {
                Debug.LogWarning("InventoryEngine : you're trying to move an empty slot.");
                return(false);
            }
            // if both objects are swappable, we'll swap them
            if (Content[startIndex].CanSwapObject)
            {
                if (!InventoryItem.IsNull(Content[endIndex]))
                {
                    if (Content[endIndex].CanSwapObject)
                    {
                        swap = true;
                    }
                }
            }
            // if the target slot is empty
            if (InventoryItem.IsNull(Content[endIndex]))
            {
                // we create a copy of our item to the destination
                Content[endIndex] = Content[startIndex].Copy();
                // we remove the original
                RemoveItemFromArray(startIndex);
                // we mention that the content has changed and the inventory probably needs a redraw if there's a GUI attached to it
                MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ContentChanged, null, this.name, null, 0, 0));
                return(true);
            }
            else
            {
                // if we can swap objects, we'll try and do it, otherwise we return false as the slot we target is not null
                if (swap)
                {
                    // we swap our items
                    InventoryItem tempItem = Content[endIndex].Copy();
                    Content[endIndex]   = Content[startIndex].Copy();
                    Content[startIndex] = tempItem;
                    MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ContentChanged, null, this.name, null, 0, 0));
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #27
0
        /// <summary>
        /// Asks the Game Manager to change the time scale for a specified duration.
        /// </summary>
        /// <returns>The time.</returns>
        protected virtual IEnumerator ChangeTime()
        {
            // we send a new time scale event for the GameManager to catch (and other classes that may listen to it too)
            MMEventManager.TriggerEvent(new MMTimeScaleEvent(MMTimeScaleMethods.For, TimeSpeed, Duration, false, 0f, false));
            GUIManager.Instance.SetTimeSplash(true);
            // we multiply the duration by the timespeed to get the real duration in seconds
            yield return(_changeTimeWFS);

            GUIManager.Instance.SetTimeSplash(false);
            // we re enable the sprite and collider, and desactivate the object
            gameObject.GetComponent <SpriteRenderer> ().enabled   = true;
            gameObject.GetComponent <CircleCollider2D> ().enabled = true;
            gameObject.SetActive(false);
        }
예제 #28
0
 /// <summary>
 /// Unpauses the game
 /// </summary>
 public virtual void UnPause(PauseMethods pauseMethod = PauseMethods.PauseMenu)
 {
     MMEventManager.TriggerEvent(new MMTimeScaleEvent(MMTimeScaleMethods.Unfreeze, 1f, 0f, false, 0f, false));
     Instance.Paused = false;
     if ((GUIManager.Instance != null) && (pauseMethod == PauseMethods.PauseMenu))
     {
         GUIManager.Instance.SetPause(false);
         _pauseMenuOpen = false;
         SetActiveInventoryInputManager(true);
     }
     if (_inventoryOpen)
     {
         _inventoryOpen = false;
     }
 }
예제 #29
0
 public virtual void TriggerPause()
 {
     if (GamePaused)
     {
         MMEventManager.TriggerEvent(new MMTimeScaleEvent(MMTimeScaleMethods.Unfreeze, 1f, 0f, false, 0f, false));
         GUIManager.Instance.SetPause(false);  //TODO RESTORE
         GamePaused = false;
     }
     else
     {
         MMEventManager.TriggerEvent(new MMTimeScaleEvent(MMTimeScaleMethods.For, 0f, 0f, false, 0f, true));
         GUIManager.Instance.SetPause(true);  //TODO RESTORE
         GamePaused = true;
     }
 }
예제 #30
0
 /// <summary>
 /// Removes the specified item from the inventory.
 /// </summary>
 /// <returns><c>true</c>, if item was removed, <c>false</c> otherwise.</returns>
 /// <param name="itemToRemove">Item to remove.</param>
 public virtual bool RemoveItem(int i, int quantity)
 {
     Content[i].Quantity -= quantity;
     if (Content[i].Quantity <= 0)
     {
         bool suppressionSuccessful = RemoveItemFromArray(i);
         MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ContentChanged, null, this.name, null, 0, 0));
         return(suppressionSuccessful);
     }
     else
     {
         MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ContentChanged, null, this.name, null, 0, 0));
         return(true);
     }
 }