<?php
/**
 * Role.php UTF-8
 * 角色信息
 *
 * @date    : 2018/1/19 15:44
 *
 * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 * @author  : wuyonghong <wyh@huosdk.com>
 * @version : HUOSDK 8.0
 */

namespace huolib\queue\request;
class Role extends Request {
    private $event           = 0;  /* 角色上传事件类型 5 */
    private $server_id       = ''; /* 游戏服务器id, */
    private $server_name     = ''; /* 游戏服务器名称 */
    private $role_id         = ''; /* 玩家角色id */
    private $role_name       = ''; /* 玩家角色名称 */
    private $role_level      = 0;  /* 玩家角色等级 */
    private $combat_num      = 0;  /* 玩家角色战力 */
    private $last_login_time = 0;  /* 最后登陆时间 */
    public function __construct($data = []) {
        if (!empty($data)) {
            $this->setData($data);
        }
    }

    /**
     * 设置数据
     *
     * @param array $data
     */
    public function setData($data = []) {
        if (empty($data)) {
            return;
        }
        $this->setEvent(get_val($data, 'event', 0));
        $this->setServerId(get_val($data, 'server_id'));
        $this->setServerName(get_val($data, 'server_name'));
        $this->setRoleId(get_val($data, 'role_id'));
        $this->setRoleName(get_val($data, 'role_name'));
        $this->setRoleLevel(get_val($data, 'role_level', 0));
        $this->setCombatNum(get_val($data, 'combat_num', 0));
        $this->setLastLoginTime(get_val($data, 'last_login_time', 0));
    }

    /**
     * 变量转数组
     *
     * @return mixed
     */
    public function toArray() {
        $_data['server_id'] = $this->getServerId();
        $_data['server_name'] = $this->getServerName();
        $_data['role_id'] = $this->getRoleId();
        $_data['role_name'] = $this->getRoleName();
        $_data['role_level'] = $this->getRoleLevel();
        $_data['type'] = $this->getEvent();
        $_data['combat_num'] = $this->getCombatNum();
        $_data['last_login_time'] = $this->getLastLoginTime();

        return $_data;
    }

    /**
     * check参数合法性
     */
    public function check() {
        // TODO: wuyonghong 2018/5/30 校验角色参数合法性
        return true;
    }

    /**
     * @return int
     */
    public function getEvent() {
        return $this->event;
    }

    /**
     * @param int $event
     */
    public function setEvent($event) {
        $this->event = $event;
    }

    /**
     * @return string
     */
    public function getServerId() {
        return $this->server_id;
    }

    /**
     * @param string $server_id
     */
    public function setServerId($server_id) {
        $this->server_id = $server_id;
    }

    /**
     * @return string
     */
    public function getServerName() {
        return $this->server_name;
    }

    /**
     * @param string $server_name
     */
    public function setServerName($server_name) {
        $this->server_name = $server_name;
    }

    /**
     * @return string
     */
    public function getRoleId() {
        return $this->role_id;
    }

    /**
     * @param string $role_id
     */
    public function setRoleId($role_id) {
        $this->role_id = $role_id;
    }

    /**
     * @return string
     */
    public function getRoleName() {
        return $this->role_name;
    }

    /**
     * @param string $role_name
     */
    public function setRoleName($role_name) {
        $this->role_name = $role_name;
    }

    /**
     * @return int
     */
    public function getRoleLevel() {
        return $this->role_level;
    }

    /**
     * @param int $role_level
     */
    public function setRoleLevel($role_level) {
        $this->role_level = $role_level;
    }

    /**
     * @return int
     */
    public function getCombatNum() {
        return $this->combat_num;
    }

    /**
     * @param int $combat_num
     */
    public function setCombatNum($combat_num) {
        $this->combat_num = $combat_num;
    }

    /**
     * @return int
     */
    public function getLastLoginTime() {
        return $this->last_login_time;
    }

    /**
     * @param int $last_login_time
     */
    public function setLastLoginTime($last_login_time) {
        $this->last_login_time = $last_login_time;
    }
}