public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jsonObject = JObject.Load(reader);

            if (Enum.TryParse <GambitActionTypes>(jsonObject["GambitActionType"].Value <string>(), out var parsedEnum))
            {
                GambitAction action;
                switch (parsedEnum)
                {
                case GambitActionTypes.CastSpellOnSelf:
                    action = new CastSpellOnSelfAction();
                    break;

                case GambitActionTypes.CastSpellOnCurrentTarget:
                    action = new CastSpellOnCurrentTargetAction();
                    break;

                case GambitActionTypes.CastSpellOnAlly:
                    action = new CastSpellOnAllyAction();
                    break;

                case GambitActionTypes.CastSpellOnEnemy:
                    action = new CastSpellOnEnemyAction();
                    break;

                case GambitActionTypes.CastSpellOnFriendlyNpc:
                    action = new CastSpellOnFriendlyNpcAction();
                    break;

                case GambitActionTypes.SleepForMilliseconds:
                    action = new SleepForTimeAction();
                    break;

                case GambitActionTypes.NoAction:
                    action = new NullAction();
                    break;

                case GambitActionTypes.ToastMessage:
                    action = new ToastMessageAction();
                    break;

                case GambitActionTypes.UseItemOnSelf:
                    action = new UseItemOnSelfAction();
                    break;

                case GambitActionTypes.PetCast:
                    action = new PetCastAction();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                serializer.Populate(jsonObject.CreateReader(), action);
                return(action);
            }
            throw new InvalidCastException();
        }
Exemple #2
0
        public static void AddActionToGambit(Gambit gambit, GambitActionTypes selectedValue)
        {
            IGambitAction newAction;

            switch (selectedValue)
            {
            case GambitActionTypes.NoAction:
                newAction = new NullAction();
                break;

            case GambitActionTypes.CastSpellOnSelf:
                newAction = new CastSpellOnSelfAction {
                    SpellName = "The Spell's Name"
                };
                break;

            case GambitActionTypes.CastSpellOnAlly:
                newAction = new CastSpellOnAllyAction {
                    SpellName = "The Spell's Name"
                };
                break;

            case GambitActionTypes.CastSpellOnEnemy:
                newAction = new CastSpellOnEnemyAction {
                    SpellName = "The Spell's Name"
                };
                break;

            case GambitActionTypes.CastSpellOnFriendlyNpc:
                newAction = new CastSpellOnFriendlyNpcAction {
                    SpellName = "The Spell's Name"
                };
                break;

            case GambitActionTypes.SleepForMilliseconds:
                newAction = new SleepForTimeAction {
                    DurationInMilliseconds = 1000
                };
                break;

            case GambitActionTypes.ToastMessage:
                newAction = new ToastMessageAction {
                    displaySeconds = 2, message = "The Toast Message"
                };
                break;

            case GambitActionTypes.UseItemOnSelf:
                newAction = new UseItemOnSelfAction()
                {
                    ItemName = "The Item's Name", AnyQuality = true
                };
                break;

            case GambitActionTypes.CastSpellOnCurrentTarget:
                newAction = new CastSpellOnCurrentTargetAction()
                {
                    SpellName = "The Spell's Name"
                };
                break;

            case GambitActionTypes.CastFillerOnCurrentTarget:
                newAction = new CastFillerOnCurrentTargetAction()
                {
                    SpellName = "The Filler's SpellName", ProcName = "The Proc's SpellName"
                };
                break;

            case GambitActionTypes.PetCast:
                newAction = new PetCastAction()
                {
                    SpellName = "The Spell's Name"
                };
                break;

            default:
                return;
            }

            gambit.ActionType = selectedValue;
            gambit.Action     = newAction;
        }