public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag); bool hasValidTargets = false; foreach (Entity target in targets) { if (target is Character character && character.Inventory != null || target is Item) { hasValidTargets = true; break; } } if (!hasValidTargets) { return; } HashSet <Item> removedItems = new HashSet <Item>(); foreach (Entity target in targets) { Inventory inventory = (target as Character)?.Inventory; if (inventory != null) { while (removedItems.Count < Amount) { var item = inventory.FindItem(it => it != null && !removedItems.Contains(it) && (string.IsNullOrEmpty(ItemIdentifier) || it.Prefab.Identifier.Equals(ItemIdentifier, StringComparison.InvariantCultureIgnoreCase)), recursive: true); if (item == null) { break; } Entity.Spawner.AddToRemoveQueue(item); removedItems.Add(item); } } else if (target is Item item) { if (string.IsNullOrEmpty(ItemIdentifier) || item.Prefab.Identifier.Equals(ItemIdentifier, StringComparison.InvariantCultureIgnoreCase)) { Entity.Spawner.AddToRemoveQueue(item); removedItems.Add(item); if (removedItems.Count >= Amount) { break; } } } } isFinished = true; }
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 (!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; } 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; } } } }
private void TryStartConversation(Character speaker, Character targetCharacter = null) { IEnumerable <Entity> targets = Enumerable.Empty <Entity>(); if (!string.IsNullOrEmpty(TargetTag)) { targets = ParentEvent.GetTargets(TargetTag).Where(e => IsValidTarget(e)); if (!targets.Any() || IsBlockedByAnotherConversation(targets)) { return; } } if (speaker?.AIController is HumanAIController humanAI) { prevIdleObjective = humanAI.ObjectiveManager.GetObjective <AIObjectiveIdle>(); prevGotoObjective = humanAI.ObjectiveManager.GetObjective <AIObjectiveGoTo>(); humanAI.SetForcedOrder( Order.PrefabList.Find(o => o.Identifier.Equals("wait", StringComparison.OrdinalIgnoreCase)), option: string.Empty, orderGiver: null); if (targets.Any()) { Entity closestTarget = null; float closestDist = float.MaxValue; foreach (Entity entity in targets) { float dist = Vector2.DistanceSquared(entity.WorldPosition, speaker.WorldPosition); if (dist < closestDist) { closestTarget = entity; closestDist = dist; } } if (closestTarget != null) { humanAI.FaceTarget(closestTarget); } } } if (targetCharacter != null && !string.IsNullOrWhiteSpace(InvokerTag)) { ParentEvent.AddTarget(InvokerTag, targetCharacter); } ShowDialog(speaker, targetCharacter); dialogOpened = true; if (speaker != null) { speaker.CampaignInteractionType = CampaignMode.InteractionType.None; speaker.SetCustomInteract(null, null); #if SERVER GameMain.NetworkMember.CreateEntityEvent(speaker, new object[] { NetEntityEvent.Type.AssignCampaignInteraction }); #endif } }
private void TryStartConversation(Character speaker, Character targetCharacter = null) { IEnumerable <Entity> targets = Enumerable.Empty <Entity>(); if (!string.IsNullOrEmpty(TargetTag)) { targets = ParentEvent.GetTargets(TargetTag).Where(e => IsValidTarget(e)); if (!targets.Any() || IsBlockedByAnotherConversation(targets)) { return; } } if (speaker?.AIController is HumanAIController humanAI) { prevSpeakerOrder = null; if (humanAI.CurrentOrder != null) { prevSpeakerOrder = new OrderInfo(humanAI.CurrentOrder, humanAI.CurrentOrderOption); } prevIdleObjective = humanAI.ObjectiveManager.GetObjective <AIObjectiveIdle>(); prevGotoObjective = humanAI.ObjectiveManager.GetObjective <AIObjectiveGoTo>(); humanAI.SetOrder( Order.PrefabList.Find(o => o.Identifier.Equals("wait", StringComparison.OrdinalIgnoreCase)), option: string.Empty, orderGiver: null, speak: false); if (targets.Any()) { Entity closestTarget = null; float closestDist = float.MaxValue; foreach (Entity entity in targets) { float dist = Vector2.DistanceSquared(entity.WorldPosition, speaker.WorldPosition); if (dist < closestDist) { closestTarget = entity; closestDist = dist; } } if (closestTarget != null) { humanAI.FaceTarget(closestTarget); } } } if (targetCharacter != null && !string.IsNullOrWhiteSpace(InvokerTag)) { ParentEvent.AddTarget(InvokerTag, targetCharacter); } ShowDialog(speaker, targetCharacter); dialogOpened = true; }
protected override bool?DetermineSuccess() { var potentialTargets = ParentEvent.GetTargets(TargetTag).Where(e => e is Character).Select(e => e as Character); if (ProbabilityBased) { return(potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill?.ToLowerInvariant()) / RequiredLevel > Rand.Range(0.0f, 1.0f, Rand.RandSync.Unsynced))); } else { return(potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill?.ToLowerInvariant()) >= RequiredLevel)); } }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag).Where(e => e is Character).Select(e => e as Character); foreach (var target in targets) { target.Info?.IncreaseSkillLevel(Skill?.ToLowerInvariant(), Amount); } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag).Where(e => e is Character).Select(e => e as Character); foreach (var target in targets) { target.Info?.IncreaseSkillLevel(Skill, Amount, target.WorldPosition + Vector2.UnitY * 150.0f); } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } affectedNpcs = ParentEvent.GetTargets(NPCTag).Where(c => c is Character).Select(c => c as Character).ToList(); foreach (var npc in affectedNpcs) { // characters will still remain on friendlyNPC team for rest of the tick npc.SetOriginalTeam(TeamTag); if (AddToCrew && (TeamTag == CharacterTeamType.Team1 || TeamTag == CharacterTeamType.Team2)) { npc.Info.StartItemsGiven = true; GameMain.GameSession.CrewManager.AddCharacter(npc); foreach (Item item in npc.Inventory.AllItems) { item.AllowStealing = true; var wifiComponent = item.GetComponent <Items.Components.WifiComponent>(); if (wifiComponent != null) { wifiComponent.TeamID = TeamTag; } var idCard = item.GetComponent <Items.Components.IdCard>(); if (idCard != null) { idCard.TeamID = TeamTag; idCard.SubmarineSpecificID = 0; } } WayPoint subWaypoint = WayPoint.WayPointList.Find(wp => wp.Submarine == Submarine.MainSub && wp.SpawnType == SpawnType.Human && wp.AssignedJob == npc.Info.Job?.Prefab) ?? WayPoint.WayPointList.Find(wp => wp.Submarine == Submarine.MainSub && wp.SpawnType == SpawnType.Human); if (subWaypoint != null) { npc.GiveIdCardTags(subWaypoint, createNetworkEvent: true); } #if SERVER GameMain.NetworkMember.CreateEntityEvent(npc, new object[] { NetEntityEvent.Type.AddToCrew, TeamTag, npc.Inventory.AllItems.Select(it => it.ID).ToArray() }); #endif } } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag); bool hasValidTargets = false; foreach (Entity target in targets) { if (target is Character character && character.Inventory != null) { hasValidTargets = true; break; } } if (!hasValidTargets) { return; } List <Item> usedItems = new List <Item>(); foreach (Entity target in targets) { Inventory inventory = (target as Character)?.Inventory; if (inventory == null) { continue; } while (usedItems.Count < Amount) { var item = inventory.FindItem(it => it != null && !usedItems.Contains(it) && it.Prefab.Identifier.Equals(ItemIdentifier, StringComparison.InvariantCultureIgnoreCase), recursive: true); if (item == null) { break; } Entity.Spawner.AddToRemoveQueue(item); usedItems.Add(item); } } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } affectedNpcs = ParentEvent.GetTargets(NPCTag).Where(e => e is Character).Select(e => e as Character); foreach (var npc in affectedNpcs) { if (!(npc.AIController is HumanAIController humanAiController)) { continue; } Character enemy = null; float closestDist = float.MaxValue; foreach (Entity target in ParentEvent.GetTargets(EnemyTag)) { if (!(target is Character character)) { continue; } float dist = Vector2.DistanceSquared(npc.WorldPosition, target.WorldPosition); if (dist < closestDist) { enemy = character; closestDist = dist; } } if (enemy == null) { continue; } npc.CombatAction = this; var objectiveManager = humanAiController.ObjectiveManager; foreach (var goToObjective in objectiveManager.GetActiveObjectives <AIObjectiveGoTo>()) { goToObjective.Abandon = true; } objectiveManager.AddObjective(new AIObjectiveCombat(npc, enemy, CombatMode, objectiveManager, coolDown: CoolDown)); } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag); foreach (var target in targets) { Vector2 pos = target.WorldPosition; var newFire = new FireSource(pos); newFire.Size = new Vector2(Size, Size); } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag); foreach (var target in targets) { if (target != null && target is Character character) { character.GodMode = Enabled; } } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } target = ParentEvent.GetTargets(TargetTag).FirstOrDefault(); if (target == null) { return; } affectedNpcs = ParentEvent.GetTargets(NPCTag).Where(c => c is Character).Select(c => c as Character).ToList(); foreach (var npc in affectedNpcs) { if (!(npc.AIController is HumanAIController humanAiController)) { continue; } if (Follow) { var newObjective = new AIObjectiveGoTo(target, npc, humanAiController.ObjectiveManager, repeat: true) { OverridePriority = 100.0f }; humanAiController.ObjectiveManager.AddObjective(newObjective); humanAiController.ObjectiveManager.WaitTimer = 0.0f; } else { foreach (var goToObjective in humanAiController.ObjectiveManager.GetActiveObjectives <AIObjectiveGoTo>()) { if (goToObjective.Target == target) { goToObjective.Abandon = true; } } } } isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag); foreach (StatusEffect effect in effects) { foreach (var target in targets) { effect.Apply(effect.type, deltaTime, target, target as ISerializableEntity); } } #if SERVER ServerWrite(targets); #endif isFinished = true; }
protected override bool?DetermineSuccess() { if (string.IsNullOrWhiteSpace(Identifier) || string.IsNullOrWhiteSpace(TargetTag)) { return(false); } List <Character> targets = ParentEvent.GetTargets(TargetTag).OfType <Character>().ToList(); foreach (var target in targets) { if (target.CharacterHealth == null) { continue; } if (TargetLimb == LimbType.None) { if (target.CharacterHealth.GetAffliction(Identifier, AllowLimbAfflictions) != null) { return(true); } } IEnumerable <Affliction> afflictions = target.CharacterHealth.GetAllAfflictions().Where(affliction => { LimbType?limbType = target.CharacterHealth.GetAfflictionLimb(affliction)?.type; if (limbType == null) { return(false); } return(limbType == TargetLimb || true); }); if (afflictions.Any(a => a.Identifier.Equals(Identifier, StringComparison.OrdinalIgnoreCase))) { return(true); } } return(false); }
partial void ShowDialog(Character speaker, Character targetCharacter) { targetClients.Clear(); if (!string.IsNullOrEmpty(TargetTag)) { IEnumerable <Entity> entities = ParentEvent.GetTargets(TargetTag); foreach (Entity e in entities) { if (!(e is Character character) || !character.IsRemotePlayer) { continue; } Client targetClient = GameMain.Server.ConnectedClients.Find(c => c.Character == character); if (targetClient != null) { targetClients.Add(targetClient); lastActiveAction[targetClient] = this; ServerWrite(speaker, targetClient); } } } else { foreach (Client c in GameMain.Server.ConnectedClients) { if (c.InGame && c.Character != null) { if (targetCharacter == null || targetCharacter == c.Character) { targetClients.Add(c); lastActiveAction[c] = this; ServerWrite(speaker, c); } } } } }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag) .Where(t => t is Character chr && chr.Inventory != null) .Select(t => t as Character).ToList(); if (targets.Count <= 0) { return; } int count = Amount; while (count > 0 && targets.Count > 0) { var items = targets[0].Inventory.Items; for (int i = 0; i < items.Length; i++) { if (items[i] != null && items[i].Prefab.Identifier.Equals(ItemIdentifier, StringComparison.InvariantCultureIgnoreCase)) { Entity.Spawner.AddToRemoveQueue(items[i]); count--; if (count <= 0) { break; } } } targets.RemoveAt(0); } isFinished = true; }
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; } } } } }
protected override bool?DetermineSuccess() { var potentialTargets = ParentEvent.GetTargets(TargetTag).Where(e => e is Character).Select(e => e as Character); return(potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill?.ToLowerInvariant()) >= RequiredLevel)); }
public override void Update(float deltaTime) { lastActiveTime = Timing.TotalTime; if (interrupt) { Interrupted?.Update(deltaTime); } else if (selectedOption < 0) { if (dialogOpened) { #if CLIENT if (GUIMessageBox.MessageBoxes.Any(mb => mb.UserData as string == "ConversationAction")) { Character.DisableControls = true; } else { Reset(); } #endif if (ShouldInterrupt()) { ResetSpeaker(); interrupt = true; } return; } if (!string.IsNullOrEmpty(SpeakerTag)) { if (speaker != null && !speaker.Removed && speaker.CampaignInteractionType == CampaignMode.InteractionType.Talk && speaker.ActiveConversation?.ParentEvent != this.ParentEvent) { return; } speaker = ParentEvent.GetTargets(SpeakerTag).FirstOrDefault(e => e is Character) as Character; if (speaker == null || speaker.Removed) { return; } //some conversation already assigned to the speaker, wait for it to be removed if (speaker.CampaignInteractionType == CampaignMode.InteractionType.Talk && speaker.ActiveConversation?.ParentEvent != this.ParentEvent) { return; } else if (!WaitForInteraction) { TryStartConversation(speaker); } else if (speaker.ActiveConversation != this) { speaker.CampaignInteractionType = CampaignMode.InteractionType.Talk; speaker.ActiveConversation = this; #if CLIENT speaker.SetCustomInteract( TryStartConversation, TextManager.GetWithVariable("CampaignInteraction.Talk", "[key]", GameMain.Config.KeyBindText(InputType.Use))); #else speaker.SetCustomInteract( TryStartConversation, TextManager.Get("CampaignInteraction.Talk")); GameMain.NetworkMember.CreateEntityEvent(speaker, new object[] { NetEntityEvent.Type.AssignCampaignInteraction }); #endif } return; } else { TryStartConversation(null); } } else { if (ShouldInterrupt()) { ResetSpeaker(); interrupt = true; } else if (Options.Any()) { Options[selectedOption].Update(deltaTime); } } }