pet.h 4.71 KB
#pragma once

#include <common.h>
#include <common_msg.pb.h>

//战斗桌子上,一边放的宠物最大数量	
#define BTL_TABLE_PET_CNT_MAX 7

class user_t;
struct pet_t;
#define EFF_FUN_PARA user_t* user_ack, user_t* user_def, pet_t* pet_ack, share_msg::btl_ack_t* out_btl_ack, bool is_ack_chaofeng, pet_t** pet_def
typedef int(*EFF_FUN)(EFF_FUN_PARA);

struct eff_t
{
	EFF_ID id;
	EFF_FUN func;
	eff_t();
};

struct eff_cfg_mgr_t {
	std::map<EFF_ID, eff_t> eff_map;
	eff_t* find(EFF_ID id);
};

extern eff_cfg_mgr_t* g_eff_cfg_mgr;


struct skill_t
{
	SKILL_ID id;
	SKILL_TYPE type;
	uint32_t levelRate;// 0:一定触发, 1:使用等级概率触发(聪明度)	
	eff_t* eff;
	std::vector<int> eff_param_vec;
	uint32_t priority;//技能优先级[0,100] 0:普通, 100:最大	
	skill_t();
	bool is_kaichang(){
		return 1 == this->type;
	}
	bool is_xianfa(){
		return 2 == this->type;
	}
	bool is_zhudong(){
		return 3 == this->type;
	}
	bool is_beidong(){
		return 4 == this->type;
	}
};

struct buf_t
{
	BUF_ID id;
	int time;//有效次数	
	int round;//持续回合数	
	int param1;
	int param2;
	int param3;
	buf_t(){
		this->id = 0;
		this->time = -1;
		this->round = -1;
		this->param1 = 0;
		this->param2 = 0;
		this->param3 = 0;
	}
};
struct pet_cfg_t{
	PET_ID id;
	PET_ATTR attr;//属性1:水 2:火 3:草	
	pet_cfg_t(){
		this->id = 0;
		this->attr = 0;
	}
};
struct pet_cfg_mgr_t
{
	bool load_cfg();
	void init();
	std::map<SKILL_ID, skill_t> skill_map;
	skill_t* find(SKILL_ID id);

	std::map<PET_ID, pet_cfg_t> pet_cfg_map;//key:id
	pet_cfg_t* find_pet_cfg(PET_ID id);
};

extern pet_cfg_mgr_t* g_pet_cfg_mgr;

struct pet_mgr_t;
struct pet_t{
	pet_t(){
		this->used_kaichang = false;
		this->skill = NULL;
		this->pet_cfg = NULL;
		this->pet_mgr = NULL;
		this->pet_key = 0;
	}
	PET_KEY pet_key;
	pet_mgr_t* pet_mgr;
	share_msg::pet_btl_t pet_btl;
	skill_t* skill;
	pet_cfg_t* pet_cfg;
	bool used_kaichang;
	std::list<buf_t> buf;
	PET_ID id();
	PET_KEY key();
	EFF_ID get_eff_id();
	uint32_t get_all_ack();
	uint32_t get_all_hp();

	// 是否可以行动 [2019/3/4 Administrator]
	bool is_active();
	bool is_die();
	// 是否可以成为被攻击目标 [2019/3/4 Administrator]
	bool can_ack_target();
	
	// 是否足够聪明触发技能 [2019/2/25 Administrator]
	bool is_congming();
	bool has_buf(BUF_ID buf_id);

	// 改变宠物数据,打包数据 [2019/3/5 Administrator]
	void out_pack_del_buf(user_t* user, pet_t* pet, buf_t* buf, share_msg::btl_ack_t* out_btl_ack);
	// 随机出对手 [2019/3/4 Administrator]
	pet_t* random_peer(user_t* user_def, bool is_ack_chaofeng);
	// 附近的宠物 [2019/3/5 Administrator]
	std::vector<pet_t*> near_pet();
	// 被动,改变hp [2019/3/6 Administrator]
	void beidong_306(share_msg::btl_ack_t* out_btl_ack);
	// 被动,受到攻击 [2019/3/6 Administrator]
	void beidong_300( share_msg::btl_ack_t* out_btl_ack, pet_t* pet_ack );
	void beidong_302( share_msg::btl_ack_t* out_btl_ack, pet_t* pet_ack, int& reduce_ack_hp );
	// 被动,保护相邻(相邻受到普通攻击,帮忙抵挡伤害) [2019/3/6 Administrator]
	pet_t* beidong_301( share_msg::btl_ack_t* out_btl_ack );

	void beidong_303(share_msg::btl_ack_t* out_btl_ack, pet_t* pet);
	void beidong_304(share_msg::btl_ack_t* out_btl_ack, pet_t* pet);
	void beidong_307(share_msg::btl_ack_t* out_btl_ack, pet_t* pet);
	void beidong_308(share_msg::btl_ack_t* out_btl_ack, pet_t* pet);
	void beidong_309(share_msg::btl_ack_t* out_btl_ack, pet_t* pet);
	//////////////////////////////////////////////////////////////////////////
	
	void update_ack(share_msg::btl_ack_t* out_btl_ack, int ack);
	void set_ack(share_msg::btl_ack_t* out_btl_ack, int ack);
	void update_hp(share_msg::btl_ack_t* out_btl_ack, int hp);
	void set_hp(share_msg::btl_ack_t* out_btl_ack, int hp);
	void add_buf(share_msg::btl_ack_t* out_btl_ack, buf_t& buf);
	void del_all_buf( share_msg::btl_ack_t* out_btl_ack, BUF_ID buf_id );
	void del_skill(share_msg::btl_ack_t* out_btl_ack);
};


struct pet_mgr_t{
	user_t* user;
	std::vector<pet_t> pet_vec;
	std::vector<pet_t> table_pet_vec;
	pet_t* find(PET_ID pet_id){
		FOREACH(this->pet_vec, it){
			pet_t& r = *it;
			if (pet_id == r.pet_btl.id()){
				return &r;
			}
		}
		return	NULL;
	}
	SKILL_ID find_skill_id(PET_ID pet_id){
		auto pet = this->find(pet_id);
		if (NULL == pet){
			return 0;
		}
		return pet->pet_btl.skill_id();
	}
	skill_t* find_skill(PET_ID pet_id){
		SKILL_ID sid = this->find_skill_id(pet_id);
		if (0 == sid){
			return NULL;
		}
		return g_pet_cfg_mgr->find(sid);
	}
	// 放到待上场队列 [2019/3/4 Administrator]
	void push_back( share_msg::btl_ack_t* out_btl_ack, pet_t& new_pet );
	// 放到桌上 [2019/3/4 Administrator]
	void push_back_on_table( share_msg::btl_ack_t* out_btl_ack, pet_t& new_pet );

	bool has_attr_on_table(PET_ATTR pet_attr){
		FOREACH(this->table_pet_vec, it){
			pet_t& pet = *it;
			if (pet_attr == pet.pet_cfg->attr){
				return true;
			}
		}
		return false;
	}


};