Module client
[hide private]
[frames] | no frames]

Source Code for Module client

  1  from commands import * 
  2  from twisted.internet.protocol import Factory 
  3  from twisted.protocols.amp import AMP 
  4  from objects import Objects 
  5  from constants import UNIT_STARTING_OPACITY 
  6  import math 
7 8 9 -class ServerNote(AMP): # client responses to server
10 - def __init__(self):
11 super(ServerNote, self).__init__(self)
12 13 @StartGame.responder
14 - def server_start_game(self):
15 ''' 16 The client stub that gets called when the server starts the game 17 ''' 18 client = Objects.get_client() 19 client._init_players() 20 client.start_game() 21 return {}
22 23 @AddPlayer.responder
24 - def server_add_player(self, pid):
25 # print "server add player" 26 client = Objects.get_client() 27 client.playerList.append(pid) 28 return {}
29 30 @UpdateHealth.responder
31 - def server_update_health(self, pid, uid, h, tid,vid):
32 # print "update_health", pid, uid, h 33 client = Objects.get_client() 34 player = client.players[pid] 35 if uid not in player.underConstruction.keys(): 36 unit = client.build_unit(tid,player,vid=vid,uid=uid) 37 else: 38 unit = player.underConstruction[uid] 39 unit.health = h 40 client._complete_build(unit, player, uid) 41 return {}
42 43 @UpdateLocation.responder
44 - def server_update_location(self, pid, uid, vid):
45 client = Objects.get_client() 46 p = client.players[pid] 47 curVertex = client.map.vertices[str(vid)] 48 client.update_location(p.units[uid], curVertex.position, curVertex) 49 return {}
50 51 @BuildUnit.responder
52 - def server_build_unit(self, pid, tid, vid, uid,buid):
53 # print "building unit", pid, tid, vid, uid 54 client = Objects.get_client() 55 player = client.players[pid] 56 if uid not in player.underConstruction.keys(): 57 client.build_unit(tid, player, vid=vid, uid=uid) 58 return {} 59 60 @MoveTroop.responder
61 - def server_move_troop(self, pid, uid, vid, path):
62 # print "server move unit", pid, vid, uid, path 63 client = Objects.get_client() 64 path = client.move_unit(client.players[pid].units[uid], path) 65 return {}
66 67 @RemoveUnit.responder
68 - def client_remove_unit(self,pid,uid):
69 # print "remove unit", pid, uid 70 client = Objects.get_client() 71 unit = client.players[pid].units[uid] 72 unit.destroy_action() 73 return {}
74 75 @Attack.responder
76 - def server_on_attack(self,tpid,tuid,val):
77 # print "server_on_attack", tpid,tuid,val 78 client = Objects.get_client() 79 p = client.players[tpid] 80 if tuid in p.units.keys(): 81 p.units[tuid].client_on_attack(val) 82 return {}
83 84 85 @AttackAnimation.responder
86 - def server_animate_attack(self,pid,uid,tpid,tuid,path):
87 #if no path, stop attacking 88 # print "server_animate_attack",pid,uid, tpid,tuid,path 89 client = Objects.get_client() 90 91 if (uid in client.players[pid].units.keys()): 92 attacker = client.players[pid].units[uid] 93 if tpid == -1 or tuid == -1: 94 attacker.end_attack(True) 95 elif path: 96 target = client.players[tpid].units[tuid] 97 attacker.attackingPath = path 98 if not attacker.is_attacking: 99 attacker.client_attack(target,client.map) 100 return {}
101
102 103 -class ServerNoteFactory(Factory):
104 protocol = ServerNote
105 106 107 # send: 108 # user attack 109 # user research 110 # user move 111 # user construction 112 # user unit special ability 113 # join request 114 115 # receive, do and send 116 # location update in move 117 # end of move 118 # attack progress 119 # destruction of unit 120 # construction progress 121 # construction completion 122 # research progress 123 # research completion 124