Go to the documentation of this file.00001 '''
00002 Combat.py
00003 game system combat code
00004
00005 Anoria (c) Gsk 2010
00006 '''
00007
00008 import BigWorld
00009 import ProcTimer
00010 import time
00011 import random
00012
00013 from attktab import AttackTable
00014 from consts import *
00015
00016
00017 class CombatResolver():
00018
00019 def __init__(self, id, hostEntity):
00020 self.id = id
00021 self.hostEntity = hostEntity
00022 self.attackTable = AttackTable()
00023 self.weaponSlots = {}
00024 self.procTimer = ProcTimer.ProcTimer()
00025
00026 def update(self):
00027 self.procTimer.update()
00028
00029 def setTargetId(self, targetId):
00030 try:
00031 targetEntity = BigWorld.entities[targetId]
00032
00033 self.attackTable.buildTable(self.hostEntity.characterSkills, targetEntity.characterSkills)
00034 except:
00035 print "CombatResolver.setTargetId(): invalid targetId=%d, cant build AttackTable" % (targetId)
00036
00037
00038 def equipWeapon(self, weapon, slot):
00039 ''' Equipping a weapon on a given slot of the combat resolver
00040 @param weapon the Resources.itemDef of the weapon
00041 @param slot is the combat resolver slot to equip '''
00042
00043 self.weaponSlots[slot] = weapon
00044
00045 def removeWeapon(self, slot):
00046 del self.weaponSlots[slot]
00047
00048 def startSlot(self, slot):
00049 try:
00050 weapon = self.weaponSlots[slot]
00051 except:
00052 print 'CombatResolver cant startSlot=%d: no weapon equiped' % (slot)
00053 return
00054
00055 self.procTimer.addProc(slot, weapon.dly, self.doWeaponAttack)
00056
00057 def stopSlot(self, slot):
00058 try:
00059 self.procTimer.delProc(slot)
00060 except:
00061 print 'CombatResolver cant stopSlot=%d: no weapon equiped' % (slot)
00062
00063
00064
00065
00066 def doWeaponAttack(self, slot):
00067
00068 dmg = 0
00069 hitType = self.attackTable.getHit()
00070 if hitType in [HIT_TYPE_NORMAL, HIT_TYPE_CRIT, HIT_TYPE_CRUSH]:
00071 dmg = self.determineWeaponDamage(slot, hitType)
00072
00073
00074
00075 self.hostEntity.onWeaponAttackPerformed(hitType, dmg)
00076
00077 def determineWeaponDamage(self, slot, hitType):
00078 weapon = self.weaponSlots[slot]
00079 baseDmg = weapon.dmg
00080 lim = baseDmg/2
00081 dmg = random.randint(baseDmg-lim, baseDmg+lim) * HIT_MULTIPLIER[hitType]
00082 return dmg
00083