Ran a code formatter on most of the old php to fix indents in vscode.

This commit is contained in:
Relintai 2021-11-14 11:02:22 +01:00
parent 8cd215e0f1
commit aa2664c200
42 changed files with 8688 additions and 9167 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,21 +2,20 @@
class Alliance extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function index()
public function index()
{
}
function alliance_menu()
public function alliance_menu()
{
$this->headers('alliance');
$this->footer();
}
}
//nowhitesp

View File

@ -2,40 +2,37 @@
class Building extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function index($id)
public function index($id)
{
$this->load->helper('url');
redirect('building/stats/' .$id);
}
function stats($slotid = 0)
{
if (!$slotid)
public function stats($slotid = 0)
{
if (!$slotid) {
$this->load->helper($url);
redirect('village/selected');
}
$this->headers('do', $slotid);
if ($this->building['id'] == 1)
{
if ($this->building['id'] == 1) {
$this->load->helper('url');
redirect('building/build');
}
if ($this->building['id'] == 2)
{
if ($this->building['id'] == 2) {
//build_in_progress
$this->headers('build_in_progress');
$event = $this->_filter_events('type', 'slotid', $slotid, 0, TRUE);
$event = $this->_filter_events('type', 'slotid', $slotid, 0, true);
$data['event'] = $event;
$data['building'] = $this->building_model->get_building($event['data1']);
@ -59,10 +56,9 @@ class Building extends MO_Controller
$this->footer();
}
function upgrade($slotid = 0)
{
if (!$slotid)
public function upgrade($slotid = 0)
{
if (!$slotid) {
$this->load->helper('url');
redirect('village/selected');
}
@ -73,28 +69,28 @@ class Building extends MO_Controller
$up['slotid'] = $slotid;
if ($this->building['next_rank'])
{
if ($this->building['next_rank']) {
$up['slotid'] = $slotid;
$up['nextrank'] = $this->building_model->get_building(
$this->building['next_rank']);
$this->building['next_rank']
);
$up['upgrade'] = $this->building_model->can_be_upgraded(
$event,
$this->resources,
$up['nextrank'],
$this->villageid);
$this->villageid
);
}
$this->load->view('building/upgrade', $up);
$this->footer();
}
function create($slotid = 0)
{
if (!$slotid)
public function create($slotid = 0)
{
if (!$slotid) {
$this->load->helper($url);
redirect('village/selected');
}
@ -102,38 +98,40 @@ class Building extends MO_Controller
$this->headers('building', $slotid);
//can create something
if ($this->building['creates'])
{
if ($this->building['creates']) {
$events = $this->_filter_events('type', 'all', $slotid, 2);
$this->load->model('unit_model');
$data['unit'] = $this->unit_model->get_unit($this->building['creates']);
if ($data['unit']['cost_unit'])
if ($data['unit']['cost_unit']) {
$data['costu'] = $this->unit_model->get_unit(
$data['unit']['cost_unit']);
else
$data['costu'] = FALSE;
$data['unit']['cost_unit']
);
} else {
$data['costu'] = false;
}
$this->load->model('resource_model');
//This should be one function
$data['maxunit'] = $this->resource_model->calc_max_unit($data['unit'],
$data['maxunit'] = $this->resource_model->calc_max_unit(
$data['unit'],
$this->building['num_creates'],
$this->resources);
$this->resources
);
$data['maxunit'] = $this->unit_model->calc_max_unit_ev(
$this->building['num_creates'],
$data['maxunit'],
$events);
$events
);
if ($events)
{
if ($events) {
$d['event'] = $events;
$this->load->view('building/events', $d);
}
}
$data['building'] = $this->building;
@ -142,10 +140,9 @@ class Building extends MO_Controller
$this->footer();
}
function assign($slotid)
{
if (!$slotid)
public function assign($slotid)
{
if (!$slotid) {
$this->load->helper($url);
redirect('village/selected');
}
@ -155,9 +152,11 @@ class Building extends MO_Controller
//have assignments
$this->load->model('assignment_model');
$assign = $this->assignment_model->get_assignments($slotid,
$assign = $this->assignment_model->get_assignments(
$slotid,
$this->villageid,
$this->userid);
$this->userid
);
$assign['slotid'] = $slotid;
@ -166,10 +165,9 @@ class Building extends MO_Controller
$this->footer();
}
function spells($slotid)
{
if (!$slotid)
public function spells($slotid)
{
if (!$slotid) {
$this->load->helper($url);
redirect('village/selected');
}
@ -178,8 +176,10 @@ class Building extends MO_Controller
$this->load->model('spell_model');
$spell['spells'] = $this->spell_model->get_spells($slotid,
$this->villageid);
$spell['spells'] = $this->spell_model->get_spells(
$slotid,
$this->villageid
);
$spell['slotid'] = $slotid;
@ -187,10 +187,9 @@ class Building extends MO_Controller
$this->footer();
}
function events($slotid = 0)
{
if (!$slotid)
public function events($slotid = 0)
{
if (!$slotid) {
$this->load->helper($url);
redirect('village/selected');
}
@ -208,10 +207,9 @@ class Building extends MO_Controller
$this->footer();
}
function research($slotid = 0)
{
if (!$slotid)
public function research($slotid = 0)
{
if (!$slotid) {
$this->load->helper('url');
redirect('village/selected');
}
@ -220,20 +218,19 @@ class Building extends MO_Controller
$events = $this->_filter_events('type', 'slot', $slotid, 4);
if (!$events)
{
if (!$events) {
$this->load->model('technology_model');
$data = $this->technology_model->get_researchable($slotid,
$this->villageid);
$data = $this->technology_model->get_researchable(
$slotid,
$this->villageid
);
$data['slotid'] = $slotid;
$this->load->view('building/research', $data);
}
else
{
} else {
$this->load->model('technology_model');
$data['technology'] = $this->technology_model->get_technology($events[0]['data1']);
@ -242,13 +239,11 @@ class Building extends MO_Controller
}
$this->footer();
}
function build($slotid = 0)
{
if (!$slotid)
public function build($slotid = 0)
{
if (!$slotid) {
$this->load->helper('url');
redirect('village/selected');
}
@ -259,18 +254,16 @@ class Building extends MO_Controller
$this->headers('build');
if ($this->building['id'] == 1)
{
if ($this->building['id'] == 1) {
//empty space
$data['buildings'] = $this->building_model->building_list(
$this->villageid);
$this->villageid
);
$data['slotid'] = $slotid;
$this->load->view('building/list', $data);
}
else
{
} else {
//slot has some building
$this->load->helper('url');
redirect('building/stats/' . $slotid);
@ -279,15 +272,16 @@ class Building extends MO_Controller
$this->footer();
}
function dobuild()
public function dobuild()
{
$this->load->helper('url');
$slotid = $this->input->post('slotid');
$buildingid = $this->input->post('id');
if (!$slotid || !$buildingid)
if (!$slotid || !$buildingid) {
redirect('village/selected');
}
$this->headers('do');
@ -296,8 +290,7 @@ class Building extends MO_Controller
$this->load->model('resource_model');
//check if building exists
if (!$this->building_model->is_valid_slot($slotid, $this->villageid))
{
if (!$this->building_model->is_valid_slot($slotid, $this->villageid)) {
//display error page
echo "is_valid_slot returned FALSE";
return;
@ -305,8 +298,7 @@ class Building extends MO_Controller
$building = $this->building_model->get_building($buildingid);
if (!$this->building_model->check_resources($this->resources, $building))
{
if (!$this->building_model->check_resources($this->resources, $building)) {
//display error page
echo "You don't have enough resources";
return;
@ -331,8 +323,7 @@ class Building extends MO_Controller
*/
//can be built
if (!$this->building_model->has_req_tech($building['req_tech'], $this->villageid))
{
if (!$this->building_model->has_req_tech($building['req_tech'], $this->villageid)) {
echo "Technology requirements not met.";
return;
}
@ -350,8 +341,10 @@ class Building extends MO_Controller
//resource substract
$this->resource_model->set_resources($this->resources);
$this->resource_model->substract_resources($building,
$this->villageid);
$this->resource_model->substract_resources(
$building,
$this->villageid
);
$this->resource_model->write_resources();
//change tile to build in progress
@ -359,27 +352,29 @@ class Building extends MO_Controller
$url = 'building/stats/' . $slotid;
redirect($url);
}
function docreate($slotid)
public function docreate($slotid)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('create_num', 'Number to create',
'is_natural_no_zero');
$this->form_validation->set_rules(
'create_num',
'Number to create',
'is_natural_no_zero'
);
$this->load->helper('url');
$url = 'building/create/' . $slotid;
$this->headers('do', $slotid);
if ($this->form_validation->run())
{
if ($this->form_validation->run()) {
$num_create = $this->input->post('create_num');
if (!$num_create)
if (!$num_create) {
redirect($url);
}
$this->load->model('building_model');
@ -387,15 +382,13 @@ class Building extends MO_Controller
$this->headers('do');
if ($building['id'] == 1 || $building['id'] == 2)
{
if ($building['id'] == 1 || $building['id'] == 2) {
//TODO show proper error
echo "There isn't any building in that slot";
return;
}
if (!$building['creates'])
{
if (!$building['creates']) {
//TODO show proper error
echo "that building can't create units";
return;
@ -409,23 +402,25 @@ class Building extends MO_Controller
$this->load->model('unit_model');
$unit = $this->unit_model->get_unit($building['creates']);
$max = $this->resource_model->calc_max_unit($unit,
$max = $this->resource_model->calc_max_unit(
$unit,
$building['num_creates'],
$res);
$res
);
$max = $this->unit_model->calc_max_unit_ev($building['num_creates'],
$max = $this->unit_model->calc_max_unit_ev(
$building['num_creates'],
$max,
$event);
$event
);
if (!$max)
{
if (!$max) {
//TODO proper error
echo "You can't make any";
return;
}
if ($num_create > $max)
{
if ($num_create > $max) {
//TODO proper error
echo "You can't make that many";
return;
@ -444,21 +439,21 @@ class Building extends MO_Controller
$this->event_model->add_event($ev);
$this->resource_model->set_resources($this->resources);
$this->resource_model->substract_resources($unit,
$this->resource_model->substract_resources(
$unit,
$this->villageid,
$num_create);
$num_create
);
$this->resource_model->write_resources();
redirect($url);
}
else
{
} else {
redirect($url);
}
}
function doupgrade()
public function doupgrade()
{
$this->headers('do');
@ -467,8 +462,7 @@ class Building extends MO_Controller
$this->form_validation->set_rules('slotid', 'Slotid', 'is_natural');
if ($this->form_validation->run())
{
if ($this->form_validation->run()) {
$this->load->model('event_model');
$this->load->model('resource_model');
$this->load->model('building_model');
@ -479,8 +473,7 @@ class Building extends MO_Controller
$building = $this->building;
if (!$building['next_rank'])
{
if (!$building['next_rank']) {
echo "Building doesn't have next rank.";
return;
}
@ -491,11 +484,14 @@ class Building extends MO_Controller
$event = $this->_filter_events('type', 'slot', $slotid, 1);
$can = $this->building_model->can_be_upgraded($event, $res, $next_rank,
$this->villageid);
$can = $this->building_model->can_be_upgraded(
$event,
$res,
$next_rank,
$this->villageid
);
if ($can == 3)
{
if ($can == 3) {
//can be upgraded
$this->load->helper('event');
@ -510,40 +506,33 @@ class Building extends MO_Controller
$this->event_model->add_event($ev);
$this->resource_model->set_resources($this->resources);
$this->resource_model->substract_resources($next_rank,
$this->villageid);
$this->resource_model->substract_resources(
$next_rank,
$this->villageid
);
$this->resource_model->write_resources();
$url = 'building/upgrade/' . $slotid;
redirect($url);
}
elseif ($can == 1)
{
} elseif ($can == 1) {
echo "Village doesn't have the required technology.";
return;
}
elseif ($can == 2)
{
} elseif ($can == 2) {
//not enough resources
echo "Not enough resources";
return;
}
else
{
} else {
//upgrading in progress
echo "Upgrade already in progress.";
return;
}
}
else
{
} else {
redirect('village/selected');
}
}
function doassign()
public function doassign()
{
$this->headers('do');
@ -551,44 +540,48 @@ class Building extends MO_Controller
$this->form_validation->set_rules('num_assign', 'Assigned number', 'is_natural');
$this->form_validation->set_rules('slotid', 'slotid', 'required|is_natural');
$this->form_validation->set_rules('assignmentid', 'Assignmentid',
'required|is_natural');
$this->form_validation->set_rules(
'assignmentid',
'Assignmentid',
'required|is_natural'
);
if ($this->form_validation->run())
{
if ($this->form_validation->run()) {
$assid = $this->input->post('assignmentid');
$slotid = $this->input->post('slotid');
$num_assign = $this->input->post('num_assign');
$this->load->model('assignment_model');
$a = $this->assignment_model->assign_unit($assid, $num_assign, $slotid, $this->resources,
$this->villageid, $this->userid);
$a = $this->assignment_model->assign_unit(
$assid,
$num_assign,
$slotid,
$this->resources,
$this->villageid,
$this->userid
);
//error handling with return value
if ($a == 1)
{
if ($a == 1) {
//no building in that slot
echo "No building in that slot";
return;
}
if ($a == 2)
{
if ($a == 2) {
//no such assignmentid
echo "No such assignmentid";
return;
}
if ($a == 3)
{
if ($a == 3) {
//building soesn't have that assignment
echo "Building doesn't have that assignment";
return;
}
if ($a == 4)
{
if ($a == 4) {
echo "You don't have any units that can be assigned in that slot";
return;
}
@ -596,15 +589,13 @@ class Building extends MO_Controller
$this->load->helper('url');
redirect('building/assign/' . $slotid);
}
else
{
} else {
$this->load->helper('url');
redirect('village/selected');
}
}
function dospell()
public function dospell()
{
$this->headers('do');
@ -613,31 +604,31 @@ class Building extends MO_Controller
$this->form_validation->set_rules('spellid', 'spellid', 'required|is_natural');
$this->form_validation->set_rules('slotid', 'slotid', 'required|is_natural');
if ($this->form_validation->run())
{
if ($this->form_validation->run()) {
$spellid = $this->input->post('spellid');
$slotid = $this->input->post('slotid');
$this->load->model('spell_model');
$a = $this->spell_model->use_spell($spellid, $slotid, $this->resources,
$this->villageid);
$a = $this->spell_model->use_spell(
$spellid,
$slotid,
$this->resources,
$this->villageid
);
//error handling with return value
if ($a == 1)
{
if ($a == 1) {
echo "Building doesn't have that spell";
return;
}
if ($a == 2)
{
if ($a == 2) {
echo "spell is on cooldown";
return;
}
if ($a == 3)
{
if ($a == 3) {
echo "Not enough resources";
return;
}
@ -646,57 +637,56 @@ class Building extends MO_Controller
$this->load->helper('url');
redirect('building/spells/' . $slotid);
}
else
{
} else {
$this->load->helper('url');
redirect('village/selected');
}
}
function doresearch()
public function doresearch()
{
$this->load->helper('url');
$slotid = $this->input->post('slotid');
$techid = $this->input->post('id');
if (!($slotid || $techid))
if (!($slotid || $techid)) {
redirect('village/selected');
}
$this->headers('do');
$event = $this->_filter_events('type', 'slot', $slotid, 4);
if ($event)
if ($event) {
echo "Already researching.";
}
$this->load->model('technology_model');
$a = $this->technology_model->do_research($techid, $this->resources, $slotid,
$this->villageid);
$a = $this->technology_model->do_research(
$techid,
$this->resources,
$slotid,
$this->villageid
);
if ($a == 1)
{
if ($a == 1) {
echo "Technology ID doesn't exist";
return;
}
if ($a == 2)
{
if ($a == 2) {
echo "Not enough resources";
return;
}
if ($a == 3)
{
if ($a == 3) {
echo "Building doesn't have that technology, or you already have it";
return;
}
redirect('building/research/' . $slotid);
}
}
//nowhitesp

View File

@ -2,13 +2,12 @@
class Changelog extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function show()
public function show()
{
$this->load->model('changelog_model');
@ -22,21 +21,19 @@ class Changelog extends MO_Controller
$this->footer();
}
function add_new_version()
public function add_new_version()
{
if (!$this->userlevel > 4)
if (!$this->userlevel > 4) {
show404();
}
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->load->view('changelog/new_version');
}
else
{
} else {
$this->load->model('changelog_model');
$text = $this->input->post('text');
@ -45,24 +42,21 @@ class Changelog extends MO_Controller
$this->load->helper('url');
redirect('changelog/show');
}
}
function add_new_commit()
public function add_new_commit()
{
if (!$this->userlevel > 4)
if (!$this->userlevel > 4) {
show404();
}
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->load->view('changelog/new_commit');
}
else
{
} else {
$this->load->model('changelog_model');
$text = $this->input->post('text');
@ -71,7 +65,6 @@ class Changelog extends MO_Controller
$this->load->helper('url');
redirect('changelog/show');
}
}
}

View File

@ -3,12 +3,12 @@ class Cron extends CI_Controller
{
//no session stuff needed for this class, so it extends from CI_Controller.
function __construct()
public function __construct()
{
parent::__construct();
}
function aiattack()
public function aiattack()
{
//check for useragent and stuff like that
@ -18,6 +18,5 @@ class Cron extends CI_Controller
echo $a;
}
}
//nowhitesp

View File

@ -2,12 +2,12 @@
class Forum extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function index()
public function index()
{
$this->headers('forum');
@ -15,6 +15,5 @@ class Forum extends MO_Controller
$this->footer();
}
}
//nowhitesp

View File

@ -2,12 +2,12 @@
class Gm extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function gm_panel()
public function gm_panel()
{
$this->headers('gm');

View File

@ -2,31 +2,29 @@
class Hero extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct('hero');
}
function index()
public function index()
{
$this->load->helper('url');
redirect('hero/selected');
}
function selected($page = 'stats', $d1 = FALSE, $d2 = FALSE, $d3 = FALSE, $d4 = FALSE)
public function selected($page = 'stats', $d1 = false, $d2 = false, $d3 = false, $d4 = false)
{
$this->headers('hero');
if ($page != 'stats' && $page != 'inventory' && $page != 'talents' && $page != 'spells' &&
$page != 'actionbars')
{
$page != 'actionbars') {
$page = 'stats';
}
$this->load->view('hero/hero_menu');
if ($page == 'stats')
{
if ($page == 'stats') {
$data['hero'] = $this->hero;
$data['hpp'] = floor(($this->hero['health'] / $this->hero['max_health']) * 100);
@ -37,22 +35,20 @@ class Hero extends MO_Controller
$data['experience'] = 10000;
$this->load->view('hero/stats', $data);
}
elseif ($page == 'inventory')
{
} elseif ($page == 'inventory') {
$this->load->model('item_model');
if ($d1 !== FALSE && $d2 !== FALSE && $d3 !== FALSE && $d4 !== FALSE)
{
if ($d1 !== false && $d2 !== false && $d3 !== false && $d4 !== false) {
$this->item_model->set_hero($this->hero);
$res['message'] = $this->item_model->swap($d1, $d2, $d3, $d4);
if ($res['message'] === TRUE)
if ($res['message'] === true) {
$this->hero = $this->item_model->get_hero();
}
$d1 = FALSE;
$d2 = FALSE;
$d1 = false;
$d2 = false;
//we doesn't care about d3,d4 that isn't used in views
}
@ -64,25 +60,19 @@ class Hero extends MO_Controller
$data['d1'] = $d1;
$data['d2'] = $d2;
$res['inventory'] = $this->load->view('hero/inventory', $data, TRUE);
$res['equipment'] = $this->load->view('hero/character', $data, TRUE);
$res['inventory'] = $this->load->view('hero/inventory', $data, true);
$res['equipment'] = $this->load->view('hero/character', $data, true);
$this->load->view('hero/inventory_view', $res);
}
elseif ($page == 'talents')
{
}
elseif ($page == 'spells')
{
}
elseif ($page == 'actionbars')
{
} elseif ($page == 'talents') {
} elseif ($page == 'spells') {
} elseif ($page == 'actionbars') {
}
$this->footer();
}
function create()
public function create()
{
$this->load->library('form_validation');
@ -91,16 +81,13 @@ class Hero extends MO_Controller
//less than!
$this->form_validation->set_rules('class', 'Class', 'required|integer|greater_than[0]|less_than[10]');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->headers('hero', 1);
$this->load->view('hero/create');
$this->footer();
}
else
{
} else {
$this->load->model('hero_model');
$data['name'] = $this->input->post('name');
@ -114,15 +101,14 @@ class Hero extends MO_Controller
}
}
function select()
public function select()
{
$this->load->model('hero_model');
$this->load->library('form_validation');
$this->form_validation->set_rules('heroid', 'Heroid', 'required');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->headers('hero');
$data['heroes'] = $this->hero_model->get_heroes($this->userid);
@ -130,9 +116,7 @@ class Hero extends MO_Controller
$this->load->view('hero/select', $data);
$this->footer();
}
else
{
} else {
$heroid = $this->input->post('heroid');
$this->hero_model->select_hero($heroid, $this->userid);
@ -142,72 +126,68 @@ class Hero extends MO_Controller
}
}
function delete($id = FALSE)
public function delete($id = false)
{
$this->load->helper('url');
if (!$id || !is_numeric($id))
if (!$id || !is_numeric($id)) {
redirect('hero/select');
}
$this->load->model('hero_model');
$this->load->library('form_validation');
$this->form_validation->set_rules('confirm', 'Confirm', 'required|callback_delete_check');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$data['id'] = $id;
$data['hero'] = $this->hero_model->get_hero($id, $this->userid);
if (!$data['hero'])
if (!$data['hero']) {
redirect('hero/select');
}
$this->headers('hero');
$this->load->view('hero/delete_confirm', $data);
$this->footer();
}
else
{
} else {
$this->hero_model->delete_hero($id, $this->userid);
redirect('hero/select');
}
}
function addstat()
public function addstat()
{
//hero's stat view calls this with a form the hidden field's name is attrid
//1 agi, 2 str, 3 stam, 4 int, 5 spirit
}
function chhn($name)
public function chhn($name)
{
$this->load->model('hero_model');
$a = $this->hero_model->hero_name_is_unique($name);
if (!$a)
{
if (!$a) {
$this->form_validation->set_message('chhn', 'Name already taken.');
return FALSE;
}
else
{
return TRUE;
return false;
} else {
return true;
}
}
function delete_check($chk)
public function delete_check($chk)
{
if ($chk == "DELETE")
return TRUE;
if ($chk == "DELETE") {
return true;
}
$this->form_validation->set_message('delete_check', 'You have to spell DELETE, exactly, and uppercase.');
return FALSE;
return false;
}
}
//nowhitesp

View File

@ -2,18 +2,18 @@
class Mail extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function index()
public function index()
{
$this->load->helper('url');
redirect('mail/inbox');
}
function inbox()
public function inbox()
{
$this->headers('mail');
@ -26,16 +26,15 @@ class Mail extends MO_Controller
$this->footer();
}
function compose($id = 0)
public function compose($id = 0)
{
$this->headers('mail');
$this->load->model('mail_model');
$this->load->library('form_validation');
$d['draft'] = FALSE;
$d['draft'] = false;
if ($id && is_numeric($id))
{
if ($id && is_numeric($id)) {
$d['draft'] = $this->mail_model->get_draft($id, $this->userid);
}
@ -43,12 +42,9 @@ class Mail extends MO_Controller
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->load->view('mail/new', $d);
}
else
{
} else {
$send = $this->input->post('send');
$draft = $this->input->post('draft');
@ -56,12 +52,9 @@ class Mail extends MO_Controller
$data['subject'] = $this->input->post('subject');
$data['message'] = $this->input->post('message');
if ($send)
{
if ($send) {
$this->mail_model->send_message($data, $this->userid);
}
else
{
} else {
$this->mail_model->save_draft($data, $this->userid);
}
}
@ -69,10 +62,9 @@ class Mail extends MO_Controller
$this->footer();
}
function del_draft($id = 0)
{
if ($id && is_numeric($id))
public function del_draft($id = 0)
{
if ($id && is_numeric($id)) {
$this->load->model("mail_model");
$this->mail_model->delete_draft($id, $this->userid);
}
@ -81,7 +73,7 @@ class Mail extends MO_Controller
redirect('mail/drafts');
}
function drafts()
public function drafts()
{
$this->load->model('mail_model');
@ -94,10 +86,9 @@ class Mail extends MO_Controller
$this->footer();
}
function read($id = 0)
{
if (!$id || !is_numeric($id))
public function read($id = 0)
{
if (!$id || !is_numeric($id)) {
$this->load->helper('url');
redirect('mail/inbox');
}
@ -111,10 +102,9 @@ class Mail extends MO_Controller
$this->load->view('mail/read', $data);
$this->footer();
}
function sent()
public function sent()
{
$this->headers('mail');
@ -127,10 +117,9 @@ class Mail extends MO_Controller
$this->footer();
}
function sread($id = 0)
{
if (!$id || !is_numeric($id))
public function sread($id = 0)
{
if (!$id || !is_numeric($id)) {
$this->load->helper('url');
redirect('mail/inbox');
}
@ -144,10 +133,9 @@ class Mail extends MO_Controller
$this->load->view('mail/sread', $data);
$this->footer();
}
function friends()
public function friends()
{
$this->headers('mail');
@ -155,10 +143,3 @@ class Mail extends MO_Controller
}
}
//nowhitesp

View File

@ -4,15 +4,16 @@ class News extends MO_Controller
{
public function index($page = 1)
{
if (!$this->check_login()) return;
if (!$this->check_login()) {
return;
}
$this->load->model('news_model');
$data['admin'] = FALSE;
$data['admin'] = false;
if ($this->userlevel > 3)
{
$data['admin'] = TRUE;
if ($this->userlevel > 3) {
$data['admin'] = true;
}
$data['news'] = $this->news_model->get_news($page);
@ -24,45 +25,37 @@ class News extends MO_Controller
public function add()
{
if ($this->userlevel < 3) show_404();
if ($this->userlevel < 3) {
show_404();
}
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->load->helper(array('form', 'url'));
$this->headers();
$this->load->view('news/add');
$this->footer();
}
else
{
} else {
$this->load->model('news_model');
if ($this->news_model->add_news($this->input->post('text'), $this->username))
{
if ($this->news_model->add_news($this->input->post('text'), $this->username)) {
$this->load->view('news/add_success');
}
else
{
} else {
$this->load->view('db_error');
}
}
}
public function delete($nid)
{
if (!$this->userlevel < 3) show_404();
if (!$this->userlevel < 3) {
show_404();
}
}
}
//nowhitesp

View File

@ -2,13 +2,12 @@
class User extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function login()
public function login()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
@ -18,57 +17,62 @@ class User extends MO_Controller
//xss_validation
//TODO figure rules out
$this->form_validation->set_rules('username', 'Username',
'required');
$this->form_validation->set_rules(
'username',
'Username',
'required'
);
//password callback -> $this->input->post('username'), after xss filter
$this->form_validation->set_rules('password', 'Password',
'required|callback_login_check');
$this->form_validation->set_rules(
'password',
'Password',
'required|callback_login_check'
);
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == false) {
$this->load->view('login/login');
}
else
{
} else {
$this->load->helper('url');
redirect('news/index');
//$this->load->view('login/success');
}
}
function register()
public function register()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
//is_unique[users.username]
//xss_clean
$this->form_validation->set_rules('username', 'Username',
'required|min_length[4]|max_length[32]|callback_register_username_check');
$this->form_validation->set_rules(
'username',
'Username',
'required|min_length[4]|max_length[32]|callback_register_username_check'
);
$this->form_validation->set_rules('password', 'Password',
'required|min_length[5]|matches[password_check]');
$this->form_validation->set_rules(
'password',
'Password',
'required|min_length[5]|matches[password_check]'
);
$this->form_validation->set_rules('password_check', 'Password check', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|matches[email_check]');
$this->form_validation->set_rules('email_check', 'Email_check', 'required');
//$this->form_validation->set_rules('license', 'License', 'required');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == false) {
$this->load->view('register/register');
}
else
{
if ($this->register_write())
{
} else {
if ($this->register_write()) {
$this->load->view('register/success');
}
}
}
function logout()
public function logout()
{
$this->session->unset_userdata('userid');
@ -79,22 +83,19 @@ class User extends MO_Controller
//$this->load->view('redirect_to_login');
}
function register_username_check($attr)
public function register_username_check($attr)
{
$this->load->model('user_model');
if ($this->user_model->reg_username_check($attr))
{
return TRUE;
}
else
{
if ($this->user_model->reg_username_check($attr)) {
return true;
} else {
$this->form_validation->set_message('register_username_check', 'Username already exists!');
return FALSE;
return false;
}
}
function register_write()
public function register_write()
{
$data['username'] = $this->input->post('username');
$data['password'] = md5($this->input->post('password'));
@ -105,27 +106,26 @@ class User extends MO_Controller
return $this->user_model->reg_write($data);
}
function login_check($attr)
public function login_check($attr)
{
$data['username'] = $this->input->post('username');
$data['password'] = md5($attr);
$this->load->model('user_model');
if ($this->user_model->login_check($data))
{
$this->session->set_userdata('userid',
$this->user_model->get_userid($data['username']));
if ($this->user_model->login_check($data)) {
$this->session->set_userdata(
'userid',
$this->user_model->get_userid($data['username'])
);
return TRUE;
}
else
{
return FALSE;
return true;
} else {
return false;
}
}
function settings()
public function settings()
{
$this->headers('settings');
@ -133,7 +133,6 @@ class User extends MO_Controller
$this->footer();
}
}//login class
//nowhitesp

View File

@ -2,26 +2,26 @@
class Village extends MO_Controller
{
function __construct()
public function __construct()
{
parent::__construct();
}
function index()
public function index()
{
$this->load->helper('url');
redirect('village/selected');
}
//function for testing, this will be handled when registering, and with npcs
function create_village()
public function create_village()
{
$this->load->model('village_model');
$this->village_model->create_village($this->userid, $this->username);
}
function selected()
public function selected()
{
$this->load->model('village_model');
@ -36,37 +36,30 @@ class Village extends MO_Controller
$this->footer();
}
function map($x = FALSE, $y = FALSE)
public function map($x = false, $y = false)
{
$this->load->model('map_model');
$action = $this->input->post('action');
if ($action == 'xy')
{
if ($action == 'xy') {
$px = $this->input->post('x');
$py = $this->input->post('y');
if (is_numeric($px) && is_numeric($py))
{
if (is_numeric($px) && is_numeric($py)) {
$x = $px;
$y = $py;
}
}
elseif ($action == 'name')
{
} elseif ($action == 'name') {
$name = $this->input->post('name');
$rep = array(';', "\"", "'", ',', '(', ')');
$name = str_replace($rep, ' ', $name);
if ($name)
{
if ($name) {
$co = $this->map_model->get_village_by_name($name);
if ($co)
{
if ($co) {
$x = $co['X'];
$y = $co['Y'];
}
@ -75,26 +68,27 @@ class Village extends MO_Controller
$this->load->model('map_model');
if (!$x && !$y)
{
if (!$x && !$y) {
$coords = $this->map_model->get_village_coords($this->villageid);
$x = $coords['X'];
$y = $coords['Y'];
}
else
{
if ($x < 7)
} else {
if ($x < 7) {
$x = 7;
}
if ($y < 7)
if ($y < 7) {
$y = 7;
}
if ($x > 235)
if ($x > 235) {
$x = 235;
}
if ($y > 235)
if ($y > 235) {
$y = 235;
}
}
$data['x'] = $x;
$data['y'] = $y;
@ -107,7 +101,7 @@ class Village extends MO_Controller
$this->footer();
}
function units()
public function units()
{
$this->load->model('unit_model');
@ -120,21 +114,20 @@ class Village extends MO_Controller
$this->footer();
}
function log($action = 'list', $id = 0)
public function log($action = 'list', $id = 0)
{
if ($action != 'list' && $action != 'view' && $action != 'delete')
if ($action != 'list' && $action != 'view' && $action != 'delete') {
$action = 'list';
}
if (!is_numeric($id))
{
if (!is_numeric($id)) {
$action = 'list';
$id = 0;
}
$this->load->model('log_model');
if ($action == 'list')
{
if ($action == 'list') {
$this->headers('village');
$data['logs'] = $this->log_model->get_combat_logs($this->villageid);
@ -143,8 +136,7 @@ class Village extends MO_Controller
$this->footer();
}
if ($action == 'view')
{
if ($action == 'view') {
$this->headers('village');
$data['log'] = $this->log_model->get_combat_log($id, $this->villageid);
@ -153,8 +145,7 @@ class Village extends MO_Controller
$this->footer();
}
if ($action == 'delete')
{
if ($action == 'delete') {
$this->log_model->delete_combat_log($id, $this->villageid);
$this->load->helper('url');
@ -162,15 +153,14 @@ class Village extends MO_Controller
}
}
function select()
public function select()
{
$this->load->model('village_model');
$this->load->library('form_validation');
$this->form_validation->set_rules('id', 'ID', 'is_natural|required');
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->headers('village');
$data['villages'] = $this->village_model->get_villages($this->userid);
@ -178,9 +168,7 @@ class Village extends MO_Controller
$this->load->view('village/select', $data);
$this->footer();
}
else
{
} else {
$id = $this->input->post('id');
$this->village_model->select_village($id, $this->userid);
@ -190,7 +178,7 @@ class Village extends MO_Controller
}
}
function events()
public function events()
{
$this->headers('village');
@ -201,31 +189,31 @@ class Village extends MO_Controller
$this->footer();
}
function settings($id = 0)
public function settings($id = 0)
{
$this->load->model('village_model');
if (!is_numeric($id) || !$id)
{
if (!is_numeric($id) || !$id) {
$this->load->heper('url');
redirect('village/selected');
}
$village = $this->village_model->get_village($id);
if ($village['userid'] != $this->userid)
{
if ($village['userid'] != $this->userid) {
$this->load->heper('url');
redirect('village/selected');
}
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name',
'required|alpha|is_unique[ai_villages.name]');
$this->form_validation->set_rules(
'name',
'Name',
'required|alpha|is_unique[ai_villages.name]'
);
if (!$this->form_validation->run())
{
if (!$this->form_validation->run()) {
$this->headers('village');
$data['id'] = $id;
@ -233,9 +221,7 @@ class Village extends MO_Controller
$this->load->view('village/settings', $data);
$this->footer();
}
else
{
} else {
$data['id'] = $id;
$name = $this->input->post('name');
$data['ai'] = $this->input->post('ai');
@ -249,14 +235,13 @@ class Village extends MO_Controller
}
}
function event_update()
public function event_update()
{
//TODO for ajax, but maybe it will be solved with APE
}
function list_all()
public function list_all()
{
}
}
//nowhitesp

View File

@ -21,12 +21,12 @@ class MO_Controller extends CI_Controller
public $new_log;
function __construct($page = 'village')
public function __construct($page = 'village')
{
parent::__construct();
$this->weather = FALSE;
$this->resources = FALSE;
$this->hero = FALSE;
$this->weather = false;
$this->resources = false;
$this->hero = false;
$this->_manage_session($page);
}
@ -43,21 +43,20 @@ class MO_Controller extends CI_Controller
$this->language = 'english';
if ($this->session->userdata('userid'))
if ($this->session->userdata('userid')) {
$this->userid = $this->session->userdata('userid');
}
$this->load->model('mo_common_model');
if ($this->userid)
{
if ($this->userid) {
$data = $this->mo_common_model->get_userdata($this->userid);
$this->userlevel = $data['userlevel'];
$this->username = $data['username'];
$this->new_mail = $data['new_mail'];
if ($page == 'village')
{
if ($page == 'village') {
$mdata = $this->mo_common_model->get_village_data($this->userid);
$this->villageid = $mdata['id'];
@ -67,8 +66,7 @@ class MO_Controller extends CI_Controller
$this->village_data = $mdata;
}
if ($page == 'hero')
{
if ($page == 'hero') {
$this->hero = $this->mo_common_model->get_hero_data($this->userid);
}
}
@ -76,13 +74,12 @@ class MO_Controller extends CI_Controller
public function check_login()
{
if ($this->userid == 0)
{
if ($this->userid == 0) {
$this->load->helper('url');
redirect('user/login');
}
return TRUE;
return true;
}
public function headers($page = 'village', $slotid = 0)
@ -93,23 +90,21 @@ class MO_Controller extends CI_Controller
$data['newmail'] = $this->new_mail;
$data['page'] = $page;
if ($page != 'hero')
{
if ($page != 'hero') {
$data['villagename'] = $this->villagename;
$data['newlog'] = $this->new_log;
if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' ||
$page == 'mail')
{
$page == 'mail') {
$this->_update();
}
//this has to be done like this, since this function will redirect if nothing in the slot
if ($page == 'building')
if ($page == 'building') {
$this->_get_slot_building($slotid);
}
if ($page != 'do')
{
if ($page != 'do') {
$data['weather'] = $this->weather;
$data['resources'] = $this->_prep_res_js();
$this->load->view('parts/header', $data);
@ -118,24 +113,20 @@ class MO_Controller extends CI_Controller
}
if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' ||
$page == 'mail')
{
$page == 'mail') {
$res['res'] = $this->resources;
$this->load->view('village/resources', $res);
}
if ($page == 'mail')
{
if ($page == 'mail') {
$this->load->view('mail/menu');
}
if ($page == 'village')
{
if ($page == 'village') {
$this->load->view('village/menu');
}
if ($page == 'building')
{
if ($page == 'building') {
$data['building'] = $this->building;
$data['slotid'] = $slotid;
@ -143,26 +134,23 @@ class MO_Controller extends CI_Controller
$this->load->view('building/menu', $data);
}
if ($page == 'do')
{
if ($page == 'do') {
$this->_update();
if ($slotid)
if ($slotid) {
$this->_get_slot_building($slotid);
}
}
elseif ($page == 'hero')
{
if (!$this->hero && !$slotid)
{
} elseif ($page == 'hero') {
if (!$this->hero && !$slotid) {
$this->load->helper('url');
redirect('hero/create');
return;
}
$data['hero'] = $this->hero;
$data['weather'] = FALSE;
$data['resources'] = FALSE;
$data['weather'] = false;
$data['resources'] = false;
$this->load->view('parts/header', $data);
$this->load->view('menu', $data);
$this->load->view('hero/menu', $data);
@ -171,11 +159,13 @@ class MO_Controller extends CI_Controller
public function _get_slot_building($slotid = 0)
{
if (!$slotid)
if (!$slotid) {
return;
}
if ($this->building)
if ($this->building) {
return;
}
$this->load->model('building_model');
$this->building = $this->building_model->get_slot_building($slotid, $this->villageid);
@ -190,8 +180,9 @@ class MO_Controller extends CI_Controller
public function _get_resources()
{
if ($this->resources)
if ($this->resources) {
return;
}
$this->load->model('resource_model');
$this->resources = $this->resource_model->get_resources($this->villageid);
@ -201,11 +192,12 @@ class MO_Controller extends CI_Controller
{
$this->load->model('event_model');
if ($this->resources || $this->events || $this->weather)
if ($this->resources || $this->events || $this->weather) {
return;
}
//event model returns resources, and events, and weather
$data = $this->event_model->update($this->village_data, TRUE);
$data = $this->event_model->update($this->village_data, true);
$this->resources = $data['resources'];
$this->events = $data['events'];
@ -228,81 +220,60 @@ class MO_Controller extends CI_Controller
this is primarily here, so when events like EVENT_BUILD needed, since there aren't going to be 2
*/
public function _filter_events($type, $filter, $slotid = 0, $ev_type = 0, $next = FALSE)
public function _filter_events($type, $filter, $slotid = 0, $ev_type = 0, $next = false)
{
//means no events
if (!$this->events)
return FALSE;
if (!$this->events) {
return false;
}
$data = FALSE;
$data = false;
if ($type == 'all')
{
if ($filter == 'slot')
{
foreach ($this->events as $row)
{
if ($row['slotid'] == $slotid)
{
if ($type == 'all') {
if ($filter == 'slot') {
foreach ($this->events as $row) {
if ($row['slotid'] == $slotid) {
$data[] = $row;
}
}
}
else
{
} else {
$data = $this->events;
}
}
if ($type == 'type')
{
if ($filter == 'all')
{
foreach ($this->events as $row)
{
if ($row['type'] == $ev_type)
{
if ($type == 'type') {
if ($filter == 'all') {
foreach ($this->events as $row) {
if ($row['type'] == $ev_type) {
$data[] = $row;
}
}
}
else
{
foreach ($this->events as $row)
{
if ($row['type'] == $ev_type && $row['slotid'] == $slotid)
{
} else {
foreach ($this->events as $row) {
if ($row['type'] == $ev_type && $row['slotid'] == $slotid) {
$data[] = $row;
}
}
}
}
if ($type == 'next')
{
if ($filter == 'all')
{
if ($type == 'next') {
if ($filter == 'all') {
$last_end = 99999999999;
$smallest = FALSE;
foreach ($this->events as $row)
{
if ($row['end'] < $last_end)
{
$smallest = false;
foreach ($this->events as $row) {
if ($row['end'] < $last_end) {
$last_end = $row['end'];
$smallest = $row;
}
}
return $smallest;
}
else
{
} else {
$last_end = 99999999999;
$smallest = FALSE;
foreach ($this->events as $row)
{
if ($row['end'] < $last_end && $row['slotid'] == $slotid)
{
$smallest = false;
foreach ($this->events as $row) {
if ($row['end'] < $last_end && $row['slotid'] == $slotid) {
$last_end = $row['end'];
$smallest = $row;
}
@ -313,19 +284,15 @@ class MO_Controller extends CI_Controller
}
//order it
if ($data)
{
if ($data) {
$last_end = 99999999999;
$last['id'] = FALSE;
$smallest = FALSE;
$last['id'] = false;
$smallest = false;
for ($i = 0; $i < sizeof($data); $i++)
{
foreach ($data as $row)
{
for ($i = 0; $i < sizeof($data); $i++) {
foreach ($data as $row) {
//accounting for events ending at the same time
if ($row['end'] <= $last_end && $last['id'] != $row['id'])
{
if ($row['end'] <= $last_end && $last['id'] != $row['id']) {
$smallest = $row;
}
}
@ -335,19 +302,21 @@ class MO_Controller extends CI_Controller
$last = $smallest;
}
if (!$next)
if (!$next) {
return $ret;
else
} else {
return $ret[0];
}
return FALSE;
}
function _prep_res_js()
return false;
}
public function _prep_res_js()
{
if (!$this->resources)
return FALSE;
if (!$this->resources) {
return false;
}
$res = $this->resources;
@ -361,18 +330,15 @@ class MO_Controller extends CI_Controller
$last = $a[0];
$index = 0;
for ($i = 0; $i < 5; $i++)
{
if ($a[$i] < $last)
{
for ($i = 0; $i < 5; $i++) {
if ($a[$i] < $last) {
$last = $a[$i];
$index = $i;
}
}
//comberting back numerical index
switch ($index)
{
switch ($index) {
case 0:
$s_index = 'food';
break;
@ -397,10 +363,10 @@ class MO_Controller extends CI_Controller
$num_tick = 0.1;
$rate = 'rate_' . $s_index;
while (TRUE)
{
if (($res[$rate] * $num_tick) > 1)
while (true) {
if (($res[$rate] * $num_tick) > 1) {
break;
}
$num_tick += 0.1;
}
@ -415,16 +381,5 @@ class MO_Controller extends CI_Controller
return $res;
}
}//MO_Controller
//nowhitesp

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,22 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
if ( ! function_exists('gender'))
{
if (! function_exists('gender')) {
function gender($gender = '')
{
if ($gender == 1)
if ($gender == 1) {
return 'Male';
else
} else {
return 'Female';
}
}
}
if ( ! function_exists('class_name'))
{
if (! function_exists('class_name')) {
function class_name($id = 0)
{
switch ($id)
{
switch ($id) {
case 1:
return 'Warrior';
case 2:

View File

@ -1,29 +1,27 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
//means set_selected
if (!function_exists('ss'))
{
if (!function_exists('ss')) {
function ss($d1, $d2, $o1, $o2)
{
if ($o1 == $d1 && $o2 == $d2)
{
if ($d1 == 'eq')
if ($o1 == $d1 && $o2 == $d2) {
if ($d1 == 'eq') {
return 'equipment_entry_selected';
else
} else {
return 'inventory_entry_selected';
}
}
}
}
//quality_(in)inventory
if (!function_exists('qi'))
{
if (!function_exists('qi')) {
function qi($row)
{
if ($row)
{
switch ($row['quality'])
{
if ($row) {
switch ($row['quality']) {
case (0):
return 'iv_quality_really_poor';
case (1):
@ -44,14 +42,11 @@ if (!function_exists('qi'))
}
//quality_(in)character('s view)
if (!function_exists('qc'))
{
if (!function_exists('qc')) {
function qc($equipment, $id)
{
if ($equipment[$id])
{
switch ($equipment[$id]['quality'])
{
if ($equipment[$id]) {
switch ($equipment[$id]['quality']) {
case (0):
return 'eq_quality_really_poor';
case (1):
@ -71,62 +66,51 @@ if (!function_exists('qc'))
}
}
if (!function_exists('can_be_equipped'))
{
if (!function_exists('can_be_equipped')) {
function can_be_equipped($item, $hero)
{
if (!$item)
return FALSE;
if (!$item) {
return false;
}
$data['can'] = FALSE;
$data['can'] = false;
$data['message'] = '';
$data['allowed_slot1'] = FALSE;
$data['allowed_slot2'] = FALSE;
$data['two_handed'] = FALSE;
$data['allowed_slot1'] = false;
$data['allowed_slot2'] = false;
$data['two_handed'] = false;
if ($item['type'] != 1)
{
if ($item['type'] != 1) {
$data['message'] = 'That item cannot be equipped.';
return $data;
}
if ($item['req_class'] != 0 && $item['req_class'] != $hero['class'])
{
if ($item['req_class'] != 0 && $item['req_class'] != $hero['class']) {
$data['message'] = 'You can never use that item.';
return $data;
}
if ($item['req_level'] > $hero['level'])
{
if ($item['req_level'] > $hero['level']) {
$data['message'] = 'Your level is too low to use that item.';
return $data;
}
if ($item['subtype'] == 6)
{
$data['can'] = TRUE;
if ($item['subtype'] == 6) {
$data['can'] = true;
$data['allowed_slot1'] = 6;
return $data;
}
elseif ($item['subtype'] == 12)
{
$data['can'] = TRUE;
} elseif ($item['subtype'] == 12) {
$data['can'] = true;
$data['allowed_slot1'] = 12;
$data['allowed_slot2'] = 13;
return $data;
}
elseif ($item['subtype'] == 14)
{
$data['can'] = TRUE;
} elseif ($item['subtype'] == 14) {
$data['can'] = true;
$data['allowed_slot1'] = 14;
$data['allowed_slot2'] = 15;
return $data;
}
elseif ($item['subtype'] == 19)
{
if ($hero['class'] == 2)
{
$data['can'] = TRUE;
} elseif ($item['subtype'] == 19) {
if ($hero['class'] == 2) {
$data['can'] = true;
$data['allowed_slot1'] = 19;
return $data;
}
@ -136,48 +120,44 @@ if (!function_exists('can_be_equipped'))
//warrior
'1' => array(0, 1, 2, 3, 4),
//rogue
'2' => array(0, 1, 2, FALSE, FALSE),
'2' => array(0, 1, 2, false, false),
//archer
'3' => array(0, 1, 2, 3, FALSE));
'3' => array(0, 1, 2, 3, false));
$dataeqslots = array(
//head
'0' => array(0, FALSE),
'0' => array(0, false),
//neck
'1' => array(1, FALSE),
'1' => array(1, false),
//shoulder
'2' => array(2, FALSE),
'2' => array(2, false),
//back
'3' => array(3, FALSE),
'3' => array(3, false),
//chest
'4' => array(4, FALSE),
'4' => array(4, false),
//shirt
'5' => array(5, FALSE),
'5' => array(5, false),
//bracer
'7' => array(7, FALSE),
'7' => array(7, false),
//gloves
'8' => array(8, FALSE),
'8' => array(8, false),
//belt
'9' => array(9, FALSE),
'9' => array(9, false),
//legs
'10' => array(10, FALSE),
'10' => array(10, false),
//foots
'11' => array(11, FALSE),
'11' => array(11, false),
);
//this means every item, whose subsubtype means the type (like cloth)
if ($item['subtype'] >= 0 && $item['subtype'] < 6 || $item['subtype'] > 6 && $item['subtype'] < 12)
{
if ($datatype[$hero['class']][$item['subsubtype']] !== FALSE)
{
$data['can'] = TRUE;
if ($item['subtype'] >= 0 && $item['subtype'] < 6 || $item['subtype'] > 6 && $item['subtype'] < 12) {
if ($datatype[$hero['class']][$item['subsubtype']] !== false) {
$data['can'] = true;
$data['allowed_slot1'] = $dataeqslots[$item['subtype']][0];
$data['allowed_slot2'] = $dataeqslots[$item['subtype']][1];
return $data;
}
else
{
$data['can'] = FALSE;
} else {
$data['can'] = false;
$data['message'] = "You don't have the required proficiency to use that item.";
return $data;
}
@ -185,53 +165,51 @@ if (!function_exists('can_be_equipped'))
$dataclasswep = array(
//warrior
'1' => array(FALSE, FALSE, FALSE, FALSE, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, FALSE, FALSE, FALSE, 20, FALSE),
'1' => array(false, false, false, false, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, false, false, false, 20, false),
//rogue
'2' => array(FALSE, 2, 3, 4, 5, 6, 7, FALSE, 9, 10,
11, FALSE, 13, 14, 15, FALSE, FALSE, FALSE, FALSE, FALSE, 21),
'2' => array(false, 2, 3, 4, 5, 6, 7, false, 9, 10,
11, false, 13, 14, 15, false, false, false, false, false, 21),
//archer
'3' => array(FALSE, 2, 3, 4, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, 13, 14, 15, 16, 17, 18, 19, FALSE, FALSE)
'3' => array(false, 2, 3, 4, false, false, false, false, false, false,
false, false, 13, 14, 15, 16, 17, 18, 19, false, false)
);
//array(first slot, second slot, two Handed)
$datawep = array(
//staff
'1' => array(16, FALSE, TRUE),
'1' => array(16, false, true),
//dagger one, main, off
'2' => array(16, 17, FALSE),
'3' => array(16, FALSE, FALSE),
'4' => array(17, FALSE, FALSE),
'2' => array(16, 17, false),
'3' => array(16, false, false),
'4' => array(17, false, false),
//mace one main, off, 2h
'5' => array(16, 17, FALSE),
'6' => array(16, FALSE, FALSE),
'7' => array(17, FALSE, FALSE),
'8' => array(16, FALSE, TRUE),
'5' => array(16, 17, false),
'6' => array(16, false, false),
'7' => array(17, false, false),
'8' => array(16, false, true),
//axe one, main, off, 2h
'9' => array(16, 17, FALSE),
'10' => array(16, FALSE, FALSE),
'11' => array(17, FALSE, FALSE),
'12' => array(16, FALSE, TRUE),
'9' => array(16, 17, false),
'10' => array(16, false, false),
'11' => array(17, false, false),
'12' => array(16, false, true),
//sword one, main, off, 2h
'13' => array(16, 17, FALSE),
'14' => array(16, FALSE, FALSE),
'15' => array(17, FALSE, FALSE),
'16' => array(16, FALSE, TRUE),
'13' => array(16, 17, false),
'14' => array(16, false, false),
'15' => array(17, false, false),
'16' => array(16, false, true),
//bow, crossbow, gun
'17' => array(18, 17, FALSE),
'18' => array(18, FALSE, FALSE),
'19' => array(18, FALSE, FALSE),
'17' => array(18, 17, false),
'18' => array(18, false, false),
'19' => array(18, false, false),
//?? warri, rogue ranged
'20' => array(18, FALSE, FALSE),
'21' => array(18, FALSE, FALSE)
'20' => array(18, false, false),
'21' => array(18, false, false)
);
if ($item['subtype'] == 16)
{
if ($dataclasswep[$hero['class']][$item['subsubtype']] !== FALSE)
{
$data['can'] = TRUE;
if ($item['subtype'] == 16) {
if ($dataclasswep[$hero['class']][$item['subsubtype']] !== false) {
$data['can'] = true;
$data['allowed_slot1'] = $datawep[$item['subsubtype']][0];
$data['allowed_slot2'] = $datawep[$item['subsubtype']][1];
$data['two_handed'] = $datawep[$item['subsubtype']][2];
@ -239,7 +217,7 @@ if (!function_exists('can_be_equipped'))
}
}
$data['can'] = FALSE;
$data['can'] = false;
$data['message'] = 'You cannot use that item.';
return $data;
}

View File

@ -1,16 +1,20 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
if ( ! function_exists('ev_type'))
{
if (! function_exists('ev_type')) {
function ev_type($ev)
{
if ($ev == 'build')
if ($ev == 'build') {
return 0;
}
if ($ev == 'upgrade')
if ($ev == 'upgrade') {
return 1;
}
if ($ev == 'create')
if ($ev == 'create') {
return 2;
}
}
}

View File

@ -1,9 +1,10 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
//using different helper for images, so they can be easily relocated to like different servers etc...
if ( ! function_exists('isite_url'))
{
if (! function_exists('isite_url')) {
function isite_url($uri = '')
{
$CI =& get_instance();
@ -13,8 +14,7 @@ if ( ! function_exists('isite_url'))
//addign img/prefix, so I don't have to in every call
if ( ! function_exists('ibase_url'))
{
if (! function_exists('ibase_url')) {
function ibase_url($uri = '')
{
$muri = 'img/' . $uri;

View File

@ -3,17 +3,18 @@ class Ai_model extends MO_Model
{
protected $settings;
function __construct()
public function __construct()
{
parent::__construct();
}
function attack()
public function attack()
{
$this->parse_settings();
if (!$this->settings['on'])
if (!$this->settings['on']) {
return 'AI is off';
}
$sql = "SELECT * FROM ai_villages WHERE attacked='0'";
@ -28,8 +29,7 @@ class Ai_model extends MO_Model
$attacking_num = $this->settings['max_attack_village_limit'];
//determining how much will attack
if ($this->settings['attack_village_rand'])
{
if ($this->settings['attack_village_rand']) {
$a = rand(0, $this->settings['attack_village_rand']);
$attacking_num -= $a;
@ -37,32 +37,27 @@ class Ai_model extends MO_Model
$log .= $attacking_num . " villages attacking. \n";
$reset = FALSE;
$reset = false;
//resetting ai_villages's attack field if everything will be set to attacked
if ($ai_village_not_attacked < $attacking_num)
{
if ($ai_village_not_attacked < $attacking_num) {
$attacking_num = $ai_village_not_attacked;
$reset = TRUE;
$reset = true;
}
//determining which villages are going to attack
for ($i = 0; $i < $attacking_num; $i++)
{
$found = FALSE;
for ($i = 0; $i < $attacking_num; $i++) {
$found = false;
while (!$found)
{
foreach ($ai_villages as $row)
{
while (!$found) {
foreach ($ai_villages as $row) {
$r = rand(1, 100);
if ($r > 50 && !isset($s[$row['id']]))
{
$s[$row['id']] = TRUE;
if ($r > 50 && !isset($s[$row['id']])) {
$s[$row['id']] = true;
$data[] = $row;
$found = TRUE;
$found = true;
break;
}
}
@ -70,25 +65,22 @@ class Ai_model extends MO_Model
}
//saving to the db that they are attacked
if (!$reset)
{
if (!$reset) {
$sql = "UPDATE ai_villages SET attacked='1' WHERE ";
$first = TRUE;
foreach ($data as $row)
{
if ($first)
$first = FALSE;
else
$first = true;
foreach ($data as $row) {
if ($first) {
$first = false;
} else {
$sql .= " OR ";
}
$sql .= "id='" . $row['id'] . "'";
}
$this->db->query($sql);
}
else
{
} else {
$sql = "UPDATE ai_villages SET attacked='0'";
$this->db->query($sql);
$log .= "ai_villages's attacked field reseted.\n";
@ -100,45 +92,35 @@ class Ai_model extends MO_Model
$num_ai_units = $q->num_rows();
$res = $q->result_array();
if ($this->settings['ai_unit_max_diff'] < $num_ai_units)
{
if ($this->settings['ai_unit_max_diff'] < $num_ai_units) {
$num = 0;
$d = FALSE;
$d = false;
while ($num != $this->settings['ai_unit_max_diff'])
{
foreach ($res as $row)
{
if (!isset($d[$row['id']]))
{
while ($num != $this->settings['ai_unit_max_diff']) {
foreach ($res as $row) {
if (!isset($d[$row['id']])) {
$r = rand(1, 50);
if ($r > 50)
{
if ($r > 50) {
$ai_units[] = $row;
$d[$row['id']] = TRUE;
$d[$row['id']] = true;
$num++;
break;
}
}
}
}
}
else
{
} else {
$ai_units = $res;
}
//adding villages to log
$log .= "Attacking villages: \n";
foreach ($data as $row)
{
foreach ($data as $row) {
$log .= $row['name'] . "(" .$row['X'] . " " . $row['Y'] . ") \n";
}
//sending attackers
foreach ($data as $row)
{
foreach ($data as $row) {
$sql = "SELECT map.X,map.Y,villages.*
FROM map
LEFT JOIN villages ON (map.villageid=villages.id AND map.type='3')
@ -151,24 +133,22 @@ class Ai_model extends MO_Model
$q = $this->db->query($sql);
//no villages in range
if (!$q->num_rows())
if (!$q->num_rows()) {
continue;
}
$log .= $row['name'] . " is attacking: \n";
$res = $q->result_array();
//sending attackers
foreach ($res as $rrow)
{
if ($rrow['ai_on'] || $rrow['ai_flagged'])
{
foreach ($res as $rrow) {
if ($rrow['ai_on'] || $rrow['ai_flagged']) {
$log .= "Sending attackers to: " . $rrow['name'] . "[" . $rrow['id'] . "]";
$log .= " (S: " . $rrow['score'] . ")\n";
$log .= "Sent: \n";
foreach ($ai_units as $unit)
{
foreach ($ai_units as $unit) {
$a = ($rrow['score'] / $unit['rate']) / $unit['per_score'];
$num = floor($a);
@ -190,10 +170,9 @@ class Ai_model extends MO_Model
write_file($f, $log);
return $log;
}
function send_attack($send, $ai_village, $village)
public function send_attack($send, $ai_village, $village)
{
$villageid = $village['id'];
@ -202,21 +181,20 @@ class Ai_model extends MO_Model
$res = $q->row_array();
if ($res['attackid'])
{
if ($res['attackid']) {
$atkid = ($res['attackid'] + 1);
}
else
} else {
$atkid = 1;
}
$first = TRUE;
$first = true;
$sql = "INSERT INTO attacks VALUES";
foreach ($send as $row)
{
if ($first)
$first = FALSE;
else
foreach ($send as $row) {
if ($first) {
$first = false;
} else {
$sql .= ',';
}
$sql .= "(default, '$villageid', '$atkid', '" . $row['unitid'] . "', '" . $row['num']. "')";
}
@ -247,10 +225,9 @@ class Ai_model extends MO_Model
$ev['data2'] = $dir;
$this->add_event($ev);
}
function parse_settings()
public function parse_settings()
{
$sql = "SELECT * FROM ai_settings";
@ -258,15 +235,14 @@ class Ai_model extends MO_Model
$res = $q->result_array();
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['setting']] = $row['value'];
}
$this->settings = $data;
}
function get_unit_list_drop_admin()
public function get_unit_list_drop_admin()
{
$sql = "SELECT * FROM ai_units";
@ -276,15 +252,14 @@ class Ai_model extends MO_Model
$data[0] = 'Nothing';
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['name'];
}
return $data;
}
function list_units_admin()
public function list_units_admin()
{
$sql = "SELECT * FROM ai_units";
@ -293,7 +268,7 @@ class Ai_model extends MO_Model
return $q->result_array();
}
function get_unit_admin($id)
public function get_unit_admin($id)
{
$sql = "SELECT * FROM ai_units WHERE id='$id'";
$q = $this->db->query($sql);
@ -301,7 +276,7 @@ class Ai_model extends MO_Model
return $q->row_array();
}
function add_unit_admin($data)
public function add_unit_admin($data)
{
$sql = "INSERT INTO ai_units
VALUES(default,
@ -322,7 +297,7 @@ class Ai_model extends MO_Model
$this->_create_sql($sql);
}
function edit_unit_admin($data)
public function edit_unit_admin($data)
{
$sql = "UPDATE ai_units
SET name='" . $data['name'] . "',
@ -343,7 +318,7 @@ class Ai_model extends MO_Model
$this->_create_sql($sql);
}
function get_settings_list_admin()
public function get_settings_list_admin()
{
$sql = "SELECT * FROM ai_settings";
@ -352,7 +327,7 @@ class Ai_model extends MO_Model
return $q->result_array();
}
function get_setting_admin($id)
public function get_setting_admin($id)
{
$sql = "SELECT * FROM ai_settings WHERE id='$id'";
$q = $this->db->query($sql);
@ -360,7 +335,7 @@ class Ai_model extends MO_Model
return $q->row_array();
}
function edit_setting_admin($data)
public function edit_setting_admin($data)
{
$sql = "UPDATE ai_settings
SET setting='" . $data['setting'] . "',
@ -373,7 +348,7 @@ class Ai_model extends MO_Model
$this->_create_sql($sql);
}
function add_setting_admin($data)
public function add_setting_admin($data)
{
$sql = "INSERT INTO ai_settings
VALUES(default,

View File

@ -2,12 +2,12 @@
class Assignment_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function assign_unit($assid, $num, $slotid, $res, $villageid, $userid)
public function assign_unit($assid, $num, $slotid, $res, $villageid, $userid)
{
$this->set_resources($res);
@ -18,8 +18,9 @@ class Assignment_model extends MO_Model
$q = $this->db->query($sql);
if (!$q->num_rows())
if (!$q->num_rows()) {
return 1;
}
$building = $q->row_array();
@ -32,8 +33,7 @@ class Assignment_model extends MO_Model
AND villageid='$villageid'";
$q = $this->db->query($sql);
if ($q->num_rows())
{
if ($q->num_rows()) {
//the user wants to just deassign
$ass = $q->row_array();
@ -49,37 +49,28 @@ class Assignment_model extends MO_Model
AND userid='$userid'";
$q = $this->db->query($sql);
if ($q->num_rows())
{
if ($q->num_rows()) {
$units = $q->result_array();
}
else
{
$units = FALSE;
} else {
$units = false;
}
$found = FALSE;
$found = false;
if ($units)
{
foreach ($units as $row)
{
if ($row['unitid'] == $ass['unitid'])
{
$found = TRUE;
if ($units) {
foreach ($units as $row) {
if ($row['unitid'] == $ass['unitid']) {
$found = true;
$fdata = $row['id'];
}
}
}
if ($found)
{
if ($found) {
$sql = "UPDATE village_units
SET unitcount = unitcount + '". $ass['num_unit'] . "'
WHERE id='$fdata'";
}
else
{
} else {
$sql = "INSERT INTO village_units
VALUES(default, '$userid', '$villageid',
'" . $ass['unitid'] . "', '" . $ass['num_unit'] . "')";
@ -88,8 +79,12 @@ class Assignment_model extends MO_Model
$this->db->query($sql);
//substract the bonuses
$this->substract_modifiers($assid, $villageid, 'assignment',
$ass['num_bonus']);
$this->substract_modifiers(
$assid,
$villageid,
'assignment',
$ass['num_bonus']
);
$this->write_resources();
@ -108,23 +103,27 @@ class Assignment_model extends MO_Model
$sql = "SELECT * FROM assignments WHERE id='$assid'";
$q = $this->db->query($sql);
if (!$q->num_rows())
if (!$q->num_rows()) {
return 2;
}
$ass = $q->row_array();
//checking technology
if ($ass['req_tech'])
if (!$this->has_req_tech($ass['req_tech'], $villageid, $slotid))
if ($ass['req_tech']) {
if (!$this->has_req_tech($ass['req_tech'], $villageid, $slotid)) {
return 3;
}
}
//check if building has that assignment
if (!($building['assignment1'] == $ass['id'] ||
$building['assignment2'] == $ass['id'] ||
$building['assignment3'] == $ass['id'] ||
$building['assignment4'] == $ass['id'] ||
$building['assignment5'] == $ass['id']))
$building['assignment5'] == $ass['id'])) {
return 3;
}
//getting unit
$sql = "SELECT * FROM village_units
@ -132,26 +131,31 @@ class Assignment_model extends MO_Model
AND userid='$userid'";
$q = $this->db->query($sql);
if (!$q->num_rows())
if (!$q->num_rows()) {
return 4;
}
$unit = $q->row_array();
//it probably shouldn't happen but who knows
if (!$unit['unitcount'])
if (!$unit['unitcount']) {
return 5;
}
//if the user just clicks on the assign we should assign max
if (!$num)
if (!$num) {
$num = $ass['max'];
}
//we shouldn't assign more than allowed
if ($ass['max'] < $num)
if ($ass['max'] < $num) {
$num = $ass['max'];
}
//determining how much can be assigned
if ($unit['unitcount'] < $num)
if ($unit['unitcount'] < $num) {
$num = $unit['unitcount'];
}
//determining number of bonuses granted
$num_bonus = floor(($num / $ass['bonus_per_assigned']));
@ -159,12 +163,9 @@ class Assignment_model extends MO_Model
$count = ($unit['unitcount'] - $num);
//updating unit field in db
if ($count <= 0)
{
if ($count <= 0) {
$sql = "DELETE FROM village_units WHERE id='" . $unit['id'] . "'";
}
else
{
} else {
$sql = "UPDATE village_units
SET unitcount=unitcount - '$num'
WHERE id='" . $unit['id'] . "'";
@ -184,8 +185,9 @@ class Assignment_model extends MO_Model
$this->write_resources();
//assignment has spell
if (!$ass['spellid'])
if (!$ass['spellid']) {
return 0;
}
/*
//only give spells if bonus is granted
@ -194,8 +196,9 @@ class Assignment_model extends MO_Model
*/
//only give spell if max unit assigned
if (!($ass['max'] == $num))
if (!($ass['max'] == $num)) {
return 0;
}
//granting spell
$sql = "INSERT INTO building_spells
@ -207,10 +210,11 @@ class Assignment_model extends MO_Model
return 0;
}
function get_assignments($slotid, $villageid, $userid)
public function get_assignments($slotid, $villageid, $userid)
{
if ($slotid > parent::TOTAL_BUILDINGS)
return 1; //that shouldn't happen
if ($slotid > parent::TOTAL_BUILDINGS) {
return 1;
} //that shouldn't happen
$sql = "SELECT buildings.* FROM village_buildings
INNER JOIN buildings ON village_buildings.buildingid = buildings.id
@ -219,8 +223,9 @@ class Assignment_model extends MO_Model
$q = $this->db->query($sql);
if (!$q->num_rows())
return 2; //nothing in that slot
if (!$q->num_rows()) {
return 2;
} //nothing in that slot
$res = $q->row_array();
@ -237,9 +242,8 @@ class Assignment_model extends MO_Model
$q = $this->db->query($sql);
if (!$q->num_rows())
{
$data['assigndata'] = FALSE; //building doesn't have assignments
if (!$q->num_rows()) {
$data['assigndata'] = false; //building doesn't have assignments
return $data;
}
@ -247,15 +251,14 @@ class Assignment_model extends MO_Model
$tech = $this->get_village_technologies($villageid, $slotid);
foreach ($adata as $row)
{
if ($this->have_technology($tech, $row['req_tech']))
foreach ($adata as $row) {
if ($this->have_technology($tech, $row['req_tech'])) {
$data['assigndata'][] = $row;
}
}
if (!isset($data['assigndata']))
{
$data['assigndata'] = FALSE;
if (!isset($data['assigndata'])) {
$data['assigndata'] = false;
return $data;
}
@ -266,12 +269,9 @@ class Assignment_model extends MO_Model
$q = $this->db->query($sql);
if (!$q->num_rows())
{
$data['assigned'] = FALSE;
}
else
{
if (!$q->num_rows()) {
$data['assigned'] = false;
} else {
$data['assigned'] = $q->result_array();
}
@ -283,20 +283,16 @@ class Assignment_model extends MO_Model
AND userid='$userid'";
$q = $this->db->query($sql);
if ($q->num_rows)
{
if ($q->num_rows) {
$data['units'] = $q->result_array();
}
else
{
$data['units'] = FALSE;
} else {
$data['units'] = false;
}
return $data;
}
function get_assignment_list_drop_admin()
public function get_assignment_list_drop_admin()
{
$sql = "SELECT * FROM assignments";
$q = $this->db->query($sql);
@ -305,15 +301,14 @@ class Assignment_model extends MO_Model
$data[0] = 'Nothing';
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['description'];
}
return $data;
}
function get_assignments_admin()
public function get_assignments_admin()
{
$sql = "SELECT * FROM assignments";
@ -322,7 +317,7 @@ class Assignment_model extends MO_Model
return $q->result_array();
}
function add_assignment_admin($data)
public function add_assignment_admin($data)
{
$sql = "INSERT INTO assignments
VALUES (default,
@ -353,7 +348,7 @@ class Assignment_model extends MO_Model
$this->_create_sql($sql);
}
function edit_assignment_admin($data)
public function edit_assignment_admin($data)
{
$sql = "UPDATE assignments
SET unitid='" . $data['unitid'] . "',
@ -384,7 +379,7 @@ class Assignment_model extends MO_Model
$this->_create_sql($sql);
}
function get_assignment_admin($id)
public function get_assignment_admin($id)
{
$sql = "SELECT * FROM assignments WHERE id='$id'";

View File

@ -1,30 +1,31 @@
<?php
class Building_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function get_building($buildingid)
public function get_building($buildingid)
{
$sql = "SELECT * FROM buildings WHERE id='$buildingid'";
$q = $this->db->query($sql);
if ($q->num_rows())
if ($q->num_rows()) {
return $q->row_array();
return FALSE;
}
function set_build_in_progress($slotid, $villageid)
return false;
}
public function set_build_in_progress($slotid, $villageid)
{
$sql = "INSERT INTO village_buildings
VALUES(default, '$villageid', '$slotid', '2')";
$this->db->query($sql);
}
function building_list($villageid)
public function building_list($villageid)
{
$sql = "SELECT * FROM buildings
WHERE rank='1'";
@ -37,10 +38,8 @@ class Building_model extends MO_Model
$vb = $q->result_array();
//checking requirements
foreach ($res as $row)
{
if ($this->can_build($villageid, $row, $vb, FALSE))
{
foreach ($res as $row) {
if ($this->can_build($villageid, $row, $vb, false)) {
$build[] = $row;
}
}
@ -48,21 +47,15 @@ class Building_model extends MO_Model
//requirements are met
$tech = $this->get_village_technologies($villageid);
foreach ($build as $row)
{
if ($row['req_tech'])
{
foreach ($tech as $trow)
{
if ($row['req_tech'] == $trow['technologyid'])
{
foreach ($build as $row) {
if ($row['req_tech']) {
foreach ($tech as $trow) {
if ($row['req_tech'] == $trow['technologyid']) {
$data[] = $row;
break;
}
}
}
else
{
} else {
$data[] = $row;
}
}
@ -74,30 +67,28 @@ class Building_model extends MO_Model
//returns 1 if technology requirement not met
//returns 2 if not enough resources
//returns 3 if can be built
function can_be_upgraded($event, $res, $building, $villageid, $query = FALSE)
{
if ($query)
public function can_be_upgraded($event, $res, $building, $villageid, $query = false)
{
if ($query) {
//this means we have to get building from the db,
//and $building is only the id
}
//check if upgrade in progress
//we can just do this, since event is filtered to update events
if ($event)
{
if ($event) {
return 0;
}
if (!$this->has_req_tech($building['req_tech'], $villageid))
if (!$this->has_req_tech($building['req_tech'], $villageid)) {
return 1;
}
if ($res['food'] < $building['cost_food'] ||
$res['wood'] < $building['cost_wood'] ||
$res['stone'] < $building['cost_stone'] ||
$res['iron'] < $building['cost_iron'] ||
$res['mana'] < $building['cost_mana'])
{
$res['mana'] < $building['cost_mana']) {
return 2;
}
@ -105,28 +96,30 @@ class Building_model extends MO_Model
return 3;
}
function can_build($villageid, $buildingid, $data = 0, $is_buildingid = TRUE)
public function can_build($villageid, $buildingid, $data = 0, $is_buildingid = true)
{
//STUB requirements aren't implemented
return TRUE;
return true;
}
function is_valid_slot($slotid, $villageid)
public function is_valid_slot($slotid, $villageid)
{
if ($slotid > parent::TOTAL_BUILDINGS)
return FALSE;
if ($slotid > parent::TOTAL_BUILDINGS) {
return false;
}
$sql = "SELECT id FROM village_buildings
WHERE villageid='$villageid' AND slotid='$slotid'";
$q = $this->db->query($sql);
if ($q->num_rows())
return FALSE;
return TRUE;
if ($q->num_rows()) {
return false;
}
function get_building_ranks_admin()
return true;
}
public function get_building_ranks_admin()
{
$sql = "SELECT * FROM buildings WHERE id > 2";
$q = $this->db->query($sql);
@ -135,20 +128,17 @@ class Building_model extends MO_Model
$data[0] = 'Nothing';
foreach ($res as $row)
{
if (!$row['next_rank'])
{
foreach ($res as $row) {
if (!$row['next_rank']) {
$name = $row['name'] . ' R: ' . $row['rank'];
$data[$row['id']] = $name;
}
}
return $data;
}
function list_buildings_admin()
public function list_buildings_admin()
{
$sql = "SELECT * FROM buildings";
$q = $this->db->query($sql);
@ -156,7 +146,7 @@ class Building_model extends MO_Model
return $q->result_array();
}
function get_building_admin($id)
public function get_building_admin($id)
{
$sql = "SELECT * FROM buildings WHERE id='$id'";
$q = $this->db->query($sql);
@ -164,9 +154,8 @@ class Building_model extends MO_Model
return $q->row_array();
}
function edit_building_admin($data)
public function edit_building_admin($data)
{
$sql = "UPDATE buildings
SET name='" . $data['name'] . "',
description='" . $data['description'] . "',
@ -214,7 +203,7 @@ class Building_model extends MO_Model
$this->_create_sql($sql);
}
function add_building_admin($data)
public function add_building_admin($data)
{
$sql = "INSERT INTO buildings VALUES(default,
'" . $data['name'] . "',

View File

@ -2,13 +2,12 @@
class Changelog_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function new_version($version)
public function new_version($version)
{
$time = time();
@ -17,7 +16,7 @@ class Changelog_model extends MO_Model
$this->_create_sql($sql);
}
function new_commit($text)
public function new_commit($text)
{
$time = time();
@ -31,7 +30,7 @@ class Changelog_model extends MO_Model
$this->_create_sql($sql);
}
function get_versions()
public function get_versions()
{
$sql = "SELECT * FROM changelog_versions ORDER BY timestamp DESC";
$q = $this->db->query($sql);
@ -40,16 +39,14 @@ class Changelog_model extends MO_Model
return $q->result_array();
}
function get_commits()
public function get_commits()
{
$sql = "SELECT * FROM changelog_commits ORDER BY timestamp DESC";
$q = $this->db->query($sql);
return $q->result_array();
}
}
//nowhitesp

View File

@ -1,10 +1,9 @@
<?php
class Cron_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
}
//nowhitesp

File diff suppressed because it is too large Load Diff

View File

@ -2,36 +2,39 @@
class Hero_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function get_heroes($userid)
public function get_heroes($userid)
{
$sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'";
$q = $this->db->query($sql, array($userid));
if ($q->num_rows())
if ($q->num_rows()) {
return $q->result_array();
return FALSE;
}
function select_hero($id, $userid)
return false;
}
public function select_hero($id, $userid)
{
$sql = "SELECT userid,deleted FROM heroes WHERE id = ?";
$q = $this->db->query($sql, array($id));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['userid'] != $userid || $res['deleted'])
return FALSE;
if ($res['userid'] != $userid || $res['deleted']) {
return false;
}
$sql = "UPDATE heroes SET selected = 0 WHERE userid = ?";
@ -41,53 +44,55 @@ class Hero_model extends MO_Model
$this->db->query($sql, array($id));
return TRUE;
return true;
}
function get_hero($id, $userid)
public function get_hero($id, $userid)
{
$sql = "SELECT * FROM heroes WHERE id = ? AND userid = ?";
$q = $this->db->query($sql, array($id, $userid));
if ($q->num_rows())
if ($q->num_rows()) {
return $q->row_array();
return FALSE;
}
function delete_hero($id, $userid)
return false;
}
public function delete_hero($id, $userid)
{
$sql = "SELECT * FROM heroes WHERE id = ?";
$q = $this->db->query($sql, array($id));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['deleted'])
return FALSE;
if ($res['deleted']) {
return false;
}
if ($userid != $res['userid'])
return FALSE;
if ($userid != $res['userid']) {
return false;
}
if ($res['selected'])
{
if ($res['selected']) {
$sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'";
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows())
return TRUE;
if (!$q->num_rows()) {
return true;
}
$data = $q->result_array();
foreach ($data as $row)
{
if ($row['id'] != $id)
{
foreach ($data as $row) {
if ($row['id'] != $id) {
$sql = "UPDATE heroes SET selected = '1' WHERE id = ?";
$this->db->query($sql, array($row['id']));
@ -101,22 +106,19 @@ class Hero_model extends MO_Model
$this->db->query($sql, array($id));
return TRUE;
return true;
}
// function get_hero_admin($id)? or gm?
function create($data, $userid)
public function create($data, $userid)
{
$name = ucfirst(mb_strtolower($data['name'], 'UTF-8'));
if ($gender == 1)
{
if ($gender == 1) {
$av = 'characters/base/male.png';
$avt = 'characters/base/male_thumb.png';
}
else
{
} else {
$av = 'characters/base/female.png';
$avt = 'characters/base/female_thumb.png';
}
@ -129,8 +131,9 @@ class Hero_model extends MO_Model
$q = $this->db->query($sql, array($data['class']));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$cd = $q->row_array();
@ -174,7 +177,7 @@ class Hero_model extends MO_Model
//make actionbar entry
}
function hero_name_is_unique($name)
public function hero_name_is_unique($name)
{
$name = ucfirst(mb_strtolower($name, 'UTF-8'));
@ -182,37 +185,40 @@ class Hero_model extends MO_Model
$q = $this->db->query($sql, array($name));
if ($q->num_rows())
return FALSE;
else
return TRUE;
if ($q->num_rows()) {
return false;
} else {
return true;
}
}
function all_hero_templates_admin()
public function all_hero_templates_admin()
{
$sql = "SELECT * FROM hero_templates";
$q = $this->db->query($sql);
if ($q->num_rows())
if ($q->num_rows()) {
return $q->result_array();
else
return FALSE;
} else {
return false;
}
}
function get_template_admin($id)
public function get_template_admin($id)
{
$sql = "SELECT * FROM hero_templates WHERE id = '$id'";
$q = $this->db->query($sql);
if ($q->num_rows())
if ($q->num_rows()) {
return $q->row_array();
else
return FALSE;
} else {
return false;
}
}
function edit_template_admin($d)
public function edit_template_admin($d)
{
$c = $this->template_calc_stats($d, 'edit');
@ -256,7 +262,7 @@ class Hero_model extends MO_Model
$this->_create_sql($sql);
}
function add_template_admin($d)
public function add_template_admin($d)
{
//0 armor is being added, because when adding a new class, eqipments shouldn't exists in db
@ -288,7 +294,7 @@ class Hero_model extends MO_Model
//this is for templates (calculating all stats)
//type can be add and edit -> edit does thing like armor calc, and damage
function template_calc_stats($d, $type)
public function template_calc_stats($d, $type)
{
$class = $d['classname'];
@ -310,8 +316,7 @@ class Hero_model extends MO_Model
$c['heal_min'] = $this->hero_stat($class, 'heal_min', $d);
$c['heal_max'] = $this->hero_stat($class, 'heal_max', $d);
if ($type == 'edit')
{
if ($type == 'edit') {
//STUB
//armor, damage, heal from items
$c['armor'] = 0;

View File

@ -1,25 +1,25 @@
<?php
class Image_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function apply_menu_images($data)
public function apply_menu_images($data)
{
$path = './img/generated/';
$this->load->library('image_lib');
if ($data['apply_all'])
if ($data['apply_all']) {
$this->prepare_dir('menu', $data['file'], $data['menu_group']);
else
$this->prepare_dir('menu', $data['file'], FALSE, $data['wm_text']);
} else {
$this->prepare_dir('menu', $data['file'], false, $data['wm_text']);
}
if (!$data['apply_all'])
{
if (!$data['apply_all']) {
$data['source_image'] = $path . $data['wm_text'] . '.png';
$this->image_lib->initialize($data);
@ -33,8 +33,7 @@ class Image_model extends MO_Model
$menu_list = $this->get_menu_list($data['menu_group']);
$menu_file_list = $this->get_menu_file_list($data['menu_group']);
for ($i = 0; $i < sizeof($menu_list); $i++)
{
for ($i = 0; $i < sizeof($menu_list); $i++) {
$data['source_image'] = $path . $menu_file_list[$i] . '.png';
$data['wm_text'] = $menu_list[$i];
@ -44,45 +43,37 @@ class Image_model extends MO_Model
}
}
function prepare_dir($for, $sourcefile, $group = 1, $filename = FALSE)
public function prepare_dir($for, $sourcefile, $group = 1, $filename = false)
{
$path = './img/generated/';
$source = './img/imggen/' . $sourcefile;
$this->load->helper('file');
delete_files($path, FALSE);
delete_files($path, false);
if ($for == 'menu')
{
if ($for == 'menu') {
$img = read_file($source);
if (!$filename)
{
if (!$filename) {
$menu_list = $this->get_menu_file_list($group);
foreach ($menu_list as $row)
{
foreach ($menu_list as $row) {
$file = $path . $row . '.png';
write_file($file, $img);
}
}
else
{
} else {
$file = $path . $filename . '.png';
write_file($file, $img);
}
}
}
}
function get_menu_list($group = 1)
{
if ($group == 1)
public function get_menu_list($group = 1)
{
if ($group == 1) {
//select village vill be omitted since it will need a different style button with a ˇ
$data[] = 'News';
$data[] = 'Village';
@ -96,18 +87,16 @@ class Image_model extends MO_Model
$data[] = 'Admin Panel';
}
if ($group == 2)
{
if ($group == 2) {
$data[] = 'Stats';
}
return $data;
}
function get_menu_file_list($group = 1)
{
if ($group == 1)
public function get_menu_file_list($group = 1)
{
if ($group == 1) {
//select village vill be omitted since it will need a different style button with a ˇ
$data[] = 'news';
$data[] = 'village';
@ -121,15 +110,14 @@ class Image_model extends MO_Model
$data[] = 'admin_panel';
}
if ($group == 2)
{
if ($group == 2) {
$data[] = 'stats';
}
return $data;
}
function get_menu_group_list_drop()
public function get_menu_group_list_drop()
{
$data = array(
'1' => 'main',
@ -138,13 +126,13 @@ class Image_model extends MO_Model
return $data;
}
function apply_slot_images($data)
public function apply_slot_images($data)
{
$path = './img/generated/';
$this->load->library('image_lib');
$this->prepare_dir('menu', $data['file'], FALSE, 'gen');
$this->prepare_dir('menu', $data['file'], false, 'gen');
$data['source_image'] = $path . 'gen.png';
@ -163,38 +151,36 @@ class Image_model extends MO_Model
$this->image_lib->initialize($data);
$this->image_lib->watermark();
}
function get_file_list_drop()
public function get_file_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./img/imggen/', 1);
foreach ($dir as $row)
{
foreach ($dir as $row) {
$a = explode('.', $row);
if (isset($a[1]))
if ($a[1] == 'png' || $a[1] == 'PNG')
if (isset($a[1])) {
if ($a[1] == 'png' || $a[1] == 'PNG') {
$data[$row] = $row;
}
}
}
return $data;
}
function get_font_list_drop()
public function get_font_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./system/fonts', 1);
foreach ($dir as $row)
{
foreach ($dir as $row) {
$a = explode('.', $row);
if ($a[1] == 'ttf' || $a['1'] == 'TTF')
{
if ($a[1] == 'ttf' || $a['1'] == 'TTF') {
$data[$row] = $row;
}
}
@ -202,7 +188,7 @@ class Image_model extends MO_Model
return $data;
}
function get_v_align_drop()
public function get_v_align_drop()
{
$data = array(
'top' => 'top',
@ -212,7 +198,7 @@ class Image_model extends MO_Model
return $data;
}
function get_h_align_drop()
public function get_h_align_drop()
{
$data = array(
'left' => 'left',
@ -222,21 +208,20 @@ class Image_model extends MO_Model
return $data;
}
function get_overlay_list_drop()
public function get_overlay_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./img/imggen/overlay/', 1);
foreach ($dir as $row)
{
foreach ($dir as $row) {
$data[$row] = $row;
}
return $data;
}
function save_menu_data($data)
public function save_menu_data($data)
{
$a = 'type : ' . $data['wm_type'] . "\n";
$a .= 'quality: ' . $data['quality'] . "\n";
@ -260,7 +245,7 @@ class Image_model extends MO_Model
write_file('./img/generated/settings.txt', $a);
}
function save_slot_data($data)
public function save_slot_data($data)
{
$a = 'type : ' . $data['wm_type'] . "\n";
$a .= 'quality: ' . $data['quality'] . "\n";

View File

@ -4,31 +4,33 @@ class Item_model extends MO_Model
{
const MAX_EQUIPMENT = 20; //19, starts with zero
function __construct()
public function __construct()
{
parent::__construct();
}
//this will equip too if needed!
function swap($d1, $d2, $d3, $d4)
public function swap($d1, $d2, $d3, $d4)
{
//data validation
if (!($d1 == 'iv' || $d1 == 'eq') || !($d3 == 'iv' || $d3 == 'eq') || !is_numeric($d2) ||
!is_numeric($d4) || ($d2 < 0 || $d2 > (parent::INVENTORY_MAX - 1)) ||
($d4 < 0 || $d4 > (parent::INVENTORY_MAX - 1)))
return FALSE;
($d4 < 0 || $d4 > (parent::INVENTORY_MAX - 1))) {
return false;
}
//nothing needs to be done (same item twice)
if (($d1 == $d3) && ($d2 == $d4))
return TRUE;
if (($d1 == $d3) && ($d2 == $d4)) {
return true;
}
//hero has to be set from controller!
if (!$this->hero)
if (!$this->hero) {
return 'Internal error';
}
//just move in inventory
if ($d1 == 'iv' && $d3 == 'iv')
{
if ($d1 == 'iv' && $d3 == 'iv') {
$sql = "SELECT * FROM heros_inventory
WHERE container = 1 AND (slot = ? OR slot = ?) AND charid = ?";
@ -36,32 +38,34 @@ class Item_model extends MO_Model
$num = $q->num_rows();
if (!$num)
return FALSE;
if (!$num) {
return false;
}
$res = $q->result_array();
$item1 = $res[0];
if ($num == 2)
if ($num == 2) {
$item2 = $res[1];
else
$item2 = FALSE;
} else {
$item2 = false;
}
if (!$item2)
{
if (!$item2) {
$sql = "UPDATE heros_inventory
SET slot = ?
WHERE id = ?";
if ($item1['slot'] == $d2)
if ($item1['slot'] == $d2) {
$to = $d4;
else
} else {
$to = $d2;
}
$this->db->query($sql, array($to, $item1['id']));
return TRUE;
return true;
}
//we only get here it two items needs to be swapped
@ -70,19 +74,21 @@ class Item_model extends MO_Model
$this->db->query($sql, array($item1['slot'], $item2['id']));
$this->db->query($sql, array($item2['slot'], $item1['id']));
return TRUE;
return true;
}
//equipping has to be performed (iv/iv case already handled!)
if ($d1 == 'iv')
if ($d1 == 'iv') {
$d1 = 1;
else
} else {
$d1 = 2;
}
if ($d3 == 'iv')
if ($d3 == 'iv') {
$d3 = 1;
else
} else {
$d3 = 2;
}
$sql = "SELECT heros_inventory.id AS invid,heros_inventory.is_soulbound,heros_inventory.stack_size,
@ -95,109 +101,98 @@ class Item_model extends MO_Model
$q = $this->db->query($sql, array($d1, $d2, $d3, $d4, $this->hero['id']));
$swap = FALSE;
$swap = false;
$num = $q->num_rows();
if ($num == 2)
{
if ($num == 2) {
$res = $q->result_array();
if ($res[0]['container'] == 1)
{
if ($res[0]['container'] == 1) {
//0 is in bag
$equip = $res[0];
$deequip = $res[1];
}
elseif ($res[1]['container'] == 1)
{
} elseif ($res[1]['container'] == 1) {
//1 is in bag
$equip = $res[1];
$deequip = $res[0];
}
else
{
} else {
//swap
$equip = $res[0];
$deequip = $res[1];
$swap = TRUE;
$swap = true;
}
}
else
{
} else {
$res = $q->row_array();
if ($res['container'] == 1)
{
if ($res['container'] == 1) {
//not equipped, just equip it
$equip = $res;
$deequip = FALSE;
$deequip = false;
if ($d1 == 1)
if ($d1 == 1) {
$equipslot = $d4;
else
} else {
$equipslot = $d2;
}
else
{
if ($d1 == 2 && $d3 == 2)
{
} else {
if ($d1 == 2 && $d3 == 2) {
//switching between 2 equipslots, but one of them is empty
$equip = $res;
$deequip = FALSE;
$deequip = false;
if ($equip['slot'] == $d2)
if ($equip['slot'] == $d2) {
$equipslot = $d4;
else
} else {
$equipslot = $d2;
$swap = TRUE;
}
else
{
$swap = true;
} else {
//equipped, just deequip it
$equip = FALSE;
$equip = false;
$deequip = $res;
if ($d1 == 2)
if ($d1 == 2) {
$deequipslot = $d4;
else
} else {
$deequipslot = $d2;
}
}
}
}
$this->load->helper('equipment');
if ($equip)
{
if ($equip) {
//$cbe = can be equipped
$cbe = can_be_equipped($equip, $this->hero);
if (!isset($cbe))
if (!isset($cbe)) {
return "Internal error! $cbe is not set!";
}
}
//each of these functions has to return!
//for switching items from inventory
if ($equip && $deequip && !$swap)
{
if ($cbe['can'] === TRUE)
{
if ($cbe['allowed_slot1'] == $deequip['slot'] || $cbe['allowed_slot2'] == $deequip['slot'])
if ($equip && $deequip && !$swap) {
if ($cbe['can'] === true) {
if ($cbe['allowed_slot1'] == $deequip['slot'] || $cbe['allowed_slot2'] == $deequip['slot']) {
$equipslot = $deequip['slot'];
}
if (!isset($equipslot))
if (!isset($equipslot)) {
return "That item cannot be equipped into that slot.";
}
if ($cbe['two_handed'])
{
if ($cbe['two_handed']) {
$eq = $this->prep_two_hand();
if ($eq !== TRUE)
if ($eq !== true) {
return $eq;
}
}
$this->hero_remove_stats($deequip);
$this->hero_add_stats($equip);
@ -212,32 +207,29 @@ class Item_model extends MO_Model
$this->calc_hero_stats();
return TRUE;
}
else
{
return true;
} else {
return $cbe['message'];
}
}
//switching between 2 slots
if ($equip && $deequip && $swap)
{
if ($equip && $deequip && $swap) {
if (!(($cbe['allowed_slot1'] == $equip['slot'] || $cbe['allowed_slot2'] == $equip['slot']) &&
($cbe['allowed_slot1'] == $deequip['slot'] || $cbe['allowed_slot2'] == $deequip['slot'])))
($cbe['allowed_slot1'] == $deequip['slot'] || $cbe['allowed_slot2'] == $deequip['slot']))) {
return "Those items cannot be swapped";
}
$sql = "UPDATE heros_inventory SET slot = ? WHERE id = ?";
$this->db->query($sql, array($equip['slot'], $deequip['invid']));
$this->db->query($sql, array($deequip['slot'], $equip['invid']));
return TRUE;
return true;
}
//just deequip
if ($deequip && !$swap)
{
if ($deequip && !$swap) {
$sql = "UPDATE heros_inventory SET container = 1, slot = ? WHERE id = ?";
$this->db->query($sql, array($deequipslot, $deequip['invid']));
@ -245,25 +237,26 @@ class Item_model extends MO_Model
$this->hero_remove_stats($deequip);
$this->calc_hero_stats();
return TRUE;
return true;
}
//just equip
if ($equip && !$swap)
{
if (!$cbe['can'])
if ($equip && !$swap) {
if (!$cbe['can']) {
return $cbe['message'];
}
if (!($cbe['allowed_slot1'] == $equipslot || $cbe['allowed_slot2'] == $equipslot))
if (!($cbe['allowed_slot1'] == $equipslot || $cbe['allowed_slot2'] == $equipslot)) {
return 'That item cannot be equipped into that slot.';
}
if ($cbe['two_handed'])
{
if ($cbe['two_handed']) {
$eq = $this->prep_two_hand();
if ($eq !== TRUE)
if ($eq !== true) {
return $eq;
}
}
$sql = "UPDATE heros_inventory SET container = 2, slot = ? WHERE id = ?";
@ -272,27 +265,27 @@ class Item_model extends MO_Model
$this->hero_add_stats($equip);
$this->calc_hero_stats();
return TRUE;
return true;
}
//switching between two equipslots, when one of the slots is empty
if ($swap)
{
if (!($cbe['allowed_slot1'] == $equipslot || $cbe['allowed_slot2'] == $equipslot))
if ($swap) {
if (!($cbe['allowed_slot1'] == $equipslot || $cbe['allowed_slot2'] == $equipslot)) {
return "That item cannot be equipped into that slot";
}
$sql = "UPDATE heros_inventory SET slot = ? WHERE id = ?";
$this->db->query($sql, array($equipslot, $equip['invid']));
return TRUE;
return true;
}
return FALSE;
return false;
}
//unequips the off hand, if the user wants to equip a two-hand wep
function prep_two_hand()
public function prep_two_hand()
{
$sql = "SELECT heros_inventory.id AS invid,heros_inventory.is_soulbound,heros_inventory.stack_size,
heros_inventory.container,heros_inventory.slot,hero_items.*
@ -303,8 +296,9 @@ class Item_model extends MO_Model
$q = $this->db->query($sql, array($this->hero['id']));
if (!$q->num_rows())
return TRUE;
if (!$q->num_rows()) {
return true;
}
$res = $q->row_array();
@ -313,39 +307,33 @@ class Item_model extends MO_Model
$q = $this->db->query($sql, array($this->hero['id']));
$slot = FALSE;
$slot = false;
if ($q->num_rows())
{
if ($q->num_rows()) {
$inv = $q->result_array();
for ($i = 0; $i < parent::INVENTORY_MAX; $i++)
{
$found = FALSE;
for ($i = 0; $i < parent::INVENTORY_MAX; $i++) {
$found = false;
foreach ($inv as $row)
{
if ($row['slot'] == $i)
{
$found = TRUE;
foreach ($inv as $row) {
if ($row['slot'] == $i) {
$found = true;
break;
}
}
if (!$found)
{
if (!$found) {
$slot = $i;
break;
}
}
}
else
{
} else {
$slot = 0;
}
if ($slot === FALSE)
if ($slot === false) {
return "You don't have any space in your inventory, to unequip the off hand.";
}
$this->hero_remove_stats($res);
@ -353,12 +341,11 @@ class Item_model extends MO_Model
$this->db->query($sql, array($slot, $res['invid']));
return TRUE;
return true;
}
//returns ['equipment'], ['money'], ['inventory']
function get_inventory($charid)
public function get_inventory($charid)
{
$sql = "SELECT heros_inventory.is_soulbound,heros_inventory.stack_size,heros_inventory.container,
heros_inventory.slot,hero_items.*
@ -368,36 +355,30 @@ class Item_model extends MO_Model
$q = $this->db->query($sql, array($charid));
if ($q->num_rows())
if ($q->num_rows()) {
$res = $q->result_array();
else
$res = FALSE;
} else {
$res = false;
}
$found = FALSE;
for ($i = 0; $i < parent::INVENTORY_MAX; $i++)
{
if ($res)
{
foreach ($res as $row)
{
if ($row['container'] == 1 && $row['slot'] == $i)
{
$found = false;
for ($i = 0; $i < parent::INVENTORY_MAX; $i++) {
if ($res) {
foreach ($res as $row) {
if ($row['container'] == 1 && $row['slot'] == $i) {
$data[] = $row;
$found = TRUE;
$found = true;
break;
}
}
if (!$found)
{
$data[] = FALSE;
if (!$found) {
$data[] = false;
}
$found = FALSE;
}
else
{
$data[] = FALSE;
$found = false;
} else {
$data[] = false;
}
}
@ -405,84 +386,71 @@ class Item_model extends MO_Model
$r['inventory'] = $data;
if ($res)
{
foreach ($res as $row)
{
if ($row['container'] == 0)
{
if ($res) {
foreach ($res as $row) {
if ($row['container'] == 0) {
$money = $row;
break;
}
}
}
if (isset($money))
if (isset($money)) {
$r['money'] = $money;
else
} else {
$r['money'] = 0;
}
//equipment
$found = FALSE;
for ($i = 0; $i < self::MAX_EQUIPMENT; $i++)
{
if ($res)
{
foreach ($res as $row)
{
if ($row['container'] == 2 && $row['slot'] == $i)
{
$found = false;
for ($i = 0; $i < self::MAX_EQUIPMENT; $i++) {
if ($res) {
foreach ($res as $row) {
if ($row['container'] == 2 && $row['slot'] == $i) {
$eq[] = $row;
$found = TRUE;
$found = true;
break;
}
}
if (!$found)
{
$eq[] = FALSE;
if (!$found) {
$eq[] = false;
}
$found = FALSE;
$found = false;
} else {
$eq[] = false;
}
else
$eq[] = FALSE;
}
$r['equipment'] = $eq;
//sort it, if needed
$found = FALSE;
if ($res)
{
for ($i = 0; $i < self::MAX_EQUIPMENT; $i++)
{
foreach ($eq as $row)
{
if ($row && $row['slot'] == $i)
{
$found = false;
if ($res) {
for ($i = 0; $i < self::MAX_EQUIPMENT; $i++) {
foreach ($eq as $row) {
if ($row && $row['slot'] == $i) {
$seq[] = $row;
$found = TRUE;
$found = true;
break;
}
}
if (!$found)
{
$seq[] = FALSE;
if (!$found) {
$seq[] = false;
}
$found = FALSE;
$found = false;
}
$r['equipment'] = $seq;
}
return $r;
}
function add_item_admin($data)
public function add_item_admin($data)
{
$sql = "INSERT INTO hero_items
VALUES(default,
@ -548,7 +516,7 @@ class Item_model extends MO_Model
$this->_create_sql($sql);
}
function edit_item_admin($data)
public function edit_item_admin($data)
{
$sql = "UPDATE hero_items
SET name = " . $this->db->escape($data['name']) . ",
@ -614,63 +582,66 @@ class Item_model extends MO_Model
$this->_create_sql($sql);
}
function get_item_admin($id)
public function get_item_admin($id)
{
$sql = "SELECT * FROM hero_items WHERE id = ?";
$q = $this->db->query($sql, array($id));
if ($q->num_rows())
if ($q->num_rows()) {
return $q->row_array();
return FALSE;
}
function all_items_admin()
return false;
}
public function all_items_admin()
{
$sql = "SELECT * FROM hero_items";
$q = $this->db->query($sql);
if ($q->num_rows())
if ($q->num_rows()) {
return $q->result_array();
return FALSE;
}
function all_items_drop_admin()
return false;
}
public function all_items_drop_admin()
{
$sql = "SELECT * FROM hero_items";
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->result_array();
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['name'];
}
if (!isset($data))
return FALSE;
if (!isset($data)) {
return false;
}
return $data;
}
function get_class_item_templates($classid)
public function get_class_item_templates($classid)
{
$sql = "SELECT * FROM hero_inventory_templates WHERE classid = ?";
$q = $this->db->query($sql, array($classid));
if ($q->num_rows())
if ($q->num_rows()) {
return $q->result_array();
return FALSE;
}
return false;
}
}
//nowhitesp

View File

@ -1,46 +1,49 @@
<?php
class Log_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function delete_combat_log($id, $villageid)
public function delete_combat_log($id, $villageid)
{
$sql = "SELECT * FROM combat_logs WHERE id='$id'";
$q = $this->db->query($sql);
if (!$q->num_rows())
if (!$q->num_rows()) {
return;
}
$res = $q->row_array();
if ($res['villageid'] != $villageid)
if ($res['villageid'] != $villageid) {
return;
}
$sql = "DELETE FROM combat_logs WHERE id='$id'";
$this->db->query($sql);
}
function get_combat_log($id, $villageid)
public function get_combat_log($id, $villageid)
{
$sql = "SELECT * FROM combat_logs WHERE id='$id'";
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['villageid'] != $villageid)
return FALSE;
if ($res['villageid'] != $villageid) {
return false;
}
if ($res['new'])
{
if ($res['new']) {
$sql = "UPDATE combat_logs SET new='0' WHERE id='$id'";
$this->db->query($sql);
}
@ -48,29 +51,27 @@ class Log_model extends MO_Model
return $res;
}
function get_combat_logs($villageid)
public function get_combat_logs($villageid)
{
$sql = "SELECT * FROM combat_logs WHERE villageid='$villageid' ORDER BY time DESC";
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->result_array();
$new = FALSE;
foreach ($res as $row)
{
if ($row['new'])
{
$new = TRUE;
$new = false;
foreach ($res as $row) {
if ($row['new']) {
$new = true;
break;
}
}
if (!$new)
{
if (!$new) {
$sql = "UPDATE villages SET new_log='0' WHERE id='$villageid'";
$this->db->query($sql);

View File

@ -2,12 +2,12 @@
class Mail_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function save_draft($data, $userid)
public function save_draft($data, $userid)
{
//values id, userid, friend, name, X, Y, time, subject, body
$sql = "INSERT INTO mail_drafts
@ -17,43 +17,46 @@ class Mail_model extends MO_Model
$this->db->query($sql, array(0, $data['name'], 0, 0, $data['subject'], $data['message']));
}
function get_drafts($userid)
public function get_drafts($userid)
{
$sql = "SELECT * FROM mail_drafts WHERE userid='$userid'";
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
return $q->result_array();
}
function get_draft($id, $userid)
public function get_draft($id, $userid)
{
$sql = "SELECT * FROM mail_drafts WHERE id = ?";
$q = $this->db->query($sql, array($id));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['userid'] != $userid)
return FALSE;
if ($res['userid'] != $userid) {
return false;
}
return $res;
}
function delete_draft($id, $userid)
public function delete_draft($id, $userid)
{
$sql = "DELETE FROM mail_drafts WHERE id = ? AND userid = ?";
$this->db->query($sql, array($id, $userid));
}
function get_inbox($userid, $new)
public function get_inbox($userid, $new)
{
$sql = "SELECT mails.*,users.username FROM mails
LEFT JOIN users on mails.sender=users.id
@ -62,26 +65,27 @@ class Mail_model extends MO_Model
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->result_array();
if (!$new)
if (!$new) {
return $res;
}
$found = FALSE;
foreach ($res as $row)
{
if ($row['new'])
{
$found = TRUE;
$found = false;
foreach ($res as $row) {
if ($row['new']) {
$found = true;
break;
}
}
if ($found)
if ($found) {
return $res;
}
$sql = "UPDATE users SET new_mail='0' WHERE id='$userid'";
@ -90,55 +94,52 @@ class Mail_model extends MO_Model
return $res;
}
function send_message($data, $userid)
public function send_message($data, $userid)
{
$sql = "SELECT * FROM users WHERE username = ?";
$q = $this->db->query($sql, array($data['name']));
if (!$q->num_rows())
if (!$q->num_rows()) {
return;
}
$res = $q->row_array();
$data['subject'] = htmlspecialchars($data['subject'], ENT_HTML5, 'UTF-8');
if (strlen($data['subject']) >= 45)
if (strlen($data['subject']) >= 45) {
$data['subject'] = (substr($data['subject'], 0, 45) . '...');
}
//determining line endings
$w = substr_count($data['message'], "\r\n");
if ($w)
if ($w) {
$exp = "\r\n";
else
} else {
$exp = "\n";
}
$message = explode($exp, $data['message']);
if ($message)
{
if ($message) {
$d = "";
foreach ($message as $row)
{
if (strlen($row) > 70)
{
foreach ($message as $row) {
if (strlen($row) > 70) {
//split into multiple lines
for ($i = 0; $i <= (floor(strlen($row) / 70)); $i++)
{
for ($i = 0; $i <= (floor(strlen($row) / 70)); $i++) {
$sub = substr($row, (0 + ($i * 70)), 70);
$d .= $sub;
if (strlen($sub) == 70)
if (strlen($sub) == 70) {
$d .= "«";
}
$d .= "\r\n";
}
}
else
{
} else {
$d .= $row . "\r\n";
}
}
@ -169,7 +170,7 @@ class Mail_model extends MO_Model
$this->db->query($sql, $sent);
}
function get_mail($id, $userid, $edit = FALSE)
public function get_mail($id, $userid, $edit = false)
{
//querying userid here, so if the user types a random id into the browser bar, it won't return anything
$sql = "SELECT mails.*,users.username FROM mails
@ -178,21 +179,20 @@ class Mail_model extends MO_Model
$q = $this->db->query($sql, array($id, $userid));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['new'])
{
if ($res['new']) {
//userid is correct we can query with just the id
$sql = "UPDATE mails SET new='0' WHERE id = ?";
$this->db->query($sql, array($id));
}
if ($edit)
{
if ($edit) {
//just in case
$breaks = array("<br />","<br>","<br/>");
@ -205,28 +205,30 @@ class Mail_model extends MO_Model
return $res;
}
function get_sent($id, $userid)
public function get_sent($id, $userid)
{
//querying userid here, so if the user types a random id into the browser bar, it won't return anything
$sql = "SELECT * FROM mail_sent WHERE id = ? AND userid = ?";
$q = $this->db->query($sql, array($id, $userid));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
return $q->row_array();
}
function get_all_sent($userid)
public function get_all_sent($userid)
{
$sql = "SELECT * FROM mail_sent WHERE userid = ?";
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
return $q->result_array();
}

View File

@ -2,26 +2,27 @@
class Map_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function get_village_by_name($name)
public function get_village_by_name($name)
{
$sql = "SELECT id FROM villages WHERE name LIKE '%" . $name . "%'";
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
return $this->get_village_coords($res['id']);
}
function get_village_coords($vid)
public function get_village_coords($vid)
{
$sql = "SELECT * FROM map WHERE type='3' AND villageid='$vid'";
$q = $this->db->query($sql);
@ -29,19 +30,23 @@ class Map_model extends MO_Model
return $q->row_array();
}
function get_map($x, $y)
public function get_map($x, $y)
{
if ($x < 7)
if ($x < 7) {
$x = 7;
}
if ($y < 7)
if ($y < 7) {
$y = 7;
}
if ($x > 235)
if ($x > 235) {
$x = 235;
}
if ($y > 235)
if ($y > 235) {
$y = 235;
}
$minx = $x - 6;
$maxx = $x + 6;
@ -60,14 +65,10 @@ class Map_model extends MO_Model
$res = $q->result_array();
//preprocess it, so view only have to do a foreach
for ($sy = $miny; $sy < ($miny + 12); $sy++)
{
for ($sx = $minx; $sx < ($minx + 12); $sx++)
{
foreach ($res as $row)
{
if (($row['X'] == $sx) && ($row['Y'] == $sy))
{
for ($sy = $miny; $sy < ($miny + 12); $sy++) {
for ($sx = $minx; $sx < ($minx + 12); $sx++) {
foreach ($res as $row) {
if (($row['X'] == $sx) && ($row['Y'] == $sy)) {
$data[] = $row;
break;
}
@ -78,30 +79,30 @@ class Map_model extends MO_Model
return $data;
}
function get_map_list_admin()
public function get_map_list_admin()
{
$this->load->helper('directory');
$map = directory_map('./sql/map/', 1);
foreach ($map as $row)
{
foreach ($map as $row) {
$a = explode('.', $row);
if (isset($a[1]))
{
if ($a[1] == 'sql')
if (isset($a[1])) {
if ($a[1] == 'sql') {
$data[] = $row;
}
}
if (isset($data))
return $data;
else
return FALSE;
}
function generate_map_admin()
if (isset($data)) {
return $data;
} else {
return false;
}
}
public function generate_map_admin()
{
//process ai village names (in different table) here
//they will be saved into a different file until everything here works correctly
@ -119,13 +120,10 @@ class Map_model extends MO_Model
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
$i = 1;
for ($x = 1; $x <= 240; $x++)
{
for ($y = 1; $y <= 240; $y++)
{
for ($x = 1; $x <= 240; $x++) {
for ($y = 1; $y <= 240; $y++) {
//if ai village space
if (!((($x + 24) % 48) || (($y + 24) % 48)))
{
if (!((($x + 24) % 48) || (($y + 24) % 48))) {
$name = $this->_rand_ai_name();
$a .= "INSERT INTO ai_villages
@ -154,19 +152,15 @@ class Map_model extends MO_Model
$q = $this->db->query($sql);
$villages = $q->result_array();
if ($villages)
{
foreach ($villages as $row)
{
$found = FALSE;
if ($villages) {
foreach ($villages as $row) {
$found = false;
while (!$found)
{
while (!$found) {
$vx = mt_rand(1, 240);
$vy = mt_rand(1, 240);
if (((($vx + 24) % 48) && (($vy + 24) % 48)))
{
if (((($vx + 24) % 48) && (($vy + 24) % 48))) {
//not in ai space
$vdata[] = array(
'id' => $row['id'],
@ -176,54 +170,44 @@ class Map_model extends MO_Model
$found = true;
}
}
}
} else {
$vdata = false;
}
else
$vdata = FALSE;
$villageid = 0;
$ai = 1;
$found = FALSE;
$found = false;
$i = 1;
for ($x = 1; $x <= 240; $x++)
{
for ($y = 1; $y <= 240; $y++)
{
for ($x = 1; $x <= 240; $x++) {
for ($y = 1; $y <= 240; $y++) {
//if not ai village space
if (((($x + 24) % 48) || (($y + 24) % 48)))
{
if ($vdata)
{
foreach ($vdata as $row)
{
if ($row['x'] == $x && $row['y'] == $y)
{
if (((($x + 24) % 48) || (($y + 24) % 48))) {
if ($vdata) {
foreach ($vdata as $row) {
if ($row['x'] == $x && $row['y'] == $y) {
$villageid = $row['id'];
$type = 3;
$found = TRUE;
$found = true;
}
}
}
if (!$found)
{
if (!$found) {
//check for village here, dont let this run when true
$r = rand(0, 100);
if ($r < 70)
if ($r < 70) {
$type = 0;
elseif ($r >= 70 && $r < 85)
} elseif ($r >= 70 && $r < 85) {
$type = 1;
else
} else {
$type = 2;
}
$found = FALSE;
}
else
{
$found = false;
} else {
//ai village space
$type = 4;
$villageid = $ai;
@ -243,7 +227,7 @@ class Map_model extends MO_Model
write_file($f, $a);
}
function apply_map_admin($file)
public function apply_map_admin($file)
{
$this->load->helper('file');
@ -251,13 +235,12 @@ class Map_model extends MO_Model
$sql = explode(';', $f);
foreach ($sql as $row)
{
foreach ($sql as $row) {
$this->db->query($row);
}
}
function _rand_ai_name()
public function _rand_ai_name()
{
//they are in keyboard order from left to right, and top to bottom
@ -272,23 +255,20 @@ class Map_model extends MO_Model
$length = rand(4, 6);
$str = '';
for ($i = 1; $i <= $length; $i++)
{
for ($i = 1; $i <= $length; $i++) {
//start with $a
if ($i % 2)
{
if ($i == 1)
if ($i % 2) {
if ($i == 1) {
$str .= strtoupper($a[mt_rand(0, 20)]);
else
} else {
$str .= $a[mt_rand(0, 20)];
}
else
} else {
$str .= $b[mt_rand(0, 4)];
}
}
return $str;
}
}
//nowhitesp

View File

@ -1,14 +1,10 @@
<?php
class Menu_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
}
//nowhitesp

View File

@ -2,25 +2,26 @@
class Mo_common_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function get_hero_data($userid)
public function get_hero_data($userid)
{
$sql = "SELECT * FROM heroes WHERE userid = ? AND selected = '1'";
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
return $q->row_array();
}
function get_userlevel($uid)
public function get_userlevel($uid)
{
$sql = "SELECT userlevel FROM users WHERE id=$uid";
@ -29,10 +30,9 @@ class Mo_common_model extends MO_Model
$res = $q->row_array();
return $res['userlevel'];
}
function get_username($uid)
public function get_username($uid)
{
$sql = "SELECT username FROM users WHERE id=$uid";
@ -43,16 +43,15 @@ class Mo_common_model extends MO_Model
return $res['username'];
}
function get_userdata($id)
public function get_userdata($id)
{
$sql = "SELECT * FROM users WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
function get_villageid($userid)
public function get_villageid($userid)
{
$sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'";
$q = $this->db->query($sql);
@ -61,13 +60,12 @@ class Mo_common_model extends MO_Model
return $res['id'];
}
function get_village_data($uid)
public function get_village_data($uid)
{
$sql = "SELECT * FROM villages WHERE userid='$uid' AND selected='1'";
$q = $this->db->query($sql);
return $q->row_array();
}
}
//nowhitesp

View File

@ -2,8 +2,7 @@
class News_model extends MO_Model
{
function get_news($page)
public function get_news($page)
{
$p = ($page - 1) * 5;
@ -14,19 +13,18 @@ class News_model extends MO_Model
return $q->result_array();
}
function add_news($text, $uname)
public function add_news($text, $uname)
{
$sql = "INSERT INTO news VALUES(default, '$uname', '$text')";
return $this->db->query($sql);
}
function del_news($id)
public function del_news($id)
{
$sql = "";
return $this->db->query($sql);
}
}
//nowhitesp

View File

@ -1,17 +1,16 @@
<?php
class Resource_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
//calculates how much unit can be created with the available resources
//since where this is called I display resources, its passed from there
function calc_max_unit($unit, $max_num, $res)
{
for ($i = 1; $i <= $max_num; $i++)
public function calc_max_unit($unit, $max_num, $res)
{
for ($i = 1; $i <= $max_num; $i++) {
$res['food'] -= $unit['cost_food'];
$res['wood'] -= $unit['cost_wood'];
$res['stone'] -= $unit['cost_stone'];
@ -21,26 +20,23 @@ class Resource_model extends MO_Model
//not sure if this is needed
if ($res['food'] < 0 && $res['wood'] < 0 &&
$res['stone'] < 0 && $res['iron'] < 0 &&
$res['mana'] < 0)
{
$res['mana'] < 0) {
return ($i - 1);
}
if ($res['food'] < 0 || $res['wood'] < 0 ||
$res['stone'] < 0 || $res['iron'] < 0 ||
$res['mana'] < 0)
{
$res['mana'] < 0) {
return ($i - 1);
}
}
return $max_num;
}
function have_enough_resources_building($buildingid, $villageid)
public function have_enough_resources_building($buildingid, $villageid)
{
$res = $this->get_resources($villageid);
@ -52,13 +48,11 @@ class Resource_model extends MO_Model
$res['wood'] >= $building['cost_wood'] &&
$res['stone'] >= $building['cost_stone'] &&
$res['iron'] >= $building['cost_iron'] &&
$res['mana'] >= $building['cost_mana'])
return TRUE;
return FALSE;
$res['mana'] >= $building['cost_mana']) {
return true;
}
return false;
}
}
//nowhitesp

View File

@ -1,12 +1,12 @@
<?php
class Spell_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function use_spell($spellid, $slotid, $res, $villageid)
public function use_spell($spellid, $slotid, $res, $villageid)
{
$this->resources = $res;
@ -24,16 +24,19 @@ class Spell_model extends MO_Model
$q = $this->db->query($sql);
if (!$q->num_rows())
if (!$q->num_rows()) {
return 1;
}
$spell = $q->row_array();
if ($spell['cooldown_end'])
if ($spell['cooldown_end']) {
return 2;
}
if (!$this->check_resources($res, $spell))
if (!$this->check_resources($res, $spell)) {
return 3;
}
//everything is fine
//substracting cost
@ -44,8 +47,7 @@ class Spell_model extends MO_Model
$this->write_resources();
if ($spell['weather_change_to'])
{
if ($spell['weather_change_to']) {
$sql = "UPDATE villages
SET weather_change_to='" . $spell['weather_change_to'] . "'
WHERE id='$villageid'";
@ -74,7 +76,7 @@ class Spell_model extends MO_Model
$this->add_event($ev);
}
function get_spells($slotid, $villageid)
public function get_spells($slotid, $villageid)
{
$this->update_spells($slotid, $villageid);
@ -93,7 +95,7 @@ class Spell_model extends MO_Model
return $q->result_array();
}
function update_spells($slotid, $villageid)
public function update_spells($slotid, $villageid)
{
$sql = "SELECT * FROM building_spell_cooldowns
WHERE slotid='$slotid'
@ -101,16 +103,15 @@ class Spell_model extends MO_Model
$q = $this->db->query($sql);
if (!$q->num_rows())
if (!$q->num_rows()) {
return;
}
$spells = $q->result_array();
$time = time();
foreach ($spells as $row)
{
if ($row['cooldown_end'] <= $time)
{
foreach ($spells as $row) {
if ($row['cooldown_end'] <= $time) {
$sql = "DELETE FROM building_spell_cooldowns
WHERE id='" . $row['id'] . "'";
$this->db->query($sql);
@ -118,14 +119,14 @@ class Spell_model extends MO_Model
}
}
function get_spell_mod_drop_admin()
public function get_spell_mod_drop_admin()
{
//STUB
$data = array('0' => 'Nothing');
return $data;
}
function list_spells_admin()
public function list_spells_admin()
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
@ -133,7 +134,7 @@ class Spell_model extends MO_Model
return $q->result_array();
}
function get_spell_list_drop_admin()
public function get_spell_list_drop_admin()
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
@ -141,15 +142,14 @@ class Spell_model extends MO_Model
$data[0] = 'No Spell';
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['description_admin'];
}
return $data;
}
function get_spell_admin($id)
public function get_spell_admin($id)
{
$sql = "SELECT * FROM spells WHERE id='$id'";
$q = $this->db->query($sql);
@ -157,9 +157,8 @@ class Spell_model extends MO_Model
return $q->row_array();
}
function edit_spell_admin($data)
public function edit_spell_admin($data)
{
$sql = "UPDATE spells
SET effect='" . $data['effect'] . "',
duration='" . $data['duration'] . "',
@ -194,7 +193,7 @@ class Spell_model extends MO_Model
$this->_create_sql($sql);
}
function add_spell_admin($data)
public function add_spell_admin($data)
{
$sql = "INSERT INTO spells VALUES(default,
'" . $data['effect'] . "',
@ -229,7 +228,7 @@ class Spell_model extends MO_Model
$this->_create_sql($sql);
}
function get_spell_effects_admin()
public function get_spell_effects_admin()
{
//STUB!
$data = array('0' => 'No Effect');

View File

@ -2,7 +2,7 @@
class Sql_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
@ -10,18 +10,18 @@ class Sql_model extends MO_Model
//updates the db version, to current time, only used when saving a change as sql which already in db
//like changes from phpmyadmin
//dummy function to call the inherited _update_db_version($time);
function update_db_version($time)
public function update_db_version($time)
{
$this->_update_db_version($time);
}
//dummy function which uses inherited _create_sql($sql);
function create_sql($sql)
public function create_sql($sql)
{
$this->_create_sql($sql);
}
function get_db_version()
public function get_db_version()
{
$sql = "SELECT version FROM db_version WHERE id='1'";
@ -32,7 +32,7 @@ class Sql_model extends MO_Model
return $res['version'];
}
function get_appliable_files()
public function get_appliable_files()
{
$this->load->helper('file');
//$full_list = get_filenames('./sql');
@ -41,42 +41,38 @@ class Sql_model extends MO_Model
$full_list = directory_map('./sql', 1);
//get out the full db dumps
foreach ($full_list as $row)
{
if (substr_compare($row, 'db', 0, 2, TRUE) && substr_compare($row, 'map', 0, 3, TRUE) &&
substr_compare($row, 'old', 0, 3, TRUE) && substr_compare($row, 'index', 0, 5, TRUE))
{
foreach ($full_list as $row) {
if (substr_compare($row, 'db', 0, 2, true) && substr_compare($row, 'map', 0, 3, true) &&
substr_compare($row, 'old', 0, 3, true) && substr_compare($row, 'index', 0, 5, true)) {
$list[] = $row;
}
}
if (!isset($list))
if (!isset($list)) {
return 0;
}
$ver = $this->get_db_version();
foreach ($list as $row)
{
foreach ($list as $row) {
$l = explode('.', $row);
if ($l[0] > $ver)
{
if ($l[0] > $ver) {
$data[] = $row;
}
}
if (!isset($data))
if (!isset($data)) {
return 0;
}
//getting the max
$max = 0;
foreach ($data as $row)
{
foreach ($data as $row) {
$l = explode('.', $row);
if ($l[0] > $max)
{
if ($l[0] > $max) {
$max = $l[0];
}
}
@ -86,14 +82,11 @@ class Sql_model extends MO_Model
$ordered[] = $max . ".sql";
for ($i = 0; $i < (sizeof($data) - 1); $i++)
{
foreach ($data as $row)
{
for ($i = 0; $i < (sizeof($data) - 1); $i++) {
foreach ($data as $row) {
$l = explode('.', $row);
if (($l[0] < $smallest) && ($l[0] > $last_found))
{
if (($l[0] < $smallest) && ($l[0] > $last_found)) {
$smallest = $l[0];
$ord = $row;
}
@ -104,28 +97,24 @@ class Sql_model extends MO_Model
$ordered[$i] = $ord;
}
if (isset($ordered))
{
if (isset($ordered)) {
return $ordered;
}
else
{
} else {
return 0;
}
}
function apply_all_sql()
public function apply_all_sql()
{
$this->load->helper('file');
$list = $this->get_appliable_files();
if (!$list)
if (!$list) {
return;
}
for ($i = 0; $i < sizeof($list); $i++)
{
for ($i = 0; $i < sizeof($list); $i++) {
//reading file, then applying it to the db
$loc = './sql/' . $list[$i];
$sql = read_file($loc);
@ -143,6 +132,5 @@ class Sql_model extends MO_Model
$this->db->query($sqlv);
}
}
}
//nowhitesp

View File

@ -1,57 +1,57 @@
<?php
class Technology_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function do_research($techid, $res, $slotid, $villageid)
public function do_research($techid, $res, $slotid, $villageid)
{
$this->set_resources($res);
$technology = $this->get_technology($techid);
//no such technology
if (!$technology)
if (!$technology) {
return 1;
}
if (!$this->check_resources($res, $technology))
if (!$this->check_resources($res, $technology)) {
return 2;
}
$tech = $this->get_researchable($slotid, $villageid);
$primary = $tech['primary'];
$secondary = $tech['secondary'];
$found = FALSE;
$group = FALSE;
foreach ($primary as $row)
{
if ($row['id'] == $techid)
{
$found = TRUE;
$found = false;
$group = false;
foreach ($primary as $row) {
if ($row['id'] == $techid) {
$found = true;
$group = 'primary';
break;
}
}
foreach ($secondary as $row)
{
if ($found)
foreach ($secondary as $row) {
if ($found) {
break;
}
if ($row['id'] = $techid)
{
$found = TRUE;
if ($row['id'] = $techid) {
$found = true;
$group = 'secondary';
break;
}
}
//building doesn't have this technology (or user already have it)
if (!$found)
if (!$found) {
return 3;
}
//everything is fine
//substract cost
@ -66,20 +66,20 @@ class Technology_model extends MO_Model
$ev['time'] = $technology['time'];
$ev['data1'] = $techid;
if ($group == 'secondary')
if ($group == 'secondary') {
$ev['data2'] = $slotid;
}
$this->add_event($ev);
}
function get_researchable($slotid, $villageid)
public function get_researchable($slotid, $villageid)
{
$building = $this->get_slot_building($slotid, $villageid);
if (!($building['tech_group'] && $building['tech_secondary_group']))
{
$data['primary'] = FALSE;
$data['secondary'] = FALSE;
if (!($building['tech_group'] && $building['tech_secondary_group'])) {
$data['primary'] = false;
$data['secondary'] = false;
return $data;
}
@ -87,8 +87,10 @@ class Technology_model extends MO_Model
$technologies = $this->get_village_technologies($villageid, $slotid);
//technologies a building can make
$building_tech = $this->get_building_technologies($building['tech_group'],
$building['tech_secondary_group']);
$building_tech = $this->get_building_technologies(
$building['tech_group'],
$building['tech_secondary_group']
);
//technologies that a village (or building) doesn't have
$av_tech = $this->select_technology_not_have($technologies, $building_tech);
@ -96,90 +98,92 @@ class Technology_model extends MO_Model
//getting technology requirements
$requirements = $this->get_requirements($av_tech);
if (!$requirements)
if (!$requirements) {
return $av_tech;
$data['primary'] = $this->apply_requirements($av_tech['primary'],
$requirements);
$data['secondary'] = $this->apply_requirements($av_tech['secondary'],
$requirements);
return $data;
}
function apply_requirements($technologies, $requirements)
{
if (!$technologies)
return FALSE;
$data['primary'] = $this->apply_requirements(
$av_tech['primary'],
$requirements
);
if (!$requirements)
$data['secondary'] = $this->apply_requirements(
$av_tech['secondary'],
$requirements
);
return $data;
}
public function apply_requirements($technologies, $requirements)
{
if (!$technologies) {
return false;
}
if (!$requirements) {
return $technologies;
}
foreach ($technologies as $row)
{
$found = FALSE;
foreach ($requirements as $req)
{
foreach ($technologies as $row) {
$found = false;
foreach ($requirements as $req) {
//if the technology's id matched the current requirement's techid
if ($req['technologyid'] == $row['id'])
{
if ($req['technologyid'] == $row['id']) {
//looking for the matching technology that is required
foreach ($technologies as $tech)
{
if ($req['req_tech_id'] == $tech['id'])
{
$found = TRUE;
foreach ($technologies as $tech) {
if ($req['req_tech_id'] == $tech['id']) {
$found = true;
break;
}
}
}
}
if (!$found)
if (!$found) {
$data[] = $row;
}
if (isset($data))
return $data;
else
return FALSE;
}
function get_requirements($tech)
if (isset($data)) {
return $data;
} else {
return false;
}
}
public function get_requirements($tech)
{
$primary = $tech['primary'];
$secondary = $tech['secondary'];
if (!$primary && !$secondary)
return FALSE;
if (!$primary && !$secondary) {
return false;
}
$sql = "SELECT * FROM technology_requirements
WHERE (";
$first = TRUE;
if ($primary)
{
foreach ($primary as $row)
{
if ($first)
$first = FALSE;
else
$first = true;
if ($primary) {
foreach ($primary as $row) {
if ($first) {
$first = false;
} else {
$sql .= "OR ";
}
$sql .= "technologyid='" . $row['id'] . "' ";
}
}
if ($secondary)
{
foreach ($secondary as $row)
{
if ($first)
$first = FALSE;
else
if ($secondary) {
foreach ($secondary as $row) {
if ($first) {
$first = false;
} else {
$sql .= "OR ";
}
$sql .= "technologyid='" . $row['id'] . "' ";
}
@ -189,87 +193,83 @@ class Technology_model extends MO_Model
$q = $this->db->query($sql);
if ($q->num_rows())
if ($q->num_rows()) {
return $q->result_array();
else
return FALSE;
} else {
return false;
}
}
//TODO better name?
function select_technology_not_have($village_tech, $building_technologies)
public function select_technology_not_have($village_tech, $building_technologies)
{
$primary = $building_technologies['primary'];
$secondary = $building_technologies['secondary'];
//adding only which village doesn't have (primary)
if ($primary)
{
$found = FALSE;
foreach ($primary as $row)
{
foreach ($village_tech as $trow)
{
if ($found)
if ($primary) {
$found = false;
foreach ($primary as $row) {
foreach ($village_tech as $trow) {
if ($found) {
continue;
}
if ($trow['technologyid'] == $row['id'])
{
$found = TRUE;
if ($trow['technologyid'] == $row['id']) {
$found = true;
}
}
if (!$found)
if (!$found) {
$data['primary'][] = $row;
}
$found = FALSE;
$found = false;
}
}
if (!isset($data['primary']))
$data['primary'] = FALSE;
if (!isset($data['primary'])) {
$data['primary'] = false;
}
if ($secondary)
{
if ($secondary) {
//same just with secondary
$found = FALSE;
foreach ($secondary as $row)
{
foreach ($village_tech as $trow)
{
if ($found)
$found = false;
foreach ($secondary as $row) {
foreach ($village_tech as $trow) {
if ($found) {
continue;
}
if ($trow['technologyid'] == $row['id'])
{
$found = TRUE;
if ($trow['technologyid'] == $row['id']) {
$found = true;
}
}
if (!$found)
if (!$found) {
$data['secondary'][] = $row;
}
$found = FALSE;
$found = false;
}
}
if (!isset($data['secondary']))
$data['secondary'] = FALSE;
if (!isset($data['secondary'])) {
$data['secondary'] = false;
}
return $data;
}
function get_building_technologies($id, $secid = 0)
{
if ($secid)
public function get_building_technologies($id, $secid = 0)
{
if ($secid) {
$sql = "SELECT technologies.*,technology_groups.groupid
FROM technology_groups
INNER JOIN technologies
ON technology_groups.technologyid=technologies.id
WHERE (groupid='$id' OR groupid='$secid')";
}
else
{
} else {
$sql = "SELECT technologies.*
FROM technology_groups
INNER JOIN technologies
@ -279,50 +279,47 @@ class Technology_model extends MO_Model
$q = $this->db->query($sql);
if (!$secid)
{
if (!$secid) {
$data['primary'] = $q->result_array();
$data['secondary'] = FALSE;
$data['secondary'] = false;
return $data;
}
$res = $q->result_array();
foreach ($res as $row)
{
if ($row['groupid'] == $id)
{
foreach ($res as $row) {
if ($row['groupid'] == $id) {
$data['primary'][] = $row;
}
else
{
} else {
$data['secondary'][] = $row;
}
}
if (!isset($data['primary']))
$data['primary'] = FALSE;
if (!isset($data['secondary']))
$data['secondary'] = FALSE;
return $data;
if (!isset($data['primary'])) {
$data['primary'] = false;
}
function get_technology($id)
if (!isset($data['secondary'])) {
$data['secondary'] = false;
}
return $data;
}
public function get_technology($id)
{
$sql = "SELECT * FROM technologies WHERE id='$id'";
$q = $this->db->query($sql);
if ($q->num_rows())
if ($q->num_rows()) {
return $q->row_array();
else
return FALSE;
} else {
return false;
}
}
function add_tech_req_admin($techid, $reqid)
public function add_tech_req_admin($techid, $reqid)
{
//dont add if already added
$sql = "SELECT * FROM technology_requirements
@ -331,8 +328,9 @@ class Technology_model extends MO_Model
$q = $this->db->query($sql);
if ($q->num_rows())
if ($q->num_rows()) {
return;
}
$sql = "INSERT INTO technology_requirements
VALUES(default, '$techid', '$reqid')";
@ -342,7 +340,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function remove_tech_req_admin($id)
public function remove_tech_req_admin($id)
{
$sql = "DELETE FROM technology_requirements
WHERE id='$id'";
@ -352,7 +350,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function get_tech_by_req_id_admin($id)
public function get_tech_by_req_id_admin($id)
{
$sql = "SELECT technologies.*
FROM technology_have_requirements
@ -365,7 +363,7 @@ class Technology_model extends MO_Model
return $q->row_array();
}
function get_tech_requirements_admin($id)
public function get_tech_requirements_admin($id)
{
$sql = "SELECT technology_requirements.*,technologies.description
FROM technology_requirements
@ -378,15 +376,16 @@ class Technology_model extends MO_Model
return $q->result_array();
}
function add_to_req_list_admin($data)
public function add_to_req_list_admin($data)
{
$sql = "SELECT * FROM technology_have_requirements
WHERE technologyid='" . $data['technologyid'] . "'";
$q = $this->db->query($sql);
if ($q->num_rows)
if ($q->num_rows) {
return;
}
$sql = "INSERT INTO technology_have_requirements
VALUES(default,
@ -398,7 +397,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function remove_from_req_list_admin($id)
public function remove_from_req_list_admin($id)
{
$sql = "DELETE FROM technology_have_requirements
WHERE id='$id'";
@ -408,7 +407,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function get_req_list_item_admin($id)
public function get_req_list_item_admin($id)
{
$sql = "SELECT technology_have_requirements.*,technologies.description
FROM technology_have_requirements
@ -421,7 +420,7 @@ class Technology_model extends MO_Model
return $q->row_array();
}
function list_tech_have_req_admin()
public function list_tech_have_req_admin()
{
$sql = "SELECT technology_have_requirements.*,technologies.description
FROM technology_have_requirements
@ -432,7 +431,7 @@ class Technology_model extends MO_Model
return $q->result_array();
}
function add_tech_to_group_admin($gid, $techid)
public function add_tech_to_group_admin($gid, $techid)
{
$sql = "INSERT INTO technology_groups
VALUES(default, '$gid', '$techid')";
@ -441,7 +440,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function remove_tech_from_group_admin($gid, $techid)
public function remove_tech_from_group_admin($gid, $techid)
{
$sql = "DELETE FROM technology_groups
WHERE groupid='$gid'
@ -451,7 +450,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function get_group_admin($id)
public function get_group_admin($id)
{
$sql = "SELECT technology_groups.*, technologies.description
FROM technology_groups
@ -463,7 +462,7 @@ class Technology_model extends MO_Model
return $q->result_array();
}
function get_tech_list_drop_admin()
public function get_tech_list_drop_admin()
{
$sql = "SELECT id,description FROM technologies";
$q = $this->db->query($sql);
@ -472,33 +471,32 @@ class Technology_model extends MO_Model
$data[0] = 'Nothing';
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['description'];
}
return $data;
}
function list_tech_drop_admin()
public function list_tech_drop_admin()
{
$sql = "SELECT id,description FROM technologies";
$q = $this->db->query($sql);
$res = $q->result_array();
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['description'];
}
if (isset($data))
if (isset($data)) {
return $data;
else
return FALSE;
} else {
return false;
}
}
function get_tech_group_list_drop_admin()
public function get_tech_group_list_drop_admin()
{
$sql = "SELECT * FROM technology_group_descriptions";
@ -508,15 +506,14 @@ class Technology_model extends MO_Model
$data[0] = 'Nothing';
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['group_name'];
}
return $data;
}
function add_tech_group_desc_admin($data)
public function add_tech_group_desc_admin($data)
{
$sql = "INSERT INTO technology_group_descriptions
VALUES(default, '" . $data['group_name'] . "')";
@ -526,7 +523,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function edit_tech_group_desc_admin($data)
public function edit_tech_group_desc_admin($data)
{
$sql = "UPDATE technology_group_descriptions
SET group_name='" . $data['group_name'] . "'
@ -537,7 +534,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function get_tech_group_desc_admin($id)
public function get_tech_group_desc_admin($id)
{
$sql = "SELECT * FROM technology_group_descriptions WHERE id='$id'";
$q = $this->db->query($sql);
@ -545,7 +542,7 @@ class Technology_model extends MO_Model
return $q->row_array();
}
function list_tech_groups_admin()
public function list_tech_groups_admin()
{
$sql = "SELECT * FROM technology_group_descriptions";
$q = $this->db->query($sql);
@ -553,7 +550,7 @@ class Technology_model extends MO_Model
return $q->result_array();
}
function list_technologies_admin()
public function list_technologies_admin()
{
$sql = "SELECT * FROM technologies";
$q = $this->db->query($sql);
@ -561,7 +558,7 @@ class Technology_model extends MO_Model
return $q->result_array();
}
function get_technology_admin($id)
public function get_technology_admin($id)
{
$sql = "SELECT * FROM technologies WHERE id='$id'";
$q = $this->db->query($sql);
@ -569,9 +566,8 @@ class Technology_model extends MO_Model
return $q->row_array();
}
function edit_technology_admin($data)
public function edit_technology_admin($data)
{
$sql = "UPDATE technologies
SET description='" . $data['description'] . "',
time='" . $data['time'] . "',
@ -607,7 +603,7 @@ class Technology_model extends MO_Model
$this->_create_sql($sql);
}
function add_technology_admin($data)
public function add_technology_admin($data)
{
$sql = "INSERT INTO technologies VALUES(default,
'" . $data['description'] . "',

View File

@ -1,12 +1,12 @@
<?php
class Unit_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function get_village_units($villageid)
public function get_village_units($villageid)
{
$sql = "SELECT users.username,units.*,village_units.userid,village_units.unitcount
FROM village_units
@ -21,7 +21,7 @@ class Unit_model extends MO_Model
return $q->result_array();
}
function get_unit($id)
public function get_unit($id)
{
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
@ -31,43 +31,44 @@ class Unit_model extends MO_Model
//calculates how many units can be created (by lookin at events)
//nothing gets queried
function calc_max_unit_ev($unit_max, $unit_res, $event)
public function calc_max_unit_ev($unit_max, $unit_res, $event)
{
$in_progress = 0;
if ($event)
{
foreach ($event as $row)
{
if ($event) {
foreach ($event as $row) {
$in_progress += $row['data2'];
}
}
//if more are in progress that the building can make
if ($in_progress >= $unit_max)
if ($in_progress >= $unit_max) {
return 0;
}
//calc how many can be made overall
$max = $unit_max - $in_progress;
//if less can be made because of events than the resources allow
if ($max <= $unit_res)
if ($max <= $unit_res) {
return $max;
}
//if events allow more than resources
if ($max > $unit_res)
if ($max > $unit_res) {
return $unit_res;
}
return $max;
}
function list_create_mod_drop_admin()
public function list_create_mod_drop_admin()
{
//STUB
return array('0' => 'Nothing');
}
function list_units_admin()
public function list_units_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
@ -75,7 +76,7 @@ class Unit_model extends MO_Model
return $q->result_array();
}
function get_unit_list_dropdown_admin()
public function get_unit_list_dropdown_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
@ -85,15 +86,14 @@ class Unit_model extends MO_Model
$data[0] = 'Nothing';
foreach ($res as $row)
{
foreach ($res as $row) {
$data[$row['id']] = $row['name'];
}
return $data;
}
function add_unit_admin($data)
public function add_unit_admin($data)
{
$sql = "INSERT INTO units
VALUES(default,
@ -127,7 +127,7 @@ class Unit_model extends MO_Model
$this->_create_sql($sql);
}
function get_unit_admin($id)
public function get_unit_admin($id)
{
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
@ -135,7 +135,7 @@ class Unit_model extends MO_Model
return $q->row_array();
}
function edit_unit_admin($data)
public function edit_unit_admin($data)
{
$sql = "UPDATE units
SET type='" . $data['type'] . "',

View File

@ -2,37 +2,31 @@
class User_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function login_check($data)
public function login_check($data)
{
$sql = "SELECT passkey FROM users WHERE username=" . $this->db->escape($data['username']);
$q = $this->db->query($sql);
if ($q->num_rows > 0)
{
if ($q->num_rows > 0) {
$row = $q->row_array();
if ($row['passkey'] == $data['password'])
{
return TRUE;
if ($row['passkey'] == $data['password']) {
return true;
} else {
return false;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
} else {
return false;
}
}
function get_userid($username)
public function get_userid($username)
{
$sql = "SELECT id FROM users WHERE username=" . $this->db->escape($username);
$q = $this->db->query($sql);
@ -41,23 +35,20 @@ class User_model extends MO_Model
return $res['id'];
}
function reg_username_check($uname)
public function reg_username_check($uname)
{
$sql = "SELECT username FROM users WHERE username=" . $this->db->escape($uname);
$q = $this->db->query($sql);
if ($q->num_rows() == 0)
{
return TRUE;
}
else
{
return FALSE;
if ($q->num_rows() == 0) {
return true;
} else {
return false;
}
}
function reg_write($data)
public function reg_write($data)
{
$sql = "INSERT INTO users VALUES(default, "
. $this->db->escape($data['username']) . ", '"

View File

@ -2,17 +2,18 @@
class Village_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function apply_settings($data)
public function apply_settings($data)
{
if ($data['ai'])
if ($data['ai']) {
$ai = 1;
else
} else {
$ai = 0;
}
$sql = "UPDATE villages
SET name='" . $data['name'] . "',
@ -22,7 +23,7 @@ class Village_model extends MO_Model
$this->db->query($sql);
}
function get_village($id)
public function get_village($id)
{
$sql = "SELECT * FROM villages WHERE id='$id'";
@ -31,23 +32,26 @@ class Village_model extends MO_Model
return $q->row_array();
}
function select_village($id, $userid)
public function select_village($id, $userid)
{
//first check if villageid belongs to user
$sql = "SELECT * FROM villages WHERE id='$id'";
$q = $this->db->query($sql);
if (!$q->num_rows())
if (!$q->num_rows()) {
return;
}
$res = $q->row_array();
if ($res['userid'] != $userid)
if ($res['userid'] != $userid) {
return;
}
if ($res['selected'])
if ($res['selected']) {
return;
}
$sql = "UPDATE villages SET selected='0' WHERE userid='$userid'";
@ -58,7 +62,7 @@ class Village_model extends MO_Model
$this->db->query($sql);
}
function get_villages($userid)
public function get_villages($userid)
{
$sql = "SELECT * FROM villages WHERE userid='$userid' ORDER BY score DESC";
@ -67,7 +71,7 @@ class Village_model extends MO_Model
return $q->result_array();
}
function create_village($userid, $username, $posx = -1, $posy = -1)
public function create_village($userid, $username, $posx = -1, $posy = -1)
{
//make all village unselected
$sql = "UPDATE villages
@ -105,10 +109,9 @@ class Village_model extends MO_Model
$this->db->query($sql);
$found = FALSE;
$found = false;
while(!$found)
{
while (!$found) {
//get a map coordinates
//we should get 20x20 field
//ids start with 1, max is 240
@ -123,11 +126,9 @@ class Village_model extends MO_Model
$res = $q->result_array();
foreach ($res as $row)
{
if ($row['type'] == 0)
{
$found = TRUE;
foreach ($res as $row) {
if ($row['type'] == 0) {
$found = true;
$sql = "UPDATE map SET type='3', villageid='$id' WHERE id='" . $row['id'] . "'";
@ -135,13 +136,12 @@ class Village_model extends MO_Model
break;
}
}
}
}
//slotids range from 1 to parent::TOTAL_BUILDINGS!
//slot 0 can be used for a wall or something
function get_buildings($vid)
public function get_buildings($vid)
{
//tODO Empty slots
@ -159,32 +159,24 @@ class Village_model extends MO_Model
$q = $this->db->query($sql);
$res = $q->result_array();
$new = FALSE;
$new = false;
$j = 0;
for ($i = 1; $i <= parent::TOTAL_BUILDINGS;$i++)
{
if (isset($res[$j]))
{
if ($res[$j]['slotid'] == $i)
{
for ($i = 1; $i <= parent::TOTAL_BUILDINGS;$i++) {
if (isset($res[$j])) {
if ($res[$j]['slotid'] == $i) {
$data[] = $res[$j];
$j++;
} else {
$new = true;
}
else
{
$new = TRUE;
}
}
else
{
$new = TRUE;
} else {
$new = true;
}
if ($new)
{
if ($new) {
$data[] = $space;
$new = FALSE;
$new = false;
}
}

View File

@ -1,12 +1,12 @@
<?php
class Weather_model extends MO_Model
{
function __construct()
public function __construct()
{
parent::__construct();
}
function get_weathers_drop_admin()
public function get_weathers_drop_admin()
{
$sql = "SELECT * FROM weathers";
$q = $this->db->query($sql);
@ -15,15 +15,14 @@ class Weather_model extends MO_Model
$data[] = 'Nothing';
foreach ($res as $row)
{
foreach ($res as $row) {
$data[] = $row['name'];
}
return $data;
}
function get_weather_effects_drop_admin()
public function get_weather_effects_drop_admin()
{
$data[0] = 'No Effect';
$data[1] = 'Fires';
@ -31,7 +30,7 @@ class Weather_model extends MO_Model
return $data;
}
function list_weathers_admin()
public function list_weathers_admin()
{
$sql = "SELECT * FROM weathers";
$q = $this->db->query($sql);
@ -39,7 +38,7 @@ class Weather_model extends MO_Model
return $q->result_array();
}
function get_weather_admin($id)
public function get_weather_admin($id)
{
$sql = "SELECT * FROM weathers WHERE id='$id'";
$q = $this->db->query($sql);
@ -47,9 +46,8 @@ class Weather_model extends MO_Model
return $q->row_array();
}
function edit_weather_admin($data)
public function edit_weather_admin($data)
{
$sql = "UPDATE weathers
SET name='" . $data['name'] . "',
description='" . $data['description'] . "',
@ -73,7 +71,7 @@ class Weather_model extends MO_Model
$this->_create_sql($sql);
}
function add_weather_admin($data)
public function add_weather_admin($data)
{
$sql = "INSERT INTO weathers VALUES(default,
'" . $data['name'] . "',
@ -96,6 +94,5 @@ class Weather_model extends MO_Model
$this->_create_sql($sql);
}
}
//nowhitesp

View File

@ -23,17 +23,14 @@ $attr_submit = array(
'value' => 'Submit',
'class' => 'submit');
if ($new)
{
if ($new) {
//set every value with set_value()
$link_form = 'admin/ai_settings';
$attr_setting['value'] = set_value('setting');
$attr_value['value'] = set_value('value');
$attr_description['value'] = set_value('description');
}
else
{
} else {
//set every value from data sent
$link_form = 'admin/ai_settings/' . $setting['id'];