function combatAction() { $this->view->title = "Combat"; $id = (int) $this->_request->getParam('id', 0); // Pour afficher la zone $zone = new Zone(); $monstre = new Monstre(); $avatar = new Avatar(); $classe = new Classe(); $case = new Case_(); // Pour afficher l'inventaire dans le menu $arme_ = new Objet(); $armure_ = new Objet(); $avatar = $avatar->findById($id); $ligne = $case->getLigne($avatar->id_case); $colonne = $case->getColonne($avatar->id_case); $classe = $classe->getNameById($avatar->id_classe); $arme_ = $arme_->findById($avatar->id_arme); $armure_ = $armure_->findById($avatar->id_armure); $case = $case->findById($avatar->id_case); $appMonstre = new Zend_Session_Namespace('appMonstre'); $fin_combat = false; //zone $zone = $zone->findById($case->id_zone); if (!isset($appMonstre->round)) { $appMonstre->round = 0; $id_monstre = $appMonstre->id_monstre; echo $id_monstre; $monstre = $monstre->findById($id_monstre); $appMonstre->hp_monstre = $monstre->hp_monstre; $appMonstre->mp_monstre = $monstre->mp_monstre; $appMonstre->att_monstre = $monstre->att_monstre; $appMonstre->attsp_monstre = $monstre->attsp_monstre; $appMonstre->def_monstre = $monstre->def_monstre; $appMonstre->defsp_monstre = $monstre->defsp_monstre; $appMonstre->vit_monstre = $monstre->vit_monstre; } else { $monstre = $monstre->findById($appMonstre->id_monstre); } if ($appMonstre->hp_monstre == 0) { $message_victoire = "Vous avez vaincu " . $monstre->nom_monstre; $fin_combat = true; $appMonstre->round = NULL; $this->view->fin_message = $message_victoire; } if ($avatar->hp_avatar == 0) { $message_defaite = "Vous avez été vaincu par " . $monstre->nom_monstre; $fin_combat = true; $appMonstre->round = NULL; $this->view->fin_message = $message_defaite; } if ($fin_combat && $avatar->hp_avatar > 0) { $dropsmonstre = new ObjetMonstre(); $dropsmonstre = $dropsmonstre->getByMonstre($appMonstre->id_monstre); $cpt = 0; $drops = array(); foreach ($dropsmonstre as $drop) { $nbaleatoire = rand(0, 100); if ($nbaleatoire < $drop->taux_drop) { $item = new LigneInventaire(); if ($item = $item->findItem($avatar->id_avatar, $drop->id_objet)) { $data = array('quantite_ligne' => $item->quantite_ligne + 1); $where = " id_avatar = " . $avatar->id_avatar . " AND id_objet = " . $drop->id_objet; $item = new LigneInventaire(); $item->update($data, $where); } else { $data = array('id_avatar' => $avatar->id_avatar, 'id_objet' => $drop->id_objet, 'quantite_ligne' => 1); $item = new LigneInventaire(); $item->insert($data); } $objet = new Objet(); $drops[$cpt] = $objet->findById($drop->id_objet)->nom_objet; $cpt++; } } $this->view->dropsmonstre = $drops; $this->view->cpt = $cpt; $avatar_ = new Avatar(); $exp = $avatar->exp_avatar + $monstre->exp_monstre; $data = array('exp_avatar' => $exp); $where = ' id_avatar = ' . $id; $avatar_->update($data, $where); lvlUp($id); $this->view->exp = $exp; } //gestion de la fuite $fuite = false; $this->view->fuite = ""; if (isset($appMonstre->fuite)) { if ($appMonstre->fuite == true) { $this->view->message_fuite = "Fuite réussie!"; $fuite = true; $appMonstre->round = NULL; } else { $this->view->message_fuite = "Fuite échouée!"; } $appMonstre->fuite = NULL; } $this->view->fuite = $fuite; $this->view->fin_combat = $fin_combat; $this->view->ligne = $ligne; $this->view->colonne = $colonne; $this->view->avatar = $avatar; $this->view->classe = $classe; $this->view->monstre = $monstre; $this->view->monstre_ = $appMonstre; $this->view->arme_ = $arme_; $this->view->armure_ = $armure_; $this->view->zone = $zone; }