diff --git a/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py b/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py index ddd53b9..f7869ba 100644 --- a/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py +++ b/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py @@ -12,7 +12,7 @@ import random from tools import playlist from tools import logger Commands = ['recents','info','createteam', 'showid', 'hideid', 'lm', 'gp', 'party', 'quit', 'kickvote', 'maxplayers', 'playlist', 'ban', 'kick', 'remove', 'end', 'quit', 'mute', 'unmute', 'slowmo', 'nv', 'dv', 'pause', - 'cameramode', 'createrole', 'addrole', 'removerole', 'addcommand', 'addcmd', 'removecommand', 'getroles', 'removecmd', 'changetag', 'customtag', 'customeffect', 'add', 'spectators', 'lobbytime'] + 'cameramode', 'createrole', 'addrole', 'removerole', 'addcommand', 'addcmd', 'removecommand', 'getroles', 'removecmd', 'changetag', 'customtag', 'customeffect','removeeffect','removetag' 'add', 'spectators', 'lobbytime'] CommandAliases = ['max', 'rm', 'next', 'restart', 'mutechat', 'unmutechat', 'sm', 'slow', 'night', 'day', 'pausegame', 'camera_mode', 'rotate_camera', 'effect'] @@ -115,6 +115,12 @@ def ExcelCommand(command, arguments, clientid, accountid): elif command in ['customeffect', 'effect']: set_custom_effect(arguments) + elif command in ['removetag']: + remove_custom_tag(arguments) + + elif command in ['removeeffect']: + remove_custom_effect(arguments) + # elif command in ['add', 'whitelist']: # whitelst_it(accountid, arguments) @@ -479,13 +485,30 @@ def set_custom_tag(arguments): except: return +def remove_custom_tag(arguments): + try: + session = ba.internal.get_foreground_host_session() + for i in session.sessionplayers: + if i.inputdevice.client_id == int(arguments[0]): + pdata.remove_tag( i.get_v1_account_id()) + except: + return + +def remove_custom_effect(arguments): + try: + session = ba.internal.get_foreground_host_session() + for i in session.sessionplayers: + if i.inputdevice.client_id == int(arguments[0]): + pdata.remove_effect( i.get_v1_account_id()) + except: + return def set_custom_effect(arguments): try: session = ba.internal.get_foreground_host_session() for i in session.sessionplayers: if i.inputdevice.client_id == int(arguments[1]): - roles = pdata.set_effect(arguments[0], i.get_v1_account_id()) + pdata.set_effect(arguments[0], i.get_v1_account_id()) except: return diff --git a/dist/ba_root/mods/playersData/pdata.py b/dist/ba_root/mods/playersData/pdata.py index 82f6836..141eed6 100644 --- a/dist/ba_root/mods/playersData/pdata.py +++ b/dist/ba_root/mods/playersData/pdata.py @@ -561,7 +561,7 @@ def get_custom() -> dict: return CacheData.custom -def set_effect(effect: str, accout_id: str) -> None: +def set_effect(effect: str, account_id: str) -> None: """Sets the costum effect for the player. Parameters @@ -572,7 +572,12 @@ def set_effect(effect: str, accout_id: str) -> None: account id of the client """ custom = get_custom() - custom["customeffects"][accout_id] = effect + if account_id in custom["customeffects"]: + effects = [custom["customeffects"][account_id]] if type(custom["customeffects"][account_id]) is str else custom["customeffects"][account_id] + effects.append(effect) + custom["customeffects"][account_id] = effects + else: + custom["customeffects"][account_id] = [effect] CacheData.custom = custom commit_c() diff --git a/dist/ba_root/mods/spazmod/effects.py b/dist/ba_root/mods/spazmod/effects.py deleted file mode 100644 index c689a7e..0000000 --- a/dist/ba_root/mods/spazmod/effects.py +++ /dev/null @@ -1,418 +0,0 @@ -# -*- coding: utf-8 -*- -# Released under the MIT License. See LICENSE for details. -# -"""Functionality related to player-controlled Spazzes.""" - -from __future__ import annotations -from ba._generated.enums import TimeType -from typing import TYPE_CHECKING, TypeVar, overload -from bastd.actor.spaz import * -from bastd.gameutils import SharedObjects -from typing import Any, Sequence, Optional, Dict, List, Union, Callable, Tuple, Set, Type, Literal -from bastd.actor import playerspaz -from bastd.actor.playerspaz import * -from bastd.actor.spazfactory import SpazFactory -from bastd.actor.popuptext import PopupText -from bastd.actor import spaz, spazappearance -from bastd.actor import bomb as stdbomb -from bastd.actor.powerupbox import PowerupBoxFactory -import ba -import _ba -import bastd -import weakref -import random -import math -import time -import base64 -import os -import json -import setting -import ba.internal -from playersData import pdata -from stats import mystats -PlayerType = TypeVar('PlayerType', bound=ba.Player) -TeamType = TypeVar('TeamType', bound=ba.Team) -tt = ba.TimeType.SIM -tf = ba.TimeFormat.MILLISECONDS - -multicolor = {0: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 250: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 500: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 750: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 1000: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 1250: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 1500: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 1750: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 2000: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 2250: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0)), - 2500: ((0+random.random()*3.0), (0+random.random()*3.0), (0+random.random()*3.0))} - - -class SurroundBallFactory(object): - def __init__(self): - self.bonesTex = ba.gettexture("powerupCurse") - self.bonesModel = ba.getmodel("bonesHead") - self.bearTex = ba.gettexture("bearColor") - self.bearModel = ba.getmodel("bearHead") - self.aliTex = ba.gettexture("aliColor") - self.aliModel = ba.getmodel("aliHead") - self.b9000Tex = ba.gettexture("cyborgColor") - self.b9000Model = ba.getmodel("cyborgHead") - self.frostyTex = ba.gettexture("frostyColor") - self.frostyModel = ba.getmodel("frostyHead") - self.cubeTex = ba.gettexture("crossOutMask") - self.cubeModel = ba.getmodel("powerup") - try: - self.mikuModel = ba.getmodel("operaSingerHead") - self.mikuTex = ba.gettexture("operaSingerColor") - except: - ba.print_exception() - self.ballMaterial = ba.Material() - self.impactSound = ba.getsound("impactMedium") - self.ballMaterial.add_actions( - actions=("modify_node_collision", "collide", False)) - - -class SurroundBall(ba.Actor): - def __init__(self, spaz, shape="bones"): - ba.Actor.__init__(self) - self.spazRef = weakref.ref(spaz) - factory = self.getFactory() - s_model, s_texture = { - "bones": (factory.bonesModel, factory.bonesTex), - "bear": (factory.bearModel, factory.bearTex), - "ali": (factory.aliModel, factory.aliTex), - "b9000": (factory.b9000Model, factory.b9000Tex), - "miku": (factory.mikuModel, factory.mikuTex), - "frosty": (factory.frostyModel, factory.frostyTex), - "RedCube": (factory.cubeModel, factory.cubeTex) - }.get(shape, (factory.bonesModel, factory.bonesTex)) - self.node = ba.newnode("prop", attrs={"model": s_model, "body": "sphere", "color_texture": s_texture, "reflection": "soft", "model_scale": 0.5, "body_scale": 0.1, "density": 0.1, "reflection_scale": [ - 0.15], "shadow_size": 0.6, "position": spaz.node.position, "velocity": (0, 0, 0), "materials": [SharedObjects.get().object_material, factory.ballMaterial]}, delegate=self) - self.surroundTimer = None - self.surroundRadius = 1.0 - self.angleDelta = math.pi / 12.0 - self.curAngle = random.random() * math.pi * 2.0 - self.curHeight = 0.0 - self.curHeightDir = 1 - self.heightDelta = 0.2 - self.heightMax = 1.0 - self.heightMin = 0.1 - self.initTimer(spaz.node.position) - - def getTargetPosition(self, spazPos): - p = spazPos - pt = (p[0] + self.surroundRadius * math.cos(self.curAngle), p[1] + - self.curHeight, p[2] + self.surroundRadius * math.sin(self.curAngle)) - self.curAngle += self.angleDelta - self.curHeight += self.heightDelta * self.curHeightDir - if (self.curHeight > self.heightMax) or (self.curHeight < self.heightMin): - self.curHeightDir = -self.curHeightDir - return pt - - def initTimer(self, p): - self.node.position = self.getTargetPosition(p) - self.surroundTimer = ba.Timer( - 30, self.circleMove, repeat=True, timetype=tt, timeformat=tf) - - def circleMove(self): - spaz = self.spazRef() - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.handlemessage(ba.DieMessage()) - return - p = spaz.node.position - pt = self.getTargetPosition(p) - pn = self.node.position - d = [pt[0] - pn[0], pt[1] - pn[1], pt[2] - pn[2]] - speed = self.getMaxSpeedByDir(d) - self.node.velocity = speed - - @staticmethod - def getMaxSpeedByDir(direction): - k = 7.0 / max((abs(x) for x in direction)) - return tuple(x * k for x in direction) - - def handlemessage(self, m): - ba.Actor.handlemessage(self, m) - if isinstance(m, ba.DieMessage): - if self.surroundTimer is not None: - self.surroundTimer = None - self.node.delete() - elif isinstance(m, ba.OutOfBoundsMessage): - self.handlemessage(ba.DieMessage()) - - def getFactory(cls): - activity = ba.getactivity() - if activity is None: - raise Exception("no current activity") - try: - return activity._sharedSurroundBallFactory - except Exception: - f = activity._sharedSurroundBallFactory = SurroundBallFactory() - return f - - -class Effect(ba.Actor): - def __init__(self, spaz, player): - ba.Actor.__init__(self) - _settings = setting.get_settings_data() - custom_tag = pdata.get_custom()['customtag'] - custom_effects = pdata.get_custom()['customeffects'] - self.source_player = player - self.spazRef = weakref.ref(spaz) - self.spazNormalColor = spaz.node.color - self.Decorations = [] - self.Enhancements = [] - self._powerScale = 1.0 - self._armorScale = 1.0 - self._lifeDrainScale = None - self._damageBounceScale = None - self._remoteMagicDamge = False - self._MulitPunch = None - self._AntiFreeze = 1.0 - self.fallWings = 0 - self.checkDeadTimer = None - self._hasDead = False - self.light = None - - node_id = self.source_player.node.playerID - cl_str = None - clID = None - for c in ba.internal.get_foreground_host_session().sessionplayers: - if (c.activityplayer) and (c.activityplayer.node.playerID == node_id): - profiles = c.inputdevice.get_player_profiles() - clID = c.inputdevice.client_id - cl_str = c.get_v1_account_id() - - try: - if cl_str in custom_effects: - effect = custom_effects[cl_str] - if effect == 'ice': - self.emitIce() - self.snowTimer = ba.Timer( - 0.5, self.emitIce, repeat=True, timetype=TimeType.SIM) - return - elif effect == 'sweat': - self.smokeTimer = ba.Timer( - 0.6, self.emitSmoke, repeat=True, timetype=TimeType.SIM) - return - elif effect == 'scorch': - self.scorchTimer = ba.Timer( - 500, self.update_Scorch, repeat=True, timetype=tt, timeformat=tf) - return - elif effect == 'glow': - self.addLightColor((1, 0.6, 0.4)) - self.checkDeadTimer = ba.Timer( - 150, self.checkPlayerifDead, repeat=True, timetype=tt, timeformat=tf) - return - elif effect == 'distortion': - self.DistortionTimer = ba.Timer( - 1000, self.emitDistortion, repeat=True, timetype=tt, timeformat=tf) - return - elif effect == 'slime': - self.slimeTimer = ba.Timer( - 250, self.emitSlime, repeat=True, timetype=tt, timeformat=tf) - return - elif effect == 'metal': - self.metalTimer = ba.Timer( - 500, self.emitMetal, repeat=True, timetype=tt, timeformat=tf) - return - elif effect == 'surrounder': - self.surround = SurroundBall(spaz, shape="bones") - return - elif effect == 'spark': - self.sparkTimer = ba.Timer( - 100, self.emitSpark, repeat=True, timetype=tt, timeformat=tf) - return - except: - pass - - if _settings['enablestats']: - pats = mystats.get_all_stats() - if cl_str in pats and _settings['enableTop5effects']: - rank = pats[cl_str]["rank"] - if rank < 6: - if rank == 1: - # self.neroLightTimer = ba.Timer(500, ba.WeakCall(self.neonLightSwitch,("shine" in self.Decorations),("extra_Highlight" in self.Decorations),("extra_NameColor" in self.Decorations)),repeat = True, timetype=tt, timeformat=tf) - self.surround = SurroundBall(spaz, shape="bones") - elif rank == 2: - - self.smokeTimer = ba.Timer( - 40, self.emitSmoke, repeat=True, timetype=tt, timeformat=tf) - elif rank == 3: - - self.addLightColor((1, 0.6, 0.4)) - self.scorchTimer = ba.Timer( - 500, self.update_Scorch, repeat=True, timetype=tt, timeformat=tf) - elif rank == 4: - self.metalTimer = ba.Timer( - 500, self.emitMetal, repeat=True, timetype=tt, timeformat=tf) - else: - self.addLightColor((1, 0.6, 0.4)) - self.checkDeadTimer = ba.Timer( - 150, self.checkPlayerifDead, repeat=True, timetype=tt, timeformat=tf) - - if "smoke" and "spark" and "snowDrops" and "slimeDrops" and "metalDrops" and "Distortion" and "neroLight" and "scorch" and "HealTimer" and "KamikazeCheck" not in self.Decorations: - # self.checkDeadTimer = ba.Timer(150, ba.WeakCall(self.checkPlayerifDead), repeat=True, timetype=tt, timeformat=tf) - if self.source_player.is_alive() and self.source_player.actor.node.exists(): - # print("OK") - self.source_player.actor.node.addDeathAction( - ba.Call(self.handlemessage, ba.DieMessage())) - - def add_multicolor_effect(self): - if spaz.node: - ba.animate_array(spaz.node, 'color', 3, multicolor, - True, timetype=tt, timeformat=tf) - - def checkPlayerifDead(self): - spaz = self.spazRef() - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.checkDeadTimer = None - self.handlemessage(ba.DieMessage()) - return - - def update_Scorch(self): - spaz = self.spazRef() - if spaz is not None and spaz.is_alive() and spaz.node.exists(): - color = (random.random(), random.random(), random.random()) - if not hasattr(self, "scorchNode") or self.scorchNode == None: - self.scorchNode = None - self.scorchNode = ba.newnode("scorch", attrs={"position": ( - spaz.node.position), "size": 1.17, "big": True}) - spaz.node.connectattr("position", self.scorchNode, "position") - ba.animate_array(self.scorchNode, "color", 3, { - 0: self.scorchNode.color, 500: color}, timetype=tt, timeformat=tf) - else: - self.scorchTimer = None - if hasattr(self, "scorchNode"): - self.scorchNode.delete() - self.handlemessage(ba.DieMessage()) - - def neonLightSwitch(self, shine, Highlight, NameColor): - spaz = self.spazRef() - if spaz is not None and spaz.is_alive() and spaz.node.exists(): - color = (random.random(), random.random(), random.random()) - if NameColor: - ba.animate_array(spaz.node, "nameColor", 3, { - 0: spaz.node.nameColor, 500: ba.safecolor(color)}, timetype=tt, timeformat=tf) - if shine: - color = tuple([min(10., 10 * x) for x in color]) - ba.animate_array(spaz.node, "color", 3, { - 0: spaz.node.color, 500: color}, timetype=tt, timeformat=tf) - if Highlight: - # print spaz.node.highlight - color = (random.random(), random.random(), random.random()) - if shine: - color = tuple([min(10., 10 * x) for x in color]) - ba.animate_array(spaz.node, "highlight", 3, { - 0: spaz.node.highlight, 500: color}, timetype=tt, timeformat=tf) - else: - self.neroLightTimer = None - self.handlemessage(ba.DieMessage()) - - def addLightColor(self, color): - self.light = ba.newnode( - "light", attrs={"color": color, "height_attenuated": False, "radius": 0.4}) - self.spazRef().node.connectattr("position", self.light, "position") - ba.animate(self.light, "intensity", { - 0: 0.1, 250: 0.3, 500: 0.1}, loop=True, timetype=tt, timeformat=tf) - - def emitDistortion(self): - spaz = self.spazRef() - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.handlemessage(ba.DieMessage()) - return - ba.emitfx(position=spaz.node.position, - emit_type="distortion", spread=1.0) - ba.emitfx(position=spaz.node.position, velocity=spaz.node.velocity, - count=random.randint(1, 5), emit_type="tendrils", tendril_type="smoke") - - def emitSpark(self): - spaz = self.spazRef() - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.handlemessage(ba.DieMessage()) - return - ba.emitfx(position=spaz.node.position, velocity=spaz.node.velocity, - count=random.randint(1, 10), scale=2, spread=0.2, chunk_type="spark") - - def emitIce(self): - spaz = self.spazRef() - - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.handlemessage(ba.DieMessage()) - return - ba.emitfx(position=spaz.node.position, velocity=spaz.node.velocity, - count=random.randint(2, 8), scale=0.4, spread=0.2, chunk_type="ice") - - def emitSmoke(self): - spaz = self.spazRef() - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.handlemessage(ba.DieMessage()) - return - ba.emitfx(position=spaz.node.position, velocity=spaz.node.velocity, - count=random.randint(1, 10), scale=2, spread=0.2, chunk_type="sweat") - - def emitSlime(self): - spaz = self.spazRef() - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.handlemessage(ba.DieMessage()) - return - ba.emitfx(position=spaz.node.position, velocity=spaz.node.velocity, - count=random.randint(1, 10), scale=0.4, spread=0.2, chunk_type="slime") - - def emitMetal(self): - spaz = self.spazRef() - if spaz is None or not spaz.is_alive() or not spaz.node.exists(): - self.handlemessage(ba.DieMessage()) - return - ba.emitfx(position=spaz.node.position, velocity=spaz.node.velocity, - count=random.randint(2, 8), scale=0.4, spread=0.2, chunk_type="metal") - - def handlemessage(self, m): - # self._handlemessageSanityCheck() - if isinstance(m, ba.OutOfBoundsMessage): - self.handlemessage(ba.DieMessage()) - elif isinstance(m, ba.DieMessage): - if hasattr(self, "light") and self.light is not None: - self.light.delete() - if hasattr(self, "smokeTimer"): - self.smokeTimer = None - if hasattr(self, "surround"): - self.surround = None - if hasattr(self, "sparkTimer"): - self.sparkTimer = None - if hasattr(self, "snowTimer"): - self.snowTimer = None - if hasattr(self, "metalTimer"): - self.metalTimer = None - if hasattr(self, "DistortionTimer"): - self.DistortionTimer = None - if hasattr(self, "slimeTimer"): - self.slimeTimer = None - if hasattr(self, "KamikazeCheck"): - self.KamikazeCheck = None - if hasattr(self, "neroLightTimer"): - self.neroLightTimer = None - if hasattr(self, "checkDeadTimer"): - self.checkDeadTimer = None - if hasattr(self, "HealTimer"): - self.HealTimer = None - if hasattr(self, "scorchTimer"): - self.scorchTimer = None - if hasattr(self, "scorchNode"): - self.scorchNode = None - if not self._hasDead: - spaz = self.spazRef() - # print str(spaz) + "Spaz" - if spaz is not None and spaz.is_alive() and spaz.node.exists(): - spaz.node.color = self.spazNormalColor - killer = spaz.last_player_attacked_by if spaz is not None else None - try: - if killer in (None, ba.Player(None)) or killer.actor is None or not killer.actor.exists() or killer.actor.hitPoints <= 0: - killer = None - except: - killer = None - # if hasattr(self,"hasDead") and not self.hasDead: - self._hasDead = True - - ba.Actor.handlemessage(self, m) diff --git a/dist/ba_root/mods/spazmod/hitmessage.py b/dist/ba_root/mods/spazmod/hitmessage.py index eb7422f..dd58d22 100644 --- a/dist/ba_root/mods/spazmod/hitmessage.py +++ b/dist/ba_root/mods/spazmod/hitmessage.py @@ -8,31 +8,24 @@ from bastd.actor.popuptext import PopupText our_settings = setting.get_settings_data() -def handle_hit(msg, hp, dmg, hit_by, msg_pos): - #Check - if not msg.hit_type: return - - #Record Out Data - dmg = dmg / 10 - if hit_by is not None: - hit_by_id = None - hit_by_id = hit_by.node.playerID - if hit_by_id is not None: - hit_by_account_id = None - for c in ba.internal.get_foreground_host_session().sessionplayers: - if (c.activityplayer) and (c.activityplayer.node.playerID == hit_by_id): - hit_by_account_id = c.get_v1_account_id() - if hit_by_account_id in damage_data: damage_data[hit_by_account_id] += float(dmg) - else: damage_data[hit_by_account_id] = float(dmg) +def handle_hit(mag, pos): + if not mag: return #Send Screen Texts in enabled if our_settings['enableHitTexts']: try: - if hp <= 0: PopupText("Rest In Peace !",color=(1,0.2,0.2),scale=1.6,position=msg_pos).autoretain() - else: - if dmg >= 800: PopupText("#PRO !",color=(1,0.2,0.2),scale=1.6,position=msg_pos).autoretain() - elif dmg >= 600 and dmg < 800: PopupText("GOOD ONE!",color=(1,0.3,0.1),scale=1.6,position=msg_pos).autoretain() - elif dmg >= 400 and dmg < 600: PopupText("OH! YEAH",color=(1,0.5,0.2),scale=1.6,position=msg_pos).autoretain() - elif dmg >= 200 and dmg < 400: PopupText("WTF!",color=(0.7,0.4,0.2),scale=1.6,position=msg_pos).autoretain() - elif dmg > 0 and dmg < 200: PopupText("!!!",color=(1,1,1),scale=1.6,position=msg_pos).autoretain() + if mag >= 110: PopupText("#PRO !",color=(1,0.2,0.2),scale=1.6,position=pos).autoretain() + elif mag >= 93 and mag < 110: PopupText("GOOD ONE!",color=(1,0.3,0.1),scale=1.6,position=pos).autoretain() + elif mag >= 63 and mag < 93: PopupText("OH! YEAH",color=(1,0.5,0.2),scale=1.6,position=pos).autoretain() + elif mag >= 45 and mag < 63: PopupText("WTF!",color=(0.7,0.4,0.2),scale=1.6,position=pos).autoretain() + elif mag > 30 and mag < 45: PopupText("!!!",color=(1,1,1),scale=1.6,position=pos).autoretain() except: pass - return \ No newline at end of file + return + + +class hit_message(ba.HitMessage): + def __init__(self, *args, **kwargs): + hit_type = kwargs["hit_type"] + if hit_type == "punch": + handle_hit(kwargs['magnitude'], kwargs['pos']) + super().__init__(*args, **kwargs) +ba.HitMessage = hit_message diff --git a/dist/ba_root/mods/spazmod/modifyspaz.py b/dist/ba_root/mods/spazmod/modifyspaz.py index 0e5c7e9..44a5683 100644 --- a/dist/ba_root/mods/spazmod/modifyspaz.py +++ b/dist/ba_root/mods/spazmod/modifyspaz.py @@ -1,12 +1,16 @@ from spazmod import tag -from spazmod import effects import setting from random import randint - +from spazmod import hitmessage import _ba,ba import ba.internal _setting=setting.get_settings_data() + +if _setting['enableeffects']: + from spazmod import spaz_effects + spaz_effects.apply() + def update_name(): import ba.internal from stats import mystats @@ -22,34 +26,31 @@ def update_name(): # all activites related to modify spaz by any how will be here def main(spaz, node, player): - + if _setting['enablehptag']: - tag.addhp(spaz) + tag.addhp(node, spaz) if _setting['enabletags']: tag.addtag(node,player) if _setting['enablerank']: tag.addrank(node,player) - if _setting['enableeffects']: - effects.Effect(spaz,player) - - #update_name() will add threading here later . it was adding delay on game start + #update_name() will add threading here later . it was adding delay on game start def getCharacter(player,character): - + if _setting["sameCharacterForTeam"]: - + if "character" in player.team.sessionteam.customdata: - + return player.team.sessionteam.customdata["character"] - + return character def getRandomCharacter(otherthen): characters=list(ba.app.spaz_appearances.keys()) invalid_characters=["Snake Shadow","Lee","Zola","Butch","Witch","Middle-Man","Alien","OldLady","Wrestler","Gretel","Robot"] - + while True: val=randint(0,len(characters)-1) ch=characters[val] @@ -68,4 +69,4 @@ def setTeamCharacter(): used.append(character) team.name=character team.customdata["character"]=character - + diff --git a/dist/ba_root/mods/spazmod/spaz_effects.py b/dist/ba_root/mods/spazmod/spaz_effects.py new file mode 100644 index 0000000..e17a142 --- /dev/null +++ b/dist/ba_root/mods/spazmod/spaz_effects.py @@ -0,0 +1,360 @@ +from bastd.actor.playerspaz import * +import ba +import bastd + +import functools +import random +from typing import List, Sequence, Optional, Dict, Any +import setting +from playersData import pdata +from stats import mystats +_settings = setting.get_settings_data() + +RANK_EFFECT_MAP = { + 1: ["rainbow", "shine"], + 2: ["sweat"], + 3: ["metal"], + 4: ["iceground"], +} +def effect(repeat_interval=0): + def _activator(method): + @functools.wraps(method) + def _inner_activator(self, *args, **kwargs): + def _caller(): + try: + method(self, *args, **kwargs) + except: + if self is None or not self.is_alive() or not self.node.exists(): + self._activations = [] + else: + raise + effect_activation = ba.Timer(repeat_interval, ba.Call(_caller), repeat=repeat_interval > 0) + self._activations.append(effect_activation) + return _inner_activator + return _activator + + +def node(check_interval=0): + def _activator(method): + @functools.wraps(method) + def _inner_activator(self): + node = method(self) + def _caller(): + if self is None or not self.is_alive() or not self.node.exists(): + node.delete() + self._activations = [] + node_activation = ba.Timer(check_interval, ba.Call(_caller), repeat=check_interval > 0) + try: + self._activations.append(node_activation) + except AttributeError: + pass + return _inner_activator + return _activator + + +class NewPlayerSpaz(PlayerSpaz): + def __init__(self, + player: ba.Player, + color: Sequence[float], + highlight: Sequence[float], + character: str, + powerups_expire: bool = True, + *args, + **kwargs): + + super().__init__(player=player, + color=color, + highlight=highlight, + character=character, + powerups_expire=powerups_expire, + *args, + **kwargs) + self._activations = [] + self.effects = [] + + ba._asyncio._asyncio_event_loop.create_task(self.set_effects()) + + async def set_effects(self): + account_id = self._player._sessionplayer.get_v1_account_id() + custom_effects = pdata.get_custom()['customeffects'] + + if account_id in custom_effects: + self.effects = [custom_effects[account_id]] if type(custom_effects[account_id]) is str else custom_effects[account_id] + else: + # check if we have any effect for his rank. + if _settings['enablestats']: + stats = mystats.get_cached_stats() + if account_id in stats and _settings['enableTop5effects']: + rank = stats[account_id]["rank"] + self.effects = RANK_EFFECT_MAP[rank] if rank in RANK_EFFECT_MAP else [] + + + + if len(self.effects) == 0: + return + + self._effect_mappings = { + "spark": self._add_spark, + "sparkground": self._add_sparkground, + "sweat": self._add_sweat, + "sweatground": self._add_sweatground, + "distortion": self._add_distortion, + "glow": self._add_glow, + "shine": self._add_shine, + "highlightshine": self._add_highlightshine, + "scorch": self._add_scorch, + "ice": self._add_ice, + "iceground": self._add_iceground, + "slime": self._add_slime, + "metal": self._add_metal, + "splinter": self._add_splinter, + "rainbow": self._add_rainbow, + "fairydust": self._add_fairydust, + "noeffect": lambda: None, + } + + for effect in self.effects: + trigger = self._effect_mappings[effect] if effect in self._effect_mappings else lambda: None + activity = self._activity() + if activity: + with ba.Context(self._activity()): + trigger() + + @effect(repeat_interval=0.1) + def _add_spark(self): + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(1, 10), + scale=0.5, + spread=0.2, + chunk_type="spark", + ) + + @effect(repeat_interval=0.1) + def _add_sparkground(self): + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(1, 5), + scale=0.2, + spread=0.1, + chunk_type="spark", + emit_type="stickers", + ) + + @effect(repeat_interval=0.04) + def _add_sweat(self): + velocity = 4.0 + calculate_position = lambda torso_position: torso_position - 0.25 + random.uniform(0, 0.5) + calculate_velocity = lambda node_velocity, multiplier: random.uniform(-velocity, velocity) + node_velocity * multiplier + position = tuple(calculate_position(coordinate) + for coordinate in self.node.torso_position) + velocity = ( + calculate_velocity(self.node.velocity[0], 2), + calculate_velocity(self.node.velocity[1], 4), + calculate_velocity(self.node.velocity[2], 2), + ) + ba.emitfx( + position=position, + velocity=velocity, + count=10, + scale=random.uniform(0.3, 1.4), + spread=0.1, + chunk_type="sweat", + ) + + @effect(repeat_interval=0.04) + def _add_sweatground(self): + velocity = 1.2 + calculate_position = lambda torso_position: torso_position - 0.25 + random.uniform(0, 0.5) + calculate_velocity = lambda node_velocity, multiplier: random.uniform(-velocity, velocity) + node_velocity * multiplier + position = tuple(calculate_position(coordinate) + for coordinate in self.node.torso_position) + velocity = ( + calculate_velocity(self.node.velocity[0], 2), + calculate_velocity(self.node.velocity[1], 4), + calculate_velocity(self.node.velocity[2], 2), + ) + ba.emitfx( + position=position, + velocity=velocity, + count=10, + scale=random.uniform(0.1, 1.2), + spread=0.1, + chunk_type="sweat", + emit_type="stickers", + ) + + @effect(repeat_interval=1.0) + def _add_distortion(self): + ba.emitfx( + position=self.node.position, + spread=1.0, + emit_type="distortion" + ) + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(1, 5), + emit_type="tendrils", + tendril_type="smoke", + ) + + @effect(repeat_interval=3.0) + def _add_shine(self): + shine_factor = 1.2 + dim_factor = 0.90 + + default_color = self.node.color + shiny_color = tuple(channel * shine_factor for channel in default_color) + dimmy_color = tuple(channel * dim_factor for channel in default_color) + animation = { + 0: default_color, + 1: dimmy_color, + 2: shiny_color, + 3: default_color, + } + ba.animate_array(self.node, "color", 3, animation) + + @effect(repeat_interval=9.0) + def _add_highlightshine(self): + shine_factor = 1.2 + dim_factor = 0.90 + + default_highlight = self.node.highlight + shiny_highlight = tuple(channel * shine_factor for channel in default_highlight) + dimmy_highlight = tuple(channel * dim_factor for channel in default_highlight) + animation = { + 0: default_highlight, + 3: dimmy_highlight, + 6: shiny_highlight, + 9: default_highlight, + } + ba.animate_array(self.node, "highlight", 3, animation) + + @effect(repeat_interval=2.0) + def _add_rainbow(self): + highlight = tuple(random.random() for _ in range(3)) + highlight = ba.safecolor(highlight) + animation = { + 0: self.node.highlight, + 2: highlight, + } + ba.animate_array(self.node, "highlight", 3, animation) + + @node(check_interval=0.5) + def _add_glow(self): + glowing_light = ba.newnode( + "light", + attrs={ + "color": (1.0, 0.4, 0.5), + "height_attenuated": False, + "radius": 0.4} + ) + self.node.connectattr("position", glowing_light, "position") + ba.animate( + glowing_light, + "intensity", + {0: 0.0, 1: 0.2, 2: 0.0}, + loop=True) + return glowing_light + + @node(check_interval=0.5) + def _add_scorch(self): + scorcher = ba.newnode( + "scorch", + attrs={ + "position": self.node.position, + "size": 1.00, + "big": True} + ) + self.node.connectattr("position", scorcher, "position") + animation = { + 0: (1,0,0), + 1: (0,1,0), + 2: (1,0,1), + 3: (0,1,1), + 4: (1,0,0), + } + ba.animate_array(scorcher, "color", 3, animation, loop=True) + return scorcher + + @effect(repeat_interval=0.5) + def _add_ice(self): + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(2, 8), + scale=0.4, + spread=0.2, + chunk_type="ice", + ) + + @effect(repeat_interval=0.05) + def _add_iceground(self): + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(1, 2), + scale=random.uniform(0, 0.5), + spread=1.0, + chunk_type="ice", + emit_type="stickers", + ) + + @effect(repeat_interval=0.25) + def _add_slime(self): + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(1, 10), + scale=0.4, + spread=0.2, + chunk_type="slime", + ) + + @effect(repeat_interval=0.25) + def _add_metal(self): + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(1, 4), + scale=0.4, + spread=0.1, + chunk_type="metal", + ) + + @effect(repeat_interval=0.75) + def _add_splinter(self): + ba.emitfx( + position=self.node.position, + velocity=self.node.velocity, + count=random.randint(1, 5), + scale=0.5, + spread=0.2, + chunk_type="splinter", + ) + + @effect(repeat_interval=0.25) + def _add_fairydust(self): + velocity = 2 + calculate_position = lambda torso_position: torso_position - 0.25 + random.uniform(0, 0.5) + calculate_velocity = lambda node_velocity, multiplier: random.uniform(-velocity, velocity) + node_velocity * multiplier + position = tuple(calculate_position(coordinate) + for coordinate in self.node.torso_position) + velocity = ( + calculate_velocity(self.node.velocity[0], 2), + calculate_velocity(self.node.velocity[1], 4), + calculate_velocity(self.node.velocity[2], 2), + ) + ba.emitfx( + position=position, + velocity=velocity, + count=random.randint(1, 10), + spread=0.1, + emit_type="fairydust", + ) + +def apply() -> None: + bastd.actor.playerspaz.PlayerSpaz = NewPlayerSpaz diff --git a/dist/ba_root/mods/spazmod/tag.py b/dist/ba_root/mods/spazmod/tag.py index 9682f05..17c997f 100644 --- a/dist/ba_root/mods/spazmod/tag.py +++ b/dist/ba_root/mods/spazmod/tag.py @@ -1,6 +1,6 @@ from playersData import pdata -import ba, setting +import ba, setting, _ba from stats import mystats sett = setting.get_settings_data() def addtag(node,player): @@ -33,16 +33,20 @@ def addrank(node,player): if rank: Rank(node,rank) -def addhp(node): - hp = node.hitpoints +def addhp(node, spaz): def showHP(): - HitPoint(owner=node,prefix=str(int(hp)),position=(0,0.75,0),shad = 1.4) - if hp: t = ba.Timer(100,ba.Call(showHP),repeat = True, timetype=ba.TimeType.SIM, timeformat=ba.TimeFormat.MILLISECONDS) + hp = spaz.hitpoints + if spaz.node.exists(): + HitPoint(owner=node,prefix=str(int(hp)),position=(0,1.75,0),shad = 1.4) + else: + spaz.hptimer = None + + spaz.hptimer = ba.Timer(100,ba.Call(showHP),repeat = True, timetype=ba.TimeType.SIM, timeformat=ba.TimeFormat.MILLISECONDS) class Tag(object): def __init__(self,owner=None,tag="somthing",col=(1,1,1)): self.node=owner - + mnode = ba.newnode('math', owner=self.node, attrs={ @@ -115,16 +119,15 @@ class Rank(object): mnode.connectattr('output', self.rank_text, 'position') class HitPoint(object): - def __init__(self,position = (0,1.5,0),owner = None,prefix = 'ADMIN',shad = 1.2): - if not sett['enablehptag']: return + def __init__(self,position = (0,1.5,0),owner = None,prefix = '0',shad = 1.2): self.position = position - self.owner = owner - m = ba.newnode('math', owner=self.owner, attrs={'input1': self.position, 'operation': 'add'}) - self.owner.connectattr('position', m, 'input2') + self.node = owner + m = ba.newnode('math', owner=self.node, attrs={'input1': self.position, 'operation': 'add'}) + self.node.connectattr('torso_position', m, 'input2') prefix = int(prefix) / 10 preFix = u"\ue047" + str(prefix) + u"\ue047" self._Text = ba.newnode('text', - owner=self.owner, + owner=self.node, attrs={ 'text':preFix, 'in_world':True, diff --git a/dist/ba_root/mods/stats/mystats.py b/dist/ba_root/mods/stats/mystats.py index 929ec1a..fb4b788 100644 --- a/dist/ba_root/mods/stats/mystats.py +++ b/dist/ba_root/mods/stats/mystats.py @@ -31,28 +31,7 @@ our_settings = setting.get_settings_data() # where our stats file and pretty html output will go base_path = os.path.join(_ba.env()['python_directory_user'], "stats" + os.sep) statsfile = base_path + 'stats.json' -htmlfile = base_path + 'stats_page.html' -table_style = "{width:100%;border: 3px solid black;border-spacing: 5px;border-collapse:collapse;text-align:center;background-color:#fff}" -heading_style = "{border: 3px solid black;text-align:center;}" -html_start = f''' - - - - Test Server - - - -

Top 200 Players

- - - - - - - - - -''' +cached_stats = {} statsDefault = { "pb-IF4VAk4a": { "rank": 65, @@ -121,20 +100,23 @@ def dump_stats(s: dict): print('Stats file not found!') -def get_stats_by_id(ID: str): - a = get_all_stats() - if ID in a: - return a[ID] +def get_stats_by_id(account_id: str): + a = get_cached_stats + if account_id in a: + return a[account_id] else: return None +def get_cached_stats(): + return cached_stats def refreshStats(): + global cached_stats # lastly, write a pretty html version. # our stats url could point at something like this... pStats = get_all_stats() - # f=open(htmlfile, 'w') - # f.write(html_start) + cached_stats = pStats + entries = [(a['scores'], a['kills'], a['deaths'], a['games'], a['name'], a['aid']) for a in pStats.values()]
RankNameScoreKillsDeathsGames Played