This commit is contained in:
aozhiwei 2019-11-20 16:01:12 +08:00
parent 1a4cbf7d94
commit a36859194e
4 changed files with 0 additions and 406 deletions

View File

@ -131,43 +131,8 @@ static void HttpTest()
}
}
static void test()
{
{
std::map<std::string, std::string> test_hash;
for (int i = 0; i < 10; ++i) {
test_hash[a8::XValue(i).GetString()] = a8::XValue(i).GetString();
}
std::map<std::string, std::string> test_hash_copy;
bool combin_ok = false;
do {
combin_ok = false;
int i = 0;
for (auto& pair1 : test_hash) {
for (auto& pair2 : test_hash_copy) {
++i;
if (i > 3) {
std::string t1 = pair1.first;
std::string t2 = pair2.first;
test_hash.erase(t1);
test_hash.erase(t2);
test_hash_copy.erase(t1);
test_hash_copy.erase(t2);
combin_ok = true;
break;
}
}
}
} while(combin_ok);
}
}
bool App::Init(int argc, char* argv[])
{
#if 0
test();
#endif
signal(SIGPIPE, SIG_IGN);
this->argc = argc;
this->argv = argv;

View File

@ -52,48 +52,12 @@ void Player::Update(int delta_time)
UpdateMove();
}
if (room->frame_no % 2 == 0) {
if (drop_weapon) {
UpdateDropWeapon();
}
if (poisoning) {
UpdatePoisoning();
}
if (select_weapon) {
UpdateSelectWeapon();
}
if (use_scope) {
UpdateUseScope();
}
if (reload) {
UpdateReload();
}
if (cancel_action) {
UpdateCancelAction();
}
if (use_item) {
UpdateUseItemIdx();
}
if (action_type != AT_None) {
UpdateAction();
}
if (spectate) {
UpdateSpectate();
}
if (emote) {
UpdateEmote();
}
if (jump) {
UpdateJump();
}
if (use_skill) {
UpdateUseSkill();
}
if (get_down) {
UpdateGetDown();
}
if (shot_start || shot_hold) {
UpdateShot();
}
}
}
@ -129,116 +93,6 @@ void Player::UpdateMove()
}
}
void Player::UpdateShot()
{
if (dead ||
a8::HasBitFlag(status, HS_Fly) ||
a8::HasBitFlag(status, HS_Jump) ) {
shot_start = false;
shot_hold = false;
series_shot_frames = 0;
return;
}
if (shot_start) {
shot_start = false;
return;
}
Weapon* p_weapon = curr_weapon;
if (tank_weapon.meta) {
p_weapon = &tank_weapon;
}
if (shot_hold) {
++series_shot_frames;
if (last_shot_frameno_ == 0 ||
(
(room->frame_no - last_shot_frameno_) * (1000 / SERVER_FRAME_RATE)) >=
p_weapon->meta->i->fire_rate()
) {
}
if (series_shot_frames > 8) {
shot_hold = false;
series_shot_frames = 0;
}
}
}
void Player::UpdateSelectWeapon()
{
if (a8::HasBitFlag(status, HS_Fly)) {
select_weapon = false;
selected_weapon_idx = 0;
return;
}
if (selected_weapon_idx >= 0 && selected_weapon_idx < weapons.size()) {
Weapon* old_weapon = curr_weapon;
Weapon* weapon = &weapons[selected_weapon_idx];
if (weapon->weapon_id != 0) {
curr_weapon = weapon;
ResetAction();
need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
if (old_weapon != weapon) {
AutoLoadingBullet();
}
}
}
select_weapon = false;
selected_weapon_idx = 0;
}
void Player::UpdateReload()
{
AutoLoadingBullet(true);
reload = false;
}
void Player::UpdateCancelAction()
{
CancelAction();
cancel_action = false;
}
void Player::UpdateUseItemIdx()
{
if (use_item_idx >= 0 && use_item_idx < IS_END) {
switch (use_item_idx) {
case IS_HEALTHKIT:
{
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(use_item_idx);
if (item_meta) {
StartAction(
AT_UseItem,
item_meta->i->use_time(),
use_item_idx,
0
);
}
}
break;
case IS_PAIN_KILLER:
{
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(use_item_idx);
if (item_meta) {
StartAction(
AT_UseItem,
item_meta->i->use_time(),
use_item_idx,
0
);
}
}
break;
default:
{
}
break;
}
}
use_item_idx = 0;
use_item = false;
}
void Player::UpdateSpectate()
{
if (room->gas_data.gas_mode == GasInactive ||
@ -263,51 +117,6 @@ void Player::UpdateEmote()
emote_id = 0;
}
void Player::UpdateJump()
{
if (a8::HasBitFlag(status, HS_Fly)) {
DoJump();
if (pos.Distance(room->last_player_jump_pos) > 64 * 4) {
size_t num = 2 + rand() % 2;
for (size_t i = 0; i < num; ++i){
room->xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE / 10,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->room->TouchHumanList(
a8::XParams()
.SetSender(hum),
[] (Human* hum, a8::XParams& param) -> bool
{
if (a8::HasBitFlag(hum->status, HS_Fly) && hum->entity_subtype != EST_Player) {
hum->DoJump();
return false;
}
return true;
});
},
&xtimer_attacher.timer_list_);
}
}
room->last_player_jump_pos = pos;
}
jump = false;
}
void Player::UpdateUseSkill()
{
DoSkill();
use_skill = false;
}
void Player::UpdateGetDown()
{
DoGetDown();
get_down = false;
}
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
{
moving = false;
@ -350,28 +159,6 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
series_shot_frames = 0;
}
last_seq_id = msg.seq();
if (msg.has_select_weapon()) {
select_weapon = true;
selected_weapon_idx = msg.select_weapon();
}
if (msg.has_drop_weapon()) {
drop_weapon = true;
drop_weapon_idx = msg.drop_weapon();
}
if (msg.has_use_scope()) {
use_scope = true;
use_scope_idx = msg.use_scope();
}
if (msg.has_reload()) {
reload = msg.reload();
}
if (msg.has_cancel_action()) {
cancel_action = msg.cancel_action();
}
if (msg.has_use_item_idx()) {
use_item = true;
use_item_idx = msg.use_item_idx();
}
if (msg.has_spectate()) {
spectate = true;
}
@ -379,132 +166,6 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
emote = true;
emote_id = msg.emote();
}
if (msg.has_jump()) {
jump = true;
}
if (msg.has_use_skill()) {
use_skill = true;
}
if (msg.has_get_down()) {
get_down = msg.get_down();
}
}
void Player::UpdateDropWeapon()
{
if (drop_weapon_idx >= 0 && drop_weapon_idx < weapons.size()) {
bool drop_ok = false;
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 (curr_weapon == weapon) {
if (weapons[GUN_SLOT2].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT2];
} else {
curr_weapon = &weapons[0];
}
}
} else if (weapon->weapon_idx == GUN_SLOT2) {
drop_ok = true;
*weapon = Weapon();
weapon->weapon_idx = drop_weapon_idx;
if (curr_weapon == weapon) {
if (weapons[GUN_SLOT1].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT1];
} else {
curr_weapon = &weapons[0];
}
}
} else if (weapon->weapon_idx == FRAG_SLOT) {
drop_ok = true;
*weapon = Weapon();
weapon->weapon_idx = drop_weapon_idx;
if (curr_weapon == weapon) {
if (weapons[GUN_SLOT1].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT1];
} else if (weapons[GUN_SLOT2].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT2];
} else {
curr_weapon = &weapons[0];
}
}
} else if (weapon->weapon_idx == SMOKE_SLOT) {
drop_ok = true;
*weapon = Weapon();
weapon->weapon_idx = drop_weapon_idx;
if (curr_weapon == weapon) {
if (weapons[GUN_SLOT1].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT1];
} else if (weapons[GUN_SLOT2].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT2];
} else {
curr_weapon = &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, pos + 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 = pos + drop_dir * (25 + rand() % 50);
room->DropItem(drop_pos, bullet_meta->i->id(), drop_num, 1);
}
}
}
need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
}
}
}
ResetAction();
AutoLoadingBullet();
drop_weapon = false;
drop_weapon_idx = 0;
}
void Player::UpdateUseScope()
{
if (IS_1XSCOPE + use_scope_idx >= IS_1XSCOPE && IS_1XSCOPE + use_scope_idx <= IS_15XSCOPE) {
if (GetInventory(IS_1XSCOPE + use_scope_idx) > 0) {
curr_scope_idx = use_scope_idx;
need_sync_active_player = true;
}
}
use_scope = false;
use_scope_idx = 0;
}
void Player::_CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg)

View File

@ -9,7 +9,6 @@ namespace cs
class CMEmote;
class CMVoice;
class MFActivePlayerData;
class MFGasData;
}
class Room;
@ -22,57 +21,27 @@ class Player : public Human
public:
int team_mode = 0;
bool use_touch = false;
long long create_tick = 0;
int last_seq_id = 0;
bool moving = false;
int moved_frames = 0;
bool select_weapon = false;
size_t selected_weapon_idx = 0;
bool drop_weapon = false;
size_t drop_weapon_idx = 0;
bool cancel_action = false;
bool use_item = false;
int use_item_idx = 0;
bool use_scope = false;
int use_scope_idx = 0;
bool reload = false;
bool spectate = false;
bool emote = false;
int emote_id = 0;
bool jump = false;
bool use_skill = false;
bool get_down = false;
Player();
virtual ~Player() override;
virtual void Initialize() override;
virtual void Update(int delta_time) override;
void UpdateMove();
void UpdateShot();
void UpdateSelectWeapon();
void UpdateDropWeapon();
void UpdateUseScope();
void UpdateReload();
void UpdateCancelAction();
void UpdateUseItemIdx();
void UpdateSpectate();
void UpdateEmote();
void UpdateJump();
void UpdateUseSkill();
void UpdateGetDown();
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);

View File

@ -48,7 +48,6 @@ Player* PlayerMgr::CreatePlayerByCMJoin(long ip_saddr, int socket, const cs::CMJ
hum->team_uuid = msg.team_uuid();
hum->team_mode = msg.team_mode();
hum->auto_fill = msg.auto_fill();
hum->use_touch = msg.use_touch();
hum->avatar_url = msg.avatar_url();
hum->energy_shield = msg.energy_shield();
hum->today_enter_times = msg.today_enter_times();