예제 #1
0
    void OnTriggerExit2D(Collider2D other)
    {
        // taxi has passenger and drive over building
        Debug.Log("Exit " + other.name);
        if (_targetTagName == "building" && _peopleId != string.Empty && _pickupState == PickupState.Pick)
        {
            if (_peopleId == _objectConfig.ID.ToString())
            {
                Debug.Log("pickup state: kick");
                // kick passenger
                _pickupState = PickupState.Kick;
            }
            //StartCoroutine (countsetMessageBox(_pickupState));
        }
        if (other.tag == "people" && _pickupState == PickupState.Empty)
        {
            Debug.Log("pickup state: Don't pick");
            other.gameObject.GetComponent <ObjectConfig> ().Anim();
            StartCoroutine(countsetMessageBox(_pickupState));
        }

        //Out
        if (_objectConfig == other.GetComponent <ObjectConfig>())
        {
            _objectConfig = null;
        }

        step = OnTriggeris.Exit;
    }
예제 #2
0
    public void OnReceiveItemPacket(int node, PacketId id, byte[] data)
    {
        ItemPacket packet = new ItemPacket(data);
        ItemData   item   = packet.GetPacket();

        string log = "[SERVER] ReceiveItemData " +
                     "itemId:" + item.itemId +
                     " state:" + item.state.ToString() +
                     " ownerId:" + item.ownerId;

        Debug.Log(log);
        dbwin.console().print(log);

        PickupState state = (PickupState)item.state;

        switch (state)
        {
        case PickupState.PickingUp:
            MediatePickupItem(item.itemId, item.ownerId);
            break;

        case PickupState.Dropping:
            MediateDropItem(item.itemId, item.ownerId);
            break;

        default:
            break;
        }
    }
예제 #3
0
 public static PickupState FromPickupInstance(Pickup instance)
 {
     var state = new PickupState();
     state.Ammo = instance.Ammo;
     state.Name = instance.PickupName;
     return state;
 }
    void Update()
    {
        PickupState = GetComponent <Pickup>().pickupState;
        // fire
        if (Input.GetButtonUp(FireButton))
        {
            if (PickupState == PickupState.HasWeapon)
            {
                currentWeapon = GetComponent <Pickup>().currentWeapon.GetComponent <Weapon>();
                hitCounter++;
                //print($"PlayerAttack: hit pos: {hitpos}");
                currentWeapon.Fire(hitPos, FirePoint.rotation);

                if (OnPlayerFired != null)
                {
                    OnPlayerFired(hitCounter);
                }
                //currentWeapon.Fire(CrosshairLandMark);
                if (hitCounter >= currentWeapon.Durability)
                {
                    DropWeapon(currentWeapon.destroyAfter);
                }
            }
        }
        // drop
        if (Input.GetButtonUp(DropWeaponButton))
        {
            if (PickupState == PickupState.HasWeapon)
            {
                DropWeapon();
            }
        }
    }
예제 #5
0
    private void HandleBuildingState()
    {
        if (_pickupState != PickupState.Pick)
        {
            return;
        }

        Debug.Log("sent passenger");

        if (_peopleId == _objectConfig.ID.ToString())
        {
            // taxi receive 100 baht.
            StartCoroutine(countsetMessageBox(PickupState.Pick));
            _moneyComponent.AddMoney(100);
            GetComponent <DriverSound> ().PlaySentSound();

            // taxi has not passenger.
            _pickupState = PickupState.Empty;
            _peopleId    = string.Empty;
        }
        else
        {
            StartCoroutine(countsetMessageBox(PickupState.Kick));
            Debug.Log("pickup state is kick. deduct money");
            _moneyComponent.DeductMoney(100);
            GetComponent <DriverSound>().PlayLosingSound();
            _pickupState = PickupState.Empty;
        }
    }
    private void PickUp()
    {
        Collider[] colliders;
        colliders = Physics.OverlapSphere(castStartPosition.position, castDistance);

        foreach (var item in colliders)
        {
            Collectable collectable = item.transform.gameObject.GetComponent <Collectable>();
            if (collectable == null)
            {
                continue;
            }
            if (collectable.PickupType == PickupType.Collectable)
            {
                //if (pickupState == PickupState.HasWeapon) return;
                GameObject pickedUp = Instantiate(item.transform.gameObject, hand.transform.position, hand.transform.rotation, hand.transform);
                pickedUp.GetComponent <Collider>().enabled = false;
                if (currentWeapon != null)
                {
                    Destroy(currentWeapon.gameObject);
                }
                currentWeapon = pickedUp;
                if (OnPickup != null)
                {
                    OnPickup(pickedUp);
                }
                pickupState = PickupState.HasWeapon;
                Destroy(item.transform.gameObject);
            }
        }
    }
예제 #7
0
파일: HandBehavior.cs 프로젝트: hwaet/LD48
    IEnumerator PickupAnimation(GameObject target)
    {
        Grabbable targetGrabbable = target.GetComponent <Grabbable>();

        if (targetGrabbable != null && targetGrabbable.Held)
        {
            yield break;
        }
        switch (target.tag)
        {
        case "fryBasket":
            yield return(PickupAndRotate(target));

            yield break;

        case "plate":
            PlateBehavior plate = target.GetComponent <PlateBehavior>();
            if (plate.Open)
            {
                plate.Close();
                yield break;
            }
            break;
        }

        pickupState  = PickupState.Seeking;
        pickupTarget = target;
        Vector3 currPos = transform.position;
        Vector3 vel     = Vector3.zero;

        //Debug.LogFormat("{0} Hand is going in", hand);
        while (pickupState == PickupState.Seeking)
        {
            if ((currPos - transform.position).magnitude > pickUpDistance || HoldingSomething)
            {
                pickupState = PickupState.Returning;
                break;
            }
            vel  = target.transform.position - this.transform.position;
            vel  = vel.normalized;
            vel *= pickupSpeed;
            rigidbody.velocity = vel;
            yield return(new WaitForFixedUpdate());
        }

        //Debug.LogFormat("{0} Hand is backing out", hand);
        while (transform.position.y < hoverHeight)
        {
            rigidbody.velocity = Vector3.up * pickupSpeed;
            yield return(new WaitForFixedUpdate());
        }

        rigidbody.velocity = Vector3.zero;
        //Debug.LogFormat("{0} Hand Done Picking Up", hand);
        pickupState = PickupState.Idle;
        yield break;
    }
예제 #8
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (Publisher.Instance.TryGetObserver(collision, out Observer observer))
     {
         pickupState = PickupState.GAIN;
         observer.PlayerInfo.scoreable.GainScore(scoreAmount);
         onGivingScore.Invoke();
     }
 }
예제 #9
0
    public void AddPickUpState(PickUpObject pickup)
    {
        PickupState pickupState = new PickupState()
        {
            ID     = pickup.ID,
            active = true
        };

        PickUps.Add(pickupState);
    }
예제 #10
0
        public PickupUnit(Actor self, Actor cargo, int delay)
        {
            this.cargo      = cargo;
            this.delay      = delay;
            carryable       = cargo.Trait <Carryable>();
            carryableFacing = cargo.Trait <IFacing>();
            carryableBody   = cargo.Trait <BodyOrientation>();

            movement       = self.Trait <IMove>();
            carryall       = self.Trait <Carryall>();
            carryallFacing = self.Trait <IFacing>();

            state = PickupState.Intercept;
        }
예제 #11
0
    private void HandlePassengerState()
    {
        if (_pickupState != PickupState.Empty)
        {
            return;
        }

        Debug.Log("pickup");
        _peopleId = _objectConfig.ID.ToString();
        GetComponent <DriverSound>().PlayPickUpSound();
        _objectConfig.gameObject.SetActive(false);

        // taxi pick passenger.
        _pickupState = PickupState.Pick;
    }
예제 #12
0
파일: HandBehavior.cs 프로젝트: hwaet/LD48
    IEnumerator PickupAndRotate(GameObject target)
    {
        pickupState  = PickupState.Seeking;
        pickupTarget = target;
        Vector3 currPos = transform.position;
        Vector3 vel;

        float      translationDistance = (transform.position - target.transform.position).magnitude;
        Quaternion targetRotation      = target.transform.rotation;

        //Debug.LogFormat("{0} Hand is going in", hand);
        while (pickupState == PickupState.Seeking)
        {
            if ((currPos - transform.position).magnitude > pickUpDistance || HoldingSomething)
            {
                break;
            }
            vel  = target.transform.position - transform.position;
            vel  = vel.normalized;
            vel *= pickupSpeed;
            rigidbody.velocity = vel;
            rigidbody.MoveRotation(Quaternion.Slerp(Quaternion.identity,
                                                    targetRotation,
                                                    1 - (transform.position - target.transform.position).magnitude / translationDistance));
            yield return(new WaitForFixedUpdate());
        }

        pickupState         = PickupState.Returning;
        translationDistance = hoverHeight - transform.position.y;
        rigidbody.rotation  = targetRotation;

        //Debug.LogFormat("{0} Hand is backing out", hand);
        while (transform.position.y < hoverHeight)
        {
            rigidbody.velocity = Vector3.up * pickupSpeed;
            rigidbody.MoveRotation(Quaternion.Slerp(targetRotation,
                                                    Quaternion.identity,
                                                    1 - (hoverHeight - transform.position.y) / translationDistance));
            //Debug.Log("Returning");
            yield return(new WaitForFixedUpdate());
        }

        rigidbody.velocity = Vector3.zero;
        rigidbody.rotation = Quaternion.identity;
        pickupState        = PickupState.Idle;
        yield break;
    }
예제 #13
0
    // Update is called once per frame
    void Update()
    {
        switch (_State)
        {
        case PickupState.GROWING:
            transform.localScale = _InitScale * _GrowFactor;
            _GrowFactor         += Time.deltaTime / GrowTime;
            if (_GrowFactor >= 1)
            {
                _GrowFactor = 1;

                EnableParticles(IdleParticles);
                _State = PickupState.SPAWNED;
                transform.Rotate(0, 0, 20 * Time.deltaTime);
                _isActive = true;
            }
            break;

        case PickupState.SHRINKING:
            transform.localScale = _InitScale * _GrowFactor;
            _GrowFactor         -= Time.deltaTime / GrowTime;
            if (_GrowFactor <= 0)
            {
                _GrowFactor = 0;
                _State      = PickupState.PICKED;
                transform.Rotate(0, 0, 20 * Time.deltaTime);
            }
            break;

        case PickupState.PICKED:
            _TimeSincePickedUp += Time.deltaTime;
            if (_TimeSincePickedUp > respawnTime)
            {
                _TimeSincePickedUp = 0;
                _State             = PickupState.GROWING;
                DisableParticles(IdleParticles);
            }
            break;

        case PickupState.SPAWNED:
            transform.Rotate(0, 0, 20 * Time.deltaTime);

            break;
        }
        ;
    }
예제 #14
0
    IEnumerator countsetMessageBox(PickupState _pickupS)
    {
        if (MessageBoxMinus.transform.parent.gameObject.activeSelf)
        {
            MessageBoxMinus.transform.parent.gameObject.SetActive(false);
        }
        if (MessageBox_dontpick.transform.parent.gameObject.activeSelf)
        {
            MessageBox_dontpick.transform.parent.gameObject.SetActive(false);
        }
        if (MessageBoxPlus.transform.parent.gameObject.activeSelf)
        {
            MessageBoxPlus.transform.parent.gameObject.SetActive(false);
        }
        Debug.Log("come");

        switch (_pickupS)
        {
        case PickupState.Pick:
            MessageBoxPlus.text = Plus_Message [Random.Range(0, Plus_Message.Length)];
            MessageBoxPlus.transform.parent.gameObject.SetActive(true);
            yield return(new WaitForSecondsRealtime(2.5f));

            MessageBoxPlus.transform.parent.gameObject.SetActive(false);
            break;

        case PickupState.Empty:
            if (_CarController.GetCarVelocity() != 0)
            {
                MessageBox_dontpick.text = dontpick_Message [Random.Range(0, dontpick_Message.Length)];
                MessageBox_dontpick.transform.parent.gameObject.SetActive(true);
                yield return(new WaitForSecondsRealtime(2.5f));

                MessageBox_dontpick.transform.parent.gameObject.SetActive(false);
            }
            break;

        case PickupState.Kick:
            MessageBoxMinus.text = Minus_Message [Random.Range(0, Minus_Message.Length)];
            MessageBoxMinus.transform.parent.gameObject.SetActive(true);
            yield return(new WaitForSecondsRealtime(2.5f));

            MessageBoxMinus.transform.parent.gameObject.SetActive(false);
            break;
        }
    }
예제 #15
0
    void OnTriggerEnter(Collider other)
    {
        if (_isActive)
        {
            if (other.tag == "DonutTruck")
            {
                if (!SCR_AbilityManager.TruckAbilityActive)
                {
                    _abilityScript.ActivateAbility(false);
                    _State    = PickupState.SHRINKING;
                    _isActive = false;
                }
                else if (!SCR_AbilityManager.TruckAbilityActive2)
                {
                    _abilityScript.ActivateAbility(false);
                    _isActive = false;
                    _State    = PickupState.SHRINKING;
                }
                OnPickupParticles();
            }
            if (other.tag == "PoliceCar")
            {
                if (!SCR_AbilityManager.PoliceAbilityActive)
                {
                    _abilityScript.ActivateAbility(true);
                    _State    = PickupState.SHRINKING;
                    _isActive = false;
                }
                else if (!SCR_AbilityManager.PoliceAbilityActive2)
                {
                    _abilityScript.ActivateAbility(true);
                    _State    = PickupState.SHRINKING;
                    _isActive = false;
                }

                OnPickupParticles();
            }
        }
    }
예제 #16
0
    public void SetState(PickupState s)
    {
        if (s == state)
        {
            return;
        }
        //Debug.Log("SetState");
        switch (s)
        {
        case PickupState.floatingFree:
            rb2d.bodyType  = RigidbodyType2D.Dynamic;
            rb2d.simulated = true;
            break;

        case PickupState.snappedToPlayer:
            rb2d.bodyType  = RigidbodyType2D.Static;
            rb2d.simulated = false;
            // Should also disable collider?
            break;
        }
        this.state = s;
    }
예제 #17
0
    // Update is called once per frame
    void Update()
    {
        if (_pickupState == PickupState.Kick)
        {
            StartCoroutine(countsetMessageBox(PickupState.Kick));
            Debug.Log("pickup state is kick. deduct money");
            _moneyComponent.DeductMoney(100);
            GetComponent <DriverSound>().PlayLosingSound();
            _pickupState = PickupState.Empty;
        }
        // not hit anything, skip it now.
        if (_objectConfig == null)
        {
            return;
        }

        if (step == OnTriggeris.Stay && _CarController.GetCarVelocity() == 0)
        {
            if (forpickup >= 0)
            {
                forpickup -= Time.deltaTime;
                return;
            }

            switch (_targetTagName)
            {
            case "people":
                HandlePassengerState();
                break;

            case "building":
                HandleBuildingState();
                break;
            }

            return;
        }
    }
예제 #18
0
 private void LoseTarget()
 {
     //Object not targeted anymore
     prompt.FadeOutText();
     currentPickupState = PickupState.noObjectTargeted;
 }
예제 #19
0
        public override Activity Tick(Actor self)
        {
            if (ChildActivity != null)
            {
                ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
                if (ChildActivity != null)
                {
                    return(this);
                }
            }

            if (cargo != carryall.Carryable)
            {
                return(NextActivity);
            }

            if (cargo.IsDead || IsCanceling || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self))
            {
                carryall.UnreserveCarryable(self);
                return(NextActivity);
            }

            if (carryall.State != Carryall.CarryallState.Reserved)
            {
                return(NextActivity);
            }

            switch (state)
            {
            case PickupState.Intercept:
                QueueChild(self, movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4), targetLineColor: Color.Yellow), true);
                state = PickupState.LockCarryable;
                return(this);

            case PickupState.LockCarryable:
                if (!carryable.LockForPickup(cargo, self))
                {
                    Cancel(self);
                }

                state = PickupState.MoveToCarryable;
                return(this);

            case PickupState.MoveToCarryable:
            {
                // Line up with the attachment point
                var localOffset    = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
                var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
                if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0)
                {
                    QueueChild(self, new Fly(self, Target.FromPos(targetPosition)), true);
                    return(this);
                }

                state = PickupState.Turn;
                return(this);
            }

            case PickupState.Turn:
                if (carryallFacing.Facing != carryableFacing.Facing)
                {
                    QueueChild(self, new Turn(self, carryableFacing.Facing), true);
                    return(this);
                }

                state = PickupState.Land;
                return(this);

            case PickupState.Land:
            {
                var localOffset    = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
                var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
                if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0 || carryallFacing.Facing != carryableFacing.Facing)
                {
                    state = PickupState.MoveToCarryable;
                    return(this);
                }

                if (targetPosition.Z != self.CenterPosition.Z)
                {
                    QueueChild(self, new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset)));
                    return(this);
                }

                state = delay > 0 ? PickupState.Wait : PickupState.Pickup;
                return(this);
            }

            case PickupState.Wait:
                QueueChild(self, new Wait(delay, false), true);
                state = PickupState.Pickup;
                return(this);

            case PickupState.Pickup:
                // Remove our carryable from world
                Attach(self);
                return(this);
            }

            return(NextActivity);
        }
예제 #20
0
    // Update is called once per frame
    void Update()
    {
        //Check for collision with liftable objects
        RaycastHit hitInfo     = new RaycastHit();
        Ray        ray         = new Ray(transform.position, transform.rotation * Vector3.forward);
        bool       objectFound = Physics.Raycast(ray, out hitInfo, distanceMax, layerMaskPickup);

        if (Input.GetButtonDown("Snap"))
        {
            snap          = !snap;
            snapText.text = "<b>[X]Snap: </b>" + ((snap) ? "ON" : "OFF");
        }
        if (Input.GetButtonDown("ShowPreview"))
        {
            showPreview      = !showPreview;
            previewText.text = "<b>[V]Preview: </b>" + ((showPreview) ? "ON" : "OFF");
        }

        if (carriedObjects.Count > 0 && currentPickupState != PickupState.interactObjectTargeted)
        {
            //Check distance mod
            float scrollDelta = Input.GetAxis("DistanceModification");
            if (scrollDelta != 0)
            {
                distance = Mathf.Clamp(distance + scrollDelta, distanceMin, distanceMax);
            }

            //Set initial drop location
            dropCoords      = new Vector3Int[] { Vector3Int.zero, Vector3Int.zero };
            dropLocations   = new Vector3[] { Vector3.zero, Vector3.zero };
            canDropAtCoords = new bool[] { true, true };
            showDrop        = new bool[] { true, true };


            if (objectFound && hitInfo.distance <= distance)
            {
                dropLocations[0] = hitInfo.point + (hitInfo.normal * 0.53f) - (snap ? Vector3.zero : carriedItem.centerLocalTransform);
                dropCoords[0]    = placementGrid.WorldToCell(dropLocations[0]);
                Box box = hitInfo.transform.gameObject.GetComponent <Box>();
                if (box != null)
                {
                    dropCoords[1]      = box.GetBoxOnTopOfMyStack().GetHighestCoordAlignedWithStack() + Vector3Int.up;
                    canDropAtCoords[1] = Vector3.Distance(transform.position, placementGrid.CellToWorld(dropCoords[1])) < distanceMax;
                }
                else
                {
                    placementPreviews[1].transform.position = placementPreviews[0].transform.position;
                    placementPreviews[1].transform.rotation = placementPreviews[0].transform.rotation;
                    canDropAtCoords[1] = false;
                    showDrop[1]        = false;
                }
            }
            else
            {
                dropLocations[0]   = transform.position + (transform.rotation * (Vector3.forward * distance) - carriedItem.centerLocalTransform);
                dropCoords[0]      = placementGrid.WorldToCell(dropLocations[0] + carriedItem.centerLocalTransform);
                canDropAtCoords[1] = false;
                showDrop[1]        = false;
            }
            //Set pickup preview materials
            if (!canDropAtCoords[1] || dropCoords[0] == dropCoords[1])
            {
                placementPreviews[0].SetPreview(carriedItem, PickupPreview.Prompt.r);
                showDrop[1] = false;
            }
            else
            {
                placementPreviews[0].SetPreview(carriedItem, PickupPreview.Prompt.r);
                placementPreviews[1].SetPreview(carriedItem, PickupPreview.Prompt.g);
            }

            //Convert back to world space
            for (int i = 0; i < dropCoords.Length; ++i)
            {
                if (i > 0 || snap)
                {
                    dropLocations[i] = placementGrid.CellToWorld(dropCoords[i]);
                }
                bool obstructionNotDetected = !Physics.CheckBox(dropLocations[i] + new Vector3(0.5f, 0.55f, 0.5f), new Vector3(0.51f, 0.475f, 0.51f), Quaternion.identity, layerMaskObstructed);
                bool clippingNotDetected    = !Physics.CheckBox(dropLocations[i] + new Vector3(0.5f, 0.55f, 0.5f), new Vector3(0.51f, 0.475f, 0.51f), Quaternion.identity, layerMaskHide);
                bool insideOfPuzzleBounds   = true;
                if (carriedItem.puzzle != null)
                {
                    insideOfPuzzleBounds = carriedItem.puzzle.IsInPuzzleBoundry(dropLocations[i]);
                }
                if (i == 0 && (!obstructionNotDetected || !clippingNotDetected))
                {
                    exception.FadeInText("NO SPACE");
                }
                if (i == 0 && !insideOfPuzzleBounds)
                {
                    exception.FadeInText("OUT OF BOUNDS");
                }
                canDropAtCoords[i] = canDropAtCoords[i] && obstructionNotDetected && clippingNotDetected && insideOfPuzzleBounds;
                MaterialPropertyBlock properties = new MaterialPropertyBlock();
                if (showDrop[i] && showPreview)
                {
                    placementPreviews[i].gameObject.SetActive(true);
                    prompt.FadeInText("<b>[R]</b>Place");
                    if (canDropAtCoords[i])
                    {
                        placementPreviews[i].SetValid(true);
                        //properties.SetColor("_Color", new Color(0.7f, 0.89f, 1f, 0.75f));
                    }
                    else
                    {
                        prompt.FadeOutText();
                        placementPreviews[i].SetValid(false);
                        //properties.SetColor("_Color", new Color(1f, 0.89f, 0.7f, 0.75f));
                    }
                    placementPreviews[i].gameObject.transform.position = Vector3.Lerp(placementPreviews[i].gameObject.transform.position, dropLocations[i], 0.25f);
                    placementPreviews[i].gameObject.transform.rotation = Quaternion.Lerp(placementPreviews[i].gameObject.transform.rotation, Quaternion.identity, 0.25f);
                    //Graphics.DrawMesh(carriedItemMesh, dropLocations[i], Quaternion.identity, carriedItemMaterial, 0, GetComponent<Camera>(), 0, properties, false);
                }
                else
                {
                    placementPreviews[i].gameObject.SetActive(false);
                }
            }
            if ((Input.GetButtonDown("Drop") || (Input.GetButtonDown("DropOnStack") && !canDropAtCoords[1])) && canDropAtCoords[0])
            {
                DropObject(dropLocations[0], Quaternion.identity);
            }
            if (Input.GetButtonDown("DropOnStack") && canDropAtCoords[1])
            {
                DropObject(dropLocations[1], Quaternion.identity);
            }
        }
        else
        {
            placementPreviews[0].gameObject.SetActive(false);
            placementPreviews[1].gameObject.SetActive(false);
            if (Input.GetButtonDown("Fire3"))
            {
                if (Player.singleton.myPickup.carriedObjects.Count > 0) //Don't reset anything if player is carrying boxes
                {
                    return;
                }
                Puzzle[] puzzles      = FindObjectsOfType <Puzzle>();
                Puzzle   activePuzzle = null;
                foreach (Puzzle puzzle in puzzles)
                {
                    if (puzzle.IsInPuzzleBoundry(Player.singleton.transform.position) == true)
                    {
                        activePuzzle = puzzle;
                        break;
                    }
                }
                if (activePuzzle)
                {
                    PuzzleSystem.ResetPuzzle(activePuzzle);
                }
            }
        }

        switch (currentPickupState)
        {
        case PickupState.noObjectTargeted:
            if (objectFound)
            {
                targetedObject = hitInfo.transform.gameObject;
                bool        busy      = true;
                PickupState nextState = PickupState.noObjectTargeted;
                switch (hitInfo.transform.tag)
                {
                case "Interactable":
                    nextState = PickupState.interactObjectTargeted;
                    targetedItemInteraction = targetedObject.GetComponent <Interaction>();
                    busy = targetedItemInteraction.IsBusy();

                    break;

                case "Liftable":
                    nextState       = PickupState.pickupObjectTargeted;
                    targetedItemBox = targetedObject.GetComponent <Box>();
                    //HighlightGroup();
                    busy = false;
                    break;

                default:
                    break;
                }
                //Check the availability of the targeted object
                if (busy == false)
                {
                    currentPickupState = nextState;
                    //Debug.Log("Target found.");
                    //Debug.Log("Targeted item: " + targetedObject.name);
                }
            }


            break;

        case PickupState.interactObjectTargeted:
            if (!targetedItemInteraction.IsBusy())
            {
                RefreshText();
            }
            if (InteractTargetLost(objectFound, hitInfo))
            {
                //Object not targeted anymore
                LoseTarget();
            }
            else
            {
                if (Input.GetButtonDown("Interact/Pickup"))
                {
                    //Interact with object
                    targetedItemInteraction.Interact(this);
                }
            }
            break;

        case PickupState.pickupObjectTargeted:
            if (PickupTargetLost(objectFound, hitInfo))
            {
                //UnHighlightGroup();
                LoseTarget();
            }
            else
            {
                prompt.FadeInText("<b>[E]</b>Lift");
                bool pickup = false;
                Box  box    = targetedItemBox;
                if (Input.GetButtonDown("Interact/Pickup"))
                {
                    //Pickup object
                    pickup = true;
                }
                if (Input.GetButtonDown("PickupOnStack"))
                {
                    //Pickup object on top of a stack
                    pickup = true;
                    box    = targetedItemBox.GetBoxOnTopOfMyStack();
                }
                if (carriedObjects.Count == 0)    //TODO Find way to show exceptions for picking up and placing seperately
                {
                    if (box.isTooHeavy)
                    {
                        exception.FadeInText("TOO HEAVY");
                    }
                    else if (carriedObjects.Count == carryObjectLimit)
                    {
                        exception.FadeInText("INVENTORY FULL");
                    }
                    else if (pickup)
                    {
                        PickupObject(box);
                    }
                }
            }
            //else if (box.GetBoxOnTopOfMe() != null)
            //{

            //    exception.FlashText("BOX BLOCKED", 2f);
            //}
            break;
        }



        //if Input.GetButtonDown("Pickup"){

        //}
    }
예제 #21
0
 // Use this for initialization
 void Start()
 {
     _pickupState    = PickupState.Empty;
     _moneyComponent = Money.GetComponent <MoneyComponent>();
 }
예제 #22
0
        public override bool Tick(Actor self)
        {
            if (cargo != carryall.Carryable)
            {
                return(true);
            }

            if (IsCanceling)
            {
                if (carryall.State == Carryall.CarryallState.Reserved)
                {
                    carryall.UnreserveCarryable(self);
                }

                return(true);
            }

            if (cargo.IsDead || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self))
            {
                carryall.UnreserveCarryable(self);
                return(true);
            }

            // Wait until we are near the target before we try to lock it
            var distSq = (cargo.CenterPosition - self.CenterPosition).HorizontalLengthSquared;

            if (state == PickupState.Intercept && distSq <= targetLockRange.LengthSquared)
            {
                state = PickupState.LockCarryable;
            }

            if (state == PickupState.LockCarryable)
            {
                var lockResponse = carryable.LockForPickup(cargo, self);
                if (lockResponse == LockResponse.Failed)
                {
                    Cancel(self);
                }
                else if (lockResponse == LockResponse.Success)
                {
                    // Pickup position and facing are now known - swap the fly/wait activity with Land
                    ChildActivity.Cancel(self);

                    var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
                    QueueChild(new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), carryableFacing.Facing));

                    // Pause briefly before attachment for visual effect
                    if (delay > 0)
                    {
                        QueueChild(new Wait(delay, false));
                    }

                    // Remove our carryable from world
                    QueueChild(new AttachUnit(self, cargo));
                    QueueChild(new TakeOff(self));

                    state = PickupState.Pickup;
                }
            }

            // Return once we are in the pickup state and the pickup activities have completed
            return(TickChild(self) && state == PickupState.Pickup);
        }
예제 #23
0
 /// <summary>
 /// State machine
 /// <summary>
 void SetPickupState(PickupState state)
 {
     pickState = state;
 }
예제 #24
0
        public override Activity Tick(Actor self)
        {
            if (innerActivity != null)
            {
                innerActivity = ActivityUtils.RunActivity(self, innerActivity);
                return(this);
            }

            if (cargo != carryall.Carryable)
            {
                return(NextActivity);
            }

            if (cargo.IsDead || IsCanceled || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self))
            {
                carryall.UnreserveCarryable(self);
                return(NextActivity);
            }

            if (carryall.State == Carryall.CarryallState.Idle)
            {
                return(NextActivity);
            }

            switch (state)
            {
            case PickupState.Intercept:
                innerActivity = movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4));
                state         = PickupState.LockCarryable;
                return(this);

            case PickupState.LockCarryable:
                state = PickupState.MoveToCarryable;
                if (!carryable.LockForPickup(cargo, self))
                {
                    state = PickupState.Aborted;
                }
                return(this);

            case PickupState.MoveToCarryable:
            {
                // Line up with the attachment point
                var localOffset    = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
                var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
                if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0)
                {
                    // Run the first tick of the move activity immediately to avoid a one-frame pause
                    innerActivity = ActivityUtils.RunActivity(self, new HeliFly(self, Target.FromPos(targetPosition)));
                    return(this);
                }

                state = PickupState.Turn;
                return(this);
            }

            case PickupState.Turn:
                if (carryallFacing.Facing != carryableFacing.Facing)
                {
                    innerActivity = new Turn(self, carryableFacing.Facing);
                    return(this);
                }

                state = PickupState.Land;
                return(this);

            case PickupState.Land:
            {
                var localOffset    = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
                var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
                if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0 || carryallFacing.Facing != carryableFacing.Facing)
                {
                    state = PickupState.MoveToCarryable;
                    return(this);
                }

                if (targetPosition.Z != self.CenterPosition.Z)
                {
                    innerActivity = new HeliLand(self, false, self.World.Map.DistanceAboveTerrain(targetPosition));
                    return(this);
                }

                state = delay > 0 ? PickupState.Wait : PickupState.Pickup;
                return(this);
            }

            case PickupState.Wait:
                state         = PickupState.Pickup;
                innerActivity = new Wait(delay, false);
                return(this);

            case PickupState.Pickup:
                // Remove our carryable from world
                Attach(self);
                return(NextActivity);

            case PickupState.Aborted:
                // We got cancelled
                carryall.UnreserveCarryable(self);
                break;
            }

            return(NextActivity);
        }
예제 #25
0
        public override bool Tick(Actor self)
        {
            if (cargo != carryall.Carryable)
            {
                return(true);
            }

            if (IsCanceling)
            {
                if (carryall.State == Carryall.CarryallState.Reserved)
                {
                    carryall.UnreserveCarryable(self);
                }

                return(true);
            }

            if (cargo.IsDead || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self))
            {
                carryall.UnreserveCarryable(self);
                return(true);
            }

            if (carryall.State != Carryall.CarryallState.Reserved)
            {
                return(true);
            }

            switch (state)
            {
            case PickupState.Intercept:
                QueueChild(movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4)));
                state = PickupState.LockCarryable;
                return(false);

            case PickupState.LockCarryable:
                if (!carryable.LockForPickup(cargo, self))
                {
                    Cancel(self);
                }

                state = PickupState.Pickup;
                return(false);

            case PickupState.Pickup:
            {
                // Land at the target location
                var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
                QueueChild(new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), carryableFacing.Facing));

                // Pause briefly before attachment for visual effect
                if (delay > 0)
                {
                    QueueChild(new Wait(delay, false));
                }

                // Remove our carryable from world
                QueueChild(new AttachUnit(self, cargo));
                QueueChild(new TakeOff(self));
                return(false);
            }
            }

            return(true);
        }
예제 #26
0
    public void SaveValues()
    {
        GameManager game = GameManager.instance;
        EnemyManager enemyManager = EnemyManager.instance;
        OnGuiManager onGuiManager = OnGuiManager.instance;
        SmoothMouseLookX mouseX = SmoothMouseLookX.instance;
        SmoothMouseLookY mouseY = SmoothMouseLookY.instance;
        TriggerHandler dragonTriggerHandler = TriggerHandler.instance;

        dragonSlayed = game.statistics.dragonSlayed;

        // save GameObject, Transform, Vector3 and Quaternion by adding .Serializable() extension
        sPlayer = game.player.gameObject.Serializable();
        sTreasure = game.treasure.gameObject.Serializable();
        if (dragonSlayed){
            GameObject dragonRagdoll = GameObject.Find("Dragon Ragdoll(Clone)");
            sDragon = dragonRagdoll.Serializable();
        } else {
            sDragon = game.dragon.gameObject.Serializable();
        }

        // save enemies and misc objects by listing them
        sGameObjects = new List<sGameObject>();
        foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[]){
            if (go.name.Equals("orc(Clone)") || go.name.Equals("orc ragdoll(Clone)") ||
                go.name.Equals("Lizard(Clone)") || go.name.Equals("Lizard ragdoll(Clone)") ||
                go.name.Equals("WereWolf(Clone)") || go.name.Equals("WereWolf ragdoll(Clone)")){
                sGameObjects.Add(go.Serializable());
            }
        }

        // save current time and date
        dateTime = System.DateTime.Now.ToString("MM/dd/yyyy, HH:mm");

        // save playtime with previous value + time since level load
        playTime = game.statistics.playTime + Time.timeSinceLevelLoad;

        // save time variables relative to Time.timeSinceLevelLoad as load game's time starts from 0
        timeOfLastWave = enemyManager.timeOfLastWave - Time.timeSinceLevelLoad;
        timeOfEnemyCountRising = enemyManager.timeOfEnemyCountRising - Time.timeSinceLevelLoad;
        spawnTimeStart = enemyManager.spawnTimeStart - Time.timeSinceLevelLoad;

        // save game difficulty setting
        difficulty = game.difficulty;

        formatVersion = game.saves.GetFormatVersion();

        // save regular variable here
        timeBetweenEnemyCountAddition = enemyManager.timeBetweenEnemyCountAddition;
        waveIntervalOnDragonFight = enemyManager.waveIntervalOnDragonFight;
        maxDragonFightEnemies = enemyManager.maxDragonFightEnemies;
        dragonFightSpwans = enemyManager.dragonFightSpwans;
        waveInterval = enemyManager.waveInterval;
        maxEnemies = enemyManager.maxEnemies;
        originalWaveInterval = enemyManager.originalWaveInterval;
        originalMaxEnemies = enemyManager.originalMaxEnemies;
        inBattle = enemyManager.inBattle;
        spawnCount = enemyManager.spawnCount;
        nextEnemyType = enemyManager.nextEnemyType;
        dragonHasAggroOnPlayer = dragonTriggerHandler.dragonHasAggroOnPlayer;
        playerKilledTrigger = dragonTriggerHandler.playerKilled;
        mousePositionX = mouseX.GetPosition();
        mousePositionY = mouseY.GetPosition();
        //mouseSensitivity = mouseX.sensitivity;
        //mouseSmoothing = mouseX.smoothing;
        level = game.statistics.level;
        bodycount = game.statistics.bodycount;
        score = game.statistics.score;
        pickupState = game.pickupState;
        bloodAlpha = onGuiManager.bloodSplatter.GetBloodAlpha();
        playerArmor = game.player.GetArmor();
        playerHealth = game.player.GetHealth();
        playerAlive = game.player.GetAliveStatus();
        treasureOnGround = game.treasure.OnGround();
        treasureAmount = game.treasure.GetTreasureAmount();
        wave = game.statistics.wave;
        gun0_rounds = game.weapons.guns[0].currentRounds;
        gun1_rounds = game.weapons.guns[1].currentRounds;
        gun2_rounds = game.weapons.guns[2].currentRounds;
        gun3_rounds = game.weapons.guns[3].currentRounds;
        gun4_rounds = game.weapons.guns[4].currentRounds;
        gun0_clips = game.weapons.guns[0].totalClips;
        gun1_clips = game.weapons.guns[1].totalClips;
        gun2_clips = game.weapons.guns[2].totalClips;
        gun3_clips = game.weapons.guns[3].totalClips;
        gun4_clips = game.weapons.guns[4].totalClips;
        pickedup_gun3 = game.weapons.guns[3].picked_up;
        pickedup_gun4 = game.weapons.guns[4].picked_up;
        pickedup_armor = game.statistics.armorPickedUp;
        grenades = game.weapons.grenadeCount;
        currentGunIndex = game.weapons.currentGunIndex;
        dragonFighting = game.dragon.GetFighting();
        dragonPatroling = game.dragon.GetPatroling();
        dragonWalking = game.dragon.GetWalking();
        dragonLanding = game.dragon.GetLanding();
        dragonHealth = game.dragon.GetHealth();
        dragonMaxHealth = game.dragon.GetMaxHealth();
        dragonBreathFire = game.dragon.breathFire;
        dragonLastBreath = game.dragon.timeOfLastFireBreath;
        dragonFlying = game.dragon.flying;
    }
예제 #27
0
 private void Start()
 {
     pickupState = PickupState.NOT_GAIN;
 }