<?php
class AreaController extends BaseController {
public function indexAction() {
//$this->view->disable();
$actions = LocationsActions::find();
foreach($actions as $action){
$line = LocationLines::FindFirst([
'conditions' => 'action = ?1 AND action_ = ?2 AND action_ <> ?1',
'bind' => [1 => $this->auth->user->action, 2 => $action->id]
]);
if($action->id !== $this->auth->user->action and $line) $arr[$action->id] = [
'top' => (($action->left / 222) * 100),
'left' => (($action->top / 300) * 100)
];
}
$this->view->setVars([
'user' => $this->auth->user,
'arr' => $arr
]);
}
public function newActionAction() {
$this->view->disable();
$act = $this->dispatcher->getParam('act');
$location = Locations::findFirstById(1);
$action = LocationsActions::findFirstById($act);
$line = LocationLines::findFirst([
'conditions' => 'action = ?1 AND action_ = ?2',
'bind' => [1 => $this->auth->user->action, 2 => $act]
]);
if($line && $action && $action->location == $location->id ){
if($action->type == 3){
$__user = $this->auth->user;
$__user->area = 0;
$__user->put = 0;
$__user->round = 1;
$__user->attack = 1;
$__user->save();
$mob = Monsters::findFirstById($action->monster);
$check = Attack::findFirstByUser($this->auth->user->id);
if($mob and !$check){
$__attack = new Attack();
$__attack->user = $this->auth->user->id;
$__attack->location = 1;
$__attack->mob = $mob->id;
$__attack->hp = $mob->hp;
$__attack->effect = 0;
$__attack->time = time();
$__attack->kill = 0;
$__attack->save();
$_area = Area::find();
$areas = Areas::find();
foreach ($areas as $area) {
$dash[$area->x][$area->y] = $area->area;
}
$randi = rand(2,4);
for ($i>0; $i<$randi; ++$i) {
while (true) {
$area = $_area[rand(0,5)];
if ($area->chanse >= rand(1, 100)) {
$rand = $area->id == 6 ? 5 : $area->id;
break;
}
}
$x = rand(0,2);
$y = rand(0,2);
$check = Areas::findFirst([
'columns' => 'x,y',
'conditions' => 'user = ?1 AND x = ?2 AND y = ?3',
'bind' => [1 => $this->auth->user->id, 2 => $x, 3 => $y]
]);
if(!$check and count($this->functions->check($x, $y, $dash)) < 3){
$__areas = new Areas();
$__areas->user = $this->auth->user->id;
$__areas->x = $x;
$__areas->y = $y;
$__areas->area = $rand;
$__areas->save();
}
else{
--$i;
}
}
}
}
}
$this->response->redirect('area/action/');
}
public function actionAction() {
$areas = Areas::find([
'conditions' => 'user = ?1',
'bind' => [1 => $this->auth->user->id]
]);
foreach ($areas as $area) $dash[$area->x][$area->y] = $area->area;
for ($y = 0; $y < 3; ++$y) {
for ($x = 0; $x < 3; ++$x) {
if(!$dash[$x][$y]){
$left = [
0 => 23.47417840375587,
1 => 41.78403755868545,
2 => 60.09389671361502,
];
$top = [
0 => 25,
1 => 48.71794871794872,
2 => 73.07692307692308,
];
$arr[$x.'_'.$y] = [
'top' => $top[$y],
'left' => $left[$x]
];
}
}
}
$this->view->setVars([
'user' => $this->auth->user,
'arr' => $arr
]);
//$this->view->disable();
}
}