last version

This commit is contained in:
theBigBlase 2023-12-21 18:21:32 -05:00
parent 62e0ced2a4
commit da1372cb5d
4 changed files with 75 additions and 14 deletions

View file

@ -1,6 +1,3 @@
Group Room
Group SmartClothes
Group Sensors
Group:Number Cam "Last roll" (Sensors)
@ -12,6 +9,12 @@ Number dmg "dernier degat" (Cam, Sensors){
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){
channel="Channel='mqtt:topic:lumiere'"
}

View file

@ -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

View file

@ -1,7 +1,12 @@
sitemap battlefield label="My home automation" {
Frame label="Battlefield" {
Text item=dmg label="Last Dmg [%s]"
Group item=Actuators icon="light"
Switch item=reset
sitemap battlefield label="Battlefield" {
Frame label="Sensors" {
Text item=dmg label="Dernier dégat infligé [%s]" icon="fire"
Text item=hp label="Point de vie restant : [%s]" icon="fire"
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"
}
}

View file

@ -14,7 +14,10 @@ Thing mqtt:topic:lumiere "lumiere" (mqtt:broker:mainBroker) {
Thing mqtt:topic:de "lecteur de" (mqtt:broker:mainBroker) {
Channels:
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"
]
}