def execute(self, obj): if not obj.Active: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False return #Tool may have changed. Refresh data toolLoad = PathUtils.getLastToolLoad(obj) if toolLoad is None or toolLoad.ToolNumber == 0: self.vertFeed = 100 self.horizFeed = 100 self.vertRapid = 100 self.horiRrapid = 100 self.radius = 0.25 obj.ToolNumber = 0 obj.ToolDescription = "UNDEFINED" else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = PathUtils.getTool(obj, toolLoad.ToolNumber) if tool.Diameter == 0: self.radius = 0.25 else: self.radius = tool.Diameter / 2 obj.ToolNumber = toolLoad.ToolNumber obj.ToolDescription = toolLoad.Name #Build preliminary comments output = "" output += "(" + obj.Label + ")" if obj.UserLabel == "": obj.Label = obj.Name + " :" + obj.ToolDescription else: obj.Label = obj.UserLabel + " :" + obj.ToolDescription #Facing is done either against base objects if obj.Base: faces = [] for b in obj.Base: for sub in b[1]: shape = getattr(b[0].Shape, sub) if isinstance(shape, Part.Face): faces.append(shape) else: print('falling out') return planeshape = Part.makeCompound(faces) #If no base object, do planing of top surface of entire model else: parentJob = PathUtils.findParentJob(obj) if parentJob is None: return baseobject = parentJob.Base if baseobject is None: return planeshape = baseobject.Shape #if user wants the boundbox, calculate that if obj.BoundaryShape == 'Boundbox': bb = planeshape.BoundBox bbperim = Part.makeBox(bb.XLength, bb.YLength, 1, Vector(bb.XMin, bb.YMin, bb.ZMin), Vector(0, 0, 1)) contourwire = TechDraw.findShapeOutline(bbperim, 1, Vector(0, 0, 1)) else: contourwire = TechDraw.findShapeOutline(planeshape, 1, Vector(0, 0, 1)) edgelist = contourwire.Edges edgelist = Part.__sortEdges__(edgelist) #use libarea to build the pattern a = area.Area() c = PathScripts.PathKurveUtils.makeAreaCurve(edgelist, 'CW') a.append(c) a.Reorder() output += self.buildpathlibarea(obj, a) path = Path.Path(output) obj.Path = path obj.ViewObject.Visibility = True
def execute(self, obj): output = "" toolLoad = PathUtils.getLastToolLoad(obj) if toolLoad is None or toolLoad.ToolNumber == 0: self.vertFeed = 100 self.horizFeed = 100 self.radius = 0.25 obj.ToolNumber = 0 obj.ToolDescription = "UNDEFINED" else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value tool = PathUtils.getTool(obj, toolLoad.ToolNumber) if tool.Diameter == 0: self.radius = 0.25 else: self.radius = tool.Diameter/2 obj.ToolNumber = toolLoad.ToolNumber obj.ToolDescription = toolLoad.Name output += "(" + obj.Label + ")" if obj.UserLabel == "": obj.Label = obj.Name + " :" + obj.ToolDescription else: obj.Label = obj.UserLabel + " :" + obj.ToolDescription if obj.Base: for b in obj.Base: for sub in b[1]: print "object base: " + str(b) import Part import PathScripts.PathKurveUtils if "Face" in sub: print "inside" shape = getattr(b[0].Shape, sub) wire = shape.OuterWire edges = wire.Edges else: print "in else" edges = [getattr(b[0].Shape, sub) for sub in b[1]] print "myedges: " + str(edges) wire = Part.Wire(edges) shape = None # output = "" if obj.Algorithm == "OCC Native": if shape is None: shape = wire output += self.buildpathocc(obj, shape) else: try: import area except: FreeCAD.Console.PrintError(translate("PathKurve", "libarea needs to be installed for this command to work.\n")) return a = area.Area() if shape is None: c = PathScripts.PathKurveUtils.makeAreaCurve(wire.Edges, 'CW') a.append(c) else: for w in shape.Wires: c = PathScripts.PathKurveUtils.makeAreaCurve(w.Edges, 'CW') a.append(c) a.Reorder() output += self.buildpathlibarea(obj, a) if obj.Active: path = Path.Path(output) obj.Path = path obj.ViewObject.Visibility = True else: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False
def profile2(curve, direction="on", radius=1.0, vertfeed=0.0, horizfeed=0.0, offset_extra=0.0, roll_radius=2.0, roll_on=None, roll_off=None, depthparams=None, extend_at_start=0.0, extend_at_end=0.0, lead_in_line_len=0.0, lead_out_line_len=0.0): from PathScripts.nc.nc import * global tags direction = direction.lower() offset_curve = area.Curve(curve) if direction == "on": use_CRC() == False if direction != "on": if direction != "left" and direction != "right": raise "direction must be left or right", direction # get tool diameter offset = radius + offset_extra if use_CRC() == False or (use_CRC() == True and CRC_nominal_path() == True): if math.fabs(offset) > 0.00005: if direction == "right": offset = -offset offset_success = offset_curve.Offset(offset) if offset_success == False: global using_area_for_offset if curve.IsClosed() and (using_area_for_offset == False): cw = curve.IsClockwise() using_area_for_offset = True a = area.Area() a.append(curve) a.Offset(-offset) for curve in a.getCurves(): curve_cw = curve.IsClockwise() if cw != curve_cw: curve.Reverse() set_good_start_point(curve, False) profile(curve, direction, 0.0, 0.0, roll_radius, roll_on, roll_off, depthparams, extend_at_start, extend_at_end, lead_in_line_len, lead_out_line_len) using_area_for_offset = False return else: raise Exception, "couldn't offset kurve " + str( offset_curve) # extend curve if extend_at_start > 0.0: span = offset_curve.GetFirstSpan() new_start = span.p + span.GetVector(0.0) * (-extend_at_start) new_curve = area.Curve() new_curve.append(new_start) for vertex in offset_curve.getVertices(): new_curve.append(vertex) offset_curve = new_curve if extend_at_end > 0.0: span = offset_curve.GetLastSpan() new_end = span.v.p + span.GetVector(1.0) * extend_at_end offset_curve.append(new_end) # remove tags further than radius from the offset kurve new_tags = [] for tag in tags: if tag.dist(offset_curve) <= radius + 0.001: new_tags.append(tag) tags = new_tags if offset_curve.getNumVertices() <= 1: raise "sketch has no spans!" # do multiple depths depths = depthparams.get_depths() current_start_depth = depthparams.start_depth # tags if len(tags) > 0: # make a copy to restore to after each level copy_of_offset_curve = area.Curve(offset_curve) prev_depth = depthparams.start_depth endpoint = None for depth in depths: mat_depth = prev_depth if len(tags) > 0: split_for_tags(offset_curve, radius, depthparams.start_depth, depth, depthparams.final_depth) # make the roll on and roll off kurves roll_on_curve = area.Curve() add_roll_on(offset_curve, roll_on_curve, direction, roll_radius, offset_extra, roll_on) roll_off_curve = area.Curve() add_roll_off(offset_curve, roll_off_curve, direction, roll_radius, offset_extra, roll_off) if use_CRC(): crc_start_point = area.Point() add_CRC_start_line(offset_curve, roll_on_curve, roll_off_curve, radius, direction, crc_start_point, lead_in_line_len) # get the tag depth at the start start_z = get_tag_z_for_span(0, offset_curve, radius, depthparams.start_depth, depth, depthparams.final_depth) if start_z > mat_depth: mat_depth = start_z # rapid across to the start s = roll_on_curve.FirstVertex().p # start point if (endpoint == None) or (endpoint != s): if use_CRC(): rapid(crc_start_point.x, crc_start_point.y) else: rapid(s.x, s.y) # rapid down to just above the material if endpoint == None: rapid(z=mat_depth + depthparams.rapid_safety_space) else: rapid(z=mat_depth) # feed down to depth mat_depth = depth if start_z > mat_depth: mat_depth = start_z feed(z=mat_depth) if use_CRC(): start_CRC(direction == "left", radius) # move to the startpoint feed(s.x, s.y) # cut the roll on arc cut_curve(roll_on_curve) # cut the main kurve current_perim = 0.0 for span in offset_curve.GetSpans(): # height for tags current_perim += span.Length() ez = get_tag_z_for_span(current_perim, offset_curve, radius, depthparams.start_depth, depth, depthparams.final_depth) if span.v.type == 0: #line feed(span.v.p.x, span.v.p.y, ez) else: if span.v.type == 1: # anti-clockwise arc arc_ccw(span.v.p.x, span.v.p.y, ez, i=span.v.c.x, j=span.v.c.y) else: arc_cw(span.v.p.x, span.v.p.y, ez, i=span.v.c.x, j=span.v.c.y) # cut the roll off arc cut_curve(roll_off_curve) endpoint = offset_curve.LastVertex().p if roll_off_curve.getNumVertices() > 0: endpoint = roll_off_curve.LastVertex().p #add CRC end_line if use_CRC(): crc_end_point = area.Point() add_CRC_end_line(offset_curve, roll_on_curve, roll_off_curve, radius, direction, crc_end_point, lead_out_line_len) if direction == "on": rapid(z=depthparams.clearance_height) else: feed(crc_end_point.x, crc_end_point.y) # restore the unsplit kurve if len(tags) > 0: offset_curve = area.Curve(copy_of_offset_curve) if use_CRC(): end_CRC() if endpoint != s: # rapid up to the clearance height rapid(z=depthparams.clearance_height) prev_depth = depth rapid(z=depthparams.clearance_height) del offset_curve if len(tags) > 0: del copy_of_offset_curve
def load_file(self, path, nameonly=False, decodewrap=False): """引数のファイル(wid, wsmファイル)を読み込む。""" try: f = cwfile.CWFile(path, "rb", decodewrap=decodewrap) no = nameonly md = self.materialdir ie = self.image_export if path.lower().endswith(".wsm"): data = summary.Summary(None, f, nameonly=no, materialdir=md, image_export=ie) data.skintype = self.skintype else: filetype = f.byte() f.seek(0) f.filedata = [] if filetype == 0: data = area.Area(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 1: data = battle.Battle(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 2: if os.path.basename(path).lower().startswith("battle"): data = battle.Battle(None, f, nameonly=no, materialdir=md, image_export=ie) else: data = cast.CastCard(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 3: data = item.ItemCard(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 4: lpath = os.path.basename(path).lower() if lpath.startswith("package"): data = package.Package(None, f, nameonly=no, materialdir=md, image_export=ie) elif lpath.startswith("mate"): data = cast.CastCard(None, f, nameonly=no, materialdir=md, image_export=ie) else: data = info.InfoCard(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 5: if os.path.basename(path).lower().startswith("item"): data = item.ItemCard(None, f, nameonly=no, materialdir=md, image_export=ie) else: data = skill.SkillCard(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 6: if os.path.basename(path).lower().startswith("info"): data = info.InfoCard(None, f, nameonly=no, materialdir=md, image_export=ie) else: data = beast.BeastCard(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 7: data = skill.SkillCard(None, f, nameonly=no, materialdir=md, image_export=ie) elif filetype == 8: data = beast.BeastCard(None, f, nameonly=no, materialdir=md, image_export=ie) else: f.close() raise ValueError(path) if not nameonly: # 読み残し分を全て読み込む f.read() f.close() return data, "".join(f.filedata) except: cw.util.print_ex() return None, None
def pocket(a,tool_radius, extra_offset, stepover, depthparams, from_center, keep_tool_down_if_poss, use_zig_zag, zig_angle, zig_unidirectional = False,start_point=None, cut_mode = 'conventional', entry_style = 'plunge'): global tool_radius_for_pocket global area_for_feed_possible #if len(a.getCurves()) > 1: # for crv in a.getCurves(): # ar = area.Area() # ar.append(crv) # pocket(ar, tool_radius, extra_offset, rapid_safety_space, start_depth, final_depth, stepover, stepdown, clearance_height, from_center, keep_tool_down_if_poss, use_zig_zag, zig_angle, zig_unidirectional) # return tool_radius_for_pocket = tool_radius if keep_tool_down_if_poss: area_for_feed_possible = area.Area(a) area_for_feed_possible.Offset(extra_offset - 0.01) use_internal_function = (area.holes_linked() == False) # use internal function, if area module is the Clipper library if use_internal_function: curve_list = a.MakePocketToolpath(tool_radius, extra_offset, stepover, from_center, use_zig_zag, zig_angle) else: global sin_angle_for_zigs global cos_angle_for_zigs global sin_minus_angle_for_zigs global cos_minus_angle_for_zigs radians_angle = zig_angle * math.pi / 180 sin_angle_for_zigs = math.sin(-radians_angle) cos_angle_for_zigs = math.cos(-radians_angle) sin_minus_angle_for_zigs = math.sin(radians_angle) cos_minus_angle_for_zigs = math.cos(radians_angle) arealist = list() a_offset = area.Area(a) current_offset = tool_radius + extra_offset a_offset.Offset(current_offset) do_recursive = True if use_zig_zag: zigzag(a_offset, stepover, zig_unidirectional) curve_list = curve_list_for_zigs else: if do_recursive: recur(arealist, a_offset, stepover, from_center) else: while(a_offset.num_curves() > 0): if from_center: arealist.insert(0, a_offset) else: arealist.append(a_offset) current_offset = current_offset + stepover a_offset = area.Area(a) a_offset.Offset(current_offset) curve_list = get_curve_list(arealist, cut_mode == 'climb') depths = depthparams.get_depths() current_start_depth = depthparams.start_depth if start_point==None: for depth in depths: cut_curvelist1(curve_list, depthparams.rapid_safety_space, current_start_depth, depth, depthparams.clearance_height, keep_tool_down_if_poss, entry_style) current_start_depth = depth else: for depth in depths: cut_curvelist2(curve_list, depthparams.rapid_safety_space, current_start_depth, depth, depthparams.clearance_height, keep_tool_down_if_poss, start_point) current_start_depth = depth
def pocket(a, tool_radius, extra_offset, rapid_safety_space, start_depth, final_depth, stepover, stepdown, clearance_height, from_center, keep_tool_down_if_poss, use_zig_zag, zig_angle, zig_unidirectional=False, start_point=None): global tool_radius_for_pocket global area_for_feed_possible tool_radius_for_pocket = tool_radius if keep_tool_down_if_poss: area_for_feed_possible = area.Area(a) area_for_feed_possible.Offset(extra_offset - 0.01) if rapid_safety_space > clearance_height: rapid_safety_space = clearance_height use_internal_function = ( area.holes_linked() == False ) # use internal function, if area module is the Clipper library if use_internal_function: curve_list = a.MakePocketToolpath(tool_radius, extra_offset, stepover, from_center, use_zig_zag, zig_angle) else: global sin_angle_for_zigs global cos_angle_for_zigs global sin_minus_angle_for_zigs global cos_minus_angle_for_zigs radians_angle = zig_angle * math.pi / 180 sin_angle_for_zigs = math.sin(-radians_angle) cos_angle_for_zigs = math.cos(-radians_angle) sin_minus_angle_for_zigs = math.sin(radians_angle) cos_minus_angle_for_zigs = math.cos(radians_angle) arealist = list() a_offset = area.Area(a) current_offset = tool_radius + extra_offset a_offset.Offset(current_offset) do_recursive = True if use_zig_zag: zigzag(a_offset, stepover, zig_unidirectional) curve_list = curve_list_for_zigs else: if do_recursive: recur(arealist, a_offset, stepover, from_center) else: while (a_offset.num_curves() > 0): if from_center: arealist.insert(0, a_offset) else: arealist.append(a_offset) current_offset = current_offset + stepover a_offset = area.Area(a) a_offset.Offset(current_offset) curve_list = get_curve_list(arealist) layer_count = int((start_depth - final_depth) / stepdown) if layer_count * stepdown + 0.00001 < start_depth - final_depth: layer_count += 1 current_start_depth = start_depth if start_point == None: for i in range(1, layer_count + 1): if i == layer_count: depth = final_depth else: depth = start_depth - i * stepdown cut_curvelist1(curve_list, rapid_safety_space, current_start_depth, depth, clearance_height, keep_tool_down_if_poss) current_start_depth = depth else: for i in range(1, layer_count + 1): if i == layer_count: depth = final_depth else: depth = start_depth - i * stepdown cut_curvelist2(curve_list, rapid_safety_space, current_start_depth, depth, clearance_height, keep_tool_down_if_poss, start_point) current_start_depth = depth
def execute(self, obj): PathLog.track() output = "" toolLoad = obj.ToolController if toolLoad is None or toolLoad.ToolNumber == 0: FreeCAD.Console.PrintError("No Tool Controller is selected. We need a tool to build a Path.") return else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = toolLoad.Proxy.getTool(toolLoad) if tool.Diameter == 0: FreeCAD.Console.PrintError("No Tool found or diameter is zero. We need a tool to build a Path.") return else: self.radius = tool.Diameter/2 # Build preliminary comments output = "" output += "(" + obj.Label + ")" # Facing is done either against base objects if obj.Base: PathLog.debug("obj.Base: {}".format(obj.Base)) faces = [] for b in obj.Base: for sub in b[1]: shape = getattr(b[0].Shape, sub) if isinstance(shape, Part.Face): faces.append(shape) else: PathLog.debug('The base subobject is not a face') return planeshape = Part.makeCompound(faces) PathLog.info("Working on a collection of faces {}".format(faces)) # If no base object, do planing of top surface of entire model else: parentJob = PathUtils.findParentJob(obj) if parentJob is None: PathLog.debug("No base object. No parent job found") return baseobject = parentJob.Base if baseobject is None: PathLog.debug("Parent job exists but no Base Object") return planeshape = baseobject.Shape PathLog.info("Working on a shape {}".format(baseobject.Name)) # if user wants the boundbox, calculate that PathLog.info("Boundary Shape: {}".format(obj.BoundaryShape)) if obj.BoundaryShape == 'Boundbox': bb = planeshape.BoundBox bbperim = Part.makeBox(bb.XLength, bb.YLength, 1, Vector(bb.XMin, bb.YMin, bb.ZMin), Vector(0, 0, 1)) contourwire = TechDraw.findShapeOutline(bbperim, 1, Vector(0, 0, 1)) else: contourwire = TechDraw.findShapeOutline(planeshape, 1, Vector(0, 0, 1)) # pocket = Path.Area(PocketMode=4,SectionCount=-1,SectionMode=1,Stepdown=0.499) # pocket.setParams(PocketExtraOffset = obj.PassExtension.Value, ToolRadius = self.radius) # pocket.add(planeshape, op=1) # #Part.show(contourwire) # path = Path.fromShapes(pocket.getShape()) edgelist = contourwire.Edges edgelist = Part.__sortEdges__(edgelist) # use libarea to build the pattern a = area.Area() c = PathScripts.PathKurveUtils.makeAreaCurve(edgelist, 'CW') PathLog.debug(c.text()) a.append(c) a.Reorder() output += self.buildpathlibarea(obj, a) path = Path.Path(output) if len(path.Commands) == 0: FreeCAD.Console.PrintMessage(translate("PathMillFace", "The selected settings did not produce a valid path.\n")) obj.Path = path obj.ViewObject.Visibility = True
def execute(self, obj): output = "" toolLoad = obj.ToolController if toolLoad is None or toolLoad.ToolNumber == 0: FreeCAD.Console.PrintError( "No Tool Controller is selected. We need a tool to build a Path." ) else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = toolLoad.Proxy.getTool(toolLoad) if not tool or tool.Diameter == 0: FreeCAD.Console.PrintError( "No Tool found or diameter is zero. We need a tool to build a Path." ) return else: self.radius = tool.Diameter / 2 if obj.Base: for b in obj.Base: for sub in b[1]: import Part import PathScripts.PathKurveUtils if "Face" in sub: shape = getattr(b[0].Shape, sub) wire = shape.OuterWire edges = wire.Edges else: edges = [getattr(b[0].Shape, sub) for sub in b[1]] wire = Part.Wire(edges) shape = None # output = "" if obj.Algorithm == "OCC Native": if shape is None: shape = wire output += self.buildpathocc(obj, shape) else: try: import area except: FreeCAD.Console.PrintError( translate( "PathKurve", "libarea needs to be installed for this command to work.\n" )) return a = area.Area() if shape is None: c = PathScripts.PathKurveUtils.makeAreaCurve( wire.Edges, 'CW') a.append(c) else: for w in shape.Wires: c = PathScripts.PathKurveUtils.makeAreaCurve( w.Edges, 'CW') a.append(c) a.Reorder() output += self.buildpathlibarea(obj, a) if obj.Active: path = Path.Path(output) obj.Path = path obj.ViewObject.Visibility = True else: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False
def zigzag(a, a_firstoffset, stepover): if a.num_curves() == 0: return global rightward_for_zigs global curve_list_for_zigs global test_count global sin_angle_for_zigs global cos_angle_for_zigs global sin_minus_angle_for_zigs global cos_minus_angle_for_zigs a = rotated_area(a) b = area.Box() a.GetBox(b) #x0 = b.MinX() - 1.0 #x1 = b.MaxX() + 1.0 x1 = b.MinX() - 1.0 x0 = b.MaxX() + 1.0 height = b.MaxY() - b.MinY() num_steps = int(height / stepover + 1) #y = b.MinY() + 0.1 y = b.MaxY() - 0.1 null_point = area.Point(0, 0) rightward_for_zigs = True curve_list_for_zigs = [] test_count = 0 for i in range(0, num_steps): #collect vertices for a box shape from X+,Y+ toward the curve #then move the tool Y+ and then back toward the X start position # -------> # | # -------< test_count = test_count + 1 y0 = y #y = y + stepover y = y - stepover p0 = area.Point(x0, y0) p1 = area.Point(x0, y) p2 = area.Point(x1, y) p3 = area.Point(x1, y0) c = area.Curve() c.append(area.Vertex(0, p0, null_point, 0)) c.append(area.Vertex(0, p1, null_point, 0)) c.append(area.Vertex(0, p2, null_point, 1)) c.append(area.Vertex(0, p3, null_point, 0)) c.append(area.Vertex(0, p0, null_point, 1)) a2 = area.Area() a2.append(c) a2.Intersect(a) rightward_for_zigs = (rightward_for_zigs == False) y10 = y + stepover #y = y + stepover y2 = y + stepover * 2 p10 = area.Point(x0, y10) p11 = area.Point(x0, y2) p12 = area.Point(x1, y2) p13 = area.Point(x1, y10) c2 = area.Curve() c2.append(area.Vertex(0, p10, null_point, 0)) c2.append(area.Vertex(0, p11, null_point, 0)) c2.append(area.Vertex(0, p12, null_point, 1)) c2.append(area.Vertex(0, p13, null_point, 0)) c2.append(area.Vertex(0, p10, null_point, 1)) a3 = area.Area() a3.append(c2) a3.Intersect(a) make_zig(a3, y0, y) rightward_for_zigs = (rightward_for_zigs == False) reorder_zigs()
def __init__(self): # Initialize white cards white_cards = [ card.Card(title="Mystic Compass", desc=("When you move, you may roll twice " "and choose which result to use."), color=0, holder=None, is_equip=True, use=None), card.Card( title="Talisman", desc=("You receive no damage from Black cards" " 'Bloodthirsty Spider', 'Vampire Bat', or 'Dynamite'."), color=0, holder=None, is_equip=True, use=None), card.Card(title="Fortune Brooch", desc=("You receive no damage from the area card" " 'Weird Woods'. You can still be healed by it."), color=0, holder=None, is_equip=True, use=None), card.Card(title="Silver Rosary", desc=("If you kill another character, " "you take all of their equipment cards."), color=0, holder=None, is_equip=True, use=None), card.Card( title="Spear of Longinus", desc=("If you are a Hunter who has revealed their identity and" " your attack is successful, you give 2 points of extra" " damage."), color=0, holder=None, is_equip=True, use=None), card.Card( title="Advent", desc=("If you are a Hunter, you may reveal your identity. " "If you do, or if you are already revealed," " you heal fully."), color=0, holder=None, is_equip=False, use=single_use.advent), card.Card(title="Disenchant Mirror", desc=("If you are a Shadow, except for Unknown, " "you must reveal your identity."), color=0, holder=None, is_equip=False, use=single_use.disenchant_mirror), card.Card( title="Blessing", desc=("Pick a character other than yourself and roll the" " 6-sided die. That character heals an amount of damage" " equal to the die roll."), color=0, holder=None, is_equip=False, use=single_use.blessing), card.Card(title="Chocolate", desc=("If you are Allie, Agnes, Emi, Ellen, Unknown," " or Ultra Soul, you may reveal your identity. " "If you do, or if you are already revealed, " "you heal fully."), color=0, holder=None, is_equip=False, use=single_use.chocolate), card.Card( title="Concealed Knowledge", desc="When this turn is over, it will be your turn again.", color=0, holder=None, is_equip=False, use=single_use.concealed_knowledge), card.Card( title="Guardian Angel", desc=("You take no damage from the direct attacks of " "other characters until the start of your next turn."), color=0, holder=None, is_equip=False, use=single_use.guardian_angel), card.Card( title="Holy Robe", desc=("Your attacks do 1 less damage and the amount of" " damage you receive from attacks is reduced by" " 1 point."), color=0, # 0 : WHITE holder=None, is_equip=True, use=lambda is_attack, successful, amt: max( 0, amt - 1) # applies to both attack and defend ), card.Card(title="Flare of Judgement", desc=("All characters except yourself" " receive 2 points of damage."), color=0, holder=None, is_equip=False, use=single_use.judgement), card.Card(title="First Aid", desc=("Place a character's damage marker to 7" " (You can choose yourself)."), color=0, holder=None, is_equip=False, use=single_use.first_aid), card.Card(title="Holy Water of Healing", desc="Heal 2 points of your damage.", color=0, holder=None, is_equip=False, use=single_use.holy_water), card.Card(title="Holy Water of Healing", desc="Heal 2 points of your damage.", color=0, holder=None, is_equip=False, use=single_use.holy_water) ] # Initialize black cards black_cards = [ card.Card( title="Cursed Sword Masamune", desc=("You must attack another character on your turn." " This attack uses the 4-sided die."), color=1, # 1 : BLACK holder=None, is_equip=True, use=None), card.Card(title="Machine Gun", desc=("Your attack will affect all characters in your" " attack range (the dice are rolled only once)."), color=1, holder=None, is_equip=True, use=None), card.Card(title="Handgun", desc="All ranges but yours become your attack range.", color=1, holder=None, is_equip=True, use=None), card.Card(title="Butcher Knife", desc=("If your attack is successful, " "you give 1 point of extra damage."), color=1, holder=None, is_equip=True, use=lambda is_attack, successful, amt: amt + 1 if (is_attack and successful) else amt), card.Card(title="Chainsaw", desc=("If your attack is successful, " "you give 1 point of extra damage."), color=1, holder=None, is_equip=True, use=lambda is_attack, successful, amt: amt + 1 if (is_attack and successful) else amt), card.Card(title="Rusted Broad Axe", desc=("If your attack is successful, " "you give 1 point of extra damage."), color=1, holder=None, is_equip=True, use=lambda is_attack, successful, amt: amt + 1 if (is_attack and successful) else amt), card.Card(title="Moody Goblin", desc="You steal an equipment card from any character.", color=1, holder=None, is_equip=False, use=single_use.moody_goblin), card.Card(title="Moody Goblin", desc="You steal an equipment card from any character.", color=1, holder=None, is_equip=False, use=single_use.moody_goblin), card.Card(title="Bloodthirsty Spider", desc=("You give 2 points of damage to any character" " and receive 2 points of damage yourself."), color=1, holder=None, is_equip=False, use=single_use.bloodthirsty_spider), card.Card(title="Vampire Bat", desc=("You give 2 points of damage to any character" " and heal 1 point of your own damage."), color=1, holder=None, is_equip=False, use=single_use.vampire_bat), card.Card(title="Vampire Bat", desc=("You give 2 points of damage to any character" " and heal 1 point of your own damage."), color=1, holder=None, is_equip=False, use=single_use.vampire_bat), card.Card(title="Vampire Bat", desc=("You give 2 points of damage to any character" " and heal 1 point of your own damage."), color=1, holder=None, is_equip=False, use=single_use.vampire_bat), card.Card( title="Diabolic Ritual", desc=("If you are a Shadow, you may reveal your identity." " If you do, you fully heal you damage."), color=1, holder=None, is_equip=False, use=single_use.diabolic_ritual), card.Card( title="Banana Peel", desc=("Give one of your equipment cards to another character. " "If you have no equipment cards," " you receive 1 point of damage."), color=1, holder=None, is_equip=False, use=single_use.banana_peel), card.Card(title="Dynamite", desc=("Roll 2 dice and give 3 points of damage to all" " characters in the area designated " "by the total number rolled " "(nothing happens if a 7 is rolled)."), color=1, holder=None, is_equip=False, use=single_use.dynamite), card.Card(title="Spiritual Doll", desc=("Pick a character and roll the 6-sided die. " "If the die number is 1 to 4, " "you give 3 points of damage to that character. " "If the die number is 5 or 6, " "you get 3 points of damage."), color=1, holder=None, is_equip=False, use=single_use.spiritual_doll) ] # Initialize hermit cards green_cards = [ card.Card( title="Hermit\'s Blackmail", desc=("I bet you're either a Neutral or a Hunter. " "If so, you must either give an Equipment card" " to the current player or receive 1 damage!"), color=2, # 2 : GREEN holder=None, is_equip=False, use=hermit.blackmail), card.Card(title="Hermit\'s Blackmail", desc=("I bet you're either a Neutral or a Hunter. " "If so, you must either give an Equipment card" " to the current player or receive 1 damage!"), color=2, holder=None, is_equip=False, use=hermit.blackmail), card.Card(title="Hermit\'s Greed", desc=("I bet you're either a Neutral or a Shadow. " "If so, you must either give an Equipment card" " to the current player or receive 1 damage!"), color=2, holder=None, is_equip=False, use=hermit.greed), card.Card(title="Hermit\'s Greed", desc=("I bet you're either a Neutral or a Shadow. " "If so, you must either give an Equipment card" " to the current player or receive 1 damage!"), color=2, holder=None, is_equip=False, use=hermit.greed), card.Card(title="Hermit\'s Anger", desc=("I bet you're either a Hunter or a Shadow. " "If so, you must either give an Equipment card" " to the current player or receive 1 damage!"), color=2, holder=None, is_equip=False, use=hermit.anger), card.Card(title="Hermit\'s Anger", desc=("I bet you're either a Hunter or a Shadow. " "If so, you must either give an Equipment card" " to the current player or receive 1 damage!"), color=2, holder=None, is_equip=False, use=hermit.anger), card.Card( title="Hermit\'s Slap", desc="I bet you're a Hunter. If so, you receive 1 damage!", color=2, holder=None, is_equip=False, use=hermit.slap), card.Card( title="Hermit\'s Slap", desc="I bet you're a Hunter. If so, you receive 1 damage!", color=2, holder=None, is_equip=False, use=hermit.slap), card.Card( title="Hermit\'s Spell", desc="I bet you're a Shadow. If so, you receive 1 damage!", color=2, holder=None, is_equip=False, use=hermit.spell), card.Card( title="Hermit\'s Exorcism", desc="I bet you're a Shadow. If so, you receive 2 damage!", color=2, holder=None, is_equip=False, use=hermit.exorcism), card.Card( title="Hermit\'s Nurturance", desc=("I bet you're a Neutral. If so, you heal 1 damage! " "(However, if you have no damage, " "then you receive 1 damage!)"), color=2, holder=None, is_equip=False, use=hermit.nurturance), card.Card(title="Hermit\'s Aid", desc=("I bet you're a Hunter. If so, you heal 1 damage! " "(However, if you have no damage, " "then you receive 1 damage!)"), color=2, holder=None, is_equip=False, use=hermit.aid), card.Card(title="Hermit\'s Huddle", desc=("I bet you're a Shadow. If so, you heal 1 damage! " "(However, if you have no damage, " "then you receive 1 damage!)"), color=2, holder=None, is_equip=False, use=hermit.huddle), card.Card(title="Hermit\'s Lesson", desc=("I bet your maximum HP is 12 or more. " "If so, you receive 2 damage!"), color=2, holder=None, is_equip=False, use=hermit.lesson), card.Card(title="Hermit\'s Bully", desc=("I bet your maximum HP is 11 or less. " "If so, you receive 1 damage!"), color=2, holder=None, is_equip=False, use=hermit.bully), card.Card(title="Hermit\'s Prediction", desc=("You must reveal your character information " "secretly to the current player!"), color=2, holder=None, is_equip=False, use=hermit.prediction) ] # Initialize white, black, hermit decks self.WHITE_DECK = deck.Deck(cards=white_cards) self.BLACK_DECK = deck.Deck(cards=black_cards) self.GREEN_DECK = deck.Deck(cards=green_cards) # Initialize characters self.CHARACTERS = [ character.Character( name="Valkyrie", alleg=0, # Shadow max_damage=13, win_cond=win_conditions.shadow, win_cond_desc="All of the Hunters (or 3 Neutrals) are dead.", special=specials.valkyrie, special_desc=("When you attack, you only roll the 4-sided die" " and inflict the amount of damage rolled."), resource_id="valkyrie"), character.Character( name="Vampire", alleg=0, # Shadow max_damage=13, win_cond=win_conditions.shadow, win_cond_desc="All of the Hunters (or 3 Neutrals) are dead.", special=specials.vampire, special_desc=("If you attack a player and inflict damage, " "you heal 2 points of your own damage."), resource_id="vampire"), character.Character( name="Werewolf", alleg=0, # Shadow max_damage=14, win_cond=win_conditions.shadow, win_cond_desc="All of the Hunters (or 3 Neutrals) are dead.", special=specials.werewolf, special_desc=("After you are attacked, " "you can counterattack immediately."), resource_id="werewolf"), character.Character( name="Ultra Soul", alleg=0, # Shadow max_damage=11, win_cond=win_conditions.shadow, win_cond_desc="All of the Hunters (or 3 Neutrals) are dead.", special=specials.ultra_soul, special_desc=("When your turn starts, you can give 3 damage" " to one player who is at" " the Underworld Gate."), resource_id="ultra-soul"), character.Character( name="Allie", alleg=1, # Neutral max_damage=8, win_cond=win_conditions.allie, win_cond_desc="You're not dead when the game is over.", special=specials.allie, special_desc="Once per game, you may fully heal your damage.", resource_id="allie"), character.Character( name="Bob", alleg=1, # Neutral max_damage=10, win_cond=win_conditions.bob, win_cond_desc="You have 5 or more equipment cards.", special=specials.bob, special_desc=("If your attack inflicts 2 or more damage, " "you may steal an Equipment card from your" " target instead of giving damage."), resource_id="bob1", modifiers={ 'min_players': 4, 'max_players': 6 }), character.Character( name="Bob", alleg=1, # Neutral max_damage=10, win_cond=win_conditions.bob, win_cond_desc="You have 5 or more equipment cards.", special=specials.bob, special_desc=("If you kill another player, " "you may take all of their Equipment cards."), resource_id="bob2", modifiers={ 'min_players': 7, 'max_players': 8 }), character.Character( name="Catherine", alleg=1, # Neutral max_damage=11, win_cond=win_conditions.catherine, win_cond_desc=("You are either the first to die or one of the" " last two players alive."), special=specials.catherine, special_desc="When your turn starts, you heal 1 damage.", resource_id="catherine"), character.Character( name="George", alleg=2, # Hunter max_damage=14, win_cond=win_conditions.hunter, win_cond_desc="All of the Shadows are dead.", special=specials.george, special_desc=("Once per game, when your turn starts, you can" " pick a player and damage them for the" " roll of a 4-sided die."), resource_id="george"), character.Character( name="Fu-ka", alleg=2, # Hunter max_damage=12, win_cond=win_conditions.hunter, win_cond_desc="All of the Shadows are dead.", special=specials.fuka, special_desc=("Once per game, when your turn starts, " "you can set the damage of any player to 7."), resource_id="fu-ka"), character.Character( name="Franklin", alleg=2, # Hunter max_damage=12, win_cond=win_conditions.hunter, win_cond_desc="All of the Shadows are dead.", special=specials.franklin, special_desc=("Once per game, when your turn starts, " "you can pick a player and damage" " them for the roll of a 6-sided die."), resource_id="franklin"), character.Character( name="Ellen", alleg=2, # Hunter max_damage=10, win_cond=win_conditions.hunter, win_cond_desc="All of the Shadows are dead.", special=specials.ellen, special_desc=("Once per game, when your turn starts, " "you can choose a player and permanently" " void their special ability."), resource_id="ellen"), # previously unimplemented official expansion characters start here character.Character( name="Agnes", alleg=1, # Neutral max_damage=8, win_cond=win_conditions.agnes, win_cond_desc="The player to your immediate right wins.", special=specials.agnes, special_desc=("Can only be used at the start of your turn. " "Changes your win condition to \'The player to " "your immediate left wins.\'"), resource_id="agnes"), character.Character( name="Bryan", alleg=1, # Neutral max_damage=10, win_cond=win_conditions.bryan, win_cond_desc=("Your attack kills a character whose HP " "is 13 or more OR you are on the Erstwhile " "Altar when the game is over."), special=specials.bryan, special_desc=("If your attack kills a character whose HP " "is 12 or less, you must reveal your identity."), resource_id="bryan"), character.Character( name="Charles", alleg=1, # Neutral max_damage=11, win_cond=win_conditions.charles, win_cond_desc=("At the time you kill another character, " "the total number of dead characters " "is 3 or more."), special=specials.charles, special_desc=("After you attack, you may give yourself 2 " "points of damage to attack the same " "character again."), resource_id="charles"), character.Character( name="Daniel", alleg=1, # Neutral max_damage=13, win_cond=win_conditions.daniel, win_cond_desc=("You are the first character to die OR " "all the Shadow characters are dead " "and you are not."), special=specials.daniel, special_desc=("As soon as another character dies, " "you must reveal your identity."), resource_id="daniel"), character.Character( name="David", alleg=1, # Neutral max_damage=13, win_cond=win_conditions.david, win_cond_desc=("You have 3 or more of the following: " "\'Talisman\', \'Spear of Longinus\', " "\'Holy Robe\', \'Silver Rosary\'."), special=specials.david, special_desc=("You may take one Equipment card " "of your choice from any discard " "pile. Only once per game."), resource_id="david"), character.Character( name="Emi", alleg=2, # Hunter max_damage=10, win_cond=win_conditions.hunter, win_cond_desc="All the Shadow characters are dead. ", special=specials.emi, special_desc=("When you move, you can roll dice " "as normal or move to an adjacent " "Area Card."), resource_id="emi"), character.Character( name="Gregor", alleg=2, # Hunter max_damage=10, win_cond=win_conditions.hunter, win_cond_desc="All the Shadow characters are dead. ", special=specials.gregor, special_desc=("Can only be used when your turn " "is over. You cannot receive any " "damage until the start of your " "next turn."), resource_id="gregor"), character.Character( name="Wight", alleg=0, # Shadow max_damage=14, win_cond=win_conditions.shadow, win_cond_desc="All of the Hunters (or 3 Neutrals) are dead.", special=specials.wight, special_desc=("When your turn is over, you may " "take an additional number of turns " "equal to the amount of dead characters. " "Once per game."), resource_id="wight"), character.Character( name="Unknown", alleg=0, # Shadow max_damage=11, win_cond=win_conditions.shadow, win_cond_desc="All of the Hunters (or 3 Neutrals) are dead.", special=specials.unknown, special_desc=("You may lie when given a Hermit card. " "You don't have to reveal your identity " "to do this."), resource_id="unknown"), ] # Initialize areas self.AREAS = [ area.Area( name="Hermit's Cabin", desc="Draw a Hermit Card.", domain=[2, 3], action=lambda gc, player: player.drawCard(gc.green_cards), resource_id="hermits-cabin"), area.Area(name="Underworld Gate", desc="Draw a card from the deck of your choice.", domain=[4, 5], action=area.underworld_gate_action, resource_id="underworld-gate"), area.Area( name="Church", desc="Draw a White Card.", domain=[6], action=lambda gc, player: player.drawCard(gc.white_cards), resource_id="church"), area.Area( name="Cemetery", desc="Draw a Black Card.", domain=[8], action=lambda gc, player: player.drawCard(gc.black_cards), resource_id="cemetery"), area.Area(name="Weird Woods", desc="Heal 1 damage or give 2 damage to any player.", domain=[9], action=area.weird_woods_action, resource_id="weird-woods"), area.Area(name="Erstwhile Altar", desc="Steal an equipment card from any player.", domain=[10], action=area.erstwhile_altar_action, resource_id="erstwhile-altar") ]
if not self.available(coord): return False toAdd.add(coord) for coord in toAdd: self.layout.set(coord, room) return True class AltPacker(object): def __init__(self, area): self.area = area if __name__ == "__main__": p = Packer(area.Area(0, 0, 20, 20)) p.addRoom(1) p.addRoom(5) p.pack() a = area.Area(-20, -20, -1, -1) p = Packer(a) for x in xrange(5): p.addRoom(1) p.pack() print p.layout
#!/usr/bin/env python3 import area import character import random currentArea = area.Area() player = character.Player() def playerTurn(): command = input("What would you like to do:\n").lower() commandUnderstood = True if len(command.split()) == 1: if command in ['north', 'n']: currentArea.move('north') elif command in ['south', 's']: currentArea.move('south') elif command in ['east', 'e']: currentArea.move('east') elif command in ['west', 'w']: currentArea.move('west') elif command == 'up': currentArea.move('up') elif command == 'down': currentArea.move('down') elif command == 'examine': currentArea.examine() elif command == "status":