Example #1
0
        protected override void OnItemsSpawned(string instanceId, LocationSpawnItemResults <LocationValuablesCollection> result)
        {
            if (result.SpawnItem.CollectOptions != null &&
                result.SpawnItem.CollectOptions.CollectRange != null)
            {
                m_triggerPool.WatchLocation(GetPoolRequestId(instanceId, result.SourceLocation), result.SourceLocation, () =>
                {
                    ResourceActivationContext ctxt;

                    if (m_activationContexts.TryGetValue(instanceId, out ctxt))
                    {
                        ctxt.FireEvent("in_range");
                    }
                }, result.SpawnItem.CollectOptions.CollectRange);
            }

            base.OnItemsSpawned(instanceId, result);
        }
        public void SpawnItem(LocationSpawnItemDriverEventArgs <LocationValuablesCollection> e, ILocationCollectionMechanic mechanic)
        {
            MapAnnotation ann = new MapAnnotation(e.Results.SourceLocation);

            var mapMechanic = mechanic as MapLocationCollectionMechanic;

            var options = e.Results.SpawnItem.CollectOptions;
            var action  = mapMechanic == null ? null : mapMechanic.CollectAction;

            DoubleRange actionRange = new DoubleRange(0, AutoCollectDistance);

            if (options != null && options.CollectRange != null)
            {
                actionRange = options.CollectRange;
            }

            var actionType = (action == null) ? null : action.Type;

            bool collectWithPanel = false;

            // if no actionType is specified, defer to the AutoCollect setting
            if ((actionType == null && AutoCollectInRange) ||
                (actionType != null && actionType == "motive.ar.inRangeLocationCollectionAction"))
            {
                m_triggerPool.WatchLocation(GetTriggerRequestId(e), e.Results.SourceLocation, () =>
                {
                    PlayCollectSound(mapMechanic);

                    WorldValuablesManager.Instance.Collect(e);
                }, actionRange);
            }
            else
            {
                collectWithPanel = true;
            }

            ann.Delegate = new MapAnnotationDelegate
            {
                OnSelect = (_ann) =>
                {
                    if (ValuablesCollectionPanel)
                    {
                        ValuablesCollectionPanel.ValuablesCollection = e.Results.SpawnItem.ValuablesCollection;
                        ValuablesCollectionPanel.OnAction            = () =>
                        {
                            RewardManager.Instance.ShowRewards(e.Results.SpawnItem.ValuablesCollection);

                            PlayCollectSound(mapMechanic);

                            WorldValuablesManager.Instance.Collect(e);
                        };

                        SelectedLocationPanelHandler.Instance.ShowSelectedLocationPanel(ValuablesCollectionPanel, _ann);

                        //if (collectWithPanel)
                        {
                            ValuablesCollectionPanel.ShowMapCollect(actionRange);
                        }
                    }
                },
                OnDeselect = (_ann) =>
                {
                    base.DeselectAnnotation(_ann);
                },
                OnGetObjectForAnnotation = (_ann) =>
                {
                    return(CreateAnnotationObject(e.Results.SpawnItem));
                }
            };

            AddAnnotation(e.Results.SourceLocation.Id, ann);
        }