def nuke_grenade_exploded(self, grenade): if (self.name is None): self.name = "AAA" self.team = self.protocol.team_2 if "NukeTeamID1" in grenade.name else self.protocol.team_1 grenade.team = self.team import math if self.name is None or self.team.spectator: return if grenade.team is not None and grenade.team is not self.team: # could happen if the player changed team return position = grenade.position x = position.x y = position.y z = position.z if x < 0 or x > 512 or y < 0 or y > 512 or z < 0 or z > 63: return x = int(math.floor(x)) y = int(math.floor(y)) z = int(math.floor(z)) for player_list in (self.team.other.get_players(), (self, ), self.team.get_players() if ("Nuke" in grenade.name and nukeTKConfig.get()) else []): for player in player_list: if not player.hp: continue damage = grenade.get_damage(player.world_object.position) if damage == 0: continue returned = self.on_hit(damage, player, GRENADE_KILL, grenade) if returned == False: continue elif returned is not None: damage = returned player.set_hp(player.hp - damage, self, hit_indicator=position.get(), kill_type=GRENADE_KILL, grenade=grenade) if self.on_block_destroy(x, y, z, GRENADE_DESTROY) == False: return map = self.protocol.map for n_x, n_y, n_z in product(range(x - 1, x + 2), range(y - 1, y + 2), range(z - 1, z + 2)): count = map.destroy_point(n_x, n_y, n_z) if count: self.total_blocks_removed += count self.on_block_removed(n_x, n_y, n_z) block_action = loaders.BlockAction() block_action.x = x block_action.y = y block_action.z = z block_action.value = GRENADE_DESTROY block_action.player_id = self.player_id self.protocol.broadcast_contained(block_action, save=True) self.protocol.update_entities()
def build_block(connection, x, y, z, color): if is_invalid_coord(x, y, z): return set_color = loaders.SetColor() set_color.value = make_color(*color) set_color.player_id = 32 connection.protocol.broadcast_contained(set_color) block_action = loaders.BlockAction() block_action.player_id = 32 block_action.x = x block_action.y = y block_action.z = z block_action.value = BUILD_BLOCK connection.protocol.map.set_point(x, y, z, color) connection.protocol.broadcast_contained(block_action, save=True)
from twisted.internet import reactor import enet from pyspades.protocol import BaseConnection from pyspades.constants import * from pyspades.packet import call_packet_handler, register_packet_handler from pyspades import contained as loaders from pyspades.collision import vector_collision, collision_3d from pyspades import world from pyspades.common import Vertex3, get_color, make_color from pyspades.weapon import WEAPONS from pyspades.mapgenerator import ProgressiveMapGenerator set_tool = loaders.SetTool() block_action = loaders.BlockAction() position_data = loaders.PositionData() restock = loaders.Restock() create_player = loaders.CreatePlayer() intel_pickup = loaders.IntelPickup() intel_capture = loaders.IntelCapture() intel_drop = loaders.IntelDrop() player_left = loaders.PlayerLeft() set_hp = loaders.SetHP() existing_player = loaders.ExistingPlayer() kill_action = loaders.KillAction() chat_message = loaders.ChatMessage() map_data = loaders.MapChunk() map_start = loaders.MapStart() state_data = loaders.StateData() ctf_data = loaders.CTFState()
def dropNuke(x, y, accuracy, connectionTeam, connection=None): mapData = connection.protocol.map z = mapData.get_z(x, y) centerPosition = [x, y, z] block_action = loaders.BlockAction() block_action.value = DESTROY_BLOCK block_action.player_id = 32 radius = radiusConfig.get() upHeight = upHeightConfig.get() downHeight = downHeightConfig.get() for x in range(-1 * radius, radius): block_action.x = centerPosition[0] + x for y in range(-1 * radius, radius): block_action.y = centerPosition[1] + y for z in range(-1 * downHeight, upHeight): block_action.z = centerPosition[2] + z if (block_action.z >= 63): continue if (sqrt((block_action.x - centerPosition[0])**2 + (block_action.y - centerPosition[1])**2) <= radius): if (mapData.get_color(block_action.x, block_action.y, block_action.z) is not None): connection.protocol.broadcast_contained(block_action) mapData.remove_point(block_action.x, block_action.y, block_action.z) def killPlayers(players): for player in players: ploc = player.get_location() if (sqrt((ploc[0] - centerPosition[0])**2 + (ploc[1] - centerPosition[1])**2) <= radius and (centerPosition[2] - upHeight + 4) <= (ploc[2]) <= (centerPosition[2] + downHeight + 2)): #player.kill(kill_type=GRENADE_KILL) killGrenade = connection.protocol.world.create_object( Grenade, 0.0, Vertex3(-5, -5, -5), None, Vertex3(0, 0, 2), None) killGrenade.name = "NoStreak" player.kill(kill_type=GRENADE_KILL, by=connection, grenade=killGrenade) connection.personalSuccessNukeTime = time() if (connectionTeam.id == 0): connection.protocol.team1SuccessNukeTime = time() else: connection.protocol.team2SuccessNukeTime = time() killPlayers(connectionTeam.other.get_players()) #killPlayers((connection.protocol.team_1 if connectionTeam.id==1 else connection.protocol.team_2).get_players()) if (nukeTKConfig.get()): killPlayers(connection.team.get_players()) grenadeAmount = grenadeAmountConfig.get() for i in range(0, grenadeAmount): randomDistance = (maximumRadiusConfig.get() - radius) / (1 + exp(-flatnessConfig.get() * (i - shiftnessConfig.get()))) fuse = (propogationTimeConfig.get()) / (grenadeAmount - radius) * i randomDegrees = random() * 360 grenadeX = centerPosition[0] + (randomDistance * cos(randomDegrees)) grenadeY = centerPosition[1] + (randomDistance * sin(randomDegrees)) grenade = connection.protocol.world.create_object( Grenade, fuse, Vertex3( grenadeX, grenadeY, min( 62, mapData.get_z(grenadeX, grenadeY) + ceil( (random() - 0.25) * 1.5))), None, Vertex3(0, 0, 2), connection.nuke_grenade_exploded) grenade.team = connectionTeam grenade.name = "nadeNoStreak" + ("NukeTeamID" + str(connectionTeam.id)) if (connectionTeam.id == 0): connection.protocol.team1NukeTime = time() else: connection.protocol.team2NukeTime = time()