public BuildOrder ToBuildOrder()
        {
            var numMaterials = this.BuildableItem.FixedBuildMaterials.Count;

            var filters = new IItemFilter[numMaterials];

            for (int idx = 0; idx < numMaterials; ++idx)
            {
                var itemIDs     = this.BuildMaterialsView[idx].ItemIDs.Where(i => i.IsSelected).Select(i => i.Value).ToArray();
                var materialIDs = this.BuildMaterialsView[idx].MaterialIDs.Where(i => i.IsSelected).Select(i => i.Value).ToArray();

                ItemIDMask im = null;
                if (itemIDs.Any())
                {
                    im = new ItemIDMask(itemIDs);
                }

                MaterialIDMask mim = null;
                if (materialIDs.Any())
                {
                    mim = new MaterialIDMask(materialIDs);
                }

                filters[idx] = new ItemFilter(im, null, mim, null);
            }

            var bo = new BuildOrder(this.BuildableItem, filters);

            return(bo);
        }
Пример #2
0
        public DesignStockpileSample()
        {
            var c = new StockpileCriteriaEditable();

            /*
             * c.ItemIDs.Add(ItemID.Log);
             * c.ItemIDs.Add(ItemID.Door);
             * c.MaterialCategories.Add(MaterialCategory.Wood);
             */
            this.Criteria = c.ToItemFilter();
        }
Пример #3
0
        public void AddConstructJob(ConstructMode mode, IntGrid2Z area, IItemFilter userItemFilter)
        {
            var locations = area.Range().Where(p => m_environment.Contains(p));

            ITerrainFilter filter;
            IItemFilter    coreItemFilter;

            switch (mode)
            {
            case ConstructMode.Floor:
                filter         = WorkHelpers.ConstructFloorTerrainFilter;
                coreItemFilter = WorkHelpers.ConstructFloorItemFilter;
                break;

            case ConstructMode.Pavement:
                filter         = WorkHelpers.ConstructPavementTerrainFilter;
                coreItemFilter = WorkHelpers.ConstructPavementItemFilter;
                break;

            case ConstructMode.Wall:
                filter         = WorkHelpers.ConstructWallTerrainFilter;
                coreItemFilter = WorkHelpers.ConstructWallItemFilter;
                break;

            default:
                throw new Exception();
            }

            IItemFilter itemFilter;

            if (userItemFilter != null)
            {
                itemFilter = new AndItemFilter(coreItemFilter, userItemFilter);
            }
            else
            {
                itemFilter = coreItemFilter;
            }

            locations = locations.Where(p => filter.Match(m_environment.GetTileData(p)));

            foreach (var l in locations)
            {
                var data = new ConstructJobData()
                {
                    Mode       = mode,
                    Location   = l,
                    ItemFilter = itemFilter,
                };

                m_jobDataList.Add(data);
            }
        }
Пример #4
0
        public void AddConstructJob(ConstructMode mode, IntGrid2Z area, IItemFilter userItemFilter)
        {
            var locations = area.Range().Where(p => m_environment.Contains(p));

            ITerrainFilter filter;
            IItemFilter coreItemFilter;

            switch (mode)
            {
                case ConstructMode.Floor:
                    filter = WorkHelpers.ConstructFloorTerrainFilter;
                    coreItemFilter = WorkHelpers.ConstructFloorItemFilter;
                    break;

                case ConstructMode.Pavement:
                    filter = WorkHelpers.ConstructPavementTerrainFilter;
                    coreItemFilter = WorkHelpers.ConstructPavementItemFilter;
                    break;

                case ConstructMode.Wall:
                    filter = WorkHelpers.ConstructWallTerrainFilter;
                    coreItemFilter = WorkHelpers.ConstructWallItemFilter;
                    break;

                default:
                    throw new Exception();
            }

            IItemFilter itemFilter;

            if (userItemFilter != null)
                itemFilter = new AndItemFilter(coreItemFilter, userItemFilter);
            else
                itemFilter = coreItemFilter;

            locations = locations.Where(p => filter.Match(m_environment.GetTileData(p)));

            foreach (var l in locations)
            {
                var data = new ConstructJobData()
                {
                    Mode = mode,
                    Location = l,
                    ItemFilter = itemFilter,
                };

                m_jobDataList.Add(data);
            }
        }
Пример #5
0
        public ItemObject GetReachableItemByDistance(IntPoint3 location, IItemFilter filter,
			Unreachables unreachables)
        {
            var items = m_items
                .Where(i => i.IsReserved == false && i.IsInstalled == false && unreachables.IsUnreachable(i.Location) == false)
                .Where(i => filter.Match(i))
                .OrderBy(i => (i.Location - location).ManhattanLength);

            foreach (var item in items)
            {
                var found = AStar.AStarFinder.CanReach(m_env, location, item.Location, DirectionSet.Exact);

                if (found)
                    return item;

                unreachables.Add(item.Location);
            }

            return null;
        }
Пример #6
0
        public ItemObject GetReachableItemByDistance(IntVector3 location, IItemFilter filter,
                                                     Unreachables unreachables)
        {
            var items = m_items
                        .Where(i => i.IsReserved == false && i.IsInstalled == false && unreachables.IsUnreachable(i.Location) == false)
                        .Where(i => filter.Match(i))
                        .OrderBy(i => (i.Location - location).ManhattanLength);

            foreach (var item in items)
            {
                var found = AStar.CanReach(m_env, location, item.Location, DirectionSet.Exact);

                if (found)
                {
                    return(item);
                }

                unreachables.Add(item.Location);
            }

            return(null);
        }
        public ItemListFilterViewModel(
            IItemFilter itemWhitelist,
            IItemFilter itemBlacklist,
            IItemService itemService)
        {
            itemWhitelist.FilterMode = FilterMode.Whitelist;
            ItemWhitelist            = itemWhitelist;
            itemBlacklist.FilterMode = FilterMode.Blacklist;
            ItemBlacklist            = itemBlacklist;

            this.FilterChanges = Observable.CombineLatest(
                itemWhitelist.FilterChanges,
                itemBlacklist.FilterChanges
                )
                                 .Select(filters => new Func <ItemEx, bool>((ItemEx item) => filters.All(filter => filter(item))));

            var tagPool = itemService.GetTags(FilterChanges).AsObservableList();

            itemWhitelist.SetTagpool(tagPool);
            itemBlacklist.SetTagpool(tagPool);

            this.Tagpool = tagPool;
        }
Пример #8
0
 public LibraryViewModel()
 {
     phraseFilter = new ItemFilter <Phrase>(DisplayAny);
 }
 public void Filter(IItemFilter <TItem> filter)
 {
     filter.Filter(availableItems, DisplayableItems);
 }
Пример #10
0
        private void OnTick()
        {
            //if (Explorer != null)
            //{
            //    Explorer.Tick();
            //}

            var update = false;

            if (!_itemThrottle.IsRunning)
            {
                _itemThrottle.Start();
                update = true;
            }
            else
            {
                if (_itemThrottle.ElapsedMilliseconds >= ItemThrottleMs)
                {
                    update = true;
                }
            }

            //using (new PerformanceTimer("Tick::WorldItem", 1))
            {
                if (update)
                {
                    var myPos = LokiPoe.MyPosition;

                    var added = 0;
                    foreach (var worldItem in LokiPoe.ObjectManager.GetObjectsByType <WorldItem>())
                    {
                        var doAdd = false;

                        Vector2i pos;
                        if (!_ignoreItems.TryGetValue(worldItem.Id, out pos))
                        {
                            doAdd = true;
                        }
                        else
                        {
                            if (pos != worldItem.Position)
                            {
                                Log.InfoFormat("[AreaStateCache] An item collision has been detected! Item id {0}.", worldItem.Id);
                                _ignoreItems.Remove(worldItem.Id);
                                doAdd = true;
                            }
                        }

                        if (doAdd)
                        {
                            if (added > 10)
                            {
                                break;
                            }

                            ++added;

                            var item = worldItem.Item;

                            if (worldItem.IsAllocatedToOther)
                            {
                                if (DateTime.Now < worldItem.PublicTime)
                                {
                                    //Log.InfoFormat("[AreaStateCache] The item {0} is not being marked for pickup because it is allocated to another player.", item.FullName);
                                    //_ignoreItems.Add(worldItem.Id, worldItem.Position);
                                    continue;
                                }
                            }

                            var visibleOverride = false;
                            if (LootVisibleItemsOverride)
                            {
                                // We can only consider items when they are visible, otherwise we ignore stuff we might want.
                                if (!LokiPoe.ConfigManager.IsAlwaysHighlightEnabled)
                                {
                                    continue;
                                }

                                if (LokiPoe.Input.GetClickableHighlightLabelPosition(worldItem) != Vector2.Zero)
                                {
                                    visibleOverride = true;
                                }
                            }

                            IItemFilter filter = null;
                            if (visibleOverride || ItemEvaluator.Match(item, EvaluationType.PickUp, out filter))
                            {
                                var location = new ItemLocation
                                {
                                    Id       = worldItem.Id,
                                    Name     = worldItem.Name,
                                    Position = worldItem.Position,
                                    Rarity   = worldItem.Item.Rarity,
                                    Metadata = worldItem.Item.Metadata
                                };

                                if (_itemLocations.ContainsKey(location.Id))
                                {
                                    _itemLocations[location.Id] = location;
                                }
                                else
                                {
                                    _itemLocations.Add(location.Id, location);
                                }

                                Log.InfoFormat("[AreaStateCache] The location {0} [{1}] is being added from filter [{3}].{2}", location.Id,
                                               location.Name,
                                               worldItem.HasAllocation ? " [Allocation " + worldItem.PublicTime + "]" : "",
                                               filter != null ? filter.Name : "(null)");
                            }

                            _ignoreItems.Add(worldItem.Id, worldItem.Position);
                        }
                    }

                    var toRemove = new List <int>();
                    foreach (var kvp in _itemLocations)
                    {
                        if (Blacklist.Contains(kvp.Key))
                        {
                            Log.InfoFormat("[AreaStateCache] The location {0} [{1}] is being removed because the id has been Blacklisted.",
                                           kvp.Value.Id, kvp.Value.Name);
                            toRemove.Add(kvp.Value.Id);
                        }
                        else if (myPos.Distance(kvp.Value.Position) < 30)
                        {
                            if (LokiPoe.ObjectManager.GetObjectById <WorldItem>(kvp.Value.Id) == null)
                            {
                                Log.InfoFormat("[AreaStateCache] The location {0} [{1}] is being removed because the WorldItem does not exist.",
                                               kvp.Value.Id, kvp.Value.Name);
                                toRemove.Add(kvp.Value.Id);
                            }
                        }
                    }

                    foreach (var id in toRemove)
                    {
                        _itemLocations.Remove(id);
                    }

                    _itemThrottle.Restart();
                }
            }

            if (!_chestThrottle.IsRunning)
            {
                _chestThrottle.Start();
            }
            else
            {
                if (_chestThrottle.ElapsedMilliseconds >= ChestThrottleMs)
                {
                    //using (new PerformanceTimer("Tick::Chest", 1))
                    {
                        var addedChests = new List <ChestLocation>();
                        foreach (var chest in LokiPoe.ObjectManager.GetObjectsByType <Chest>().ToList())
                        {
                            ChestLocation location;
                            if (!_chestLocations.TryGetValue(chest.Id, out location))
                            {
                                location = new ChestLocation
                                {
                                    Id            = chest.Id,
                                    Name          = chest.Name,
                                    IsTargetable  = chest.IsTargetable,
                                    IsOpened      = chest.IsOpened,
                                    IsStrongBox   = chest.IsStrongBox,
                                    IsVaalVessel  = chest.IsVaalVessel,
                                    OpensOnDamage = chest.OpensOnDamage,
                                    Position      = chest.Position,
                                    Stats         = chest.Stats.ToList(),
                                    IsIdentified  = chest.IsIdentified,
                                    IsBreakable   = chest.OpensOnDamage,
                                    Rarity        = chest.Rarity,
                                    Metadata      = chest.Type
                                };

                                _chestLocations.Add(location.Id, location);

                                addedChests.Add(location);
                            }

                            if (!location.IsOpened)
                            {
                                location.IsOpened     = chest.IsOpened;
                                location.IsLocked     = chest.IsLocked;
                                location.IsTargetable = chest.IsTargetable;
                                // Support for chests that change locked state, without the lock state updating.
                                var tc = chest.Components.TransitionableComponent;
                                if (tc != null)
                                {
                                    if ((tc.Flag1 & 2) != 0)
                                    {
                                        location.IsLocked = false;
                                    }
                                }
                                if (chest.IsVaalVessel)
                                {
                                    location.IsLocked = false;
                                }
                                if (!location.IsCorrupted && chest.IsCorrupted)
                                {
                                    location.IsCorrupted = chest.IsCorrupted;
                                    location.Stats       = chest.Stats.ToList();
                                }
                                if (!location.IsIdentified && chest.IsIdentified)
                                {
                                    location.IsIdentified = chest.IsIdentified;
                                    location.Stats        = chest.Stats.ToList();
                                }
                            }

                            if (addedChests.Count > 10)
                            {
                                break;
                            }
                        }

                        foreach (var location in addedChests)
                        {
                            if (!location.IsBreakable)
                            {
                                location.Position = ExilePather.FastWalkablePositionFor(location.Position);
                            }

                            LokiPoe.InvokeEvent(OnChestLocationAdded, null, new OnChestLocationAddedEventArgs(location));
                        }

                        addedChests.Clear();

                        _chestThrottle.Restart();
                    }
                }
            }

            if (!_questThrottle.IsRunning)
            {
                _questThrottle.Start();
            }
            else
            {
                if (_questThrottle.ElapsedMilliseconds >= QuestThrottleMs)
                {
                    if (LokiPoe.CurrentWorldArea.IsMissionArea)
                    {
                        if (!HasKaruiSpiritLocation)
                        {
                            var obj = LokiPoe.ObjectManager.GetObjectByName("Karui Spirit");
                            if (obj != null)
                            {
                                AddLocation(ExilePather.FastWalkablePositionFor(obj), obj.Id, obj.Name);
                                HasKaruiSpiritLocation = true;
                            }
                        }
                    }

                    _questThrottle.Restart();
                }
            }

            if (!_throttle.IsRunning)
            {
                _throttle.Start();
            }
            else
            {
                if (_throttle.ElapsedMilliseconds >= ThrottleMs)
                {
                    if (!_timeInInstance.IsRunning)
                    {
                        _timeInInstance.Start();
                    }

                    if (!_timeInArea.IsRunning)
                    {
                        _timeInArea.Start();
                    }

                    // Do we need to update wp state flags.
                    if (_updateCheckForWaypoint)
                    {
                        // If the current area doesn't have a wp, we do not want to do any more logic processing.
                        if (!LokiPoe.CurrentWorldArea.HasWaypoint)
                        {
                            _updateCheckForWaypoint = false;
                            ShouldCheckForWaypoint  = false;
                            HasWaypointLocation     = false;
                            HasWaypointEntry        = false;
                        }
                        else
                        {
                            ShouldCheckForWaypoint = true;
                        }
                    }

                    // Do we need to update at state flags.
                    if (_updateAreaTransition)
                    {
                        ShouldCheckForAreaTransition = true;
                    }

                    if (ShouldCheckForStash)
                    {
                        //using (new PerformanceTimer("ShouldCheckForStash", 1))
                        {
                            if (!HasStashLocation)
                            {
                                var stash = LokiPoe.ObjectManager.Stash;
                                if (stash != null)
                                {
                                    // Save the location so we know where it is when the entity isn't in view.
                                    AddLocation(ExilePather.FastWalkablePositionFor(stash), stash.Id, "Stash");

                                    // We now have the waypoint location.
                                    HasStashLocation = true;
                                }
                            }
                            else
                            {
                                ShouldCheckForStash = false;
                            }
                        }
                    }

                    // If we need to handle wps.
                    if (ShouldCheckForWaypoint)
                    {
                        //using (new PerformanceTimer("ShouldCheckForWaypoint", 1))
                        {
                            // If we don't have the wp location yet, check to see if we see one.
                            if (!HasWaypointLocation)
                            {
                                var wp = LokiPoe.ObjectManager.Waypoint;
                                if (wp != null)
                                {
                                    // Save the location so we know where it is when the entity isn't in view.
                                    AddLocation(ExilePather.FastWalkablePositionFor(wp), wp.Id, "Waypoint");

                                    // We now have the waypoint location.
                                    HasWaypointLocation = true;
                                }
                            }

                            // If we don't have the wp entry yet, poll for us having it now.
                            // But only if we've seen the waypoint, since otherwise there's no way we have it.
                            if (HasWaypointLocation && !HasWaypointEntry)
                            {
                                var areaId = WorldArea.Id;
                                HasWaypointEntry = LokiPoe.InstanceInfo.AvailableWaypoints.ContainsKey(areaId);
                            }

                            // Once we have both the location and the entry, we do not need to execute wp logic anymore.
                            if (HasWaypointLocation && HasWaypointEntry)
                            {
                                _updateCheckForWaypoint = false;
                                ShouldCheckForWaypoint  = false;
                            }
                        }
                    }

                    // If we need to handle ats.
                    if (ShouldCheckForAreaTransition)
                    {
                        //using (new PerformanceTimer("ShouldCheckForAreaTransition", 1))
                        {
                            // If there are any area transitions on screen, add them if we don't already know of them.
                            foreach (var transition in LokiPoe.ObjectManager.Objects.OfType <AreaTransition>().ToList())
                            {
                                var name = transition.Name;

                                // We have to check all this in order to handle the areas that have transitions with the same name, but different
                                // entity ids.
                                if (HasLocation(name, transition.Id))
                                {
                                    continue;
                                }

                                AddLocation(ExilePather.FastWalkablePositionFor(transition), transition.Id, name);

                                if (!SeenAreaTransitions.Contains(name))
                                {
                                    SeenAreaTransitions.Add(name);
                                }
                            }
                        }
                    }

                    // Check to see if we need a new anchor point to kite back towards.
                    if (!_hasAnchorPoint || LokiPoe.LocalData.AreaHash != _anchorPointSeed)
                    {
                        ResetAnchorPoint();
                        ResetCurrentAnchorPoint();
                    }

                    _throttle.Restart();
                }
            }
        }
Пример #11
0
 public void RemoveFilter(IItemFilter <T> filter)
 {
     _filters.Remove(filter);
 }
Пример #12
0
 public void AddFilter(IItemFilter <T> filter)
 {
     _filters.Add(filter);
 }
Пример #13
0
        public BuildOrder(BuildableItem buildableItem, IItemFilter[] userFilters)
        {
            this.BuildableItem = buildableItem;
            this.UserItemFilters = userFilters;

            if (this.BuildableItem.MaterialID.HasValue)
                this.Name = String.Format("{0} {1}", this.BuildableItem.MaterialID, this.BuildableItem.ItemInfo.Name);
            else
                this.Name = this.BuildableItem.ItemInfo.Name;

            this.SourceItems = new ItemObject[this.BuildableItem.FixedBuildMaterials.Count];
        }
Пример #14
0
 public AndItemFilter(IItemFilter filter1, IItemFilter filter2, IItemFilter filter3)
 {
     m_filters = new IItemFilter[] { filter1, filter2, filter3 };
 }
Пример #15
0
 public OrItemFilter(IItemFilter filter1, IItemFilter filter2)
 {
     m_filters = new IItemFilter[] { filter1, filter2 };
 }
Пример #16
0
 public OrItemFilter(IItemFilter filter1, IItemFilter filter2)
 {
     m_filters = new IItemFilter[] { filter1, filter2 };
 }
Пример #17
0
 public AndItemFilter(IItemFilter filter1, IItemFilter filter2, IItemFilter filter3)
 {
     m_filters = new IItemFilter[] { filter1, filter2, filter3 };
 }
Пример #18
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            DebugInventory();
        }

        //Drop item
        if (Input.GetKeyDown(PlayerData.Instance.keybinds["Drop Item"]) && mouseInventory.inventoryReadOnly[0] != null)
        {
            ItemEntityPool.Instance.CreateItemEntity(Camera.main.ScreenToWorldPoint(Input.mousePosition), mouseInventory.inventoryReadOnly[0].item);
            mouseInventory.DecrementStack(0);
        }

        //Fire weapon
        if (Input.GetKey(PlayerData.Instance.keybinds["Fire Weapon"]))
        {
            fireWeapon = true;
        }

        if (Input.GetKeyDown(PlayerData.Instance.keybinds["Rotate Buildable"]))
        {
            placementRotation--;
            if (placementRotation < 0)
            {
                placementRotation = 7;
            }
        }


        if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            Vector3        mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2        mousePos2D = new Vector2(mousePos.x, mousePos.y);
            RaycastHit2D[] hits       = new RaycastHit2D[1];
            Physics2D.Raycast(mousePos2D, Vector2.zero, filterMining, hits);

            if (mouseInventory.inventoryReadOnly[0] != null)
            {
                ItemThrowable throwable = mouseInventory.inventoryReadOnly[0].item as ItemThrowable;
                if (throwable != null && Input.GetMouseButtonDown(0)) //thrown item code
                {
                    Vector3    place  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    ThrownItem thrown = Instantiate(throwable.thrownResult, this.transform.position, Quaternion.identity).GetComponent <ThrownItem>();
                    thrown.SetTarget(place);
                    mouseInventory.DecrementStack(0);
                }
                else if (mouseInventory.inventoryReadOnly[0].item.placeableResult != null) //place building code
                {
                    Vector2 size;
                    IRotate rotateable;
                    if (mouseInventory.inventoryReadOnly[0].item.placeableResult.TryGetComponent(out rotateable))
                    {
                        placeSpriteRenderer.sprite = rotateable.GetRotatedPlaceSprite(placementRotation);
                        size = rotateable.GetRotatedBoundingBox(placementRotation);
                    }
                    else
                    {
                        placeSpriteRenderer.sprite = mouseInventory.inventoryReadOnly[0].item.placeableResult.GetComponent <SpriteRenderer>().sprite;
                        size = mouseInventory.inventoryReadOnly[0].item.placeableResult.GetComponent <BoxCollider2D>().size;
                    }

                    Vector3 place        = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Vector3 placeRounded = new Vector3(Mathf.Round(place.x), Mathf.Round(place.y), 0);
                    Vector3 placeVector  = placeGrid.WorldToCell(placeRounded);
                    size = new Vector2(Mathf.CeilToInt(size.x), Mathf.CeilToInt(size.y));
                    Vector3 offset = new Vector3(0, 0);
                    if (size.x % 2 != 0)
                    {
                        offset.x = 0.5f;
                    }
                    if (size.y % 2 != 0)
                    {
                        offset.y = 0.5f;
                    }

                    placeSprite.transform.position = placeVector - offset;



                    BuildingManager buildingManager;


                    if (rotateable != null && Physics2D.OverlapBox(placeVector - offset, size - new Vector2(0.1f, 0.1f), 0.0f, filter, colliders) == 0)
                    {
                        rotateable.GetRotatedPlaceSprite(placementRotation);
                        placeSpriteRenderer.color = new Color(0, 1, 0, 0.25f);
                        if (Input.GetMouseButton(0))
                        {
                            GameObject building = Instantiate(mouseInventory.inventoryReadOnly[0].item.placeableResult, placeVector - offset, Quaternion.identity);
                            building.GetComponent <Health>().alliance = characterAlliance.allianceCode;
                            building.GetComponent <IRotate>().InitializeRotated(placementRotation);
                            DestroyGrassAt(placeVector - offset, size);
                            mouseInventory.DecrementStack(0);
                            UpdateLoaders(building.transform.position, size);
                        }
                    }
                    else if (mouseInventory.inventoryReadOnly[0].item.placeableResult.TryGetComponent(out buildingManager))
                    {
                        Physics2D.OverlapBox(placeVector - offset, size - new Vector2(0.1f, 0.1f), 0.0f, filterMining, collidersList);
                        List <Mineable> mineables;
                        if (buildingManager.CheckPlacement(collidersList, out mineables, placeVector - offset))
                        {
                            placeSpriteRenderer.color = new Color(0, 1, 0, 0.25f);
                            if (Input.GetMouseButton(0))
                            {
                                GameObject building = Instantiate(mouseInventory.inventoryReadOnly[0].item.placeableResult, placeVector - offset, Quaternion.identity);
                                building.GetComponent <CraftingManagerFixed>().SetMineables(mineables);
                                building.GetComponent <Health>().alliance = characterAlliance.allianceCode;
                                DestroyGrassAt(placeVector - offset, size);
                                mouseInventory.DecrementStack(0);
                                UpdateLoaders(building.transform.position, size);
                            }
                        }
                        else
                        {
                            placeSpriteRenderer.color = new Color(1, 0, 0, 0.25f);
                        }
                    }
                    else if (Physics2D.OverlapBox(placeVector - offset, size - new Vector2(0.1f, 0.1f), 0.0f, filter, colliders) == 0)
                    {
                        placeSpriteRenderer.color = new Color(0, 1, 0, 0.25f);
                        if (Input.GetMouseButton(0))
                        {
                            GameObject building = Instantiate(mouseInventory.inventoryReadOnly[0].item.placeableResult, placeVector - offset, Quaternion.identity);
                            building.GetComponent <Health>().alliance = characterAlliance.allianceCode;
                            DestroyGrassAt(placeVector - offset, size);
                            mouseInventory.DecrementStack(0);
                            UpdateLoaders(building.transform.position, size);
                        }
                    }
                    else
                    {
                        placeSpriteRenderer.color = new Color(1, 0, 0, 0.25f);
                    }
                }
                else if (mouseInventory.inventoryReadOnly[0].item.placeableResult == null)
                {
                    placeSpriteRenderer.color = new Color(1, 1, 1, 0);
                }
            }
            else
            {
                placeSpriteRenderer.color = new Color(1, 1, 1, 0);
            }

            if (hits[0].collider != null)
            {
                #region Left Click Interaction
                if (Input.GetMouseButtonDown(0))
                {
                    Inventory             inventory             = null;
                    CraftingManagerRecipe craftingManagerRecipe = null;
                    CraftingManagerFixed  craftingManagerFixed  = null;
                    IItemFilter           itemFilter            = null;
                    if (hits[0].collider.gameObject.TryGetComponent <CraftingManagerRecipe>(out craftingManagerRecipe))
                    {
                        filterItemUI.SetFilterFocus(null);
                        machineUI.SetLinkedMachine(hits[0].collider.gameObject);
                        inventoryInteractUI.SetViewedInventory(null);
                    }
                    else if (hits[0].collider.gameObject.TryGetComponent <CraftingManagerFixed>(out craftingManagerFixed))
                    {
                        filterItemUI.SetFilterFocus(null);
                        machineUI.SetLinkedMachine(hits[0].collider.gameObject);
                        inventoryInteractUI.SetViewedInventory(null);
                    }
                    else if (hits[0].collider.gameObject.TryGetComponent <Inventory>(out inventory))
                    {
                        filterItemUI.SetFilterFocus(null);
                        inventoryInteractUI.SetViewedInventory(inventory);
                        machineUI.SetLinkedMachine(null);
                    }
                    else if (hits[0].collider.gameObject.TryGetComponent <IItemFilter>(out itemFilter))
                    {
                        filterItemUI.SetFilterFocus(itemFilter);
                        machineUI.SetLinkedMachine(null);
                        inventoryInteractUI.SetViewedInventory(null);
                    }
                    else
                    {
                        inventoryInteractUI.SetViewedInventory(null);
                        machineUI.SetLinkedMachine(null);
                    }
                }
                #endregion Left Click Interaction

                #region Right Click Interaction
                if (Input.GetMouseButtonDown(1))
                {
                    Mineable mineable;
                    if (hits[0].collider.TryGetComponent(out mineable))
                    {
                        currentMineable = mineable;
                    }
                }

                if (currentMineable != null)
                {
                    Mineable mineable;
                    if (hits[0].collider.TryGetComponent(out mineable))
                    {
                        if (!ReferenceEquals(currentMineable, mineable))
                        {
                            miningProgress  = 0;
                            currentMineable = mineable;
                        }
                    }
                }
                #endregion Right Click Interaction
            }
            else
            {
                currentMineable = null;
            }
        }
        else
        {
            placeSpriteRenderer.color = new Color(1, 1, 1, 0);
        }

        if (Input.GetKeyDown(PlayerData.Instance.keybinds["Change Ammo"]))
        {
            selectedAmmoSlot++;
            if (selectedAmmoSlot >= ammoInventory.inventoryReadOnly.Count)
            {
                selectedAmmoSlot = 0;
            }
            ammoSlotSelected.SetHighlightedSlot(selectedAmmoSlot);
        }
    }
Пример #19
0
    public void SetFilterFocus(IItemFilter filterEntity)
    {
        filterHighlight.SetActive(false);
        this.filterEntity = filterEntity;
        if (filterEntity != null)
        {
            itemId = filterEntity.GetFilterItem();
            string[] filterNames = filterEntity.GetFilterNames();
            for (int i = 0; i < filterStateList.Count; i++)
            {
                filterToggleGroup.UnregisterToggle(filterStateList[i]);
                Destroy(filterStateList[i].gameObject);
            }
            filterStateList.Clear();
            if (filterNames.Length > 1)
            {
                for (int i = 0; i < filterNames.Length; i++)
                {
                    GameObject filterStateButton = Instantiate(filterOutputTogglePrefab, filterStatePanel.transform, false);
                    Toggle     toggle            = filterStateButton.GetComponent <Toggle>();
                    filterStateList.Add(toggle);
                    filterStateButton.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = filterNames[i];
                    toggle.group = filterToggleGroup;
                    if (filterEntity.GetFilter() == filterNames[i])
                    {
                        toggle.isOn = true;
                    }
                    else
                    {
                        toggle.isOn = false;
                    }
                }
                for (int i = 0; i < filterStateList.Count; i++)
                {
                    filterStateList[i].onValueChanged.AddListener(delegate { OnClickToggle(); });
                }
            }
            else
            {
                GameObject toggleOnOff = Instantiate(filterOutputTogglePrefab, filterStatePanel.transform, false);
                Toggle     temp        = toggleOnOff.GetComponent <Toggle>();
                filterStateList.Add(temp);
                toggleOnOff.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = "Enabled";
                temp.group = filterToggleGroup;
                string filterString = filterEntity.GetFilter();
                if (filterString == "Enabled")
                {
                    temp.isOn = true;
                }
                else
                {
                    temp.isOn = false;
                }
                temp.onValueChanged.AddListener(delegate { OnClickToggle(); });
            }
            if (itemId != -1)
            {
                for (int i = 0; i < filterItemList.Count; i++)
                {
                    if (filterItemList[i].GetComponent <InventorySlot>().item.id == itemId)
                    {
                        filterHighlight.SetActive(true);
                        filterHighlight.transform.SetParent(filterItemList[i].transform, false);
                        filterHighlight.transform.position = filterItemList[i].transform.position;
                    }
                }
            }

            GetComponent <MenuSlideOut>().TogglePanel(MenuSlideOut.PanelState.panelOut);
        }
        else
        {
            GetComponent <MenuSlideOut>().TogglePanel(MenuSlideOut.PanelState.panelIn);
        }
    }
Пример #20
0
 public PagedDataSetBuilder <TItem, TResult> WithItemFilter(IItemFilter <TItem> itemFilter) => WithItemFilter(x => Task.FromResult(itemFilter));