예제 #1
0
 private void ProcessSegment(PlayerObject player, NPCPage page, NPCSegment segment, uint objectID)
 {
     player.NPCObjectID = objectID;
     player.NPCScriptID = ScriptID;
     player.NPCSuccess.Add(segment, segment.Check(player));
     player.NPCPage = page;
 }
예제 #2
0
        private List <NPCPage> ParsePages(IList <string> lines, string key = MainKey)
        {
            List <NPCPage> pages   = new List <NPCPage>();
            List <string>  buttons = new List <string>();

            NPCPage page = ParsePage(lines, key);

            pages.Add(page);

            buttons.AddRange(page.Buttons);

            for (int i = 0; i < buttons.Count; i++)
            {
                string section = buttons[i];

                bool match = pages.Any(t => t.Key.ToUpper() == section.ToUpper());

                if (match)
                {
                    continue;
                }

                page = ParsePage(lines, section);
                buttons.AddRange(page.Buttons);

                pages.Add(page);
            }

            return(pages);
        }
예제 #3
0
        private void Response(PlayerObject player, NPCPage page)
        {
            player.Enqueue(new S.NPCResponse {
                Page = player.NPCSpeech
            });

            ProcessSpecial(player, page);
        }
예제 #4
0
        public void Call(string key)
        {
            key = key.ToUpper();

            for (int i = 0; i < NPCPages.Count; i++)
            {
                NPCPage page = NPCPages[i];
                if (!String.Equals(page.Key, key, StringComparison.CurrentCultureIgnoreCase)) continue;

                foreach (NPCSegment segment in page.SegmentList)
                {
                    if (page.BreakFromSegments)
                    {
                        page.BreakFromSegments = false;
                        break;
                    }

                    ProcessSegment(page, segment);
                }
            }
        }
예제 #5
0
 private void ProcessSegment(MonsterObject monster, NPCPage page, NPCSegment segment)
 {
     segment.Check(monster);
 }
예제 #6
0
        private NPCPage ParsePage(IList<string> scriptLines, string sectionName)
        {
            bool nextPage = false, nextSection = false;

            List<string> lines = scriptLines.Where(x => !string.IsNullOrEmpty(x)).ToList();

            NPCPage Page = new NPCPage(sectionName);

            //Cleans arguments out of search page name
            string tempSectionName = Page.ArgumentParse(sectionName);

            //parse all individual pages in a script, defined by sectionName
            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];

                if (line.StartsWith(";")) continue;

                if (!lines[i].ToUpper().StartsWith(tempSectionName.ToUpper())) continue;

                List<string> segmentLines = new List<string>();

                nextPage = false;

                //Found a page, now process that page and split it into segments
                for (int j = i + 1; j < lines.Count; j++)
                {
                    if (lines[j].StartsWith(";")) continue;

                    string nextLine = lines[j];

                    if (j < lines.Count - 1)
                        nextLine = lines[j + 1];
                    else
                        nextLine = "";

                    if (lines[j].StartsWith("#INCLUDE"))
                    {
                        lines.InsertRange(j + 1, ParseInclude(lines[j]).Where(x => !string.IsNullOrEmpty(x)).ToList());
                        continue;
                    }

                    if (nextLine.StartsWith("[") && nextLine.EndsWith("]"))
                    {
                        nextPage = true;
                    }

                    else if (nextLine.StartsWith("#IF"))
                    {
                        nextSection = true;
                    }

                    if (nextSection || nextPage)
                    {
                        segmentLines.Add(lines[j]);

                        //end of segment, so need to parse it and put into the segment list within the page
                        if (segmentLines.Count > 0)
                        {
                            NPCSegment segment = ParseSegment(Page, segmentLines);

                            List<string> currentButtons = new List<string>();
                            currentButtons.AddRange(segment.Buttons);
                            currentButtons.AddRange(segment.ElseButtons);
                            currentButtons.AddRange(segment.GotoButtons);

                            Page.Buttons.AddRange(currentButtons);
                            Page.SegmentList.Add(segment);
                            segmentLines.Clear();

                            nextSection = false;
                        }

                        if (nextPage) break;

                        continue;
                    }

                    segmentLines.Add(lines[j]);
                }

                //bottom of script reached, add all lines found to new segment
                if (segmentLines.Count > 0)
                {
                    NPCSegment segment = ParseSegment(Page, segmentLines);

                    List<string> currentButtons = new List<string>();
                    currentButtons.AddRange(segment.Buttons);
                    currentButtons.AddRange(segment.ElseButtons);
                    currentButtons.AddRange(segment.GotoButtons);

                    Page.Buttons.AddRange(currentButtons);
                    Page.SegmentList.Add(segment);
                    segmentLines.Clear();
                }

                return Page;
            }

            return Page;
        }
예제 #7
0
        private void ProcessPage(PlayerObject player, NPCPage page)
        {
            player.NPCID = ObjectID;
            player.NPCPage = page;
            player.NPCSuccess = page.Check(player);

            switch (page.Key)
            {
                case BuyKey:
                    for (int i = 0; i < Goods.Count; i++)
                        player.CheckItemInfo(Goods[i]);

                    player.Enqueue(new S.NPCGoods {List = GoodsIndex, Rate = Info.PriceRate});
                    break;
                case SellKey:
                    player.Enqueue(new S.NPCSell());
                    break;
                case RepairKey:
                    player.Enqueue(new S.NPCRepair { Rate = Info.PriceRate });
                    break;
                case SRepairKey:
                    player.Enqueue(new S.NPCSRepair { Rate = Info.PriceRate });
                    break;
                case StorageKey:
                    player.SendStorage();
                    player.Enqueue(new S.NPCStorage());
                    break;
                case BuyBackKey:
                    break;
                case ConsignKey:
                    player.Enqueue(new S.NPCConsign());
                    break;
                case MarketKey:
                    player.UserMatch = false;
                    player.GetMarket(string.Empty, ItemType.Nothing);
                    break;
                case ConsignmentsKey:
                    player.UserMatch = true;
                    player.GetMarket(string.Empty, ItemType.Nothing);
                    break;
            }
        }
예제 #8
0
        private NPCSegment ParseSegment(NPCPage page, IEnumerable <string> scriptLines)
        {
            List <string>
            checks          = new List <string>(),
                acts        = new List <string>(),
                say         = new List <string>(),
                buttons     = new List <string>(),
                elseSay     = new List <string>(),
                elseActs    = new List <string>(),
                elseButtons = new List <string>(),
                gotoButtons = new List <string>();

            List <string> lines = scriptLines.ToList();
            List <string> currentSay = say, currentButtons = buttons;

            Regex regex = new Regex(@"<.*?/(\@.*?)>");

            for (int i = 0; i < lines.Count; i++)
            {
                if (string.IsNullOrEmpty(lines[i]))
                {
                    continue;
                }

                if (lines[i].StartsWith(";"))
                {
                    continue;
                }

                if (lines[i].StartsWith("#"))
                {
                    string[] action = lines[i].Remove(0, 1).ToUpper().Trim().Split(' ');
                    switch (action[0])
                    {
                    case "IF":
                        currentSay     = checks;
                        currentButtons = null;
                        continue;

                    case "SAY":
                        currentSay     = say;
                        currentButtons = buttons;
                        continue;

                    case "ACT":
                        currentSay     = acts;
                        currentButtons = gotoButtons;
                        continue;

                    case "ELSESAY":
                        currentSay     = elseSay;
                        currentButtons = elseButtons;
                        continue;

                    case "ELSEACT":
                        currentSay     = elseActs;
                        currentButtons = gotoButtons;
                        continue;

                    default:
                        throw new NotImplementedException();
                    }
                }

                if (lines[i].StartsWith("[") && lines[i].EndsWith("]"))
                {
                    break;
                }

                if (currentButtons != null)
                {
                    Match match = regex.Match(lines[i]);

                    while (match.Success)
                    {
                        string argu = match.Groups[1].Captures[0].Value;

                        currentButtons.Add(string.Format("[{0}]", argu));
                        match = match.NextMatch();
                    }

                    //Check if line has a goto command
                    var parts = lines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    if (parts.Count() > 1)
                    {
                        switch (parts[0].ToUpper())
                        {
                        case "GOTO":
                        case "GROUPGOTO":
                            gotoButtons.Add(string.Format("[{0}]", parts[1].ToUpper()));
                            break;

                        case "TIMERECALL":
                        case "DELAYGOTO":
                        case "TIMERECALLGROUP":
                            if (parts.Length > 2)
                            {
                                gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper()));
                            }
                            break;
                        }
                    }
                }

                currentSay.Add(lines[i].TrimEnd());
            }

            NPCSegment segment = new NPCSegment(page, say, buttons, elseSay, elseButtons, gotoButtons);

            for (int i = 0; i < checks.Count; i++)
            {
                segment.ParseCheck(checks[i]);
            }

            for (int i = 0; i < acts.Count; i++)
            {
                segment.ParseAct(segment.ActList, acts[i]);
            }

            for (int i = 0; i < elseActs.Count; i++)
            {
                segment.ParseAct(segment.ElseActList, elseActs[i]);
            }


            currentButtons = new List <string>();
            currentButtons.AddRange(buttons);
            currentButtons.AddRange(elseButtons);
            currentButtons.AddRange(gotoButtons);

            return(segment);
        }
예제 #9
0
        private NPCSegment ParseSegment(NPCPage page, IEnumerable<string> scriptLines)
        {
            List<string>
                checks = new List<string>(),
                acts = new List<string>(),
                say = new List<string>(),
                buttons = new List<string>(),
                elseSay = new List<string>(),
                elseActs = new List<string>(),
                elseButtons = new List<string>(),
                gotoButtons = new List<string>();

            List<string> lines = scriptLines.ToList();
            List<string> currentSay = say, currentButtons = buttons;

            for (int i = 0; i < lines.Count; i++)
            {
                if (string.IsNullOrEmpty(lines[i])) continue;

                if (lines[i].StartsWith("#"))
                {
                    string[] action = lines[i].Remove(0, 1).ToUpper().Trim().Split(' ');
                    switch (action[0])
                    {
                        case "IF":
                            currentSay = checks;
                            currentButtons = null;
                            continue;
                        case "SAY":
                            currentSay = say;
                            currentButtons = buttons;
                            continue;
                        case "ACT":
                            currentSay = acts;
                            currentButtons = gotoButtons;
                            continue;
                        case "ELSESAY":
                            currentSay = elseSay;
                            currentButtons = elseButtons;
                            continue;
                        case "ELSEACT":
                            currentSay = elseActs;
                            currentButtons = gotoButtons;
                            continue;
                        default:
                            throw new NotImplementedException();
                    }
                }

                if (lines[i].StartsWith("[") && lines[i].EndsWith("]")) break;

                if (currentButtons != null)
                {
                    Match match = Regex.Match(lines[i]);
                    while (match.Success)
                    {
                        string argu = match.Groups[1].Captures[0].Value;

                        currentButtons.Add(string.Format("[{0}]", argu));//ToUpper()
                        match = match.NextMatch();
                    }

                    //Check if line has a goto command
                    var parts = lines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    if (parts.Count() > 1)
                        switch (parts[0].ToUpper())
                        {
                            case "GOTO":
                            case "GROUPGOTO":
                                gotoButtons.Add(string.Format("[{0}]", parts[1].ToUpper()));
                                break;
                            case "TIMERECALL":
                                if (parts.Length > 2)
                                    gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper()));
                                break;
                            case "TIMERECALLGROUP":
                                if (parts.Length > 2)
                                    gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper()));
                                break;
                            case "DELAYGOTO":
                                gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper()));
                                break;
                        }
                }

                currentSay.Add(lines[i].TrimEnd());
            }

            NPCSegment segment = new NPCSegment(page, say, buttons, elseSay, elseButtons, gotoButtons);

            for (int i = 0; i < checks.Count; i++)
                segment.ParseCheck(checks[i]);

            for (int i = 0; i < acts.Count; i++)
                segment.ParseAct(segment.ActList, acts[i]);

            for (int i = 0; i < elseActs.Count; i++)
                segment.ParseAct(segment.ElseActList, elseActs[i]);

            currentButtons = new List<string>();
            currentButtons.AddRange(buttons);
            currentButtons.AddRange(elseButtons);
            currentButtons.AddRange(gotoButtons);

            return segment;
        }
예제 #10
0
 private void ProcessSegment(PlayerObject player, NPCPage page, NPCSegment segment)
 {
     player.NPCID      = ObjectID;
     player.NPCSuccess = segment.Check(player);
     player.NPCPage    = page;
 }
예제 #11
0
        public void Call(PlayerObject player, string key)
        {
            key = key.ToUpper();

            if (!player.NPCDelayed)
            {
                if (key != MainKey) // && ObjectID != player.DefaultNPC.ObjectID
                {
                    if (player.NPCID != ObjectID)
                    {
                        return;
                    }

                    bool found = false;

                    if (player.NPCSuccess)
                    {
                        foreach (NPCSegment segment in player.NPCPage.SegmentList)
                        {
                            if (segment.Buttons.Any(c => c.ToUpper().Contains(key)))
                            {
                                found = true;
                            }
                        }
                    }
                    else
                    {
                        foreach (NPCSegment segment in player.NPCPage.SegmentList)
                        {
                            if (!segment.ElseButtons.Any(c => c.ToUpper().Contains(key)))
                            {
                                found = true;
                            }
                        }
                    }

                    if (!found)
                    {
                        return;
                    }
                }
            }
            else
            {
                player.NPCDelayed = false;
            }

            if (key.StartsWith("[@@") && player.NPCInputStr == string.Empty)
            {
                //send off packet to request input
                player.Enqueue(new S.NPCRequestInput {
                    NPCID = ObjectID, PageName = key
                });
                return;
            }

            for (int i = 0; i < NPCPages.Count; i++)
            {
                NPCPage page = NPCPages[i];
                if (!String.Equals(page.Key, key, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                player.NPCSpeech = new List <string>();

                foreach (NPCSegment segment in page.SegmentList)
                {
                    ProcessSegment(player, page, segment);
                }

                Response(player, page);
            }


            player.NPCInputStr = string.Empty;
        }
예제 #12
0
파일: NPCObject.cs 프로젝트: Pete107/Mir2
 private void ProcessSegment(NPCPage page, NPCSegment segment)
 {
     segment.Check();
 }
예제 #13
0
파일: NPCObject.cs 프로젝트: Pete107/Mir2
 private void ProcessSegment(MonsterObject Monster, NPCPage page, NPCSegment segment)
 {
     segment.Check(Monster);
 }
예제 #14
0
 private void ProcessSegment(NPCPage page, NPCSegment segment)
 {
     segment.Check();
 }
예제 #15
0
 private void ProcessSegment(PlayerObject player, NPCPage page, NPCSegment segment)
 {
     player.NPCID = ObjectID;
     player.NPCSuccess = segment.Check(player);
     player.NPCPage = page;
 }
예제 #16
0
        private void ProcessSpecial(PlayerObject player, NPCPage page)
        {
            List <UserItem> allGoods = new List <UserItem>();

            switch (page.Key.ToUpper())
            {
            case BuyKey:
                for (int i = 0; i < Goods.Count; i++)
                {
                    player.CheckItem(Goods[i]);
                }

                player.Enqueue(new S.NPCGoods {
                    List = Goods, Rate = PriceRate(player), Type = PanelType.Buy
                });
                break;

            case SellKey:
                player.Enqueue(new S.NPCSell());
                break;

            case BuySellKey:
                for (int i = 0; i < Goods.Count; i++)
                {
                    player.CheckItem(Goods[i]);
                }

                player.Enqueue(new S.NPCGoods {
                    List = Goods, Rate = PriceRate(player), Type = PanelType.Buy
                });
                player.Enqueue(new S.NPCSell());
                break;

            case RepairKey:
                player.Enqueue(new S.NPCRepair {
                    Rate = PriceRate(player)
                });
                break;

            case SRepairKey:
                player.Enqueue(new S.NPCSRepair {
                    Rate = PriceRate(player)
                });
                break;

            case CraftKey:
                for (int i = 0; i < CraftGoods.Count; i++)
                {
                    player.CheckItemInfo(CraftGoods[i].Item.Info);
                }

                player.Enqueue(new S.NPCGoods {
                    List = (from x in CraftGoods where x.CanCraft(player) select x.Item).ToList(), Rate = PriceRate(player), Type = PanelType.Craft
                });
                break;

            case RefineKey:
                if (player.Info.CurrentRefine != null)
                {
                    player.ReceiveChat("You're already refining an item.", ChatType.System);
                    player.Enqueue(new S.NPCRefine {
                        Rate = (Settings.RefineCost), Refining = true
                    });
                    break;
                }
                else
                {
                    player.Enqueue(new S.NPCRefine {
                        Rate = (Settings.RefineCost), Refining = false
                    });
                }
                break;

            case RefineCheckKey:
                player.Enqueue(new S.NPCCheckRefine());
                break;

            case RefineCollectKey:
                player.CollectRefine();
                break;

            case ReplaceWedRingKey:
                player.Enqueue(new S.NPCReplaceWedRing {
                    Rate = Settings.ReplaceWedRingCost
                });
                break;

            case StorageKey:
                player.SendStorage();
                player.Enqueue(new S.NPCStorage());
                break;

            case BuyBackKey:
            {
                var callingNPC = NPCObject.Get(player.NPCObjectID);

                if (callingNPC != null)
                {
                    if (!callingNPC.BuyBack.ContainsKey(player.Name))
                    {
                        callingNPC.BuyBack[player.Name] = new List <UserItem>();
                    }

                    for (int i = 0; i < callingNPC.BuyBack[player.Name].Count; i++)
                    {
                        player.CheckItem(callingNPC.BuyBack[player.Name][i]);
                    }

                    player.Enqueue(new S.NPCGoods {
                            List = callingNPC.BuyBack[player.Name], Rate = PriceRate(player), Type = PanelType.Buy
                        });
                }
            }
            break;

            case BuyUsedKey:
            {
                var callingNPC = NPCObject.Get(player.NPCObjectID);

                if (callingNPC != null)
                {
                    for (int i = 0; i < callingNPC.UsedGoods.Count; i++)
                    {
                        player.CheckItem(callingNPC.UsedGoods[i]);
                    }

                    player.Enqueue(new S.NPCGoods {
                            List = callingNPC.UsedGoods, Rate = PriceRate(player), Type = PanelType.Buy
                        });
                }
            }
            break;

            case ConsignKey:
                player.Enqueue(new S.NPCConsign());
                break;

            case MarketKey:
                player.UserMatch = false;
                player.GetMarket(string.Empty, ItemType.Nothing);
                break;

            case GuildCreateKey:
                if (player.Info.Level < Settings.Guild_RequiredLevel)
                {
                    player.ReceiveChat(String.Format("You have to be at least level {0} to create a guild.", Settings.Guild_RequiredLevel), ChatType.System);
                }
                else if (player.MyGuild == null)
                {
                    player.CanCreateGuild = true;
                    player.Enqueue(new S.GuildNameRequest());
                }
                else
                {
                    player.ReceiveChat("You are already part of a guild.", ChatType.System);
                }
                break;

            case RequestWarKey:
                if (player.MyGuild != null)
                {
                    if (player.MyGuildRank != player.MyGuild.Ranks[0])
                    {
                        player.ReceiveChat("You must be the leader to request a war.", ChatType.System);
                        return;
                    }
                    player.Enqueue(new S.GuildRequestWar());
                }
                else
                {
                    player.ReceiveChat(GameLanguage.NotInGuild, ChatType.System);
                }
                break;

            case SendParcelKey:
                player.Enqueue(new S.MailSendRequest());
                break;

            case CollectParcelKey:

                sbyte result = 0;

                if (player.GetMailAwaitingCollectionAmount() < 1)
                {
                    result = -1;
                }
                else
                {
                    foreach (var mail in player.Info.Mail)
                    {
                        if (mail.Parcel)
                        {
                            mail.Collected = true;
                        }
                    }
                }
                player.Enqueue(new S.ParcelCollected {
                    Result = result
                });
                player.GetMail();
                break;

            case AwakeningKey:
                player.Enqueue(new S.NPCAwakening());
                break;

            case DisassembleKey:
                player.Enqueue(new S.NPCDisassemble());
                break;

            case DowngradeKey:
                player.Enqueue(new S.NPCDowngrade());
                break;

            case ResetKey:
                player.Enqueue(new S.NPCReset());
                break;

            case PearlBuyKey:
                for (int i = 0; i < Goods.Count; i++)
                {
                    player.CheckItem(Goods[i]);
                }

                player.Enqueue(new S.NPCPearlGoods {
                    List = Goods, Rate = PriceRate(player)
                });
                break;
            }
        }
예제 #17
0
        private void ProcessSpecial(PlayerObject player, NPCPage page)
        {
            List<UserItem> allGoods = new List<UserItem>();

            switch (page.Key.ToUpper())
            {
                case BuyKey:
                    for (int i = 0; i < Goods.Count; i++)
                        player.CheckItem(Goods[i]);

                    player.Enqueue(new S.NPCGoods { List = Goods, Rate = Info.PriceRate });
                    break;
                case SellKey:
                    player.Enqueue(new S.NPCSell());
                    break;
                case BuySellKey:
                    for (int i = 0; i < Goods.Count; i++)
                        player.CheckItem(Goods[i]);

                    player.Enqueue(new S.NPCGoods { List = Goods, Rate = Info.PriceRate });
                    player.Enqueue(new S.NPCSell());
                    break;
                case RepairKey:
                    player.Enqueue(new S.NPCRepair { Rate = Info.PriceRate });
                    break;
                case SRepairKey:
                    player.Enqueue(new S.NPCSRepair { Rate = Info.PriceRate });
                    break;
                case RefineKey:
                    if (player.Info.CurrentRefine != null)
                    {
                        player.ReceiveChat("You're already refining an item.", ChatType.System);
                        player.Enqueue(new S.NPCRefine { Rate = (Settings.RefineCost), Refining = true });
                        break;
                    }
                    else
                        player.Enqueue(new S.NPCRefine { Rate = (Settings.RefineCost), Refining = false });
                    break;
                case RefineCheckKey:
                    player.Enqueue(new S.NPCCheckRefine());
                    break;
                case RefineCollectKey:
                    player.CollectRefine();
                    break;
                case ReplaceWedRingKey:
                    player.Enqueue(new S.NPCReplaceWedRing { Rate = Settings.ReplaceWedRingCost });
                    break;
                case StorageKey:
                    player.SendStorage();
                    player.Enqueue(new S.NPCStorage());
                    break;
                case BuyBackKey:
                    if (!BuyBack.ContainsKey(player.Name)) BuyBack[player.Name] = new List<UserItem>();

                    for (int i = 0; i < BuyBack[player.Name].Count; i++)
                    {
                        player.CheckItem(BuyBack[player.Name][i]);
                    }

                    player.Enqueue(new S.NPCGoods { List = BuyBack[player.Name], Rate = Info.PriceRate });
                    break;
                case BuyUsedKey:
                    for (int i = 0; i < UsedGoods.Count; i++)
                        player.CheckItem(UsedGoods[i]);

                    player.Enqueue(new S.NPCGoods { List = UsedGoods, Rate = Info.PriceRate });
                    break;
                case ConsignKey:
                    player.Enqueue(new S.NPCConsign());
                    break;
                case MarketKey:
                    player.UserMatch = false;
                    player.GetMarket(string.Empty, ItemType.Nothing);
                    break;
                case ConsignmentsKey:
                    player.UserMatch = true;
                    player.GetMarket(string.Empty, ItemType.Nothing);
                    break;
                case GuildCreateKey:
                    if (player.Info.Level < Settings.Guild_RequiredLevel)
                    {
                        player.ReceiveChat(String.Format("You have to be at least level {0} to create a guild.", Settings.Guild_RequiredLevel), ChatType.System);
                    }
                    if (player.MyGuild == null)
                    {
                        player.CanCreateGuild = true;
                        player.Enqueue(new S.GuildNameRequest());
                    }
                    else
                        player.ReceiveChat("You are already part of a guild.", ChatType.System);
                    break;
                case RequestWarKey:
                    if (player.MyGuild != null)
                    {
                        if (player.MyGuildRank != player.MyGuild.Ranks[0])
                        {
                            player.ReceiveChat("You must be the leader to request a war.", ChatType.System);
                            return;
                        }
                        player.Enqueue(new S.GuildRequestWar());
                    }
                    else
                    {
                        player.ReceiveChat("You are not in a guild.", ChatType.System);
                    }
                    break;
                case SendParcelKey:
                    player.Enqueue(new S.MailSendRequest());
                    break;
                case CollectParcelKey:

                    sbyte result = 0;

                    if (player.GetMailAwaitingCollectionAmount() < 1)
                    {
                        result = -1;
                    }
                    else
                    {
                        foreach (var mail in player.Info.Mail)
                        {
                            if (mail.Parcel) mail.Collected = true;
                        }
                    }
                    player.Enqueue(new S.ParcelCollected { Result = result });
                    player.GetMail();
                    break;
                case AwakeningKey:
                    player.Enqueue(new S.NPCAwakening());
                    break;
                case DisassembleKey:
                    player.Enqueue(new S.NPCDisassemble());
                    break;
                case DowngradeKey:
                    player.Enqueue(new S.NPCDowngrade());
                    break;
                case ResetKey:
                    player.Enqueue(new S.NPCReset());
                    break;
                case PearlBuyKey:
                    for (int i = 0; i < Goods.Count; i++)
                        player.CheckItem(Goods[i]);

                    player.Enqueue(new S.NPCPearlGoods { List = Goods, Rate = Info.PriceRate });
                    break;
            }
        }
예제 #18
0
        private NPCPage ParsePage(IList <string> scriptLines, string sectionName)
        {
            bool nextPage = false, nextSection = false;

            List <string> lines = scriptLines.Where(x => !string.IsNullOrEmpty(x)).ToList();

            NPCPage Page = new NPCPage(sectionName);

            //Cleans arguments out of search page name
            string tempSectionName = Page.ArgumentParse(sectionName);

            //parse all individual pages in a script, defined by sectionName
            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];

                if (line.StartsWith(";"))
                {
                    continue;
                }

                if (!lines[i].ToUpper().StartsWith(tempSectionName.ToUpper()))
                {
                    continue;
                }

                List <string> segmentLines = new List <string>();

                nextPage = false;

                //Found a page, now process that page and split it into segments
                for (int j = i + 1; j < lines.Count; j++)
                {
                    string nextLine = lines[j];

                    if (j < lines.Count - 1)
                    {
                        nextLine = lines[j + 1];
                    }
                    else
                    {
                        nextLine = "";
                    }

                    if (nextLine.StartsWith("[") && nextLine.EndsWith("]"))
                    {
                        nextPage = true;
                    }

                    else if (nextLine.StartsWith("#IF"))
                    {
                        nextSection = true;
                    }

                    if (nextSection || nextPage)
                    {
                        segmentLines.Add(lines[j]);

                        //end of segment, so need to parse it and put into the segment list within the page
                        if (segmentLines.Count > 0)
                        {
                            NPCSegment segment = ParseSegment(Page, segmentLines);

                            List <string> currentButtons = new List <string>();
                            currentButtons.AddRange(segment.Buttons);
                            currentButtons.AddRange(segment.ElseButtons);
                            currentButtons.AddRange(segment.GotoButtons);

                            Page.Buttons.AddRange(currentButtons);
                            Page.SegmentList.Add(segment);
                            segmentLines.Clear();

                            nextSection = false;
                        }

                        if (nextPage)
                        {
                            break;
                        }

                        continue;
                    }

                    segmentLines.Add(lines[j]);
                }

                //bottom of script reached, add all lines found to new segment
                if (segmentLines.Count > 0)
                {
                    NPCSegment segment = ParseSegment(Page, segmentLines);

                    List <string> currentButtons = new List <string>();
                    currentButtons.AddRange(segment.Buttons);
                    currentButtons.AddRange(segment.ElseButtons);
                    currentButtons.AddRange(segment.GotoButtons);

                    Page.Buttons.AddRange(currentButtons);
                    Page.SegmentList.Add(segment);
                    segmentLines.Clear();
                }

                return(Page);
            }

            return(Page);
        }
예제 #19
0
        private void Response(PlayerObject player, NPCPage page)
        {
            player.Enqueue(new S.NPCResponse { Page = player.NPCSpeech });

            ProcessSpecial(player, page);
        }
예제 #20
0
        public void Call(PlayerObject player, uint objectID, string key)
        {
            key = key.ToUpper();

            if (!player.NPCDelayed)
            {
                if (key != MainKey)
                {
                    if (player.NPCObjectID != objectID)
                    {
                        return;
                    }

                    bool found = false;

                    foreach (NPCSegment segment in player.NPCPage.SegmentList)
                    {
                        if (!player.NPCSuccess.TryGetValue(segment, out bool result))
                        {
                            break;                                                           //no result for segment ?
                        }
                        if ((result ? segment.Buttons : segment.ElseButtons).Any(s => s.ToUpper() == key))
                        {
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        MessageQueue.Enqueue(string.Format("Player: {0} was prevented access to NPC key: '{1}' ", player.Name, key));
                        return;
                    }
                }
            }
            else
            {
                player.NPCDelayed = false;
            }

            if (key.StartsWith("[@@") && player.NPCInputStr == string.Empty)
            {
                //send off packet to request input
                player.Enqueue(new S.NPCRequestInput {
                    NPCID = player.NPCObjectID, PageName = key
                });
                return;
            }

            for (int i = 0; i < NPCPages.Count; i++)
            {
                NPCPage page = NPCPages[i];
                if (!String.Equals(page.Key, key, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                player.NPCSpeech = new List <string>();
                player.NPCSuccess.Clear();

                foreach (NPCSegment segment in page.SegmentList)
                {
                    if (page.BreakFromSegments)
                    {
                        page.BreakFromSegments = false;
                        break;
                    }

                    ProcessSegment(player, page, segment, objectID);
                }

                Response(player, page);
            }


            player.NPCInputStr = string.Empty;
        }
예제 #21
0
        private List<string> ParseSection(IList<string> lines, string sectionName)
        {
            List<string>
                checks = new List<string>(),
                acts = new List<string>(),
                say = new List<string>(),
                buttons = new List<string>(),
                elseSay = new List<string>(),
                elseActs = new List<string>(),
                elseButtons = new List<string>();

            List<string> currentSay = say, currentButtons = buttons;

            for (int i = 0; i < lines.Count; i++)
            {
                if (!lines[i].StartsWith(sectionName)) continue;

                for (int x = i + 1; x < lines.Count; x++)
                {
                    if (string.IsNullOrEmpty(lines[x])) continue;

                    if (lines[x].StartsWith("#"))
                    {
                        switch (lines[x].Remove(0, 1).ToUpper())
                        {
                            case "IF":
                                currentSay = checks;
                                currentButtons = null;
                                continue;
                            case "SAY":
                                currentSay = say;
                                currentButtons = buttons;
                                continue;
                            case "ACT":
                                currentSay = acts;
                                currentButtons = null;
                                continue;
                            case "ELSESAY":
                                currentSay = elseSay;
                                currentButtons = elseButtons;
                                continue;
                            case "ELSEACT":
                                currentSay = elseActs;
                                currentButtons = null;
                                continue;
                            default:
                                throw new NotImplementedException();
                        }
                    }

                    if (lines[x].StartsWith("[") && lines[x].EndsWith("]")) break;

                    if (currentButtons != null)
                    {
                        Match match = Regex.Match(lines[x]);
                        while (match.Success)
                        {
                            currentButtons.Add(string.Format("[{0}]", match.Groups[1].Captures[0].Value));
                            match = match.NextMatch();
                        }
                    }

                    currentSay.Add(lines[x].TrimEnd());
                }

                break;
            }

            NPCPage page = new NPCPage(sectionName, say, buttons, elseSay, elseButtons);

            for (int i = 0; i < checks.Count; i++)
                page.ParseCheck(checks[i]);

            for (int i = 0; i < acts.Count; i++)
                page.ParseAct(page.ActList, acts[i]);

            for (int i = 0; i < elseActs.Count; i++)
                page.ParseAct(page.ElseActList, elseActs[i]);

            NPCSections.Add(page);

            currentButtons = new List<string>();
            currentButtons.AddRange(buttons);
            currentButtons.AddRange(elseButtons);

            return currentButtons;
        }