last version
This commit is contained in:
parent
62e0ced2a4
commit
da1372cb5d
4 changed files with 75 additions and 14 deletions
|
@ -3,6 +3,9 @@ import org.eclipse.smarthome.model.script.ScriptServiceUtil
|
|||
|
||||
val mqttActions = getActions("mqtt", "mqtt:broker:mainBroker")
|
||||
val TAG_FileName = "battlefield.rules"
|
||||
val hp_init = 20 as Number
|
||||
val last_roll = 0 as Number
|
||||
val concurent_roll = 0 as Number
|
||||
|
||||
|
||||
rule "Démarrage de openHAB"
|
||||
|
@ -10,7 +13,8 @@ when
|
|||
System started
|
||||
then
|
||||
logInfo(TAG_FileName, "Rule : Démarrage de openHAB")
|
||||
// il n'y a personne dans la pièce et l'éclairage est fermé
|
||||
|
||||
hp.postUpdate(hp_init)
|
||||
mqttActions = getActions("mqtt", "mqtt:broker:mainBroker")
|
||||
|
||||
animation_toggle.sendCommand(ON)
|
||||
|
@ -20,9 +24,7 @@ rule "light toggle"
|
|||
when
|
||||
Item animation_toggle received command
|
||||
then
|
||||
logInfo(TAG_FileName, "Rule : mqtt evts")
|
||||
logInfo(TAG_FileName, "item animation_toggle changed to " +
|
||||
animation_toggle.state)
|
||||
logInfo(TAG_FileName, "WHAT " + animation_toggle.state)
|
||||
|
||||
mqttActions.publishMQTT("lumiere/degat/toggle",
|
||||
animation_toggle.state.toString(), false)
|
||||
|
@ -33,10 +35,58 @@ rule "light animation"
|
|||
when
|
||||
Item animation received command
|
||||
then
|
||||
logInfo(TAG_FileName, "Rule : mqtt evts")
|
||||
logInfo(TAG_FileName, "item animation changed to " +
|
||||
animation.state)
|
||||
|
||||
mqttActions.publishMQTT("lumiere/degat/animation",
|
||||
animation.state.toString(), false)
|
||||
end
|
||||
|
||||
rule "update hp"
|
||||
when
|
||||
Item dmg received update
|
||||
then
|
||||
val current_roll = dmg.state as Number
|
||||
if(current_roll == last_roll){
|
||||
concurent_roll = concurent_roll + 1
|
||||
val Number current_dmg
|
||||
logInfo(TAG_FileName, "HP: IF: concurent_roll = " + concurent_roll)
|
||||
current_dmg = current_roll * Math.pow(2, (concurent_roll as Number).floatValue)
|
||||
val current_hp = hp.state as Number
|
||||
hp.postUpdate(current_hp - current_dmg)
|
||||
}
|
||||
else{
|
||||
last_roll = current_roll
|
||||
concurent_roll = 0
|
||||
logInfo(TAG_FileName, "HP: ELSE")
|
||||
var new_val = hp.state as Number
|
||||
hp.postUpdate(new_val - dmg.state)
|
||||
}
|
||||
end
|
||||
|
||||
rule "die"
|
||||
when
|
||||
Item hp changed
|
||||
then
|
||||
if((hp.state as Number) <= 0){
|
||||
animation.sendCommand("mort")
|
||||
hp.sendCommand(0)
|
||||
}
|
||||
else if(concurent_roll >= 1){
|
||||
animation.sendCommand("coup critique")
|
||||
}
|
||||
else{
|
||||
animation.sendCommand("degat")
|
||||
}
|
||||
end
|
||||
|
||||
rule "reset"
|
||||
when
|
||||
Item reset changed to ON
|
||||
then
|
||||
concurent_roll = 0
|
||||
last_roll = 0
|
||||
hp.postUpdate(hp_init)
|
||||
dmg.postUpdate(0)
|
||||
reset.postUpdate(OFF)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue