internal static CustomExpHandlerBase FireHandler(byte typeID, LG_Layer layer, WardenObjectiveDataBlock objectiveData)
 {
     if (_Handlers.TryGetValue(typeID, out var handler))
     {
         return(FireHandlerByContainer(handler, layer, objectiveData));
     }
     else
     {
         throw new ArgumentException($"typeID: {typeID} is not defined, Are you missing some plugin?");
     }
 }
예제 #2
0
        private void Start()
        {
            if (!setup)
            {
                this.light            = GetComponent <LG_Light>();
                this.animator         = GetComponent <LG_LightAnimator>() ?? this.light?.GetC_Light()?.gameObject?.GetComponent <LG_LightAnimator>();
                this.currentColor     = this.light.m_color;
                this.currentIntensity = this.light.GetIntensity();
                this.startIntensity   = this.currentIntensity;

                this.area  = this.light?.GetC_Light()?.m_sourceNode?.CourseNode?.m_area;
                this.zone  = this.area?.m_zone;
                this.layer = this.zone?.Layer;

                controllers.Add(this);
                this.setup = true;
            }
        }
        internal static CustomExpHandlerBase[] FireAllGlobalHandler(LG_Layer layer, WardenObjectiveDataBlock objectiveData)
        {
            var handlerList = new HandlerList();

            foreach (var handler in _GlobalHandlers)
            {
                if (!_AllowedGlobalHandlers.Any(x => !string.IsNullOrEmpty(handler.GUID) && x.Equals(handler.GUID, StringComparison.OrdinalIgnoreCase)))
                {
                    continue;
                }

                var handlerInstance = FireHandlerByContainer(handler, layer, objectiveData, isGlobalHandler: true);

                if (handlerInstance != null)
                {
                    handlerList.Add(handlerInstance);
                }
            }

            return(handlerList.ToArray());
        }
        internal void Setup(LG_Layer layer, WardenObjectiveDataBlock objectiveData, bool isGlobalHandler)
        {
            Layer         = layer;
            LayerType     = layer.m_type;
            ObjectiveData = objectiveData;

            IsDefaultObjective = Enum.IsDefined(typeof(eWardenObjectiveType), ObjectiveData.Type);
            IsGlobalHandler    = isGlobalHandler;

            var activeExpedition = RundownManager.ActiveExpedition;

            switch (LayerType)
            {
            case LG_LayerType.MainLayer:
                LayerData = activeExpedition.MainLayerData;
                break;

            case LG_LayerType.SecondaryLayer:
                LayerData = activeExpedition.SecondaryLayerData;
                break;

            case LG_LayerType.ThirdLayer:
                LayerData = activeExpedition.ThirdLayerData;
                break;
            }

            var data = RundownManager.GetActiveExpeditionData();

            CurrentExpeditionTier  = data.tier;
            CurrentExpeditionIndex = data.expeditionIndex;

            Builder         = new BuilderProxy(this);
            WinConditions   = new WinConditionProxy(this);
            ObjectiveStatus = new ObjectiveStatusProxy(this);


            var buildDone      = new Action(BuildDone);
            var elevatorArrive = new Action(ElevatorArrive);
            var levelSuccess   = new Action(OnExpeditionSuccess);
            var levelFail      = new Action(OnExpeditionFail);

            GlobalMessage.OnBuildDoneLate  += buildDone;
            GlobalMessage.OnElevatorArrive += elevatorArrive;

            GlobalMessage.OnLevelSuccess += levelSuccess;
            GlobalMessage.OnLevelFail    += levelFail;

            OnUnloadEvent += () =>
            {
                GlobalMessage.OnBuildDoneLate  -= buildDone;
                GlobalMessage.OnElevatorArrive -= elevatorArrive;

                GlobalMessage.OnLevelSuccess -= levelSuccess;
                GlobalMessage.OnLevelFail    -= levelFail;
            };

            OnSetupEvent?.Invoke();

            OnSetup();

            //Check WinCondition has been set after Setup
            if (!IsGlobalHandler && (!IsDefaultObjective && !ObjectiveStatus.Is))
            {
                Logger.Error("Every Custom Type Handler should set their ObjectiveStatus Update Behaviour Inside OnSetup()! Handler has been Unloaded!\n - typeID: {0}\n - handler {1}", (byte)ObjectiveData.Type, GetType().Name);
                UnloadSelf();
                return;
            }
        }
        private static CustomExpHandlerBase FireHandlerByContainer(HandlerTypeContainer handlerContainer, LG_Layer layer, WardenObjectiveDataBlock objectiveData, bool isGlobalHandler = false)
        {
            if (handlerContainer.Setting == null)
            {
                return(null);
            }

            if (!handlerContainer.Setting.ShouldFire_Internal(layer.m_type, objectiveData))
            {
                return(null);
            }

            var handler = handlerContainer.CreateInstance();

            handler.Setup(layer, objectiveData, isGlobalHandler);
            handler.HandlerGUID = new Guid().ToString();

            _ActiveHandlers.Add(handler);

            return(handler);
        }