Added an artifact that attracts creatures, item max health can be changed & items can be made indestructible

This commit is contained in:
Joonas Rikkonen
2017-07-04 22:10:30 +03:00
parent d397253fa1
commit 9b054ebd50
14 changed files with 83 additions and 33 deletions

View File

@@ -93,7 +93,7 @@ namespace Barotrauma.Items.Components
public void Draw(SpriteBatch spriteBatch, bool editing)
{
Color color = (item.IsSelected) ? Color.Green : Color.White;
color = color * (item.Condition / 100.0f);
color = color * (item.Condition / item.Prefab.Health);
color.A = 255;
//prefab.sprite.Draw(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color);

View File

@@ -156,7 +156,7 @@ namespace Barotrauma
}
if (!unfixedFound)
{
item.Condition = 100.0f;
item.Condition = item.Prefab.Health;
frame = null;
}
}

View File

@@ -167,21 +167,21 @@ namespace Barotrauma
if (item != null && drawItem)
{
if (item.Condition < 100.0f)
if (item.Condition < item.Prefab.Health)
{
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Bottom - 8, rect.Width, 8), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch,
new Rectangle(rect.X, rect.Bottom - 8, (int)(rect.Width * item.Condition / 100.0f), 8),
new Rectangle(rect.X, rect.Bottom - 8, (int)(rect.Width * item.Condition / item.Prefab.Health), 8),
Color.Lerp(Color.Red, Color.Green, item.Condition / 100.0f) * 0.8f, true);
}
var containedItems = item.ContainedItems;
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < 100.0f)
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < item.Prefab.Health)
{
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch,
new Rectangle(rect.X, rect.Y, (int)(rect.Width * containedItems[0].Condition / 100.0f), 8),
Color.Lerp(Color.Red, Color.Green, containedItems[0].Condition / 100.0f) * 0.8f, true);
Color.Lerp(Color.Red, Color.Green, containedItems[0].Condition / item.Prefab.Health) * 0.8f, true);
}
}

View File

@@ -1,15 +1,12 @@
using Barotrauma.Items.Components;
using Barotrauma.Networking;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Xml.Linq;
@@ -455,7 +452,7 @@ namespace Barotrauma
ownInventory.ClientRead(type, msg, sendingTime);
break;
case NetEntityEvent.Type.Status:
condition = msg.ReadRangedSingle(0.0f, 100.0f, 8);
condition = msg.ReadRangedSingle(0.0f, prefab.Health, 8);
if (FixRequirements.Count > 0)
{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

@@ -6,7 +6,7 @@
Tags="alien"
pickdistance="150">
<Sprite texture="artifact.png" depth="0.7" sourcerect="59,0,60,61"/>
<Sprite texture="artifact.png" depth="0.7" sourcerect="58,0,60,60"/>
<Deconstruct time="30">
<Item name="Steel Bar"/>
@@ -15,7 +15,7 @@
<Item name="Uranium Bar"/>
</Deconstruct>
<Body width="60" height="61" density="50"/>
<Body width="60" height="61" density="50" friction="0.95"/>
<Holdable slots="RightHand+LeftHand" holdpos="30,-15" handle1="0,10" handle2="0,-10">
<StatusEffect type="Always" target="Hull" oxygen="-50000.0"/>
@@ -28,7 +28,7 @@
Tags="alien"
pickdistance="150">
<Sprite texture="artifact.png" depth="0.7" sourcerect="0,0,58,56"/>
<Sprite texture="artifact.png" depth="0.7" sourcerect="1,0,57,56"/>
<Deconstruct time="30">
<Item name="Steel Bar"/>
@@ -37,7 +37,7 @@
<Item name="Incendium Bar"/>
</Deconstruct>
<Body radius="28" density="50"/>
<Body radius="28" density="50" friction="0.95"/>
<Holdable slots="RightHand+LeftHand" holdpos="30,-15" handle1="0,10" handle2="0,-10">
<StatusEffect type="Always">
@@ -48,6 +48,7 @@
<Item
name="Faraday Artifact"
category="Alien"
Tags="alien"
pickdistance="150">
@@ -60,7 +61,30 @@
<Item name="Fulgurium Bar"/>
</Deconstruct>
<Body radius="25" density="50"/>
<Body radius="25" density="50" friction="0.95"/>
<Holdable slots="RightHand+LeftHand" holdpos="30,-15" handle1="0,10" handle2="0,-10"/>
</Item>
<Item
name="Nasonov Artifact"
category="Alien"
Tags="alien"
pickdistance="150"
indestructible="true">
<Sprite texture="artifact.png" depth="0.7" sourcerect="60,61,63,67"/>
<Deconstruct time="30">
<Item name="Steel Bar"/>
<Item name="Fulgurium Bar"/>
<Item name="Fulgurium Bar"/>
<Item name="Fulgurium Bar"/>
</Deconstruct>
<AiTarget sightrange="10000.0" soundrange="10000"/>
<Body width="55" height="55" density="50" friction="0.95"/>
<Holdable slots="RightHand+LeftHand" holdpos="30,-15" handle1="0,10" handle2="0,-10"/>
</Item>
@@ -72,7 +96,7 @@
tags="alien,smallitem"
impacttolerance="8">
<Sprite texture="artifact.png" depth="0.7" sourcerect="119,96,9,32"/>
<Sprite texture="artifact.png" depth="0.7" sourcerect="119,0,9,32"/>
<Body width="9" height="32" density="15"/>
@@ -100,7 +124,7 @@
<Item name="Sulphuric Acid"/>
</Deconstruct>
<Sprite texture="artifact.png" depth="0.7" sourcerect="119,96,9,32"/>
<Sprite texture="artifact.png" depth="0.7" sourcerect="119,0,9,32"/>
<Body width="9" height="32" density="15"/>

View File

@@ -26,6 +26,19 @@
<message header="Artifact collected" text="The artifact is now on board. Navigate the submarine out of the cavern to claim the reward."/>
</SalvageMission>
<SalvageMission
name="Salvaging an artifact"
description="Researchers of [location1] have picked up an infrasonic signal highly similar to those emitted by alien artifacts previously discovered on Europa. Investigate the signal and retrieve the potential artifact."
commonness="10"
reward="2000"
radarlabel="Infrasonic signal"
failuremessage="Retrieving the artifact failed"
successmessage="The artifact has been succesfully retrieved"
spawntype="ruin"
itemname="Nasonov Artifact">
<message header="Artifact collected" text="The artifact is now on board. Navigate the submarine out of the cavern to claim the reward."/>
</SalvageMission>
<MonsterMission
name="Killing a Moloch"
description="A particularly aggressive Moloch has been terrorizing vessels traveling between [location1] and [location2]. A reward of 1000 credits has been promised to those who kill the creature."

View File

@@ -502,7 +502,7 @@ namespace Barotrauma
case "fixitems":
foreach (Item it in Item.ItemList)
{
it.Condition = 100.0f;
it.Condition = it.Prefab.Health;
}
break;
case "fixhull":

View File

@@ -14,7 +14,7 @@
public override void Update(float deltaTime)
{
if (item.Condition > 50.0f) Finished();
if (item.Condition > item.Prefab.Health * 0.5f) Finished();
}
}
}

View File

@@ -58,7 +58,7 @@ namespace Barotrauma.Items.Components
foreach (DeconstructItem deconstructProduct in targetItem.Prefab.DeconstructItems)
{
if (deconstructProduct.RequireFullCondition && targetItem.Condition < 100.0f) continue;
if (deconstructProduct.RequireFullCondition && targetItem.Condition < targetItem.Prefab.Health) continue;
var itemPrefab = MapEntityPrefab.list.FirstOrDefault(ip => ip.Name.ToLowerInvariant() == deconstructProduct.ItemPrefabName.ToLowerInvariant()) as ItemPrefab;
if (itemPrefab == null)

View File

@@ -178,10 +178,11 @@ namespace Barotrauma
{
if (GameMain.Client != null) return;
if (!MathUtils.IsValid(value)) return;
if (prefab.Indestructible) return;
float prev = condition;
condition = MathHelper.Clamp(value, 0.0f, 100.0f);
if (condition == 0.0f && prev>0.0f)
condition = MathHelper.Clamp(value, 0.0f, prefab.Health);
if (condition == 0.0f && prev > 0.0f)
{
ApplyStatusEffects(ActionType.OnBroken, 1.0f, null);
foreach (FixRequirement req in FixRequirements)
@@ -192,7 +193,7 @@ namespace Barotrauma
if (GameMain.Server != null && lastSentCondition != condition)
{
if (Math.Abs(lastSentCondition - condition) > 1.0f || condition == 0.0f || condition == 100.0f)
if (Math.Abs(lastSentCondition - condition) > 1.0f || condition == 0.0f || condition == prefab.Health)
{
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
lastSentCondition = condition;
@@ -205,7 +206,7 @@ namespace Barotrauma
{
get { return condition; }
}
[Editable, HasDefaultValue("", true)]
public string Tags
{
@@ -340,9 +341,9 @@ namespace Barotrauma
rect = newRect;
if (submarine==null || !submarine.Loading) FindHull();
condition = 100.0f;
lastSentCondition = 100.0f;
condition = prefab.Health;
lastSentCondition = prefab.Health;
XElement element = prefab.ConfigElement;
if (element == null) return;
@@ -740,6 +741,8 @@ namespace Barotrauma
public AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = true)
{
if (prefab.Indestructible) return new AttackResult();
float damageAmount = attack.GetStructureDamage(deltaTime);
Condition -= damageAmount;
@@ -1321,9 +1324,9 @@ namespace Barotrauma
ownInventory.ServerWrite(msg, c, extraData);
break;
case NetEntityEvent.Type.Status:
//clamp above 0.5f if condition > 0.0f
//clamp to (MaxHealth / 255.0f) if condition > 0.0f
//to prevent condition from being rounded down to 0.0 even if the item is not broken
msg.WriteRangedSingle(condition > 0.0f ? Math.Max(condition, 0.5f) : 0.0f, 0.0f, 100.0f, 8);
msg.WriteRangedSingle(condition > 0.0f ? Math.Max(condition, prefab.Health / 255.0f) : 0.0f, 0.0f, prefab.Health, 8);
if (condition <= 0.0f && FixRequirements.Count > 0)
{
@@ -1370,7 +1373,7 @@ namespace Barotrauma
FixRequirements[requirementIndex].Fixed = true;
if (condition <= 0.0f && FixRequirements.All(f => f.Fixed))
{
Condition = 100.0f;
Condition = prefab.Health;
}
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });

View File

@@ -104,6 +104,17 @@ namespace Barotrauma
get { return offsetOnSelected; }
}
public float Health
{
get;
private set;
}
public bool Indestructible
{
get;
private set;
}
public float ImpactTolerance
{
@@ -242,8 +253,10 @@ namespace Barotrauma
CanUseOnSelf = ToolBox.GetAttributeBool(element, "canuseonself", false);
FireProof = ToolBox.GetAttributeBool(element, "fireproof", false);
Health = ToolBox.GetAttributeFloat(element, "health", 100.0f);
Indestructible = ToolBox.GetAttributeBool(element, "indestructible", false);
FireProof = ToolBox.GetAttributeBool(element, "fireproof", false);
ImpactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", 0.0f);
string aliases = ToolBox.GetAttributeString(element, "aliases", "");

View File

@@ -330,7 +330,7 @@ namespace Barotrauma.Networking
continue;
}
item.Condition = 100.0f;
item.Condition = item.Prefab.Health;
var powerContainer = item.GetComponent<PowerContainer>();
if (powerContainer != null)

View File

@@ -290,7 +290,7 @@ namespace Barotrauma
body.CollidesWith = Physics.CollisionWall | Physics.CollisionLevel;
body.Friction = ToolBox.GetAttributeFloat(element, "friction", 0.3f);
body.Restitution = 0.05f;
body.Restitution = ToolBox.GetAttributeFloat(element, "restitution", 0.05f);
body.BodyType = BodyType.Dynamic;