<?php

namespace loyalsoft;

/**
 * 玩家关卡地图数据
 * @author gwang
 * @version 
 *         1.0.0 Created at 2021年3月2日14:32:52 关卡分三层处理 大陆->区域->关卡.
 */
class Info_Map extends Object_ext {

    /**
     * 大陆数据
     * @var dict<int,Ins_Mainland>
     */
    public $mainlands;
    
    /**
     * 战斗关卡记录--1.记录剧情关卡记录；2.副本唤灵师关卡 3.副本武器关卡 4.副本言灵关卡  
     * @param type $arg
     */
    public $battleRecord = array();

    function __construct($arg = null) {
        if (null === $arg) {
//            $this->battleRecord = new \stdClass();
//            $arr = array();
//            $arr[] = 1;
//            $arr[] = 2;
//            $arr[] = 3;
//            $arr[] = 4;
//            foreach ($arr as $key) {
//                $this->battleRecord->$key = array();
//            }
          
            // 直接初始化8个大陆的基本数据
            $this->mainlands = ObjectInit();
            foreach (GameConfig::gate_mainland() as $id => $land) {
                $ins = new Ins_Mainland();
                $ins->landId = $id;
                if (1 == $id) {                                                 # 第一个大陆, 直接开启第一个区域
                    $zones = explode(',', $land->containZones);
                    $zoneid = $zones[0];
                    $zone = new Ins_Mapzone();
                    $zone->zoneid = $zoneid;
                    $zonecfg = GameConfig::gate_zone_getItem($zoneid);
                    my_Assert($zonecfg, ErrCode::err_const_no);
                    $gateIds = explode(',', $zonecfg->contains);
                    $zone->gates[] = $gateIds[0];
                    $ins->normal->$zoneid = $zone;
                }
                $this->mainlands->$id = $ins;
            }
        } else {
            parent::__construct($arg);
        }
    }

    public function addBattleRecord($gateId) {                    
        if(!in_array($gateId,$this->battleRecord)){
            if(strlen($gateId) == 8 && substr($gateId,0,3) == 2001){
                $type = Enum_TargetStatistics::HuanLingShiGateId_ComUserNum;
            } elseif (strlen($gateId) == 8 && substr($gateId,0,3) == 2002) {
                $type = Enum_TargetStatistics::WeaponGateId_ComUserNum;
            } elseif (strlen($gateId) == 8 && substr($gateId,0,3) == 2003) {
                $type = Enum_TargetStatistics::YanLingGateId_ComUserNum;
            } else {
                $type = Enum_TargetStatistics::storyGateId_ComUserNum;
            }
                      
            $arr = $this->battleRecord;
            $arr[] = $gateId;
            $this->battleRecord= $arr;
            StatisticsProc::TargetStatistics($type, $gateId);
        }
    }
    
    public function addBattleNumRecord($gateId,$ret) {                           
            if(strlen($gateId) == 8 && substr($gateId,0,3) == 2001){
                $type = Enum_TargetStatistics::HuanLingShiGateId_BattleNum;
            } elseif (strlen($gateId) == 8 && substr($gateId,0,3) == 2002) {
                $type = Enum_TargetStatistics::WeaponGateId_BattleNum;
            } elseif (strlen($gateId) == 8 && substr($gateId,0,3) == 2003) {
                $type = Enum_TargetStatistics::YanLingGateId_BattleNum;
            } else {
                $type = Enum_TargetStatistics::storyGateId_BattleNum;
            }
            $battleNum = 0;
            $passNum = 0;
            if($ret == true){
                $battleNum = 1;
                $passNum = 1;
            } else {
                $battleNum = 1;
                $passNum = 0;
            }
                      
            $ctx = $battleNum."/".$passNum;
            StatisticsProc::TargetStatistics($type, $gateId,$ctx);        
    }
}
