Ejemplo n.º 1
0
        protected T GetElementValue <T>(XElement aParent, XName aName) where T : struct
        {
            var element = GetElement(aParent, aName);

            if (element != null)
            {
                try {
                    if (typeof(T).IsEnum)
                    {
                        return((T)Enum.Parse(typeof(T), element.Value, true));
                    }
                    else
                    {
                        return((T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(element.Value));
                    }
                }
                catch {
                    if (OnXmlParseErrorOccurred(element, XmlErrorTypes.ValueParseError, element.Value))
                    {
                        throw new Exceptions.ProcessingAborted();
                    }
                }
            }

            return(default(T));
        }
        public async Task <bool> Handle(UpdateListingCommand request, CancellationToken cancellationToken)
        {
            request.Listing.Status = (ListingStatus)Enum.Parse(typeof(ListingStatus), request.Listing.ListingStatus);
            _context.Listings.Update(request.Listing);
            await _context.SaveChangesAsync(cancellationToken);

            _logger.LogInformation($"Listing Update: {request.Listing.Address}: Successfully updated");
            return(await Task.FromResult(true));
        }
Ejemplo n.º 3
0
        protected override void ProcessResource(ObjectCollection aObjects)
        {
            var files = GetXmlFiles(Directories.Objects);

            if (files.Any())
            {
                OnCategoryProcessing(ResourceTypes.Objects);
                var previous = SetCurrentDirectory(Directories.Objects);

                foreach (var file in files)
                {
                    var document = LoadXml(file);

                    if (document != null)
                    {
                        var obj = new Object()
                        {
                            ID          = GetElementValue <int>(document, "ID"),
                            Name        = GetElement(document, "Name").Value,
                            SpriteIndex = GetElementValue <int>(document, "SpriteIndex"),
                            ParentIndex = GetElementValue <int>(document, "ParentIndex"),
                            MaskIndex   = GetElementValue <int>(document, "MaskIndex"),
                            Depth       = GetElementValue <int>(document, "Depth"),
                            Solid       = GetElementValue <bool>(document, "Solid"),
                            Visible     = GetElementValue <bool>(document, "Visible"),
                            Persistent  = GetElementValue <bool>(document, "Persistent")
                        };

                        foreach (var element in document.Element("Events").Elements("Event"))
                        {
                            var ev = new Object.Event();
                            ev.Type      = (EventTypes)Enum.Parse(typeof(EventTypes), element.Attribute("Type").Value);
                            ev.Parameter = int.Parse(element.Attribute("Parameter").Value);
                            ev.Actions.AddRange(ReadActions(element.Element("Actions")));

                            obj.Events.Add(ev);
                        }

                        aObjects.Add(obj);
                    }

                    OnAbortProcessingCallback();
                }

                OnCategoryProcessed(ResourceTypes.Objects);
                SetCurrentDirectory(previous);
            }
        }
Ejemplo n.º 4
0
        public override async Task <AddRoomReply> AddRoom(AddRoomRequest request, ServerCallContext context)
        {
            var room = new Room()
            {
                Name     = request.Name,
                RoomType = Enum.Parse <RoomType>(request.RoomType),
                Price    = request.Price
            };
            var addedRoom = await _repository.AddAsync(room);

            return(new AddRoomReply()
            {
                Id = addedRoom.Id.ToString(),
                Name = addedRoom.Name
            });
        }
Ejemplo n.º 5
0
        public override async Task <AddCarReply> AddCar(AddCarRequest request, ServerCallContext context)
        {
            var car = new Car()
            {
                Name    = request.Name,
                CarType = Enum.Parse <CarType>(request.CarType),
                Price   = request.Price
            };
            var addedCar = await _repository.AddAsync(car);

            return(new AddCarReply()
            {
                Id = addedCar.Id.ToString(),
                Name = addedCar.Name
            });
        }
Ejemplo n.º 6
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        /// <summary>
        /// Raises the enable event when OCLogger is loaded.  Initialized here.
        /// </summary>
        public void OnEnable()
        {
            LogLevel logLevel = LogLevel.NONE;

            try
            {
                logLevel = (LogLevel)
                           Enum.Parse(typeof(LogLevel), OCConfig.Instance.get("LOG_LEVEL"));
            }
            catch (ArgumentException ae)
            {
                UnityEngine.Debug.LogError
                    ("In OCLogger.OnEnable: Failed to construct [" + ae.Message + "]");
            }
            CurrentLevel = logLevel;

            IsLogEnabled = logLevel > LogLevel.NONE;
        }
Ejemplo n.º 7
0
 private ResourceType ParseResourceType(string resourceType)
 {
     AssertCorrectResourceType(resourceType);
     return((ResourceType)Enum.Parse(typeof(ResourceType),
                                     resourceType, ignoreCase: true));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Takes the item from the item slot
        /// </summary>
        /// <param name="direct"> Flag for if the item will be taken directly from the itemslot with no dragging </param>
        public void TakeItem(bool direct = false)
        {
            if (currentItemDisplay != null && isTakeable == true)
            {
                bool itemTaken = false;

                if (currentItemDisplay.type == ItemConstants.CONSUMABLE)    // consumable items are used on click
                {
                    string[] effects = currentItemDisplay.GetEffects();
                    int[]    amounts = currentItemDisplay.GetValues();
                    for (int i = 0; i < effects.Length; i++)
                    {
                        if (effects[i] == "EXP")
                        {
                            PartyManager.instance.AddEXP(amounts[i]);
                        }
                        else if (effects[i] == "HP")
                        {
                            StartCoroutine(PartyManager.instance.ChangeHPAll(amounts[i]));
                        }
                        else if (effects[i] == "MP")
                        {
                            PartyManager.instance.ChangeMPAll(amounts[i]);
                        }
                        else if (effects[i] == "WAX")
                        {
                            PartyManager.instance.AddWAX(amounts[i]);
                        }
                        else if (effects[i] != "none")   // status effects
                        {
                            PartyManager.instance.AddStatusEffect((StatusEffectConstant)Enum.Parse(typeof(StatusEffectConstant), effects[i]), amounts[i]);
                        }
                    }
                    itemTaken = true;
                    Destroy(currentItemDisplay.gameObject);
                }
                else    // non-consumable items must be dragged into the user's inventory, or placed directly via button

                /*
                 *  Item taken directly from an eventsDisplay/rewardsPanel via the "take all" button
                 *  resulting in the item being placed in the corresponding panel if there's room
                 */
                {
                    if (direct == true)
                    {
                        Panel targetPanel = EventManager.instance.GetTargetPanel(currentItemDisplay.type);

                        if (targetPanel == parentPanel)     // selling from a panel via shift click
                        {
                            EventDisplay ed = EventManager.instance.TryPlaceItem();
                            if (ed != null)
                            {
                                ed.SellItem(currentItemDisplay);
                                itemTaken = true;
                            }
                        }
                        else if (currentItemDisplay.type == ItemConstants.GEAR)
                        {
                            GearPanel gearPanel = (GearPanel)targetPanel;
                            if (gearPanel.PlaceItem(currentItemDisplay, direct))
                            {
                                itemTaken = true;
                            }
                        }
                        else if (currentItemDisplay.type == ItemConstants.CANDLE)
                        {
                            CandlesPanel candlesPanel = (CandlesPanel)targetPanel;
                            if (candlesPanel.PlaceItem(currentItemDisplay, direct))
                            {
                                itemTaken = true;
                            }
                        }
                        else if (currentItemDisplay.type == ItemConstants.SPECIAL)
                        {
                            SpecialPanel specialPanel = (SpecialPanel)targetPanel;
                            if (specialPanel.PlaceItem(currentItemDisplay, direct))
                            {
                                itemTaken = true;
                            }
                        }
                    }
                    else
                    {
                        UIManager.instance.heldItemDisplay = currentItemDisplay;
                        UIManager.instance.StartDragItem();
                        UIManager.instance.panelButtonsEnabled = false;
                        itemTaken = true;
                    }
                }

                if (itemTaken)      // if item is taken, update the itemSlot
                {
                    currentItemDisplay          = null;
                    defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 255);
                    t.SetVisible(false);
                    SetTooltipText();

                    if (parentPanel.GetPanelName() == PanelConstants.GEARPANEL)
                    {
                        if (itemSlotSubType == ItemConstants.ANY)       // gearPanel updates to have more free spare itemSlots
                        {
                            GearPanel gearPanel = (GearPanel)parentPanel;
                            gearPanel.TakeItem();
                        }
                        else    // item was unequipped from partyMember
                        {
                            PartyManager.instance.UnequipGear(itemSlotSubType);
                        }
                    }
                    else if (parentPanel.GetPanelName() == PanelConstants.CANDLESPANEL)
                    {
                        CandlesPanel candlesPanel = (CandlesPanel)parentPanel;

                        if (itemSlotSubType == ItemConstants.ANY)       // candlesPanel updates to have more free spare itemSlots
                        {
                            candlesPanel.TakeItem();
                        }
                        else    // item was unequipped from partyMember
                        {
                            PartyManager.instance.UnequipCandle(itemSlotSubType);
                            candlesPanel.SetUsable(itemSlotSubType[0] - '0');
                        }
                    }
                    else if (parentPanel.GetPanelName() == PanelConstants.SPECIALPANEL)
                    {
                        SpecialPanel specialPanel = (SpecialPanel)parentPanel;
                        if (itemSlotSubType == ItemConstants.ANY)       // specialPanel updates to have more free spare itemSlots
                        {
                            specialPanel.TakeItem();
                        }
                    }
                    else if (UIManager.instance.heldItemDisplay != null)
                    {
                        EventManager.instance.OpenItemPanel(UIManager.instance.heldItemDisplay);
                        parentPanel.TakeItem();
                        EventManager.instance.UpdateTakeAll();
                    }
                    else
                    {
                        parentPanel.TakeItem();
                        EventManager.instance.UpdateTakeAll();
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public bool Execute(WorkFlowCommand command, Context context)
        {
            if (context?.ImageStream == null)
            {
                return(true);
            }
            if (!CheckCondition(command, context))
            {
                return(true);
            }
            context.ImageStream.Seek(0, SeekOrigin.Begin);
            MagickImage watermark = null;

            using (MagickImage image = new MagickImage(context.ImageStream))
            {
                // check the cache if the image is already is loaded
                if (context.Cache.ContainsKey(command.GetHashCode().ToString()))
                {
                    var cache = context.Cache[command.GetHashCode().ToString()];
                    if (cache.Id == command.Properties["OverlayFile"].ToString(context))
                    {
                        watermark = (MagickImage)cache.Object;
                    }
                    else
                    {
                        cache.DisposeObject();
                        context.Cache.Remove(command.GetHashCode().ToString());
                    }
                }
                if (watermark == null && File.Exists(command.Properties["OverlayFile"].ToString(context)))
                {
                    // Read the watermark that will be put on top of the image
                    watermark = new MagickImage(command.Properties["OverlayFile"].ToString(context));

                    if (command.Properties["StrechOverlay"].ToBool(context))
                    {
                        watermark.Resize(image.Width, image.Height);
                    }
                    // Optionally make the watermark more transparent
                    context.Cache.Add(command.GetHashCode().ToString(),
                                      new CacheObject()
                    {
                        Id     = command.Properties["OverlayFile"].ToString(context),
                        Object = watermark
                    });
                }

                if (watermark != null)
                {
                    if (command.Properties["Transparency"].ToInt(context) != 100)
                    {
                        watermark.Evaluate(Channels.Alpha, EvaluateOperator.Add,
                                           -(255 * (100 - command.Properties["Transparency"].ToInt(context)) / 100));
                    }
                    image.Composite(watermark,
                                    (Gravity)Enum.Parse(typeof(Gravity), command.Properties["Position"].ToString(context)),
                                    CompositeOperator.Over);
                }

                if (!string.IsNullOrEmpty(command.Properties["Text"].ToString(context)))
                {
                    image.Settings.Font          = command.Properties["TextFont"].ToString(context);
                    image.Settings.FontPointsize = command.Properties["TextPointSize"].ToInt(context);;

                    Color color = (Color)ColorConverter.ConvertFromString(command.Properties["TextFillColor"].ToString(context));
                    image.Settings.FillColor = new MagickColor(color.R, color.G, color.B, (byte)(255 * (100 - command.Properties["TextTransparency"].ToInt(context)) / 100));
                    color = (Color)ColorConverter.ConvertFromString(command.Properties["TextStrokeColor"].ToString(context));
                    image.Settings.StrokeColor = new MagickColor(color.R, color.G, color.B, (byte)(255 * (100 - command.Properties["TextTransparency"].ToInt(context)) / 100));

                    image.Annotate(command.Properties["Text"].ToString(context).Replace("\\n", "\n"),
                                   (Gravity)Enum.Parse(typeof(Gravity), command.Properties["TextPosition"].ToString(context)));
                }

                image.Write(context.ImageStream, MagickFormat.Jpg);
            }
            return(true);
        }
Ejemplo n.º 10
0
        public static void ComboBox(SerializedProperty property)
        {
            var action       = (Action)property.Object;
            var propertyInfo = property.Property;
            var enumData     = (Enum)property.Property.GetValue(action);

            var panel = new DockPanel {
                VerticalAlignment = VerticalAlignment.Center,
                // Margin = new Thickness(5, 0, 5, 0)
                Margin = actionPropertyIndex == 0 ? new Thickness(5, 0, 5, 0) : new Thickness(5, 5, 5, 0)
            };

            actionPropertyIndex++;

            var options = (string[])Enum.GetNames(enumData.GetType());

            var label = propertyInfo.GetCustomAttribute <LabelAttribute>()?.text ?? propertyInfo.Name.ToDisplayName();

            // var actions = ActionsControl.control;
            var textBlock = new TextBlock {
                Text              = label,
                Width             = 100,
                VerticalAlignment = VerticalAlignment.Center
            };

            var tooltip = property.Property.GetCustomAttribute <TooltipAttribute>();

            if (tooltip is TooltipAttribute attr)
            {
                textBlock.ToolTip = attr.toolTip;
                ToolTipService.SetShowDuration(textBlock, int.MaxValue);
            }

            var comboBox = new ComboBox {
                Margin     = new Thickness(5, 0, 2, 0),
                Foreground = Brushes.Black
            };

            comboBox.DropDownClosed += (sender, evt) => {
                // ActionsControl.OnActionsUpdated(sender);
            };

            foreach (var option in options)
            {
                var v           = Enum.Parse(enumData.GetType(), option);
                var bindingData = new BindingData {
                    Action   = action,
                    Property = propertyInfo,
                    Label    = textBlock,
                    Input    = comboBox,
                    Value    = v
                };
                var comboBoxItem = new ComboBoxItem {
                    DataContext = bindingData,
                    Content     = new TextBlock {
                        Text = option.ToDisplayName(), Foreground = Brushes.Black
                    },
                };
                if (propertyInfo.GetValue(action).Equals(v))
                {
                    comboBox.SelectedItem = comboBoxItem;
                }
                comboBox.Items.Add(comboBoxItem);
            }

            // Note: Add the event after the initial selection so it doesn't get triggered.
            comboBox.SelectionChanged += (sender, evt) => {
                var comboBox = (ComboBox)sender;
                var item     = (ComboBoxItem)comboBox.SelectedItem;
                var context  = (BindingData)item.DataContext;
                propertyInfo.SetValue(action, context.Value);
                EventBus.OnLayerActionChanged(sender);
            };

            DockPanel.SetDock(textBlock, Dock.Left);
            DockPanel.SetDock(comboBox, Dock.Right);

            panel.Children.Add(textBlock);
            panel.Children.Add(comboBox);

            AddAction(panel, property);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Applies a champion buff to a monster at random
        /// TODO: Make AddStatusEffectPermanent similar to AddStatusEffect
        /// </summary>
        /// <param name="championBuffs"> List of championBuffs that can be applied in the subArea (assumed length 3) </param>
        public void GetChampionBuff(string[] championBuffs)
        {
            if (multiplier == 4)        // boss monsters can only be champion if GetBossBuff() allows it (otherwise too op)
            {
                isChampion = Random.Range(0, 100) < championChance;
            }
            else
            {
                isChampion = Random.Range(0, 100) < (championChance + PartyManager.instance.bonusChampionChance);
            }

            if (isChampion == true)
            {
                multiplier += 0.5f;
                this.EXP    = (int)((Mathf.Pow(LVL, 1.65f) + ((STR + DEX + INT + LUK) / 10)) * this.multiplier * (1 / difficultyModifier));
                this.WAX    = (int)(Mathf.Pow(LVL + 1, 1.65f) * this.multiplier * (1 / difficultyModifier));
                monsterReward.UpgradeResult();
                dropChance = 100;

                StatusEffectConstant championBuff = (StatusEffectConstant)Enum.Parse(typeof(StatusEffectConstant), championBuffs[Random.Range(0, championBuffs.Length)]);
                StatusEffect         newStatus;
                switch (championBuff)
                {
                case StatusEffectConstant.CHAMPIONATK:
                {
                    if (PATK >= MATK)
                    {
                        newStatus = new StatusEffect(StatusEffectConstant.CHAMPIONPATK, 999);
                    }
                    else
                    {
                        newStatus = new StatusEffect(StatusEffectConstant.CHAMPIONMATK, 999);
                    }
                    AddStatusEffectPermanent(newStatus);
                    md.AddStatusEffectDisplay(newStatus);
                    break;
                }

                case StatusEffectConstant.CHAMPIONDEF:
                {
                    if (PDEF >= MDEF)
                    {
                        newStatus = new StatusEffect(StatusEffectConstant.CHAMPIONPDEF, 999);
                    }
                    else
                    {
                        newStatus = new StatusEffect(StatusEffectConstant.CHAMPIONMDEF, 999);
                    }
                    AddStatusEffectPermanent(newStatus);
                    md.AddStatusEffectDisplay(newStatus);
                    break;
                }

                case StatusEffectConstant.CHAMPIONHP:
                {
                    newStatus = new StatusEffect(StatusEffectConstant.CHAMPIONHP, 999);
                    newStatus.SetValue(this, this);
                    AddStatusEffectPermanent(newStatus);
                    md.AddStatusEffectDisplay(newStatus);
                    break;
                }
                }
            }
        }