From b2c1fe54ca81eb8ee51622653177968db762f6cd Mon Sep 17 00:00:00 2001 From: princetoday Date: Wed, 2 Oct 2024 16:25:57 +0530 Subject: [PATCH 1/2] start.json --- pico8/start.json | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 pico8/start.json diff --git a/pico8/start.json b/pico8/start.json new file mode 100644 index 0000000..5686789 --- /dev/null +++ b/pico8/start.json @@ -0,0 +1,49 @@ +{ + "name": "MonsterName", + "health": 10, + "states": { + "arriving": { + "animation": "default_arrival_animation", + "sound": "default_arrival_sound" + }, + "idle": { + "armor": 0, + "attack": 5, + "defense": 2, + "speed": 3, + "abilities": [ + "basic_attack", + "charge" + ] + }, + "dying_state": "default_dying_animation" + }, + "phases": { + "1.0": { + "arriving": { + "animation": "arrival_phase1_animation", + "sound": "arrival_phase1_sound" + }, + "idle": {} + }, + "0.5": { + "arriving": { + "animation": "arrival_phase2_animation", + "sound": "arrival_phase2_sound" + }, + "idle": { + "added_armor": 0.25 + } + }, + "0.25": { + "arriving": { + "animation": "arrival_phase3_animation", + "sound": "arrival_phase3_sound" + }, + "idle": { + "attack": 10, + "added_armor": 0.5 + } + } + } +} \ No newline at end of file From 8307b17b9a7df0911b255c2921f357d733a674db Mon Sep 17 00:00:00 2001 From: princetoday Date: Fri, 4 Oct 2024 11:46:46 +0530 Subject: [PATCH 2/2] Health-Based State Transitons, Updated tick Mmage Handling, --- invasion/enemy.py | 83 +++++++++++++++++++++++------------------------ pico8/start.json | 49 ---------------------------- 2 files changed, 40 insertions(+), 92 deletions(-) delete mode 100644 pico8/start.json diff --git a/invasion/enemy.py b/invasion/enemy.py index c29862c..ef93af2 100644 --- a/invasion/enemy.py +++ b/invasion/enemy.py @@ -1,6 +1,5 @@ import discord from discord import Member - import random import json import asyncio @@ -8,14 +7,15 @@ import re import os - ARRIVING_STATE = "arriving" WIN_STATE = "dying" -LOSE_STATE = "attacking" +def new_func(): + LOSE_STATE = "attacking" + return LOSE_STATE +LOSE_STATE = new_func() BOMB_DMG_TYPE = "bomb" - class Enemy(): def __init__(self, path: str, min_enrage_mult: float, max_enrage_mult: float, enraged: bool=False): self.path = path @@ -50,21 +50,10 @@ def __init__(self, path: str, min_enrage_mult: float, max_enrage_mult: float, en self.max_enrage_mult = max_enrage_mult self.enraged = enraged - # maybe reduce the number of these so it makes more sense which is stronger self._title_prefixes = [ - "Angry", - "Enraged", - "Formidable", - "Rampaging", - "Ferocious", - "Epic", - "Mythic", - "Ancient", - "Colossal", - "Unstoppable", - "Apocalyptic", - "Eternal", - "Divine" + "Angry", "Enraged", "Formidable", "Rampaging", "Ferocious", + "Epic", "Mythic", "Ancient", "Colossal", "Unstoppable", + "Apocalyptic", "Eternal", "Divine" ] if stats.get('enrage_titles_override'): self._title_prefixes = stats['enrage_titles_override'] @@ -72,14 +61,13 @@ def __init__(self, path: str, min_enrage_mult: float, max_enrage_mult: float, en self.enraged_amt = min_enrage_mult if enraged: - # am I doing my math right here? - min_enrage_mult-=1 - max_enrage_mult-=1 - enraged_amt = min_enrage_mult + random.random() * (max_enrage_mult-min_enrage_mult) + min_enrage_mult -= 1 + max_enrage_mult -= 1 + enraged_amt = min_enrage_mult + random.random() * (max_enrage_mult - min_enrage_mult) self.health *= enraged_amt + 1 self.max_health = self.health - self.reward_mult *= enraged_amt * .75 + 1 + self.reward_mult *= enraged_amt * 0.75 + 1 self.enraged_amt = enraged_amt + 1 self.name = f"{self.title_prefix} {self.name}" @@ -158,7 +146,6 @@ def title_prefix(self): px = len(self._title_prefixes) - 1 return self._title_prefixes[ - # map value from between mn and mx (exclusive) to between pn and px (inclusive) math.floor((self.enraged_amt - mn) / (mx - mn) * (px - pn)) + pn ] @@ -168,7 +155,7 @@ def countdown(self): try: return max(5, cd) except: - return max(5, random.random()*(cd[1]-cd[0]) + cd[0]) + return max(5, random.random() * (cd[1] - cd[0]) + cd[0]) def format_msg(self, msg, **kwargs): if msg: @@ -182,52 +169,56 @@ def hurt(self, player: Member, dmg_type: str, damage: int): return is_bomb = dmg_type == BOMB_DMG_TYPE pid = player.id - # dmg as an arg for purchasable bombs if (not is_bomb) and dmg_type not in self.hurt_by: - # miss penalty - self.hurt_mult[pid] = self.hurt_mult.get(pid, 1) * .9 + self.hurt_mult[pid] = self.hurt_mult.get(pid, 1) * 0.9 return 0 hurt_mult = 1 if is_bomb else self.hurt_mult.get(pid, 1) - dmg = damage * hurt_mult * max(1 - (self.armor+self.added_armor), 0) + dmg = damage * hurt_mult * max(1 - (self.armor + self.added_armor), 0) self.health -= dmg if self.health <= 0: self.health = 0 self.attacked_by[player.id] = self.attacked_by.get(player.id, 0) + min(self.health, dmg) if not is_bomb: - # make future hits weaker - self.hurt_mult[pid] = self.hurt_mult.get(pid, 1) * .75 + self.hurt_mult[pid] = self.hurt_mult.get(pid, 1) * 0.75 else: self.bombed_by[player.id] = self.bombed_by.get(player.id, 0) + 1 return dmg - def attack(self): - self.state = LOSE_STATE - return self.penalty_mult - def tick(self): if self.health <= 0: self.health = 0 self.state = WIN_STATE return + + # Health-based state transitions + health_percentage = self.health_percentage + if health_percentage > 0.75: + self.state = "standing" # Dragon stands tall + elif health_percentage > 0.25: + self.state = "flying" # Dragon flies above attacks + else: + self.state = "attacking" # Dragon breathes fire on the server + # Handle the arrival state transition if self.state == ARRIVING_STATE: self.state = self.default_state else: choices = {s: self.states[s].get('weight', 1) for s in - self.state_dict.get('next_state', self._active_states) - } + self.state_dict.get('next_state', self._active_states)} self.state = random.choices( [*choices], weights=[*choices.values()] )[0] + self.hurt_mult = {} - + async def update(self): self.bombed_by = {} - + await asyncio.sleep(self.countdown) - self.linger -= self.countdown/60 + self.linger -= self.countdown / 60 + if self.linger <= 0: self.linger = 0 if self.health <= 0: @@ -235,7 +226,13 @@ async def update(self): else: self.state = LOSE_STATE return - self.tick() - + + # Add logic for handling Dragon's behaviors based on current state + if self.state == "attacking": + # Dragon deals damage when in attacking state + damage = self.attacking + # You might want to specify how much damage the Dragon does here + # For example, deal damage to players that are currently engaged + # Implement damage dealing logic here if necessary - \ No newline at end of file + self.tick() diff --git a/pico8/start.json b/pico8/start.json deleted file mode 100644 index 5686789..0000000 --- a/pico8/start.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "MonsterName", - "health": 10, - "states": { - "arriving": { - "animation": "default_arrival_animation", - "sound": "default_arrival_sound" - }, - "idle": { - "armor": 0, - "attack": 5, - "defense": 2, - "speed": 3, - "abilities": [ - "basic_attack", - "charge" - ] - }, - "dying_state": "default_dying_animation" - }, - "phases": { - "1.0": { - "arriving": { - "animation": "arrival_phase1_animation", - "sound": "arrival_phase1_sound" - }, - "idle": {} - }, - "0.5": { - "arriving": { - "animation": "arrival_phase2_animation", - "sound": "arrival_phase2_sound" - }, - "idle": { - "added_armor": 0.25 - } - }, - "0.25": { - "arriving": { - "animation": "arrival_phase3_animation", - "sound": "arrival_phase3_sound" - }, - "idle": { - "attack": 10, - "added_armor": 0.5 - } - } - } -} \ No newline at end of file