public static void OnScriptsCompiled(DOLEvent e, object sender, EventArgs args) { // What npctemplate should we use for the zonepoint ? ushort model; NpcTemplate zp; try{ model = (ushort)ServerProperties.Properties.ZONEPOINT_NPCTEMPLATE; zp = new NpcTemplate(GameServer.Database.SelectObjects<DBNpcTemplate>("`TemplateId` = @TemplateId", new QueryParameter("@TemplateId", model)).FirstOrDefault()); if (model <= 0 || zp == null) throw new ArgumentNullException(); } catch { return; } // processing all the ZP IList<ZonePoint> zonePoints = GameServer.Database.SelectAllObjects<ZonePoint>(); foreach (ZonePoint z in zonePoints) { if (z.SourceRegion == 0) continue; // find target region for the current zonepoint Region r = WorldMgr.GetRegion(z.TargetRegion); if (r == null) { log.Warn("Zonepoint Id (" + z.Id + ") references an inexistent target region " + z.TargetRegion + " - skipping, ZP not created"); continue; } GameNPC npc = new GameNPC(zp); npc.CurrentRegionID = z.SourceRegion; npc.X = z.SourceX; npc.Y = z.SourceY; npc.Z = z.SourceZ; npc.Name = r.Description; npc.GuildName = "ZonePoint (Open)"; if (r.IsDisabled) npc.GuildName = "ZonePoint (Closed)"; npc.AddToWorld(); } }
public L2Object spawnNpc(int id, int x, int y, int z, int h) { NpcTemplate template = this.getNpcTemplate(id); if (template == null) { Console.WriteLine("null template " + id); return(null); } L2Warrior o = new L2Warrior(); o.setTemplate(template); //switch (template._type) //{ // case NpcTemplate.L2NpcType.warrior: // case NpcTemplate.L2NpcType.zzoldagu: // case NpcTemplate.L2NpcType.herb_warrior: // case NpcTemplate.L2NpcType.boss: // o = new L2Warrior(); // ((L2Warrior)o).setTemplate(template); // break; // default: // o = new L2Citizen(); // ((L2Citizen)o).setTemplate(template); // break; //} o.X = x; o.Y = y; o.Z = z; o.Heading = h; o.SpawnX = x; o.SpawnY = y; o.SpawnZ = z; L2World.Instance.RealiseEntry(o, null, true); o.onSpawn(); return(o); }
/// <summary> /// Override Add To World to Spawn Teleporters in Circle /// And start Timer. /// </summary> /// <returns></returns> public override bool AddToWorld() { if (!base.AddToWorld()) { return(false); } // Add the Item Pad m_worldObject.X = X; m_worldObject.Y = Y; m_worldObject.Z = Z; m_worldObject.Heading = Heading; m_worldObject.Model = PortalWorldObjectModel; m_worldObject.AddToWorld(); // Add the teleporters NpcTemplate teleporters = NpcTemplateMgr.GetTemplate(PortalTeleportersTemplateID); ushort divisor = (ushort)(4096 / PortalTeleporterCount); for (int cnt = 0; cnt < PortalTeleporterCount; cnt++) { GameNPC teleporter = new GameNPC(teleporters); var tgt = GameMath.GetPointFromHeading(Position, (ushort)((Heading + (cnt * divisor)) % 4096), PortalCeremonyRange); teleporter.X = tgt.X; teleporter.Y = tgt.Y; teleporter.Z = Z; teleporter.CurrentRegion = CurrentRegion; teleporter.Heading = (ushort)((Heading + (cnt * divisor) + 2048) % 4096); m_teleporters.Add(teleporter); teleporter.AddToWorld(); } // Start Timer. m_teleportTimer = new RegionTimer(this); m_teleportTimer.Callback = new RegionTimerCallback(TeleportTimerCallback); m_teleportTimer.Start((int)(PortalTeleportInterval >> 4)); return(true); }
public static void OnScriptsCompiled(DOLEvent e, object sender, EventArgs args) { // What npctemplate should we use for the zonepoint ? ushort model; NpcTemplate zp; try { model = (ushort)ServerProperties.Properties.ZONEPOINT_NPCTEMPLATE; zp = new NpcTemplate(GameServer.Database.SelectObject<DBNpcTemplate>("TemplateId =" + model.ToString())); if (model <= 0 || zp == null) throw new ArgumentNullException(); } catch { return; } // processing all the ZP IList<ZonePoint> zonePoints = GameServer.Database.SelectAllObjects<ZonePoint>(); foreach (ZonePoint z in zonePoints) { if (z.SourceRegion == 0) continue; //find region Region r = WorldMgr.GetRegion(z.TargetRegion); GameNPC npc = new GameNPC(zp); npc.CurrentRegionID = z.SourceRegion; npc.X = z.SourceX; npc.Y = z.SourceY; npc.Z = z.SourceZ; npc.Name = r.Description; if (r.IsDisabled) npc.GuildName = "ZonePoint (Closed)"; else npc.GuildName = "ZonePoint (Open)"; npc.AddToWorld(); } }
private bool FilterByName(object obj) { NpcTemplate npcTemplate = (NpcTemplate)obj; if (FilterName.Text.Length > 0) { if (npcTemplate.Name.IndexOf(FilterName.Text, StringComparison.OrdinalIgnoreCase) == -1) { return(false); } } if (FilterLevel.Text.Length > 0) { bool textIsValid = true; for (int i = 0; i < FilterLevel.Text.Length; i++) { if (FilterLevel.Text[i] < '0' || FilterLevel.Text[i] > '9') { textIsValid = false; break; } } if (textIsValid) { int level = int.Parse(FilterLevel.Text); if (npcTemplate.Level != level) { return(false); } } } return(true); }
internal void SetNpc(int id) { if (npcs == null) { npcs = new SortedList <int, L2Npc>(); } NpcTemplate t = new NpcTemplate(new StatsSet()); //NpcTable.Instance.GetNpcTemplate(id); L2Npc npc = null; switch (t.NpcId) { case 35461: npc = new L2HideoutManager(this); break; case 35462: npc = new L2Doormen(this); break; } //npc.setTemplate(t); if (npc == null) { return; } StructureSpawn ss = StructureTable.Instance.GetSpawn(id); npc.X = ss.X; npc.Y = ss.Y; npc.Z = ss.Z; npc.Heading = ss.Heading; npcs.Add(t.NpcId, npc); }
public void Load() { _templates = new Dictionary <uint, NpcTemplate>(); _goods = new Dictionary <uint, MerchantGoods>(); using (var connection = SQLite.CreateConnection()) { _log.Info("Loading npc templates..."); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * from npcs"; command.Prepare(); using (var sqliteDataReader = command.ExecuteReader()) using (var reader = new SQLiteWrapperReader(sqliteDataReader)) { while (reader.Read()) { var template = new NpcTemplate(); template.Id = reader.GetUInt32("id"); template.Name = reader.GetString("name"); template.CharRaceId = reader.GetInt32("char_race_id"); template.NpcGradeId = (NpcGradeType)reader.GetByte("npc_grade_id"); template.NpcKindId = (NpcKindType)reader.GetByte("npc_kind_id"); template.Level = reader.GetByte("level"); template.NpcTemplateId = (NpcTemplateType)reader.GetByte("npc_template_id"); template.ModelId = reader.GetUInt32("model_id"); template.FactionId = reader.GetUInt32("faction_id"); template.SkillTrainer = reader.GetBoolean("skill_trainer", true); template.AiFileId = reader.GetInt32("ai_file_id"); template.Merchant = reader.GetBoolean("merchant", true); template.NpcNicknameId = reader.GetInt32("npc_nickname_id"); template.Auctioneer = reader.GetBoolean("auctioneer", true); template.ShowNameTag = reader.GetBoolean("show_name_tag", true); template.VisibleToCreatorOnly = reader.GetBoolean("visible_to_creator_only", true); template.NoExp = reader.GetBoolean("no_exp", true); template.PetItemId = reader.GetInt32("pet_item_id", 0); template.BaseSkillId = reader.GetInt32("base_skill_id"); template.TrackFriendship = reader.GetBoolean("track_friendship", true); template.Priest = reader.GetBoolean("priest", true); template.NpcTedencyId = reader.GetInt32("npc_tendency_id", 0); template.Blacksmith = reader.GetBoolean("blacksmith", true); template.Teleporter = reader.GetBoolean("teleporter", true); template.Opacity = reader.GetFloat("opacity"); template.AbilityChanger = reader.GetBoolean("ability_changer", true); template.Scale = reader.GetFloat("scale"); template.SightRangeScale = reader.GetFloat("sight_range_scale"); template.SightFovScale = reader.GetFloat("sight_fov_scale"); template.MilestoneId = reader.GetInt32("milestone_id", 0); template.AttackStartRangeScale = reader.GetFloat("attack_start_range_scale"); template.Aggression = reader.GetBoolean("aggression", true); template.ExpMultiplier = reader.GetFloat("exp_multiplier"); template.ExpAdder = reader.GetInt32("exp_adder"); template.Stabler = reader.GetBoolean("stabler", true); template.AcceptAggroLink = reader.GetBoolean("accept_aggro_link", true); template.RecrutingBattlefieldId = reader.GetInt32("recruiting_battle_field_id"); template.ReturnDistance = reader.GetFloat("return_distance"); template.NpcAiParamId = reader.GetInt32("npc_ai_param_id"); template.NonPushableByActor = reader.GetBoolean("non_pushable_by_actor", true); template.Banker = reader.GetBoolean("banker", true); template.AggroLinkSpecialRuleId = reader.GetInt32("aggro_link_special_rule_id"); template.AggroLinkHelpDist = reader.GetFloat("aggro_link_help_dist"); template.AggroLinkSightCheck = reader.GetBoolean("aggro_link_sight_check", true); template.Expedition = reader.GetBoolean("expedition", true); template.HonorPoint = reader.GetInt32("honor_point"); template.Trader = reader.GetBoolean("trader", true); template.AggroLinkSpecialGuard = reader.GetBoolean("aggro_link_special_guard", true); template.AggroLinkSpecialIgnoreNpcAttacker = reader.GetBoolean("aggro_link_special_ignore_npc_attacker", true); template.AbsoluteReturnDistance = reader.GetFloat("absolute_return_distance"); template.Repairman = reader.GetBoolean("repairman", true); template.ActivateAiAlways = reader.GetBoolean("activate_ai_always", true); template.Specialty = reader.GetBoolean("specialty", true); template.UseRangeMod = reader.GetBoolean("use_range_mod", true); template.NpcPostureSetId = reader.GetInt32("npc_posture_set_id"); template.MateEquipSlotPackId = reader.GetInt32("mate_equip_slot_pack_id", 0); template.MateKindId = reader.GetInt32("mate_kind_id", 0); template.EngageCombatGiveQuestId = reader.GetInt32("engage_combat_give_quest_id", 0); template.NoApplyTotalCustom = reader.GetBoolean("no_apply_total_custom", true); template.BaseSkillStrafe = reader.GetBoolean("base_skill_strafe", true); template.BaseSkillDelay = reader.GetFloat("base_skill_delay"); template.NpcInteractionSetId = reader.GetInt32("npc_interaction_set_id", 0); template.UseAbuserList = reader.GetBoolean("use_abuser_list", true); template.ReturnWhenEnterHousingArea = reader.GetBoolean("return_when_enter_housing_area", true); template.LookConverter = reader.GetBoolean("look_converter", true); template.UseDDCMSMountSkill = reader.GetBoolean("use_ddcms_mount_skill", true); template.CrowdEffect = reader.GetBoolean("crowd_effect", true); var bodyPack = reader.GetInt32("equip_bodies_id", 0); var clothPack = reader.GetInt32("equip_cloths_id", 0); var weaponPack = reader.GetInt32("equip_weapons_id", 0); var totalCustomId = reader.GetInt32("total_custom_id", 0); if (clothPack > 0) { using (var command2 = connection.CreateCommand()) { command2.CommandText = "SELECT * FROM equip_pack_cloths WHERE id=@id"; command2.Prepare(); command2.Parameters.AddWithValue("id", clothPack); using (var sqliteReader2 = command2.ExecuteReader()) using (var reader2 = new SQLiteWrapperReader(sqliteReader2)) { while (reader2.Read()) { template.Items.Headgear = reader2.GetUInt32("headgear_id"); template.Items.HeadgearGrade = reader2.GetByte("headgear_grade_id"); template.Items.Necklace = reader2.GetUInt32("necklace_id"); template.Items.NecklaceGrade = reader2.GetByte("necklace_grade_id"); template.Items.Shirt = reader2.GetUInt32("shirt_id"); template.Items.ShirtGrade = reader2.GetByte("shirt_grade_id"); template.Items.Belt = reader2.GetUInt32("belt_id"); template.Items.BeltGrade = reader2.GetByte("belt_grade_id"); template.Items.Pants = reader2.GetUInt32("pants_id"); template.Items.PantsGrade = reader2.GetByte("pants_grade_id"); template.Items.Gloves = reader2.GetUInt32("glove_id"); template.Items.GlovesGrade = reader2.GetByte("glove_grade_id"); template.Items.Shoes = reader2.GetUInt32("shoes_id"); template.Items.ShoesGrade = reader2.GetByte("shoes_grade_id"); template.Items.Bracelet = reader2.GetUInt32("bracelet_id"); template.Items.BraceletGrade = reader2.GetByte("bracelet_grade_id"); template.Items.Back = reader2.GetUInt32("back_id"); template.Items.BackGrade = reader2.GetByte("back_grade_id"); template.Items.Cosplay = reader2.GetUInt32("cosplay_id"); template.Items.CosplayGrade = reader2.GetByte("cosplay_grade_id"); template.Items.Undershirts = reader2.GetUInt32("undershirt_id"); template.Items.UndershirtsGrade = reader2.GetByte("undershirt_grade_id"); template.Items.Underpants = reader2.GetUInt32("underpants_id"); template.Items.UnderpantsGrade = reader2.GetByte("underpants_grade_id"); } } } } if (weaponPack > 0) { using (var command2 = connection.CreateCommand()) { command2.CommandText = "SELECT * FROM equip_pack_weapons WHERE id=@id"; command2.Prepare(); command2.Parameters.AddWithValue("id", weaponPack); using (var sqliteReader2 = command2.ExecuteReader()) using (var reader2 = new SQLiteWrapperReader(sqliteReader2)) { while (reader2.Read()) { template.Items.Mainhand = reader2.GetUInt32("mainhand_id"); template.Items.MainhandGrade = reader2.GetByte("mainhand_grade_id"); template.Items.Offhand = reader2.GetUInt32("offhand_id"); template.Items.OffhandGrade = reader2.GetByte("offhand_grade_id"); template.Items.Ranged = reader2.GetUInt32("ranged_id"); template.Items.RangedGrade = reader2.GetByte("ranged_grade_id"); template.Items.Musical = reader2.GetUInt32("musical_id"); template.Items.MusicalGrade = reader2.GetByte("musical_grade_id"); } } } } if (totalCustomId > 0) { using (var command2 = connection.CreateCommand()) { command2.CommandText = "SELECT * FROM total_character_customs WHERE id=@id"; command2.Prepare(); command2.Parameters.AddWithValue("id", totalCustomId); using (var sqliteReader2 = command2.ExecuteReader()) using (var reader2 = new SQLiteWrapperReader(sqliteReader2)) { while (reader2.Read()) { template.HairId = reader2.GetUInt32("hair_id"); template.ModelParams = new UnitCustomModelParams(UnitCustomModelType.Face); template.ModelParams .SetHairColorId(reader2.GetUInt32("hair_color_id")) .SetSkinColorId(reader2.GetUInt32("skin_color_id")); template.ModelParams.Face.MovableDecalAssetId = reader2.GetUInt32("face_movable_decal_asset_id"); template.ModelParams.Face.MovableDecalScale = reader2.GetFloat("face_movable_decal_scale"); template.ModelParams.Face.MovableDecalRotate = reader2.GetFloat("face_movable_decal_rotate"); template.ModelParams.Face.MovableDecalMoveX = reader2.GetInt16("face_movable_decal_move_x"); template.ModelParams.Face.MovableDecalMoveY = reader2.GetInt16("face_movable_decal_move_y"); template.ModelParams.Face.SetFixedDecalAsset(0, reader2.GetUInt32("face_fixed_decal_asset_0_id"), reader2.GetFloat("face_fixed_decal_asset_0_weight")); template.ModelParams.Face.SetFixedDecalAsset(1, reader2.GetUInt32("face_fixed_decal_asset_1_id"), reader2.GetFloat("face_fixed_decal_asset_1_weight")); template.ModelParams.Face.SetFixedDecalAsset(2, reader2.GetUInt32("face_fixed_decal_asset_2_id"), reader2.GetFloat("face_fixed_decal_asset_2_weight")); template.ModelParams.Face.SetFixedDecalAsset(3, reader2.GetUInt32("face_fixed_decal_asset_3_id"), reader2.GetFloat("face_fixed_decal_asset_3_weight")); template.ModelParams.Face.DiffuseMapId = reader2.GetUInt32("face_diffuse_map_id"); template.ModelParams.Face.NormalMapId = reader2.GetUInt32("face_normal_map_id"); template.ModelParams.Face.EyelashMapId = reader2.GetUInt32("face_eyelash_map_id"); template.ModelParams.Face.LipColor = reader2.GetUInt32("lip_color"); template.ModelParams.Face.LeftPupilColor = reader2.GetUInt32("left_pupil_color"); template.ModelParams.Face.RightPupilColor = reader2.GetUInt32("right_pupil_color"); template.ModelParams.Face.EyebrowColor = reader2.GetUInt32("eyebrow_color"); reader2.GetBytes("modifier", 0, template.ModelParams.Face.Modifier, 0, 128); template.ModelParams.Face.MovableDecalWeight = reader2.GetFloat("face_movable_decal_weight"); template.ModelParams.Face.NormalMapWeight = reader2.GetFloat("face_normal_map_weight"); template.ModelParams.Face.DecoColor = reader2.GetUInt32("deco_color"); } } } } else { template.ModelParams = new UnitCustomModelParams(UnitCustomModelType.Skin); } if (template.NpcPostureSetId > 0) { using (var command2 = connection.CreateCommand()) { command2.CommandText = "SELECT * FROM npc_postures WHERE npc_posture_set_id=@id"; command2.Prepare(); command2.Parameters.AddWithValue("id", template.NpcPostureSetId); using (var sqliteReader2 = command2.ExecuteReader()) using (var reader2 = new SQLiteWrapperReader(sqliteReader2)) { if (reader2.Read()) { template.AnimActionId = reader2.GetUInt32("anim_action_id"); } } } } using (var command2 = connection.CreateCommand()) { command2.CommandText = "SELECT * FROM item_body_parts WHERE model_id = @model_id"; command2.Prepare(); command2.Parameters.AddWithValue("model_id", template.ModelId); using (var sqliteReader2 = command2.ExecuteReader()) using (var reader2 = new SQLiteWrapperReader(sqliteReader2)) { while (reader2.Read()) { var itemId = reader2.GetUInt32("item_id", 0); var slot = reader2.GetInt32("slot_type_id") - 23; template.BodyItems[slot] = itemId; } } } if (template.CharRaceId > 0) { using (var command2 = connection.CreateCommand()) { command2.CommandText = "SELECT char_race_id, char_gender_id FROM characters WHERE model_id = @model_id"; command2.Prepare(); command2.Parameters.AddWithValue("model_id", template.ModelId); using (var sqliteReader2 = command2.ExecuteReader()) using (var reader2 = new SQLiteWrapperReader(sqliteReader2)) { if (reader2.Read()) { template.Race = reader2.GetByte("char_race_id"); template.Gender = reader2.GetByte("char_gender_id"); } } } } _templates.Add(template.Id, template); } } } using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM unit_modifiers WHERE owner_type='Npc'"; command.Prepare(); using (var sqliteDataReader = command.ExecuteReader()) using (var reader = new SQLiteWrapperReader(sqliteDataReader)) { while (reader.Read()) { var npcId = reader.GetUInt32("owner_id"); if (!_templates.ContainsKey(npcId)) { continue; } var npc = _templates[npcId]; var template = new BonusTemplate(); template.Attribute = (UnitAttribute)reader.GetByte("unit_attribute_id"); template.ModifierType = (UnitModifierType)reader.GetByte("unit_modifier_type_id"); template.Value = reader.GetInt32("value"); template.LinearLevelBonus = reader.GetInt32("linear_level_bonus"); npc.Bonuses.Add(template); } } } using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM npc_initial_buffs"; command.Prepare(); using (var reader = new SQLiteWrapperReader(command.ExecuteReader())) { while (reader.Read()) { var id = reader.GetUInt32("npc_id"); var buffId = reader.GetUInt32("buff_id"); if (!_templates.ContainsKey(id)) { continue; } var template = _templates[id]; template.Buffs.Add(buffId); } } } using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM merchants"; command.Prepare(); using (var reader = new SQLiteWrapperReader(command.ExecuteReader())) { while (reader.Read()) { var id = reader.GetUInt32("npc_id"); if (!_templates.ContainsKey(id)) { continue; } var template = _templates[id]; template.MerchantPackId = reader.GetUInt32("merchant_pack_id"); } } } _log.Info("Loaded {0} npc templates", _templates.Count); _log.Info("Loading merchant packs..."); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM merchant_goods"; command.Prepare(); using (var reader = new SQLiteWrapperReader(command.ExecuteReader())) { while (reader.Read()) { var id = reader.GetUInt32("merchant_pack_id"); if (!_goods.ContainsKey(id)) { _goods.Add(id, new MerchantGoods(id)); } var itemId = reader.GetUInt32("item_id"); var grade = reader.GetByte("grade_id"); if (_goods[id].Items.ContainsKey(itemId)) { if (_goods[id].Items[itemId].IndexOf(grade) > -1) { continue; } _goods[id].Items[itemId].Add(grade); } else { _goods[id].Items.Add(itemId, new List <byte> { grade }); } } } } _log.Info("Loaded {0} merchant packs", _goods.Count); } }
public L2Doormen(int objectId, NpcTemplate template, HideoutTemplate hideout) : base(objectId, template) { _hideout = (Hideout)hideout; StructureControlled = true; }
public L2Warrior(int objectId, NpcTemplate template, L2Spawn spawn) : base(objectId, template, spawn) { }
public L2Pet(int objectId, NpcTemplate template) : base(objectId, template) { ObjectSummonType = 2; Name = string.Empty; Inventory = new PetInventory(this); }
public L2Summon(int objectId, NpcTemplate template) : base(objectId, template) { ObjectSummonType = 1; }
public L2Spawn(NpcTemplate template, IdFactory idFactory, SpawnTable spawnTable) { Template = template ?? throw new ArgumentNullException(nameof(template)); _idFactory = idFactory; _spawnTable = spawnTable; }
private static void ParseNpcTemplates() { NpcTemplates = new Dictionary <int, Dictionary <int, NpcTemplate> >(); DataCenter dc = DCT.GetDataCenter(); int count = 0; foreach (var dcObject in dc.GetMainObjectsByName("NpcData")) { var zoneData = dc.GetValues(dcObject); int huntingZoneId = int.Parse(zoneData["huntingZoneId"].ToString()); NpcTemplates.Add(huntingZoneId, new Dictionary <int, NpcTemplate>()); foreach (var data in (List <Dictionary <string, object> >)zoneData["Template"]) { NpcTemplate template = new NpcTemplate(); template.HuntingZoneId = huntingZoneId; template.Id = int.Parse(data["id"].ToString()); template.Scale = data.ContainsKey("scale") ? float.Parse(data["scale"].ToString()) : 1f; if (data.ContainsKey("size") && data["size"].ToString().Length > 0) { template.Size = ParseEnum <NpcSize>(data["size"]); } else { template.Size = NpcSize.Medium; } int shapeId = int.Parse(data["shapeId"].ToString()); template.Shape = Shapes[shapeId]; try { template.Level = int.Parse(((List <Dictionary <string, object> >)data["Stat"])[0]["level"].ToString()); } catch { template.Level = 1; } template.Name = null; template.Title = null; if (NpcNames.ContainsKey(huntingZoneId) && NpcNames[huntingZoneId].ContainsKey(template.Id)) { template.Name = NpcNames[huntingZoneId][template.Id].Key; template.Title = NpcNames[huntingZoneId][template.Id].Value; } //resourceSize //resourceType //class if (data.ContainsKey("gender") && data["gender"].ToString().Length > 0) { try { template.Gender = ParseEnum <Gender>(data["gender"]); } catch { //Nothing } } if (data.ContainsKey("race") && data["race"].ToString().Length > 0) { template.Race = data["race"].ToString(); } else { template.Race = null; } if (data.ContainsKey("parentId")) { template.ParentId = int.Parse(data["parentId"].ToString()); } //despawnScriptId //basicActionId if (data.ContainsKey("collideOnMove")) { template.CollideOnMove = bool.Parse(data["collideOnMove"].ToString()); } if (data.ContainsKey("cameraPenetratable")) { template.CameraPenetratable = bool.Parse(data["cameraPenetratable"].ToString()); } if (data.ContainsKey("isHomunculus")) { template.IsHomunculus = bool.Parse(data["isHomunculus"].ToString()); } //deathShapeId if (data.ContainsKey("dontTurn")) { template.DontTurn = bool.Parse(data["dontTurn"].ToString()); } if (data.ContainsKey("villager")) { template.IsVillager = bool.Parse(data["villager"].ToString()); } if (data.ContainsKey("isObjectNpc")) { template.IsObject = bool.Parse(data["isObjectNpc"].ToString()); } if (data.ContainsKey("elite")) { template.IsElite = bool.Parse(data["elite"].ToString()); } if (data.ContainsKey("unionElite")) { template.IsUnionElite = bool.Parse(data["unionElite"].ToString()); } if (data.ContainsKey("isFreeNamed")) { template.IsFreeNamed = bool.Parse(data["isFreeNamed"].ToString()); } if (data.ContainsKey("showAggroTarget")) { template.ShowAggroTarget = bool.Parse(data["showAggroTarget"].ToString()); } //spawnScriptId if (data.ContainsKey("isSpirit")) { template.IsSpirit = bool.Parse(data["isSpirit"].ToString()); } if (data.ContainsKey("isWideBroadcaster")) { template.IsWideBroadcaster = bool.Parse(data["isWideBroadcaster"].ToString()); } //villagerVolumeActiveRange //villagerVolumeHalfHeight //villagerVolumeInteractionDist //villagerVolumeOffset if (data.ContainsKey("showShorttermTarget")) { template.ShowShorttermTarget = bool.Parse(data["showShorttermTarget"].ToString()); } //__value__ //cannotPassThrough //vehicleEx //NamePlate //VehicleType //SeatList //Shader //DeathEffect //Stat (Level) //AltAnimation //Emoticon if (!NpcTemplates[huntingZoneId].ContainsKey(template.Id)) { NpcTemplates[huntingZoneId].Add(template.Id, template); } else { Console.WriteLine("Dublicate NPC template: {0},{1}", huntingZoneId, template.Id); } count++; } } Console.WriteLine("Loaded {0} npc templates...", count); }
private static void NpcTemplateExport() { List <NpcTemplate> templates = new List <NpcTemplate>(); int BytesOfSeparation = 7860; int ID_Offset = 0x0107b448; var YBiBuffer = YBi.Decrypt(File.ReadAllBytes(DataPath + "YBi.cfg")); List <byte[]> list = new List <byte[]>(); lock (YBiBuffer) { while (BitConverter.ToInt32(YBiBuffer, ID_Offset) != 0) { long itemId = BitConverter.ToInt64(YBiBuffer, ID_Offset); byte[] temp = new byte[BytesOfSeparation]; Buffer.BlockCopy(YBiBuffer, ID_Offset, temp, 0, BytesOfSeparation); list.Add(temp); ID_Offset += BytesOfSeparation; } } lock (list) { try { foreach (byte[] data in list) { lock (data) { using (MemoryStream Stream = new MemoryStream(data)) { byte[] ids = new byte[4]; Stream.Read(ids, 0, ids.Length); byte[] names = new byte[64]; Stream.Read(names, 0, names.Length); Stream.Position += 2; byte[] levels = new byte[2]; Stream.Read(levels, 0, levels.Length); byte[] hps = new byte[4]; Stream.Read(hps, 0, hps.Length); byte[] descs = new byte[1024]; Stream.Read(descs, 0, descs.Length); byte[] choice1 = new byte[4]; Stream.Read(choice1, 0, choice1.Length); byte[] choice2 = new byte[4]; Stream.Read(choice2, 0, choice2.Length); byte[] choice3 = new byte[4]; Stream.Read(choice3, 0, choice3.Length); byte[] choice4 = new byte[4]; Stream.Read(choice4, 0, choice4.Length); int NpcId = BitConverter.ToInt32(ids, 0); string NpcName = Encoding.GetEncoding(EncodingName).GetString(names).Replace("\0", ""); int NpcLevel = BitConverter.ToInt16(levels, 0); int NpcHp = BitConverter.ToInt32(hps, 0); string NpcDesc = Encoding.GetEncoding(EncodingName).GetString(descs).Replace("\0", ""); int NpcChoice1 = BitConverter.ToInt32(choice1, 0); int NpcChoice2 = BitConverter.ToInt32(choice2, 0); int NpcChoice3 = BitConverter.ToInt32(choice3, 0); int NpcChoice4 = BitConverter.ToInt32(choice4, 0); Log.Debug("-----------------------------------------------------"); Log.Debug("NpcId = {0}", NpcId); Log.Debug("NpcName = {0}", NpcName); Log.Debug("NpcLevel = {0}", NpcLevel); Log.Debug("NpcHp = {0}", NpcHp); Log.Debug("NpcDesc = {0}", NpcDesc); Log.Debug("NpcChoice1 = {0}", NpcChoice1); Log.Debug("NpcChoice2 = {0}", NpcChoice2); Log.Debug("NpcChoice3 = {0}", NpcChoice3); Log.Debug("NpcChoice4 = {0}", NpcChoice4); Log.Debug("-----------------------------------------------------"); using (var entity = new PublicDbEntities()) { var dbdata = entity.TBL_XWWL_NPC.Where(v => v.FLD_PID == NpcId).FirstOrDefault(); if (dbdata != null) { NpcTemplate template = new NpcTemplate() { ID = NpcId, Name = NpcName, HealthPoint = NpcHp, Attack = (int)dbdata.FLD_AT, Defense = (int)dbdata.FLD_DF, Npc = (NpcId < 10000 && NpcId > 0) ? 1 : 0, Level = (int)dbdata.FLD_LEVEL, Exp = (int)dbdata.FLD_EXP, Auto = (int)dbdata.FLD_AUTO, Boss = dbdata.FLD_BOSS, }; templates.Add(template); Log.Debug("Npc NpcId = {0} Name = {1}", template.ID, template.Name); } else { Log.Debug("No db data for Npc id = {0}", NpcId); } } } } } } catch (Exception ex) { Log.ErrorException("NpcTemplateExport:", ex); } } /*using (var file = File.Create("Data/npcs.bin")) * { * Serializer.SerializeWithLengthPrefix<List<NpcTemplate>>(file, templates, PrefixStyle.Fixed32); * }*/ }
private static void ParseFor(NpcTemplate npcTemplate) { if (npcTemplate.Level < 1 //|| npcTemplate.Level > 12 || npcTemplate.IsObject || npcTemplate.IsVillager) { return; } int fullId = npcTemplate.FullId; lock (DropLock) { if (Drop.ContainsKey(fullId)) { return; } Drop.Add(fullId, new List <int>()); } int page = 1; string name = ""; while (true) { string npcHtml = ""; if (page == 1) { npcHtml = Utils.LoadPage("http://www.teratome.com/npc/" + fullId); } else { npcHtml = Utils.LoadPage("http://www.teratome.com/npc/" + fullId + "/" + name + "/detail/page/" + page + "/tab/drops"); } if (npcHtml.Length == 0) { return; } foreach (Match itemMatch in Regex.Matches(npcHtml, "<tr data-href=\"/item/([0-9]+)/")) { Drop[fullId].Add(int.Parse(itemMatch.Groups[1].Value)); } if (name.Length == 0) { Match nameMatch = Regex.Match( npcHtml, "<link href=\"http://www.teratome.com/npc/" + fullId + "/([^\"]+)\""); name = nameMatch.Groups[1].Value; } Match match = Regex.Match(npcHtml, "<a class=\"link-next\" href=\"#drops;page:([0-9]+)\">Next"); if (!match.Success) { return; } page = int.Parse(match.Groups[1].Value); } }
public void Initialize() { FileInfo file = new FileInfo(@"scripts\npc_vid.txt"); using (StreamReader sreader = file.OpenText()) { while (!sreader.EndOfStream) { string line = sreader.ReadLine(); if (line.Length == 0 || line.StartsWith("#")) { continue; } string[] pt = line.Split('\t'); NpcVid vid = new NpcVid(); vid.cl = pt[0]; for (byte ord = 1; ord < pt.Length; ord++) { string parameter = pt[ord]; string value = parameter.Substring(parameter.IndexOf('{') + 1); value = value.Remove(value.Length - 1); switch (parameter.Split('{')[0].ToLower()) { case "coll": vid.radius = Convert.ToDouble(value.Split(' ')[0]); vid.height = Convert.ToDouble(value.Split(' ')[1]); break; case "spd": vid.minspd = Convert.ToInt32(value.Split(' ')[0]); vid.maxspd = Convert.ToInt32(value.Split(' ')[1]); break; } } npcVids.Add(vid.cl, vid); } } file = new FileInfo(@"scripts\npcdata.txt"); using (StreamReader sreader = file.OpenText()) { while (!sreader.EndOfStream) { string line = sreader.ReadLine(); if (line.Length == 0 || line.StartsWith("#")) { continue; } string[] pt = line.Split('\t'); NpcTemplate template = new NpcTemplate(); template.NpcId = Convert.ToInt32(pt[0]); try { template.Category = (TObjectCategory)Enum.Parse(typeof(TObjectCategory), pt[1]); } catch (Exception) { CLogger.error("Npc category was not found " + pt[1]); continue; } try { if (npcVids.ContainsKey(pt[2].Split('.')[1])) { NpcVid vid = npcVids[pt[2].Split('.')[1]]; template.CollisionRadius = vid.radius; template.CollisionHeight = vid.height; } } catch (Exception) { Console.WriteLine("err2 in #" + template.NpcId + " '" + pt[2] + "'"); } for (byte ord = 3; ord < pt.Length; ord++) { string parameter = pt[ord]; string value = ""; if (parameter.Length == 0) { continue; } try { value = parameter.Substring(parameter.IndexOf('{') + 1); value = value.Remove(value.Length - 1); } catch (Exception) { Console.WriteLine("err in #" + template.NpcId + " '" + parameter + "'"); } switch (parameter.Split('{')[0].ToLower()) { case "level": template.Level = Convert.ToByte(value); break; case "exp": template.exp = Convert.ToInt64(value); break; case "ex_crt_effect": template.ex_crt_effect = Convert.ToInt32(value); break; case "unique": template.unique = Convert.ToInt32(value); break; case "s_npc_prop_hp_rate": template.s_npc_prop_hp_rate = Convert.ToDouble(value); break; case "race": template.Race = (TObjectRace)Enum.Parse(typeof(TObjectRace), value); break; case "sex": template.Sex = (TObjectSex)Enum.Parse(typeof(TObjectSex), value); break; case "skill_list": template.setNpcSkills(value); break; case "slot_chest": template.slot_chest = value; break; case "slot_rhand": template.slot_rhand = value; break; case "slot_lhand": template.slot_lhand = value; break; case "hit_time_factor": template.hit_time_factor = Convert.ToDouble(value); break; case "hit_time_factor_skill": template.hit_time_factor_skill = Convert.ToDouble(value.Split(' ')[0]); break; case "str": template.Str = Convert.ToInt32(value); break; case "int": template.Int = Convert.ToInt32(value); break; case "dex": template.Dex = Convert.ToInt32(value); break; case "wit": template.Wit = Convert.ToInt32(value); break; case "con": template.Con = Convert.ToInt32(value); break; case "men": template.Men = Convert.ToInt32(value); break; case "org_hp": template.org_hp = Convert.ToDouble(value); break; case "org_hp_regen": template.org_hp_regen = Convert.ToDouble(value); break; case "org_mp": template.org_mp = Convert.ToDouble(value); break; case "org_mp_regen": template.org_mp_regen = Convert.ToDouble(value); break; case "base_attack_type": template.base_attack_type = (TObjectBaseAttackType)Enum.Parse(typeof(TObjectBaseAttackType), value); break; case "base_attack_range": template.base_attack_range = Convert.ToInt32(value); break; case "base_damage_range": // template.Men = Convert.ToInt32(value); break; case "base_rand_dam": template.base_rand_dam = Convert.ToInt32(value); break; case "base_physical_attack": template.base_physical_attack = Convert.ToDouble(value); break; case "base_critical": template.base_critical = Convert.ToInt32(value); break; case "physical_hit_modify": template.physical_hit_modify = Convert.ToDouble(value); break; case "base_attack_speed": template.base_attack_speed = Convert.ToInt32(value); break; case "base_reuse_delay": template.base_reuse_delay = Convert.ToInt32(value); break; case "base_magic_attack": template.base_magic_attack = Convert.ToDouble(value); break; case "base_defend": template.base_defend = Convert.ToDouble(value); break; case "base_magic_defend": template.base_magic_defend = Convert.ToDouble(value); break; case "base_attribute_attack": // template.physical_hit_modify = Convert.ToDouble(value); break; case "base_attribute_defend": // template.physical_hit_modify = Convert.ToDouble(value); break; case "physical_avoid_modify": template.physical_avoid_modify = Convert.ToDouble(value); break; case "shield_defense_rate": template.shield_defense_rate = Convert.ToInt32(value); break; case "shield_defense": template.shield_defense = Convert.ToDouble(value); break; case "safe_height": template.safe_height = Convert.ToInt32(value); break; case "soulshot_count": template.soulshot_count = Convert.ToInt32(value); break; case "spiritshot_count": template.spiritshot_count = Convert.ToInt32(value); break; case "clan": template.clan = value; break; case "clan_help_range": template.clan_help_range = Convert.ToInt32(value); break; case "undying": template.undying = Convert.ToInt32(value); break; case "can_be_attacked": template.can_be_attacked = Convert.ToInt32(value); break; case "corpse_time": template.corpse_time = Convert.ToInt32(value); break; case "no_sleep_mode": template.no_sleep_mode = Convert.ToInt32(value); break; case "agro_range": template.agro_range = Convert.ToInt32(value); break; case "passable_door": template.passable_door = Convert.ToInt32(value); break; case "can_move": template.can_move = Convert.ToInt32(value); break; case "flying": template.flying = Convert.ToInt32(value); break; case "has_summoner": template.has_summoner = Convert.ToInt32(value); break; case "targetable": template.targetable = Convert.ToInt32(value); break; case "show_name_tag": template.show_name_tag = Convert.ToInt32(value); break; case "event_flag": template.event_flag = Convert.ToInt32(value); break; case "unsowing": template.unsowing = Convert.ToInt32(value); break; case "private_respawn_log": template.private_respawn_log = Convert.ToInt32(value); break; case "acquire_exp_rate": template.acquire_exp_rate = Convert.ToDouble(value); break; case "acquire_sp": template.acquire_sp = (int)Convert.ToDouble(value); break; case "acquire_rp": template.acquire_rp = (int)Convert.ToDouble(value); break; case "fake_class_id": template.fake_class_id = Convert.ToInt32(value); break; } } _npcs.Add(template.NpcId, template); } } XElement xml = XElement.Parse(File.ReadAllText(@"scripts\dropdata.xml")); XElement ex = xml.Element("list"); int dropitems = 0; foreach (var m in ex.Elements()) { if (m.Name == "npc") { NpcTemplate template = _npcs[int.Parse(m.Attribute("id").Value)]; foreach (var stp in m.Elements()) { switch (stp.Name.LocalName) { case "drop": { if (template.DropData == null) { template.DropData = new DropContainer(); } foreach (var boxes in stp.Elements()) { if (boxes.Name == "box") { DropBox box = new DropBox(); box.rate = double.Parse(boxes.Attribute("rate").Value); foreach (var items in boxes.Elements()) { if (items.Name == "item") { DropItem item = new DropItem(); item.id = int.Parse(items.Attribute("id").Value); item.min = long.Parse(items.Attribute("min").Value); item.max = long.Parse(items.Attribute("max").Value); item.rate = double.Parse(items.Attribute("rate").Value); item.template = ItemTable.getInstance().getItem(item.id); box.items.Add(item); dropitems++; } } template.DropData.multidrop.Add(box); } } } break; case "drop_ex": { if (template.DropData == null) { template.DropData = new DropContainer(); } foreach (var boxes in stp.Elements()) { if (boxes.Name == "box") { DropBox box = new DropBox(); box.rate = double.Parse(boxes.Attribute("rate").Value); foreach (var items in boxes.Elements()) { if (items.Name == "item") { DropItem item = new DropItem(); item.id = int.Parse(items.Attribute("id").Value); item.min = long.Parse(items.Attribute("min").Value); item.max = long.Parse(items.Attribute("max").Value); item.rate = double.Parse(items.Attribute("rate").Value); item.template = ItemTable.getInstance().getItem(item.id); box.items.Add(item); dropitems++; } } template.DropData.multidrop_ex.Add(box); } } } break; case "spoil": { if (template.DropData == null) { template.DropData = new DropContainer(); } foreach (var boxes in stp.Elements()) { if (boxes.Name == "item") { DropItem item = new DropItem(); item.id = int.Parse(boxes.Attribute("id").Value); item.min = long.Parse(boxes.Attribute("min").Value); item.max = long.Parse(boxes.Attribute("max").Value); item.rate = double.Parse(boxes.Attribute("rate").Value); item.template = ItemTable.getInstance().getItem(item.id); template.DropData.spoil.Add(item); dropitems++; } } } break; case "qdrop": { if (template.DropData == null) { template.DropData = new DropContainer(); } foreach (var boxes in stp.Elements()) { if (boxes.Name == "item") { DropItem item = new DropItem(); item.id = int.Parse(boxes.Attribute("id").Value); item.min = long.Parse(boxes.Attribute("min").Value); item.max = long.Parse(boxes.Attribute("max").Value); item.rate = double.Parse(boxes.Attribute("rate").Value); item.template = ItemTable.getInstance().getItem(item.id); template.DropData.qdrop.Add(item); dropitems++; } } } break; } } } } GC.Collect(); GC.WaitForPendingFinalizers(); CLogger.info("NpcTable: loaded #" + _npcs.Count + " NPC, #" + npcVids.Count + " VIDs, " + dropitems + " drop items."); }
private static void OnNpcSpawned(NpcTemplate template, Npc npc) { npc.Actions.Add(new NpcPetExchangeAction()); npc.Actions.Add(new NpcPetDropCollectAction()); }
public L2Spawn(NpcTemplate template) { Template = template ?? throw new ArgumentNullException(nameof(template)); }
public L2Warrior(SpawnTable spawnTable, int objectId, NpcTemplate template, L2Spawn spawn) : base(spawnTable, objectId, template, spawn) { }
public L2Warrior(int objectId, NpcTemplate template) : base(objectId, template) { }
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); } }
public void WriteTemplateFromNode(XmlNode innerData, NpcTemplate npc) { if (innerData.Attributes["name"] != null && innerData.Attributes["val"] != null) { switch (innerData.Attributes["name"].Value) { case "radius": npc.CollisionRadius = GetDouble(innerData); break; case "height": npc.CollisionHeight = GetDouble(innerData); break; case "rHand": npc.RHand = GetInt(innerData); break; case "lHand": npc.LHand = GetInt(innerData); break; case "type": npc.Type = GetString(innerData); break; case "exp": npc.Exp = GetInt(innerData); break; case "sp": npc.Sp = GetInt(innerData); break; case "hp": npc.Hp = GetDouble(innerData); break; case "mp": npc.Mp = GetDouble(innerData); break; case "hpRegen": npc.BaseHpReg = GetDouble(innerData); break; case "mpRegen": npc.BaseMpReg = GetDouble(innerData); break; case "pAtk": npc.BasePAtk = GetDouble(innerData); break; case "pDef": npc.BasePDef = GetDouble(innerData); break; case "mAtk": npc.BaseMAtk = GetDouble(innerData); break; case "mDef": npc.BaseMDef = GetDouble(innerData); break; case "crit": npc.BaseCritRate = GetInt(innerData); break; case "atkSpd": npc.BasePAtkSpd = GetInt(innerData); break; case "str": npc.BaseStr = GetInt(innerData); break; case "int": npc.BaseInt = GetInt(innerData); break; case "dex": npc.BaseDex = GetInt(innerData); break; case "wit": npc.BaseWit = GetInt(innerData); break; case "con": npc.BaseCon = GetInt(innerData); break; case "men": npc.BaseMen = GetInt(innerData); break; case "corpseTime": npc.CorpseTime = GetInt(innerData); break; case "walkSpd": npc.BaseWalkSpd = GetInt(innerData); break; case "runSpd": npc.BaseRunSpd = GetInt(innerData); break; case "dropHerbGroup": npc.DropHerbGroup = GetInt(innerData); break; case "": break; } string DataValue = innerData.Attributes["val"].Value; } //if (innerData.Name == "drops") //{ // string type = set.GetString("type"); // bool isRaid = type.EqualsIgnoreCase("L2RaidBoss") || type.EqualsIgnoreCase("L2GrandBoss"); // List<DropCategory> drops = new List<DropCategory>(); // foreach (XmlNode dropCat in innerData.ChildNodes) // { // if ("category".EqualsIgnoreCase(dropCat.Name)) // { // attrs = dropCat.Attributes; // DropCategory category = new DropCategory(Int32.Parse(attrs.GetNamedItem("id").Value)); // foreach (XmlNode item in dropCat.ChildNodes) // { // if ("drop".EqualsIgnoreCase(item.Name)) // { // attrs = item.Attributes; // DropData data = new DropData(); // data.SetItemId(Int32.Parse(attrs.GetNamedItem("itemid").Value)); // data.SetMinDrop(Int32.Parse(attrs.GetNamedItem("min").Value)); // data.SetMaxDrop(Int32.Parse(attrs.GetNamedItem("max").Value)); // data.SetChance(Int32.Parse(attrs.GetNamedItem("chance").Value)); // //TODO: warning undefined itemId // //if (ItemTable.getInstance().getTemplate(data.GetItemId()) == null) // //{ // // Log.Warning("Droplist data for undefined itemId: " + data.getItemId()); // // continue; // //} // category.AddDropData(data, isRaid); // } // } // drops.Add(category); // } // } // set.Set("drops", drops); //} }