public InteractiveObject(Map map, InteractiveSpawn spawn) { Spawn = spawn; Position = new ObjectPosition(map, spawn.CellId); GenerateSkills(); }
public InteractiveSpawn Map(InteractiveSpawn spawn, InteractiveSpawnSkills binding, InteractiveSkillRecord skill) { InteractiveSpawn result; if (spawn == null) { result = this.m_current; } else { if (this.m_current != null && this.m_current.Id == spawn.Id) { if (binding.InteractiveSpawnId == this.m_current.Id && binding.SkillId == skill.Id) { this.m_current.Skills.Add(skill); } result = null; } else { InteractiveSpawn current = this.m_current; this.m_current = spawn; if (binding.InteractiveSpawnId == this.m_current.Id && binding.SkillId == skill.Id) { this.m_current.Skills.Add(skill); } result = current; } } return(result); }
public void AddInteractiveSpawn(InteractiveSpawn spawn, InteractiveCustomSkillRecord skill, InteractiveSpawnSkills spawnSkill) { Database.Insert(spawn); Database.Insert(skill); Database.Insert(spawnSkill); m_interactivesSpawns.Add(spawn.Id, spawn); spawn.GetMap().SpawnInteractive(spawn); }
public void RemoveInteractiveSpawn(InteractiveSpawn spawn) { var skills = spawn.GetSkills(); foreach (var skill in skills) { Database.Delete(skill); Database.Delete("interactives_spawns_skills", "SkillId", skill.Id); } var map = spawn.GetMap(); foreach (var io in map.GetInteractiveObjects().Where(x => x.Spawn == spawn).ToArray()) { map.UnSpawnInteractive(io); } Database.Delete(spawn); m_interactivesSpawns.Remove(spawn.Id); }
public InteractiveObject(InteractiveSpawn spawn) { this.Spawn = spawn; this.Position = spawn.GetPosition(); this.GenerateSkills(); }
public void AddInteractiveSpawn(InteractiveSpawn spawn) { base.Database.Insert(spawn); this.m_interactivesSpawns.Add(spawn.Id, spawn); }
public static void LoadSpawns() { // Since 2.36 version there is the same interactive on different maps because of the 16/9 mode, we have to find the correct one Console.WriteLine("Generating interactive spawns"); var worldDatabase = Program.ConnectToWorld(); if (worldDatabase == null) { return; } worldDatabase.Database.Execute("DELETE FROM interactives_spawns"); worldDatabase.Database.Execute("ALTER TABLE interactives_spawns AUTO_INCREMENT=1"); string eleFilePath = Path.Combine(Program.FindDofusPath(), "content", "maps", "elements.ele"); string mapsfilePath = Path.Combine(Program.FindDofusPath(), "content", "maps", "maps0.d2p"); var eleFile = new EleReader(eleFilePath); var eleInstance = eleFile.ReadElements(); var d2pFile = new D2pFile(mapsfilePath); var entries = d2pFile.ReadAllFiles(); var i = 0; var ids = new List <int>(); var failures = new List <int>(); var spawns = new Dictionary <int, InteractiveSpawn>(); var elementsGlobal = new Dictionary <int, DlmGraphicalElement>(); var identifiableElementsByMap = new Dictionary <int, List <IdentifiableElement> >(); int fails = 0; Console.WriteLine("Loading maps ... "); Program.InitializeCounter(); foreach (var mapBytes in entries.Values) { DlmReader mapFile; DlmMap map = null; try { mapFile = new DlmReader(mapBytes) { DecryptionKey = Program.MapDecryptionKey }; map = mapFile.ReadMap(); } catch (Exception) { fails++; continue; } var elements = (from layer in map.Layers from cell in layer.Cells from element in cell.Elements.OfType <DlmGraphicalElement>() where element.Identifier != 0 let point = new MapPoint(cell.Id) select new IdentifiableElement(element, map)).ToList(); identifiableElementsByMap.Add(map.Id, elements); Program.UpdateCounter(i++, entries.Count); } Program.EndCounter(); var identifiableElements = identifiableElementsByMap.Values.SelectMany(x => x). GroupBy(x => x.Element.Identifier).ToDictionary(x => x.Key, x => x.ToList()); Program.InitializeCounter(); i = 0; // every elements grouped by the same id foreach (var keyPair in identifiableElements) { var likelyElement = keyPair.Value.Where(x => !x.Ignore) .OrderByDescending(x => DistanceFromBorder(new MapPoint(x.Element.Cell.Id))) .ThenBy(x => Math.Abs(x.Element.PixelOffset.X) + Math.Abs(x.Element.PixelOffset.Y)).First(); var eleElement = eleInstance.GraphicalDatas[(int)likelyElement.Element.ElementId]; InteractiveSpawn spawn; spawn = new InteractiveSpawn { Id = (int)likelyElement.Element.Identifier, MapId = likelyElement.Map.Id, CellId = likelyElement.Element.Cell.Id, Animated = eleElement is AnimatedGraphicalElementData || eleElement is EntityGraphicalElementData, ElementId = (int)likelyElement.Element.ElementId }; if (ids.Contains(spawn.Id)) { Console.WriteLine($"Id {spawn.Id} already added"); failures.Add(spawn.Id); continue; } ids.Add(spawn.Id); worldDatabase.Database.Insert("interactives_spawns", "Id", false, spawn); spawns.Add(spawn.Id, spawn); elementsGlobal.Add(spawn.Id, likelyElement.Element); Program.UpdateCounter(i++, identifiableElements.Count); } Program.EndCounter(); if (fails > 0) { Console.WriteLine($"{fails} failes !"); } Program.ExecutePatch("./Patchs/interactives_spawns_patch.sql", worldDatabase.Database); }
public override void ExecuteAdd(TriggerBase trigger) { var character = trigger is GameTrigger ? (trigger as GameTrigger).Character : null; if (character == null) { return; } var map = trigger.Get <Map>("mapDst"); if (map == null) { trigger.ReplyError("Map '{0}' doesn't exist", trigger.Get <int>("mapid")); } else { var mapSrc = character.Map; var cellIdDst = map.Cells[trigger.Get <short>("cellidDst")]; var elementId = trigger.Get <int>("elementId"); var template = trigger.Get <InteractiveTemplate>("templateId"); var templateId = template == null ? 0 : template.Id; var direction = trigger.Get <DirectionsEnum>("orientationId"); if (mapSrc.GetInteractiveObject(elementId) != null) { trigger.ReplyError("Interactive object {0} already exists on map {1}", elementId, mapSrc.Id); return; } var spawnId = InteractiveManager.Instance.PopSpawnId(); var skillId = InteractiveManager.Instance.PopSkillId(); var skill = new InteractiveCustomSkillRecord { Id = skillId, Type = "Teleport", Duration = 0, Parameter0 = map.Id.ToString(), Parameter1 = cellIdDst.Id.ToString(), Parameter2 = direction.ToString("D") }; var spawn = new InteractiveSpawn { Id = spawnId, MapId = mapSrc.Id, CustomSkills = { skill }, TemplateId = templateId }; var spawnSkill = new InteractiveSpawnSkills { InteractiveSpawnId = spawnId, SkillId = skillId }; WorldServer.Instance.IOTaskPool.AddMessage(() => { InteractiveManager.Instance.AddInteractiveSpawn(spawn, skill, spawnSkill); ContextRoleplayHandler.SendMapComplementaryInformationsDataMessage(character.Client); }); trigger.ReplyBold("Add Interactive {0} on map {1}", spawn.Template?.Name ?? "(no name)", spawn.MapId); } }