예제 #1
0
        public override void Update(float deltaTime)
        {
            if (isFinished)
            {
                return;
            }

            isRunning = true;

            var targets1 = ParentEvent.GetTargets(Target1Tag);

            if (!targets1.Any())
            {
                return;
            }

            foreach (Entity e1 in targets1)
            {
                if (DisableInCombat && IsInCombat(e1))
                {
                    continue;
                }
                if (DisableIfTargetIncapacitated && e1 is Character character1 && (character1.IsDead || character1.IsIncapacitated))
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(TargetModuleType))
                {
                    if (IsCloseEnoughToHull(e1, out Hull hull))
                    {
                        Trigger(e1, hull);
                        return;
                    }
                    continue;
                }

                var targets2 = ParentEvent.GetTargets(Target2Tag);

                foreach (Entity e2 in targets2)
                {
                    if (e1 == e2)
                    {
                        continue;
                    }
                    if (DisableInCombat && IsInCombat(e2))
                    {
                        continue;
                    }
                    if (DisableIfTargetIncapacitated && e2 is Character character2 && (character2.IsDead || character2.IsIncapacitated))
                    {
                        continue;
                    }

                    if (WaitForInteraction)
                    {
                        Character player = null;
                        Character npc    = null;
                        Item      item   = null;
                        npcOrItem?.TryGet(out npc);
                        npcOrItem?.TryGet(out item);
                        if (e1 is Character char1)
                        {
                            if (char1.IsBot)
                            {
                                npc ??= char1;
                            }
                            else
                            {
                                player = char1;
                            }
                        }
                        else
                        {
                            item ??= e1 as Item;
                        }
                        if (e2 is Character char2)
                        {
                            if (char2.IsBot)
                            {
                                npc ??= char2;
                            }
                            else
                            {
                                player = char2;
                            }
                        }
                        else
                        {
                            item ??= e2 as Item;
                        }

                        if (player != null)
                        {
                            if (npc != null)
                            {
                                if (npc.CampaignInteractionType != CampaignMode.InteractionType.Examine)
                                {
                                    npcOrItem = npc;
                                    npc.CampaignInteractionType = CampaignMode.InteractionType.Examine;
                                    npc.RequireConsciousnessForCustomInteract = false;
#if CLIENT
                                    npc.SetCustomInteract(
                                        (speaker, player) => { if (e1 == speaker)
                                                               {
                                                                   Trigger(speaker, player);
                                                               }
                                                               else
                                                               {
                                                                   Trigger(player, speaker);
                                                               } },
                                        TextManager.GetWithVariable("CampaignInteraction.Examine", "[key]", GameMain.Config.KeyBindText(InputType.Use)));
#else
                                    npc.SetCustomInteract(
                                        (speaker, player) => { if (e1 == speaker)
                                                               {
                                                                   Trigger(speaker, player);
                                                               }
                                                               else
                                                               {
                                                                   Trigger(player, speaker);
                                                               } },
                                        TextManager.Get("CampaignInteraction.Talk"));
                                    GameMain.NetworkMember.CreateEntityEvent(npc, new object[] { NetEntityEvent.Type.AssignCampaignInteraction });
#endif
                                }

                                return;
                            }
                            else if (item != null)
                            {
                                npcOrItem = item;
                                item.CampaignInteractionType = CampaignMode.InteractionType.Examine;
                                if (player.SelectedConstruction == item ||
                                    player.Inventory != null && player.Inventory.Contains(item) ||
                                    (player.FocusedItem == item && player.IsKeyHit(InputType.Use)))
                                {
                                    Trigger(e1, e2);
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        Vector2 pos1 = e1.WorldPosition;
                        Vector2 pos2 = e2.WorldPosition;
                        distance = Vector2.Distance(pos1, pos2);
                        if (((e1 is MapEntity m1) && Submarine.RectContains(m1.WorldRect, pos2)) ||
                            ((e2 is MapEntity m2) && Submarine.RectContains(m2.WorldRect, pos1)) ||
                            Vector2.DistanceSquared(pos1, pos2) < Radius * Radius)
                        {
                            Trigger(e1, e2);
                            return;
                        }
                    }
                }
            }
        }