コード例 #1
0
def check_defender_targets(user_data, enemy_data):
	defending_enemy = EwEnemy(id_enemy=enemy_data.id_enemy)
	searched_user = EwUser(id_user=user_data.id_user, id_server=user_data.id_server)

	if (defending_enemy.poi != searched_user.poi) or (searched_user.life_state == ewcfg.life_state_corpse):
		defending_enemy.id_target = ""
		defending_enemy.persist()
		return False
	else:
		return True
コード例 #2
0
ファイル: ewutils.py プロジェクト: seanialt/endless-war
def sap_tick(id_server):

	try:
		users = execute_sql_query("SELECT {id_user} FROM users WHERE {id_server} = %s AND {life_state} > 0 AND {sap} + {hardened_sap} < {level}".format(
			id_user = ewcfg.col_id_user,
			life_state = ewcfg.col_life_state,
			sap = ewcfg.col_sap,
			hardened_sap = ewcfg.col_hardened_sap,
			level = ewcfg.col_slimelevel,
			id_server = ewcfg.col_id_server,
		),(
			id_server,
		))

		for user in users:
			user_data = EwUser(id_user = user[0], id_server = id_server)
			user_data.sap += 1
			user_data.limit_fix()
			user_data.persist()

		enemies = execute_sql_query("SELECT {id_enemy} FROM enemies WHERE {id_server} = %s AND {hardened_sap} < {level} / 2".format(
			id_enemy = ewcfg.col_id_enemy,
			hardened_sap = ewcfg.col_enemy_hardened_sap,
			level = ewcfg.col_enemy_level,
			id_server = ewcfg.col_id_server,
		),(
			id_server,
		))

		for enemy in enemies:
			if random.random() < 0.5:
				enemy_data = EwEnemy(id_enemy = enemy[0])
				enemy_data.hardened_sap += 1
				enemy_data.persist()
	except:
		logMsg("An error occured in sap tick for server {}".format(id_server))
コード例 #3
0
async def enemyBleedSlimes(id_server = None):
	if id_server != None:
		try:
			conn_info = databaseConnect()
			conn = conn_info.get('conn')
			cursor = conn.cursor();

			cursor.execute("SELECT id_enemy FROM enemies WHERE id_server = %s AND {bleed_storage} > 1".format(
				bleed_storage = ewcfg.col_enemy_bleed_storage
			), (
				id_server,
			))

			enemies = cursor.fetchall()
			total_bled = 0
			resp_cont = EwResponseContainer(id_server = id_server)
			for enemy in enemies:
				enemy_data = EwEnemy(id_enemy = enemy[0], id_server = id_server)
				slimes_to_bleed = enemy_data.bleed_storage * (1 - .5 ** (ewcfg.bleed_tick_length / ewcfg.bleed_half_life))
				slimes_to_bleed = max(slimes_to_bleed, ewcfg.bleed_tick_length * 1000)
				slimes_to_bleed = min(slimes_to_bleed, enemy_data.bleed_storage)

				district_data = EwDistrict(id_server = id_server, district = enemy_data.poi)

				#round up or down, randomly weighted
				remainder = slimes_to_bleed - int(slimes_to_bleed)
				if random.random() < remainder:
					slimes_to_bleed += 1
				slimes_to_bleed = int(slimes_to_bleed)

				if slimes_to_bleed >= 1:
					enemy_data.bleed_storage -= slimes_to_bleed
					enemy_data.change_slimes(n = - slimes_to_bleed, source = ewcfg.source_bleeding)
					enemy_data.persist()
					district_data.change_slimes(n = slimes_to_bleed, source = ewcfg.source_bleeding)
					district_data.persist()
					total_bled += slimes_to_bleed

					if enemy_data.slimes <= 0:
						ewhunting.delete_enemy(enemy_data)

			await resp_cont.post()
			conn.commit()
		finally:
			# Clean up the database handles.
			cursor.close()
			databaseClose(conn_info)
コード例 #4
0
async def explode(damage = 0, district_data = None):
	id_server = district_data.id_server
	poi = district_data.name

	client = get_client()
	server = client.get_server(id_server)

	resp_cont = EwResponseContainer(id_server = id_server)
	response = ""
	channel = ewcfg.id_to_poi.get(poi).channel

	life_states = [ewcfg.life_state_juvenile, ewcfg.life_state_enlisted, ewcfg.life_state_executive]
	users = district_data.get_players_in_district(life_states = life_states)

	enemies = district_data.get_enemies_in_district()

	# damage players
	for user in users:
		user_data = EwUser(id_user = user, id_server = id_server)
		mutations = user_data.get_mutations()

		if True:
			player_data = EwPlayer(id_user = user_data.id_user)
			response = "{} is blown back by the explosion’s sheer force! They lose {} slime!!".format(player_data.display_name, damage)
			resp_cont.add_channel_response(channel, response)
			slimes_damage = damage
			if user_data.slimes < slimes_damage + user_data.bleed_storage:
				# die in the explosion
				district_data.change_slimes(n = user_data.slimes, source = ewcfg.source_killing)
				district_data.persist()
				slimes_dropped = user_data.totaldamage + user_data.slimes
				explode_damage = slime_bylevel(user_data.slimelevel)

				user_data.die(cause = ewcfg.cause_killing)
				#user_data.change_slimes(n = -slimes_dropped / 10, source = ewcfg.source_ghostification)
				user_data.persist()

				response = "Alas, {} was caught too close to the blast. They are consumed by the flames, and die in the explosion.".format(player_data.display_name)
				resp_cont.add_channel_response(channel, response)

				if ewcfg.mutation_id_spontaneouscombustion in mutations:
					sub_explosion = await explode(explode_damage, district_data)
					resp_cont.add_response_container(sub_explosion)

				await ewrolemgr.updateRoles(client = client, member = server.get_member(user_data.id_user))
			else:
				# survive
				slime_splatter = 0.5 * slimes_damage
				district_data.change_slimes(n = slime_splatter, source = ewcfg.source_killing)
				district_data.persist()
				slimes_damage -= slime_splatter
				user_data.bleed_storage += slimes_damage
				user_data.change_slimes(n = -slime_splatter, source = ewcfg.source_killing)
				user_data.persist()

	# damage enemies
	for enemy in enemies:
		enemy_data = EwEnemy(id_enemy = enemy, id_server = id_server)

		if True:
			response = "{} is blown back by the explosion’s sheer force! They lose {} slime!!".format(enemy_data.display_name, damage)
			resp_cont.add_channel_response(channel, response)
			slimes_damage = damage
			if enemy_data.slimes < slimes_damage + enemy_data.bleed_storage:
				# die in the explosion
				district_data.change_slimes(n = enemy_data.slimes, source = ewcfg.source_killing)
				district_data.persist()
				# slimes_dropped = enemy_data.totaldamage + enemy_data.slimes
				# explode_damage = ewutils.slime_bylevel(enemy_data.level)

				response = "Alas, {} was caught too close to the blast. They are consumed by the flames, and die in the explosion.".format(enemy_data.display_name)
				response += "\n\n" + ewhunting.drop_enemy_loot(enemy_data, district_data)
				resp_cont.add_channel_response(channel, response)

				enemy_data.life_state = ewcfg.enemy_lifestate_dead
				enemy_data.persist()

			else:
				# survive
				slime_splatter = 0.5 * slimes_damage
				district_data.change_slimes(n = slime_splatter, source = ewcfg.source_killing)
				district_data.persist()
				slimes_damage -= slime_splatter
				enemy_data.bleed_storage += slimes_damage
				enemy_data.change_slimes(n = -slime_splatter, source = ewcfg.source_killing)
				enemy_data.persist()
	return resp_cont
コード例 #5
0
async def weather_tick(id_server=None):
    if id_server != None:
        try:
            market_data = EwMarket(id_server=id_server)

            if market_data.weather == ewcfg.weather_sunny:
                exposed_pois = []
                exposed_pois.extend(ewcfg.capturable_districts)
                exposed_pois.extend(ewcfg.outskirts)
                exposed_pois = tuple(exposed_pois)

                users = ewutils.execute_sql_query(
                    "SELECT id_user FROM users WHERE id_server = %s AND {poi} IN %s AND {life_state} > 0"
                    .format(poi=ewcfg.col_poi,
                            life_state=ewcfg.col_life_state),
                    (id_server, exposed_pois))
                for user in users:
                    try:
                        user_data = EwUser(id_user=user[0],
                                           id_server=id_server)
                        if user_data.life_state == ewcfg.life_state_kingpin:
                            continue
                        else:
                            mutations = user_data.get_mutations()
                            if ewcfg.mutation_id_airlock in mutations:
                                user_data.hunger -= min(user_data.hunger, 5)
                    except:
                        ewutils.logMsg(
                            "Error occurred in weather tick for server {}".
                            format(id_server))

            if market_data.weather != ewcfg.weather_bicarbonaterain:
                return

            exposed_pois = []
            exposed_pois.extend(ewcfg.capturable_districts)
            exposed_pois.extend(ewcfg.outskirts)
            exposed_pois = tuple(exposed_pois)

            client = ewutils.get_client()
            server = client.get_guild(id_server)

            users = ewutils.execute_sql_query(
                "SELECT id_user FROM users WHERE id_server = %s AND {poi} IN %s AND {life_state} > 0"
                .format(poi=ewcfg.col_poi, life_state=ewcfg.col_life_state),
                (id_server, exposed_pois))

            deathreport = ""
            resp_cont = ewutils.EwResponseContainer(id_server=id_server)
            for user in users:
                user_data = EwUser(id_user=user[0], id_server=id_server)
                if user_data.life_state == ewcfg.life_state_kingpin:
                    continue
                user_poi = ewcfg.id_to_poi.get(user_data.poi)
                player_data = EwPlayer(id_server=user_data.id_server,
                                       id_user=user_data.id_user)

                protected = False
                slimeoid_protected = False

                if user_data.weapon >= 0:
                    weapon_item = EwItem(id_item=user_data.weapon)
                    if weapon_item.item_props.get(
                            'weapon_type') in ewcfg.rain_protection:
                        protected = True

                cosmetics = ewitem.inventory(
                    id_user=user_data.id_user,
                    id_server=id_server,
                    item_type_filter=ewcfg.it_cosmetic)

                for cosmetic in cosmetics:
                    cosmetic_data = EwItem(id_item=cosmetic.get('id_item'))
                    if cosmetic_data.item_props.get(
                            'id_cosmetic') in ewcfg.rain_protection:
                        if cosmetic_data.item_props.get('adorned') == 'true':
                            protected = True
                        elif cosmetic_data.item_props.get(
                                'slimeoid') == 'true':
                            slimeoid_protected = True

                if not protected:

                    if user_data.life_state == ewcfg.life_state_shambler:
                        slime_gain = (ewcfg.slimes_shambler -
                                      user_data.slimes) / 10
                        slime_gain = max(0, int(slime_gain))
                        user_data.change_slimes(n=slime_gain,
                                                source=ewcfg.source_weather)

                    else:
                        if random.random() < 0.01:
                            user_data.degradation += 1

                    user_data.persist()

                if not slimeoid_protected:
                    slimeoid_data = EwSlimeoid(id_user=user_data.id_user,
                                               id_server=id_server)

                    if slimeoid_data.life_state != ewcfg.slimeoid_state_active:
                        continue

                    slimeoid_response = ""
                    if random.randrange(10) < slimeoid_data.level:
                        slimeoid_response = "*{uname}*: {slname} cries out in pain, as it's hit by the bicarbonate rain.".format(
                            uname=player_data.display_name,
                            slname=slimeoid_data.name)

                    else:
                        item_props = {
                            'context':
                            ewcfg.context_slimeoidheart,
                            'subcontext':
                            slimeoid_data.id_slimeoid,
                            'item_name':
                            "Heart of {}".format(slimeoid_data.name),
                            'item_desc':
                            "A poudrin-like crystal. If you listen carefully you can hear something that sounds like a faint heartbeat."
                        }
                        ewitem.item_create(id_user=str(user_data.id_user),
                                           id_server=id_server,
                                           item_type=ewcfg.it_item,
                                           item_props=item_props)
                        slimeoid_data.die()
                        slimeoid_data.persist()
                        slimeoid_response = "*{uname}*: {slname} lets out a final whimper as it's dissolved by the bicarbonate rain. {skull} You quickly pocket its heart.".format(
                            uname=player_data.display_name,
                            slname=slimeoid_data.name,
                            skull=ewcfg.emote_slimeskull)

                    resp_cont.add_channel_response(user_poi.channel,
                                                   slimeoid_response)
            for poi in exposed_pois:
                district_data = EwDistrict(district=poi, id_server=id_server)
                slimes_to_erase = district_data.slimes * 0.01 * ewcfg.weather_tick_length
                slimes_to_erase = max(slimes_to_erase,
                                      ewcfg.weather_tick_length * 1000)
                slimes_to_erase = min(district_data.slimes, slimes_to_erase)

                #round up or down, randomly weighted
                remainder = slimes_to_erase - int(slimes_to_erase)
                if random.random() < remainder:
                    slimes_to_erase += 1
                slimes_to_erase = int(slimes_to_erase)

                district_data.change_slimes(n=-slimes_to_erase,
                                            source=ewcfg.source_weather)
                district_data.persist()

            enemies = ewutils.execute_sql_query(
                "SELECT id_enemy FROM enemies WHERE id_server = %s AND {poi} IN %s AND {life_state} = %s AND {weathertype} != %s"
                .format(poi=ewcfg.col_enemy_poi,
                        life_state=ewcfg.col_enemy_life_state,
                        weathertype=ewcfg.col_enemy_weathertype),
                (id_server, exposed_pois, ewcfg.enemy_lifestate_alive,
                 ewcfg.enemy_weathertype_rainresist))

            for enemy in enemies:
                enemy_data = EwEnemy(id_enemy=enemy[0])
                enemy_poi = ewcfg.id_to_poi.get(enemy_data.poi)

                slimes_to_erase = enemy_data.slimes * 0.01 * ewcfg.weather_tick_length
                slimes_to_erase = max(slimes_to_erase,
                                      ewcfg.weather_tick_length * 1000)
                slimes_to_erase = min(enemy_data.slimes, slimes_to_erase)

                #round up or down, randomly weighted
                remainder = slimes_to_erase - int(slimes_to_erase)
                if random.random() < remainder:
                    slimes_to_erase += 1
                slimes_to_erase = int(slimes_to_erase)

                enemy_data.change_slimes(n=-slimes_to_erase,
                                         source=ewcfg.source_weather)
                enemy_data.persist()

                response = "{name} takes {slimeloss:,} damage from the bicarbonate rain.".format(
                    name=enemy_data.display_name, slimeloss=slimes_to_erase)
                resp_cont.add_channel_response(enemy_poi.channel, response)
                if enemy_data.slimes <= 0:
                    ewhunting.delete_enemy(enemy_data)
                    deathreport = "{skull} {name} is dissolved by the bicarbonate rain. {skull}".format(
                        skull=ewcfg.emote_slimeskull,
                        name=enemy_data.display_name)
                    resp_cont.add_channel_response(enemy_poi.channel,
                                                   deathreport)

            await resp_cont.post()

        except:
            ewutils.logMsg(
                "Error occurred in weather tick for server {}".format(
                    id_server))
コード例 #6
0
ファイル: ewutils.py プロジェクト: seanialt/endless-war
def explode(damage = 0, district_data = None, market_data = None):
	id_server = district_data.id_server
	poi = district_data.name

	if market_data == None:
		market_data = EwMarket(id_server = district_data.id_server)

	client = get_client()
	server = client.get_server(id_server)

	resp_cont = EwResponseContainer(id_server = id_server)
	response = ""
	channel = ewcfg.id_to_poi.get(poi).channel

	life_states = [ewcfg.life_state_juvenile, ewcfg.life_state_enlisted, ewcfg.life_state_executive]
	users = district_data.get_players_in_district(life_states = life_states)

	enemies = district_data.get_enemies_in_district()

	# damage players
	for user in users:
		user_data = EwUser(id_user = user, id_server = id_server)
		mutations = user_data.get_mutations()

		user_weapon = None
		user_weapon_item = None
		if user_data.weapon >= 0:
			user_weapon_item = EwItem(id_item = user_data.weapon)
			user_weapon = ewcfg.weapon_map.get(user_weapon_item.item_props.get("weapon_type"))

		# apply defensive mods
		slimes_damage_target = damage * ewwep.damage_mod_defend(
			shootee_data = user_data,
			shootee_mutations = mutations,
			shootee_weapon = user_weapon,
			market_data = market_data
		)

		# apply sap armor
		sap_armor = ewwep.get_sap_armor(shootee_data = user_data, sap_ignored = 0)
		slimes_damage_target *= sap_armor
		slimes_damage_target = int(max(0, slimes_damage_target))

		player_data = EwPlayer(id_user = user_data.id_user)
		response = "{} is blown back by the explosion’s sheer force! They lose {:,} slime!!".format(player_data.display_name, slimes_damage_target)
		resp_cont.add_channel_response(channel, response)
		slimes_damage = slimes_damage_target
		if user_data.slimes < slimes_damage + user_data.bleed_storage:
			# die in the explosion
			district_data.change_slimes(n = user_data.slimes, source = ewcfg.source_killing)
			district_data.persist()
			slimes_dropped = user_data.totaldamage + user_data.slimes
			explode_damage = slime_bylevel(user_data.slimelevel)

			user_data.die(cause = ewcfg.cause_killing)
			#user_data.change_slimes(n = -slimes_dropped / 10, source = ewcfg.source_ghostification)
			user_data.persist()

			response = "Alas, {} was caught too close to the blast. They are consumed by the flames, and die in the explosion.".format(player_data.display_name)
			resp_cont.add_channel_response(channel, response)

			if ewcfg.mutation_id_spontaneouscombustion in mutations:
				sub_explosion = explode(explode_damage, district_data)
				resp_cont.add_response_container(sub_explosion)

			resp_cont.add_member_to_update(server.get_member(user_data.id_user))
		else:
			# survive
			slime_splatter = 0.5 * slimes_damage
			district_data.change_slimes(n = slime_splatter, source = ewcfg.source_killing)
			district_data.persist()
			slimes_damage -= slime_splatter
			user_data.bleed_storage += slimes_damage
			user_data.change_slimes(n = -slime_splatter, source = ewcfg.source_killing)
			user_data.persist()

	# damage enemies
	for enemy in enemies:
		enemy_data = EwEnemy(id_enemy = enemy, id_server = id_server)

		response = "{} is blown back by the explosion’s sheer force! They lose {:,} slime!!".format(enemy_data.display_name, damage)
		resp_cont.add_channel_response(channel, response)

		slimes_damage_target = damage
			
		# apply sap armor
		sap_armor = ewwep.get_sap_armor(shootee_data = enemy_data, sap_ignored = 0)
		slimes_damage_target *= sap_armor
		slimes_damage_target = int(max(0, slimes_damage_target))

		slimes_damage = slimes_damage_target
		if enemy_data.slimes < slimes_damage + enemy_data.bleed_storage:
			# die in the explosion
			district_data.change_slimes(n = enemy_data.slimes, source = ewcfg.source_killing)
			district_data.persist()
			# slimes_dropped = enemy_data.totaldamage + enemy_data.slimes
			# explode_damage = ewutils.slime_bylevel(enemy_data.level)

			response = "Alas, {} was caught too close to the blast. They are consumed by the flames, and die in the explosion.".format(enemy_data.display_name)
			resp_cont.add_response_container(ewhunting.drop_enemy_loot(enemy_data, district_data))
			resp_cont.add_channel_response(channel, response)

			enemy_data.life_state = ewcfg.enemy_lifestate_dead
			enemy_data.persist()

		else:
			# survive
			slime_splatter = 0.5 * slimes_damage
			district_data.change_slimes(n = slime_splatter, source = ewcfg.source_killing)
			district_data.persist()
			slimes_damage -= slime_splatter
			enemy_data.bleed_storage += slimes_damage
			enemy_data.change_slimes(n = -slime_splatter, source = ewcfg.source_killing)
			enemy_data.persist()
	return resp_cont