Exemplo n.º 1
0
        protected void CreateDialog(List <Character> speakers, string conversationTag, float minInterval)
        {
            if (dialogLastSpoken.TryGetValue(conversationTag, out double lastTime))
            {
                if (Timing.TotalTime - lastTime < minInterval)
                {
                    return;
                }
            }

            CrewManager.AddConversation(
                NPCConversation.CreateRandom(speakers, new List <string>()
            {
                conversationTag
            }));
            dialogLastSpoken[conversationTag] = Timing.TotalTime;
        }
Exemplo n.º 2
0
        partial void CreateRandomConversation()
        {
            List <Character> availableSpeakers = Character.CharacterList.FindAll(c =>
                                                                                 c.AIController is HumanAIController &&
                                                                                 !c.IsDead &&
                                                                                 c.SpeechImpediment <= 100.0f);

            foreach (Client client in GameMain.Server.ConnectedClients)
            {
                if (client.Character != null)
                {
                    availableSpeakers.Remove(client.Character);
                }
            }

            pendingConversationLines.AddRange(NPCConversation.CreateRandom(availableSpeakers));
        }
Exemplo n.º 3
0
        private void UpdateConversations(float deltaTime)
        {
            if (GameMain.NetworkMember != null && GameMain.NetworkMember.ServerSettings.DisableBotConversations)
            {
                return;
            }

            conversationTimer -= deltaTime;
            if (conversationTimer <= 0.0f)
            {
                CreateRandomConversation();
                conversationTimer = Rand.Range(ConversationIntervalMin, ConversationIntervalMax);
                if (GameMain.NetworkMember != null)
                {
                    conversationTimer *= ConversationIntervalMultiplierMultiplayer;
                }
            }

            if (welcomeMessageNPC == null)
            {
                foreach (Character npc in Character.CharacterList)
                {
                    if (npc.TeamID != Character.TeamType.FriendlyNPC || npc.CurrentHull == null || npc.IsIncapacitated)
                    {
                        continue;
                    }
                    if (npc.AIController?.ObjectiveManager != null && (npc.AIController.ObjectiveManager.IsCurrentObjective <AIObjectiveFindSafety>() || npc.AIController.ObjectiveManager.IsCurrentObjective <AIObjectiveCombat>()))
                    {
                        continue;
                    }
                    foreach (Character player in Character.CharacterList)
                    {
                        if (player.TeamID != npc.TeamID && !player.IsIncapacitated && player.CurrentHull == npc.CurrentHull)
                        {
                            List <Character> availableSpeakers = new List <Character>()
                            {
                                npc, player
                            };
                            List <string> dialogFlags = new List <string>()
                            {
                                "OutpostNPC", "EnterOutpost"
                            };
                            if (GameMain.GameSession?.GameMode is CampaignMode campaignMode && campaignMode.Map?.CurrentLocation?.Reputation != null)
                            {
                                float normalizedReputation = MathUtils.InverseLerp(
                                    campaignMode.Map.CurrentLocation.Reputation.MinReputation,
                                    campaignMode.Map.CurrentLocation.Reputation.MaxReputation,
                                    campaignMode.Map.CurrentLocation.Reputation.Value);
                                if (normalizedReputation < 0.2f)
                                {
                                    dialogFlags.Add("LowReputation");
                                }
                                else if (normalizedReputation > 0.8f)
                                {
                                    dialogFlags.Add("HighReputation");
                                }
                            }
                            pendingConversationLines.AddRange(NPCConversation.CreateRandom(availableSpeakers, dialogFlags));
                            welcomeMessageNPC = npc;
                            break;
                        }
                    }
                    if (welcomeMessageNPC != null)
                    {
                        break;
                    }
                }
            }
            else if (welcomeMessageNPC.Removed)
            {
                welcomeMessageNPC = null;
            }

            if (pendingConversationLines.Count > 0)
            {
                conversationLineTimer -= deltaTime;
                if (conversationLineTimer <= 0.0f)
                {
                    //speaker of the next line can't speak, interrupt the conversation
                    if (pendingConversationLines[0].First.SpeechImpediment >= 100.0f)
                    {
                        pendingConversationLines.Clear();
                        return;
                    }

                    pendingConversationLines[0].First.Speak(pendingConversationLines[0].Second, null);
                    if (pendingConversationLines.Count > 1)
                    {
                        conversationLineTimer = MathHelper.Clamp(pendingConversationLines[0].Second.Length * 0.1f, 1.0f, 5.0f);
                    }
                    pendingConversationLines.RemoveAt(0);
                }
            }
        }