game2006/server/gameserver/commands.cc
aozhiwei 84b4dc80e9 1
2024-04-12 14:39:56 +08:00

469 lines
17 KiB
C++

#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 "mapinstance.h"
#include "team.h"
#include "loot.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 MYDEBUG
return;
#endif
std::vector<std::string> 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);
{
glm::vec3 center = GetPos().ToGlmVec3();
room->map_instance->Scale(center);
glm::vec3 point;
bool ok = false;
for (int i = 0; i < 10; ++i) {
ok = room->map_instance->FindConnectableNearestPoint(center, 1.0f + 10 * i, point);
if (ok) {
break;
}
}
if (ok) {
room->map_instance->UnScale(point);
GetMutablePos().FromGlmVec3(point);
room->grid_service->MoveCreature(this);
}
}
} 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,
0,
0);
} else if (cmd == "stop_world") {
room->stop_world = true;
} else if (cmd == "start_world") {
room->stop_world = false;
} else if (cmd == "chiji") {
#if MYDEBUG
if (room->IsMobaModeRoom()) {
while (GetTeam()->GetKillCount() <100) {
GetTeam()->IncKillCount();
}
if (!room->moba_over_timer.expired()) {
room->xtimer.ModifyTime(room->moba_over_timer, 0);
}
} else {
room->debug_params[119] = 1;
room->xtimer.SetTimeoutEx
(1,
[this] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
room->GetIncubator()->ShowHand();
}
},
&xtimer_attacher);
}
#endif
} else if (cmd == "disable_gas_damage") {
#if MYDEBUG
room->debug_params[120] = 1;
room->xtimer.SetTimeoutEx
(SERVER_FRAME_RATE * 60 * 10,
[this] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
room->debug_params[120] = 0;
}
},
&xtimer_attacher);
#endif
} 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,
0,
0);
}
} 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<int> mons = std::vector<int>{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()->GetAttr(kHVAT_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 == "delbuff" && cmds.size() >= 2) {
int buff_id = a8::XValue(cmds[1]);
RemoveBuffById(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 == "findhero" && cmds.size() >= 2) {
int hero_id = a8::XValue(cmds[1]);
bool found = false;
room->TraverseHumanList
(
[this, hero_id, &found] (Human* hum) -> bool
{
if (!hum->dead && hum->GetHeroMeta()->id() == hero_id && GetTeam() != hum->GetTeam()) {
hum->GetMovement()->ClearPath();
hum->GetMutablePos().FromGlmVec3(GetPos().ToGlmVec3());
room->grid_service->MoveCreature(hum);
found = true;
return false;
}
return true;
});
if (!found) {
SendDebugMsg(a8::Format("not found", {}));
}
} else if (cmd == "find_teammate") {
GetTeam()->TraverseMembers
(
[this] (Human* hum) -> bool
{
a8::SetBitFlag(hum->status, CS_NoDie);
hum->GetMovement()->ClearPath();
hum->GetMutablePos().FromGlmVec3(GetPos().ToGlmVec3());
room->grid_service->MoveCreature(hum);
return true;
});
} 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 attr_val = GetAbility()->GetAttr(attr_id);
SendDebugMsg(a8::Format("attr_id:%d attr_val:%f", {attr_id, attr_val}));
} else if (cmd == "bufflist") {
SendDebugMsg(DebugOutBuffList());
} else if (cmd == "throwitem_test") {
Human* target = nullptr;
room->TraverseHumanList
(
[this] (Human* hum) mutable
{
if (hum->IsAndroid()) {
std::vector<int> present_items{30202, 30201, 30301, 30203, 30207, 30208, 30209, 30210, 30204, 30205, 30206, 30302, 30303};
for (int item_id : present_items) {
hum->GMAddItem(item_id, 10);
}
}
return true;
});
} else if (cmd == "next_raid") {
#if MYDEBUG
room->GetAirRaid()->NextRaid();
#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 == "nodie") {
a8::SetBitFlag(status, CS_NoDie);
} 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_attr") {
if (cmds.size() > 3) {
Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this :
room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt());
int attr_id = a8::XValue(cmds[2]);
float value = a8::XValue(cmds[3]).GetDouble();
if (target) {
auto handle = target->GetAbility()->AddAttr(attr_id, value);
std::vector<std::string> strings = target->GetAbility()->GMShowAttrs();
for (auto& str : strings) {
SendDebugMsg("数值: " + str);
}
if (!handle.expired()) {
std::string source_name = "<-gm.self";
auto cb = std::make_shared<std::function<std::string()>>
(
[source_name] () -> std::string
{
return source_name;
});
target->GetAbility()->SetSource(handle, cb);
}
}
}
} else if (cmd == "del_attr") {
if (cmds.size() > 3) {
Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this :
room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt());
int attr_id = a8::XValue(cmds[2]);
int idx = a8::XValue(cmds[3]);
if (target) {
target->GetAbility()->GMDelAttr(attr_id, idx);
std::vector<std::string> strings = target->GetAbility()->GMShowAttrs();
for (auto& str : strings) {
SendDebugMsg("数值: " + str);
}
}
}
} else if (cmd == "clear_attr") {
if (cmds.size() > 1) {
Creature* target = a8::XValue(cmds[1]).GetInt() <= 0 ? this :
room->GetCreatureByUniId(a8::XValue(cmds[1]).GetInt());
if (target) {
target->GetAbility()->GMClearAttr();
std::vector<std::string> strings = target->GetAbility()->GMShowAttrs();
for (auto& str : strings) {
SendDebugMsg("数值: " + str);
}
}
}
} 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<std::string> 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);
Creature* master = nullptr;
if (cmds.size() >= 2) {
hero_meta = mt::Hero::GetById(a8::XValue(cmds[1]));
}
if (cmds.size() >= 3) {
master = this;
}
if (hero_meta) {
Hero* hero = room->CreateHero
(master,
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);
#if 0
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);
}
}
#endif
}
} 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);
} else if (cmd == "fast_forward") {
room->GMFastForward();
} else if (cmd == "last_pickup") {
#ifdef MYDEBUG
SendDebugMsg(a8::Format("拾取道具: 距离当前时间(毫秒):%d 数量:%d",
{
(room->GetFrameNo() - last_interaction_frameno_) * FRAME_RATE_MS,
last_interaction_objids_.size()
}));
SendDebugMsg("道具拾取: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
for (int obj_uniid : last_interaction_objids_) {
std::string obj_type = "?";
std::string obj_name = "?";
int item_id = 0;
int entity_type = 0;
Entity* entity = room->GetEntityByUniId(obj_uniid);
if (entity) {
entity_type = entity->GetEntityType();
switch (entity->GetEntityType()) {
case ET_Loot:
{
item_id = ((Loot*)entity)->item_id;
}
break;
default:
{
}
break;
}
}
SendDebugMsg(a8::Format("拾取道具: obj_uniid:%d item_id:%s",
{
obj_uniid,
item_id,
}));
#endif
}
SendDebugMsg("道具拾取: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
} else if (cmd == "winexp" && cmds.size() >= 1) {
float exp = a8::XValue(cmds[1]).GetDouble();
if (exp > 0) {
WinExp(exp);
}
std::vector<std::string> strings = GetAbility()->GMShowAttrs();
for (auto& str : strings) {
SendDebugMsg("数值: " + str);
}
} else if (cmd == "findpath" && cmds.size() >= 3) {
float x = a8::XValue(cmds[1]).GetDouble();
float y = a8::XValue(cmds[2]).GetDouble();
float z = a8::XValue(cmds[3]).GetDouble();
GetMovement()->FindPath(glm::vec3(x, y, z), 10);
}
#ifdef MYDEBUG
a8::XPrintf("exec_cmd:%s\n", {cmd});
#endif
}