public static Npc CreateNpc(SpawnTemplate spawnTemplate) { var npc = new Npc { NpcId = spawnTemplate.NpcId, SpawnTemplate = spawnTemplate, NpcTemplate = Data.Data.NpcTemplates[spawnTemplate.Type][spawnTemplate.NpcId], Position = new WorldPosition { MapId = spawnTemplate.MapId, X = spawnTemplate.X, Y = spawnTemplate.Y, Z = spawnTemplate.Z + ((spawnTemplate.FullId == 6301151 || spawnTemplate.FullId == 6301152 || spawnTemplate.FullId == 6301153) ? 0 : 25), Heading = spawnTemplate.Heading, } }; npc.BindPoint = npc.Position.Clone(); npc.GameStats = CreatureLogic.InitGameStats(npc); CreatureLogic.UpdateCreatureStats(npc); AiLogic.InitAi(npc); return(npc); }
public static int LoadSpawns() { Spawns = new Dictionary <int, List <SpawnTemplate> >(); int readed = 0; foreach (string fileName in Directory.GetFiles(DataPath + "spawn")) { if (fileName.Contains("_spawn.bin")) { using (FileStream stream = File.OpenRead(fileName)) { while (stream.Position < stream.Length) { SpawnTemplate spawnTemplate = Serializer.DeserializeWithLengthPrefix <SpawnTemplate>(stream, PrefixStyle.Fixed32); if (!Spawns.ContainsKey(spawnTemplate.MapId)) { Spawns.Add(spawnTemplate.MapId, new List <SpawnTemplate>()); } Spawns[spawnTemplate.MapId].Add(spawnTemplate); readed++; } } } } return(readed); }
public static Npc CreateNpc(SpawnTemplate spawnTemplate) { NpcTemplate npcTemplate = (Data.Data.NpcTemplates.ContainsKey(spawnTemplate.NpcId)) ? Data.Data.NpcTemplates[spawnTemplate.NpcId] : new NpcTemplate(); var npc = new Npc { NpcId = spawnTemplate.NpcId, SpawnTemplate = spawnTemplate, NpcTemplate = npcTemplate, Position = new WorldPosition { MapId = spawnTemplate.MapId, X = spawnTemplate.X, Y = spawnTemplate.Y, Z = spawnTemplate.Z, }, }; npc.BindPoint = npc.Position.Clone(); npc.GameStats = CreatureLogic.InitGameStats(npc); CreatureLogic.UpdateCreatureStats(npc); AiLogic.InitAi(npc); return(npc); }
public override void CallBack(object o) { ClientManager.EnterCriticalArea(); try { //mob.Map.DeleteActor(mob.Actor); mob.Actor.e.OnReSpawn(); if (mob.ai != null) { if (mob.Map.GetRegionPlayerCount(mob.Actor.region) != 0)// the ai is only need to be switched on if there is player on that region { mob.ai.Start(); } } mob.timeSignature.actorID = 0; //readd the loot mob.Actor.NPCinv = new List <SagaDB.Items.Item>(); if (MapServer.ScriptManager.templates.ContainsKey(mob.Type)) { SpawnTemplate st = MapServer.ScriptManager.templates[mob.Type]; foreach (Dictionary <string, string> loot in st.lootItems) { int amount = 1; if (loot.ContainsKey("amount")) { amount = int.Parse(loot["amount"]); } int itemid = int.Parse(loot["id"]); float perc = (float)Config.Instance.DropRate / 100; for (int i = 0; i < amount; ++i) { if (Global.Random.Next(0, 10000) <= int.Parse(loot["rate"]) * perc) { mob.AddLoot(itemid); } } } } // >> set a random position float[] pos = ScriptManager.GetRandomPos(mob.Map, mob.StartX, mob.StartY, mob.range); mob.Actor.x = pos[0]; mob.Actor.y = pos[1]; mob.Actor.z = pos[2]; mob.Map.RegisterActor(mob.Actor); } catch (Exception ex) { Logger.ShowError(ex); } ClientManager.LeaveCriticalArea(); }
private void CreateGroup(IConnection connection) { var npcs = Global.VisibleService.FindTargets(connection.Player, connection.Player.Position, 50, TargetingAreaType.Enemy); npcs.Sort((c1, c2) => { Npc npc1 = c1 as Npc; Npc npc2 = c2 as Npc; if (npc1 == null || npc2 == null) { return(0); } return(npc2.NpcTemplate.Size.GetHashCode() .CompareTo(npc1.NpcTemplate.Size.GetHashCode())); }); int counter = 0; int startAngle = RandomUtilities.Random().Next(0, 359); foreach (var creature in npcs) { Npc npc = creature as Npc; if (npc == null) { continue; } int count = int.Parse(GetValue(connection, "Enter count of: [" + npc.NpcTemplate.Name + "]")); if (count > 0) { for (int i = 0; i < count; i++) { SpawnTemplate spawnTemplate = npc.SpawnTemplate.Clone(); spawnTemplate.X += (float)(150f * Math.Cos(startAngle + counter * 30) * counter / 2 / Math.PI + RandomUtilities.Random().Next(-25, 25)); spawnTemplate.Y += (float)(150f * Math.Sin(startAngle + counter * 30) * counter / 2 / Math.PI + RandomUtilities.Random().Next(-25, 25)); Global.MapService.SpawnTeraObject(MapService.CreateNpc(spawnTemplate), npc.Instance); counter++; } Global.MapService.DespawnTeraObject(npc); } } }
private static void SpawnTemplateExport() { List <SpawnTemplate> templates = new List <SpawnTemplate>(); using (var entity = new PublicDbEntities()) { var list = entity.TBL_XWWL_NPC_SL.ToList(); foreach (var data in list) { SpawnTemplate spawn = new SpawnTemplate() { NpcId = data.FLD_PID, Type = (short)data.FLD_NPC, MapId = data.FLD_MID, X = (float)data.FLD_X, Y = (float)data.FLD_Y, Z = (float)data.FLD_Z, Face1 = (float)data.FLD_FACE0, Face2 = (float)data.FLD_FACE, }; templates.Add(spawn); Log.Debug("Npc SL NpcId = {0} Map = {1}", spawn.NpcId, spawn.MapId); } var list2 = entity.TBL_XWWL_NPC.ToList(); foreach (var data in list2) { SpawnTemplate spawn = new SpawnTemplate() { NpcId = data.FLD_PID, Type = (short)data.FLD_NPC, MapId = data.FLD_MID, X = (float)data.FLD_X, Y = (float)data.FLD_Y, Z = (float)data.FLD_Z, Face1 = (float)data.FLD_FACE0, Face2 = (float)data.FLD_FACE, }; templates.Add(spawn); Log.Debug("Npc NpcId = {0} Map = {1}", spawn.NpcId, spawn.MapId); } using (var file = File.Create("Data/spawns.bin")) { Serializer.SerializeWithLengthPrefix <List <SpawnTemplate> >(file, templates, PrefixStyle.Fixed32); } } }
/// <summary> /// Spawns Enemies in Room /// </summary> private void SpawnEnemies() { if (hasSpawnedEnemies) { return; } for (int i = 0; i < enemiesInRoom.Length; i++) { SpawnTemplate template = enemiesInRoom[i]; GameObject enemy = Instantiate(template.EnemyPrefab); enemy.transform.SetParent(enemyHolder.transform); enemy.transform.localPosition = template.SpawnPosition; enemy.transform.rotation = Quaternion.Euler(0, 0, template.SpawnRotation); AEnemy script = enemy.GetComponent <AEnemy>(); enemies.Add(script); script.AddDeathListener(CheckRoomClear); } hasSpawnedEnemies = true; }
private static int ParseSpawnData(Dictionary <string, object> spawnData) { int count = 0; foreach (var data in (List <Dictionary <string, object> >)spawnData["String"]) { int huntingZoneId = int.Parse(data["huntingZoneId"].ToString()); int templateId = int.Parse(data["templateId"].ToString()); string[] arr = data["string"].ToString().Split(new[] { '|', '#' }); for (int i = 0; i < arr.Length; i++) { int mapId = int.Parse(arr[i++]); string[] coords = arr[i].Split(new[] { ',' }); float x = float.Parse(coords[0].Replace('.', ',')); float y = float.Parse(coords[1].Replace('.', ',')); float z = float.Parse(coords[2].Replace('.', ',')); SpawnTemplate template = new SpawnTemplate { MapId = mapId, NpcId = templateId, Type = (short)huntingZoneId, X = x, Y = y, Z = z, Heading = (short)Funcs.Random().Next(short.MinValue, short.MaxValue) }; if (!Spawn.ContainsKey(mapId)) { Spawn.Add(mapId, new List <SpawnTemplate>()); } Spawn[mapId].Add(template); count++; } } return(count); }
private void Run(object sender, RoutedEventArgs e) { short spNpcInfoOpCode = Packet.GetPacketOpcode(MainWindow, "SpNpcInfo"); short spBindOpCode = Packet.GetPacketOpcode(MainWindow, "SpCharacterBind"); Dictionary <int, Dictionary <long, byte[]> > npcs = new Dictionary <int, Dictionary <long, byte[]> >(); int mapId = 0; /*if (File.Exists("data/spawn/7001_spawn.dat")) * { * npcs.Add(7001, new Dictionary<long, byte[]>()); * using (stream = File.Open("data/spawn/7001_spawn.dat",FileMode.Open)) * { * using (BinaryReader r = new BinaryReader(stream)) * { * int counter = r.ReadInt32(); * * for (int i = 0; i < counter; i++) * { * long uid = r.ReadInt64(); * int datalen = r.ReadInt32(); * byte[] datas = r.ReadBytes(datalen); * npcs[7001].Add(uid, datas); * } * } * } * }*/ foreach (Packet packet in MainWindow.Packets) { if (packet.OpCode == spBindOpCode) { mapId = BitConverter.ToInt32(packet.Data, 4); if (!npcs.ContainsKey(mapId)) { npcs.Add(mapId, new Dictionary <long, byte[]>()); } continue; } if (packet.OpCode != spNpcInfoOpCode) { continue; } long id = BitConverter.ToInt64(packet.Data, 10); if (npcs[mapId].ContainsKey(id)) { continue; } byte[] data = new byte[packet.Data.Length - 8]; Buffer.BlockCopy(packet.Data, 8, data, 0, data.Length); npcs[mapId].Add(id, data); } int count = 0; if (!Directory.Exists("data")) { Directory.CreateDirectory("data"); } if (!Directory.Exists("data/spawn")) { Directory.CreateDirectory("data/spawn"); } foreach (int mapid in npcs.Keys) { using (FileStream stream = File.Create("data/spawn/" + mapid + "_spawn.bin")) { foreach (KeyValuePair <long, byte[]> keyValuePair in npcs[mapid]) { SpawnTemplate spawnTemplate = new SpawnTemplate { NpcId = BitConverter.ToInt32(keyValuePair.Value, 36), Type = BitConverter.ToInt16(keyValuePair.Value, 40), MapId = mapid, X = BitConverter.ToSingle(keyValuePair.Value, 18), Y = BitConverter.ToSingle(keyValuePair.Value, 22), Z = BitConverter.ToSingle(keyValuePair.Value, 26), Heading = BitConverter.ToInt16(keyValuePair.Value, 30) }; Serializer.SerializeWithLengthPrefix(stream, spawnTemplate, PrefixStyle.Fixed32); count++; } } } MainWindow.SetText("Finded " + count + " npcs in " + npcs.Count + " maps!"); }
void Create(IList <string> args) { Task.Run( () => _fuse.ConnectOrSpawn("Fuse create", Timeout.InfiniteTimeSpan)); var argIdx = 0; var templateName = args.TryGetAt(argIdx++) .OrThrow(new ExitWithError(Usage)); var name = args.TryGetAt(argIdx++).Or("Untitled"); var validatedName = FileName.Validate(name); if (!validatedName.HasValue) { throw new ExitWithError(validatedName.Error.Capitalize()); } try { var destPath = args.TryGetAt(argIdx++).Select( p => (_fileSystem.ResolveAbsolutePath(p) as AbsoluteDirectoryPath).ToOptional() .OrThrow(new ExitWithError("Invalid project path" + ": " + args[argIdx - 1]))); var spawnTemplate = new SpawnTemplate(_fileSystem); var projectTemplate = _projectTemplates().FirstOrDefault(t => TemplateNameEquals(t, templateName)); var fileTemplate = _fileTemplates().FirstOrDefault(t => TemplateNameEquals(t, templateName)); if (projectTemplate == null && fileTemplate == null) { throw new ExitWithError("Unknown template name, see fuse help create for a list of valid template names."); } var templateIsProjectTemplate = projectTemplate != null; if (templateIsProjectTemplate) { var resultPath = spawnTemplate.CreateProject(name, projectTemplate, destPath); using (_textWriter.PushColor(ConsoleColor.Green)) _textWriter.WriteLine("Created project: '" + name + "' at '" + resultPath.NativePath + "'"); } else { var resultPath = spawnTemplate.CreateFile(name, fileTemplate, destPath) .OrThrow(new FailedToCreateFileFromTemplate("Failed to create file from template (unknown reason)")); using (_textWriter.PushColor(ConsoleColor.Green)) _textWriter.WriteLine("Created file at '" + resultPath.NativePath + "'"); } } catch (ProjectNotFound) { throw new ExitWithError("Could not find a project to put the file in, please check if destination folder or its parents contains a project."); } catch (FileAlreadyExist e) { throw new ExitWithError(e.Message); } catch (InvalidPath p) { throw new ExitWithError("Invalid project path" + ": " + p.Path); } catch (SecurityException e) { throw new ExitWithError(e.Message); } catch (DaemonException e) { throw new ExitWithError(e.Message); } catch (FailedToCreateFileFromTemplate e) { throw new ExitWithError(e.Message); } catch (ProjectFolderNotEmpty) { throw new ExitWithError("A folder with that name already exists, and it is not empty."); } catch (UnauthorizedAccessException e) { throw new ExitWithError(e.Message); } catch (IOException e) { throw new ExitWithError(e.Message); } catch (FailedToAddProjectToRecentList e) { throw new ExitWithError(e.Message); } }
IControl CreateContent(Template template, IDialog <bool> dialog) { var projectLocation = UserSettings.Folder("MostRecentlyUsedFolder") .Convert(v => v.Or(Optional.Some(_fuse.ProjectsDir)), d => d) .AutoInvalidate(TimeSpan.FromMilliseconds(100)); var validatedLocation = projectLocation.Validate(v => v.NativePath, ValidateExistingDirectory); var projectName = Property.Create( Optional.Some(_shell.MakeUnique(projectLocation.Latest().First().Value / "App").Name)); var validatedName = projectName.Validate(v => v.ToString(), DirectoryName.Validate); var possibleProjectName = projectLocation.CombineLatest( projectName, (loc, pro) => { return(loc.SelectMany(l => pro.Select(n => l / n))); }) .Select( d => d.HasValue && Directory.Exists(d.Value.NativePath) ? Optional.Some("Project '" + d.Value.Name + "' already exists in " + d.Value.ContainingDirectory.NativePath) : Optional.None()); return (Layout.Dock() .Bottom(Layout.Dock() .Right( Buttons.DefaultButtonPrimary( text: "Create", cmd: Observable.CombineLatest( projectName, projectLocation, (name, location) => { var projectDirectory = location.SelectMany(l => name.Select(n => l / n)) .Where(d => !_shell.Exists(d)); return Command.Create( isEnabled: projectDirectory.HasValue, action: async() => { var spawnTemplate = new SpawnTemplate(_shell); var resultPath = spawnTemplate.CreateProject(name.Value.ToString(), template, location.Value); var projectPath = resultPath / new FileName(name.Value + ".unoproj"); await Application.OpenDocument(projectPath, showWindow: true); dialog.Close(true); }); }).Switch()) .WithWidth(104)) .Right(Buttons.DefaultButton(text: "Cancel", cmd: Command.Enabled(() => dialog.Close(false))) .WithWidth(104) .WithPadding(right: new Points(16))) .Fill()) .Fill( Layout.StackFromTop( Label.Create("Name:", color: Theme.DefaultText) .WithPadding(LabelThickness), ValidatedTextBox.Create(validatedName) .WithPadding(ControlPadding), Control.Empty .WithHeight(8), Label.Create("Location:", color: Theme.DefaultText) .WithPadding(LabelThickness), Layout.Dock() .Right( Buttons.DefaultButton(text: "Browse", cmd: Command.Enabled(async() => { var directory = await dialog.BrowseForDirectory(await projectLocation.FirstAsync().Or(DirectoryPath.GetCurrentDirectory())); if (directory.HasValue) { projectLocation.Write(directory.Value, save: true); } })) .WithWidth(80) .WithHeight(22) .CenterVertically() .WithPadding(LabelThickness) ) .Fill(ValidatedTextBox.Create(validatedLocation) .WithPadding(ControlPadding)), ErrorLabel.Create(possibleProjectName) .WithPadding(ControlPadding))) .WithPadding(ControlPadding) .WithPadding(ControlPadding) .WithBackground(Theme.PanelBackground)); }