#coding:utf8
'''
Created on 2013-10-25
战斗类
战场ID分配规则
2位数 第一位 表示战斗阵营 1主动 2被动方
后一位表示阵眼的位置
@author: lan (www.9miao.com)
'''
#from core.PlayersManager import PlayersManager
import random,math
from app.game.core.fight.BattleStateMachine import BattleStateMachine
from app.share.dbopear import dbSkill
import copy
POWEREFFECTID = 0
HITDISTANCE = 60#打击距离
DODGEEFFECT = 9999#闪避的文字特效
IGNOREEFFECT = 9998#破防的文字特效
COUNTERATTACK = 9997#反击的文字特效
CRITEFFECT = 9996#暴击的文字特效
CATCHPETEFF = 9995 #抓宠成功的特效
IMMUNITYEFFECT = 0#免疫的文字特效
BOSSDIFFICULTY = 5#boss的困难标识
CATCHPETSKILLGROUP = 8108 #抓宠技能的技能组ID
POWATTUP = 0 #攻击方每次能量增长
POWDEFUP = 0 #被攻击方每次能量增长
#抓宠的方法
############################################
#CATCHRANGE = {1:range(65,217),2:range(9,217),3:range(1,217)}
#伤害计算公式
def DamageFormula(actor,enemy,attackType,skillFormulass,state = 1):
'''伤害计算公式'''
defense = 0
attack = 0
exec(skillFormulass)
if attack<=0:
return attack
hurt = int(round(attack-defense)+random.randint(1,5))
if enemy['chaLevel']<20:
hurt = int(round(attack-defense)+random.randint(1,5))
else:
hurt = int(max(round((attack - defense)+random.randint(1,10)),
10+random.randint(10,60)))
if hurt < 0 and state == 2:
hurt = 1
return hurt
class Fight:
'''战斗类'''
WIDTH = 1000 #战场的宽度
HEIGHT = 570 #战场的高度
MOVEABLE = 300 #活动区域的起始纵坐标
DISTANCE_X = 100 #角色在X轴上得距离
DISTANCE_Y = 50 #角色在Y轴上得距离
DISTANCE_PHA = 120 #方阵到中心点的间距
MAX_ROUND = 30 #战斗的最大回合数
def __init__(self,activeSide,passiveSide,center=0):
'''初始化战斗类
@param center: int 碰撞点的坐标
@param activeSide: 攻击方
@param passiveSide: 防守方
'''
self.activeSide = activeSide #主动方对象
self.passiveSide = passiveSide #被动方对象
self.fighters = {} #所有战斗成员数据{chaBattleId:fightdata}
self.center = center #战斗碰撞点的坐标
self.activeList = [] #主动方的成员的战场id列表
self.passiveList = [] #被动方得成员的战场id列表
self.order = [] #战斗序列
self.now_round = 0 #战斗的当前回合数
self.FightData = [] #战斗产生的数据
self.initData = []
self.resources = set([0]) #战斗中用到的资源列表
self.battleStateMachine = BattleStateMachine(self)#战斗的状态机
self.fixBattleSidePosition() #初始化战场
self.battleResult = 1 #战斗结果
self.hasboss = False #战斗中是否有boss
self.initOrder() #安排出手顺序
def fixBattleSidePosition(self):
'''确定战斗成员的位置,初始化战场,初始化角色技能CD
'''
for activeMember in self.activeSide.getMembers():#初始化主动方
eyeNo = self.activeSide.getCharacterEyeNo(activeMember['chaId'])
activeMember['chaPos'] = eyeNo#初始角色的在战场中的位置
activeMember['chaDirection'] = 1#设置角色的阵营
battleId = 10 + eyeNo
activeMember['chaBattleId'] = battleId#分配角色的战场Id
activeMember['died'] = 0#角色是否死亡
activeMember['nextReleaseSkill'] = 0#角色下次释放的技能序号
activeMember['skillIDByAttack '] = 0#角色遭受的攻击的技能id
activeMember['reactionAddition'] = 0#角色的反伤加成
activeMember['skillCDRecord'] = [{'skillID':skillID,'traceCD':0} for\
skillID in activeMember['ActiveSkillList']\
if skillID>0]
self.initData.append(copy.deepcopy(activeMember))
self.fighters[10 + eyeNo] = activeMember
self.activeList.append(10 + eyeNo)
for passiveMember in self.passiveSide.getMembers():#初始化主动方
eyeNo = self.passiveSide.getCharacterEyeNo(passiveMember['chaId'])
passiveMember['chaPos'] = eyeNo
passiveMember['chaDirection'] = 2
battleId = 20 + eyeNo
passiveMember['chaBattleId'] = 20 + eyeNo
passiveMember['died'] = 0#角色是否死亡
passiveMember['nextReleaseSkill'] = 0#角色下次释放的技能序号
passiveMember['skillIDByAttack '] = 0#角色遭受的攻击的技能id
passiveMember['reactionAddition'] = 0#角色的反伤加成
passiveMember['skillCDRecord'] = [{'skillID':skillID,'traceCD':0}\
for skillID in passiveMember['ActiveSkillList']]
#角色是否技能的CD记录
self.initData.append(copy.deepcopy(passiveMember))
self.fighters[20 + eyeNo] = passiveMember
self.passiveList.append(20 + eyeNo)
if passiveMember['difficulty']==5:
self.hasboss = True
def initOrder(self):
'''初始化战斗次序'''
self.order = sorted(self.fighters.keys(),reverse=True,\
key = lambda d:self.fighters[d]['speed'])
def findTarget(self,actorId,targetType=2,rule = 1):
'''寻找目标
@param actorId: int 行动者的ID
@param targetType: int 目标的类型 1己方 2敌方
@param rule: int 查找规则 1单体 2全体
'''
targetList = []#技能作用目标
actorId_EyeNo = actorId%10 #根据行动者的id得到行动者所在阵法的位置
actor = self.fighters[actorId]
actorId_Camp = actor['chaDirection'] #根据行动者的id得到行动者所在战场的阵营
if actorId_Camp ==1:
enemyList = self.passiveList
ownList = self.activeList
else:
enemyList = self.activeList
ownList = self.passiveList
lines = {1:[1,4,7],2:[2,5,8],3:[3,6,9]}#所有的行数
rows = {1:[1,2,3],2:[4,5,6],3:[7,8,9]} #所有的列数
ruleDict = {1:[1,2,3],2:[2,1,3],3:[3,2,1]}#不同行列的寻找对手规则
for key,value in lines.items():
if actorId_EyeNo in value:
lineno = key #目标列号
break
for key,value in rows.items():
if actorId_EyeNo in value:
rowno = key #目标列号
break
if targetType == 1:#当目标位己方时
target_Camp = actorId_Camp
candidatelist = ownList #攻击的目标列表
candidate = actorId #攻击参照点
else:#当目标位敌方时
target_Camp = 3 - actorId_Camp
candidatelist = enemyList
dd = ruleDict.get(lineno)
sequence = lines[dd[0]]+lines[dd[1]]+lines[dd[2]]
candidatelist.sort(key= lambda d: sequence.index(d%10))
candidate = candidatelist[0]
candidate_EyeNo = candidate%10
for key,value in lines.items():
if candidate_EyeNo in value:
lineno = key #目标列号
break
for key,value in rows.items():
if candidate_EyeNo in value
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
进击的9秒-server:sql脚本及python工程 (186个子文件)
技能效果公式规则.docx 23KB
更新部分.docx 11KB
环境部署.docx 11KB
config.json 977B
game1.log 7KB
net.log 555B
gate.log 540B
dbfront.log 0B
admin.log 0B
fight.py 36KB
BattleStateMachine.py 12KB
dbuser.py 7KB
dbpool.py 6KB
Pet.py 4KB
login.py 4KB
dbSkill.py 4KB
User.py 4KB
CharacterMatrixComponent.py 4KB
stateBuffer.py 4KB
CharacterSkillComponent.py 3KB
urls.py 3KB
netforwarding.py 3KB
VCharacterManager.py 3KB
CharacterArenaComponent.py 3KB
PlayerCharacter.py 3KB
scenesermanger.py 3KB
robot.py 3KB
CharacterPetComponent.py 2KB
handle.py 2KB
pet.py 2KB
PlayersManager.py 2KB
login.py 2KB
AttributeComponent.py 2KB
skill.py 2KB
netapp.py 2KB
skill.py 2KB
UserManager.py 2KB
virtualcharacter.py 2KB
matrix.py 1KB
gateservice.py 1KB
arean.py 1KB
arena.py 1KB
battleSide.py 1KB
McharacterManager.py 1KB
mcharacter.py 1018B
clienttest.py 985B
dataloader.py 876B
enter.py 841B
appmain.py 798B
util.py 779B
dataloader.py 771B
roleinfo.py 739B
initconfig.py 731B
admin.py 692B
initconfig.py 620B
initconfig.py 568B
dbCharacter.py 527B
memmode.py 522B
memmode.py 500B
roleinfo.py 491B
loginout.py 478B
gatenodeservice.py 399B
memmode.py 334B
startmaster.py 308B
Component.py 297B
gatenodeapp.py 290B
initconfig.py 185B
dbfrontserver.py 135B
gameserver.py 132B
gateserver.py 132B
netserver.py 131B
initconfig.py 127B
adminserver.py 109B
__init__.py 103B
doreload.py 79B
__init__.py 20B
__init__.py 12B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
fight.pyc 22KB
共 186 条
- 1
- 2
资源评论
- xiaorf2014-07-18其实9秒就能下
- ivoolong2014-06-09针对mysql的,没有用上,还是感谢分享。
这是一个神秘的博客
- 粉丝: 529
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功