Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
JsModLoader.cs
浏览该文件的文档.
1#if !IOS && !BROWSER
2using Engine;
4using Jint;
5using Jint.Native.Function;
6
7namespace Game {
8 public class JsModLoader : ModLoader {
9 public override void OnMinerDig(ComponentMiner miner, TerrainRaycastResult raycastResult, ref float DigProgress, out bool Digged) {
10 bool Digged1 = false;
11 if (JsInterface.handlersDictionary.TryGetValue("OnMinerDig", out List<Function> functions)) {
12 float DigProgress1 = DigProgress;
13 foreach (Function function in functions) {
14 Digged1 |= JsInterface.Invoke(function, miner, raycastResult, DigProgress1).AsBoolean();
15 }
16 }
17 Digged = Digged1;
18 }
19
20 [Obsolete]
21 public override void OnMinerPlace(ComponentMiner miner,
22 TerrainRaycastResult raycastResult,
23 int x,
24 int y,
25 int z,
26 int value,
27 out bool Placed) {
28 bool Placed1 = false;
29 if (JsInterface.handlersDictionary.TryGetValue("OnMinerPlace", out List<Function> functions)) {
30 foreach (Function function in functions) {
31 Placed1 |= JsInterface.Invoke(
32 function,
33 miner,
34 raycastResult,
35 x,
36 y,
37 z,
38 value
39 )
40 .AsBoolean();
41 }
42 }
43 Placed = Placed1;
44 }
45
46 public override bool OnPlayerSpawned(PlayerData.SpawnMode spawnMode, ComponentPlayer componentPlayer, Vector3 position) {
47 if (JsInterface.handlersDictionary.TryGetValue("OnPlayerSpawned", out List<Function> functions)) {
48 foreach (Function function in functions) {
49 JsInterface.Invoke(function, spawnMode, componentPlayer, position);
50 }
51 }
52 return false;
53 }
54
55 public override void OnPlayerDead(PlayerData playerData) {
56 if (JsInterface.handlersDictionary.TryGetValue("OnPlayerDead", out List<Function> functions)) {
57 foreach (Function function in functions) {
58 JsInterface.Invoke(function, playerData);
59 }
60 }
61 }
62
63 public override void ProcessAttackment(Attackment attackment) {
64 if (JsInterface.handlersDictionary.TryGetValue("ProcessAttackment", out List<Function> functions)) {
65 foreach (Function function in functions) {
66 JsInterface.Invoke(function, attackment);
67 }
68 }
69 }
70
71 public override void CalculateCreatureInjuryAmount(Injury injury) {
72 if (JsInterface.handlersDictionary.TryGetValue("CalculateCreatureInjuryAmount", out List<Function> functions)) {
73 foreach (Function function in functions) {
74 JsInterface.Invoke(function, injury);
75 }
76 }
77 }
78
79 public override void OnProjectLoaded(Project project) {
80 if (JsInterface.handlersDictionary.TryGetValue("OnProjectLoaded", out List<Function> functions)) {
81 foreach (Function function in functions) {
82 JsInterface.Invoke(function, project);
83 }
84 }
85 }
86
87 public override void OnProjectDisposed() {
88 if (JsInterface.handlersDictionary.TryGetValue("OnProjectDisposed", out List<Function> functions)) {
89 foreach (Function function in functions) {
90 JsInterface.Invoke(function);
91 }
92 }
93 }
94 }
95}
96
97#elif __IOS
98
99
100using Engine;
101using GameEntitySystem;
102using JavaScriptCore;
103using static JavaScriptCore.JSValue;
104using static System.Runtime.InteropServices.JavaScript.JSType;
105
106namespace Game {
107 public class JsModLoader : ModLoader {
108 public JSContext JSContext;
109 public override void OnMinerDig(ComponentMiner miner, TerrainRaycastResult raycastResult, ref float DigProgress, out bool Digged) {
110 bool Digged1 = false;
111 if (JsInterface.handlersDictionary.TryGetValue("OnMinerDig", out List<JSValue> functions)) {
112 float DigProgress1 = DigProgress;
113 foreach (JSValue function in functions) {
114 Digged1 = function.Call(JSValue.From(JSValue.FromObject(miner),JSContext), JSValue.From(JSValue.FromObject(raycastResult),JSContext), JSValue.From(DigProgress1,JSContext)).ToBool();
115 }
116 }
117 Digged = Digged1;
118 }
119
120 public override void OnMinerPlace(ComponentMiner miner,
121 TerrainRaycastResult raycastResult,
122 int x,
123 int y,
124 int z,
125 int value,
126 out bool Placed) {
127 bool Placed1 = false;
128 if (JsInterface.handlersDictionary.TryGetValue("OnMinerPlace", out List<JSValue> functions)) {
129 foreach (JSValue function in functions) {
130 Placed1 |= function.Call(JSValue.From(JSValue.FromObject(miner),JSContext), JSValue.From(JSValue.FromObject(raycastResult),JSContext), JSValue.From(x,JSContext), JSValue.From(y,JSContext), JSValue.From(z,JSContext), JSValue.From(value,JSContext)).ToBool();
131 }
132 }
133 Placed = Placed1;
134 }
135
136 public override bool OnPlayerSpawned(PlayerData.SpawnMode spawnMode, ComponentPlayer componentPlayer, Vector3 position) {
137 if (JsInterface.handlersDictionary.TryGetValue("OnPlayerSpawned", out List<JSValue> functions)) {
138 foreach (var function in functions) {
139 function.Call(JSValue.From(JSValue.FromObject(spawnMode), JSContext), JSValue.From(JSValue.FromObject(componentPlayer), JSContext), JSValue.From(JSValue.FromObject(position), JSContext));
140 }
141
142 }
143 return false;
144 }
145
146 public override void OnPlayerDead(PlayerData playerData) {
147 if (JsInterface.handlersDictionary.TryGetValue("OnPlayerDead", out List<JSValue> functions)) {
148 foreach (JSValue function in functions) {
149 function.Call(JSValue.From(JSValue.FromObject(playerData), JSContext));
150 }
151 }
152 }
153
154 public override void ProcessAttackment(Attackment attackment) {
155 if (JsInterface.handlersDictionary.TryGetValue("ProcessAttackment", out List<JSValue> functions)) {
156 foreach (JSValue function in functions) {
157 function.Call(JSValue.From(JSValue.FromObject(attackment), JSContext));
158 }
159 }
160 }
161
162 public override void CalculateCreatureInjuryAmount(Injury injury) {
163 if (JsInterface.handlersDictionary.TryGetValue("CalculateCreatureInjuryAmount", out List<JSValue> functions)) {
164 foreach (JSValue function in functions) {
165 function.Call(JSValue.From(JSValue.FromObject(injury), JSContext));
166 }
167 }
168 }
169
170 public override void OnProjectLoaded(Project project) {
171 if (JsInterface.handlersDictionary.TryGetValue("OnProjectLoaded", out List<JSValue> functions)) {
172 foreach (JSValue function in functions) {
173 function.Call(JSValue.From(JSValue.FromObject(project), JSContext));
174 }
175 }
176 }
177
178 public override void OnProjectDisposed() {
179 if (JsInterface.handlersDictionary.TryGetValue("OnProjectDisposed", out List<JSValue> functions)) {
180 foreach (JSValue function in functions) {
181 function.Call();
182 }
183 }
184 }
185 }
186}
187#endif
Engine.Vector3 Vector3
The spell "Attackment" is wrong, But it is not recommended to change it because many mods rely on thi...
static Dictionary< string, List< Function > > handlersDictionary
static JsValue Invoke(string str, params object[] arguments)
override void OnProjectDisposed()
当Project被释放时执行
override void OnProjectLoaded(Project project)
当Project被加载时执行
override void CalculateCreatureInjuryAmount(Injury injury)
计算生物收到伤害的量
override void OnPlayerDead(PlayerData playerData)
当人物死亡时执行。在玩家进入世界且玩家处于死亡状态时也会执行 可以通过playerData.m_stateMachine.PreviousState == "Playing",来判断是刚死的,还是加载世...
override bool OnPlayerSpawned(PlayerData.SpawnMode spawnMode, ComponentPlayer componentPlayer, Vector3 position)
人物出生时执行
override void OnMinerDig(ComponentMiner miner, TerrainRaycastResult raycastResult, ref float DigProgress, out bool Digged)
当人物挖掘时执行
override void ProcessAttackment(Attackment attackment)
在攻击时执行
override void OnMinerPlace(ComponentMiner miner, TerrainRaycastResult raycastResult, int x, int y, int z, int value, out bool Placed)
当人物放置时执行,若Placed为true则不执行原放置操作