Survivalcraft API 1.8.2.3
v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentDigInMudBehavior.cs
浏览该文件的文档.
1
using
Engine
;
2
using
GameEntitySystem
;
3
using
TemplatesDatabase
;
4
5
namespace
Game
{
6
public
class
ComponentDigInMudBehavior
:
ComponentBehavior
,
IUpdateable
{
7
public
SubsystemTerrain
m_subsystemTerrain
;
8
9
public
SubsystemTime
m_subsystemTime
;
10
11
public
ComponentCreature
m_componentCreature
;
12
13
public
ComponentPathfinding
m_componentPathfinding
;
14
15
public
ComponentMiner
m_componentMiner
;
16
17
public
ComponentFishModel
m_componentFishModel
;
18
19
public
ComponentSwimAwayBehavior
m_componentSwimAwayBehavior
;
20
21
public
StateMachine
m_stateMachine
=
new
();
22
23
public
Random
m_random
=
new
();
24
25
public
float
m_importanceLevel
;
26
27
public
double
m_sinkTime
;
28
29
public
double
m_digInTime
;
30
31
public
double
m_digOutTime
=
double
.NegativeInfinity;
32
33
public
float
m_maxDigInDepth
;
34
35
public
int
m_digInBlockIndex
;
36
37
public
ComponentBody
m_collidedWithBody
;
38
39
public
UpdateOrder
UpdateOrder
=>
UpdateOrder
.Default;
40
41
public
override
float
ImportanceLevel
=>
m_importanceLevel
;
42
43
public
virtual
void
Update
(
float
dt) {
44
m_stateMachine
.Update();
45
m_collidedWithBody
=
null
;
46
}
47
48
public
override
void
Load
(
ValuesDictionary
valuesDictionary,
IdToEntityMap
idToEntityMap) {
49
m_subsystemTerrain
=
Project
.FindSubsystem<
SubsystemTerrain
>(
true
);
50
m_subsystemTime
=
Project
.FindSubsystem<
SubsystemTime
>(
true
);
51
m_componentCreature
=
Entity
.FindComponent<
ComponentCreature
>(
true
);
52
m_componentPathfinding
=
Entity
.FindComponent<
ComponentPathfinding
>(
true
);
53
m_componentMiner
=
Entity
.FindComponent<
ComponentMiner
>(
true
);
54
m_componentFishModel
=
Entity
.FindComponent<
ComponentFishModel
>(
true
);
55
m_componentSwimAwayBehavior
=
Entity
.FindComponent<
ComponentSwimAwayBehavior
>(
true
);
56
string
digInBlockName = valuesDictionary.GetValue<
string
>(
"DigInBlockName"
);
57
m_digInBlockIndex
= !
string
.IsNullOrEmpty(digInBlockName)
58
?
BlocksManager
.
Blocks
.First(b => b.GetType().Name == digInBlockName).
BlockIndex
59
: 0;
60
m_maxDigInDepth
= valuesDictionary.GetValue<
float
>(
"MaxDigInDepth"
);
61
m_componentCreature.ComponentBody.CollidedWithBody += delegate(
ComponentBody
b) {
m_collidedWithBody
= b; };
62
m_stateMachine
.AddState(
63
"Inactive"
,
64
delegate {
m_importanceLevel
= 0f; },
65
delegate {
66
if
(
m_random
.Float(0f, 1f) < 0.5f *
m_subsystemTime
.GameTimeDelta
67
&&
m_subsystemTime
.GameTime >
m_digOutTime
+ 15.0
68
&&
m_digInBlockIndex
!= 0) {
69
int
x =
Terrain
.
ToCell
(
m_componentCreature
.ComponentBody.Position.X);
70
int
y =
Terrain
.
ToCell
(
m_componentCreature
.ComponentBody.Position.Y - 0.9f);
71
int
z =
Terrain
.
ToCell
(
m_componentCreature
.ComponentBody.Position.Z);
72
if
(
m_subsystemTerrain
.Terrain.GetCellContents(x, y, z) ==
m_digInBlockIndex
) {
73
m_importanceLevel
=
m_random
.Float(1f, 3f);
74
}
75
}
76
if
(
IsActive
) {
77
m_stateMachine
.TransitionTo(
"Sink"
);
78
}
79
},
80
null
81
);
82
m_stateMachine
.AddState(
83
"Sink"
,
84
delegate {
85
m_importanceLevel
= 10f;
86
m_sinkTime
=
m_subsystemTime
.GameTime;
87
m_componentPathfinding
.Stop();
88
},
89
delegate {
90
if
(
m_random
.Float(0f, 1f) < 2f *
m_subsystemTime
.GameTimeDelta
91
&&
m_componentCreature
.ComponentBody.StandingOnValue ==
m_digInBlockIndex
92
&&
m_componentCreature
.ComponentBody.Velocity.LengthSquared() < 1f) {
93
m_stateMachine
.TransitionTo(
"DigIn"
);
94
}
95
if
(!
IsActive
96
||
m_subsystemTime
.GameTime >
m_sinkTime
+ 6.0) {
97
m_stateMachine
.TransitionTo(
"Inactive"
);
98
}
99
},
100
null
101
);
102
m_stateMachine
.AddState(
103
"DigIn"
,
104
delegate {
105
m_digInTime
=
m_subsystemTime
.GameTime;
106
m_digOutTime
=
m_digInTime
+
m_random
.Float(30f, 60f);
107
},
108
delegate {
109
m_componentFishModel.DigInOrder =
m_maxDigInDepth
;
110
if
(
m_collidedWithBody
!=
null
) {
111
if
(
m_subsystemTime
.GameTime -
m_digInTime
> 2.0
112
&&
m_collidedWithBody
.Density < 0.95f) {
113
m_componentMiner
.Hit(
114
m_collidedWithBody
,
115
m_collidedWithBody
.Position,
116
Vector3
.
Normalize
(
m_collidedWithBody
.Position -
m_componentCreature
.ComponentBody.Position)
117
);
118
}
119
m_componentSwimAwayBehavior
.SwimAwayFrom(
m_collidedWithBody
);
120
m_stateMachine
.TransitionTo(
"Inactive"
);
121
}
122
if
(!
IsActive
123
||
m_subsystemTime
.GameTime >=
m_digOutTime
124
||
m_componentCreature
.ComponentBody.StandingOnValue !=
m_digInBlockIndex
125
||
m_componentCreature
.ComponentBody.Velocity.LengthSquared() > 1f) {
126
m_stateMachine
.TransitionTo(
"Inactive"
);
127
}
128
},
129
null
130
);
131
m_stateMachine
.TransitionTo(
"Inactive"
);
132
}
133
134
public
virtual
Vector3
?
FindDestination
() {
135
for
(
int
i = 0; i < 8; i++) {
136
Vector2
vector =
m_random
.Vector2(1f, 1f);
137
float
y = 0.2f *
m_random
.Float(-0.8f, 1f);
138
Vector3
v =
Vector3
.
Normalize
(
new
Vector3
(vector.
X
, y, vector.
Y
));
139
Vector3
vector2 = m_componentCreature.ComponentBody.Position +
m_random
.Float(8f, 16f) * v;
140
TerrainRaycastResult
? terrainRaycastResult =
m_subsystemTerrain
.Raycast(
141
m_componentCreature
.ComponentBody.Position,
142
vector2,
143
false
,
144
false
,
145
delegate(
int
value,
float
_) {
146
int
num =
Terrain
.
ExtractContents
(value);
147
return
!(
BlocksManager
.
Blocks
[num] is
WaterBlock
);
148
}
149
);
150
if
(!terrainRaycastResult.HasValue) {
151
return
vector2;
152
}
153
if
(terrainRaycastResult.
Value
.Distance > 4f) {
154
return
m_componentCreature.ComponentBody.Position + v * terrainRaycastResult.
Value
.Distance;
155
}
156
}
157
return
null
;
158
}
159
}
160
}
Vector3
Engine.Vector3 Vector3
定义
SubsystemAudio.cs:5
Game.Block.BlockIndex
int BlockIndex
定义
Block.cs:6
Game.BlocksManager
定义
BlocksManager.cs:10
Game.BlocksManager.Blocks
static Block[] Blocks
定义
BlocksManager.cs:41
Game.ComponentBehavior
定义
ComponentBehavior.cs:4
Game.ComponentBehavior.IsActive
virtual bool IsActive
定义
ComponentBehavior.cs:7
Game.ComponentBody
定义
ComponentBody.cs:7
Game.ComponentCreature
定义
ComponentCreature.cs:7
Game.ComponentDigInMudBehavior
定义
ComponentDigInMudBehavior.cs:6
Game.ComponentDigInMudBehavior.ImportanceLevel
override float ImportanceLevel
定义
ComponentDigInMudBehavior.cs:41
Game.ComponentDigInMudBehavior.m_subsystemTime
SubsystemTime m_subsystemTime
定义
ComponentDigInMudBehavior.cs:9
Game.ComponentDigInMudBehavior.m_componentFishModel
ComponentFishModel m_componentFishModel
定义
ComponentDigInMudBehavior.cs:17
Game.ComponentDigInMudBehavior.m_collidedWithBody
ComponentBody m_collidedWithBody
定义
ComponentDigInMudBehavior.cs:37
Game.ComponentDigInMudBehavior.m_subsystemTerrain
SubsystemTerrain m_subsystemTerrain
定义
ComponentDigInMudBehavior.cs:7
Game.ComponentDigInMudBehavior.UpdateOrder
UpdateOrder UpdateOrder
定义
ComponentDigInMudBehavior.cs:39
Game.ComponentDigInMudBehavior.m_maxDigInDepth
float m_maxDigInDepth
定义
ComponentDigInMudBehavior.cs:33
Game.ComponentDigInMudBehavior.m_importanceLevel
float m_importanceLevel
定义
ComponentDigInMudBehavior.cs:25
Game.ComponentDigInMudBehavior.m_random
Random m_random
定义
ComponentDigInMudBehavior.cs:23
Game.ComponentDigInMudBehavior.m_componentCreature
ComponentCreature m_componentCreature
定义
ComponentDigInMudBehavior.cs:11
Game.ComponentDigInMudBehavior.FindDestination
virtual ? Vector3 FindDestination()
定义
ComponentDigInMudBehavior.cs:134
Game.ComponentDigInMudBehavior.m_digOutTime
double m_digOutTime
定义
ComponentDigInMudBehavior.cs:31
Game.ComponentDigInMudBehavior.m_digInTime
double m_digInTime
定义
ComponentDigInMudBehavior.cs:29
Game.ComponentDigInMudBehavior.m_componentMiner
ComponentMiner m_componentMiner
定义
ComponentDigInMudBehavior.cs:15
Game.ComponentDigInMudBehavior.m_stateMachine
StateMachine m_stateMachine
定义
ComponentDigInMudBehavior.cs:21
Game.ComponentDigInMudBehavior.m_digInBlockIndex
int m_digInBlockIndex
定义
ComponentDigInMudBehavior.cs:35
Game.ComponentDigInMudBehavior.Load
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
定义
ComponentDigInMudBehavior.cs:48
Game.ComponentDigInMudBehavior.m_componentSwimAwayBehavior
ComponentSwimAwayBehavior m_componentSwimAwayBehavior
定义
ComponentDigInMudBehavior.cs:19
Game.ComponentDigInMudBehavior.m_sinkTime
double m_sinkTime
定义
ComponentDigInMudBehavior.cs:27
Game.ComponentDigInMudBehavior.m_componentPathfinding
ComponentPathfinding m_componentPathfinding
定义
ComponentDigInMudBehavior.cs:13
Game.ComponentDigInMudBehavior.Update
virtual void Update(float dt)
定义
ComponentDigInMudBehavior.cs:43
Game.ComponentFishModel
定义
ComponentFishModel.cs:7
Game.ComponentMiner
定义
ComponentMiner.cs:7
Game.ComponentPathfinding
定义
ComponentPathfinding.cs:6
Game.ComponentSwimAwayBehavior
定义
ComponentSwimAwayBehavior.cs:6
Game.Random
定义
Random.cs:5
Game.StateMachine
定义
StateMachine.cs:2
Game.SubsystemTerrain
定义
SubsystemTerrain.cs:6
Game.SubsystemTime
定义
SubsystemTime.cs:6
Game.Terrain
定义
Terrain.cs:5
Game.Terrain.ExtractContents
static int ExtractContents(int value)
定义
Terrain.cs:303
Game.Terrain.ToCell
static int ToCell(float x)
定义
Terrain.cs:210
Game.WaterBlock
定义
WaterBlock.cs:3
GameEntitySystem.Component.ValuesDictionary
ValuesDictionary ValuesDictionary
定义
Component.cs:12
GameEntitySystem.Component.Project
Project Project
定义
Component.cs:16
GameEntitySystem.Component.Entity
Entity Entity
定义
Component.cs:14
GameEntitySystem.IdToEntityMap
定义
IdToEntityMap.cs:5
Game.IUpdateable
定义
IUpdateable.cs:2
Engine
定义
BaseSound.cs:10
GameEntitySystem
定义
Component.cs:6
Game
定义
ContentFileBridge.cs:4
TemplatesDatabase
定义
Database.cs:6
Engine.Vector2
定义
Vector2.cs:2
Engine.Vector2.Y
float Y
定义
Vector2.cs:5
Engine.Vector2.X
float X
定义
Vector2.cs:3
Engine.Vector3
定义
Vector3.cs:2
Engine.Vector3.Normalize
static Vector3 Normalize(Vector3 v)
定义
Vector3.cs:154
Game.TerrainRaycastResult
定义
TerrainRaycastResult.cs:5
Game.TerrainRaycastResult.Value
int Value
定义
TerrainRaycastResult.cs:10
SurvivalcraftApi 1.8.2.3
Survivalcraft.Windows
Component
ComponentDigInMudBehavior.cs
制作者
1.16.1