last version
This commit is contained in:
parent
62e0ced2a4
commit
da1372cb5d
4 changed files with 75 additions and 14 deletions
|
@ -1,6 +1,3 @@
|
||||||
Group Room
|
|
||||||
Group SmartClothes
|
|
||||||
|
|
||||||
Group Sensors
|
Group Sensors
|
||||||
Group:Number Cam "Last roll" (Sensors)
|
Group:Number Cam "Last roll" (Sensors)
|
||||||
|
|
||||||
|
@ -12,6 +9,12 @@ Number dmg "dernier degat" (Cam, Sensors){
|
||||||
channel="Channel='mqtt:topic:de'"
|
channel="Channel='mqtt:topic:de'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Number hp "Points de vie"
|
||||||
|
|
||||||
|
Image dmg_img "Image du de" (Cam, Sensors){
|
||||||
|
channel="Channel='mqtt:topic:de'"
|
||||||
|
}
|
||||||
|
|
||||||
Switch animation_toggle "toggle animation degat" (Lights){
|
Switch animation_toggle "toggle animation degat" (Lights){
|
||||||
channel="Channel='mqtt:topic:lumiere'"
|
channel="Channel='mqtt:topic:lumiere'"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@ import org.eclipse.smarthome.model.script.ScriptServiceUtil
|
||||||
|
|
||||||
val mqttActions = getActions("mqtt", "mqtt:broker:mainBroker")
|
val mqttActions = getActions("mqtt", "mqtt:broker:mainBroker")
|
||||||
val TAG_FileName = "battlefield.rules"
|
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"
|
rule "Démarrage de openHAB"
|
||||||
|
@ -10,7 +13,8 @@ when
|
||||||
System started
|
System started
|
||||||
then
|
then
|
||||||
logInfo(TAG_FileName, "Rule : Démarrage de openHAB")
|
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")
|
mqttActions = getActions("mqtt", "mqtt:broker:mainBroker")
|
||||||
|
|
||||||
animation_toggle.sendCommand(ON)
|
animation_toggle.sendCommand(ON)
|
||||||
|
@ -20,9 +24,7 @@ rule "light toggle"
|
||||||
when
|
when
|
||||||
Item animation_toggle received command
|
Item animation_toggle received command
|
||||||
then
|
then
|
||||||
logInfo(TAG_FileName, "Rule : mqtt evts")
|
logInfo(TAG_FileName, "WHAT " + animation_toggle.state)
|
||||||
logInfo(TAG_FileName, "item animation_toggle changed to " +
|
|
||||||
animation_toggle.state)
|
|
||||||
|
|
||||||
mqttActions.publishMQTT("lumiere/degat/toggle",
|
mqttActions.publishMQTT("lumiere/degat/toggle",
|
||||||
animation_toggle.state.toString(), false)
|
animation_toggle.state.toString(), false)
|
||||||
|
@ -33,10 +35,58 @@ rule "light animation"
|
||||||
when
|
when
|
||||||
Item animation received command
|
Item animation received command
|
||||||
then
|
then
|
||||||
logInfo(TAG_FileName, "Rule : mqtt evts")
|
|
||||||
logInfo(TAG_FileName, "item animation changed to " +
|
logInfo(TAG_FileName, "item animation changed to " +
|
||||||
animation.state)
|
animation.state)
|
||||||
|
|
||||||
mqttActions.publishMQTT("lumiere/degat/animation",
|
mqttActions.publishMQTT("lumiere/degat/animation",
|
||||||
animation.state.toString(), false)
|
animation.state.toString(), false)
|
||||||
end
|
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
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
sitemap battlefield label="My home automation" {
|
sitemap battlefield label="Battlefield" {
|
||||||
Frame label="Battlefield" {
|
Frame label="Sensors" {
|
||||||
Text item=dmg label="Last Dmg [%s]"
|
Text item=dmg label="Dernier dégat infligé [%s]" icon="fire"
|
||||||
Group item=Actuators icon="light"
|
Text item=hp label="Point de vie restant : [%s]" icon="fire"
|
||||||
Switch item=reset
|
Switch item=reset label="Forcer le prochain tour"
|
||||||
|
Image item=dmg_img icon="light" label="Dernier lancé :"
|
||||||
|
}
|
||||||
|
Frame label="Actuators" {
|
||||||
|
Text item=animation label="Dernière animation [%s]" icon="siren"
|
||||||
|
Switch item=animation_toggle label="Activer les animations"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,10 @@ Thing mqtt:topic:lumiere "lumiere" (mqtt:broker:mainBroker) {
|
||||||
Thing mqtt:topic:de "lecteur de" (mqtt:broker:mainBroker) {
|
Thing mqtt:topic:de "lecteur de" (mqtt:broker:mainBroker) {
|
||||||
Channels:
|
Channels:
|
||||||
Type number : de "effecteur degat" [
|
Type number : de "effecteur degat" [
|
||||||
stateTopic="capteur/de/degat/dernierLance"
|
stateTopic="capteur/de/degat/dernierLanceDmg"
|
||||||
|
]
|
||||||
|
Type string : img "nouvelle image" [
|
||||||
|
stateTopic="capteur/de/degat/dernierLanceImg"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue