Ejemplo n.º 1
0
        public override async Task <NpcOptions> GetOptions(User activeUser)
        {
            var opts = new NpcOptions();

            opts.Options.Add("Take a gift!", (int)Actions.TakeAGift);
            return(opts);
        }
Ejemplo n.º 2
0
 public void NpcInteractStateSaved()
 {
     try
     {
         var        mrLegit      = this.MrLegitlyFestive;
         NpcOptions user1Options = mrLegit.GetOptions(Context.User1).Result;
         foreach (var option in user1Options.Options)
         {
             NpcStateRepo.ClearNpcState(CritterServer.Contract.Npc.MrLegitlyFestive, Context.User1.Id);
             NpcAction action = mrLegit.Interact(option.Value, Context.User1).Result;
             Assert.NotEqual("Uh oh!", action.Title);
             NpcAction action2 = mrLegit.Interact(option.Value, Context.User1).Result;
             Assert.Equal("Uh oh!", action2.Title);
         }
     }
     catch (AggregateException a)
     {
         Console.WriteLine(a.Message);
         foreach (Exception innerException in a.Flatten().InnerExceptions)
         {
             Console.WriteLine(innerException.Message);
         }
         throw;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
 }
        public override async Task <NpcOptions> GetOptions(User activeUser)
        {
            var opts = new NpcOptions();

            opts.Options.Add("Take some free pizza!", (int)Actions.TakePizza);
            return(opts);
        }
Ejemplo n.º 4
0
        public NpcAgent CreateNpc(UUID sceneid, UGUI owner, UGI group, string firstName, string lastName, Vector3 position, Notecard nc, NpcOptions options = NpcOptions.None)
        {
            SceneInterface   scene;
            AgentServiceList agentServiceList = m_NonpersistentAgentServices;

            if ((options & NpcOptions.Persistent) != NpcOptions.None)
            {
                if (m_NpcPresenceService == null)
                {
                    throw new InvalidOperationException("Persistence of NPCs not configured");
                }
                agentServiceList = m_PersistentAgentServices;
            }

            NpcPresenceServiceInterface presenceService  = agentServiceList.Get <NpcPresenceServiceInterface>();
            InventoryServiceInterface   inventoryService = agentServiceList.Get <InventoryServiceInterface>();

            var npcId = new UGUIWithName
            {
                ID        = UUID.Random,
                FirstName = firstName,
                LastName  = lastName
            };

            if (m_KnownScenes.TryGetValue(sceneid, out scene))
            {
                var agent = new NpcAgent(npcId, agentServiceList, sceneid)
                {
                    NpcOwner = owner,
                    Group    = group
                };
                try
                {
                    m_NpcAgents.Add(agent.ID, agent);
                    var npcInfo = new NpcPresenceInfo
                    {
                        RegionID = sceneid,
                        Npc      = agent.NamedOwner,
                        Owner    = agent.NpcOwner,
                        Group    = agent.Group,
                    };
                    inventoryService.CheckInventory(npcInfo.Npc.ID);
                    presenceService.Store(npcInfo);
                    agent.CurrentScene = scene;
                    agent.Position     = position;
                    scene.Add(agent);
                }
                catch
                {
                    if (m_NpcPresenceService != null)
                    {
                        presenceService.Remove(agent.ID);
                    }
                    inventoryService.Remove(agent.ID);
                    m_NpcAgents.Remove(agent.ID);
                    throw;
                }
                agent.EnableListen();

                scene.SendAgentObjectToAllAgents(agent);
                agent.SendAnimations();

                ThreadPool.QueueUserWorkItem(LoadAppearanceFromNotecardJob, new RebakeJob {
                    Notecard = nc, Agent = agent
                });
                return(agent);
            }

            throw new KeyNotFoundException("Scene not found");
        }
Ejemplo n.º 5
0
        public async Task NpcGiveAndTakeItems()
        {
            try
            {
                var        mrLegit      = this.MrLegitlyFestive;
                NpcOptions user1Options = mrLegit.GetOptions(Context.User1).Result;

                // Clear any existing configs
                var cfgs = await CfgRepo.RetrieveItemGenerationConfigForNpc(CritterServer.Contract.Npc.MrLegitlyFestive);

                foreach (var cfg in cfgs)
                {
                    await CfgRepo.DeleteItemGenerationConfigForNpc(CritterServer.Contract.Npc.MrLegitlyFestive);
                }

                // Cfg for Give item
                var cfg1 = new ItemGenerationConfig
                {
                    NpcId    = (int)CritterServer.Contract.Npc.MrLegitlyFestive,
                    ItemType = Context.ItemType2,
                    Quantity = 3
                };

                await CfgRepo.CreateItemGenerationConfigForNpc(CritterServer.Contract.Npc.MrLegitlyFestive, cfg1);

                // Get count of item type 2 before interacting
                List <InventoryItemDetails> inv1Before = await InventoryDomain.GetFullInventory(Context.User1);

                var itemType2CountBefore = inv1Before.Select(i => i.ItemType.Id == Context.ItemType2).Count();

                // Interact
                await NpcStateRepo.ClearNpcState(CritterServer.Contract.Npc.MrLegitlyFestive, Context.User1.Id);

                NpcAction action = mrLegit.Interact(0, Context.User1).Result;
                int       reportedItemType2CountAdded = action.AddedItems.Select(i => i.ItemType.Id == Context.ItemType2).Count();

                // Get count of item type 2 after interacting to make sure they were added
                List <InventoryItemDetails> inv1After = await InventoryDomain.GetFullInventory(Context.User1);

                var itemType2CountAfter = inv1After.Select(i => i.ItemType.Id == Context.ItemType2).Count();

                // Cleanup before next test
                await CfgRepo.DeleteItemGenerationConfigForNpc(CritterServer.Contract.Npc.MrLegitlyFestive);

                // Assertions
                Assert.Equal(3, reportedItemType2CountAdded);
                Assert.Equal(3, itemType2CountAfter - itemType2CountBefore);

                // Cfg for Take items (will need another way to test this when this functionality is removed from mrlegit)
                var cfg2 = new ItemGenerationConfig
                {
                    NpcId    = (int)CritterServer.Contract.Npc.MrLegitlyFestive,
                    ItemType = Context.ItemType2,
                    Quantity = -3
                };

                await CfgRepo.CreateItemGenerationConfigForNpc(CritterServer.Contract.Npc.MrLegitlyFestive, cfg2);

                // Get count of item type 2 before interacting
                List <InventoryItemDetails> inv2Before = await InventoryDomain.GetFullInventory(Context.User1);

                var itemType2CountBefore2 = inv2Before.Select(i => i.ItemType.Id == Context.ItemType2).Count();

                // Interact
                await NpcStateRepo.ClearNpcState(CritterServer.Contract.Npc.MrLegitlyFestive, Context.User1.Id);

                NpcAction action2 = mrLegit.Interact(0, Context.User1).Result;
                int       reportedItemType2CountRemoved = action2.RemovedItems.Select(i => i.ItemType.Id == Context.ItemType2).Count();

                // Get count of item type 2 after interacting to make sure they were added
                List <InventoryItemDetails> inv2After = await InventoryDomain.GetFullInventory(Context.User1);

                var itemType2CountAfter2 = inv2After.Select(i => i.ItemType.Id == Context.ItemType2).Count();

                // Cleanup
                await CfgRepo.DeleteItemGenerationConfigForNpc(CritterServer.Contract.Npc.MrLegitlyFestive);

                // Assertions
                Assert.Equal(3, reportedItemType2CountRemoved);
                Assert.Equal(-3, itemType2CountAfter2 - itemType2CountBefore2);
            }
            catch (AggregateException a)
            {
                Console.WriteLine(a.Message);
                foreach (Exception innerException in a.Flatten().InnerExceptions)
                {
                    Console.WriteLine(innerException.Message);
                }
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }