コード例 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        LostItem item = collision.gameObject.GetComponent <LostItem>();

        if (item == null)
        {
            return;
        }

        if (_item.IsSelected || (_item.IsMoving && !item.IsMoving))
        {
            if (_objectsOnTop.Count == 0)
            {
                if (transform.position.z > item.transform.position.z - 1)
                {
                    transform.position = new Vector3(transform.position.x, transform.position.y, item.transform.position.z - 1);
                }
            }
            else if (item.transform.position.z == transform.position.z - 1)
            {
                item.transform.position += new Vector3(0, 0, 1);
                transform.position      -= new Vector3(0, 0, 1);
            }
        }

        if (item.transform.position.z < transform.position.z)
        {
            _objectsOnTop.Add(item.gameObject);
            _objectsOnTop.Sort((a, b) => (int)(b.transform.position.z - a.transform.position.z));
        }
    }
コード例 #2
0
ファイル: Table.cs プロジェクト: DragosPopse/LostAndFound
    public void ConstraintMovement(LostItem item, bool condition)
    {
        if (condition)
        {
            var itemBounds      = item.GetComponent <BoxCollider2D>().bounds;
            var itemNewPosition = item.NewPosition;

            //Check if point is not within bounds
            if (itemNewPosition.x + itemBounds.extents.x > Bounds.max.x)
            {
                itemNewPosition.x = Bounds.max.x - itemBounds.extents.x;
            }
            else if (itemNewPosition.x - itemBounds.extents.x < Bounds.min.x)
            {
                itemNewPosition.x = Bounds.min.x + itemBounds.extents.x;
            }

            if (itemNewPosition.y + itemBounds.extents.y > Bounds.max.y && !item.IsSelected)
            {
                itemNewPosition.y = Bounds.max.y - itemBounds.extents.y;
            }
            else if (itemNewPosition.y - itemBounds.extents.y < Bounds.min.y)
            {
                itemNewPosition.y = Bounds.min.y + itemBounds.extents.y;
            }

            item.NewPosition = itemNewPosition;
        }
    }
コード例 #3
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            hasTalked = true;
            GameObject playerCarry = collision.gameObject.GetComponent <PlayerController>().carrying;
            if (playerCarry)
            {
                if (playerCarry == myObject)
                {
                    LostItem thisItem = myObject.GetComponent <LostItem>();
                    objectFound = true;
                    phrase      = foundPhrasePool[Random.Range(0, foundPhrasePool.Length)];
                    phrase      = phrase.Replace("1", thisItem.myName);
                    Destroy(myObject);
                }
            }
            else
            {
                text.text = "That's not mine...";
            }

            showText();
        }
    }
コード例 #4
0
ファイル: LostController.cs プロジェクト: s4sixty/iFind
        public IActionResult Post([FromBody] LostItem item)
        {
            try
            {
                LostItem itemCheck = db.LostItems.SingleOrDefault(x => x.Id.Equals(item.Id));
                // check if item exists
                if (itemCheck != null)
                {
                    return(Conflict());
                }

                item.UserId = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);

                // set creation date
                item.CreatedAt  = DateTime.UtcNow;
                item.ModifiedAt = DateTime.UtcNow;

                db.LostItems.Add(item);
                db.SaveChanges();

                return(Ok(new { item }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
コード例 #5
0
    private void OnCollisionStay2D(Collision2D collision)
    {
        if (!_waiting)
        {
            return;
        }

        LostItem item = collision.gameObject.GetComponent <LostItem>();

        if (!item)
        {
            return;
        }

        _renderer.sprite = _angrySprite;
        var wanted = CustomerManager.Instance.wantedItems;

        if (!wanted.Contains(item))
        {
            return;
        }
        if (item != _wantedItem && item != _stealItem)
        {
            return;
        }

        _renderer.sprite = _gaspSprite;
        if (item.IsSelected)
        {
            return;
        }

        _foundItem = item;
        wanted.Remove(_wantedItem);
    }
コード例 #6
0
ファイル: LostController.cs プロジェクト: s4sixty/iFind
        public IActionResult Put([FromBody] LostItem item)
        {
            try
            {
                LostItem itemCheck = db.LostItems.SingleOrDefault(x => x.Id.Equals(item.Id));
                // check if username exists
                if (itemCheck == null)
                {
                    return(BadRequest());
                }

                // set creation date
                item.ModifiedAt = DateTime.UtcNow;

                db.Update(item);
                db.SaveChanges();

                return(Ok(new
                {
                    message = "item modified successefully",
                    item
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
コード例 #7
0
ファイル: LostController.cs プロジェクト: s4sixty/iFind
        public async Task <IActionResult> GetAsync(int id)
        {
            var item = db.LostItems
                       .Include(c => c.Comments)
                       .Where(c => c.Id == id);

            if (item == null)
            {
                return(NotFound());
            }

            LostItem owner = await db.LostItems.FindAsync(id);

            int    UserId = owner.UserId;
            string token  = GenerateJSONWebToken(UserId);

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            var response = await client.GetAsync("https://ifind-auth.herokuapp.com/api/v1/users/");

            var stringJson = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <object>(stringJson);

            return(Ok(new { item, owner = result }));
        }
コード例 #8
0
    private IEnumerator AskForMissingItem()
    {
        var items       = LostItem.Instances;
        var wantedItems = CustomerManager.Instance.wantedItems;

        while (items.Count - wantedItems.Count == 0)
        {
            yield return(null);
        }

        int      max  = items.Count;
        LostItem item = null;

        do
        {
            // Pick random available spot.
            var random      = GameManager.Instance.Random;
            int randomIndex = random.Next(0, max);
            item = items[randomIndex];
        } while (wantedItems.Contains(item));

        wantedItems.Add(item);
        _wantedItem = item;

        // ReSharper disable once LocalVariableHidesMember
        var renderer = item.GetComponent <SpriteRenderer>();

        _wantedItemRenderer.sprite = renderer.sprite;
        _wantedItemRenderer.color  = Color.black;
        _wantedItemRenderer.gameObject.SetActive(true);
    }
コード例 #9
0
        public async Task <IActionResult> PutLostItem(string id, LostItem lostItem)
        {
            if (id != lostItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(lostItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LostItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #10
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("LostItem"))
     {
         carrying = collision.gameObject;
         LostItem itemCarried = carrying.GetComponent <LostItem>();
         itemCarried.follow = carryPoint;
     }
 }
コード例 #11
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        LostItem item = collision.gameObject.GetComponent <LostItem>();

        if (!item)
        {
            return;
        }
        _animationLocked++;
    }
コード例 #12
0
ファイル: LostController.cs プロジェクト: s4sixty/iFind
        public IActionResult Delete(int id)
        {
            LostItem item = db.LostItems.Find(id);

            db.LostItems.Remove(item);
            db.SaveChanges();
            return(Ok(new
            {
                message = "item deleted succesefully.",
                item
            }));
        }
コード例 #13
0
    public void PoolItem(LostItem item)
    {
        var sprite = item.GetComponent <SpriteRenderer>().sprite;

        for (int i = 0; i < _usedItems.Count; i++)
        {
            if (_usedItems[i].GetComponent <SpriteRenderer>().sprite == sprite)
            {
                _itemPool.Add(_usedItems[i]);
                _usedItems.Remove(_usedItems[i]);
                break;
            }
        }
    }
コード例 #14
0
        public async Task <IActionResult> Create(LostItemViewModel model)
        {
            var user = await userManager.GetUserAsync(HttpContext.User);

            if (ModelState.IsValid)
            {
                Image image = null;
                if (model.Photo != null)
                {
                    if (!utility.IsSizeAllowed(model.Photo))
                    {
                        ModelState.AddModelError("Photo", "Your file is too large, maximum allowed size is: 5MB");
                        return(View(model));
                    }

                    if (!utility.IsImageExtensionAllowed(model.Photo))
                    {
                        ModelState.AddModelError("Photo", "Please only file of type:.jpg, .jpeg, .gif, .png, .bmp  are allowed");
                        return(View(model));
                    }
                    var photoPath = utility.SaveImageToFolder(model.Photo);
                    image = new Image {
                        ImagePath = photoPath
                    };
                }
                user.PhoneNumber = model.PhoneNumber;
                LostItem itemm = new LostItem
                {
                    LostItemUser   = user,
                    NameOfLostItem = model.NameOfLostItem,
                    //StateId = model.StateId,
                    Description       = model.Description,
                    Color             = model.Color,
                    DateMisplaced     = model.DateMisplaced,
                    ExactArea         = model.ExactArea,
                    WhereItemWasLost  = model.WhereItemWasLost,
                    LocalGovernmentId = model.LocalGovernmentId,
                    Image             = image,
                };

                repository.Create(itemm);
                repository.Save();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.StateList = await stateRepository.GetAllStates();

            return(View(model));
        }
コード例 #15
0
    // Start is called before the first frame update
    void Start()
    {
        interactBox = gameObject.GetComponent <BoxCollider2D>();
        phrase      = lostPhrasePool[Random.Range(0, lostPhrasePool.Length)];
        hideText();

        LostItem lost = myObject.GetComponent <LostItem>();

        lost.owner = gameObject;

        string objectName = myObject.GetComponent <LostItem>().myName;

        phrase    = phrase.Replace("1", objectName);
        text.text = phrase;
    }
コード例 #16
0
    // Update is called once per frame
    void Update()
    {
        xSpeed = Input.GetAxisRaw("Horizontal") * walkSpeed * Time.deltaTime;
        ySpeed = Input.GetAxisRaw("Vertical") * walkSpeed * Time.deltaTime;

        if (!Physics2D.OverlapCircle(transform.position + new Vector3(xSpeed, ySpeed, 0), .1f, solid))
        {
            transform.position += new Vector3(xSpeed, ySpeed, 0);
        }

        anim.SetFloat("Speed", Mathf.Abs(Input.GetAxisRaw("Horizontal")) + Mathf.Abs(Input.GetAxisRaw("Vertical")));

        if (carrying)
        {
            LostItem item       = carrying.GetComponent <LostItem>();
            Vector3  target     = item.owner.transform.position;
            Vector3  currentPos = transform.position;

            NPCController owner = item.owner.GetComponent <NPCController>();
            if (owner.hasTalked)
            {
                arrow.SetActive(true);
            }

            target.z = 0f;
            target.x = target.x - currentPos.x;
            target.y = target.y - currentPos.y;

            float angle = Mathf.Atan2(target.y, target.x) * Mathf.Rad2Deg;
            arrow.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
        }
        else
        {
            arrow.SetActive(false);
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            magnifier.active = !magnifier.active;
        }

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

        screenPoint.z = 25f;

        magnifier.transform.position = screenPoint;
    }
コード例 #17
0
        public async Task <IActionResult> PostAsync([FromBody] Comments comment, int id)
        {
            LostItem item = await db.LostItems.FindAsync(id);

            if (item == null)
            {
                return(NotFound());
            }
            comment.UserId = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
            // set creation date
            comment.CreatedAt = DateTime.UtcNow;
            comment.LostItem  = item;
            db.Comments.Add(comment);
            //item.Comments.Add(comment);
            db.SaveChanges();

            return(Ok(new { comment, item }));
        }
コード例 #18
0
        public async Task <ActionResult <LostItem> > PostLostItem(LostItem lostItem)
        {
            _context.LostItems.Add(lostItem);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (LostItemExists(lostItem.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetLostItem", new { id = lostItem.Id }, lostItem));
        }
コード例 #19
0
 public void Create(LostItem entity)
 {
     context.LostItems.Add(entity);
 }
コード例 #20
0
 public void Update(LostItem entity)
 {
     context.Update(entity);
 }
コード例 #21
0
 // Start is called before the first frame update
 void Start()
 {
     _item   = GetComponent <LostItem>();
     _camera = MainCamera.Instance.GetComponent <Camera>();
 }
コード例 #22
0
    private IEnumerator UpdateCustomer()
    {
        _waiting   = true;
        _foundItem = null;

        float min = _settings.minWaitDuration;
        float max = _settings.maxWaitDuration;

        var random = GameManager.Instance.Random;

        // Calculate maximum wait duration.
        float t         = (float)random.NextDouble();
        float duration  = Mathf.Lerp(min, max, t);
        float remaining = duration;

        // Calculate whether or not the character is trying to steal something.
        bool  stealing = _settings.stealChance > random.NextDouble();
        var   potentialStealTargets = LostItem.Instances;
        int   stealIndex            = random.Next(0, potentialStealTargets.Count);
        float stealInterval         = _settings.stealInterval;

        // Check if the stealing item is the same as the wanted item.
        if (potentialStealTargets.Count > 0)
        {
            _stealItem = stealing ? potentialStealTargets[stealIndex] : null;
        }
        else
        {
            _stealItem = null;
        }

        while (((remaining -= Time.deltaTime) > 0 || _stealItem) && !_foundItem)
        {
            // Update animation.
            if (_animationLocked == 0)
            {
                _renderer.sprite = _waitingSprite;
            }

            float lerp = 1f - remaining / duration;
            float eval = _settings.angryColorCurve.Evaluate(lerp);

            // Update stealing.
            if (remaining < 0)
            {
                stealInterval -= Time.deltaTime;
                if (stealInterval <= 0)
                {
                    if (_stealItem)
                    {
                        if (_stealItem.IsSelected)
                        {
                            stealInterval = _settings.stealInterval;
                        }
                        else
                        {
                            _stealItem.LerpFactor  = _settings.stealLerp;
                            _stealItem.NewPosition = transform.position;
                        }
                    }
                    else
                    {
                        _stealItem = null;
                    }
                }
            }

            // Calculate bounce.
            var   bounceMaxOffset = new Vector3(0, -_settings.bounceMultiplier, 0);
            float bounceEval      = _settings.bounceCurve.Evaluate((duration - remaining) % _settings.bounceDuration);
            var   bounceOffset    = Vector3.LerpUnclamped(Vector3.zero, bounceMaxOffset, bounceEval);

            transform.position = _spot.transform.position + bounceOffset;

            // Update color based on how long the customer is waiting.
            // The customer gets redder (angry) the longer it waits.
            var color = Color.LerpUnclamped(Color.white, _settings.angryColor, eval);
            _renderer.color = color;
            yield return(null);
        }

        _waiting = false;
    }
コード例 #23
0
 public void Delete(LostItem entity)
 {
     context.Remove(entity);
 }
コード例 #24
0
        public async Task <IActionResult> Edit(int id, LostItem model, IFormFile file = null)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            var lostItem = await repository.GetLostItemById(id);

            Image image = null;

            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    if (!utility.IsSizeAllowed(file))
                    {
                        ModelState.AddModelError("Photo", "Your file is too large, maximum allowed size is: 5MB");
                        return(View(file));
                    }

                    if (!utility.IsImageExtensionAllowed(file))
                    {
                        ModelState.AddModelError("Photo", "Please only file of type:.jpg, .jpeg, .gif, .png, .bmp  are allowed");
                        return(View(file));
                    }
                    var photoPath = utility.SaveImageToFolder(file);
                    image = new Image {
                        ImagePath = photoPath
                    };
                    lostItem.Image = image;
                }
                try
                {
                    lostItem.NameOfLostItem    = model.NameOfLostItem;
                    lostItem.Description       = model.Description;
                    lostItem.ItemCategory      = model.ItemCategory;
                    lostItem.ExactArea         = model.ExactArea;
                    lostItem.WhereItemWasLost  = model.WhereItemWasLost;
                    lostItem.Color             = model.Color;
                    lostItem.DateMisplaced     = model.DateMisplaced;
                    lostItem.LocalGovernmentId = model.LocalGovernmentId;
                    lostItem.ModifiedOn        = DateTime.UtcNow;
                    repository.Update(lostItem);
                    repository.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LostItemExists(lostItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }