1
This commit is contained in:
parent
ef03b4c83a
commit
d097a6fd24
@ -426,6 +426,7 @@ const int NEXT_FRAME_TIMER = 2;
|
|||||||
const int MAX_WEAPON_NUM = 14;
|
const int MAX_WEAPON_NUM = 14;
|
||||||
const int MAX_SKIN_LV = 9;
|
const int MAX_SKIN_LV = 9;
|
||||||
|
|
||||||
|
const int GUN_SLOT0 = 0;
|
||||||
const int GUN_SLOT1 = 1;
|
const int GUN_SLOT1 = 1;
|
||||||
const int GUN_SLOT2 = 2;
|
const int GUN_SLOT2 = 2;
|
||||||
|
|
||||||
|
@ -3757,3 +3757,125 @@ void Human::ProcAddItemDto(AddItemDTO& dto)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Human::DropWeapon(int weapon_idx)
|
||||||
|
{
|
||||||
|
if (weapon_idx < 0 ||
|
||||||
|
weapon_idx >= weapons.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool drop_ok = false;
|
||||||
|
Weapon* weapon = &weapons[weapon_idx];
|
||||||
|
int weapon_id = weapon->weapon_id;
|
||||||
|
int weapon_lv = weapon->weapon_lv;
|
||||||
|
int weapon_ammo = weapon->ammo;
|
||||||
|
MetaData::Equip* weapon_meta = weapon->meta;
|
||||||
|
if (weapon->weapon_id != 0) {
|
||||||
|
switch (weapon->weapon_idx) {
|
||||||
|
case GUN_SLOT0:
|
||||||
|
{
|
||||||
|
if (weapon->weapon_id != default_weapon.weapon_id) {
|
||||||
|
drop_ok = true;
|
||||||
|
*weapon = default_weapon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GUN_SLOT1:
|
||||||
|
{
|
||||||
|
drop_ok = true;
|
||||||
|
*weapon = Weapon();
|
||||||
|
weapon->weapon_idx = weapon_idx;
|
||||||
|
if (GetCurrWeapon() == weapon) {
|
||||||
|
if (weapons[GUN_SLOT2].weapon_id != 0) {
|
||||||
|
SetCurrWeapon(&weapons[GUN_SLOT2]);
|
||||||
|
} else {
|
||||||
|
SetCurrWeapon(&weapons[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GUN_SLOT2:
|
||||||
|
{
|
||||||
|
drop_ok = true;
|
||||||
|
*weapon = Weapon();
|
||||||
|
weapon->weapon_idx = weapon_idx;
|
||||||
|
if (GetCurrWeapon() == weapon) {
|
||||||
|
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
||||||
|
SetCurrWeapon(&weapons[GUN_SLOT1]);
|
||||||
|
} else {
|
||||||
|
SetCurrWeapon(&weapons[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FRAG_SLOT:
|
||||||
|
{
|
||||||
|
drop_ok = true;
|
||||||
|
*weapon = Weapon();
|
||||||
|
weapon->weapon_idx = weapon_idx;
|
||||||
|
if (GetCurrWeapon() == weapon) {
|
||||||
|
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
||||||
|
SetCurrWeapon(&weapons[GUN_SLOT1]);
|
||||||
|
} else if (weapons[GUN_SLOT2].weapon_id != 0) {
|
||||||
|
SetCurrWeapon(&weapons[GUN_SLOT2]);
|
||||||
|
} else {
|
||||||
|
SetCurrWeapon(&weapons[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SMOKE_SLOT:
|
||||||
|
{
|
||||||
|
drop_ok = true;
|
||||||
|
*weapon = Weapon();
|
||||||
|
weapon->weapon_idx = weapon_idx;
|
||||||
|
if (GetCurrWeapon() == weapon) {
|
||||||
|
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
||||||
|
SetCurrWeapon(&weapons[GUN_SLOT1]);
|
||||||
|
} else if (weapons[GUN_SLOT2].weapon_id != 0) {
|
||||||
|
SetCurrWeapon(&weapons[GUN_SLOT2]);
|
||||||
|
} else {
|
||||||
|
SetCurrWeapon(&weapons[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (drop_ok) {
|
||||||
|
{
|
||||||
|
a8::Vec2 dir = a8::Vec2::UP;
|
||||||
|
dir.Rotate(a8::RandAngle());
|
||||||
|
room->CreateLoot(weapon_id, GetPos() + dir * (40 + rand() % 50), 1, weapon_lv);
|
||||||
|
}
|
||||||
|
if (weapon_ammo > 0) {
|
||||||
|
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(weapon_meta->i->use_bullet());
|
||||||
|
if (bullet_meta && bullet_meta->i->_inventory_slot() > 0) {
|
||||||
|
int volume = GetVolume(bullet_meta->i->_inventory_slot());
|
||||||
|
int inventory = GetInventory(bullet_meta->i->_inventory_slot());
|
||||||
|
int add_inventory = std::min(weapon_ammo, volume - std::min(volume, inventory));
|
||||||
|
if (add_inventory > 0 &&
|
||||||
|
!(weapon_idx == FRAG_SLOT || weapon_idx == SMOKE_SLOT)) {
|
||||||
|
AddInventory(bullet_meta->i->_inventory_slot(), add_inventory);
|
||||||
|
}
|
||||||
|
int drop_num = weapon_ammo - add_inventory;
|
||||||
|
if (drop_num > 0) {
|
||||||
|
a8::Vec2 drop_dir = a8::Vec2::UP;
|
||||||
|
drop_dir.Rotate(a8::RandAngle());
|
||||||
|
a8::Vec2 drop_pos = GetPos() + drop_dir * (25 + rand() % 50);
|
||||||
|
if (bullet_meta->i->_inventory_slot() == IS_FRAG ||
|
||||||
|
bullet_meta->i->_inventory_slot() == IS_SMOKE) {
|
||||||
|
//只有手雷和烟雾弹会掉落
|
||||||
|
room->DropItem(drop_pos, bullet_meta->i->id(), drop_num, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
need_sync_active_player = true;
|
||||||
|
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -284,6 +284,7 @@ protected:
|
|||||||
Weapon* TakeonWeapon(MetaData::Equip* equip_meta);
|
Weapon* TakeonWeapon(MetaData::Equip* equip_meta);
|
||||||
void LootInteraction(Loot* entity);
|
void LootInteraction(Loot* entity);
|
||||||
void ProcAddItemDto(AddItemDTO& dto);
|
void ProcAddItemDto(AddItemDTO& dto);
|
||||||
|
void DropWeapon(int weapon_idx);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ClearFrameData();
|
void ClearFrameData();
|
||||||
|
@ -855,105 +855,7 @@ void Player::UpdateDropWeapon()
|
|||||||
drop_weapon_idx < weapons.size() &&
|
drop_weapon_idx < weapons.size() &&
|
||||||
!HasBuffEffect(kBET_Terminator) &&
|
!HasBuffEffect(kBET_Terminator) &&
|
||||||
!FreezeOperate()) {
|
!FreezeOperate()) {
|
||||||
bool drop_ok = false;
|
DropWeapon(drop_weapon_idx);
|
||||||
Weapon* weapon = &weapons[drop_weapon_idx];
|
|
||||||
int weapon_id = weapon->weapon_id;
|
|
||||||
int weapon_lv = weapon->weapon_lv;
|
|
||||||
int weapon_ammo = weapon->ammo;
|
|
||||||
MetaData::Equip* weapon_meta = weapon->meta;
|
|
||||||
if (weapon->weapon_id != 0) {
|
|
||||||
if (weapon->weapon_idx == 0) {
|
|
||||||
if (weapon->weapon_id != default_weapon.weapon_id) {
|
|
||||||
drop_ok = true;
|
|
||||||
*weapon = default_weapon;
|
|
||||||
}
|
|
||||||
} else if (weapon->weapon_idx == GUN_SLOT1) {
|
|
||||||
drop_ok = true;
|
|
||||||
*weapon = Weapon();
|
|
||||||
weapon->weapon_idx = drop_weapon_idx;
|
|
||||||
if (GetCurrWeapon() == weapon) {
|
|
||||||
if (weapons[GUN_SLOT2].weapon_id != 0) {
|
|
||||||
SetCurrWeapon(&weapons[GUN_SLOT2]);
|
|
||||||
} else {
|
|
||||||
SetCurrWeapon(&weapons[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (weapon->weapon_idx == GUN_SLOT2) {
|
|
||||||
drop_ok = true;
|
|
||||||
*weapon = Weapon();
|
|
||||||
weapon->weapon_idx = drop_weapon_idx;
|
|
||||||
if (GetCurrWeapon() == weapon) {
|
|
||||||
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
|
||||||
SetCurrWeapon(&weapons[GUN_SLOT1]);
|
|
||||||
} else {
|
|
||||||
SetCurrWeapon(&weapons[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (weapon->weapon_idx == FRAG_SLOT) {
|
|
||||||
drop_ok = true;
|
|
||||||
*weapon = Weapon();
|
|
||||||
weapon->weapon_idx = drop_weapon_idx;
|
|
||||||
if (GetCurrWeapon() == weapon) {
|
|
||||||
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
|
||||||
SetCurrWeapon(&weapons[GUN_SLOT1]);
|
|
||||||
} else if (weapons[GUN_SLOT2].weapon_id != 0) {
|
|
||||||
SetCurrWeapon(&weapons[GUN_SLOT2]);
|
|
||||||
} else {
|
|
||||||
SetCurrWeapon(&weapons[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (weapon->weapon_idx == SMOKE_SLOT) {
|
|
||||||
drop_ok = true;
|
|
||||||
*weapon = Weapon();
|
|
||||||
weapon->weapon_idx = drop_weapon_idx;
|
|
||||||
if (GetCurrWeapon() == weapon) {
|
|
||||||
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
|
||||||
SetCurrWeapon(&weapons[GUN_SLOT1]);
|
|
||||||
} else if (weapons[GUN_SLOT2].weapon_id != 0) {
|
|
||||||
SetCurrWeapon(&weapons[GUN_SLOT2]);
|
|
||||||
} else {
|
|
||||||
SetCurrWeapon(&weapons[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (drop_ok) {
|
|
||||||
if (drop_weapon_idx == 0 ||
|
|
||||||
drop_weapon_idx == GUN_SLOT1 ||
|
|
||||||
drop_weapon_idx == GUN_SLOT2 ||
|
|
||||||
drop_weapon_idx == FRAG_SLOT ||
|
|
||||||
drop_weapon_idx == SMOKE_SLOT
|
|
||||||
) {
|
|
||||||
a8::Vec2 dir = a8::Vec2::UP;
|
|
||||||
dir.Rotate(a8::RandAngle());
|
|
||||||
room->CreateLoot(weapon_id, GetPos() + dir * (40 + rand() % 50), 1, weapon_lv);
|
|
||||||
}
|
|
||||||
if (weapon_ammo > 0) {
|
|
||||||
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(weapon_meta->i->use_bullet());
|
|
||||||
if (bullet_meta && bullet_meta->i->_inventory_slot() > 0) {
|
|
||||||
int volume = GetVolume(bullet_meta->i->_inventory_slot());
|
|
||||||
int inventory = GetInventory(bullet_meta->i->_inventory_slot());
|
|
||||||
int add_inventory = std::min(weapon_ammo, volume - std::min(volume, inventory));
|
|
||||||
if (add_inventory > 0 &&
|
|
||||||
!(drop_weapon_idx == FRAG_SLOT || drop_weapon_idx == SMOKE_SLOT)) {
|
|
||||||
AddInventory(bullet_meta->i->_inventory_slot(), add_inventory);
|
|
||||||
}
|
|
||||||
int drop_num = weapon_ammo - add_inventory;
|
|
||||||
if (drop_num > 0) {
|
|
||||||
a8::Vec2 drop_dir = a8::Vec2::UP;
|
|
||||||
drop_dir.Rotate(a8::RandAngle());
|
|
||||||
a8::Vec2 drop_pos = GetPos() + drop_dir * (25 + rand() % 50);
|
|
||||||
if (bullet_meta->i->_inventory_slot() == IS_FRAG ||
|
|
||||||
bullet_meta->i->_inventory_slot() == IS_SMOKE) {
|
|
||||||
//只有手雷和烟雾弹会掉落
|
|
||||||
room->DropItem(drop_pos, bullet_meta->i->id(), drop_num, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
need_sync_active_player = true;
|
|
||||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ResetAction();
|
ResetAction();
|
||||||
AutoLoadingBullet();
|
AutoLoadingBullet();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user