Exemple #1
0
        public bool Remove(GameSession session, long uid, short slot, int amount, out Item outItem)
        {
            outItem = null;
            if (session.Player.Inventory.Items.ContainsKey(slot))
            {
                return(false);
            }

            int outItemIndex = Array.FindIndex(Items, 0, Items.Length, x => x != null && x.Uid == uid);

            outItem = Items[outItemIndex];
            if (amount >= outItem.Amount)
            {
                Items[outItemIndex] = null;
                session.Send(StorageInventory.Remove(uid));
                return(true);
            }

            if (outItem.TrySplit(amount, out Item splitItem))
            {
                outItem.Amount -= amount;
                session.Send(StorageInventory.Add(outItem, slot));
                outItem = splitItem;
                return(true);
            }
            return(false);
        }
Exemple #2
0
        private void UpdateWallet()
        {
            switch (Type)
            {
            case CurrencyType.Meso:
                Player.Session.Send(MesosPacket.UpdateMesos(Player.Session));
                break;

            case CurrencyType.Meret:
            case CurrencyType.GameMeret:
            case CurrencyType.EventMeret:
                Player.Session.Send(MeretsPacket.UpdateMerets(Player.Session));
                break;

            case CurrencyType.ValorToken:
            case CurrencyType.Treva:
            case CurrencyType.Rue:
            case CurrencyType.HaviFruit:
                Player.Session.Send(WalletPacket.UpdateWallet(Type, Amount));
                break;

            case CurrencyType.Bank:
                Player.Session.Send(StorageInventory.UpdateMesos(Amount));
                break;

            default:
                break;
            }
        }
 void Start()
 {
     if (storageInventory == null)
     {
         storageInventory = GetComponent <StorageInventory>();
     }
 }
        public void Convert(int sourceItemId, int targetItemId)
        {
            StorageInventory destinationStorage = characterSwitch.GetCurrentCharacter().GetComponentInChildren <StorageInventory>();

            destinationStorage.RemoveItemFromStorage(sourceItemId, 1);
            destinationStorage.AddItemToStorage(targetItemId, 1);
        }
 void Init()
 {
     if (sourceStorage == null || destinationStorage == null)
     {
         sourceStorage      = SceneGraphSearch.Find(sourceStoragePath).GetComponentInChildren <StorageInventory>();
         destinationStorage = SceneGraphSearch.Find(destinationStoragePath).GetComponentInChildren <StorageInventory>();
     }
 }
Exemple #6
0
 public void LoadBank(GameSession session)
 {
     session.Send(StorageInventory.Update());
     session.Send(StorageInventory.Expand(ExtraSize));
     session.Send(StorageInventory.ExpandAnim());
     session.Send(StorageInventory.UpdateMesos(session.Player.Wallet.Bank.Amount));
     LoadItems(session);
 }
Exemple #7
0
 public override void Start()
 {
     camera           = GameObject.Find("Main Camera").transform;
     playerGameObject = GameObject.Find("Player");
     world            = GameObject.Find("World").GetComponent <World>();
     Cursor.lockState = CursorLockMode.Locked;
     playerInventory  = new StorageInventory(100);
 }
Exemple #8
0
        public void Sort(GameSession session)
        {
            List <Item> tempItems = Items.Where(x => x != null).ToList();

            tempItems.Sort((x, y) => x.Id.CompareTo(y.Id));
            Items = new Item[DEFAULT_SIZE + ExtraSize];
            for (int i = 0; i < tempItems.Count; i++)
            {
                Items[i] = tempItems[i];
            }
            session.Send(StorageInventory.Sort(Items));
        }
Exemple #9
0
 void GetStorageInventory()
 {
     try
     {
         storageInventory = playerInventory.GetComponent <PlayerInteract>().focus.GetComponent <StorageInventory>();
         storageInventory.onItemChangedCallback += UpdateStorageUI;
     }
     catch
     {
         return;
     }
 }
        private void OnEnable()
        {
            inventory = (StorageInventory)target;
            if (target == null)
            {
                DestroyImmediate(this);
                return;
            }

            slotsInformationProperty = serializedObject.FindProperty(slotsInformationName);

            CheckAndCreateSubEditor(inventory.slotsInformation);
        }
        private void UpdateItemSlots(StorageInventory inventory, InventorySlotsInformation slotsInfo)
        {
            var itemSlotsFromUI = inventory.GetComponentsInChildren <ItemSlot>();

            if (itemSlotsFromUI == null)
            {
                return;
            }

            for (int i = 0; i < itemSlotsFromUI.Length; i++)
            {
                itemSlotsFromUI[i].SetBackground(slotsInfo.BackgroundImage);
            }
        }
        private void AddOrRemoveItemSlots(StorageInventory inventory, InventorySlotsInformation slotsInfo)
        {
            inventory.itemSlots = new ItemSlot[slotsInfo.NumberOfSlots];
            var bgImage = slotsInfo.BackgroundImage;

            var numberOfSlotsOnUI = 0;
            var itemSlotsFromUI   = inventory.GetComponentsInChildren <ItemSlot>();

            if (itemSlotsFromUI != null)
            {
                numberOfSlotsOnUI = itemSlotsFromUI.Length;
            }

            int i = 0;

            for (i = 0; i < inventory.itemSlots.Length && i < numberOfSlotsOnUI; i++)
            {
                inventory.itemSlots[i] = itemSlotsFromUI[i];
            }

            if (inventory.itemSlots.Length == numberOfSlotsOnUI)
            {
                return;
            }

            if (inventory.itemSlots.Length > numberOfSlotsOnUI)
            {
                // add new slots on UI
                for (; i < inventory.itemSlots.Length; i++)
                {
                    var gameObject = new GameObject();
                    gameObject.name = "ItemSlot " + i;
                    gameObject.AddComponent <RectTransform>();
                    gameObject.transform.parent = inventory.transform;

                    var itemSlot = gameObject.AddComponent <ItemSlot>();
                    itemSlot.SetBackground(bgImage);

                    inventory.itemSlots[i] = itemSlot;
                }

                return;
            }

            // extra slots are present on UI. Delete them
            for (; i < numberOfSlotsOnUI; i++)
            {
                DestroyImmediate(itemSlotsFromUI[i].gameObject);
            }
        }
Exemple #13
0
        public void Expand(GameSession session)
        {
            long meretPrice      = 330;
            int  expansionAmount = 6;

            if (!session.Player.Wallet.RemoveMerets(meretPrice))
            {
                return;
            }
            ExtraSize += expansionAmount;
            session.Send(StorageInventory.Expand(ExtraSize));
            session.Send(StorageInventory.ExpandAnim());
            UpdateInventorySize();
        }
    // Use this for initialization
    void Start()
    {
        inventoryItemList = (ItemDataBaseList)Resources.Load("ItemDatabase");

        while (counter < amountOfChest)
        {
            counter++;

            creatingItemsForChest = 0;

            int itemAmountForChest = Random.Range(minItemInChest, maxItemInChest);
            List <Item_On_Object> itemsForChest = new List <Item_On_Object>();

            while (creatingItemsForChest < itemAmountForChest)
            {
                randomItemNumber = Random.Range(1, inventoryItemList.itemList.Count - 1);
                int raffle = Random.Range(1, 100);

                if (raffle <= inventoryItemList.itemList[randomItemNumber].rarity)
                {
                    itemsForChest.Add(inventoryItemList.itemList[randomItemNumber].getCopy());
                    creatingItemsForChest++;
                }
            }


            Terrain terrain = Terrain.activeTerrain;

            float x = Random.Range(5, terrain.terrainData.size.x - 5);
            float z = Random.Range(5, terrain.terrainData.size.z - 5);

            float height = terrain.terrainData.GetHeight((int)x, (int)z);

            GameObject       chest = (GameObject)Instantiate(storageBox);
            StorageInventory sI    = chest.GetComponent <StorageInventory>();
            sI.inventory = GameObject.FindGameObjectWithTag("Storage");

            for (int i = 0; i < itemsForChest.Count; i++)
            {
                sI.storageItems.Add(inventoryItemList.getItemByID(itemsForChest[i].itemID));

                int randomValue = Random.Range(1, sI.storageItems[sI.storageItems.Count - 1].maxStack);
                sI.storageItems[sI.storageItems.Count - 1].itemValue = randomValue;
            }

            chest.transform.localPosition = new Vector3(x, height + 2, z);
        }
    }
Exemple #15
0
        public void Add(GameSession session, long uid, int amount, short slot)
        {
            Item item = session.Player.Inventory.Items[uid];

            if (amount < item.Amount)
            {
                item.TrySplit(amount, out Item splitItem);
                session.Send(ItemInventoryPacket.Update(uid, item.Amount));
                item = splitItem;
            }
            else
            {
                InventoryController.Remove(session, uid, out Item removedItem);
                item = removedItem;
            }

            if (slot >= 0)
            {
                if (Items[slot] == null)
                {
                    Items[slot] = item;
                    session.Send(StorageInventory.Add(item, slot));
                    return;
                }
                else
                {
                    slot = -1;
                }
            }

            if (slot == -1)
            {
                for (slot = 0; slot < Items.Length; slot++)
                {
                    if (Items[slot] != null)
                    {
                        continue;
                    }
                    Items[slot] = item;
                    session.Send(StorageInventory.Add(item, slot));
                    return;
                }
            }
        }
Exemple #16
0
        public void Move(GameSession session, long dstUid, short dstSlot)
        {
            Item  dstItem = Items[dstSlot];
            long  srcUid  = 0;
            short srcSlot = 0;

            if (dstItem != null)
            {
                srcUid  = dstItem.Uid;
                srcSlot = (short)Array.FindIndex(Items, 0, Items.Length, x => x != null && x.Uid == dstUid);
                Item temp = Items[srcSlot];
                Items[srcSlot] = dstItem;
                Items[dstSlot] = temp;
            }
            else
            {
                short oldSlot = (short)Array.FindIndex(Items, 0, Items.Length, x => x != null && x.Uid == dstUid);
                Items[dstSlot] = Items.FirstOrDefault(x => x != null && x.Uid == dstUid);
                Items[oldSlot] = null;
            }
            session.Send(StorageInventory.Move(srcUid, srcSlot, dstUid, dstSlot));
        }
Exemple #17
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            _QuitOnConnectionErrors();

            // Check that motion tracking is tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                Screen.sleepTimeout = lostTrackingSleepTimeout;
                if (!m_IsQuitting && Session.Status.IsValid())
                {
                    SearchingForPlaneUI.SetActive(true);
                }

                return;
            }

            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
            Session.GetTrackables <TrackedPlane>(m_NewPlanes, TrackableQueryFilter.New);
            for (int i = 0; i < m_NewPlanes.Count; i++)
            {
                // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
                // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
                // coordinates.
                GameObject planeObject = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                     transform);
                planeObject.GetComponent <TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
            }

            // Disable the snackbar UI when no planes are valid.
            Session.GetTrackables <TrackedPlane>(m_AllPlanes);
            bool showSearchingUI = true;
            bool showPlaceFarmUI = false;
            bool showTileUI      = false;
            bool showEscapeUI    = false;
            bool showCurrencyUI  = false;

            if (selectedTile != null)
            {
                showEscapeUI   = true;
                showTileUI     = true;
                showCurrencyUI = true;
            }
            for (int i = 0; i < m_AllPlanes.Count; i++)
            {
                if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                {
                    showSearchingUI = false;
                    showPlaceFarmUI = true;
                    break;
                }
            }
            if (farmCreated)
            {
                showPlaceFarmUI = false;
            }

            PlaceFarmUI.SetActive(showPlaceFarmUI);
            SearchingForPlaneUI.SetActive(showSearchingUI);
            TileUI.SetActive(showTileUI);
            EscapeUI.SetActive(showEscapeUI);
            CurrencyUI.SetActive(showCurrencyUI);



            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            // Raycast against the location the player touched to search for planes.
            TrackableHit      hit;
            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                              TrackableHitFlags.FeaturePointWithSurfaceNormal;

            if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && !farmCreated)
            {
                farmObject = Instantiate(FarmPrefab, hit.Pose.position, hit.Pose.rotation);

                // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                // world evolves.
                var anchor = hit.Trackable.CreateAnchor(hit.Pose);


                // Make Farm model a child of the anchor.
                farmObject.transform.parent = anchor.transform;

                farmCreated = true;
            }



            //Create ray and raycasthit for tile selection
            Ray        ray     = Camera.current.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit tileHit = new RaycastHit();

            //Selects tile and changes material, currently uses color.yellow as temporary highlighter.
            if (farmCreated && Physics.Raycast(ray, out tileHit))
            {
                if (selectedTile != tileHit.collider.gameObject && selectedTile != null)
                {
                    mSelected.color = mOriginal.color;
                }
                selectedTile = tileHit.collider.gameObject;
                mSelected    = selectedTile.GetComponent <Renderer>().material;
                if (mSelected.color != Color.yellow)
                {
                    //_ShowAndroidToastMessage("Original Material Saved");
                    mOriginal = new Material(mSelected);
                }

                mSelected.color = Color.yellow;
            }

            try
            {
                CheckWaterLevel();
                _ShowAndroidToastMessage("Check Water OK!");
            }
            catch (Exception e)
            {
                //_ShowAndroidToastMessage("Water code crashed");
            }
            try
            {
                CheckPlantStage();
                _ShowAndroidToastMessage("Check Plant OK!");
            }
            catch (Exception e)
            {
                //_ShowAndroidToastMessage("Check plant crashed");
            }

            if (TileUI.activeSelf)
            {
                Button[] buttonList    = TileUI.GetComponentsInChildren <Button>();
                Button   harvestButton = buttonList[0];
                Button   waterButton   = buttonList[1];
                Button   plantButton   = buttonList[2];

                StorageInventory storage = plantButton.GetComponent <StorageInventory>();



                plantButton.onClick.AddListener(() =>
                {
                    //                    Plant(selectedTile, -1);
                    storage.OpenInventory();
                });
                waterButton.onClick.AddListener(() =>
                {
                    TileState oldState = selectedTile.GetComponent <TileState>();
                    TileState copy     = null;
                    GetCopyOf(oldState, copy, oldState.GetType());
                    DestroyImmediate(oldState);
                    TileState newState = selectedTile.AddComponent <TileState>();
                    GetCopyOf(copy, newState, copy.GetType());
                    newState.Water();
                });
                harvestButton.onClick.AddListener(() => { Harvest(selectedTile); });


                if (InventoryUI.activeSelf)
                {
                    Button[] seedButtons = InventoryUI.GetComponentsInChildren <Button>();
                    int      i           = 0;


                    seedButtons[0].onClick.AddListener(() =>
                    {
                        try
                        {
                            _ShowAndroidToastMessage("Selected item at " + 0);
                            Plant(selectedTile, 0);
                            storage.OpenInventory();
                        }
                        catch (Exception e)
                        {
                            _ShowAndroidToastMessage("Inventory Button listener crashed");
                        }
                    });

                    seedButtons[1].onClick.AddListener(() =>
                    {
                        try
                        {
                            _ShowAndroidToastMessage("Selected item at " + 1);
                            Plant(selectedTile, 1);
                            storage.OpenInventory();
                        }
                        catch (Exception e)
                        {
                            _ShowAndroidToastMessage("Inventory Button listener crashed");
                        }
                    });

                    seedButtons[2].onClick.AddListener(() =>
                    {
                        try
                        {
                            _ShowAndroidToastMessage("Selected item at " + 2);
                            Plant(selectedTile, 2);
                            storage.OpenInventory();
                        }
                        catch (Exception e)
                        {
                            _ShowAndroidToastMessage("Inventory Button listener crashed");
                        }
                    });

                    seedButtons[3].onClick.AddListener(() =>
                    {
                        try
                        {
                            _ShowAndroidToastMessage("Selected item at " + 3);
                            Plant(selectedTile, 3);
                            storage.OpenInventory();
                        }
                        catch (Exception e)
                        {
                            _ShowAndroidToastMessage("Inventory Button listener crashed");
                        }
                    });
                }
            }



            if (EscapeUI.activeSelf)
            {
                Button[] buttonList   = EscapeUI.GetComponentsInChildren <Button>();
                Button   escapeButton = buttonList[0];

                escapeButton.onClick.AddListener(() =>
                {
                    mSelected.color = mOriginal.color;
                    selectedTile    = null;
                });
            }



            //    //Scale Farm by pinching
            //    if (Input.touchCount == 2 && farmCreated)
            //    {
            //        if (Input.touchCount >= 2 && (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved))
            //        {
            //            Vector2 touch1 = Input.GetTouch(0).position;
            //            Vector2 touch2 = Input.GetTouch(1).position;

            //            newDistance = (touch1 - touch2).sqrMagnitude;
            //            float changeInDistance = newDistance - initialDistance;
            //            float percentageChange = changeInDistance / initialDistance;


            //            Vector3 newScale = farmObject.transform.localScale;
            //            newScale += percentageChange * newScale;

            //            farmObject.transform.localScale = newScale;

            //        }

            //    }
        }
 void Start()
 {
     storageInventory = GetComponent <StorageInventory>();
 }
 private static void HandleSort(GameSession session)
 {
     session.Send(StorageInventory.Update());
     session.Player.BankInventory.Sort(session);
 }
Exemple #20
0
 public void LoadItems(GameSession session)
 {
     Items = new Item[DEFAULT_SIZE + ExtraSize];
     session.Send(StorageInventory.LoadItems(Items));
 }
Exemple #21
0
 private void Start()
 {
     inventory = GetComponent <StorageInventory>();
 }
Exemple #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="map"></param>
 /// <param name="cellId"></param>
 public TrashCan(MapInstance map, int cellId)
     : base(map, cellId)
 {
     m_storage = new StorageInventory();
 }
        public bool CanTransfer(StorageInventory storage, int itemId, int itemAmount)
        {
            Item item = storage.FindItemById(itemId);

            return(item != null && item.itemValue >= itemAmount);
        }
        public void Create(int itemId, int itemAmount)
        {
            StorageInventory destinationStorage = characterSwitch.GetCurrentCharacter().GetComponentInChildren <StorageInventory>();

            destinationStorage.AddItemToStorage(itemId, itemAmount);
        }
Exemple #25
0
 public void LoadItems(GameSession session)
 {
     session.Send(StorageInventory.LoadItems(Items));
 }
 // Update is called once per frame
 void OnEnable()
 {
     inv = target as StorageInventory;
 }
Exemple #27
0
        private StorageInventory _inventory;    // Reference to the Inventory component.

        protected override void SpecificInit()
        {
            _inventory = FindObjectOfType <StorageInventory>();
        }
 // Update is called once per frame
 void OnEnable()
 {
     inv = target as StorageInventory;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="character"></param>
 /// <param name="storage"></param>
 public GameStorageExchangeAction(CharacterEntity character, StorageInventory storage, ExchangeTypeEnum type = ExchangeTypeEnum.EXCHANGE_STORAGE)
     : base(new StorageExchange(character, storage, type), character, null)
 {
 }
Exemple #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="character"></param>
 /// <param name="storage"></param>
 /// <param name="type"></param>
 public StorageExchange(CharacterEntity character, StorageInventory storage, ExchangeTypeEnum type = ExchangeTypeEnum.EXCHANGE_STORAGE)
     : base(type)
 {
     Character = character;
     Storage   = storage;
 }