#include "precompile.h" #include "player.h" #include "room.h" #include "skill.h" #include "buff.h" #include "app.h" #include "ability.h" #include "movement.h" #include "android.h" #include "airraid.h" #include "car.h" #include "incubator.h" #include "cs_proto.pb.h" #include "mt/Equip.h" #include "mt/Text.h" #include "mt/Param.h" #include "mt/Buff.h" #include "mt/Robot.h" #include "mt/Hero.h" void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg) { #ifndef DEBUG return; #endif std::vector cmds; a8::Split(msg.cmd().c_str(), cmds, ' '); if (cmds.empty()) { return; } std::string cmd = cmds[0]; if (cmd == "gps") { SendDebugMsg(a8::Format("gps: %f,%f,%f", {GetPos().GetX(), GetPos().GetY(), GetPos().GetZ()})); } else if (cmd == "info") { SendDebugMsg(a8::Format("attack_dir: %f,%f,%f", {GetAttackDir().x, GetAttackDir().y, GetAttackDir().z})); } else if (cmd == "goto" && cmds.size() >= 3) { float x = a8::XValue(cmds[1]).GetDouble(); float y = a8::XValue(cmds[2]).GetDouble(); float z = a8::XValue(cmds[3]).GetDouble(); GetMutablePos().FromGlmVec3(glm::vec3(x, y, z)); room->grid_service->MoveCreature(this); } else if (cmd == "setmode") { if (cmds.empty()) { App::Instance()->UnSetFlag(20); } else { if (cmds[1] == "peace") { App::Instance()->SetFlag(20); } else { App::Instance()->UnSetFlag(20); } } } else if (cmd == "additem" && cmds.size() >= 3) { int item_id = a8::XValue(cmds[1]); int item_num = a8::XValue(cmds[2]); GMAddItem(item_id, item_num); } else if (cmd == "infinite_bullet_mode") { room->SetInfiniteBulletMode(); } else if (cmd == "watchwar") { AsyncRequestWatchWar(false); } else if (cmd == "killself") { float dmg_out = 0; float dmg = GetMaxHP() + 10; DecHP(dmg, VP_Gas, TEXT("battle_server_killer_gas", "毒圈"), VW_Gas, VP_Gas, TEXT("battle_server_killer_gas", "毒圈"), dmg_out); } else if (cmd == "stop_world") { room->stop_world = true; } else if (cmd == "start_world") { room->stop_world = false; } else if (cmd == "add_hp") { if (cmds.size() > 1) { float hp = a8::XValue(cmds[1]).GetDouble(); AddHp(hp); } } else if (cmd == "dec_hp") { if (cmds.size() > 1) { float dmg_out = 0; float dmg = a8::XValue(cmds[1]).GetDouble(); DecHP(dmg, VP_Gas, TEXT("battle_server_killer_gas", "毒圈"), VW_Gas, VP_Gas, TEXT("battle_server_killer_gas", "毒圈"), dmg_out); } } else if (cmd == "add_shield") { if (cmds.size() > 1) { float hp = a8::XValue(cmds[1]).GetDouble(); AddEnergyShield(hp); } } else if (cmd == "shuaguai" && cmds.size() >= 3) { int hero_id = a8::XValue(cmds[1]); int hero_num = a8::XValue(cmds[2]); std::vector mons = std::vector{hero_id}; // 999 #if 1 #else room->ShuaMon(GetPos(), mons, 100); #endif } else if (cmd == "jiuyuan") { TryAddBuff(this, kRescuerBuffId); int downed_relive_time = mt::Param::GetIntParam("downed_relive_time") * 1000; downed_relive_time -= GetAbility()->GetAttrAbs(kHAT_RescueTime); downed_relive_time = std::max(0, downed_relive_time); downed_relive_time = 1000 * 30; StartAction( AT_Relive, downed_relive_time, room->GetFrameNo(), 0 ); } else if (cmd == "gps") { SendDebugMsg(a8::Format("gps:%f %f %f", {})); } else if (cmd == "addbuff" && cmds.size() >= 2) { int buff_id = a8::XValue(cmds[1]); const mt::Buff* buff_meta = mt::Buff::GetById(buff_id); if (buff_meta) { MustBeAddBuff(this, buff_id); } } else if (cmd == "findobj" && cmds.size() >= 2) { int obj_uniid = a8::XValue(cmds[1]); Entity* e = room->GetEntityByUniId(obj_uniid); if (e && e->IsEntityType(ET_Player)) { Human* hum = (Human*)e; hum->GetMovement()->ClearPath(); hum->GetMutablePos().FromGlmVec3(GetPos().ToGlmVec3()); room->grid_service->MoveCreature(hum); } } else if (cmd == "randomobj" && cmds.size() >= 2) { int weapon_id = a8::XValue(cmds[1]); Human* target = nullptr; room->TraverseHumanList ( [this, weapon_id, &target] (Human* hum) mutable { if (hum->IsAndroid() && !hum->dead && hum->team_id != team_id) { if (hum->AsAndroid()->robot_meta->weapon_id() == weapon_id) { target = hum; return false; } } return true; }); if (target) { target->GetMovement()->ClearPath(); target->GetMutablePos().FromGlmVec3(GetPos().ToGlmVec3()); room->grid_service->MoveCreature(target); } } else if (cmd == "getattr" && cmds.size() >= 2) { int attr_id = a8::XValue(cmds[1]); float abs_val = GetAbility()->GetAttrAbs(attr_id); float rate_val = GetAbility()->GetAttrRate(attr_id); SendDebugMsg(a8::Format("attr_id:%d abs_val:%f rate_val:%f", {attr_id, abs_val, rate_val})); } else if (cmd == "bufflist") { SendDebugMsg(DebugOutBuffList()); } else if (cmd == "set_inactive_time" && cmds.size() >= 2) { #if DEBUG App::Instance()->debug_params[1] = a8::XValue(cmds[1]); #endif } else if (cmd == "set_born_frameno_offset" && cmds.size() >= 2) { #if DEBUG App::Instance()->debug_params[118] = a8::XValue(cmds[1]); #endif } else if (cmd == "chiji") { #if DEBUG room->debug_params[119] = 1; #endif } else if (cmd == "airraid") { #if DEBUG room->debug_params[121] = 1; #endif } else if (cmd == "next_raid") { #if DEBUG room->debug_params[121] = 1; room->GetAirRaid()->NextRaid(); #endif } else if (cmd == "autodie") { #if DEBUG if (cmds.size() >= 2) { if (cmds[1] == "open") { App::Instance()->debug_params[120] = 1; } else if (cmds[1] == "close") { App::Instance()->debug_params.erase(120); } } else { App::Instance()->debug_params[120] = 1; } #endif } else if (cmd == "wudi") { int buff_uniid = TryAddBuff(this, 1005); if (buff_uniid != 0) { Buff* buff = GetBuffByUniId(buff_uniid); if (!buff->remover_timer.expired()) { room->xtimer.ModifyTime(buff->remover_timer, SERVER_FRAME_RATE * 10000); } } } else if (cmd == "drop_loot") { if (cmds.size() >= 2) { const mt::Equip* equip_meta = mt::Equip::GetById(a8::XValue(cmds[1])); if (equip_meta) { Position drop_pos = GetPos(); room->DropItem(drop_pos.ToGlmVec3(), equip_meta->id(), 1, 1); } } } else if (cmd == "add_base_attr") { if (cmds.size() > 4) { Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); int type = a8::XValue(cmds[2]); int attr_id = a8::XValue(cmds[3]); float value = a8::XValue(cmds[4]).GetDouble(); if (target) { if (type == 1) { target->GetAbility()->AddAttrAbs(attr_id, value); } else { target->GetAbility()->AddAttrRate(attr_id, value); } } } } else if (cmd == "del_base_attr") { if (cmds.size() > 4) { Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); int type = a8::XValue(cmds[2]); int attr_id = a8::XValue(cmds[3]); int idx = a8::XValue(cmds[4]); if (target) { target->GetAbility()->GMDelBaseAttr(type, attr_id, idx); } } } else if (cmd == "clear_base_attr") { if (cmds.size() > 1) { Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); int type = 0; if (target) { target->GetAbility()->GMClearBaseAttr(type); } } } else if (cmd == "add_grow_attr") { if (cmds.size() > 4) { Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); int type = a8::XValue(cmds[2]); int attr_id = a8::XValue(cmds[3]); float value = a8::XValue(cmds[4]).GetDouble(); if (target) { if (type == 1) { target->GetAbility()->AddAttrAddition(attr_id, value); } else { target->GetAbility()->AddAttrRuduce(attr_id, value); } } } } else if (cmd == "del_grow_attr") { if (cmds.size() > 4) { Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); int type = a8::XValue(cmds[2]); int attr_id = a8::XValue(cmds[3]); int idx = a8::XValue(cmds[4]); if (target) { target->GetAbility()->GMDelGrowAttr(type, attr_id, idx); } } } else if (cmd == "clear_grow_attr") { if (cmds.size() > 1) { Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); int type = 0; if (target) { target->GetAbility()->GMClearGrowAttr(type); } } } else if (cmd == "show_attrs") { if (cmds.size() > 1) { Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this : room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt()); int type = 0; if (target) { std::vector strings = target->GetAbility()->GMShowAttrs(); for (auto& str : strings) { SendDebugMsg("数值: " + str); } } } } else if (cmd == "reset_skill" && cmds.size() >= 2) { int skill_id = a8::XValue(cmds[1]); Skill* skill = GetSkill(skill_id); if (skill) { skill->Accelerate(-10000000); } } else if (cmd == "create_boss") { const mt::Hero* hero_meta = mt::Hero::GetById(60100); if (cmds.size() >= 2) { hero_meta = mt::Hero::GetById(a8::XValue(cmds[1])); } if (hero_meta) { Hero* hero = room->CreateHero (nullptr, hero_meta, GetPos().ToGlmVec3(), GlmHelper::UP, 666 ); } } else if (cmd == "create_car") { const mt::Equip* equip_meta = mt::Equip::GetById(30503); if (equip_meta) { int car_uniid = room->AllocUniid(); glm::vec3 pos = GetPos().ToGlmVec3(); Car* c = room->CreateCar(nullptr, car_uniid, equip_meta, pos, 0, nullptr); if (c) { #if 0 CarObject car; car.car_id = equip_meta->id(); car.pos = c->GetPos().ToGlmVec3(); room->car_hash_[c->GetUniId()] = car; #endif } } } else if (cmd == "use_skill") { if (cmds.size() >= 2 && GetCar() && GetCar()->IsDriver(this)) { int skill_id = a8::XValue(cmds[1]); Skill* skill = GetCar()->GetSkill(skill_id); Human* enemy = room->FindEnemy(this, 300); if (enemy && skill) { if (GetCar()->CanUseSkill(skill_id) && enemy->GetPos().Distance2D2(GetPos()) > 0.0001f) { glm::vec3 skill_dir = enemy->GetPos().ToGlmVec3() - GetPos().ToGlmVec3(); float skill_distance = GlmHelper::Norm(skill_dir); GlmHelper::Normalize(skill_dir); GetCar()->DoSkill(skill_id, enemy->GetUniId(), skill_dir, skill_distance); } } } } else if (cmd == "show_hand") { room->xtimer.SetTimeoutEx ( 1, [this] (int event, const a8::Args* args) { if (a8::TIMER_EXEC_EVENT == event) { room->GetIncubator()->ShowHand(); } }, &xtimer_attacher); } #ifdef DEBUG a8::XPrintf("exec_cmd:%s\n", {cmd}); #endif }