1
This commit is contained in:
parent
8154244110
commit
2e3b720eb5
@ -1,19 +1,51 @@
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
|
||||||
import cs_proto_pb2
|
import cs_proto_pb2
|
||||||
import cs_msgid_pb2
|
import cs_msgid_pb2
|
||||||
|
|
||||||
|
kPropHp = 1
|
||||||
|
kPropMaxHp = 2
|
||||||
|
kPropInventory = 3
|
||||||
|
kPropSkillLeftTime_ = 4
|
||||||
|
kPropSkillCd = 5
|
||||||
|
kPropTankBulletNum = 6
|
||||||
|
kPropTankOil = 7
|
||||||
|
kPropBulletNum = 8
|
||||||
|
kPropItem = 9
|
||||||
|
kPropWeaponAmmo = 10
|
||||||
|
kPropCar = 11
|
||||||
|
|
||||||
|
kPropZombieId = 23
|
||||||
|
kPropSkillLeftTime = 24
|
||||||
|
kPropSkillCurrTimes = 25
|
||||||
|
kPropSkillMaxTimes = 26
|
||||||
|
kPropCarOil = 27
|
||||||
|
kPropFollowTarget = 30
|
||||||
|
kPropDive = 31
|
||||||
|
|
||||||
class Simulate(object):
|
class Simulate(object):
|
||||||
|
|
||||||
def __init__(self, joined_msg, mapinfo_msg):
|
def __init__(self, joined_msg, mapinfo_msg):
|
||||||
|
|
||||||
self._joined_msg = joined_msg
|
self._joined_msg = joined_msg
|
||||||
self._mapinfo_msg = mapinfo_msg
|
self._mapinfo_msg = mapinfo_msg
|
||||||
self._curr_player = None
|
self._curr_player = {
|
||||||
|
'obj_uniid': 0,
|
||||||
|
'action_type': 0,
|
||||||
|
'action_duration': 0,
|
||||||
|
'action_frameno': 0,
|
||||||
|
'items': [],
|
||||||
|
'inventory': [],
|
||||||
|
'cur_weapon_idx': 0,
|
||||||
|
'weapons': [],
|
||||||
|
'skill_list': []
|
||||||
|
}
|
||||||
self._frames = []
|
self._frames = []
|
||||||
self._curr_frameno = 0
|
self._curr_frameno = 0
|
||||||
self._objHash = []
|
self._objHash = {}
|
||||||
|
|
||||||
def addFrame(self, frame):
|
def addFrame(self, frame):
|
||||||
self._frames.append(frame)
|
self._frames.append(frame)
|
||||||
@ -24,8 +56,164 @@ class Simulate(object):
|
|||||||
self._updateFrame(self._frames[i])
|
self._updateFrame(self._frames[i])
|
||||||
i += 1
|
i += 1
|
||||||
self._frames = []
|
self._frames = []
|
||||||
|
self._cmmove()
|
||||||
|
|
||||||
|
def _cmmove(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def _updateFrame(self, frame):
|
def _updateFrame(self, frame):
|
||||||
self._curr_frameno = frame.frameno
|
self._curr_frameno = frame.frameno
|
||||||
for obj in frame.full_objects:
|
for newobj in frame.full_objects:
|
||||||
self._objHash[obj['union_obj_' + obj.object_type]] = obj
|
obj = self._getRealFullObj(newobj)
|
||||||
|
if newobj.object_flags == 0:
|
||||||
|
self._objHash[obj.obj_uniid] = obj
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
for partobj in frame.part_objects:
|
||||||
|
self._updatePartObj(self._getRealPartObj(partobj))
|
||||||
|
self._updateActivePlayerData(frame)
|
||||||
|
for objid in frame.out_objids:
|
||||||
|
del self._objHash[objid]
|
||||||
|
for objid in frame.del_objids:
|
||||||
|
del self._objHash[objid]
|
||||||
|
self._chgedBuffList(frame)
|
||||||
|
self._chgedPropList(frame)
|
||||||
|
|
||||||
|
def _getRealFullObj(self, newobj):
|
||||||
|
if newobj.object_type == 1:
|
||||||
|
return newobj.union_obj_1
|
||||||
|
elif newobj.object_type == 2:
|
||||||
|
return newobj.union_obj_2
|
||||||
|
elif newobj.object_type == 3:
|
||||||
|
return newobj.union_obj_3
|
||||||
|
elif newobj.object_type == 4:
|
||||||
|
return newobj.union_obj_4
|
||||||
|
elif newobj.object_type == 5:
|
||||||
|
return newobj.union_obj_5
|
||||||
|
elif newobj.object_type == 6:
|
||||||
|
return newobj.union_obj_6
|
||||||
|
elif newobj.object_type == 7:
|
||||||
|
return newobj.union_obj_7
|
||||||
|
elif newobj.object_type == 8:
|
||||||
|
return newobj.union_obj_8
|
||||||
|
elif newobj.object_type == 9:
|
||||||
|
return newobj.union_obj_9
|
||||||
|
elif newobj.object_type == 10:
|
||||||
|
return newobj.union_obj_10
|
||||||
|
elif newobj.object_type == 11:
|
||||||
|
return newobj.union_obj_11
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _getRealPartObj(self, partobj):
|
||||||
|
if partobj.object_type == 1:
|
||||||
|
return partobj.union_obj_1
|
||||||
|
elif partobj.object_type == 2:
|
||||||
|
return partobj.union_obj_2
|
||||||
|
elif partobj.object_type == 3:
|
||||||
|
return partobj.union_obj_3
|
||||||
|
elif partobj.object_type == 4:
|
||||||
|
return partobj.union_obj_4
|
||||||
|
elif partobj.object_type == 5:
|
||||||
|
return partobj.union_obj_5
|
||||||
|
elif partobj.object_type == 6:
|
||||||
|
return partobj.union_obj_6
|
||||||
|
elif partobj.object_type == 7:
|
||||||
|
return partobj.union_obj_7
|
||||||
|
elif partobj.object_type == 8:
|
||||||
|
return partobj.union_obj_8
|
||||||
|
elif partobj.object_type == 9:
|
||||||
|
return partobj.union_obj_9
|
||||||
|
elif partobj.object_type == 10:
|
||||||
|
return partobj.union_obj_10
|
||||||
|
elif partobj.object_type == 11:
|
||||||
|
return partobj.union_obj_11
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _updatePartObj(self, obj):
|
||||||
|
entity = self._objHash[obj.obj_uniid]
|
||||||
|
entity.pos = obj.pos
|
||||||
|
entity.dir = obj.dir
|
||||||
|
|
||||||
|
def _updateActivePlayerData(self, frame):
|
||||||
|
active_player = self._objHash[frame.active_player_id]
|
||||||
|
self._curr_player['obj_uniid'] = frame.active_player_id
|
||||||
|
self._curr_player['action_type'] = frame.action_type
|
||||||
|
self._curr_player['action_duration'] = frame.action_duration
|
||||||
|
self._curr_player['action_frameno'] = frame.action_frameno
|
||||||
|
self._curr_player['items'] = frame.items
|
||||||
|
self._curr_player['inventory'] = frame.inventory
|
||||||
|
self._curr_player['cur_weapon_idx'] = frame.cur_weapon_idx
|
||||||
|
self._curr_player['weapons'] = frame.weapons
|
||||||
|
self._curr_player['skill_list'] = frame.skill_list
|
||||||
|
|
||||||
|
def _chgedBuffList(self, frame):
|
||||||
|
for chged_buff in frame.chged_buff_list:
|
||||||
|
entity = self._objHash[chged_buff.obj_id]
|
||||||
|
if entity:
|
||||||
|
if chged_buff.chg == 0:
|
||||||
|
self._entityUpdateBuff(entity, chged_buff.buff)
|
||||||
|
elif chged_buff.chg == 1:
|
||||||
|
self._entityRemoveBuff(entity, chged_buff.buff)
|
||||||
|
|
||||||
|
def _chgedPropList(self, frame):
|
||||||
|
for chged_prop in frame.chged_property_list:
|
||||||
|
entity = self._objHash[chged_prop.obj_id]
|
||||||
|
if entity:
|
||||||
|
self.applyChgedProp(entity, chged_prop)
|
||||||
|
|
||||||
|
def _entityUpdateBuff(self, entity, pb_buff):
|
||||||
|
buff = self.getBuffByUniId(self, entity, pb_buff.buff_uniid)
|
||||||
|
if buff:
|
||||||
|
entity.buff_list.erase(buff)
|
||||||
|
entity.buff_list.append(pb_buff)
|
||||||
|
|
||||||
|
def _entityRemoveBuff(self, entity, pb_buff):
|
||||||
|
buff = self.getBuffByUniId(self, entity, pb_buff.buff_uniid)
|
||||||
|
if buff:
|
||||||
|
entity.buff_list.erase(buff)
|
||||||
|
|
||||||
|
def getBuffByUniId(self, entity, buff_uniid):
|
||||||
|
for buff in entity.buff_list:
|
||||||
|
if buff.buff_uniid == buff_uniid:
|
||||||
|
return buff
|
||||||
|
return None
|
||||||
|
|
||||||
|
def applyChgedProp(self, e, prop):
|
||||||
|
if prop.property_type == kPropHp:
|
||||||
|
e.health = prop.value
|
||||||
|
elif prop.property_type == kPropMaxHp:
|
||||||
|
e.max_health = prop.value
|
||||||
|
elif prop.property_type == kPropInventory:
|
||||||
|
self._curr_player['inventory'][prop.property_subtype] = prop.value
|
||||||
|
elif prop.property_type == kPropSkillLeftTime_:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropSkillCd:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropTankBulletNum:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropTankOil:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropBulletNum:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropItem:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropWeaponAmmo:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropCar:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropZombieId:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropSkillLeftTime:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropSkillCurrTimes:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropSkillMaxTimes:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropCarOil:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropFollowTarget:
|
||||||
|
pass
|
||||||
|
elif prop.property_type == kPropDive:
|
||||||
|
pass
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
from tornado import gen
|
from tornado import gen
|
||||||
from tornado import httpclient
|
from tornado import httpclient
|
||||||
@ -129,7 +131,8 @@ class VirtualClient(object):
|
|||||||
self._simulate.update()
|
self._simulate.update()
|
||||||
yield None
|
yield None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('co_updateSimulate', e)
|
exc_type, exc_value, exc_obj = sys.exc_info()
|
||||||
|
traceback.print_tb(exc_obj, exc_type, exc_value)
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def run(self):
|
def run(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user