public void Load(string mapJson, bool import = false, bool clearEvents = true) { lock (MapLock) { var up = Up; var down = Down; var left = Left; var right = Right; base.Load(mapJson); if (import) { Up = up; Down = down; Left = left; Right = right; } Autotiles = new MapAutotiles(this); //Initialize Local Events if (clearEvents) { LocalEvents.Clear(); foreach (var id in EventIds) { var evt = EventBase.Get(id); LocalEvents.Add(id, evt); } } } }
private EventBase GetSelectedEvent() { if (lstCommonEvents.SelectedNode == null || lstCommonEvents.SelectedNode.Tag == null) { return(null); } return(EventBase.Get((Guid)lstCommonEvents.SelectedNode.Tag)); }
//Events private void SpawnGlobalEvents() { GlobalEventInstances.Clear(); foreach (var id in EventIds) { var evt = EventBase.Get(id); if (evt != null && evt.Global) { GlobalEventInstances.TryAdd(evt, new Event(evt.Id, evt, Id)); } } }
private void btnDelete_Click(object sender, EventArgs e) { if (lstCommonEvents.SelectedNode?.Tag != null && EventBase.Get((Guid)lstCommonEvents.SelectedNode.Tag) != null) { if (MessageBox.Show( Strings.CommonEventEditor.deleteprompt, Strings.CommonEventEditor.delete, MessageBoxButtons.YesNo ) == DialogResult.Yes) { PacketSender.SendDeleteObject(EventBase.Get((Guid)lstCommonEvents.SelectedNode.Tag)); } } }
private void lstCommonEvents_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (lstCommonEvents.SelectedNode == null || lstCommonEvents.SelectedNode.Tag == null) { return; } var editor = new FrmEvent(null) { MyEvent = EventBase.Get((Guid)lstCommonEvents.SelectedNode.Tag) }; editor.InitEditor(false, false, false); editor.ShowDialog(); InitEditor(); Globals.MainForm.BringToFront(); BringToFront(); }
private void toolStripItemPaste_Click(object sender, EventArgs e) { if (mEditorItem != null && mCopiedItem != null && lstQuests.Focused) { var startEventId = mEditorItem.StartEventId; var endEventId = mEditorItem.EndEventId; mEditorItem.Load(mCopiedItem, true); EventBase.Get(startEventId).Load(mEditorItem.StartEvent.JsonData); EventBase.Get(endEventId).Load(mEditorItem.EndEvent.JsonData); mEditorItem.StartEventId = startEventId; mEditorItem.EndEventId = endEventId; //Fix tasks foreach (var tsk in mEditorItem.Tasks) { var oldId = tsk.Id; tsk.Id = Guid.NewGuid(); if (mEditorItem.AddEvents.ContainsKey(oldId)) { mEditorItem.AddEvents.Add(tsk.Id, mEditorItem.AddEvents[oldId]); tsk.EditingEvent = mEditorItem.AddEvents[tsk.Id]; mEditorItem.AddEvents.Remove(oldId); } else { var tskEventData = EventBase.Get(tsk.CompletionEventId).JsonData; tsk.CompletionEventId = Guid.Empty; tsk.EditingEvent = new EventBase(Guid.Empty, Guid.Empty, 0, 0, false); tsk.EditingEvent.Name = Strings.TaskEditor.completionevent.ToString(mEditorItem.Name); tsk.EditingEvent.Load(tskEventData); mEditorItem.AddEvents.Add(tsk.Id, tsk.EditingEvent); } } UpdateEditor(); } }
private void InitEditor() { var selectedId = Guid.Empty; var folderNodes = new Dictionary <string, TreeNode>(); if (lstCommonEvents.SelectedNode != null && lstCommonEvents.SelectedNode.Tag != null) { selectedId = (Guid)lstCommonEvents.SelectedNode.Tag; } lstCommonEvents.Nodes.Clear(); //Collect folders var mFolders = new List <string>(); foreach (var itm in EventBase.Lookup) { if (((EventBase)itm.Value).CommonEvent) { if (!string.IsNullOrEmpty(((EventBase)itm.Value).Folder) && !mFolders.Contains(((EventBase)itm.Value).Folder)) { mFolders.Add(((EventBase)itm.Value).Folder); if (!mKnownFolders.Contains(((EventBase)itm.Value).Folder)) { mKnownFolders.Add(((EventBase)itm.Value).Folder); } } } } mFolders.Sort(); mKnownFolders.Sort(); cmbFolder.Items.Clear(); cmbFolder.Items.Add(""); cmbFolder.Items.AddRange(mKnownFolders.ToArray()); lstCommonEvents.Sorted = !btnChronological.Checked; if (!btnChronological.Checked && !CustomSearch()) { foreach (var folder in mFolders) { var node = lstCommonEvents.Nodes.Add(folder); node.ImageIndex = 0; node.SelectedImageIndex = 0; folderNodes.Add(folder, node); } } foreach (var itm in EventBase.ItemPairs) { var node = new TreeNode(itm.Value); node.Tag = itm.Key; node.ImageIndex = 1; node.SelectedImageIndex = 1; var folder = EventBase.Get(itm.Key).Folder; if (!string.IsNullOrEmpty(folder) && !btnChronological.Checked && !CustomSearch()) { var folderNode = folderNodes[folder]; folderNode.Nodes.Add(node); if (itm.Key == selectedId) { folderNode.Expand(); } } else { lstCommonEvents.Nodes.Add(node); } if (CustomSearch()) { if (!node.Text.ToLower().Contains(txtSearch.Text.ToLower())) { node.Remove(); } } if (itm.Key == selectedId) { lstCommonEvents.SelectedNode = node; } } var selectedNode = lstCommonEvents.SelectedNode; if (!btnChronological.Checked) { lstCommonEvents.Sort(); } lstCommonEvents.SelectedNode = selectedNode; foreach (var node in mExpandedFolders) { if (folderNodes.ContainsKey(node)) { folderNodes[node].Expand(); } } }
private void cmbOnDeathEventParty_SelectedIndexChanged(object sender, EventArgs e) { mEditorItem.OnDeathPartyEvent = EventBase.Get(EventBase.IdFromList(cmbOnDeathEventParty.SelectedIndex - 1)); }
private void cmbEvent_SelectedIndexChanged(object sender, EventArgs e) { mEditorItem.Event = EventBase.Get(EventBase.IdFromList(cmbEvent.SelectedIndex - 1)); }
//GameObjectPacket private static void HandlePacket(GameObjectPacket packet) { var id = packet.Id; var deleted = packet.Deleted; var json = ""; if (!packet.Deleted) { json = packet.Data; } switch (packet.Type) { case GameObjectType.Animation: if (deleted) { var anim = AnimationBase.Get(id); anim.Delete(); } else { var anim = new AnimationBase(id); anim.Load(json); try { AnimationBase.Lookup.Set(id, anim); } catch (Exception exception) { Log.Error($"Another mystery NPE. [Lookup={AnimationBase.Lookup}]"); if (exception.InnerException != null) { Log.Error(exception.InnerException); } Log.Error(exception); Log.Error($"{nameof(id)}={id},{nameof(anim)}={anim}"); throw; } } break; case GameObjectType.Class: if (deleted) { var cls = ClassBase.Get(id); cls.Delete(); } else { var cls = new ClassBase(id); cls.Load(json); ClassBase.Lookup.Set(id, cls); } break; case GameObjectType.Item: if (deleted) { var itm = ItemBase.Get(id); itm.Delete(); } else { var itm = new ItemBase(id); itm.Load(json); ItemBase.Lookup.Set(id, itm); } break; case GameObjectType.Npc: if (deleted) { var npc = NpcBase.Get(id); npc.Delete(); } else { var npc = new NpcBase(id); npc.Load(json); NpcBase.Lookup.Set(id, npc); } break; case GameObjectType.Projectile: if (deleted) { var proj = ProjectileBase.Get(id); proj.Delete(); } else { var proj = new ProjectileBase(id); proj.Load(json); ProjectileBase.Lookup.Set(id, proj); } break; case GameObjectType.Quest: if (deleted) { var qst = QuestBase.Get(id); qst.Delete(); } else { var qst = new QuestBase(id); qst.Load(json); foreach (var tsk in qst.Tasks) { qst.OriginalTaskEventIds.Add(tsk.Id, tsk.CompletionEventId); } QuestBase.Lookup.Set(id, qst); } break; case GameObjectType.Resource: if (deleted) { var res = ResourceBase.Get(id); res.Delete(); } else { var res = new ResourceBase(id); res.Load(json); ResourceBase.Lookup.Set(id, res); } break; case GameObjectType.Shop: if (deleted) { var shp = ShopBase.Get(id); shp.Delete(); } else { var shp = new ShopBase(id); shp.Load(json); ShopBase.Lookup.Set(id, shp); } break; case GameObjectType.Spell: if (deleted) { var spl = SpellBase.Get(id); spl.Delete(); } else { var spl = new SpellBase(id); spl.Load(json); SpellBase.Lookup.Set(id, spl); } break; case GameObjectType.CraftTables: if (deleted) { var cft = CraftingTableBase.Get(id); cft.Delete(); } else { var cft = new CraftingTableBase(id); cft.Load(json); CraftingTableBase.Lookup.Set(id, cft); } break; case GameObjectType.Crafts: if (deleted) { var cft = CraftBase.Get(id); cft.Delete(); } else { var cft = new CraftBase(id); cft.Load(json); CraftBase.Lookup.Set(id, cft); } break; case GameObjectType.Map: //Handled in a different packet break; case GameObjectType.Event: var wasCommon = false; if (deleted) { var evt = EventBase.Get(id); wasCommon = evt.CommonEvent; evt.Delete(); } else { var evt = new EventBase(id); evt.Load(json); wasCommon = evt.CommonEvent; EventBase.Lookup.Set(id, evt); } if (!wasCommon) { return; } break; case GameObjectType.PlayerVariable: if (deleted) { var pvar = PlayerVariableBase.Get(id); pvar.Delete(); } else { var pvar = new PlayerVariableBase(id); pvar.Load(json); PlayerVariableBase.Lookup.Set(id, pvar); } break; case GameObjectType.ServerVariable: if (deleted) { var svar = ServerVariableBase.Get(id); svar.Delete(); } else { var svar = new ServerVariableBase(id); svar.Load(json); ServerVariableBase.Lookup.Set(id, svar); } break; case GameObjectType.Tileset: var obj = new TilesetBase(id); obj.Load(json); TilesetBase.Lookup.Set(id, obj); if (Globals.HasGameData && !packet.AnotherFollowing) { GameContentManager.LoadTilesets(); } break; default: throw new ArgumentOutOfRangeException(); } GameObjectUpdatedDelegate?.Invoke(packet.Type); }