1using System.Globalization;
36 public static string fName =
"ComponentMiner";
49 [Obsolete(
"Do not set the added hit interval, set m_basicHitInterval instead.")]
89 if (
ComponentFactors?.OtherFactorsResults.TryGetValue(
"DigSpeed", out
float result) ??
false) {
124 public virtual void Poke(
bool forceRestart) {
145 float digTimeWithActiveTool =
CalculateDigTime(cellValue, activeBlockValue);
165 && !ComponentPlayer.ComponentInput.IsControlledByTouch
166 && m_subsystemGameInfo.WorldSettings.GameMode ==
GameMode.Creative;
170 modLoader.OnMinerDig(
this, raycastResult, ref
m_digProgress, out
bool flag3);
177 && digTimeWithActiveTool >= 3f
182 if (bestInventoryToolValue == 0) {
183 if (activeBlockContents != 23 && flag) {
188 else if (
CalculateDigTime(cellValue, bestInventoryToolValue) < 0.5f * digTimeWithActiveTool || flag) {
216 int durabilityReduction = 1;
217 int playerDataAdd = 1;
223 modLoader.OnBlockDug(
this, digValue, cellValue, ref durabilityReduction, ref mute, ref playerDataAdd);
233 ComponentCreature.PlayerStats.BlocksDug += playerDataAdd;
266 if (placementData.
Value != 0) {
268 int num2 = placementData.CellFace.X + point.
X;
269 int num3 = placementData.CellFace.Y + point.
Y;
270 int num4 = placementData.CellFace.Z + point.
Z;
272 bool placementNotAllowed_ =
false;
277 loader.BeforeMinerPlace(
284 out
bool placementNotAllowed
287 placementNotAllowed_ |= placementNotAllowed;
291 if (placementNotAllowed_) {
297#pragma warning disable CS0618
298 modLoader.OnMinerPlace(
307#pragma warning restore CS0618
315 modLoader.OnMinerPlace(
345 boundingBox.Min +=
new Vector3(0.2f);
346 boundingBox.Max -=
new Vector3(0.2f);
348 for (
int i = 0; i < customCollisionBoxes.Length; i++) {
350 box.Min +=
new Vector3(num2, num3, num4);
351 box.Max +=
new Vector3(num2, num3, num4);
361 for (
int i = 0; i < blockBehaviors.Length; i++) {
362 blockBehaviors[i].
OnItemPlaced(num2, num3, num4, ref placementData, value);
411 for (
int i = 0; i < blockBehaviors.Length; i++) {
412 if (blockBehaviors[i].OnUse(ray,
this)) {
422 for (
int i = 0; i < blockBehaviors.Length; i++) {
423 if (blockBehaviors[i].OnInteract(raycastResult,
this)) {
441 for (
int i = 0; i < blockBehaviors.Length; i++) {
442 if (blockBehaviors[i].OnInteract(raycastResult,
this)) {
458 modLoader.SetHitInterval(
this, ref hitInterval);
498 modLoader.OnMinerHit(
521 int durabilityReduction = 1;
526 loader.OnMinerHit2(
this, componentBody, hitPoint, hitDirection, ref durabilityReduction, ref attackment);
535 hitPoint + 0.75f * hitDirection,
541 "SetHitValueParticleSystem",
543 modLoader.SetHitValueParticleSystem(particleSystem,
null);
577 for (
int i = 0; i < blockBehaviors.Length; i++) {
578 if (blockBehaviors[i].OnAim(aim,
this, state)) {
598 bool raycastTerrain =
true,
599 bool raycastBodies =
true,
600 bool raycastMovingBlocks =
true,
601 float? Reach =
null) {
603 if (Reach.HasValue) {
610 Vector3 end = ray.Position + direction * (reach + 1f);
618 (body, distance) =>
Vector3.
DistanceSquared(start + distance * direction, creaturePosition) <= reach * reach
626 if (raycastMovingBlocks) {
630 if (raycastTerrain) {
636 (value, distance) => {
661 float num = bodyRaycastResult?.
Distance ??
float.PositiveInfinity;
662 float num2 = movingBlocksRaycastResult?.
Distance ??
float.PositiveInfinity;
663 float num3 = terrainRaycastResult?.
Distance ??
float.PositiveInfinity;
664 if (bodyRaycastResult.HasValue
667 return bodyRaycastResult.Value;
669 if (movingBlocksRaycastResult.HasValue
672 return movingBlocksRaycastResult.Value;
674 if (terrainRaycastResult.HasValue
677 return terrainRaycastResult.
Value;
679 return new Ray3(start, direction);
684 bool raycastTerrain =
true,
685 bool raycastBodies =
true,
686 bool raycastMovingBlocks =
true,
687 float? reach =
null) where T : struct {
688 object obj =
Raycast(ray, mode, raycastTerrain, raycastBodies, raycastMovingBlocks, reach);
689 return obj is T obj1 ? obj1 :
null;
720 catch (Exception e) {
721 Log.
Error($
"Attack execute error: {e}");
730 bool isMeleeAttack) {
739 [Obsolete(
"Use AddHitValueParticleSystem() in Attackment instead.",
true)]
744 string text2 = (0f - damage).ToString(
"0", CultureInfo.InvariantCulture);
746 if (attackerBody !=
null) {
747 hitValueParticleVelocity = attackerBody.
Velocity;
749 Color color = attackerComponentPlayer !=
null && damage > 0f && attackedComponentHealth !=
null ? Color.White :
Color.
Transparent;
750 HitValueParticleSystem particleSystem =
new(hitPoint + 0.75f * hitDirection, 1f * hitDirection + hitValueParticleVelocity, color, text2);
752 "SetHitValueParticleSystem",
754 modLoader.SetHitValueParticleSystem(particleSystem,
null);
778 || !
m_subsystemTime.PeriodicGameTimeEvent(1.0, GetHashCode() % 100 / 100f)) {
784 for (
int i = 0; i < 10; i++) {
786 new Ray3(eyePosition, forwardVector +
m_random.Vector3(0.75f)),
789 if (terrainRaycastResult.HasValue
790 && terrainRaycastResult.
Value.Distance < 1.5f
814 AttackPower = valuesDictionary.GetValue<
float>(
"AttackPower");
815#pragma warning disable CS0618
816 HitInterval = valuesDictionary.GetValue<
float>(
"HitInterval");
817#pragma warning restore CS0618
819 if (
string.CompareOrdinal(
m_subsystemGameInfo.WorldSettings.OriginalSerializationVersion,
"2.4") < 0
827 valuesDictionary.SetValue(
"AttackPower",
AttackPower);
843 if (componentLocomotion !=
null
860 if (digResilience <
float.PositiveInfinity) {
863 return float.PositiveInfinity;
869 && ShovelPower >= 2f) {
873 && QuarryPower >= 2f) {
877 && HackPower >= 2f) {
882 return float.PositiveInfinity;
898 return float.PositiveInfinity;
907 "IsLevelSufficientForTool",
909 modLoader.IsLevelSufficientForTool(
this, toolValue, ref canUse, out skip);
static void Error(object message)
static float Remainder(float x, float y)
static float Saturate(float x)
static int Max(int x1, int x2)
static double FrameStartTime
The spell "Attackment" is wrong, But it is not recommended to change it because many mods rely on thi...
virtual void ProcessAttackment()
virtual BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
virtual float GetDigResilience(int value)
virtual bool IsGatherable_(int value)
virtual BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
方块放置方向
virtual float GetHackPower(int value)
virtual int GetToolLevel(int value)
virtual bool IsInteractive(SubsystemTerrain subsystemTerrain, int value)
virtual float GetMeleePower(int value)
virtual float GetQuarryPower(int value)
virtual bool IsAimable_(int value)
virtual bool IsPlacementTransparent_(int value)
virtual int GetPlayerLevelRequired(int value)
virtual bool IsPlaceable_(int value)
virtual BlockPlacementData GetDigValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, int toolValue, TerrainRaycastResult raycastResult)
virtual float GetShovelPower(int value)
virtual bool GetIsDiggingTransparent(int value)
virtual float GetMeleeHitProbability(int value)
virtual bool IsCollidable_(int value)
virtual string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
virtual BlockDigMethod GetBlockDigMethod(int value)
virtual BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
static int DamageItem(int value, int damageCount, Entity owner=null)
virtual float ImmersionFactor
virtual ComponentBody ParentBody
virtual ComponentBody StandingOnBody
virtual ? int StandingOnValue
virtual double HitInterval
伤害间隔(原版为0.66f)
SubsystemAudio m_subsystemAudio
ComponentPlayer ComponentPlayer
ComponentCreature ComponentCreature
virtual void RemoveActiveTool(int removeCount)
bool m_digSpeedBasedOnStrengthFactor
挖掘速度是否受玩家力量属性加成
bool Aim(Ray3 aim, AimState state)
static void AddHitValueParticleSystem(float damage, Entity attacker, Entity attacked, Vector3 hitPoint, Vector3 hitDirection)
SubsystemGameInfo m_subsystemGameInfo
virtual void Poke(bool forceRestart)
virtual int FindBestInventoryToolForDigging(int digValue)
double m_lastToolHintTime
static void AttackBody(Attackment attackment)
SubsystemTerrain m_subsystemTerrain
bool Place(TerrainRaycastResult raycastResult)
static void AttackBody(ComponentBody target, ComponentCreature attacker, Vector3 hitPoint, Vector3 hitDirection, float attackPower, bool isMeleeAttack)
bool Interact(TerrainRaycastResult raycastResult)
SubsystemBodies m_subsystemBodies
virtual float CalculateDigTime(int digValue, int toolValue)
double m_basicHitInterval
ComponentFactors ComponentFactors
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
T? Raycast< T >(Ray3 ray, RaycastMode mode, bool raycastTerrain=true, bool raycastBodies=true, bool raycastMovingBlocks=true, float? reach=null)
void Hit(ComponentBody componentBody, Vector3 hitPoint, Vector3 hitDirection)
virtual object Raycast(Ray3 ray, RaycastMode mode, bool raycastTerrain=true, bool raycastBodies=true, bool raycastMovingBlocks=true, float? Reach=null)
发出射线检测,检测玩家点击到的目标
bool Place(TerrainRaycastResult raycastResult, int value)
static bool IsBlockPlacingAllowed(ComponentBody componentBody)
virtual bool IsLevelSufficientForTool(int toolValue)
virtual void Update(float dt)
ComponentHealth m_componentHealth
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
SubsystemSoundMaterials m_subsystemSoundMaterials
virtual void DamageActiveTool(int damageCount)
bool Dig(TerrainRaycastResult raycastResult)
SubsystemTime m_subsystemTime
SubsystemMovingBlocks m_subsystemMovingBlocks
SubsystemBlockBehaviors m_subsystemBlockBehaviors
bool Interact(MovingBlocksRaycastResult raycastResult)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static float CreativeReach
static float CreativeDigTime
static int VisibilityRange
virtual void OnItemPlaced(int x, int y, int z, ref BlockPlacementData placementData, int itemValue)
static int ExtractContents(int value)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
Component FindComponent(Type type, string name, bool throwOnError)
virtual Subsystem FindSubsystem(Type type, string name, bool throwOnError)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
int GetSlotValue(int slotIndex)
bool Intersection(BoundingBox box)
Vector3 GetForwardVector()
static float DistanceSquared(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static readonly Vector3 Zero
static float Dot(Vector3 v1, Vector3 v2)
static Point3 FaceToPoint3(int face)
Vector3 HitPoint(float offsetFromSurface=0f)