Skip to content

Commit ee27e38

Browse files
committed
scripting cont
1 parent 2af1661 commit ee27e38

12 files changed

Lines changed: 98 additions & 49 deletions

File tree

Bootstrap/Spigot/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
plugins {
22
id 'java-library'
33
id 'com.github.johnrengelman.shadow' version '7.0.0'
4+
id("xyz.jpenilla.run-paper") version "1.0.4"
5+
46
}
57

68
group = 'cz.neumimto.rpg'

Common/lib-cp/NT-Script-0.1.9.jar

2.79 KB
Binary file not shown.

Common/src/main/java/cz/neumimto/rpg/common/effects/ScriptEffectBase.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
public class ScriptEffectBase extends UnstackableEffectBase {
77

8-
public static Handler onApply;
9-
public static Handler onTick;
10-
public static Handler onRemove;
118

129
public interface Handler<T extends EffectBase> {
1310

@@ -20,24 +17,5 @@ public ScriptEffectBase() {
2017
effectName = "w";
2118
}
2219

23-
@Override
24-
public void onApply(IEffect self) {
25-
if (onApply != null) {
26-
onApply.run(this);
27-
}
28-
}
29-
30-
@Override
31-
public void onTick(IEffect self) {
32-
if (onTick != null) {
33-
onTick.run(this);
34-
}
35-
}
3620

37-
@Override
38-
public void onRemove(IEffect self) {
39-
if (onRemove != null) {
40-
onRemove.run(this);
41-
}
42-
}
4321
}

Common/src/main/java/cz/neumimto/rpg/common/effects/UnstackableEffectBase.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ public void removeStack(IEffect iEffect) {
3737

3838
}
3939

40-
@Override
41-
public void setConsumer(IEffectConsumer consumer) {
42-
super.setConsumer(consumer);
43-
}
44-
4540
@Override
4641
public IEffectContainer<VALUE, IEffect<VALUE>> getEffectContainer() {
4742
return this;
@@ -56,4 +51,14 @@ public <T extends IEffect<VALUE>> IEffectContainer<VALUE, T> constructEffectCont
5651
public void setEffectContainer(IEffectContainer<VALUE, IEffect<VALUE>> iEffectContainer) {
5752

5853
}
54+
55+
@Override
56+
public void setConsumer(IEffectConsumer consumer) {
57+
super.setConsumer(consumer);
58+
}
59+
60+
@Override
61+
public IEffectConsumer getConsumer() {
62+
return super.getConsumer();
63+
}
5964
}

Common/src/main/java/cz/neumimto/rpg/common/scripting/mechanics/EffectsM.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,38 @@
1111
import javax.inject.Inject;
1212
import javax.inject.Singleton;
1313

14+
import static cz.neumimto.nts.annotations.ScriptMeta.*;
15+
1416
@Singleton
1517
@AutoService(NTScriptProxy.class)
1618
public class EffectsM implements NTScriptProxy {
1719

1820
@Inject
1921
private EffectService effectService;
2022

21-
@ScriptMeta.Function("add_effect")
22-
@ScriptMeta.Handler
23+
@Function("add_effect")
24+
@Handler
2325
public void applyEffect(
24-
@ScriptMeta.NamedParam("e|effect") IEffect effect,
25-
@ScriptMeta.NamedParam("s|source") IEffectSourceProvider provider,
26-
@ScriptMeta.NamedParam("es|entity_source")IEntity entity
26+
@NamedParam("e|effect") IEffect effect,
27+
@NamedParam("s|source") IEffectSourceProvider provider,
28+
@NamedParam("es|entity_source")IEntity entity
2729
) {
2830
effectService.addEffect(effect,provider, entity);
2931
}
3032

31-
@ScriptMeta.Function("remove_effect")
32-
public void removeEffect(@ScriptMeta.NamedParam("en|effect_name") String effect, @ScriptMeta.NamedParam("e|entity") IEntity target) {
33+
@Function("remove_effect")
34+
@Handler
35+
public void removeEffect(@NamedParam("en|effect_name") String effect,
36+
@NamedParam("e|entity") IEntity target) {
3337
if (target.hasEffect(effect)) {
3438
effectService.removeEffectContainer(target.getEffect(effect), target);
3539
}
3640
}
3741

38-
@ScriptMeta.Function("get_effect")
39-
public IEffectContainer getEffect(@ScriptMeta.NamedParam("en|effect_name") String effect, @ScriptMeta.NamedParam("e|entity") IEntity target) {
42+
@Function("get_effect")
43+
@Handler
44+
public IEffectContainer getEffect(@NamedParam("en|effect_name") String effect,
45+
@NamedParam("e|entity") IEntity target) {
4046
return target.getEffect(effect);
4147
}
4248

Common/src/main/java/cz/neumimto/rpg/common/scripting/mechanics/SkillCommons.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
import cz.neumimto.nts.annotations.ScriptMeta.NamedParam;
77
import cz.neumimto.rpg.common.entity.IEntity;
88
import cz.neumimto.rpg.common.entity.IEntityType;
9+
import cz.neumimto.rpg.common.logging.Log;
910
import cz.neumimto.rpg.common.skills.PlayerSkillContext;
1011
import jdk.jfr.Name;
1112

13+
import java.util.logging.Logger;
14+
1215
@AutoService(NTScriptProxy.class)
1316
public class SkillCommons implements NTScriptProxy {
1417

18+
private static Logger logger = Logger.getLogger("NTS-DEBUG");
19+
1520
@Handler
1621
@Function("config_value")
1722
public double configValue(
@@ -26,4 +31,16 @@ public double configValue(
2631
public boolean exists(@NamedParam("o|obj|var") Object o) {
2732
return o != null;
2833
}
34+
35+
@Handler
36+
@Function("print")
37+
public void print(@NamedParam("o|obj|var") Object o) {
38+
logger.info(String.valueOf(o));
39+
}
40+
41+
@Handler
42+
@Function("printd")
43+
public void printd(@NamedParam("d|n")double d) {
44+
logger.info(""+d);
45+
}
2946
}

Common/src/main/java/cz/neumimto/rpg/common/skills/SkillService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,21 @@ private void loadSkillDefinitionFile(Config config, ClassLoader urlClassLoader)
284284
public void loadSkillDefinitions(ClassLoader urlClassLoader, SkillsDefinition definition) {
285285
if (definition.effects != null) {
286286
definition.effects.stream()
287+
.peek(a-> Log.info("Compiling Effect " +a.id))
287288
.map(a -> EffectScriptGenerator.from(a, urlClassLoader))
288289
.filter(Objects::nonNull)
289290
.forEach(a->Rpg.get().getScriptEngine().STL.add(a));
290291
}
291292
if (definition.skills != null) {
292293
definition.skills.stream()
294+
.peek(a-> Log.info("Compiling Skill " +a.id))
293295
.map(a -> skillDefinitionToSkill(a, urlClassLoader))
294296
.filter(Objects::nonNull)
295297
.forEach(this::registerAdditionalCatalog);
296298
}
297299
if (definition.listeners != null) {
298300
definition.listeners.stream()
301+
.peek(a-> Log.info("Compiling Listener " +a.id))
299302
.map(a-> ListenerScriptGenerator.from(a, urlClassLoader))
300303
.filter(Objects::nonNull)
301304
.map(a->injector.getInstance(a))

Common/src/main/java/cz/neumimto/rpg/common/skills/scripting/EffectScriptGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
*
5656
* 1) Effect base class
5757
*
58+
* @SimpleName("Test")
5859
* public class Test{timestamp} extends UnstackableEffect {
5960
* public double Num;
6061
* public static Handler onApply;
@@ -89,6 +90,7 @@
8990
* }
9091
*
9192
* This proxy implementation is also automatically initialized with guice injector and its reference is injected into the static field
93+
*
9294
* Test{timestamp}.OnApply = injector.newInstance(HandlerTest{timestamp}.class)
9395
*
9496
* The timestamps are part of all classnames to ensure easy reloading at runtime, im not reimplementing osgi, just throw away old refs
@@ -117,7 +119,8 @@ public ClassVisitor wrap(TypeDescription instrumentedType, ClassVisitor classVis
117119
}
118120
})
119121
.name("cz.neumimto.rpg.generated.effects." + model.id + System.currentTimeMillis())
120-
.annotateType(AnnotationDescription.Builder.ofType(ScriptMeta.Function.class).define("value", model.id).build());
122+
.annotateType(AnnotationDescription.Builder.ofType(ScriptMeta.Function.class).define("value", model.id).build())
123+
.annotateType(AnnotationDescription.Builder.ofType(ScriptMeta.SimpleName.class).define("value", model.id).build());
121124

122125
for (Map.Entry<String, String> field : model.fields.entrySet()) {
123126
String value = field.getValue();
@@ -163,7 +166,7 @@ public ClassVisitor wrap(TypeDescription instrumentedType, ClassVisitor classVis
163166

164167
}
165168

166-
bb.make().saveIn(new File("/tmp"));
169+
// bb.make().saveIn(new File("/tmp"));
167170
Class<? extends EffectBase> loaded = bb.make()
168171
.load(classLoader, INJECTION)
169172
.getLoaded();

Common/src/main/resources/assets/nt-rpg/defaults/skills.conf

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,15 @@ Skills: [
248248
Id: "ntrpg:devourMagic"
249249
Handler: nts
250250
SuperType: Active
251-
Script """
251+
Script: """
252252
@duration = $settings.duration
253253
@multiplier = $settings.multiplier
254254

255255
@effect = DevourMagicEffect{}
256-
@effect.consumer=@caster
257-
@effect.duration=@duration
258-
@effect.multiplier=@multiplier
256+
@effect.consumer = @caster
257+
@effect.duration = @duration
258+
@effect.multiplier = @multiplier
259+
@effect.period = 1000
259260

260261
add_effect{effect=@effect, es=@caster, source=@this_skill}
261262

@@ -270,19 +271,28 @@ Effects: [
270271
Fields {
271272
multiplier: numeric
272273
}
274+
OnTick: """
275+
@consumer = @effect.consumer
276+
277+
RETURN
278+
"""
273279
}
274280
]
275281
Listeners: [
276282
{
277-
SuperType: IEntitySkillDamageLateEvent
283+
Id: InternalSkillListener
284+
Event: IEntitySkillDamageLateEvent
278285
Script: """
279286
@target = @event.target
280-
@effect = @target.getEffect{a="DevourMagicEffect"}
287+
@effect = get_effect{e=@target, en="DevourMagicEffect"} as DevourMagicEffect
281288
IF exists{var=@effect}
282-
@damage = event.damage
289+
@damage = @event.damage
283290
@mana = @effect.multiplier * @event.damage
291+
@event.damage = @damage - @mana
284292
regain_mana{e=@target, a=@mana, s=@effect}
285293
END
294+
295+
RETURN
286296
"""
287297
}
288298
]

Common/src/test/java/cz/neumimto/rpg/TestApiImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public class TestApiImpl implements RpgApi {
8989
@Inject
9090
private Injector injector;
9191

92+
public static List<Object> listeners = new ArrayList<>();
93+
9294
@Override
9395
public ResourceLoader getResourceLoader() {
9496
return resourceLoader;
@@ -173,12 +175,12 @@ public boolean postEvent(Object event) {
173175

174176
@Override
175177
public void unregisterListeners(Object listener) {
176-
178+
listeners.remove(listener);
177179
}
178180

179181
@Override
180182
public void registerListeners(Object listener) {
181-
183+
listeners.add(listener);
182184
}
183185

184186
@Override

0 commit comments

Comments
 (0)