public override void OnTalkTo(Character source) { if (OldTemplate != null) { OldTemplate.OnTalkTo(source); } }
public static bool JsonToCard(string file) { try { string json = File.ReadAllText(file); OldTemplate old = OldTemplate.FromJson(json); CardConfig card = new CardConfig(); card.MediaLocation = old.AssetLocation; card.ButtonBackground = old.ButtonBackground; card.ButtonForeground = old.ButtonForeground; card.ButtonText = old.ButtonText; card.Location = "Center"; card.Loop = old.LoopAnimation.ToString(); card.Background = old.WindowBackground; card.NameForeground = "#000000"; card.StaticName = old.UseDeviceName ? "" : old.DefaultDeviceName; card.StretchMode = "Uniform"; card.TemplateName = old.TemplateName; card.TimeOut = "7500"; card.Tint = "#EA000000"; File.WriteAllText(Helper.NextAvailableFilename($"{Helper.TemplateFolder}\\{card.TemplateName}.card"), CreateConfigFile.Create(card)); return(true); } catch (Exception) { return(false); } }
public override GroupTemplate GetGroupTemplate() { if (OldTemplate != null) { return(OldTemplate.GetGroupTemplate()); } return(null); }
public string GetOldTemplateFolderId() { if (OldTemplate != null) { return(OldTemplate.GetMonsterId().ToString()); } return(MonsterId.CustomMonster.ToString()); }
private MonsterId GetOldTemplateId() { if (OldTemplate != null) { return(OldTemplate.GetMonsterId()); } return(MonsterId.CustomMonster); }
public override string GetFolderName() { if (OldTemplate != null) { return(OldTemplate.GetMonsterId().ToString()); } return(MonsterId.CustomMonster.ToString()); }
public override void InitMonsterStats(Monster m, int level) { if (OldTemplate != null) { OldTemplate.InitMonsterStats(m, level); } base.InitMonsterStats(m, level); }
public override void InitAppearanceData(Monster m, EnemyData data) { if (OldTemplate != null) { OldTemplate.InitAppearanceData(m, data); } bool changed = false; if (Animation != null) { data.SetAnimation(Animation, "prefabs/animation/" + Animation + "/", SpriteSize); changed = true; } else if (Sprite != null) { if (GameSession.loadExternalGraphics) { Sprite spr = CustomGraphics.LoadSprite("monsters/" + Sprite, 500, 500); if (spr != null) { data.SetSprite(spr, SpriteSize); changed = true; } else { data.SetSprite("prefabs/entity/CustomCell/" + Sprite, SpriteSize); changed = true; } } else { data.SetSprite("prefabs/entity/CustomCell/" + Sprite, SpriteSize); changed = true; } } if (Mass > 0) { data.SetMass(Mass); changed = true; } if (changed) { data.UpdateCollider(name_turret); } }
public override MonsterAI CreateAI(Character ch) { if (AiType != null) { MonsterAI ai = null; MonsterTemplate t; List <Type> types = Utils.GetTypesInNamespace("Assets.scripts.AI", true, typeof(MonsterAI)); foreach (Type type in types) { if (type.Name.Equals(AiType, StringComparison.InvariantCultureIgnoreCase)) { ai = Activator.CreateInstance(type, ch) as MonsterAI; break; } } if (ai == null) { throw new NullReferenceException("CustomAIType " + AiType + " doesnt exist!"); } foreach (AddModuleInfo info in NewModules) { int id = info.id; string module = info.module + "Module"; bool highPrior = info.atHighPriority; List <Type> moduleTypes = Utils.GetTypesInNamespace("Assets.scripts.AI.Modules", true, typeof(AIAttackModule)); AIAttackModule newModule = null; foreach (Type type in moduleTypes) { if (type.Name.Equals(module, StringComparison.InvariantCultureIgnoreCase)) { newModule = Activator.CreateInstance(type, ai) as AIAttackModule; break; } } if (newModule != null) { newModule.id = id; Debug.Log("added new module " + newModule.id + " name " + module); ai.AddPriorityAttackModule(newModule, highPrior); } else { Debug.LogError("unknown module: " + module); } } FieldInfo field; foreach (AiParamInfo info in AiParams) { int id = info.id; string module = info.module + "Module"; string key = info.param; string value = info.value; AIAttackModule moduleClass; // find by ID if (id > 0) { moduleClass = ai.GetAttackModule(id); } else // find by module name { moduleClass = ai.GetAttackModule(module); } field = moduleClass.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance); if (field != null) { if (field.FieldType == typeof(int)) { field.SetValue(moduleClass, Int32.Parse(value)); } else if (field.FieldType == typeof(float)) { field.SetValue(moduleClass, float.Parse(value)); } else if (field.FieldType == typeof(double)) { field.SetValue(moduleClass, Double.Parse(value)); } else if (field.FieldType == typeof(bool)) { field.SetValue(moduleClass, Boolean.Parse(value)); } else if (field.FieldType == typeof(string)) { field.SetValue(moduleClass, value); } else { throw new ArgumentException("invalid custom AI field " + key + " - has unknown type (not int, float, double or string)"); } } else { Debug.LogError("Cant write to property " + key + " in " + moduleClass.GetType().Name + " (property is null)"); } } Debug.Log("Created custom " + ai.GetType().Name + " AI for " + ch.Name); name_turret = ch.Name; return(ai); } else if (OldTemplate != null) { return(OldTemplate.CreateAI(ch)); } throw new NullReferenceException("null AI (not set for some reason"); }
public override void InitSkillsOnMonster(SkillSet set, ActiveSkill meleeSkill, int level) { if (OldTemplate != null) { OldTemplate.InitSkillsOnMonster(set, meleeSkill, level); } FieldInfo field; foreach (SkillModifyInfo info in SkillModifyInfo) { string key = info.key; string value = info.value; Skill sk = set.GetSkill(info.id); field = sk.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance); if (field != null) { if (field.FieldType == typeof(int)) { field.SetValue(sk, Int32.Parse(value)); } else if (field.FieldType == typeof(float)) { field.SetValue(sk, float.Parse(value)); } else if (field.FieldType == typeof(double)) { field.SetValue(sk, Double.Parse(value)); } else if (field.FieldType == typeof(bool)) { field.SetValue(sk, Boolean.Parse(value)); } else if (field.FieldType == typeof(string)) { field.SetValue(sk, value); } else { throw new ArgumentException("invalid custom skill field " + key + " - has unknown type (not int, float, double or string)"); } } else { Debug.LogError("Cant write to property " + key + " in " + sk.GetType().Name + " (property is null)"); } } if (MeleeSkill != null) { foreach (SkillModifyInfo info in AutoattackSkillModifyInfos) { string key = info.key; string value = info.value; field = meleeSkill.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance); if (field != null) { if (field.FieldType == typeof(int)) { field.SetValue(meleeSkill, Int32.Parse(value)); } else if (field.FieldType == typeof(float)) { field.SetValue(meleeSkill, float.Parse(value)); } else if (field.FieldType == typeof(double)) { field.SetValue(meleeSkill, Double.Parse(value)); } else if (field.FieldType == typeof(bool)) { field.SetValue(meleeSkill, Boolean.Parse(value)); } else if (field.FieldType == typeof(string)) { field.SetValue(meleeSkill, value); } else { throw new ArgumentException("invalid custom autoattack skill field " + key + " - has unknown type (not int, float, double or string)"); } } else { Debug.LogError("Cant write to property " + key + " in " + meleeSkill.GetType().Name + " (property is null)"); } } } if (DisabledEffects.Count > 0) { foreach (SkillId id in DisabledEffects) { Skill sk = set.GetSkill(id); sk.DisableOriginalEffects(); } } if (DisabledMeleeEffects) { if (meleeSkill != null) { meleeSkill.DisableOriginalEffects(); } } if (SkillAddEffects.Count > 0) { foreach (SkillEffectInfo info in SkillAddEffects) { Skill sk = set.GetSkill(info.id); string name = info.effectName; object[] parameters; SkillEffect effect = null; foreach (Type t in Utils.GetTypesInNamespace("Assets.scripts.Skills.SkillEffects", true, typeof(SkillEffect))) { if (t.Name.Equals("Effect" + name, StringComparison.InvariantCultureIgnoreCase)) { foreach (ConstructorInfo ci in t.GetConstructors()) { parameters = new object[ci.GetParameters().Length]; bool matches = true; // pro dany konstruktor zjistit, jestli jsou jeho parametry definovane for (int i = 0; i < ci.GetParameters().Length; i++) { ParameterInfo pi = ci.GetParameters()[i]; string val; if (!info.parameters.TryGetValue(pi.Name, out val)) { matches = false; break; } else { if (pi.ParameterType == typeof(int)) { parameters[i] = Int32.Parse(val); } else if (pi.ParameterType == typeof(float)) { parameters[i] = float.Parse(val); } else if (pi.ParameterType == typeof(double)) { parameters[i] = Double.Parse(val); } else if (pi.ParameterType == typeof(bool)) { parameters[i] = Boolean.Parse(val); } else if (pi.ParameterType == typeof(string)) { parameters[i] = val; } else { throw new ArgumentException("invalid param when constructing skill effect " + pi.ParameterType + " - cant parse"); } } } // this constructor will be used if (matches) { effect = (SkillEffect)ci.Invoke(parameters); break; } } break; } } if (effect != null) { sk.AddAdditionalEffect(effect); } else { Debug.LogError("couldnt create instance of " + name + " with parameters " + info.parameters); } } } if (MeleeAddEffects.Count > 0 && meleeSkill != null) { foreach (SkillEffectInfo info in MeleeAddEffects) { string name = info.effectName; object[] parameters; SkillEffect effect = null; foreach (Type t in Utils.GetTypesInNamespace("Assets.scripts.Skills.SkillEffects", true, typeof(SkillEffect))) { if (t.Name.Equals("Effect" + name, StringComparison.InvariantCultureIgnoreCase)) { foreach (ConstructorInfo ci in t.GetConstructors()) { parameters = new object[ci.GetParameters().Length]; bool matches = true; // pro dany konstruktor zjistit, jestli jsou jeho parametry definovane for (int i = 0; i < ci.GetParameters().Length; i++) { ParameterInfo pi = ci.GetParameters()[i]; string val; if (!info.parameters.TryGetValue(pi.Name, out val)) { matches = false; break; } else { if (pi.ParameterType == typeof(int)) { parameters[i] = Int32.Parse(val); } else if (pi.ParameterType == typeof(float)) { parameters[i] = float.Parse(val); } else if (pi.ParameterType == typeof(double)) { parameters[i] = Double.Parse(val); } else if (pi.ParameterType == typeof(bool)) { parameters[i] = Boolean.Parse(val); } else if (pi.ParameterType == typeof(string)) { parameters[i] = val; } else { throw new ArgumentException("invalid param when constructing skill effect " + pi.ParameterType + " - cant parse"); } } } // this constructor will be used if (matches) { effect = (SkillEffect)ci.Invoke(parameters); break; } } break; } } if (effect != null) { meleeSkill.AddAdditionalEffect(effect); } else { Debug.LogError("couldnt create instance of " + name + " with parameters " + info.parameters); } } } }