From aa2664c200ca7436b9e442508c2186f9b9ddf365 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 14 Nov 2021 11:02:22 +0100 Subject: [PATCH] Ran a code formatter on most of the old php to fix indents in vscode. --- Mourne-CI/application/controllers/admin.php | 3354 ++++++++--------- .../application/controllers/alliance.php | 27 +- .../application/controllers/building.php | 1258 +++---- .../application/controllers/changelog.php | 111 +- Mourne-CI/application/controllers/cron.php | 27 +- Mourne-CI/application/controllers/forum.php | 23 +- Mourne-CI/application/controllers/gm.php | 20 +- Mourne-CI/application/controllers/hero.php | 306 +- Mourne-CI/application/controllers/mail.php | 253 +- Mourne-CI/application/controllers/news.php | 101 +- Mourne-CI/application/controllers/user.php | 215 +- Mourne-CI/application/controllers/village.php | 419 +- Mourne-CI/application/core/MO_Controller.php | 673 ++-- Mourne-CI/application/core/MO_Model.php | 2360 ++++++------ .../application/helpers/class_helper.php | 52 +- .../application/helpers/equipment_helper.php | 298 +- .../application/helpers/event_helper.php | 34 +- Mourne-CI/application/helpers/murl_helper.php | 34 +- Mourne-CI/application/models/ai_model.php | 553 ++- .../application/models/assignment_model.php | 459 ++- .../application/models/building_model.php | 279 +- .../application/models/changelog_model.php | 71 +- Mourne-CI/application/models/cron_model.php | 11 +- Mourne-CI/application/models/event_model.php | 1929 +++++----- Mourne-CI/application/models/hero_model.php | 423 ++- Mourne-CI/application/models/image_model.php | 475 ++- Mourne-CI/application/models/item_model.php | 895 +++-- Mourne-CI/application/models/log_model.php | 137 +- Mourne-CI/application/models/mail_model.php | 340 +- Mourne-CI/application/models/map_model.php | 424 +-- Mourne-CI/application/models/menu_model.php | 14 +- .../application/models/mo_common_model.php | 100 +- Mourne-CI/application/models/news_model.php | 38 +- .../application/models/resource_model.php | 96 +- Mourne-CI/application/models/spell_model.php | 229 +- Mourne-CI/application/models/sql_model.php | 228 +- .../application/models/technology_model.php | 898 +++-- Mourne-CI/application/models/unit_model.php | 192 +- Mourne-CI/application/models/user_model.php | 101 +- .../application/models/village_model.php | 250 +- .../application/models/weather_model.php | 99 +- .../views/admin/ai_settings_tool/settings.php | 49 +- 42 files changed, 8688 insertions(+), 9167 deletions(-) diff --git a/Mourne-CI/application/controllers/admin.php b/Mourne-CI/application/controllers/admin.php index c06e3c7..232621f 100755 --- a/Mourne-CI/application/controllers/admin.php +++ b/Mourne-CI/application/controllers/admin.php @@ -1,1935 +1,1879 @@ userlevel < 5) show_404(); - - $this->headers('admin'); - $this->load->view('admin/panel.php'); - $this->footer(); - } - - function building_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('building_model'); - - $data['buildings'] = $this->building_model->list_buildings_admin(); - - $this->headers('admin'); - $this->load->view('admin/building_tool/list.php', $data); - $this->footer(); - } - - function building($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('building_model'); - $this->load->model('unit_model'); - $this->load->model('assignment_model'); - $this->load->model('technology_model'); - - $this->form_validation->set_rules('name', 'Name', 'required'); - $this->form_validation->set_rules('description', 'Description', 'alphanumeric'); - $this->form_validation->set_rules('icon', 'Icon', 'required'); - $this->form_validation->set_rules('rank', 'Rank', 'integer'); - $data['nextr'] = $this->input->post('next_rank'); //has to be done like this :( - $data['optnr'] = $this->building_model->get_building_ranks_admin(); - - $this->form_validation->set_rules('time_to_build', 'Time to Build', 'integer'); - - //creates - $data['screate'] = $this->input->post('creates'); - $data['optcre'] = $this->unit_model->get_unit_list_dropdown_admin(); - - $this->form_validation->set_rules('num_creates', 'Num Creates', 'integer'); - - $this->form_validation->set_rules('score', 'Score', 'integer'); - $this->form_validation->set_rules('defense', 'Defense', 'integer'); - - $data['sability'] = $this->input->post('ability'); - - $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); - $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); - $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); - $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); - $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); - - $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); - $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); - $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); - $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); - $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); - - $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); - $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); - $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); - $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); - $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); - - $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); - $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); - $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); - $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); - $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); - - //assignments - $data['optass'] = $this->assignment_model->get_assignment_list_drop_admin(); - $data['assign1'] = $this->input->post('assign1'); - $data['assign2'] = $this->input->post('assign2'); - $data['assign3'] = $this->input->post('assign3'); - $data['assign4'] = $this->input->post('assign4'); - $data['assign5'] = $this->input->post('assign5'); - - $data['optreqtech'] = $this->technology_model->get_tech_list_drop_admin(); - $data['selreqtech'] = $this->input->post('req_tech'); - - $data['opttechgroup'] = $this->technology_model->get_tech_group_list_drop_admin(); - - $data['seltechgroup'] = $this->input->post('tech_group'); - $data['seltechsecgroup'] = $this->input->post('tech_secondary_group'); - - if (!$this->form_validation->run()) + public function __construct() { - $this->headers('admin'); - - if ($id == -1) - { - //making new - $data['new'] = TRUE; - - $this->load->view('admin/building_tool/building', $data); - } - else - { - //editing - $data['new'] = FALSE; - - $data['building'] = $this->building_model->get_building_admin($id); - - $this->load->view('admin/building_tool/building', $data); - } - - $this->footer(); - } - else - { - $data['id'] = $id; - $data['name'] = $this->input->post('name'); - $data['description'] = $this->input->post('description'); - $data['icon'] = $this->input->post('icon'); - $data['rank'] = $this->input->post('rank'); - $data['next_rank'] = $this->input->post('next_rank'); - $data['time_to_build'] = $this->input->post('time_to_build'); - - $data['creates'] = $this->input->post('creates'); - $data['num_creates'] = $this->input->post('num_creates'); - - $data['score'] = $this->input->post('score'); - $data['defense'] = $this->input->post('defense'); - $data['ability'] = $this->input->post('ability'); - - $data['cost_food'] = $this->input->post('cost_food'); - $data['cost_wood'] = $this->input->post('cost_wood'); - $data['cost_stone'] = $this->input->post('cost_stone'); - $data['cost_iron'] = $this->input->post('cost_iron'); - $data['cost_mana'] = $this->input->post('cost_mana'); - - $data['mod_max_food'] = $this->input->post('mod_max_food'); - $data['mod_max_wood'] = $this->input->post('mod_max_wood'); - $data['mod_max_stone'] = $this->input->post('mod_max_stone'); - $data['mod_max_iron'] = $this->input->post('mod_max_iron'); - $data['mod_max_mana'] = $this->input->post('mod_max_mana'); - - $data['mod_rate_food'] = $this->input->post('mod_rate_food'); - $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); - $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); - $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); - $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); - - $data['mod_percent_food'] = $this->input->post('mod_percent_food'); - $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); - $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); - $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); - $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); - - $data['assignment1'] = $this->input->post('assign1'); - $data['assignment2'] = $this->input->post('assign2'); - $data['assignment3'] = $this->input->post('assign3'); - $data['assignment4'] = $this->input->post('assign4'); - $data['assignment5'] = $this->input->post('assign5'); - - $data['req_tech'] = $this->input->post('req_tech'); - - $data['tech_group'] = $this->input->post('tech_group'); - $data['tech_secondary_group'] = $this->input->post('tech_secondary_group'); - - $this->load->model('building_model'); - - if ($id == -1) - { - //making new - $this->building_model->add_building_admin($data); - } - else - { - //editing - $this->building_model->edit_building_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/building_tool'); - } - } - -//unit tool - function unit_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('unit_model'); - - $data['units'] = $this->unit_model->list_units_admin(); - - $this->headers('admin'); - $this->load->view('admin/unit_tool/list.php', $data); - $this->footer(); - } - - function unit($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('unit_model'); - $this->load->model('ai_model'); - - $this->form_validation->set_rules('name', 'Name', 'required'); - $this->form_validation->set_rules('icon', 'Icon', 'required'); - $this->form_validation->set_rules('type', 'Type', 'integer'); - - $this->form_validation->set_rules('score', 'Score', 'integer'); - - $data['scd'] = $this->input->post('can_defend'); - - $this->form_validation->set_rules('defense', 'Type', 'numeric'); - $this->form_validation->set_rules('attack', 'Type', 'numeric'); - - $data['sstrong'] = $this->input->post('strong_against'); - $data['sweak'] = $this->input->post('weak_against'); - - $data['optaiu'] = $this->ai_model->get_unit_list_drop_admin(); - - $this->form_validation->set_rules('turn', 'Turn', 'integer'); - $this->form_validation->set_rules('ability', 'Ability', 'integer'); - - $this->form_validation->set_rules('time_to_create', 'Time to Create', 'integer'); - - $data['costu'] = $this->input->post('cost_unit'); //has to be done like this :( - $data['optu'] = $this->unit_model->get_unit_list_dropdown_admin(); - - $this->form_validation->set_rules('cost_num_unit', 'Cost Number of Units', 'integer'); - - $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); - $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); - $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); - $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); - $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); - - $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); - $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); - $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); - $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); - $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); - - if (!$this->form_validation->run()) - { - $this->headers('admin'); - - if ($id == -1) - { - //making new - $data['new'] = TRUE; - - $this->load->view('admin/unit_tool/unit', $data); - } - else - { - //editing - $data['new'] = FALSE; - - $data['unit'] = $this->unit_model->get_unit_admin($id); - - $this->load->view('admin/unit_tool/unit', $data); - } - - $this->footer(); - } - else - { - $data['id'] = $id; - $data['type'] = $this->input->post('type'); - $data['name'] = $this->input->post('name'); - $data['icon'] = $this->input->post('icon'); - $data['score'] = $this->input->post('score'); - - $data['can_defend'] = $this->input->post('can_defend'); - $data['defense'] = $this->input->post('defense'); - $data['attack'] = $this->input->post('attack'); - $data['weak_against'] = $this->input->post('weak_against'); - $data['strong_against'] = $this->input->post('strong_against'); - $data['turn'] = $this->input->post('turn'); - $data['ability'] = $this->input->post('ability'); - - $data['time_to_create'] = $this->input->post('time_to_create'); - - $data['cost_unit'] = $this->input->post('cost_unit'); - $data['cost_num_unit'] = $this->input->post('cost_num_unit'); - - $data['cost_food'] = $this->input->post('cost_food'); - $data['cost_wood'] = $this->input->post('cost_wood'); - $data['cost_stone'] = $this->input->post('cost_stone'); - $data['cost_iron'] = $this->input->post('cost_iron'); - $data['cost_mana'] = $this->input->post('cost_mana'); - - $data['mod_rate_food'] = $this->input->post('mod_rate_food'); - $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); - $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); - $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); - $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); - - $this->load->model('unit_model'); - - if ($id == -1) - { - //making new - $this->unit_model->add_unit_admin($data); - } - else - { - //editing - $this->unit_model->edit_unit_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/unit_tool'); - } - } - -//assignment tool - function assignment_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('assignment_model'); - - $data['assignments'] = $this->assignment_model->get_assignments_admin(); - - $this->headers('admin'); - $this->load->view('admin/assignment_tool/list.php', $data); - $this->footer(); - } - - function assignment($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('assignment_model'); - $this->load->model('unit_model'); - $this->load->model('spell_model'); - $this->load->model('technology_model'); - - //assign - $data['sassign'] = $this->input->post('unitid'); - $data['optass'] = $this->unit_model->get_unit_list_dropdown_admin(); - - $this->form_validation->set_rules('max', 'Max Assign', 'is_natural|required'); - $this->form_validation->set_rules('bonus_per_assigned', 'Assigned/bonus', - 'integer'); - - $data['ssp'] = $this->input->post('spellid'); - $data['optsp'] = $this->spell_model->get_spell_list_drop_admin(); - - $data['srtech'] = $this->input->post('req_tech'); - $data['optrtech'] = $this->technology_model->get_tech_list_drop_admin(); - - $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); - $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); - $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); - $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); - $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); - - $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); - $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); - $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); - $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); - $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); - - $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'numeric'); - $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'numeric'); - $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'numeric'); - $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'numeric'); - $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'numeric'); - - $this->form_validation->set_rules('description', 'Description', 'alphanumeric'); - - if (!$this->form_validation->run()) - { - $this->headers('admin'); - - if ($id == -1) - { - //making new - $data['new'] = TRUE; - - $this->load->view('admin/assignment_tool/assignment', $data); - } - else - { - //editing - $data['new'] = FALSE; - - $data['assignment'] = $this->assignment_model->get_assignment_admin($id); - - $this->load->view('admin/assignment_tool/assignment', $data); - } - - $this->footer(); - } - else - { - $data['id'] = $id; - $data['unitid'] = $this->input->post('unitid'); - $data['max'] = $this->input->post('max'); - $data['bonus_per_assigned'] = $this->input->post('bonus_per_assigned'); - $data['spellid'] = $this->input->post('spellid'); - $data['req_tech'] = $this->input->post('req_tech'); - - $data['mod_max_food'] = $this->input->post('mod_max_food'); - $data['mod_max_wood'] = $this->input->post('mod_max_wood'); - $data['mod_max_stone'] = $this->input->post('mod_max_stone'); - $data['mod_max_iron'] = $this->input->post('mod_max_iron'); - $data['mod_max_mana'] = $this->input->post('mod_max_mana'); - - $data['mod_rate_food'] = $this->input->post('mod_rate_food'); - $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); - $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); - $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); - $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); - - $data['mod_percent_food'] = $this->input->post('mod_percent_food'); - $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); - $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); - $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); - $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); - - $data['description'] = $this->input->post('description'); - - $this->load->model('assignment_model'); - - if ($id == -1) - { - //making new - $this->assignment_model->add_assignment_admin($data); - } - else - { - //editing - $this->assignment_model->edit_assignment_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/assignment_tool'); - } - } - -//technology tool - function technology_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('technology_model'); - - $data['technologies'] = $this->technology_model->list_technologies_admin(); - - $this->headers('admin'); - $this->load->view('admin/technology_tool/list.php', $data); - $this->footer(); - } - - function technology($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('technology_model'); - $this->load->model('spell_model'); - $this->load->model('unit_model'); - - $this->form_validation->set_rules('description', 'Description', 'required'); - - $this->form_validation->set_rules('time', 'Time', 'integer'); - - $this->form_validation->set_rules('score', 'Score', 'integer'); - - $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); - $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); - $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); - $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); - $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); - - $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); - $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); - $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); - $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); - $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); - - $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); - $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); - $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); - $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); - $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); - - $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); - $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); - $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); - $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); - $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); - - - //mod_spell_id dropdown - $data['mspidopt'] = $this->spell_model->get_spell_mod_drop_admin(); - $data['sspid'] = $this->input->post('mod_spell_id'); - - //mod_create_id dropdown - $data['mcidopt'] = $this->unit_model->list_create_mod_drop_admin(); - $data['smcid'] = $this->input->post('mod_create_id'); - - $data['sflai'] = $this->input->post('flag_ai'); - - $data['selissec'] = $this->input->post('is_secondary'); - - if (!$this->form_validation->run()) - { - $this->headers('admin'); - - if ($id == -1) - { - //making new - $data['new'] = TRUE; - - $this->load->view('admin/technology_tool/technology', $data); - } - else - { - //editing - $data['new'] = FALSE; - - $data['technology'] = $this->technology_model->get_technology_admin( - $id); - - $this->load->view('admin/technology_tool/technology', $data); - } - - $this->footer(); - } - else - { - $data['id'] = $id; - $data['description'] = $this->input->post('description'); - - $data['time'] = $this->input->post('time'); - - $data['score'] = $this->input->post('score'); - - $data['cost_food'] = $this->input->post('cost_food'); - $data['cost_wood'] = $this->input->post('cost_wood'); - $data['cost_stone'] = $this->input->post('cost_stone'); - $data['cost_iron'] = $this->input->post('cost_iron'); - $data['cost_mana'] = $this->input->post('cost_mana'); - - $data['mod_max_food'] = $this->input->post('mod_max_food'); - $data['mod_max_wood'] = $this->input->post('mod_max_wood'); - $data['mod_max_stone'] = $this->input->post('mod_max_stone'); - $data['mod_max_iron'] = $this->input->post('mod_max_iron'); - $data['mod_max_mana'] = $this->input->post('mod_max_mana'); - - $data['mod_rate_food'] = $this->input->post('mod_rate_food'); - $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); - $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); - $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); - $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); - - $data['mod_percent_food'] = $this->input->post('mod_percent_food'); - $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); - $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); - $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); - $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); - - $data['mod_create_id'] = $this->input->post('mod_create_id'); - $data['mod_spell_id'] = $this->input->post('mod_spell_id'); - - $data['flag_ai'] = $this->input->post('flag_ai'); - - $data['is_secondary'] = $this->input->post('is_secondary'); - - $this->load->model('building_model'); - - if ($id == -1) - { - //making new - $this->technology_model->add_technology_admin($data); - } - else - { - //editing - $this->technology_model->edit_technology_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/technology_tool'); - } - } - -//technology_group_tool - function technology_group_desc($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('technology_model'); - - $this->form_validation->set_rules('group_name', 'Group Name', 'required'); - - if (!$this->form_validation->run()) - { - $this->headers('admin'); - - if ($id == -1) - { - //making new - $data['new'] = TRUE; - - $this->load->view('admin/technology_group_tool/tech_group_desc', - $data); - } - else - { - //editing - $data['new'] = FALSE; - - $data['group'] = $this->technology_model->get_tech_group_desc_admin( - $id); - - $this->load->view('admin/technology_group_tool/tech_group_desc', - $data); - } - - $this->footer(); - } - else - { - $data['id'] = $id; - $data['group_name'] = $this->input->post('group_name'); - - $this->load->model('technology_model'); - - if ($id == -1) - { - //making new - $this->technology_model->add_tech_group_desc_admin($data); - } - else - { - //editing - $this->technology_model->edit_tech_group_desc_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/technology_group_tool'); - } - } - -//technology group tool - function technology_group_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('technology_model'); - - $data['groups'] = $this->technology_model->list_tech_groups_admin(); - - $this->headers('admin'); - $this->load->view('admin/technology_group_tool/list.php', $data); - $this->footer(); - } - - function technology_group($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('technology_model'); - - $this->form_validation->set_rules('action', 'Action', 'required'); - - if (!$this->form_validation->run()) - { - $this->headers('admin'); - - $data['id'] = $id; - $data['group'] = $this->technology_model->get_group_admin($id); - $data['opttech'] = $this->technology_model->list_tech_drop_admin(); - $data['seltech'] = $this->input->post('add'); - - $this->load->view('admin/technology_group_tool/tech_groups', $data); - - $this->footer(); - } - else - { - $action = $this->input->post('action'); - - $this->load->model('technology_model'); - - if ($action == 'add') - { - $techid = $this->input->post('add'); - - $this->technology_model->add_tech_to_group_admin($id, $techid); - } - elseif ($action == 'delete') - { - $techid = $this->input->post('id'); - $this->technology_model->remove_tech_from_group_admin($id, $techid); - } - $this->load->helper('url'); - - redirect('admin/technology_group/' . $id); - } - } - -//technology requirements tool - function technology_requirements_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('technology_model'); - - $data['technologies'] = $this->technology_model->list_tech_have_req_admin(); - - $this->headers('admin'); - $this->load->view('admin/technology_requirements_tool/list.php', $data); - $this->footer(); - } - - function have_technology_requirement($id = -1) - { - if ($this->userlevel < 5) show_404(); - - if (!$id) - { - $this->load->helper('url'); - redirect('admin/admin_panel'); + parent::__construct(); } - $this->load->library('form_validation'); - - $this->form_validation->set_rules('action', 'Action', 'required'); - - $this->load->model('technology_model'); - - if (!$this->form_validation->run()) + public function admin_panel() { - $this->headers('admin'); + if ($this->userlevel < 5) { + show_404(); + } - if ($id == -1) - { - $data['opts'] = $this->technology_model->list_tech_drop_admin(); - - $this->load->view('admin/technology_requirements_tool/add_to_list', - $data); - - } - else - { - $data['id'] = $id; - $data['tech'] = $this->technology_model->get_req_list_item_admin( - $id); - - $this->load->view('admin/technology_requirements_tool/remove_conf', - $data); - } - - $this->footer(); + $this->headers('admin'); + $this->load->view('admin/panel.php'); + $this->footer(); } - else + + public function building_tool() { - $action = $this->input->post('action'); + if ($this->userlevel < 5) { + show_404(); + } - if ($action == 'new') - { - $data['technologyid'] = $this->input->post('technologyid'); - $data['comment'] = $this->input->post('comment'); + $this->load->model('building_model'); - $this->technology_model->add_to_req_list_admin($data); - } + $data['buildings'] = $this->building_model->list_buildings_admin(); - if ($action == 'delete') - { - $id = $this->input->post('technologyid'); - - $this->technology_model->remove_from_req_list_admin($id); - } - - $this->load->helper('url'); - redirect('admin/technology_requirements_tool'); + $this->headers('admin'); + $this->load->view('admin/building_tool/list.php', $data); + $this->footer(); } - } - function technology_requirements($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('technology_model'); - - $this->form_validation->set_rules('action', 'Action', 'required'); - - if (!$this->form_validation->run()) + public function building($id = -1) { - $this->headers('admin'); + if ($this->userlevel < 5) { + show_404(); + } - $data['id'] = $id; - + $this->load->library('form_validation'); + $this->load->model('building_model'); + $this->load->model('unit_model'); + $this->load->model('assignment_model'); + $this->load->model('technology_model'); - $data['technology'] = $this->technology_model->get_tech_by_req_id_admin( - $id); - $data['required'] = $this->technology_model->get_tech_requirements_admin( - $data['technology']['id']); + $this->form_validation->set_rules('name', 'Name', 'required'); + $this->form_validation->set_rules('description', 'Description', 'alphanumeric'); + $this->form_validation->set_rules('icon', 'Icon', 'required'); + $this->form_validation->set_rules('rank', 'Rank', 'integer'); + $data['nextr'] = $this->input->post('next_rank'); //has to be done like this :( + $data['optnr'] = $this->building_model->get_building_ranks_admin(); - $data['opttech'] = $this->technology_model->list_tech_drop_admin(); - $data['seltech'] = $this->input->post('add'); + $this->form_validation->set_rules('time_to_build', 'Time to Build', 'integer'); - $this->load->view('admin/technology_requirements_tool/tech_req', $data); + //creates + $data['screate'] = $this->input->post('creates'); + $data['optcre'] = $this->unit_model->get_unit_list_dropdown_admin(); - $this->footer(); + $this->form_validation->set_rules('num_creates', 'Num Creates', 'integer'); + + $this->form_validation->set_rules('score', 'Score', 'integer'); + $this->form_validation->set_rules('defense', 'Defense', 'integer'); + + $data['sability'] = $this->input->post('ability'); + + $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); + $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); + $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); + $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); + $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); + + $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); + $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); + $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); + $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); + $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); + + $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); + $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); + $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); + $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); + $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); + + $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); + $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); + $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); + $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); + $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); + + //assignments + $data['optass'] = $this->assignment_model->get_assignment_list_drop_admin(); + $data['assign1'] = $this->input->post('assign1'); + $data['assign2'] = $this->input->post('assign2'); + $data['assign3'] = $this->input->post('assign3'); + $data['assign4'] = $this->input->post('assign4'); + $data['assign5'] = $this->input->post('assign5'); + + $data['optreqtech'] = $this->technology_model->get_tech_list_drop_admin(); + $data['selreqtech'] = $this->input->post('req_tech'); + + $data['opttechgroup'] = $this->technology_model->get_tech_group_list_drop_admin(); + + $data['seltechgroup'] = $this->input->post('tech_group'); + $data['seltechsecgroup'] = $this->input->post('tech_secondary_group'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view('admin/building_tool/building', $data); + } else { + //editing + $data['new'] = false; + + $data['building'] = $this->building_model->get_building_admin($id); + + $this->load->view('admin/building_tool/building', $data); + } + + $this->footer(); + } else { + $data['id'] = $id; + $data['name'] = $this->input->post('name'); + $data['description'] = $this->input->post('description'); + $data['icon'] = $this->input->post('icon'); + $data['rank'] = $this->input->post('rank'); + $data['next_rank'] = $this->input->post('next_rank'); + $data['time_to_build'] = $this->input->post('time_to_build'); + + $data['creates'] = $this->input->post('creates'); + $data['num_creates'] = $this->input->post('num_creates'); + + $data['score'] = $this->input->post('score'); + $data['defense'] = $this->input->post('defense'); + $data['ability'] = $this->input->post('ability'); + + $data['cost_food'] = $this->input->post('cost_food'); + $data['cost_wood'] = $this->input->post('cost_wood'); + $data['cost_stone'] = $this->input->post('cost_stone'); + $data['cost_iron'] = $this->input->post('cost_iron'); + $data['cost_mana'] = $this->input->post('cost_mana'); + + $data['mod_max_food'] = $this->input->post('mod_max_food'); + $data['mod_max_wood'] = $this->input->post('mod_max_wood'); + $data['mod_max_stone'] = $this->input->post('mod_max_stone'); + $data['mod_max_iron'] = $this->input->post('mod_max_iron'); + $data['mod_max_mana'] = $this->input->post('mod_max_mana'); + + $data['mod_rate_food'] = $this->input->post('mod_rate_food'); + $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); + $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); + $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); + $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); + + $data['mod_percent_food'] = $this->input->post('mod_percent_food'); + $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); + $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); + $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); + $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); + + $data['assignment1'] = $this->input->post('assign1'); + $data['assignment2'] = $this->input->post('assign2'); + $data['assignment3'] = $this->input->post('assign3'); + $data['assignment4'] = $this->input->post('assign4'); + $data['assignment5'] = $this->input->post('assign5'); + + $data['req_tech'] = $this->input->post('req_tech'); + + $data['tech_group'] = $this->input->post('tech_group'); + $data['tech_secondary_group'] = $this->input->post('tech_secondary_group'); + + $this->load->model('building_model'); + + if ($id == -1) { + //making new + $this->building_model->add_building_admin($data); + } else { + //editing + $this->building_model->edit_building_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/building_tool'); + } } - else + + //unit tool + public function unit_tool() { - $action = $this->input->post('action'); - - if ($action == 'add') - { - $techid = $this->input->post('technologyid'); - $addtechid = $this->input->post('add'); + if ($this->userlevel < 5) { + show_404(); + } - $this->technology_model->add_tech_req_admin($techid, $addtechid); - } - elseif ($action == 'delete') - { - $tid = $this->input->post('id'); - $this->technology_model->remove_tech_req_admin($tid); - } - $this->load->helper('url'); + $this->load->model('unit_model'); - redirect('admin/technology_requirements/' . $id); + $data['units'] = $this->unit_model->list_units_admin(); + + $this->headers('admin'); + $this->load->view('admin/unit_tool/list.php', $data); + $this->footer(); } - } -//spell_tool - function spell_tool() - { - if ($this->userlevel < 5) show_404(); + public function unit($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } - $this->load->model('spell_model'); + $this->load->library('form_validation'); + $this->load->model('unit_model'); + $this->load->model('ai_model'); - $data['spells'] = $this->spell_model->list_spells_admin(); + $this->form_validation->set_rules('name', 'Name', 'required'); + $this->form_validation->set_rules('icon', 'Icon', 'required'); + $this->form_validation->set_rules('type', 'Type', 'integer'); - $this->headers('admin'); - $this->load->view('admin/spell_tool/list.php', $data); - $this->footer(); - } + $this->form_validation->set_rules('score', 'Score', 'integer'); - function spell($id = -1) - { - if ($this->userlevel < 5) show_404(); + $data['scd'] = $this->input->post('can_defend'); - $this->load->library('form_validation'); - $this->load->model('spell_model'); - $this->load->model('weather_model'); + $this->form_validation->set_rules('defense', 'Type', 'numeric'); + $this->form_validation->set_rules('attack', 'Type', 'numeric'); - //spell effects - $data['seff'] = $this->input->post('effect'); - $data['opteff'] = $this->spell_model->get_spell_effects_admin(); + $data['sstrong'] = $this->input->post('strong_against'); + $data['sweak'] = $this->input->post('weak_against'); - $this->form_validation->set_rules('duration', 'Duration', 'required|is_natural'); - $this->form_validation->set_rules('cooldown', 'Cooldown', 'required|is_natural'); - $this->form_validation->set_rules('description', 'Description', 'required'); - $this->form_validation->set_rules('description_admin', 'Desc Admin', 'required'); + $data['optaiu'] = $this->ai_model->get_unit_list_drop_admin(); - $data['sweather'] = $this->input->post('weather_change_to'); - $data['optweather'] = $this->weather_model->get_weathers_drop_admin(); + $this->form_validation->set_rules('turn', 'Turn', 'integer'); + $this->form_validation->set_rules('ability', 'Ability', 'integer'); + + $this->form_validation->set_rules('time_to_create', 'Time to Create', 'integer'); + + $data['costu'] = $this->input->post('cost_unit'); //has to be done like this :( + $data['optu'] = $this->unit_model->get_unit_list_dropdown_admin(); + + $this->form_validation->set_rules('cost_num_unit', 'Cost Number of Units', 'integer'); + + $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); + $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); + $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); + $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); + $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); + + $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); + $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); + $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); + $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); + $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view('admin/unit_tool/unit', $data); + } else { + //editing + $data['new'] = false; + + $data['unit'] = $this->unit_model->get_unit_admin($id); + + $this->load->view('admin/unit_tool/unit', $data); + } + + $this->footer(); + } else { + $data['id'] = $id; + $data['type'] = $this->input->post('type'); + $data['name'] = $this->input->post('name'); + $data['icon'] = $this->input->post('icon'); + $data['score'] = $this->input->post('score'); + + $data['can_defend'] = $this->input->post('can_defend'); + $data['defense'] = $this->input->post('defense'); + $data['attack'] = $this->input->post('attack'); + $data['weak_against'] = $this->input->post('weak_against'); + $data['strong_against'] = $this->input->post('strong_against'); + $data['turn'] = $this->input->post('turn'); + $data['ability'] = $this->input->post('ability'); + + $data['time_to_create'] = $this->input->post('time_to_create'); + + $data['cost_unit'] = $this->input->post('cost_unit'); + $data['cost_num_unit'] = $this->input->post('cost_num_unit'); + + $data['cost_food'] = $this->input->post('cost_food'); + $data['cost_wood'] = $this->input->post('cost_wood'); + $data['cost_stone'] = $this->input->post('cost_stone'); + $data['cost_iron'] = $this->input->post('cost_iron'); + $data['cost_mana'] = $this->input->post('cost_mana'); + + $data['mod_rate_food'] = $this->input->post('mod_rate_food'); + $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); + $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); + $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); + $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); + + $this->load->model('unit_model'); + + if ($id == -1) { + //making new + $this->unit_model->add_unit_admin($data); + } else { + //editing + $this->unit_model->edit_unit_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/unit_tool'); + } + } + + //assignment tool + public function assignment_tool() + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('assignment_model'); + + $data['assignments'] = $this->assignment_model->get_assignments_admin(); + + $this->headers('admin'); + $this->load->view('admin/assignment_tool/list.php', $data); + $this->footer(); + } + + public function assignment($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->library('form_validation'); + $this->load->model('assignment_model'); + $this->load->model('unit_model'); + $this->load->model('spell_model'); + $this->load->model('technology_model'); + + //assign + $data['sassign'] = $this->input->post('unitid'); + $data['optass'] = $this->unit_model->get_unit_list_dropdown_admin(); + + $this->form_validation->set_rules('max', 'Max Assign', 'is_natural|required'); + $this->form_validation->set_rules( + 'bonus_per_assigned', + 'Assigned/bonus', + 'integer' + ); + + $data['ssp'] = $this->input->post('spellid'); + $data['optsp'] = $this->spell_model->get_spell_list_drop_admin(); + + $data['srtech'] = $this->input->post('req_tech'); + $data['optrtech'] = $this->technology_model->get_tech_list_drop_admin(); + + $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); + $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); + $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); + $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); + $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); + + $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); + $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); + $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); + $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); + $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); + + $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'numeric'); + $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'numeric'); + $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'numeric'); + $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'numeric'); + $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'numeric'); + + $this->form_validation->set_rules('description', 'Description', 'alphanumeric'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view('admin/assignment_tool/assignment', $data); + } else { + //editing + $data['new'] = false; + + $data['assignment'] = $this->assignment_model->get_assignment_admin($id); + + $this->load->view('admin/assignment_tool/assignment', $data); + } + + $this->footer(); + } else { + $data['id'] = $id; + $data['unitid'] = $this->input->post('unitid'); + $data['max'] = $this->input->post('max'); + $data['bonus_per_assigned'] = $this->input->post('bonus_per_assigned'); + $data['spellid'] = $this->input->post('spellid'); + $data['req_tech'] = $this->input->post('req_tech'); + + $data['mod_max_food'] = $this->input->post('mod_max_food'); + $data['mod_max_wood'] = $this->input->post('mod_max_wood'); + $data['mod_max_stone'] = $this->input->post('mod_max_stone'); + $data['mod_max_iron'] = $this->input->post('mod_max_iron'); + $data['mod_max_mana'] = $this->input->post('mod_max_mana'); + + $data['mod_rate_food'] = $this->input->post('mod_rate_food'); + $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); + $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); + $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); + $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); + + $data['mod_percent_food'] = $this->input->post('mod_percent_food'); + $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); + $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); + $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); + $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); + + $data['description'] = $this->input->post('description'); + + $this->load->model('assignment_model'); + + if ($id == -1) { + //making new + $this->assignment_model->add_assignment_admin($data); + } else { + //editing + $this->assignment_model->edit_assignment_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/assignment_tool'); + } + } + + //technology tool + public function technology_tool() + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('technology_model'); + + $data['technologies'] = $this->technology_model->list_technologies_admin(); + + $this->headers('admin'); + $this->load->view('admin/technology_tool/list.php', $data); + $this->footer(); + } + + public function technology($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->library('form_validation'); + $this->load->model('technology_model'); + $this->load->model('spell_model'); + $this->load->model('unit_model'); + + $this->form_validation->set_rules('description', 'Description', 'required'); + + $this->form_validation->set_rules('time', 'Time', 'integer'); + + $this->form_validation->set_rules('score', 'Score', 'integer'); + + $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); + $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); + $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); + $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); + $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); + + $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); + $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); + $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); + $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); + $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); + + $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); + $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); + $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); + $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); + $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); + + $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); + $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); + $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); + $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); + $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); + + + //mod_spell_id dropdown + $data['mspidopt'] = $this->spell_model->get_spell_mod_drop_admin(); + $data['sspid'] = $this->input->post('mod_spell_id'); + + //mod_create_id dropdown + $data['mcidopt'] = $this->unit_model->list_create_mod_drop_admin(); + $data['smcid'] = $this->input->post('mod_create_id'); + + $data['sflai'] = $this->input->post('flag_ai'); + + $data['selissec'] = $this->input->post('is_secondary'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view('admin/technology_tool/technology', $data); + } else { + //editing + $data['new'] = false; + + $data['technology'] = $this->technology_model->get_technology_admin( + $id + ); + + $this->load->view('admin/technology_tool/technology', $data); + } + + $this->footer(); + } else { + $data['id'] = $id; + $data['description'] = $this->input->post('description'); + + $data['time'] = $this->input->post('time'); + + $data['score'] = $this->input->post('score'); + + $data['cost_food'] = $this->input->post('cost_food'); + $data['cost_wood'] = $this->input->post('cost_wood'); + $data['cost_stone'] = $this->input->post('cost_stone'); + $data['cost_iron'] = $this->input->post('cost_iron'); + $data['cost_mana'] = $this->input->post('cost_mana'); + + $data['mod_max_food'] = $this->input->post('mod_max_food'); + $data['mod_max_wood'] = $this->input->post('mod_max_wood'); + $data['mod_max_stone'] = $this->input->post('mod_max_stone'); + $data['mod_max_iron'] = $this->input->post('mod_max_iron'); + $data['mod_max_mana'] = $this->input->post('mod_max_mana'); + + $data['mod_rate_food'] = $this->input->post('mod_rate_food'); + $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); + $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); + $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); + $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); + + $data['mod_percent_food'] = $this->input->post('mod_percent_food'); + $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); + $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); + $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); + $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); + + $data['mod_create_id'] = $this->input->post('mod_create_id'); + $data['mod_spell_id'] = $this->input->post('mod_spell_id'); + + $data['flag_ai'] = $this->input->post('flag_ai'); + + $data['is_secondary'] = $this->input->post('is_secondary'); + + $this->load->model('building_model'); + + if ($id == -1) { + //making new + $this->technology_model->add_technology_admin($data); + } else { + //editing + $this->technology_model->edit_technology_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/technology_tool'); + } + } + + //technology_group_tool + public function technology_group_desc($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->library('form_validation'); + $this->load->model('technology_model'); + + $this->form_validation->set_rules('group_name', 'Group Name', 'required'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view( + 'admin/technology_group_tool/tech_group_desc', + $data + ); + } else { + //editing + $data['new'] = false; + + $data['group'] = $this->technology_model->get_tech_group_desc_admin( + $id + ); + + $this->load->view( + 'admin/technology_group_tool/tech_group_desc', + $data + ); + } + + $this->footer(); + } else { + $data['id'] = $id; + $data['group_name'] = $this->input->post('group_name'); + + $this->load->model('technology_model'); + + if ($id == -1) { + //making new + $this->technology_model->add_tech_group_desc_admin($data); + } else { + //editing + $this->technology_model->edit_tech_group_desc_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/technology_group_tool'); + } + } + + //technology group tool + public function technology_group_tool() + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('technology_model'); + + $data['groups'] = $this->technology_model->list_tech_groups_admin(); + + $this->headers('admin'); + $this->load->view('admin/technology_group_tool/list.php', $data); + $this->footer(); + } + + public function technology_group($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->library('form_validation'); + $this->load->model('technology_model'); + + $this->form_validation->set_rules('action', 'Action', 'required'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + $data['id'] = $id; + $data['group'] = $this->technology_model->get_group_admin($id); + $data['opttech'] = $this->technology_model->list_tech_drop_admin(); + $data['seltech'] = $this->input->post('add'); + + $this->load->view('admin/technology_group_tool/tech_groups', $data); + + $this->footer(); + } else { + $action = $this->input->post('action'); + + $this->load->model('technology_model'); + + if ($action == 'add') { + $techid = $this->input->post('add'); + + $this->technology_model->add_tech_to_group_admin($id, $techid); + } elseif ($action == 'delete') { + $techid = $this->input->post('id'); + $this->technology_model->remove_tech_from_group_admin($id, $techid); + } + $this->load->helper('url'); + + redirect('admin/technology_group/' . $id); + } + } + + //technology requirements tool + public function technology_requirements_tool() + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('technology_model'); + + $data['technologies'] = $this->technology_model->list_tech_have_req_admin(); + + $this->headers('admin'); + $this->load->view('admin/technology_requirements_tool/list.php', $data); + $this->footer(); + } + + public function have_technology_requirement($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } + + if (!$id) { + $this->load->helper('url'); + redirect('admin/admin_panel'); + } + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('action', 'Action', 'required'); + + $this->load->model('technology_model'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + if ($id == -1) { + $data['opts'] = $this->technology_model->list_tech_drop_admin(); + + $this->load->view( + 'admin/technology_requirements_tool/add_to_list', + $data + ); + } else { + $data['id'] = $id; + $data['tech'] = $this->technology_model->get_req_list_item_admin( + $id + ); + + $this->load->view( + 'admin/technology_requirements_tool/remove_conf', + $data + ); + } + + $this->footer(); + } else { + $action = $this->input->post('action'); + + if ($action == 'new') { + $data['technologyid'] = $this->input->post('technologyid'); + $data['comment'] = $this->input->post('comment'); + + $this->technology_model->add_to_req_list_admin($data); + } + + if ($action == 'delete') { + $id = $this->input->post('technologyid'); + + $this->technology_model->remove_from_req_list_admin($id); + } + + $this->load->helper('url'); + redirect('admin/technology_requirements_tool'); + } + } + + public function technology_requirements($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->library('form_validation'); + $this->load->model('technology_model'); + + $this->form_validation->set_rules('action', 'Action', 'required'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + $data['id'] = $id; + + + $data['technology'] = $this->technology_model->get_tech_by_req_id_admin( + $id + ); + $data['required'] = $this->technology_model->get_tech_requirements_admin( + $data['technology']['id'] + ); + + $data['opttech'] = $this->technology_model->list_tech_drop_admin(); + $data['seltech'] = $this->input->post('add'); + + $this->load->view('admin/technology_requirements_tool/tech_req', $data); + + $this->footer(); + } else { + $action = $this->input->post('action'); + + if ($action == 'add') { + $techid = $this->input->post('technologyid'); + $addtechid = $this->input->post('add'); + + $this->technology_model->add_tech_req_admin($techid, $addtechid); + } elseif ($action == 'delete') { + $tid = $this->input->post('id'); + $this->technology_model->remove_tech_req_admin($tid); + } + $this->load->helper('url'); + + redirect('admin/technology_requirements/' . $id); + } + } + + //spell_tool + public function spell_tool() + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('spell_model'); + + $data['spells'] = $this->spell_model->list_spells_admin(); + + $this->headers('admin'); + $this->load->view('admin/spell_tool/list.php', $data); + $this->footer(); + } + + public function spell($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->library('form_validation'); + $this->load->model('spell_model'); + $this->load->model('weather_model'); + + //spell effects + $data['seff'] = $this->input->post('effect'); + $data['opteff'] = $this->spell_model->get_spell_effects_admin(); + + $this->form_validation->set_rules('duration', 'Duration', 'required|is_natural'); + $this->form_validation->set_rules('cooldown', 'Cooldown', 'required|is_natural'); + $this->form_validation->set_rules('description', 'Description', 'required'); + $this->form_validation->set_rules('description_admin', 'Desc Admin', 'required'); + + $data['sweather'] = $this->input->post('weather_change_to'); + $data['optweather'] = $this->weather_model->get_weathers_drop_admin(); - $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); - $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); - $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); - $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); - $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); + $this->form_validation->set_rules('cost_food', 'cost_food', 'integer'); + $this->form_validation->set_rules('cost_wood', 'cost_wood', 'integer'); + $this->form_validation->set_rules('cost_stone', 'cost_stone', 'integer'); + $this->form_validation->set_rules('cost_iron', 'cost_iron', 'integer'); + $this->form_validation->set_rules('cost_mana', 'cost_mana', 'integer'); - $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); - $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); - $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); - $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); - $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); + $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); + $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); + $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); + $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); + $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); - $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); - $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); - $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); - $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); - $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); + $this->form_validation->set_rules('mod_rate_food', 'Mod Rate Food', 'numeric'); + $this->form_validation->set_rules('mod_rate_wood', 'Mod Rate Wood', 'numeric'); + $this->form_validation->set_rules('mod_rate_stone', 'Mod Rate Stone', 'numeric'); + $this->form_validation->set_rules('mod_rate_iron', 'Mod Rate Iron', 'numeric'); + $this->form_validation->set_rules('mod_rate_mana', 'Mod Rate Mana', 'numeric'); - $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); - $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); - $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); - $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); - $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); + $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); + $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); + $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); + $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); + $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); - if (!$this->form_validation->run()) - { - $this->headers('admin'); + if (!$this->form_validation->run()) { + $this->headers('admin'); - if ($id == -1) - { - //making new - $data['new'] = TRUE; + if ($id == -1) { + //making new + $data['new'] = true; - $this->load->view('admin/spell_tool/spell', $data); - } - else - { - //editing - $data['new'] = FALSE; + $this->load->view('admin/spell_tool/spell', $data); + } else { + //editing + $data['new'] = false; - $data['spell'] = $this->spell_model->get_spell_admin($id); + $data['spell'] = $this->spell_model->get_spell_admin($id); - $this->load->view('admin/spell_tool/spell', $data); - } + $this->load->view('admin/spell_tool/spell', $data); + } - $this->footer(); + $this->footer(); + } else { + $data['id'] = $id; + $data['effect'] = $this->input->post('effect'); + $data['duration'] = $this->input->post('duration'); + $data['cooldown'] = $this->input->post('cooldown'); + $data['description'] = $this->input->post('description'); + $data['description_admin'] = $this->input->post('description_admin'); + + $data['weather_change_to'] = $this->input->post('weather_change_to'); + + $data['cost_food'] = $this->input->post('cost_food'); + $data['cost_wood'] = $this->input->post('cost_wood'); + $data['cost_stone'] = $this->input->post('cost_stone'); + $data['cost_iron'] = $this->input->post('cost_iron'); + $data['cost_mana'] = $this->input->post('cost_mana'); + + $data['mod_max_food'] = $this->input->post('mod_max_food'); + $data['mod_max_wood'] = $this->input->post('mod_max_wood'); + $data['mod_max_stone'] = $this->input->post('mod_max_stone'); + $data['mod_max_iron'] = $this->input->post('mod_max_iron'); + $data['mod_max_mana'] = $this->input->post('mod_max_mana'); + + $data['mod_rate_food'] = $this->input->post('mod_rate_food'); + $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); + $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); + $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); + $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); + + $data['mod_percent_food'] = $this->input->post('mod_percent_food'); + $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); + $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); + $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); + $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); + + $this->load->model('spell_model'); + + if ($id == -1) { + //making new + $this->spell_model->add_spell_admin($data); + } else { + //editing + $this->spell_model->edit_spell_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/spell_tool'); + } } - else + + //weather_tool + public function weather_tool() { - $data['id'] = $id; - $data['effect'] = $this->input->post('effect'); - $data['duration'] = $this->input->post('duration'); - $data['cooldown'] = $this->input->post('cooldown'); - $data['description'] = $this->input->post('description'); - $data['description_admin'] = $this->input->post('description_admin'); + if ($this->userlevel < 5) { + show_404(); + } - $data['weather_change_to'] = $this->input->post('weather_change_to'); + $this->load->model('weather_model'); - $data['cost_food'] = $this->input->post('cost_food'); - $data['cost_wood'] = $this->input->post('cost_wood'); - $data['cost_stone'] = $this->input->post('cost_stone'); - $data['cost_iron'] = $this->input->post('cost_iron'); - $data['cost_mana'] = $this->input->post('cost_mana'); + $data['weathers'] = $this->weather_model->list_weathers_admin(); - $data['mod_max_food'] = $this->input->post('mod_max_food'); - $data['mod_max_wood'] = $this->input->post('mod_max_wood'); - $data['mod_max_stone'] = $this->input->post('mod_max_stone'); - $data['mod_max_iron'] = $this->input->post('mod_max_iron'); - $data['mod_max_mana'] = $this->input->post('mod_max_mana'); - - $data['mod_rate_food'] = $this->input->post('mod_rate_food'); - $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); - $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); - $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); - $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); - - $data['mod_percent_food'] = $this->input->post('mod_percent_food'); - $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); - $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); - $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); - $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); - - $this->load->model('spell_model'); - - if ($id == -1) - { - //making new - $this->spell_model->add_spell_admin($data); - } - else - { - //editing - $this->spell_model->edit_spell_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/spell_tool'); + $this->headers('admin'); + $this->load->view('admin/weather_tool/list.php', $data); + $this->footer(); } - } -//weather_tool - function weather_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('weather_model'); - - $data['weathers'] = $this->weather_model->list_weathers_admin(); - - $this->headers('admin'); - $this->load->view('admin/weather_tool/list.php', $data); - $this->footer(); - } - - function weather($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('weather_model'); - - $this->form_validation->set_rules('name', 'Name', 'required'); - $this->form_validation->set_rules('description', 'Description', 'required'); - $this->form_validation->set_rules('art', 'Art', 'required'); - $this->form_validation->set_rules('css', 'CSS', 'required'); - - //spell effects - $data['seff'] = $this->input->post('effect'); - $data['opteff'] = $this->weather_model->get_weather_effects_drop_admin(); - - $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); - $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); - $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); - $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); - $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); - - $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); - $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); - $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); - $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); - $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); - - if (!$this->form_validation->run()) + public function weather($id = -1) { - $this->headers('admin'); + if ($this->userlevel < 5) { + show_404(); + } - if ($id == -1) - { - //making new - $data['new'] = TRUE; + $this->load->library('form_validation'); + $this->load->model('weather_model'); - $this->load->view('admin/weather_tool/weather', $data); - } - else - { - //editing - $data['new'] = FALSE; + $this->form_validation->set_rules('name', 'Name', 'required'); + $this->form_validation->set_rules('description', 'Description', 'required'); + $this->form_validation->set_rules('art', 'Art', 'required'); + $this->form_validation->set_rules('css', 'CSS', 'required'); - $data['weather'] = $this->weather_model->get_weather_admin($id); + //spell effects + $data['seff'] = $this->input->post('effect'); + $data['opteff'] = $this->weather_model->get_weather_effects_drop_admin(); - $this->load->view('admin/weather_tool/weather', $data); - } + $this->form_validation->set_rules('mod_max_food', 'Mod Max Food', 'integer'); + $this->form_validation->set_rules('mod_max_wood', 'Mod Max Wood', 'integer'); + $this->form_validation->set_rules('mod_max_stone', 'Mod Max Stone', 'integer'); + $this->form_validation->set_rules('mod_max_iron', 'Mod Max Iron', 'integer'); + $this->form_validation->set_rules('mod_max_mana', 'Mod Max Mana', 'integer'); - $this->footer(); + $this->form_validation->set_rules('mod_percent_food', 'Mod Percent Food', 'integer'); + $this->form_validation->set_rules('mod_percent_wood', 'Mod Percent Wood', 'integer'); + $this->form_validation->set_rules('mod_percent_stone', 'Mod Percent Stone', 'integer'); + $this->form_validation->set_rules('mod_percent_iron', 'Mod Percent Iron', 'integer'); + $this->form_validation->set_rules('mod_percent_mana', 'Mod Percent Mana', 'integer'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); + + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view('admin/weather_tool/weather', $data); + } else { + //editing + $data['new'] = false; + + $data['weather'] = $this->weather_model->get_weather_admin($id); + + $this->load->view('admin/weather_tool/weather', $data); + } + + $this->footer(); + } else { + $data['id'] = $id; + + $data['name'] = $this->input->post('name'); + $data['description'] = $this->input->post('description'); + $data['art'] = $this->input->post('art'); + $data['css'] = $this->input->post('css'); + + $data['effect'] = $this->input->post('effect'); + + $data['cost_food'] = $this->input->post('cost_food'); + $data['cost_wood'] = $this->input->post('cost_wood'); + $data['cost_stone'] = $this->input->post('cost_stone'); + $data['cost_iron'] = $this->input->post('cost_iron'); + $data['cost_mana'] = $this->input->post('cost_mana'); + + $data['mod_max_food'] = $this->input->post('mod_max_food'); + $data['mod_max_wood'] = $this->input->post('mod_max_wood'); + $data['mod_max_stone'] = $this->input->post('mod_max_stone'); + $data['mod_max_iron'] = $this->input->post('mod_max_iron'); + $data['mod_max_mana'] = $this->input->post('mod_max_mana'); + + $data['mod_rate_food'] = $this->input->post('mod_rate_food'); + $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); + $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); + $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); + $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); + + $data['mod_percent_food'] = $this->input->post('mod_percent_food'); + $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); + $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); + $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); + $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); + + $this->load->model('weather_model'); + + if ($id == -1) { + //making new + $this->weather_model->add_weather_admin($data); + } else { + //editing + $this->weather_model->edit_weather_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/weather_tool'); + } } - else + + //HERO TOOLS + + //hero templates + public function hero_template_tool() { - $data['id'] = $id; + if ($this->userlevel < 5) { + show_404(); + } - $data['name'] = $this->input->post('name'); - $data['description'] = $this->input->post('description'); - $data['art'] = $this->input->post('art'); - $data['css'] = $this->input->post('css'); + $this->load->model('hero_model'); - $data['effect'] = $this->input->post('effect'); + $data['templates'] = $this->hero_model->all_hero_templates_admin(); - $data['cost_food'] = $this->input->post('cost_food'); - $data['cost_wood'] = $this->input->post('cost_wood'); - $data['cost_stone'] = $this->input->post('cost_stone'); - $data['cost_iron'] = $this->input->post('cost_iron'); - $data['cost_mana'] = $this->input->post('cost_mana'); - - $data['mod_max_food'] = $this->input->post('mod_max_food'); - $data['mod_max_wood'] = $this->input->post('mod_max_wood'); - $data['mod_max_stone'] = $this->input->post('mod_max_stone'); - $data['mod_max_iron'] = $this->input->post('mod_max_iron'); - $data['mod_max_mana'] = $this->input->post('mod_max_mana'); - - $data['mod_rate_food'] = $this->input->post('mod_rate_food'); - $data['mod_rate_wood'] = $this->input->post('mod_rate_wood'); - $data['mod_rate_stone'] = $this->input->post('mod_rate_stone'); - $data['mod_rate_iron'] = $this->input->post('mod_rate_iron'); - $data['mod_rate_mana'] = $this->input->post('mod_rate_mana'); - - $data['mod_percent_food'] = $this->input->post('mod_percent_food'); - $data['mod_percent_wood'] = $this->input->post('mod_percent_wood'); - $data['mod_percent_stone'] = $this->input->post('mod_percent_stone'); - $data['mod_percent_iron'] = $this->input->post('mod_percent_iron'); - $data['mod_percent_mana'] = $this->input->post('mod_percent_mana'); - - $this->load->model('weather_model'); - - if ($id == -1) - { - //making new - $this->weather_model->add_weather_admin($data); - } - else - { - //editing - $this->weather_model->edit_weather_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/weather_tool'); + $this->headers('admin'); + $this->load->view('admin/hero_template_tool/list.php', $data); + $this->footer(); } - } - //HERO TOOLS + public function hero_templates($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } - //hero templates - function hero_template_tool() - { - if ($this->userlevel < 5) show_404(); + $this->load->model('hero_model'); - $this->load->model('hero_model'); + $this->load->library('form_validation'); - $data['templates'] = $this->hero_model->all_hero_templates_admin(); - - $this->headers('admin'); - $this->load->view('admin/hero_template_tool/list.php', $data); - $this->footer(); - } - - function hero_templates($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('hero_model'); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('classname', 'Classname', 'required|alpha'); + $this->form_validation->set_rules('classname', 'Classname', 'required|alpha'); - $this->form_validation->set_rules('nomod_max_health', 'Nomod Health', 'required|is_natural'); - $this->form_validation->set_rules('nomod_max_mana', 'Nomod Mana', 'required|is_natural'); + $this->form_validation->set_rules('nomod_max_health', 'Nomod Health', 'required|is_natural'); + $this->form_validation->set_rules('nomod_max_mana', 'Nomod Mana', 'required|is_natural'); - $this->form_validation->set_rules('agility', 'Agility', 'integer'); - $this->form_validation->set_rules('strength', 'Strength', 'integer'); - $this->form_validation->set_rules('stamina', 'Stamina', 'integer'); - $this->form_validation->set_rules('intellect', 'Intellect', 'integer'); - $this->form_validation->set_rules('spirit', 'Spirit', 'integer'); + $this->form_validation->set_rules('agility', 'Agility', 'integer'); + $this->form_validation->set_rules('strength', 'Strength', 'integer'); + $this->form_validation->set_rules('stamina', 'Stamina', 'integer'); + $this->form_validation->set_rules('intellect', 'Intellect', 'integer'); + $this->form_validation->set_rules('spirit', 'Spirit', 'integer'); - $this->form_validation->set_rules('nomod_attackpower', 'Nomod Attackpower', 'integer'); + $this->form_validation->set_rules('nomod_attackpower', 'Nomod Attackpower', 'integer'); - $this->form_validation->set_rules('nomod_dodge', 'Nomod Dodge', 'numeric'); - $this->form_validation->set_rules('nomod_parry', 'Nomod Parry', 'numeric'); - $this->form_validation->set_rules('hit', 'Hit', 'numeric'); - $this->form_validation->set_rules('nomod_crit', 'Nomod Crit', 'numeric'); + $this->form_validation->set_rules('nomod_dodge', 'Nomod Dodge', 'numeric'); + $this->form_validation->set_rules('nomod_parry', 'Nomod Parry', 'numeric'); + $this->form_validation->set_rules('hit', 'Hit', 'numeric'); + $this->form_validation->set_rules('nomod_crit', 'Nomod Crit', 'numeric'); - $this->form_validation->set_rules('nomod_damage_min', 'Nomod Damage Min', 'integer'); - $this->form_validation->set_rules('nomod_damage_max', 'Nomod Damage Max', 'integer'); + $this->form_validation->set_rules('nomod_damage_min', 'Nomod Damage Min', 'integer'); + $this->form_validation->set_rules('nomod_damage_max', 'Nomod Damage Max', 'integer'); - $this->form_validation->set_rules('nomod_ranged_damage_min', 'Nomod Damage Min', 'integer'); - $this->form_validation->set_rules('nomod_ranged_damage_max', 'Nomod Damage Max', 'integer'); + $this->form_validation->set_rules('nomod_ranged_damage_min', 'Nomod Damage Min', 'integer'); + $this->form_validation->set_rules('nomod_ranged_damage_max', 'Nomod Damage Max', 'integer'); - $this->form_validation->set_rules('nomod_heal_min', 'Nomod Heal Min', 'integer'); - $this->form_validation->set_rules('nomod_heal_max', 'Nomod Heal Max', 'integer'); + $this->form_validation->set_rules('nomod_heal_min', 'Nomod Heal Min', 'integer'); + $this->form_validation->set_rules('nomod_heal_max', 'Nomod Heal Max', 'integer'); - if (!$this->form_validation->run()) - { - $this->headers('admin'); + if (!$this->form_validation->run()) { + $this->headers('admin'); - if ($id == -1) - { - //making new - $data['new'] = TRUE; + if ($id == -1) { + //making new + $data['new'] = true; - $this->load->view('admin/hero_template_tool/hero', $data); - } - else - { - //editing - $data['new'] = FALSE; + $this->load->view('admin/hero_template_tool/hero', $data); + } else { + //editing + $data['new'] = false; - $data['template'] = $this->hero_model->get_template_admin($id); + $data['template'] = $this->hero_model->get_template_admin($id); - $this->load->view('admin/hero_template_tool/hero', $data); - } + $this->load->view('admin/hero_template_tool/hero', $data); + } - $this->footer(); + $this->footer(); + } else { + $data['id'] = $id; + + $data['classname'] = $this->input->post('classname'); + + $data['nomod_max_health'] = $this->input->post('nomod_max_health'); + $data['nomod_max_mana'] = $this->input->post('nomod_max_mana'); + + $data['agility'] = $this->input->post('agility'); + $data['strength'] = $this->input->post('strength'); + $data['stamina'] = $this->input->post('stamina'); + $data['intellect'] = $this->input->post('intellect'); + $data['spirit'] = $this->input->post('spirit'); + + $data['nomod_attackpower'] = $this->input->post('nomod_attackpower'); + + $data['nomod_dodge'] = $this->input->post('nomod_dodge'); + $data['nomod_parry'] = $this->input->post('nomod_parry'); + $data['hit'] = $this->input->post('hit'); + $data['nomod_crit'] = $this->input->post('nomod_crit'); + + $data['nomod_damage_min'] = $this->input->post('nomod_damage_min'); + $data['nomod_damage_max'] = $this->input->post('nomod_damage_max'); + + $data['nomod_ranged_damage_min'] = $this->input->post('nomod_ranged_damage_min'); + $data['nomod_ranged_damage_max'] = $this->input->post('nomod_ranged_damage_max'); + + $data['nomod_heal_min'] = $this->input->post('nomod_heal_min'); + $data['nomod_heal_max'] = $this->input->post('nomod_heal_max'); + + if ($id == -1) { + //making new + $this->hero_model->add_template_admin($data); + } else { + //editing + $this->hero_model->edit_template_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/hero_template_tool'); + } } - else + + //technology requirements tool + public function hero_inventory_template_tool() { - $data['id'] = $id; + if ($this->userlevel < 5) { + show_404(); + } - $data['classname'] = $this->input->post('classname'); + $this->load->model('hero_model'); - $data['nomod_max_health'] = $this->input->post('nomod_max_health'); - $data['nomod_max_mana'] = $this->input->post('nomod_max_mana'); + $data['classes'] = $this->hero_model->all_hero_templates_admin(); - $data['agility'] = $this->input->post('agility'); - $data['strength'] = $this->input->post('strength'); - $data['stamina'] = $this->input->post('stamina'); - $data['intellect'] = $this->input->post('intellect'); - $data['spirit'] = $this->input->post('spirit'); - - $data['nomod_attackpower'] = $this->input->post('nomod_attackpower'); - - $data['nomod_dodge'] = $this->input->post('nomod_dodge'); - $data['nomod_parry'] = $this->input->post('nomod_parry'); - $data['hit'] = $this->input->post('hit'); - $data['nomod_crit'] = $this->input->post('nomod_crit'); - - $data['nomod_damage_min'] = $this->input->post('nomod_damage_min'); - $data['nomod_damage_max'] = $this->input->post('nomod_damage_max'); - - $data['nomod_ranged_damage_min'] = $this->input->post('nomod_ranged_damage_min'); - $data['nomod_ranged_damage_max'] = $this->input->post('nomod_ranged_damage_max'); - - $data['nomod_heal_min'] = $this->input->post('nomod_heal_min'); - $data['nomod_heal_max'] = $this->input->post('nomod_heal_max'); - - if ($id == -1) - { - //making new - $this->hero_model->add_template_admin($data); - } - else - { - //editing - $this->hero_model->edit_template_admin($data); - } - - $this->load->helper('url'); - - redirect('admin/hero_template_tool'); + $this->headers('admin'); + $this->load->view('admin/hero_inventory_template_tool/list.php', $data); + $this->footer(); } - } -//technology requirements tool - function hero_inventory_template_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('hero_model'); - - $data['classes'] = $this->hero_model->all_hero_templates_admin(); - - $this->headers('admin'); - $this->load->view('admin/hero_inventory_template_tool/list.php', $data); - $this->footer(); - } - - function hero_inventory_templates($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('item_model'); - - $this->form_validation->set_rules('action', 'Action', 'required'); - - if (!$this->form_validation->run()) + public function hero_inventory_templates($id = -1) { - $this->headers('admin'); + if ($this->userlevel < 5) { + show_404(); + } - $data['id'] = $id; + $this->load->library('form_validation'); + $this->load->model('item_model'); - $this->load->model('hero_model'); + $this->form_validation->set_rules('action', 'Action', 'required'); + + if (!$this->form_validation->run()) { + $this->headers('admin'); - $data['hero'] = $this->hero_model->get_template_admin($id); - $data['items'] = $this->item_model->get_class_item_templates($id); + $data['id'] = $id; - $data['optitems'] = $this->item_model->all_items_drop_admin(); - $data['selitems'] = $this->input->post('add'); + $this->load->model('hero_model'); - $this->load->view('admin/hero_inventory_template_tool/items', $data); + $data['hero'] = $this->hero_model->get_template_admin($id); + $data['items'] = $this->item_model->get_class_item_templates($id); - $this->footer(); + $data['optitems'] = $this->item_model->all_items_drop_admin(); + $data['selitems'] = $this->input->post('add'); + + $this->load->view('admin/hero_inventory_template_tool/items', $data); + + $this->footer(); + } else { + $action = $this->input->post('action'); + + if ($action == 'add') { + $classid = $this->input->post('classid'); + $additemid = $this->input->post('add'); + + $this->item_model->add_hero_item_template_admin($classid, $additemid); + } elseif ($action == 'delete') { + $iid = $this->input->post('id'); + $this->item_model->remove_hero_item_template_admin($iid); + } + $this->load->helper('url'); + + redirect('admin/hero_inventory_templates/' . $id); + } } - else + + //item tool + public function item_tool() { - $action = $this->input->post('action'); - - if ($action == 'add') - { - $classid = $this->input->post('classid'); - $additemid = $this->input->post('add'); + if ($this->userlevel < 5) { + show_404(); + } - $this->item_model->add_hero_item_template_admin($classid, $additemid); - } - elseif ($action == 'delete') - { - $iid = $this->input->post('id'); - $this->item_model->remove_hero_item_template_admin($iid); - } - $this->load->helper('url'); + $this->load->model('item_model'); - redirect('admin/hero_inventory_templates/' . $id); + $data['items'] = $this->item_model->all_items_admin(); + + $this->headers('admin'); + $this->load->view('admin/item_tool/list.php', $data); + $this->footer(); } - } - //item tool - function item_tool() - { - if ($this->userlevel < 5) show_404(); + public function items($id = -1) + { + if ($this->userlevel < 5) { + show_404(); + } - $this->load->model('item_model'); + $this->load->model('item_model'); - $data['items'] = $this->item_model->all_items_admin(); + $this->load->library('form_validation'); - $this->headers('admin'); - $this->load->view('admin/item_tool/list.php', $data); - $this->footer(); - } + $this->form_validation->set_rules('name', 'Name', 'required'); + $this->form_validation->set_rules('icon', 'Icon', 'required'); - function items($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('item_model'); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('name', 'Name', 'required'); - $this->form_validation->set_rules('icon', 'Icon', 'required'); - - $data['selquality'] = $this->input->post('quality'); + $data['selquality'] = $this->input->post('quality'); - $this->form_validation->set_rules('itemlevel', 'Itemlevel', 'integer'); - $this->form_validation->set_rules('stack', 'Stack', 'integer'); + $this->form_validation->set_rules('itemlevel', 'Itemlevel', 'integer'); + $this->form_validation->set_rules('stack', 'Stack', 'integer'); - $data['seltype'] = $this->input->post('type'); - $data['selsubtype'] = $this->input->post('subtype'); - $data['selsubsubtype'] = $this->input->post('subsubtype'); + $data['seltype'] = $this->input->post('type'); + $data['selsubtype'] = $this->input->post('subtype'); + $data['selsubsubtype'] = $this->input->post('subsubtype'); - $this->form_validation->set_rules('sell_price', 'Sell Price', 'integer'); - $this->form_validation->set_rules('buy_price', 'Buy Price', 'integer'); + $this->form_validation->set_rules('sell_price', 'Sell Price', 'integer'); + $this->form_validation->set_rules('buy_price', 'Buy Price', 'integer'); - $this->form_validation->set_rules('text', 'Text', 'alphanumeric'); + $this->form_validation->set_rules('text', 'Text', 'alphanumeric'); - $data['selsoulbound'] = $this->input->post('soulbound'); + $data['selsoulbound'] = $this->input->post('soulbound'); - $data['optspell'] = array('0' => 'NYI!'); - $data['selspell'] = $this->input->post('spell'); + $data['optspell'] = array('0' => 'NYI!'); + $data['selspell'] = $this->input->post('spell'); - $data['optproc'] = array('0' => 'NYI!'); - $data['selproc'] = $this->input->post('proc'); + $data['optproc'] = array('0' => 'NYI!'); + $data['selproc'] = $this->input->post('proc'); - $this->form_validation->set_rules('req_level', 'Req Level', 'integer'); + $this->form_validation->set_rules('req_level', 'Req Level', 'integer'); - $data['selreqclass'] = $this->input->post('req_class'); + $data['selreqclass'] = $this->input->post('req_class'); - $this->form_validation->set_rules('nomod_max_health', 'Nomod Max Health', 'is_natural'); - $this->form_validation->set_rules('nomod_max_mana', 'Nomod Max Mana', 'is_natural'); + $this->form_validation->set_rules('nomod_max_health', 'Nomod Max Health', 'is_natural'); + $this->form_validation->set_rules('nomod_max_mana', 'Nomod Max Mana', 'is_natural'); - $this->form_validation->set_rules('percent_max_health', 'Percent Max Health', 'is_natural'); - $this->form_validation->set_rules('percent_max_mana', 'Percent Max Mana', 'is_natural'); + $this->form_validation->set_rules('percent_max_health', 'Percent Max Health', 'is_natural'); + $this->form_validation->set_rules('percent_max_mana', 'Percent Max Mana', 'is_natural'); - $this->form_validation->set_rules('nomod_agility', 'Nomod Agility', 'integer'); - $this->form_validation->set_rules('nomod_strength', 'Nomod Strength', 'integer'); - $this->form_validation->set_rules('nomod_stamina', 'Nomod Stamina', 'integer'); - $this->form_validation->set_rules('nomod_intellect', 'Nomod Intellect', 'integer'); - $this->form_validation->set_rules('nomod_spirit', 'Nomod Spirit', 'integer'); + $this->form_validation->set_rules('nomod_agility', 'Nomod Agility', 'integer'); + $this->form_validation->set_rules('nomod_strength', 'Nomod Strength', 'integer'); + $this->form_validation->set_rules('nomod_stamina', 'Nomod Stamina', 'integer'); + $this->form_validation->set_rules('nomod_intellect', 'Nomod Intellect', 'integer'); + $this->form_validation->set_rules('nomod_spirit', 'Nomod Spirit', 'integer'); - $this->form_validation->set_rules('percent_agility', 'Percent Agility', 'integer'); - $this->form_validation->set_rules('percent_strength', 'Percent Strength', 'integer'); - $this->form_validation->set_rules('percent_stamina', 'Percent Stamina', 'integer'); - $this->form_validation->set_rules('percent_intellect', 'Percent Intellect', 'integer'); - $this->form_validation->set_rules('percent_spirit', 'Percent Spirit', 'integer'); + $this->form_validation->set_rules('percent_agility', 'Percent Agility', 'integer'); + $this->form_validation->set_rules('percent_strength', 'Percent Strength', 'integer'); + $this->form_validation->set_rules('percent_stamina', 'Percent Stamina', 'integer'); + $this->form_validation->set_rules('percent_intellect', 'Percent Intellect', 'integer'); + $this->form_validation->set_rules('percent_spirit', 'Percent Spirit', 'integer'); - $this->form_validation->set_rules('nomod_attackpower', 'Nomod Attackpower', 'integer'); - $this->form_validation->set_rules('percent_attackpower', 'Percent Attackpower', 'integer'); + $this->form_validation->set_rules('nomod_attackpower', 'Nomod Attackpower', 'integer'); + $this->form_validation->set_rules('percent_attackpower', 'Percent Attackpower', 'integer'); - $this->form_validation->set_rules('nomod_armor', 'Nomod Armor', 'integer'); - $this->form_validation->set_rules('percent_armor', 'Percent Armor', 'integer'); + $this->form_validation->set_rules('nomod_armor', 'Nomod Armor', 'integer'); + $this->form_validation->set_rules('percent_armor', 'Percent Armor', 'integer'); - $this->form_validation->set_rules('nomod_dodge', 'Nomod Dodge', 'numeric'); - $this->form_validation->set_rules('nomod_parry', 'Nomod Parry', 'numeric'); - $this->form_validation->set_rules('hit', 'Hit', 'numeric'); - $this->form_validation->set_rules('nomod_crit', 'Nomod Crit', 'numeric'); + $this->form_validation->set_rules('nomod_dodge', 'Nomod Dodge', 'numeric'); + $this->form_validation->set_rules('nomod_parry', 'Nomod Parry', 'numeric'); + $this->form_validation->set_rules('hit', 'Hit', 'numeric'); + $this->form_validation->set_rules('nomod_crit', 'Nomod Crit', 'numeric'); - $this->form_validation->set_rules('nomod_damage_min', 'Nomod Damage Min', 'integer'); - $this->form_validation->set_rules('nomod_damage_max', 'Nomod Damage Max', 'integer'); - $this->form_validation->set_rules('percent_damage_min', 'Percent Damage Min', 'integer'); - $this->form_validation->set_rules('percent_damage_max', 'Percent Damage Max', 'integer'); + $this->form_validation->set_rules('nomod_damage_min', 'Nomod Damage Min', 'integer'); + $this->form_validation->set_rules('nomod_damage_max', 'Nomod Damage Max', 'integer'); + $this->form_validation->set_rules('percent_damage_min', 'Percent Damage Min', 'integer'); + $this->form_validation->set_rules('percent_damage_max', 'Percent Damage Max', 'integer'); - $this->form_validation->set_rules('nomod_ranged_damage_min', 'Nomod Ranged Damage Min', 'integer'); - $this->form_validation->set_rules('nomod_ranged_damage_max', 'Nomod Ranged Damage Max', 'integer'); - $this->form_validation->set_rules('percent_ranged_damage_min', 'Percent Ranged Damage Min', 'integer'); - $this->form_validation->set_rules('percent_ranged_damage_max', 'Percent Ranged Damage Max', 'integer'); + $this->form_validation->set_rules('nomod_ranged_damage_min', 'Nomod Ranged Damage Min', 'integer'); + $this->form_validation->set_rules('nomod_ranged_damage_max', 'Nomod Ranged Damage Max', 'integer'); + $this->form_validation->set_rules('percent_ranged_damage_min', 'Percent Ranged Damage Min', 'integer'); + $this->form_validation->set_rules('percent_ranged_damage_max', 'Percent Ranged Damage Max', 'integer'); - $this->form_validation->set_rules('nomod_heal_min', 'Nomod Heal Min', 'integer'); - $this->form_validation->set_rules('nomod_heal_max', 'Nomod Heal Max', 'integer'); - $this->form_validation->set_rules('percent_heal_min', 'Percent Heal Min', 'integer'); - $this->form_validation->set_rules('percent_heal_max', 'Percent Heal Max', 'integer'); + $this->form_validation->set_rules('nomod_heal_min', 'Nomod Heal Min', 'integer'); + $this->form_validation->set_rules('nomod_heal_max', 'Nomod Heal Max', 'integer'); + $this->form_validation->set_rules('percent_heal_min', 'Percent Heal Min', 'integer'); + $this->form_validation->set_rules('percent_heal_max', 'Percent Heal Max', 'integer'); - $this->form_validation->set_rules('life_leech', 'Life Leech', 'integer'); - $this->form_validation->set_rules('mana_leech', 'Mana Leech', 'integer'); + $this->form_validation->set_rules('life_leech', 'Life Leech', 'integer'); + $this->form_validation->set_rules('mana_leech', 'Mana Leech', 'integer'); - $this->form_validation->set_rules('level_modifier', 'Level Modifier', 'integer'); - $this->form_validation->set_rules('level_modifier_max', 'Level Modifier Max', 'integer'); + $this->form_validation->set_rules('level_modifier', 'Level Modifier', 'integer'); + $this->form_validation->set_rules('level_modifier_max', 'Level Modifier Max', 'integer'); - $this->form_validation->set_rules('data1', 'Data1', 'integer'); - $this->form_validation->set_rules('data2', 'Data2', 'integer'); + $this->form_validation->set_rules('data1', 'Data1', 'integer'); + $this->form_validation->set_rules('data2', 'Data2', 'integer'); - if (!$this->form_validation->run()) - { - $this->headers('admin'); + if (!$this->form_validation->run()) { + $this->headers('admin'); - if ($id == -1) - { - //making new - $data['new'] = TRUE; + if ($id == -1) { + //making new + $data['new'] = true; - $this->load->view('admin/item_tool/item', $data); - } - else - { - //editing - $data['new'] = FALSE; + $this->load->view('admin/item_tool/item', $data); + } else { + //editing + $data['new'] = false; - $data['item'] = $this->item_model->get_item_admin($id); + $data['item'] = $this->item_model->get_item_admin($id); - $this->load->view('admin/item_tool/item', $data); - } + $this->load->view('admin/item_tool/item', $data); + } - $this->footer(); - } - else - { - $data['id'] = $id; + $this->footer(); + } else { + $data['id'] = $id; - $data['name'] = $this->input->post('name'); - $data['icon'] = $this->input->post('icon'); + $data['name'] = $this->input->post('name'); + $data['icon'] = $this->input->post('icon'); - $data['quality'] = $this->input->post('quality'); + $data['quality'] = $this->input->post('quality'); - $data['itemlevel'] = $this->input->post('itemlevel'); - $data['stack'] = $this->input->post('stack'); + $data['itemlevel'] = $this->input->post('itemlevel'); + $data['stack'] = $this->input->post('stack'); - $data['type'] = $this->input->post('type'); - $data['subtype'] = $this->input->post('subtype'); - $data['subsubtype'] = $this->input->post('subsubtype'); + $data['type'] = $this->input->post('type'); + $data['subtype'] = $this->input->post('subtype'); + $data['subsubtype'] = $this->input->post('subsubtype'); - $data['sell_price'] = $this->input->post('sell_price'); - $data['buy_price'] = $this->input->post('buy_price'); + $data['sell_price'] = $this->input->post('sell_price'); + $data['buy_price'] = $this->input->post('buy_price'); - $data['text'] = $this->input->post('text'); + $data['text'] = $this->input->post('text'); - $data['soulbound'] = $this->input->post('soulbound'); + $data['soulbound'] = $this->input->post('soulbound'); - $data['spell'] = $this->input->post('spell'); + $data['spell'] = $this->input->post('spell'); - $data['proc'] = $this->input->post('proc'); + $data['proc'] = $this->input->post('proc'); - $data['req_level'] = $this->input->post('req_level'); + $data['req_level'] = $this->input->post('req_level'); - $data['req_class'] = $this->input->post('req_class'); + $data['req_class'] = $this->input->post('req_class'); - $data['nomod_max_health'] = $this->input->post('nomod_max_health'); - $data['nomod_max_mana'] = $this->input->post('nomod_max_mana'); + $data['nomod_max_health'] = $this->input->post('nomod_max_health'); + $data['nomod_max_mana'] = $this->input->post('nomod_max_mana'); - $data['percent_max_health'] = $this->input->post('percent_max_health'); - $data['percent_max_mana'] = $this->input->post('percent_max_mana'); + $data['percent_max_health'] = $this->input->post('percent_max_health'); + $data['percent_max_mana'] = $this->input->post('percent_max_mana'); - $data['nomod_agility'] = $this->input->post('nomod_agility'); - $data['nomod_strength'] = $this->input->post('nomod_strength'); - $data['nomod_stamina'] = $this->input->post('nomod_stamina'); - $data['nomod_intellect'] = $this->input->post('nomod_intellect'); - $data['nomod_spirit'] = $this->input->post('nomod_spirit'); + $data['nomod_agility'] = $this->input->post('nomod_agility'); + $data['nomod_strength'] = $this->input->post('nomod_strength'); + $data['nomod_stamina'] = $this->input->post('nomod_stamina'); + $data['nomod_intellect'] = $this->input->post('nomod_intellect'); + $data['nomod_spirit'] = $this->input->post('nomod_spirit'); - $data['percent_agility'] = $this->input->post('percent_agility'); - $data['percent_strength'] = $this->input->post('percent_strength'); - $data['percent_stamina'] = $this->input->post('percent_stamina'); - $data['percent_intellect'] = $this->input->post('percent_intellect'); - $data['percent_spirit'] = $this->input->post('percent_spirit'); + $data['percent_agility'] = $this->input->post('percent_agility'); + $data['percent_strength'] = $this->input->post('percent_strength'); + $data['percent_stamina'] = $this->input->post('percent_stamina'); + $data['percent_intellect'] = $this->input->post('percent_intellect'); + $data['percent_spirit'] = $this->input->post('percent_spirit'); - $data['nomod_attackpower'] = $this->input->post('nomod_attackpower'); - $data['percent_attackpower'] = $this->input->post('percent_attackpower'); + $data['nomod_attackpower'] = $this->input->post('nomod_attackpower'); + $data['percent_attackpower'] = $this->input->post('percent_attackpower'); - $data['nomod_armor'] = $this->input->post('nomod_armor'); - $data['percent_armor'] = $this->input->post('percent_armor'); + $data['nomod_armor'] = $this->input->post('nomod_armor'); + $data['percent_armor'] = $this->input->post('percent_armor'); - $data['nomod_dodge'] = $this->input->post('nomod_dodge'); - $data['nomod_parry'] = $this->input->post('nomod_parry'); - $data['hit'] = $this->input->post('hit'); - $data['nomod_crit'] = $this->input->post('nomod_crit'); + $data['nomod_dodge'] = $this->input->post('nomod_dodge'); + $data['nomod_parry'] = $this->input->post('nomod_parry'); + $data['hit'] = $this->input->post('hit'); + $data['nomod_crit'] = $this->input->post('nomod_crit'); - $data['nomod_damage_min'] = $this->input->post('nomod_damage_min'); - $data['nomod_damage_max'] = $this->input->post('nomod_damage_max'); + $data['nomod_damage_min'] = $this->input->post('nomod_damage_min'); + $data['nomod_damage_max'] = $this->input->post('nomod_damage_max'); - $data['percent_damage_min'] = $this->input->post('percent_damage_min'); - $data['percent_damage_max'] = $this->input->post('percent_damage_max'); + $data['percent_damage_min'] = $this->input->post('percent_damage_min'); + $data['percent_damage_max'] = $this->input->post('percent_damage_max'); - $data['nomod_ranged_damage_min'] = $this->input->post('nomod_ranged_damage_min'); - $data['nomod_ranged_damage_max'] = $this->input->post('nomod_ranged_damage_max'); + $data['nomod_ranged_damage_min'] = $this->input->post('nomod_ranged_damage_min'); + $data['nomod_ranged_damage_max'] = $this->input->post('nomod_ranged_damage_max'); - $data['percent_ranged_damage_min'] = $this->input->post('percent_ranged_damage_min'); - $data['percent_ranged_damage_max'] = $this->input->post('percent_ranged_damage_max'); + $data['percent_ranged_damage_min'] = $this->input->post('percent_ranged_damage_min'); + $data['percent_ranged_damage_max'] = $this->input->post('percent_ranged_damage_max'); - $data['nomod_heal_min'] = $this->input->post('nomod_heal_min'); - $data['nomod_heal_max'] = $this->input->post('nomod_heal_max'); + $data['nomod_heal_min'] = $this->input->post('nomod_heal_min'); + $data['nomod_heal_max'] = $this->input->post('nomod_heal_max'); - $data['percent_heal_min'] = $this->input->post('percent_heal_min'); - $data['percent_heal_max'] = $this->input->post('percent_heal_max'); + $data['percent_heal_min'] = $this->input->post('percent_heal_min'); + $data['percent_heal_max'] = $this->input->post('percent_heal_max'); - $data['life_leech'] = $this->input->post('life_leech'); - $data['mana_leech'] = $this->input->post('mana_leech'); + $data['life_leech'] = $this->input->post('life_leech'); + $data['mana_leech'] = $this->input->post('mana_leech'); - $data['level_modifier'] = $this->input->post('level_modifier'); - $data['level_modifier_max'] = $this->input->post('level_modifier_max'); + $data['level_modifier'] = $this->input->post('level_modifier'); + $data['level_modifier_max'] = $this->input->post('level_modifier_max'); - $data['data1'] = $this->input->post('data1'); - $data['data2'] = $this->input->post('data2'); + $data['data1'] = $this->input->post('data1'); + $data['data2'] = $this->input->post('data2'); - if ($id == -1) - { - //making new - $this->item_model->add_item_admin($data); - } - else - { - //editing - $this->item_model->edit_item_admin($data); - } + if ($id == -1) { + //making new + $this->item_model->add_item_admin($data); + } else { + //editing + $this->item_model->edit_item_admin($data); + } - $this->load->helper('url'); + $this->load->helper('url'); - redirect('admin/item_tool'); + redirect('admin/item_tool'); + } } - } -//AI Units - function ai_unit_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('ai_model'); - - $data['units'] = $this->ai_model->list_units_admin(); - - $this->headers('admin'); - $this->load->view('admin/ai_unit_tool/list.php', $data); - $this->footer(); - } - - function ai_unit($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('unit_model'); - $this->load->model('ai_model'); - - $this->form_validation->set_rules('name', 'Name', 'required'); - $this->form_validation->set_rules('icon', 'Icon', 'required'); - $this->form_validation->set_rules('ability', 'Ability', 'integer'); - $this->form_validation->set_rules('can_carry', 'Can Carry', 'integer'); - $this->form_validation->set_rules('attack', 'Attack', 'numeric'); - $this->form_validation->set_rules('Defense', 'Defense', 'numeric'); - $this->form_validation->set_rules('rate', 'Rate', 'numeric'); - $this->form_validation->set_rules('per_score', 'Per Score', 'integer'); - $this->form_validation->set_rules('turn', 'Turn', 'integer'); - - $data['sstrong'] = $this->input->post('strong_against'); - $data['sweak'] = $this->input->post('weak_against'); - - $data['optu'] = $this->unit_model->get_unit_list_dropdown_admin(); - - if (!$this->form_validation->run()) + //AI Units + public function ai_unit_tool() { - $this->headers('admin'); + if ($this->userlevel < 5) { + show_404(); + } - if ($id == -1) - { - //making new - $data['new'] = TRUE; + $this->load->model('ai_model'); - $this->load->view('admin/ai_unit_tool/unit', $data); - } - else - { - //editing - $data['new'] = FALSE; + $data['units'] = $this->ai_model->list_units_admin(); - $data['unit'] = $this->ai_model->get_unit_admin($id); - - $this->load->view('admin/ai_unit_tool/unit', $data); - } - - $this->footer(); + $this->headers('admin'); + $this->load->view('admin/ai_unit_tool/list.php', $data); + $this->footer(); } - else + + public function ai_unit($id = -1) { - $data['id'] = $id; - $data['name'] = $this->input->post('name'); - $data['icon'] = $this->input->post('icon'); - $data['ability'] = $this->input->post('ability'); + if ($this->userlevel < 5) { + show_404(); + } - $data['can_carry'] = $this->input->post('can_carry'); - $data['attack'] = $this->input->post('attack'); - $data['defense'] = $this->input->post('defense'); + $this->load->library('form_validation'); + $this->load->model('unit_model'); + $this->load->model('ai_model'); - $data['rate'] = $this->input->post('rate'); - $data['per_score'] = $this->input->post('per_score'); - $data['turn'] = $this->input->post('turn'); - $data['strong_against'] = $this->input->post('strong_against'); - $data['weak_against'] = $this->input->post('weak_against'); + $this->form_validation->set_rules('name', 'Name', 'required'); + $this->form_validation->set_rules('icon', 'Icon', 'required'); + $this->form_validation->set_rules('ability', 'Ability', 'integer'); + $this->form_validation->set_rules('can_carry', 'Can Carry', 'integer'); + $this->form_validation->set_rules('attack', 'Attack', 'numeric'); + $this->form_validation->set_rules('Defense', 'Defense', 'numeric'); + $this->form_validation->set_rules('rate', 'Rate', 'numeric'); + $this->form_validation->set_rules('per_score', 'Per Score', 'integer'); + $this->form_validation->set_rules('turn', 'Turn', 'integer'); - $this->load->model('ai_model'); + $data['sstrong'] = $this->input->post('strong_against'); + $data['sweak'] = $this->input->post('weak_against'); - if ($id == -1) - { - //making new - $this->ai_model->add_unit_admin($data); - } - else - { - //editing - $this->ai_model->edit_unit_admin($data); - } + $data['optu'] = $this->unit_model->get_unit_list_dropdown_admin(); - $this->load->helper('url'); + if (!$this->form_validation->run()) { + $this->headers('admin'); - redirect('admin/ai_unit_tool'); + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view('admin/ai_unit_tool/unit', $data); + } else { + //editing + $data['new'] = false; + + $data['unit'] = $this->ai_model->get_unit_admin($id); + + $this->load->view('admin/ai_unit_tool/unit', $data); + } + + $this->footer(); + } else { + $data['id'] = $id; + $data['name'] = $this->input->post('name'); + $data['icon'] = $this->input->post('icon'); + $data['ability'] = $this->input->post('ability'); + + $data['can_carry'] = $this->input->post('can_carry'); + $data['attack'] = $this->input->post('attack'); + $data['defense'] = $this->input->post('defense'); + + $data['rate'] = $this->input->post('rate'); + $data['per_score'] = $this->input->post('per_score'); + $data['turn'] = $this->input->post('turn'); + $data['strong_against'] = $this->input->post('strong_against'); + $data['weak_against'] = $this->input->post('weak_against'); + + $this->load->model('ai_model'); + + if ($id == -1) { + //making new + $this->ai_model->add_unit_admin($data); + } else { + //editing + $this->ai_model->edit_unit_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/ai_unit_tool'); + } } - } -//AI Settings - function ai_settings_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('ai_model'); - - $data['settings'] = $this->ai_model->get_settings_list_admin(); - - $this->headers('admin'); - $this->load->view('admin/ai_settings_tool/list.php', $data); - $this->footer(); - } - - - function ai_settings($id = -1) - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - $this->load->model('ai_model'); - - $this->form_validation->set_rules('setting', 'Setting', 'required'); - $this->form_validation->set_rules('value', 'Value', 'required'); - $this->form_validation->set_rules('description', 'Description', 'required'); - - if (!$this->form_validation->run()) + //AI Settings + public function ai_settings_tool() { - $this->headers('admin'); + if ($this->userlevel < 5) { + show_404(); + } - if ($id == -1) - { - //making new - $data['new'] = TRUE; + $this->load->model('ai_model'); - $this->load->view('admin/ai_settings_tool/settings', $data); - } - else - { - //editing - $data['new'] = FALSE; + $data['settings'] = $this->ai_model->get_settings_list_admin(); - $data['setting'] = $this->ai_model->get_setting_admin($id); - - $this->load->view('admin/ai_settings_tool/settings', $data); - } - - $this->footer(); + $this->headers('admin'); + $this->load->view('admin/ai_settings_tool/list.php', $data); + $this->footer(); } - else + + + public function ai_settings($id = -1) { - $data['id'] = $id; - $data['setting'] = $this->input->post('setting'); - $data['value'] = $this->input->post('value'); - $data['description'] = $this->input->post('description'); + if ($this->userlevel < 5) { + show_404(); + } - $this->load->model('ai_model'); + $this->load->library('form_validation'); + $this->load->model('ai_model'); - if ($id == -1) - { - //making new - $this->ai_model->add_setting_admin($data); - } - else - { - //editing - $this->ai_model->edit_setting_admin($data); - } + $this->form_validation->set_rules('setting', 'Setting', 'required'); + $this->form_validation->set_rules('value', 'Value', 'required'); + $this->form_validation->set_rules('description', 'Description', 'required'); - $this->load->helper('url'); + if (!$this->form_validation->run()) { + $this->headers('admin'); - redirect('admin/ai_settings_tool'); + if ($id == -1) { + //making new + $data['new'] = true; + + $this->load->view('admin/ai_settings_tool/settings', $data); + } else { + //editing + $data['new'] = false; + + $data['setting'] = $this->ai_model->get_setting_admin($id); + + $this->load->view('admin/ai_settings_tool/settings', $data); + } + + $this->footer(); + } else { + $data['id'] = $id; + $data['setting'] = $this->input->post('setting'); + $data['value'] = $this->input->post('value'); + $data['description'] = $this->input->post('description'); + + $this->load->model('ai_model'); + + if ($id == -1) { + //making new + $this->ai_model->add_setting_admin($data); + } else { + //editing + $this->ai_model->edit_setting_admin($data); + } + + $this->load->helper('url'); + + redirect('admin/ai_settings_tool'); + } } - } -//map tools - function map_tool() - { - if ($this->userlevel < 5) show_404(); - $this->load->model('map_model'); - $this->load->library('form_validation'); - - $this->form_validation->set_rules('action', 'Action', 'required'); - - if (!$this->form_validation->run()) + //map tools + public function map_tool() { - $this->headers('admin'); + if ($this->userlevel < 5) { + show_404(); + } + $this->load->model('map_model'); + $this->load->library('form_validation'); - $data['files'] = $this->map_model->get_map_list_admin(); - $this->load->view('admin/map_tool/list', $data); + $this->form_validation->set_rules('action', 'Action', 'required'); - $this->footer(); + if (!$this->form_validation->run()) { + $this->headers('admin'); + + $data['files'] = $this->map_model->get_map_list_admin(); + $this->load->view('admin/map_tool/list', $data); + + $this->footer(); + } else { + $action = $this->input->post('action'); + + if ($action == 'apply') { + $file = $this->input->post('filename'); + + $this->map_model->apply_map_admin($file); + } + + + $this->load->helper('url'); + redirect('admin/map_tool'); + } } - else + + public function map_generator() { - $action = $this->input->post('action'); + if ($this->userlevel < 5) { + show_404(); + } - if ($action == 'apply') - { - $file = $this->input->post('filename'); + $this->load->model('map_model'); + $this->map_model->generate_map_admin(); - $this->map_model->apply_map_admin($file); - } - - - $this->load->helper('url'); - redirect('admin/map_tool'); + $this->load->helper('url'); + redirect('admin/map_tool'); } - } - function map_generator() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('map_model'); - $this->map_model->generate_map_admin(); - - $this->load->helper('url'); - redirect('admin/map_tool'); - - } - -//image tool - function menu_image() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('image_model'); - $this->load->library('form_validation'); - - $this->form_validation->set_rules('submit', 'Submit', 'required'); - - $data['optimg'] = $this->image_model->get_file_list_drop(); - $data['optfont'] = $this->image_model->get_font_list_drop(); - $data['optvalign'] = $this->image_model->get_v_align_drop(); - $data['opthalign'] = $this->image_model->get_h_align_drop(); - $data['optgroup'] = $this->image_model->get_menu_group_list_drop(); - - $this->headers('admin'); - - if (!$this->form_validation->run()) + //image tool + public function menu_image() { - $this->load->view('admin/image_tool/menu_image', $data); + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('image_model'); + $this->load->library('form_validation'); + + $this->form_validation->set_rules('submit', 'Submit', 'required'); + + $data['optimg'] = $this->image_model->get_file_list_drop(); + $data['optfont'] = $this->image_model->get_font_list_drop(); + $data['optvalign'] = $this->image_model->get_v_align_drop(); + $data['opthalign'] = $this->image_model->get_h_align_drop(); + $data['optgroup'] = $this->image_model->get_menu_group_list_drop(); + + $this->headers('admin'); + + if (!$this->form_validation->run()) { + $this->load->view('admin/image_tool/menu_image', $data); + } else { + $data['wm_type'] = 'text'; + $data['quality'] = '100%'; + + $data['file'] = $this->input->post('file'); + + $data['padding'] = $this->input->post('padding'); + $data['wm_vrt_alignment'] = $this->input->post('v_align'); + $data['wm_hor_alignment'] = $this->input->post('h_align'); + $data['wm_hor_offset'] = $this->input->post('h_offset'); + $data['wm_vrt_offset'] = $this->input->post('v_offset'); + + $data['wm_text'] = $this->input->post('text'); + $data['wm_font_path'] = './system/fonts/' . $this->input->post('font'); + $data['wm_font_size'] = $this->input->post('font_size'); + $data['wm_font_color'] = $this->input->post('font_color'); + $data['wm_shadow_color'] = $this->input->post('shadow_color'); + $data['wm_shadow_distance'] = $this->input->post('shadow_distance'); + + $data['apply_all'] = $this->input->post('apply_all'); + $data['menu_group'] = $this->input->post('menu_group'); + + $this->image_model->apply_menu_images($data); + + $this->image_model->save_menu_data($data); + + $view['applyall'] = $data['apply_all']; + $view['list'] = $this->image_model->get_menu_file_list($data['menu_group']); + $view['text'] = $data['wm_text']; + + $this->load->view('admin/image_tool/menu_image_view', $view); + } + + $this->footer(); } - else + + public function slot_image() { - $data['wm_type'] = 'text'; - $data['quality'] = '100%'; - - $data['file'] = $this->input->post('file'); + if ($this->userlevel < 5) { + show_404(); + } - $data['padding'] = $this->input->post('padding'); - $data['wm_vrt_alignment'] = $this->input->post('v_align'); - $data['wm_hor_alignment'] = $this->input->post('h_align'); - $data['wm_hor_offset'] = $this->input->post('h_offset'); - $data['wm_vrt_offset'] = $this->input->post('v_offset'); - - $data['wm_text'] = $this->input->post('text'); - $data['wm_font_path'] = './system/fonts/' . $this->input->post('font'); - $data['wm_font_size'] = $this->input->post('font_size'); - $data['wm_font_color'] = $this->input->post('font_color'); - $data['wm_shadow_color'] = $this->input->post('shadow_color'); - $data['wm_shadow_distance'] = $this->input->post('shadow_distance'); - $data['apply_all'] = $this->input->post('apply_all'); - $data['menu_group'] = $this->input->post('menu_group'); + $this->load->model('image_model'); + $this->load->library('form_validation'); - $this->image_model->apply_menu_images($data); + $this->form_validation->set_rules('submit', 'Submit', 'required'); - $this->image_model->save_menu_data($data); + $data['optimg'] = $this->image_model->get_file_list_drop(); + $data['optfont'] = $this->image_model->get_font_list_drop(); + $data['optvalign'] = $this->image_model->get_v_align_drop(); + $data['opthalign'] = $this->image_model->get_h_align_drop(); + $data['optgroup'] = $this->image_model->get_menu_group_list_drop(); + $data['optoverlay'] = $this->image_model->get_overlay_list_drop(); - $view['applyall'] = $data['apply_all']; - $view['list'] = $this->image_model->get_menu_file_list($data['menu_group']); - $view['text'] = $data['wm_text']; + $this->headers('admin'); - $this->load->view('admin/image_tool/menu_image_view', $view); + if (!$this->form_validation->run()) { + $this->load->view('admin/image_tool/slot_image', $data); + } else { + $path = './img/imggen/overlay/'; + + $data['wm_type'] = $this->input->post('wm_type'); + $data['quality'] = '100%'; + + $data['file'] = $this->input->post('file'); + + $data['padding'] = $this->input->post('padding'); + $data['wm_vrt_alignment'] = $this->input->post('v_align'); + $data['wm_hor_alignment'] = $this->input->post('h_align'); + $data['wm_hor_offset'] = $this->input->post('h_offset'); + $data['wm_vrt_offset'] = $this->input->post('v_offset'); + + $data['wm_text'] = $this->input->post('text'); + $data['wm_font_path'] = './system/fonts/' . $this->input->post('font'); + $data['wm_font_size'] = $this->input->post('font_size'); + $data['wm_font_color'] = $this->input->post('font_color'); + $data['wm_shadow_color'] = $this->input->post('shadow_color'); + $data['wm_shadow_distance'] = $this->input->post('shadow_distance'); + + $data['wm_overlay_path'] = $path . $this->input->post('wm_overlay_path'); + $data['wm_opacity'] = $this->input->post('wm_opacity'); + $data['wm_x_transp'] = $this->input->post('wm_x_transp'); + $data['wm_y_transp'] = $this->input->post('wm_y_transp'); + + $data['rank_text'] = $this->input->post('rank_text'); + $data['rank_font_size'] = $this->input->post('rank_font_size'); + $data['rank_v_align'] = $this->input->post('rank_v_align'); + $data['rank_h_align'] = $this->input->post('rank_h_align'); + $data['rank_h_offset'] = $this->input->post('rank_h_offset'); + $data['rank_v_offset'] = $this->input->post('rank_v_offset'); + $data['rank_padding'] = $this->input->post('rank_padding'); + + $this->image_model->apply_slot_images($data); + + $this->image_model->save_slot_data($data); + + $this->load->view('admin/image_tool/slot_image_view'); + } + + $this->footer(); } - $this->footer(); - } - - function slot_image() - { - if ($this->userlevel < 5) show_404(); - - - $this->load->model('image_model'); - $this->load->library('form_validation'); - - $this->form_validation->set_rules('submit', 'Submit', 'required'); - - $data['optimg'] = $this->image_model->get_file_list_drop(); - $data['optfont'] = $this->image_model->get_font_list_drop(); - $data['optvalign'] = $this->image_model->get_v_align_drop(); - $data['opthalign'] = $this->image_model->get_h_align_drop(); - $data['optgroup'] = $this->image_model->get_menu_group_list_drop(); - $data['optoverlay'] = $this->image_model->get_overlay_list_drop(); - - $this->headers('admin'); - - if (!$this->form_validation->run()) + //sql_tool begin + public function sql_tool() { - $this->load->view('admin/image_tool/slot_image', $data); + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('sql_model'); + + $data['list'] = $this->sql_model->get_appliable_files(); + + $this->headers('admin'); + $this->load->view('admin/sql_tool/list', $data); + $this->footer(); } - else + + //sql_tool + public function sql_new() { - $path = './img/imggen/overlay/'; + if ($this->userlevel < 5) { + show_404(); + } - $data['wm_type'] = $this->input->post('wm_type'); - $data['quality'] = '100%'; - - $data['file'] = $this->input->post('file'); + $this->load->library('form_validation'); - $data['padding'] = $this->input->post('padding'); - $data['wm_vrt_alignment'] = $this->input->post('v_align'); - $data['wm_hor_alignment'] = $this->input->post('h_align'); - $data['wm_hor_offset'] = $this->input->post('h_offset'); - $data['wm_vrt_offset'] = $this->input->post('v_offset'); - - $data['wm_text'] = $this->input->post('text'); - $data['wm_font_path'] = './system/fonts/' . $this->input->post('font'); - $data['wm_font_size'] = $this->input->post('font_size'); - $data['wm_font_color'] = $this->input->post('font_color'); - $data['wm_shadow_color'] = $this->input->post('shadow_color'); - $data['wm_shadow_distance'] = $this->input->post('shadow_distance'); + $this->form_validation->set_rules('sql', 'SQL', 'required'); - $data['wm_overlay_path'] = $path . $this->input->post('wm_overlay_path'); - $data['wm_opacity'] = $this->input->post('wm_opacity'); - $data['wm_x_transp'] = $this->input->post('wm_x_transp'); - $data['wm_y_transp'] = $this->input->post('wm_y_transp'); + if (!$this->form_validation->run()) { + $this->headers('admin'); + $this->load->view('admin/sql_tool/new'); + $this->footer(); + } else { + $sql = $this->input->post('sql'); - $data['rank_text'] = $this->input->post('rank_text'); - $data['rank_font_size'] = $this->input->post('rank_font_size'); - $data['rank_v_align'] = $this->input->post('rank_v_align'); - $data['rank_h_align'] = $this->input->post('rank_h_align'); - $data['rank_h_offset'] = $this->input->post('rank_h_offset'); - $data['rank_v_offset'] = $this->input->post('rank_v_offset'); - $data['rank_padding'] = $this->input->post('rank_padding'); - - $this->image_model->apply_slot_images($data); + $this->load->model('sql_model'); - $this->image_model->save_slot_data($data); + $this->sql_model->create_sql($sql); - $this->load->view('admin/image_tool/slot_image_view'); + $this->load->helper('url'); + + redirect('admin/sql_tool'); + } } + //sql_tool - $this->footer(); - } - -//sql_tool begin - function sql_tool() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('sql_model'); - - $data['list'] = $this->sql_model->get_appliable_files(); - - $this->headers('admin'); - $this->load->view('admin/sql_tool/list', $data); - $this->footer(); - - } - -//sql_tool - function sql_new() - { - if ($this->userlevel < 5) show_404(); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('sql', 'SQL', 'required'); - - if (!$this->form_validation->run()) + public function sql_apply_all() { - $this->headers('admin'); - $this->load->view('admin/sql_tool/new'); - $this->footer(); + if ($this->userlevel < 5) { + show_404(); + } + + $this->load->model('sql_model'); + + $this->sql_model->apply_all_sql(); + + $this->load->helper('url'); + + redirect('admin/sql_tool'); } - else - { - $sql = $this->input->post('sql'); - - $this->load->model('sql_model'); - - $this->sql_model->create_sql($sql); - - $this->load->helper('url'); - - redirect('admin/sql_tool'); - } - - } -//sql_tool - - function sql_apply_all() - { - if ($this->userlevel < 5) show_404(); - - $this->load->model('sql_model'); - - $this->sql_model->apply_all_sql(); - - $this->load->helper('url'); - - redirect('admin/sql_tool'); - } -//sql_tool end - + //sql_tool end } //nowhitesp diff --git a/Mourne-CI/application/controllers/alliance.php b/Mourne-CI/application/controllers/alliance.php index 91fe712..f30053b 100755 --- a/Mourne-CI/application/controllers/alliance.php +++ b/Mourne-CI/application/controllers/alliance.php @@ -2,21 +2,20 @@ class Alliance extends MO_Controller { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function index() - { - } + public function index() + { + } - function alliance_menu() - { - $this->headers('alliance'); - - $this->footer(); - } + public function alliance_menu() + { + $this->headers('alliance'); + $this->footer(); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/controllers/building.php b/Mourne-CI/application/controllers/building.php index bbac00c..26e86f5 100755 --- a/Mourne-CI/application/controllers/building.php +++ b/Mourne-CI/application/controllers/building.php @@ -2,701 +2,691 @@ class Building extends MO_Controller { - function __construct() - { - parent::__construct(); - } - - function index($id) - { - $this->load->helper('url'); - redirect('building/stats/' .$id); - } - - function stats($slotid = 0) - { - if (!$slotid) + public function __construct() { - $this->load->helper($url); - redirect('village/selected'); + parent::__construct(); } - $this->headers('do', $slotid); - - if ($this->building['id'] == 1) + public function index($id) { - $this->load->helper('url'); - redirect('building/build'); + $this->load->helper('url'); + redirect('building/stats/' .$id); } - if ($this->building['id'] == 2) + public function stats($slotid = 0) { - //build_in_progress + if (!$slotid) { + $this->load->helper($url); + redirect('village/selected'); + } - $this->headers('build_in_progress'); + $this->headers('do', $slotid); - $event = $this->_filter_events('type', 'slotid', $slotid, 0, TRUE); + if ($this->building['id'] == 1) { + $this->load->helper('url'); + redirect('building/build'); + } - $data['event'] = $event; - $data['building'] = $this->building_model->get_building($event['data1']); + if ($this->building['id'] == 2) { + //build_in_progress + + $this->headers('build_in_progress'); + + $event = $this->_filter_events('type', 'slotid', $slotid, 0, true); + + $data['event'] = $event; + $data['building'] = $this->building_model->get_building($event['data1']); - $this->load->view('building/header', $data); - $this->load->view('building/spacer'); - $this->load->view('building/next_event', $data); - $this->load->view('building/stats', $data); - - $this->footer(); - - return; + $this->load->view('building/header', $data); + $this->load->view('building/spacer'); + $this->load->view('building/next_event', $data); + $this->load->view('building/stats', $data); + + $this->footer(); + + return; + } + + $this->headers('building', $slotid); + + $data['slotid'] = $slotid; + + $this->load->view('building/stats', $data); + + $this->footer(); } - $this->headers('building', $slotid); - - $data['slotid'] = $slotid; - - $this->load->view('building/stats', $data); - - $this->footer(); - } - - function upgrade($slotid = 0) - { - if (!$slotid) + public function upgrade($slotid = 0) { - $this->load->helper('url'); - redirect('village/selected'); + if (!$slotid) { + $this->load->helper('url'); + redirect('village/selected'); + } + + $this->headers('building', $slotid); + + $event = $this->_filter_events('type', 'slot', $slotid, 1); + + $up['slotid'] = $slotid; + + if ($this->building['next_rank']) { + $up['slotid'] = $slotid; + + $up['nextrank'] = $this->building_model->get_building( + $this->building['next_rank'] + ); + + $up['upgrade'] = $this->building_model->can_be_upgraded( + $event, + $this->resources, + $up['nextrank'], + $this->villageid + ); + } + + $this->load->view('building/upgrade', $up); + $this->footer(); } - $this->headers('building', $slotid); - - $event = $this->_filter_events('type', 'slot', $slotid, 1); - - $up['slotid'] = $slotid; - - if ($this->building['next_rank']) + public function create($slotid = 0) { - $up['slotid'] = $slotid; + if (!$slotid) { + $this->load->helper($url); + redirect('village/selected'); + } - $up['nextrank'] = $this->building_model->get_building( - $this->building['next_rank']); + $this->headers('building', $slotid); - $up['upgrade'] = $this->building_model->can_be_upgraded( - $event, - $this->resources, - $up['nextrank'], - $this->villageid); + //can create something + 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']) { + $data['costu'] = $this->unit_model->get_unit( + $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'], + $this->building['num_creates'], + $this->resources + ); + + $data['maxunit'] = $this->unit_model->calc_max_unit_ev( + $this->building['num_creates'], + $data['maxunit'], + $events + ); + + if ($events) { + $d['event'] = $events; + $this->load->view('building/events', $d); + } + } + + $data['building'] = $this->building; + $this->load->view('building/building_create', $data); + + $this->footer(); } - $this->load->view('building/upgrade', $up); - $this->footer(); - } - - function create($slotid = 0) - { - if (!$slotid) + public function assign($slotid) { - $this->load->helper($url); - redirect('village/selected'); + if (!$slotid) { + $this->load->helper($url); + redirect('village/selected'); + } + + $this->headers('building', $slotid); + + //have assignments + $this->load->model('assignment_model'); + + $assign = $this->assignment_model->get_assignments( + $slotid, + $this->villageid, + $this->userid + ); + + $assign['slotid'] = $slotid; + + $this->load->view('building/assignments', $assign); + + $this->footer(); } - $this->headers('building', $slotid); - - //can create something - if ($this->building['creates']) + public function spells($slotid) { - $events = $this->_filter_events('type', 'all', $slotid, 2); + if (!$slotid) { + $this->load->helper($url); + redirect('village/selected'); + } - $this->load->model('unit_model'); + $this->headers('building', $slotid); - $data['unit'] = $this->unit_model->get_unit($this->building['creates']); + $this->load->model('spell_model'); - if ($data['unit']['cost_unit']) - $data['costu'] = $this->unit_model->get_unit( - $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'], - $this->building['num_creates'], - $this->resources); - - $data['maxunit'] = $this->unit_model->calc_max_unit_ev( - $this->building['num_creates'], - $data['maxunit'], - $events); - - if ($events) - { - $d['event'] = $events; - $this->load->view('building/events', $d); - } + $spell['spells'] = $this->spell_model->get_spells( + $slotid, + $this->villageid + ); + + $spell['slotid'] = $slotid; + $this->load->view('building/spells', $spell); + $this->footer(); } - $data['building'] = $this->building; - $this->load->view('building/building_create', $data); - - $this->footer(); - } - - function assign($slotid) - { - if (!$slotid) + public function events($slotid = 0) { - $this->load->helper($url); - redirect('village/selected'); + if (!$slotid) { + $this->load->helper($url); + redirect('village/selected'); + } + + $this->headers('building', $slotid); + + //$this->load->model('event_model'); + //$data['event'] = $this->event_model->get_events($slotid, + // $this->villageid); + + $data['event'] = $this->_filter_events('all', 'slot', $slotid); + + $this->load->view('building/events', $data); + + $this->footer(); } - $this->headers('building', $slotid); - - //have assignments - $this->load->model('assignment_model'); - - $assign = $this->assignment_model->get_assignments($slotid, - $this->villageid, - $this->userid); - - $assign['slotid'] = $slotid; - - $this->load->view('building/assignments', $assign); - - $this->footer(); - } - - function spells($slotid) - { - if (!$slotid) + public function research($slotid = 0) { - $this->load->helper($url); - redirect('village/selected'); + if (!$slotid) { + $this->load->helper('url'); + redirect('village/selected'); + } + + $this->headers('building', $slotid); + + $events = $this->_filter_events('type', 'slot', $slotid, 4); + + if (!$events) { + $this->load->model('technology_model'); + + $data = $this->technology_model->get_researchable( + $slotid, + $this->villageid + ); + + $data['slotid'] = $slotid; + + + $this->load->view('building/research', $data); + } else { + $this->load->model('technology_model'); + + $data['technology'] = $this->technology_model->get_technology($events[0]['data1']); + + $this->load->view('building/al_research', $data); + } + + $this->footer(); } - $this->headers('building', $slotid); - - $this->load->model('spell_model'); - - $spell['spells'] = $this->spell_model->get_spells($slotid, - $this->villageid); - - $spell['slotid'] = $slotid; - - $this->load->view('building/spells', $spell); - $this->footer(); - } - - function events($slotid = 0) - { - if (!$slotid) + public function build($slotid = 0) { - $this->load->helper($url); - redirect('village/selected'); + if (!$slotid) { + $this->load->helper('url'); + redirect('village/selected'); + } + + $this->load->model('building_model'); + + $this->_get_slot_building($slotid); + + $this->headers('build'); + + if ($this->building['id'] == 1) { + //empty space + + $data['buildings'] = $this->building_model->building_list( + $this->villageid + ); + + $data['slotid'] = $slotid; + $this->load->view('building/list', $data); + } else { + //slot has some building + $this->load->helper('url'); + redirect('building/stats/' . $slotid); + } + + $this->footer(); } - $this->headers('building', $slotid); - - //$this->load->model('event_model'); - //$data['event'] = $this->event_model->get_events($slotid, -// $this->villageid); - - $data['event'] = $this->_filter_events('all', 'slot', $slotid); - - $this->load->view('building/events', $data); - - $this->footer(); - } - - function research($slotid = 0) - { - if (!$slotid) + public function dobuild() { - $this->load->helper('url'); - redirect('village/selected'); + $this->load->helper('url'); + + $slotid = $this->input->post('slotid'); + $buildingid = $this->input->post('id'); + + if (!$slotid || !$buildingid) { + redirect('village/selected'); + } + + $this->headers('do'); + + $this->load->model('building_model'); + //$this->load->model('event_model'); + $this->load->model('resource_model'); + + //check if building exists + if (!$this->building_model->is_valid_slot($slotid, $this->villageid)) { + //display error page + echo "is_valid_slot returned FALSE"; + return; + } + + $building = $this->building_model->get_building($buildingid); + + if (!$this->building_model->check_resources($this->resources, $building)) { + //display error page + echo "You don't have enough resources"; + return; + } + + /* + //do this matters? maybe it should be removed. + if ($this->event_model->has_event($slotid, $this->villageid)) + { + //display error page + echo "has_event returned TRUE"; + return; + } + */ + /* this probably aren't needed + if (!$this->building_model->can_build($this->villageid, $buildingid)) + { + //display an error page + echo "can_build returned FALSE"; + return; + } + */ + + //can be built + if (!$this->building_model->has_req_tech($building['req_tech'], $this->villageid)) { + echo "Technology requirements not met."; + return; + } + + //add_event + $this->load->helper('event'); + + $ev['type'] = ev_type('build'); + $ev['villageid'] = $this->villageid; + $ev['slotid'] = $slotid; + $ev['time'] = $building['time_to_build']; + $ev['data1'] = $buildingid; + + $this->event_model->add_event($ev); + + //resource substract + $this->resource_model->set_resources($this->resources); + $this->resource_model->substract_resources( + $building, + $this->villageid + ); + $this->resource_model->write_resources(); + + //change tile to build in progress + $this->building_model->set_build_in_progress($slotid, $this->villageid); + + $url = 'building/stats/' . $slotid; + redirect($url); } - $this->headers('building', $slotid); - - $events = $this->_filter_events('type', 'slot', $slotid, 4); - - if (!$events) + public function docreate($slotid) { - $this->load->model('technology_model'); + $this->load->library('form_validation'); - $data = $this->technology_model->get_researchable($slotid, - $this->villageid); + $this->form_validation->set_rules( + 'create_num', + 'Number to create', + 'is_natural_no_zero' + ); - $data['slotid'] = $slotid; + $this->load->helper('url'); + $url = 'building/create/' . $slotid; + $this->headers('do', $slotid); - $this->load->view('building/research', $data); + if ($this->form_validation->run()) { + $num_create = $this->input->post('create_num'); + + if (!$num_create) { + redirect($url); + } + + $this->load->model('building_model'); + + $building = $this->building; + + $this->headers('do'); + + if ($building['id'] == 1 || $building['id'] == 2) { + //TODO show proper error + echo "There isn't any building in that slot"; + return; + } + + if (!$building['creates']) { + //TODO show proper error + echo "that building can't create units"; + return; + } + + $event = $this->_filter_events('type', 'slot', $slotid, 2); + + $this->load->model('resource_model'); + $res = $this->resources; + + $this->load->model('unit_model'); + $unit = $this->unit_model->get_unit($building['creates']); + + $max = $this->resource_model->calc_max_unit( + $unit, + $building['num_creates'], + $res + ); + + $max = $this->unit_model->calc_max_unit_ev( + $building['num_creates'], + $max, + $event + ); + + if (!$max) { + //TODO proper error + echo "You can't make any"; + return; + } + + if ($num_create > $max) { + //TODO proper error + echo "You can't make that many"; + return; + } + + //add event + $this->load->helper('event'); + + $ev['type'] = ev_type('create'); + $ev['villageid'] = $this->villageid; + $ev['slotid'] = $slotid; + $ev['time'] = ($unit['time_to_create'] * $num_create); + $ev['data1'] = $unit['id']; + $ev['data2'] = $num_create; + + $this->event_model->add_event($ev); + + $this->resource_model->set_resources($this->resources); + $this->resource_model->substract_resources( + $unit, + $this->villageid, + $num_create + ); + + $this->resource_model->write_resources(); + + redirect($url); + } else { + redirect($url); + } } - else + + public function doupgrade() { - $this->load->model('technology_model'); + $this->headers('do'); - $data['technology'] = $this->technology_model->get_technology($events[0]['data1']); + $this->load->helper('url'); + $this->load->library('form_validation'); - $this->load->view('building/al_research', $data); + $this->form_validation->set_rules('slotid', 'Slotid', 'is_natural'); + + if ($this->form_validation->run()) { + $this->load->model('event_model'); + $this->load->model('resource_model'); + $this->load->model('building_model'); + + $slotid = $this->input->post('slotid'); + + $this->headers('do', $slotid); + + $building = $this->building; + + if (!$building['next_rank']) { + echo "Building doesn't have next rank."; + return; + } + + $next_rank = $this->building_model->get_building($building['next_rank']); + $res = $this->resources; + + + $event = $this->_filter_events('type', 'slot', $slotid, 1); + + $can = $this->building_model->can_be_upgraded( + $event, + $res, + $next_rank, + $this->villageid + ); + + if ($can == 3) { + //can be upgraded + + $this->load->helper('event'); + + $ev['type'] = ev_type('upgrade'); + $ev['villageid'] = $this->villageid; + $ev['slotid'] = $slotid; + $ev['time'] = $next_rank['time_to_build']; + $ev['data1'] = $next_rank['id']; + $ev['data2'] = $building['id']; + + $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->write_resources(); + + $url = 'building/upgrade/' . $slotid; + redirect($url); + } elseif ($can == 1) { + echo "Village doesn't have the required technology."; + return; + } elseif ($can == 2) { + //not enough resources + echo "Not enough resources"; + return; + } else { + //upgrading in progress + echo "Upgrade already in progress."; + return; + } + } else { + redirect('village/selected'); + } } - $this->footer(); - - } - - function build($slotid = 0) - { - if (!$slotid) + public function doassign() { - $this->load->helper('url'); - redirect('village/selected'); + $this->headers('do'); + + $this->load->library('form_validation'); + + $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' + ); + + 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 + ); + + //error handling with return value + if ($a == 1) { + //no building in that slot + echo "No building in that slot"; + return; + } + + if ($a == 2) { + //no such assignmentid + echo "No such assignmentid"; + return; + } + + if ($a == 3) { + //building soesn't have that assignment + echo "Building doesn't have that assignment"; + return; + } + + if ($a == 4) { + echo "You don't have any units that can be assigned in that slot"; + return; + } + + + $this->load->helper('url'); + redirect('building/assign/' . $slotid); + } else { + $this->load->helper('url'); + redirect('village/selected'); + } } - $this->load->model('building_model'); - - $this->_get_slot_building($slotid); - - $this->headers('build'); - - if ($this->building['id'] == 1) + public function dospell() { - //empty space + $this->headers('do'); - $data['buildings'] = $this->building_model->building_list( - $this->villageid); + $this->load->library('form_validation'); - $data['slotid'] = $slotid; - $this->load->view('building/list', $data); + $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()) { + $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 + ); + + //error handling with return value + if ($a == 1) { + echo "Building doesn't have that spell"; + return; + } + + if ($a == 2) { + echo "spell is on cooldown"; + return; + } + + if ($a == 3) { + echo "Not enough resources"; + return; + } + + + + $this->load->helper('url'); + redirect('building/spells/' . $slotid); + } else { + $this->load->helper('url'); + redirect('village/selected'); + } } - else + + public function doresearch() { - //slot has some building - $this->load->helper('url'); - redirect('building/stats/' . $slotid); + $this->load->helper('url'); + + $slotid = $this->input->post('slotid'); + $techid = $this->input->post('id'); + + if (!($slotid || $techid)) { + redirect('village/selected'); + } + + $this->headers('do'); + + $event = $this->_filter_events('type', 'slot', $slotid, 4); + + if ($event) { + echo "Already researching."; + } + + $this->load->model('technology_model'); + + $a = $this->technology_model->do_research( + $techid, + $this->resources, + $slotid, + $this->villageid + ); + + if ($a == 1) { + echo "Technology ID doesn't exist"; + return; + } + + if ($a == 2) { + echo "Not enough resources"; + return; + } + + if ($a == 3) { + echo "Building doesn't have that technology, or you already have it"; + return; + } + + redirect('building/research/' . $slotid); } - - $this->footer(); - } - - function dobuild() - { - $this->load->helper('url'); - - $slotid = $this->input->post('slotid'); - $buildingid = $this->input->post('id'); - - if (!$slotid || !$buildingid) - redirect('village/selected'); - - $this->headers('do'); - - $this->load->model('building_model'); - //$this->load->model('event_model'); - $this->load->model('resource_model'); - - //check if building exists - if (!$this->building_model->is_valid_slot($slotid, $this->villageid)) - { - //display error page - echo "is_valid_slot returned FALSE"; - return; - } - - $building = $this->building_model->get_building($buildingid); - - if (!$this->building_model->check_resources($this->resources, $building)) - { - //display error page - echo "You don't have enough resources"; - return; - } - -/* - //do this matters? maybe it should be removed. - if ($this->event_model->has_event($slotid, $this->villageid)) - { - //display error page - echo "has_event returned TRUE"; - return; - } -*/ -/* this probably aren't needed - if (!$this->building_model->can_build($this->villageid, $buildingid)) - { - //display an error page - echo "can_build returned FALSE"; - return; - } -*/ - - //can be built - if (!$this->building_model->has_req_tech($building['req_tech'], $this->villageid)) - { - echo "Technology requirements not met."; - return; - } - - //add_event - $this->load->helper('event'); - - $ev['type'] = ev_type('build'); - $ev['villageid'] = $this->villageid; - $ev['slotid'] = $slotid; - $ev['time'] = $building['time_to_build']; - $ev['data1'] = $buildingid; - - $this->event_model->add_event($ev); - - //resource substract - $this->resource_model->set_resources($this->resources); - $this->resource_model->substract_resources($building, - $this->villageid); - $this->resource_model->write_resources(); - - //change tile to build in progress - $this->building_model->set_build_in_progress($slotid, $this->villageid); - - $url = 'building/stats/' . $slotid; - redirect($url); - - } - - function docreate($slotid) - { - $this->load->library('form_validation'); - - $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()) - { - $num_create = $this->input->post('create_num'); - - if (!$num_create) - redirect($url); - - $this->load->model('building_model'); - - $building = $this->building; - - $this->headers('do'); - - if ($building['id'] == 1 || $building['id'] == 2) - { - //TODO show proper error - echo "There isn't any building in that slot"; - return; - } - - if (!$building['creates']) - { - //TODO show proper error - echo "that building can't create units"; - return; - } - - $event = $this->_filter_events('type', 'slot', $slotid, 2); - - $this->load->model('resource_model'); - $res = $this->resources; - - $this->load->model('unit_model'); - $unit = $this->unit_model->get_unit($building['creates']); - - $max = $this->resource_model->calc_max_unit($unit, - $building['num_creates'], - $res); - - $max = $this->unit_model->calc_max_unit_ev($building['num_creates'], - $max, - $event); - - if (!$max) - { - //TODO proper error - echo "You can't make any"; - return; - } - - if ($num_create > $max) - { - //TODO proper error - echo "You can't make that many"; - return; - } - - //add event - $this->load->helper('event'); - - $ev['type'] = ev_type('create'); - $ev['villageid'] = $this->villageid; - $ev['slotid'] = $slotid; - $ev['time'] = ($unit['time_to_create'] * $num_create); - $ev['data1'] = $unit['id']; - $ev['data2'] = $num_create; - - $this->event_model->add_event($ev); - - $this->resource_model->set_resources($this->resources); - $this->resource_model->substract_resources($unit, - $this->villageid, - $num_create); - - $this->resource_model->write_resources(); - - redirect($url); - } - else - { - redirect($url); - } - } - - function doupgrade() - { - $this->headers('do'); - - $this->load->helper('url'); - $this->load->library('form_validation'); - - $this->form_validation->set_rules('slotid', 'Slotid', 'is_natural'); - - if ($this->form_validation->run()) - { - $this->load->model('event_model'); - $this->load->model('resource_model'); - $this->load->model('building_model'); - - $slotid = $this->input->post('slotid'); - - $this->headers('do', $slotid); - - $building = $this->building; - - if (!$building['next_rank']) - { - echo "Building doesn't have next rank."; - return; - } - - $next_rank = $this->building_model->get_building($building['next_rank']); - $res = $this->resources; - - - $event = $this->_filter_events('type', 'slot', $slotid, 1); - - $can = $this->building_model->can_be_upgraded($event, $res, $next_rank, - $this->villageid); - - if ($can == 3) - { - //can be upgraded - - $this->load->helper('event'); - - $ev['type'] = ev_type('upgrade'); - $ev['villageid'] = $this->villageid; - $ev['slotid'] = $slotid; - $ev['time'] = $next_rank['time_to_build']; - $ev['data1'] = $next_rank['id']; - $ev['data2'] = $building['id']; - - $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->write_resources(); - - $url = 'building/upgrade/' . $slotid; - redirect($url); - - } - elseif ($can == 1) - { - echo "Village doesn't have the required technology."; - return; - } - elseif ($can == 2) - { - //not enough resources - echo "Not enough resources"; - return; - } - else - { - //upgrading in progress - echo "Upgrade already in progress."; - return; - } - } - else - { - redirect('village/selected'); - } - } - - function doassign() - { - $this->headers('do'); - - $this->load->library('form_validation'); - - $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'); - - 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); - - //error handling with return value - if ($a == 1) - { - //no building in that slot - echo "No building in that slot"; - return; - } - - if ($a == 2) - { - //no such assignmentid - echo "No such assignmentid"; - return; - } - - if ($a == 3) - { - //building soesn't have that assignment - echo "Building doesn't have that assignment"; - return; - } - - if ($a == 4) - { - echo "You don't have any units that can be assigned in that slot"; - return; - } - - - $this->load->helper('url'); - redirect('building/assign/' . $slotid); - } - else - { - $this->load->helper('url'); - redirect('village/selected'); - } - } - - function dospell() - { - $this->headers('do'); - - $this->load->library('form_validation'); - - $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()) - { - $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); - - //error handling with return value - if ($a == 1) - { - echo "Building doesn't have that spell"; - return; - } - - if ($a == 2) - { - echo "spell is on cooldown"; - return; - } - - if ($a == 3) - { - echo "Not enough resources"; - return; - } - - - - $this->load->helper('url'); - redirect('building/spells/' . $slotid); - } - else - { - $this->load->helper('url'); - redirect('village/selected'); - } - - } - - function doresearch() - { - $this->load->helper('url'); - - $slotid = $this->input->post('slotid'); - $techid = $this->input->post('id'); - - if (!($slotid || $techid)) - redirect('village/selected'); - - $this->headers('do'); - - $event = $this->_filter_events('type', 'slot', $slotid, 4); - - if ($event) - echo "Already researching."; - - $this->load->model('technology_model'); - - $a = $this->technology_model->do_research($techid, $this->resources, $slotid, - $this->villageid); - - if ($a == 1) - { - echo "Technology ID doesn't exist"; - return; - } - - if ($a == 2) - { - echo "Not enough resources"; - return; - } - - if ($a == 3) - { - echo "Building doesn't have that technology, or you already have it"; - return; - } - - redirect('building/research/' . $slotid); - - } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/controllers/changelog.php b/Mourne-CI/application/controllers/changelog.php index 616223c..15f3f60 100755 --- a/Mourne-CI/application/controllers/changelog.php +++ b/Mourne-CI/application/controllers/changelog.php @@ -2,77 +2,70 @@ class Changelog extends MO_Controller { - - function __construct() - { - parent::__construct(); - } - - function show() - { - $this->load->model('changelog_model'); - - $data['versions'] = $this->changelog_model->get_versions(); - $data['commits'] = $this->changelog_model->get_commits(); - $data['userlevel'] = $this->userlevel; - $data['required_userlevel'] = 4; - - $this->headers(); - $this->load->view('changelog/changelog', $data); - $this->footer(); - } - - function add_new_version() - { - if (!$this->userlevel > 4) - show404(); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('text', 'Text', 'required'); - - if (!$this->form_validation->run()) + public function __construct() { - $this->load->view('changelog/new_version'); + parent::__construct(); } - else + + public function show() { - $this->load->model('changelog_model'); + $this->load->model('changelog_model'); - $text = $this->input->post('text'); - $this->changelog_model->new_version($text); + $data['versions'] = $this->changelog_model->get_versions(); + $data['commits'] = $this->changelog_model->get_commits(); + $data['userlevel'] = $this->userlevel; + $data['required_userlevel'] = 4; - $this->load->helper('url'); - redirect('changelog/show'); + $this->headers(); + $this->load->view('changelog/changelog', $data); + $this->footer(); } - } - - function add_new_commit() - { - if (!$this->userlevel > 4) - show404(); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('text', 'Text', 'required'); - - if (!$this->form_validation->run()) - { - $this->load->view('changelog/new_commit'); - } - else + public function add_new_version() { - $this->load->model('changelog_model'); + if (!$this->userlevel > 4) { + show404(); + } - $text = $this->input->post('text'); - $this->changelog_model->new_commit($text); + $this->load->library('form_validation'); - $this->load->helper('url'); - redirect('changelog/show'); + $this->form_validation->set_rules('text', 'Text', 'required'); + + if (!$this->form_validation->run()) { + $this->load->view('changelog/new_version'); + } else { + $this->load->model('changelog_model'); + + $text = $this->input->post('text'); + $this->changelog_model->new_version($text); + + $this->load->helper('url'); + redirect('changelog/show'); + } } - } + public function add_new_commit() + { + if (!$this->userlevel > 4) { + show404(); + } + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('text', 'Text', 'required'); + + if (!$this->form_validation->run()) { + $this->load->view('changelog/new_commit'); + } else { + $this->load->model('changelog_model'); + + $text = $this->input->post('text'); + $this->changelog_model->new_commit($text); + + $this->load->helper('url'); + redirect('changelog/show'); + } + } } //nowhitesp diff --git a/Mourne-CI/application/controllers/cron.php b/Mourne-CI/application/controllers/cron.php index 80ed01e..6098d7f 100755 --- a/Mourne-CI/application/controllers/cron.php +++ b/Mourne-CI/application/controllers/cron.php @@ -1,23 +1,22 @@ load->model('ai_model'); + $this->load->model('ai_model'); - $a = $this->ai_model->attack(); - - echo $a; - } + $a = $this->ai_model->attack(); + echo $a; + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/controllers/forum.php b/Mourne-CI/application/controllers/forum.php index 8ea6a81..45ae560 100755 --- a/Mourne-CI/application/controllers/forum.php +++ b/Mourne-CI/application/controllers/forum.php @@ -2,19 +2,18 @@ class Forum extends MO_Controller { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function index() - { - $this->headers('forum'); + public function index() + { + $this->headers('forum'); - $this->load->view('forum/notimpl'); - - $this->footer(); - } + $this->load->view('forum/notimpl'); + $this->footer(); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/controllers/gm.php b/Mourne-CI/application/controllers/gm.php index a53e2b8..a3a57b2 100755 --- a/Mourne-CI/application/controllers/gm.php +++ b/Mourne-CI/application/controllers/gm.php @@ -2,16 +2,16 @@ class Gm extends MO_Controller { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function gm_panel() - { - $this->headers('gm'); + public function gm_panel() + { + $this->headers('gm'); - $this->footer(); - } + $this->footer(); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/controllers/hero.php b/Mourne-CI/application/controllers/hero.php index 043e285..32ef77f 100755 --- a/Mourne-CI/application/controllers/hero.php +++ b/Mourne-CI/application/controllers/hero.php @@ -2,212 +2,192 @@ class Hero extends MO_Controller { - function __construct() - { - parent::__construct('hero'); - } - - function index() - { - $this->load->helper('url'); - redirect('hero/selected'); - } - - 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') + public function __construct() { - $page = 'stats'; + parent::__construct('hero'); } - $this->load->view('hero/hero_menu'); + public function index() + { + $this->load->helper('url'); + redirect('hero/selected'); + } + + 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 = 'stats'; + } + + $this->load->view('hero/hero_menu'); - if ($page == 'stats') - { - $data['hero'] = $this->hero; + if ($page == 'stats') { + $data['hero'] = $this->hero; - $data['hpp'] = floor(($this->hero['health'] / $this->hero['max_health']) * 100); - $data['mpp'] = floor(($this->hero['mana'] / $this->hero['max_mana']) * 100); - $data['exp'] = floor(($this->hero['experience'] /1000) * 100); + $data['hpp'] = floor(($this->hero['health'] / $this->hero['max_health']) * 100); + $data['mpp'] = floor(($this->hero['mana'] / $this->hero['max_mana']) * 100); + $data['exp'] = floor(($this->hero['experience'] /1000) * 100); - //STUB! - $data['experience'] = 10000; + //STUB! + $data['experience'] = 10000; - $this->load->view('hero/stats', $data); - } - elseif ($page == 'inventory') - { - $this->load->model('item_model'); + $this->load->view('hero/stats', $data); + } elseif ($page == 'inventory') { + $this->load->model('item_model'); - if ($d1 !== FALSE && $d2 !== FALSE && $d3 !== FALSE && $d4 !== FALSE) - { - $this->item_model->set_hero($this->hero); + 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); + $res['message'] = $this->item_model->swap($d1, $d2, $d3, $d4); - if ($res['message'] === TRUE) - $this->hero = $this->item_model->get_hero(); + if ($res['message'] === true) { + $this->hero = $this->item_model->get_hero(); + } - $d1 = FALSE; - $d2 = FALSE; - //we doesn't care about d3,d4 that isn't used in views - } + $d1 = false; + $d2 = false; + //we doesn't care about d3,d4 that isn't used in views + } - $data = $this->item_model->get_inventory($this->hero['id']); + $data = $this->item_model->get_inventory($this->hero['id']); - $data['hero'] = $this->hero; + $data['hero'] = $this->hero; - $data['d1'] = $d1; - $data['d2'] = $d2; + $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') - { + $this->load->view('hero/inventory_view', $res); + } elseif ($page == 'talents') { + } elseif ($page == 'spells') { + } elseif ($page == 'actionbars') { + } + + $this->footer(); } - $this->footer(); - } - - function create() - { - $this->load->library('form_validation'); - - $this->form_validation->set_rules('name', 'Name', 'required|alpha|callback_chhn'); - $this->form_validation->set_rules('gender', 'Gender', 'required|greater_than[0]|less_than[3]|integer'); - //less than! - $this->form_validation->set_rules('class', 'Class', 'required|integer|greater_than[0]|less_than[10]'); - - if (!$this->form_validation->run()) + public function create() { - $this->headers('hero', 1); + $this->load->library('form_validation'); + + $this->form_validation->set_rules('name', 'Name', 'required|alpha|callback_chhn'); + $this->form_validation->set_rules('gender', 'Gender', 'required|greater_than[0]|less_than[3]|integer'); + //less than! + $this->form_validation->set_rules('class', 'Class', 'required|integer|greater_than[0]|less_than[10]'); + + if (!$this->form_validation->run()) { + $this->headers('hero', 1); - $this->load->view('hero/create'); + $this->load->view('hero/create'); - $this->footer(); - } - else - { - $this->load->model('hero_model'); + $this->footer(); + } else { + $this->load->model('hero_model'); - $data['name'] = $this->input->post('name'); - $data['gender'] = $this->input->post('gender'); - $data['class'] = $this->input->post('class'); + $data['name'] = $this->input->post('name'); + $data['gender'] = $this->input->post('gender'); + $data['class'] = $this->input->post('class'); - $this->hero_model->create($data, $this->userid); + $this->hero_model->create($data, $this->userid); - $this->load->helper('url'); - redirect('hero/selected'); + $this->load->helper('url'); + redirect('hero/selected'); + } } - } - 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()) + public function select() { - $this->headers('hero'); + $this->load->model('hero_model'); + $this->load->library('form_validation'); - $data['heroes'] = $this->hero_model->get_heroes($this->userid); + $this->form_validation->set_rules('heroid', 'Heroid', 'required'); - $this->load->view('hero/select', $data); + if (!$this->form_validation->run()) { + $this->headers('hero'); - $this->footer(); + $data['heroes'] = $this->hero_model->get_heroes($this->userid); + + $this->load->view('hero/select', $data); + + $this->footer(); + } else { + $heroid = $this->input->post('heroid'); + + $this->hero_model->select_hero($heroid, $this->userid); + + $this->load->helper('url'); + redirect('hero/selected'); + } } - else + + public function delete($id = false) { - $heroid = $this->input->post('heroid'); + $this->load->helper('url'); - $this->hero_model->select_hero($heroid, $this->userid); + if (!$id || !is_numeric($id)) { + redirect('hero/select'); + } - $this->load->helper('url'); - redirect('hero/selected'); + $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()) { + $data['id'] = $id; + $data['hero'] = $this->hero_model->get_hero($id, $this->userid); + + if (!$data['hero']) { + redirect('hero/select'); + } + + $this->headers('hero'); + + $this->load->view('hero/delete_confirm', $data); + + $this->footer(); + } else { + $this->hero_model->delete_hero($id, $this->userid); + + redirect('hero/select'); + } } - } - function delete($id = FALSE) - { - $this->load->helper('url'); - - 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()) + public function addstat() { - $data['id'] = $id; - $data['hero'] = $this->hero_model->get_hero($id, $this->userid); - - if (!$data['hero']) - redirect('hero/select'); - - $this->headers('hero'); - - $this->load->view('hero/delete_confirm', $data); - - $this->footer(); - } - else - { - $this->hero_model->delete_hero($id, $this->userid); - - redirect('hero/select'); - } - } - - function addstat() - { - //hero's stat view calls this with a form the hidden field's name is attrid + //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) - { - $this->load->model('hero_model'); - - $a = $this->hero_model->hero_name_is_unique($name); - - if (!$a) - { - $this->form_validation->set_message('chhn', 'Name already taken.'); - return FALSE; } - else + + public function chhn($name) { - return TRUE; + $this->load->model('hero_model'); + + $a = $this->hero_model->hero_name_is_unique($name); + + if (!$a) { + $this->form_validation->set_message('chhn', 'Name already taken.'); + return false; + } else { + return true; + } } - } - function delete_check($chk) - { - if ($chk == "DELETE") - return TRUE; + public function delete_check($chk) + { + if ($chk == "DELETE") { + return true; + } - $this->form_validation->set_message('delete_check', 'You have to spell DELETE, exactly, and uppercase.'); - - return FALSE; - } + $this->form_validation->set_message('delete_check', 'You have to spell DELETE, exactly, and uppercase.'); + return false; + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/controllers/mail.php b/Mourne-CI/application/controllers/mail.php index 8512a6b..b96c498 100755 --- a/Mourne-CI/application/controllers/mail.php +++ b/Mourne-CI/application/controllers/mail.php @@ -2,163 +2,144 @@ class Mail extends MO_Controller { - function __construct() - { - parent::__construct(); - } - - function index() - { - $this->load->helper('url'); - redirect('mail/inbox'); - } - - function inbox() - { - $this->headers('mail'); - - $this->load->model('mail_model'); - - $data['mails'] = $this->mail_model->get_inbox($this->userid, $this->new_mail); - - $this->load->view('mail/inbox', $data); - - $this->footer(); - } - - function compose($id = 0) - { - $this->headers('mail'); - $this->load->model('mail_model'); - $this->load->library('form_validation'); - - $d['draft'] = FALSE; - - if ($id && is_numeric($id)) + public function __construct() { - $d['draft'] = $this->mail_model->get_draft($id, $this->userid); + parent::__construct(); } - $this->form_validation->set_rules('name', 'Username', 'required'); - $this->form_validation->set_rules('subject', 'Subject', 'required'); - $this->form_validation->set_rules('message', 'Message', 'required'); - - if (!$this->form_validation->run()) + public function index() { - $this->load->view('mail/new', $d); - } - else - { - $send = $this->input->post('send'); - $draft = $this->input->post('draft'); - - $data['name'] = $this->input->post('name'); - $data['subject'] = $this->input->post('subject'); - $data['message'] = $this->input->post('message'); - - if ($send) - { - $this->mail_model->send_message($data, $this->userid); - } - else - { - $this->mail_model->save_draft($data, $this->userid); - } + $this->load->helper('url'); + redirect('mail/inbox'); } - $this->footer(); - } - - function del_draft($id = 0) - { - if ($id && is_numeric($id)) + public function inbox() { - $this->load->model("mail_model"); - $this->mail_model->delete_draft($id, $this->userid); + $this->headers('mail'); + + $this->load->model('mail_model'); + + $data['mails'] = $this->mail_model->get_inbox($this->userid, $this->new_mail); + + $this->load->view('mail/inbox', $data); + + $this->footer(); } - $this->load->helper('url'); - redirect('mail/drafts'); - } - - function drafts() - { - $this->load->model('mail_model'); - - $this->headers('mail'); - - $data['mails'] = $this->mail_model->get_drafts($this->userid); - - $this->load->view('mail/drafts', $data); - - $this->footer(); - } - - function read($id = 0) - { - if (!$id || !is_numeric($id)) + public function compose($id = 0) { - $this->load->helper('url'); - redirect('mail/inbox'); + $this->headers('mail'); + $this->load->model('mail_model'); + $this->load->library('form_validation'); + + $d['draft'] = false; + + if ($id && is_numeric($id)) { + $d['draft'] = $this->mail_model->get_draft($id, $this->userid); + } + + $this->form_validation->set_rules('name', 'Username', 'required'); + $this->form_validation->set_rules('subject', 'Subject', 'required'); + $this->form_validation->set_rules('message', 'Message', 'required'); + + if (!$this->form_validation->run()) { + $this->load->view('mail/new', $d); + } else { + $send = $this->input->post('send'); + $draft = $this->input->post('draft'); + + $data['name'] = $this->input->post('name'); + $data['subject'] = $this->input->post('subject'); + $data['message'] = $this->input->post('message'); + + if ($send) { + $this->mail_model->send_message($data, $this->userid); + } else { + $this->mail_model->save_draft($data, $this->userid); + } + } + + $this->footer(); } - $this->load->model('mail_model'); - - $this->headers('mail'); - - $data['mail'] = $this->mail_model->get_mail($id, $this->userid); - - $this->load->view('mail/read', $data); - - $this->footer(); - - } - - function sent() - { - $this->headers('mail'); - - $this->load->model('mail_model'); - - $data['mails'] = $this->mail_model->get_all_sent($this->userid); - - $this->load->view('mail/sent', $data); - - $this->footer(); - } - - function sread($id = 0) - { - if (!$id || !is_numeric($id)) + public function del_draft($id = 0) { - $this->load->helper('url'); - redirect('mail/inbox'); + if ($id && is_numeric($id)) { + $this->load->model("mail_model"); + $this->mail_model->delete_draft($id, $this->userid); + } + + $this->load->helper('url'); + redirect('mail/drafts'); } - $this->load->model('mail_model'); + public function drafts() + { + $this->load->model('mail_model'); - $this->headers('mail'); + $this->headers('mail'); - $data['mail'] = $this->mail_model->get_sent($id, $this->userid); + $data['mails'] = $this->mail_model->get_drafts($this->userid); - $this->load->view('mail/sread', $data); + $this->load->view('mail/drafts', $data); - $this->footer(); + $this->footer(); + } - } + public function read($id = 0) + { + if (!$id || !is_numeric($id)) { + $this->load->helper('url'); + redirect('mail/inbox'); + } - function friends() - { - $this->headers('mail'); + $this->load->model('mail_model'); - $this->footer(); - } + $this->headers('mail'); + + $data['mail'] = $this->mail_model->get_mail($id, $this->userid); + + $this->load->view('mail/read', $data); + + $this->footer(); + } + + public function sent() + { + $this->headers('mail'); + + $this->load->model('mail_model'); + + $data['mails'] = $this->mail_model->get_all_sent($this->userid); + + $this->load->view('mail/sent', $data); + + $this->footer(); + } + + public function sread($id = 0) + { + if (!$id || !is_numeric($id)) { + $this->load->helper('url'); + redirect('mail/inbox'); + } + + $this->load->model('mail_model'); + + $this->headers('mail'); + + $data['mail'] = $this->mail_model->get_sent($id, $this->userid); + + $this->load->view('mail/sread', $data); + + $this->footer(); + } + + public function friends() + { + $this->headers('mail'); + + $this->footer(); + } } //nowhitesp - - - - - - - diff --git a/Mourne-CI/application/controllers/news.php b/Mourne-CI/application/controllers/news.php index fc1c9c8..3d61fb2 100755 --- a/Mourne-CI/application/controllers/news.php +++ b/Mourne-CI/application/controllers/news.php @@ -2,67 +2,60 @@ class News extends MO_Controller { - public function index($page = 1) - { - if (!$this->check_login()) return; - - $this->load->model('news_model'); - - $data['admin'] = FALSE; - - if ($this->userlevel > 3) + public function index($page = 1) { - $data['admin'] = TRUE; + if (!$this->check_login()) { + return; + } + + $this->load->model('news_model'); + + $data['admin'] = false; + + if ($this->userlevel > 3) { + $data['admin'] = true; + } + + $data['news'] = $this->news_model->get_news($page); + + $this->headers(); + $this->load->view('news/news', $data); + $this->footer(); } - $data['news'] = $this->news_model->get_news($page); - - $this->headers(); - $this->load->view('news/news', $data); - $this->footer(); - } - - public function add() - { - if ($this->userlevel < 3) show_404(); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('text', 'Text', 'required'); - - if (!$this->form_validation->run()) + public function add() { - - $this->load->helper(array('form', 'url')); + if ($this->userlevel < 3) { + show_404(); + } - $this->headers(); - $this->load->view('news/add'); - $this->footer(); - } - else - { - $this->load->model('news_model'); - - if ($this->news_model->add_news($this->input->post('text'), $this->username)) - { - $this->load->view('news/add_success'); - } - else - { - $this->load->view('db_error'); - } + $this->load->library('form_validation'); + + $this->form_validation->set_rules('text', 'Text', 'required'); + + if (!$this->form_validation->run()) { + $this->load->helper(array('form', 'url')); + + $this->headers(); + $this->load->view('news/add'); + $this->footer(); + } else { + $this->load->model('news_model'); + + if ($this->news_model->add_news($this->input->post('text'), $this->username)) { + $this->load->view('news/add_success'); + } else { + $this->load->view('db_error'); + } + } } - } - - public function delete($nid) - { - if (!$this->userlevel < 3) show_404(); - - - - } - + public function delete($nid) + { + if (!$this->userlevel < 3) { + show_404(); + } + } } //nowhitesp diff --git a/Mourne-CI/application/controllers/user.php b/Mourne-CI/application/controllers/user.php index e8b6159..2b98e01 100755 --- a/Mourne-CI/application/controllers/user.php +++ b/Mourne-CI/application/controllers/user.php @@ -2,138 +2,137 @@ class User extends MO_Controller { + public function __construct() + { + parent::__construct(); + } - function __construct() - { - parent::__construct(); - } + public function login() + { + $this->load->helper(array('form', 'url')); + $this->load->library('form_validation'); - function login() - { - $this->load->helper(array('form', 'url')); - $this->load->library('form_validation'); + //is_unique[users.username] - //is_unique[users.username] - - //xss_validation + //xss_validation - //TODO figure rules out - $this->form_validation->set_rules('username', 'Username', - 'required'); + //TODO figure rules out + $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'); + //password callback -> $this->input->post('username'), after xss filter + $this->form_validation->set_rules( + 'password', + 'Password', + 'required|callback_login_check' + ); - if ($this->form_validation->run() == FALSE) - { - $this->load->view('login/login'); + if ($this->form_validation->run() == false) { + $this->load->view('login/login'); + } else { + $this->load->helper('url'); + redirect('news/index'); + //$this->load->view('login/success'); + } } - else + + public function register() { - $this->load->helper('url'); - redirect('news/index'); - //$this->load->view('login/success'); + $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( + '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) { + $this->load->view('register/register'); + } else { + if ($this->register_write()) { + $this->load->view('register/success'); + } + } } - } - 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('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) + public function logout() { - $this->load->view('register/register'); - } - else - { - if ($this->register_write()) - { - $this->load->view('register/success'); - } - } - } + $this->session->unset_userdata('userid'); - function logout() - { - $this->session->unset_userdata('userid'); + $this->load->helper('url'); + redirect('user/login'); - $this->load->helper('url'); - redirect('user/login'); - - //TODO make it look cool + //TODO make it look cool //$this->load->view('redirect_to_login'); - } - - function register_username_check($attr) - { - $this->load->model('user_model'); - - if ($this->user_model->reg_username_check($attr)) - { - return TRUE; } - else + + public function register_username_check($attr) { - $this->form_validation->set_message('register_username_check', 'Username already exists!'); - return FALSE; + $this->load->model('user_model'); + + if ($this->user_model->reg_username_check($attr)) { + return true; + } else { + $this->form_validation->set_message('register_username_check', 'Username already exists!'); + return false; + } } - } - function register_write() - { - $data['username'] = $this->input->post('username'); - $data['password'] = md5($this->input->post('password')); - $data['email'] = $this->input->post('email'); - - $this->load->model('user_model'); - - return $this->user_model->reg_write($data); - } - - 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)) + public function register_write() { - $this->session->set_userdata('userid', - $this->user_model->get_userid($data['username'])); + $data['username'] = $this->input->post('username'); + $data['password'] = md5($this->input->post('password')); + $data['email'] = $this->input->post('email'); - return TRUE; + $this->load->model('user_model'); + + return $this->user_model->reg_write($data); } - else - { - return FALSE; - } - } - function settings() - { - $this->headers('settings'); + 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']) + ); + + return true; + } else { + return false; + } + } + + public function settings() + { + $this->headers('settings'); - $this->footer(); - } - + $this->footer(); + } }//login class -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/controllers/village.php b/Mourne-CI/application/controllers/village.php index f89fee9..e27b512 100755 --- a/Mourne-CI/application/controllers/village.php +++ b/Mourne-CI/application/controllers/village.php @@ -2,261 +2,246 @@ class Village extends MO_Controller { - function __construct() - { - parent::__construct(); - } - - function index() - { - $this->load->helper('url'); - redirect('village/selected'); - } - - //function for testing, this will be handled when registering, and with npcs - function create_village() - { - $this->load->model('village_model'); - - $this->village_model->create_village($this->userid, $this->username); - } - - function selected() - { - $this->load->model('village_model'); - - $this->headers('village'); - - $build['buildings'] = $this->village_model->get_buildings($this->villageid); - - $event['event'] = $this->_filter_events('next', 'all'); - - $this->load->view('village/next_event', $event); - $this->load->view('village/grid', $build); - $this->footer(); - } - - function map($x = FALSE, $y = FALSE) - { - $this->load->model('map_model'); - $action = $this->input->post('action'); - - if ($action == 'xy') + public function __construct() { - $px = $this->input->post('x'); - $py = $this->input->post('y'); - - if (is_numeric($px) && is_numeric($py)) - { - $x = $px; - $y = $py; - } - - } - elseif ($action == 'name') - { - $name = $this->input->post('name'); - - $rep = array(';', "\"", "'", ',', '(', ')'); - - $name = str_replace($rep, ' ', $name); - - if ($name) - { - $co = $this->map_model->get_village_by_name($name); - - if ($co) - { - $x = $co['X']; - $y = $co['Y']; - } - } + parent::__construct(); } - $this->load->model('map_model'); - - if (!$x && !$y) + public function index() { - $coords = $this->map_model->get_village_coords($this->villageid); - $x = $coords['X']; - $y = $coords['Y']; - } - else - { - if ($x < 7) - $x = 7; - - if ($y < 7) - $y = 7; - - if ($x > 235) - $x = 235; - - if ($y > 235) - $y = 235; + $this->load->helper('url'); + redirect('village/selected'); } - $data['x'] = $x; - $data['y'] = $y; - $data['map'] = $this->map_model->get_map($x, $y); - - $this->headers('village'); - - $this->load->view('village/map', $data); - - $this->footer(); - } - - function units() - { - $this->load->model('unit_model'); - - $data['units'] = $this->unit_model->get_village_units($this->villageid); - - $this->headers('village'); - - $this->load->view('village/units', $data); - - $this->footer(); - } - - function log($action = 'list', $id = 0) - { - if ($action != 'list' && $action != 'view' && $action != 'delete') - $action = 'list'; - - if (!is_numeric($id)) + //function for testing, this will be handled when registering, and with npcs + public function create_village() { - $action = 'list'; - $id = 0; + $this->load->model('village_model'); + + $this->village_model->create_village($this->userid, $this->username); } - $this->load->model('log_model'); - - if ($action == 'list') + public function selected() { - $this->headers('village'); + $this->load->model('village_model'); - $data['logs'] = $this->log_model->get_combat_logs($this->villageid); - $this->load->view('village/log/list', $data); + $this->headers('village'); - $this->footer(); + $build['buildings'] = $this->village_model->get_buildings($this->villageid); + + $event['event'] = $this->_filter_events('next', 'all'); + + $this->load->view('village/next_event', $event); + $this->load->view('village/grid', $build); + $this->footer(); } - if ($action == 'view') + public function map($x = false, $y = false) { - $this->headers('village'); + $this->load->model('map_model'); + $action = $this->input->post('action'); - $data['log'] = $this->log_model->get_combat_log($id, $this->villageid); - $this->load->view('village/log/combat', $data); + if ($action == 'xy') { + $px = $this->input->post('x'); + $py = $this->input->post('y'); - $this->footer(); + if (is_numeric($px) && is_numeric($py)) { + $x = $px; + $y = $py; + } + } elseif ($action == 'name') { + $name = $this->input->post('name'); + + $rep = array(';', "\"", "'", ',', '(', ')'); + + $name = str_replace($rep, ' ', $name); + + if ($name) { + $co = $this->map_model->get_village_by_name($name); + + if ($co) { + $x = $co['X']; + $y = $co['Y']; + } + } + } + + $this->load->model('map_model'); + + if (!$x && !$y) { + $coords = $this->map_model->get_village_coords($this->villageid); + $x = $coords['X']; + $y = $coords['Y']; + } else { + if ($x < 7) { + $x = 7; + } + + if ($y < 7) { + $y = 7; + } + + if ($x > 235) { + $x = 235; + } + + if ($y > 235) { + $y = 235; + } + } + + $data['x'] = $x; + $data['y'] = $y; + $data['map'] = $this->map_model->get_map($x, $y); + + $this->headers('village'); + + $this->load->view('village/map', $data); + + $this->footer(); } - if ($action == 'delete') + public function units() { - $this->log_model->delete_combat_log($id, $this->villageid); + $this->load->model('unit_model'); - $this->load->helper('url'); - redirect('village/log'); - } - } + $data['units'] = $this->unit_model->get_village_units($this->villageid); - function select() - { - $this->load->model('village_model'); - $this->load->library('form_validation'); + $this->headers('village'); - $this->form_validation->set_rules('id', 'ID', 'is_natural|required'); + $this->load->view('village/units', $data); - if (!$this->form_validation->run()) - { - $this->headers('village'); - - $data['villages'] = $this->village_model->get_villages($this->userid); - - $this->load->view('village/select', $data); - - $this->footer(); - } - else - { - $id = $this->input->post('id'); - - $this->village_model->select_village($id, $this->userid); - - $this->load->helper('url'); - redirect('village/selected'); - } - } - - function events() - { - $this->headers('village'); - - $data['event'] = $this->_filter_events('all', 'all'); - - $this->load->view('village/events', $data); - - $this->footer(); - } - - function settings($id = 0) - { - $this->load->model('village_model'); - - if (!is_numeric($id) || !$id) - { - $this->load->heper('url'); - redirect('village/selected'); + $this->footer(); } - $village = $this->village_model->get_village($id); - - if ($village['userid'] != $this->userid) + public function log($action = 'list', $id = 0) { - $this->load->heper('url'); - redirect('village/selected'); + if ($action != 'list' && $action != 'view' && $action != 'delete') { + $action = 'list'; + } + + if (!is_numeric($id)) { + $action = 'list'; + $id = 0; + } + + $this->load->model('log_model'); + + if ($action == 'list') { + $this->headers('village'); + + $data['logs'] = $this->log_model->get_combat_logs($this->villageid); + $this->load->view('village/log/list', $data); + + $this->footer(); + } + + if ($action == 'view') { + $this->headers('village'); + + $data['log'] = $this->log_model->get_combat_log($id, $this->villageid); + $this->load->view('village/log/combat', $data); + + $this->footer(); + } + + if ($action == 'delete') { + $this->log_model->delete_combat_log($id, $this->villageid); + + $this->load->helper('url'); + redirect('village/log'); + } } - $this->load->library('form_validation'); - - $this->form_validation->set_rules('name', 'Name', - 'required|alpha|is_unique[ai_villages.name]'); - - if (!$this->form_validation->run()) + public function select() { - $this->headers('village'); + $this->load->model('village_model'); + $this->load->library('form_validation'); - $data['id'] = $id; - $data['village'] = $village; + $this->form_validation->set_rules('id', 'ID', 'is_natural|required'); - $this->load->view('village/settings', $data); - $this->footer(); + if (!$this->form_validation->run()) { + $this->headers('village'); + + $data['villages'] = $this->village_model->get_villages($this->userid); + + $this->load->view('village/select', $data); + + $this->footer(); + } else { + $id = $this->input->post('id'); + + $this->village_model->select_village($id, $this->userid); + + $this->load->helper('url'); + redirect('village/selected'); + } } - else + + public function events() { - $data['id'] = $id; - $name = $this->input->post('name'); - $data['ai'] = $this->input->post('ai'); + $this->headers('village'); - $data['name'] = ucfirst(strtolower($name)); + $data['event'] = $this->_filter_events('all', 'all'); - $this->village_model->apply_settings($data); + $this->load->view('village/events', $data); + + $this->footer(); + } + + public function settings($id = 0) + { + $this->load->model('village_model'); + + if (!is_numeric($id) || !$id) { + $this->load->heper('url'); + redirect('village/selected'); + } + + $village = $this->village_model->get_village($id); + + 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]' + ); + + if (!$this->form_validation->run()) { + $this->headers('village'); + + $data['id'] = $id; + $data['village'] = $village; + + $this->load->view('village/settings', $data); + $this->footer(); + } else { + $data['id'] = $id; + $name = $this->input->post('name'); + $data['ai'] = $this->input->post('ai'); + + $data['name'] = ucfirst(strtolower($name)); + + $this->village_model->apply_settings($data); - $this->load->helper('url'); - redirect('village/select'); + $this->load->helper('url'); + redirect('village/select'); + } } - } - function event_update() - { - //TODO for ajax, but maybe it will be solved with APE - } - - function list_all() - { - } + public function event_update() + { + //TODO for ajax, but maybe it will be solved with APE + } + public function list_all() + { + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/core/MO_Controller.php b/Mourne-CI/application/core/MO_Controller.php index 90d453a..b9438f6 100755 --- a/Mourne-CI/application/core/MO_Controller.php +++ b/Mourne-CI/application/core/MO_Controller.php @@ -2,429 +2,384 @@ class MO_Controller extends CI_Controller { - public $userid; - public $username; - public $language; - public $userlevel; - public $villageid; - public $village_name; - public $resources; - public $events; - public $building; - public $village_data; - public $weather; + public $userid; + public $username; + public $language; + public $userlevel; + public $villageid; + public $village_name; + public $resources; + public $events; + public $building; + public $village_data; + public $weather; - //hero stuff - public $hero; + //hero stuff + public $hero; - public $new_mail; - public $new_log; - + public $new_mail; + public $new_log; + - function __construct($page = 'village') - { - parent::__construct(); - $this->weather = FALSE; - $this->resources = FALSE; - $this->hero = FALSE; + public function __construct($page = 'village') + { + parent::__construct(); + $this->weather = false; + $this->resources = false; + $this->hero = false; - $this->_manage_session($page); - } + $this->_manage_session($page); + } - public function _manage_session($page) - { - $this->userid = 0; + public function _manage_session($page) + { + $this->userid = 0; - //this should be solved with db! + //this should be solved with db! // if (!$this->session->userdata('language')) // $this->session->set_userdata('language', 'english'); // $this->language = $this->session->userdata('language'); - $this->language = 'english'; + $this->language = 'english'; - if ($this->session->userdata('userid')) - $this->userid = $this->session->userdata('userid'); + if ($this->session->userdata('userid')) { + $this->userid = $this->session->userdata('userid'); + } - $this->load->model('mo_common_model'); + $this->load->model('mo_common_model'); - if ($this->userid) - { - $data = $this->mo_common_model->get_userdata($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']; + $this->userlevel = $data['userlevel']; + $this->username = $data['username']; + $this->new_mail = $data['new_mail']; - if ($page == 'village') - { - $mdata = $this->mo_common_model->get_village_data($this->userid); + if ($page == 'village') { + $mdata = $this->mo_common_model->get_village_data($this->userid); - $this->villageid = $mdata['id']; - $this->villagename = $mdata['name']; - $this->new_log = $mdata['new_log']; + $this->villageid = $mdata['id']; + $this->villagename = $mdata['name']; + $this->new_log = $mdata['new_log']; - $this->village_data = $mdata; - } + $this->village_data = $mdata; + } - if ($page == 'hero') - { - $this->hero = $this->mo_common_model->get_hero_data($this->userid); - } - } - } - - public function check_login() - { - if ($this->userid == 0) - { - $this->load->helper('url'); - redirect('user/login'); + if ($page == 'hero') { + $this->hero = $this->mo_common_model->get_hero_data($this->userid); + } + } } - return TRUE; - } - - public function headers($page = 'village', $slotid = 0) - { - $data['username'] = $this->username; - $data['userid'] = $this->userid; - $data['userlevel'] = $this->userlevel; - $data['newmail'] = $this->new_mail; - $data['page'] = $page; - - if ($page != 'hero') + public function check_login() { - $data['villagename'] = $this->villagename; - $data['newlog'] = $this->new_log; + if ($this->userid == 0) { + $this->load->helper('url'); + redirect('user/login'); + } - if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' || - $page == 'mail') - { - $this->_update(); - } - - //this has to be done like this, since this function will redirect if nothing in the slot - if ($page == 'building') - $this->_get_slot_building($slotid); - - if ($page != 'do') - { - $data['weather'] = $this->weather; - $data['resources'] = $this->_prep_res_js(); - $this->load->view('parts/header', $data); - $this->load->view('menu', $data); - $this->load->view('parts/js_res', $data); - } - - if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' || - $page == 'mail') - { - $res['res'] = $this->resources; - $this->load->view('village/resources', $res); - } - - if ($page == 'mail') - { - $this->load->view('mail/menu'); - } - - if ($page == 'village') - { - $this->load->view('village/menu'); - } - - if ($page == 'building') - { - $data['building'] = $this->building; - $data['slotid'] = $slotid; - - $this->load->view('building/header', $data); - $this->load->view('building/menu', $data); - } - - if ($page == 'do') - { - $this->_update(); - - if ($slotid) - $this->_get_slot_building($slotid); - } + return true; } - elseif ($page == 'hero') + + public function headers($page = 'village', $slotid = 0) { - if (!$this->hero && !$slotid) - { - $this->load->helper('url'); - redirect('hero/create'); - return; - } + $data['username'] = $this->username; + $data['userid'] = $this->userid; + $data['userlevel'] = $this->userlevel; + $data['newmail'] = $this->new_mail; + $data['page'] = $page; - $data['hero'] = $this->hero; - $data['weather'] = FALSE; - $data['resources'] = FALSE; - $this->load->view('parts/header', $data); - $this->load->view('menu', $data); - $this->load->view('hero/menu', $data); + 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') { + $this->_update(); + } + + //this has to be done like this, since this function will redirect if nothing in the slot + if ($page == 'building') { + $this->_get_slot_building($slotid); + } + + if ($page != 'do') { + $data['weather'] = $this->weather; + $data['resources'] = $this->_prep_res_js(); + $this->load->view('parts/header', $data); + $this->load->view('menu', $data); + $this->load->view('parts/js_res', $data); + } + + if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' || + $page == 'mail') { + $res['res'] = $this->resources; + $this->load->view('village/resources', $res); + } + + if ($page == 'mail') { + $this->load->view('mail/menu'); + } + + if ($page == 'village') { + $this->load->view('village/menu'); + } + + if ($page == 'building') { + $data['building'] = $this->building; + $data['slotid'] = $slotid; + + $this->load->view('building/header', $data); + $this->load->view('building/menu', $data); + } + + if ($page == 'do') { + $this->_update(); + + if ($slotid) { + $this->_get_slot_building($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; + $this->load->view('parts/header', $data); + $this->load->view('menu', $data); + $this->load->view('hero/menu', $data); + } } - } - public function _get_slot_building($slotid = 0) - { - if (!$slotid) - return; + public function _get_slot_building($slotid = 0) + { + if (!$slotid) { + return; + } - if ($this->building) - return; + if ($this->building) { + return; + } - $this->load->model('building_model'); - $this->building = $this->building_model->get_slot_building($slotid, $this->villageid); + $this->load->model('building_model'); + $this->building = $this->building_model->get_slot_building($slotid, $this->villageid); - //this is commented out, because get_slot_building cannot return FALSE lol + //this is commented out, because get_slot_building cannot return FALSE lol // if (!$this->building) // { // $this->load->helper('url'); // redirect('village/selected'); //} - } - - public function _get_resources() - { - if ($this->resources) - return; - - $this->load->model('resource_model'); - $this->resources = $this->resource_model->get_resources($this->villageid); - } - - public function _update() - { - $this->load->model('event_model'); - - 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); - - $this->resources = $data['resources']; - $this->events = $data['events']; - $this->weather = $data['weather']; - } - - public function footer() - { - $this->load->view('parts/footer'); - } - - /* - filter events, based on type and filter, and order it ASC - type -> 'next', 'type', 'all' - if type == 'type' you have to provide an event type - filter -> 'all', 'slot' - if filter == 'slot' you have to provide slotid - next -> TRUE/FALSE - only return the next event, this is here, so every type can be asked to return the next one - 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) - { - //means no events - if (!$this->events) - return FALSE; - - $data = FALSE; - - if ($type == 'all') - { - if ($filter == 'slot') - { - foreach ($this->events as $row) - { - if ($row['slotid'] == $slotid) - { - $data[] = $row; - } - } - } - else - { - $data = $this->events; - } } - if ($type == 'type') + public function _get_resources() { - 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) - { - $data[] = $row; - } - } - } + if ($this->resources) { + return; + } + + $this->load->model('resource_model'); + $this->resources = $this->resource_model->get_resources($this->villageid); } - if ($type == 'next') + public function _update() { - if ($filter == 'all') - { - $last_end = 99999999999; - $smallest = FALSE; - foreach ($this->events as $row) - { - if ($row['end'] < $last_end) - { - $last_end = $row['end']; - $smallest = $row; - } - } + $this->load->model('event_model'); - return $smallest; - } - else - { - $last_end = 99999999999; - $smallest = FALSE; - foreach ($this->events as $row) - { - if ($row['end'] < $last_end && $row['slotid'] == $slotid) - { - $last_end = $row['end']; - $smallest = $row; - } - } + if ($this->resources || $this->events || $this->weather) { + return; + } - return $smallest; - } + //event model returns resources, and events, and weather + $data = $this->event_model->update($this->village_data, true); + + $this->resources = $data['resources']; + $this->events = $data['events']; + $this->weather = $data['weather']; } - //order it - if ($data) + public function footer() { - $last_end = 99999999999; - $last['id'] = FALSE; - $smallest = FALSE; - - 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']) - { - $smallest = $row; - } - } - - $ret[] = $smallest; - $last_end = $smallest['end']; - $last = $smallest; - } - - if (!$next) - return $ret; - else - return $ret[0]; + $this->load->view('parts/footer'); } - return FALSE; - } + /* + filter events, based on type and filter, and order it ASC + type -> 'next', 'type', 'all' + if type == 'type' you have to provide an event type + filter -> 'all', 'slot' + if filter == 'slot' you have to provide slotid + next -> TRUE/FALSE + only return the next event, this is here, so every type can be asked to return the next one + this is primarily here, so when events like EVENT_BUILD needed, since there aren't going to be 2 + */ - function _prep_res_js() - { - if (!$this->resources) - return FALSE; - - $res = $this->resources; - - //determining which have the lowest rate - $a[] = $res['food']; - $a[] = $res['wood']; - $a[] = $res['stone']; - $a[] = $res['iron']; - $a[] = $res['mana']; - - $last = $a[0]; - $index = 0; - - for ($i = 0; $i < 5; $i++) + public function _filter_events($type, $filter, $slotid = 0, $ev_type = 0, $next = false) { - if ($a[$i] < $last) - { - $last = $a[$i]; - $index = $i; - } + //means no events + if (!$this->events) { + return false; + } + + $data = false; + + if ($type == 'all') { + if ($filter == 'slot') { + foreach ($this->events as $row) { + if ($row['slotid'] == $slotid) { + $data[] = $row; + } + } + } else { + $data = $this->events; + } + } + + 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) { + $data[] = $row; + } + } + } + } + + if ($type == 'next') { + if ($filter == 'all') { + $last_end = 99999999999; + $smallest = false; + foreach ($this->events as $row) { + if ($row['end'] < $last_end) { + $last_end = $row['end']; + $smallest = $row; + } + } + + return $smallest; + } else { + $last_end = 99999999999; + $smallest = false; + foreach ($this->events as $row) { + if ($row['end'] < $last_end && $row['slotid'] == $slotid) { + $last_end = $row['end']; + $smallest = $row; + } + } + + return $smallest; + } + } + + //order it + if ($data) { + $last_end = 99999999999; + $last['id'] = false; + $smallest = false; + + 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']) { + $smallest = $row; + } + } + + $ret[] = $smallest; + $last_end = $smallest['end']; + $last = $smallest; + } + + if (!$next) { + return $ret; + } else { + return $ret[0]; + } + } + + return false; } - //comberting back numerical index - switch ($index) + public function _prep_res_js() { + if (!$this->resources) { + return false; + } + + $res = $this->resources; + + //determining which have the lowest rate + $a[] = $res['food']; + $a[] = $res['wood']; + $a[] = $res['stone']; + $a[] = $res['iron']; + $a[] = $res['mana']; + + $last = $a[0]; + $index = 0; + + for ($i = 0; $i < 5; $i++) { + if ($a[$i] < $last) { + $last = $a[$i]; + $index = $i; + } + } + + //comberting back numerical index + switch ($index) { case 0: - $s_index = 'food'; - break; + $s_index = 'food'; + break; case 1: - $s_index = 'wood'; - break; + $s_index = 'wood'; + break; case 2: - $s_index = 'stone'; - break; + $s_index = 'stone'; + break; case 3: - $s_index = 'iron'; - break; + $s_index = 'iron'; + break; case 4: - $s_index = 'mana'; - break; + $s_index = 'mana'; + break; default: - $s_index = 'food'; - break; + $s_index = 'food'; + break; } - //calculating the rate it brings 1 resource - $num_tick = 0.1; - $rate = 'rate_' . $s_index; + //calculating the rate it brings 1 resource + $num_tick = 0.1; + $rate = 'rate_' . $s_index; - while (TRUE) - { - if (($res[$rate] * $num_tick) > 1) - break; + while (true) { + if (($res[$rate] * $num_tick) > 1) { + break; + } - $num_tick += 0.1; + $num_tick += 0.1; + } + + $res['rate_food'] *= $num_tick; + $res['rate_wood'] *= $num_tick; + $res['rate_stone'] *= $num_tick; + $res['rate_iron'] *= $num_tick; + $res['rate_mana'] *= $num_tick; + + $res['timer_tick'] = (1000 * $num_tick); + + return $res; } - - $res['rate_food'] *= $num_tick; - $res['rate_wood'] *= $num_tick; - $res['rate_stone'] *= $num_tick; - $res['rate_iron'] *= $num_tick; - $res['rate_mana'] *= $num_tick; - - $res['timer_tick'] = (1000 * $num_tick); - - return $res; - } - }//MO_Controller //nowhitesp - - - - - - - - - - diff --git a/Mourne-CI/application/core/MO_Model.php b/Mourne-CI/application/core/MO_Model.php index da7ff99..ce76ead 100755 --- a/Mourne-CI/application/core/MO_Model.php +++ b/Mourne-CI/application/core/MO_Model.php @@ -2,86 +2,88 @@ class MO_Model extends CI_Model { - const EVENT_BUILD = 0; - const EVENT_UPGRADE = 1; - const EVENT_CREATE = 2; - const EVENT_SPELL_END = 3; - const EVENT_RESEARCH_END = 4; - const EVENT_ATTACK = 5; + const EVENT_BUILD = 0; + const EVENT_UPGRADE = 1; + const EVENT_CREATE = 2; + const EVENT_SPELL_END = 3; + const EVENT_RESEARCH_END = 4; + const EVENT_ATTACK = 5; - const ATTACK_UP = 1; - const ATTACK_LEFT = 2; - const ATTACK_RIGHT = 3; - const ATTACK_DOWN = 4; + const ATTACK_UP = 1; + const ATTACK_LEFT = 2; + const ATTACK_RIGHT = 3; + const ATTACK_DOWN = 4; - const TOTAL_BUILDINGS = 209; - const BUILDING_CULOMN = 19; - const BUILDING_ROW = 11; + const TOTAL_BUILDINGS = 209; + const BUILDING_CULOMN = 19; + const BUILDING_ROW = 11; - //hero - const INVENTORY_MAX = 100; //0-99! + //hero + const INVENTORY_MAX = 100; //0-99! //Resource manipulations - public $resources; - public $resources_changed; - public $modifiers_changed; - public $score; + public $resources; + public $resources_changed; + public $modifiers_changed; + public $score; - //unit manipulations - public $unitq_initialized; - public $unitq_village_units; //stores units which are in the db - public $unitq_changes; //the changes - public $unitq_units; //the changed units data + //unit manipulations + public $unitq_initialized; + public $unitq_village_units; //stores units which are in the db + public $unitq_changes; //the changes + public $unitq_units; //the changed units data - public $villageid; - public $userid; + public $villageid; + public $userid; - //hero - public $hero; - public $hero_stat_changed; - public $hero_exp_changed; - public $hero_hpmp_changed; + //hero + public $hero; + public $hero_stat_changed; + public $hero_exp_changed; + public $hero_hpmp_changed; - function __construct() - { - parent::__construct(); - $this->resources = FALSE; - $this->resources_changed = FALSE; - $this->modifiers_changed = FALSE; - $this->score = 0; + public function __construct() + { + parent::__construct(); + $this->resources = false; + $this->resources_changed = false; + $this->modifiers_changed = false; + $this->score = 0; - $this->unitq_initialized = FALSE; - $this->unitq_village_units = FALSE; - $this->unitq_changes = FALSE; - $this->unitq_units = FALSE; + $this->unitq_initialized = false; + $this->unitq_village_units = false; + $this->unitq_changes = false; + $this->unitq_units = false; - $this->villageid = FALSE; - $this->userid = FALSE; + $this->villageid = false; + $this->userid = false; - $this->hero = FALSE; - $this->hero_stat_changed = FALSE; - $this->hero_exp_changed = FALSE; - $this->hero_hpmp_changed = FALSE; - } + $this->hero = false; + $this->hero_stat_changed = false; + $this->hero_exp_changed = false; + $this->hero_hpmp_changed = false; + } -/* - This doesn't work with codeigniter, gives a bunch of errors. - function __destruct() - { - $this->write_resources(); - } -*/ - //event - function add_event($data) - { - if (!isset($data['data1'])) - $data['data1'] = 0; - if (!isset($data['data2'])) - $data['data2'] = 0; + /* + This doesn't work with codeigniter, gives a bunch of errors. + function __destruct() + { + $this->write_resources(); + } + */ + //event + public function add_event($data) + { + if (!isset($data['data1'])) { + $data['data1'] = 0; + } + if (!isset($data['data2'])) { + $data['data2'] = 0; + } - $end = (time() + $data['time']); + $end = (time() + $data['time']); - $sql = "INSERT INTO events + $sql = "INSERT INTO events VALUES(default, '" . $data['villageid'] . "', '" . $data['slotid'] . "', @@ -90,407 +92,425 @@ class MO_Model extends CI_Model '" . $data['data1'] . "', '" . $data['data2'] . "')"; - $this->db->query($sql); - } - - //event end - - //resources - function check_resources($res, $data) - { - if ($res['food'] >= $data['cost_food'] && - $res['wood'] >= $data['cost_wood'] && - $res['stone'] >= $data['cost_stone'] && - $res['iron'] >= $data['cost_iron'] && - $res['mana'] >= $data['cost_mana']) - return TRUE; - - return FALSE; - } - - function set_resources($res) - { - $this->resources = $res; - } - - //adds modifiers from the building - function add_modifiers($id, $villageid, $type = 'building', $num = 1, $noquery = FALSE) - { - if (!$this->resources) - $this->get_resources($villageid); - - if (!$noquery) - { - if ($type == 'building') - $sql = "SELECT * FROM buildings WHERE id='$id'"; - - if ($type == 'unit') - $sql = "SELECT * FROM units WHERE id='$id'"; - - if ($type == 'assignment') - $sql = "SELECT * FROM assignments WHERE id='$id'"; - - if ($type == 'spell') - $sql = "SELECT * FROM spells WHERE id='$id'"; - - if ($type == 'technology') - $sql = "SELECT * FROM technologies WHERE id='$id'"; - - if ($type == 'weather') - $sql = "SELECT * FROM weathers WHERE id='$id'"; - - $q = $this->db->query($sql); - $data = $q->row_array(); - } - else - { - $data = $id; + $this->db->query($sql); } - //if everything is 0 don't do anything - if ($type == 'building' || $type == 'assignment' || $type == 'spell' || - $type == 'technology') - if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || - $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_rate_food'] || - $data['mod_rate_wood'] || $data['mod_rate_stone'] || $data['mod_rate_iron'] || - $data['mod_rate_mana'] || $data['mod_percent_food'] || $data['mod_percent_wood'] || - $data['mod_percent_stone'] || $data['mod_percent_iron'] || $data['mod_percent_mana'])) - return; + //event end - if ($type == 'weather') - if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || - $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_percent_food'] || - $data['mod_percent_wood'] || $data['mod_percent_stone'] || $data['mod_percent_iron'] || - $data['mod_percent_mana'])) - return; - - if ($type == 'unit') - if (!($data['mod_rate_food'] || $data['mod_rate_wood'] || - $data['mod_rate_stone'] || $data['mod_rate_iron'] || - $data['mod_rate_mana'])) - return; - - //this is sure at this point - $this->modifiers_changed = TRUE; - $res = $this->resources; - - - if ($type == 'building' || $type == 'assignment' || $type == 'spell' || $type == 'technology') + //resources + public function check_resources($res, $data) { - $res['max_food'] += ($data['mod_max_food'] * $num); - $res['max_wood'] += ($data['mod_max_wood'] * $num); - $res['max_stone'] += ($data['mod_max_stone'] * $num); - $res['max_iron'] += ($data['mod_max_iron'] * $num); - $res['max_mana'] += ($data['mod_max_mana'] * $num); + if ($res['food'] >= $data['cost_food'] && + $res['wood'] >= $data['cost_wood'] && + $res['stone'] >= $data['cost_stone'] && + $res['iron'] >= $data['cost_iron'] && + $res['mana'] >= $data['cost_mana']) { + return true; + } - $res['rate_nm_food'] += ($data['mod_rate_food'] * $num); - $res['rate_nm_wood'] += ($data['mod_rate_wood'] * $num); - $res['rate_nm_stone'] += ($data['mod_rate_stone'] * $num); - $res['rate_nm_iron'] += ($data['mod_rate_iron'] * $num); - $res['rate_nm_mana'] += ($data['mod_rate_mana'] * $num); - - $res['percent_food'] += ($data['mod_percent_food'] * $num); - $res['percent_wood'] += ($data['mod_percent_wood'] * $num); - $res['percent_stone'] += ($data['mod_percent_stone'] * $num); - $res['percent_iron'] += ($data['mod_percent_iron'] * $num); - $res['percent_mana'] += ($data['mod_percent_mana'] * $num); + return false; } - if ($type == 'unit') + public function set_resources($res) { - $res['rate_nm_food'] += ($data['mod_rate_food'] * $num); - $res['rate_nm_wood'] += ($data['mod_rate_wood'] * $num); - $res['rate_nm_stone'] += ($data['mod_rate_stone'] * $num); - $res['rate_nm_iron'] += ($data['mod_rate_iron'] * $num); - $res['rate_nm_mana'] += ($data['mod_rate_mana'] * $num); + $this->resources = $res; } - //has to be done this way, because this doesn't have flat rate modifiers - //so adding it to spells (etc) above could error out - if ($type == 'weather') + //adds modifiers from the building + public function add_modifiers($id, $villageid, $type = 'building', $num = 1, $noquery = false) { - $res['max_food'] += ($data['mod_max_food'] * $num); - $res['max_wood'] += ($data['mod_max_wood'] * $num); - $res['max_stone'] += ($data['mod_max_stone'] * $num); - $res['max_iron'] += ($data['mod_max_iron'] * $num); - $res['max_mana'] += ($data['mod_max_mana'] * $num); + if (!$this->resources) { + $this->get_resources($villageid); + } - $res['percent_food'] += ($data['mod_percent_food'] * $num); - $res['percent_wood'] += ($data['mod_percent_wood'] * $num); - $res['percent_stone'] += ($data['mod_percent_stone'] * $num); - $res['percent_iron'] += ($data['mod_percent_iron'] * $num); - $res['percent_mana'] += ($data['mod_percent_mana'] * $num); + if (!$noquery) { + if ($type == 'building') { + $sql = "SELECT * FROM buildings WHERE id='$id'"; + } + + if ($type == 'unit') { + $sql = "SELECT * FROM units WHERE id='$id'"; + } + + if ($type == 'assignment') { + $sql = "SELECT * FROM assignments WHERE id='$id'"; + } + + if ($type == 'spell') { + $sql = "SELECT * FROM spells WHERE id='$id'"; + } + + if ($type == 'technology') { + $sql = "SELECT * FROM technologies WHERE id='$id'"; + } + + if ($type == 'weather') { + $sql = "SELECT * FROM weathers WHERE id='$id'"; + } + + $q = $this->db->query($sql); + $data = $q->row_array(); + } else { + $data = $id; + } + + //if everything is 0 don't do anything + if ($type == 'building' || $type == 'assignment' || $type == 'spell' || + $type == 'technology') { + if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || + $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_rate_food'] || + $data['mod_rate_wood'] || $data['mod_rate_stone'] || $data['mod_rate_iron'] || + $data['mod_rate_mana'] || $data['mod_percent_food'] || $data['mod_percent_wood'] || + $data['mod_percent_stone'] || $data['mod_percent_iron'] || $data['mod_percent_mana'])) { + return; + } + } + + if ($type == 'weather') { + if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || + $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_percent_food'] || + $data['mod_percent_wood'] || $data['mod_percent_stone'] || $data['mod_percent_iron'] || + $data['mod_percent_mana'])) { + return; + } + } + + if ($type == 'unit') { + if (!($data['mod_rate_food'] || $data['mod_rate_wood'] || + $data['mod_rate_stone'] || $data['mod_rate_iron'] || + $data['mod_rate_mana'])) { + return; + } + } + + //this is sure at this point + $this->modifiers_changed = true; + $res = $this->resources; + + + if ($type == 'building' || $type == 'assignment' || $type == 'spell' || $type == 'technology') { + $res['max_food'] += ($data['mod_max_food'] * $num); + $res['max_wood'] += ($data['mod_max_wood'] * $num); + $res['max_stone'] += ($data['mod_max_stone'] * $num); + $res['max_iron'] += ($data['mod_max_iron'] * $num); + $res['max_mana'] += ($data['mod_max_mana'] * $num); + + $res['rate_nm_food'] += ($data['mod_rate_food'] * $num); + $res['rate_nm_wood'] += ($data['mod_rate_wood'] * $num); + $res['rate_nm_stone'] += ($data['mod_rate_stone'] * $num); + $res['rate_nm_iron'] += ($data['mod_rate_iron'] * $num); + $res['rate_nm_mana'] += ($data['mod_rate_mana'] * $num); + + $res['percent_food'] += ($data['mod_percent_food'] * $num); + $res['percent_wood'] += ($data['mod_percent_wood'] * $num); + $res['percent_stone'] += ($data['mod_percent_stone'] * $num); + $res['percent_iron'] += ($data['mod_percent_iron'] * $num); + $res['percent_mana'] += ($data['mod_percent_mana'] * $num); + } + + if ($type == 'unit') { + $res['rate_nm_food'] += ($data['mod_rate_food'] * $num); + $res['rate_nm_wood'] += ($data['mod_rate_wood'] * $num); + $res['rate_nm_stone'] += ($data['mod_rate_stone'] * $num); + $res['rate_nm_iron'] += ($data['mod_rate_iron'] * $num); + $res['rate_nm_mana'] += ($data['mod_rate_mana'] * $num); + } + + //has to be done this way, because this doesn't have flat rate modifiers + //so adding it to spells (etc) above could error out + if ($type == 'weather') { + $res['max_food'] += ($data['mod_max_food'] * $num); + $res['max_wood'] += ($data['mod_max_wood'] * $num); + $res['max_stone'] += ($data['mod_max_stone'] * $num); + $res['max_iron'] += ($data['mod_max_iron'] * $num); + $res['max_mana'] += ($data['mod_max_mana'] * $num); + + $res['percent_food'] += ($data['mod_percent_food'] * $num); + $res['percent_wood'] += ($data['mod_percent_wood'] * $num); + $res['percent_stone'] += ($data['mod_percent_stone'] * $num); + $res['percent_iron'] += ($data['mod_percent_iron'] * $num); + $res['percent_mana'] += ($data['mod_percent_mana'] * $num); + } + + $res['rate_food'] = ($res['rate_nm_food'] * ($res['percent_food'] / 100)); + $res['rate_wood'] = ($res['rate_nm_wood'] * ($res['percent_wood'] / 100)); + $res['rate_stone'] = ($res['rate_nm_stone'] * ($res['percent_stone'] / 100)); + $res['rate_iron'] = ($res['rate_nm_iron'] * ($res['percent_iron'] / 100)); + $res['rate_mana'] = ($res['rate_nm_mana'] * ($res['percent_mana'] / 100)); + + $this->resources = $res; + + //add score + if ($type == 'building' || $type == 'unit' || $type == 'technology') { + $this->score += ($data['score'] * $num); + } } - $res['rate_food'] = ($res['rate_nm_food'] * ($res['percent_food'] / 100)); - $res['rate_wood'] = ($res['rate_nm_wood'] * ($res['percent_wood'] / 100)); - $res['rate_stone'] = ($res['rate_nm_stone'] * ($res['percent_stone'] / 100)); - $res['rate_iron'] = ($res['rate_nm_iron'] * ($res['percent_iron'] / 100)); - $res['rate_mana'] = ($res['rate_nm_mana'] * ($res['percent_mana'] / 100)); - - $this->resources = $res; - - //add score - if ($type == 'building' || $type == 'unit' || $type == 'technology') + public function substract_modifiers($id, $villageid, $type = 'building', $num = 1, $noquery = false) { - $this->score += ($data['score'] * $num); - } - } + if (!$this->resources) { + $this->get_resources($villageid); + } - function substract_modifiers($id, $villageid, $type = 'building', $num = 1, $noquery = FALSE) - { - if (!$this->resources) - $this->get_resources($villageid); + if (!$noquery) { + if ($type == 'building') { + $sql = "SELECT * FROM buildings WHERE id='$id'"; + } - if (!$noquery) - { - if ($type == 'building') - $sql = "SELECT * FROM buildings WHERE id='$id'"; + if ($type == 'unit') { + $sql = "SELECT * FROM units WHERE id='$id'"; + } - if ($type == 'unit') - $sql = "SELECT * FROM units WHERE id='$id'"; + if ($type == 'assignment') { + $sql = "SELECT * FROM assignments WHERE id='$id'"; + } - if ($type == 'assignment') - $sql = "SELECT * FROM assignments WHERE id='$id'"; + if ($type == 'spell') { + $sql = "SELECT * FROM spells WHERE id='$id'"; + } - if ($type == 'spell') - $sql = "SELECT * FROM spells WHERE id='$id'"; + if ($type == 'technology') { + $sql = "SELECT * FROM technologies WHERE id='$id'"; + } - if ($type == 'technology') - $sql = "SELECT * FROM technologies WHERE id='$id'"; + if ($type == 'weather') { + $sql = "SELECT * FROM weathers WHERE id='$id'"; + } - if ($type == 'weather') - $sql = "SELECT * FROM weathers WHERE id='$id'"; + $q = $this->db->query($sql); + $data = $q->row_array(); + } else { + $data = $id; + } - $q = $this->db->query($sql); - $data = $q->row_array(); - } - else - { - $data = $id; + //if everything is 0 don't do anything + if ($type == 'building' || $type == 'assignment' || $type == 'spell' || + $type == 'technology') { + if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || + $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_rate_food'] || + $data['mod_rate_wood'] || $data['mod_rate_stone'] || $data['mod_rate_iron'] || + $data['mod_rate_mana'] || $data['mod_percent_food'] || $data['mod_percent_wood'] || + $data['mod_percent_stone'] || $data['mod_percent_iron'] || $data['mod_percent_mana'])) { + return; + } + } + + if ($type == 'weather') { + if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || + $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_percent_food'] || + $data['mod_percent_wood'] || $data['mod_percent_stone'] || $data['mod_percent_iron'] || + $data['mod_percent_mana'])) { + return; + } + } + + if ($type == 'unit') { + if (!($data['mod_rate_food'] || $data['mod_rate_wood'] || + $data['mod_rate_stone'] || $data['mod_rate_iron'] || + $data['mod_rate_mana'])) { + return; + } + } + + //this is sure at this point + $this->modifiers_changed = true; + $res = $this->resources; + + if ($type == 'building' || $type == 'assignment' || $type == 'spell' || $type == 'technology') { + $res['max_food'] -= ($data['mod_max_food'] * $num); + $res['max_wood'] -= ($data['mod_max_wood'] * $num); + $res['max_stone'] -= ($data['mod_max_stone'] * $num); + $res['max_iron'] -= ($data['mod_max_iron'] * $num); + $res['max_mana'] -= ($data['mod_max_mana'] * $num); + + $res['rate_nm_food'] -= ($data['mod_rate_food'] * $num); + $res['rate_nm_wood'] -= ($data['mod_rate_wood'] * $num); + $res['rate_nm_stone'] -= ($data['mod_rate_stone'] * $num); + $res['rate_nm_iron'] -= ($data['mod_rate_iron'] * $num); + $res['rate_nm_mana'] -= ($data['mod_rate_mana'] * $num); + + $res['percent_food'] -= ($data['mod_percent_food'] * $num); + $res['percent_wood'] -= ($data['mod_percent_wood'] * $num); + $res['percent_stone'] -= ($data['mod_percent_stone'] * $num); + $res['percent_iron'] -= ($data['mod_percent_iron'] * $num); + $res['percent_mana'] -= ($data['mod_percent_mana'] * $num); + } + + if ($type == 'unit') { + $res['rate_nm_food'] -= ($data['mod_rate_food'] * $num); + $res['rate_nm_wood'] -= ($data['mod_rate_wood'] * $num); + $res['rate_nm_stone'] -= ($data['mod_rate_stone'] * $num); + $res['rate_nm_iron'] -= ($data['mod_rate_iron'] * $num); + $res['rate_nm_mana'] -= ($data['mod_rate_mana'] * $num); + } + + //has to be done this way, because this doesn't have flat rate modifiers + //so adding it to spells (etc) above could error out + if ($type == 'weather') { + $res['max_food'] -= ($data['mod_max_food'] * $num); + $res['max_wood'] -= ($data['mod_max_wood'] * $num); + $res['max_stone'] -= ($data['mod_max_stone'] * $num); + $res['max_iron'] -= ($data['mod_max_iron'] * $num); + $res['max_mana'] -= ($data['mod_max_mana'] * $num); + + $res['percent_food'] -= ($data['mod_percent_food'] * $num); + $res['percent_wood'] -= ($data['mod_percent_wood'] * $num); + $res['percent_stone'] -= ($data['mod_percent_stone'] * $num); + $res['percent_iron'] -= ($data['mod_percent_iron'] * $num); + $res['percent_mana'] -= ($data['mod_percent_mana'] * $num); + } + + $res['rate_food'] = ($res['rate_nm_food'] * ($res['percent_food'] / 100)); + $res['rate_wood'] = ($res['rate_nm_wood'] * ($res['percent_wood'] / 100)); + $res['rate_stone'] = ($res['rate_nm_stone'] * ($res['percent_stone'] / 100)); + $res['rate_iron'] = ($res['rate_nm_iron'] * ($res['percent_iron'] / 100)); + $res['rate_mana'] = ($res['rate_nm_mana'] * ($res['percent_mana'] / 100)); + + $this->resources = $res; + + //add score + if ($type == 'building' || $type == 'unit' || $type == 'technology') { + $this->score -= ($data['score'] * $num); + } } - //if everything is 0 don't do anything - if ($type == 'building' || $type == 'assignment' || $type == 'spell' || - $type == 'technology') - if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || - $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_rate_food'] || - $data['mod_rate_wood'] || $data['mod_rate_stone'] || $data['mod_rate_iron'] || - $data['mod_rate_mana'] || $data['mod_percent_food'] || $data['mod_percent_wood'] || - $data['mod_percent_stone'] || $data['mod_percent_iron'] || $data['mod_percent_mana'])) - return; - - if ($type == 'weather') - if (!($data['mod_max_food'] || $data['mod_max_wood'] || $data['mod_max_stone'] || - $data['mod_max_iron'] || $data['mod_max_mana'] || $data['mod_percent_food'] || - $data['mod_percent_wood'] || $data['mod_percent_stone'] || $data['mod_percent_iron'] || - $data['mod_percent_mana'])) - return; - - if ($type == 'unit') - if (!($data['mod_rate_food'] || $data['mod_rate_wood'] || - $data['mod_rate_stone'] || $data['mod_rate_iron'] || - $data['mod_rate_mana'])) - return; - - //this is sure at this point - $this->modifiers_changed = TRUE; - $res = $this->resources; - - if ($type == 'building' || $type == 'assignment' || $type == 'spell' || $type == 'technology') + //substractes resources, $data has to have cost_* fields! + public function substract_resources($data, $villageid = 0, $num = 1) { - $res['max_food'] -= ($data['mod_max_food'] * $num); - $res['max_wood'] -= ($data['mod_max_wood'] * $num); - $res['max_stone'] -= ($data['mod_max_stone'] * $num); - $res['max_iron'] -= ($data['mod_max_iron'] * $num); - $res['max_mana'] -= ($data['mod_max_mana'] * $num); + //can only happen if not called from events, but shouldn't + if (!$this->resources) { + $this->get_resources($villageid); + $this->update_resources(); + //$this->_create_sql_debug('sub_resources got called wo $this->resources!'); + } - $res['rate_nm_food'] -= ($data['mod_rate_food'] * $num); - $res['rate_nm_wood'] -= ($data['mod_rate_wood'] * $num); - $res['rate_nm_stone'] -= ($data['mod_rate_stone'] * $num); - $res['rate_nm_iron'] -= ($data['mod_rate_iron'] * $num); - $res['rate_nm_mana'] -= ($data['mod_rate_mana'] * $num); + $res = $this->resources; - $res['percent_food'] -= ($data['mod_percent_food'] * $num); - $res['percent_wood'] -= ($data['mod_percent_wood'] * $num); - $res['percent_stone'] -= ($data['mod_percent_stone'] * $num); - $res['percent_iron'] -= ($data['mod_percent_iron'] * $num); - $res['percent_mana'] -= ($data['mod_percent_mana'] * $num); + $res['food'] -= ($data['cost_food'] * $num); + $res['wood'] -= ($data['cost_wood'] * $num); + $res['stone'] -= ($data['cost_stone'] * $num); + $res['iron'] -= ($data['cost_iron'] * $num); + $res['mana'] -= ($data['cost_mana'] * $num); + + if ($res['food'] < 0 || $res['wood'] < 0 || $res['stone'] < 0 || + $res['iron'] < 0 || $res['mana'] < 0) { + return false; + } + + $this->resources = $res; + $this->resources_changed = true; + + return true; } - if ($type == 'unit') + /* + //probably nothing uses it TODO remove + function set_resources($data, $villageid) + { + $sql = "UPDATE resources + SET food='" . $data['food'] . "', + wood='" . $data['wood'] . "', + stone='" . $data['stone'] . "', + iron='" . $data['iron'] . "', + mana='" . $data['mana'] . "' + WHERE villageid='$villageid'"; + + $this->db->query($sql); + } + */ + //despite the name it updates the resources first, then returns them. + public function get_resources($vid) { - $res['rate_nm_food'] -= ($data['mod_rate_food'] * $num); - $res['rate_nm_wood'] -= ($data['mod_rate_wood'] * $num); - $res['rate_nm_stone'] -= ($data['mod_rate_stone'] * $num); - $res['rate_nm_iron'] -= ($data['mod_rate_iron'] * $num); - $res['rate_nm_mana'] -= ($data['mod_rate_mana'] * $num); + //to not break existing functionality TODO remove returning + if ($this->resources) { + return $this->resources; + } + + //getting resources + $sql = "SELECT * FROM resources WHERE villageid='$vid'"; + $q = $this->db->query($sql); + + $this->resources = $q->row_array(); + + //to not break existing functions, should be removed + return $this->resources; } - //has to be done this way, because this doesn't have flat rate modifiers - //so adding it to spells (etc) above could error out - if ($type == 'weather') + public function update_resources($time = false) { - $res['max_food'] -= ($data['mod_max_food'] * $num); - $res['max_wood'] -= ($data['mod_max_wood'] * $num); - $res['max_stone'] -= ($data['mod_max_stone'] * $num); - $res['max_iron'] -= ($data['mod_max_iron'] * $num); - $res['max_mana'] -= ($data['mod_max_mana'] * $num); + if ($time === false) { + $time = time(); + } - $res['percent_food'] -= ($data['mod_percent_food'] * $num); - $res['percent_wood'] -= ($data['mod_percent_wood'] * $num); - $res['percent_stone'] -= ($data['mod_percent_stone'] * $num); - $res['percent_iron'] -= ($data['mod_percent_iron'] * $num); - $res['percent_mana'] -= ($data['mod_percent_mana'] * $num); + $res = $this->resources; + + //if already at maximum + //we still have to update last_time, because it will screw up things. + if (($res['food'] == $res['max_food']) && + ($res['wood'] == $res['max_wood']) && + ($res['stone'] == $res['max_stone']) && + ($res['iron'] == $res['max_iron']) && + ($res['mana'] == $res['max_mana'])) { + //do not set $this->resources_changed here, so write only updates the time in the db + $this->resources['last_updated'] = $time; + return; + } + + $ticks = ($time - $res['last_updated']); + + //if more than one event end at the same time this could happen + if (!$ticks) { + return; + } + + $res['food'] += ($res['rate_food'] * $ticks); + $res['wood'] += ($res['rate_wood'] * $ticks); + $res['stone'] += ($res['rate_stone'] * $ticks); + $res['iron'] += ($res['rate_iron'] * $ticks); + $res['mana'] += ($res['rate_mana'] * $ticks); + + //check if over the limit + if ($res['food'] > $res['max_food']) { + $res['food'] = $res['max_food']; + } + if ($res['wood'] > $res['max_wood']) { + $res['wood'] = $res['max_wood']; + } + if ($res['stone'] > $res['max_stone']) { + $res['stone'] = $res['max_stone']; + } + if ($res['iron'] > $res['max_iron']) { + $res['iron'] = $res['max_iron']; + } + if ($res['mana'] > $res['max_mana']) { + $res['mana'] = $res['max_mana']; + } + + $res['last_updated'] = $time; + + //update the db + $this->resources_changed = true; + $this->resources = $res; } - $res['rate_food'] = ($res['rate_nm_food'] * ($res['percent_food'] / 100)); - $res['rate_wood'] = ($res['rate_nm_wood'] * ($res['percent_wood'] / 100)); - $res['rate_stone'] = ($res['rate_nm_stone'] * ($res['percent_stone'] / 100)); - $res['rate_iron'] = ($res['rate_nm_iron'] * ($res['percent_iron'] / 100)); - $res['rate_mana'] = ($res['rate_nm_mana'] * ($res['percent_mana'] / 100)); - - $this->resources = $res; - - //add score - if ($type == 'building' || $type == 'unit' || $type == 'technology') + public function write_resources() { - $this->score -= ($data['score'] * $num); - } - } - - //substractes resources, $data has to have cost_* fields! - function substract_resources($data, $villageid = 0, $num = 1) - { - //can only happen if not called from events, but shouldn't - if (!$this->resources) - { - $this->get_resources($villageid); - $this->update_resources(); - //$this->_create_sql_debug('sub_resources got called wo $this->resources!'); - } - - $res = $this->resources; - - $res['food'] -= ($data['cost_food'] * $num); - $res['wood'] -= ($data['cost_wood'] * $num); - $res['stone'] -= ($data['cost_stone'] * $num); - $res['iron'] -= ($data['cost_iron'] * $num); - $res['mana'] -= ($data['cost_mana'] * $num); - - if ($res['food'] < 0 || $res['wood'] < 0 || $res['stone'] < 0 || - $res['iron'] < 0 || $res['mana'] < 0) - return FALSE; - - $this->resources = $res; - $this->resources_changed = TRUE; - - return TRUE; - } - -/* - //probably nothing uses it TODO remove - function set_resources($data, $villageid) - { - $sql = "UPDATE resources - SET food='" . $data['food'] . "', - wood='" . $data['wood'] . "', - stone='" . $data['stone'] . "', - iron='" . $data['iron'] . "', - mana='" . $data['mana'] . "' - WHERE villageid='$villageid'"; - - $this->db->query($sql); - } -*/ - //despite the name it updates the resources first, then returns them. - function get_resources($vid) - { - //to not break existing functionality TODO remove returning - if ($this->resources) - return $this->resources; - - //getting resources - $sql = "SELECT * FROM resources WHERE villageid='$vid'"; - $q = $this->db->query($sql); - - $this->resources = $q->row_array(); - - //to not break existing functions, should be removed - return $this->resources; - } - - function update_resources($time = FALSE) - { - if ($time === FALSE) - $time = time(); - - $res = $this->resources; - - //if already at maximum - //we still have to update last_time, because it will screw up things. - if (($res['food'] == $res['max_food']) && - ($res['wood'] == $res['max_wood']) && - ($res['stone'] == $res['max_stone']) && - ($res['iron'] == $res['max_iron']) && - ($res['mana'] == $res['max_mana'])) - { - //do not set $this->resources_changed here, so write only updates the time in the db - $this->resources['last_updated'] = $time; - return; - } - - $ticks = ($time - $res['last_updated']); - - //if more than one event end at the same time this could happen - if (!$ticks) - return; - - $res['food'] += ($res['rate_food'] * $ticks); - $res['wood'] += ($res['rate_wood'] * $ticks); - $res['stone'] += ($res['rate_stone'] * $ticks); - $res['iron'] += ($res['rate_iron'] * $ticks); - $res['mana'] += ($res['rate_mana'] * $ticks); - - //check if over the limit - if ($res['food'] > $res['max_food']) - $res['food'] = $res['max_food']; - if ($res['wood'] > $res['max_wood']) - $res['wood'] = $res['max_wood']; - if ($res['stone'] > $res['max_stone']) - $res['stone'] = $res['max_stone']; - if ($res['iron'] > $res['max_iron']) - $res['iron'] = $res['max_iron']; - if ($res['mana'] > $res['max_mana']) - $res['mana'] = $res['max_mana']; - - $res['last_updated'] = $time; - - //update the db - $this->resources_changed = TRUE; - $this->resources = $res; - } - - function write_resources() - { - //we only have to update last_time - if (!$this->resources_changed && !$this->modifiers_changed) - { - $time = time(); - $sql = "UPDATE resources + //we only have to update last_time + if (!$this->resources_changed && !$this->modifiers_changed) { + $time = time(); + $sql = "UPDATE resources SET last_updated='" . $this->resources['last_updated'] . "' WHERE villageid='" . $this->resources['villageid'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - return; - } + return; + } - $res = $this->resources; + $res = $this->resources; - if ($this->modifiers_changed) - { - $sql = "UPDATE resources + if ($this->modifiers_changed) { + $sql = "UPDATE resources SET food='" . $res['food'] . "', wood='" . $res['wood'] . "', stone='" . $res['stone'] . "', @@ -519,13 +539,12 @@ class MO_Model extends CI_Model percent_mana = '" . $res['percent_mana'] . "' WHERE villageid='" . $res['villageid'] . "'"; - $this->db->query($sql); - } + $this->db->query($sql); + } - if ($this->resources_changed && !$this->modifiers_changed) - { - //update the db - $sql = "UPDATE resources + if ($this->resources_changed && !$this->modifiers_changed) { + //update the db + $sql = "UPDATE resources SET food='" . $res['food'] . "', wood='" . $res['wood'] . "', stone='" . $res['stone'] . "', @@ -534,428 +553,406 @@ class MO_Model extends CI_Model last_updated='" . $res['last_updated'] . "' WHERE villageid='" . $res['villageid'] . "'"; - $this->db->query($sql); - } + $this->db->query($sql); + } - if ($this->score) - { - $sql = "UPDATE villages + if ($this->score) { + $sql = "UPDATE villages SET score = score + '" . $this->score . "' WHERE id='" . $this->resources['villageid'] . "'"; - $this->db->query($sql); + $this->db->query($sql); + } } - } - //resources end + //resources end - //unit functions + //unit functions - //Resource system have to be initialized! + //Resource system have to be initialized! - function unitq_initialize($villageid, $userid = FALSE, $data = FALSE) - { - if ($this->unitq_initialized) - return; - - $this->villageid = $villageid; - - //if we don't know it query it - if (!$userid) + public function unitq_initialize($villageid, $userid = false, $data = false) { - $sql = "SELECT userid FROM villages WHERE id='$villageid'"; + if ($this->unitq_initialized) { + return; + } - $q = $this->db->query($sql); + $this->villageid = $villageid; - $res = $q->row_array(); + //if we don't know it query it + if (!$userid) { + $sql = "SELECT userid FROM villages WHERE id='$villageid'"; - $this->userid = $res['userid']; + $q = $this->db->query($sql); + + $res = $q->row_array(); + + $this->userid = $res['userid']; + } else { + $this->userid = $userid; + } + + //if we had to query units for some reason don't query it again + if (!$data) { + $sql = "SELECT * FROM village_units WHERE villageid='$villageid'"; + + $q = $this->db->query($sql); + + $this->unitq_village_units = $q->result_array(); + } else { + $this->unitq_village_units = $q->result_array(); + } + + //getting unitdata + $sql = "SELECT * FROM units"; + + $q = $this->db->query($sql); + + $this->unitq_units = $q->result_array(); + + $this->unitq_initialized = true; } - else - $this->userid = $userid; - //if we had to query units for some reason don't query it again - if (!$data) + public function unitq_change($action, $unitid, $num, $nomod = false) { - $sql = "SELECT * FROM village_units WHERE villageid='$villageid'"; + if (!$this->unitq_initialized) { + return; + } - $q = $this->db->query($sql); + //getting unitdata + foreach ($this->unitq_units as $row) { + if ($row['id'] == $unitid) { + $unitd = $row; + break; + } + } - $this->unitq_village_units = $q->result_array(); + //error + if (!$unitd) { + return; + } + + $index = false; + + //finding if that type of unit is in the village + if ($this->unitq_village_units) { + for ($i = 0; $i < sizeof($this->unitq_village_units); $i++) { + if ($this->unitq_village_units[$i]['unitid'] == $unitid) { + $index = $i; + break; + } + } + } + + $data['id'] = $unitid; + + if ($action == '+') { + if ($index !== false) { + $data['unitcount'] = ($this->unitq_village_units[$index]['unitcount'] + $num); + } else { + $data['unitcount'] = $num; + } + + if (!$nomod) { + $this->substract_modifiers($unitd, $this->villageid, 'unit', $num, true); + } + } + + if ($action == '-') { + //this expression doesn't have any mean if we don't have that type of unit + if ($index !== false) { + $data['unitcount'] = ($this->unitq_village_units[$index]['unitcount'] - $num); + + if ($data['unitcount'] < 0) { + //adding -1 means substracting it + $num += $data['unitcount']; + $data['unitcount'] = 0; + } + + if (!$nomod) { + $this->add_modifiers($unitd, $this->villageid, 'unit', $num, true); + } + } + } + + if ($action == '+-') { + if ($index !== false) { + $data['unitcount'] = ($this->unitq_village_units[$index]['unitcount'] + $num); + } else { + $data['unitcount'] = $num; + } + + if ($num > 0) { + if (!$nomod) { + $this->substract_modifiers($unitd, $this->villageid, 'unit', $num, true); + } + } else { + if (!$nomod) { + $this->add_modifiers($unitd, $this->villageid, 'unit', $num, true); + } + } + } + + if ($action == '=') { + if ($index !== false) { + $data['unitcount'] = $num; + } + + $number = $this->unitq_village_units[$index]['unitcount'] - $num; + + if ($num > 0) { + if (!$nomod) { + $this->add_modifiers($unitd, $this->villageid, 'unit', $num, true); + } + } else { + if (!$nomod) { + $this->substract_modifiers($unitd, $this->villageid, 'unit', $num, true); + } + } + } + + //error + if (!isset($data['unitcount'])) { + return; + } + + $indexc = false; + + //finding the index which contains our unit + if ($this->unitq_changes) { + for ($i = 0; $i < sizeof($this->unitq_changes); $i++) { + if ($this->unitq_changes[$i]['id'] == $unitid) { + $indexc = $i; + break; + } + } + } + + if ($indexc !== false) { + $this->unitq_changes[$indexc]['unitcount'] = $data['unitcount']; + } else { + $this->unitq_changes[] = array('id' => $data['id'], 'unitcount' => $data['unitcount']); + } } - else - $this->unitq_village_units = $q->result_array(); - //getting unitdata - $sql = "SELECT * FROM units"; - - $q = $this->db->query($sql); - - $this->unitq_units = $q->result_array(); - - $this->unitq_initialized = TRUE; - } - - function unitq_change($action, $unitid, $num, $nomod = FALSE) - { - if (!$this->unitq_initialized) - return; - - //getting unitdata - foreach ($this->unitq_units as $row) + public function unitq_get_units() { - if ($row['id'] == $unitid) - { - $unitd = $row; - break; - } + return $this->unitq_units; } - - //error - if (!$unitd) - return; - - $index = FALSE; - - //finding if that type of unit is in the village - if ($this->unitq_village_units) - { - for ($i = 0; $i < sizeof($this->unitq_village_units); $i++) - { - if ($this->unitq_village_units[$i]['unitid'] == $unitid) - { - $index = $i; - break; - } - } - } - - $data['id'] = $unitid; - - if ($action == '+') - { - if ($index !== FALSE) - $data['unitcount'] = ($this->unitq_village_units[$index]['unitcount'] + $num); - else - $data['unitcount'] = $num; - - if (!$nomod) - $this->substract_modifiers($unitd, $this->villageid, 'unit', $num, TRUE); - } - - if ($action == '-') - { - //this expression doesn't have any mean if we don't have that type of unit - if ($index !== FALSE) - { - $data['unitcount'] = ($this->unitq_village_units[$index]['unitcount'] - $num); - - if ($data['unitcount'] < 0) - { - //adding -1 means substracting it - $num += $data['unitcount']; - $data['unitcount'] = 0; - } - - if (!$nomod) - $this->add_modifiers($unitd, $this->villageid, 'unit', $num, TRUE); - } - } - - if ($action == '+-') - { - if ($index !== FALSE) - $data['unitcount'] = ($this->unitq_village_units[$index]['unitcount'] + $num); - else - $data['unitcount'] = $num; - - if ($num > 0) - { - if (!$nomod) - $this->substract_modifiers($unitd, $this->villageid, 'unit', $num, TRUE); - } - else - { - if (!$nomod) - $this->add_modifiers($unitd, $this->villageid, 'unit', $num, TRUE); - } - } - - if ($action == '=') - { - if ($index !== FALSE) - $data['unitcount'] = $num; - - $number = $this->unitq_village_units[$index]['unitcount'] - $num; - - if ($num > 0) - { - if (!$nomod) - $this->add_modifiers($unitd, $this->villageid, 'unit', $num, TRUE); - } - else - { - if (!$nomod) - $this->substract_modifiers($unitd, $this->villageid, 'unit', $num, TRUE); - } - } - - //error - if (!isset($data['unitcount'])) - return; - - $indexc = FALSE; - - //finding the index which contains our unit - if ($this->unitq_changes) - { - for ($i = 0; $i < sizeof($this->unitq_changes); $i++) - { - if ($this->unitq_changes[$i]['id'] == $unitid) - { - $indexc = $i; - break; - } - } - } - - if ($indexc !== FALSE) - $this->unitq_changes[$indexc]['unitcount'] = $data['unitcount']; - else - $this->unitq_changes[] = array('id' => $data['id'], 'unitcount' => $data['unitcount']); - - } - - function unitq_get_units() - { - return $this->unitq_units; - } - function unitq_get_village_units() - { - $data = $this->unitq_village_units; - - if ($this->unitq_changes) + public function unitq_get_village_units() { - foreach ($this->unitq_changes as $row) - { - for ($i = 0; $i < sizeof($data); $i++) - { - if ($row['id'] == $data[$i]['unitid']) - $data[$i]['unitcount'] = $row['unitcount']; - } - } + $data = $this->unitq_village_units; + + if ($this->unitq_changes) { + foreach ($this->unitq_changes as $row) { + for ($i = 0; $i < sizeof($data); $i++) { + if ($row['id'] == $data[$i]['unitid']) { + $data[$i]['unitcount'] = $row['unitcount']; + } + } + } + } + + return $data; } - return $data; - } - - //write changes to db - function unitq_write() - { - if (!$this->unitq_initialized) - return; - - if (!$this->unitq_changes) - return; - - foreach ($this->unitq_changes as $row) + //write changes to db + public function unitq_write() { - $vu = FALSE; + if (!$this->unitq_initialized) { + return; + } - //searching for village_units's row - foreach ($this->unitq_village_units as $vurow) - { - if ($row['id'] == $vurow['unitid']) - { - $vu = $vurow; - break; - } - } + if (!$this->unitq_changes) { + return; + } - //its <= just in case - //nothing to do here - if (!$vu && $row['unitcount'] <= 0) - continue; + foreach ($this->unitq_changes as $row) { + $vu = false; - //nothing to do here - if ($vu) - if ($row['unitcount'] == $vu['unitcount']) - continue; + //searching for village_units's row + foreach ($this->unitq_village_units as $vurow) { + if ($row['id'] == $vurow['unitid']) { + $vu = $vurow; + break; + } + } - //DELETING row - if ($vu && $row['unitcount'] <= 0) - { - $sql = "DELETE FROM village_units WHERE id='" . $vu['id'] . "'"; - $this->db->query($sql); - continue; - } + //its <= just in case + //nothing to do here + if (!$vu && $row['unitcount'] <= 0) { + continue; + } - //other cases handled at this point, we only need to check for vu - if ($vu) - { - $sql = "UPDATE village_units + //nothing to do here + if ($vu) { + if ($row['unitcount'] == $vu['unitcount']) { + continue; + } + } + + //DELETING row + if ($vu && $row['unitcount'] <= 0) { + $sql = "DELETE FROM village_units WHERE id='" . $vu['id'] . "'"; + $this->db->query($sql); + continue; + } + + //other cases handled at this point, we only need to check for vu + if ($vu) { + $sql = "UPDATE village_units SET unitcount='" . $row['unitcount'] . "' WHERE id='" . $vu['id'] . "'"; - } - else - { - $sql = "INSERT INTO village_units + } else { + $sql = "INSERT INTO village_units VALUES(default, '" . $this->userid . "', '" . $this->villageid . "', '" . $row['id'] . "', '" . $row['unitcount'] . "')"; - } + } - $this->db->query($sql); + $this->db->query($sql); + } } - } - //unit functions end + //unit functions end - //building - function get_slot_building($slotid, $villageid) - { - $sql = "SELECT buildings.* FROM village_buildings + //building + public function get_slot_building($slotid, $villageid) + { + $sql = "SELECT buildings.* FROM village_buildings INNER JOIN buildings ON village_buildings.buildingid=buildings.id WHERE village_buildings.villageid='$villageid' AND village_buildings.slotid='$slotid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows()) - return $q->row_array(); + if ($q->num_rows()) { + return $q->row_array(); + } - $sql = "SELECT * FROM buildings WHERE id='1'"; - $q = $this->db->query($sql); + $sql = "SELECT * FROM buildings WHERE id='1'"; + $q = $this->db->query($sql); - return $q->row_array(); - } - //building end + return $q->row_array(); + } + //building end - //technologies - function add_technology($techid, $group, $tech, $slotid, $villageid) - { - //group == 0 primary, group == 1 secondary - if (!$group) + //technologies + public function add_technology($techid, $group, $tech, $slotid, $villageid) { - $sql = "INSERT INTO village_technologies + //group == 0 primary, group == 1 secondary + if (!$group) { + $sql = "INSERT INTO village_technologies VALUES(default, '$villageid', '0', '$techid')"; - } - else - { - $sql = "INSERT INTO village_technologies + } else { + $sql = "INSERT INTO village_technologies VALUES(default, '$villageid', '$slotid', '$techid')"; + } + + $this->db->query($sql); + + if ($tech['flag_ai']) { + $sql = "UPDATE villages SET ai_flagged='1' WHERE id='$villageid'"; + + $this->db->query($sql); + } } - $this->db->query($sql); - - if ($tech['flag_ai']) + public function get_village_technologies($villageid, $slotid = 0) { - $sql = "UPDATE villages SET ai_flagged='1' WHERE id='$villageid'"; - - $this->db->query($sql); - } - } - - function get_village_technologies($villageid, $slotid = 0) - { - if ($slotid) - { - $sql = "SELECT * FROM village_technologies + if ($slotid) { + $sql = "SELECT * FROM village_technologies WHERE villageid='$villageid' AND (slotid='0' OR slotid='$slotid')"; - } - else - { - $sql = "SELECT * FROM village_technologies + } else { + $sql = "SELECT * FROM village_technologies WHERE villageid='$villageid' AND slotid='0'"; + } + + $q = $this->db->query($sql); + + return $q->result_array(); } - $q = $this->db->query($sql); - - return $q->result_array(); - } - - //data is tecnology data - function have_technology($data, $techid) - { - if (!$techid) - return TRUE; - - foreach ($data as $row) + //data is tecnology data + public function have_technology($data, $techid) { - if ($row['technologyid'] == $techid) - return TRUE; + if (!$techid) { + return true; + } + + foreach ($data as $row) { + if ($row['technologyid'] == $techid) { + return true; + } + } + + return false; } - return FALSE; - } - - function has_req_tech($techid, $villageid, $slotid = 0) - { - if (!$techid) - return TRUE; - - $tech = $this->get_village_technologies($villageid, $slotid); - - foreach ($tech as $row) + public function has_req_tech($techid, $villageid, $slotid = 0) { - if ($row['technologyid'] == $techid) - return TRUE; + if (!$techid) { + return true; + } + + $tech = $this->get_village_technologies($villageid, $slotid); + + foreach ($tech as $row) { + if ($row['technologyid'] == $techid) { + return true; + } + } + + return false; } - return FALSE; - } + //technologies end - //technologies end - - //combat log - function add_combat_log($log, $villageid) - { - $sql = "INSERT INTO combat_logs + //combat log + public function add_combat_log($log, $villageid) + { + $sql = "INSERT INTO combat_logs VALUES(default, '$villageid', '" . time() . "', '1', '$log')"; - $this->db->query($sql); + $this->db->query($sql); - $sql = "UPDATE villages SET new_log='1' WHERE id='$villageid'"; + $sql = "UPDATE villages SET new_log='1' WHERE id='$villageid'"; - $this->db->query($sql); - } - - //combat log end - - //Hero Functions - - //set hero - function set_hero($data) - { - $this->hero = $data; - } - - //to be used with controllers after like equipping, and stat recalculations, combat etc - function get_hero() - { - return $this->hero; - } - - //Hero db update function - function hero_write() - { - //if more than on flag set unset the not needed ones - if ($this->hero_stat_changed) - { - $this->hero_hpmp_changed = FALSE; - $this->hero_exp_changed = FALSE; - } - elseif ($this->hero_exp_changed) - { - $this->hero_hpmp_changed = FALSE; + $this->db->query($sql); } - if ($this->hero_stat_changed) - { - $d = $this->hero; + //combat log end - $sql = "UPDATE heroes + //Hero Functions + + //set hero + public function set_hero($data) + { + $this->hero = $data; + } + + //to be used with controllers after like equipping, and stat recalculations, combat etc + public function get_hero() + { + return $this->hero; + } + + //Hero db update function + public function hero_write() + { + //if more than on flag set unset the not needed ones + if ($this->hero_stat_changed) { + $this->hero_hpmp_changed = false; + $this->hero_exp_changed = false; + } elseif ($this->hero_exp_changed) { + $this->hero_hpmp_changed = false; + } + + if ($this->hero_stat_changed) { + $d = $this->hero; + + $sql = "UPDATE heroes SET level = '" . $d['level'] . "', experience = '" . $d['experience'] . "', health = '" . $d['health'] . "', @@ -1022,502 +1019,461 @@ class MO_Model extends CI_Model mana_leech = '" . $d['mana_leech'] . "' WHERE id = '" . $d['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - return TRUE; - } + return true; + } - //exp, hp, mp - if ($this->hero_exp_changed) - { - $d = $this->hero; + //exp, hp, mp + if ($this->hero_exp_changed) { + $d = $this->hero; - $sql = "UPDATE heroes + $sql = "UPDATE heroes SET health='" . $d['health'] . "', mana='" . $d['mana'] . "', experience='" . $d['experience'] . "' WHERE id = '" . $d['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - return TRUE; - } + return true; + } - if ($this->hero_hpmp_changed) - { - $d = $this->hero; + if ($this->hero_hpmp_changed) { + $d = $this->hero; - $sql = "UPDATE heroes + $sql = "UPDATE heroes SET health='" . $d['health'] . "', mana='" . $d['mana'] . "', WHERE id = '" . $d['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - return TRUE; + return true; + } + + return false; } - return FALSE; - } + //Hero stat calc functions - //Hero stat calc functions + //thins calculates every char stats (like when equipping) + public function calc_hero_stats() + { + $d = $this->hero; + $c = $this->hero['class']; - //thins calculates every char stats (like when equipping) - function calc_hero_stats() - { - $d = $this->hero; - $c = $this->hero['class']; + //base stats + $d['agility'] = floor(($d['nomod_agility'] / 100) * $d['percent_agility']); + $d['strength'] = floor(($d['nomod_strength'] / 100) * $d['percent_strength']); + $d['stamina'] = floor(($d['nomod_stamina'] / 100) * $d['percent_stamina']); + $d['intellect'] = floor(($d['nomod_intellect'] / 100) * $d['percent_intellect']); + $d['spirit'] = floor(($d['nomod_spirit'] / 100) * $d['percent_spirit']); - //base stats - $d['agility'] = floor(($d['nomod_agility'] / 100) * $d['percent_agility']); - $d['strength'] = floor(($d['nomod_strength'] / 100) * $d['percent_strength']); - $d['stamina'] = floor(($d['nomod_stamina'] / 100) * $d['percent_stamina']); - $d['intellect'] = floor(($d['nomod_intellect'] / 100) * $d['percent_intellect']); - $d['spirit'] = floor(($d['nomod_spirit'] / 100) * $d['percent_spirit']); + //health, mana + $d['max_health'] = $this->hero_stat($c, 'max_health', $d); + $d['max_mana'] = $this->hero_stat($c, 'max_mana', $d); - //health, mana - $d['max_health'] = $this->hero_stat($c, 'max_health', $d); - $d['max_mana'] = $this->hero_stat($c, 'max_mana', $d); - - $d['max_health'] = floor(($d['max_health'] / 100) * $d['percent_max_health']); - $d['max_mana'] = floor(($d['max_mana'] / 100) * $d['percent_max_mana']); + $d['max_health'] = floor(($d['max_health'] / 100) * $d['percent_max_health']); + $d['max_mana'] = floor(($d['max_mana'] / 100) * $d['percent_max_mana']); - $d['health'] = $d['max_health']; - $d['mana'] = $d['max_mana']; + $d['health'] = $d['max_health']; + $d['mana'] = $d['max_mana']; - //ap - $d['attackpower'] = $this->hero_stat($c, 'attackpower', $d); - $d['attackpower'] = floor(($d['attackpower'] / 100) * $d['percent_attackpower']); + //ap + $d['attackpower'] = $this->hero_stat($c, 'attackpower', $d); + $d['attackpower'] = floor(($d['attackpower'] / 100) * $d['percent_attackpower']); - //% stats - $d['dodge'] = $this->hero_stat($c, 'dodge', $d); - $d['parry'] = $this->hero_stat($c, 'parry', $d); - $d['crit'] = $this->hero_stat($c, 'crit', $d); + //% stats + $d['dodge'] = $this->hero_stat($c, 'dodge', $d); + $d['parry'] = $this->hero_stat($c, 'parry', $d); + $d['crit'] = $this->hero_stat($c, 'crit', $d); - //damage - $d['damage_min'] = $this->hero_stat($c, 'damage_min', $d); - $d['damage_min'] = floor(($d['damage_min'] / 100) * $d['percent_damage_min']); - $d['damage_max'] = $this->hero_stat($c, 'damage_max', $d); - $d['damage_max'] = floor(($d['damage_max'] / 100) * $d['percent_damage_max']); + //damage + $d['damage_min'] = $this->hero_stat($c, 'damage_min', $d); + $d['damage_min'] = floor(($d['damage_min'] / 100) * $d['percent_damage_min']); + $d['damage_max'] = $this->hero_stat($c, 'damage_max', $d); + $d['damage_max'] = floor(($d['damage_max'] / 100) * $d['percent_damage_max']); - //ranged damage - $d['ranged_damage_min'] = $this->hero_stat($c, 'ranged_damage_min', $d); - $d['ranged_damage_min'] = floor(($d['ranged_damage_min'] / 100) * $d['percent_ranged_damage_min']); - $d['ranged_damage_max'] = $this->hero_stat($c, 'ranged_damage_max', $d); - $d['ranged_damage_max'] = floor(($d['ranged_damage_max'] / 100) * $d['percent_ranged_damage_max']); + //ranged damage + $d['ranged_damage_min'] = $this->hero_stat($c, 'ranged_damage_min', $d); + $d['ranged_damage_min'] = floor(($d['ranged_damage_min'] / 100) * $d['percent_ranged_damage_min']); + $d['ranged_damage_max'] = $this->hero_stat($c, 'ranged_damage_max', $d); + $d['ranged_damage_max'] = floor(($d['ranged_damage_max'] / 100) * $d['percent_ranged_damage_max']); - //heal - $d['heal_min'] = $this->hero_stat($c, 'heal_min', $d); - $d['heal_min'] = floor(($d['heal_min'] / 100) * $d['percent_heal_min']); - $d['heal_max'] = $this->hero_stat($c, 'heal_max', $d); - $d['heal_max'] = floor(($d['heal_max'] / 100) * $d['percent_heal_max']); + //heal + $d['heal_min'] = $this->hero_stat($c, 'heal_min', $d); + $d['heal_min'] = floor(($d['heal_min'] / 100) * $d['percent_heal_min']); + $d['heal_max'] = $this->hero_stat($c, 'heal_max', $d); + $d['heal_max'] = floor(($d['heal_max'] / 100) * $d['percent_heal_max']); - //armor - $d['armor'] = floor(($d['nomod_armor'] / 100) * $d['percent_armor']); + //armor + $d['armor'] = floor(($d['nomod_armor'] / 100) * $d['percent_armor']); - $this->hero = $d; - $this->hero_stat_changed = TRUE; + $this->hero = $d; + $this->hero_stat_changed = true; - $this->hero_write(); - } - - //the function which has all the class formulas - //class can be string or id - function hero_stat($class, $type, $data = FALSE) - { - if (!$data) - $data = $this->hero; - - if ($class == 1 || $class == 'Warrior') - { - if ($type == 'attackpower') - { - $ATTACKPOWER_BASE = 0; - $ATTACKPOWER_FACTOR_STR = 20; - $ATTACKPOWER_FACTOR_AGI = 10; - - $c = $ATTACKPOWER_BASE; - $c += ($data['strength'] * $ATTACKPOWER_FACTOR_STR); - $c += ($data['agility'] * $ATTACKPOWER_FACTOR_AGI); - $c += $data['nomod_attackpower']; - } - elseif ($type == 'crit') - { - $CRIT_BASE = 0; - //how much of these stats give 1% crit - $CRIT_FACTOR_AGI = 40; - $CRIT_FACTOR_STR = 30; - $CRIT_FACTOR_INT = 60; - - $c = $CRIT_BASE; - $c += ($data['agility'] / $CRIT_FACTOR_AGI); - $c += ($data['strength'] / $CRIT_FACTOR_STR); - $c += ($data['intellect'] / $CRIT_FACTOR_INT); - $c += $data['nomod_crit']; - } - } - elseif ($class == 2 || $class == 'Rogue') - { - if ($type == 'attackpower') - { - $ATTACKPOWER_BASE = 0; - $ATTACKPOWER_FACTOR_STR = 5; - $ATTACKPOWER_FACTOR_AGI = 25; - - $c = $ATTACKPOWER_BASE; - $c += ($data['strength'] * $ATTACKPOWER_FACTOR_STR); - $c += ($data['agility'] * $ATTACKPOWER_FACTOR_AGI); - $c += $data['nomod_attackpower']; - } - elseif ($type == 'crit') - { - $CRIT_BASE = 0; - //how much of these stats give 1% crit - $CRIT_FACTOR_AGI = 25; - $CRIT_FACTOR_STR = 50; - $CRIT_FACTOR_INT = 60; - - $c = $CRIT_BASE; - $c += ($data['agility'] / $CRIT_FACTOR_AGI); - $c += ($data['strength'] / $CRIT_FACTOR_STR); - $c += ($data['intellect'] / $CRIT_FACTOR_INT); - $c += $data['nomod_crit']; - } - } - elseif ($class == 3 || $class == 'Archer') - { - if ($type == 'attackpower') - { - $ATTACKPOWER_BASE = 0; - $ATTACKPOWER_FACTOR_STR = 10; - $ATTACKPOWER_FACTOR_AGI = 20; - - $c = $ATTACKPOWER_BASE; - $c += ($data['strength'] * $ATTACKPOWER_FACTOR_STR); - $c += ($data['agility'] * $ATTACKPOWER_FACTOR_AGI); - $c += $data['nomod_attackpower']; - } - elseif ($type == 'crit') - { - $CRIT_BASE = 0; - //how much of these stats give 1% crit - $CRIT_FACTOR_AGI = 30; - $CRIT_FACTOR_STR = 60; - $CRIT_FACTOR_INT = 40; - - $c = $CRIT_BASE; - $c += ($data['agility'] / $CRIT_FACTOR_AGI); - $c += ($data['strength'] / $CRIT_FACTOR_STR); - $c += ($data['intellect'] / $CRIT_FACTOR_INT); - $c += $data['nomod_crit']; - } + $this->hero_write(); } - if ($type == 'max_health') + //the function which has all the class formulas + //class can be string or id + public function hero_stat($class, $type, $data = false) { - $HEALTH_FACTOR = 10; + if (!$data) { + $data = $this->hero; + } - $c = $data['stamina'] * $HEALTH_FACTOR; - $c += $data['nomod_max_health']; - } - elseif ($type == 'max_mana') - { - $MANA_FACTOR = 10; + if ($class == 1 || $class == 'Warrior') { + if ($type == 'attackpower') { + $ATTACKPOWER_BASE = 0; + $ATTACKPOWER_FACTOR_STR = 20; + $ATTACKPOWER_FACTOR_AGI = 10; - $c = $data['intellect'] * $MANA_FACTOR; - $c += $data['nomod_max_mana']; - } - elseif ($type == 'dodge') - { - $DODGE_BASE = 0; - //how much agi gives 1% dodge - $DODGE_FACTOR_AGI = 30; + $c = $ATTACKPOWER_BASE; + $c += ($data['strength'] * $ATTACKPOWER_FACTOR_STR); + $c += ($data['agility'] * $ATTACKPOWER_FACTOR_AGI); + $c += $data['nomod_attackpower']; + } elseif ($type == 'crit') { + $CRIT_BASE = 0; + //how much of these stats give 1% crit + $CRIT_FACTOR_AGI = 40; + $CRIT_FACTOR_STR = 30; + $CRIT_FACTOR_INT = 60; - $c = $DODGE_BASE; - $c += ($data['agility'] / $DODGE_FACTOR_AGI); - $c += $data['nomod_dodge']; - } - elseif ($type == 'parry') - { - $PARRY_BASE = 0; - //how much str gives 1% parry - $PARRY_FACTOR_STR = 30; + $c = $CRIT_BASE; + $c += ($data['agility'] / $CRIT_FACTOR_AGI); + $c += ($data['strength'] / $CRIT_FACTOR_STR); + $c += ($data['intellect'] / $CRIT_FACTOR_INT); + $c += $data['nomod_crit']; + } + } elseif ($class == 2 || $class == 'Rogue') { + if ($type == 'attackpower') { + $ATTACKPOWER_BASE = 0; + $ATTACKPOWER_FACTOR_STR = 5; + $ATTACKPOWER_FACTOR_AGI = 25; - $c = $PARRY_BASE; - $c += ($data['strength'] / $PARRY_FACTOR_STR); - $c += $data['nomod_parry']; - } - elseif ($type == 'damage_min') - { - $DAMAGE_BASE = 0; - //how much ap gives 1 dmg increase - $DAMAGE_FACTOR = 100; + $c = $ATTACKPOWER_BASE; + $c += ($data['strength'] * $ATTACKPOWER_FACTOR_STR); + $c += ($data['agility'] * $ATTACKPOWER_FACTOR_AGI); + $c += $data['nomod_attackpower']; + } elseif ($type == 'crit') { + $CRIT_BASE = 0; + //how much of these stats give 1% crit + $CRIT_FACTOR_AGI = 25; + $CRIT_FACTOR_STR = 50; + $CRIT_FACTOR_INT = 60; - $c = $DAMAGE_BASE; - $c += floor($data['attackpower'] / $DAMAGE_FACTOR); - $c += $data['nomod_damage_min']; - } - elseif ($type == 'damage_max') - { - $DAMAGE_BASE = 0; - //how much ap gives 1 dmg increase - $DAMAGE_FACTOR = 100; + $c = $CRIT_BASE; + $c += ($data['agility'] / $CRIT_FACTOR_AGI); + $c += ($data['strength'] / $CRIT_FACTOR_STR); + $c += ($data['intellect'] / $CRIT_FACTOR_INT); + $c += $data['nomod_crit']; + } + } elseif ($class == 3 || $class == 'Archer') { + if ($type == 'attackpower') { + $ATTACKPOWER_BASE = 0; + $ATTACKPOWER_FACTOR_STR = 10; + $ATTACKPOWER_FACTOR_AGI = 20; - $c = $DAMAGE_BASE; - $c += floor($data['attackpower'] / $DAMAGE_FACTOR); - $c += $data['nomod_damage_max']; - } - elseif ($type == 'ranged_damage_min') - { - $DAMAGE_BASE = 0; - //how much ap gives 1 dmg increase - $DAMAGE_FACTOR = 100; + $c = $ATTACKPOWER_BASE; + $c += ($data['strength'] * $ATTACKPOWER_FACTOR_STR); + $c += ($data['agility'] * $ATTACKPOWER_FACTOR_AGI); + $c += $data['nomod_attackpower']; + } elseif ($type == 'crit') { + $CRIT_BASE = 0; + //how much of these stats give 1% crit + $CRIT_FACTOR_AGI = 30; + $CRIT_FACTOR_STR = 60; + $CRIT_FACTOR_INT = 40; - $c = $DAMAGE_BASE; - $c += floor($data['attackpower'] / $DAMAGE_FACTOR); - $c += $data['nomod_ranged_damage_min']; - } - elseif ($type == 'ranged_damage_max') - { - $DAMAGE_BASE = 0; - //how much ap gives 1 dmg increase - $DAMAGE_FACTOR = 100; + $c = $CRIT_BASE; + $c += ($data['agility'] / $CRIT_FACTOR_AGI); + $c += ($data['strength'] / $CRIT_FACTOR_STR); + $c += ($data['intellect'] / $CRIT_FACTOR_INT); + $c += $data['nomod_crit']; + } + } - $c = $DAMAGE_BASE; - $c += floor($data['attackpower'] / $DAMAGE_FACTOR); - $c += $data['nomod_ranged_damage_max']; - } - elseif ($type == 'heal_min') - { - $c = 0; - } - elseif ($type == 'heal_max') - { - $c = 0; + if ($type == 'max_health') { + $HEALTH_FACTOR = 10; + + $c = $data['stamina'] * $HEALTH_FACTOR; + $c += $data['nomod_max_health']; + } elseif ($type == 'max_mana') { + $MANA_FACTOR = 10; + + $c = $data['intellect'] * $MANA_FACTOR; + $c += $data['nomod_max_mana']; + } elseif ($type == 'dodge') { + $DODGE_BASE = 0; + //how much agi gives 1% dodge + $DODGE_FACTOR_AGI = 30; + + $c = $DODGE_BASE; + $c += ($data['agility'] / $DODGE_FACTOR_AGI); + $c += $data['nomod_dodge']; + } elseif ($type == 'parry') { + $PARRY_BASE = 0; + //how much str gives 1% parry + $PARRY_FACTOR_STR = 30; + + $c = $PARRY_BASE; + $c += ($data['strength'] / $PARRY_FACTOR_STR); + $c += $data['nomod_parry']; + } elseif ($type == 'damage_min') { + $DAMAGE_BASE = 0; + //how much ap gives 1 dmg increase + $DAMAGE_FACTOR = 100; + + $c = $DAMAGE_BASE; + $c += floor($data['attackpower'] / $DAMAGE_FACTOR); + $c += $data['nomod_damage_min']; + } elseif ($type == 'damage_max') { + $DAMAGE_BASE = 0; + //how much ap gives 1 dmg increase + $DAMAGE_FACTOR = 100; + + $c = $DAMAGE_BASE; + $c += floor($data['attackpower'] / $DAMAGE_FACTOR); + $c += $data['nomod_damage_max']; + } elseif ($type == 'ranged_damage_min') { + $DAMAGE_BASE = 0; + //how much ap gives 1 dmg increase + $DAMAGE_FACTOR = 100; + + $c = $DAMAGE_BASE; + $c += floor($data['attackpower'] / $DAMAGE_FACTOR); + $c += $data['nomod_ranged_damage_min']; + } elseif ($type == 'ranged_damage_max') { + $DAMAGE_BASE = 0; + //how much ap gives 1 dmg increase + $DAMAGE_FACTOR = 100; + + $c = $DAMAGE_BASE; + $c += floor($data['attackpower'] / $DAMAGE_FACTOR); + $c += $data['nomod_ranged_damage_max']; + } elseif ($type == 'heal_min') { + $c = 0; + } elseif ($type == 'heal_max') { + $c = 0; + } + + if (isset($c)) { + return $c; + } + + return false; } - if (isset($c)) - return $c; - - return FALSE; - } - - function hero_add_stats($data) - { - $d = $this->hero; - - if (isset($data['level_modifier'])) + public function hero_add_stats($data) { - $lvlmax = $data['level_modifier_max']; + $d = $this->hero; - //this means no limit - if (!$lvlmax) - $lvlmax = $this->hero['level']; + if (isset($data['level_modifier'])) { + $lvlmax = $data['level_modifier_max']; - if ($lvlmax < $this->hero['level']) - $lvlmod = $lvlmax; - else - $lvlmod = $this->hero['level']; + //this means no limit + if (!$lvlmax) { + $lvlmax = $this->hero['level']; + } - $lvlmod *= $data['level_modifier']; - } - else - { - $lvlmod = 0; + if ($lvlmax < $this->hero['level']) { + $lvlmod = $lvlmax; + } else { + $lvlmod = $this->hero['level']; + } + + $lvlmod *= $data['level_modifier']; + } else { + $lvlmod = 0; + } + + $d['percent_max_health'] += $data['percent_max_health']; + $d['percent_max_mana'] += $data['percent_max_mana']; + + $d['nomod_max_health'] += $data['nomod_max_health']; + $d['nomod_max_mana'] += $data['nomod_max_mana']; + + $d['percent_agility'] += $data['percent_agility']; + $d['percent_strength'] += $data['percent_strength']; + $d['percent_stamina'] += $data['percent_stamina']; + $d['percent_intellect'] += $data['percent_intellect']; + $d['percent_spirit'] += $data['percent_spirit']; + + $d['nomod_agility'] += $data['nomod_agility'] + $lvlmod; + $d['nomod_strength'] += $data['nomod_strength'] + $lvlmod; + $d['nomod_stamina'] += $data['nomod_stamina'] + $lvlmod; + $d['nomod_intellect'] += $data['nomod_intellect'] + $lvlmod; + $d['nomod_spirit'] += $data['nomod_spirit'] + $lvlmod; + + $d['percent_attackpower'] += $data['percent_attackpower']; + $d['nomod_attackpower'] += $data['nomod_attackpower']; + + $d['percent_armor'] += $data['percent_armor']; + $d['nomod_armor'] += $data['nomod_armor']; + + $d['nomod_dodge'] += $data['nomod_dodge']; + $d['nomod_parry'] += $data['nomod_parry']; + $d['hit'] += $data['hit']; + $d['nomod_crit'] += $data['nomod_crit']; + + $d['percent_damage_min'] += $data['percent_damage_min']; + $d['percent_damage_max'] += $data['percent_damage_max']; + $d['nomod_damage_min'] += $data['nomod_damage_min']; + $d['nomod_damage_max'] += $data['nomod_damage_max']; + + $d['percent_ranged_damage_min'] += $data['percent_ranged_damage_min']; + $d['percent_ranged_damage_max'] += $data['percent_ranged_damage_max']; + $d['nomod_ranged_damage_min'] += $data['nomod_ranged_damage_min']; + $d['nomod_ranged_damage_max'] += $data['nomod_ranged_damage_max']; + + $d['percent_heal_min'] += $data['percent_heal_min']; + $d['percent_heal_max'] += $data['percent_heal_max']; + + $d['nomod_heal_min'] += $data['nomod_heal_min']; + $d['nomod_heal_max'] += $data['nomod_heal_max']; + + $d['life_leech'] += $data['life_leech']; + $d['mana_leech'] += $data['mana_leech']; + + $this->hero = $d; } - $d['percent_max_health'] += $data['percent_max_health']; - $d['percent_max_mana'] += $data['percent_max_mana']; - - $d['nomod_max_health'] += $data['nomod_max_health']; - $d['nomod_max_mana'] += $data['nomod_max_mana']; - - $d['percent_agility'] += $data['percent_agility']; - $d['percent_strength'] += $data['percent_strength']; - $d['percent_stamina'] += $data['percent_stamina']; - $d['percent_intellect'] += $data['percent_intellect']; - $d['percent_spirit'] += $data['percent_spirit']; - - $d['nomod_agility'] += $data['nomod_agility'] + $lvlmod; - $d['nomod_strength'] += $data['nomod_strength'] + $lvlmod; - $d['nomod_stamina'] += $data['nomod_stamina'] + $lvlmod; - $d['nomod_intellect'] += $data['nomod_intellect'] + $lvlmod; - $d['nomod_spirit'] += $data['nomod_spirit'] + $lvlmod; - - $d['percent_attackpower'] += $data['percent_attackpower']; - $d['nomod_attackpower'] += $data['nomod_attackpower']; - - $d['percent_armor'] += $data['percent_armor']; - $d['nomod_armor'] += $data['nomod_armor']; - - $d['nomod_dodge'] += $data['nomod_dodge']; - $d['nomod_parry'] += $data['nomod_parry']; - $d['hit'] += $data['hit']; - $d['nomod_crit'] += $data['nomod_crit']; - - $d['percent_damage_min'] += $data['percent_damage_min']; - $d['percent_damage_max'] += $data['percent_damage_max']; - $d['nomod_damage_min'] += $data['nomod_damage_min']; - $d['nomod_damage_max'] += $data['nomod_damage_max']; - - $d['percent_ranged_damage_min'] += $data['percent_ranged_damage_min']; - $d['percent_ranged_damage_max'] += $data['percent_ranged_damage_max']; - $d['nomod_ranged_damage_min'] += $data['nomod_ranged_damage_min']; - $d['nomod_ranged_damage_max'] += $data['nomod_ranged_damage_max']; - - $d['percent_heal_min'] += $data['percent_heal_min']; - $d['percent_heal_max'] += $data['percent_heal_max']; - - $d['nomod_heal_min'] += $data['nomod_heal_min']; - $d['nomod_heal_max'] += $data['nomod_heal_max']; - - $d['life_leech'] += $data['life_leech']; - $d['mana_leech'] += $data['mana_leech']; - - $this->hero = $d; - } - - function hero_remove_stats($data) - { - $d = $this->hero; - - if (isset($data['level_modifier'])) + public function hero_remove_stats($data) { - $lvlmax = $data['level_modifier_max']; + $d = $this->hero; - //this means no limit - if (!$lvlmax) - $lvlmax = $this->hero['level']; + if (isset($data['level_modifier'])) { + $lvlmax = $data['level_modifier_max']; - if ($lvlmax < $this->hero['level']) - $lvlmod = $lvlmax; - else - $lvlmod = $this->hero['level']; + //this means no limit + if (!$lvlmax) { + $lvlmax = $this->hero['level']; + } - $lvlmod *= $data['level_modifier']; - } - else - { - $lvlmod = 0; + if ($lvlmax < $this->hero['level']) { + $lvlmod = $lvlmax; + } else { + $lvlmod = $this->hero['level']; + } + + $lvlmod *= $data['level_modifier']; + } else { + $lvlmod = 0; + } + + $d['percent_max_health'] -= $data['percent_max_health']; + $d['percent_max_mana'] -= $data['percent_max_mana']; + + $d['nomod_max_health'] -= $data['nomod_max_health']; + $d['nomod_max_mana'] -= $data['nomod_max_mana']; + + $d['percent_agility'] -= $data['percent_agility']; + $d['percent_strength'] -= $data['percent_strength']; + $d['percent_stamina'] -= $data['percent_stamina']; + $d['percent_intellect'] -= $data['percent_intellect']; + $d['percent_spirit'] -= $data['percent_spirit']; + + $d['nomod_agility'] -= $data['nomod_agility'] + $lvlmod; + $d['nomod_strength'] -= $data['nomod_strength'] + $lvlmod; + $d['nomod_stamina'] -= $data['nomod_stamina'] + $lvlmod; + $d['nomod_intellect'] -= $data['nomod_intellect'] + $lvlmod; + $d['nomod_spirit'] -= $data['nomod_spirit'] + $lvlmod; + + $d['percent_attackpower'] -= $data['percent_attackpower']; + $d['nomod_attackpower'] -= $data['nomod_attackpower']; + + $d['percent_armor'] -= $data['percent_armor']; + $d['nomod_armor'] -= $data['nomod_armor']; + + $d['nomod_dodge'] -= $data['nomod_dodge']; + $d['nomod_parry'] -= $data['nomod_parry']; + $d['hit'] -= $data['hit']; + $d['nomod_crit'] -= $data['nomod_crit']; + + $d['percent_damage_min'] -= $data['percent_damage_min']; + $d['percent_damage_max'] -= $data['percent_damage_max']; + $d['nomod_damage_min'] -= $data['nomod_damage_min']; + $d['nomod_damage_max'] -= $data['nomod_damage_max']; + + $d['percent_ranged_damage_min'] -= $data['percent_ranged_damage_min']; + $d['percent_ranged_damage_max'] -= $data['percent_ranged_damage_max']; + $d['nomod_ranged_damage_min'] -= $data['nomod_ranged_damage_min']; + $d['nomod_ranged_damage_max'] -= $data['nomod_ranged_damage_max']; + + $d['percent_heal_min'] -= $data['percent_heal_min']; + $d['percent_heal_max'] -= $data['percent_heal_max']; + $d['nomod_heal_min'] -= $data['nomod_heal_min']; + $d['nomod_heal_max'] -= $data['nomod_heal_max']; + + $d['life_leech'] -= $data['life_leech']; + $d['mana_leech'] -= $data['mana_leech']; + + $this->hero = $d; } - $d['percent_max_health'] -= $data['percent_max_health']; - $d['percent_max_mana'] -= $data['percent_max_mana']; + //Hero stat calc functions end - $d['nomod_max_health'] -= $data['nomod_max_health']; - $d['nomod_max_mana'] -= $data['nomod_max_mana']; - - $d['percent_agility'] -= $data['percent_agility']; - $d['percent_strength'] -= $data['percent_strength']; - $d['percent_stamina'] -= $data['percent_stamina']; - $d['percent_intellect'] -= $data['percent_intellect']; - $d['percent_spirit'] -= $data['percent_spirit']; - - $d['nomod_agility'] -= $data['nomod_agility'] + $lvlmod; - $d['nomod_strength'] -= $data['nomod_strength'] + $lvlmod; - $d['nomod_stamina'] -= $data['nomod_stamina'] + $lvlmod; - $d['nomod_intellect'] -= $data['nomod_intellect'] + $lvlmod; - $d['nomod_spirit'] -= $data['nomod_spirit'] + $lvlmod; - - $d['percent_attackpower'] -= $data['percent_attackpower']; - $d['nomod_attackpower'] -= $data['nomod_attackpower']; - - $d['percent_armor'] -= $data['percent_armor']; - $d['nomod_armor'] -= $data['nomod_armor']; - - $d['nomod_dodge'] -= $data['nomod_dodge']; - $d['nomod_parry'] -= $data['nomod_parry']; - $d['hit'] -= $data['hit']; - $d['nomod_crit'] -= $data['nomod_crit']; - - $d['percent_damage_min'] -= $data['percent_damage_min']; - $d['percent_damage_max'] -= $data['percent_damage_max']; - $d['nomod_damage_min'] -= $data['nomod_damage_min']; - $d['nomod_damage_max'] -= $data['nomod_damage_max']; - - $d['percent_ranged_damage_min'] -= $data['percent_ranged_damage_min']; - $d['percent_ranged_damage_max'] -= $data['percent_ranged_damage_max']; - $d['nomod_ranged_damage_min'] -= $data['nomod_ranged_damage_min']; - $d['nomod_ranged_damage_max'] -= $data['nomod_ranged_damage_max']; - - $d['percent_heal_min'] -= $data['percent_heal_min']; - $d['percent_heal_max'] -= $data['percent_heal_max']; - $d['nomod_heal_min'] -= $data['nomod_heal_min']; - $d['nomod_heal_max'] -= $data['nomod_heal_max']; - - $d['life_leech'] -= $data['life_leech']; - $d['mana_leech'] -= $data['mana_leech']; - - $this->hero = $d; - } - - //Hero stat calc functions end - - function hero_find_empty_bagspace($data, $key = 'id') - { - if (!$data) - return 0; - - $found = FALSE; - for ($i = 0; $i < self::INVENTORY_MAX; $i++) + public function hero_find_empty_bagspace($data, $key = 'id') { - foreach ($data as $row) - { - if ($row[$key] == $i) - { - $found = TRUE; - break; - } - } + if (!$data) { + return 0; + } - if ($found) - { - $found = FALSE; - } - else - { - return $i; - } + $found = false; + for ($i = 0; $i < self::INVENTORY_MAX; $i++) { + foreach ($data as $row) { + if ($row[$key] == $i) { + $found = true; + break; + } + } + + if ($found) { + $found = false; + } else { + return $i; + } + } + + return false; } - return FALSE; - } + //Hero Functions end - //Hero Functions end + //admin sql functions + public function _create_sql($sql) + { + $this->load->helper('file'); - //admin sql functions - function _create_sql($sql) - { - $this->load->helper('file'); + $time = time(); - $time = time(); + $file = './sql/' .$time . '.sql'; - $file = './sql/' .$time . '.sql'; + write_file($file, $sql); - write_file($file, $sql); + $this->_update_db_version($time); + } - $this->_update_db_version($time); - } + public function _update_db_version($time) + { + $sql = "UPDATE db_version SET version='$time' WHERE id='1'"; - function _update_db_version($time) - { - $sql = "UPDATE db_version SET version='$time' WHERE id='1'"; + $this->db->query($sql); + } - $this->db->query($sql); - } + public function _create_sql_debug($sql) + { + $this->load->helper('file'); - function _create_sql_debug($sql) - { - $this->load->helper('file'); + $time = time(); - $time = time(); + $file = './sql/debug_' .$time . '.sql'; - $file = './sql/debug_' .$time . '.sql'; - - write_file($file, $sql); - } - - //admin sql functions end + write_file($file, $sql); + } + //admin sql functions end } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/helpers/class_helper.php b/Mourne-CI/application/helpers/class_helper.php index e425091..c5d7ad0 100755 --- a/Mourne-CI/application/helpers/class_helper.php +++ b/Mourne-CI/application/helpers/class_helper.php @@ -1,30 +1,30 @@ - $hero['level']) - { - $data['message'] = 'Your level is too low to use that item.'; - return $data; - } + 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; - $data['allowed_slot1'] = 6; - return $data; - } - elseif ($item['subtype'] == 12) - { - $data['can'] = TRUE; - $data['allowed_slot1'] = 12; - $data['allowed_slot2'] = 13; - return $data; - } - 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; - $data['allowed_slot1'] = 19; - return $data; - } - } + if ($item['subtype'] == 6) { + $data['can'] = true; + $data['allowed_slot1'] = 6; + return $data; + } elseif ($item['subtype'] == 12) { + $data['can'] = true; + $data['allowed_slot1'] = 12; + $data['allowed_slot2'] = 13; + return $data; + } 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; + $data['allowed_slot1'] = 19; + return $data; + } + } - $datatype = array( + $datatype = array( //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( + $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; - $data['allowed_slot1'] = $dataeqslots[$item['subtype']][0]; - $data['allowed_slot2'] = $dataeqslots[$item['subtype']][1]; - return $data; - } - else - { - $data['can'] = FALSE; - $data['message'] = "You don't have the required proficiency to use that item."; - return $data; - } - } + //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; + $data['allowed_slot1'] = $dataeqslots[$item['subtype']][0]; + $data['allowed_slot2'] = $dataeqslots[$item['subtype']][1]; + return $data; + } else { + $data['can'] = false; + $data['message'] = "You don't have the required proficiency to use that item."; + return $data; + } + } - $dataclasswep = array( + $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( + //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; - $data['allowed_slot1'] = $datawep[$item['subsubtype']][0]; - $data['allowed_slot2'] = $datawep[$item['subsubtype']][1]; - $data['two_handed'] = $datawep[$item['subsubtype']][2]; - return $data; - } - } + 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]; + return $data; + } + } - $data['can'] = FALSE; - $data['message'] = 'You cannot use that item.'; - return $data; - } -} \ No newline at end of file + $data['can'] = false; + $data['message'] = 'You cannot use that item.'; + return $data; + } +} diff --git a/Mourne-CI/application/helpers/event_helper.php b/Mourne-CI/application/helpers/event_helper.php index 55e80f0..76b1bd0 100755 --- a/Mourne-CI/application/helpers/event_helper.php +++ b/Mourne-CI/application/helpers/event_helper.php @@ -1,16 +1,20 @@ -config->site_url($uri); - } +if (! function_exists('isite_url')) { + function isite_url($uri = '') + { + $CI =& get_instance(); + return $CI->config->site_url($uri); + } } //addign img/prefix, so I don't have to in every call -if ( ! function_exists('ibase_url')) -{ - function ibase_url($uri = '') - { - $muri = 'img/' . $uri; - $CI =& get_instance(); - return $CI->config->base_url($muri); - } -} \ No newline at end of file +if (! function_exists('ibase_url')) { + function ibase_url($uri = '') + { + $muri = 'img/' . $uri; + $CI =& get_instance(); + return $CI->config->base_url($muri); + } +} diff --git a/Mourne-CI/application/models/ai_model.php b/Mourne-CI/application/models/ai_model.php index d1542de..64db6ec 100755 --- a/Mourne-CI/application/models/ai_model.php +++ b/Mourne-CI/application/models/ai_model.php @@ -1,145 +1,127 @@ parse_settings(); - - if (!$this->settings['on']) - return 'AI is off'; - - $sql = "SELECT * FROM ai_villages WHERE attacked='0'"; - - $q = $this->db->query($sql); - - $ai_village_not_attacked = $q->num_rows(); - - $log = "ai_villages query returned " . $ai_village_not_attacked . " rows. \n"; - - $ai_villages = $q->result_array(); - - $attacking_num = $this->settings['max_attack_village_limit']; - - //determining how much will attack - if ($this->settings['attack_village_rand']) + public function __construct() { - $a = rand(0, $this->settings['attack_village_rand']); - - $attacking_num -= $a; + parent::__construct(); } - $log .= $attacking_num . " villages attacking. \n"; - - $reset = FALSE; - - //resetting ai_villages's attack field if everything will be set to attacked - if ($ai_village_not_attacked < $attacking_num) + public function attack() { - $attacking_num = $ai_village_not_attacked; + $this->parse_settings(); - $reset = TRUE; - } + if (!$this->settings['on']) { + return 'AI is off'; + } - //determining which villages are going to attack - for ($i = 0; $i < $attacking_num; $i++) - { - $found = FALSE; + $sql = "SELECT * FROM ai_villages WHERE attacked='0'"; - while (!$found) - { - foreach ($ai_villages as $row) - { - $r = rand(1, 100); + $q = $this->db->query($sql); - if ($r > 50 && !isset($s[$row['id']])) - { - $s[$row['id']] = TRUE; - $data[] = $row; - $found = TRUE; - break; - } - } - } - } + $ai_village_not_attacked = $q->num_rows(); - //saving to the db that they are attacked - if (!$reset) - { - $sql = "UPDATE ai_villages SET attacked='1' WHERE "; + $log = "ai_villages query returned " . $ai_village_not_attacked . " rows. \n"; - $first = TRUE; - foreach ($data as $row) - { - if ($first) - $first = FALSE; - else - $sql .= " OR "; - - $sql .= "id='" . $row['id'] . "'"; - } + $ai_villages = $q->result_array(); - $this->db->query($sql); - } - else - { - $sql = "UPDATE ai_villages SET attacked='0'"; - $this->db->query($sql); - $log .= "ai_villages's attacked field reseted.\n"; - } + $attacking_num = $this->settings['max_attack_village_limit']; - //getting ai_units - $sql = "SELECT * FROM ai_units"; - $q = $this->db->query($sql); - $num_ai_units = $q->num_rows(); - $res = $q->result_array(); + //determining how much will attack + if ($this->settings['attack_village_rand']) { + $a = rand(0, $this->settings['attack_village_rand']); + + $attacking_num -= $a; + } - if ($this->settings['ai_unit_max_diff'] < $num_ai_units) - { - $num = 0; - $d = FALSE; + $log .= $attacking_num . " villages attacking. \n"; + + $reset = false; - while ($num != $this->settings['ai_unit_max_diff']) - { - foreach ($res as $row) - { - if (!isset($d[$row['id']])) - { - $r = rand(1,50); - if ($r > 50) - { - $ai_units[] = $row; - $d[$row['id']] = TRUE; - $num++; - break; - } - } - } - } - - } - else - { - $ai_units = $res; - } + //resetting ai_villages's attack field if everything will be set to attacked + if ($ai_village_not_attacked < $attacking_num) { + $attacking_num = $ai_village_not_attacked; - //adding villages to log - $log .= "Attacking villages: \n"; - foreach ($data as $row) - { - $log .= $row['name'] . "(" .$row['X'] . " " . $row['Y'] . ") \n"; - } + $reset = true; + } - //sending attackers - foreach ($data as $row) - { - $sql = "SELECT map.X,map.Y,villages.* + //determining which villages are going to attack + for ($i = 0; $i < $attacking_num; $i++) { + $found = false; + + while (!$found) { + foreach ($ai_villages as $row) { + $r = rand(1, 100); + + if ($r > 50 && !isset($s[$row['id']])) { + $s[$row['id']] = true; + $data[] = $row; + $found = true; + break; + } + } + } + } + + //saving to the db that they are attacked + if (!$reset) { + $sql = "UPDATE ai_villages SET attacked='1' WHERE "; + + $first = true; + foreach ($data as $row) { + if ($first) { + $first = false; + } else { + $sql .= " OR "; + } + + $sql .= "id='" . $row['id'] . "'"; + } + + $this->db->query($sql); + } else { + $sql = "UPDATE ai_villages SET attacked='0'"; + $this->db->query($sql); + $log .= "ai_villages's attacked field reseted.\n"; + } + + //getting ai_units + $sql = "SELECT * FROM ai_units"; + $q = $this->db->query($sql); + $num_ai_units = $q->num_rows(); + $res = $q->result_array(); + + if ($this->settings['ai_unit_max_diff'] < $num_ai_units) { + $num = 0; + $d = false; + + while ($num != $this->settings['ai_unit_max_diff']) { + foreach ($res as $row) { + if (!isset($d[$row['id']])) { + $r = rand(1, 50); + if ($r > 50) { + $ai_units[] = $row; + $d[$row['id']] = true; + $num++; + break; + } + } + } + } + } else { + $ai_units = $res; + } + + //adding villages to log + $log .= "Attacking villages: \n"; + foreach ($data as $row) { + $log .= $row['name'] . "(" .$row['X'] . " " . $row['Y'] . ") \n"; + } + + //sending attackers + 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') WHERE (map.type = 3 AND @@ -148,162 +130,155 @@ class Ai_model extends MO_Model AND map.Y > '" . ($row['Y'] - 24) . "' AND map.Y < '" . ($row['Y'] + 24) . "')"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - //no villages in range - if (!$q->num_rows()) - continue; + //no villages in range + if (!$q->num_rows()) { + continue; + } - $log .= $row['name'] . " is attacking: \n"; + $log .= $row['name'] . " is attacking: \n"; - $res = $q->result_array(); - - //sending attackers - 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"; + $res = $q->result_array(); + + //sending attackers + 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) - { - $a = ($rrow['score'] / $unit['rate']) / $unit['per_score']; - $num = floor($a); + foreach ($ai_units as $unit) { + $a = ($rrow['score'] / $unit['rate']) / $unit['per_score']; + $num = floor($a); - $log .= $unit['name'] . "->" . $num . "\n"; + $log .= $unit['name'] . "->" . $num . "\n"; - $send[] = array('unitid' => $unit['id'], - 'num' => $num); - } + $send[] = array('unitid' => $unit['id'], + 'num' => $num); + } - $this->send_attack($send, $row, $rrow); - } - } + $this->send_attack($send, $row, $rrow); + } + } + } + + $this->load->helper('file'); + + $f = './logs/ai_log/log_' . time() . '.txt'; + + write_file($f, $log); + + return $log; } - $this->load->helper('file'); - - $f = './logs/ai_log/log_' . time() . '.txt'; - - write_file($f, $log); - - return $log; - - } - - function send_attack($send, $ai_village, $village) - { - $villageid = $village['id']; - - $sql = "SELECT max(attackid) AS attackid FROM attacks WHERE villageid='$villageid'"; - $q = $this->db->query($sql); - - $res = $q->row_array(); - - if ($res['attackid']) + public function send_attack($send, $ai_village, $village) { - $atkid = ($res['attackid'] + 1); - } - else - $atkid = 1; + $villageid = $village['id']; - $first = TRUE; - $sql = "INSERT INTO attacks VALUES"; - foreach ($send as $row) + $sql = "SELECT max(attackid) AS attackid FROM attacks WHERE villageid='$villageid'"; + $q = $this->db->query($sql); + + $res = $q->row_array(); + + if ($res['attackid']) { + $atkid = ($res['attackid'] + 1); + } else { + $atkid = 1; + } + + $first = true; + $sql = "INSERT INTO attacks VALUES"; + foreach ($send as $row) { + if ($first) { + $first = false; + } else { + $sql .= ','; + } + + $sql .= "(default, '$villageid', '$atkid', '" . $row['unitid'] . "', '" . $row['num']. "')"; + } + + $sql .= ";"; + + $this->db->query($sql); + + //calculate distance + $dist = sqrt(pow($ai_village['X'] - $village['X'], 2) + pow($ai_village['Y'] - $village['Y'], 2)); + + //15 min 1 square + $time = $dist * 900; + $r = rand(3600, 10800); + $end = $time + $r; + + //todo remove + $end = 20; + + //attack random sides + $dir = rand(1, 4); + + $ev['villageid'] = $villageid; + $ev['slotid'] = 0; + $ev['type'] = parent::EVENT_ATTACK; + $ev['time'] = $end; + $ev['data1'] = $atkid; + $ev['data2'] = $dir; + + $this->add_event($ev); + } + + public function parse_settings() { - if ($first) - $first = FALSE; - else - $sql .= ','; + $sql = "SELECT * FROM ai_settings"; - $sql .= "(default, '$villageid', '$atkid', '" . $row['unitid'] . "', '" . $row['num']. "')"; + $q = $this->db->query($sql); + + $res = $q->result_array(); + + foreach ($res as $row) { + $data[$row['setting']] = $row['value']; + } + + $this->settings = $data; } - $sql .= ";"; - - $this->db->query($sql); - - //calculate distance - $dist = sqrt(pow($ai_village['X'] - $village['X'], 2) + pow($ai_village['Y'] - $village['Y'], 2)); - - //15 min 1 square - $time = $dist * 900; - $r = rand(3600, 10800); - $end = $time + $r; - - //todo remove - $end = 20; - - //attack random sides - $dir = rand(1, 4); - - $ev['villageid'] = $villageid; - $ev['slotid'] = 0; - $ev['type'] = parent::EVENT_ATTACK; - $ev['time'] = $end; - $ev['data1'] = $atkid; - $ev['data2'] = $dir; - - $this->add_event($ev); - - } - - function parse_settings() - { - $sql = "SELECT * FROM ai_settings"; - - $q = $this->db->query($sql); - - $res = $q->result_array(); - - foreach ($res as $row) + public function get_unit_list_drop_admin() { - $data[$row['setting']] = $row['value']; + $sql = "SELECT * FROM ai_units"; + + $q = $this->db->query($sql); + + $res = $q->result_array(); + + $data[0] = 'Nothing'; + + foreach ($res as $row) { + $data[$row['id']] = $row['name']; + } + + return $data; } - $this->settings = $data; - } - - function get_unit_list_drop_admin() - { - $sql = "SELECT * FROM ai_units"; - - $q = $this->db->query($sql); - - $res = $q->result_array(); - - $data[0] = 'Nothing'; - - foreach ($res as $row) + public function list_units_admin() { - $data[$row['id']] = $row['name']; + $sql = "SELECT * FROM ai_units"; + + $q = $this->db->query($sql); + + return $q->result_array(); } - return $data; - } + public function get_unit_admin($id) + { + $sql = "SELECT * FROM ai_units WHERE id='$id'"; + $q = $this->db->query($sql); - function list_units_admin() - { - $sql = "SELECT * FROM ai_units"; + return $q->row_array(); + } - $q = $this->db->query($sql); - - return $q->result_array(); - } - - function get_unit_admin($id) - { - $sql = "SELECT * FROM ai_units WHERE id='$id'"; - $q = $this->db->query($sql); - - return $q->row_array(); - } - - function add_unit_admin($data) - { - $sql = "INSERT INTO ai_units + public function add_unit_admin($data) + { + $sql = "INSERT INTO ai_units VALUES(default, '" . $data['name'] . "', '" . $data['icon'] . "', @@ -317,14 +292,14 @@ class Ai_model extends MO_Model '" . $data['strong_against'] . "', '" . $data['weak_against'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function edit_unit_admin($data) - { - $sql = "UPDATE ai_units + public function edit_unit_admin($data) + { + $sql = "UPDATE ai_units SET name='" . $data['name'] . "', icon='" . $data['icon'] . "', ability='" . $data['ability'] . "', @@ -338,52 +313,52 @@ class Ai_model extends MO_Model weak_against='" . $data['weak_against'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_settings_list_admin() - { - $sql = "SELECT * FROM ai_settings"; + public function get_settings_list_admin() + { + $sql = "SELECT * FROM ai_settings"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function get_setting_admin($id) - { - $sql = "SELECT * FROM ai_settings WHERE id='$id'"; - $q = $this->db->query($sql); + public function get_setting_admin($id) + { + $sql = "SELECT * FROM ai_settings WHERE id='$id'"; + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function edit_setting_admin($data) - { - $sql = "UPDATE ai_settings + public function edit_setting_admin($data) + { + $sql = "UPDATE ai_settings SET setting='" . $data['setting'] . "', value='" . $data['value'] . "', description='" . $data['description'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function add_setting_admin($data) - { - $sql = "INSERT INTO ai_settings + public function add_setting_admin($data) + { + $sql = "INSERT INTO ai_settings VALUES(default, '" . $data['setting'] . "', '" . $data['value'] . "' , '" . $data['description'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/assignment_model.php b/Mourne-CI/application/models/assignment_model.php index 11c41df..d9b7f59 100755 --- a/Mourne-CI/application/models/assignment_model.php +++ b/Mourne-CI/application/models/assignment_model.php @@ -2,230 +2,235 @@ class Assignment_model extends MO_Model { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function assign_unit($assid, $num, $slotid, $res, $villageid, $userid) - { - $this->set_resources($res); + public function assign_unit($assid, $num, $slotid, $res, $villageid, $userid) + { + $this->set_resources($res); - //check if there is building in that slot - $sql = "SELECT buildings.* FROM village_buildings + //check if there is building in that slot + $sql = "SELECT buildings.* FROM village_buildings INNER JOIN buildings ON village_buildings.buildingid=buildings.id WHERE slotid='$slotid' AND villageid='$villageid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return 1; + if (!$q->num_rows()) { + return 1; + } - $building = $q->row_array(); + $building = $q->row_array(); - //check if there is already an assignment in which case we just deassign - //in this case num will be 0 unless they play with the form, - //but we shouldn't care about that since the user can write 0 into the form - $sql = "SELECT * FROM building_assignments + //check if there is already an assignment in which case we just deassign + //in this case num will be 0 unless they play with the form, + //but we shouldn't care about that since the user can write 0 into the form + $sql = "SELECT * FROM building_assignments WHERE assignmentid='$assid' AND slotid='$slotid' AND villageid='$villageid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows()) - { - //the user wants to just deassign - $ass = $q->row_array(); + if ($q->num_rows()) { + //the user wants to just deassign + $ass = $q->row_array(); - //delete assignment - $sql = "DELETE FROM building_assignments WHERE id='" . $ass['id'] . "'"; - $this->db->query($sql); + //delete assignment + $sql = "DELETE FROM building_assignments WHERE id='" . $ass['id'] . "'"; + $this->db->query($sql); - //giving back units - - //getting units - $sql = "SELECT * FROM village_units + //giving back units + + //getting units + $sql = "SELECT * FROM village_units WHERE villageid='$villageid' AND userid='$userid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows()) - { - $units = $q->result_array(); - } - else - { - $units = FALSE; - } + if ($q->num_rows()) { + $units = $q->result_array(); + } else { + $units = false; + } - $found = FALSE; + $found = false; - if ($units) - { - foreach ($units as $row) - { - if ($row['unitid'] == $ass['unitid']) - { - $found = TRUE; - $fdata = $row['id']; - } - } - } + if ($units) { + foreach ($units as $row) { + if ($row['unitid'] == $ass['unitid']) { + $found = true; + $fdata = $row['id']; + } + } + } - if ($found) - { - $sql = "UPDATE village_units + if ($found) { + $sql = "UPDATE village_units SET unitcount = unitcount + '". $ass['num_unit'] . "' WHERE id='$fdata'"; - } - else - { - $sql = "INSERT INTO village_units + } else { + $sql = "INSERT INTO village_units VALUES(default, '$userid', '$villageid', '" . $ass['unitid'] . "', '" . $ass['num_unit'] . "')"; - } + } - $this->db->query($sql); + $this->db->query($sql); - //substract the bonuses - $this->substract_modifiers($assid, $villageid, 'assignment', - $ass['num_bonus']); + //substract the bonuses + $this->substract_modifiers( + $assid, + $villageid, + 'assignment', + $ass['num_bonus'] + ); - $this->write_resources(); + $this->write_resources(); - //taking away spells - $sql = "DELETE FROM building_spells + //taking away spells + $sql = "DELETE FROM building_spells WHERE assignmentid='$assid' AND slotid='$slotid' AND villageid='$villageid'"; - $this->db->query($sql); + $this->db->query($sql); - return 0; - } + return 0; + } - //check if assignment exists - $sql = "SELECT * FROM assignments WHERE id='$assid'"; - $q = $this->db->query($sql); + //check if assignment exists + $sql = "SELECT * FROM assignments WHERE id='$assid'"; + $q = $this->db->query($sql); - if (!$q->num_rows()) - return 2; + if (!$q->num_rows()) { + return 2; + } - $ass = $q->row_array(); + $ass = $q->row_array(); - //checking technology - 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'])) - return 3; + //checking technology + 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'])) { + return 3; + } - //getting unit - $sql = "SELECT * FROM village_units + //getting unit + $sql = "SELECT * FROM village_units WHERE unitid='" . $ass['unitid'] . "' AND userid='$userid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return 4; + if (!$q->num_rows()) { + return 4; + } - $unit = $q->row_array(); + $unit = $q->row_array(); - //it probably shouldn't happen but who knows - if (!$unit['unitcount']) - return 5; + //it probably shouldn't happen but who knows + if (!$unit['unitcount']) { + return 5; + } - //if the user just clicks on the assign we should assign max - if (!$num) - $num = $ass['max']; + //if the user just clicks on the assign we should assign max + if (!$num) { + $num = $ass['max']; + } - //we shouldn't assign more than allowed - if ($ass['max'] < $num) - $num = $ass['max']; + //we shouldn't assign more than allowed + if ($ass['max'] < $num) { + $num = $ass['max']; + } - //determining how much can be assigned - if ($unit['unitcount'] < $num) - $num = $unit['unitcount']; + //determining how much can be assigned + if ($unit['unitcount'] < $num) { + $num = $unit['unitcount']; + } - //determining number of bonuses granted - $num_bonus = floor(($num / $ass['bonus_per_assigned'])); + //determining number of bonuses granted + $num_bonus = floor(($num / $ass['bonus_per_assigned'])); - $count = ($unit['unitcount'] - $num); + $count = ($unit['unitcount'] - $num); - //updating unit field in db - if ($count <= 0) - { - $sql = "DELETE FROM village_units WHERE id='" . $unit['id'] . "'"; - } - else - { - $sql = "UPDATE village_units + //updating unit field in db + if ($count <= 0) { + $sql = "DELETE FROM village_units WHERE id='" . $unit['id'] . "'"; + } else { + $sql = "UPDATE village_units SET unitcount=unitcount - '$num' WHERE id='" . $unit['id'] . "'"; - } + } - $this->db->query($sql); + $this->db->query($sql); - //adding assignment - $sql = "INSERT INTO building_assignments + //adding assignment + $sql = "INSERT INTO building_assignments VALUES(default, '$villageid', '$slotid', '" . $unit['unitid'] . "', '$num', '" . $assid . "', '$num_bonus')"; - $this->db->query($sql); + $this->db->query($sql); - //grant resource bonus - $this->add_modifiers($assid, $villageid, 'assignment', $num_bonus); - $this->write_resources(); + //grant resource bonus + $this->add_modifiers($assid, $villageid, 'assignment', $num_bonus); + $this->write_resources(); - //assignment has spell - if (!$ass['spellid']) - return 0; + //assignment has spell + if (!$ass['spellid']) { + return 0; + } - /* - //only give spells if bonus is granted - if (!$num_bonus) - return 0; - */ + /* + //only give spells if bonus is granted + if (!$num_bonus) + return 0; + */ - //only give spell if max unit assigned - if (!($ass['max'] == $num)) - return 0; + //only give spell if max unit assigned + if (!($ass['max'] == $num)) { + return 0; + } - //granting spell - $sql = "INSERT INTO building_spells + //granting spell + $sql = "INSERT INTO building_spells VALUES(default, '$villageid', '$slotid', '$assid', '" . $ass['spellid'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - return 0; - } + return 0; + } - function get_assignments($slotid, $villageid, $userid) - { - if ($slotid > parent::TOTAL_BUILDINGS) - return 1; //that shouldn't happen + public function get_assignments($slotid, $villageid, $userid) + { + if ($slotid > parent::TOTAL_BUILDINGS) { + return 1; + } //that shouldn't happen - $sql = "SELECT buildings.* FROM village_buildings + $sql = "SELECT buildings.* FROM village_buildings INNER JOIN buildings ON village_buildings.buildingid = buildings.id WHERE village_buildings.slotid='$slotid' AND village_buildings.villageid='$villageid'"; - $q = $this->db->query($sql); + $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(); + $res = $q->row_array(); - //getting assignment data - $sql = "SELECT assignments.*,units.name + //getting assignment data + $sql = "SELECT assignments.*,units.name FROM assignments INNER JOIN units ON assignments.unitid=units.id WHERE assignments.id='" . $res['assignment1'] . "' @@ -234,97 +239,87 @@ class Assignment_model extends MO_Model OR assignments.id='" . $res['assignment4'] . "' OR assignments.id='" . $res['assignment5'] . "'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - { - $data['assigndata'] = FALSE; //building doesn't have assignments - return $data; - } + if (!$q->num_rows()) { + $data['assigndata'] = false; //building doesn't have assignments + return $data; + } - $adata = $q->result_array(); + $adata = $q->result_array(); - $tech = $this->get_village_technologies($villageid, $slotid); + $tech = $this->get_village_technologies($villageid, $slotid); - foreach ($adata as $row) - { - if ($this->have_technology($tech, $row['req_tech'])) - $data['assigndata'][] = $row; - } + foreach ($adata as $row) { + if ($this->have_technology($tech, $row['req_tech'])) { + $data['assigndata'][] = $row; + } + } - if (!isset($data['assigndata'])) - { - $data['assigndata'] = FALSE; - return $data; - } + if (!isset($data['assigndata'])) { + $data['assigndata'] = false; + return $data; + } - //getting assigned data - $sql = "SELECT * FROM building_assignments + //getting assigned data + $sql = "SELECT * FROM building_assignments WHERE slotid='$slotid' AND villageid='$villageid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - { - $data['assigned'] = FALSE; - } - else - { - $data['assigned'] = $q->result_array(); - } + if (!$q->num_rows()) { + $data['assigned'] = false; + } else { + $data['assigned'] = $q->result_array(); + } - $data['building'] = $res; + $data['building'] = $res; - //getting units - $sql = "SELECT * FROM village_units + //getting units + $sql = "SELECT * FROM village_units WHERE villageid='$villageid' AND userid='$userid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows) - { - $data['units'] = $q->result_array(); - } - else - { - $data['units'] = FALSE; + if ($q->num_rows) { + $data['units'] = $q->result_array(); + } else { + $data['units'] = false; + } + + return $data; } - return $data; - - } - - function get_assignment_list_drop_admin() - { - $sql = "SELECT * FROM assignments"; - $q = $this->db->query($sql); - - $res = $q->result_array(); - - $data[0] = 'Nothing'; - - foreach ($res as $row) + public function get_assignment_list_drop_admin() { - $data[$row['id']] = $row['description']; + $sql = "SELECT * FROM assignments"; + $q = $this->db->query($sql); + + $res = $q->result_array(); + + $data[0] = 'Nothing'; + + foreach ($res as $row) { + $data[$row['id']] = $row['description']; + } + + return $data; } - return $data; - } + public function get_assignments_admin() + { + $sql = "SELECT * FROM assignments"; - function get_assignments_admin() - { - $sql = "SELECT * FROM assignments"; + $q = $this->db->query($sql); - $q = $this->db->query($sql); + return $q->result_array(); + } - return $q->result_array(); - } - - function add_assignment_admin($data) - { - $sql = "INSERT INTO assignments + public function add_assignment_admin($data) + { + $sql = "INSERT INTO assignments VALUES (default, '" . $data['unitid'] . "', '" . $data['max'] . "', @@ -348,14 +343,14 @@ class Assignment_model extends MO_Model '" . $data['mod_percent_mana'] . "', '" . $data['description'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function edit_assignment_admin($data) - { - $sql = "UPDATE assignments + public function edit_assignment_admin($data) + { + $sql = "UPDATE assignments SET unitid='" . $data['unitid'] . "', max='" . $data['max'] . "', bonus_per_assigned='" . $data['bonus_per_assigned'] . "', @@ -379,18 +374,18 @@ class Assignment_model extends MO_Model description='" . $data['description'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_assignment_admin($id) - { - $sql = "SELECT * FROM assignments WHERE id='$id'"; + public function get_assignment_admin($id) + { + $sql = "SELECT * FROM assignments WHERE id='$id'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } } //nowhitesp diff --git a/Mourne-CI/application/models/building_model.php b/Mourne-CI/application/models/building_model.php index ff60f1a..32f9dbc 100755 --- a/Mourne-CI/application/models/building_model.php +++ b/Mourne-CI/application/models/building_model.php @@ -1,173 +1,162 @@ db->query($sql); + public function get_building($buildingid) + { + $sql = "SELECT * FROM buildings WHERE id='$buildingid'"; + $q = $this->db->query($sql); - if ($q->num_rows()) - return $q->row_array(); + if ($q->num_rows()) { + return $q->row_array(); + } - return FALSE; - } + return false; + } - function set_build_in_progress($slotid, $villageid) - { - $sql = "INSERT INTO village_buildings + public function set_build_in_progress($slotid, $villageid) + { + $sql = "INSERT INTO village_buildings VALUES(default, '$villageid', '$slotid', '2')"; - $this->db->query($sql); - } + $this->db->query($sql); + } - function building_list($villageid) - { - $sql = "SELECT * FROM buildings + public function building_list($villageid) + { + $sql = "SELECT * FROM buildings WHERE rank='1'"; - $q = $this->db->query($sql); - $res = $q->result_array(); + $q = $this->db->query($sql); + $res = $q->result_array(); - $sql = "SELECT * FROM village_buildings WHERE villageid='$villageid'"; - $q = $this->db->query($sql); - $vb = $q->result_array(); + $sql = "SELECT * FROM village_buildings WHERE villageid='$villageid'"; + $q = $this->db->query($sql); + $vb = $q->result_array(); - //checking requirements - foreach ($res as $row) - { - if ($this->can_build($villageid, $row, $vb, FALSE)) - { - $build[] = $row; - } + //checking requirements + foreach ($res as $row) { + if ($this->can_build($villageid, $row, $vb, false)) { + $build[] = $row; + } + } + + //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']) { + $data[] = $row; + break; + } + } + } else { + $data[] = $row; + } + } + + return $data; } - //requirements are met - $tech = $this->get_village_technologies($villageid); - - foreach ($build as $row) + //returns 0 if upgrade in progress + //returns 1 if technology requirement not met + //returns 2 if not enough resources + //returns 3 if can be built + public function can_be_upgraded($event, $res, $building, $villageid, $query = false) { - if ($row['req_tech']) - { - foreach ($tech as $trow) - { - if ($row['req_tech'] == $trow['technologyid']) - { - $data[] = $row; - break; - } - } - } - else - { - $data[] = $row; - } - } - - return $data; - } - - //returns 0 if upgrade in progress - //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) - { - //this means we have to get building from the db, + 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) { + return 0; + } + + 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']) { + return 2; + } + + //can be built + return 3; } - //check if upgrade in progress - //we can just do this, since event is filtered to update events - if ($event) + public function can_build($villageid, $buildingid, $data = 0, $is_buildingid = true) { - return 0; + //STUB requirements aren't implemented + return true; } - 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']) + public function is_valid_slot($slotid, $villageid) { - return 2; - } + if ($slotid > parent::TOTAL_BUILDINGS) { + return false; + } - //can be built - return 3; - } - - function can_build($villageid, $buildingid, $data = 0, $is_buildingid = TRUE) - { - //STUB requirements aren't implemented - return TRUE; - } - - function is_valid_slot($slotid, $villageid) - { - if ($slotid > parent::TOTAL_BUILDINGS) - return FALSE; - - $sql = "SELECT id FROM village_buildings + $sql = "SELECT id FROM village_buildings WHERE villageid='$villageid' AND slotid='$slotid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows()) - return FALSE; + if ($q->num_rows()) { + return false; + } - return TRUE; - } - - function get_building_ranks_admin() - { - $sql = "SELECT * FROM buildings WHERE id > 2"; - $q = $this->db->query($sql); - - $res = $q->result_array(); - - $data[0] = 'Nothing'; - - foreach ($res as $row) - { - if (!$row['next_rank']) - { - $name = $row['name'] . ' R: ' . $row['rank']; - $data[$row['id']] = $name; - } - + return true; } - return $data; - } + public function get_building_ranks_admin() + { + $sql = "SELECT * FROM buildings WHERE id > 2"; + $q = $this->db->query($sql); - function list_buildings_admin() - { - $sql = "SELECT * FROM buildings"; - $q = $this->db->query($sql); + $res = $q->result_array(); - return $q->result_array(); - } + $data[0] = 'Nothing'; - function get_building_admin($id) - { - $sql = "SELECT * FROM buildings WHERE id='$id'"; - $q = $this->db->query($sql); + foreach ($res as $row) { + if (!$row['next_rank']) { + $name = $row['name'] . ' R: ' . $row['rank']; + $data[$row['id']] = $name; + } + } - return $q->row_array(); - } + return $data; + } - function edit_building_admin($data) - { + public function list_buildings_admin() + { + $sql = "SELECT * FROM buildings"; + $q = $this->db->query($sql); - $sql = "UPDATE buildings + return $q->result_array(); + } + + public function get_building_admin($id) + { + $sql = "SELECT * FROM buildings WHERE id='$id'"; + $q = $this->db->query($sql); + + return $q->row_array(); + } + + public function edit_building_admin($data) + { + $sql = "UPDATE buildings SET name='" . $data['name'] . "', description='" . $data['description'] . "', icon='" . $data['icon'] . "', @@ -209,14 +198,14 @@ class Building_model extends MO_Model tech_secondary_group='" . $data['tech_secondary_group'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function add_building_admin($data) - { - $sql = "INSERT INTO buildings VALUES(default, + public function add_building_admin($data) + { + $sql = "INSERT INTO buildings VALUES(default, '" . $data['name'] . "', '" . $data['description'] . "', '" . $data['icon'] . "', @@ -257,9 +246,9 @@ class Building_model extends MO_Model '" . $data['tech_group'] . "', '" . $data['tech_secondary_group'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/changelog_model.php b/Mourne-CI/application/models/changelog_model.php index 7bb94ca..4a404e9 100755 --- a/Mourne-CI/application/models/changelog_model.php +++ b/Mourne-CI/application/models/changelog_model.php @@ -2,54 +2,51 @@ class Changelog_model extends MO_Model { + public function __construct() + { + parent::__construct(); + } - function __construct() - { - parent::__construct(); - } + public function new_version($version) + { + $time = time(); - function new_version($version) - { - $time = time(); + $sql = "INSERT INTO changelog_versions VALUES(default, '$version', '$time')"; + $this->db->query($sql); + $this->_create_sql($sql); + } - $sql = "INSERT INTO changelog_versions VALUES(default, '$version', '$time')"; - $this->db->query($sql); - $this->_create_sql($sql); - } + public function new_commit($text) + { + $time = time(); - function new_commit($text) - { - $time = time(); + $sql = "SELECT id FROM changelog_versions ORDER BY id DESC LIMIT 1"; + $q = $this->db->query($sql); + $res = $q->row_array(); + $versionid = $res['id']; - $sql = "SELECT id FROM changelog_versions ORDER BY id DESC LIMIT 1"; - $q = $this->db->query($sql); - $res = $q->row_array(); - $versionid = $res['id']; + $sql = "INSERT INTO changelog_commits VALUES(default, '$versionid', '$text', '$time')"; + $this->db->query($sql); + $this->_create_sql($sql); + } - $sql = "INSERT INTO changelog_commits VALUES(default, '$versionid', '$text', '$time')"; - $this->db->query($sql); - $this->_create_sql($sql); - } - - function get_versions() - { - $sql = "SELECT * FROM changelog_versions ORDER BY timestamp DESC"; - $q = $this->db->query($sql); + public function get_versions() + { + $sql = "SELECT * FROM changelog_versions ORDER BY timestamp DESC"; + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function get_commits() - { - $sql = "SELECT * FROM changelog_commits ORDER BY timestamp DESC"; - $q = $this->db->query($sql); + public function get_commits() + { + $sql = "SELECT * FROM changelog_commits ORDER BY timestamp DESC"; + $q = $this->db->query($sql); - return $q->result_array(); - - } - + return $q->result_array(); + } } //nowhitesp diff --git a/Mourne-CI/application/models/cron_model.php b/Mourne-CI/application/models/cron_model.php index cdf0bcd..13417f3 100755 --- a/Mourne-CI/application/models/cron_model.php +++ b/Mourne-CI/application/models/cron_model.php @@ -1,10 +1,9 @@ weather = FALSE; - $this->weathers = FALSE; - $this->weather_change = FALSE; - - $this->village_data = FALSE; - } - - function update($vdata, $d = FALSE) - { - //TODO make helpers for get_next_event and alike functions and remove this if - if ($d) + public function __construct() { - $villageid = $vdata['id']; - $this->village_data = $vdata; - } - else - { - $villageid = $vdata; - $sql = "SELECT * FROM villages WHERE id='$villageid'"; - $q = $this->db->query($sql); - $this->village_data = $q->row_array(); + parent::__construct(); + $this->weather = false; + $this->weathers = false; + $this->weather_change = false; + + $this->village_data = false; } - $this->get_resources($villageid); - - $this->get_weathers(); - - $sql = "SELECT * FROM events WHERE villageid='$villageid' ORDER BY end ASC"; - $q = $this->db->query($sql); - - if (!$q->num_rows()) + public function update($vdata, $d = false) { - $this->update_resources(time()); - $this->update_weather(time()); - $this->write_weather(); - $this->write_resources(); - $data['resources'] = $this->resources; - $data['events'] = FALSE; - $data['weather'] = $this->weather; - return $data; + //TODO make helpers for get_next_event and alike functions and remove this if + if ($d) { + $villageid = $vdata['id']; + $this->village_data = $vdata; + } else { + $villageid = $vdata; + $sql = "SELECT * FROM villages WHERE id='$villageid'"; + $q = $this->db->query($sql); + $this->village_data = $q->row_array(); + } + + $this->get_resources($villageid); + + $this->get_weathers(); + + $sql = "SELECT * FROM events WHERE villageid='$villageid' ORDER BY end ASC"; + $q = $this->db->query($sql); + + if (!$q->num_rows()) { + $this->update_resources(time()); + $this->update_weather(time()); + $this->write_weather(); + $this->write_resources(); + $data['resources'] = $this->resources; + $data['events'] = false; + $data['weather'] = $this->weather; + return $data; + } + + $events = $q->result_array(); + + $time = time(); + $log = ""; + $i = 0; + foreach ($events as $row) { + if ($row['end'] < $time) { + switch ($row['type']) { + case (parent::EVENT_BUILD): + $this->update_resources($row['end']); + $this->update_weather($row['end']); + $this->_build_finished($row); + $this->delete_event($row['id']); + unset($events[$i]); + break; + case (parent::EVENT_UPGRADE): + $this->update_resources($row['end']); + $this->update_weather($row['end']); + $this->_upgrade_finished($row); + $this->delete_event($row['id']); + unset($events[$i]); + break; + case (parent::EVENT_CREATE): + $this->update_resources($row['end']); + $this->update_weather($row['end']); + $this->_create_finished($row); + $this->delete_event($row['id']); + unset($events[$i]); + break; + case (parent::EVENT_SPELL_END): + $this->update_resources($row['end']); + $this->update_weather($row['end']); + $this->_spell_end($row); + $this->delete_event($row['id']); + unset($events[$i]); + break; + case (parent::EVENT_RESEARCH_END): + $this->update_resources($row['end']); + $this->update_weather($row['end']); + $this->_research_end($row); + $this->delete_event($row['id']); + unset($events[$i]); + break; + case (parent::EVENT_ATTACK): + $this->update_resources($row['end']); + $this->update_weather($row['end']); + $this->_attack($row); + $this->delete_event($row['id']); + unset($events[$i]); + break; + default: + $this->update_resources($row['end']); + $this->update_weather($row['end']); + $this->delete_event($row['id']); + unset($events[$i]); + break; + } + } + + $i++; + } + + $this->update_resources(time()); + $this->update_weather(time()); + + $this->unitq_write(); + $this->write_resources(); + $this->write_weather(); + + //TODO this can probably simplified, need some research if the array will be unsetted when all of its + //content is unsetted + if (isset($events)) { + if ($events) { + //this is to start at index 0 + foreach ($events as $row) { + $fevents[] = $row; + } + + $data['events'] = $fevents; + } else { + $data['events'] = false; + } + } else { + $data['events'] = false; + } + + $data['resources'] = $this->resources; + $data['weather'] = $this->weather; + + return $data; } - $events = $q->result_array(); - - $time = time(); - $log = ""; - $i = 0; - foreach ($events as $row) + public function get_weathers() { - if ($row['end'] < $time) - { - switch ($row['type']) - { - case (parent::EVENT_BUILD): - $this->update_resources($row['end']); - $this->update_weather($row['end']); - $this->_build_finished($row); - $this->delete_event($row['id']); - unset($events[$i]); - break; - case (parent::EVENT_UPGRADE): - $this->update_resources($row['end']); - $this->update_weather($row['end']); - $this->_upgrade_finished($row); - $this->delete_event($row['id']); - unset($events[$i]); - break; - case (parent::EVENT_CREATE): - $this->update_resources($row['end']); - $this->update_weather($row['end']); - $this->_create_finished($row); - $this->delete_event($row['id']); - unset($events[$i]); - break; - case (parent::EVENT_SPELL_END): - $this->update_resources($row['end']); - $this->update_weather($row['end']); - $this->_spell_end($row); - $this->delete_event($row['id']); - unset($events[$i]); - break; - case (parent::EVENT_RESEARCH_END): - $this->update_resources($row['end']); - $this->update_weather($row['end']); - $this->_research_end($row); - $this->delete_event($row['id']); - unset($events[$i]); - break; - case (parent::EVENT_ATTACK): - $this->update_resources($row['end']); - $this->update_weather($row['end']); - $this->_attack($row); - $this->delete_event($row['id']); - unset($events[$i]); - break; - default: - $this->update_resources($row['end']); - $this->update_weather($row['end']); - $this->delete_event($row['id']); - unset($events[$i]); - break; - } - } + $sql = "SELECT * FROM weathers ORDER BY id ASC"; + $q = $this->db->query($sql); - $i++; + $this->weathers = $q->result_array(); + + foreach ($this->weathers as $row) { + if ($this->village_data['weather'] == $row['id']) { + $this->weather = $row; + break; + } + } } - $this->update_resources(time()); - $this->update_weather(time()); - - $this->unitq_write(); - $this->write_resources(); - $this->write_weather(); - - //TODO this can probably simplified, need some research if the array will be unsetted when all of its - //content is unsetted - if (isset($events)) + public function update_weather($time = false) { - if ($events) - { - //this is to start at index 0 - foreach ($events as $row) - { - $fevents[] = $row; - } + if (!$time) { + $time = time(); + } - $data['events'] = $fevents; - } - else - { - $data['events'] = FALSE; - } - } - else - { - $data['events'] = FALSE; - } + //first time weather calculation + if (!$this->village_data['last_weather_change'] && !$this->village_data['weather']) { + $r = rand(0, (sizeof($this->weathers) - 1)); - $data['resources'] = $this->resources; - $data['weather'] = $this->weather; + $this->weather = $this->weathers[$r]; - return $data; - } + $this->add_modifiers($this->weather, $this->village_data['id'], 'weather', 1, true); - function get_weathers() - { - $sql = "SELECT * FROM weathers ORDER BY id ASC"; - $q = $this->db->query($sql); + $this->village_data['last_weather_change'] = $time; + $this->village_data['weather'] = $this->weather['id']; - $this->weathers = $q->result_array(); + $this->weather_change = true; + } - foreach ($this->weathers as $row) - { - if ($this->village_data['weather'] == $row['id']) - { - $this->weather = $row; - break; - } - } - } + //if this happens its a spell, which means we have to only set this + if ($this->village_data['weather_change_to'] && ($time == time() || ($time + 1) == time() + || ($time + 2) == time())) { + //just making sure 1-2 sec delay can happen + $w = $this->village_data['weather_change_to']; - function update_weather($time = FALSE) - { - if (!$time) - $time = time(); + $this->substract_modifiers($this->weather, $this->village_data['id'], 'weather', 1, true); - //first time weather calculation - if (!$this->village_data['last_weather_change'] && !$this->village_data['weather']) - { - $r = rand(0, (sizeof($this->weathers) - 1)); + foreach ($this->weathers as $row) { + if ($row['id'] == $w) { + $this->weather = $row; + break; + } + } - $this->weather = $this->weathers[$r]; + $this->add_modifiers($this->weather, $this->village_data['id'], 'weather', 1, true); - $this->add_modifiers($this->weather, $this->village_data['id'], 'weather', 1, TRUE); + $this->village_data['last_weather_change'] = $time; + $this->village_data['weather'] = $this->weather['id']; + $this->village_data['weather_change_to'] = 0; - $this->village_data['last_weather_change'] = $time; - $this->village_data['weather'] = $this->weather['id']; + $this->weather_change = true; + } - $this->weather_change = TRUE; - } - - //if this happens its a spell, which means we have to only set this - if ($this->village_data['weather_change_to'] && ($time == time() || ($time + 1) == time() - || ($time + 2) == time())) - { - //just making sure 1-2 sec delay can happen - $w = $this->village_data['weather_change_to']; - - $this->substract_modifiers($this->weather, $this->village_data['id'], 'weather', 1, TRUE); - - foreach ($this->weathers as $row) - { - if ($row['id'] == $w) - { - $this->weather = $row; - break; - } - } - - $this->add_modifiers($this->weather, $this->village_data['id'], 'weather', 1, TRUE); - - $this->village_data['last_weather_change'] = $time; - $this->village_data['weather'] = $this->weather['id']; - $this->village_data['weather_change_to'] = 0; - - $this->weather_change = TRUE; - } - - //changing weather every hour - $nc = $this->village_data['last_weather_change'] + 3600; + //changing weather every hour + $nc = $this->village_data['last_weather_change'] + 3600; - //if more than a hour - if ($nc < $time) - { - $r = rand(0, (sizeof($this->weathers) - 1)); + //if more than a hour + if ($nc < $time) { + $r = rand(0, (sizeof($this->weathers) - 1)); - $this->substract_modifiers($this->weather, $this->village_data['id'], 'weather', 1, TRUE); + $this->substract_modifiers($this->weather, $this->village_data['id'], 'weather', 1, true); - $this->weather = $this->weathers[$r]; + $this->weather = $this->weathers[$r]; - $this->add_modifiers($this->weather, $this->village_data['id'], 'weather', 1, TRUE); + $this->add_modifiers($this->weather, $this->village_data['id'], 'weather', 1, true); - $this->village_data['last_weather_change'] = $time; - $this->village_data['weather'] = $this->weather['id']; + $this->village_data['last_weather_change'] = $time; + $this->village_data['weather'] = $this->weather['id']; - $this->weather_change = TRUE; + $this->weather_change = true; - if ($time == time() || ($time + 1) == time() || ($time + 2) == time()) - { - //process abilities here like fires - } + if ($time == time() || ($time + 1) == time() || ($time + 2) == time()) { + //process abilities here like fires + } + } } - } - function write_weather() - { - if (!$this->weather_change) - return; + public function write_weather() + { + if (!$this->weather_change) { + return; + } - $sql = "UPDATE villages + $sql = "UPDATE villages SET weather='" . $this->weather['id'] . "', last_weather_change='" . $this->village_data['last_weather_change'] . "', weather_change_to='" . $this->village_data['weather_change_to'] . "' WHERE id='" . $this->village_data['id'] . "'"; - $this->db->query($sql); - } - - function delete_event($evid) - { - $sql = "DELETE FROM events WHERE id='$evid'"; - $this->db->query($sql); - } - - //gets events by slotid - function get_events($slotid, $villageid) - { - $this->update($villageid); - - $sql = "SELECT * FROM events WHERE villageid='$villageid' AND slotid='$slotid'"; - $q = $this->db->query($sql); - - if ($q->num_rows()) - return $q->result_array(); - - return FALSE; - } - - function has_event($slotid, $villageid) - { - $this->update($villageid); - - $sql = "SELECT id FROM events WHERE villageid='$villageid' AND slotid='$slotid'"; - $q = $this->db->query($sql); - - if ($q->num_rows()) - return TRUE; - - return FALSE; - } - - //gets the next event for display - function get_next_event($villageid) - { - $this->update($villageid); - - $sql = "SELECT * FROM events WHERE villageid='$villageid'"; - $q = $this->db->query($sql); - - if (!$q->num_rows()) - return FALSE; - - $res = $q->result_array(); - - $min = 0; - - foreach ($res as $row) - { - if (!$min) - $min = $row; - - if ($row['end'] < $min['end']) - $min = $row; + $this->db->query($sql); } - return $min; - - } - - function check_event($event, $type) - { - if (!$event) - return FALSE; - - if ($type == 'build') - $type = parent::EVENT_BUILD; - elseif ($type == 'upgrade') - $type = parent::EVENT_UPGRADE; - elseif ($type == 'create') - $type = parent::EVENT_CREATE; - - foreach ($event as $row) + public function delete_event($evid) { - if ($row['type'] == $type) - return TRUE; + $sql = "DELETE FROM events WHERE id='$evid'"; + $this->db->query($sql); } - return FALSE; - } + //gets events by slotid + public function get_events($slotid, $villageid) + { + $this->update($villageid); - function _build_finished($data) - { - //delete build_in progress tile - $sql = "DELETE FROM village_buildings + $sql = "SELECT * FROM events WHERE villageid='$villageid' AND slotid='$slotid'"; + $q = $this->db->query($sql); + + if ($q->num_rows()) { + return $q->result_array(); + } + + return false; + } + + public function has_event($slotid, $villageid) + { + $this->update($villageid); + + $sql = "SELECT id FROM events WHERE villageid='$villageid' AND slotid='$slotid'"; + $q = $this->db->query($sql); + + if ($q->num_rows()) { + return true; + } + + return false; + } + + //gets the next event for display + public function get_next_event($villageid) + { + $this->update($villageid); + + $sql = "SELECT * FROM events WHERE villageid='$villageid'"; + $q = $this->db->query($sql); + + if (!$q->num_rows()) { + return false; + } + + $res = $q->result_array(); + + $min = 0; + + foreach ($res as $row) { + if (!$min) { + $min = $row; + } + + if ($row['end'] < $min['end']) { + $min = $row; + } + } + + return $min; + } + + public function check_event($event, $type) + { + if (!$event) { + return false; + } + + if ($type == 'build') { + $type = parent::EVENT_BUILD; + } elseif ($type == 'upgrade') { + $type = parent::EVENT_UPGRADE; + } elseif ($type == 'create') { + $type = parent::EVENT_CREATE; + } + + foreach ($event as $row) { + if ($row['type'] == $type) { + return true; + } + } + + return false; + } + + public function _build_finished($data) + { + //delete build_in progress tile + $sql = "DELETE FROM village_buildings WHERE villageid='" . $data['villageid'] . "' AND slotid='" . $data['slotid'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - //data1 should contain the buildingid - $sql = "INSERT INTO village_buildings + //data1 should contain the buildingid + $sql = "INSERT INTO village_buildings VALUES(default, '" . $data['villageid'] . "', '" . $data['slotid'] . "', '" . $data['data1'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->add_modifiers($data['data1'], $data['villageid']); - } + $this->add_modifiers($data['data1'], $data['villageid']); + } - function _upgrade_finished($data) - { - //initialize unitq - $this->unitq_initialize($data['villageid']); + public function _upgrade_finished($data) + { + //initialize unitq + $this->unitq_initialize($data['villageid']); - //deassign everything - $this->_deassign_all($data); + //deassign everything + $this->_deassign_all($data); - //remove prev rank's modifier - $this->substract_modifiers($data['data2'], $data['villageid']); + //remove prev rank's modifier + $this->substract_modifiers($data['data2'], $data['villageid']); - //update entry - $sql = "UPDATE village_buildings + //update entry + $sql = "UPDATE village_buildings SET buildingid='" . $data['data1'] . "' WHERE villageid='" . $data['villageid'] . "' AND slotid='" . $data['slotid'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - //add new modifiers - $this->add_modifiers($data['data1'], $data['villageid']); - } + //add new modifiers + $this->add_modifiers($data['data1'], $data['villageid']); + } - function _create_finished($data) - { - $this->unitq_initialize($data['villageid']); + public function _create_finished($data) + { + $this->unitq_initialize($data['villageid']); - $this->unitq_change('+', $data['data1'], $data['data2']); - } + $this->unitq_change('+', $data['data1'], $data['data2']); + } - function _deassign_all($data) - { - $sql = "SELECT * FROM building_assignments + public function _deassign_all($data) + { + $sql = "SELECT * FROM building_assignments LEFT JOIN assignments ON building_assignments.assignmentid=assignments.id WHERE slotid='" . $data['slotid'] . "' AND villageid='" . $data['villageid'] . "'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return; - - $ass = $q->result_array(); + if (!$q->num_rows()) { + return; + } + + $ass = $q->result_array(); - //deleting assignments - $sql = "DELETE FROM building_assignments + //deleting assignments + $sql = "DELETE FROM building_assignments WHERE slotid='" . $data['slotid'] . "' AND villageid='" . $data['villageid'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - foreach ($ass as $row) - { - $this->substract_modifiers($row, $data['villageid'], 'assignment', $row['num_bonus'], TRUE); + foreach ($ass as $row) { + $this->substract_modifiers($row, $data['villageid'], 'assignment', $row['num_bonus'], true); - //giving units back - $this->unitq_change('+', $row['unitid'], $row['num_unit'], TRUE); - } + //giving units back + $this->unitq_change('+', $row['unitid'], $row['num_unit'], true); + } - //take away spells - $sql = "DELETE FROM building_spells + //take away spells + $sql = "DELETE FROM building_spells WHERE villageid='" . $data['villageid'] . "' AND slotid='" . $data['slotid'] . "'"; - $this->db->query($sql); - } + $this->db->query($sql); + } - function _spell_end($data) - { - $this->substract_modifiers($data['data1'], $data['villageid'], 'spell'); - } + public function _spell_end($data) + { + $this->substract_modifiers($data['data1'], $data['villageid'], 'spell'); + } - function _research_end($data) - { - $sql = "SELECT * FROM technologies WHERE id='" . $data['data1'] . "'"; + public function _research_end($data) + { + $sql = "SELECT * FROM technologies WHERE id='" . $data['data1'] . "'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return; + if (!$q->num_rows()) { + return; + } - $tech = $q->row_array(); + $tech = $q->row_array(); - $this->add_modifiers($tech, $data['villageid'], 'technology', 1, TRUE); + $this->add_modifiers($tech, $data['villageid'], 'technology', 1, true); - $this->add_technology($data['data1'], $data['data2'], $tech, - $data['slotid'], $data['villageid']); - } + $this->add_technology( + $data['data1'], + $data['data2'], + $tech, + $data['slotid'], + $data['villageid'] + ); + } - function _attack($data) - { - $this->unitq_initialize($data['villageid']); + public function _attack($data) + { + $this->unitq_initialize($data['villageid']); - //get village units who can defend - $defenders = $this->_get_defenders(); - $userid = $this->userid; + //get village units who can defend + $defenders = $this->_get_defenders(); + $userid = $this->userid; - $attackers = $this->_get_attackers($data['data1'], $data['villageid']); - $village = $this->_get_village($data['villageid']); + $attackers = $this->_get_attackers($data['data1'], $data['villageid']); + $village = $this->_get_village($data['villageid']); - $log = $this->_combat($defenders, $attackers, $village, $data['data2'], - $data['villageid'], $userid); + $log = $this->_combat( + $defenders, + $attackers, + $village, + $data['data2'], + $data['villageid'], + $userid + ); - $this->add_combat_log($log, $data['villageid']); + $this->add_combat_log($log, $data['villageid']); - //delete attack from the db - $sql = "DELETE FROM attacks + //delete attack from the db + $sql = "DELETE FROM attacks WHERE villageid='" . $data['villageid'] . "' AND attackid='" .$data['data1'] . "'"; - $this->db->query($sql); - - } - - function _get_defenders() - { - $units = $this->unitq_get_units(); - $vu = $this->unitq_get_village_units(); - - if (!$vu) - return FALSE; - - for ($i = 0; $i < sizeof($vu); $i++) - { - foreach ($units as $u) - { - if ($vu[$i]['unitid'] == $u['id']) - { - $d[$i] = $u; - $d[$i]['unitcount'] = $vu[$i]['unitcount']; - } - } + $this->db->query($sql); } - if (!isset($d)) - return FALSE; - - foreach ($d as $row) + public function _get_defenders() { - if ($row['can_defend']) - $data[] = $row; - } + $units = $this->unitq_get_units(); + $vu = $this->unitq_get_village_units(); + + if (!$vu) { + return false; + } + + for ($i = 0; $i < sizeof($vu); $i++) { + foreach ($units as $u) { + if ($vu[$i]['unitid'] == $u['id']) { + $d[$i] = $u; + $d[$i]['unitcount'] = $vu[$i]['unitcount']; + } + } + } + + if (!isset($d)) { + return false; + } + + foreach ($d as $row) { + if ($row['can_defend']) { + $data[] = $row; + } + } - if (isset($data)) - return $data; - else - return FALSE; - } + if (isset($data)) { + return $data; + } else { + return false; + } + } - function _get_attackers($atkid, $villageid) - { - $sql = "SELECT attacks.ai_unitcount AS unitcount,ai_units.* + public function _get_attackers($atkid, $villageid) + { + $sql = "SELECT attacks.ai_unitcount AS unitcount,ai_units.* FROM attacks LEFT JOIN ai_units ON attacks.ai_unitid=ai_units.id WHERE villageid='$villageid' AND attackid='$atkid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function _get_village($villageid) - { - $sql = "SELECT buildings.*,village_buildings.slotid + public function _get_village($villageid) + { + $sql = "SELECT buildings.*,village_buildings.slotid FROM village_buildings LEFT JOIN buildings on village_buildings.buildingid=buildings.id WHERE villageid='$villageid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - $res = $q->result_array(); + $res = $q->result_array(); - $i = 1; - for ($y = 1; $y <= parent::BUILDING_ROW; $y++) - { - for ($x = 1; $x <= parent::BUILDING_CULOMN; $x++) - { - $found = FALSE; + $i = 1; + for ($y = 1; $y <= parent::BUILDING_ROW; $y++) { + for ($x = 1; $x <= parent::BUILDING_CULOMN; $x++) { + $found = false; - foreach ($res as $row) - { - if ($row['slotid'] == $i) - { - $found = TRUE; - $data[$x][$y] = $row; - } - } + foreach ($res as $row) { + if ($row['slotid'] == $i) { + $found = true; + $data[$x][$y] = $row; + } + } - if (!$found) - $data[$x][$y] = FALSE; + if (!$found) { + $data[$x][$y] = false; + } - $i++; - } + $i++; + } + } + + return $data; } - return $data; - } - - function _combat($defenders, $attackers, $village, $dir, $villageid, $userid) - { - $this->load->helper('date'); - $datestring = "%Y.%m.%d - %H:%i:%s"; - - $log = "Attack (" . mdate($datestring, time()) . "):

"; - - $log .= $this->_def_atk_list($defenders, $attackers); - - //combat with defenders - if ($defenders) + public function _combat($defenders, $attackers, $village, $dir, $villageid, $userid) { - //save some sizeof() calls - $def_size = sizeof($defenders) - 1; - $atk_size = sizeof($attackers) - 1; + $this->load->helper('date'); + $datestring = "%Y.%m.%d - %H:%i:%s"; - //using the smaller - if ($def_size < $atk_size) - { - $iter = $defenders; - $iter_t = 'def'; - } - else - { - $iter = $attackers; - $iter_t = 'atk'; - } + $log = "Attack (" . mdate($datestring, time()) . "):

"; - //generating who fight with who - for ($i = 0; $i < sizeof($iter); $i++) - { - $found = FALSE; + $log .= $this->_def_atk_list($defenders, $attackers); - while(!$found) - { - if ($iter_t == 'def') - $r = rand(0, $atk_size); - else - $r = rand(0, $def_size); + //combat with defenders + if ($defenders) { + //save some sizeof() calls + $def_size = sizeof($defenders) - 1; + $atk_size = sizeof($attackers) - 1; - if (!isset($d[$r])) - { - if ($iter_t == 'def') - { - $turn_a = $attackers[$r]['turn']; - $turn_p = $defenders[$i]['turn']; - } - else - { - $turn_a = $attackers[$i]['turn']; - $turn_p = $defenders[$r]['turn']; - } + //using the smaller + if ($def_size < $atk_size) { + $iter = $defenders; + $iter_t = 'def'; + } else { + $iter = $attackers; + $iter_t = 'atk'; + } - if ($turn_a > $turn_p) - $turn = 'pl'; - elseif ($turn_p > $turn_a) - $turn = 'ai'; - else - $turn = 'sa'; + //generating who fight with who + for ($i = 0; $i < sizeof($iter); $i++) { + $found = false; - if ($iter_t == 'def') - { - $unit_a = $attackers[$r]; - $unit_p = $defenders[$i]; - } - else - { - $unit_a = $attackers[$i]; - $unit_p = $defenders[$r]; - } + while (!$found) { + if ($iter_t == 'def') { + $r = rand(0, $atk_size); + } else { + $r = rand(0, $def_size); + } - $hit = $this->_hit($unit_a, $unit_p, $turn); + if (!isset($d[$r])) { + if ($iter_t == 'def') { + $turn_a = $attackers[$r]['turn']; + $turn_p = $defenders[$i]['turn']; + } else { + $turn_a = $attackers[$i]['turn']; + $turn_p = $defenders[$r]['turn']; + } - $log .= $hit['log']; - $log .= "
"; - - //write back hit - if ($iter_t == 'def') - { - $attackers[$r]['unitcount'] -= $hit['ai']; - $defend = $defenders[$i]; - } - else - { - $attackers[$i]['unitcount'] -= $hit['ai']; - $defend = $defenders[$r]; - } + if ($turn_a > $turn_p) { + $turn = 'pl'; + } elseif ($turn_p > $turn_a) { + $turn = 'ai'; + } else { + $turn = 'sa'; + } - $d[$r] = TRUE; - $found = TRUE; - } - } - } - } - else - { - $log .= "You doesn\'t have any defenders, attackers attack your village.
"; + if ($iter_t == 'def') { + $unit_a = $attackers[$r]; + $unit_p = $defenders[$i]; + } else { + $unit_a = $attackers[$i]; + $unit_p = $defenders[$r]; + } + + $hit = $this->_hit($unit_a, $unit_p, $turn); + + $log .= $hit['log']; + $log .= "
"; + + //write back hit + if ($iter_t == 'def') { + $attackers[$r]['unitcount'] -= $hit['ai']; + $defend = $defenders[$i]; + } else { + $attackers[$i]['unitcount'] -= $hit['ai']; + $defend = $defenders[$r]; + } + + $d[$r] = true; + $found = true; + } + } + } + } else { + $log .= "You doesn\'t have any defenders, attackers attack your village.
"; + } + + //there is no unsetting in the above part, so this will always be true + //leftover atackers go for the village + //if ($attackers) + //{ + //ability 1 means they can't stole + //} + + $buildings = false; + + //create an array with these, containing the first building in every row or culomn + //it has to be foreachable + if ($dir == parent::ATTACK_UP) { + for ($x = 1; $x <= parent::BUILDING_CULOMN; $x++) { + $found = false; + + for ($y = 1; $y <= parent::BUILDING_ROW; $y++) { + $building = $village[$x][$y]; + + if ($building) { + $buildings[] = $building; + $found = true; + break; + } + } + + if (!$found) { + $buildings[] = false; + } + } + } elseif ($dir == parent::ATTACK_LEFT) { + for ($y = 1; $y <= parent::BUILDING_ROW; $y++) { + $found = false; + + for ($x = 1; $x <= parent::BUILDING_ROW; $x++) { + $building = $village[$x][$y]; + + if ($building) { + $buildings[] = $building; + $found = true; + break; + } + } + + if (!$found) { + $buildings[] = false; + } + } + } elseif ($dir == parent::ATTACK_RIGHT) { + for ($y = 1; $y <= parent::BUILDING_ROW; $y++) { + $found = false; + + for ($x = parent::BUILDING_ROW; $x >= 1; $x--) { + $building = $village[$x][$y]; + + if ($building) { + $buildings[] = $building; + $found = true; + break; + } + } + + if (!$found) { + $buildings[] = false; + } + } + } elseif ($dir == parent::ATTACK_DOWN) { + for ($x = 1; $x <= parent::BUILDING_CULOMN; $x++) { + $found = false; + + for ($y = parent::BUILDING_ROW; $y >= 1; $y--) { + $building = $village[$x][$y]; + + if ($building) { + $buildings[] = $building; + $found = true; + break; + } + } + + if (!$found) { + $buildings[] = false; + } + } + } + + //calc the enemy's remainder power, and how much they can steal + //they should steal that much if they hit something without ability 1 + $remainder['pow'] = 0; + $remainder['steal'] = 0; + foreach ($attackers as $row) { + $remainder['pow'] += ($row['unitcount'] * $row['attack']); + $remainder['steal'] += ($row['unitcount'] * $row['can_carry']); + } + + if ($remainder['pow'] || $remainder['steal']) { + $log .= "The remainder of attackers attack your village from "; + + if ($dir == parent::ATTACK_UP) { + $log .= "up"; + } elseif ($dir == parent::ATTACK_LEFT) { + $log .= "left"; + } elseif ($dir == parent::ATTACK_RIGHT) { + $log .= "right"; + } elseif ($dir == parent::ATTACK_DOWN) { + $log .= "down"; + } + + $log .= ".

"; + + //hit buildings + $log .= $this->_hit_building($buildings, $remainder, $villageid); + } + + //ballists should attack here once + $ballist = false; + foreach ($attackers as $row) { + if ($row['ability'] == 1) { + $ballist = $row; + } + } + + if ($ballist) { + if ($ballist['unitcount']) { + $r_x = rand(1, parent::BUILDING_CULOMN); + $r_y = rand(1, parent::BUILDING_ROW); + + $rem['pow'] = $ballist['unitcount'] * $ballist['attack']; + $rem['steal'] = 0; + + //$log .= "
"; + + $log .= $this->_hit_building_ability($village[$r_x][$r_y], $rem, $villageid); + } + } + + //return log for writing + return $log; } - //there is no unsetting in the above part, so this will always be true - //leftover atackers go for the village - //if ($attackers) - //{ - //ability 1 means they can't stole - //} - - $buildings = FALSE; - - //create an array with these, containing the first building in every row or culomn - //it has to be foreachable - if ($dir == parent::ATTACK_UP) + public function _hit($ai, $pl, $turn) { - for ($x = 1; $x <= parent::BUILDING_CULOMN; $x++) - { - $found = FALSE; + if ($turn == 'ai') { + $first = $ai; + $second = $pl; + } elseif ($turn == 'pl') { + $first = $pl; + $second = $ai; + } else { + $first = $ai; + $second = $pl; + } - for ($y = 1; $y <= parent::BUILDING_ROW; $y++) - { - $building = $village[$x][$y]; + if ($turn == 'ai') { + $log = $first['name'] . "s (" . $first['unitcount'] . ")"; + $log .= " ambushes your " . $second['name'] . "s"; + $log .= " (" . $second['unitcount'] . "):
"; + } elseif ($turn == 'pl') { + $log = "Your " . $first['name'] . "s (" . $first['unitcount'] . ")"; + $log .= " ambushes " . $second['name'] . "s"; + $log .= " (" . $second['unitcount'] . "):
"; + } else { + $log = "Your " . $pl['name'] . "s (" . $pl['unitcount'] . ")"; + $log .= " attacks " . $ai['name'] . "s"; + $log .= " (" . $ai['unitcount'] . ")
"; + } - if ($building) - { - $buildings[] = $building; - $found = TRUE; - break; - } - } - - if (!$found) - $buildings[] = FALSE; - } - } - elseif ($dir == parent::ATTACK_LEFT) - { - for ($y = 1; $y <= parent::BUILDING_ROW; $y++) - { - $found = FALSE; + //calc stuff - for ($x = 1; $x <= parent::BUILDING_ROW; $x++) - { - $building = $village[$x][$y]; + $first_atk = $first['attack'] * $first['unitcount']; - if ($building) - { - $buildings[] = $building; - $found = TRUE; - break; - } - } - - if (!$found) - $buildings[] = FALSE; - } - } - elseif ($dir == parent::ATTACK_RIGHT) - { - for ($y = 1; $y <= parent::BUILDING_ROW; $y++) - { - $found = FALSE; + if ($first['strong_against'] == $second['id']) { + $first_atk *= 1.2; + } - for ($x = parent::BUILDING_ROW; $x >= 1; $x--) - { - $building = $village[$x][$y]; + if ($first['weak_against'] == $second['id']) { + $first_atk *= 0.8; + } - if ($building) - { - $buildings[] = $building; - $found = TRUE; - break; - } - } - - if (!$found) - $buildings[] = FALSE; - } - } - elseif ($dir == parent::ATTACK_DOWN) - { - for ($x = 1; $x <= parent::BUILDING_CULOMN; $x++) - { - $found = FALSE; + //critical 5% + if (rand(0, 100) > 95) { + $first_atk *= 1.5; + $first_crit = true; + } else { + $first_crit = false; + } - for ($y = parent::BUILDING_ROW; $y >= 1; $y--) - { - $building = $village[$x][$y]; + //abilities here too? + + //calc how much dies + $second_d = floor($first_atk / $second['defense']); - if ($building) - { - $buildings[] = $building; - $found = TRUE; - break; - } - } - - if (!$found) - $buildings[] = FALSE; - } + if ($second_d > $second['unitcount']) { + $second_d = $second['unitcount']; + } + + //if ambush + if ($turn == 'ai' || $turn == 'pl') { + $second['unitcount'] -= $second_d; + } + + $second_atk = $second['attack'] * $second['unitcount']; + + if ($second['strong_against'] == $first['id']) { + $second_atk *= 1.2; + } + + if ($second['weak_against'] == $first['id']) { + $second_atk *= 0.8; + } + + //critical 5% + if (rand(0, 100) > 95) { + $second_atk *= 1.5; + $second_crit = true; + } else { + $second_crit = false; + } + + + //some abilities can be processed here + + + //calc how much dies + $first_d = floor($second_atk / $first['defense']); + + if ($first_d > $first['unitcount']) { + $first_d = $first['unitcount']; + } + + //sa == same + if ($turn == 'sa') { + //in this case $first = $ai, $second = pl, but the order doesn't matters + //players first + $log .= "Your " . $second['name'] . "s hits for " . $second_atk; + + if ($second_crit) { + $log .= " (critical)"; + } + + $log .= ", " . $first_d . " enemy dies.
"; + + //now ai + $log .= "Enemy " . $first['name'] . "s hits for " . $first_atk; + if ($first_crit) { + $log .= " (critical)"; + } + + $log .= ", " . $second_d . " of your units dies.
"; + } else { + if ($turn == 'pl') { + $log .= "Your " . $first['name'] . "s hits for " . $first_atk; + + if ($first_crit) { + $log .= " (critical)"; + } + + $log .= ", " . $second_d . " enemy dies.
"; + + $log .= "Enemy " . $second['name'] . "s hits for " . $second_atk; + if ($second_crit) { + $log .= " (critical)"; + } + + $log .= ", " . $first_d . " of your units dies.
"; + } else { + $log .= "Enemy's " . $first['name'] . "s hits for " . $first_atk; + if ($first_crit) { + $log .= " (critical)"; + } + + $log .= ", " . $second_d . " of your units dies.
"; + + $log .= "Your " . $second['name'] . "s hits for " . $second_atk; + + if ($second_crit) { + $log .= " (critical)"; + } + + $log .= ", " . $first_d . " of your units dies.
"; + } + } + + if ($turn == 'ai') { + $ai_d = $first_d; + $pl_d = $second_d; + $uid = $second['id']; + } elseif ($turn == 'pl') { + $pl_d = $first_d; + $ai_d = $second_d; + $uid = $first['id']; + } else { + $ai_d = $first_d; + $pl_d = $second_d; + $uid = $second['id']; + } + + $data['ai'] = $ai_d; + $data['pl'] = $pl_d; + $data['log'] = $log; + + //unitq is inialized already + $this->unitq_change('-', $uid, $pl_d); + + return $data; } - //calc the enemy's remainder power, and how much they can steal - //they should steal that much if they hit something without ability 1 - $remainder['pow'] = 0; - $remainder['steal'] = 0; - foreach ($attackers as $row) + public function _hit_building($buildings, $remainder, $villageid) { - $remainder['pow'] += ($row['unitcount'] * $row['attack']); - $remainder['steal'] += ($row['unitcount'] * $row['can_carry']); - } + $log = ""; - if ($remainder['pow'] || $remainder['steal']) - { - $log .= "The remainder of attackers attack your village from "; + for ($i = 0; $i < 3; $i++) { + $r = rand(0, (sizeof($buildings) -1)); + + $b = $buildings[$r]; - if ($dir == parent::ATTACK_UP) - $log .= "up"; - elseif ($dir == parent::ATTACK_LEFT) - $log .= "left"; - elseif ($dir == parent::ATTACK_RIGHT) - $log .= "right"; - elseif ($dir == parent::ATTACK_DOWN) - $log .= "down"; + if ($b) { + $log .= "The enemy attacked your " . $b['name']; + $log .= "(Slot " . $b['slotid'] . ")
"; - $log .= ".

"; + if ($b['defense'] > $remainder['pow']) { + $log .= "They downgraded it.
"; - //hit buildings - $log .= $this->_hit_building($buildings, $remainder, $villageid); + //downgrade + $buildings[$r] = $this->_downgrade($b, $villageid); + } else { + $log .= "They didn\'t do sufficient damage.
"; + } - } - - //ballists should attack here once - $ballist = FALSE; - foreach ($attackers as $row) - { - if ($row['ability'] == 1) - $ballist = $row; - } + //steal if not ability 1 and steal is greated than 0 + if ($b['ability'] != 1 && $remainder['steal']) { + $s = ($remainder['steal'] / 5); + + $res['cost_food'] = $s; + $res['cost_wood'] = $s; + $res['cost_stone'] = $s; + $res['cost_iron'] = $s; + $res['cost_mana'] = $s; - if ($ballist) - { - if ($ballist['unitcount']) - { - $r_x = rand(1, parent::BUILDING_CULOMN); - $r_y = rand(1, parent::BUILDING_ROW); + $this->substract_resources($res, $villageid); - $rem['pow'] = $ballist['unitcount'] * $ballist['attack']; - $rem['steal'] = 0; + $log .= "They stole " . $s . " from all of your resources.
"; + } else { + $log .= "The enemy wasn\'t able to steal from your resources.
"; + } + } else { + if ($remainder['steal']) { + $s = ($remainder['steal'] / 5); + + $res['cost_food'] = $s; + $res['cost_wood'] = $s; + $res['cost_stone'] = $s; + $res['cost_iron'] = $s; + $res['cost_mana'] = $s; - //$log .= "
"; + $this->substract_resources($res, $villageid); - $log .= $this->_hit_building_ability($village[$r_x][$r_y], $rem, $villageid); - } - } - - //return log for writing - return $log; - } - - function _hit($ai, $pl, $turn) - { - if ($turn == 'ai') - { - $first = $ai; - $second = $pl; - } - elseif ($turn == 'pl') - { - $first = $pl; - $second = $ai; - } - else - { - $first = $ai; - $second = $pl; - } - - if ($turn == 'ai') - { - $log = $first['name'] . "s (" . $first['unitcount'] . ")"; - $log .= " ambushes your " . $second['name'] . "s"; - $log .= " (" . $second['unitcount'] . "):
"; - } - elseif ($turn == 'pl') - { - $log = "Your " . $first['name'] . "s (" . $first['unitcount'] . ")"; - $log .= " ambushes " . $second['name'] . "s"; - $log .= " (" . $second['unitcount'] . "):
"; - } - else - { - $log = "Your " . $pl['name'] . "s (" . $pl['unitcount'] . ")"; - $log .= " attacks " . $ai['name'] . "s"; - $log .= " (" . $ai['unitcount'] . ")
"; - } - - //calc stuff - - $first_atk = $first['attack'] * $first['unitcount']; - - if ($first['strong_against'] == $second['id']) - $first_atk *= 1.2; - - if ($first['weak_against'] == $second['id']) - $first_atk *= 0.8; - - //critical 5% - if (rand(0, 100) > 95) - { - $first_atk *= 1.5; - $first_crit = TRUE; - } - else - $first_crit = FALSE; - - //abilities here too? - - //calc how much dies - $second_d = floor($first_atk / $second['defense']); - - if ($second_d > $second['unitcount']) - $second_d = $second['unitcount']; - - //if ambush - if ($turn == 'ai' || $turn == 'pl') - { - $second['unitcount'] -= $second_d; - } - - $second_atk = $second['attack'] * $second['unitcount']; - - if ($second['strong_against'] == $first['id']) - $second_atk *= 1.2; - - if ($second['weak_against'] == $first['id']) - $second_atk *= 0.8; - - //critical 5% - if (rand(0, 100) > 95) - { - $second_atk *= 1.5; - $second_crit = TRUE; - } - else - $second_crit = FALSE; - - - //some abilities can be processed here - - - //calc how much dies - $first_d = floor($second_atk / $first['defense']); - - if ($first_d > $first['unitcount']) - $first_d = $first['unitcount']; - - //sa == same - if ($turn == 'sa') - { - //in this case $first = $ai, $second = pl, but the order doesn't matters - //players first - $log .= "Your " . $second['name'] . "s hits for " . $second_atk; - - if ($second_crit) - $log .= " (critical)"; - - $log .= ", " . $first_d . " enemy dies.
"; - - //now ai - $log .= "Enemy " . $first['name'] . "s hits for " . $first_atk; - if ($first_crit) - $log .= " (critical)"; - - $log .= ", " . $second_d . " of your units dies.
"; - } - else - { - if ($turn == 'pl') - { - $log .= "Your " . $first['name'] . "s hits for " . $first_atk; - - if ($first_crit) - $log .= " (critical)"; - - $log .= ", " . $second_d . " enemy dies.
"; - - $log .= "Enemy " . $second['name'] . "s hits for " . $second_atk; - if ($second_crit) - $log .= " (critical)"; - - $log .= ", " . $first_d . " of your units dies.
"; - } - else - { - $log .= "Enemy's " . $first['name'] . "s hits for " . $first_atk; - if ($first_crit) - $log .= " (critical)"; - - $log .= ", " . $second_d . " of your units dies.
"; - - $log .= "Your " . $second['name'] . "s hits for " . $second_atk; - - if ($second_crit) - $log .= " (critical)"; - - $log .= ", " . $first_d . " of your units dies.
"; - } - } - - if ($turn == 'ai') - { - $ai_d = $first_d; - $pl_d = $second_d; - $uid = $second['id']; - } - elseif ($turn == 'pl') - { - $pl_d = $first_d; - $ai_d = $second_d; - $uid = $first['id']; - } - else - { - $ai_d = $first_d; - $pl_d = $second_d; - $uid = $second['id']; - } - - $data['ai'] = $ai_d; - $data['pl'] = $pl_d; - $data['log'] = $log; - - //unitq is inialized already - $this->unitq_change('-', $uid, $pl_d); - - return $data; - } - - function _hit_building($buildings, $remainder, $villageid) - { - $log = ""; - - for ($i = 0; $i < 3; $i++) - { - $r = rand(0, (sizeof($buildings) -1)); - - $b = $buildings[$r]; - - if ($b) - { - $log .= "The enemy attacked your " . $b['name']; - $log .= "(Slot " . $b['slotid'] . ")
"; - - if ($b['defense'] > $remainder['pow']) - { - $log .= "They downgraded it.
"; - - //downgrade - $buildings[$r] = $this->_downgrade($b, $villageid); - } - else - { - $log .= "They didn\'t do sufficient damage.
"; - } - - //steal if not ability 1 and steal is greated than 0 - if ($b['ability'] != 1 && $remainder['steal']) - { - $s = ($remainder['steal'] / 5); - - $res['cost_food'] = $s; - $res['cost_wood'] = $s; - $res['cost_stone'] = $s; - $res['cost_iron'] = $s; - $res['cost_mana'] = $s; - - $this->substract_resources($res, $villageid); - - $log .= "They stole " . $s . " from all of your resources.
"; - } - else - { - $log .= "The enemy wasn\'t able to steal from your resources.
"; - } - } - else - { - if ($remainder['steal']) - { - $s = ($remainder['steal'] / 5); - - $res['cost_food'] = $s; - $res['cost_wood'] = $s; - $res['cost_stone'] = $s; - $res['cost_iron'] = $s; - $res['cost_mana'] = $s; - - $this->substract_resources($res, $villageid); - - $log .= "The enemy found an opening in your village\'s defenses,
"; - $log .= "you lost " . $s . " from all resources!
"; - } - else - { - $log .= "The enemy found an opening in your village\'s defenses,
"; - $log .= "but wasn\t able to steal resources.
"; - } - } - $log .= "
"; - } + $log .= "The enemy found an opening in your village\'s defenses,
"; + $log .= "you lost " . $s . " from all resources!
"; + } else { + $log .= "The enemy found an opening in your village\'s defenses,
"; + $log .= "but wasn\t able to steal resources.
"; + } + } + $log .= "
"; + } - return $log; - } - - function _hit_building_ability($building, $remainder, $villageid) - { - $log = ""; - - $b = $building; - - if ($b) - { - $log .= "Ballists attacked your " . $b['name']; - $log .= "(Slot " . $b['slotid'] . ")
"; - - if ($b['defense'] > $remainder['pow']) - { - $log .= "They downgraded it.
"; - - //downgrade - //we don't need the return here, since this is the last function call in the event. - $this->_downgrade($b, $villageid); - } - else - { - $log .= "They didn\'t do sufficient damage.
"; - } + return $log; } - else + + public function _hit_building_ability($building, $remainder, $villageid) { - $log .= "Ballists attacked your village, but they missed every building."; + $log = ""; + + $b = $building; + + if ($b) { + $log .= "Ballists attacked your " . $b['name']; + $log .= "(Slot " . $b['slotid'] . ")
"; + + if ($b['defense'] > $remainder['pow']) { + $log .= "They downgraded it.
"; + + //downgrade + //we don't need the return here, since this is the last function call in the event. + $this->_downgrade($b, $villageid); + } else { + $log .= "They didn\'t do sufficient damage.
"; + } + } else { + $log .= "Ballists attacked your village, but they missed every building."; + } + + return $log; } - - return $log; - } - function _downgrade($building, $villageid) - { - $slotid = $building['slotid']; - - $sql = "SELECT * FROM buildings WHERE next_rank='" . $building['id'] . "'"; - - $q = $this->db->query($sql); - - if (!$q->num_rows()) + public function _downgrade($building, $villageid) { - //means its rank1 - $this->substract_modifiers($building['id'], $villageid, 'building'); - //$this->delete_building($slotid, $villageid); + $slotid = $building['slotid']; - //deassign all - $d['villageid'] = $villageid; - $d['slotid'] = $slotid; - $this->_deassign_all($d); + $sql = "SELECT * FROM buildings WHERE next_rank='" . $building['id'] . "'"; - $sql = "DELETE FROM village_buildings + $q = $this->db->query($sql); + + if (!$q->num_rows()) { + //means its rank1 + $this->substract_modifiers($building['id'], $villageid, 'building'); + //$this->delete_building($slotid, $villageid); + + //deassign all + $d['villageid'] = $villageid; + $d['slotid'] = $slotid; + $this->_deassign_all($d); + + $sql = "DELETE FROM village_buildings WHERE villageid='$villageid' AND slotid='$slotid'"; - $this->db->query($sql); + $this->db->query($sql); - return; - } + return; + } - $prev_r = $q->row_array(); + $prev_r = $q->row_array(); - $this->substract_modifiers($building['id'], $villageid, 'building'); + $this->substract_modifiers($building['id'], $villageid, 'building'); - //deassign all - $d['villageid'] = $villageid; - $d['slotid'] = $slotid; - $this->_deassign_all($d); + //deassign all + $d['villageid'] = $villageid; + $d['slotid'] = $slotid; + $this->_deassign_all($d); - //change building - $sql = "UPDATE village_buildings + //change building + $sql = "UPDATE village_buildings SET buildingid='" . $prev_r['id'] . "' WHERE villageid='$villageid' AND slotid='$slotid'"; - $this->db->query($sql); + $this->db->query($sql); - $this->add_modifiers($prev_r['id'], $villageid, 'building'); + $this->add_modifiers($prev_r['id'], $villageid, 'building'); - $prev_r['slotid'] = $slotid; + $prev_r['slotid'] = $slotid; - return $prev_r; - } - - function _def_atk_list($defenders, $attackers) - { - $log = ""; - - if ($defenders) - { - $log .= "Your defenders:
"; - - foreach ($defenders as $row) - { - $log .= $row['name'] . " x " . $row['unitcount'] . "
"; - } - } - else - { - $log .= "You don\'t have any defenders.
"; + return $prev_r; } - $log .= "
"; - $log .= "Attackers:
"; - - foreach ($attackers as $row) + public function _def_atk_list($defenders, $attackers) { - $log .= $row['name'] . " x " . $row['unitcount'] . "
"; + $log = ""; + + if ($defenders) { + $log .= "Your defenders:
"; + + foreach ($defenders as $row) { + $log .= $row['name'] . " x " . $row['unitcount'] . "
"; + } + } else { + $log .= "You don\'t have any defenders.
"; + } + + $log .= "
"; + $log .= "Attackers:
"; + + foreach ($attackers as $row) { + $log .= $row['name'] . " x " . $row['unitcount'] . "
"; + } + + $log .= "
"; + + return $log; } - - $log .= "
"; - - return $log; - } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/hero_model.php b/Mourne-CI/application/models/hero_model.php index b5b8356..534eccc 100644 --- a/Mourne-CI/application/models/hero_model.php +++ b/Mourne-CI/application/models/hero_model.php @@ -2,144 +2,147 @@ class Hero_model extends MO_Model { - function __construct() - { - parent::__construct(); - } - - function get_heroes($userid) - { - $sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'"; - - $q = $this->db->query($sql, array($userid)); - - if ($q->num_rows()) - return $q->result_array(); - - return FALSE; - } - - 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; - - $res = $q->row_array(); - - if ($res['userid'] != $userid || $res['deleted']) - return FALSE; - - $sql = "UPDATE heroes SET selected = 0 WHERE userid = ?"; - - $this->db->query($sql, array($userid)); - - $sql = "UPDATE heroes SET selected = 1 WHERE id = ?"; - - $this->db->query($sql, array($id)); - - return TRUE; - } - - 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()) - return $q->row_array(); - - return FALSE; - } - - function delete_hero($id, $userid) - { - $sql = "SELECT * FROM heroes WHERE id = ?"; - - $q = $this->db->query($sql, array($id)); - - if (!$q->num_rows()) - return FALSE; - - $res = $q->row_array(); - - if ($res['deleted']) - return FALSE; - - if ($userid != $res['userid']) - return FALSE; - - if ($res['selected']) + public function __construct() { - $sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'"; - - $q = $this->db->query($sql, array($userid)); - - if (!$q->num_rows()) - return TRUE; - - $data = $q->result_array(); - - foreach ($data as $row) - { - if ($row['id'] != $id) - { - $sql = "UPDATE heroes SET selected = '1' WHERE id = ?"; - $this->db->query($sql, array($row['id'])); - - break; - } - } + parent::__construct(); } - $sql = "UPDATE heroes SET deleted='1', delete_name = '" . $res['name'] . "', name='' + 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()) { + return $q->result_array(); + } + + 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; + } + + $res = $q->row_array(); + + if ($res['userid'] != $userid || $res['deleted']) { + return false; + } + + $sql = "UPDATE heroes SET selected = 0 WHERE userid = ?"; + + $this->db->query($sql, array($userid)); + + $sql = "UPDATE heroes SET selected = 1 WHERE id = ?"; + + $this->db->query($sql, array($id)); + + return true; + } + + 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()) { + return $q->row_array(); + } + + 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; + } + + $res = $q->row_array(); + + if ($res['deleted']) { + return false; + } + + if ($userid != $res['userid']) { + return false; + } + + 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; + } + + $data = $q->result_array(); + + foreach ($data as $row) { + if ($row['id'] != $id) { + $sql = "UPDATE heroes SET selected = '1' WHERE id = ?"; + $this->db->query($sql, array($row['id'])); + + break; + } + } + } + + $sql = "UPDATE heroes SET deleted='1', delete_name = '" . $res['name'] . "', name='' WHERE id = ?"; - $this->db->query($sql, array($id)); + $this->db->query($sql, array($id)); - return TRUE; - } - -// function get_hero_admin($id)? or gm? - - function create($data, $userid) - { - $name = ucfirst(mb_strtolower($data['name'], 'UTF-8')); - - if ($gender == 1) - { - $av = 'characters/base/male.png'; - $avt = 'characters/base/male_thumb.png'; - } - else - { - $av = 'characters/base/female.png'; - $avt = 'characters/base/female_thumb.png'; + return true; } - $sql = "UPDATE heroes SET selected='0' WHERE userid = ?"; + // function get_hero_admin($id)? or gm? - $this->db->query($sql, array($userid)); + public function create($data, $userid) + { + $name = ucfirst(mb_strtolower($data['name'], 'UTF-8')); - $sql = "SELECT * FROM hero_templates WHERE id = ?"; + if ($gender == 1) { + $av = 'characters/base/male.png'; + $avt = 'characters/base/male_thumb.png'; + } else { + $av = 'characters/base/female.png'; + $avt = 'characters/base/female_thumb.png'; + } - $q = $this->db->query($sql, array($data['class'])); + $sql = "UPDATE heroes SET selected='0' WHERE userid = ?"; - if (!$q->num_rows()) - return FALSE; + $this->db->query($sql, array($userid)); - $cd = $q->row_array(); + $sql = "SELECT * FROM hero_templates WHERE id = ?"; - //getting inventory template, and applying the stats + $q = $this->db->query($sql, array($data['class'])); + + if (!$q->num_rows()) { + return false; + } + + $cd = $q->row_array(); + + //getting inventory template, and applying the stats - $sql = "INSERT INTO heroes + $sql = "INSERT INTO heroes VALUES(default, '$userid', ?, default, default, ?, default, '" . $cd['max_health'] . "', '" . $cd['max_mana'] . "', '" . $cd['max_health'] . "', '" . $cd['max_mana'] . "', default, default, '" . $cd['nomod_max_health'] . "', @@ -165,58 +168,61 @@ class Hero_model extends MO_Model '" . $cd['nomod_heal_min'] . "', '" . $cd['nomod_heal_max'] . "', default, default, ?, default, ?, ?, default, '')"; - $this->db->query($sql, array($name, $data['class'], $data['gender'], $av, $avt)); + $this->db->query($sql, array($name, $data['class'], $data['gender'], $av, $avt)); - //add invertory here + //add invertory here //add starter spells //make actionbar entry - } + } - function hero_name_is_unique($name) - { - $name = ucfirst(mb_strtolower($name, 'UTF-8')); + public function hero_name_is_unique($name) + { + $name = ucfirst(mb_strtolower($name, 'UTF-8')); - $sql = "SELECT * FROM heroes WHERE name = ? LIMIT 0, 1"; + $sql = "SELECT * FROM heroes WHERE name = ? LIMIT 0, 1"; - $q = $this->db->query($sql, array($name)); + $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() - { - $sql = "SELECT * FROM hero_templates"; + public function all_hero_templates_admin() + { + $sql = "SELECT * FROM hero_templates"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows()) - return $q->result_array(); - else - return FALSE; - } + if ($q->num_rows()) { + return $q->result_array(); + } else { + return false; + } + } - function get_template_admin($id) - { - $sql = "SELECT * FROM hero_templates WHERE id = '$id'"; + public function get_template_admin($id) + { + $sql = "SELECT * FROM hero_templates WHERE id = '$id'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows()) - return $q->row_array(); - else - return FALSE; - } + if ($q->num_rows()) { + return $q->row_array(); + } else { + return false; + } + } - function edit_template_admin($d) - { - $c = $this->template_calc_stats($d, 'edit'); + public function edit_template_admin($d) + { + $c = $this->template_calc_stats($d, 'edit'); - $sql = "UPDATE hero_templates + $sql = "UPDATE hero_templates SET classname = '" . $d['classname'] . "', nomod_max_health = '" . $d['nomod_max_health'] . "', nomod_max_mana = '" . $d['nomod_max_mana'] . "', @@ -251,21 +257,21 @@ class Hero_model extends MO_Model heal_max = '" . $c['heal_max'] . "' WHERE id = '" . $d['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function add_template_admin($d) - { - //0 armor is being added, because when adding a new class, eqipments shouldn't exists in db + public function add_template_admin($d) + { + //0 armor is being added, because when adding a new class, eqipments shouldn't exists in db - //think about this! - //maybe this is uniform in template and normal mode! or can be made uniform - $c = $this->template_calc_stats($d, 'add'); + //think about this! + //maybe this is uniform in template and normal mode! or can be made uniform + $c = $this->template_calc_stats($d, 'add'); - $sql = "INSERT INTO hero_templates + $sql = "INSERT INTO hero_templates VALUES(default, '" . $d['classname'] . "', '" . $d['nomod_max_health'] . "', '" . $d['nomod_max_mana'] . "', '" . $c['max_health'] . "', '" . $c['max_mana'] . "', '" . $d['agility'] . "', '" . $d['strength'] . "', @@ -281,51 +287,50 @@ class Hero_model extends MO_Model '" . $d['nomod_heal_min'] . "', '" . $d['nomod_heal_max'] . "', '" . $c['heal_min'] . "', '" . $c['heal_max'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } - - //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) - { - $class = $d['classname']; - - $c['max_health'] = $this->hero_stat($class, 'max_health', $d); - $c['max_mana'] = $this->hero_stat($class, 'max_mana', $d); - - $c['attackpower'] = $this->hero_stat($class, 'attackpower', $d); - - $c['crit'] = $this->hero_stat($class, 'crit', $d); - $c['parry'] = $this->hero_stat($class, 'parry', $d); - $c['dodge'] = $this->hero_stat($class, 'dodge', $d); - - $c['damage_min'] = $this->hero_stat($class, 'damage_min', $d); - $c['damage_max'] = $this->hero_stat($class, 'damage_max', $d); - - $c['ranged_damage_min'] = $this->hero_stat($class, 'ranged_damage_min', $d); - $c['ranged_damage_max'] = $this->hero_stat($class, 'ranged_damage_max', $d); - - $c['heal_min'] = $this->hero_stat($class, 'heal_min', $d); - $c['heal_max'] = $this->hero_stat($class, 'heal_max', $d); - - if ($type == 'edit') - { - //STUB - //armor, damage, heal from items - $c['armor'] = 0; - $c['nomod_damage_min'] = $d['nomod_damage_min']; - $c['nomod_damage_max'] = $d['nomod_damage_max']; - - $c['nomod_ranged_damage_min'] = $d['nomod_ranged_damage_min']; - $c['nomod_ranged_damage_max'] = $d['nomod_ranged_damage_max']; - - $c['nomod_heal_min'] = $d['nomod_heal_min']; - $c['nomod_heal_max'] = $d['nomod_heal_max']; + $this->_create_sql($sql); } - return $c; - } + //this is for templates (calculating all stats) + //type can be add and edit -> edit does thing like armor calc, and damage + public function template_calc_stats($d, $type) + { + $class = $d['classname']; + + $c['max_health'] = $this->hero_stat($class, 'max_health', $d); + $c['max_mana'] = $this->hero_stat($class, 'max_mana', $d); + + $c['attackpower'] = $this->hero_stat($class, 'attackpower', $d); + + $c['crit'] = $this->hero_stat($class, 'crit', $d); + $c['parry'] = $this->hero_stat($class, 'parry', $d); + $c['dodge'] = $this->hero_stat($class, 'dodge', $d); + + $c['damage_min'] = $this->hero_stat($class, 'damage_min', $d); + $c['damage_max'] = $this->hero_stat($class, 'damage_max', $d); + + $c['ranged_damage_min'] = $this->hero_stat($class, 'ranged_damage_min', $d); + $c['ranged_damage_max'] = $this->hero_stat($class, 'ranged_damage_max', $d); + + $c['heal_min'] = $this->hero_stat($class, 'heal_min', $d); + $c['heal_max'] = $this->hero_stat($class, 'heal_max', $d); + + if ($type == 'edit') { + //STUB + //armor, damage, heal from items + $c['armor'] = 0; + $c['nomod_damage_min'] = $d['nomod_damage_min']; + $c['nomod_damage_max'] = $d['nomod_damage_max']; + + $c['nomod_ranged_damage_min'] = $d['nomod_ranged_damage_min']; + $c['nomod_ranged_damage_max'] = $d['nomod_ranged_damage_max']; + + $c['nomod_heal_min'] = $d['nomod_heal_min']; + $c['nomod_heal_max'] = $d['nomod_heal_max']; + } + + return $c; + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/image_model.php b/Mourne-CI/application/models/image_model.php index eb0defa..8e7400b 100755 --- a/Mourne-CI/application/models/image_model.php +++ b/Mourne-CI/application/models/image_model.php @@ -1,298 +1,283 @@ load->library('image_lib'); - - if ($data['apply_all']) - $this->prepare_dir('menu', $data['file'], $data['menu_group']); - else - $this->prepare_dir('menu', $data['file'], FALSE, $data['wm_text']); - - - if (!$data['apply_all']) + public function __construct() { - $data['source_image'] = $path . $data['wm_text'] . '.png'; - - $this->image_lib->initialize($data); - - $this->image_lib->watermark(); - - return; + parent::__construct(); } - //apply all is set - $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++) + public function apply_menu_images($data) { - $data['source_image'] = $path . $menu_file_list[$i] . '.png'; - $data['wm_text'] = $menu_list[$i]; + $path = './img/generated/'; - $this->image_lib->initialize($data); - $this->image_lib->watermark(); - $this->image_lib->clear(); - } - } + $this->load->library('image_lib'); - function prepare_dir($for, $sourcefile, $group = 1, $filename = FALSE) - { - $path = './img/generated/'; - $source = './img/imggen/' . $sourcefile; + if ($data['apply_all']) { + $this->prepare_dir('menu', $data['file'], $data['menu_group']); + } else { + $this->prepare_dir('menu', $data['file'], false, $data['wm_text']); + } - $this->load->helper('file'); + + if (!$data['apply_all']) { + $data['source_image'] = $path . $data['wm_text'] . '.png'; - delete_files($path, FALSE); + $this->image_lib->initialize($data); - if ($for == 'menu') - { - $img = read_file($source); + $this->image_lib->watermark(); - if (!$filename) - { - $menu_list = $this->get_menu_file_list($group); + return; + } - foreach ($menu_list as $row) - { - $file = $path . $row . '.png'; + //apply all is set + $menu_list = $this->get_menu_list($data['menu_group']); + $menu_file_list = $this->get_menu_file_list($data['menu_group']); - write_file($file, $img); - } - } - else - { - $file = $path . $filename . '.png'; + for ($i = 0; $i < sizeof($menu_list); $i++) { + $data['source_image'] = $path . $menu_file_list[$i] . '.png'; + $data['wm_text'] = $menu_list[$i]; - write_file($file, $img); - } - + $this->image_lib->initialize($data); + $this->image_lib->watermark(); + $this->image_lib->clear(); + } } - } + public function prepare_dir($for, $sourcefile, $group = 1, $filename = false) + { + $path = './img/generated/'; + $source = './img/imggen/' . $sourcefile; - 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'; - $data[] = 'Select Village'; - $data[] = 'Forum'; - $data[] = 'Changelog'; - $data[] = 'Settings'; - $data[] = 'Logout'; - $data[] = 'Forum Mod Panel'; - $data[] = 'GM Panel'; - $data[] = 'Admin Panel'; - } - - if ($group == 2) - { - $data[] = 'Stats'; + $this->load->helper('file'); + + delete_files($path, false); + + if ($for == 'menu') { + $img = read_file($source); + + if (!$filename) { + $menu_list = $this->get_menu_file_list($group); + + foreach ($menu_list as $row) { + $file = $path . $row . '.png'; + + write_file($file, $img); + } + } else { + $file = $path . $filename . '.png'; + + write_file($file, $img); + } + } } - return $data; - } + 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'; + $data[] = 'Select Village'; + $data[] = 'Forum'; + $data[] = 'Changelog'; + $data[] = 'Settings'; + $data[] = 'Logout'; + $data[] = 'Forum Mod Panel'; + $data[] = 'GM Panel'; + $data[] = 'Admin Panel'; + } + + if ($group == 2) { + $data[] = 'Stats'; + } - 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'; - $data[] = 'select_village'; - $data[] = 'forum'; - $data[] = 'changelog'; - $data[] = 'settings'; - $data[] = 'logout'; - $data[] = 'forum_mod_panel'; - $data[] = 'gm_panel'; - $data[] = 'admin_panel'; - } - - if ($group == 2) - { - $data[] = 'stats'; + return $data; } - return $data; - } + 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'; + $data[] = 'select_village'; + $data[] = 'forum'; + $data[] = 'changelog'; + $data[] = 'settings'; + $data[] = 'logout'; + $data[] = 'forum_mod_panel'; + $data[] = 'gm_panel'; + $data[] = 'admin_panel'; + } + + if ($group == 2) { + $data[] = 'stats'; + } - function get_menu_group_list_drop() - { - $data = array( + return $data; + } + + public function get_menu_group_list_drop() + { + $data = array( '1' => 'main', '2' => 'alt1'); - return $data; - } - - function apply_slot_images($data) - { - $path = './img/generated/'; - - $this->load->library('image_lib'); - - $this->prepare_dir('menu', $data['file'], FALSE, 'gen'); - - $data['source_image'] = $path . 'gen.png'; - - $this->image_lib->initialize($data); - $this->image_lib->watermark(); - $this->image_lib->clear(); - - $data['wm_type'] = 'text'; - $data['wm_text'] = $data['rank_text']; - $data['wm_font_size'] = $data['rank_font_size']; - $data['wm_vrt_alignment'] = $data['rank_v_align']; - $data['wm_hor_alignment'] = $data['rank_h_align']; - $data['wm_hor_offset'] = $data['rank_h_offset']; - $data['wm_vrt_offset'] = $data['rank_v_offset']; - $data['padding'] = $data['rank_padding']; - - $this->image_lib->initialize($data); - $this->image_lib->watermark(); - - } - - function get_file_list_drop() - { - $this->load->helper('directory'); - - $dir = directory_map('./img/imggen/', 1); - - foreach ($dir as $row) - { - $a = explode('.', $row); - if (isset($a[1])) - if ($a[1] == 'png' || $a[1] == 'PNG') - $data[$row] = $row; + return $data; } - return $data; - } - - function get_font_list_drop() - { - $this->load->helper('directory'); - - $dir = directory_map('./system/fonts', 1); - - foreach ($dir as $row) + public function apply_slot_images($data) { - $a = explode('.', $row); + $path = './img/generated/'; - if ($a[1] == 'ttf' || $a['1'] == 'TTF') - { - $data[$row] = $row; - } + $this->load->library('image_lib'); + + $this->prepare_dir('menu', $data['file'], false, 'gen'); + + $data['source_image'] = $path . 'gen.png'; + + $this->image_lib->initialize($data); + $this->image_lib->watermark(); + $this->image_lib->clear(); + + $data['wm_type'] = 'text'; + $data['wm_text'] = $data['rank_text']; + $data['wm_font_size'] = $data['rank_font_size']; + $data['wm_vrt_alignment'] = $data['rank_v_align']; + $data['wm_hor_alignment'] = $data['rank_h_align']; + $data['wm_hor_offset'] = $data['rank_h_offset']; + $data['wm_vrt_offset'] = $data['rank_v_offset']; + $data['padding'] = $data['rank_padding']; + + $this->image_lib->initialize($data); + $this->image_lib->watermark(); } - return $data; - } + public function get_file_list_drop() + { + $this->load->helper('directory'); - function get_v_align_drop() - { - $data = array( + $dir = directory_map('./img/imggen/', 1); + + foreach ($dir as $row) { + $a = explode('.', $row); + if (isset($a[1])) { + if ($a[1] == 'png' || $a[1] == 'PNG') { + $data[$row] = $row; + } + } + } + + return $data; + } + + public function get_font_list_drop() + { + $this->load->helper('directory'); + + $dir = directory_map('./system/fonts', 1); + + foreach ($dir as $row) { + $a = explode('.', $row); + + if ($a[1] == 'ttf' || $a['1'] == 'TTF') { + $data[$row] = $row; + } + } + + return $data; + } + + public function get_v_align_drop() + { + $data = array( 'top' => 'top', 'middle' => 'middle', 'bottom' => 'bottom'); - return $data; - } + return $data; + } - function get_h_align_drop() - { - $data = array( + public function get_h_align_drop() + { + $data = array( 'left' => 'left', 'center' => 'center', 'right' => 'right'); - return $data; - } - - function get_overlay_list_drop() - { - $this->load->helper('directory'); - - $dir = directory_map('./img/imggen/overlay/', 1); - - foreach ($dir as $row) + return $data; + } + + public function get_overlay_list_drop() { - $data[$row] = $row; + $this->load->helper('directory'); + + $dir = directory_map('./img/imggen/overlay/', 1); + + foreach ($dir as $row) { + $data[$row] = $row; + } + + return $data; } - return $data; - } + public function save_menu_data($data) + { + $a = 'type : ' . $data['wm_type'] . "\n"; + $a .= 'quality: ' . $data['quality'] . "\n"; + $a .= 'file: ' . $data['file'] . "\n"; + $a .= 'padding: ' . $data['padding'] . "\n"; + $a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n"; + $a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n"; + $a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n"; + $a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n"; + $a .= 'text: ' . $data['wm_text'] . "\n"; + $a .= 'font path: ' . $data['wm_font_path'] . "\n"; + $a .= 'font size: ' . $data['wm_font_size'] . "\n"; + $a .= 'font color: ' . $data['wm_font_color'] . "\n"; + $a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n"; + $a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n"; + $a .= 'apply all: ' . $data['apply_all'] . "\n"; + $a .= 'Menu Group: ' . $data['menu_group'] . "\n"; - function save_menu_data($data) - { - $a = 'type : ' . $data['wm_type'] . "\n"; - $a .= 'quality: ' . $data['quality'] . "\n"; - $a .= 'file: ' . $data['file'] . "\n"; - $a .= 'padding: ' . $data['padding'] . "\n"; - $a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n"; - $a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n"; - $a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n"; - $a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n"; - $a .= 'text: ' . $data['wm_text'] . "\n"; - $a .= 'font path: ' . $data['wm_font_path'] . "\n"; - $a .= 'font size: ' . $data['wm_font_size'] . "\n"; - $a .= 'font color: ' . $data['wm_font_color'] . "\n"; - $a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n"; - $a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n"; - $a .= 'apply all: ' . $data['apply_all'] . "\n"; - $a .= 'Menu Group: ' . $data['menu_group'] . "\n"; + $this->load->helper('file'); - $this->load->helper('file'); + write_file('./img/generated/settings.txt', $a); + } - write_file('./img/generated/settings.txt', $a); - } + public function save_slot_data($data) + { + $a = 'type : ' . $data['wm_type'] . "\n"; + $a .= 'quality: ' . $data['quality'] . "\n"; + $a .= 'file: ' . $data['file'] . "\n"; + $a .= 'padding: ' . $data['padding'] . "\n"; + $a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n"; + $a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n"; + $a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n"; + $a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n"; + $a .= 'text: ' . $data['wm_text'] . "\n"; + $a .= 'font path: ' . $data['wm_font_path'] . "\n"; + $a .= 'font size: ' . $data['wm_font_size'] . "\n"; + $a .= 'font color: ' . $data['wm_font_color'] . "\n"; + $a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n"; + $a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n"; + $a .= '------------------------image---------------------------' . "\n"; + $a .= 'overlay image: ' . $data['wm_overlay_path'] . "\n"; + $a .= 'opacity: ' . $data['wm_opacity'] . "\n"; + $a .= 'x transp: ' . $data['wm_x_transp'] . "\n"; + $a .= 'y transp: ' . $data['wm_y_transp'] . "\n"; + $a .= '------------------------rank----------------------------' . "\n"; + $a .= 'text: ' . $data['rank_text'] . "\n"; + $a .= 'font size: ' . $data['rank_font_size'] . "\n"; + $a .= 'V align: ' . $data['rank_v_align'] . "\n"; + $a .= 'H align: ' . $data['rank_h_align'] . "\n"; + $a .= 'H offset: ' . $data['rank_h_offset'] . "\n"; + $a .= 'V offset: ' . $data['rank_v_offset'] . "\n"; + $a .= 'padding: ' . $data['rank_padding'] . "\n"; - function save_slot_data($data) - { - $a = 'type : ' . $data['wm_type'] . "\n"; - $a .= 'quality: ' . $data['quality'] . "\n"; - $a .= 'file: ' . $data['file'] . "\n"; - $a .= 'padding: ' . $data['padding'] . "\n"; - $a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n"; - $a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n"; - $a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n"; - $a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n"; - $a .= 'text: ' . $data['wm_text'] . "\n"; - $a .= 'font path: ' . $data['wm_font_path'] . "\n"; - $a .= 'font size: ' . $data['wm_font_size'] . "\n"; - $a .= 'font color: ' . $data['wm_font_color'] . "\n"; - $a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n"; - $a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n"; - $a .= '------------------------image---------------------------' . "\n"; - $a .= 'overlay image: ' . $data['wm_overlay_path'] . "\n"; - $a .= 'opacity: ' . $data['wm_opacity'] . "\n"; - $a .= 'x transp: ' . $data['wm_x_transp'] . "\n"; - $a .= 'y transp: ' . $data['wm_y_transp'] . "\n"; - $a .= '------------------------rank----------------------------' . "\n"; - $a .= 'text: ' . $data['rank_text'] . "\n"; - $a .= 'font size: ' . $data['rank_font_size'] . "\n"; - $a .= 'V align: ' . $data['rank_v_align'] . "\n"; - $a .= 'H align: ' . $data['rank_h_align'] . "\n"; - $a .= 'H offset: ' . $data['rank_h_offset'] . "\n"; - $a .= 'V offset: ' . $data['rank_v_offset'] . "\n"; - $a .= 'padding: ' . $data['rank_padding'] . "\n"; + $this->load->helper('file'); - $this->load->helper('file'); - - write_file('./img/generated/settings.txt', $a); - } + write_file('./img/generated/settings.txt', $a); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/item_model.php b/Mourne-CI/application/models/item_model.php index 17dd477..3d1608c 100644 --- a/Mourne-CI/application/models/item_model.php +++ b/Mourne-CI/application/models/item_model.php @@ -2,90 +2,96 @@ class Item_model extends MO_Model { - const MAX_EQUIPMENT = 20; //19, starts with zero + const MAX_EQUIPMENT = 20; //19, starts with zero - function __construct() - { - parent::__construct(); - } - - //this will equip too if needed! - 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; - - //nothing needs to be done (same item twice) - if (($d1 == $d3) && ($d2 == $d4)) - return TRUE; - - //hero has to be set from controller! - if (!$this->hero) - return 'Internal error'; - - //just move in inventory - if ($d1 == 'iv' && $d3 == 'iv') + public function __construct() { - $sql = "SELECT * FROM heros_inventory + parent::__construct(); + } + + //this will equip too if needed! + 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; + } + + //nothing needs to be done (same item twice) + if (($d1 == $d3) && ($d2 == $d4)) { + return true; + } + + //hero has to be set from controller! + if (!$this->hero) { + return 'Internal error'; + } + + //just move in inventory + if ($d1 == 'iv' && $d3 == 'iv') { + $sql = "SELECT * FROM heros_inventory WHERE container = 1 AND (slot = ? OR slot = ?) AND charid = ?"; - $q = $this->db->query($sql, array($d2, $d4, $this->hero['id'])); + $q = $this->db->query($sql, array($d2, $d4, $this->hero['id'])); - $num = $q->num_rows(); + $num = $q->num_rows(); - if (!$num) - return FALSE; + if (!$num) { + return false; + } - $res = $q->result_array(); + $res = $q->result_array(); - $item1 = $res[0]; + $item1 = $res[0]; - if ($num == 2) - $item2 = $res[1]; - else - $item2 = FALSE; + if ($num == 2) { + $item2 = $res[1]; + } else { + $item2 = false; + } - if (!$item2) - { - $sql = "UPDATE heros_inventory + if (!$item2) { + $sql = "UPDATE heros_inventory SET slot = ? WHERE id = ?"; - if ($item1['slot'] == $d2) - $to = $d4; - else - $to = $d2; + if ($item1['slot'] == $d2) { + $to = $d4; + } else { + $to = $d2; + } - $this->db->query($sql, array($to, $item1['id'])); + $this->db->query($sql, array($to, $item1['id'])); - return TRUE; - } + return true; + } - //we only get here it two items needs to be swapped - $sql = "UPDATE heros_inventory SET slot = ? WHERE id = ?"; + //we only get here it two items needs to be swapped + $sql = "UPDATE heros_inventory SET slot = ? WHERE id = ?"; - $this->db->query($sql, array($item1['slot'], $item2['id'])); - $this->db->query($sql, array($item2['slot'], $item1['id'])); + $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') - $d1 = 1; - else - $d1 = 2; + //equipping has to be performed (iv/iv case already handled!) + if ($d1 == 'iv') { + $d1 = 1; + } else { + $d1 = 2; + } - if ($d3 == 'iv') - $d3 = 1; - else - $d3 = 2; + if ($d3 == 'iv') { + $d3 = 1; + } else { + $d3 = 2; + } - $sql = "SELECT heros_inventory.id AS invid,heros_inventory.is_soulbound,heros_inventory.stack_size, + $sql = "SELECT heros_inventory.id AS invid,heros_inventory.is_soulbound,heros_inventory.stack_size, heros_inventory.container,heros_inventory.slot,hero_items.* FROM heros_inventory LEFT JOIN hero_items on heros_inventory.itemid = hero_items.id @@ -93,398 +99,360 @@ class Item_model extends MO_Model (heros_inventory.container = ? AND heros_inventory.slot = ?)) AND charid = ?"; - $q = $this->db->query($sql, array($d1, $d2, $d3, $d4, $this->hero['id'])); + $q = $this->db->query($sql, array($d1, $d2, $d3, $d4, $this->hero['id'])); - $swap = FALSE; + $swap = false; - $num = $q->num_rows(); + $num = $q->num_rows(); - if ($num == 2) - { - $res = $q->result_array(); + if ($num == 2) { + $res = $q->result_array(); - if ($res[0]['container'] == 1) - { - //0 is in bag - $equip = $res[0]; - $deequip = $res[1]; - } - elseif ($res[1]['container'] == 1) - { - //1 is in bag - $equip = $res[1]; - $deequip = $res[0]; - } - else - { - //swap - $equip = $res[0]; - $deequip = $res[1]; - $swap = TRUE; - } - } - else - { - $res = $q->row_array(); + if ($res[0]['container'] == 1) { + //0 is in bag + $equip = $res[0]; + $deequip = $res[1]; + } elseif ($res[1]['container'] == 1) { + //1 is in bag + $equip = $res[1]; + $deequip = $res[0]; + } else { + //swap + $equip = $res[0]; + $deequip = $res[1]; + $swap = true; + } + } else { + $res = $q->row_array(); - if ($res['container'] == 1) - { - //not equipped, just equip it - $equip = $res; - $deequip = FALSE; + if ($res['container'] == 1) { + //not equipped, just equip it + $equip = $res; + $deequip = false; - if ($d1 == 1) - $equipslot = $d4; - else - $equipslot = $d2; - } - else - { - if ($d1 == 2 && $d3 == 2) - { - //switching between 2 equipslots, but one of them is empty - $equip = $res; - $deequip = FALSE; + if ($d1 == 1) { + $equipslot = $d4; + } else { + $equipslot = $d2; + } + } else { + if ($d1 == 2 && $d3 == 2) { + //switching between 2 equipslots, but one of them is empty + $equip = $res; + $deequip = false; - if ($equip['slot'] == $d2) - $equipslot = $d4; - else - $equipslot = $d2; + if ($equip['slot'] == $d2) { + $equipslot = $d4; + } else { + $equipslot = $d2; + } - $swap = TRUE; - } - else - { - //equipped, just deequip it - $equip = FALSE; - $deequip = $res; - - if ($d1 == 2) - $deequipslot = $d4; - else - $deequipslot = $d2; - } - } - } + $swap = true; + } else { + //equipped, just deequip it + $equip = false; + $deequip = $res; + + if ($d1 == 2) { + $deequipslot = $d4; + } else { + $deequipslot = $d2; + } + } + } + } - $this->load->helper('equipment'); + $this->load->helper('equipment'); - if ($equip) - { - //$cbe = can be equipped - $cbe = can_be_equipped($equip, $this->hero); + if ($equip) { + //$cbe = can be equipped + $cbe = can_be_equipped($equip, $this->hero); - if (!isset($cbe)) - return "Internal error! $cbe is not set!"; + 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']) { + $equipslot = $deequip['slot']; + } + + if (!isset($equipslot)) { + return "That item cannot be equipped into that slot."; + } + + if ($cbe['two_handed']) { + $eq = $this->prep_two_hand(); + + if ($eq !== true) { + return $eq; + } + } + + $this->hero_remove_stats($deequip); + $this->hero_add_stats($equip); + + $sql = "UPDATE heros_inventory SET container = ?, slot = ? WHERE id = ?"; + + //deequipping + $this->db->query($sql, array(1, $equip['slot'], $deequip['invid'])); + + //equip + $this->db->query($sql, array(2, $equipslot, $equip['invid'])); + + $this->calc_hero_stats(); + + return true; + } else { + return $cbe['message']; + } + } + + //switching between 2 slots + 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']))) { + 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; + } + + //just deequip + if ($deequip && !$swap) { + $sql = "UPDATE heros_inventory SET container = 1, slot = ? WHERE id = ?"; + + $this->db->query($sql, array($deequipslot, $deequip['invid'])); + + $this->hero_remove_stats($deequip); + $this->calc_hero_stats(); + + return true; + } + + //just equip + if ($equip && !$swap) { + if (!$cbe['can']) { + return $cbe['message']; + } + + if (!($cbe['allowed_slot1'] == $equipslot || $cbe['allowed_slot2'] == $equipslot)) { + return 'That item cannot be equipped into that slot.'; + } + + if ($cbe['two_handed']) { + $eq = $this->prep_two_hand(); + + if ($eq !== true) { + return $eq; + } + } + + $sql = "UPDATE heros_inventory SET container = 2, slot = ? WHERE id = ?"; + + $this->db->query($sql, array($equipslot, $equip['invid'])); + + $this->hero_add_stats($equip); + $this->calc_hero_stats(); + + return true; + } + + //switching between two equipslots, when one of the slots is empty + 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 false; } - //each of these functions has to return! - - //for switching items from inventory - if ($equip && $deequip && !$swap) + //unequips the off hand, if the user wants to equip a two-hand wep + public function prep_two_hand() { - if ($cbe['can'] === TRUE) - { - if ($cbe['allowed_slot1'] == $deequip['slot'] || $cbe['allowed_slot2'] == $deequip['slot']) - $equipslot = $deequip['slot']; - - if (!isset($equipslot)) - return "That item cannot be equipped into that slot."; - - if ($cbe['two_handed']) - { - $eq = $this->prep_two_hand(); - - if ($eq !== TRUE) - return $eq; - } - - $this->hero_remove_stats($deequip); - $this->hero_add_stats($equip); - - $sql = "UPDATE heros_inventory SET container = ?, slot = ? WHERE id = ?"; - - //deequipping - $this->db->query($sql, array(1, $equip['slot'], $deequip['invid'])); - - //equip - $this->db->query($sql, array(2, $equipslot, $equip['invid'])); - - $this->calc_hero_stats(); - - return TRUE; - } - else - { - return $cbe['message']; - } - } - - //switching between 2 slots - 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']))) - 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; - } - - //just deequip - if ($deequip && !$swap) - { - $sql = "UPDATE heros_inventory SET container = 1, slot = ? WHERE id = ?"; - - $this->db->query($sql, array($deequipslot, $deequip['invid'])); - - $this->hero_remove_stats($deequip); - $this->calc_hero_stats(); - - return TRUE; - } - - //just equip - if ($equip && !$swap) - { - if (!$cbe['can']) - return $cbe['message']; - - if (!($cbe['allowed_slot1'] == $equipslot || $cbe['allowed_slot2'] == $equipslot)) - return 'That item cannot be equipped into that slot.'; - - if ($cbe['two_handed']) - { - $eq = $this->prep_two_hand(); - - if ($eq !== TRUE) - return $eq; - } - - $sql = "UPDATE heros_inventory SET container = 2, slot = ? WHERE id = ?"; - - $this->db->query($sql, array($equipslot, $equip['invid'])); - - $this->hero_add_stats($equip); - $this->calc_hero_stats(); - - return TRUE; - } - - //switching between two equipslots, when one of the slots is empty - 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 FALSE; - } - - //unequips the off hand, if the user wants to equip a two-hand wep - function prep_two_hand() - { - $sql = "SELECT heros_inventory.id AS invid,heros_inventory.is_soulbound,heros_inventory.stack_size, + $sql = "SELECT heros_inventory.id AS invid,heros_inventory.is_soulbound,heros_inventory.stack_size, heros_inventory.container,heros_inventory.slot,hero_items.* FROM heros_inventory LEFT JOIN hero_items on heros_inventory.itemid = hero_items.id WHERE (heros_inventory.container = 2 AND heros_inventory.slot = 17) AND charid = ?"; - $q = $this->db->query($sql, array($this->hero['id'])); + $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(); + $res = $q->row_array(); - //find an empty place - $sql = "SELECT * FROM heros_inventory WHERE container = 1 AND charid = ?"; + //find an empty place + $sql = "SELECT * FROM heros_inventory WHERE container = 1 AND charid = ?"; - $q = $this->db->query($sql, array($this->hero['id'])); + $q = $this->db->query($sql, array($this->hero['id'])); - $slot = FALSE; + $slot = false; - if ($q->num_rows()) - { - $inv = $q->result_array(); + 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; - break; - } - } + foreach ($inv as $row) { + if ($row['slot'] == $i) { + $found = true; + break; + } + } - if (!$found) - { - $slot = $i; - break; - } - } - } - else - { - $slot = 0; + if (!$found) { + $slot = $i; + break; + } + } + } else { + $slot = 0; + } + + if ($slot === false) { + return "You don't have any space in your inventory, to unequip the off hand."; + } + + $this->hero_remove_stats($res); + + $sql = "UPDATE heros_inventory SET slot = ?, container = 1 WHERE id = ?"; + + $this->db->query($sql, array($slot, $res['invid'])); + + return true; } - if ($slot === FALSE) - return "You don't have any space in your inventory, to unequip the off hand."; - - $this->hero_remove_stats($res); - - $sql = "UPDATE heros_inventory SET slot = ?, container = 1 WHERE id = ?"; - - $this->db->query($sql, array($slot, $res['invid'])); - - return TRUE; - - } - - //returns ['equipment'], ['money'], ['inventory'] - function get_inventory($charid) - { - $sql = "SELECT heros_inventory.is_soulbound,heros_inventory.stack_size,heros_inventory.container, + //returns ['equipment'], ['money'], ['inventory'] + public function get_inventory($charid) + { + $sql = "SELECT heros_inventory.is_soulbound,heros_inventory.stack_size,heros_inventory.container, heros_inventory.slot,hero_items.* FROM heros_inventory LEFT JOIN hero_items ON heros_inventory.itemid=hero_items.id WHERE charid = ?"; - $q = $this->db->query($sql, array($charid)); + $q = $this->db->query($sql, array($charid)); - if ($q->num_rows()) - $res = $q->result_array(); - else - $res = FALSE; + if ($q->num_rows()) { + $res = $q->result_array(); + } 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) - { - $data[] = $row; - $found = TRUE; - break; - } - } + $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; + break; + } + } - if (!$found) - { - $data[] = FALSE; - } + if (!$found) { + $data[] = false; + } - $found = FALSE; - } - else - { - $data[] = FALSE; - } - } + $found = false; + } else { + $data[] = false; + } + } - //sort it + //sort it - $r['inventory'] = $data; + $r['inventory'] = $data; - if ($res) - { - foreach ($res as $row) - { - if ($row['container'] == 0) - { - $money = $row; - break; - } - } - } + if ($res) { + foreach ($res as $row) { + if ($row['container'] == 0) { + $money = $row; + break; + } + } + } - if (isset($money)) - $r['money'] = $money; - else - $r['money'] = 0; + if (isset($money)) { + $r['money'] = $money; + } 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) - { - $eq[] = $row; - $found = TRUE; - break; - } - } + //equipment + $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; + break; + } + } - if (!$found) - { - $eq[] = FALSE; - } + if (!$found) { + $eq[] = false; + } - $found = FALSE; - } - else - $eq[] = FALSE; - } + $found = false; + } else { + $eq[] = false; + } + } - $r['equipment'] = $eq; + $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) - { - $seq[] = $row; - $found = TRUE; - break; - } - } + //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) { + $seq[] = $row; + $found = true; + break; + } + } - if (!$found) - { - $seq[] = FALSE; - } + if (!$found) { + $seq[] = false; + } - $found = FALSE; - } + $found = false; + } - $r['equipment'] = $seq; + $r['equipment'] = $seq; + } + + return $r; } - return $r; - - } - - function add_item_admin($data) - { - $sql = "INSERT INTO hero_items + public function add_item_admin($data) + { + $sql = "INSERT INTO hero_items VALUES(default, " . $this->db->escape($data['name']) . ", " . $this->db->escape($data['icon']) . ", @@ -543,14 +511,14 @@ class Item_model extends MO_Model '" . $data['data1'] . "', '" . $data['data2'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function edit_item_admin($data) - { - $sql = "UPDATE hero_items + public function edit_item_admin($data) + { + $sql = "UPDATE hero_items SET name = " . $this->db->escape($data['name']) . ", icon = " . $this->db->escape($data['icon']) . ", quality = '" . $data['quality'] . "', @@ -609,68 +577,71 @@ class Item_model extends MO_Model data2 = '" . $data['data2'] . "' WHERE id = '" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } - - function get_item_admin($id) - { - $sql = "SELECT * FROM hero_items WHERE id = ?"; - - $q = $this->db->query($sql, array($id)); - - if ($q->num_rows()) - return $q->row_array(); - - return FALSE; - } - - function all_items_admin() - { - $sql = "SELECT * FROM hero_items"; - - $q = $this->db->query($sql); - - if ($q->num_rows()) - return $q->result_array(); - - return FALSE; - } - - function all_items_drop_admin() - { - $sql = "SELECT * FROM hero_items"; - - $q = $this->db->query($sql); - - if (!$q->num_rows()) - return FALSE; - - $res = $q->result_array(); - - foreach ($res as $row) - { - $data[$row['id']] = $row['name']; + $this->_create_sql($sql); } - if (!isset($data)) - return FALSE; + public function get_item_admin($id) + { + $sql = "SELECT * FROM hero_items WHERE id = ?"; - return $data; - } + $q = $this->db->query($sql, array($id)); - function get_class_item_templates($classid) - { - $sql = "SELECT * FROM hero_inventory_templates WHERE classid = ?"; + if ($q->num_rows()) { + return $q->row_array(); + } + + return false; + } + + public function all_items_admin() + { + $sql = "SELECT * FROM hero_items"; + + $q = $this->db->query($sql); + + if ($q->num_rows()) { + return $q->result_array(); + } + + return false; + } + + public function all_items_drop_admin() + { + $sql = "SELECT * FROM hero_items"; + + $q = $this->db->query($sql); + + if (!$q->num_rows()) { + return false; + } + + $res = $q->result_array(); + + foreach ($res as $row) { + $data[$row['id']] = $row['name']; + } + + if (!isset($data)) { + return false; + } + + return $data; + } + + public function get_class_item_templates($classid) + { + $sql = "SELECT * FROM hero_inventory_templates WHERE classid = ?"; - $q = $this->db->query($sql, array($classid)); + $q = $this->db->query($sql, array($classid)); - if ($q->num_rows()) - return $q->result_array(); - - return FALSE; - } + if ($q->num_rows()) { + return $q->result_array(); + } + return false; + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/log_model.php b/Mourne-CI/application/models/log_model.php index e0f2092..5914820 100755 --- a/Mourne-CI/application/models/log_model.php +++ b/Mourne-CI/application/models/log_model.php @@ -1,82 +1,83 @@ db->query($sql); - - if (!$q->num_rows()) - return; - - $res = $q->row_array(); - - if ($res['villageid'] != $villageid) - return; - - $sql = "DELETE FROM combat_logs WHERE id='$id'"; - - $this->db->query($sql); - } - - 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; - - $res = $q->row_array(); - - if ($res['villageid'] != $villageid) - return FALSE; - - if ($res['new']) + public function __construct() { - $sql = "UPDATE combat_logs SET new='0' WHERE id='$id'"; - $this->db->query($sql); + parent::__construct(); } - return $res; - } - - 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; - - $res = $q->result_array(); - - $new = FALSE; - foreach ($res as $row) + public function delete_combat_log($id, $villageid) { - if ($row['new']) - { - $new = TRUE; - break; - } + $sql = "SELECT * FROM combat_logs WHERE id='$id'"; + + $q = $this->db->query($sql); + + if (!$q->num_rows()) { + return; + } + + $res = $q->row_array(); + + if ($res['villageid'] != $villageid) { + return; + } + + $sql = "DELETE FROM combat_logs WHERE id='$id'"; + + $this->db->query($sql); } - if (!$new) + public function get_combat_log($id, $villageid) { - $sql = "UPDATE villages SET new_log='0' WHERE id='$villageid'"; + $sql = "SELECT * FROM combat_logs WHERE id='$id'"; - $this->db->query($sql); + $q = $this->db->query($sql); + + if (!$q->num_rows()) { + return false; + } + + $res = $q->row_array(); + + if ($res['villageid'] != $villageid) { + return false; + } + + if ($res['new']) { + $sql = "UPDATE combat_logs SET new='0' WHERE id='$id'"; + $this->db->query($sql); + } + + return $res; } + + public function get_combat_logs($villageid) + { + $sql = "SELECT * FROM combat_logs WHERE villageid='$villageid' ORDER BY time DESC"; - return $res; - } + $q = $this->db->query($sql); + + if (!$q->num_rows()) { + return false; + } + + $res = $q->result_array(); + + $new = false; + foreach ($res as $row) { + if ($row['new']) { + $new = true; + break; + } + } + + if (!$new) { + $sql = "UPDATE villages SET new_log='0' WHERE id='$villageid'"; + + $this->db->query($sql); + } + + return $res; + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/mail_model.php b/Mourne-CI/application/models/mail_model.php index 87ea2da..3a99d51 100755 --- a/Mourne-CI/application/models/mail_model.php +++ b/Mourne-CI/application/models/mail_model.php @@ -2,233 +2,235 @@ class Mail_model extends MO_Model { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function save_draft($data, $userid) - { - //values id, userid, friend, name, X, Y, time, subject, body - $sql = "INSERT INTO mail_drafts + public function save_draft($data, $userid) + { + //values id, userid, friend, name, X, Y, time, subject, body + $sql = "INSERT INTO mail_drafts VALUES(default, '$userid', ?, ?, ?, ?, '" . time() . "', ?, ?)"; - //friend, name, X, Y, subject, body - $this->db->query($sql, array(0, $data['name'], 0, 0, $data['subject'], $data['message'])); - } + //friend, name, X, Y, subject, body + $this->db->query($sql, array(0, $data['name'], 0, 0, $data['subject'], $data['message'])); + } - function get_drafts($userid) - { - $sql = "SELECT * FROM mail_drafts WHERE userid='$userid'"; + public function get_drafts($userid) + { + $sql = "SELECT * FROM mail_drafts WHERE userid='$userid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return FALSE; + if (!$q->num_rows()) { + return false; + } - return $q->result_array(); - } + return $q->result_array(); + } - function get_draft($id, $userid) - { - $sql = "SELECT * FROM mail_drafts WHERE id = ?"; + public function get_draft($id, $userid) + { + $sql = "SELECT * FROM mail_drafts WHERE id = ?"; - $q = $this->db->query($sql, array($id)); + $q = $this->db->query($sql, array($id)); - if (!$q->num_rows()) - return FALSE; + if (!$q->num_rows()) { + return false; + } - $res = $q->row_array(); + $res = $q->row_array(); - if ($res['userid'] != $userid) - return FALSE; + if ($res['userid'] != $userid) { + return false; + } - return $res; - } + return $res; + } - function delete_draft($id, $userid) - { - $sql = "DELETE FROM mail_drafts WHERE id = ? AND userid = ?"; + public function delete_draft($id, $userid) + { + $sql = "DELETE FROM mail_drafts WHERE id = ? AND userid = ?"; - $this->db->query($sql, array($id, $userid)); - } + $this->db->query($sql, array($id, $userid)); + } - function get_inbox($userid, $new) - { - $sql = "SELECT mails.*,users.username FROM mails + public function get_inbox($userid, $new) + { + $sql = "SELECT mails.*,users.username FROM mails LEFT JOIN users on mails.sender=users.id WHERE owner='$userid' ORDER BY time DESC"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return FALSE; + if (!$q->num_rows()) { + return false; + } - $res = $q->result_array(); + $res = $q->result_array(); - if (!$new) - return $res; + if (!$new) { + return $res; + } - $found = FALSE; - foreach ($res as $row) - { - if ($row['new']) - { - $found = TRUE; - break; - } + $found = false; + foreach ($res as $row) { + if ($row['new']) { + $found = true; + break; + } + } + + if ($found) { + return $res; + } + + $sql = "UPDATE users SET new_mail='0' WHERE id='$userid'"; + + $this->db->query($sql); + + return $res; } - if ($found) - return $res; - - $sql = "UPDATE users SET new_mail='0' WHERE id='$userid'"; - - $this->db->query($sql); - - return $res; - } - - function send_message($data, $userid) - { - $sql = "SELECT * FROM users WHERE username = ?"; - - $q = $this->db->query($sql, array($data['name'])); - - if (!$q->num_rows()) - return; - - $res = $q->row_array(); - - $data['subject'] = htmlspecialchars($data['subject'], ENT_HTML5, 'UTF-8'); - - if (strlen($data['subject']) >= 45) - $data['subject'] = (substr($data['subject'], 0, 45) . '...'); - - //determining line endings - $w = substr_count($data['message'], "\r\n"); - - if ($w) - $exp = "\r\n"; - else - $exp = "\n"; - - $message = explode($exp, $data['message']); - - if ($message) + public function send_message($data, $userid) { - $d = ""; - foreach ($message as $row) - { - if (strlen($row) > 70) - { - //split into multiple lines - for ($i = 0; $i <= (floor(strlen($row) / 70)); $i++) - { - - $sub = substr($row, (0 + ($i * 70)), 70); + $sql = "SELECT * FROM users WHERE username = ?"; - $d .= $sub; + $q = $this->db->query($sql, array($data['name'])); - if (strlen($sub) == 70) - $d .= "«"; + if (!$q->num_rows()) { + return; + } - $d .= "\r\n"; - } - } - else - { - $d .= $row . "\r\n"; - } - } + $res = $q->row_array(); - $data['message'] = $d; - } + $data['subject'] = htmlspecialchars($data['subject'], ENT_HTML5, 'UTF-8'); - $data['message'] = htmlspecialchars($data['message'], ENT_HTML5, 'UTF-8'); + if (strlen($data['subject']) >= 45) { + $data['subject'] = (substr($data['subject'], 0, 45) . '...'); + } - $breaks = array("\r\n", "\n"); - $text = str_ireplace($breaks, "
", $data['message']); + //determining line endings + $w = substr_count($data['message'], "\r\n"); - $sql = "INSERT INTO mails VALUES(default, + if ($w) { + $exp = "\r\n"; + } else { + $exp = "\n"; + } + + $message = explode($exp, $data['message']); + + if ($message) { + $d = ""; + foreach ($message as $row) { + if (strlen($row) > 70) { + //split into multiple lines + for ($i = 0; $i <= (floor(strlen($row) / 70)); $i++) { + $sub = substr($row, (0 + ($i * 70)), 70); + + $d .= $sub; + + if (strlen($sub) == 70) { + $d .= "«"; + } + + $d .= "\r\n"; + } + } else { + $d .= $row . "\r\n"; + } + } + + $data['message'] = $d; + } + + $data['message'] = htmlspecialchars($data['message'], ENT_HTML5, 'UTF-8'); + + $breaks = array("\r\n", "\n"); + $text = str_ireplace($breaks, "
", $data['message']); + + $sql = "INSERT INTO mails VALUES(default, '" . $res['id'] . "', '$userid', '" . time() . "', ?, ?, '1')"; - $this->db->query($sql, array($data['subject'], $text)); + $this->db->query($sql, array($data['subject'], $text)); - $sql = "UPDATE users SET new_mail='1' WHERE id='" . $res['id'] . "'"; + $sql = "UPDATE users SET new_mail='1' WHERE id='" . $res['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - //saving mail to sent - //id, userid, to_id, to, time, subject, body - $sql = "INSERT INTO mail_sent VALUES(default, ?, ?, ?, " . time(). ", ?, ?)"; + //saving mail to sent + //id, userid, to_id, to, time, subject, body + $sql = "INSERT INTO mail_sent VALUES(default, ?, ?, ?, " . time(). ", ?, ?)"; - $sent = array($userid, $res['id'], $res['username'], $data['subject'], $data['message']); + $sent = array($userid, $res['id'], $res['username'], $data['subject'], $data['message']); - $this->db->query($sql, $sent); - } + $this->db->query($sql, $sent); + } - 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 + 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 LEFT JOIN users ON mails.sender=users.id WHERE mails.id = ? AND mails.owner = ?"; - $q = $this->db->query($sql, array($id, $userid)); + $q = $this->db->query($sql, array($id, $userid)); - if (!$q->num_rows()) - return FALSE; + if (!$q->num_rows()) { + return false; + } - $res = $q->row_array(); + $res = $q->row_array(); - if ($res['new']) - { - //userid is correct we can query with just the id - $sql = "UPDATE mails SET new='0' WHERE id = ?"; + 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)); + $this->db->query($sql, array($id)); + } + + if ($edit) { + //just in case + $breaks = array("
","
","
"); + + $data['body'] = str_ireplace($breaks, "\r\n", $data['body']); + + $data['body'] = htmlspecialchars_decode($data['body'], ENT_HTML5, 'UTF-8'); + $data['subject'] = htmlspecialchars_decode($data['subject'], ENT_HTML5, 'UTF-8'); + } + + return $res; } - if ($edit) + public function get_sent($id, $userid) { - //just in case - $breaks = array("
","
","
"); + //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 = ?"; - $data['body'] = str_ireplace($breaks, "\r\n", $data['body']); + $q = $this->db->query($sql, array($id, $userid)); - $data['body'] = htmlspecialchars_decode($data['body'], ENT_HTML5, 'UTF-8'); - $data['subject'] = htmlspecialchars_decode($data['subject'], ENT_HTML5, 'UTF-8'); + if (!$q->num_rows()) { + return false; + } + + return $q->row_array(); } - return $res; - } - 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 = ?"; + public function get_all_sent($userid) + { + $sql = "SELECT * FROM mail_sent WHERE userid = ?"; - $q = $this->db->query($sql, array($id, $userid)); + $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_all_sent($userid) - { - $sql = "SELECT * FROM mail_sent WHERE userid = ?"; - - $q = $this->db->query($sql, array($userid)); - - if (!$q->num_rows()) - return FALSE; - - return $q->result_array(); - } + return $q->result_array(); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/map_model.php b/Mourne-CI/application/models/map_model.php index b5b9c4d..4b994ce 100755 --- a/Mourne-CI/application/models/map_model.php +++ b/Mourne-CI/application/models/map_model.php @@ -2,114 +2,115 @@ class Map_model extends MO_Model { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function get_village_by_name($name) - { - $sql = "SELECT id FROM villages WHERE name LIKE '%" . $name . "%'"; + public function get_village_by_name($name) + { + $sql = "SELECT id FROM villages WHERE name LIKE '%" . $name . "%'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return FALSE; + if (!$q->num_rows()) { + return false; + } - $res = $q->row_array(); + $res = $q->row_array(); - return $this->get_village_coords($res['id']); - } + return $this->get_village_coords($res['id']); + } - function get_village_coords($vid) - { - $sql = "SELECT * FROM map WHERE type='3' AND villageid='$vid'"; - $q = $this->db->query($sql); + public function get_village_coords($vid) + { + $sql = "SELECT * FROM map WHERE type='3' AND villageid='$vid'"; + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function get_map($x, $y) - { - if ($x < 7) - $x = 7; + public function get_map($x, $y) + { + if ($x < 7) { + $x = 7; + } - if ($y < 7) - $y = 7; + if ($y < 7) { + $y = 7; + } - if ($x > 235) - $x = 235; + if ($x > 235) { + $x = 235; + } - if ($y > 235) - $y = 235; + if ($y > 235) { + $y = 235; + } - $minx = $x - 6; - $maxx = $x + 6; - $miny = $y - 6; - $maxy = $y + 6; + $minx = $x - 6; + $maxx = $x + 6; + $miny = $y - 6; + $maxy = $y + 6; - //< at max so it gets 12 rows and cols - $sql = "SELECT map.*,ai_villages.name AS ai_name,villages.name FROM map + //< at max so it gets 12 rows and cols + $sql = "SELECT map.*,ai_villages.name AS ai_name,villages.name FROM map LEFT JOIN ai_villages ON map.villageid=ai_villages.id AND map.type='4' LEFT JOIN villages ON map.villageid=villages.id AND map.type='3' WHERE ((map.X >= '$minx') AND (map.X < '$maxx') AND (map.Y >= '$miny') AND (map.Y < '$maxy'))"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - $res = $q->result_array(); + $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)) - { - $data[] = $row; - break; - } - } - } + //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)) { + $data[] = $row; + break; + } + } + } + } + + return $data; } - return $data; - } - - function get_map_list_admin() - { - $this->load->helper('directory'); - - $map = directory_map('./sql/map/', 1); - - foreach ($map as $row) + public function get_map_list_admin() { - $a = explode('.', $row); + $this->load->helper('directory'); - if (isset($a[1])) - { - if ($a[1] == 'sql') - $data[] = $row; - } - } + $map = directory_map('./sql/map/', 1); + + foreach ($map as $row) { + $a = explode('.', $row); + + if (isset($a[1])) { + if ($a[1] == 'sql') { + $data[] = $row; + } + } + } - if (isset($data)) - return $data; - else - return FALSE; - } + if (isset($data)) { + return $data; + } else { + return false; + } + } - 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 - //add .! - $a = "DROP TABLE IF EXISTS ai_villages; \n"; + 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 + //add .! + $a = "DROP TABLE IF EXISTS ai_villages; \n"; - //create table - $a .= "CREATE TABLE IF NOT EXISTS `ai_villages` ( + //create table + $a .= "CREATE TABLE IF NOT EXISTS `ai_villages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `attacked` tinyint(4) NOT NULL, @@ -118,27 +119,24 @@ class Map_model extends MO_Model PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"; - $i = 1; - for ($x = 1; $x <= 240; $x++) - { - for ($y = 1; $y <= 240; $y++) - { - //if ai village space - if (!((($x + 24) % 48) || (($y + 24) % 48))) - { - $name = $this->_rand_ai_name(); - - $a .= "INSERT INTO ai_villages + $i = 1; + for ($x = 1; $x <= 240; $x++) { + for ($y = 1; $y <= 240; $y++) { + //if ai village space + if (!((($x + 24) % 48) || (($y + 24) % 48))) { + $name = $this->_rand_ai_name(); + + $a .= "INSERT INTO ai_villages VALUES('$i', '$name', '0', '$x', '$y'); \n"; - $i++; - } - } - } + $i++; + } + } + } - $a .= "DROP TABLE IF EXISTS map; \n"; + $a .= "DROP TABLE IF EXISTS map; \n"; - $a .= "CREATE TABLE IF NOT EXISTS `map` ( + $a .= "CREATE TABLE IF NOT EXISTS `map` ( `id` int(11) NOT NULL AUTO_INCREMENT, `X` int(11) NOT NULL, `Y` int(11) NOT NULL, @@ -148,147 +146,129 @@ class Map_model extends MO_Model KEY `X` (`X`,`Y`,`type`,`villageid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"; - $a .= "\n"; + $a .= "\n"; - $sql = "SELECT * FROM villages"; - $q = $this->db->query($sql); - $villages = $q->result_array(); + $sql = "SELECT * FROM villages"; + $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) - { - $vx = mt_rand(1, 240); - $vy = mt_rand(1, 240); + while (!$found) { + $vx = mt_rand(1, 240); + $vy = mt_rand(1, 240); - if (((($vx + 24) % 48) && (($vy + 24) % 48))) - { - //not in ai space - $vdata[] = array( - 'id' => $row['id'], - 'x' => $vx, - 'y' => $vy); + if (((($vx + 24) % 48) && (($vy + 24) % 48))) { + //not in ai space + $vdata[] = array( + 'id' => $row['id'], + 'x' => $vx, + 'y' => $vy); - $found = true; - } - } + $found = true; + } + } + } + } else { + $vdata = false; + } - } - } - else - $vdata = FALSE; + $villageid = 0; + $ai = 1; + $found = false; - $villageid = 0; - $ai = 1; - $found = FALSE; + $i = 1; + 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) { + $villageid = $row['id']; + $type = 3; + $found = true; + } + } + } - $i = 1; - 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) - { - $villageid = $row['id']; - $type = 3; - $found = TRUE; - } - } - } + if (!$found) { + //check for village here, dont let this run when true + $r = rand(0, 100); + if ($r < 70) { + $type = 0; + } elseif ($r >= 70 && $r < 85) { + $type = 1; + } else { + $type = 2; + } + } + + $found = false; + } else { + //ai village space + $type = 4; + $villageid = $ai; + $ai++; + } - if (!$found) - { - //check for village here, dont let this run when true - $r = rand(0, 100); - if ($r < 70) - $type = 0; - elseif ($r >= 70 && $r < 85) - $type = 1; - else - $type = 2; - } - - $found = FALSE; - - } - else - { - //ai village space - $type = 4; - $villageid = $ai; - $ai++; - } + $a .= "INSERT INTO map VALUES('$i', '$x', '$y', '$type', '$villageid');\n"; + $villageid = 0; + $i++; + } + } - $a .= "INSERT INTO map VALUES('$i', '$x', '$y', '$type', '$villageid');\n"; - $villageid = 0; - $i++; - } + $this->load->helper('file'); + + $f = './sql/map/map' . time() . '.sql'; + + write_file($f, $a); } - $this->load->helper('file'); - - $f = './sql/map/map' . time() . '.sql'; - - write_file($f, $a); - } - - function apply_map_admin($file) - { - $this->load->helper('file'); - - $f = readfile(('./sql/map/' . $file)); - - $sql = explode(';', $f); - - foreach ($sql as $row) + public function apply_map_admin($file) { - $this->db->query($row); - } - } + $this->load->helper('file'); - function _rand_ai_name() - { - //they are in keyboard order from left to right, and top to bottom + $f = readfile(('./sql/map/' . $file)); - //21 entries - $a = array('q', 'w', 'r', 't', 'z', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'y', 'x', - 'c', 'v', 'b', 'n', 'm'); - - //5 entries - $b = array('e', 'u', 'i', 'o', 'a'); - - //ai village names should be between 4-6 chars - $length = rand(4, 6); - - $str = ''; - for ($i = 1; $i <= $length; $i++) - { - //start with $a - if ($i % 2) - { - if ($i == 1) - $str .= strtoupper($a[mt_rand(0,20)]); - else - $str .= $a[mt_rand(0, 20)]; - } - else - $str .= $b[mt_rand(0, 4)]; + $sql = explode(';', $f); + foreach ($sql as $row) { + $this->db->query($row); + } } - return $str; - } + public function _rand_ai_name() + { + //they are in keyboard order from left to right, and top to bottom + //21 entries + $a = array('q', 'w', 'r', 't', 'z', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'y', 'x', + 'c', 'v', 'b', 'n', 'm'); + + //5 entries + $b = array('e', 'u', 'i', 'o', 'a'); + + //ai village names should be between 4-6 chars + $length = rand(4, 6); + + $str = ''; + for ($i = 1; $i <= $length; $i++) { + //start with $a + if ($i % 2) { + if ($i == 1) { + $str .= strtoupper($a[mt_rand(0, 20)]); + } else { + $str .= $a[mt_rand(0, 20)]; + } + } else { + $str .= $b[mt_rand(0, 4)]; + } + } + + return $str; + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/menu_model.php b/Mourne-CI/application/models/menu_model.php index 715ccb2..684d2d5 100755 --- a/Mourne-CI/application/models/menu_model.php +++ b/Mourne-CI/application/models/menu_model.php @@ -1,14 +1,10 @@ db->query($sql, array($userid)); + $q = $this->db->query($sql, array($userid)); - if (!$q->num_rows()) - return FALSE; + if (!$q->num_rows()) { + return false; + } - return $q->row_array(); - } + return $q->row_array(); + } - function get_userlevel($uid) - { - $sql = "SELECT userlevel FROM users WHERE id=$uid"; - - $q = $this->db->query($sql); + public function get_userlevel($uid) + { + $sql = "SELECT userlevel FROM users WHERE id=$uid"; + + $q = $this->db->query($sql); - $res = $q->row_array(); - - return $res['userlevel']; + $res = $q->row_array(); + + return $res['userlevel']; + } - } + public function get_username($uid) + { + $sql = "SELECT username FROM users WHERE id=$uid"; - function get_username($uid) - { - $sql = "SELECT username FROM users WHERE id=$uid"; + $q = $this->db->query($sql); - $q = $this->db->query($sql); + $res = $q->row_array(); - $res = $q->row_array(); + return $res['username']; + } - return $res['username']; - } + public function get_userdata($id) + { + $sql = "SELECT * FROM users WHERE id='$id'"; + $q = $this->db->query($sql); - function get_userdata($id) - { - $sql = "SELECT * FROM users WHERE id='$id'"; - $q = $this->db->query($sql); + return $q->row_array(); + } - return $q->row_array(); + public function get_villageid($userid) + { + $sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'"; + $q = $this->db->query($sql); + $res = $q->row_array(); - } - - function get_villageid($userid) - { - $sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'"; - $q = $this->db->query($sql); - $res = $q->row_array(); - - return $res['id']; - } - - function get_village_data($uid) - { - $sql = "SELECT * FROM villages WHERE userid='$uid' AND selected='1'"; - $q = $this->db->query($sql); - return $q->row_array(); - } + return $res['id']; + } + 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 \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/news_model.php b/Mourne-CI/application/models/news_model.php index 62985ae..74e8f6b 100755 --- a/Mourne-CI/application/models/news_model.php +++ b/Mourne-CI/application/models/news_model.php @@ -2,31 +2,29 @@ class News_model extends MO_Model { + public function get_news($page) + { + $p = ($page - 1) * 5; - function get_news($page) - { - $p = ($page - 1) * 5; + $sql = "SELECT * FROM news LIMIT $p, 5"; - $sql = "SELECT * FROM news LIMIT $p, 5"; + $q = $this->db->query($sql); - $q = $this->db->query($sql); + return $q->result_array(); + } - return $q->result_array(); - } - - function add_news($text, $uname) - { - $sql = "INSERT INTO news VALUES(default, '$uname', '$text')"; - - return $this->db->query($sql); - } - - function del_news($id) - { - $sql = ""; - return $this->db->query($sql); - } + public function add_news($text, $uname) + { + $sql = "INSERT INTO news VALUES(default, '$uname', '$text')"; + + return $this->db->query($sql); + } + public function del_news($id) + { + $sql = ""; + return $this->db->query($sql); + } } //nowhitesp diff --git a/Mourne-CI/application/models/resource_model.php b/Mourne-CI/application/models/resource_model.php index 87b35eb..f61561a 100755 --- a/Mourne-CI/application/models/resource_model.php +++ b/Mourne-CI/application/models/resource_model.php @@ -1,64 +1,58 @@ get_resources($villageid); + public function have_enough_resources_building($buildingid, $villageid) + { + $res = $this->get_resources($villageid); - $sql = "SELECT * FROM buildings WHERE id='$buildingid'"; - $q = $this->db->query($sql); - $building = $q->row_array(); + $sql = "SELECT * FROM buildings WHERE id='$buildingid'"; + $q = $this->db->query($sql); + $building = $q->row_array(); - 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']) - return TRUE; + 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']) { + return true; + } - return FALSE; - - } - - + return false; + } } //nowhitesp diff --git a/Mourne-CI/application/models/spell_model.php b/Mourne-CI/application/models/spell_model.php index 8691116..42b1b00 100755 --- a/Mourne-CI/application/models/spell_model.php +++ b/Mourne-CI/application/models/spell_model.php @@ -1,17 +1,17 @@ resources = $res; + public function use_spell($spellid, $slotid, $res, $villageid) + { + $this->resources = $res; - //getting spell - $sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end + //getting spell + $sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end FROM building_spells LEFT JOIN spells ON building_spells.spellid=spells.id LEFT JOIN building_spell_cooldowns @@ -22,63 +22,65 @@ class Spell_model extends MO_Model AND building_spells.slotid='$slotid' AND building_spells.spellid='$spellid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return 1; + if (!$q->num_rows()) { + return 1; + } - $spell = $q->row_array(); + $spell = $q->row_array(); - if ($spell['cooldown_end']) - return 2; + if ($spell['cooldown_end']) { + return 2; + } - if (!$this->check_resources($res, $spell)) - return 3; + if (!$this->check_resources($res, $spell)) { + return 3; + } - //everything is fine - //substracting cost - $this->substract_resources($spell, $villageid); + //everything is fine + //substracting cost + $this->substract_resources($spell, $villageid); - //addign modofiers - $this->add_modifiers($spell['id'], $villageid, 'spell'); + //addign modofiers + $this->add_modifiers($spell['id'], $villageid, 'spell'); - $this->write_resources(); + $this->write_resources(); - if ($spell['weather_change_to']) - { - $sql = "UPDATE villages + if ($spell['weather_change_to']) { + $sql = "UPDATE villages SET weather_change_to='" . $spell['weather_change_to'] . "' WHERE id='$villageid'"; - $this->db->query($sql); - } + $this->db->query($sql); + } - //do spelleffects here + //do spelleffects here - //adding cooldown - $cd = $spell['cooldown'] + time(); + //adding cooldown + $cd = $spell['cooldown'] + time(); - $sql = "INSERT INTO building_spell_cooldowns + $sql = "INSERT INTO building_spell_cooldowns VALUES(default, '$villageid', '$slotid', '" . $spell['id'] . "', '$cd')"; - $this->db->query($sql); + $this->db->query($sql); - //adding spell_effect_end to events - $ev['type'] = 3; - $ev['villageid'] = $villageid; - $ev['slotid'] = $slotid; - $ev['time'] = $spell['duration']; - $ev['data1'] = $spell['id']; + //adding spell_effect_end to events + $ev['type'] = 3; + $ev['villageid'] = $villageid; + $ev['slotid'] = $slotid; + $ev['time'] = $spell['duration']; + $ev['data1'] = $spell['id']; - $this->add_event($ev); - } + $this->add_event($ev); + } - function get_spells($slotid, $villageid) - { - $this->update_spells($slotid, $villageid); + public function get_spells($slotid, $villageid) + { + $this->update_spells($slotid, $villageid); - $sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end + $sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end FROM building_spells LEFT JOIN spells ON building_spells.spellid=spells.id LEFT JOIN building_spell_cooldowns @@ -88,79 +90,76 @@ class Spell_model extends MO_Model WHERE building_spells.villageid='$villageid' AND building_spells.slotid='$slotid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function update_spells($slotid, $villageid) - { - $sql = "SELECT * FROM building_spell_cooldowns + public function update_spells($slotid, $villageid) + { + $sql = "SELECT * FROM building_spell_cooldowns WHERE slotid='$slotid' AND villageid='$villageid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return; + if (!$q->num_rows()) { + return; + } - $spells = $q->result_array(); - $time = time(); + $spells = $q->result_array(); + $time = time(); - foreach ($spells as $row) - { - if ($row['cooldown_end'] <= $time) - { - $sql = "DELETE FROM building_spell_cooldowns + foreach ($spells as $row) { + if ($row['cooldown_end'] <= $time) { + $sql = "DELETE FROM building_spell_cooldowns WHERE id='" . $row['id'] . "'"; - $this->db->query($sql); - } + $this->db->query($sql); + } + } } - } - function get_spell_mod_drop_admin() - { - //STUB - $data = array('0' => 'Nothing'); - return $data; - } - - function list_spells_admin() - { - $sql = "SELECT * FROM spells"; - $q = $this->db->query($sql); - - return $q->result_array(); - } - - function get_spell_list_drop_admin() - { - $sql = "SELECT * FROM spells"; - $q = $this->db->query($sql); - $res = $q->result_array(); - - $data[0] = 'No Spell'; - - foreach ($res as $row) + public function get_spell_mod_drop_admin() { - $data[$row['id']] = $row['description_admin']; + //STUB + $data = array('0' => 'Nothing'); + return $data; } - return $data; - } + public function list_spells_admin() + { + $sql = "SELECT * FROM spells"; + $q = $this->db->query($sql); - function get_spell_admin($id) - { - $sql = "SELECT * FROM spells WHERE id='$id'"; - $q = $this->db->query($sql); + return $q->result_array(); + } - return $q->row_array(); - } + public function get_spell_list_drop_admin() + { + $sql = "SELECT * FROM spells"; + $q = $this->db->query($sql); + $res = $q->result_array(); - function edit_spell_admin($data) - { + $data[0] = 'No Spell'; - $sql = "UPDATE spells + foreach ($res as $row) { + $data[$row['id']] = $row['description_admin']; + } + + return $data; + } + + public function get_spell_admin($id) + { + $sql = "SELECT * FROM spells WHERE id='$id'"; + $q = $this->db->query($sql); + + return $q->row_array(); + } + + public function edit_spell_admin($data) + { + $sql = "UPDATE spells SET effect='" . $data['effect'] . "', duration='" . $data['duration'] . "', cooldown='" . $data['cooldown'] . "', @@ -189,14 +188,14 @@ class Spell_model extends MO_Model mod_percent_mana='" . $data['mod_percent_mana'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function add_spell_admin($data) - { - $sql = "INSERT INTO spells VALUES(default, + public function add_spell_admin($data) + { + $sql = "INSERT INTO spells VALUES(default, '" . $data['effect'] . "', '" . $data['duration'] . "', '" . $data['cooldown'] . "', @@ -224,17 +223,17 @@ class Spell_model extends MO_Model '" . $data['mod_percent_iron'] . "', '" . $data['mod_percent_mana'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_spell_effects_admin() - { - //STUB! - $data = array('0' => 'No Effect'); + public function get_spell_effects_admin() + { + //STUB! + $data = array('0' => 'No Effect'); - return $data; - } + return $data; + } } //nowhitesp diff --git a/Mourne-CI/application/models/sql_model.php b/Mourne-CI/application/models/sql_model.php index e7b96d6..bed1032 100755 --- a/Mourne-CI/application/models/sql_model.php +++ b/Mourne-CI/application/models/sql_model.php @@ -2,147 +2,135 @@ class Sql_model extends MO_Model { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - //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) - { - $this->_update_db_version($time); - } + //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); + public function update_db_version($time) + { + $this->_update_db_version($time); + } - //dummy function which uses inherited _create_sql($sql); - function create_sql($sql) - { - $this->_create_sql($sql); - } + //dummy function which uses inherited _create_sql($sql); + public function create_sql($sql) + { + $this->_create_sql($sql); + } - function get_db_version() - { - $sql = "SELECT version FROM db_version WHERE id='1'"; + public function get_db_version() + { + $sql = "SELECT version FROM db_version WHERE id='1'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - $res = $q->row_array(); + $res = $q->row_array(); - return $res['version']; - } + return $res['version']; + } - function get_appliable_files() - { - $this->load->helper('file'); - //$full_list = get_filenames('./sql'); + public function get_appliable_files() + { + $this->load->helper('file'); + //$full_list = get_filenames('./sql'); - $this->load->helper('directory'); - $full_list = directory_map('./sql', 1); + $this->load->helper('directory'); + $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)) - { - $list[] = $row; - } - } - - if (!isset($list)) - return 0; - - $ver = $this->get_db_version(); - - foreach ($list as $row) - { - $l = explode('.', $row); - - if ($l[0] > $ver) - { - $data[] = $row; - } - } - - if (!isset($data)) - return 0; - - //getting the max - $max = 0; - - foreach ($data as $row) - { - $l = explode('.', $row); - - if ($l[0] > $max) - { - $max = $l[0]; - } - } - - $smallest = $max; - $last_found = 0; - - $ordered[] = $max . ".sql"; - - for ($i = 0; $i < (sizeof($data) - 1); $i++) - { - foreach ($data as $row) - { - $l = explode('.', $row); - - if (($l[0] < $smallest) && ($l[0] > $last_found)) - { - $smallest = $l[0]; - $ord = $row; + //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)) { + $list[] = $row; + } } - } - $last_found = $smallest; - $smallest = $max; - $ordered[$i] = $ord; + if (!isset($list)) { + return 0; + } + + $ver = $this->get_db_version(); + + foreach ($list as $row) { + $l = explode('.', $row); + + if ($l[0] > $ver) { + $data[] = $row; + } + } + + if (!isset($data)) { + return 0; + } + + //getting the max + $max = 0; + + foreach ($data as $row) { + $l = explode('.', $row); + + if ($l[0] > $max) { + $max = $l[0]; + } + } + + $smallest = $max; + $last_found = 0; + + $ordered[] = $max . ".sql"; + + for ($i = 0; $i < (sizeof($data) - 1); $i++) { + foreach ($data as $row) { + $l = explode('.', $row); + + if (($l[0] < $smallest) && ($l[0] > $last_found)) { + $smallest = $l[0]; + $ord = $row; + } + } + + $last_found = $smallest; + $smallest = $max; + $ordered[$i] = $ord; + } + + if (isset($ordered)) { + return $ordered; + } else { + return 0; + } } - if (isset($ordered)) + public function apply_all_sql() { - return $ordered; - } - else - { - return 0; - } - - } + $this->load->helper('file'); - function apply_all_sql() - { - $this->load->helper('file'); + $list = $this->get_appliable_files(); - $list = $this->get_appliable_files(); + if (!$list) { + return; + } - if (!$list) - return; - - for ($i = 0; $i < sizeof($list); $i++) - { - //reading file, then applying it to the db - $loc = './sql/' . $list[$i]; - $sql = read_file($loc); + for ($i = 0; $i < sizeof($list); $i++) { + //reading file, then applying it to the db + $loc = './sql/' . $list[$i]; + $sql = read_file($loc); - var_dump($loc); + var_dump($loc); - $this->db->query($sql); + $this->db->query($sql); - //TODO check if error happened, then stop everything - //check is not needed, it just throws the error + //TODO check if error happened, then stop everything + //check is not needed, it just throws the error - //update db_version - $ver = explode('.', $list[$i]); - $sqlv = "UPDATE db_version SET version='" . $ver[0] . "' WHERE id='1'"; - $this->db->query($sqlv); + //update db_version + $ver = explode('.', $list[$i]); + $sqlv = "UPDATE db_version SET version='" . $ver[0] . "' WHERE id='1'"; + $this->db->query($sqlv); + } } - } - } //nowhitesp diff --git a/Mourne-CI/application/models/technology_model.php b/Mourne-CI/application/models/technology_model.php index 70751ce..6ff20ea 100755 --- a/Mourne-CI/application/models/technology_model.php +++ b/Mourne-CI/application/models/technology_model.php @@ -1,578 +1,574 @@ set_resources($res); - - $technology = $this->get_technology($techid); - - //no such technology - if (!$technology) - return 1; - - 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) + public function __construct() { - if ($row['id'] == $techid) - { - $found = TRUE; - $group = 'primary'; - break; - } + parent::__construct(); } - foreach ($secondary as $row) + public function do_research($techid, $res, $slotid, $villageid) { - if ($found) - break; + $this->set_resources($res); - if ($row['id'] = $techid) - { - $found = TRUE; - $group = 'secondary'; - break; - } + $technology = $this->get_technology($techid); + + //no such technology + if (!$technology) { + return 1; + } + + 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; + $group = 'primary'; + break; + } + } + + foreach ($secondary as $row) { + if ($found) { + break; + } + + if ($row['id'] = $techid) { + $found = true; + $group = 'secondary'; + break; + } + } + + //building doesn't have this technology (or user already have it) + if (!$found) { + return 3; + } + + //everything is fine + //substract cost + $this->substract_resources($technology, $villageid); + + $this->write_resources(); + + //add event + $ev['type'] = 4; + $ev['villageid'] = $villageid; + $ev['slotid'] = $slotid; + $ev['time'] = $technology['time']; + $ev['data1'] = $techid; + + if ($group == 'secondary') { + $ev['data2'] = $slotid; + } + + $this->add_event($ev); } - //building doesn't have this technology (or user already have it) - if (!$found) - return 3; - - //everything is fine - //substract cost - $this->substract_resources($technology, $villageid); - - $this->write_resources(); - - //add event - $ev['type'] = 4; - $ev['villageid'] = $villageid; - $ev['slotid'] = $slotid; - $ev['time'] = $technology['time']; - $ev['data1'] = $techid; - - if ($group == 'secondary') - $ev['data2'] = $slotid; - - $this->add_event($ev); - } - - function get_researchable($slotid, $villageid) - { - $building = $this->get_slot_building($slotid, $villageid); - - if (!($building['tech_group'] && $building['tech_secondary_group'])) + public function get_researchable($slotid, $villageid) { - $data['primary'] = FALSE; - $data['secondary'] = FALSE; - return $data; + $building = $this->get_slot_building($slotid, $villageid); + + if (!($building['tech_group'] && $building['tech_secondary_group'])) { + $data['primary'] = false; + $data['secondary'] = false; + return $data; + } + + //technologies a village has + $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'] + ); + + //technologies that a village (or building) doesn't have + $av_tech = $this->select_technology_not_have($technologies, $building_tech); + + //getting technology requirements + $requirements = $this->get_requirements($av_tech); + + 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; } - //technologies a village has - $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']); - - //technologies that a village (or building) doesn't have - $av_tech = $this->select_technology_not_have($technologies, $building_tech); - - //getting technology requirements - $requirements = $this->get_requirements($av_tech); - - 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; - - if (!$requirements) - return $technologies; - - foreach ($technologies as $row) + public function apply_requirements($technologies, $requirements) { - $found = FALSE; - foreach ($requirements as $req) - { - //if the technology's id matched the current requirement's techid - 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; - break; - } - } - } - } + if (!$technologies) { + return false; + } - if (!$found) - $data[] = $row; + if (!$requirements) { + return $technologies; + } + + 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']) { + //looking for the matching technology that is required + foreach ($technologies as $tech) { + if ($req['req_tech_id'] == $tech['id']) { + $found = true; + break; + } + } + } + } + + if (!$found) { + $data[] = $row; + } + } + + if (isset($data)) { + return $data; + } else { + return false; + } } - if (isset($data)) - return $data; - else - return FALSE; - } + public function get_requirements($tech) + { + $primary = $tech['primary']; + $secondary = $tech['secondary']; - 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 + $sql = "SELECT * FROM technology_requirements WHERE ("; - $first = TRUE; - if ($primary) - { - foreach ($primary as $row) - { - if ($first) - $first = FALSE; - else - $sql .= "OR "; - - $sql .= "technologyid='" . $row['id'] . "' "; - } + $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 { + $sql .= "OR "; + } + + $sql .= "technologyid='" . $row['id'] . "' "; + } + } + + $sql .= ")"; + + $q = $this->db->query($sql); + + if ($q->num_rows()) { + return $q->result_array(); + } else { + return false; + } } - if ($secondary) + //TODO better name? + public function select_technology_not_have($village_tech, $building_technologies) { - foreach ($secondary as $row) - { - if ($first) - $first = FALSE; - else - $sql .= "OR "; + $primary = $building_technologies['primary']; + $secondary = $building_technologies['secondary']; - $sql .= "technologyid='" . $row['id'] . "' "; - } + //adding only which village doesn't have (primary) + if ($primary) { + $found = false; + foreach ($primary as $row) { + foreach ($village_tech as $trow) { + if ($found) { + continue; + } + + if ($trow['technologyid'] == $row['id']) { + $found = true; + } + } + + if (!$found) { + $data['primary'][] = $row; + } + + $found = false; + } + } + if (!isset($data['primary'])) { + $data['primary'] = false; + } + + + if ($secondary) { + //same just with secondary + $found = false; + foreach ($secondary as $row) { + foreach ($village_tech as $trow) { + if ($found) { + continue; + } + + if ($trow['technologyid'] == $row['id']) { + $found = true; + } + } + + if (!$found) { + $data['secondary'][] = $row; + } + + $found = false; + } + } + + if (!isset($data['secondary'])) { + $data['secondary'] = false; + } + + return $data; } - $sql .= ")"; - - $q = $this->db->query($sql); - - if ($q->num_rows()) - return $q->result_array(); - else - return FALSE; - } - - //TODO better name? - 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) + public function get_building_technologies($id, $secid = 0) { - $found = FALSE; - foreach ($primary as $row) - { - foreach ($village_tech as $trow) - { - if ($found) - continue; - - if ($trow['technologyid'] == $row['id']) - { - $found = TRUE; - } - } - - if (!$found) - $data['primary'][] = $row; - - $found = FALSE; - } - } - if (!isset($data['primary'])) - $data['primary'] = FALSE; - - - if ($secondary) - { - //same just with secondary - $found = FALSE; - foreach ($secondary as $row) - { - foreach ($village_tech as $trow) - { - if ($found) - continue; - - if ($trow['technologyid'] == $row['id']) - { - $found = TRUE; - } - } - - if (!$found) - $data['secondary'][] = $row; - - $found = FALSE; - } - } - - if (!isset($data['secondary'])) - $data['secondary'] = FALSE; - - return $data; - } - - function get_building_technologies($id, $secid = 0) - { - if ($secid) - { - $sql = "SELECT technologies.*,technology_groups.groupid + 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 - { - $sql = "SELECT technologies.* + } else { + $sql = "SELECT technologies.* FROM technology_groups INNER JOIN technologies ON technology_groups.technologyid=technologies.id WHERE groupid='$id'"; + } + + $q = $this->db->query($sql); + + if (!$secid) { + $data['primary'] = $q->result_array(); + $data['secondary'] = false; + + return $data; + } + + $res = $q->result_array(); + + foreach ($res as $row) { + if ($row['groupid'] == $id) { + $data['primary'][] = $row; + } else { + $data['secondary'][] = $row; + } + } + + if (!isset($data['primary'])) { + $data['primary'] = false; + } + + if (!isset($data['secondary'])) { + $data['secondary'] = false; + } + + return $data; } - $q = $this->db->query($sql); - - if (!$secid) + public function get_technology($id) { - $data['primary'] = $q->result_array(); - $data['secondary'] = FALSE; + $sql = "SELECT * FROM technologies WHERE id='$id'"; + $q = $this->db->query($sql); - return $data; + if ($q->num_rows()) { + return $q->row_array(); + } else { + return false; + } } - $res = $q->result_array(); - - foreach ($res as $row) + public function add_tech_req_admin($techid, $reqid) { - if ($row['groupid'] == $id) - { - $data['primary'][] = $row; - } - else - { - $data['secondary'][] = $row; - } - } - - if (!isset($data['primary'])) - $data['primary'] = FALSE; - - if (!isset($data['secondary'])) - $data['secondary'] = FALSE; - - return $data; - - } - - function get_technology($id) - { - $sql = "SELECT * FROM technologies WHERE id='$id'"; - $q = $this->db->query($sql); - - if ($q->num_rows()) - return $q->row_array(); - else - return FALSE; - } - - function add_tech_req_admin($techid, $reqid) - { - //dont add if already added - $sql = "SELECT * FROM technology_requirements + //dont add if already added + $sql = "SELECT * FROM technology_requirements WHERE technologyid='$techid' AND req_tech_id='$reqid'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows()) - return; + if ($q->num_rows()) { + return; + } - $sql = "INSERT INTO technology_requirements + $sql = "INSERT INTO technology_requirements VALUES(default, '$techid', '$reqid')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function remove_tech_req_admin($id) - { - $sql = "DELETE FROM technology_requirements + public function remove_tech_req_admin($id) + { + $sql = "DELETE FROM technology_requirements WHERE id='$id'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_tech_by_req_id_admin($id) - { - $sql = "SELECT technologies.* + public function get_tech_by_req_id_admin($id) + { + $sql = "SELECT technologies.* FROM technology_have_requirements INNER JOIN technologies ON technology_have_requirements.technologyid=technologies.id WHERE technology_have_requirements.id='$id'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function get_tech_requirements_admin($id) - { - $sql = "SELECT technology_requirements.*,technologies.description + public function get_tech_requirements_admin($id) + { + $sql = "SELECT technology_requirements.*,technologies.description FROM technology_requirements INNER JOIN technologies ON technology_requirements.req_tech_id=technologies.id WHERE technologyid='$id'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function add_to_req_list_admin($data) - { - $sql = "SELECT * FROM technology_have_requirements + public function add_to_req_list_admin($data) + { + $sql = "SELECT * FROM technology_have_requirements WHERE technologyid='" . $data['technologyid'] . "'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - if ($q->num_rows) - return; + if ($q->num_rows) { + return; + } - $sql = "INSERT INTO technology_have_requirements + $sql = "INSERT INTO technology_have_requirements VALUES(default, '" . $data['technologyid'] . "', '" . $data['comment'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function remove_from_req_list_admin($id) - { - $sql = "DELETE FROM technology_have_requirements + public function remove_from_req_list_admin($id) + { + $sql = "DELETE FROM technology_have_requirements WHERE id='$id'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_req_list_item_admin($id) - { - $sql = "SELECT technology_have_requirements.*,technologies.description + public function get_req_list_item_admin($id) + { + $sql = "SELECT technology_have_requirements.*,technologies.description FROM technology_have_requirements INNER JOIN technologies ON technology_have_requirements.technologyid=technologies.id WHERE technology_have_requirements.id='$id'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function list_tech_have_req_admin() - { - $sql = "SELECT technology_have_requirements.*,technologies.description + public function list_tech_have_req_admin() + { + $sql = "SELECT technology_have_requirements.*,technologies.description FROM technology_have_requirements INNER JOIN technologies ON technology_have_requirements.technologyid=technologies.id"; - $q = $this->db->query($sql); - return $q->result_array(); - } + $q = $this->db->query($sql); + return $q->result_array(); + } - function add_tech_to_group_admin($gid, $techid) - { - $sql = "INSERT INTO technology_groups + public function add_tech_to_group_admin($gid, $techid) + { + $sql = "INSERT INTO technology_groups VALUES(default, '$gid', '$techid')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function remove_tech_from_group_admin($gid, $techid) - { - $sql = "DELETE FROM technology_groups + public function remove_tech_from_group_admin($gid, $techid) + { + $sql = "DELETE FROM technology_groups WHERE groupid='$gid' AND technologyid='$techid'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_group_admin($id) - { - $sql = "SELECT technology_groups.*, technologies.description + public function get_group_admin($id) + { + $sql = "SELECT technology_groups.*, technologies.description FROM technology_groups INNER JOIN technologies ON technology_groups.technologyid=technologies.id WHERE groupid='$id'"; - - $q = $this->db->query($sql); + + $q = $this->db->query($sql); - return $q->result_array(); - } - - function get_tech_list_drop_admin() - { - $sql = "SELECT id,description FROM technologies"; - $q = $this->db->query($sql); - - $res = $q->result_array(); - - $data[0] = 'Nothing'; - - foreach ($res as $row) - { - $data[$row['id']] = $row['description']; + return $q->result_array(); } - return $data; - } - - function list_tech_drop_admin() - { - $sql = "SELECT id,description FROM technologies"; - $q = $this->db->query($sql); - - $res = $q->result_array(); - - foreach ($res as $row) + public function get_tech_list_drop_admin() { - $data[$row['id']] = $row['description']; + $sql = "SELECT id,description FROM technologies"; + $q = $this->db->query($sql); + + $res = $q->result_array(); + + $data[0] = 'Nothing'; + + foreach ($res as $row) { + $data[$row['id']] = $row['description']; + } + + return $data; } - if (isset($data)) - return $data; - else - return FALSE; - } - - function get_tech_group_list_drop_admin() - { - $sql = "SELECT * FROM technology_group_descriptions"; - - $q = $this->db->query($sql); - - $res = $q->result_array(); - - $data[0] = 'Nothing'; - - foreach ($res as $row) + public function list_tech_drop_admin() { - $data[$row['id']] = $row['group_name']; + $sql = "SELECT id,description FROM technologies"; + $q = $this->db->query($sql); + + $res = $q->result_array(); + + foreach ($res as $row) { + $data[$row['id']] = $row['description']; + } + + if (isset($data)) { + return $data; + } else { + return false; + } } - return $data; - } + public function get_tech_group_list_drop_admin() + { + $sql = "SELECT * FROM technology_group_descriptions"; - function add_tech_group_desc_admin($data) - { - $sql = "INSERT INTO technology_group_descriptions + $q = $this->db->query($sql); + + $res = $q->result_array(); + + $data[0] = 'Nothing'; + + foreach ($res as $row) { + $data[$row['id']] = $row['group_name']; + } + + return $data; + } + + public function add_tech_group_desc_admin($data) + { + $sql = "INSERT INTO technology_group_descriptions VALUES(default, '" . $data['group_name'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function edit_tech_group_desc_admin($data) - { - $sql = "UPDATE technology_group_descriptions + public function edit_tech_group_desc_admin($data) + { + $sql = "UPDATE technology_group_descriptions SET group_name='" . $data['group_name'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_tech_group_desc_admin($id) - { - $sql = "SELECT * FROM technology_group_descriptions WHERE id='$id'"; - $q = $this->db->query($sql); + public function get_tech_group_desc_admin($id) + { + $sql = "SELECT * FROM technology_group_descriptions WHERE id='$id'"; + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function list_tech_groups_admin() - { - $sql = "SELECT * FROM technology_group_descriptions"; - $q = $this->db->query($sql); + public function list_tech_groups_admin() + { + $sql = "SELECT * FROM technology_group_descriptions"; + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function list_technologies_admin() - { - $sql = "SELECT * FROM technologies"; - $q = $this->db->query($sql); + public function list_technologies_admin() + { + $sql = "SELECT * FROM technologies"; + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function get_technology_admin($id) - { - $sql = "SELECT * FROM technologies WHERE id='$id'"; - $q = $this->db->query($sql); + public function get_technology_admin($id) + { + $sql = "SELECT * FROM technologies WHERE id='$id'"; + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function edit_technology_admin($data) - { - - $sql = "UPDATE technologies + public function edit_technology_admin($data) + { + $sql = "UPDATE technologies SET description='" . $data['description'] . "', time='" . $data['time'] . "', score='" . $data['score'] . "', @@ -602,14 +598,14 @@ class Technology_model extends MO_Model is_secondary='" . $data['is_secondary'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function add_technology_admin($data) - { - $sql = "INSERT INTO technologies VALUES(default, + public function add_technology_admin($data) + { + $sql = "INSERT INTO technologies VALUES(default, '" . $data['description'] . "', '" . $data['time'] . "', '" . $data['score'] . "', @@ -638,9 +634,9 @@ class Technology_model extends MO_Model '" . $data['flag_ai'] . "', '" . $data['is_secondary'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } } //nowhitesp diff --git a/Mourne-CI/application/models/unit_model.php b/Mourne-CI/application/models/unit_model.php index 73992d3..4027ebc 100755 --- a/Mourne-CI/application/models/unit_model.php +++ b/Mourne-CI/application/models/unit_model.php @@ -1,101 +1,101 @@ db->query($sql); + $q = $this->db->query($sql); - //TODO order it! + //TODO order it! - return $q->result_array(); - } - - function get_unit($id) - { - $sql = "SELECT * FROM units WHERE id='$id'"; - $q = $this->db->query($sql); - - return $q->row_array(); - } - - //calculates how many units can be created (by lookin at events) - //nothing gets queried - function calc_max_unit_ev($unit_max, $unit_res, $event) - { - $in_progress = 0; - - if ($event) - { - foreach ($event as $row) - { - $in_progress += $row['data2']; - } + return $q->result_array(); } - //if more are in progress that the building can make - 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) - return $max; - - //if events allow more than resources - if ($max > $unit_res) - return $unit_res; - - return $max; - } - - function list_create_mod_drop_admin() - { - //STUB - return array('0' => 'Nothing'); - } - - function list_units_admin() - { - $sql = "SELECT * FROM units"; - $q = $this->db->query($sql); - - return $q->result_array(); - } - - function get_unit_list_dropdown_admin() - { - $sql = "SELECT * FROM units"; - $q = $this->db->query($sql); - - $res = $q->result_array(); - - $data[0] = 'Nothing'; - - - foreach ($res as $row) + public function get_unit($id) { - $data[$row['id']] = $row['name']; + $sql = "SELECT * FROM units WHERE id='$id'"; + $q = $this->db->query($sql); + + return $q->row_array(); } - return $data; - } + //calculates how many units can be created (by lookin at events) + //nothing gets queried + public function calc_max_unit_ev($unit_max, $unit_res, $event) + { + $in_progress = 0; - function add_unit_admin($data) - { - $sql = "INSERT INTO units + 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) { + 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) { + return $max; + } + + //if events allow more than resources + if ($max > $unit_res) { + return $unit_res; + } + + return $max; + } + + public function list_create_mod_drop_admin() + { + //STUB + return array('0' => 'Nothing'); + } + + public function list_units_admin() + { + $sql = "SELECT * FROM units"; + $q = $this->db->query($sql); + + return $q->result_array(); + } + + public function get_unit_list_dropdown_admin() + { + $sql = "SELECT * FROM units"; + $q = $this->db->query($sql); + + $res = $q->result_array(); + + $data[0] = 'Nothing'; + + + foreach ($res as $row) { + $data[$row['id']] = $row['name']; + } + + return $data; + } + + public function add_unit_admin($data) + { + $sql = "INSERT INTO units VALUES(default, '" . $data['type'] . "', '" . $data['name'] . "', @@ -122,22 +122,22 @@ class Unit_model extends MO_Model '" . $data['mod_rate_iron'] . "', '" . $data['mod_rate_mana'] . "')"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function get_unit_admin($id) - { - $sql = "SELECT * FROM units WHERE id='$id'"; - $q = $this->db->query($sql); + public function get_unit_admin($id) + { + $sql = "SELECT * FROM units WHERE id='$id'"; + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function edit_unit_admin($data) - { - $sql = "UPDATE units + public function edit_unit_admin($data) + { + $sql = "UPDATE units SET type='" . $data['type'] . "', name='" . $data['name'] . "', icon='" . $data['icon'] . "', @@ -164,9 +164,9 @@ class Unit_model extends MO_Model mod_rate_mana='" . $data['mod_rate_mana'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } } //nowhitesp diff --git a/Mourne-CI/application/models/user_model.php b/Mourne-CI/application/models/user_model.php index 4a0637c..4a5f604 100755 --- a/Mourne-CI/application/models/user_model.php +++ b/Mourne-CI/application/models/user_model.php @@ -2,71 +2,62 @@ class User_model extends MO_Model { - function __construct() - { - parent::__construct(); - } - - 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) + public function __construct() { - $row = $q->row_array(); - - if ($row['passkey'] == $data['password']) - { - return TRUE; - } - else - { - return FALSE; - } + parent::__construct(); } - else + + public function login_check($data) { - return FALSE; + $sql = "SELECT passkey FROM users WHERE username=" . $this->db->escape($data['username']); + + $q = $this->db->query($sql); + + if ($q->num_rows > 0) { + $row = $q->row_array(); + + if ($row['passkey'] == $data['password']) { + return true; + } else { + return false; + } + } else { + return false; + } } - } - function get_userid($username) - { - $sql = "SELECT id FROM users WHERE username=" . $this->db->escape($username); - $q = $this->db->query($sql); - $res = $q->row_array(); - - return $res['id']; - } - - 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) + public function get_userid($username) { - return TRUE; - } - else - { - return FALSE; - } - } + $sql = "SELECT id FROM users WHERE username=" . $this->db->escape($username); + $q = $this->db->query($sql); + $res = $q->row_array(); - function reg_write($data) - { - $sql = "INSERT INTO users VALUES(default, " - . $this->db->escape($data['username']) . ", '" - . $data['password'] . "', '" + return $res['id']; + } + + 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; + } + } + + public function reg_write($data) + { + $sql = "INSERT INTO users VALUES(default, " + . $this->db->escape($data['username']) . ", '" + . $data['password'] . "', '" . $data['email'] . "', default, default, default)"; - return $this->db->query($sql); - } + return $this->db->query($sql); + } } //nowhitesp diff --git a/Mourne-CI/application/models/village_model.php b/Mourne-CI/application/models/village_model.php index 05a1fa2..20a5e42 100755 --- a/Mourne-CI/application/models/village_model.php +++ b/Mourne-CI/application/models/village_model.php @@ -2,99 +2,103 @@ class Village_model extends MO_Model { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function apply_settings($data) - { - if ($data['ai']) - $ai = 1; - else - $ai = 0; + public function apply_settings($data) + { + if ($data['ai']) { + $ai = 1; + } else { + $ai = 0; + } - $sql = "UPDATE villages - SET name='" . $data['name'] . "', - ai_on = '$ai' - WHERE id='" . $data['id'] . "'"; + $sql = "UPDATE villages + SET name='" . $data['name'] . "', + ai_on = '$ai' + WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); - } + $this->db->query($sql); + } - function get_village($id) - { - $sql = "SELECT * FROM villages WHERE id='$id'"; + public function get_village($id) + { + $sql = "SELECT * FROM villages WHERE id='$id'"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function select_village($id, $userid) - { - //first check if villageid belongs to user - $sql = "SELECT * FROM villages WHERE id='$id'"; + 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); + $q = $this->db->query($sql); - if (!$q->num_rows()) - return; + if (!$q->num_rows()) { + return; + } - $res = $q->row_array(); + $res = $q->row_array(); - if ($res['userid'] != $userid) - return; + if ($res['userid'] != $userid) { + return; + } - if ($res['selected']) - return; + if ($res['selected']) { + return; + } - $sql = "UPDATE villages SET selected='0' WHERE userid='$userid'"; + $sql = "UPDATE villages SET selected='0' WHERE userid='$userid'"; - $this->db->query($sql); + $this->db->query($sql); - $sql = "UPDATE villages SET selected='1' WHERE id='$id'"; + $sql = "UPDATE villages SET selected='1' WHERE id='$id'"; - $this->db->query($sql); - } + $this->db->query($sql); + } - function get_villages($userid) - { - $sql = "SELECT * FROM villages WHERE userid='$userid' ORDER BY score DESC"; + public function get_villages($userid) + { + $sql = "SELECT * FROM villages WHERE userid='$userid' ORDER BY score DESC"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function create_village($userid, $username, $posx = -1, $posy = -1) - { - //make all village unselected - $sql = "UPDATE villages + public function create_village($userid, $username, $posx = -1, $posy = -1) + { + //make all village unselected + $sql = "UPDATE villages SET selected='0' WHERE userid='$userid'"; - $this->db->query($sql); + $this->db->query($sql); - $villagename = $username . "\'s village"; + $villagename = $username . "\'s village"; - $sql = "INSERT INTO villages VALUES(default, '$userid', '$villagename', + $sql = "INSERT INTO villages VALUES(default, '$userid', '$villagename', default, '1', default, default, default, default, default, default)"; - $this->db->query($sql); + $this->db->query($sql); - //getting back id from newly created village - $sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'"; - $q = $this->db->query($sql); - $res = $q->row_array(); + //getting back id from newly created village + $sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'"; + $q = $this->db->query($sql); + $res = $q->row_array(); - $id = $res['id']; + $id = $res['id']; - //resources-> id, villageid, res[5], max_res[5], rate_res[5], last_updated - $time = time(); + //resources-> id, villageid, res[5], max_res[5], rate_res[5], last_updated + $time = time(); - //make resources entry - $sql = "INSERT INTO resources + //make resources entry + $sql = "INSERT INTO resources VALUES(default, '$id', default, default, default, default, default, default, default, default, default, default, @@ -103,92 +107,80 @@ class Village_model extends MO_Model default, default, default, default, default, '$time')"; - $this->db->query($sql); + $this->db->query($sql); - $found = FALSE; + $found = false; - while(!$found) - { - //get a map coordinates - //we should get 20x20 field - //ids start with 1, max is 240 - $x_m_s = rand(1, 220); - $y_m_s = rand(1, 220); + while (!$found) { + //get a map coordinates + //we should get 20x20 field + //ids start with 1, max is 240 + $x_m_s = rand(1, 220); + $y_m_s = rand(1, 220); - $sql = "SELECT * FROM map + $sql = "SELECT * FROM map WHERE (X >= '$x_m_s' AND X <= '" . ($x_m_s + 20) . "') AND (Y >= '$y_m_s' AND Y <= '" . ($y_m_s + 20) . "')"; - $q = $this->db->query($sql); + $q = $this->db->query($sql); - $res = $q->result_array(); + $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'] . "'"; - - $this->db->query($sql); - break; - } - } + $sql = "UPDATE map SET type='3', villageid='$id' WHERE id='" . $row['id'] . "'"; + $this->db->query($sql); + break; + } + } + } } - } - //slotids range from 1 to parent::TOTAL_BUILDINGS! - //slot 0 can be used for a wall or something - function get_buildings($vid) - { - //tODO Empty slots + //slotids range from 1 to parent::TOTAL_BUILDINGS! + //slot 0 can be used for a wall or something + public function get_buildings($vid) + { + //tODO Empty slots - //TODO query, get building info for empty spaces, and thats going to be pushed into empty - //speces + //TODO query, get building info for empty spaces, and thats going to be pushed into empty + //speces - $sql = "SELECT * FROM buildings WHERE id='1'"; - $q = $this->db->query($sql); - $space = $q->row_array(); + $sql = "SELECT * FROM buildings WHERE id='1'"; + $q = $this->db->query($sql); + $space = $q->row_array(); - //this needs left join - $sql = "SELECT * FROM village_buildings + //this needs left join + $sql = "SELECT * FROM village_buildings INNER JOIN buildings ON village_buildings.buildingid=buildings.id WHERE villageid='$vid' ORDER BY slotid ASC"; - $q = $this->db->query($sql); - $res = $q->result_array(); + $q = $this->db->query($sql); + $res = $q->result_array(); - $new = FALSE; - $j = 0; + $new = false; + $j = 0; - 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; - } + 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; + } - if ($new) - { - $data[] = $space; - $new = FALSE; - } + if ($new) { + $data[] = $space; + $new = false; + } + } + + return $data; } - - return $data; - } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/models/weather_model.php b/Mourne-CI/application/models/weather_model.php index 52d2e79..5906b2b 100755 --- a/Mourne-CI/application/models/weather_model.php +++ b/Mourne-CI/application/models/weather_model.php @@ -1,56 +1,54 @@ db->query($sql); - - $res = $q->result_array(); - - $data[] = 'Nothing'; - - foreach ($res as $row) + public function __construct() { - $data[] = $row['name']; + parent::__construct(); } - return $data; - } + public function get_weathers_drop_admin() + { + $sql = "SELECT * FROM weathers"; + $q = $this->db->query($sql); - function get_weather_effects_drop_admin() - { - $data[0] = 'No Effect'; - $data[1] = 'Fires'; + $res = $q->result_array(); + + $data[] = 'Nothing'; + + foreach ($res as $row) { + $data[] = $row['name']; + } + + return $data; + } + + public function get_weather_effects_drop_admin() + { + $data[0] = 'No Effect'; + $data[1] = 'Fires'; - return $data; - } + return $data; + } - function list_weathers_admin() - { - $sql = "SELECT * FROM weathers"; - $q = $this->db->query($sql); + public function list_weathers_admin() + { + $sql = "SELECT * FROM weathers"; + $q = $this->db->query($sql); - return $q->result_array(); - } + return $q->result_array(); + } - function get_weather_admin($id) - { - $sql = "SELECT * FROM weathers WHERE id='$id'"; - $q = $this->db->query($sql); + public function get_weather_admin($id) + { + $sql = "SELECT * FROM weathers WHERE id='$id'"; + $q = $this->db->query($sql); - return $q->row_array(); - } + return $q->row_array(); + } - function edit_weather_admin($data) - { - - $sql = "UPDATE weathers + public function edit_weather_admin($data) + { + $sql = "UPDATE weathers SET name='" . $data['name'] . "', description='" . $data['description'] . "', art='" . $data['art'] . "', @@ -68,14 +66,14 @@ class Weather_model extends MO_Model mod_percent_mana='" . $data['mod_percent_mana'] . "' WHERE id='" . $data['id'] . "'"; - $this->db->query($sql); + $this->db->query($sql); - $this->_create_sql($sql); - } + $this->_create_sql($sql); + } - function add_weather_admin($data) - { - $sql = "INSERT INTO weathers VALUES(default, + public function add_weather_admin($data) + { + $sql = "INSERT INTO weathers VALUES(default, '" . $data['name'] . "', '" . $data['description'] . "', '" . $data['art'] . "', @@ -92,10 +90,9 @@ class Weather_model extends MO_Model '" . $data['mod_percent_iron'] . "', '" . $data['mod_percent_mana'] . "')"; - $this->db->query($sql); - - $this->_create_sql($sql); - } + $this->db->query($sql); + $this->_create_sql($sql); + } } -//nowhitesp \ No newline at end of file +//nowhitesp diff --git a/Mourne-CI/application/views/admin/ai_settings_tool/settings.php b/Mourne-CI/application/views/admin/ai_settings_tool/settings.php index a054001..78b4ce5 100755 --- a/Mourne-CI/application/views/admin/ai_settings_tool/settings.php +++ b/Mourne-CI/application/views/admin/ai_settings_tool/settings.php @@ -5,41 +5,38 @@ $this->load->helper('form'); $link_back = 'admin/ai_settings_tool'; $attr_description = array( - 'name' => 'description', - 'rows' => '5', - 'cols' => '50', - 'class' => 'textarea'); + 'name' => 'description', + 'rows' => '5', + 'cols' => '50', + 'class' => 'textarea'); $attr_setting = array( - 'name' => 'setting', - 'class' => 'input'); + 'name' => 'setting', + 'class' => 'input'); $attr_value = array( - 'name' => 'value', - 'class' => 'input'); + 'name' => 'value', + 'class' => 'input'); $attr_submit = array( - 'name' => 'submit', - 'value' => 'Submit', - 'class' => 'submit'); + 'name' => 'submit', + 'value' => 'Submit', + 'class' => 'submit'); -if ($new) -{ - //set every value with set_value() - $link_form = 'admin/ai_settings'; +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 -{ - //set every value from data sent - $link_form = 'admin/ai_settings/' . $setting['id']; + $attr_setting['value'] = set_value('setting'); + $attr_value['value'] = set_value('value'); + $attr_description['value'] = set_value('description'); +} else { + //set every value from data sent + $link_form = 'admin/ai_settings/' . $setting['id']; - $attr_setting['value'] = $setting['setting']; - $attr_value['value'] = $setting['value']; - $attr_description['value'] = $setting['description']; + $attr_setting['value'] = $setting['setting']; + $attr_value['value'] = $setting['value']; + $attr_description['value'] = $setting['description']; } ?>