This commit is contained in:
aozhiwei 2021-05-10 16:44:06 +08:00
parent 9376761336
commit 88f9102ea2
3 changed files with 97 additions and 61 deletions

View File

@ -1637,7 +1637,7 @@ void Creature::SlaveOnRemove(Entity* slave)
void Creature::RemoveSurplusHero(int buff_id, int id, int num) void Creature::RemoveSurplusHero(int buff_id, int id, int num)
{ {
if (slave_heros_.size() >= num) { if (slave_heros_.size() >= num && num > 0) {
std::vector<Hero*> matched_heros; std::vector<Hero*> matched_heros;
for (auto& itr : slave_heros_) { for (auto& itr : slave_heros_) {
if (std::get<0>(itr) == buff_id && if (std::get<0>(itr) == buff_id &&
@ -1645,7 +1645,7 @@ void Creature::RemoveSurplusHero(int buff_id, int id, int num)
matched_heros.push_back(std::get<1>(itr)); matched_heros.push_back(std::get<1>(itr));
} }
} }
if (matched_heros.size() >= num) { while (matched_heros.size() >= num) {
} }
} }
@ -1653,7 +1653,7 @@ void Creature::RemoveSurplusHero(int buff_id, int id, int num)
void Creature::RemoveSurplusObstacle(int buff_id, int id, int num) void Creature::RemoveSurplusObstacle(int buff_id, int id, int num)
{ {
if (slave_things_.size() >= num) { if (slave_things_.size() >= num && num > 0) {
std::vector<RoomObstacle*> matched_things; std::vector<RoomObstacle*> matched_things;
for (auto& itr : slave_things_) { for (auto& itr : slave_things_) {
if (std::get<0>(itr) == buff_id && if (std::get<0>(itr) == buff_id &&
@ -1661,7 +1661,7 @@ void Creature::RemoveSurplusObstacle(int buff_id, int id, int num)
matched_things.push_back(std::get<1>(itr)); matched_things.push_back(std::get<1>(itr));
} }
} }
if (matched_things.size() >= num) { while (matched_things.size() >= num) {
} }
} }

View File

@ -3529,72 +3529,108 @@ void Human::GMAddItem(int item_id, int item_num)
if (!item_meta) { if (!item_meta) {
return; return;
} }
if (item_meta->i->_inventory_slot() >= 0 && if (item_meta->i->equip_type() == EQUIP_TYPE_WEAPON) {
item_meta->i->_inventory_slot() < IS_END) { if (item_meta->i->equip_subtype() == 1) {
if (GetInventory(item_meta->i->_inventory_slot()) >= if (default_weapon.weapon_id != weapons[0].weapon_id) {
GetVolume(item_meta->i->_inventory_slot()) } else {
) { weapons[0].weapon_idx = 0;
/* weapons[0].weapon_id = item_id;
cs::SMPickup notifymsg; weapons[0].weapon_lv = std::max(1, 1);
notifymsg.set_error_code(1); weapons[0].ammo = 0;
SendNotifyMsg(notifymsg); weapons[0].meta = item_meta;
*/ weapons[0].Recalc();
return;
}
int add_num = GetVolume(item_meta->i->_inventory_slot()) -
GetInventory(item_meta->i->_inventory_slot());
add_num = std::min(item_num, add_num);
AddInventory(item_meta->i->_inventory_slot(), add_num);
switch (item_meta->i->_inventory_slot()) {
case IS_FRAG:
case IS_SMOKE:
{
Weapon* weapon = &weapons[SPEC1_SLOT_BEGIN +
(item_meta->i->_inventory_slot() - SPEC1_IS_BEGIN)
];
weapon->weapon_id = item_id;
weapon->weapon_lv = 1;
weapon->ammo += item_num;
weapon->meta = item_meta;
weapon->Recalc();
DecInventory(item_meta->i->_inventory_slot(), add_num);
} }
break; } else {
case IS_1XSCOPE: Weapon* weapon = nullptr;
case IS_2XSCOPE: if (weapons[GUN_SLOT1].weapon_id == 0) {
case IS_4XSCOPE: weapon = &weapons[GUN_SLOT1];
case IS_8XSCOPE: weapon->weapon_idx = GUN_SLOT1;
case IS_15XSCOPE: if (GetCurrWeapon() != &weapons[GUN_SLOT2] && !FreezeOperate()) {
{ SetCurrWeapon(&weapons[GUN_SLOT1]);
if (item_meta->i->_inventory_slot() - IS_1XSCOPE > curr_scope_idx) { }
curr_scope_idx = item_meta->i->_inventory_slot() - IS_1XSCOPE; } else if (weapons[GUN_SLOT2].weapon_id == 0) {
weapon = &weapons[GUN_SLOT2];
weapon->weapon_idx = GUN_SLOT2;
if (GetCurrWeapon() != &weapons[GUN_SLOT1] && !FreezeOperate()) {
SetCurrWeapon(&weapons[GUN_SLOT2]);
} }
} }
break; if (weapon) {
case IS_POSION_GAS_BOMB:
case IS_MOLOTOR_COCKTAIL:
case IS_TRAP:
case IS_MINE:
{
Weapon* weapon = &weapons[SPEC2_SLOT_BEGIN +
(item_meta->i->_inventory_slot() - SPEC2_IS_BEGIN)
];
weapon->weapon_id = item_id; weapon->weapon_id = item_id;
weapon->weapon_lv = 1; weapon->weapon_lv = std::max(1, 1);
weapon->ammo += item_num; weapon->ammo = 0;
weapon->meta = item_meta; weapon->meta = item_meta;
weapon->Recalc(); weapon->Recalc();
DecInventory(item_meta->i->_inventory_slot(), add_num);
} }
break; }
default: } else {
{ if (item_meta->i->_inventory_slot() >= 0 &&
item_meta->i->_inventory_slot() < IS_END) {
if (GetInventory(item_meta->i->_inventory_slot()) >=
GetVolume(item_meta->i->_inventory_slot())
) {
/*
cs::SMPickup notifymsg;
notifymsg.set_error_code(1);
SendNotifyMsg(notifymsg);
*/
return;
}
int add_num = GetVolume(item_meta->i->_inventory_slot()) -
GetInventory(item_meta->i->_inventory_slot());
add_num = std::min(item_num, add_num);
AddInventory(item_meta->i->_inventory_slot(), add_num);
switch (item_meta->i->_inventory_slot()) {
case IS_FRAG:
case IS_SMOKE:
{
Weapon* weapon = &weapons[SPEC1_SLOT_BEGIN +
(item_meta->i->_inventory_slot() - SPEC1_IS_BEGIN)
];
weapon->weapon_id = item_id;
weapon->weapon_lv = 1;
weapon->ammo += item_num;
weapon->meta = item_meta;
weapon->Recalc();
DecInventory(item_meta->i->_inventory_slot(), add_num);
}
break;
case IS_1XSCOPE:
case IS_2XSCOPE:
case IS_4XSCOPE:
case IS_8XSCOPE:
case IS_15XSCOPE:
{
if (item_meta->i->_inventory_slot() - IS_1XSCOPE > curr_scope_idx) {
curr_scope_idx = item_meta->i->_inventory_slot() - IS_1XSCOPE;
}
}
break;
case IS_POSION_GAS_BOMB:
case IS_MOLOTOR_COCKTAIL:
case IS_TRAP:
case IS_MINE:
{
Weapon* weapon = &weapons[SPEC2_SLOT_BEGIN +
(item_meta->i->_inventory_slot() - SPEC2_IS_BEGIN)
];
weapon->weapon_id = item_id;
weapon->weapon_lv = 1;
weapon->ammo += item_num;
weapon->meta = item_meta;
weapon->Recalc();
DecInventory(item_meta->i->_inventory_slot(), add_num);
}
break;
default:
{
#if 0 #if 0
abort(); abort();
#endif #endif
}
break;
} }
break;
} }
} }
need_sync_active_player = true; need_sync_active_player = true;

View File

@ -1605,7 +1605,7 @@ void Player::UpdateAiming()
abort(); abort();
} else if (power_idx + 1 == p_weapon->meta->power_charge.size()) { } else if (power_idx + 1 == p_weapon->meta->power_charge.size()) {
} else { } else {
long long passed_time = room->GetFrameNo() - aiming_frameno * FRAME_RATE_MS; long long passed_time = (room->GetFrameNo() - aiming_frameno) * FRAME_RATE_MS;
if (passed_time >= std::get<0>(p_weapon->meta->power_charge[power_idx + 1])) { if (passed_time >= std::get<0>(p_weapon->meta->power_charge[power_idx + 1])) {
++power_idx; ++power_idx;
RemoveBuffByEffectId(kBET_ShotCharge); RemoveBuffByEffectId(kBET_ShotCharge);