(8e2e25260) Spawn multiple monsters using the same spatial and temporal spreading logic as in events.

This commit is contained in:
Joonas Rikkonen
2019-04-29 21:05:06 +03:00
parent 42e541f3fa
commit 69c4b9a74f
4 changed files with 33 additions and 25 deletions
@@ -85,8 +85,7 @@ namespace Barotrauma
{ {
if (character.Inventory != null) if (character.Inventory != null)
{ {
if (!character.LockHands && character.Stun < 0.1f && if (!character.LockHands && character.Stun < 0.1f)
(character.SelectedConstruction == null || character.SelectedConstruction.GetComponent<Controller>() == null))
{ {
character.Inventory.Update(deltaTime, cam); character.Inventory.Update(deltaTime, cam);
} }
@@ -321,7 +320,6 @@ namespace Barotrauma
} }
if (character.Inventory != null && !character.LockHands) if (character.Inventory != null && !character.LockHands)
{ {
character.Inventory.Locked = (character.SelectedConstruction != null && character.SelectedConstruction.GetComponent<Controller>() != null);
character.Inventory.DrawOwn(spriteBatch); character.Inventory.DrawOwn(spriteBatch);
character.Inventory.CurrentLayout = CharacterHealth.OpenHealthWindow == null && character.SelectedCharacter == null ? character.Inventory.CurrentLayout = CharacterHealth.OpenHealthWindow == null && character.SelectedCharacter == null ?
CharacterInventory.Layout.Default : CharacterInventory.Layout.Default :
@@ -793,7 +793,7 @@ namespace Barotrauma
base.Draw(spriteBatch); base.Draw(spriteBatch);
if (hideButton != null && hideButton.Visible && !Locked) if (hideButton != null && hideButton.Visible)
{ {
hideButton.DrawManually(spriteBatch, alsoChildren: true); hideButton.DrawManually(spriteBatch, alsoChildren: true);
} }
@@ -835,7 +835,6 @@ namespace Barotrauma
color = Color.White; color = Color.White;
highlightedQuickUseSlot = slots[i]; highlightedQuickUseSlot = slots[i];
} }
if (Locked) { color *= 0.3f; }
var quickUseIndicator = Items[i].AllowedSlots.Any(a => a == InvSlotType.Any) ? var quickUseIndicator = Items[i].AllowedSlots.Any(a => a == InvSlotType.Any) ?
EquipIndicator : DropIndicator; EquipIndicator : DropIndicator;
@@ -820,9 +820,8 @@ namespace Barotrauma
else else
{ {
Sprite slotSprite = slot.SlotSprite ?? slotSpriteSmall; Sprite slotSprite = slot.SlotSprite ?? slotSpriteSmall;
Color slotColor = slot.IsHighlighted ? Color.White : Color.White * 0.8f;
if (inventory != null && inventory.Locked) { slotColor = Color.Gray * 0.5f; } spriteBatch.Draw(slotSprite.Texture, rect, slotSprite.SourceRect, slot.IsHighlighted ? Color.White : Color.White * 0.8f);
spriteBatch.Draw(slotSprite.Texture, rect, slotSprite.SourceRect, slotColor);
if (item != null && drawItem) if (item != null && drawItem)
{ {
@@ -874,17 +873,14 @@ namespace Barotrauma
} }
indicatorSprite.Draw(spriteBatch, containedIndicatorArea.Center.ToVector2(), indicatorSprite.Draw(spriteBatch, containedIndicatorArea.Center.ToVector2(),
(inventory != null && inventory.Locked) ? Color.DarkGray * 0.5f : Color.DarkGray * 0.9f, Color.DarkGray * 0.9f,
origin: indicatorSprite.size / 2, origin: indicatorSprite.size / 2,
rotate: 0.0f, rotate: 0.0f,
scale: indicatorScale); scale: indicatorScale);
Color indicatorColor = ToolBox.GradientLerp(containedState, Color.Red, Color.Orange, Color.Green);
if (inventory != null && inventory.Locked) { indicatorColor *= 0.5f; }
spriteBatch.Draw(indicatorSprite.Texture, containedIndicatorArea.Center.ToVector2(), spriteBatch.Draw(indicatorSprite.Texture, containedIndicatorArea.Center.ToVector2(),
sourceRectangle: new Rectangle(indicatorSprite.SourceRect.Location, new Point((int)(indicatorSprite.SourceRect.Width * containedState), indicatorSprite.SourceRect.Height)), sourceRectangle: new Rectangle(indicatorSprite.SourceRect.Location, new Point((int)(indicatorSprite.SourceRect.Width * containedState), indicatorSprite.SourceRect.Height)),
color: indicatorColor, color: ToolBox.GradientLerp(containedState, Color.Red, Color.Orange, Color.Green),
rotation: 0.0f, rotation: 0.0f,
origin: indicatorSprite.size / 2, origin: indicatorSprite.size / 2,
scale: indicatorScale, scale: indicatorScale,
@@ -924,7 +920,6 @@ namespace Barotrauma
} }
Color spriteColor = sprite == item.Sprite ? item.GetSpriteColor() : item.GetInventoryIconColor(); Color spriteColor = sprite == item.Sprite ? item.GetSpriteColor() : item.GetInventoryIconColor();
if (inventory != null && inventory.Locked) { spriteColor *= 0.5f; }
if (CharacterHealth.OpenHealthWindow != null && !item.UseInHealthInterface) if (CharacterHealth.OpenHealthWindow != null && !item.UseInHealthInterface)
{ {
spriteColor = Color.Lerp(spriteColor, Color.TransparentBlack, 0.5f); spriteColor = Color.Lerp(spriteColor, Color.TransparentBlack, 0.5f);
@@ -936,10 +931,7 @@ namespace Barotrauma
sprite.Draw(spriteBatch, itemPos, spriteColor, rotation, scale); sprite.Draw(spriteBatch, itemPos, spriteColor, rotation, scale);
} }
if (inventory != null && if (inventory != null && Character.Controlled?.Inventory == inventory && slot.QuickUseKey != Keys.None)
!inventory.Locked &&
Character.Controlled?.Inventory == inventory &&
slot.QuickUseKey != Keys.None)
{ {
GUI.DrawString(spriteBatch, rect.Location.ToVector2(), GUI.DrawString(spriteBatch, rect.Location.ToVector2(),
slot.QuickUseKey.ToString().Substring(1, 1), slot.QuickUseKey.ToString().Substring(1, 1),
@@ -34,14 +34,33 @@ namespace Barotrauma
{ {
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out Vector2 spawnPos); Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out Vector2 spawnPos);
bool isClient = GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient; //bool isClient = GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient;
//for (int i = 0; i < monsterCount; i++)
//{
// monsters.Add(Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false));
//}
//monsters.ForEach(m => m.Enabled = false);
//SwarmBehavior.CreateSwarm(monsters.Cast<AICharacter>());
//sonarPositions.Add(spawnPos);
float offsetAmount = 500;
for (int i = 0; i < monsterCount; i++) for (int i = 0; i < monsterCount; i++)
{ {
monsters.Add(Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false)); CoroutineManager.InvokeAfter(() =>
{
bool isClient = GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient;
var monster = Character.Create(monsterFile, spawnPos + Rand.Vector(offsetAmount, Rand.RandSync.Server), i.ToString(), null, isClient, true, true);
monster.Enabled = false;
monsters.Add(monster);
if (monsters.Count == monsterCount)
{
//this will do nothing if the monsters have no swarm behavior defined,
//otherwise it'll make the spawned characters act as a swarm
SwarmBehavior.CreateSwarm(monsters.Cast<AICharacter>());
sonarPositions.Add(spawnPos);
}
}, Rand.Range(0f, monsterCount / 2, Rand.RandSync.Server));
} }
monsters.ForEach(m => m.Enabled = false);
SwarmBehavior.CreateSwarm(monsters.Cast<AICharacter>());
sonarPositions.Add(spawnPos);
} }
public override void Update(float deltaTime) public override void Update(float deltaTime)