예제 #1
0
        LoreDiscovery TryGetRandomLoreDiscovery(IWorldAccessor world, IPlayer serverplayer, string category)
        {
            Dictionary <string, LoreDiscovery> discoveredLore;

            loreDiscoveryiesByPlayerUid.TryGetValue(serverplayer.PlayerUID, out discoveredLore);

            if (discoveredLore == null)
            {
                loreDiscoveryiesByPlayerUid[serverplayer.PlayerUID] = discoveredLore = new Dictionary <string, LoreDiscovery>();
            }

            JournalAsset[] journalAssets;

            ensureJournalAssetsLoaded();
            journalAssets = journalAssetsByCode.Values.ToArray();

            journalAssets.Shuffle(world.Rand);


            for (int i = 0; i < journalAssets.Length; i++)
            {
                JournalAsset journalAsset = journalAssets[i];
                if (journalAsset.Category != category)
                {
                    continue;
                }

                if (!discoveredLore.ContainsKey(journalAsset.Code))
                {
                    return(discoveredLore[journalAsset.Code] = new LoreDiscovery()
                    {
                        Code = journalAsset.Code, ChapterIds = new List <int>()
                        {
                            0
                        }
                    });
                }

                LoreDiscovery ld = discoveredLore[journalAsset.Code];

                for (int p = 0; p < journalAsset.Pieces.Length; p++)
                {
                    if (!ld.ChapterIds.Contains(p))
                    {
                        ld.ChapterIds.Add(p);
                        return(new LoreDiscovery()
                        {
                            Code = journalAsset.Code, ChapterIds = new List <int>()
                            {
                                p
                            }
                        });
                    }
                }
            }

            return(null);
        }
예제 #2
0
        LoreDiscovery TryGetRandomLoreDiscovery(IWorldAccessor world, IPlayer serverplayer, string category)
        {
            Dictionary <string, LoreDiscovery> discoveredLore = null;

            loreDiscoveryiesByPlayerUid.TryGetValue(serverplayer.PlayerUID, out discoveredLore);

            if (discoveredLore == null)
            {
                loreDiscoveryiesByPlayerUid[serverplayer.PlayerUID] = discoveredLore = new Dictionary <string, LoreDiscovery>();
            }

            JournalAsset[] journalAssets;

            if (journalAssetsByCode == null)
            {
                journalAssetsByCode = new Dictionary <string, JournalAsset>();

                journalAssets = world.AssetManager.GetMany <JournalAsset>(world.Logger, "journal/").Values.ToArray();
                foreach (JournalAsset asset in journalAssets)
                {
                    journalAssetsByCode[asset.Code] = asset;
                }
            }
            else
            {
                journalAssets = journalAssetsByCode.Values.ToArray();
            }

            journalAssets.Shuffle(world.Rand);


            for (int i = 0; i < journalAssets.Length; i++)
            {
                JournalAsset journalAsset = journalAssets[i];
                if (journalAsset.Category != category)
                {
                    continue;
                }

                if (!discoveredLore.ContainsKey(journalAsset.Code))
                {
                    return(discoveredLore[journalAsset.Code] = new LoreDiscovery()
                    {
                        Code = journalAsset.Code, PieceIds = new List <int>()
                        {
                            0
                        }
                    });
                }

                LoreDiscovery ld = discoveredLore[journalAsset.Code];

                for (int p = 0; p < journalAsset.Pieces.Length; p++)
                {
                    if (!ld.PieceIds.Contains(p))
                    {
                        ld.PieceIds.Add(p);
                        return(new LoreDiscovery()
                        {
                            Code = journalAsset.Code, PieceIds = new List <int>()
                            {
                                p
                            }
                        });
                    }
                }
            }

            return(null);
        }
예제 #3
0
        private void OnLoreDiscovery(string eventName, ref EnumHandling handling, IAttribute data)
        {
            TreeAttribute tree      = data as TreeAttribute;
            string        playerUid = tree.GetString("playeruid");
            string        category  = tree.GetString("category");

            IServerPlayer plr = sapi.World.PlayerByUid(playerUid) as IServerPlayer;

            LoreDiscovery discovery = TryGetRandomLoreDiscovery(sapi.World, plr, category);

            if (discovery == null)
            {
                plr.SendMessage(GlobalConstants.GeneralChatGroup, Lang.Get("Nothing of significance in these pages"), EnumChatType.Notification);
                return;
            }



            handling = EnumHandling.PreventDefault;

            Journal journal = null;

            if (!journalsByPlayerUid.TryGetValue(playerUid, out journal))
            {
                journalsByPlayerUid[playerUid] = journal = new Journal();
            }

            JournalEntry entry = null;
            JournalAsset asset = journalAssetsByCode[discovery.Code];

            for (int i = 0; i < journal.Entries.Count; i++)
            {
                if (journal.Entries[i].LoreCode == discovery.Code)
                {
                    entry = journal.Entries[i];
                    break;
                }
            }

            bool isNew = false;

            if (entry == null)
            {
                journal.Entries.Add(entry = new JournalEntry()
                {
                    Editable = false, Title = asset.Title, LoreCode = discovery.Code, EntryId = journal.Entries.Count
                });
                isNew = true;
            }

            for (int i = 0; i < discovery.PieceIds.Count; i++)
            {
                JournalPiecce piece = new JournalPiecce()
                {
                    Text = asset.Pieces[discovery.PieceIds[i]], EntryId = entry.EntryId
                };
                entry.Chapters.Add(piece);
                if (!isNew)
                {
                    serverChannel.SendPacket(piece, plr);
                }
            }

            if (isNew)
            {
                serverChannel.SendPacket(entry, plr);
            }

            plr.SendMessage(GlobalConstants.GeneralChatGroup, Lang.Get("lorediscovery", entry.Title), EnumChatType.Notification);
        }
예제 #4
0
        public void DiscoverLore(LoreDiscovery discovery, IServerPlayer plr)
        {
            string playerUid = plr.PlayerUID;

            Journal journal;

            if (!journalsByPlayerUid.TryGetValue(playerUid, out journal))
            {
                journalsByPlayerUid[playerUid] = journal = new Journal();
            }

            JournalEntry entry = null;

            ensureJournalAssetsLoaded();
            JournalAsset asset = journalAssetsByCode[discovery.Code];

            for (int i = 0; i < journal.Entries.Count; i++)
            {
                if (journal.Entries[i].LoreCode == discovery.Code)
                {
                    entry = journal.Entries[i];
                    break;
                }
            }

            bool isNew = false;

            if (entry == null)
            {
                journal.Entries.Add(entry = new JournalEntry()
                {
                    Editable = false, Title = asset.Title, LoreCode = discovery.Code, EntryId = journal.Entries.Count
                });
                isNew = true;
            }

            int partnum   = 0;
            int partcount = asset.Pieces.Length;

            for (int i = 0; i < discovery.ChapterIds.Count; i++)
            {
                JournalChapter chapter = new JournalChapter()
                {
                    Text = asset.Pieces[discovery.ChapterIds[i]], EntryId = entry.EntryId, ChapterId = discovery.ChapterIds[i]
                };
                entry.Chapters.Add(chapter);
                if (!isNew)
                {
                    serverChannel.SendPacket(chapter, plr);
                }

                partnum = discovery.ChapterIds[i];
            }

            if (isNew)
            {
                serverChannel.SendPacket(entry, plr);
            }


            sapi.SendIngameDiscovery(plr, "lore-" + discovery.Code, null, partnum + 1, partcount);
            sapi.World.PlaySoundAt(new AssetLocation("sounds/effect/deepbell"), plr.Entity, null, false, 32, 0.5f);
        }