<?php

/*
 * 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.
 */

/**
 * Description of UserMissEx
 * 
 * @author jgao
 */
class Info_MissInfo {
    //put your code here

    /**
     * 正在进行中的任务
     * @var MisStatus 
     */
    public $ingMissions = null;
    /// <summary>
    /// 已经完成的任务
    /// </summary>
    public $overMissions = null;

    /**
     * 未完待续的任务
     * @var type 
     */
    public $contMissions = null;

    /**
     * 构造函数 
     */
    function __construct() {
        $this->ingMissions = new stdClass();
        $this->overMissions = new stdClass();
        $this->contMissions = new stdClass();
    }

    function initialize($value) {
        CommUtil::loadObject($value, $this);
        foreach ($this->ingMissions as $id => $val) { // 强类型化
            $ing = new MisStatus();
            $ing->initialize($val);
            $this->ingMissions->$id = $ing;
        }
    }

    /// <summary>
    /// 设置任务数据
    /// </summary>
    /// <param name="id"></param>
    /// <param name="mo"></param>
    public function setMission($id, $ing) {
        if ($id == 0)
            return;
        $this->ingMissions->$id = $ing;
    }

    /**
     * 
     * @param type $id
     * @return MisStatus
     */
    public function GetMission($id) {
        if (dict_exists($this->ingMissions, $id)) {
            return $this->ingMissions->$id;
        }
        return null;
    }

    /// <summary>
    /// 新增触发任务
    /// </summary>
    /// <param name="id"></param>
    public function addMission($id) {
        if ($id == 0) {
            return null;
        }
        $mo = dataCenter()->getMissionConst($id);
        $status = MisStatus::initFromMo($mo);
        $this->setMission($id, $status);
        return $status;
    }

    /// <summary>
    /// 是否挂载某个任务
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public function hasMission($id) {
        return dict_exists($this->ingMissions, $id);
    }

    /// <summary>
    /// 删除某个任务
    /// </summary>
    /// <param name="id"></param>
    public function delMission($id) {
        if ($this->hasMission($id)) {
            dict_remove($this->ingMissions, $id);
        }
    }

    /// <summary>
    /// 某任务是否曾经完成过
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public function onceFinished($id) {
        return dict_exists($this->overMissions, $id);
    }

    /// <summary>
    /// 完成某个任务
    /// </summary>
    /// <param name="id"></param>
    /// <param name="suc"></param>
    public function finishMission($id) {
        if ($this->hasMission($id)) {
            $this->delMission($id);
            $this->overMissions->$id = "ok";
        }
    }

}
