From a09367c78fb98b71442765757f2b1dedf8e88da6 Mon Sep 17 00:00:00 2001 From: Faerdan Date: Sun, 18 Jun 2017 22:30:54 +0100 Subject: [PATCH] Updated and refactored how items and characters are chosen for interactions in the world. The new system has more precision, with items under the cursor taking priority (this helps with small items which are in front of large items). A new method CanInteractWith(Item) has been added to the Character class which does all validation of interaction with items, including new distance calculations based on bounding boxes. This gives more consistency in selecting and interacting with all sizes and shapes of items. Because of this pickdistance (not interactdistance) has been removed from all item configurations (in their XML config files) and the default InteractDistance for all items is now 120. --- .../Content/Items/Artifacts/artifacts.xml | 20 +- Barotrauma/Content/Items/Button/button.xml | 2 +- .../Content/Items/Diving/divinggear.xml | 8 +- Barotrauma/Content/Items/Door/doors.xml | 10 +- .../Content/Items/Electricity/lights.xml | 4 +- .../Content/Items/Electricity/monitors.xml | 2 +- .../Content/Items/Electricity/poweritems.xml | 6 +- .../Content/Items/Electricity/signalitems.xml | 38 +- Barotrauma/Content/Items/Engine/engine.xml | 8 +- .../Content/Items/Fabricators/fabricators.xml | 6 +- .../Content/Items/Fabricators/materials.xml | 12 +- .../Content/Items/Jobgear/captaingear.xml | 6 +- .../Content/Items/Jobgear/doctorgear.xml | 6 +- Barotrauma/Content/Items/Jobgear/engigear.xml | 4 +- Barotrauma/Content/Items/Jobgear/misc.xml | 6 +- .../Content/Items/Jobgear/securitygear.xml | 6 +- Barotrauma/Content/Items/Medical/medical.xml | 44 +- Barotrauma/Content/Items/MiniMap/item.xml | 2 +- Barotrauma/Content/Items/Pump/pump.xml | 4 +- Barotrauma/Content/Items/Reactor/reactor.xml | 6 +- Barotrauma/Content/Items/Tools/tools.xml | 18 +- .../Content/Items/Weapons/depthcharge.xml | 8 +- .../Content/Items/Weapons/explosives.xml | 12 +- Barotrauma/Content/Items/Weapons/railgun.xml | 10 +- Barotrauma/Content/Items/Weapons/weapons.xml | 16 +- Barotrauma/Content/Items/idcard.xml | 2 +- .../Characters/AI/IndoorsSteeringManager.cs | 6 +- .../AI/Objectives/AIObjectiveContainItem.cs | 2 +- .../AI/Objectives/AIObjectiveGetItem.cs | 4 +- .../AI/Objectives/AIObjectiveGoTo.cs | 2 +- .../AI/Objectives/AIObjectiveOperateItem.cs | 4 +- .../Source/Characters/Animation/Ragdoll.cs | 4 +- Barotrauma/Source/Characters/Character.cs | 432 ++++++++++-------- Barotrauma/Source/Characters/CharacterHUD.cs | 16 +- .../Source/Characters/CharacterNetworking.cs | 16 +- .../GameModes/Tutorials/BasicTutorial.cs | 2 +- .../Items/Components/Holdable/Pickable.cs | 4 +- .../Items/Components/Machines/Controller.cs | 8 +- .../Source/Items/Components/StatusHUD.cs | 4 +- Barotrauma/Source/Items/Item.cs | 118 +---- Barotrauma/Source/Items/ItemPrefab.cs | 26 +- Barotrauma/Source/Map/Lights/LightManager.cs | 12 +- Barotrauma/Source/Map/MapEntity.cs | 10 +- Barotrauma/Source/Screens/EditMapScreen.cs | 2 +- Barotrauma/Source/Screens/GameScreen.cs | 21 +- 45 files changed, 483 insertions(+), 476 deletions(-) diff --git a/Barotrauma/Content/Items/Artifacts/artifacts.xml b/Barotrauma/Content/Items/Artifacts/artifacts.xml index ba1631cc6..01b7b8f47 100644 --- a/Barotrauma/Content/Items/Artifacts/artifacts.xml +++ b/Barotrauma/Content/Items/Artifacts/artifacts.xml @@ -4,7 +4,7 @@ name="Skyholder Artifact" category="Alien" Tags="alien" - pickdistance="150"> + > @@ -26,7 +26,7 @@ name="Thermal Artifact" category="Alien" Tags="alien" - pickdistance="150"> + > @@ -49,7 +49,7 @@ + > @@ -68,7 +68,7 @@ @@ -88,7 +88,7 @@ @@ -113,7 +113,7 @@ name="Ancient Weapon" category="Alien" Tags="alien,smallitem" - pickdistance="200"> + > @@ -164,7 +164,7 @@ category="Alien" Tags="alien" linkable="true" - pickdistance="150.0"> + > @@ -186,7 +186,7 @@ category="Alien" linkable="true" Tags="alien" - pickdistance="150.0"> + > @@ -208,7 +208,7 @@ linkable="true" category="Alien" Tags="alien" - pickdistance="150.0"> + > @@ -225,7 +225,7 @@ linkable="true" category="Alien" Tags="alien" - pickdistance="150.0"> + > diff --git a/Barotrauma/Content/Items/Button/button.xml b/Barotrauma/Content/Items/Button/button.xml index 35954a92c..3a4fcde6f 100644 --- a/Barotrauma/Content/Items/Button/button.xml +++ b/Barotrauma/Content/Items/Button/button.xml @@ -3,7 +3,7 @@ category="Electrical" linkable="true" tags="smallitem" - pickdistance="150.0" + price="10"> diff --git a/Barotrauma/Content/Items/Diving/divinggear.xml b/Barotrauma/Content/Items/Diving/divinggear.xml index d537af6c2..be3e97cd8 100644 --- a/Barotrauma/Content/Items/Diving/divinggear.xml +++ b/Barotrauma/Content/Items/Diving/divinggear.xml @@ -4,7 +4,7 @@ name="Oxygen Tank" category="Equipment,Misc" Tags="smallitem" - pickdistance="150" + price="50"> @@ -26,7 +26,7 @@ name="Diving Mask" category="Equipment" Tags="smallitem,diving" - pickdistance="200" + price="50" description="Small enough to carry around in case of need, but won't protect you from the water pressure in the event of a full-blown hull breach."> @@ -63,7 +63,7 @@ name="Diving Suit" category="Equipment" tags="diving" - pickdistance="200" + price="200" fireproof="true" description="An atmospheric diving suit capable of withstanding the immense pressure under Europa's crust."> @@ -113,7 +113,7 @@ name="Underwater Scooter" category="Equipment" Tags="smallitem" - pickdistance="200" + price="50" description="A battery-powered underwater propulsion device."> diff --git a/Barotrauma/Content/Items/Door/doors.xml b/Barotrauma/Content/Items/Door/doors.xml index 9587ecf87..a90974cfa 100644 --- a/Barotrauma/Content/Items/Door/doors.xml +++ b/Barotrauma/Content/Items/Door/doors.xml @@ -2,7 +2,7 @@ + > @@ -30,7 +30,7 @@ + > @@ -58,7 +58,7 @@ + > @@ -86,7 +86,7 @@ + > @@ -117,7 +117,7 @@ + > diff --git a/Barotrauma/Content/Items/Electricity/lights.xml b/Barotrauma/Content/Items/Electricity/lights.xml index 04e0f4f93..b3a87ee2f 100644 --- a/Barotrauma/Content/Items/Electricity/lights.xml +++ b/Barotrauma/Content/Items/Electricity/lights.xml @@ -6,7 +6,7 @@ name="Lamp" category="Electrical" Tags="smallitem" - pickdistance="150"> + > @@ -26,7 +26,7 @@ name="Emergency Light" category="Electrical" Tags="smallitem" - pickdistance="150"> + > diff --git a/Barotrauma/Content/Items/Electricity/monitors.xml b/Barotrauma/Content/Items/Electricity/monitors.xml index 2ec8eeb98..251937672 100644 --- a/Barotrauma/Content/Items/Electricity/monitors.xml +++ b/Barotrauma/Content/Items/Electricity/monitors.xml @@ -2,7 +2,7 @@ + > diff --git a/Barotrauma/Content/Items/Electricity/poweritems.xml b/Barotrauma/Content/Items/Electricity/poweritems.xml index bc2d764bc..c8d0e8e48 100644 --- a/Barotrauma/Content/Items/Electricity/poweritems.xml +++ b/Barotrauma/Content/Items/Electricity/poweritems.xml @@ -4,7 +4,7 @@ name="Junction Box" category="Electrical" linkable="true" - pickdistance="150" + description="Serves as a hub for power distribution and relaying signals between devices."> @@ -40,7 +40,7 @@ name="Battery" category="Electrical" linkable="true" - pickdistance="150" + description="Generally used for storing backup power in case of a reactor failure."> @@ -68,7 +68,7 @@ name="Supercapacitor" category="Electrical" linkable="true" - pickdistance="150" + description="Can deliver charge much faster than batteries."> diff --git a/Barotrauma/Content/Items/Electricity/signalitems.xml b/Barotrauma/Content/Items/Electricity/signalitems.xml index 597fce51b..5914f3b77 100644 --- a/Barotrauma/Content/Items/Electricity/signalitems.xml +++ b/Barotrauma/Content/Items/Electricity/signalitems.xml @@ -6,7 +6,7 @@ name="Wire" category="Electrical" Tags="smallitem,wire" - pickdistance="150" + linkable="true" canbepicked="true" price="10"> @@ -29,7 +29,7 @@ category="Electrical" Tags="smallitem,wire" spritecolor="1.0,0.0,0.0,1.0" - pickdistance="150" + linkable="true" canbepicked="true" price="10"> @@ -51,7 +51,7 @@ category="Electrical" Tags="smallitem,wire" spritecolor="0.0,0.6,1.0,1.0" - pickdistance="150" + linkable="true" canbepicked="true" price="10"> @@ -73,7 +73,7 @@ category="Electrical" Tags="smallitem,wire" spritecolor="1.0,0.5,0.0,1.0" - pickdistance="150" + linkable="true" canbepicked="true" price="10"> @@ -94,7 +94,7 @@ name="FPGA Circuit" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="100" description="Field-programmable gate array - a multi-purpose circuit which can be reconfigured for use in a large variety of electrical devices."> @@ -110,7 +110,7 @@ name="And Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Sends a signal when both inputs receive a signal within a set period of each other."> @@ -145,7 +145,7 @@ name="Or Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Sends a signal if either of the inputs receive a signal."> @@ -179,7 +179,7 @@ name="Not Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Sends a signal when the input is NOT receiving a signal."> @@ -211,7 +211,7 @@ name="Relay Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="When switched on, forwards all received signals from the input connections to the outputs."> @@ -257,7 +257,7 @@ name="Delay Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Delays all received signals for a specific amount of time."> @@ -289,7 +289,7 @@ name="Light Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10"> @@ -324,7 +324,7 @@ name="Oxygen Detector" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Sends out a value between 0-100 depending on the quality of the surrounding air."> @@ -355,7 +355,7 @@ name="Water Detector" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Sends out a signal when the detector is submerged."> @@ -386,7 +386,7 @@ name="Signal Check Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Sends a signal when a signal matching a specific value is received."> @@ -420,7 +420,7 @@ name="RegEx Find Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10" description="Sends a signal if the received signal matches a specific regular expression pattern."> @@ -452,7 +452,7 @@ name="Wifi Component" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="20" description="Allows remote communication between other Wifi Components that are using the same channel."> @@ -484,7 +484,7 @@ name="Emergency Siren" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10"> @@ -517,7 +517,7 @@ name="Alarm Buzzer" category="Electrical" Tags="smallitem" - pickdistance="150" + linkable="true" price="10"> @@ -550,7 +550,7 @@ name="Camera" category="Electrical" Tags="smallitem" - pickdistance="150" + focusonselected="true" offsetonselected="500" linkable="true" diff --git a/Barotrauma/Content/Items/Engine/engine.xml b/Barotrauma/Content/Items/Engine/engine.xml index 41600d1c0..aedcec445 100644 --- a/Barotrauma/Content/Items/Engine/engine.xml +++ b/Barotrauma/Content/Items/Engine/engine.xml @@ -6,7 +6,7 @@ linkable="true" category="Machine" pickthroughwalls="true" - pickdistance="150"> + > @@ -34,7 +34,7 @@ linkable="true" category="Machine" pickthroughwalls="true" - pickdistance="150"> + > @@ -60,7 +60,7 @@ name="Navigation Terminal" linkable="true" category="Machine" - pickdistance="150"> + > @@ -96,7 +96,7 @@ name="Sonar Monitor" linkable="true" category="Machine" - pickdistance="150"> + > diff --git a/Barotrauma/Content/Items/Fabricators/fabricators.xml b/Barotrauma/Content/Items/Fabricators/fabricators.xml index f3f5e6952..e90a36068 100644 --- a/Barotrauma/Content/Items/Fabricators/fabricators.xml +++ b/Barotrauma/Content/Items/Fabricators/fabricators.xml @@ -3,7 +3,7 @@ @@ -84,7 +84,7 @@ @@ -157,7 +157,7 @@ diff --git a/Barotrauma/Content/Items/Fabricators/materials.xml b/Barotrauma/Content/Items/Fabricators/materials.xml index 32c8e39a6..489349d65 100644 --- a/Barotrauma/Content/Items/Fabricators/materials.xml +++ b/Barotrauma/Content/Items/Fabricators/materials.xml @@ -4,7 +4,7 @@ name="Steel Bar" category="Material" Tags="smallitem" - pickdistance="150" + canbepicked="true" price="50"> @@ -24,7 +24,7 @@ name="Uranium Bar" category="Material" Tags="smallitem" - pickdistance="150" + spritecolor="0.2,0.35,0.06,1.0" canbepicked="true" price="100"> @@ -45,7 +45,7 @@ name="Copper Bar" category="Material" Tags="smallitem" - pickdistance="150" + spritecolor="0.78,0.55,0.2,1.0" canbepicked="true" price="50"> @@ -61,7 +61,7 @@ name="Polycarbonate Bar" category="Material" Tags="smallitem" - pickdistance="150" + spritecolor="0.9,0.9,1.0,0.9" canbepicked="true" price="50"> @@ -77,7 +77,7 @@ name="Incendium Bar" category="Material" Tags="smallitem" - pickdistance="150" + spritecolor="0.5,0.0,0.0,1.0" canbepicked="true"> @@ -97,7 +97,7 @@ name="Fulgurium Bar" category="Material" Tags="smallitem" - pickdistance="150" + spritecolor="1.0,0.7,0.05,1.0" canbepicked="true"> diff --git a/Barotrauma/Content/Items/Jobgear/captaingear.xml b/Barotrauma/Content/Items/Jobgear/captaingear.xml index 86f6c402b..d01749550 100644 --- a/Barotrauma/Content/Items/Jobgear/captaingear.xml +++ b/Barotrauma/Content/Items/Jobgear/captaingear.xml @@ -2,7 +2,7 @@ @@ -18,7 +18,7 @@ @@ -39,7 +39,7 @@ diff --git a/Barotrauma/Content/Items/Jobgear/doctorgear.xml b/Barotrauma/Content/Items/Jobgear/doctorgear.xml index 12ce2e492..d8b3bb6e7 100644 --- a/Barotrauma/Content/Items/Jobgear/doctorgear.xml +++ b/Barotrauma/Content/Items/Jobgear/doctorgear.xml @@ -2,7 +2,7 @@ @@ -20,7 +20,7 @@ @@ -45,7 +45,7 @@ diff --git a/Barotrauma/Content/Items/Jobgear/engigear.xml b/Barotrauma/Content/Items/Jobgear/engigear.xml index ce7f89054..a4281f7e1 100644 --- a/Barotrauma/Content/Items/Jobgear/engigear.xml +++ b/Barotrauma/Content/Items/Jobgear/engigear.xml @@ -2,7 +2,7 @@ @@ -30,7 +30,7 @@ diff --git a/Barotrauma/Content/Items/Jobgear/misc.xml b/Barotrauma/Content/Items/Jobgear/misc.xml index d3ac00fb2..5a8c593f1 100644 --- a/Barotrauma/Content/Items/Jobgear/misc.xml +++ b/Barotrauma/Content/Items/Jobgear/misc.xml @@ -2,7 +2,7 @@ @@ -28,7 +28,7 @@ @@ -44,7 +44,7 @@ diff --git a/Barotrauma/Content/Items/Jobgear/securitygear.xml b/Barotrauma/Content/Items/Jobgear/securitygear.xml index 1fb1e62e4..804017f10 100644 --- a/Barotrauma/Content/Items/Jobgear/securitygear.xml +++ b/Barotrauma/Content/Items/Jobgear/securitygear.xml @@ -2,7 +2,7 @@ @@ -20,7 +20,7 @@ @@ -41,7 +41,7 @@ diff --git a/Barotrauma/Content/Items/Medical/medical.xml b/Barotrauma/Content/Items/Medical/medical.xml index 8b1585312..bc86ed1ee 100644 --- a/Barotrauma/Content/Items/Medical/medical.xml +++ b/Barotrauma/Content/Items/Medical/medical.xml @@ -4,7 +4,7 @@ name="Medical Syringe" category="Equipment" Tags="smallitem,medical" - pickdistance="150" + price="50" canuseonself="true" description="Injection is often a much more effective method of administering drugs than taking them orally."> @@ -31,7 +31,7 @@ name="Bandage" category="Equipment" Tags="smallitem,medical" - pickdistance="150" + canuseonself="true" price="20" description="Treated with a hemostatic agent that quickly seals most minor wounds."> @@ -51,7 +51,7 @@ name="Iron Powder" category="Material" Tags="smallitem,chem" - pickdistance="150" + price="5"> @@ -66,7 +66,7 @@ category="Material" spritecolor="1.0,1.0,0.7,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + description="A mild stimulant which is used as an incredient in the manufacture of various medicines." price="10"> @@ -91,7 +91,7 @@ category="Material" spritecolor="0.5,0.5,1.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + canuseonself="true" description="Most commonly used for treating oxygen deprivation." price="50"> @@ -112,7 +112,7 @@ category="Material" spritecolor="0.6,0.4,0.2,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + canuseonself="true" description="A hemostatic agent that slows down bleeding." price="50"> @@ -138,7 +138,7 @@ category="Material" spritecolor="0.8,0.0,0.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + canuseonself="true" description="Highly effective at treating various types of physical trauma." price="50"> @@ -164,7 +164,7 @@ category="Material" spritecolor="1.0,1.0,0.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + description="A highly potent corrigodone-based stimulant." price="150"> @@ -184,7 +184,7 @@ category="Material" spritecolor="1.0,1.0,1.0,0.6" Tags="smallitem,chem,medical" - pickdistance="150" + price="20"> @@ -204,7 +204,7 @@ spritecolor="0.0,0.9,0.1,1.0" Tags="smallitem,chem,medical" canuseonself="true" - pickdistance="150" + price="20"> @@ -228,7 +228,7 @@ category="Material" spritecolor="0.7,0.7,0.7,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + price="20"> @@ -247,7 +247,7 @@ category="Material" spritecolor="0.8,0.8,0.8,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + price="20"> @@ -266,7 +266,7 @@ category="Material" spritecolor="0.1,0.1,0.1,1.0" Tags="smallitem,chem,explosive" - pickdistance="150" + price="50"> @@ -287,7 +287,7 @@ category="Material" spritecolor="1.0,1.0,1.0,0.8" Tags="smallitem,chem,medical" - pickdistance="150" + price="20"> @@ -306,7 +306,7 @@ category="Material" spritecolor="0.5,0.0,0.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + price="20"> @@ -325,7 +325,7 @@ category="Material" spritecolor="0.5,0.0,0.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + price="50"> @@ -344,7 +344,7 @@ category="Material" spritecolor="0.2,0.35,0.06,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + price="50"> @@ -363,7 +363,7 @@ category="Material" spritecolor="0.8,0.3,0.8,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + description="A potent muscle stimulant." price="50"> @@ -383,7 +383,7 @@ category="Material" spritecolor="0.0,0.0,0.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + description="A highly potent neurotoxin." price="200"> @@ -403,7 +403,7 @@ category="Material" spritecolor="0.0,0.0,0.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + description="Dormant eggs of the Europan lifeform colloquially referred to as 'husk parasite'." price="200"> @@ -423,7 +423,7 @@ category="Material" spritecolor="0.0,0.0,0.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + description="An antiparasitic drug used in the treatment of husk parasite infections." price="300"> @@ -443,7 +443,7 @@ category="Material" spritecolor="0.6,0.8,1.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + canuseonself="true" description="A mildy toxic solution that slowly releases oxygen into the bloodstream when injected."> diff --git a/Barotrauma/Content/Items/MiniMap/item.xml b/Barotrauma/Content/Items/MiniMap/item.xml index b4cea1c25..62ad09905 100644 --- a/Barotrauma/Content/Items/MiniMap/item.xml +++ b/Barotrauma/Content/Items/MiniMap/item.xml @@ -3,7 +3,7 @@ aliases="MiniMap" category="Machine" linkable="true" - pickdistance="150"> + > diff --git a/Barotrauma/Content/Items/Pump/pump.xml b/Barotrauma/Content/Items/Pump/pump.xml index 9b957be14..491974dec 100644 --- a/Barotrauma/Content/Items/Pump/pump.xml +++ b/Barotrauma/Content/Items/Pump/pump.xml @@ -3,7 +3,7 @@ name="Pump" linkable="true" category="Machine" - pickdistance="200"> + > @@ -26,7 +26,7 @@ name="Small Pump" linkable="true" category="Machine" - pickdistance="150"> + > diff --git a/Barotrauma/Content/Items/Reactor/reactor.xml b/Barotrauma/Content/Items/Reactor/reactor.xml index fd01c2165..80fbf39b4 100644 --- a/Barotrauma/Content/Items/Reactor/reactor.xml +++ b/Barotrauma/Content/Items/Reactor/reactor.xml @@ -55,7 +55,7 @@ @@ -73,7 +73,7 @@ @@ -92,7 +92,7 @@ + > diff --git a/Barotrauma/Content/Items/Tools/tools.xml b/Barotrauma/Content/Items/Tools/tools.xml index 1b53bfdbc..cc5f710f6 100644 --- a/Barotrauma/Content/Items/Tools/tools.xml +++ b/Barotrauma/Content/Items/Tools/tools.xml @@ -4,7 +4,7 @@ name="Welding Tool" category="Equipment" Tags="smallitem" - pickdistance="200" + price="100" description="One of the most crucial tools on board the submarine. Also works underwater."> @@ -60,7 +60,7 @@ name="Plasma Cutter" category="Equipment" Tags="smallitem" - pickdistance="200" + price="100" description="Cuts through various materials using a jet of ionized oxygen."> @@ -105,7 +105,7 @@ name="Welding Fuel Tank" category="Equipment" Tags="smallitem" - pickdistance="150" + price="50"> @@ -127,7 +127,7 @@ name="Fire Extinguisher" category="Equipment" Tags="smallitem" - pickdistance="200" + price="100" description="A handheld carbon dioxide extinguisher."> @@ -156,7 +156,7 @@ name="Screwdriver" category="Equipment" Tags="smallitem" - pickdistance="200" + price="10"> @@ -171,7 +171,7 @@ name="Wrench" category="Equipment" Tags="smallitem" - pickdistance="200" + price="10"> @@ -188,7 +188,7 @@ name="Handheld Sonar" category="Equipment" Tags="smallitem" - pickdistance="200" + price="10"> @@ -218,7 +218,7 @@ name="Flashlight" category="Equipment" Tags="smallitem" - pickdistance="200" + price="10"> @@ -249,7 +249,7 @@ diff --git a/Barotrauma/Content/Items/Weapons/depthcharge.xml b/Barotrauma/Content/Items/Weapons/depthcharge.xml index c3c31176c..58663800c 100644 --- a/Barotrauma/Content/Items/Weapons/depthcharge.xml +++ b/Barotrauma/Content/Items/Weapons/depthcharge.xml @@ -6,7 +6,7 @@ focusonselected="true" offsetonselected="700" linkable="true" - pickdistance="150"> + > @@ -24,7 +24,7 @@ name="Depth Charge Loader" category="Machine" linkable="true" - pickdistance="150"> + > @@ -37,7 +37,7 @@ @@ -65,7 +65,7 @@ diff --git a/Barotrauma/Content/Items/Weapons/explosives.xml b/Barotrauma/Content/Items/Weapons/explosives.xml index 57c683c19..09d6b74b7 100644 --- a/Barotrauma/Content/Items/Weapons/explosives.xml +++ b/Barotrauma/Content/Items/Weapons/explosives.xml @@ -4,7 +4,7 @@ name="C-4 Block" category="Equipment" Tags="smallitem,explosive" - pickdistance="150" + price="100"> @@ -22,7 +22,7 @@ name="Compound N" category="Equipment" Tags="smallitem,explosive" - pickdistance="150"> + > @@ -40,7 +40,7 @@ name="Volatile Compound N" category="Equipment" Tags="smallitem,explosive" - pickdistance="150"> + > @@ -60,7 +60,7 @@ description="A compound made of C-4 and incendium." category="Equipment" Tags="smallitem,explosive" - pickdistance="150"> + > @@ -80,7 +80,7 @@ description="A device that detonates any contained explosive when receiving a signal." category="Equipment" Tags="smallitem" - pickdistance="150" + price="50"> @@ -109,7 +109,7 @@ description="A highly unstable liquid that may explode when subjected to heat or physical shock." spritecolor="1.0,1.0,1.0,1.0" Tags="smallitem,chem,medical" - pickdistance="150" + impacttolerance="4"> diff --git a/Barotrauma/Content/Items/Weapons/railgun.xml b/Barotrauma/Content/Items/Weapons/railgun.xml index ec3636731..77eba067f 100644 --- a/Barotrauma/Content/Items/Weapons/railgun.xml +++ b/Barotrauma/Content/Items/Weapons/railgun.xml @@ -5,7 +5,7 @@ focusonselected="true" offsetonselected="700" linkable="true" - pickdistance="150"> + > @@ -30,7 +30,7 @@ category="Machine" type="Controller" linkable="true" - pickdistance="150"> + > @@ -53,7 +53,7 @@ name="Railgun Loader" category="Machine" linkable="true" - pickdistance="150"> + > @@ -67,7 +67,7 @@ @@ -98,7 +98,7 @@ diff --git a/Barotrauma/Content/Items/Weapons/weapons.xml b/Barotrauma/Content/Items/Weapons/weapons.xml index 5b80c984d..9b78208f0 100644 --- a/Barotrauma/Content/Items/Weapons/weapons.xml +++ b/Barotrauma/Content/Items/Weapons/weapons.xml @@ -4,7 +4,7 @@ @@ -25,7 +25,7 @@ @@ -57,7 +57,7 @@ @@ -75,7 +75,7 @@ @@ -94,7 +94,7 @@ name="Stun Baton" category="Equipment" Tags="smallitem,weapon" - pickdistance="150" + price="100" description="If verbal orders are insufficient, a high-voltage shock from a Stun Baton may be enough to beat an unruly crew member into submission."> @@ -129,7 +129,7 @@ @@ -150,7 +150,7 @@ @@ -170,7 +170,7 @@ diff --git a/Barotrauma/Content/Items/idcard.xml b/Barotrauma/Content/Items/idcard.xml index dfafdd8e7..1c2d8c62e 100644 --- a/Barotrauma/Content/Items/idcard.xml +++ b/Barotrauma/Content/Items/idcard.xml @@ -4,7 +4,7 @@ name="ID Card" category="Equipment" Tags="smallitem" - pickdistance="150"> + > diff --git a/Barotrauma/Source/Characters/AI/IndoorsSteeringManager.cs b/Barotrauma/Source/Characters/AI/IndoorsSteeringManager.cs index b446539ad..58dd11178 100644 --- a/Barotrauma/Source/Characters/AI/IndoorsSteeringManager.cs +++ b/Barotrauma/Source/Characters/AI/IndoorsSteeringManager.cs @@ -141,7 +141,7 @@ namespace Barotrauma { if (character.SelectedConstruction != currentPath.CurrentNode.Ladders.Item && currentPath.CurrentNode.Ladders.Item.IsInsideTrigger(character.WorldPosition)) { - currentPath.CurrentNode.Ladders.Item.Pick(character, false, true); + currentPath.CurrentNode.Ladders.Item.TryInteract(character, false, true); } } @@ -239,7 +239,7 @@ namespace Barotrauma foreach (Controller controller in buttons) { float dist = Vector2.Distance(controller.Item.WorldPosition, character.WorldPosition); - if (dist > controller.Item.PickDistance * 2.0f) continue; + if (dist > controller.Item.InteractDistance * 2.0f) continue; if (dist < closestDist || closestButton == null) { @@ -256,7 +256,7 @@ namespace Barotrauma return; } - closestButton.Item.Pick(character, false, true); + closestButton.Item.TryInteract(character, false, true); break; } } diff --git a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveContainItem.cs b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveContainItem.cs index cad9038cc..2888964f1 100644 --- a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveContainItem.cs +++ b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveContainItem.cs @@ -64,7 +64,7 @@ namespace Barotrauma } else { - if (Vector2.Distance(character.Position, container.Item.Position) > container.Item.PickDistance + if (Vector2.Distance(character.Position, container.Item.Position) > container.Item.InteractDistance && !container.Item.IsInsideTrigger(character.Position)) { AddSubObjective(new AIObjectiveGoTo(container.Item, character)); diff --git a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs index ab2ce3af0..d3d04d326 100644 --- a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs +++ b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs @@ -57,7 +57,7 @@ namespace Barotrauma FindTargetItem(); if (targetItem == null || moveToTarget == null) return; - if (Vector2.Distance(character.Position, moveToTarget.Position) < targetItem.PickDistance*2.0f) + if (Vector2.Distance(character.Position, moveToTarget.Position) < targetItem.InteractDistance*2.0f) { int targetSlot = -1; if (equip) @@ -93,7 +93,7 @@ namespace Barotrauma } } - targetItem.Pick(character, false, true); + targetItem.TryInteract(character, false, true); if (targetSlot > -1 && character.Inventory.IsInLimbSlot(targetItem, InvSlotType.Any)) { diff --git a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs index bcbcec0dc..3a9b2e037 100644 --- a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs +++ b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs @@ -126,7 +126,7 @@ namespace Barotrauma if (item != null) { - allowedDistance = Math.Max(ConvertUnits.ToSimUnits(item.PickDistance), allowedDistance); + allowedDistance = Math.Max(ConvertUnits.ToSimUnits(item.InteractDistance), allowedDistance); if (item.IsInsideTrigger(character.WorldPosition)) completed = true; } diff --git a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs index 443a0079e..ca893ffef 100644 --- a/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs +++ b/Barotrauma/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs @@ -53,12 +53,12 @@ namespace Barotrauma if (target.CanBeSelected) { - if (Vector2.Distance(character.Position, target.Item.Position) < target.Item.PickDistance + if (Vector2.Distance(character.Position, target.Item.Position) < target.Item.InteractDistance || target.Item.IsInsideTrigger(character.WorldPosition)) { if (character.SelectedConstruction != target.Item && target.CanBeSelected) { - target.Item.Pick(character, false, true); + target.Item.TryInteract(character, false, true); } if (component.AIOperate(deltaTime, character, this)) isCompleted = true; diff --git a/Barotrauma/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/Source/Characters/Animation/Ragdoll.cs index f069d5d1f..27e10604e 100644 --- a/Barotrauma/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/Source/Characters/Animation/Ragdoll.cs @@ -1270,7 +1270,7 @@ namespace Barotrauma var newSelectedConstruction = (Item)character.MemState[0].Interact; if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction) { - newSelectedConstruction.Pick(character, true, true); + newSelectedConstruction.TryInteract(character, true, true); } character.SelectedConstruction = newSelectedConstruction; } @@ -1362,7 +1362,7 @@ namespace Barotrauma var newSelectedConstruction = (Item)serverPos.Interact; if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction) { - newSelectedConstruction.Pick(character, true, true); + newSelectedConstruction.TryInteract(character, true, true); } character.SelectedConstruction = newSelectedConstruction; } diff --git a/Barotrauma/Source/Characters/Character.cs b/Barotrauma/Source/Characters/Character.cs index 0e133f1fa..c52a1d353 100644 --- a/Barotrauma/Source/Characters/Character.cs +++ b/Barotrauma/Source/Characters/Character.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; +using Barotrauma.Items.Components; namespace Barotrauma { @@ -94,8 +95,8 @@ namespace Barotrauma private float health, lastSentHealth; protected float minHealth, maxHealth; - protected Item closestItem; - private Character closestCharacter, selectedCharacter; + protected Item focusedItem; + private Character focusedCharacter, selectedCharacter; private Dictionary hudProgressBars; @@ -184,6 +185,11 @@ namespace Barotrauma get { return !IsUnconscious && Stun <= 0.0f && !isDead; } } + public bool CanInteract + { + get { return AllowInput && !LockHands; } + } + public Vector2 CursorPosition { get { return cursorPosition; } @@ -199,9 +205,9 @@ namespace Barotrauma get { return Submarine == null ? cursorPosition : cursorPosition + Submarine.Position; } } - public Character ClosestCharacter + public Character FocusedCharacter { - get { return closestCharacter; } + get { return focusedCharacter; } } public Character SelectedCharacter @@ -421,9 +427,9 @@ namespace Barotrauma set { selectedConstruction = value; } } - public Item ClosestItem + public Item FocusedItem { - get { return closestItem; } + get { return focusedItem; } } public virtual AIController AIController @@ -622,7 +628,7 @@ namespace Barotrauma System.Diagnostics.Debug.Assert(item != null); if (item == null) continue; - item.Pick(this, true, true, true); + item.TryInteract(this, true, true, true); inventory.TryPutItem(item, i, false, false); } } @@ -764,7 +770,7 @@ namespace Barotrauma return (Info==null || Info.Job==null) ? 0 : Info.Job.GetSkillLevel(skillName); } - float findClosestTimer; + float findFocusedTimer; public Vector2 GetTargetMovement() { @@ -1003,7 +1009,7 @@ namespace Barotrauma public bool CanAccessInventory(Inventory inventory) { - if (!AllowInput || LockHands) return false; + if (!CanInteract) return false; //the inventory belongs to some other character if (inventory.Owner is Character && inventory.Owner != this) @@ -1011,14 +1017,13 @@ namespace Barotrauma var owner = (Character)inventory.Owner; //can only be accessed if the character is incapacitated and has been selected - return selectedCharacter == owner && - (owner.isDead || owner.IsUnconscious || owner.Stun > 0.0f || owner.LockHands); + return selectedCharacter == owner && (!owner.CanInteract); } if (inventory.Owner is Item) { var owner = (Item)inventory.Owner; - if (!CanAccessItem(owner)) + if (!CanInteractWith(owner)) { return false; } @@ -1026,53 +1031,162 @@ namespace Barotrauma return true; } - public bool CanAccessItem(Item item) + public bool CanInteractWith(Item item) { - if (!AllowInput || LockHands) return false; + float distanceToItem; + return CanInteractWith(item, out distanceToItem); + } + + public bool CanInteractWith(Item item, out float distanceToItem) + { + distanceToItem = -1.0f; + + if (!CanInteract) return false; if (item.ParentInventory != null) { return CanAccessInventory(item.ParentInventory); } - float maxDist = item.PickDistance * 1.2f; - if (maxDist <= 0.01f) - { - maxDist = 150.0f; - } + if (item.InteractDistance == 0.0f && !item.Prefab.Triggers.Any()) return false; - if (Vector2.DistanceSquared(WorldPosition, item.WorldPosition) < maxDist*maxDist || - item.IsInsideTrigger(WorldPosition)) - { - return true; - } + Pickable pickableComponent = item.GetComponent(); + if (pickableComponent != null && (pickableComponent.Picker != null && !pickableComponent.Picker.IsDead)) return false; + + Vector2 characterDirection = Vector2.Transform(Vector2.UnitY, Quaternion.CreateFromAxisAngle(Vector3.UnitZ, AnimController.Collider.Rotation)); - return item.GetComponent() != null; - } - - private Item FindClosestItem(Vector2 mouseSimPos, out float distance) - { - distance = 0.0f; - - Limb torso = AnimController.GetLimb(LimbType.Torso); - - if (torso == null) return null; - - Vector2 pos = (torso.body.TargetPosition != null) ? (Vector2)torso.body.TargetPosition : torso.SimPosition; - Vector2 pickPos = mouseSimPos; + Vector2 upperBodyPosition = Position + (characterDirection * 20.0f); + Vector2 lowerBodyPosition = Position - (characterDirection * 60.0f); if (Submarine != null) { - pos += Submarine.SimPosition; - pickPos += Submarine.SimPosition; + upperBodyPosition += Submarine.Position; + lowerBodyPosition += Submarine.Position; } - if (selectedConstruction != null) pickPos = ConvertUnits.ToSimUnits(selectedConstruction.WorldPosition); + Vector2 playerDistanceCheckPosition; + Rectangle itemDisplayRect; - return Item.FindPickable(pos, pickPos, AnimController.CurrentHull, selectedItems, out distance); + bool insideTrigger = false; + if (item.Prefab.Triggers.Any()) + { + foreach (Rectangle trigger in item.Prefab.Triggers) + { + Rectangle transformedTrigger = new Rectangle( + item.WorldRect.X + trigger.X, + (item.WorldRect.Y + trigger.Y) - ((trigger.Height == 0) ? item.Rect.Height : trigger.Height), + (trigger.Width == 0) ? item.Rect.Width : trigger.Width, + (trigger.Height == 0) ? item.Rect.Height : trigger.Height); + + // Get the point along the line between lowerBodyPosition and upperBodyPosition which is closest to the center of itemDisplayRect + playerDistanceCheckPosition = Vector2.Clamp(transformedTrigger.Center.ToVector2(), lowerBodyPosition, upperBodyPosition); + + if (!transformedTrigger.Contains(upperBodyPosition)) return false; + + insideTrigger = true; + } + if (!insideTrigger) return false; + } + itemDisplayRect = new Rectangle(item.InteractionRect.X, item.InteractionRect.Y - item.InteractionRect.Height, item.InteractionRect.Width, item.InteractionRect.Height); + + // Get the point along the line between lowerBodyPosition and upperBodyPosition which is closest to the center of itemDisplayRect + playerDistanceCheckPosition = Vector2.Clamp(itemDisplayRect.Center.ToVector2(), lowerBodyPosition, upperBodyPosition); + + // Here we get the point on the itemDisplayRect which is closest to playerDistanceCheckPosition + Vector2 rectIntersectionPoint = new Vector2(Math.Max(itemDisplayRect.X, Math.Min(itemDisplayRect.X + itemDisplayRect.Width, playerDistanceCheckPosition.X)), Math.Max(itemDisplayRect.Y, Math.Min(itemDisplayRect.Y + itemDisplayRect.Height, playerDistanceCheckPosition.Y))); + + // If playerDistanceCheckPosition is inside the itemDisplayRect then we consider the character to within 0 distance of the item + if (!itemDisplayRect.Contains(playerDistanceCheckPosition)) + { + distanceToItem = Vector2.Distance(rectIntersectionPoint, playerDistanceCheckPosition); + } + + if (distanceToItem > item.InteractDistance && item.InteractDistance > 0.0f) return false; + + if (!item.Prefab.InteractThroughWalls && Screen.Selected != GameMain.EditMapScreen && !insideTrigger) + { + Vector2 itemPosition = item.SimPosition; + if (Submarine == null && item.Submarine != null) + { + //character is outside, item inside + itemPosition += item.Submarine.SimPosition; + } + else if (Submarine != null && item.Submarine == null) + { + //character is inside, item outside + itemPosition -= Submarine.SimPosition; + } + else if (Submarine != item.Submarine) + { + //character and the item are inside different subs + itemPosition += item.Submarine.SimPosition; + itemPosition -= Submarine.SimPosition; + } + Body body = Submarine.CheckVisibility(SimPosition, itemPosition, true); + if (body != null && body.UserData as Item != item) return false; + } + + return true; } - private Character FindClosestCharacter(Vector2 mouseSimPos, float maxDist = 150.0f) + /// + /// Finds the front (lowest depth) interactable item at a position. "Interactable" in this case means that the character can "reach" the item. + /// + /// The Character who is looking for the interactable item, only items that are close enough to this character are returned + /// The item at the simPosition, with the lowest depth, is returned + /// If this is true and an item cannot be found at simPosition then a nearest item will be returned if possible + /// If a hull is specified, only items within that hull are returned + public Item FindItemAtPosition(Vector2 simPosition, float aimAssistModifier = 0.0f, Hull hull = null, Item[] ignoredItems = null) + { + if (Submarine != null) + { + simPosition += Submarine.SimPosition; + } + + Vector2 displayPosition = ConvertUnits.ToDisplayUnits(simPosition); + + Item highestPriorityItemAtPosition = null; + Item closestItem = null; + float closestItemDistance = 0.0f; + + foreach (Item item in Item.ItemList) + { + if (ignoredItems != null && ignoredItems.Contains(item)) continue; + if (item.body != null && !item.body.Enabled) continue; + + if (CanInteractWith(item)) + { + if (item.IsMouseOn(displayPosition)) + { + Console.WriteLine("Name: " + item.Name + " Priority:" + item.InteractPriority); + } + if (item.IsMouseOn(displayPosition) && (highestPriorityItemAtPosition == null || + ((highestPriorityItemAtPosition.InteractPriority < item.InteractPriority) || + (highestPriorityItemAtPosition.InteractPriority == item.InteractPriority && highestPriorityItemAtPosition.GetDrawDepth() > item.GetDrawDepth())))) + { + highestPriorityItemAtPosition = item; + } + else if (aimAssistModifier > 0.0f) + { + float distanceToItem = Vector2.Distance(item.WorldPosition, displayPosition); + if (distanceToItem < (100.0f * aimAssistModifier) && (closestItem == null || distanceToItem < closestItemDistance)) + { + closestItem = item; + closestItemDistance = distanceToItem; + } + } + } + } + + if (highestPriorityItemAtPosition == null) + { + return closestItem; + } + + return highestPriorityItemAtPosition; + } + + private Character FindCharacterAtPosition(Vector2 mouseSimPos, float maxDist = 150.0f) { Character closestCharacter = null; float closestDist = 0.0f; @@ -1081,17 +1195,25 @@ namespace Barotrauma foreach (Character c in CharacterList) { - if (c == this || !c.enabled) continue; - - if (Vector2.DistanceSquared(SimPosition, c.SimPosition) > maxDist*maxDist) continue; + if (c == this || !c.enabled || c.info == null || !c.IsHumanoid || !c.CanBeSelected) continue; float dist = Vector2.DistanceSquared(mouseSimPos, c.SimPosition); - if (dist < maxDist*maxDist && (closestCharacter==null || dist /// Control the Character according to player input /// @@ -1147,7 +1328,7 @@ namespace Barotrauma { if (!DisableControls) { - for (int i = 0; i < keys.Length; i++ ) + for (int i = 0; i < keys.Length; i++) { keys[i].SetState(); } @@ -1163,7 +1344,7 @@ namespace Barotrauma if (moveCam && needsAir) { - if (pressureProtection < 80.0f && + if (pressureProtection < 80.0f && (AnimController.CurrentHull == null || AnimController.CurrentHull.LethalPressure > 50.0f)) { float pressure = AnimController.CurrentHull == null ? 100.0f : AnimController.CurrentHull.LethalPressure; @@ -1197,69 +1378,7 @@ namespace Barotrauma } } - if (!LockHands) - { - //find the closest item if selectkey has been hit, or if the Character is being - //controlled by the player (in order to highlight it) - - if (findClosestTimer <= 0.0f || Screen.Selected == GameMain.EditMapScreen) - { - closestCharacter = FindClosestCharacter(mouseSimPos); - if (closestCharacter != null && closestCharacter.info==null) - { - closestCharacter = null; - } - - float closestItemDist = 0.0f; - closestItem = FindClosestItem(mouseSimPos, out closestItemDist); - - if (closestCharacter != null && closestItem != null) - { - if (Vector2.DistanceSquared(closestCharacter.SimPosition, mouseSimPos) < ConvertUnits.ToSimUnits(closestItemDist)*ConvertUnits.ToSimUnits(closestItemDist)) - { - if (selectedConstruction != closestItem) closestItem = null; - } - else - { - closestCharacter = null; - } - } - - findClosestTimer = 0.1f; - } - else - { - findClosestTimer -= deltaTime; - } - - if (selectedCharacter == null && closestItem != null) - { - closestItem.IsHighlighted = true; - if (!LockHands && closestItem.Pick(this)) - { - - } - } - - if (IsKeyHit(InputType.Select)) - { - if (selectedCharacter != null) - { - DeselectCharacter(); - } - else if (closestCharacter != null && closestCharacter.IsHumanoid && closestCharacter.CanBeSelected) - { - SelectCharacter(closestCharacter); - } - } - } - else - { - if (selectedCharacter != null) DeselectCharacter(); - selectedConstruction = null; - closestItem = null; - closestCharacter = null; - } + DoInteractionUpdate(deltaTime, mouseSimPos); DisableControls = false; } @@ -1424,78 +1543,18 @@ namespace Barotrauma { ControlLocalPlayer(deltaTime, cam); } + else + { + Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition); + DoInteractionUpdate(deltaTime, mouseSimPos); + } Control(deltaTime, cam); - if (selectedConstruction != null && !selectedConstruction.IsInPickRange(WorldPosition)) + if (selectedConstruction != null && !CanInteractWith(selectedConstruction)) { selectedConstruction = null; } - - if (controlled != this && (!(this is AICharacter) || IsRemotePlayer)) - { - if (!LockHands) - { - Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition); - - if (IsKeyHit(InputType.Select) && GameMain.Server==null) - { - closestCharacter = FindClosestCharacter(mouseSimPos); - if (closestCharacter != null && closestCharacter.info == null) - { - closestCharacter = null; - } - - float closestItemDist = 0.0f; - closestItem = FindClosestItem(mouseSimPos, out closestItemDist); - - if (closestCharacter != null && closestItem != null) - { - if (closestItem != null) closestItemDist = (closestItem.Position - AnimController.Collider.Position).Length(); - if (Vector2.Distance(closestCharacter.SimPosition, mouseSimPos) < ConvertUnits.ToSimUnits(closestItemDist)) - { - if (selectedConstruction != closestItem) closestItem = null; - } - else - { - closestCharacter = null; - } - } - } - - if (selectedCharacter == null && closestItem != null) - { - //DebugConsole.NewMessage(closestItem.ToString(), Color.Yellow); - //closestItem.IsHighlighted = true; - if (!LockHands && closestItem.Pick(this)) - { - if (AnimController.Anim == AnimController.Animation.Climbing) - { - //DebugConsole.NewMessage("ladder woo",Color.Lime); - } - } - } - - if (IsKeyHit(InputType.Select)) - { - if (selectedCharacter != null) - { - DeselectCharacter(); - } - else if (closestCharacter != null && closestCharacter.IsHumanoid && closestCharacter.CanBeSelected) - { - SelectCharacter(closestCharacter); - } - } - } - else - { - if (selectedCharacter != null) DeselectCharacter(); - selectedConstruction = null; - closestItem = null; - closestCharacter = null; - } - } if (selectedCharacter != null && AnimController.Anim == AnimController.Animation.CPR) { @@ -1574,6 +1633,21 @@ namespace Barotrauma if (!Enabled) return; AnimController.Draw(spriteBatch); + + /*Console.WriteLine("Rotation: " + AnimController.Collider.Rotation); + + Vector2 dir = Vector2.Transform(Vector2.UnitY, Quaternion.CreateFromAxisAngle(Vector3.UnitZ, AnimController.Collider.Rotation)); + + Vector2 pos1 = Position + (dir * 20.0f); + Vector2 pos2 = Position - (dir * 60.0f); + + if (Submarine != null) + { + pos1 += Submarine.Position; + pos2 += Submarine.Position; + } + + GUI.DrawLine(spriteBatch, new Vector2(pos1.X, -pos1.Y), new Vector2(pos2.X, -(pos2.Y)), Color.Green);*/ } public void DrawHUD(SpriteBatch spriteBatch, Camera cam) @@ -1956,7 +2030,7 @@ namespace Barotrauma foreach (Character c in CharacterList) { - if (c.closestCharacter == this) c.closestCharacter = null; + if (c.focusedCharacter == this) c.focusedCharacter = null; if (c.selectedCharacter == this) c.selectedCharacter = null; } } diff --git a/Barotrauma/Source/Characters/CharacterHUD.cs b/Barotrauma/Source/Characters/CharacterHUD.cs index 4ee4f6230..0a81b0c3b 100644 --- a/Barotrauma/Source/Characters/CharacterHUD.cs +++ b/Barotrauma/Source/Characters/CharacterHUD.cs @@ -182,27 +182,27 @@ namespace Barotrauma if (cprButton.Visible) cprButton.Draw(spriteBatch); } - if (character.ClosestCharacter != null && character.ClosestCharacter.CanBeSelected) + if (character.FocusedCharacter != null && character.FocusedCharacter.CanBeSelected) { - Vector2 startPos = character.DrawPosition + (character.ClosestCharacter.DrawPosition - character.DrawPosition) * 0.7f; + Vector2 startPos = character.DrawPosition + (character.FocusedCharacter.DrawPosition - character.DrawPosition) * 0.7f; startPos = cam.WorldToScreen(startPos); Vector2 textPos = startPos; - textPos -= new Vector2(GUI.Font.MeasureString(character.ClosestCharacter.Info.Name).X / 2, 20); + textPos -= new Vector2(GUI.Font.MeasureString(character.FocusedCharacter.Info.Name).X / 2, 20); - GUI.DrawString(spriteBatch, textPos, character.ClosestCharacter.Info.Name, Color.White, Color.Black, 2); + GUI.DrawString(spriteBatch, textPos, character.FocusedCharacter.Info.Name, Color.White, Color.Black, 2); } - else if (character.SelectedCharacter == null && character.ClosestItem != null && character.SelectedConstruction == null) + else if (character.SelectedCharacter == null && character.FocusedItem != null && character.SelectedConstruction == null) { - var hudTexts = character.ClosestItem.GetHUDTexts(character); + var hudTexts = character.FocusedItem.GetHUDTexts(character); Vector2 startPos = new Vector2((int)(GameMain.GraphicsWidth / 2.0f), GameMain.GraphicsHeight); startPos.Y -= 50 + hudTexts.Count * 25; Vector2 textPos = startPos; - textPos -= new Vector2((int)GUI.Font.MeasureString(character.ClosestItem.Name).X / 2, 20); + textPos -= new Vector2((int)GUI.Font.MeasureString(character.FocusedItem.Name).X / 2, 20); - GUI.DrawString(spriteBatch, textPos, character.ClosestItem.Name, Color.White, Color.Black * 0.7f, 2); + GUI.DrawString(spriteBatch, textPos, character.FocusedItem.Name, Color.White, Color.Black * 0.7f, 2); textPos.Y += 30.0f; foreach (ColoredText coloredText in hudTexts) diff --git a/Barotrauma/Source/Characters/CharacterNetworking.cs b/Barotrauma/Source/Characters/CharacterNetworking.cs index 0f52f1c80..a33df8ed6 100644 --- a/Barotrauma/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/Source/Characters/CharacterNetworking.cs @@ -147,13 +147,13 @@ namespace Barotrauma var closestEntity = Entity.FindEntityByID(memInput[memInput.Count - 1].interact); if (closestEntity is Item) { - closestItem = (Item)closestEntity; - closestCharacter = null; + focusedItem = (Item)closestEntity; + focusedCharacter = null; } else if (closestEntity is Character) { - closestCharacter = (Character)closestEntity; - closestItem = null; + focusedCharacter = (Character)closestEntity; + focusedItem = null; } memInput.RemoveAt(memInput.Count - 1); @@ -205,13 +205,13 @@ namespace Barotrauma NetInputMem newMem = new NetInputMem(); newMem.states = newInput; newMem.intAim = intAngle; - if (closestItem != null) + if (focusedItem != null) { - newMem.interact = closestItem.ID; + newMem.interact = focusedItem.ID; } - else if (closestCharacter != null) + else if (focusedCharacter != null) { - newMem.interact = closestCharacter.ID; + newMem.interact = focusedCharacter.ID; } memInput.Insert(0, newMem); diff --git a/Barotrauma/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs b/Barotrauma/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs index fbd40ca05..d052b6b5f 100644 --- a/Barotrauma/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs +++ b/Barotrauma/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs @@ -388,7 +388,7 @@ namespace Barotrauma.Tutorials while (!HasItem("Diving Mask") && !HasItem("Diving Suit")) { if (!divingMaskSelected && - Character.Controlled.ClosestItem != null && Character.Controlled.ClosestItem.Name == "Diving Suit") + Character.Controlled.FocusedItem != null && Character.Controlled.FocusedItem.Name == "Diving Suit") { infoBox = CreateInfoFrame("There can only be one item in each inventory slot, so you need to take off " + "the jumpsuit if you wish to wear a diving suit."); diff --git a/Barotrauma/Source/Items/Components/Holdable/Pickable.cs b/Barotrauma/Source/Items/Components/Holdable/Pickable.cs index 589dbd8b3..8fde5f9f5 100644 --- a/Barotrauma/Source/Items/Components/Holdable/Pickable.cs +++ b/Barotrauma/Source/Items/Components/Holdable/Pickable.cs @@ -105,9 +105,7 @@ namespace Barotrauma.Items.Components pickTimer = 0.0f; while (pickTimer < requiredTime && Screen.Selected != GameMain.EditMapScreen) { - if (picker.IsKeyDown(InputType.Aim) || - !item.IsInPickRange(picker.WorldPosition) || - picker.Stun > 0.0f || picker.IsDead) + if (picker.IsKeyDown(InputType.Aim) || !picker.CanInteractWith(item)) { StopPicking(picker); yield return CoroutineStatus.Success; diff --git a/Barotrauma/Source/Items/Components/Machines/Controller.cs b/Barotrauma/Source/Items/Components/Machines/Controller.cs index 82c4cb9d4..6a7abde17 100644 --- a/Barotrauma/Source/Items/Components/Machines/Controller.cs +++ b/Barotrauma/Source/Items/Components/Machines/Controller.cs @@ -77,10 +77,8 @@ namespace Barotrauma.Items.Components this.cam = cam; if (character == null - || character.IsDead - || character.Stun > 0.0f || character.SelectedConstruction != item - || Vector2.Distance(character.Position, item.Position) > item.PickDistance * 2.0f) + || !character.CanInteractWith(item)) { if (character != null) { @@ -150,7 +148,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character activator = null) { - if (character == null || activator != character || character.SelectedConstruction != item) + if (character == null || activator != character || character.SelectedConstruction != item || !character.CanInteractWith(item)) { character = null; return false; @@ -165,7 +163,7 @@ namespace Barotrauma.Items.Components public override void SecondaryUse(float deltaTime, Character character = null) { - if (this.character == null || this.character != character || this.character.SelectedConstruction != item) + if (this.character == null || this.character != character || this.character.SelectedConstruction != item || !character.CanInteractWith(item)) { character = null; return; diff --git a/Barotrauma/Source/Items/Components/StatusHUD.cs b/Barotrauma/Source/Items/Components/StatusHUD.cs index d4f2de7da..55bcf1e5f 100644 --- a/Barotrauma/Source/Items/Components/StatusHUD.cs +++ b/Barotrauma/Source/Items/Components/StatusHUD.cs @@ -28,9 +28,9 @@ namespace Barotrauma.Items.Components GUI.DrawRectangle(spriteBatch, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Green * 0.1f, true); - if (character.ClosestCharacter == null) return; + if (character.FocusedCharacter == null) return; - var target = character.ClosestCharacter; + var target = character.FocusedCharacter; Vector2 hudPos = GameMain.GameScreen.Cam.WorldToScreen(target.WorldPosition); hudPos += Vector2.UnitX * 50.0f; diff --git a/Barotrauma/Source/Items/Item.cs b/Barotrauma/Source/Items/Item.cs index 26f502ddc..952730137 100644 --- a/Barotrauma/Source/Items/Item.cs +++ b/Barotrauma/Source/Items/Item.cs @@ -136,9 +136,14 @@ namespace Barotrauma get { return prefab.sprite; } } - public float PickDistance + public float InteractDistance { - get { return prefab.PickDistance; } + get { return prefab.InteractDistance; } + } + + public float InteractPriority + { + get { return prefab.InteractPriority; } } public override Vector2 SimPosition @@ -919,8 +924,7 @@ namespace Barotrauma if (prefab.sprite != null) { - float depth = Sprite.Depth; - depth += (ID % 255) * 0.000001f; + float depth = GetDrawDepth(); if (body == null) { @@ -975,7 +979,7 @@ namespace Barotrauma if (IsSelected || isHighlighted) { GUI.DrawRectangle(spriteBatch, new Vector2(DrawPosition.X - rect.Width / 2, -(DrawPosition.Y+rect.Height/2)), new Vector2(rect.Width, rect.Height), Color.Green,false,0,(int)Math.Max((1.5f/GameScreen.Selected.Cam.Zoom),1.0f)); - + foreach (Rectangle t in prefab.Triggers) { Rectangle transformedTrigger = TransformTrigger(t); @@ -1304,77 +1308,11 @@ namespace Barotrauma yield return CoroutineStatus.Success; } - public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull = null, Item[] ignoredItems = null) + public float GetDrawDepth() { - float dist; - return FindPickable(position, pickPosition, hull, ignoredItems, out dist); - } + return Sprite.Depth + ((ID % 255) * 0.000001f); + } - /// Position of the Character doing the pick, only items that are close enough to this are checked - /// the item closest to pickPosition is returned - /// If a hull is specified, only items within that hull are checked - public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull, Item[] ignoredItems, out float distance) - { - float closestDist = 0.0f, dist; - Item closest = null; - - Vector2 displayPos = ConvertUnits.ToDisplayUnits(position); - Vector2 displayPickPos = ConvertUnits.ToDisplayUnits(pickPosition); - - distance = 1000.0f; - - foreach (Item item in ItemList) - { - if (ignoredItems != null && ignoredItems.Contains(item)) continue; - if (item.body != null && !item.body.Enabled) continue; - - if (item.PickDistance == 0.0f && !item.prefab.Triggers.Any()) continue; - - Pickable pickableComponent = item.GetComponent(); - if (pickableComponent != null && (pickableComponent.Picker != null && !pickableComponent.Picker.IsDead)) continue; - - float pickDist = Vector2.Distance(item.WorldPosition, displayPickPos); - - bool insideTrigger = false; - foreach (Rectangle trigger in item.prefab.Triggers) - { - Rectangle transformedTrigger = item.TransformTrigger(trigger, true); - - if (!Submarine.RectContains(transformedTrigger, displayPos)) continue; - - insideTrigger = true; - - Vector2 triggerCenter = new Vector2(transformedTrigger.Center.X, transformedTrigger.Y - transformedTrigger.Height / 2); - pickDist = Math.Min(Math.Abs(triggerCenter.X - displayPickPos.X), Math.Abs(triggerCenter.Y - displayPickPos.Y)); - } - - if (!insideTrigger && item.prefab.Triggers.Any()) continue; - - if (pickDist > item.PickDistance && item.PickDistance > 0.0f) continue; - - dist = item.Sprite.Depth * 10.0f + pickDist; - if (item.IsMouseOn(displayPickPos)) dist = dist * 0.1f; - - if (closest == null || dist < closestDist) - { - if (item.PickDistance > 0.0f && Vector2.Distance(displayPos, item.WorldPosition) > item.prefab.PickDistance) continue; - - if (!item.prefab.PickThroughWalls && Screen.Selected != GameMain.EditMapScreen && !insideTrigger) - { - Body body = Submarine.CheckVisibility(item.Submarine == null ? position : position - item.Submarine.SimPosition, item.SimPosition, true); - if (body != null && body.UserData as Item != item) continue; - } - - closestDist = dist; - closest = item; - - distance = pickDist; - } - } - - return closest; - } - public bool IsInsideTrigger(Vector2 worldPosition) { foreach (Rectangle trigger in prefab.Triggers) @@ -1387,26 +1325,19 @@ namespace Barotrauma return false; } - public bool IsInPickRange(Vector2 worldPosition) - { - if (IsInsideTrigger(worldPosition)) return true; - - return Vector2.Distance(WorldPosition, worldPosition) < PickDistance; - } - public bool CanClientAccess(Client c) { - return c != null && c.Character != null && c.Character.CanAccessItem(this); + return c != null && c.Character != null && c.Character.CanInteractWith(this); } - public bool Pick(Character picker, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceActionKey=false) + public bool TryInteract(Character picker, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceActionKey=false) { bool hasRequiredSkills = true; bool picked = false, selected = false; Skill requiredSkill = null; - + foreach (ItemComponent ic in components) { bool pickHit = false, selectHit = false; @@ -1434,7 +1365,6 @@ namespace Barotrauma } } - if (!pickHit && !selectHit) continue; Skill tempRequiredSkill; @@ -1444,7 +1374,7 @@ namespace Barotrauma bool showUiMsg = picker == Character.Controlled && Screen.Selected != GameMain.EditMapScreen; if (!ignoreRequiredItems && !ic.HasRequiredItems(picker, showUiMsg)) continue; - if ((ic.CanBePicked && pickHit && ic.Pick(picker)) || + if ((ic.CanBePicked && pickHit && ic.Pick(picker)) || (ic.CanBeSelected && selectHit && ic.Select(picker))) { picked = true; @@ -1466,22 +1396,22 @@ namespace Barotrauma if (picker.IsKeyHit(InputType.Select) || forceSelectKey) picker.SelectedConstruction = null; } else if (selected) - { + { picker.SelectedConstruction = this; } - - if (!hasRequiredSkills && Character.Controlled==picker && Screen.Selected != GameMain.EditMapScreen) + + if (!hasRequiredSkills && Character.Controlled == picker && Screen.Selected != GameMain.EditMapScreen) { GUI.AddMessage("Your skills may be insufficient to use the item!", Color.Red, 5.0f); if (requiredSkill != null) { - GUI.AddMessage("("+requiredSkill.Name+" level "+requiredSkill.Level+" required)", Color.Red, 5.0f); + GUI.AddMessage("(" + requiredSkill.Name + " level " + requiredSkill.Level + " required)", Color.Red, 5.0f); } } - if (Container!=null) Container.RemoveContained(this); + if (Container != null) Container.RemoveContained(this); - return true; + return true; } @@ -1853,7 +1783,7 @@ namespace Barotrauma int requirementIndex = FixRequirements.Count == 1 ? 0 : msg.ReadRangedInteger(0, FixRequirements.Count - 1); - if (c.Character == null || !c.Character.CanAccessItem(this)) return; + if (c.Character == null || !c.Character.CanInteractWith(this)) return; if (!FixRequirements[requirementIndex].CanBeFixed(c.Character)) return; FixRequirements[requirementIndex].Fixed = true; @@ -1866,7 +1796,7 @@ namespace Barotrauma break; case NetEntityEvent.Type.ApplyStatusEffect: - if (c.Character == null || !c.Character.CanAccessItem(this)) return; + if (c.Character == null || !c.Character.CanInteractWith(this)) return; ApplyStatusEffects(ActionType.OnUse, (float)Timing.Step, c.Character); diff --git a/Barotrauma/Source/Items/ItemPrefab.cs b/Barotrauma/Source/Items/ItemPrefab.cs index 8a154b5aa..2c952fdd2 100644 --- a/Barotrauma/Source/Items/ItemPrefab.cs +++ b/Barotrauma/Source/Items/ItemPrefab.cs @@ -35,9 +35,11 @@ namespace Barotrauma protected Vector2 size; //how close the Character has to be to the item to pick it up - private float pickDistance; + private float interactDistance; + // this can be used to allow items which are behind other items tp + private float interactPriority; - private bool pickThroughWalls; + private bool interactThroughWalls; //an area next to the construction //the construction can be Activated() by a Character inside the area @@ -80,14 +82,19 @@ namespace Barotrauma private set; } - public float PickDistance + public float InteractDistance { - get { return pickDistance; } + get { return interactDistance; } } - public bool PickThroughWalls + public float InteractPriority { - get { return pickThroughWalls; } + get { return interactPriority; } + } + + public bool InteractThroughWalls + { + get { return interactThroughWalls; } } public override bool IsLinkable @@ -268,9 +275,10 @@ namespace Barotrauma Description = ToolBox.GetAttributeString(element, "description", ""); - pickThroughWalls = ToolBox.GetAttributeBool(element, "pickthroughwalls", false); - pickDistance = ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f); - + interactThroughWalls = ToolBox.GetAttributeBool(element, "interactthroughwalls", false); + interactDistance = ToolBox.GetAttributeFloat(element, "interactdistance", 120.0f); // Default to 120 as the new item picking method is tuned to this number + interactPriority = ToolBox.GetAttributeFloat(element, "interactpriority", 0.0f); + isLinkable = ToolBox.GetAttributeBool(element, "linkable", false); resizeHorizontal = ToolBox.GetAttributeBool(element, "resizehorizontal", false); diff --git a/Barotrauma/Source/Map/Lights/LightManager.cs b/Barotrauma/Source/Map/Lights/LightManager.cs index 44355c81b..872394927 100644 --- a/Barotrauma/Source/Map/Lights/LightManager.cs +++ b/Barotrauma/Source/Map/Lights/LightManager.cs @@ -164,15 +164,15 @@ namespace Barotrauma.Lights if (Character.Controlled != null) { - if (Character.Controlled.ClosestItem != null) + if (Character.Controlled.FocusedItem != null) { - Character.Controlled.ClosestItem.IsHighlighted = true; - Character.Controlled.ClosestItem.Draw(spriteBatch, false, true); - Character.Controlled.ClosestItem.IsHighlighted = true; + Character.Controlled.FocusedItem.IsHighlighted = true; + Character.Controlled.FocusedItem.Draw(spriteBatch, false, true); + Character.Controlled.FocusedItem.IsHighlighted = true; } - else if (Character.Controlled.ClosestCharacter != null) + else if (Character.Controlled.FocusedCharacter != null) { - Character.Controlled.ClosestCharacter.Draw(spriteBatch); + Character.Controlled.FocusedCharacter.Draw(spriteBatch); } } diff --git a/Barotrauma/Source/Map/MapEntity.cs b/Barotrauma/Source/Map/MapEntity.cs index 2727c4054..240c0d455 100644 --- a/Barotrauma/Source/Map/MapEntity.cs +++ b/Barotrauma/Source/Map/MapEntity.cs @@ -110,6 +110,14 @@ namespace Barotrauma get { return Submarine == null ? rect : new Rectangle((int)(Submarine.Position.X + rect.X), (int)(Submarine.Position.Y + rect.Y), rect.Width, rect.Height); } } + public Rectangle InteractionRect + { + get + { + return WorldRect; + } + } + public virtual Sprite Sprite { get { return null; } @@ -231,7 +239,7 @@ namespace Barotrauma public virtual bool IsMouseOn(Vector2 position) { - return (Submarine.RectContains(WorldRect, position)); + return (Submarine.RectContains(InteractionRect, position)); } public virtual MapEntity Clone() diff --git a/Barotrauma/Source/Screens/EditMapScreen.cs b/Barotrauma/Source/Screens/EditMapScreen.cs index fe7a802e6..ec260836c 100644 --- a/Barotrauma/Source/Screens/EditMapScreen.cs +++ b/Barotrauma/Source/Screens/EditMapScreen.cs @@ -1072,7 +1072,7 @@ namespace Barotrauma dummyCharacter.SelectedConstruction.UpdateHUD(cam, dummyCharacter); } - if (PlayerInput.KeyHit(InputType.Select) && dummyCharacter.ClosestItem != dummyCharacter.SelectedConstruction) dummyCharacter.SelectedConstruction = null; + if (PlayerInput.KeyHit(InputType.Select) && dummyCharacter.FocusedItem != dummyCharacter.SelectedConstruction) dummyCharacter.SelectedConstruction = null; } CharacterHUD.Update((float)deltaTime, dummyCharacter); diff --git a/Barotrauma/Source/Screens/GameScreen.cs b/Barotrauma/Source/Screens/GameScreen.cs index d35cddc8c..8c98252ee 100644 --- a/Barotrauma/Source/Screens/GameScreen.cs +++ b/Barotrauma/Source/Screens/GameScreen.cs @@ -90,12 +90,9 @@ namespace Barotrauma public override void AddToGUIUpdateList() { - if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) + if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null && Character.Controlled.CanInteractWith(Character.Controlled.SelectedConstruction)) { - if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) - { - Character.Controlled.SelectedConstruction.AddToGUIUpdateList(); - } + Character.Controlled.SelectedConstruction.AddToGUIUpdateList(); } if (GameMain.GameSession != null) GameMain.GameSession.AddToGUIUpdateList(); @@ -137,12 +134,9 @@ namespace Barotrauma if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime); - if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) + if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null && Character.Controlled.CanInteractWith(Character.Controlled.SelectedConstruction)) { - if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) - { - Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled); - } + Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled); } Character.UpdateAll(cam, (float)deltaTime); @@ -199,12 +193,9 @@ namespace Barotrauma spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); - if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) + if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null && Character.Controlled.CanInteractWith(Character.Controlled.SelectedConstruction)) { - if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) - { - Character.Controlled.SelectedConstruction.DrawHUD(spriteBatch, cam, Character.Controlled); - } + Character.Controlled.SelectedConstruction.DrawHUD(spriteBatch, cam, Character.Controlled); } if (Character.Controlled != null && cam != null) Character.Controlled.DrawHUD(spriteBatch, cam);