Go to the documentation of this file.00001 '''
00002 Anoria (c) Gsk 2010
00003 '''
00004
00005
00006
00007
00008
00009 import BigWorld
00010
00011 from Actor import Actor
00012 from config import consts
00013 from config import state
00014 from config import event
00015
00016 from Resources import ItemDef
00017
00018 import Anoria
00019
00020 class Avatar(BigWorld.Entity, Actor):
00021
00022 def __init__(self):
00023 BigWorld.Entity.__init__(self)
00024 Actor.__init__(self)
00025 self.isPlayer = True
00026 self.name = "%s.%d" % (self.name, self.id)
00027
00028
00029 self.addEventProc(event.UNDER_ATTACK, self.eventUnderAttack)
00030
00031
00032 weapon = ItemDef()
00033 weapon.id = 'dev-test-sword-14-3000'
00034 weapon.dmg = 14
00035 weapon.dly = 3000
00036 self.combatResolver.equipWeapon(weapon, 0)
00037
00038
00039
00040
00041
00042
00043
00044
00045 def onTimer(self, timerId, userData):
00046 ''' onTimer() is the regular update tick processor for Avatar. Think of it as Avatar's brain
00047 @param: timerId several timers can be started with differing timerIds
00048 @param: userData can be used to pass in info from the function starting the timer '''
00049 Actor.onTimer(self, timerId, userData)
00050 if userData != 0: return
00051
00052 if self.states[state.STATE_COMBAT] == state.S_COMBAT_ON:
00053
00054 if self.targetId != None:
00055 target = self.getTargetEntity()
00056 if target == None:
00057 self.targetLost()
00058 else:
00059 dist = self.position.distTo(target.position)
00060 inRange = consts.MELEE_MAX_DISTANCE - dist > 0.0
00061 if not inRange:
00062 if self.states[state.STATE_ATTACK] == state.S_ATTACK_ON:
00063 self.pauseAutoattack()
00064 elif self.states[state.STATE_ATTACK] == state.S_ATTACK_PAUSED:
00065 self.pauseAutoattack(restart=True)
00066
00067
00068 if not self.states[state.STATE_ATTACK] == state.S_ATTACK_ON and not self.haveAggro():
00069 self.exitCombat()
00070 else:
00071
00072 self.doHealthRegen()
00073
00074
00075
00076 self.combatResolver.update()
00077
00078
00079
00080
00081
00082
00083 def rpc_setTarget(self, id, entityId):
00084 ''' rpc_setTarget is called by the client whenever it targets some entity
00085 @param: id is the id of the calling client entity
00086 @param: entityId is the id of the entity being targeted '''
00087
00088 if entityId != 0:
00089 if entityId != self.targetId:
00090 print 'Avatar_%d.rpc_setTarget() setting target, Id=%d' % (self.id, entityId)
00091 self.setTarget(entityId)
00092 else:
00093 self.targetId = None
00094 self.stopAutoattack()
00095
00096
00097 def rpcAutoAttackToggle(self, id):
00098 '''this function is a toggle: calling it when already auto attacking
00099 will turn auto attack off again
00100 @param: id is the id of the client entity making the call'''
00101
00102 print 'Avatar_%d.rpcAutoAttackToggle(): from Id=%d' % (self.id, id)
00103 if self.states[state.STATE_ATTACK] != state.S_ATTACK_OFF:
00104 self.stopAutoattack()
00105 else:
00106 self.beginAutoAttack()
00107
00108 def rpcSay( self, id, message ):
00109 if self.id == id:
00110 text = "%s says: '%s'" % (self.name, message)
00111 print text
00112 self.otherClients.rpc_chatText(text, 1)
00113
00114
00115
00116
00117
00118 def beginAutoAttack(self):
00119
00120 target = self.getTargetEntity()
00121 if target == None:
00122 self.client.rpc_printString(4, consts.MELEE_COMBAT_CHANNEL_ID)
00123 return
00124
00125 if target == self:
00126 self.client.rpc_printString(10, consts.MELEE_COMBAT_CHANNEL_ID)
00127 return
00128
00129 dist = self.position.distTo(target.position)
00130 inRange = consts.MELEE_MAX_DISTANCE - dist >= 0.0
00131 print 'Avatar_%d.initCombat(): target dist=%.3f, inRange=%s' % (self.id, dist, inRange)
00132 if not inRange:
00133 self.client.rpc_printString(3, consts.MELEE_COMBAT_CHANNEL_ID)
00134 return
00135
00136
00137 self.enterCombat()
00138 self.allClients.rpcChangeState(state.STATE_ATTACK, state.S_ATTACK_ON)
00139
00140 def targetLost(self):
00141 Actor.targetLost(self)
00142 self.client.rpcTargetLost()
00143
00144
00145
00146
00147
00148
00149
00150
00151 def eventUnderAttack(self, attackerId, eventValue):
00152 ''' eventUnderAttack is received when ever anything hostile is done to this Actor.
00153 @param: attackerId is the entity id of the hostile entity
00154 @param: eventValue is the type of hostile activity '''
00155
00156 print "Avatar_%d.eventUnderAttack(): attackerId=%d, eventValue=[%d]%s" \
00157 % (self.id, attackerId, eventValue, event.ATTACK_EVENTS[eventValue])
00158
00159 self.aggroFromEntity(attackerId)
00160
00161 if not self.states[state.STATE_COMBAT] == state.S_COMBAT_ON:
00162 self.enterCombat()
00163