diff --git a/server/gameserver/android.cc b/server/gameserver/android.cc index f4063393..35d29644 100644 --- a/server/gameserver/android.cc +++ b/server/gameserver/android.cc @@ -35,6 +35,15 @@ void Android::Initialize() { auto context = std::make_shared(); SetBattleContext(context); + context->ForceInit + ( + App::Instance()->AllocTempHeroUniId(), + meta, + App::Instance()->AllocTempWeaponUniId(), + GetCurrWeapon()->meta, + 0, + nullptr + ); } } diff --git a/server/gameserver/app.cc b/server/gameserver/app.cc index 57a97e63..60500d58 100644 --- a/server/gameserver/app.cc +++ b/server/gameserver/app.cc @@ -675,3 +675,27 @@ void App::FreeIMMsgQueue() } im_msg_mutex_->unlock(); } + +long long App::AllocTempHeroUniId() +{ + if (curr_uniid_ < 1000) { + curr_uniid_ = 1000; + } + if (curr_uniid_ > 100000000) { + curr_uniid_ = 1001; + } + ++curr_uniid_; + return -curr_uniid_; +} + +long long App::AllocTempWeaponUniId() +{ + if (curr_uniid_ < 1000) { + curr_uniid_ = 1000; + } + if (curr_uniid_ > 100000000) { + curr_uniid_ = 1000; + } + ++curr_uniid_; + return -curr_uniid_; +} diff --git a/server/gameserver/app.h b/server/gameserver/app.h index 25ac9eda..50a7e6da 100644 --- a/server/gameserver/app.h +++ b/server/gameserver/app.h @@ -38,6 +38,8 @@ public: bool HasFlag(int flag); void SetFlag(int flag); void UnSetFlag(int flag); + long long AllocTempHeroUniId(); + long long AllocTempWeaponUniId(); private: void QuickExecute(int delta_time); @@ -100,6 +102,8 @@ private: std::map context_hash_; + long long curr_uniid_ = 0; + public: int msgnode_size_ = 0 ; int working_msgnode_size_ = 0; diff --git a/server/gameserver/car.cc b/server/gameserver/car.cc index 57eead7f..4cf19938 100644 --- a/server/gameserver/car.cc +++ b/server/gameserver/car.cc @@ -15,6 +15,8 @@ #include "obstacle.h" #include "ability.h" #include "entityfactory.h" +#include "app.h" + Car::Car():Creature() { @@ -54,6 +56,15 @@ void Car::Initialize() { auto context = std::make_shared(); SetBattleContext(context); + context->ForceInit + ( + App::Instance()->AllocTempHeroUniId(), + hero_meta_, + App::Instance()->AllocTempWeaponUniId(), + GetCurrWeapon()->meta, + 0, + nullptr + ); } } diff --git a/server/gameserver/hero.cc b/server/gameserver/hero.cc index 6af07c1a..db6c62e0 100644 --- a/server/gameserver/hero.cc +++ b/server/gameserver/hero.cc @@ -14,6 +14,7 @@ #include "bullet.h" #include "explosion.h" #include "roomobstacle.h" +#include "app.h" Hero::Hero():Creature() { @@ -51,6 +52,15 @@ void Hero::Initialize() { auto context = std::make_shared(); SetBattleContext(context); + context->ForceInit + ( + App::Instance()->AllocTempHeroUniId(), + meta, + App::Instance()->AllocTempWeaponUniId(), + GetCurrWeapon()->meta, + 0, + nullptr + ); } }