protected override bool?DetermineSuccess() { var targets = ParentEvent.GetTargets(TargetTag); if (!targets.Any()) { return(null); } foreach (var target in targets) { if (!(target is Character chr)) { continue; } if (chr.Inventory == null) { continue; } if (itemTags.Any(tag => chr.Inventory.Items.Any(item => item != null && item.HasTag(tag)))) { return(true); } foreach (var identifier in itemIdentifierSplit) { if (chr.Inventory.Items.Any(it => it != null && it.Prefab.Identifier.Equals(identifier, StringComparison.InvariantCultureIgnoreCase))) { return(true); } } } return(false); }
public override void Update(float deltaTime) { if (isFinished) { return; } var targets = ParentEvent.GetTargets(TargetTag); foreach (StatusEffect effect in effects) { foreach (var target in targets) { if (target is Item targetItem) { effect.Apply(effect.type, deltaTime, target, targetItem.AllPropertyObjects); } else { effect.Apply(effect.type, deltaTime, target, target as ISerializableEntity); } } } #if SERVER ServerWrite(targets); #endif isFinished = true; }
public override void Update(float deltaTime) { if (isFinished) { return; } var afflictionPrefab = AfflictionPrefab.List.FirstOrDefault(p => p.Identifier.Equals(Affliction, StringComparison.InvariantCultureIgnoreCase)); if (afflictionPrefab != null) { var targets = ParentEvent.GetTargets(TargetTag); foreach (var target in targets) { if (target != null && target is Character character) { var limb = LimbType != LimbType.None ? character.AnimController.GetLimb(LimbType) : null; if (Strength > 0.0f) { character.CharacterHealth.ApplyAffliction(limb, afflictionPrefab.Instantiate(Strength)); } else if (Strength < 0.0f) { character.CharacterHealth.ReduceAffliction(limb, Affliction, -Strength); } } } } isFinished = true; }
private bool ShouldInterrupt() { IEnumerable <Entity> targets = Enumerable.Empty <Entity>(); if (!string.IsNullOrEmpty(TargetTag)) { targets = ParentEvent.GetTargets(TargetTag).Where(e => IsValidTarget(e)); if (!targets.Any()) { return(true); } } if (speaker != null) { if (!string.IsNullOrEmpty(TargetTag)) { if (targets.All(t => Vector2.DistanceSquared(t.WorldPosition, speaker.WorldPosition) > InterruptDistance * InterruptDistance)) { return(true); } } if (speaker.AIController is HumanAIController humanAI && !humanAI.AllowCampaignInteraction()) { return(true); } return(speaker.Removed || speaker.IsDead || speaker.IsIncapacitated); } return(false); }
protected override bool?DetermineSuccess() { var targets = ParentEvent.GetTargets(TargetTag); if (!targets.Any()) { return(null); } foreach (var target in targets) { if (!(target is Character chr)) { continue; } if (chr.Inventory == null) { continue; } if (itemTags.Any(tag => chr.Inventory.FindItemByTag(tag, recursive: true) != null)) { return(true); } foreach (var identifier in itemIdentifierSplit) { if (chr.Inventory.FindItemByIdentifier(identifier, recursive: true) != null) { return(true); } } } return(false); }
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) { if (!(npc.AIController is HumanAIController humanAiController)) { continue; } if (Wait) { gotoObjective = new AIObjectiveGoTo(npc, npc, humanAiController.ObjectiveManager, repeat: true) { OverridePriority = 100.0f }; humanAiController.ObjectiveManager.AddObjective(gotoObjective); humanAiController.ObjectiveManager.WaitTimer = 0.0f; } else { if (gotoObjective != null) { gotoObjective.Abandon = true; } } } 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; } } #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 || 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; }
private void TagCrew() { #if CLIENT GameMain.GameSession.CrewManager.GetCharacters().ForEach(c => ParentEvent.AddTarget(Tag, c)); #else TagPlayers(); TagBots(); //TODO: this seems like it would tag more than it should, fix #endif }
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 TagCrew() { #if CLIENT GameMain.GameSession.CrewManager.GetCharacters().ForEach(c => ParentEvent.AddTarget(Tag, c)); #else TagPlayers(); TagBots(playerCrewOnly: true); #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) { 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 TagHumansByIdentifier(string identifier) { foreach (Character c in Character.CharacterList) { if (c.Prefab?.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase) ?? false) { ParentEvent.AddTarget(Tag, c); } } }
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; }
public static ParentEvent read(BinaryReader binaryReader) { ParentEvent newObj = new ParentEvent(); newObj.object_id = binaryReader.ReadUInt32(); newObj.child_id = binaryReader.ReadUInt32(); newObj.child_location = binaryReader.ReadUInt32(); newObj.placement_id = binaryReader.ReadUInt32(); newObj.timestamps = PhysicsTimestampPack.read(binaryReader); return(newObj); }
private void TagBots() { if (IgnoreIncapacitatedCharacters) { ParentEvent.AddTargetPredicate(Tag, e => e is Character c && c.IsBot && !c.IsIncapacitated); } else { ParentEvent.AddTargetPredicate(Tag, e => e is Character c && c.IsBot); } }
private void TagBots(bool playerCrewOnly) { if (IgnoreIncapacitatedCharacters) { ParentEvent.AddTargetPredicate(Tag, e => e is Character c && c.IsBot && !c.IsIncapacitated && (!playerCrewOnly || c.TeamID == CharacterTeamType.Team1)); } else { ParentEvent.AddTargetPredicate(Tag, e => e is Character c && c.IsBot && (!playerCrewOnly || c.TeamID == CharacterTeamType.Team1)); } }
public override void Update(float deltaTime) { if (isFinished) { return; } if (!string.IsNullOrWhiteSpace(Tag)) { ParentEvent.RemoveTag(Tag); } isFinished = 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, Amount, target.WorldPosition + Vector2.UnitY * 150.0f); } 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?.ToLowerInvariant(), Amount); } 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(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; } 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; }
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); }
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; }
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); } } } } }