示例#1
0
    private static Node CreateInteractionBehavior(Dorf d, IInteractable i)
    {
        Condition findWork = new Condition(() => {
            //TODO: what check here? Maybe an action to get a work-place?
            return false;
        });

        BehaviorTrees.Action goToWork = new BehaviorTrees.Action(() => {
            //TODO: replace vector param with location of workplace!
            var mc = new MoveCommand(d,new Vector3(),WALKSPEED);
            if (mc.isAllowed()) {
                mc.execute();
                return Node.Status.RUNNING;
            } else {
                return Node.Status.FAIL;
            }
        });

        BehaviorTrees.Action work = new BehaviorTrees.Action(() => {
            //TODO: replace null value with some kind of interactable variable from d.
            var ic = new InteractCommand(d,null);
            if (ic.isAllowed()) {
                ic.execute();
                return Node.Status.RUNNING;
            } else {
                return Node.Status.FAIL;
            }
        });

        SequenceSelector root = new SequenceSelector(findWork,goToWork,work);
        return root;
    }
示例#2
0
 //private Methods
 private void InteractCheck(Vector3 center, float radius)
 {
     float minDist = float.MaxValue;
     Collider[] hitColliders = Physics.OverlapSphere(center, radius);
     List<Collider> interactables = new List<Collider>();
     for (int i = 0; i < hitColliders.Length; i++)
     {
         if (hitColliders[i].GetComponent<IInteractable>() != null)
         {
             interactables.Add(hitColliders[i]);
         }
     }
     int n = 0;
     while (n < interactables.Count)
     {
         //compare distance between player and interactable objects
         //if current dist is smaller than min dist then store that object in ObjectToInteractWith and set minDist to that value
         if (minDist > Vector3.Distance(interactables[n].transform.position, m_Actor.transform.position))
         {
             minDist = Vector3.Distance(interactables[n].transform.position, m_Actor.transform.position);
             current = interactables[n].GetComponent<IInteractable>();
             //Debug.Log("Closest Interactable: " + interactables[n]);
         }
         n++;
     }
     if(interactables.Count < 1)
     {
         current = null;
     }
 }
示例#3
0
文件: Swiches.cs 项目: JonECG/Brogue
 public presserPlate(IInteractable actingOn)
 {
     active = false;
     isSolid = true;
     isPassable = true;
     target = actingOn;
 }
示例#4
0
        /// <summary>
        /// Returns an interactable in the current world's scene that p_interactable collides with if its position were changed.
        /// if p_interactable is colliding with p_exclude, that collision doesn't count
        /// (i.e. it doesn't make sense to check whether something is colliding with itself)
        /// </summary>
        /// <param name="p_interactable">Interactable to check</param>
        /// <param name="p_offset">The proposed movement of the Interactable</param>
        /// <param name="p_exclude">An interactable to exclude from collision checking</param>
        /// <returns>An interactable that p_interactable collides with; null if no collisions are detected</returns>
        public static IInteractable collisionWithInteractableAtRelative(IInteractable p_interactable, Point p_offset, IInteractable p_exclude)
        {
            IInteractable l_collidedObject = null;
            foreach (IInteractable i in WorldManager.m_currentRoom.Interactables)
            {
                if (i == p_exclude || m_excluded.Contains(i))
                {
                    continue;
                }
                Rectangle l_copy = p_interactable.getBoundingRect();    //preserve this just in case
                Rectangle l_spriteBounds;
                l_spriteBounds.X = l_copy.X + p_offset.X;
                l_spriteBounds.Y = l_copy.Y + p_offset.Y;
                l_spriteBounds.Width = l_copy.Width;
                l_spriteBounds.Height = l_copy.Height;

                Rectangle l_charBounds = i.getBoundingRect();
                if (l_spriteBounds.Intersects(l_charBounds))
                {
                    l_collidedObject = i;
                    break;
                }
            }
            return l_collidedObject;
        }
 public InteractWithNearestState(NavMeshAgent agent, GameObject goal)
 {
     _agent = agent;
     cam = _agent.gameObject.GetComponent<CharacterAnimMovement>();
     _intaractableGoal = goal.GetComponent<IInteractable>();
     _interactGameObject = goal;
 }
        public InteractWithNearestState(NavMeshAgent agent, string tag, GameObject pickup)
        {
            _agent = agent;

            cam = _agent.gameObject.GetComponent<CharacterAnimMovement>();

            _interactGameObject = pickup;

            var interactables = GameObject.FindGameObjectsWithTag(tag);
            if (interactables.Length < 1)
            {
                GameObject.FindGameObjectWithTag("AudioManager").GetComponent<AudioManager>().FemaleNoSoundPlay();
                _state = State.Done;
                return;
            }

            foreach (var i in interactables)
            {
                _interactGameObject = i;
                var dest = i.GetComponent<IInteractable>();
                if(!dest.CanThisBeInteractedWith(pickup)) continue;
                var path = new NavMeshPath();
                agent.CalculatePath(dest.InteractPosition(_agent.transform.position), path);

                if (path.status != NavMeshPathStatus.PathComplete) continue;

                _intaractableGoal = dest;
                break;
            }

            if(_intaractableGoal == null)
                _state = State.Done;
        }
示例#7
0
    public override bool CheckInteraction(ISelectable[] selectedObjects, IInteractable obj)
    {
        if (selectedObjects[0].GetType() == typeof(Unit) && obj.GetType() == typeof(Map)) {
            return true;
        }

        return false;
    }
示例#8
0
        private void DoInteract(SimulationComponent simulation, IInteractor interactor, IInteractable interactable)
        {
            var quest = simulation.World.Quests.SingleOrDefault(q => q.Name == "Heidis Quest");
            before.Visible = quest.State == QuestState.Inactive;
            after.Visible = quest.State == QuestState.Active && quest.CurrentProgress.Id == "return";

            RheinwerkGame game = simulation.Game as RheinwerkGame;
            simulation.ShowInteractionScreen(interactor as Player, new DialogScreen(game.Screen, this, interactor as Player, dialog));
        }
示例#9
0
 public override void onCollide(IInteractable other)
 {
     base.onCollide(other);
     if (other is Hero)
     {
         Hero h1 = (Hero)other;
         h1.shiftHealth(-1);
         //dec health?
     }
 }
示例#10
0
 //public Methods
 public void Interact()
 {
     if (current != null)
     {
         Debug.Log("Interact successful");
         current.OnInteraction();
     }
     else
     {
         Debug.Log("Interact Failed");
         current = null;
     }
 }
示例#11
0
	// Update is called once per frame
	void Update () {

        currentObject = PerformRaycast();

        if (currentObject != null)
        {
            currentObject.Highlight();
        }



	
	}
示例#12
0
 public void foodCollideEvent(IInteractable collider)
 {
     if (collider is Hero
         || (Hero.instance.hasFollower() && CharacterManager.getCharacter(Hero.instance.getFollowerID()) == collider))
     {
         if (Quest.isQuestStateActive(QuestID.FoodFight, QuestState.Progress1)
             && Quest.isQuestStateInactive(QuestID.FoodFight, QuestState.Progress2))
         {
             ScreenTransition.requestTransition(delegate()
             {
                 WorldManager.setRoomNoTransition(PlaceID.Cafeteria, 24 * TILE_SIZE, 10 * TILE_SIZE, Direction.West);
                 CharacterManager.getCharacter(PersonID.Phil).setPosition(25 * TILE_SIZE, 10 * TILE_SIZE);
                 CharacterManager.getCharacter(PersonID.Phil).reset();
             });
         }
         else if (Quest.isQuestStateActive(QuestID.FoodFight, QuestState.Progress3)
         && Quest.isQuestStateInactive(QuestID.FoodFight, QuestState.Progress4))
         {
             ScreenTransition.requestTransition(delegate()
             {
                 WorldManager.setRoomNoTransition(PlaceID.Cafeteria, 12 * TILE_SIZE, 9 * TILE_SIZE, Direction.West);
                 CharacterManager.getCharacter(PersonID.Artie).setPosition(12 * TILE_SIZE, 8 * TILE_SIZE);
                 CharacterManager.getCharacter(PersonID.Artie).reset();
             });
         }
         else if (Quest.isQuestStateActive(QuestID.FoodFight, QuestState.Progress5)
         && Quest.isQuestStateInactive(QuestID.FoodFight, QuestState.Progress6))
         {
             ScreenTransition.requestTransition(delegate()
             {
                 WorldManager.setRoomNoTransition(PlaceID.Cafeteria, 17 * TILE_SIZE, 14 * TILE_SIZE, Direction.West);
                 CharacterManager.getCharacter(PersonID.Bill).setPosition(16 * TILE_SIZE, 14 * TILE_SIZE);
                 CharacterManager.getCharacter(PersonID.Bill).reset();
             });
         }
         else if (Quest.isQuestStateActive(QuestID.FoodFight, QuestState.Progress7)
         && Quest.isQuestStateInactive(QuestID.FoodFight, QuestState.Progress8))
         {
             ScreenTransition.requestTransition(delegate()
             {
                 WorldManager.setRoomNoTransition(PlaceID.Cafeteria, 24 * TILE_SIZE, 18 * TILE_SIZE, Direction.West);
                 CharacterManager.getCharacter(PersonID.Claude).setPosition(25 * TILE_SIZE, 18 * TILE_SIZE);
                 CharacterManager.getCharacter(PersonID.Claude).reset();
             });
         }
         else
             WorldManager.setRoom(PlaceID.Cafeteria, 1 * TILE_SIZE, 8 * TILE_SIZE, Direction.East);
     }
 }
示例#13
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Camera"))
     {
         inCameraView = true;
     }
     else if (other.gameObject.CompareTag("Light"))
     {
         inLight = true;
     }
     else if (other.gameObject.CompareTag("Interactible"))
     {
         Debug.Log("OnTriggerEnter interactible");
         interactObject = other.gameObject.GetComponent <IInteractable>();
         GameManager.instance.UpdateOnScreenMessage("Press E to interact");
     }
 }
示例#14
0
    private void OnInteractStart(IInteractable interactable)
    {
        switch (interactable.type)
        {
        case InteractionType.MAN_STATION:
        {
            this.animator.SetBool(this.manStationParamBoolName, true);
        }
        break;

        case InteractionType.REPAIR:
        {
            this.animator.SetBool(this.repairParamBoolName, true);
        }
        break;
        }
    }
示例#15
0
    private void ClickTarget()
    {
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            RaycastHit2D hit = Physics2D.Raycast(mainCamra.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, LayerMask.GetMask("Clickable"));
            if (hit.collider != null && hit.collider.tag == "Enemy")
            {
                if (currentTarget != null)
                {
                    currentTarget.DeSelect();
                }
                currentTarget = hit.collider.GetComponent <Enemy>();

                player.MyTarget = currentTarget.Select();

                ////MainController 显示 Target 血条
                //MainController.Instance.ShowTargetFrame(currentTarget);
            }
            else
            {
                ////MainController 隐藏 Target 血条
                //MainController.Instance.HideTargetFrame();

                if (currentTarget != null)
                {
                    currentTarget.DeSelect();
                }
                currentTarget   = null;
                player.MyTarget = null;
            }
        }
        else if (Input.GetMouseButtonDown(1) && !EventSystem.current.IsPointerOverGameObject())
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, LayerMask.GetMask("Clickable"));

            if (hit.collider != null)
            {
                IInteractable entity = hit.collider.gameObject.GetComponent <IInteractable>();
                if (hit.collider != null && (hit.collider.tag == "Enemy" || hit.collider.tag == "Interactable") && (hit.collider.gameObject.GetComponent <IInteractable>() == player.MyInteractable))
                {
                    entity.Interact();
                }
            }
        }
    }
示例#16
0
    void Update()
    {
        if (player != null)
        {
            closest = null; // get the closest entity
            foreach (IInteractable interactable in AIData.interactables)
            {
                if (interactable as PlayerCore || interactable == null || !interactable.GetInteractible())
                {
                    continue;
                }

                if (closest == null)
                {
                    closest = interactable;
                }
                else if ((interactable.GetTransform().position - player.transform.position).sqrMagnitude <=
                         (closest.GetTransform().position - player.transform.position).sqrMagnitude)
                {
                    closest = interactable;
                }
            }

            if (closest is IVendor vendor)
            {
                var blueprint = vendor.GetVendingBlueprint();
                var range     = blueprint.range;

                if (!player.GetIsDead() && (closest.GetTransform().position - player.transform.position).sqrMagnitude <= range)
                {
                    for (int i = 0; i < blueprint.items.Count; i++)
                    {
                        if (InputManager.GetKey(KeyName.TurretQuickPurchase))
                        {
                            if (Input.GetKeyDown((1 + i).ToString()))
                            {
                                vendorUI.SetVendor(vendor, player);
                                vendorUI.onButtonPressed(i);
                            }
                        }
                    }
                }
            }
        }
    }
示例#17
0
    /// <summary>
    /// Gestion du clic sur une cible
    /// </summary>
    private void ClickTarget()
    {
        // Raycast depuis la position de la souris dans le jeu
        RaycastHit2D hit = Physics2D.Raycast(mainCamera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, LayerMask.GetMask("Clickable"));

        // Clic gauche et que l'on ne pointe pas sur un élément de l'interface (par exemple un bouton d'action)
        if (Input.GetMouseButtonDown(0) & !EventSystem.current.IsPointerOverGameObject())
        {
            // Désélection de la cible courante
            DeSelectTarget();

            // Si l'on touche un ennemi
            if (hit.collider != null && hit.collider.CompareTag("Enemy"))
            {
                // Sélection de la nouvelle cible
                SelectTarget(hit.collider.GetComponent <Enemy>());
            }
            // Désélection de la cible
            else
            {
                // Masque la frame de la cible
                UIManager.MyInstance.HideTargetFrame();

                // Supprime les références à la cible
                currentTarget   = null;
                player.MyTarget = null;
            }
        }
        // Clic droit et que l'on ne pointe pas sur un élément de l'interface (par exemple un bouton d'action)
        else if (Input.GetMouseButtonDown(1) & !EventSystem.current.IsPointerOverGameObject())
        {
            // S'il y a une entité avec laquelle le joueur est en interaction
            if (hit.collider != null)
            {
                IInteractable entity = hit.collider.gameObject.GetComponent <IInteractable>();

                // Si l'on touche quelque chose et que celle-ci a un tag "Enemy" ou Interactable et que cette entité est dans la liste avec laquelle le joueur est en interaction
                if (hit.collider != null && (hit.collider.CompareTag("Enemy") || hit.collider.CompareTag("Interactable")) && player.MyInteractables.Contains(entity))
                {
                    // Interaction avec le personnage
                    entity.Interact();
                }
            }
        }
    }
示例#18
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray ray = new Ray(cam.transform.position, cam.transform.forward);

            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                IInteractable interactable = hit.transform.GetComponent <IInteractable>();

                if (interactable == null)
                {
                    return;
                }
                interactable.OnInteract();
            }
        }
    }
示例#19
0
    private void ScreenPick()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit hitInfo;

        Physics.Raycast(ray, out hitInfo, 1000.0f, _layerMask, QueryTriggerInteraction.Collide);

        // Was something hit?
        if (hitInfo.transform)
        {
            IInteractable i = hitInfo.transform.GetComponentInParent <IInteractable>();
            if (i != null)
            {
                i.Interact();
            }
        }
    }
示例#20
0
    void Awake()
    {
        if (_singleInstance != null)
        {
            Object.Destroy(gameObject);
            return;
        }
        rigidBody = GetComponent <Rigidbody>();
        SetupAudioEmitters();
        DontDestroyOnLoad(gameObject);
        _singleInstance = this;

        SceneManager.sceneLoaded += (Scene scene, LoadSceneMode mode) =>
        {
            currentInteractable = null;
            SetupAudioEmitters();
        };
    }
示例#21
0
    private void orderTarget()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            RaycastHit hit;
            Vector3    fwd = transform.TransformDirection(Vector3.forward);
            Ray        ray = Camera.main.ScreenPointToRay(crosshair.transform.position);
            Debug.DrawRay(transform.position, ray.direction, Color.blue, 3f);
            if (Physics.Raycast(ray, out hit, 45))
            {
                IInteractable i = hit.collider.GetComponent <IInteractable>();

                if (i != null)
                {
                }
            }
        }
    }
示例#22
0
    private bool CanStartCommandInteraction(IInteractable interactable)
    {
        if (interactable.interact.CanStart(this.crewman))
        {
            // Anyone else on this job yet?
            foreach (var crewman in Game.instance.crewmen)
            {
                if (crewman.GetComponent <CrewmanInteraction>().commandedInteractable == interactable)
                {
                    return(false);
                }
            }

            return(true);
        }

        return(false);
    }
示例#23
0
        private void OnTriggerEnter2D(Collider2D other)
        {
            IInteractable interactable = other.GetComponent <IInteractable>();

            if (null == interactable || !interactable.CanInteract)
            {
                return;
            }

            var interactables = _interactables.GetOrAdd(interactable.GetType());

            if (interactables.Add(interactable))
            {
                InteractableAddedEvent?.Invoke(this, new InteractableEventArgs {
                    Interactable = interactable
                });
            }
        }
示例#24
0
        private void Interact_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.up, 1f, LayerMask.GetMask("Entities"));

            if (hit)
            {
                IInteractable interactable = hit.collider.gameObject.GetComponent <IInteractable>();
                if (interactable != null)
                {
                    object interacted = interactable.Interact();
                    if (interacted.GetType() == typeof(Inventory))
                    {
                        //Display inventory being interacted with
                        uiManager.ObserveInventory((Inventory)interacted);
                    }
                }
            }
        }
示例#25
0
    private void Interact()
    {
        Collider2D c = CheckForthTile();

        if (c != null)
        {
            IInteractable interactable = c.GetComponent <IInteractable>();
            if (interactable != null)
            {
                interactable.OnInteract();
            }

            if (c.CompareTag("Water"))
            {
                StartCoroutine(StartSwimming());
            }
        }
    }
    // When interact button is input:
    public void InteractInput()
    {
        int currentNearestObjectIndex = CheckNearestObjectSlot();

        // If not null, and there are nearby interactables...
        if (currentNearestObjectIndex > -1)
        {
            interactedObject = nearbyInteractables [currentNearestObjectIndex];

            // Run OnInteract() function in all of the IInteractable Monobehaviors attached to the interactedObject
            IInteractable[] interactedObjectMonobehaviors = interactedObject.GetComponents <IInteractable> ();
            foreach (IInteractable mb in interactedObjectMonobehaviors)
            {
                IInteractable interactable = (IInteractable)mb;
                interactable.OnInteract();                  // This might need to get triggered at a specific frame of animation. i.e. Only remove item from the ground when the character's hand grasps it.
            }
        }
    }
示例#27
0
    private IInteractable GetClosestInteractable()
    {
        IInteractable result           = null;
        float         shortestDistance = 0f;

        for (int i = 0; i < interactables.Count; i++)
        {
            float currentDistance = (((MonoBehaviour)interactables[i]).transform.position - transform.position).magnitude;

            if (shortestDistance == 0f || currentDistance < shortestDistance)
            {
                shortestDistance = currentDistance;
                result           = interactables[i];
            }
        }

        return(result);
    }
    public static IInteractable GetClostestsInteractable(this List <IInteractable> list, Vector3 position)
    {
        IInteractable closest          = null;
        var           shortestDistance = Mathf.Infinity;

        foreach (var otherPosition in list)
        {
            var distance = (position - otherPosition.GetPosition()).sqrMagnitude;

            if (distance < shortestDistance)
            {
                closest          = otherPosition;
                shortestDistance = distance;
            }
        }

        return(closest);
    }
示例#29
0
 public void NotfiyInteractablesMovedAway(Collider2D[] tempInteractables)
 {
     if (nearbyInteractables != null)
     {
         foreach (Collider2D collider in nearbyInteractables)
         {
             if (!tempInteractables.Contains(collider))
             {
                 IInteractable movedFrom = GameManager.getInstance().GetInteractable(collider.transform);
                 if (movedFrom != null)
                 {
                     movedFrom.InRange(false);
                 }
             }
         }
     }
     nearbyInteractables = tempInteractables;
 }
示例#30
0
        public override void Execute()
        {
            Physics.Raycast(_transform.position + Vector3.up,
                            _transform.forward, out var hit, 2f,
                            LayerMask.GetMask(LayerName));

            Debug.Log($"{gameObject.name} is trying to interact!");

            if (hit.collider == null)
            {
                return;
            }

            Debug.Log($"{gameObject.name} is interacted with {hit.collider.name}");

            _interactedWith = hit.collider.GetComponent <IInteractable>();
            _interactedWith?.Interact();
        }
示例#31
0
    private void SetInteraction(IInteractable interactableObject)
    {
        if (interactableObject == null)
        {
            return;
        }
        if (interactableObject.gameObject.transform == transform)
        {
            Debug.LogWarning("Cannot interact with self.");
            return;
        }

        NextInteraction = interactableObject;

        motor.setDestination(NextInteraction.GetInteractionPoint(transform));

        // Todo: Remove action points (or maybe keep that in the player movement script along with everything else).
    }
示例#32
0
    public void CheckInput()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        bool       rayHit = Physics.Raycast(ray, out hit, Mathf.Infinity, layerToRaycastTo);

        if (Input.GetMouseButtonDown(0))
        {
            isMouseDown = true;
            if (rayHit)
            {
                IInteractable interactable = hit.collider.gameObject.GetComponent <IInteractable>();
                interactable?.OnTouchBegin();
            }
            else
            {
                GameManager.Instance.DeselectAll();
            }
            return;
        }

        if (isMouseDown && Input.GetMouseButton(0))
        {
            if (rayHit)
            {
                IInteractable interactable = hit.collider.gameObject.GetComponent <IInteractable>();
                interactable?.OnTouchMoved();
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            isMouseDown = false;
            if (rayHit)
            {
                IInteractable interactable = hit.collider.gameObject.GetComponent <IInteractable>();
                interactable?.OnTouchEnd();
            }
            else
            {
                GameManager.Instance.DeselectAll();
            }
        }
    }
示例#33
0
    private void HandleRaycast()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, raycastDistance))
        {
            IInteractable lootable = hit.collider.GetComponent <IInteractable>();

            if (lootable != null)
            {
                if (lootable == currentTarget)
                {
                    return;
                }
                else if (currentTarget != null)
                {
                    currentTarget.OnEndLook();
                    currentTarget = lootable;
                    currentTarget.OnStartLook();
                }
                else
                {
                    currentTarget = lootable;
                    currentTarget.OnStartLook();
                }
            }
            else
            {
                if (currentTarget != null)
                {
                    currentTarget.OnEndLook();
                    currentTarget = null;
                }
            }
        }
        else
        {
            if (currentTarget != null)
            {
                currentTarget.OnEndLook();
                currentTarget = null;
            }
        }
    }
示例#34
0
        private void Awake()
        {
            _target = GetComponentInParent <IInteractable>();
            _user   = StreamClient.Instance;

            Observable.Merge(_user.SelectedTypeRx, _user.SelectedIdRx.Select(_ => ""))
            .SampleFrame(1)
            .ObserveOnMainThread()
            .TakeUntilDestroy(this)
            .Subscribe(_ => UpdateEnabled());

            if (DisableOnZenMode)
            {
                _user.ZenModeRx
                .ObserveOnMainThread()
                .TakeUntilDestroy(this)
                .Subscribe(_ => UpdateEnabled());
            }
        }
        public void Start()
        {
            Key key;
            IList <IInteractionEffect> effects = new List <IInteractionEffect>();

            while ((key = this.keyReader.ReadKey()) != Key.None)
            {
                if (this.currentPlayer.Stamina <= 0)
                {
                    this.ApplyEffects(effects);
                    effects = new List <IInteractionEffect>();

                    this.ToggleCurrentPlayer();
                }

                GridDirection direction = (GridDirection)Enum.Parse(typeof(GridDirection), key.ToString());
                IInteractable neighbour = this.layout.GetNeighbour(this.currentPlayer, direction);
                if (neighbour != null)
                {
                    effects.Add(neighbour.InteractWith(this.currentPlayer.LaunchEffect()));
                }
                this.layout.Move(this.currentPlayer, direction);

                this.currentPlayer.Stamina--;
                this.layout.Update();

                IPlayer foughtPlayer = this.players.FirstOrDefault(p => p.FightPosition != FightPosition.Neutral);
                if (foughtPlayer != null)
                {
                    this.Winner = foughtPlayer.FightPosition == FightPosition.Won
                        ? foughtPlayer
                        : this.players.FirstOrDefault(p => p != foughtPlayer);

                    break;
                }
            }

            if (this.Winner == null)
            {
                this.ApplyEffects(effects);
                this.Winner = this.players.FirstOrDefault(p => p.Power == this.players.Max(ip => ip.Power));
            }
        }
示例#36
0
    public override void ResetState(IInteractable gun)
    {
        _playerController.GunAnchor.rotation = _cameraController.CameraRoot.rotation;

        if (gun == null)
        {
            TakeGunFromHolster();
        }
        else
        {
            HoldGun((GunScript)gun);
        }

        _isAiming = false;
        _isFiring = false;

        _dropGunTimer       = 0;
        _punchCoolDownTimer = _playerController.PunchCoolDown;
    }
示例#37
0
 public void TributeMenu(int spaces)
 {
     try
     {
         m_choiceresult = LuaEngine.Instance.RunString("return {}").First() as LuaTable;
         m_curchoice    = new SwapGiveMenu(0, spaces, (List <int> chosenGoods) =>
         {
             LuaFunction addfn = LuaEngine.Instance.RunString("return function(tbl, val) table.insert(tbl, val) end").First() as LuaFunction;
             foreach (int chosenGood in chosenGoods)
             {
                 addfn.Call(m_choiceresult, chosenGood);
             }
         });
     }
     catch (Exception e)
     {
         DiagManager.Instance.LogInfo(String.Format("ScriptUI.TributeMenu(): Encountered exception:\n{0}", e.Message));
     }
 }
示例#38
0
    public override void ExecuteInteraction(ISelectable[] selectedObjects, IInteractable obj)
    {
        int cntPoints = selectedObjects.Length;
        Vector3[] points = new Vector3[cntPoints];

        int ring = 0;
        int ringCnt = 0;
        float ringAngle = 0;

        Vector3 targetPos;
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast (ray, out hit, 2000)) {
            targetPos = hit.point;
        } else {
            return;
        }

        float unitSize = 0;
        for (int i = 0; i < selectedObjects.Length; i++) {
            unitSize = Mathf.Max(unitSize, (selectedObjects[i] as Unit).sizeRadius);
        }

        // TODO: We should use map tiles for this
        for (int i = 0; i < cntPoints; i++) {
            if (ringCnt == ring * 2 + 1) {
                ring++;
                ringCnt = 0;
                ringAngle = 0;
            }

            points[i] = targetPos + new Vector3(unitSize * ring * Mathf.Cos(ringAngle),
                                                unitSize * ring * Mathf.Sin(ringAngle),
                                                0);

            ringCnt = ringCnt + 1;
            ringAngle = ringAngle + 2 * Mathf.PI / (ring * 2 + 1);
        }

        for (int i = 0; i < cntPoints; i++) {
            (selectedObjects[i] as Unit).MoveTo(points[i]);
        }
    }
示例#39
0
    public void ChangeOwnership(int ID)
    {
        IInteractable interactable = InteractableFactory.Instance.GetInteractable(ID);

        if (isOffline)
        {
            networkRPC.ChangeOwnership(interactable.ID);
            return;
        }

        switch (interactable.effectType)
        {
        case EffectType.EFFECT_BOTH: photonView.RPC("ChangeOwnership", RpcTarget.AllBuffered, ID); break;

        case EffectType.EFFECT_OWN: networkRPC.Interact(interactable.ID); break;

        case EffectType.EFFECT_OTHER: photonView.RPC("ChangeOwnership", RpcTarget.OthersBuffered, ID); break;
        }
    }
示例#40
0
        private IInteractable SweepForInteraction()
        {
            UpdateCapsulePoints();

            var interactables = Physics.CapsuleCastAll(m_Point1, m_Point2, 0.6f, Vector3.down, 1f, m_InteractableLayer);

            foreach (var hit in interactables)
            {
                if (m_Interactable != null)
                {
                    // only active while close to object, and remove it after interaction
                    // so only set it to true once
                    m_InteractableText.SetActive(true);
                }

                return(m_Interactable = hit.transform.gameObject.GetComponent(typeof(IInteractable)) as IInteractable);
            }
            return(null);
        }
示例#41
0
    private void OnTriggerExit(Collider other)
    {
        IInteractable        temp         = other.GetComponent <IInteractable>();
        IOnEnterInteractable autoInteract = other.GetComponent <IOnEnterInteractable>();

        if (temp == focus)
        {
            if (temp != null)
            {
                temp.LeaveInteract();
            }
            OnExitInteractable?.Invoke();
            focus = null;
        }
        if (autoInteract != null)
        {
            autoInteract.Leave();
        }
    }
示例#42
0
 public void SpoilsMenu(LuaTable appraisalMap)
 {
     try
     {
         List <Tuple <InvItem, InvItem> > goodsList = new List <Tuple <InvItem, InvItem> >();
         foreach (object key in appraisalMap.Keys)
         {
             LuaTable entry = appraisalMap[key] as LuaTable;
             InvItem  box   = entry["Box"] as InvItem;
             InvItem  item  = entry["Item"] as InvItem;
             goodsList.Add(new Tuple <InvItem, InvItem>(box, item));
         }
         m_curchoice = new SpoilsMenu(goodsList);
     }
     catch (Exception e)
     {
         DiagManager.Instance.LogInfo(String.Format("ScriptUI.SpoilsMenu(): Encountered exception:\n{0}", e.Message));
     }
 }
示例#43
0
    IEnumerator OpenChest(IInteractable interactable)
    {
        GameObject chestObject = interactable.GetObject();
        Chest      chest       = chestObject.GetComponent <Chest>();
        GameObject item        = chest.GetItem();

        _linkAnimator.SetBool("IsPickingUp", true);
        _linkRigidbody.constraints = RigidbodyConstraints2D.FreezeAll;
        while (!Input.GetKeyDown(KeyCode.A))
        {
            yield return(null);
        }
        _invetory.Add(item.GetComponent <Item>().GetItemDescriptor());
        Destroy(item);
        _linkAnimator.SetBool("IsPickingUp", false);
        _linkRigidbody.constraints = RigidbodyConstraints2D.None;
        _linkRigidbody.constraints = RigidbodyConstraints2D.FreezeRotation;
        yield return(null);
    }
示例#44
0
        // returns an object in the specified Tiled map object layer that the given sprite collides with
        // throws exception if the specified layer does not exist!
        public static MapObject collisionWithObjectAtRelative(IInteractable p_interactable, Point p_offset, String p_layer)
        {
            MapObject l_collidedObject = null;

            foreach (MapObject m in ((MapObjectLayer) WorldManager.m_currentRoom.background.GetLayer(p_layer)).Objects) {
                Rectangle l_copy = p_interactable.getBoundingRect();    //preserve this just in case
                Rectangle l_spriteBounds;
                l_spriteBounds.X = l_copy.X + p_offset.X;
                l_spriteBounds.Y = l_copy.Y + p_offset.Y;
                l_spriteBounds.Width = l_copy.Width;
                l_spriteBounds.Height = l_copy.Height;

                if (l_spriteBounds.Intersects(m.Bounds)) {
                    l_collidedObject = m;
                    break;
                }
            }

            return l_collidedObject;
        }
示例#45
0
    void GetNearestInteractableNPCInScene()
    {
        if (interactables.Count > 1) SortInteractables();

        for (int i = 0; i < interactables.Count; i++)
        {
            float dist = (interactables[i].transform.position - transform.position).sqrMagnitude;

            if (dist > maxInteractionRange)
            {
                closetInteractable = null;
                return;
            }

            closetInteractable = interactables[i].GetComponent<IInteractable>();
            return;
        }

        closetInteractable = null;
    }
示例#46
0
文件: Item.cs 项目: BjkGkh/R106
        internal Item(uint Id, int Sprite, string PublicName, string Name, string Type, int Width, int Length, 
            double Height, bool Stackable, bool Walkable, bool IsSeat, bool AllowRecycle, bool AllowTrade, bool AllowMarketplaceSell, bool AllowGift, bool AllowInventoryStack,
            InteractionType InteractionType, int Modes, string VendingIds, SortedDictionary<uint, double> heightModes, bool isGroupItem)
        {
            this.Id = Id;
            this.SpriteId = Sprite;
            this.PublicName = PublicName;
            this.Name = Name;
			this.Type = char.ToLower(Type[0]);
            this.Width = Width;
            this.Length = Length;
            this.Height = Height;
            this.Stackable = Stackable;
            this.Walkable = Walkable;
            this.IsSeat = IsSeat;
            this.AllowRecycle = AllowRecycle;
			this.HeightModes = heightModes;
            this.AllowTrade = AllowTrade;
            this.AllowMarketplaceSell = AllowMarketplaceSell;
            this.AllowGift = AllowGift;
            this.AllowInventoryStack = AllowInventoryStack;
            this.InteractionType = InteractionType;
            this.FurniInteractor = FurniInteractorFactory.GetInteractable(this.InteractionType);
            this.FurniInitializer = FurniIInitializerFactory.GetInteractable(this.InteractionType);
            this.FurniTrigger = FurniTriggerFactory.GetInteractable(this.InteractionType);
            this.Modes = Modes;
            this.VendingIds = new List<int>();
            this.IsGift = false;
            this.IsGroupItem = isGroupItem;

            if (VendingIds.Contains(","))
            {
                foreach (string VendingId in VendingIds.Split(','))
                    this.VendingIds.Add(TextHandling.ParseInt32(VendingId));
            }
            else if (!VendingIds.Equals(string.Empty) && (TextHandling.ParseInt32(VendingIds)) > 0)
                this.VendingIds.Add(TextHandling.ParseInt32(VendingIds));
        }
示例#47
0
    protected bool TryInvoking(IInteractable[] list, GadgetIdentifier identifier)
    {
        //If any gadget was invoked successfully, we return true in the end
        bool anyGadgetFired = false;

        for (int i = 0; i < list.Length; i++)
        {
            if (list[i].Execute(identifier))
            {
                anyGadgetFired = true;
            }
        }

        if (anyGadgetFired)
        {
            return true;
        }

        //Usually this should return false because no action was fired at this point.
        //To prevent the system from skipping to the next nearest object we simply always
        //tell it that the invocation was a success
        return true;
    }
示例#48
0
 public virtual void onCollide(IInteractable other)
 {
 }
示例#49
0
 public static void removeObjectFromRoom(IInteractable p_obj, PlaceID p_room)
 {
     m_rooms[p_room].removeObject(p_obj);
 }
        protected override void InnerDoInteraction(ILocation location, IAgent actor, IInteractable target)
        {
            if (location == null) throw new ArgumentNullException("location");
            if (target == null) throw new ArgumentNullException("target");

            // TODO: Pick an interaction from a list when we have more than one
            // TODO: Other interaction types

            // Resolve action
            var result = this.attackInteraction.Interact(actor, target);

            // Discard used up resource nodes
            if (target is IResourceNode && target.CurrentResourceCount == 0)
            {
                location.CurrentResources.Remove(target as IResourceNode);
            }

            // Log the action
            if (result > 0)
            {
                actor.Species.RecordConsumptionOf(ToUnique(target), result);

                this.AddEventToAgent(actor, new TargetedEvent(location, CurrentGeneration, ToUnique(target), result));
                if (target is IAgent)
                {
                    var targetAgent = target as IAgent;
                    this.AddEventToAgent(targetAgent, new TargetOfEvent(location, CurrentGeneration, ToUnique(actor), result));
                }
            }
        }
示例#51
0
 public static void addObjectToRoom(IInteractable p_obj, PlaceID p_room)
 {
     m_rooms[p_room].addObject(p_obj);
 }
示例#52
0
 void Awake()
 {
     interactable = interactableObject.GetComponent<IInteractable>();
     interactableObject = null;
 }
示例#53
0
 private void heroBulletCollideEvent(IInteractable collider)
 {
     if (collider is BraceFace)
     {
         BraceFace b1 = (BraceFace)collider;
         b1.shiftHealth(-1);
         //dec health
     }
 }
示例#54
0
 /// <summary>
 /// We assume whenever the Hero collides with a pickup he picks it up.
 /// </summary>
 public override void onCollide(IInteractable other)
 {
     base.onCollide(other);
     Hero.instance.pickup(this);     //roundabout.. change later
 }
示例#55
0
 private void braceBulletCollideEvent(IInteractable collider)
 {
     if (collider is Hero)
     {
         Hero h1 = (Hero)collider;
         h1.shiftHealth(-1);
         //dec health
     }
 }
示例#56
0
 public static void enqueueObjectToCurrentRoom(IInteractable p_obj)
 {
     m_rooms[m_currentRoomID].enqueueObject(p_obj);
 }
示例#57
0
文件: Swiches.cs 项目: JonECG/Brogue
 public Switch(IInteractable actingOn, Direction directionToFace)
 {
     active = false;
     isSolid = false;
     isPassable = false;
     directionFacing = directionToFace;
     targets = new List<IInteractable>();
     targets.Add(actingOn);
 }
示例#58
0
文件: Swiches.cs 项目: JonECG/Brogue
 public void addTarget(IInteractable actingOn)
 {
     targets.Add(actingOn);
 }
示例#59
0
 public override void onCollide(IInteractable other)
 {
     base.onCollide(other);
     if (mEvent != null)
     {
         mEvent(other);
     }
 }
示例#60
0
文件: Swiches.cs 项目: JonECG/Brogue
 public void link(IInteractable actingOn)
 {
     target = actingOn;
 }