Allow multiple calls of <Use/> for repeat-use chemicals or autoinjectors or something

This commit is contained in:
Alex Noir
2017-12-28 17:41:44 +03:00
parent 741e26251d
commit 1815062dda
2 changed files with 111 additions and 26 deletions
@@ -55,6 +55,10 @@
<StatusEffect type="OnUse" target="This, Character" bleeding="-0.1" duration="5.0">
<Sound file="Content/Items/Medical/bandage.ogg" range="500"/>
</StatusEffect>
<StatusEffect type="OnUse" target="This, Character" health="0.1" duration="5.0" checkconditionalalways="true">
<!-- Only give healing effect if their health is more than 50 -->
<Conditional Health="gt 50">
</StatusEffect>
</MeleeWeapon>
</Item>
@@ -73,7 +77,7 @@
<StatusEffect type="OnUse" target="Character" Health="-2" duration="10">
<RequiredItem name="Medical Syringe" type="Container"/>
</StatusEffect>
</Throwable>>
</Throwable>
</Item>
<Item
@@ -363,6 +367,26 @@
</Throwable>
</Item>
<Item
name="Morbusanide"
category="Material"
spritecolor="0.0,0.0,0.2,1.0"
Tags="smallitem,chem,medical"
description="A morbusine antidote.">
<Sprite texture ="med.png" sourcerect="24,16,8,16" depth="0.6"/>
<Body width="8" height="16" density="10"/>
<Throwable canBeCombined="true" slots="Any,RightHand,LeftHand" throwforce="4.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="Character">
<RequiredItem name="Medical Syringe" type="Container"/>
<Conditional hasstatustag="morbusine"/>
<Cancel/>
</StatusEffect>
</Throwable>
</Item>
<Item
name="Liquid Oxygenite"
category="Material"
@@ -457,7 +481,7 @@
<Body width="8" height="16" density="25"/>
<Throwable canBeCombined="true" slots="Any,RightHand,LeftHand" throwforce="4.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="Character" bleeding="0.1" duration="60.0">
<StatusEffect tags="poison,uranium" type="OnUse" target="Character" bleeding="0.1" duration="60.0">
<RequiredItem name="Medical Syringe" type="Container"/>
</StatusEffect>
</Throwable>
@@ -497,7 +521,7 @@
<Body width="8" height="16" density="10"/>
<Throwable canBeCombined="true" slots="Any,RightHand,LeftHand" throwforce="4.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="Character" Health="-5.0" duration="60.0">
<StatusEffect tags="poison,morbusine" type="OnUse" target="Character" Health="-5.0" duration="60.0">
<RequiredItem name="Medical Syringe" type="Container"/>
</StatusEffect>
</Throwable>
@@ -531,24 +555,21 @@
</Item>
<Item
name="Amanitin"
category="Material"
spritecolor="1.0,0.3,0.3,1.0"
Tags="smallitem,chem,medical"
description="A devious poison with a delayed effect. Requires higher dosage to be lethal.">
<!-- price="2000" Should be mixed by traitor medics more than anything -->
<!-- Direct counter to Amanitin is Liquid Oxygenite -->
name="Sufforin"
category="Material"
spritecolor="1.0,0.3,0.3,1.0"
Tags="smallitem,chem,medical"
description="A devious poison with a delayed effect.">
<!-- Can only be crafted. Direct counter to Sufforin is Liquid Oxygenite, though it's not strictly an antidote. -->
<Sprite texture ="med.png" sourcerect="24,16,8,16" depth="0.6"/>
<Body width="8" height="16" density="10"/>
<Throwable canBeCombined="true" slots="Any,RightHand,LeftHand" throwforce="4.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="Character" Oxygen="-15.0" Health="-5.0">
<StatusEffect type="OnUse" target="Character" Health="-5.0">
<RequiredItem name="Medical Syringe" type="Container"/>
</StatusEffect>
<!-- Here's a problem: if a chemical with delay is injected into more than one person, only the last person will get that delayed effect.
Everyone else gets off scott free! Woo!!!..... -->
<StatusEffect type="OnUse" target="Character" Oxygen="-10.0" Health="-0.5" duration="60.0" delay="20.0">
<StatusEffect tags="poison,sufforin" type="OnUse" target="Character" Oxygen="-15.0" Health="-0.5" duration="60.0" delay="20.0">
<RequiredItem name="Medical Syringe" type="Container"/>
</StatusEffect>
</Throwable>
@@ -135,7 +135,8 @@ namespace Barotrauma
public bool Stackable; //Can the same status effect be applied several times to the same targets?
private readonly bool useItem;
private readonly int useItemCount;
private readonly int cancelStatusEffect;
public readonly ActionType type;
@@ -288,7 +289,14 @@ namespace Barotrauma
break;
case "use":
case "useitem":
useItem = true;
useItemCount++;
break;
case "cancel":
case "cancelstatuseffect":
//This only works if there's a conditional checking for status effect tags. There is no way to cancel *all* status effects atm.
cancelStatusEffect = 1;
if (subElement.GetAttributeBool("all", false) == true)
cancelStatusEffect = 2;
break;
case "requireditem":
case "requireditems":
@@ -324,6 +332,7 @@ namespace Barotrauma
case "ne":
case "neq":
case "notequals":
case "!":
case "!e":
case "!eq":
case "!equals":
@@ -396,14 +405,66 @@ namespace Barotrauma
foreach (ISerializableEntity target in targets)
{
foreach (PropertyConditional pc in propertyConditionals)
{
string op = pc.Operator;
object value = pc.Value;
//TODO: Somehow check for non-serialized properties like SpeciesName for even more robust conditional conditioning
if (target == null || target.SerializableProperties == null || !target.SerializableProperties.TryGetValue(pc.Attribute, out SerializableProperty property)) continue;
{
if (target == null || target.SerializableProperties == null) continue;
if (!pc.Matches(property))
if (!target.SerializableProperties.TryGetValue(pc.Attribute, out SerializableProperty property))
{
//Do special conditional checks
string valStr = pc.Value.ToString();
if (pc.Attribute == "name")
return pc.Operator == "==" ? target.Name == valStr : target.Name != valStr;
if (pc.Attribute == "speciesname" && target is Character)
return pc.Operator == "==" ? ((Character)target).SpeciesName == valStr : ((Character)target).SpeciesName != valStr;
if ((pc.Attribute == "hastag" || pc.Attribute == "hastags") && target is Item)
{
string[] readTags = valStr.Split(',');
int matches = 0;
foreach (string tag in readTags)
if (((Item)target).HasTag(tag)) matches++;
//If operator is == then it needs to match everything, otherwise if its != there must be zero matches.
return pc.Operator == "==" ? matches >= readTags.Length : matches <= 0;
}
List<DurationListElement> durations = DurationList.FindAll(d => d.Targets.Contains(target));
List<DelayedListElement> delays = DelayedEffect.DelayList.FindAll(d => d.Targets.Contains(target));
bool success = false;
if (pc.Attribute == "hasstatustag" || pc.Attribute == "hasstatustags" && (durations.Any() || delays.Any()))
{
string[] readTags = valStr.Split(',');
foreach (DurationListElement duration in durations)
{
int matches = 0;
foreach (string tag in readTags)
if (duration.Parent.HasTag(tag)) matches++;
success = pc.Operator == "==" ? matches >= readTags.Length : matches <= 0;
if (cancelStatusEffect > 0 && success)
DurationList.Remove(duration);
if (cancelStatusEffect != 2) //cancelStatusEffect 1 = only cancel once, cancelStatusEffect 2 = cancel all of matching tags
return success;
}
foreach (DelayedListElement delay in delays)
{
int matches = 0;
foreach (string tag in readTags)
if (delay.Parent.HasTag(tag)) matches++;
success = pc.Operator == "==" ? matches >= readTags.Length : matches <= 0;
if (cancelStatusEffect > 0 && success)
DelayedEffect.DelayList.Remove(delay);
if (cancelStatusEffect != 2) //ditto
return success;
}
}
return success;
}
else if (!pc.Matches(property))
return false;
}
}
@@ -456,11 +517,14 @@ namespace Barotrauma
}
#endif
if (useItem)
if (useItemCount > 0)
{
foreach (Item item in targets.FindAll(t => t is Item).Cast<Item>())
for (int i=0; i<useItemCount; i++)
{
item.Use(deltaTime, targets.FirstOrDefault(t => t is Character) as Character);
foreach (Item item in targets.FindAll(t => t is Item).Cast<Item>())
{
item.Use(deltaTime, targets.FirstOrDefault(t => t is Character) as Character);
}
}
}