public virtual void SaveIntoDatabase() { DBNpcTemplate tmp = GameServer.Database.FindObjectByKey<DBNpcTemplate>(TemplateId); bool add = false; if (tmp == null) { tmp = new DBNpcTemplate(); add = true; } if (TemplateId == 0) tmp.TemplateId = GetNextFreeTemplateId(); else tmp.TemplateId = TemplateId; tmp.TranslationId = TranslationId; tmp.AggroLevel = AggroLevel; tmp.AggroRange = AggroRange; tmp.BlockChance = BlockChance; tmp.BodyType = BodyType; tmp.Charisma = Charisma; tmp.ClassType = ClassType; tmp.Constitution = Constitution; tmp.Dexterity = Dexterity; tmp.Empathy = Empathy; tmp.EquipmentTemplateID = EquipmentTemplateID; tmp.ItemsListTemplateID = ItemsListTemplateID; tmp.EvadeChance = EvadeChance; tmp.Flags = Flags; tmp.GuildName = GuildName; tmp.ExamineArticle = ExamineArticle; tmp.MessageArticle = MessageArticle; tmp.Intelligence = Intelligence; tmp.LeftHandSwingChance = LeftHandSwingChance; tmp.Level = Level; tmp.MaxDistance = MaxDistance; tmp.MaxSpeed = MaxSpeed; tmp.MeleeDamageType = (byte)MeleeDamageType; tmp.Model = Model; tmp.Name = Name; tmp.Suffix = Suffix; tmp.ParryChance = ParryChance; tmp.Piety = Piety; tmp.Quickness = Quickness; tmp.Size = Size; tmp.Strength = Strength; tmp.TetherRange = TetherRange; if( m_abilities != null && m_abilities.Count > 0 ) { string serializedAbilities = ""; foreach ( Ability npcAbility in m_abilities ) { if ( npcAbility != null ) if ( serializedAbilities.Length > 0 ) serializedAbilities += ";"; serializedAbilities += npcAbility.Name + "|" + npcAbility.Level; } tmp.Abilities = serializedAbilities; } if ( m_spells != null && m_spells.Count > 0 ) { string serializedSpells = ""; foreach ( Spell npcSpell in m_spells ) { if ( npcSpell != null ) if ( serializedSpells.Length > 0 ) serializedSpells += ";"; serializedSpells += npcSpell.ID; } tmp.Spells = serializedSpells; } if ( m_styles != null && m_styles.Count > 0 ) { string serializedStyles = ""; foreach ( Style npcStyle in m_styles ) { if ( npcStyle != null ) if ( serializedStyles.Length > 0 ) serializedStyles += ";"; serializedStyles += npcStyle.ID + "|" + npcStyle.ClassID; } tmp.Styles = serializedStyles; } if (add) GameServer.Database.AddObject(tmp); else GameServer.Database.SaveObject(tmp); }
/// <summary> /// Constructs a new NpcTemplate /// </summary> /// <param name="data">The source npc template data</param> public NpcTemplate(DBNpcTemplate data) { if (data == null) throw new ArgumentNullException("data"); m_templateId = data.TemplateId; m_translationId = data.TranslationId; m_name = data.Name; m_suffix = data.Suffix; m_classType = data.ClassType; m_guildName = data.GuildName; m_examineArticle = data.ExamineArticle; m_messageArticle = data.MessageArticle; m_model = data.Model; m_size = data.Size; if (m_size == null) m_size = "50"; m_level = data.Level; if (m_level == null) m_level = "0"; m_equipmentTemplateID = data.EquipmentTemplateID; m_itemsListTemplateID = data.ItemsListTemplateID; m_maxSpeed = data.MaxSpeed; m_parryChance = data.ParryChance; m_evadeChance = data.EvadeChance; m_blockChance = data.BlockChance; m_leftHandSwingChance = data.LeftHandSwingChance; m_strength = data.Strength; m_constitution = data.Constitution; m_dexterity = data.Dexterity; m_quickness = data.Quickness; m_intelligence = data.Intelligence; m_piety = data.Piety; m_charisma = data.Charisma; m_empathy = data.Empathy; //Time to add Spells/Styles and Abilties to the templates m_abilities = new ArrayList(); m_spelllines = new ArrayList(); m_spells = new ArrayList(); //Adding the spells to an Arraylist here if (data.Spells != null && data.Spells.Length > 0) { string[] spells = data.Spells.Split(';'); for (int k = 0; k < spells.Length; k++) { int id = int.Parse(spells[k]); Spell sp = SkillBase.GetSpellByID(id); if (sp != null) m_spells.Add(sp); else log.Error("Tried to load a null spell into NPC template " + m_templateId + " spell ID: " + id); } } // Adding Style list to Template NPC m_styles = new ArrayList(); if (data.Styles != null && data.Styles.Length > 0) { string[] styles = data.Styles.Split(';'); for (int i = 0; i < styles.Length; i++) { if (styles[i].Trim().Length == 0) continue; string[] styleAndClass = styles[i].Split('|'); if (styleAndClass.Length != 2) continue; string stylePart = styleAndClass[0].Trim(); string classPart = styleAndClass[1].Trim(); if (stylePart.Length == 0 || classPart.Length == 0) continue; int styleID = int.Parse(stylePart); int classID = int.Parse(classPart); Style style = SkillBase.GetStyleByID(styleID, classID); m_styles.Add(style); } } //Adding Abilities to Template NPC. //Certain Abilities have levels will need to fix that down the road. -Batlas if (data.Abilities != null && data.Abilities.Length > 0) { foreach (string splitab in data.Abilities.SplitCSV()) { string[] ab = splitab.Split('|'); if (splitab.Trim().Length == 0) continue; int id = 1; if (ab.Length>1) id = int.Parse(ab[1]); Ability abil = SkillBase.GetAbility(ab[0], id); if (abil != null) m_abilities.Add(abil); } } m_flags = data.Flags; m_meleeDamageType = (eDamageType)data.MeleeDamageType; if (data.MeleeDamageType == 0) m_meleeDamageType = eDamageType.Slash; m_inventory = data.EquipmentTemplateID; m_aggroLevel = data.AggroLevel; m_aggroRange = data.AggroRange; m_race = (ushort)data.Race; m_bodyType = (ushort)data.BodyType; m_maxdistance = data.MaxDistance; m_tetherRange = data.TetherRange; m_visibleActiveWeaponSlot = data.VisibleWeaponSlots; m_replaceMobValues = data.ReplaceMobValues; }
private static void CheckNPCTemplate(int templateID, string classType, string name, string guild, string model, string inventory, string merchantListID) { NpcTemplate template = NpcTemplateMgr.GetTemplate(templateID); if (template == null) { DBNpcTemplate dbTemplate = new DBNpcTemplate { Name = name, TemplateId = templateID, ClassType = classType, GuildName = guild, Model = model, Size = "50", Level = "50", ItemsListTemplateID = merchantListID, EquipmentTemplateID = inventory, PackageID = "Housing" }; template = new NpcTemplate(dbTemplate); template.SaveIntoDatabase(); NpcTemplateMgr.AddTemplate(template); } }