public static function check($event = false) { require_once 'Cause.class.php'; require_once 'Effect.class.php'; global $conf; $causeManager = new Cause(); $effectManager = new Effect(); $causes = array(); $storyCauses = $causeManager->loadAll(array('story' => $event->story)); $validate = $event->story; foreach ($storyCauses as $storyCause) { switch ($storyCause->type) { case 'listen': if ($event->type == $storyCause->type) { if ($storyCause->value != $event->value) { $validate = false; } } break; case 'time': list($i, $h, $d, $m, $y) = explode('-', date('i-H-d-m-Y')); list($i2, $h2, $d2, $m2, $y2) = explode('-', $storyCause->value); if ($storyCause->value != $i . '-' . $h . '-' . $d . '-' . $m . '-' . $y) { $validate = false; } if (!(($i == $i2 || $i2 == '*') && ($h == $h2 || $h2 == '*') && ($d == $d2 || $d2 == '*') && ($m == $m2 || $m2 == '*') && ($y == $y2 || $y2 == '*'))) { $validate = false; } break; case 'readvar': if ($conf->get($storyCause->target, 'var') != $storyCause->value) { $validate = false; } break; } } if ($validate != false) { //consequences $effects = $effectManager->loadAll(array('story' => $event->story), 'sort'); foreach ($effects as $effect) { switch ($effect->type) { case 'command': exec($effect->value); break; case 'var': $conf->put($effect->target, $effect->value, 'var'); break; case 'actuator': file_get_contents('action.php?action=' . $effect->value); break; case 'sleep': if (is_numeric($effect->value)) { sleep($effect->value); } break; case 'talk': $clientManager = new Client(); $clients = $clientManager->populate(); foreach ($clients as $client) { $client->talk($effect->value); } break; } } } /* $manager = new Story(); //get all dictionnary values $query = ' SELECT * FROM plugin_story_cause WHERE story = (SELECT story.id FROM plugin_story story LEFT JOIN plugin_story_cause cause ON story.id = cause.story)'; $storyToCheck = array(); $results = $manager->customQuery($query); while($result = $results->fetchArray()){ $storyToCheck[$result['story']][] = $result; } if(count($storyToCheck)!=0){ foreach($storyToCheck as $story=>$causes){ //On part du principe que le scénario est validé tant qu'aucune cause manquante ne viens la contredire $activateStory = true; //On vas checker toutes les causes de ce scenario foreach($causes as $cause){ $validateCause = false; switch($cause['type']){ case 'listen': if($cause['value'] == $dic['lastphrase']) $validateCause = true; if($cause['operator']=='!=') $validateCause = !$validateCause; break; case 'readvar': break; case 'event': break; case 'time': list($i2,$h2,$d2,$m2,$y2) = explode('-',$cause['value']); if ( ($i == $i2 || $i2 == '*') && ($h == $h2 || $h2 == '*') && ($d == $d2 || $d2 == '*') && ($m == $m2 || $m2 == '*') && ($y == $y2 || $y2 == '*') ) $validateCause = true; if($cause['operator']=='!=') $validateCause = !$validateCause; break; } $activateStory = $activateStory && $validateCause; var_dump($cause); } if($activateStory) var_dump('story validated !'); } }*/ }
public function apply(GameState $state) { parent::apply($state); $state->playerMana += 101; }
function story_plugin_action() { global $_, $myUser; switch ($_['action']) { case 'plugin_story_get_type_template': Action::write(function ($_, &$response) { $templates = array_merge(Cause::types(), Effect::types()); $template = $templates[$_['type']]; preg_match_all("/(\\{)(.*?)(\\})/", $template['template'], $matches, PREG_SET_ORDER); foreach ($matches as $match) { $template['template'] = str_replace($match[0], $_['data'][$match[2]], $template['template']); } /* $matches = preg_split("/\[(.*?)\]/", $template['template'],-1,PREG_SPLIT_DELIM_CAPTURE); $tpl = ''; for($i=0;$i<count($matches);$i+=2){ $start = $matches[$i]; $var = $matches[$i+1]; list($name,$value) = explode(':',$var); if($_['data'][$name] == $value) { $tpl.= 'selected="selected"'; } $tpl.= $start; } $template['template'] = $tpl; */ $response['html'] = '<li class="line" data-type="' . $_['type'] . '"> <i class="fa ' . $template['icon'] . '"></i> <strong>' . $template['label'] . '</strong> ' . $template['template'] . ' <div class="delete"><i onclick="deleteLine(this);" class="fa fa-times"></i></div> </li>'; }, array()); break; case 'plugin_story_get_causes_effects': Action::write(function ($_, &$response) { $cause = new Cause(); $effect = new Effect(); $effects = $effect->loadAll(array('story' => $_['id']), 'sort'); $causes = $cause->loadAll(array('story' => $_['id']), 'sort'); foreach ($causes as $caus) { $data = $caus->getValues(); $response['results'][] = array('type' => $caus->type, 'panel' => "CAUSE", 'data' => array('value' => $data->value, 'target' => $data->target, 'operator' => $data->operator, 'union' => $data->union)); } foreach ($effects as $eff) { $data = $eff->getValues(); $response['results'][] = array('type' => $eff->type, 'panel' => "EFFECT", 'data' => array('value' => $data->value, 'target' => $data->target, 'operator' => $data->operator, 'union' => $data->union)); } }, array()); break; case 'plugin_story_get_captors_plugins': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'type' => Device::CAPTOR)); $response['plugins'] = array(); foreach ($devices as $device) { if (!isset($response['plugins'][$device->plugin])) { $response['plugins'][] = $device->plugin; } } }, array()); break; case 'plugin_story_get_captors': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'plugin' => $_['plugin'], 'type' => Device::CAPTOR)); foreach ($devices as $device) { $response['devices'][] = array('plugin' => $device->plugin, 'label' => $device->label, 'id' => $device->id); } }, array()); break; case 'plugin_story_get_captor_values': Action::write(function ($_, &$response) { $deviceManager = new Device(); $device = $deviceManager->getById($_['id']); $response['values'] = $device->getValues(); }, array()); break; case 'plugin_story_delete_story': Action::write(function ($_, &$response) { $storyManager = new Story(); $causeManager = new Cause(); $effectManager = new Effect(); $storyManager->delete(array('id' => $_['id'])); $causeManager->delete(array('story' => $_['id'])); $effectManager->delete(array('story' => $_['id'])); }, array()); break; case 'plugin_story_check': require_once dirname(__FILE__) . '/Cause.class.php'; $vocal = new Cause(); $vocal = $vocal->getById($_['event']); Story::check($vocal); break; case 'plugin_story_save_story': Action::write(function ($_, &$response) { $causeManager = new Cause(); $effectManager = new Effect(); $story = new Story(); if (isset($_['story']['id']) && $_['story']['id'] != '0') { $story = $story->getById($_['story']['id']); $causeManager->delete(array('story' => $story->id)); $effectManager->delete(array('story' => $story->id)); } $story->label = $_['story']['label']; $story->date = time(); $story->state = 1; $story->save(); $i = 0; foreach ($_['story']['causes'] as $cause) { $current = new Cause(); $current->type = $cause['type']; $current->operator = @$cause['operator']; $current->setValues($cause); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } $i = 0; foreach ($_['story']['effects'] as $effect) { $current = new Effect(); $current->type = $effect['type']; $current->setValues($effect); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } }, array()); break; } }
function story_plugin_action() { global $_, $myUser; switch ($_['action']) { case 'DELETE_STORY': $storyManager = new Story(); $causeManager = new Cause(); $effectManager = new Effect(); $storyManager->delete(array('id' => $_['id'])); $causeManager->delete(array('story' => $_['id'])); $effectManager->delete(array('story' => $_['id'])); break; case 'plugin_story_check': require_once 'Cause.class.php'; $vocal = new Cause(); $vocal = $vocal->getById($_['event']); Story::check($vocal); break; case 'SAVE_STORY': $causeManager = new Cause(); $effectManager = new Effect(); $story = new Story(); if (isset($_['story']['id']) && $_['story']['id'] != '0') { $story = $story->getById($_['story']['id']); $causeManager->delete(array('story' => $story->id)); $effectManager->delete(array('story' => $story->id)); } $story->label = $_['story']['label']; $story->date = time(); $story->state = 1; $story->save(); $i = 0; foreach ($_['story']['cause'] as $cause) { $current = new Cause(); $current->type = $cause['type']; $current->target = is_array(@$cause['target']) ? implode('|', @$cause['target']) : @$cause['target']; $current->operator = @$cause['operator']; $current->value = $cause['value']; $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } $i = 0; foreach ($_['story']['effect'] as $effect) { $current = new Effect(); $current->type = $effect['type']; $current->target = is_array(@$effect['target']) ? implode('|', @$effect['target']) : @$effect['target']; $current->value = $effect['value']; $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } break; } }
<?php $story = new Story(); $cause = new Cause(); $effect = new Effect(); $causes = array(); $effects = array(); if (isset($_['story'])) { $story = $story->getById($_['story']); $effects = $effect->loadAll(array('story' => $story->id), 'sort'); $causes = $cause->loadAll(array('story' => $story->id), 'sort'); } ?> <div class="story"> <h1>Nom : <input id="storyName" value="<?php echo $story->label; ?> " placeholder="Scénario 1"/></h1> <input type="hidden" id="story" value="<?php echo $story->id; ?> "> <h2> <span id="causePanelButton" class="active" onclick="switchCauseEffect('CAUSE');"><i class="fa fa-puzzle-piece"></i> Causes</span> / <span id="effectPanelButton" onclick="switchCauseEffect('EFFECT');"><i class="fa fa-bolt"></i> Effets</span> </h2> <div id="causePanel"> <ul class="toolbar"> <?php
public static function check($event = false) { require_once dirname(__FILE__) . '/Cause.class.php'; require_once dirname(__FILE__) . '/Effect.class.php'; global $conf; $causeManager = new Cause(); $effectManager = new Effect(); $causes = array(); $storyCauses = $causeManager->loadAll(array('story' => $event->story)); $validate = $event->story; foreach ($storyCauses as $storyCause) { switch ($storyCause->type) { case 'listen': if ($event->type == $storyCause->type) { if ($storyCause->value != $event->value) { $validate = false; } } break; case 'time': list($i, $h, $d, $m, $y) = explode('-', date('i-H-d-m-Y')); list($i2, $h2, $d2, $m2, $y2) = explode('-', $storyCause->value); if ($storyCause->value != $i . '-' . $h . '-' . $d . '-' . $m . '-' . $y) { $validate = false; } if (!(($i == $i2 || $i2 == '*') && ($h == $h2 || $h2 == '*') && ($d == $d2 || $d2 == '*') && ($m == $m2 || $m2 == '*') && ($y == $y2 || $y2 == '*'))) { $validate = false; } break; case 'readvar': if ($conf->get($storyCause->target, 'var') != $storyCause->value) { $validate = false; } break; } } if ($validate != false) { //consequences $effects = $effectManager->loadAll(array('story' => $event->story), 'sort'); foreach ($effects as $effect) { switch ($effect->type) { case 'command': exec($effect->value); break; case 'var': $conf->put($effect->target, $effect->value, 'var'); break; case 'actuator': file_get_contents('action.php?action=' . $effect->value); break; case 'sleep': if (is_numeric($effect->value)) { sleep($effect->value); } break; case 'talk': $clientManager = new Client(); $clients = $clientManager->populate(); foreach ($clients as $client) { $client->talk($effect->value); } break; } } } }
function story_plugin_action() { global $_, $myUser; switch ($_['action']) { case 'plugin_story_get_type_template': Action::write(function ($_, &$response) { $templates = array_merge(Cause::types(), Effect::types()); $template = $templates[$_['type']]; $response['html'] = '<li class="line" data-type="' . $_['type'] . '"> <i class="fa ' . $template['icon'] . '"></i> <strong>' . $template['label'] . '</strong> ' . $template['template'] . ' <div class="delete"><i onclick="deleteLine(this);" class="fa fa-times"></i></div> </li>'; }, array()); break; case 'plugin_story_get_captors_plugins': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'type' => Device::CAPTOR)); $response['plugins'] = array(); foreach ($devices as $device) { if (!isset($response['plugins'][$device->plugin])) { $response['plugins'][] = $device->plugin; } } }, array()); break; case 'plugin_story_get_captors': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'plugin' => $_['plugin'], 'type' => Device::CAPTOR)); foreach ($devices as $device) { $response['devices'][] = array('plugin' => $device->plugin, 'label' => $device->label, 'id' => $device->id); } }, array()); break; case 'plugin_story_get_captor_values': Action::write(function ($_, &$response) { $deviceManager = new Device(); $device = $deviceManager->getById($_['id']); $response['values'] = $device->getValues(); }, array()); break; case 'plugin_story_delete_story': Action::write(function ($_, &$response) { $storyManager = new Story(); $causeManager = new Cause(); $effectManager = new Effect(); $storyManager->delete(array('id' => $_['id'])); $causeManager->delete(array('story' => $_['id'])); $effectManager->delete(array('story' => $_['id'])); }, array()); break; case 'plugin_story_check': require_once dirname(__FILE__) . '/Cause.class.php'; $vocal = new Cause(); $vocal = $vocal->getById($_['event']); Story::check($vocal); break; case 'plugin_story_save_story': Action::write(function ($_, &$response) { $causeManager = new Cause(); $effectManager = new Effect(); $story = new Story(); if (isset($_['story']['id']) && $_['story']['id'] != '0') { $story = $story->getById($_['story']['id']); $causeManager->delete(array('story' => $story->id)); $effectManager->delete(array('story' => $story->id)); } $story->label = $_['story']['label']; $story->date = time(); $story->state = 1; $story->save(); $i = 0; foreach ($_['story']['causes'] as $cause) { $current = new Cause(); $current->type = $cause['type']; $current->operator = @$cause['operator']; $current->setValues($cause); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } $i = 0; foreach ($_['story']['effects'] as $effect) { $current = new Effect(); $current->type = $effect['type']; $current->setValues($effect); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } }, array()); break; } }
echo '<li data-type="' . $key . '" class="' . $key . '"><i class="fa ' . $type['icon'] . '"></i> ' . $type['label'] . '</li>'; } ?> <div class="clear"></div> </ul> <ul class="workspace"> <li class="union">SI</li> <li id="place-0" class="place"> </li> </ul> </div> <div id="effectPanel"> <ul class="toolbar"> <?php foreach (Effect::types() as $key => $type) { echo '<li data-type="' . $key . '" class="' . $key . '"><i class="fa ' . $type['icon'] . '"></i> ' . $type['label'] . '</li>'; } ?> <div class="clear"></div> </ul> <ul class="workspace"> <li class="union">ALORS</li> <li id="place-effect-0" class="place"> </li> </ul> </div> <div onclick="saveStory();" class="clear btn" style="margin-left:15px;cursor:pointer;"><i class="fa fa-check"></i> Enregistrer</div> </div>