Beispiel #1
0
    [SerializeField] private AudioPlayable _damageSound; // global for now but can be per character/ennemy

    protected override void OnGamePresentationUpdate()
    {
        if (_audioSource == null)
        {
            return;
        }

        // Item sounds
        foreach (var gameActionEvent in PresentationEvents.GameActionEvents.SinceLastPresUpdate)
        {
            SimWorld.TryGetComponent(gameActionEvent.GameActionContext.Action, out SimAssetId entitySimAssetID);

            GameObject entityPrefab = PresentationHelpers.FindSimAssetPrefab(entitySimAssetID);
            if (entityPrefab != null)
            {
                var sfx = entityPrefab.GetComponent <GameActionAuth>()?.SfxOnUse;
                if (sfx != null)
                {
                    sfx.PlayOn(_audioSource);
                }
            }
        }

        // Damage sounds
        foreach (var hpDeltaEvent in PresentationEvents.HealthDeltaEvents.SinceLastPresUpdate)
        {
            if (_damageSound != null)
            {
                _damageSound.PlayOn(_audioSource);
            }
        }
    }
Beispiel #2
0
    private void OnLevelSet(Level level)
    {
        if (IsLevelStarted)
        {
            Log.Error("Cannot start another level (not yet implemented)");
            return;
        }
        IsLevelStarted = true;
        PresentationHelpers.PresentationWorld.GetExistingSystem <TickSimulationSystem>().UnpauseSimulation(LEVEL_NOT_STARTED);

        if (Game.PlayingAsMaster)
        {
            // load simulation scenes
            PresentationHelpers.SubmitInput(new SimCommandLoadScene()
            {
                SceneName = SimManagersScene.SceneName
            });
            foreach (SceneInfo scene in level.SimulationScenes)
            {
                PresentationHelpers.SubmitInput(new SimCommandLoadScene()
                {
                    SceneName = scene.SceneName
                });
            }
        }

        // instantiate presentation
        Game.InstantiateGameplayPresentationSystems();

        // load presentation scenes
        foreach (SceneInfo scene in level.PresentationScenes)
        {
            SceneService.LoadAsync(scene.SceneName);
        }
    }
    void IWorldUIPointerClickHandler.OnPointerClick()
    {
        if (!Cache.LocalPawnAlive)
        {
            return;
        }

        fix2 entityPosition = SimWorld.GetComponent <FixTranslation>(SimEntity);
        fix2 pawnPosition   = Cache.LocalPawnPosition;

        if (fixMath.distancemanhattan(entityPosition, pawnPosition) > SimulationGameConstants.InteractibleMaxDistanceManhattan)
        {
            PresentationHelpers.RequestFloatingText((Vector2)entityPosition, "Trop loin", Color.white);
            return;
        }

        switch (_clickAction)
        {
        case ClickAction.OpenChest:
            if (InteractableInventoryDisplaySystem.Instance != null)
            {
                InteractableInventoryDisplaySystem.Instance.SetupDisplayForInventory(SimEntity);
            }
            break;

        case ClickAction.TriggerSignal:
            PresentationHelpers.RequestFloatingText((Vector2)entityPosition, "Click", Color.white);
            SimWorld.SubmitInput(new SimPlayerInputClickSignalEmitter(SimEntity));
            break;
        }
    }
Beispiel #4
0
    private static void CheatSetPawnDoodle(string imagePath)
    {
        if (!GamePresentationCache.Instance.Ready)
        {
            return;
        }

        var    simWorld  = GamePresentationCache.Instance.SimWorld;
        Entity localPawn = GamePresentationCache.Instance.LocalPawn;

        // find current pawn's doodle asset
        Guid currentDoodleGuid = Guid.Empty;

        if (simWorld.TryGetComponent(localPawn, out DoodleId doodleId))
        {
            currentDoodleGuid = doodleId.Guid;
        }

        PlayerDoodleAsset playerDoodleAsset = PlayerAssetManager.Instance.GetAsset <PlayerDoodleAsset>(currentDoodleGuid);

        // If pawn's doodle doesn't exist, create a new one + submit a sim input to assign it
        if (playerDoodleAsset == null)
        {
            playerDoodleAsset = PlayerAssetManager.Instance.CreateAsset <PlayerDoodleAsset>();

            PresentationHelpers.SubmitInput(new SimPlayerInputSetPawnDoodle(playerDoodleAsset.Guid, true));
        }

        // Load image into doodle texture
        playerDoodleAsset.Load(File.ReadAllBytes(imagePath));

        // publish changes
        PlayerAssetManager.Instance.PublishAssetChanges(playerDoodleAsset.Guid);
    }
Beispiel #5
0
    void UpdateCachedPlayers()
    {
        _cachedPlayers.Clear();

        PresentationHelpers.GetSimulationWorld().Entities
        .WithAll <PlayerTag, Name, PersistentId>()
        .ForEach((Entity playerEntity) =>
        {
            _cachedPlayers.Add(playerEntity);
        });
    }
Beispiel #6
0
 public static void MainMenu(ApplicationController gameManager)
 {
     do
     {
         //THINGS TO DISPLAY IN THE MAIN MENU:
         //Title
         //MainMenuOptions
         //CheckUserInput
     } while (gameManager.GameState == GameState.MainMenu); //end dowhile loop
     PresentationHelpers.LoopRedirect(gameManager);
 }//end Main Menu
Beispiel #7
0
    protected override void OnGamePresentationUpdate()
    {
        foreach (var gameActionEvent in PresentationEvents.GameActionEvents.SinceLastPresUpdate)
        {
            SimWorld.TryGetComponent(gameActionEvent.GameActionContext.LastPhysicalInstigator, out FixTranslation lastPhysicalInstigatorTranslation);

            // ITEM USED VFX
            // only do the vfx if not an auto attack
            if (!SimWorld.HasComponent <AutoAttackAction>(gameActionEvent.GameActionContext.ActionInstigatorActor) ||
                (SimWorld.TryGetComponent(gameActionEvent.GameActionContext.ActionInstigatorActor, out AutoAttackAction autoAttack) && autoAttack.Value != gameActionEvent.GameActionContext.Action))
            {
                SimWorld.TryGetComponent(gameActionEvent.GameActionContext.ActionInstigatorActor, out SimAssetId instigatorAssetId);
                GameObject itemPrefab = PresentationHelpers.FindSimAssetPrefab(instigatorAssetId);
                if (itemPrefab != null &&
                    itemPrefab.TryGetComponent(out ItemAuth itemAuth))
                {
                    if (itemAuth.Icon != null && ItemUsedVFX != null)
                    {
                        ItemUsedVFX.TriggerVFX(new KeyValuePair <string, object>("Location", lastPhysicalInstigatorTranslation.Value.ToUnityVec())
                                               , new KeyValuePair <string, object>("Sprite", itemAuth.Icon));
                    }
                }
            }

            // GAME ACTION USED VFX
            SimWorld.TryGetComponent(gameActionEvent.GameActionContext.Action, out SimAssetId gameActionAssetId);
            GameObject gameActionPrefab = PresentationHelpers.FindSimAssetPrefab(gameActionAssetId);
            if (gameActionPrefab != null && gameActionPrefab.TryGetComponent(out GameActionAuth gameActionAuth))
            {
                VFXDefinition instigatorVFX = gameActionAuth.InstigatorVFX;

                if (instigatorVFX != null)
                {
                    instigatorVFX.TriggerVFX(new KeyValuePair <string, object>("Location", lastPhysicalInstigatorTranslation.Value.ToUnityVec()));
                }

                VFXDefinition targetsVFX = gameActionAuth.TargetsVFX;
                if (targetsVFX != null && gameActionEvent.GameActionContext.Targets.IsCreated)
                {
                    for (int i = 0; i < gameActionEvent.GameActionContext.Targets.Length; i++)
                    {
                        Entity target = gameActionEvent.GameActionContext.Targets[i];
                        if (SimWorld.TryGetComponent(target, out FixTranslation targetLocation))
                        {
                            targetsVFX.TriggerVFX(new KeyValuePair <string, object>("Location", targetLocation.Value.ToUnityVec()));
                        }
                    }
                }
            }
        }
    }
        public void Execute(int index, TransformAccess transform)
        {
            Entity simEntity = BindedSimEntities[index];

            if (SimTranslations.HasComponent(simEntity))
            {
                transform.localPosition = SimTranslations[simEntity].Value.ToUnityVec();
            }

            if (SimRotations.HasComponent(simEntity))
            {
                transform.localRotation = PresentationHelpers.SimRotationToUnityRotation(SimRotations[simEntity]);
            }
        }
    public static void CheatInvicible()
    {
        var localPlayerInfo = PlayerHelpers.GetLocalPlayerInfo();

        if (localPlayerInfo == null)
        {
            Log.Warning("No local player found");
            return;
        }

        PresentationHelpers.SubmitInput(new SimInputCheatToggleInvincible()
        {
        });
    }
    public static void CheatGiveAllItems()
    {
        var localPlayerInfo = PlayerHelpers.GetLocalPlayerInfo();

        if (localPlayerInfo == null)
        {
            Log.Warning("No local player found");
            return;
        }

        PresentationHelpers.SubmitInput(new SimInputCheatAddAllItems()
        {
            PlayerId = localPlayerInfo.SimPlayerId,
        });
    }
    public static void CheatHealSelf(int amount)
    {
        var localPlayerInfo = PlayerHelpers.GetLocalPlayerInfo();

        if (localPlayerInfo == null)
        {
            Log.Warning("No local player found");
            return;
        }

        PresentationHelpers.SubmitInput(new SimInputCheatDamageSelf()
        {
            PlayerId = localPlayerInfo.SimPlayerId,
            Damage   = -amount
        });
    }
    public static void CheatSoloPlay(int playerIndex)
    {
        var localPlayerInfo = PlayerHelpers.GetLocalPlayerInfo();

        if (localPlayerInfo == null)
        {
            Log.Warning("No local player found");
            return;
        }

        PresentationHelpers.SubmitInput(new SimInputCheatSoloPlay()
        {
            PlayerId  = localPlayerInfo.SimPlayerId,
            PawnIndex = playerIndex
        });
    }
    public static void CheatImpulseSelf(float x, float y)
    {
        var localPlayerInfo = PlayerHelpers.GetLocalPlayerInfo();

        if (localPlayerInfo == null)
        {
            Log.Warning("No local player found");
            return;
        }

        PresentationHelpers.SubmitInput(new SimInputCheatImpulseSelf()
        {
            PlayerId     = localPlayerInfo.SimPlayerId,
            ImpulseValue = new fix2((fix)x, (fix)y)
        });
    }
    public static void CheatTeleportAtMouse()
    {
        var localPlayerInfo = PlayerHelpers.GetLocalPlayerInfo();

        if (localPlayerInfo == null)
        {
            Log.Warning("No local player found");
            return;
        }

        Vector3 destination = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        PresentationHelpers.SubmitInput(new SimInputCheatTeleport()
        {
            PlayerId    = localPlayerInfo.SimPlayerId,
            Destination = new fix2((fix)destination.x, (fix)destination.y)
        });
    }
Beispiel #15
0
    public override void OnGUI()
    {
        UpdateCachedPlayers();
        var simPlayers       = _cachedPlayers;
        var simWorldAccessor = PresentationHelpers.GetSimulationWorld();

        GUILayout.BeginHorizontal();

        GUILayout.BeginVertical();
        GUILayout.Label("Player Name", DebugPanelStyles.boldText);
        for (int i = 0; i < simPlayers.Count; i++)
        {
            ApplyPlayerTextColor(simPlayers[i]);
            GUILayout.Label(simWorldAccessor.GetComponent <Name>(simPlayers[i]).Value.ToString());
        }
        ResetTextColor();
        GUILayout.EndVertical();


        GUILayout.BeginVertical();
        GUILayout.Label("Sim Player Id", DebugPanelStyles.boldText);
        for (int i = 0; i < simPlayers.Count; i++)
        {
            ApplyPlayerTextColor(simPlayers[i]);
            GUILayout.Label(simWorldAccessor.GetComponent <PersistentId>(simPlayers[i]).Value.ToString());
        }
        ResetTextColor();
        GUILayout.EndVertical();


        GUILayout.BeginVertical();
        GUILayout.Label("isBeingPlayed", DebugPanelStyles.boldText);
        for (int i = 0; i < simPlayers.Count; i++)
        {
            ApplyPlayerTextColor(simPlayers[i]);
            GUILayout.Label(PlayerHelpers.GetPlayerFromSimPlayer(simPlayers[i], PresentationHelpers.GetSimulationWorld()) == null ? "false" : "true");
        }
        ResetTextColor();
        GUILayout.EndVertical();

        GUILayout.EndHorizontal();
    }
Beispiel #16
0
    private void UpdateTooltipDescription(Entity item, ItemAuth itemAuth)
    {
        _descriptionData.Clear();
        if (item != Entity.Null)
        {
            // General Description
            _descriptionData.Add(new DescriptionData(itemAuth.EffectDescription, Color.white, true));

            // AP Cost
            _descriptionData.Add(new DescriptionData("Coût AP : " + itemAuth.ApCost, Color.white, true));

            // Item Specific Settings
            if (itemAuth.CooldownType == ItemAuth.CooldownMode.Seconds)
            {
                _descriptionData.Add(new DescriptionData($"Cooldown (time) : {itemAuth.CooldownDuration}", Color.white, true));
            }
        }

        PresentationHelpers.UpdateGameObjectList(_descriptionElements, _descriptionData, _itemDescriptionPrefab, _itemDescriptionContainer,
                                                 onUpdate: (element, data) => element.UpdateDescription(data.Desc, data.Color, data.AddBG));
    }
Beispiel #17
0
    public void ActivateContextMenuDisplay(System.Action <int?> actionSelected, params string[] actionsName)
    {
        _callback = actionSelected;

        // set position
        _contextMenuDisplay.position = Input.mousePosition + new Vector3(_displacementX, _displacementY, 0);

        PresentationHelpers.ResizeGameObjectList(_actionElements, actionsName.Length, _actionPrefab, _actionContainer);

        for (int i = 0; i < actionsName.Length; i++)
        {
            int choiceIndex = i;
            _actionElements[i].Init(actionsName[i], () =>
            {
                Callback(choiceIndex);
                SetContextMenuActive(false);
            });
        }

        SetContextMenuActive(true);
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (PresentationHelpers.GetSimulationWorld() != null)
        {
            Entity simEntity = ((BindedSimEntityManaged)target).SimEntity;
            if (PresentationHelpers.GetSimulationWorld().Exists(simEntity))
            {
                string entityName = PresentationHelpers.GetSimulationWorld().GetName(simEntity);
                EditorGUILayout.LabelField($"Binded to: {entityName} - {simEntity}", EditorStyles.boldLabel);
            }
            else
            {
                EditorGUILayout.LabelField($"Binded to destroyed entity: {simEntity}", EditorStyles.boldLabel);
            }


            //TODO: Test: destroying the sim entity destroys the gameobject
            //      Implenent: transform is copied to gameobject
        }
    }
    public override Tween GetDOTWEENAnimationSequence(Entity entity, Vector3 spriteStartPos, Transform spriteTransform)
    {
        Sequence sq = DOTween.Sequence();

        GameAction.ResultDataElement resultData = GetGameActionResultData();

        Vector2 startPos = spriteStartPos;
        Vector2 endPos   = startPos;

        if (resultData.AttackVector.ToUnityVec() != Vector2.zero)
        {
            endPos += resultData.AttackVector.ToUnityVec();
        }
        else if (resultData.Position.ToUnityVec() != Vector2.zero)
        {
            endPos = resultData.Position.ToUnityVec() - (Vector2)spriteTransform.position;
        }
        else if ((resultData.Entity != Entity.Null) && PresentationHelpers.GetSimulationWorld().TryGetComponent(resultData.Entity, out FixTranslation translation))
        {
            endPos = translation.Value.ToUnityVec() - (Vector2)spriteTransform.position;
        }

        if (VFXOnTarget != null)
        {
            _data.Add(new KeyValuePair <string, object>("Transform", spriteTransform));
            _data.Add(new KeyValuePair <string, object>("AttackVector", resultData.AttackVector));
            _data.Add(new KeyValuePair <string, object>("InstigatorStartPosition", spriteTransform.position));
            sq.Append(spriteTransform.DOLocalMove(endPos, Duration / 2).OnComplete(() => { VFXOnTarget.TriggerVFX(_data); }));
        }
        else
        {
            sq.Append(spriteTransform.DOLocalMove(endPos, Duration / 2));
        }

        sq.Append(spriteTransform.DOLocalMove(startPos, Duration / 2));

        return(sq);
    }
    protected override void OnGamePresentationUpdate()
    {
        if (SimWorld.TryGetBufferReadOnly(SimEntity, out DynamicBuffer <InventoryItemReference> items))
        {
            if ((items.Length == 1))
            {
                if (!_appearanceChanged)
                {
                    _appearanceChanged = true;

                    _spriteContainer.localScale = new Vector3(_scaleChange, _scaleChange, 1);

                    InventoryItemReference item = items[0];
                    if (SimWorld.TryGetComponent(item.ItemEntity, out SimAssetId itemIDComponent))
                    {
                        ItemAuth itemAuth = PresentationHelpers.FindItemAuth(itemIDComponent);
                        _chestRenderer.sprite = itemAuth.Icon;
                    }

                    _bgRenderer.gameObject.SetActive(true);

                    _currentAnimation = _spriteContainer.DOMoveY(transform.position.y + _yDisplacement, _animationDuration).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.InOutSine);
                }
            }
            else
            {
                _appearanceChanged = false;

                _bgRenderer.gameObject.SetActive(false);

                _spriteContainer.localScale = new Vector3(1, 1, 1);

                _currentAnimation?.Kill();
            }
        }
    }
Beispiel #21
0
    public override void OnEnter()
    {
        _surveyStateMachine.Blackboard = _surveySMBlackboard;
        _surveySMBlackboard.Cache      = Cache;
        _surveySMBlackboard.ResultParameters.Clear();
        _surveySMBlackboard.IsDebug = false;

        CursorOverlayService.Instance.ResetCursorToDefault();

        if (InputParameter != null && InputParameter.ActionInstigator != Entity.Null && InputParameter.ActionPrefab != Entity.Null)
        {
            if (SimWorld.TryGetComponent(InputParameter.ActionPrefab, out SimAssetId objectSimAssetID))
            {
                _surveySMBlackboard.ActionAuth = PresentationHelpers.FindActionAuth(objectSimAssetID);
            }

            if (_surveySMBlackboard.ActionAuth == null)
            {
                StateMachine.TransitionTo(UIStateType.Gameplay);
                return;
            }

            // Init process of parameter selection
            GameActionId actionId         = SimWorld.GetComponent <GameActionId>(InputParameter.ActionPrefab);
            GameAction   objectGameAction = GameActionBank.GetAction(actionId);

            _surveySMBlackboard.UseContext             = CommonReads.GetActionContext(SimWorld, InputParameter.ActionInstigator, InputParameter.ActionPrefab);
            _surveySMBlackboard.ParametersDescriptions = objectGameAction.GetExecutionContract(SimWorld, InputParameter.ActionPrefab).ParameterTypes;
        }
        else
        {
            _surveySMBlackboard.IsDebug = true;
        }

        _surveyStateMachine.TransitionTo(new SurveyState());
    }
Beispiel #22
0
    private void OnDrawGizmos()
    {
        ExternalSimWorldAccessor simWorld = PresentationHelpers.GetSimulationWorld();

        if (simWorld == null || !simWorld.HasSingleton <GridInfo>())
        {
            return;
        }

        GridInfo gridRect = simWorld.GetSingleton <GridInfo>();

        Rect visualRect = new Rect(new Vector2(gridRect.TileMin.x, gridRect.TileMin.y), new Vector2(gridRect.Width, gridRect.Height));

        Vector2 bottomLeft  = visualRect.min;
        Vector2 bottomRight = new Vector2(visualRect.max.x, visualRect.min.y);
        Vector2 TopLeft     = new Vector2(visualRect.min.x, visualRect.max.y);
        Vector2 TopRight    = visualRect.max;

        Gizmos.color = Color;
        Gizmos.DrawLine(bottomLeft, bottomRight);
        Gizmos.DrawLine(bottomLeft, TopLeft);
        Gizmos.DrawLine(TopLeft, TopRight);
        Gizmos.DrawLine(TopRight, bottomRight);
    }
Beispiel #23
0
        }//end InGame()

        public static void InGameExploration(ApplicationController gameManager)
        {
            do
            {
                //check to break loop? The CheckInGameLoop method checks the gameManager's
                //GameState prop. If it == InGame, then it returns true. The if statement
                //is checking if the GameState is NOT InGame, and if it's not, it'll break
                //out of the exploration loop. This could definitely use some refactoring.
                if (!CheckInGameLoop(gameManager))
                {
                    break;
                }

                //Things that need to be done in the loop:
                //clear the window.
                Console.Clear();

                //Display "header" that tells you that you're not in combat.

                //display the map
                //PresentationHelpers.DisplayMap(gameManager.CurrentMap);

                //display list of actors on map

                //display appropriate options for the player while exploring.
                //This was my attempt at an Object Oriented approach. I'm not happy with it,
                //but it lead me to an idea. I was thinking we'd have a list of PlayerOptions
                //in the database/xml files based on a class similar to your MenuItems class,
                //with a name, hotkey, and maybe more (like what action it's supposed to take,
                //or conditions to be able to use the ability or whatever).
                //For example: "Interact", "I", Interact(Object target) or something.
                DisplayPlayerOptions_Exploraton();
                //I think that we don't really need a
                //gameManager at all if we just have the presentation layer refer to the data
                //layer's xml to find out what the current map/gameState/whatever is, right?


                //***Big Problem***
                //This is where all the loops can't be object oriented. They each use a switch
                //switch statement in order to check for user input. Then they have to use that
                //input to redirect the player to the intended state. If we go with my idea for
                //DisplayPlayerOptions, then we'd just need a for each loop, right? Send a list
                //of all the player's options based on the gameState and conditions, then
                //iterate through to put them on screen. Then save the next user input, and check
                //it against the name/hotkey of each item in the list of available options, then,
                //if there's a match, call the action associated with that item.
                bool choiceMade = false;
                do
                {
                    string userInput = System.Console.ReadLine().ToUpper();
                    switch (userInput)
                    {
                    case "X":
                        System.Console.WriteLine("Thanks for playing!");
                        choiceMade = true;
                        break;

                    default:
                        PresentationHelpers.InvalidSelectionMessage();
                        break;
                    }
                } while (!choiceMade);
            } while (true);//end dowhile
        }//end InGameExploration
    private bool HandleGameActionAnimation()
    {
        foreach (GameActionUsedEventData gameActionEvent in PresentationEvents.GameActionEvents.SinceLastPresUpdate)
        {
            if (gameActionEvent.GameActionContext.LastPhysicalInstigator == SimEntity && gameActionEvent.GameActionContext.Action != Entity.Null && !_hasTriggeredAnAnimation)
            {
                TriggerAnimationInteruptionOnStateChange();

                _hasTriggeredAnAnimation = true;
                _lastTransitionTime      = SimWorld.Time.ElapsedTime;

                // GAME ACTION AUTH & ANIMATION TRIGGER
                SimWorld.TryGetComponent(gameActionEvent.GameActionContext.Action, out SimAssetId instigatorAssetId);
                GameObject instigatorPrefab = PresentationHelpers.FindSimAssetPrefab(instigatorAssetId);
                if (instigatorPrefab.TryGetComponent(out GameActionAuth gameActionAuth))
                {
                    _currentAnimation = gameActionAuth.Animation;

                    // add additionnal animation to play in queue (skip the first we'll play)
                    if (gameActionAuth.Animation != null)
                    {
                        for (int i = 1; i < gameActionEvent.GameActionResult.Count; i++)
                        {
                            // ANIMATION DATA
                            List <KeyValuePair <string, object> > currentAnimationData = new List <KeyValuePair <string, object> >();
                            currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContext", gameActionEvent.GameActionContext));

                            switch (i)
                            {
                            case 1:
                                currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_1));
                                break;

                            case 2:
                                currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_2));
                                break;

                            case 3:
                                currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_3));
                                break;

                            default:
                                break;
                            }

                            _queuedAnimations.Add(new QueuedAnimation()
                            {
                                Data = currentAnimationData, Definition = _currentAnimation, HasPlayed = false
                            });
                        }

                        // ANIMATION DATA
                        List <KeyValuePair <string, object> > animationData = new List <KeyValuePair <string, object> >();
                        animationData.Add(new KeyValuePair <string, object>("GameActionContext", gameActionEvent.GameActionContext));
                        animationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_0));

                        _currentAnimation.TriggerAnimation(SimEntity, _spriteStartPos, _bone, animationData);
                    }
                }

                _previousState = AnimationType.GameAction;
            }
        }

        if (!_hasTriggeredAnAnimation)
        {
            // find queued animation to play
            QueuedAnimation animationToPlay = null;
            for (int i = 0; i < _queuedAnimations.Count; i++)
            {
                if (!_queuedAnimations[i].HasPlayed)
                {
                    animationToPlay = _queuedAnimations[i];
                    _queuedAnimations[i].HasPlayed = true;
                    break;
                }
            }

            if (animationToPlay != null)
            {
                TriggerAnimationInteruptionOnStateChange();

                _hasTriggeredAnAnimation = true;
                _lastTransitionTime      = SimWorld.Time.ElapsedTime;

                _currentAnimation = animationToPlay.Definition ?? FindAnimation(AnimationType.GameAction);
                _currentAnimation.TriggerAnimation(SimEntity, _spriteStartPos, _bone, animationToPlay.Data);

                _previousState = AnimationType.GameAction;
            }
            else
            {
                _queuedAnimations.Clear();
            }
        }

        return(_hasTriggeredAnAnimation);
    }
    private void UpdateInventorySlots()
    {
        if (SimWorld.TryGetBufferReadOnly(Cache.LocalPawn, out DynamicBuffer <InventoryItemReference> inventory))
        {
            List <DisplayedItemData> displayedInventory = ListPool <DisplayedItemData> .Take();

            // gather all items to display
            for (int i = 0; i < inventory.Length; i++)
            {
                Entity item = inventory[i].ItemEntity;

                if (SimWorld.TryGetComponent(item, out SimAssetId itemAssetId))
                {
                    ItemAuth itemGameActionAuth = PresentationHelpers.FindItemAuth(itemAssetId);
                    if (itemGameActionAuth != null && !itemGameActionAuth.HideInInventory)
                    {
                        displayedInventory.Add(new DisplayedItemData()
                        {
                            ItemAuth = itemGameActionAuth,
                            ItemRef  = inventory[i],
                            Index    = i
                        });
                    }
                }
            }

            // Ajust Slot amount accordiwdng to inventory max size
            InventoryCapacity inventoryCapacity = SimWorld.GetComponent <InventoryCapacity>(Cache.LocalPawn);

            _gridLayoutGroup.constraintCount = min(_maxCollumns, inventoryCapacity);

            PresentationHelpers.ResizeGameObjectList(_slotVisuals, max(min(_maxCollumns, inventoryCapacity), displayedInventory.Count), _inventorySlotPrefab, _slotsContainer);

            for (int i = 0; i < _slotVisuals.Count; i++)
            {
                if (i < displayedInventory.Count)
                {
                    Entity item   = displayedInventory[i].ItemRef.ItemEntity;
                    int    stacks = displayedInventory[i].ItemRef.Stacks;

                    if (stacks == 1 && !SimWorld.GetComponent <StackableFlag>(item))
                    {
                        stacks = -1; // used in display to hide stacks
                    }
                    _slotVisuals[i].UpdateCurrentInventorySlot(displayedInventory[i].ItemAuth,
                                                               displayedInventory[i].Index,
                                                               GetSlotShotcut(i),
                                                               OnIntentionToUsePrimaryActionOnItem,
                                                               OnIntentionToUseSecondaryActionOnItem,
                                                               stacks);

                    if (!CommonReads.CanUseItem(SimWorld, Cache.LocalPawn, item))
                    {
                        _slotVisuals[i].UpdateDisplayAsUnavailable(item);
                    }
                }
                else
                {
                    _slotVisuals[i].UpdateCurrentInventorySlot(null, i, GetSlotShotcut(i), null, null);
                }
            }

            ListPool <DisplayedItemData> .Release(displayedInventory);
        }
    }
 public static void CheatRemoveAllCooldowns()
 {
     PresentationHelpers.SubmitInput(new SimInputCheatRemoveAllCooldowns());
 }
Beispiel #27
0
    static void ApplyPlayerTextColor(Entity simPlayer)
    {
        PlayerInfo p = PlayerHelpers.GetPlayerFromSimPlayer(simPlayer, PresentationHelpers.GetSimulationWorld());

        GUI.color = p == null ? Color.red : Color.white;
    }