Loading item from module using Groovy

This commit is contained in:
Song Minjae
2017-04-26 23:53:22 +09:00
parent 05c9c8f5df
commit 49d3c9f55b
27 changed files with 291 additions and 67 deletions

View File

@@ -1,9 +1,10 @@
# Load order
# Load Order
# Modules are loaded from top to bottom.
# And yes, you can disable basegame, but we don't recommend.
# Acceptable formats:
# module_name,description_in_English_no_comma,
# module_name,description_in_English_no_comma,(external Jar 1);(external Jar 2); ...
# module_name,description_in_English_no_comma,(entry_point.kts),(external Jars sep'd by semicolon)...
# If entry_point is not given, the program will try to run <modulename>.kts.
# if even that does not exist, an the program will quit with error.
# and yes, you can disable basegame, but we don't recommend.
basegame,The base game,
dwarventech,Dwarven technicians are emerged,
basegame,The base game,basegame.groovy,
dwarventech,Dwarven technicians are emerged from their hiding,,
1 # Load order # Load Order
2 # Modules are loaded from top to bottom. # Modules are loaded from top to bottom.
# And yes, you can disable basegame, but we don't recommend.
3 # Acceptable formats: # Acceptable formats:
4 # module_name,description_in_English_no_comma, # module_name,description_in_English_no_comma,(entry_point.kts),(external Jars sep'd by semicolon)...
5 # module_name,description_in_English_no_comma,(external Jar 1);(external Jar 2); ... # If entry_point is not given, the program will try to run <modulename>.kts.
6 # if even that does not exist, an the program will quit with error.
7 # and yes, you can disable basegame, but we don't recommend.
8 basegame,The base game, basegame,The base game,basegame.groovy,
9 dwarventech,Dwarven technicians are emerged, dwarventech,Dwarven technicians are emerged from their hiding,,
10

View File

@@ -0,0 +1 @@
print "Hello, world!"

View File

@@ -0,0 +1,9 @@
import net.torvald.terrarum.ModMgr
/**
* Created by SKYHi14 on 2017-04-26.
*/
static void invoke(String module) {
ModMgr.GameItemLoader.invoke(module)
}

View File

@@ -1,2 +1,2 @@
"id";"filename"
"8448";"testpick.lua"
"8448";"testpick.groovy"
1 id filename
2 8448 testpick.lua testpick.groovy

View File

@@ -0,0 +1,97 @@
/**
* Created by SKYHi14 on 2017-04-26.
*/
import net.torvald.point.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.tileproperties.Tile
import org.jetbrains.annotations.NotNull
import org.newdawn.slick.GameContainer
static InventoryItem invoke(int id) {
return new TestPick(id)
}
class TestPick extends InventoryItem {
int originalID
int dynamicID
String originalName = "GROOVY_PICK"
double baseMass = 10.0
Double baseToolSize = 10.0
boolean stackable = true
int maxDurability = 147
float durability = maxDurability
int equipPosition = 9 //EquipPosition.HAND_GRIP
String inventoryCategory = "tool" //Category.TOOL
// !! TEST MATERIAL !!
Material material = new Material(0,0,0,0,0,0,0,0,1,0.0)
TestPick(int id) {
originalID = id
dynamicID = id
name = "Groovy Pickaxe"
}
@Override
boolean isUnique() {
return false
}
@Override
boolean isDynamic() {
return true
}
@Override
boolean primaryUse(@NotNull GameContainer gc, int delta) {
int mouseTileX = Terrarum.getMouseTileX()
int mouseTileY = Terrarum.getMouseTileY()
def mousePoint = new Point2d(mouseTileX, mouseTileY)
def actorvalue = Terrarum.ingame.player.actorValue
using = true
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
// return false if hitting actors
Terrarum.ingame.actorContainer.forEach({
if (it instanceof ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint))
return false
})
// return false if here's no tile
if (Tile.AIR == Terrarum.ingame.world.getTileFromTerrain(mouseTileX, mouseTileY))
return false
// filter passed, do the job
double swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)
Terrarum.ingame.world.inflictTerrainDamage(
mouseTileX, mouseTileY,
Calculate.pickaxePower(Terrarum.ingame.player, material) * swingDmgToFrameDmg
)
return true
}
@Override
boolean endPrimaryUse(@NotNull GameContainer gc, int delta) {
using = false
// reset action timer to zero
Terrarum.ingame.player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
return true
}
}

View File

@@ -6,10 +6,14 @@
"argn"; "9"; "0.91";"argentum/silver"
"stal"; "14"; "1.73";"steel"
"eaur"; "21"; "1.36";"elven aurichalcum"
"tial"; "33"; "2.16";"titanium alloy"
"tial"; "33"; "2.16";"titanium alloy (Ti6Al4V)"
"admt"; "71"; "3.42";"adamant"
# idst: ID_STRING
# forcemod: related to attack points
# Attack points = `4 * forcemod.sqrt()` for each strike
# endurance: multiplier, using copper as reference; determines durability of tools/weapons/armours/etc.
# Comments: do nothing; do not parse
1 idst forcemod endurance comments
6 argn 9 0.91 argentum/silver
7 stal 14 1.73 steel
8 eaur 21 1.36 elven aurichalcum
9 tial 33 2.16 titanium alloy titanium alloy (Ti6Al4V)
10 admt 71 3.42 adamant
11 # forcemod: related to attack points # idst: ID_STRING
12 # forcemod: related to attack points
13 # Attack points = `4 * forcemod.sqrt()` for each strike
14 # Attack points = `4 * forcemod.sqrt()` for each strike # endurance: multiplier, using copper as reference determines durability of tools/weapons/armours/etc.
15 # endurance: multiplier, using copper as reference # Comments: do nothing determines durability of tools/weapons/armours/etc. do not parse
16
17
18
19

View File

@@ -0,0 +1,3 @@
println("Hello, world!!")
return 42