protected NPC(NPCDescriptor descriptor) { _scripts = new List <Script>(); this.Name = descriptor.Name; this.Level = descriptor.Level; this.MaxRoam = descriptor.MaxRoam; this.Position = descriptor.Position; this.FrameSize = descriptor.FrameSize; this.UniqueID = descriptor.UniqueID; this.AggresiveRange = descriptor.AggresiveRange; this.Reach = descriptor.Reach; this.Speed = descriptor.Speed; this.TexturePath = descriptor.TexturePath; this.Stats.Defense = descriptor.Stats.Defense; this.Stats.Dexterity = descriptor.Stats.Dexterity; this.Stats.CurrentHealth = descriptor.Stats.CurrentHealth; this.Stats.Health = descriptor.Stats.Health; this.Stats.Strength = descriptor.Stats.Strength; this.Stats.Intelligence = descriptor.Stats.Intelligence; this.CollisionBounds = descriptor.CollisionBounds; this.DialogueBranch = descriptor.DialogueBranch; this.InitalizeScripts(descriptor.Scripts); if (!string.IsNullOrEmpty(descriptor.Dialogue)) { this.Dialogue = Engine.Services.Get <DialogueManager>().Get(descriptor.Dialogue); this.DialogueBranch = descriptor.DialogueBranch; } }
public NPCDefinition(NPCDescriptor descriptor) { this.Descriptor = descriptor; Script script = new Script(EngineConstants.FILEPATH_SCRIPTS + "aggressive_npc.lua"); this.InitalizeDefaultBehavior(); //this.InitalizeScripts(descriptor); }
public NPCDescriptor LoadNPC(string filePath) { if (_npcs.ContainsKey(filePath)) { return(_npcs[filePath]); } var npc = NPCDescriptor.Load(filePath); _npcs.Add(filePath, npc); return(npc); }
public DockNPCEditor(Project project, string text, Image icon, FileInfo file) : this() { _project = project; _regularDockText = text; _unsavedDockText = text + "*"; DockText = text; Icon = icon; _file = file; _npc = _project.LoadNPC(file.FullName); this.txtName.Text = _npc.Name; this.radAggressive.Checked = _npc.Aggressive; this.radUnaggressive.Checked = !_npc.Aggressive; this.txtStr.Text = _npc.Stats.Strength.ToString(); this.txtInt.Text = _npc.Stats.Intelligence.ToString(); this.txtDef.Text = _npc.Stats.Defense.ToString(); this.txtHealth.Text = _npc.Stats.Health.ToString(); this.txtDex.Text = _npc.Stats.Dexterity.ToString(); this.txtFrameWidth.Text = _npc.FrameSize.X.ToString(); this.txtFrameHeight.Text = _npc.FrameSize.Y.ToString(); this.txtColLeft.Text = _npc.CollisionBounds.Left.ToString(); this.txtColTop.Text = _npc.CollisionBounds.Top.ToString(); this.txtColWidth.Text = _npc.CollisionBounds.Width.ToString(); this.txtColHeight.Text = _npc.CollisionBounds.Height.ToString(); this.txtMaxRoam.Text = _npc.MaxRoam.X.ToString(); this.cmbEquipSlot.DataSource = Enum.GetValues(typeof(EquipmentSlots)); this.cmbEquipSlot.SelectedItem = EquipmentSlots.MainArm; if (File.Exists(_project.ClientRootDirectory + "/" + _npc.TexturePath)) { this.picSpriteSheet.Load(_project.ClientRootDirectory + "/" + _npc.TexturePath); this.picCollisionPreview.Load(_project.ClientRootDirectory + "/" + _npc.TexturePath); if (_npc.FrameSize == Vector.Zero) { _npc.FrameSize = new Vector(this.picSpriteSheet.Image.Width, this.picSpriteSheet.Image.Height); } this.txtFrameWidth.Text = _npc.FrameSize.X.ToString(); this.txtFrameHeight.Text = _npc.FrameSize.Y.ToString(); } }
public FileInfo AddNPC(string filePath) { var npc = NPCDescriptor.Create(); npc.Name = Path.GetFileNameWithoutExtension(filePath); npc.Save(filePath); var npcFile = new FileInfo(filePath); _npcFiles.Add(filePath, npcFile); this.NPCAdded?.Invoke(this, new FileEventArgs(npcFile)); return(npcFile); }
private void InitalizeScripts(NPCDescriptor descriptor) { _behaviorDefinition = new ActorBehaviorDefinition(); foreach (var scriptDef in descriptor.Scripts) { string scriptActionHook = scriptDef.Key; string scriptContent = scriptDef.Value; Script script = new Script(scriptContent, false); switch (scriptActionHook) { case "OnAttack": this.BehaviorDefinition.Attack = new ScriptFunction(args => script.GetFunction("Attack").Call(args)); break; case "OnCreated": this.BehaviorDefinition.OnCreated = new ScriptAction((args => { script.GetFunction("OnCreated").Call(args); } )); break; case "OnAttacked": this.BehaviorDefinition.Attacked = new ScriptAction((args => { script.GetFunction("Attacked").Call(args); } )); break; case "OnDeath": this.BehaviorDefinition.OnDeath = new ScriptAction((args => { script.GetFunction("OnDeath").Call(args); } )); break; case "OnUpdate": this.BehaviorDefinition.Update = new ScriptAction((args => { script.GetFunction("Update").Call(args); } )); break; } } }
private void LoadNPCS() { Console.WriteLine("Loading NPCs..."); var directoryInfo = new DirectoryInfo(EngineConstants.FILEPATH_NPCS); FileInfo[] files = directoryInfo.GetFiles("*" + EngineConstants.NPC_FILE_EXT); foreach (var file in files) { NPCDescriptor npcDesc = NPCDescriptor.Load(file.FullName); _npcs.Add(npcDesc.Name, new NPCDefinition(npcDesc)); } Console.WriteLine($"Loaded {files.Length} NPCs."); }
private void LoadNPCS() { Console.WriteLine("Loading NPCs..."); var directoryInfo = new DirectoryInfo(Constants.FILEPATH_NPCS); FileInfo[] files = directoryInfo.GetFiles("*" + EngineConstants.NPC_FILE_EXT); foreach (var file in files) { NPCDescriptor npcDesc = _npcDataManager.Load(new ContentFileDataLoaderArguments(Path.GetFileNameWithoutExtension(file.Name))); if (npcDesc != null) { _npcs.Add(npcDesc.UniqueID, npcDesc); } } Console.WriteLine($"Loaded {_npcs.Count} NPCs."); }
public NPC(NPCDescriptor descriptor, Map map) : this(descriptor) { if (descriptor == null) { Engine.Services.Get <Logger>().LogEvent($"Null npc spawned on map {map.Name}!", LogTypes.ERROR, new Exception($"Null npc spawned on map {map.Name}!")); } this.GameTimers = new GameTimerManager(); this.StateMachine = new ActorStateMachine <NPC>(this); this.CollisionBody = new CollisionBody(this); _map = map; this.Sprite = new SpriteInfo(this.TexturePath); this.Layer = map.Layers.ElementAt(0); _random = new Random(); _targetPath = new Stack <Vector>(); _map.AddActor(this); var npcDataPacket = new Packet(PacketType.NPC_DATA, ChannelType.UNASSIGNED); npcDataPacket.Message.Write(this.Pack()); _map.SendPacket(npcDataPacket, NetDeliveryMethod.ReliableOrdered); try { this.Behavior?.OnCreated(this); } catch (Exception ex) { Engine.Services.Get <Logger>().LogEvent("Error handling OnCreated: " + ex.Message, LogTypes.ERROR, ex); } }
public NPCSpawnAttributeData(NPCDescriptor npc, int respawnTime, int maxSpawns) { this.NPCID = npc.Name; this.RespawnTime = respawnTime; this.MaxSpawns = maxSpawns; }
public NPCDefinition(NPCDescriptor descriptor) { this.Descriptor = descriptor; this.InitalizeScripts(descriptor); }
public void Initalize() { _npc = _project.LoadNPC(this.ContentFile.FullName); if (_npc == null) { base.Close(); DarkMessageBox.ShowError("Error loading npc!", "Error!"); return; } this.txtName.Text = _npc.Name; this.txtStr.Text = _npc.Stats.Strength.ToString(); this.txtInt.Text = _npc.Stats.Intelligence.ToString(); this.txtDef.Text = _npc.Stats.Defense.ToString(); this.txtHealth.Text = _npc.Stats.CurrentHealth.ToString(); this.txtDex.Text = _npc.Stats.Dexterity.ToString(); this.txtFrameWidth.Text = _npc.FrameSize.X.ToString(); this.txtFrameHeight.Text = _npc.FrameSize.Y.ToString(); this.txtColLeft.Text = _npc.CollisionBounds.X.ToString(); this.txtColTop.Text = _npc.CollisionBounds.Y.ToString(); this.txtColWidth.Text = _npc.CollisionBounds.Width.ToString(); this.txtColHeight.Text = _npc.CollisionBounds.Height.ToString(); this.txtMaxRoam.Text = _npc.MaxRoam.X.ToString(); this.txtSpeed.Text = _npc.Speed.ToString(); this.txtAggressiveRange.Text = _npc.AggresiveRange.ToString(); this.txtReachX.Text = _npc.Reach.X.ToString(); this.txtReachY.Text = _npc.Reach.Y.ToString(); this.cmbEquipSlot.DataSource = Enum.GetValues(typeof(EquipmentSlots)); this.cmbEquipSlot.SelectedItem = EquipmentSlots.MainArm; this.cmbDialogue.Items.Add("None"); foreach (var dialogue in _project.DialogueFiles) { var comboItem = new DarkComboItem(Path.GetFileNameWithoutExtension(dialogue.Name)) { Tag = dialogue }; this.cmbDialogue.Items.Add(comboItem); } if (!string.IsNullOrEmpty(_npc.Dialogue) && this.cmbDialogue.Items.Contains(_npc.Dialogue)) { this.cmbDialogue.SelectedItem = Path.GetFileNameWithoutExtension(_npc.Dialogue); _selectedDialogue = _project.LoadDialogue((((DarkComboItem)this.cmbDialogue.SelectedItem).Tag as FileInfo).FullName); _npc.Dialogue = _selectedDialogue.Name; this.cmbDialogueBranch.Items.Add("None"); foreach (var branch in _selectedDialogue.Branches) { this.cmbDialogueBranch.Items.Add(branch.Name); } if (this.cmbDialogueBranch.Items.Contains(_npc.DialogueBranch)) { this.cmbDialogueBranch.SelectedItem = _npc.DialogueBranch; } else { this.cmbDialogueBranch.SelectedItem = "None"; } this.cmbDialogueBranch.Enabled = true; this.cmbDialogueBranch.Enabled = true; } else { this.cmbDialogue.SelectedItem = "None"; this.cmbDialogueBranch.Enabled = false; } this.UpdateCustomVariablesView(); if (File.Exists(_project.ClientRootDirectory + "/" + _npc.TexturePath)) { this.picSpriteSheet.Load(_project.ClientRootDirectory + "/" + _npc.TexturePath); this.picCollisionPreview.Load(_project.ClientRootDirectory + "/" + _npc.TexturePath); if (_npc.FrameSize == Vector.Zero) { _npc.FrameSize = new Vector(this.picSpriteSheet.Image.Width, this.picSpriteSheet.Image.Height); } this.txtFrameWidth.Text = _npc.FrameSize.X.ToString(); this.txtFrameHeight.Text = _npc.FrameSize.Y.ToString(); } else if (!string.IsNullOrEmpty(_npc.TexturePath)) { DarkMessageBox.ShowError($"Cannot load sprite sheet image {_npc.TexturePath}, the file does not exist!", "Error!", DarkDialogButton.Ok); } _unsaved = true; }