📄 gameunit.cpp
字号:
shu.pos.src_y = m_FlatY;
shu.pos.src_h = m_fHeight;
shu.pos.dest_x = m_FlatX;
shu.pos.dest_y = m_FlatY;
shu.pos.dest_h = m_fHeight;
m_pGame->query_handle_unit(&shu);
// STRUCT_HANDLE_PLACE shp;
// shp.pos.uid = m_id;
// shp.pos.src_x = m_FlatX;
// shp.pos.src_y = m_FlatY;
// shp.pos.src_h = m_fHeight;
// shp.pos.dest_x = m_FlatX;
// shp.pos.dest_y = m_FlatY;
// shp.pos.dest_h = m_fHeight;
//
// m_pGame->query_handle_place(&shp);
}
}
else
{
m_is_indispensable = TRUE;
DWORD dwTime = Sys_GetTime();
m_map_query_holder["goto"] = 0;
m_map_query_holder["melee"] = 0;
m_map_query_holder["spell"] = 0;
}
}
BOOL Game_Unit::IsPlayer()
{
if(m_pGame==NULL)
return FALSE;
Game_Unit* pUnit = m_pGame->GetControlUnit();
if(pUnit==NULL)
return FALSE;
return m_id==pUnit->m_id;
}
void Game_Unit::query_speek(const char* strSpeek)
{
m_pGame->query_speek(m_id, strSpeek);
}
void Game_Unit::query_goto(float x, float y)
{
DWORD dwTime = Sys_GetTime();
if(dwTime-m_map_query_holder["goto"]>300)
{
m_map_query_holder["goto"] = dwTime;
if(CanGoto())
{
STRUCT_HANDLE_PLACE shp;
shp.uid = m_id;
shp.pos.src_x = m_FlatX;
shp.pos.src_y = m_FlatY;
shp.pos.dest_h = m_fHeight;
shp.pos.dest_x = x;
shp.pos.dest_y = y;
shp.pos.dest_h = m_fHeight;
//pUnit->PlyWalkTo(point.x+x, point.y+y);
m_pGame->query_handle_place(&shp);
}
}
}
void Game_Unit::query_melee(Game_Unit* pUnit, uint32 type)
{
if(!CanMelee())
{
return;
}
if(pUnit->is_death())
return;
DWORD dwTime = Sys_GetTime();
if(dwTime-m_map_query_holder["melee"]>500)
{
m_map_query_holder["melee"] = dwTime;
m_map_query_holder["spell"] = dwTime;
m_map_query_holder["goto"] = dwTime;
STRUCT_HANDLE_UNIT shu;
shu.action = GSACT_ATTACK;
shu.uid = m_id;
shu.uid_obj = pUnit->GetID();
shu.uid_action_type = type;
shu.pos.src_x = m_FlatX;
shu.pos.src_y = m_FlatY;
shu.pos.src_h = m_fHeight;
shu.pos.dest_x = pUnit->m_FlatX;
shu.pos.dest_y = pUnit->m_FlatY;
shu.pos.dest_h = pUnit->m_fHeight;
m_pGame->query_handle_unit(&shu);
if(IsPlayer() && !(CanRanged() && m_ani_spell.IsReady()))
{//
float f_max = 0.60f;
if(m_ani_spell.IsReady() || CanRanged())
{
f_max = 0.88f;
}
float f_n = rnd();
if(f_n>f_max)
{
shu.action = GSACT_SPELL;
if(f_n>0.90 && !m_ani_spell.IsReady() && !CanRanged())
{
uint16 skills[] = {2051,2052,2053,2054,2055};
shu.uid_action_type = skills[uint16(float(rand())/(RAND_MAX+1)*5)];
}
else
{
uint16 skills[] = {1001,1002,2003,1004,2005};
shu.uid_action_type = skills[uint16(float(rand())/(RAND_MAX+1)*5)];
}
shu.uid = GetID();
shu.uid_obj = pUnit->GetID();
shu.pos.src_x = m_FlatX;
shu.pos.src_y = m_FlatY;
shu.pos.src_h = m_fHeight;
shu.pos.dest_x = pUnit->m_FlatX;
shu.pos.dest_y = pUnit->m_FlatY;
shu.pos.dest_h = pUnit->m_fHeight;
m_pGame->query_handle_unit(&shu);
}
}
}
}
void Game_Unit::query_spell(float x, float y, uint32 uid_spell)
{
Game_Unit* pUnit_obj = get_aim_unit();
if(uid_spell>2050)
{
pUnit_obj = this;
}
if(pUnit_obj==NULL || pUnit_obj->is_death())
return;
DWORD dwTime = Sys_GetTime();
if(dwTime-m_map_query_holder["spell"]>500)
{
m_map_query_holder["spell"] = dwTime;
m_map_query_holder["melee"] = dwTime;
m_map_query_holder["goto"] = dwTime;
//if(CanSpell())
{
STRUCT_HANDLE_UNIT shu;
shu.action = GSACT_SPELL;
shu.uid_action_type = uid_spell;
shu.uid = GetID();
shu.uid_obj = pUnit_obj->GetID();
shu.pos.src_x = m_FlatX;
shu.pos.src_y = m_FlatY;
shu.pos.src_h = m_fHeight;
shu.pos.dest_x = pUnit_obj->m_FlatX;
shu.pos.dest_y = pUnit_obj->m_FlatY;
shu.pos.dest_h = pUnit_obj->m_fHeight;
m_pGame->query_handle_unit(&shu);
}
}
}
BOOL Game_Unit::CanGoto()
{
if(is_death())
return FALSE;
if(is_wait() || is_walk() || is_fidget())
return TRUE;
// if(is_block() || is_flinch())
// {
// if(rnd()<0.2 && m_pAnimation->GetFinishPercent()>30 || m_pAnimation->GetFinishPercent()>70)//%50机会可以挣脱
// {
// return TRUE;
// }
// }
// if(is_melee() || is_ranged() || is_spell())
// {
// if(m_pAnimation->GetFinishPercent()>90)//动作完成80%
// {
// return TRUE;
// }
// }
return FALSE;
}
BOOL Game_Unit::CanMelee()
{
if(!m_ani_melee.IsReady())
return FALSE;
if(is_melee()
|| is_flinch()
|| is_death()
|| is_spell())
return FALSE;
return TRUE;
}
BOOL Game_Unit::CanSpell()
{
if(!m_ani_spell.IsReady())
return FALSE;
DWORD dwTime = Sys_GetTime() - m_map_query_holder["spell"];
if((CanRanged() || !IsPlayer()))
{
if(dwTime<3000)
return FALSE;
}
else if(dwTime<1700)
return FALSE;
if(is_melee()
|| is_flinch()
|| is_death()
|| is_spell())
return FALSE;
return TRUE;
}
BOOL Game_Unit::CanFlinch()
{
if(!m_ani_flinch.IsReady())
return FALSE;
// if(is_melee())
// {
// if(m_ani_melee.GetFinishPercent()>60)
// return TRUE;
// return FALSE;
// }
if(is_flinch()
|| is_death())
return FALSE;
return TRUE;
}
void Game_Unit::add_effect_tip(const char* str_tip, D3DCOLOR color, float scale, FLAG flag)
{
if(m_pWorld&&m_pWorld->GetGsEngine())
{
UNIT_EFFECT_TIP* p_uet = new UNIT_EFFECT_TIP;
p_uet->pos_x = m_fPosX;
p_uet->pos_y = m_fPosY-50;
p_uet->pos_h = 0;
p_uet->flag = flag;
p_uet->alpha = 1.0f;
p_uet->tex.SetGsEngine(m_pWorld->GetGsEngine());
p_uet->tex.CreateEx(100, 50);
p_uet->scale = scale;
GRECT rc(0,0,100,30);
p_uet->tex.DrawText(NULL,
str_tip,
&rc,
100,
30,
DT_CENTER|DT_SINGLELINE|DT_VCENTER,
color
);
p_uet->tex.SetBasePoint(GPOINT(50,25));
m_list_effect_tip.push_back(p_uet);
}
}
void Game_Unit::query_update_state()
{
//上报位置
if(m_is_locate_control==FALSE)
{
if(!IsPlayer())
return;
}
STRUCT_UPDATE_STATE sus;
sus.uid = m_id;
sus.src_x = m_FlatX;
sus.src_y = m_FlatY;
sus.src_h = m_fHeight;
sus.face_to = GetFaceToDegree();
m_pGame->query_update_state(&sus);
}
void Game_Unit::add_effect_specific(STRUCT_EFFECT_SPECIFIC &uae)
{
m_list_effect_specific.push_back(uae);
}
void Game_Unit::add_magic_effect_specific(STRUCT_EFFECT_SPECIFIC &uae)
{
if(uae.uid_action_type>=2000)
{//过程魔法
PARTICLE_MAGIC* ppm = new PARTICLE_MAGIC;
ppm->pos_x = m_FlatX;
ppm->pos_y = m_FlatY;
ppm->pos_h = 0;
ppm->life = 100;
ppm->angle = GetAnimation()->GetAngleFaceTo();
ppm->ses = uae;
ppm->speed = 700;
ppm->particles.SetGsEngine(m_pWorld->GetGsEngine());
ppm->particles.Create(g_get_particle_magic_res(uae.uid_action_type).c_str());
ppm->p_ani=NULL;
m_list_particle_magic.push_back(ppm);
}
else if(uae.uid_action_type>=100)
{//远程攻击
PARTICLE_MAGIC* ppm = new PARTICLE_MAGIC;
ppm->pos_x = m_FlatX;
ppm->pos_y = m_FlatY;
ppm->pos_h = 0;
ppm->life = 100;
ppm->angle = GetAnimation()->GetAngleFaceTo();
ppm->ses = uae;
ppm->speed = 1200;
ppm->particles.SetGsEngine(m_pWorld->GetGsEngine());
ppm->particles.Create(g_get_particle_magic_res(uae.uid_action_type).c_str());
ppm->p_ani = &m_ani_arrow;
m_list_particle_magic.push_back(ppm);
}
}
HRESULT Game_Unit::update_name()
{
// m_tex_status.Clear(0);
D3DCOLOR color;
// if(color==0)
{
Game_Unit* pPlayer = m_pGame->GetControlUnit();
if(pPlayer && pPlayer!=this)
{
int lv = base_level - pPlayer->base_level;
if(lv>5)
{
color = RGBA_MAKE(255,0,205,255);
}
else if(lv>2)
{
color = RGBA_MAKE(255,0,100,255);
}
else
{
color = RGBA_MAKE(200,0,10,255);
}
}
else
{
color = RGBA_MAKE(0,255,255,255);
}
}
GRECT rc(0,0,200,50);
return m_tex_status.DrawText(NULL,
m_str_name.c_str(),
&rc,
rc.width(),
rc.height(),
DT_CENTER|DT_SINGLELINE|DT_VCENTER,
color,
RGBA_MAKE(0,0,0,0)
);
}
HRESULT Game_Unit::update_status()
{
HRESULT hr;
//life
GRECT rc(50,36,150,40);
hr = m_tex_status.Clear(RGBA_MAKE(100, 50, 50, 70), &rc);
int len;
if(base_life>0)
{
len = 50+100.0f*life/base_life;
if(len<50)
len=50;
if(len>150)
len=150;
rc = GRECT(50, 36, len, 40);
hr = m_tex_status.Clear(RGBA_MAKE(255, 0, 0, 255), &rc);
}
//mana
rc = GRECT(50, 41, 150, 45);
hr = m_tex_status.Clear(RGBA_MAKE(50, 50, 100, 70), &rc);
if(base_mana>0)
{
len = 50+100.0f*mana/base_mana;
if(len<50)
len=50;
if(len>150)
len=150;
rc = GRECT(50, 41, len, 45);
hr = m_tex_status.Clear(RGBA_MAKE(0, 0, 200, 255), &rc);
}
return hr;
}
Game_Unit* Game_Unit::get_aim_unit()
{
return (Game_Unit*)m_pWorld->GetObject(m_aim_unit);
}
void Game_Unit::add_effect_ani(const char *strAni)
{
// if(std::string(str_tip)!="miss")
// {
GSANI* pAni = new GSANI;
pAni->SetGsEngine(m_pWorld->GetGsEngine());
pAni->Create(strAni);//"animation\\spell\\lighting.txg");
//pAni->Create("animation\\txg\\eff005");
pAni->Play(GS_ANI_PLAY_LOOP, TRUE, 1);
m_list_ani_effect.push_back(pAni);
// }
}
void Game_Unit::add_effect_sound(const char *strSound)
{
// if(m_pWorld && m_pWorld->GetGsEngine())
{
CGsSound* pSound = NULL;
if(m_sex>0)
{
char str[255];
int len = strlen(strSound);
if(strSound[len-4]=='.')
{
strcpy(str, strSound);
str[len-4]=0;
sprintf(str, "%s_%d%s", str, m_sex, strSound+len-4);
// m_pGame->add_game_msg(RGBA_MAKE(0,255,255,255), str);
}
else
{
sprintf(str, "%s_%d", str, m_sex);
}
pSound = m_pWorld->GetGsEngine()->FindSound(str);
}
if(pSound==NULL)
pSound = m_pWorld->GetGsEngine()->FindSound(strSound);
if(pSound)
{
pSound->Play();
m_list_sound.push_back(pSound);
}
}
}
void Game_Unit::SetSpeekText(const char *strSpeek)
{
m_tex_speeking.Clear(0);
GRECT rc(0,0,500,30);
m_tex_speeking.DrawText(NULL,
strSpeek,
&rc,
rc.width(),
rc.height(),
DT_CENTER|DT_SINGLELINE|DT_VCENTER,
RGBA_MAKE(250,250,200,255),
RGBA_MAKE(100,0,200,100)
);
m_alpha_speeking = 1.0f;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -