<?php
namespace loyalsoft;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace loyalsoft;

/**
 * Description of CollegeInfo
 *
 * @author cyzhao
 */
class Info_College extends Object_ext{
    /**
     * 当前所在的级别 
     */
    public $collegeId = 1;

    /// <summary>
    /// 所处的课程id
    /// </summary>
    public $courseId = 1001;
    
    /**
     * 将领取课程奖励的保存在这
     * @var type
     */
    public $comCourseList = array();

    /// <summary>
    /// 任务卡信息
    /// </summary>
    //public List<missCourseItem> compMissCardList = new List<missCourseItem>();
    public $compMissCardDic=null;
    
    /**
     * 当前课程进度，进入下一个课程清0
     * @var type
     */
    public $progress = 0;
    
    /**
     * 年级奖励领取记录
     * @var type
     */
    public $collegeRewardList = array();
    
    /**
     * 
     * @var type
     */
    public $maskCollege = 0;

    /**
     * 构造函数
     * @param type $args
     */
    public function __construct($args = null) {    
        if($args == null){
            $this->compMissCardDic = new \stdClass();
        } else {
            parent::__construct($args);   
        }                    
    }
    
    public function initialize() {
//        $this->compMissCardDic = new \stdClass();  
//        $dic = GameConfig::course_getItem($this->courseId);       
//        $misslist = explode(',',$dic->misslist);      
//        foreach ($misslist as $id) {
//            $item = new ins_missCourseItem();        
//            $item->initialize($id);         
//            $this->compMissCardDic->$id = $item;
//        }
        $this->initCompMissCardDic();
    }
    
    public function initCompMissCardDic() {
        $this->compMissCardDic = new \stdClass();  
        $dic = GameConfig::course_getItem($this->courseId);       
        $misslist = explode(',',$dic->misslist);      
        foreach ($misslist as $id) {
            $item = new ins_missCourseItem();        
            $item->initialize($id);         
            $this->compMissCardDic->$id = $item;
        }
    }
    
    /**
     * 修改任务卡状态
     * @param type $id
     * @param type $state
     */
    public function modifyTaskCardState($id,$state) {       
        if(!StlUtil::dictHasProperty($this->compMissCardDic, $id)){
            return;
        }
        $this->compMissCardDic->$id->type = $state;
        $this->progress += 1;           
        
        TaskProc::OnFinishSchoolTask();
    }
      
    public function updataCourseNew() {            
        //检测是否到下一年级
//        $collegeDic = GameConfig::college_getItem($this->collegeId);      
//        if(in_array($this->courseId +1,explode(',', $collegeDic->cList))){
//            $this->courseId += 1;
//            $this->initCompMissCardDic();
//            $this->progress = 0;
//        } else {
            
        $this->collegeRewardList[] = $this->collegeId;
        //TaskProc::OnFinishAllSchoolTaskOfGrade($this->collegeId);
        
        $this->collegeId += 1;    
        $newCollegeDic = GameConfig::college_getItem($this->collegeId);  
        if($newCollegeDic == null){
            $this->maskCollege = Enum_College::finish;
            $this->collegeId -= 1;
        } elseif ($newCollegeDic != null && $newCollegeDic->cList == null) {
            $this->maskCollege = Enum_College::update;
        } else {
            $cList = explode(',', $newCollegeDic->cList);
            $this->courseId = $cList[0];
            $this->initCompMissCardDic();   
        }                    
//        }                  
    }
    
    /**
     * 
     */
    public function updataCourse() { 
        $this->comCourseList[] = $this->courseId;       
        //检测是否到下一年级
        $collegeDic = GameConfig::college_getItem($this->collegeId);      
        if(in_array($this->courseId +1,explode(',', $collegeDic->cList))){
            $this->courseId += 1;
            $this->initCompMissCardDic();
            $this->progress = 0;
        } 
        
//        else {
//            $this->collegeId += 1;
//            $newCollegeDic = GameConfig::college_getItem($this->collegeId);  
//            $cList = explode(',', $newCollegeDic->cList);
//            $this->courseId = $cList[0];
//            $this->initCompMissCardDic();
//            $this->progress = 0;
//        }                  
    }
    
    public function checkCollege() {
        if($this->maskCollege == Enum_College::update){
            $dic = GameConfig::college_getItem($this->collegeId);
            if($dic != null && $dic->cList != null){
                $this->maskCollege = 0;
                $cList = explode(',', $dic->cList);
                $this->courseId = $cList[0];
                $this->initCompMissCardDic();
            }                               
        }           
    }
    
    
}
