添加特殊移动逻辑

This commit is contained in:
aozhiwei 2020-07-27 20:26:09 +08:00
parent eb46ffae0c
commit b87ab4089f
5 changed files with 93 additions and 28 deletions

View File

@ -134,6 +134,18 @@ void Human::Initialize()
float Human::GetSpeed() float Human::GetSpeed()
{ {
{
Buff* buff = GetBuffByEffectId(kBET_JumpTo);
if (buff) {
return buff->meta->param2;
}
}
{
Buff* buff = GetBuffByEffectId(kBET_Pull);
if (buff) {
return buff->meta->param2;
}
}
if (downed) { if (downed) {
return meta->i->move_speed3(); return meta->i->move_speed3();
} else { } else {
@ -1240,7 +1252,7 @@ void Human::DoSkill()
ResetSkill(); ResetSkill();
playing_skill = true; playing_skill = true;
last_use_skill_frameno_ = room->GetFrameNo(); last_use_skill_frameno_ = room->GetFrameNo();
#if 1 #if 0
skill_target_id = GetEntityUniId(); skill_target_id = GetEntityUniId();
#endif #endif
Entity* entity = room->GetEntityByUniId(skill_target_id); Entity* entity = room->GetEntityByUniId(skill_target_id);
@ -1854,30 +1866,59 @@ int Human::GetSkinConfigLv(int skin_id)
return itr != skin_configs.end() ? itr->second : 0; return itr != skin_configs.end() ? itr->second : 0;
} }
bool Human::HasSpecMove()
{
return GetBuffByEffectId(kBET_JumpTo) ||
GetBuffByEffectId(kBET_Pull);
}
void Human::_UpdateSpecMove()
{
if (!HasSpecMove()) {
return;
}
bool move_end = false;
float target_distance = target_pos.Distance(GetPos());
if (target_distance <= 0.000001f) {
move_end = true;
} else {
a8::Vec2 old_move_dir = move_dir;
move_dir = target_pos - GetPos();
move_dir.Normalize();
bool is_collision = false;
std::function<bool ()> old_on_move_collision = on_move_collision;
on_move_collision =
[&is_collision] () {
is_collision = true;
return false;
};
_UpdateMove(std::min((int)target_distance, (int)GetSpeed()));
on_move_collision = old_on_move_collision;
move_dir = old_move_dir;
target_distance = target_pos.Distance(GetPos());
if (is_collision || target_distance <= 1.0001f) {
move_end = true;
}
}
if (move_end) {
if (GetBuffByEffectId(kBET_JumpTo)) {
RemoveBuffByEffectId(kBET_JumpTo);
}
if (GetBuffByEffectId(kBET_Pull)) {
RemoveBuffByEffectId(kBET_Pull);
}
}
}
void Human::_UpdateMove(int speed) void Human::_UpdateMove(int speed)
{ {
#if 1
do { do {
int distance = std::min(5, speed); int distance = std::min(5, speed);
_InternalUpdateMove(distance); _InternalUpdateMove(distance);
speed -= distance; speed -= distance;
} while (speed > 0); } while (speed > 0);
#else
for (int i = 0; i < speed; ++i) {
a8::Vec2 old_pos = GetPos();
SetPos(GetPos() + move_dir);
if (IsCollisionInMapService()) {
SetPos(old_pos);
FindPathInMapService();
#if 0
if (rand() % 3 == 0) {
i += 1;
}
#endif
}
room->grid_service->MoveHuman(this);
}
#endif
} }
void Human::ChangeToRace(RaceType_e race, int level) void Human::ChangeToRace(RaceType_e race, int level)
@ -1972,6 +2013,15 @@ void Human::WinExp(Human* sender, int exp)
} }
} }
bool Human::IsEnemy(Human* hum)
{
if (room->GetRoomMode() == kZombieMode) {
return hum->GetRace() != GetRace();
} else {
return team_id != hum->team_id;
}
}
void Human::_InternalUpdateMove(float speed) void Human::_InternalUpdateMove(float speed)
{ {
float nx = move_dir.x * speed; float nx = move_dir.x * speed;
@ -3266,7 +3316,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
Entity* entity = room->GetEntityByUniId(skill_target_id); Entity* entity = room->GetEntityByUniId(skill_target_id);
if (entity && entity->IsEntityType(ET_Player)) { if (entity && entity->IsEntityType(ET_Player)) {
Human* hum = (Human*)entity; Human* hum = (Human*)entity;
if (hum->team_id != team_id) { if (IsEnemy(hum)) {
target_list.insert(hum); target_list.insert(hum);
} }
} }
@ -3304,10 +3354,10 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
( (
[this, &target_pos, &target_list] (Human* hum, bool& stop) [this, &target_pos, &target_list] (Human* hum, bool& stop)
{ {
if ((hum == this || hum->team_id != team_id) && if ((hum == this || this->IsEnemy(hum)) &&
hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) { hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) {
target_list.insert(hum); target_list.insert(hum);
} }
}); });
} }
break; break;
@ -3316,7 +3366,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
Entity* entity = room->GetEntityByUniId(skill_target_id); Entity* entity = room->GetEntityByUniId(skill_target_id);
if (entity && entity->IsEntityType(ET_Player)) { if (entity && entity->IsEntityType(ET_Player)) {
Human* hum = (Human*)entity; Human* hum = (Human*)entity;
if (hum->team_id != team_id) { if (IsEnemy(hum)) {
target_list.insert(hum); target_list.insert(hum);
} }
} }

View File

@ -281,6 +281,8 @@ class Human : public MoveableEntity
Entity* GetLastCollisionDoor() { return last_collision_door_; } Entity* GetLastCollisionDoor() { return last_collision_door_; }
void SetLastCollisionDoor(Entity* door) { last_collision_door_ = door; } void SetLastCollisionDoor(Entity* door) { last_collision_door_ = door; }
ObjectSyncFlags* GetObjectSyncFlags(int obj_uniid); ObjectSyncFlags* GetObjectSyncFlags(int obj_uniid);
bool HasSpecMove();
void _UpdateSpecMove();
void _UpdateMove(int speed); void _UpdateMove(int speed);
RaceType_e GetRace() { return race_; } RaceType_e GetRace() { return race_; }
void ChangeToRace(RaceType_e race, int level); void ChangeToRace(RaceType_e race, int level);
@ -288,6 +290,7 @@ class Human : public MoveableEntity
void WinExp(Human* sender, int exp); void WinExp(Human* sender, int exp);
HumanCar& GetCar() { return car_; } HumanCar& GetCar() { return car_; }
void DeadDrop(); void DeadDrop();
bool IsEnemy(Human* hum);
protected: protected:
void _InternalUpdateMove(float speed); void _InternalUpdateMove(float speed);

View File

@ -54,8 +54,12 @@ void Player::InternalUpdate(int delta_time)
if (poisoning) { if (poisoning) {
poisoning_time += delta_time; poisoning_time += delta_time;
} }
if (moving) { if (HasSpecMove()) {
UpdateMove(); _UpdateSpecMove();
} else {
if (moving) {
UpdateMove();
}
} }
if (room->GetFrameNo() % 2 == 0) { if (room->GetFrameNo() % 2 == 0) {
if (drop_weapon) { if (drop_weapon) {

View File

@ -2603,7 +2603,11 @@ void Room::AddPlayerPostProc(Player* hum)
RandRemoveAndroid(); RandRemoveAndroid();
} }
if (GetRoomMode() == kZombieMode) { if (GetRoomMode() == kZombieMode) {
#if 1
hum->ChangeToRace(kZombieRace, 3);
#else
hum->ChangeToRace(kHumanRace, 1); hum->ChangeToRace(kHumanRace, 1);
#endif
} }
#ifdef DEBUG #ifdef DEBUG
xtimer.AddRepeatTimerAndAttach xtimer.AddRepeatTimerAndAttach

View File

@ -136,8 +136,12 @@ void ZombieAI::UpdateAI()
} }
break; break;
} }
if (node_->moving) { if (hum->HasSpecMove()) {
DoMove(); hum->_UpdateSpecMove();
} else {
if (node_->moving) {
DoMove();
}
} }
} }