<?php

namespace loyalsoft;

/**
 * 任务信息
 */
class Ins_TaskInfo extends Object_ext {

    /**
     *
     * @var 任务ID 
     */
    public $taskId;

    /**
     * @var float 任务进度(浮点值好了>=1代表完成)
     */
    public $progress = 0;

    /**
     * 用于将进度更新的数据待会给客户端,比如当前PVP积分之类的,在客户端是无法即时拿到数据的
     * @var object
     */
    public $tag1;
    public $tag2;

    /**
     * @var int 计数器
     */
    public $counter = 0;

    /**
     * @var int 奖励是否已领取 0/1
     */
    public $rewardGeted = 0;

    public function bCheckProgress($param) {
        $taskCfg = GameConfig::task_getItem($this->taskId);
        my_Assert($taskCfg != null, ErrCode::err_const_no);                     # 获取任务配置数据   
        if ($taskCfg->tasktype != $param->taskType) {                           # 任务类型必须匹配
            return false;
        }
        if (is_null($taskCfg->canshu1)) {
            $this->progress = 1;
            return true;
        }
        $this->tag1 = max($this->tag1, $param->canshu1);
        if ($taskCfg->canshu1 <= $param->canshu1) {
            if (null == $taskCfg->canshu2 || 0 == $taskCfg->canshu2) {
                $this->progress = 1;
                return true;
            }
            if (is_numeric($taskCfg->canshu2)) {
                $this->tag2 = max($this->tag2, $param->canshu2);
                if ($taskCfg->canshu2 <= $param->canshu2) {
                    $this->progress = 1;
                    return true;
                }
            } else {
                $this->tag2 = $param->canshu2;
                if ($taskCfg->canshu2 == $param->canshu2) {
                    $this->progress = 1;
                    return true;
                }
            }
        }
        return false;
    }

}
