Track LocalMods as part of monolith
This commit is contained in:
+154
@@ -0,0 +1,154 @@
|
||||
-- Consent Required API
|
||||
-- Any Lua script can access this API by adding this line:
|
||||
-- local Api = require "com.github.cintique.ConsentRequired.Api"
|
||||
local Environment = require("ConsentRequiredExtended.Util.Environment")
|
||||
local Barotrauma = require("ConsentRequiredExtended.Util.Barotrauma")
|
||||
|
||||
local _ENV = Environment.PrepareEnvironment(_ENV)
|
||||
|
||||
-- Table of identifiers (strings) of items that when used
|
||||
-- as a treatment on an NPC from a different team,
|
||||
-- causes that NPC (and their allies) to become hostile
|
||||
-- towards the player.
|
||||
local affectedItems = {}
|
||||
|
||||
---Adds an item (by identifier string) to `affectedItems`.
|
||||
---@param identifier string
|
||||
function AddAffectedItem(identifier)
|
||||
table.insert(affectedItems, identifier)
|
||||
end
|
||||
|
||||
LuaUserData.MakeFieldAccessible(Descriptors["Barotrauma.AbandonedOutpostMission"], "requireRescue")
|
||||
|
||||
-- Character type doesn't have tags we can assign a custom "rescuetarget" tag to
|
||||
-- So instead we just hold characters which need rescue in a table and compare their entity IDs
|
||||
-- This table is only resfreshed on roundstart
|
||||
local rescuetargets = {}
|
||||
|
||||
---Returns a boolean indicating whether a given item is affected or not.
|
||||
---@param identifier string The identifier of the item that we are testing.
|
||||
---@return boolean isAffected True if the item is affected, false otherwise.
|
||||
function IsItemAffected(identifier)
|
||||
for _, item in pairs(affectedItems) do
|
||||
if item == identifier or HF.StartsWith(identifier, item) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
LuaUserData.MakeMethodAccessible(Descriptors["Barotrauma.HumanAIController"], "RespondToAttack")
|
||||
|
||||
local ADD_ATTACKER_DAMAGE = 130 -- Heelge: this used to max out negative rep gain, now only around 4 negative rep, any less negative rep is too forgiving.
|
||||
|
||||
---@param aiChar Barotrauma_Character The AI character to be made hostile.
|
||||
---@param instigator Barotrauma_Character The character to be the target of the AI's wrath.
|
||||
function makeHostile(aiChar, instigator)
|
||||
--There is a bit of code which causes attackresults without afflictions to get discarded if some other affliction happens whichin a second
|
||||
--That one was "fun" to debug
|
||||
--aiChar.AIController.OnAttacked(instigator, Barotrauma.AttackResult.NewAttackResultFromDamage(ADD_ATTACKER_DAMAGE))
|
||||
Timer.Wait(function()
|
||||
aiChar.AIController.RespondToAttack(instigator, Barotrauma.AttackResult.NewAttackResultFromDamage(ADD_ATTACKER_DAMAGE))
|
||||
aiChar.AddAttacker(instigator, ADD_ATTACKER_DAMAGE)
|
||||
end, 500)
|
||||
-- as this bypasses usual npc reaction timer add a bit of delay to make it not instant
|
||||
end
|
||||
|
||||
---@param char1 Barotrauma_Character Character one.
|
||||
---@param char2 Barotrauma_Character Character two.
|
||||
---@return boolean charactersAreOnSameTeam True if characters one & two are on the same team, false otherwise.
|
||||
function isOnSameTeam(char1, char2)
|
||||
local team1 = char1.TeamID
|
||||
local team2 = char2.TeamID
|
||||
return team1 == team2
|
||||
end
|
||||
|
||||
---Updates current rescue targets list, separate so we dont cycle thru all missions every time we apply item to chacter. Use IsRescueTarget(target) after this.
|
||||
function UpdateRescueTargets()
|
||||
rescuetargets = {}
|
||||
for mission in Game.GameSession.Missions do
|
||||
if LuaUserData.IsTargetType(mission.Prefab.MissionClass, "Barotrauma.AbandonedOutpostMission") then
|
||||
for character in mission.requireRescue do
|
||||
rescuetargets[character.ID] = character
|
||||
--table.insert(rescuetargets, character)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print('rescue targets =')
|
||||
-- for char in rescuetargets do print(char.Name) end
|
||||
end
|
||||
|
||||
---@param target Barotrauma_Character The character we want to confirm as being rescued
|
||||
---@return boolean consent True if target is rescue mission target, false otherwise
|
||||
function IsRescueTarget(target)
|
||||
-- for char in rescuetargets do
|
||||
-- if target.ID == char.ID then return true end
|
||||
-- end
|
||||
if rescuetargets[target.ID] ~= nil then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---@param user Barotrauma_Character The character who desires consent.
|
||||
---@param target Barotrauma_Character The character who gives consent
|
||||
---@return boolean consent True if consent is given, false otherwise.
|
||||
function hasConsent(user, target)
|
||||
return isOnSameTeam(user, target) or target.IsEscorted or IsRescueTarget(target) -- No longer needs to be shared.
|
||||
end
|
||||
|
||||
---@param aiChar Barotrauma_Character The (AI but not necessarily) character whose sight is being tested.
|
||||
---@param target Barotrauma_Character The character to be seen.
|
||||
---@return boolean aiCanSeeTarget True if the AI can see the target character.
|
||||
function canAiSeeTarget(aiChar, target)
|
||||
-- I'll just use what Barotrauma uses for witness line of sight
|
||||
local aiVisibleHulls = aiChar.GetVisibleHulls()
|
||||
local targetCurrentHull = target.CurrentHull
|
||||
for _, visibleHull in pairs(aiVisibleHulls) do
|
||||
if targetCurrentHull == visibleHull then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---@param user Barotrauma_Character The character of the instigator being witnessed.
|
||||
---@param victim Barotrauma_Character The character of the victim of the crime being witnessed.
|
||||
---@return Barotrauma_Character[] Characters that have witnessed the crime.
|
||||
function getWitnessesToCrime(user, victim)
|
||||
local witnesses = {}
|
||||
for _, char in pairs(Character.CharacterList) do
|
||||
if
|
||||
not char.Removed
|
||||
and not char.IsUnconscious
|
||||
and char.IsBot
|
||||
and char.IsHuman
|
||||
and isOnSameTeam(char, victim)
|
||||
then
|
||||
local isWitnessingUser = canAiSeeTarget(char, user)
|
||||
if isWitnessingUser then
|
||||
table.insert(witnesses, char)
|
||||
end
|
||||
end
|
||||
end
|
||||
return witnesses
|
||||
end
|
||||
|
||||
---@param user Barotrauma_Character The character that is applying the affected item.
|
||||
---@param target Barotrauma_Character The character of the target of the affected item's application.
|
||||
function onAffectedItemApplied(user, target)
|
||||
if not hasConsent(user, target) and target.IsBot and target.IsHuman then
|
||||
if not target.IsIncapacitated and target.Stun <= 10 then
|
||||
makeHostile(target, user)
|
||||
else
|
||||
-- Vanilla Barotrauma Human AI doesn't care what you do to their unconscious teammates, even shooting them in the head
|
||||
-- Let's fix that for this particular case of mistreatment
|
||||
local witnesses = getWitnessesToCrime(user, target)
|
||||
for _, witness in pairs(witnesses) do
|
||||
makeHostile(witness, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Environment.Export(_ENV)
|
||||
@@ -0,0 +1,67 @@
|
||||
-- User edited configuration file.
|
||||
local Environment = require("ConsentRequiredExtended.Util.Environment")
|
||||
|
||||
local _ENV = Environment.PrepareEnvironment(_ENV)
|
||||
|
||||
--------- Start editing here ---------
|
||||
|
||||
AffectedItems = {
|
||||
-- Neurotrauma
|
||||
-- "healthscanner", --健康扫描仪 -- whats a tiny bit of radiation damage between friends?
|
||||
"bloodanalyzer", --血液分析仪
|
||||
"opium", --药用鸦片
|
||||
"antidama1", --吗啡
|
||||
"antidama2", --芬太尼
|
||||
"antibleeding3", --抗生素凝膠
|
||||
"propofol", -- 异丙酚
|
||||
"mannitol", -- 甘露醇
|
||||
"pressuremeds", -- 压力药物
|
||||
"meth",
|
||||
"needle",
|
||||
"adrenaline",
|
||||
"multiscalpel", -- 多功能手术刀
|
||||
"advscalpel", -- 手术刀
|
||||
"advhemostat", -- 止血钳
|
||||
"advretractors", -- 皮肤牵引器
|
||||
"tweezers", -- 镊子
|
||||
"surgicaldrill", -- 骨钻
|
||||
"surgerysaw", -- 手术锯
|
||||
"organscalpel_liver", -- 器官切割刀:肝脏
|
||||
"organscalpel_lungs", -- 器官切割刀:肺
|
||||
"organscalpel_kidneys", -- 器官切割刀:肾脏
|
||||
"organscalpel_heart", -- 器官切割刀:心脏
|
||||
"organscalpel_brain", -- 器官切割刀:大脑
|
||||
"emptybloodpack", -- 空血袋
|
||||
"bloodpack",
|
||||
"alienblood", -- 异星血浆
|
||||
"tourniquet", -- 止血带
|
||||
"defibrillator", -- 手动除颤器
|
||||
"aed", -- 智能除颤器
|
||||
"bvm", -- 人工呼吸器
|
||||
"antibiotics", -- 广谱抗生素
|
||||
"sulphuricacid", -- 硫酸
|
||||
"divingknife", -- 潜水刀
|
||||
"divingknifedementonite", -- 攝魂潛水刀
|
||||
"divingknifehardened", -- 硬化潛水刀
|
||||
"crowbar", -- 潜水刀
|
||||
"crowbardementonite", -- 攝魂撬棍
|
||||
"crowbarhardened", -- 硬化撬棍
|
||||
"stasisbag", -- 冷藏袋
|
||||
"autocpr", -- 全自动CPR
|
||||
-- NeuroEyes
|
||||
"organscalpel_eyes", -- 器官切割刀:眼睛
|
||||
-- blahaj 布罗艾鲨鱼
|
||||
-- "blahaj", -- 布罗艾鲨鱼 -- Blahaj never hurt anyone
|
||||
-- "blahajplus", -- 大鲨鲨
|
||||
"blahajplusplus", -- 超大鲨鲨
|
||||
-- Pharmacy 制药大师
|
||||
"custompill", -- 自制药丸
|
||||
"custompill_horsepill", -- 大药丸
|
||||
"custompill_tablets", -- 药片
|
||||
-- vanilla 原版
|
||||
"toyhammer", -- 玩具锤子
|
||||
}
|
||||
|
||||
--------- Stop editing here ---------
|
||||
|
||||
return Environment.Export(_ENV)
|
||||
@@ -0,0 +1,40 @@
|
||||
-- Do not take my blood or organs without my consent, thanks.
|
||||
-- Causes AI to get angry at you if you use certain medical items on them.
|
||||
-- These items are those related to organ and blood removal.
|
||||
-- This mod is meant to be accompanied by Neurotrauma, and aims to
|
||||
-- resolve the issue of being freely able to steal blood/organs from
|
||||
-- neutral NPCs (e.g. outposts, VIPs) without them getting mad at you.
|
||||
local Api = require("ConsentRequiredExtended.Api")
|
||||
local OnItemApplied = require("ConsentRequiredExtended.OnItemApplied")
|
||||
local onMeleeWeaponHandleImpact = require("ConsentRequiredExtended.onMeleeWeaponHandleImpact")
|
||||
local onHandleProjectileCollision = require("ConsentRequiredExtended.onHandleProjectileCollision")
|
||||
local Config = require("ConsentRequiredExtended.Config")
|
||||
|
||||
local LUA_EVENT_ITEM_APPLYTREATMENT = "item.ApplyTreatment"
|
||||
local HOOK_NAME_ITEM_APPLYTREATMENT = "ConsentRequiredExtended.onItemApplyTreatment"
|
||||
|
||||
local LUA_EVENT_MELEEWEAPON_HANDLEIMPACT = "meleeWeapon.handleImpact"
|
||||
local HOOK_NAME_MELEEWEAPON_HANDLEIMPACT = "ConsentRequiredExtended.onMeleeWeaponHandleImpact"
|
||||
|
||||
local LUA_EVENT_ROUNDSTART = "roundStart"
|
||||
local HOOK_NAME_UPDATE_RESCUETARGETS = "ConsentRequiredExtended.onUpdateRescueTargets"
|
||||
|
||||
-- Set up affected items from config.
|
||||
for _, affectedItem in pairs(Config.AffectedItems) do
|
||||
Api.AddAffectedItem(affectedItem)
|
||||
end
|
||||
|
||||
Hook.Add(LUA_EVENT_ITEM_APPLYTREATMENT, HOOK_NAME_ITEM_APPLYTREATMENT, OnItemApplied)
|
||||
|
||||
-- damn meleeWeapon
|
||||
Hook.Add(LUA_EVENT_MELEEWEAPON_HANDLEIMPACT, HOOK_NAME_MELEEWEAPON_HANDLEIMPACT, onMeleeWeaponHandleImpact)
|
||||
|
||||
Hook.Add(LUA_EVENT_ROUNDSTART, HOOK_NAME_UPDATE_RESCUETARGETS, Api.UpdateRescueTargets)
|
||||
|
||||
Hook.Patch(
|
||||
"ConsentRequiredExtended.onHandleProjectileCollision",
|
||||
"Barotrauma.Items.Components.Projectile",
|
||||
"HandleProjectileCollision",
|
||||
onHandleProjectileCollision,
|
||||
Hook.HookMethodType.After
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
local Api = require("ConsentRequiredExtended.Api")
|
||||
|
||||
local function isItemAffected(identifier)
|
||||
return Api.IsItemAffected(identifier)
|
||||
end
|
||||
|
||||
---@param item Barotrauma_Item Item being applied.
|
||||
---@param user Barotrauma_Character The character that is applying the item.
|
||||
---@param target Barotrauma_Character The character of the target of the item's application.
|
||||
local function OnItemApplied(item, user, target)
|
||||
if not NTConfig.Get("NTCRE_ConsentRequiredExtra", true) then
|
||||
return
|
||||
end
|
||||
local itemIdentifier = item.Prefab.Identifier.Value
|
||||
if isItemAffected(itemIdentifier) then
|
||||
Api.onAffectedItemApplied(user, target)
|
||||
end
|
||||
end
|
||||
|
||||
return OnItemApplied
|
||||
@@ -0,0 +1,90 @@
|
||||
-- Functions for interfacing with Barotrauma.
|
||||
|
||||
local Environment = require 'ConsentRequiredExtended.Util.Environment'
|
||||
local _ENV = Environment.PrepareEnvironment(_ENV)
|
||||
|
||||
-- local Clr = require 'ConsentRequiredExtended.Util.Clr'
|
||||
-- local UserData = require 'ConsentRequiredExtended.Util.UserData'
|
||||
|
||||
---Functions related to working with Barotrauma.AttackResult.
|
||||
AttackResult = {}
|
||||
|
||||
---Initialise AttackResults.
|
||||
-- local function Init_AttackResult()
|
||||
-- -- Registrations.
|
||||
-- UserData.RegisterStandardType("System.Reflection.FieldInfo")
|
||||
|
||||
-- -- Construct a List<Affliction> generic type.
|
||||
-- local afflictionsListClrType = Clr.CreateConstructedGenericType("System.Collections.Generic.List`1", "Barotrauma.Affliction")
|
||||
-- local attackResultAfflictionsField = Clr.GetRawClrType("Barotrauma.AttackResult").GetField("Afflictions")
|
||||
|
||||
-- ---Instantiates a new AttackResult with damage and empty afflictions.
|
||||
-- ---@param damage number An amount of damage.
|
||||
-- function AttackResult.NewAttackResultFromDamage(damage)
|
||||
-- -- Instantiate a new AttackResult.
|
||||
-- local attackResult = _G.AttackResult(damage, nil)
|
||||
|
||||
-- -- Instantiate an empty List<Afflictions> (this is to prevent NREs),
|
||||
-- -- and set it to attackResult.Afflictions. This is a readonly field,
|
||||
-- -- hence the use of reflection.
|
||||
-- local afflictionsList = UserData.FromClrType({}, afflictionsListClrType)
|
||||
-- attackResultAfflictionsField.SetValue(attackResult, afflictionsList)
|
||||
|
||||
-- return attackResult
|
||||
-- end
|
||||
-- end
|
||||
|
||||
---Initialise AttackResults without needing to register system.type and reflections
|
||||
local function Init_AttackResult()
|
||||
-- Registrations.
|
||||
LuaUserData.MakePropertyAccessible(Descriptors['Barotrauma.AttackResult'], 'Damage')
|
||||
|
||||
---Instantiates a new AttackResult with damage and empty afflictions.
|
||||
---@param damage number An amount of damage.
|
||||
function AttackResult.NewAttackResultFromDamage(damage)
|
||||
-- I have not noticed any NREs from affliction list being null
|
||||
-- but just in case here is version which intializes with empty list
|
||||
-- Also uncomment MakePropertyAccessible Damage above
|
||||
local attackResult = _G.AttackResult({}, nil, {})
|
||||
attackResult.Damage = damage
|
||||
|
||||
--local attackResult = _G.AttackResult(damage)
|
||||
|
||||
return attackResult
|
||||
end
|
||||
end
|
||||
|
||||
---Runs at start-up, handles registrations, etc.
|
||||
function Init()
|
||||
Init_AttackResult()
|
||||
end
|
||||
|
||||
function Test()
|
||||
local errors = {}
|
||||
local function AssertEquals(testDescription, expected, got)
|
||||
if expected ~= got then
|
||||
local errorString = string.format(
|
||||
"Test Error: %s\n\texpected = %s\n\tgot = %s",
|
||||
testDescription,
|
||||
tostring(expected),
|
||||
tostring(got)
|
||||
)
|
||||
table.insert(errors, errorString)
|
||||
end
|
||||
end
|
||||
local atkRes = AttackResult.NewAttackResultFromDamage(10)
|
||||
AssertEquals("atkRes.Damage", 10, atkRes.Damage)
|
||||
AssertEquals("atkRes.Afflictions is null", true, atkRes.Afflictions ~= nil)
|
||||
AssertEquals("#atkRes.Afflictions is non-zero", 0, #atkRes.Afflictions)
|
||||
|
||||
if #errors == 0 then
|
||||
print("Tests successful")
|
||||
else
|
||||
for _, err in pairs(errors) do
|
||||
print(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Init()
|
||||
return Environment.Export(_ENV)
|
||||
@@ -0,0 +1,74 @@
|
||||
-- Functions for working with CLR types.
|
||||
|
||||
local Environment = require 'ConsentRequiredExtended.Util.Environment'
|
||||
local _ENV = Environment.PrepareEnvironment(_ENV)
|
||||
|
||||
local UserData = require 'ConsentRequiredExtended.Util.UserData'
|
||||
|
||||
---Construct ClrType wrapper table for CLR types.
|
||||
---@param underlyingType userdata The underlying type (CLR type: System.Type).
|
||||
---@return ClrType Wrapper table for working with CLR types.
|
||||
local function New(underlyingType)
|
||||
---@class ClrType
|
||||
local clrType = {}
|
||||
|
||||
---Instantiate an object for the given CLR type.
|
||||
---@return any An instance of the CLR type. Actual Lua type depends on MoonSharp conversions.
|
||||
function clrType:Instantiate()
|
||||
-- TODO: Implement args.
|
||||
return underlyingType.Assembly.CreateInstance(underlyingType.FullName)
|
||||
end
|
||||
|
||||
---Get the underlying type as a raw CLR type object.
|
||||
---@return userdata The raw underlying type (CLR type: System.Type).
|
||||
function clrType:GetUnderlyingType()
|
||||
return underlyingType
|
||||
end
|
||||
|
||||
---Get the full name of the CLR type.
|
||||
---@return string The full name of the type.
|
||||
function clrType:GetFullName()
|
||||
return underlyingType.FullName
|
||||
end
|
||||
|
||||
return clrType
|
||||
end
|
||||
|
||||
---Create a constructed generic type.
|
||||
---@param genericTypeName string The name of the generic type to construct and register.
|
||||
---@vararg string
|
||||
---@return ClrType The constructed generic type.
|
||||
function CreateConstructedGenericType(genericTypeName, ...)
|
||||
local genericTypeArgumentsString = table.pack(...)
|
||||
|
||||
local genericTypeArgumentsType = {}
|
||||
for _, typeString in pairs(genericTypeArgumentsString) do
|
||||
table.insert(genericTypeArgumentsType, GetRawClrType(typeString))
|
||||
end
|
||||
|
||||
local genericTypeDefinition = GetRawClrType(genericTypeName)
|
||||
local constructedGenericType = genericTypeDefinition.MakeGenericType(table.unpack(genericTypeArgumentsType))
|
||||
return New(constructedGenericType)
|
||||
end
|
||||
|
||||
---Get a System.Type object from a type name.
|
||||
---@param typeName string Name of the type.
|
||||
---@return userdata The type object (CLR type: System.Type).
|
||||
function GetRawClrType(typeName)
|
||||
return LuaUserData.GetType(typeName)
|
||||
end
|
||||
|
||||
---Get a ClrType instance wrapping a Type object that matches the type name.
|
||||
---@param typeName string Name of the type.
|
||||
---@return ClrType The CLR type.
|
||||
function GetClrType(typeName)
|
||||
return New(GetRawClrType(typeName))
|
||||
end
|
||||
|
||||
local function Init()
|
||||
UserData.RegisterStandardType("System.Type")
|
||||
UserData.RegisterStandardType("System.Reflection.RuntimeAssembly")
|
||||
end
|
||||
|
||||
Init()
|
||||
return Environment.Export(_ENV)
|
||||
@@ -0,0 +1,32 @@
|
||||
-- Functions for managing the mod's environment.
|
||||
|
||||
---Isolate a function or module's environment from Global.
|
||||
---@param env table The _ENV table.
|
||||
local function prepareEnvironment(env)
|
||||
return setmetatable(
|
||||
{},
|
||||
{
|
||||
__index = _G,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
local _ENV = prepareEnvironment(_ENV)
|
||||
|
||||
PrepareEnvironment = prepareEnvironment
|
||||
|
||||
---Create an empty table whose metatable indexes non-local variables declared within
|
||||
---a function/module's environment, and is immutable to any changes.
|
||||
---@param env table The _ENV table.
|
||||
---@return table Empty table that interfaces with _ENV.
|
||||
function Export(env)
|
||||
return setmetatable(
|
||||
{},
|
||||
{
|
||||
__index = function(t, k) return env[k] end,
|
||||
__newindex = function() error("Attempted to modify a protected table.") end
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
return Export(_ENV)
|
||||
@@ -0,0 +1,35 @@
|
||||
-- Functions for creating userdata.
|
||||
|
||||
local Environment = require 'ConsentRequiredExtended.Util.Environment'
|
||||
local _ENV = Environment.PrepareEnvironment(_ENV)
|
||||
|
||||
---Create a userdata that references the type in a static context.
|
||||
---@param clrTypeName string The name of the type to point to.
|
||||
---@return userdata A userdata that references the type in a static context.
|
||||
function FromStringStatic(clrTypeName)
|
||||
LuaUserData.CreateStatic(clrTypeName)
|
||||
end
|
||||
|
||||
---Create a userdata that references the type described by a ClrType in a static context.
|
||||
---@param clrType ClrType ClrType that describes the type being referenced.
|
||||
---@return userdata A userdata that references the type in a static context.
|
||||
function FromClrTypeStatic(clrType)
|
||||
return FromStringStatic(clrType:GetFullName())
|
||||
end
|
||||
|
||||
---Create a userdata that references an instance of a CLR type with conversion.
|
||||
---@param value any A Lua value to convert to a CLR object of the given type and wrap up in a userdata.
|
||||
---@param clrType ClrType The CLR type to instantiate and wrap in the userdata.
|
||||
---@return userdata A userdata that references the an instance of the CLR type.
|
||||
function FromClrType(value, clrType)
|
||||
return LuaUserData.CreateUserDataFromType(value, clrType:GetUnderlyingType())
|
||||
end
|
||||
|
||||
---Register standard types with MoonSharp. For generics use RegisterClrType.ConstructedGenericType.
|
||||
---@param typeName string Name of the type to register.
|
||||
function RegisterStandardType(typeName)
|
||||
local desc = LuaUserData.RegisterType(typeName)
|
||||
_G.Descriptors[typeName] = desc
|
||||
end
|
||||
|
||||
return Environment.Export(_ENV)
|
||||
@@ -0,0 +1,18 @@
|
||||
local SRC_NAMESPACE = "ConsentRequiredExtended."
|
||||
local MAIN = "Main"
|
||||
local LUA_EVENT_LOADED = "loaded"
|
||||
local HOOK_NAME_ON_LOADED = "ConsentRequiredExtended.onLoaded"
|
||||
|
||||
if Game.IsMultiplayer and CLIENT then return end
|
||||
|
||||
local function onLoaded()
|
||||
-- Only run client side if not multiplayer
|
||||
---@diagnostic disable-next-line: undefined-global
|
||||
-- if Game.IsMultiplayer and CLIENT then return end
|
||||
|
||||
local requireStr = SRC_NAMESPACE .. MAIN
|
||||
|
||||
require(requireStr)
|
||||
end
|
||||
|
||||
Hook.Add(LUA_EVENT_LOADED, HOOK_NAME_ON_LOADED, onLoaded)
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
local Api = require("ConsentRequiredExtended.Api")
|
||||
|
||||
local function isItemAffected(identifier)
|
||||
return Api.IsItemAffected(identifier)
|
||||
end
|
||||
|
||||
local function onHandleProjectileCollision(projectile, ptable)
|
||||
if not ptable.ReturnValue then
|
||||
return
|
||||
end
|
||||
if not NTConfig.Get("NTCRE_ConsentRequiredExtra", true) then
|
||||
return
|
||||
end
|
||||
if not isItemAffected(projectile.Item.Prefab.Identifier.Value) then
|
||||
return
|
||||
end
|
||||
if projectile.User == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local target = ptable["target"]
|
||||
if target.Body == nil or target.Body.UserData == nil then
|
||||
return
|
||||
end
|
||||
local targetUserData = target.Body.UserData
|
||||
|
||||
local targetUser = nil
|
||||
if LuaUserData.IsTargetType(targetUserData, "Barotrauma.Limb") then
|
||||
targetUser = targetUserData.character
|
||||
elseif LuaUserData.IsTargetType(targetUserData, "Barotrauma.Character") then
|
||||
targetUser = targetUserData
|
||||
end
|
||||
|
||||
if targetUser ~= nil then
|
||||
Api.onAffectedItemApplied(projectile.User, targetUser)
|
||||
end
|
||||
end
|
||||
|
||||
return onHandleProjectileCollision
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
local Api = require("ConsentRequiredExtended.Api")
|
||||
|
||||
local function isItemAffected(identifier)
|
||||
return Api.IsItemAffected(identifier)
|
||||
end
|
||||
|
||||
---@param meleeweapon Weapon target
|
||||
---@param target The target of the hit could be a limb or just a character.
|
||||
local function onMeleeWeaponHandleImpact(meleeweapon, target)
|
||||
if not NTConfig.Get("NTCRE_ConsentRequiredExtra", true) then
|
||||
return
|
||||
end
|
||||
if meleeweapon == nil or target == nil then
|
||||
return
|
||||
end
|
||||
local itemIdentifier = meleeweapon.item.Prefab.Identifier.Value
|
||||
if isItemAffected(itemIdentifier) then
|
||||
local user = meleeweapon.picker
|
||||
if user == nil then
|
||||
return
|
||||
end
|
||||
local targetUserData = target.UserData
|
||||
if targetUserData == nil then
|
||||
return
|
||||
end
|
||||
local targetUser = nil
|
||||
if LuaUserData.IsTargetType(targetUserData, "Barotrauma.Limb") then
|
||||
targetUser = targetUserData.character
|
||||
elseif LuaUserData.IsTargetType(targetUserData, "Barotrauma.Character") then
|
||||
targetUser = targetUserData
|
||||
end
|
||||
if targetUser ~= nil then
|
||||
Api.onAffectedItemApplied(user, targetUser)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return onMeleeWeaponHandleImpact
|
||||
Reference in New Issue
Block a user