Exemplo n.º 1
0
 public function caravan_send($config, $player, $town, $wood, $stone, $iron)
 {
     $town = textV($town);
     $wood = (int) $wood;
     $stone = (int) $stone;
     $iron = (int) $iron;
     if ($wood + $stone + $iron < 1) {
         $msg = 'wyślij minimum 1 sztukę jakiegoś surowca';
     } elseif ($player->clan_id == 0) {
         $msg = 'nie jesteś w klanie, karawany można wysyłać tylko do sojuszników w swoim klanie';
     } elseif ($player->town->t_wood < $wood || $player->town->t_stone < $stone || $player->town->t_iron < $iron) {
         $msg = 'nie posiadasz tyle surowców';
     } else {
         $can = get_row($q = "select clan_id, t_id from users inner join towns on t_usr_id = usr_id where t_name = '" . $town . "' limit 1");
         if (empty($can)) {
             $msg = 'takie miasto nie istnieje';
         } elseif ($can->clan_id != $player->clan_id) {
             $msg = 'te miasto nie jest w tym samym klanie co ty';
         } else {
             $event_check = get_one("select count(*) from events where (e_type = 20 or e_type = 21) and e_done = 0 and e_t_id = " . $player->actual_town);
             if ($event_check > 9) {
                 $msg = 'masz już maksymalną ilość karawan w podróży';
             } else {
                 $market_lvl = get_one("select go_lvl from game_objects where go_type = 1 and go_subtype = 6 and go_t_id = " . $player->actual_town);
                 if (empty($market_lvl)) {
                     $msg = 'nie posiadasz rynku, jak chcesz wysłać karawanę??';
                 } elseif ($market_lvl <= $event_check) {
                     $msg = 'masz już maksymalną ilość karawan w podróży';
                 } else {
                     $y = get_row("select * from map where m_t_id =" . $can->t_id);
                     $x = get_row("select * from map where m_t_id =" . $player->actual_town);
                     if ($x->m_x != $y->m_x && $x->m_y == $y->m_y) {
                         $range = abs($y->m_x - $x->m_x) * 300;
                     } elseif ($x->m_x == $y->m_x && $x->m_y != $y->m_y) {
                         $range = abs($y->m_y - $x->m_y) * 300;
                     } else {
                         $range = floor(sqrt(pow(abs($y->m_x - $x->m_x), 2) + pow(abs($y->m_y - $x->m_y), 2))) * 300;
                     }
                     call("insert into caravan(ca_from, ca_to, ca_wood, ca_stone, ca_iron)\n\t\t\t\t\t\t\tvalue(" . $player->actual_town . "," . $can->t_id . "," . $wood . "," . $stone . "," . $iron . ")");
                     $ca = get_row("select last_insert_id() as ca, unix_timestamp() as estart");
                     require_once 'functions/TownMgr.php';
                     $TownMgr = new TownMgr();
                     $TownMgr->change_resources($config, $player->actual_town, -$wood, -$stone, -$iron, 0);
                     require_once 'functions/EventsMgr.php';
                     $EventMgr = new EventsMgr();
                     $EventMgr->event_add($config, $player->actual_town, 20, $can->t_id, $ca->ca, 0, $ca->estart, $ca->estart + $range, 0);
                     $msg = 'wysłano karawanę do miasta ' . $town;
                 }
             }
         }
     }
     return $msg;
 }
Exemplo n.º 2
0
 public function colectors_send($config, $player, $town, $count)
 {
     $town = textV($town);
     $count = (int) $count;
     if ($count < 1) {
         $msg = 'wyślij minimum 1 zwiadowcę';
     } else {
         $can = get_row($q = "select go_lvl from game_objects where go_type = 3 and go_subtype = 8 and go_t_id =" . $player->actual_town);
         if (empty($can)) {
             $msg = 'nie posiadasz zbieraczy';
         } elseif ($can->go_lvl < $count) {
             $msg = 'nie posiadasz zbieraczy';
         } else {
             $event_check = get_one("select count(*) from events where (e_type = 70 or e_type = 71) and e_done = 0 and e_t_id = " . $player->actual_town);
             if ($event_check > 9) {
                 $msg = 'masz już maksymalną ilość wysłanych grup zbieraczy';
             } else {
                 $can = get_row("select t_id, t_usr_id from towns where t_name ='" . $town . "' limit 1");
                 if (empty($can)) {
                     $msg = 'nie ma takiego miasta';
                 } else {
                     $y = get_row("select * from map where m_t_id =" . $can->t_id);
                     $x = get_row("select * from map where m_t_id =" . $player->actual_town);
                     if ($x->m_x != $y->m_x && $x->m_y == $y->m_y) {
                         $range = abs($y->m_x - $x->m_x) * 300;
                     } elseif ($x->m_x == $y->m_x && $x->m_y != $y->m_y) {
                         $range = abs($y->m_y - $x->m_y) * 300;
                     } else {
                         $range = floor(sqrt(pow(abs($y->m_x - $x->m_x), 2) + pow(abs($y->m_y - $x->m_y), 2))) * 300;
                     }
                     $tnow = get_one("select unix_timestamp()");
                     call("update game_objects set go_lvl = go_lvl - {$count} where go_type = 3 and go_subtype = 8 and go_t_id =" . $player->actual_town);
                     call("insert into colectors (co_counts) value (" . $count . ")");
                     $id = get_one("select last_insert_id()");
                     require_once 'functions/EventsMgr.php';
                     $EventMgr = new EventsMgr();
                     $EventMgr->event_add($config, $player->actual_town, 70, $can->t_id, $id, 0, $tnow, $tnow + $range, 0);
                     $msg = 'wysłano wyprawę do miasta ' . $town;
                 }
             }
         }
     }
     return $msg;
 }
Exemplo n.º 3
0
 public function spell_cast($config, $player, $spell)
 {
     $spell = intV($spell);
     $can = get_row("select *, unix_timestamp() as tnow from arena_spells_param inner join arena_user_spells on usp_usr_id = " . $player->usr_id . " and usp_spp_id = " . $spell . " where spp_id = " . $spell . " limit 1");
     if (empty($can)) {
         $msg = 'nie ma takiego zaklęcia ';
     } elseif ($player->energy < $can->spp_energy) {
         $msg = 'za mało energii';
     } elseif ($can->usp_active == 1) {
         $msg = 'już aktywne';
     } else {
         call("update arena_user_spells set usp_active = 1 where usp_usr_id = " . $player->usr_id . " and usp_spp_id = " . $spell);
         call("update arena_users set energy =  energy - " . $can->spp_energy . " where usr_id = " . $player->usr_id);
         $this->add_stats($config, $player, $can->spp_attack, $can->spp_defence, $can->spp_absorb, $can->spp_life_max, $can->spp_energy_max, $can->spp_life_inc, $can->spp_energy_inc, $can->spp_dam_min, $can->spp_dam_max);
         require_once 'funkcje/EventsMgr.php';
         $EventsMgr = new EventsMgr();
         $EventsMgr->event_add($config, $player->usr_id, 1, $spell, 0, $can->tnow, $can->tnow + $can->spp_time, 0);
         $msg = 'rzucono zaklęcie';
     }
     return $msg;
 }
Exemplo n.º 4
0
 public function build($config, $player, $type, $subtype, $count)
 {
     //mini walidacja, wszystkie dane powinny być liczbowe
     $type = (int) $type;
     $subtype = (int) $subtype;
     $count = (int) $count;
     //jeżeli w dziwny nie wiadomy sposób przesłano ilość mniejszą niż 1 to ustaw = 1
     if ($count < 1) {
         $count = 1;
     }
     //jeżeli budujemy coś innego niż jdnostkę to ilość = 1
     if ($type != 3) {
         $count = 1;
     }
     //ustaw nr błędu = 1 /nieokreślony
     $error = 1;
     //pobierz dane obiektu
     $object = get_row("\n\t\t\tselect * from game_objects_param \n\t\t\tleft join game_objects \n\t\t\ton go_t_id = " . $player->actual_town . "\n\t\t\tand go_gop_id = gop_id\n\t\t\twhere gop_type = " . $type . " and gop_subtype = " . $subtype . "\n\t\t\tlimit 1\n\t\t");
     //jeżeli obiektu nie ma na liście obiektów wybudowanych, to bierz pod uwagę parametry startowe
     if (empty($object->go_id)) {
         if (!empty($object->gop_id)) {
             $object->go_wood = $object->gop_wood;
             $object->go_stone = $object->gop_stone;
             $object->go_iron = $object->gop_iron;
             $object->go_pop = $object->gop_pop;
             $object->go_time = $object->gop_time;
             $object->go_lvl = 0;
         } else {
             //jeżeli w ogóle nie ma takiego obiektu ustaw error = 2
             $error = 2;
         }
     }
     //jeżeli obiekt to jednostka to ustaw max_lvl > lvl (de facto sprawdzane potem, bo przy jednostce nie ma limitów)
     if ($type == 3) {
         $object->gop_max_lvl = $object->go_lvl + 1;
     }
     //jeżeli nie wywaliło erroru 2
     if ($error == 1) {
         $object->go_wood = $object->go_wood * $count;
         $object->go_stone = $object->go_stone * $count;
         $object->go_iron = $object->go_iron * $count;
         $object->go_pop = $object->go_pop * $count;
         $object->go_time = $object->go_time * $count;
         if ($player->town->t_wood < $object->go_wood || $player->town->t_iron < $object->go_iron || $player->town->t_stone < $object->go_stone || $player->town->t_pop_max - $player->town->t_pop < $object->go_pop) {
             //jeżeli za mało surowców ustaw error = 3
             $error = 3;
         } else {
             if ($object->go_lvl == $object->gop_max_lvl) {
                 //jeżeli osiągnięto poziom maksymalny ustaw error = 4
                 $error = 4;
             } else {
                 //jeżeli nie to pobierz ilość aktywnych zdarzeń w kolejce dla danego typu
                 $events_check = get_one("select count(*) from events where e_t_id = " . $player->actual_town . " and e_type = " . $type . " and e_done = 0");
                 // w zależności od typu ustaw limit kolejki
                 switch ($type) {
                     case 1:
                         $max_events = 3;
                         break;
                         //budynki
                     //budynki
                     case 2:
                         $max_events = 2;
                         break;
                         //technologie
                     //technologie
                     case 3:
                         $max_events = 5;
                         break;
                         //jednostki
                     //jednostki
                     default:
                         $max_events = 0;
                         break;
                 }
                 $isbuild = get_one("select count(*) from events where e_t_id = " . $player->actual_town . " and e_type = " . $type . " and e_done = 0 and e_subtype = " . $subtype . "");
                 if ($events_check >= $max_events) {
                     //jeżeli osiągnięto limit kolejki dla danego typu  ustaw error = 5
                     $error = 5;
                 } elseif ($isbuild > 0) {
                     $error = 6;
                 } else {
                     //pobierz ostatni wykonywany element w kolejce
                     $last_event_time = get_one("select e_end from events where e_t_id = " . $player->actual_town . " and e_type = " . $type . " and e_done = 0 order by e_id desc");
                     $utime = get_one("select unix_timestamp()");
                     //jeżeli jest coś w kolejce to ustaw odpowiednio czas
                     if (!empty($last_event_time)) {
                         $start = $last_event_time;
                         $end = $object->go_time + $last_event_time;
                     } else {
                         $start = $utime;
                         $end = $utime + $object->go_time;
                     }
                     //dodaj element do kolejki
                     require_once 'functions/EventsMgr.php';
                     $event = new EventsMgr();
                     $event->event_add($config, $player->actual_town, $type, $subtype, $count, 0, $start, $end, 0);
                     //odejmij surowce
                     require_once 'functions/TownMgr.php';
                     $town = new TownMgr();
                     $town->change_resources($config, $player->actual_town, -$object->go_wood, -$object->go_stone, -$object->go_iron, $object->go_pop);
                     //zwróć error = 0 /nie ma błędu
                     $error = 0;
                 }
             }
         }
     }
     return $error;
 }
Exemplo n.º 5
0
 public function army_send($config, $player, $town, $units)
 {
     $town = textV($town);
     $sum = 0;
     foreach ($units as $unit) {
         $unit = (int) $unit;
         $sum += $unit;
     }
     if ($sum < 1) {
         $msg = 'wyślij minimum 1 jednostkę';
     } else {
         $check = count($units);
         foreach ($units as $key => $value) {
             $can = get_row("select * from game_objects where go_type = 3 and go_subtype = {$key} and go_t_id =" . $player->actual_town . " and go_lvl >= {$value}");
             if (!empty($can)) {
                 $check--;
             }
             $units1[$key]->data = $can;
             $units1[$key]->count = $value;
         }
         if ($check != 0) {
             $msg = 'nie posiadasz tyle jednostek';
         } else {
             $event_check = get_one("select count(*) from events where (e_type = 30 or e_type = 31) and e_done = 0 and e_t_id = " . $player->actual_town);
             if ($event_check > 9) {
                 $msg = 'masz już maksymalną ilość wysłanych wypraw wojskowych';
             } else {
                 $can = get_row("select t_id, t_usr_id from towns where t_name ='" . $town . "' limit 1");
                 if (empty($can)) {
                     $msg = 'nie ma takiego miasta';
                 } elseif ($can->t_usr_id == $player->usr_id) {
                     $msg = 'nie atakuj swojego miasta';
                 } else {
                     $y = get_row("select * from map where m_t_id =" . $can->t_id);
                     $x = get_row("select * from map where m_t_id =" . $player->actual_town);
                     if ($x->m_x != $y->m_x && $x->m_y == $y->m_y) {
                         $range = abs($y->m_x - $x->m_x) * 300;
                     } elseif ($x->m_x == $y->m_x && $x->m_y != $y->m_y) {
                         $range = abs($y->m_y - $x->m_y) * 300;
                     } else {
                         $range = floor(sqrt(pow(abs($y->m_x - $x->m_x), 2) + pow(abs($y->m_y - $x->m_y), 2))) * 300;
                     }
                     $tnow = get_one("select unix_timestamp()");
                     call("insert into army (a_t_id, a_vs_id) value (" . $player->actual_town . "," . $can->t_id . ")");
                     $army_id = get_one("select last_insert_id()");
                     $insert = "insert into army_units(au_a_id, au_gop_subtype, au_counts, au_attack, au_defence, au_life, au_range) values ";
                     foreach ($units1 as $unit) {
                         call("update game_objects set go_lvl = go_lvl - " . $unit->count . " where go_type = 3 and go_subtype = " . $unit->data->go_subtype . " and go_t_id =" . $player->actual_town);
                         $insert .= "(" . $army_id . "," . $unit->data->go_subtype . "," . $unit->count . "," . $unit->data->go_attack . "," . $unit->data->go_defence . "," . $unit->data->go_life . "," . $unit->data->go_range . "),";
                     }
                     $insert = substr($insert, 0, -1);
                     call($insert);
                     require_once 'functions/EventsMgr.php';
                     $EventMgr = new EventsMgr();
                     $EventMgr->event_add($config, $player->actual_town, 30, $can->t_id, $army_id, 0, $tnow, $tnow + $range, 0);
                     $msg = 'wysłano wyprawę do miasta ' . $town;
                 }
             }
         }
     }
     return $msg;
 }