Exemplo n.º 1
0
 private void BuildMonsterAttack()
 {
     switch (mattackTypeCombobox.Text)
     {
     default:
         mattack = null;
         break;
     }
 }
Exemplo n.º 2
0
            static public void Add(string id, MonsterAttack mattack)
            {
                List <MonsterAttack> temp_attack;

                if (mattacks_by_id.TryGetValue(id, out temp_attack))
                {
                    temp_attack.Add(mattack);
                    mattacks_by_id[id] = temp_attack;
                }
                else
                {
                    temp_attack = new List <MonsterAttack> {
                        mattack
                    };
                    mattacks_by_id.Add(id, temp_attack);
                }
            }
Exemplo n.º 3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }
            List <MonsterAttack> ret = new List <MonsterAttack> {
            };
            JArray main_array        = JArray.Load(reader);

            foreach (JToken token in main_array)
            {
                if (token.Type == JTokenType.Array)
                {
                    JArray array = token.ToObject <JArray>();
                    ret.Add(new MonsterAttack
                    {
                        Id       = (string)array[0],
                        Cooldown = (int)array[1]
                    });
                }
                else
                {
                    MonsterAttack        test = token.ToObject <MonsterAttack>(serializer);
                    List <MonsterAttack> loaded_attack_list = Program.LoadedObjectDictionary.GetMAttacks(test.Id);
                    JObject token_object = token.ToObject <JObject>(serializer);
                    string  type;
                    if (loaded_attack_list != null)
                    {
                        JObject base_object = JObject.FromObject(loaded_attack_list[0], serializer);
                        type = loaded_attack_list[0].Type == "monster_attack" ? loaded_attack_list[0].AttackType : loaded_attack_list[0].Type;
                        base_object.Merge(token_object,
                                          new JsonMergeSettings
                        {
                            MergeArrayHandling = MergeArrayHandling.Replace
                        });
                        token_object = base_object;
                    }
                    else
                    {
                        type = test.Type == "monster_attack" ? test.AttackType : test.Type;
                    }
                    switch (type)
                    {
                    case "hardcoded":
                        ret.Add(token.ToObject <MonsterAttack>(serializer));
                        break;

                    case "leap":
                        ret.Add(token_object.ToObject <MonsterAttackLeap>(serializer));
                        break;

                    case "bite":
                        ret.Add(token_object.ToObject <MonsterAttackBite>(serializer));
                        break;

                    case "gun":
                        ret.Add(token_object.ToObject <MonsterAttackGun>(serializer));
                        break;

                    case "melee":
                        ret.Add(token_object.ToObject <MonsterAttackMelee>(serializer));
                        break;

                    case "spell":
                        ret.Add(token_object.ToObject <MonsterAttackSpell>(serializer));
                        break;

                    default: break;
                    }
                }
            }
            if (ret.Count == 0)
            {
                return(null);
            }
            else
            {
                return(ret);
            }
        }
Exemplo n.º 4
0
 private void cancelButton_Click(object sender, EventArgs e)
 {
     mattack = null;
 }
Exemplo n.º 5
0
        private void TryLoadObjectLists()
        {
            string cdda_path;

            try
            {
                string cdda_path_file = System.Windows.Forms.Application.StartupPath + "\\cdda_data_path";
                cdda_path = File.ReadAllText(cdda_path_file);
            }
            catch
            {
                cddaFolderBrowserDialog.ShowDialog();
                cdda_path = cddaFolderBrowserDialog.SelectedPath;
            }
            currentPathLabel.Text = cdda_path;
            if (cdda_path == "")
            {
                return;
            }
            else
            {
                File.WriteAllText(Application.StartupPath + "\\cdda_data_path", cdda_path);
            }
            DirectoryInfo  dir   = new DirectoryInfo(cdda_path);
            JsonSerializer j_ser = new JsonSerializer
            {
                ContractResolver = new IgnoreEmptyEnumerablesResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                }
            };

            foreach (FileInfo file in dir.GetFiles("*.json", SearchOption.AllDirectories))
            {
                string file_text = File.ReadAllText(file.FullName);
                try
                {
                    JArray         ja        = JArray.Parse(file_text);
                    List <JObject> temp_list = (List <JObject>)ja.ToObject(typeof(List <JObject>));
                    foreach (JObject obj in temp_list)
                    {
                        GenericTypedObject generic_object = (GenericTypedObject)obj.ToObject(typeof(GenericTypedObject), j_ser);
                        if (generic_object.valid())
                        {
                            Program.LoadedObjectDictionary.Add(generic_object.Type, generic_object.GetId());
                            switch (generic_object.Type)
                            {
                            case "MONSTER":
                                Mtype temp = (Mtype)obj.ToObject(typeof(Mtype), j_ser);
                                Program.LoadedObjectDictionary.Add(generic_object.Id, temp);
                                break;

                            case "SPELL":
                                Program.LoadedObjectDictionary.Add(generic_object.Id, (spell.spell_type)obj.ToObject(typeof(spell.spell_type), j_ser));
                                break;

                            case "monster_attack":
                                MonsterAttack loaded_attack = (MonsterAttack)obj.ToObject(typeof(MonsterAttack), j_ser);
                                switch (loaded_attack.AttackType)
                                {
                                case "hardcoded":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, loaded_attack);
                                    break;

                                case "leap":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackLeap)obj.ToObject(typeof(MonsterAttackLeap), j_ser));
                                    break;

                                case "bite":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackBite)obj.ToObject(typeof(MonsterAttackBite), j_ser));
                                    break;

                                case "melee":
                                    string melee = obj.ToString();
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackMelee)obj.ToObject(typeof(MonsterAttackMelee), j_ser));
                                    break;

                                case "spell":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackSpell)obj.ToObject(typeof(MonsterAttackSpell), j_ser));
                                    break;

                                case "gun":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackGun)obj.ToObject(typeof(MonsterAttackGun), j_ser));
                                    break;

                                default: break;
                                }
                                break;

                            case "material":
                                Program.LoadedObjectDictionary.Add(generic_object.Ident, (MaterialType)obj.ToObject(typeof(MaterialType), j_ser));
                                break;

                            default: break;
                            }
                        }
                    }
                } catch (Newtonsoft.Json.JsonReaderException)
                {
                } catch (System.ArgumentException)
                {
                }
            }
        }