private void OnInteract(InteractEvent ev)
 {
     if (!_started && ev.interactable == interactable)
     {
         StartMission();
     }
 }
예제 #2
0
 private void Awake()
 {
     if (OnInteract == null)
     {
         OnInteract = new InteractEvent();
     }
 }
예제 #3
0
 public void OnInteract(InputAction.CallbackContext context)
 {
     if (context.phase == InputActionPhase.Performed)
     {
         InteractEvent.Invoke();
     }
 }
    private void OnInteract(InteractEvent ev)
    {
        if (ev.interactable == startInteract)
        {
            if (!_started)
            {
                _started              = true;
                endInteract.enabled   = true;
                startInteract.enabled = false;
                EventBus.Post(new GeneralHintEvent {
                    msg = "Go to the end post to finish the mission!"
                });
                GameContext.Instance.playerCtl.CarryMission(true);

                MissionManager.currentMission = endMissionHint;
            }
        }
        else if (ev.interactable == endInteract)
        {
            if (_started)
            {
                _started              = false;
                endInteract.enabled   = false;
                startInteract.enabled = true;

                GameContext.Instance.player.GetComponent <MonoPlayer>().money += moneyAdd.random;
                GameContext.Instance.playerCtl.CarryMission(false);
                _coinSound.Play();
                EventBus.Post(new GeneralHintEvent {
                    msg = "Mission finished!"
                });
            }
        }
    }
예제 #5
0
 public void OnInteract(InputAction.CallbackContext context)
 {
     if ((context.phase == InputActionPhase.Performed) &&
         (_gameStateManager.CurrentGameState == GameState.Gameplay))                // Interaction is only possible when in gameplay GameState
     {
         InteractEvent.Invoke();
     }
 }
예제 #6
0
 public override void Interact()
 {
     base.Interact();
     talk();
     if (InteractEvent != null)
     {
         InteractEvent.Invoke(this);
     }
 }
예제 #7
0
        // TODO: Replace anti-pattern of components storing functionality
        // Actions should be handled through the AI and Steering/Pathfinding

        // Handles calling interaction function
        void Handle(InteractEvent e)
        {
            Interactive interactive;

            if (e.Object.TryGetComponents(out interactive))
            {
                interactive.InteractAction(e.Actor);
            }
        }
예제 #8
0
 private void _OnInteract(InteractEvent evt)
 {
     if (evt.interactable.gameObject == gameObject)
     {
         if (_state == FoodPlantState.Normal)
         {
             _Transit(FoodPlantState.Harvested);
         }
     }
 }
예제 #9
0
    private void Grab(GameObject p_toGrab)
    {
        InteractEvent.Invoke();
        m_grabbedObject       = p_toGrab;
        m_grabbedObjectScript = m_grabbedObject.GetComponent <Grabbable>();

        m_grabbedObjectScript.Grab(gameObject);
        m_distanceBetweenObjectAndCameraDueToMeshSize = m_grabbedObjectScript.CalculateDistanceToCameraOffset();
        m_grabbedDuringThisFrame = true;
    }
 private void _OnInteract(InteractEvent ev)
 {
     if (ev.interactable == _interact)
     {
         _missionStarted   = true;
         _interact.enabled = false;
         _outOfRangeTimer  = 0f;
         _accompanyTimer   = 0f;
     }
 }
예제 #11
0
    private void ThrowObject(float p_strength)
    {
        InteractEvent.Invoke();

        m_grabbedObjectScript.Drop(gameObject);
        m_grabbedObjectScript.Throw(p_strength);

        m_grabbedObject       = null;
        m_grabbedObjectScript = null;
    }
예제 #12
0
        //------------------------------------------------------------------------/
        // Messages
        //------------------------------------------------------------------------/
        private void Awake()
        {
            if (!root)
            {
                StratusDebug.LogErrorBreak("No root transform selected for sensing!", this);
                return;
            }

            this.interactEvent = new InteractEvent(this);
            this.scanTimer     = new StratusStopwatch(this.scanInterval);
            this.OnAwake();
        }
예제 #13
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out _hit, InteractDistance))
         {
             if (_hit.collider.gameObject != null)
             {
                 InteractEvent.Invoke(_hit.collider.gameObject);
             }
         }
     }
 }
예제 #14
0
        //------------------------------------------------------------------------/
        // Messages
        //------------------------------------------------------------------------/
        private void Awake()
        {
            if (!root)
            {
                Trace.Error("No root transform selected for sensing!", this, true);
            }

            this.interactEvent = new InteractEvent()
            {
                sensor = this
            };
            this.scanTimer = new Stopwatch(this.scanInterval);
            this.OnAwake();
        }
예제 #15
0
 public override void Interact()
 {
     if (Active)
     {
         if (CurrentPage >= Pages.Count - 1)
         {
             Hide();
             InteractEvent?.Invoke(this, null);
         }
         else
         {
             CurrentPage++;
             Stopwatch.Restart();
         }
     }
 }
예제 #16
0
        private void OnPlayerInteract(InteractEvent interactEvent)
        {
            #region Checks
            if (interactEvent == null)
            {
                return;
            }
            if (interactEvent.Cancelled)
            {
                return;
            }
            if (interactEvent.Entity == null)
            {
                return;
            }
            if (interactEvent.ControllerEntity == null)
            {
                return;
            }
            if (!interactEvent.ControllerEntity.IsPlayer)
            {
                return;
            }
            #endregion

            var player   = interactEvent.ControllerEntity.Owner;
            var security = interactEvent.Entity.TryGet <ISecurable>();
            if (security == null)
            {
                return;
            }
            var objectGUID = security.ObjectGUID;

            StationCraftingData data;
            if (!Data.StationCraftingData.TryGetValue(objectGUID, out data))
            {
                data = new StationCraftingData(interactEvent.Entity.name);
                Data.Add(objectGUID, data);
            }

            data.SetInteraction(player.Id);

            SaveData();
        }
예제 #17
0
 public override void Interact()
 {
     InteractEvent?.Invoke(this, null);
 }
예제 #18
0
 public void invokeEvent(InteractEventArgs interactEventArgs)
 {
     InteractEvent?.Invoke(this, interactEventArgs);
 }
예제 #19
0
        public void AddInteractionController()
        {
            var controller     = new SmartController();
            var buttonsCreated = StaticServiceLocator.ContainsService <List <IButtonAble> >();

            if (!buttonsCreated)
            {
                var interactButton = new List <IButtonAble>
                {
                    new KeyButton(Keys.E),
                    new GamePadButton(Buttons.A)
                };
                StaticServiceLocator.AddService(interactButton);
            }
            var buttons     = StaticServiceLocator.GetService <List <IButtonAble> >();
            var smartButton = new CompositeSmartButton(buttons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    if (!DialogBox.Interact())
                    {
                        InteractEvent?.Invoke(this, null);
                    }
                }
            };

            controller.AddButton(smartButton);
            var upButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadUp, PlayerIndex.One, false)
            };
            var smartUpButton = new CompositeSmartButton(upButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Up();
                }
            };

            controller.AddButton(smartUpButton);
            var downButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadDown, PlayerIndex.One, false)
            };
            var smartDownButton = new CompositeSmartButton(downButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Down();
                }
            };

            controller.AddButton(smartDownButton);
            var optionsButtons = new List <IButtonAble>
            {
                new KeyButton(Keys.Escape),
                new GamePadButton(Buttons.Start)
            };
            var optionsAction = new CompositeSmartButton(optionsButtons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    _backButtonClickEvent.Invoke(this, null);
                }
            };

            controller.AddButton(optionsAction);
            UpdateList.Add(controller);
        }
예제 #20
0
 private void OnInteract()
 {
     //Debug.Log("OnInteract");
     InteractEvent?.Invoke();
 }
예제 #21
0
        static Event ParseEvent(IDataReader dataReader)
        {
            Event @event;
            var   type = (EventType)dataReader.ReadByte();

            switch (type)
            {
            case EventType.Teleport:
            {
                // 1. byte is the x coordinate
                // 2. byte is the y coordinate
                // 3. byte is the character direction
                // Then 1 unknown byte
                // Then 1 byte for the transtion type (0-5)
                // Then a word for the map index
                // Then 2 unknown bytes (seem to be 00 FF)
                uint x          = dataReader.ReadByte();
                uint y          = dataReader.ReadByte();
                var  direction  = (CharacterDirection)dataReader.ReadByte();
                var  unknown1   = dataReader.ReadByte();
                var  transition = (TeleportEvent.TransitionType)dataReader.ReadByte();
                uint mapIndex   = dataReader.ReadWord();
                var  unknown2   = dataReader.ReadBytes(2);
                @event = new TeleportEvent
                {
                    MapIndex   = mapIndex,
                    X          = x,
                    Y          = y,
                    Direction  = direction,
                    Transition = transition,
                    Unknown1   = unknown1,
                    Unknown2   = unknown2,
                };
                break;
            }

            case EventType.Door:
            {
                // 1. byte is a lockpicking chance reduction (0: already open, 100: can't open via lockpicking)
                // 2. byte is the door index (used for unlock bits in savegame)
                // 3. byte is an optional text index that is shown initially (0xff = no text)
                // 4. byte is an optional text index if the door was unlocked (0xff = no text)
                // 5. byte is unknown (always 0)
                // word at position 6 is the key index if a key must unlock it
                // last word is the event index (0-based) of the event that is called when unlocking fails
                var  lockpickingChanceReduction = dataReader.ReadByte();
                var  doorIndex            = dataReader.ReadByte();
                var  textIndex            = dataReader.ReadByte();
                var  unlockTextIndex      = dataReader.ReadByte();
                var  unused               = dataReader.ReadByte();
                uint keyIndex             = dataReader.ReadWord();
                var  unlockFailEventIndex = dataReader.ReadWord();
                @event = new DoorEvent
                {
                    LockpickingChanceReduction = lockpickingChanceReduction,
                    DoorIndex              = doorIndex,
                    TextIndex              = textIndex,
                    UnlockTextIndex        = unlockTextIndex,
                    Unused                 = unused,
                    KeyIndex               = keyIndex,
                    UnlockFailedEventIndex = unlockFailEventIndex
                };
                break;
            }

            case EventType.Chest:
            {
                // 1. byte is a lockpicking chance reduction (0: already open, 100: can't open via lockpicking)
                // 2. byte are the chest flags
                // 3. byte is an optional text index (0xff = no text)
                // 4. byte is the chest index (0-based)
                // 5. byte (0 = chest, 1 = pile/removable loot or item) or "remove if empty"
                // word at position 6 is the key index if a key must unlock it
                // last word is the event index (0-based) of the event that is called when unlocking fails
                var  lockpickingChanceReduction = dataReader.ReadByte();
                var  flags                = (ChestEvent.ChestFlags)dataReader.ReadByte();
                var  textIndex            = dataReader.ReadByte();
                uint chestIndex           = dataReader.ReadByte();
                bool removeWhenEmpty      = dataReader.ReadByte() != 0;
                uint keyIndex             = dataReader.ReadWord();
                var  unlockFailEventIndex = dataReader.ReadWord();
                @event = new ChestEvent
                {
                    LockpickingChanceReduction = lockpickingChanceReduction,
                    Flags                  = flags,
                    TextIndex              = textIndex,
                    ChestIndex             = chestIndex,
                    RemoveWhenEmpty        = removeWhenEmpty,
                    KeyIndex               = keyIndex,
                    UnlockFailedEventIndex = unlockFailEventIndex
                };
                break;
            }

            case EventType.PopupText:
            {
                // event image index (0xff = no image)
                // trigger (1 = move, 2 = eye cursor, 3 = both)
                // unknown boolean
                // map text index as word
                // 4 unknown bytes
                var eventImageIndex = dataReader.ReadByte();
                var popupTrigger    = (EventTrigger)dataReader.ReadByte();
                var unknownBool     = dataReader.ReadByte() != 0;
                var textIndex       = dataReader.ReadWord();
                var unknown         = dataReader.ReadBytes(4);
                @event = new PopupTextEvent
                {
                    EventImageIndex = eventImageIndex,
                    PopupTrigger    = popupTrigger,
                    TextIndex       = textIndex,
                    UnknownBool     = unknownBool,
                    Unknown         = unknown
                };
                break;
            }

            case EventType.Spinner:
            {
                var direction = (CharacterDirection)dataReader.ReadByte();
                var unused    = dataReader.ReadBytes(8);
                @event = new SpinnerEvent
                {
                    Direction = direction,
                    Unused    = unused
                };
                break;
            }

            case EventType.Trap:
            {
                var ailment         = (TrapEvent.TrapAilment)dataReader.ReadByte();
                var target          = (TrapEvent.TrapTarget)dataReader.ReadByte();
                var affectedGenders = (GenderFlag)dataReader.ReadByte();
                var baseDamage      = dataReader.ReadByte();
                var unused          = dataReader.ReadBytes(5); // unused
                @event = new TrapEvent
                {
                    Ailment         = ailment,
                    Target          = target,
                    AffectedGenders = affectedGenders,
                    BaseDamage      = baseDamage,
                    Unused          = unused
                };
                break;
            }

            case EventType.RemoveBuffs:
            {
                byte affectedBuffs = dataReader.ReadByte();
                var  unused        = dataReader.ReadBytes(8);
                @event = new RemoveBuffsEvent
                {
                    AffectedBuff = affectedBuffs == 0 ? (ActiveSpellType?)null: (ActiveSpellType)(affectedBuffs - 1),
                    Unused       = unused
                };
                break;
            }

            case EventType.Riddlemouth:
            {
                var introTextIndex          = dataReader.ReadByte();
                var solutionTextIndex       = dataReader.ReadByte();
                var unused                  = dataReader.ReadBytes(3);
                var correctAnswerTextIndex1 = dataReader.ReadWord();
                var correctAnswerTextIndex2 = dataReader.ReadWord();
                @event = new RiddlemouthEvent
                {
                    RiddleTextIndex               = introTextIndex,
                    SolutionTextIndex             = solutionTextIndex,
                    CorrectAnswerDictionaryIndex1 = correctAnswerTextIndex1,
                    CorrectAnswerDictionaryIndex2 = correctAnswerTextIndex2,
                    Unused = unused
                };
                break;
            }

            case EventType.Award:
            {
                var awardType      = (AwardEvent.AwardType)dataReader.ReadByte();
                var awardOperation = (AwardEvent.AwardOperation)dataReader.ReadByte();
                var random         = dataReader.ReadByte() != 0;
                var awardTarget    = (AwardEvent.AwardTarget)dataReader.ReadByte();
                var unknown        = dataReader.ReadByte();
                var awardTypeValue = dataReader.ReadWord();
                var value          = dataReader.ReadWord();
                @event = new AwardEvent
                {
                    TypeOfAward    = awardType,
                    Operation      = awardOperation,
                    Random         = random,
                    Target         = awardTarget,
                    AwardTypeValue = awardTypeValue,
                    Value          = value,
                    Unknown        = unknown
                };
                break;
            }

            case EventType.ChangeTile:
            {
                var x              = dataReader.ReadByte();
                var y              = dataReader.ReadByte();
                var unknown        = dataReader.ReadBytes(3);
                var frontTileIndex = dataReader.ReadWord();     // also wall/object index in lower byte
                var mapIndex       = dataReader.ReadWord();
                @event = new ChangeTileEvent
                {
                    X = x,
                    Y = y,
                    FrontTileIndex = frontTileIndex,
                    MapIndex       = mapIndex,
                    Unknown        = unknown
                };
                break;
            }

            case EventType.StartBattle:
            {
                var unknown1          = dataReader.ReadBytes(6);
                var monsterGroupIndex = dataReader.ReadByte();
                var unknown2          = dataReader.ReadBytes(2);
                @event = new StartBattleEvent
                {
                    MonsterGroupIndex = monsterGroupIndex,
                    Unknown1          = unknown1,
                    Unknown2          = unknown2
                };
                break;
            }

            case EventType.EnterPlace:
            {
                // map text index when closed (0xff is default message)
                // place type (see PlaceType)
                // opening hour
                // closing hour
                // text index for using the place (sleep, train, buy, etc)
                // place index (1-based, word)
                // 2 unknown bytes
                var textIndexWhenClosed = dataReader.ReadByte();
                var placeType           = (PlaceType)dataReader.ReadByte();
                var openingHour         = dataReader.ReadByte();
                var closingHour         = dataReader.ReadByte();
                var usePlaceTextIndex   = dataReader.ReadByte();
                var placeIndex          = dataReader.ReadWord();
                var merchantIndex       = dataReader.ReadWord();
                @event = new EnterPlaceEvent
                {
                    ClosedTextIndex   = textIndexWhenClosed,
                    PlaceType         = placeType,
                    OpeningHour       = openingHour,
                    ClosingHour       = closingHour,
                    PlaceIndex        = placeIndex,
                    UsePlaceTextIndex = usePlaceTextIndex,
                    MerchantDataIndex = merchantIndex
                };
                break;
            }

            case EventType.Condition:
            {
                var conditionType        = (ConditionEvent.ConditionType)dataReader.ReadByte();
                var value                = dataReader.ReadByte();
                var count                = dataReader.ReadByte();
                var unknown1             = dataReader.ReadBytes(2);
                var objectIndex          = dataReader.ReadWord();
                var jumpToIfNotFulfilled = dataReader.ReadWord();
                @event = new ConditionEvent
                {
                    TypeOfCondition = conditionType,
                    ObjectIndex     = objectIndex,
                    Value           = value,
                    Count           = count,
                    Unknown1        = unknown1,
                    ContinueIfFalseWithMapEventIndex = jumpToIfNotFulfilled
                };
                break;
            }

            case EventType.Action:
            {
                var actionType  = (ActionEvent.ActionType)dataReader.ReadByte();
                var value       = dataReader.ReadByte();
                var count       = dataReader.ReadByte();
                var unknown1    = dataReader.ReadBytes(2);
                var objectIndex = dataReader.ReadWord();
                var unknown2    = dataReader.ReadBytes(2);
                @event = new ActionEvent
                {
                    TypeOfAction = actionType,
                    ObjectIndex  = objectIndex,
                    Value        = value,
                    Unknown1     = unknown1,
                    Unknown2     = unknown2
                };
                break;
            }

            case EventType.Dice100Roll:
            {
                var chance = dataReader.ReadByte();
                var unused = dataReader.ReadBytes(6);
                var jumpToIfNotFulfilled = dataReader.ReadWord();
                @event = new Dice100RollEvent
                {
                    Chance = chance,
                    Unused = unused,
                    ContinueIfFalseWithMapEventIndex = jumpToIfNotFulfilled
                };
                break;
            }

            case EventType.Conversation:
            {
                var interaction = (ConversationEvent.InteractionType)dataReader.ReadByte();
                var unused1     = dataReader.ReadBytes(4); // unused
                var value       = dataReader.ReadWord();
                var unused2     = dataReader.ReadBytes(2); // unused
                @event = new ConversationEvent
                {
                    Interaction = interaction,
                    Value       = value,
                    Unused1     = unused1,
                    Unused2     = unused2
                };
                break;
            }

            case EventType.PrintText:
            {
                var npcTextIndex = dataReader.ReadByte();
                var unused       = dataReader.ReadBytes(8); // unused
                @event = new PrintTextEvent
                {
                    NPCTextIndex = npcTextIndex,
                    Unused       = unused
                };
                break;
            }

            case EventType.Create:
            {
                var createType = (CreateEvent.CreateType)dataReader.ReadByte();
                var unused     = dataReader.ReadBytes(4);
                var amount     = dataReader.ReadWord();
                var itemIndex  = dataReader.ReadWord();
                @event = new CreateEvent
                {
                    TypeOfCreation = createType,
                    Unused         = unused,
                    Amount         = amount,
                    ItemIndex      = itemIndex
                };
                break;
            }

            case EventType.Decision:
            {
                var textIndex    = dataReader.ReadByte();
                var unknown1     = dataReader.ReadBytes(6);
                var noEventIndex = dataReader.ReadWord();
                @event = new DecisionEvent
                {
                    TextIndex    = textIndex,
                    NoEventIndex = noEventIndex,
                    Unknown1     = unknown1
                };
                break;
            }

            case EventType.ChangeMusic:
            {
                var musicIndex = dataReader.ReadWord();
                var volume     = dataReader.ReadByte();
                var unknown1   = dataReader.ReadBytes(6);
                @event = new ChangeMusicEvent
                {
                    MusicIndex = musicIndex,
                    Volume     = volume,
                    Unknown1   = unknown1
                };
                break;
            }

            case EventType.Exit:
            {
                @event = new ExitEvent
                {
                    Unused = dataReader.ReadBytes(9)
                };
                break;
            }

            case EventType.Spawn:
            {
                // byte0: x
                // byte1: y
                // byte2: travel type (see TravelType)
                // byte3-4: unused?
                // byte5-6: map index
                // byte7-8: unused?
                var x          = dataReader.ReadByte();
                var y          = dataReader.ReadByte();
                var travelType = (TravelType)dataReader.ReadByte();
                var unknown1   = dataReader.ReadBytes(2);   // unknown
                var mapIndex   = dataReader.ReadWord();
                var unknown2   = dataReader.ReadBytes(2);   // unknown
                @event = new SpawnEvent
                {
                    X          = x,
                    Y          = y,
                    TravelType = travelType,
                    Unknown1   = unknown1,
                    MapIndex   = mapIndex,
                    Unknown2   = unknown2
                };
                break;
            }

            case EventType.Interact:
            {
                @event = new InteractEvent
                {
                    Unused = dataReader.ReadBytes(9)
                };
                break;
            }

            default:
            {
                @event = new DebugEvent
                {
                    Data = dataReader.ReadBytes(9)
                };
                break;
            }
            }

            @event.Type = type;

            return(@event);
        }