mourne_rcpp_fw/Mourne-CI/application/models/spell_model.php

240 lines
6.7 KiB
PHP
Raw Normal View History

2021-10-30 19:02:07 +02:00
<?php
class Spell_model extends MO_Model
{
public function __construct()
{
parent::__construct();
}
2021-10-30 19:02:07 +02:00
public function use_spell($spellid, $slotid, $res, $villageid)
{
$this->resources = $res;
2021-10-30 19:02:07 +02:00
//getting spell
$sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end
2021-10-30 19:02:07 +02:00
FROM building_spells
LEFT JOIN spells ON building_spells.spellid=spells.id
LEFT JOIN building_spell_cooldowns
ON (building_spells.spellid=building_spell_cooldowns.spellid
AND building_spell_cooldowns.slotid='$slotid'
AND building_spell_cooldowns.villageid='$villageid')
WHERE building_spells.villageid='$villageid'
AND building_spells.slotid='$slotid'
AND building_spells.spellid='$spellid'";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
if (!$q->num_rows()) {
return 1;
}
2021-10-30 19:02:07 +02:00
$spell = $q->row_array();
2021-10-30 19:02:07 +02:00
if ($spell['cooldown_end']) {
return 2;
}
2021-10-30 19:02:07 +02:00
if (!$this->check_resources($res, $spell)) {
return 3;
}
2021-10-30 19:02:07 +02:00
//everything is fine
//substracting cost
$this->substract_resources($spell, $villageid);
2021-10-30 19:02:07 +02:00
//addign modofiers
$this->add_modifiers($spell['id'], $villageid, 'spell');
2021-10-30 19:02:07 +02:00
$this->write_resources();
2021-10-30 19:02:07 +02:00
if ($spell['weather_change_to']) {
$sql = "UPDATE villages
2021-10-30 19:02:07 +02:00
SET weather_change_to='" . $spell['weather_change_to'] . "'
WHERE id='$villageid'";
$this->db->query($sql);
}
2021-10-30 19:02:07 +02:00
//do spelleffects here
2021-10-30 19:02:07 +02:00
//adding cooldown
$cd = $spell['cooldown'] + time();
2021-10-30 19:02:07 +02:00
$sql = "INSERT INTO building_spell_cooldowns
2021-10-30 19:02:07 +02:00
VALUES(default, '$villageid', '$slotid',
'" . $spell['id'] . "', '$cd')";
$this->db->query($sql);
2021-10-30 19:02:07 +02:00
//adding spell_effect_end to events
$ev['type'] = 3;
$ev['villageid'] = $villageid;
$ev['slotid'] = $slotid;
$ev['time'] = $spell['duration'];
$ev['data1'] = $spell['id'];
2021-10-30 19:02:07 +02:00
$this->add_event($ev);
}
2021-10-30 19:02:07 +02:00
public function get_spells($slotid, $villageid)
{
$this->update_spells($slotid, $villageid);
2021-10-30 19:02:07 +02:00
$sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end
2021-10-30 19:02:07 +02:00
FROM building_spells
LEFT JOIN spells ON building_spells.spellid=spells.id
LEFT JOIN building_spell_cooldowns
ON (building_spells.spellid=building_spell_cooldowns.spellid
AND building_spell_cooldowns.slotid='$slotid'
AND building_spell_cooldowns.villageid='$villageid')
WHERE building_spells.villageid='$villageid'
AND building_spells.slotid='$slotid'";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
return $q->result_array();
}
2021-10-30 19:02:07 +02:00
public function update_spells($slotid, $villageid)
{
$sql = "SELECT * FROM building_spell_cooldowns
2021-10-30 19:02:07 +02:00
WHERE slotid='$slotid'
AND villageid='$villageid'";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
if (!$q->num_rows()) {
return;
}
2021-10-30 19:02:07 +02:00
$spells = $q->result_array();
$time = time();
2021-10-30 19:02:07 +02:00
foreach ($spells as $row) {
if ($row['cooldown_end'] <= $time) {
$sql = "DELETE FROM building_spell_cooldowns
2021-10-30 19:02:07 +02:00
WHERE id='" . $row['id'] . "'";
$this->db->query($sql);
}
}
2021-10-30 19:02:07 +02:00
}
public function get_spell_mod_drop_admin()
{
//STUB
$data = array('0' => 'Nothing');
return $data;
}
2021-10-30 19:02:07 +02:00
public function list_spells_admin()
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
return $q->result_array();
}
2021-10-30 19:02:07 +02:00
public function get_spell_list_drop_admin()
2021-10-30 19:02:07 +02:00
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
$res = $q->result_array();
2021-10-30 19:02:07 +02:00
$data[0] = 'No Spell';
2021-10-30 19:02:07 +02:00
foreach ($res as $row) {
$data[$row['id']] = $row['description_admin'];
}
2021-10-30 19:02:07 +02:00
return $data;
}
2021-10-30 19:02:07 +02:00
public function get_spell_admin($id)
{
$sql = "SELECT * FROM spells WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
2021-10-30 19:02:07 +02:00
public function edit_spell_admin($data)
{
$sql = "UPDATE spells
2021-10-30 19:02:07 +02:00
SET effect='" . $data['effect'] . "',
duration='" . $data['duration'] . "',
cooldown='" . $data['cooldown'] . "',
description='" . $data['description'] . "',
description_admin='" . $data['description_admin'] . "',
weather_change_to='" . $data['weather_change_to'] . "',
cost_food='" . $data['cost_food'] . "',
cost_wood='" . $data['cost_wood'] . "',
cost_stone='" . $data['cost_stone'] . "',
cost_iron='" . $data['cost_iron'] . "',
cost_mana='" . $data['cost_mana'] . "',
mod_max_food='" . $data['mod_max_food'] . "',
mod_max_wood='" . $data['mod_max_wood'] . "',
mod_max_stone='" . $data['mod_max_stone'] . "',
mod_max_iron='" . $data['mod_max_iron'] . "',
mod_max_mana='" . $data['mod_max_mana'] . "',
mod_rate_food='" . $data['mod_rate_food'] . "',
mod_rate_wood='" . $data['mod_rate_wood'] . "',
mod_rate_stone='" . $data['mod_rate_stone'] . "',
mod_rate_iron='" . $data['mod_rate_iron'] . "',
mod_rate_mana='" . $data['mod_rate_mana'] . "',
mod_percent_food='" . $data['mod_percent_food'] . "',
mod_percent_wood='" . $data['mod_percent_wood'] . "',
mod_percent_stone='" . $data['mod_percent_stone'] . "',
mod_percent_iron='" . $data['mod_percent_iron'] . "',
mod_percent_mana='" . $data['mod_percent_mana'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
2021-10-30 19:02:07 +02:00
$this->_create_sql($sql);
}
2021-10-30 19:02:07 +02:00
public function add_spell_admin($data)
{
$sql = "INSERT INTO spells VALUES(default,
2021-10-30 19:02:07 +02:00
'" . $data['effect'] . "',
'" . $data['duration'] . "',
'" . $data['cooldown'] . "',
'" . $data['description'] . "',
'" . $data['description_admin'] . "',
'" . $data['weather_change_to'] . "',
'" . $data['cost_food'] . "',
'" . $data['cost_wood'] . "',
'" . $data['cost_stone'] . "',
'" . $data['cost_iron'] . "',
'" . $data['cost_mana'] . "',
'" . $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'] . "')";
$this->db->query($sql);
2021-10-30 19:02:07 +02:00
$this->_create_sql($sql);
}
2021-10-30 19:02:07 +02:00
public function get_spell_effects_admin()
{
//STUB!
$data = array('0' => 'No Effect');
2021-10-30 19:02:07 +02:00
return $data;
}
2021-10-30 19:02:07 +02:00
}
//nowhitesp