public override void DoUpdate() { if (!update) { UpdateEvent evt = new UpdateEvent() { Actor = ScriptHandler.NPC, UpdateType = UpdateTypes.NPCTalk, UserData = dialogID }; NPCMap.SendEventToAllActorsWhoCanSeeActor(MapEvents.EVENT_BROADCAST, evt, ScriptHandler.NPC, false); update = true; } }
public override void DoUpdate() { if (!updated) { MoveArgument arg = new MoveArgument() { X = x, Y = y, Z = z, Dir = dir, Speed = speed, DashID = dashID, DashUnknown = dashUnknown, BNSMoveType = moveType }; NPCMap.MoveActor(ScriptHandler.NPC, arg, false); updated = true; } }
public static void LoadNPCs() { var sqlText = "SELECT * FROM npcs"; var sqlCommand = new MySqlCommand(sqlText, Program.DBHelper.Use()); var sqlReader = sqlCommand.ExecuteReader(); while (sqlReader.Read()) { var npcModel = new Models.NPC.NoPlayerCharacterModel() { ID = sqlReader.GetInt32("ID"), GfxID = sqlReader.GetInt32("Gfx"), Size = sqlReader.GetInt32("Size"), Sex = sqlReader.GetInt32("Sex"), Color = sqlReader.GetInt32("Color1"), Color2 = sqlReader.GetInt32("Color2"), Color3 = sqlReader.GetInt32("Color3"), Name = sqlReader.GetString("Name"), Items = sqlReader.GetString("Items"), Question = (sqlReader.GetInt32("initQuestion") != -1 ? QuestionsList.First (x => x.QuestionID == sqlReader.GetInt32("initQuestion")) : null), }; foreach (var itemToSell in sqlReader.GetString("SellingList").Split(',')) { if (itemToSell == "") { continue; } npcModel.SellingList.Add(int.Parse(itemToSell)); } var infosMap = sqlReader.GetString("Mapinfos").Split(';'); var npc = new NPCMap(npcModel) { MapID = int.Parse(infosMap[0]), MapCell = int.Parse(infosMap[1]), Dir = int.Parse(infosMap[2]), MustMove = bool.Parse(infosMap[3]), }; if (MapsRequests.MapsList.Any(x => x.Model.ID == npc.MapID)) { var map = MapsRequests.MapsList.First(x => x.Model.ID == npc.MapID); npc.ID = MapsRequests.MapsList.First(x => x.Model.ID == npc.MapID).NextNpcID(); map.Npcs.Add(npc); npc.StartMove(); } NpcsList.Add(npc); } sqlReader.Close(); Utilities.Loggers.Status.Write(string.Format("Loaded '{0}' npcs from the database !", NpcsList.Count)); }
private void worker_DoWork(object sender, DoWorkEventArgs e) { try { worker.ReportProgress(0, "Allocating memory..."); Invoke(new Action(() => { if (pbHeightmap.Image != null) { pbHeightmap.Image.Dispose(); pbHeightmap.Image = null; } })); _heightmap = new Heightmap(); _heightmap.Width = _worldSize; _heightmap.Height = _worldSize; worker.ReportProgress(0, "Generating heightmap..."); var map = _heightmap.Generate(); worker.ReportProgress(0, "Rendering preview..."); var bmp = new Bitmap(_worldSize, _worldSize); var lck = bmp.LockBits(new Rectangle(0, 0, _worldSize, _worldSize), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var data = new byte[Math.Abs(lck.Stride) * lck.Height]; for (int i = 0; i < data.Length; i += 4) { double v = map[i / 4]; byte gray = (byte)(v * 255); data[i] = gray; data[i + 1] = gray; data[i + 2] = gray; data[i + 3] = 255; float p = (float)i / data.Length; worker.ReportProgress((int)(p * 100), "Rendering preview..."); } Marshal.Copy(data, 0, lck.Scan0, data.Length); data = null; bmp.UnlockBits(lck); lck = null; pbHeightmap.Image = bmp; _npc = new NPCMap(_heightmap.Seed, map); map = null; worker.ReportProgress(0, "Generating NPC density map..."); var npcMap = _npc.GenerateDensityMap(); bmp = new Bitmap(_worldSize, _worldSize); lck = bmp.LockBits(new Rectangle(0, 0, _worldSize, _worldSize), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); data = new byte[Math.Abs(lck.Stride) * lck.Height]; for (int i = 0; i < data.Length; i += 4) { bool v = npcMap[i / 4]; if (v) { data[i] = 255; data[i + 1] = 255; data[i + 2] = 255; data[i + 3] = 255; } else { data[i] = 0; data[i + 1] = 0; data[i + 2] = 0; data[i + 3] = 255; } float p = (float)i / data.Length; worker.ReportProgress((int)(p * 100), "Rendering preview..."); } Marshal.Copy(data, 0, lck.Scan0, data.Length); data = null; bmp.UnlockBits(lck); lck = null; pbDensity.Image = bmp; worker.ReportProgress(0, "Generating NPC type map..."); var types = _npc.GetTypeMap(npcMap); bmp = new Bitmap(_worldSize, _worldSize); lck = bmp.LockBits(new Rectangle(0, 0, _worldSize, _worldSize), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); data = new byte[Math.Abs(lck.Stride) * lck.Height]; for (int i = 0; i < data.Length; i += 4) { int t = types[i / 4]; Color px = Color.Black; switch (t) { case 1: px = Color.Yellow; break; case 2: px = Color.Red; break; case 3: px = Color.Orange; break; case 4: px = Color.Gray; break; case 5: px = Color.Pink; break; case 6: px = Color.Green; break; case 7: px = Color.Blue; break; case 8: px = Color.White; break; } data[i] = px.R; data[i + 1] = px.G; data[i + 2] = px.B; data[i + 3] = 255; float p = (float)i / data.Length; worker.ReportProgress((int)(p * 100), "Rendering preview..."); } Marshal.Copy(data, 0, lck.Scan0, data.Length); data = null; bmp.UnlockBits(lck); lck = null; pbTypes.Image = bmp; } catch (Exception ex) { Invoke(new Action(() => { MessageBox.Show(caption: "Heightmap generation error", text: ex.Message, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); })); } }