5dc31c213f
commit 7245c721339885d062567befc052a592391b3b4a Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 10 15:22:31 2019 +0200 Fixed StatusEffects only applying afflictions to one limb even if the target is "Character" instead of "Limb", added a subtle screen distortion effect to heavy radiation sickness. Closes #1256 commit e0db27e62ec9546fd4b182a0cc97f7e5830645ae Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sat Mar 9 21:53:51 2019 +0200 Fixed WrapText adding unnecessary spaces after every line break. Closes #1215 commit 988bc58d51c195ad9265b84a1e97e0101cd3f808 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sat Mar 9 21:12:50 2019 +0200 Fixed crashing when attempting to create a body for a wall section that's less than 1 unit long (e.g. if a wall that's just slightly longer than the wall section size receives damage). commit 8c31157425a9e2ec02312618d1bfa359ab3ee87d Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sat Mar 9 20:30:44 2019 +0200 Fixed clients being unable to toggle the respawn shuttle on/off commit a4ccb039219830efe9cd305c26942dda1bd04e9c Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sat Mar 9 19:33:22 2019 +0200 Fixed inability to select the respawn shuttle as a client host commit b89b2d2c282d8c74d7ccd37b3f29dcab51eff680 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sat Mar 9 19:32:41 2019 +0200 Made it possible to edit the style of the ListBox under GUIDropDowns, increased the opacity of the listbox to make the contents more readable when there's text behind it commit 8f6d9aef3d637fe37a18c78f4b15ef8fd266374e Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sat Mar 9 18:11:23 2019 +0200 Fixed NetLobbyScreen not showing the names of the submarines the client doesn't have
190 lines
7.0 KiB
C#
190 lines
7.0 KiB
C#
using Barotrauma.Items.Components;
|
|
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
class AIObjectiveCombat : AIObjective
|
|
{
|
|
const float CoolDown = 10.0f;
|
|
|
|
//the largest amount of damage the enemy has inflicted on this character
|
|
//(may be higher than enemyStrength if the enemy is e.g. a human using items)
|
|
public float MaxEnemyDamage;
|
|
|
|
private Character enemy;
|
|
|
|
private AIObjectiveFindSafety escapeObjective;
|
|
|
|
private AIObjectiveContainItem reloadWeaponObjective;
|
|
|
|
private float coolDownTimer;
|
|
|
|
public AIObjectiveCombat(Character character, Character enemy) : base(character, "")
|
|
{
|
|
this.enemy = enemy;
|
|
coolDownTimer = CoolDown;
|
|
}
|
|
|
|
protected override void Act(float deltaTime)
|
|
{
|
|
coolDownTimer -= deltaTime;
|
|
|
|
var weapon = character.Inventory.FindItemByTag("weapon");
|
|
if (weapon == null)
|
|
{
|
|
Escape(deltaTime);
|
|
}
|
|
else
|
|
{
|
|
if (!character.SelectedItems.Contains(weapon))
|
|
{
|
|
if (character.Inventory.TryPutItem(weapon, 3, true, false, character))
|
|
{
|
|
weapon.Equip(character);
|
|
}
|
|
else
|
|
{
|
|
//couldn't equip the item, escape
|
|
Escape(deltaTime);
|
|
return;
|
|
}
|
|
}
|
|
|
|
//make sure the weapon is loaded
|
|
var weaponComponent =
|
|
weapon.GetComponent<RangedWeapon>() as ItemComponent ??
|
|
weapon.GetComponent<MeleeWeapon>() as ItemComponent ??
|
|
weapon.GetComponent<RepairTool>() as ItemComponent;
|
|
if (weaponComponent != null && weaponComponent.requiredItems.ContainsKey(RelatedItem.RelationType.Contained))
|
|
{
|
|
var containedItems = weapon.ContainedItems;
|
|
foreach (RelatedItem requiredItem in weaponComponent.requiredItems[RelatedItem.RelationType.Contained])
|
|
{
|
|
Item containedItem = containedItems.FirstOrDefault(it => it.Condition > 0.0f && requiredItem.MatchesItem(it));
|
|
if (containedItem == null)
|
|
{
|
|
var newReloadWeaponObjective = new AIObjectiveContainItem(character, requiredItem.Identifiers, weapon.GetComponent<ItemContainer>());
|
|
if (!newReloadWeaponObjective.IsDuplicate(reloadWeaponObjective))
|
|
{
|
|
reloadWeaponObjective = newReloadWeaponObjective;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (reloadWeaponObjective != null)
|
|
{
|
|
if (reloadWeaponObjective.IsCompleted())
|
|
{
|
|
reloadWeaponObjective = null;
|
|
}
|
|
else if (!reloadWeaponObjective.CanBeCompleted)
|
|
{
|
|
Escape(deltaTime);
|
|
}
|
|
else
|
|
{
|
|
reloadWeaponObjective.TryComplete(deltaTime);
|
|
}
|
|
return;
|
|
}
|
|
|
|
character.CursorPosition = enemy.Position;
|
|
character.SetInput(InputType.Aim, false, true);
|
|
|
|
Vector2 enemyDiff = Vector2.Normalize(enemy.Position - character.Position);
|
|
if (!MathUtils.IsValid(enemyDiff)) enemyDiff = Rand.Vector(1.0f);
|
|
float weaponAngle = ((weapon.body.Dir == 1.0f) ? weapon.body.Rotation : weapon.body.Rotation - MathHelper.Pi);
|
|
Vector2 weaponDir = new Vector2((float)Math.Cos(weaponAngle), (float)Math.Sin(weaponAngle));
|
|
|
|
if (Vector2.Dot(enemyDiff, weaponDir) < 0.9f) return;
|
|
|
|
List<FarseerPhysics.Dynamics.Body> ignoredBodies = new List<FarseerPhysics.Dynamics.Body>();
|
|
foreach (Limb limb in character.AnimController.Limbs)
|
|
{
|
|
ignoredBodies.Add(limb.body.FarseerBody);
|
|
}
|
|
|
|
var pickedBody = Submarine.PickBody(character.SimPosition, enemy.SimPosition, ignoredBodies);
|
|
if (pickedBody != null && !(pickedBody.UserData is Limb)) return;
|
|
|
|
weapon.Use(deltaTime, character);
|
|
}
|
|
}
|
|
|
|
private void Escape(float deltaTime)
|
|
{
|
|
if (escapeObjective == null)
|
|
{
|
|
escapeObjective = new AIObjectiveFindSafety(character);
|
|
}
|
|
|
|
if (enemy.AnimController.CurrentHull == character.AnimController.CurrentHull)
|
|
{
|
|
escapeObjective.OverrideCurrentHullSafety = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
escapeObjective.OverrideCurrentHullSafety = null;
|
|
}
|
|
|
|
escapeObjective.TryComplete(deltaTime);
|
|
}
|
|
|
|
public override bool IsCompleted()
|
|
{
|
|
return enemy == null || enemy.Removed || enemy.IsDead || coolDownTimer <= 0.0f;
|
|
}
|
|
|
|
public override float GetPriority(AIObjectiveManager objectiveManager)
|
|
{
|
|
if (enemy == null || enemy.Removed)
|
|
{
|
|
return 0.0f;
|
|
}
|
|
|
|
if (objectiveManager.CurrentOrder == this)
|
|
{
|
|
return AIObjectiveManager.OrderPriority;
|
|
}
|
|
|
|
//clamp the strength to the health of this character
|
|
//(it doesn't make a difference whether the enemy does 200 or 600 damage, it's one hit kill anyway)
|
|
|
|
float enemyDanger = Math.Min(Math.Max(CalculateEnemyStrength(), MaxEnemyDamage), character.Health) + enemy.Health / 10.0f;
|
|
|
|
if (enemy.AIController is EnemyAIController enemyAI)
|
|
{
|
|
if (enemyAI.SelectedAiTarget == character.AiTarget) enemyDanger *= 2.0f;
|
|
}
|
|
|
|
return Math.Max(enemyDanger, AIObjectiveManager.OrderPriority);
|
|
}
|
|
|
|
public override bool IsDuplicate(AIObjective otherObjective)
|
|
{
|
|
AIObjectiveCombat objective = otherObjective as AIObjectiveCombat;
|
|
if (objective == null) return false;
|
|
|
|
return objective.enemy == enemy;
|
|
}
|
|
|
|
private float CalculateEnemyStrength()
|
|
{
|
|
float enemyStrength = 0;
|
|
AttackContext currentContext = character.GetAttackContext();
|
|
foreach (Limb limb in enemy.AnimController.Limbs)
|
|
{
|
|
if (limb.attack == null) continue;
|
|
if (!limb.attack.IsValidContext(currentContext)) { continue; }
|
|
if (!limb.attack.IsValidTarget(AttackTarget.Character)) { continue; }
|
|
enemyStrength += limb.attack.GetTotalDamage(false);
|
|
}
|
|
return enemyStrength;
|
|
}
|
|
}
|
|
}
|