This commit is contained in:
aozhiwei 2023-03-28 18:49:27 +08:00
parent 5b98cb12c6
commit 034a42ed3e
4 changed files with 177 additions and 42 deletions

View File

@ -501,12 +501,73 @@ float Ability::GetAttrRuduce(int attr_id)
void Ability::GMDelBaseAttr(int type, int attr_id, int idx)
{
if (IsValidHumanAttr(attr_id)) {
if (type == 1) {
list_head* head = &std::get<1>(attr_abs_[attr_id]);
list_head* pos = nullptr;
list_head* next = nullptr;
int i = 0;
list_for_each_safe(pos, next, head) {
if (idx == -1 || idx == i) {
AttrAbs* e = list_entry(pos,
AttrAbs,
entry);
list_del_init(&e->entry);
delete e;
if (idx > -1) {
break;
}
}
++i;
}
RecalcAttrAbs(attr_id);
} else if (type == 2) {
list_head* head = &std::get<1>(attr_rate_[attr_id]);
list_head* pos = nullptr;
list_head* next = nullptr;
int i = 0;
list_for_each_safe(pos, next, head) {
if (idx == -1 || idx == i) {
AttrRate* e = list_entry(pos,
AttrRate,
entry);
list_del_init(&e->entry);
delete e;
if (idx > -1) {
break;
}
}
++i;
}
RecalcAttrRate(attr_id);
}
}
}
void Ability::GMClearBaseAttr(int type)
{
for (auto& tuple : attr_abs_) {
std::get<0>(tuple) = 0.0f;
while (!list_empty(&std::get<1>(tuple))) {
AttrAbs* e = list_first_entry(&std::get<1>(tuple),
AttrAbs,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
}
}
for (auto& tuple : attr_rate_) {
std::get<0>(tuple) = 0.0f;
while (!list_empty(&std::get<1>(tuple))) {
AttrRate* e = list_first_entry(&std::get<1>(tuple),
AttrRate,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
}
}
}
void Ability::GMDelGrowAttr(int type, int attr_id, int idx)
@ -516,7 +577,51 @@ void Ability::GMDelGrowAttr(int type, int attr_id, int idx)
void Ability::GMClearGrowAttr(int type)
{
for (auto& tuple : attr_add_) {
std::get<0>(tuple) = 0.0f;
while (!list_empty(&std::get<1>(tuple))) {
AttrAddition* e = list_first_entry(&std::get<1>(tuple),
AttrAddition,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
}
}
for (auto& tuple : attr_dec_) {
std::get<0>(tuple) = 0.0f;
while (!list_empty(&std::get<1>(tuple))) {
AttrRuduce* e = list_first_entry(&std::get<1>(tuple),
AttrRuduce,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
}
}
for (auto& tuple : vattr_add_) {
std::get<0>(tuple) = 0.0f;
while (!list_empty(&std::get<1>(tuple))) {
AttrAddition* e = list_first_entry(&std::get<1>(tuple),
AttrAddition,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
}
}
for (auto& tuple : vattr_dec_) {
std::get<0>(tuple) = 0.0f;
while (!list_empty(&std::get<1>(tuple))) {
AttrRuduce* e = list_first_entry(&std::get<1>(tuple),
AttrRuduce,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
}
}
}
std::vector<std::string> Ability::GMShowAttrs()

View File

@ -167,60 +167,83 @@ void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg)
}
}
} else if (cmd == "add_base_attr") {
Creature* target = nullptr;
int type = 0;
int attr_id = 0;
float value = 0;
if (target) {
if (type == 1) {
target->GetAbility()->AddAttrAbs(attr_id, value);
} else {
target->GetAbility()->AddAttrRate(attr_id, value);
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") {
Creature* target = nullptr;
int type = 0;
int attr_id = 0;
int idx = 0;
if (target) {
target->GetAbility()->GMDelBaseAttr(type, attr_id, idx);
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") {
Creature* target = nullptr;
int type = 0;
if (target) {
target->GetAbility()->GMClearBaseAttr(type);
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") {
Creature* target = nullptr;
int type = 0;
int attr_id = 0;
float value = 0;
if (target) {
if (type == 1) {
target->GetAbility()->AddAttrAddition(attr_id, value);
} else {
target->GetAbility()->AddAttrRuduce(attr_id, value);
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") {
Creature* target = nullptr;
int type = 0;
int attr_id = 0;
int idx = 0;
if (target) {
target->GetAbility()->GMDelGrowAttr(type, attr_id, idx);
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") {
Creature* target = nullptr;
int type = 0;
if (target) {
target->GetAbility()->GMClearGrowAttr(type);
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") {
Creature* target = nullptr;
if (target) {
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()->GMShowAttrs();
}
}
} else if (cmd == "reset_skill" && cmds.size() >= 2) {
int skill_id = a8::XValue(cmds[1]);

View File

@ -3532,3 +3532,9 @@ Team* Room::GetTeam(int team_id)
auto itr = team_hash_.find(team_id);
return itr != team_hash_.end() ? itr->second : nullptr;
}
Creature* Room::GetCreatureByUniId(int uniid)
{
Entity* e = GetEntityByUniId(uniid);
return e && e->IsCreature(this) ? (Creature*)e : nullptr;
}

View File

@ -109,6 +109,7 @@ public:
Player* GetPlayerByAccountId(const std::string& accountid);
Player* GetPlayerByUniId(int uniid);
Entity* GetEntityByUniId(int uniid);
Creature* GetCreatureByUniId(int uniid);
Human* GetHumanByUniId(int uniid);
int GetRealPlayerNum() { return accountid_hash_.size();}
void OnEnterNewWave(int wave);