Example #1
0
    def __init__(self):
        self.id = next_id()
        self.tour = 0
        self.neutral = player('Neutral', 'Galaxy', I('mutant'), 0)
        self.players = dict()
        self.players[self.neutral.id] = self.neutral
        self.technos, self.def_ships = static_create(self.neutral)
        self.tmpscheme = dict()

        self.schemes = dict() # hold all schemes, def_ships contain standart ships
        for sc in self.def_ships.itervalues():
            self.schemes[sc.id] = sc

        self.systems_p = dict()        # mapping by position
        self.systems_i = dict()        # mapping by id
        count = 0
        while count < conf.nsyst:
            position = (randint(-conf.bound, conf.bound), 
                        randint(-conf.bound, conf.bound))
            if position in self.systems_p:
                continue
            
            syst = system(position, self.neutral)
            self.systems_p[position] = syst
            self.systems_i[syst.id] = syst
            count += 1
Example #2
0
 def __init__(self, pos, neutral):
     self.id = next_id()
     self.position = pos
     self.assets = dict()
     a = asset(neutral, self)
     a.populate()
     self.assets[a.id] = a
Example #3
0
 def __init__(self, what, count, target):
     self.id = next_id()
     self.what = what
     self.poc = count * what.get_carac(I('poc'))
     assert(self.poc > 0)
     self.count = count
     assert(self.count > 0)
     self.target = target
Example #4
0
 def __init__(self, name, ha, sa, pa, velocity, scope):
     self.id = next_id()
     self.name = name
     self.sa = sa
     self.ha = ha
     self.pa = pa
     self.velocity = velocity
     self.scope = scope
     self.accuracy = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
Example #5
0
 def __init__(self, owner, name, brand, domain, cut): # domain public/private/alliance
     self.id = next_id()
     self.name = name
     self.brand = brand
     self.domain = domain
     self.cut = cut
     self.owner = owner
     self.compos = dict()
     self.caracs = dict()
     self.merchs = dict()
     self.valid = True
Example #6
0
 def __init__(self, owner, name, pos, guideline=I('neutral'), target=None):
     self.id = next_id()
     self.name = name
     self.owner = owner
     self.compos = dict()     # (vso, race) -> (nombre, degats)
     self.caracs = dict()
     self.cargo = dict()
     self.position = pos
     self.move = None        # position destination
     self.caracs[I('behaviour')] = guideline
     self.caracs[I('target')] = target
Example #7
0
 def __init__(self, owner, syst):
     self.id = next_id()
     self.owner = owner
     self.referer = syst
     self.name = random_string()
     self.planets = dict()    #rule : pla1.id < pla2.id <=> pla1.position < pla2.position
     self.culture = 0
     self.merchs = dict()
     self.policy = I('tax')
     self.constructions = dict() 
     self.poc = 0
     self.ore = 0
     owner.add_asset(self)
     for m in F('goods'):
         self.merchs[m] = 0
Example #8
0
def makeassignment():
    user = asyncio.run(client.get_user(util.verify_headers(request.headers)))
    user_id = user.id
    class_id = request.form.get("classId", None)

    classroom = classroom_db.find_one({"id": int(class_id)})

    if classroom == None or user_id not in classroom["teachers"]:
        return abort(404)

    name = request.form.get("name", None)
    instructions = request.form.get("instructions", None)

    if not name or len(name.replace(" ", "")) == 0:
        return "Invalid Name"
    if not instructions or len(instructions.replace(" ", "")) == 0:
        return "Invalid Instructions"

    submissions = {}
    for student_id in classroom["students"]:
        submissions[str(student_id)] = {
            "status": "not viewed",
            "repl_url": None,
            "feedback": None
        }
    assignment_id = util.next_id(assignment_db.find())
    assignment_db.insert_one({
        "id": assignment_id,
        "name": name,
        "instructions": instructions,
        "modal_answer_url": None,
        "submissions": submissions
    })
    classroom_db.update_one({"id": int(class_id)},
                            {"$push": {
                                "assignments": assignment_id
                            }})

    return f"/classroom/{class_id}/{assignment_id}"
Example #9
0
    def __init__(self, pos, asset):
        self.id = next_id()
        self.referer = asset
        self.position = pos    # position of pla inside planet system
        self.atmosphere = choice(F('atmosphere'))
        self.caracs = (randint(1, 99), randint(1, 99)) # temp, rad
        self.size = randint(1, 5)
        self.structure = self.size*50 + randint(0, 100)
        self.terra = [ 0, False ]     # terra level, true si deja terra ce tour
        self.taxe = I('tax_norm')
        self.stab = [ 100, 100 ] # current stab, old stab
        self.ore = [randint(1, 5), randint(5, 10)]
        self.revolt = False
        self.constructions = dict()
        if not randint(0, 10):    # ~environ 10% de chance de prod
            self.merch = choice(F('goods'))
        else:
            self.merch = None

        self.pops = dict()
        pmax = self.get_popmax(I('mutant'))
        self.pops[I('mutant')] = randint(pmax/2, 3*pmax/4)
Example #10
0
 def __init__(self, name, domain, race, tour):
     self.id = next_id()
     self.name = name
     self.domain = domain
     self.assets = dict()
     self.race = race
     self.capital = None
     self.technos = dict()
     self.cache_ftech = dict() # cache future techno
     self.research = dict() # recherche techno en cours | tech -> points
     self.started = tour
     self.alife = True
     self.schemes, self.tmpschemes = dict(), dict()
     self.limits = conf.limits.copy()     # limites personnelles
     self.state = dict()                 # etat courant des limits
     for l in self.limits:
         self.state[l] = 0
     self.fleets, self.tmpfleets = dict(), dict()
     self.percent = [0, 0, 0] # budget tech, special, contre esp
     self.bank = [20000, 0, 0] # centaure, points tech, points spe
     self.budgets = dict()
     self.msg = list()
     self.alliances = dict()
Example #11
0
def make_class():
    form = request.form
    files = request.files
    user = util.verify_headers(request.headers)

    name = form.get("name", None)
    language = form.get("language", None)
    description = form.get("description", None)
    classroom_pfp = files.get("classroom-pfp", None)
    try:
        Image.open(classroom_pfp)
    except:
        classroom_pfp = None

    classroom_id = str(util.next_id(classroom_db.find()))
    user = asyncio.run(client.get_user(user))
    user_id = user.id
    user_username = user.name
    user_pfp = user.avatar

    if len(name.replace(" ", "")) == 0 or not name:
        return "Invalid Name"
    if language.lower() not in util.langs:
        return "Invalid Language"
    if classroom_pfp != None and not util.allowed_file(classroom_pfp.filename):
        return "Invalid File Type"
    if len(description.replace(" ", "")) == 0:
        description = "A " + util.langs[
            language.lower()]["name"] + " classroom"

    if not classroom_pfp:
        cloud_img_url = "https://res.cloudinary.com/codingcactus/image/upload/v1611481743/classrooms/repl_logo_p9bqek.png"
    else:
        filename = classroom_id + "." + classroom_pfp.filename.split(".")[1]
        Image.open(classroom_pfp).convert("RGB").save(filename)
        r = cloudinary.uploader.upload(filename,
                                       folder="classrooms/",
                                       public_id=classroom_id,
                                       overwrite=True,
                                       resource_type="image")
        cloud_img_url = r["url"].replace("http://", "https://")
        os.remove(filename)

    classroom_db.insert_one({
        "id": int(classroom_id),
        "owner_id": user_id,
        "owner_username": user_username,
        "owner_pfp": user_pfp,
        "created": time.time(),
        "name": name,
        "language": language.lower(),
        "description": description,
        "classroom_pfp_url": cloud_img_url,
        "teachers": [user_id],
        "students": [],
        "assignments": [],
        "studentInviteLink": None,
        "studentInviteCode": None,
        "teacherInviteLink": None,
        "teacherInviteCode": None
    })
    user_db.update_one({"id": user_id},
                       {"$addToSet": {
                           "classrooms": int(classroom_id)
                       }})

    return f"/classroom/{classroom_id}/teachers"
Example #12
0
def clone():
    form = request.form
    files = request.files
    user = util.verify_headers(request.headers)

    clone_class_id = form.get("classId", None)
    name = form.get("name", None)
    description = form.get("description", None)
    classroom_pfp = files.get("classroom-pfp", None)
    try:
        Image.open(classroom_pfp)
    except:
        classroom_pfp = None

    classroom_id = str(util.next_id(classroom_db.find()))
    user = (asyncio.run(client.get_user(user)))
    user_id = user.id
    user_username = user.name
    user_pfp = user.avatar

    if clone_class_id: return abort(404)

    if len(name.replace(" ", "")) == 0 or not name:
        return "Invalid Name"
    if classroom_pfp != None and not util.allowed_file(classroom_pfp.filename):
        return "Invalid File Type"

    clone_classroom = classroom_db.find_one({"id": int(clone_class_id)})
    language = clone_classroom["language"]

    if len(description.replace(" ", "")) == 0:
        description = "A " + util.langs[
            language.lower()]["name"] + " classroom"

    if not classroom_pfp:
        cloud_img_url = clone_classroom["classroom_pfp_url"]
    else:
        filename = classroom_id + "." + classroom_pfp.filename.split(".")[1]
        Image.open(classroom_pfp).convert("RGB").save(filename)
        r = cloudinary.uploader.upload(filename,
                                       folder="classrooms/",
                                       public_id=classroom_id,
                                       overwrite=True,
                                       resource_type="image")
        cloud_img_url = r["url"].replace("http://", "https://")
        os.remove(filename)

    assignments = []
    assignment_ids = []
    next_id = util.next_id(assignment_db.find())
    loops = 0
    for assignment_id in clone_classroom["assignments"]:
        assignment = dict(assignment_db.find_one({"id": assignment_id}))
        del assignment["_id"]
        assignment["id"] = next_id + loops
        assignment["submissions"] = {}
        assignments.append(assignment)
        assignment_ids.append(next_id + loops)
        loops += 1

    assignment_db.insert_many(assignments)

    classroom_db.insert_one({
        "id": int(classroom_id),
        "owner_id": user_id,
        "owner_username": user_username,
        "owner_pfp": user_pfp,
        "created": time.time(),
        "name": name,
        "language": language.lower(),
        "description": description,
        "classroom_pfp_url": cloud_img_url,
        "teachers": [user_id],
        "students": [],
        "assignments": assignment_ids,
        "studentInviteLink": None,
        "studentInviteCode": None,
        "teacherInviteLink": None,
        "teacherInviteCode": None
    })
    user_db.update_one({"id": user_id},
                       {"$addToSet": {
                           "classrooms": int(classroom_id)
                       }})

    return f"/classroom/{classroom_id}/teachers"
Example #13
0
 def __init__(self, name):
     self.id = next_id()
     self.name = name
     self.caracs = dict()
     self.parents = list()
     self.antagonists = list()