private void Execute(ref short dState, bool isStart, MapPlayer player) { DialogEntry entry; while (_entries.TryGetValue(dState, out entry)) { if (entry.Type == DialogType.Greetings && (!isStart || _npcs[entry.Npc] != player.Dialog)) { dState++; continue; } if (entry.Condition == DialogCondition.Always || CheckCondition(dState, isStart, player, entry)) { switch (entry.Type) { case DialogType.Choice: SetChoices(dState, isStart, player, entry); return; case DialogType.Command: ExecuteCommand(ref dState, isStart, player, entry); if (entry.IsEnd) { return; } if (!entry.IsGoTo) { dState++; } continue; case DialogType.Say: case DialogType.Greetings: player.DialogSetMessage(_npcs[entry.Npc], entry.Message); return; } } else { dState++; } } player.DialogEnd(); }
public void OnDialogNext(MapPlayer player) { short dState = player.Data.GetDialogState(_id); if (_entries.TryGetValue(dState, out var entry)) { ExecuteCommand(ref dState, false, player, entry); if (!entry.IsEnd) { if (!entry.IsGoTo) { dState++; } Execute(ref dState, false, player); } } else { player.DialogEnd(); } player.Data.Dialogs[_id] = dState; }
private bool SelectChoice(ref short dState, bool isStart, MapPlayer player, int index) { List <DialogChoice> choices = player.Choices; DialogEntry entry; if (index < 0 || index >= choices.Count) { return(false); } var choice = choices[index]; choices.Clear(); if (_entries.TryGetValue(choice.State, out entry)) { dState = choice.State; if (entry.Condition == DialogCondition.Always || CheckCondition(dState, isStart, player, entry)) { player.LastDialogChoice = dState; if (entry.Command != DialogCommand.None) { ExecuteCommand(ref dState, isStart, player, entry); } if (entry.IsEnd) { return(false); } if (entry.IsGoTo) { return(true); } } while (_entries.TryGetValue(dState, out entry) && entry.Type == DialogType.Choice) { dState++; } return(true); } player.DialogEnd(); return(false); }
private void ExecuteCommand(ref short dState, bool isStart, MapPlayer player, DialogEntry entry) { int var01; WO_NPC var02; switch (entry.Command) { case DialogCommand.DialogEnd: if (entry.CommandData01 >= 0) { dState = (short)entry.CommandData01; } player.DialogEnd(); return; case DialogCommand.GoTo: if (entry.CommandData01 >= 0) { if (entry.CommandData02 > entry.CommandData01) { dState = (short)Constants.RND.Next(entry.CommandData01, entry.CommandData02 + 1); } else { dState = (short)entry.CommandData01; } } return; case DialogCommand.AddXP: if (entry.CommandData02 == -1) { player.Stats.AddExpAll((uint)entry.CommandData01); } else { player.Stats.AddExp((TalentMarkId)entry.CommandData02, (uint)entry.CommandData01); } break; case DialogCommand.AddBits: player.Items.AddBits(entry.CommandData01); break; case DialogCommand.AddItem: player.Items.AddItems(entry.CommandData01, entry.CommandData02); break; case DialogCommand.RemoveBits: player.Items.AddBits(-entry.CommandData01); break; case DialogCommand.RemoveItem: player.Items.RemoveItems(entry.CommandData01, entry.CommandData02); break; case DialogCommand.CloneNPCIndex: if (!player.Clones.ContainsKey(_npcs[entry.Npc].NPC.ID)) { _npcs[entry.Npc].Clone(player); } break; case DialogCommand.SetCloneMoveState: var01 = _npcs[entry.Npc].NPC.ID; if (player.Clones.TryGetValue(var01, out var02) && var02.Movement is ScriptedMovement) { (var02.Movement as ScriptedMovement).State = (ushort)entry.CommandData01; } break; case DialogCommand.AddQuest: case DialogCommand.RemoveQuest: case DialogCommand.SetQuestState: break; } }